[lxc-devel] [lxd/master] lxd/networks: Consider IPv6 neighborhood entries

stgraber on Github lxc-bot at linuxcontainers.org
Wed Feb 5 17:06:03 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200205/2bf64a58/attachment.bin>
-------------- next part --------------
From 8cff1bbf8c9198bba49fead300d3c4cfff388b86 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 5 Feb 2020 12:05:19 -0500
Subject: [PATCH] lxd/networks: Consider IPv6 neighborhood entries
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: St├ęphane Graber <stgraber at ubuntu.com>
---
 lxd/network/network_utils.go | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/lxd/network/network_utils.go b/lxd/network/network_utils.go
index 5868310881..176abbfc8e 100644
--- a/lxd/network/network_utils.go
+++ b/lxd/network/network_utils.go
@@ -680,6 +680,36 @@ func GetHostDevice(parent string, vlan string) string {
 func GetLeaseAddresses(s *state.State, networkName string, hwaddr string) ([]api.InstanceStateNetworkAddress, error) {
 	addresses := []api.InstanceStateNetworkAddress{}
 
+	// Look for neighborhood entries for IPv6.
+	out, err := shared.RunCommand("ip", "-6", "neigh", "show", "dev", networkName)
+	if err == nil {
+		for _, line := range strings.Split(out, "\n") {
+			// Split fields and early validation.
+			fields := strings.Fields(line)
+			if len(fields) != 4 {
+				continue
+			}
+
+			if fields[2] != hwaddr {
+				continue
+			}
+
+			// Prepare the entry.
+			addr := api.InstanceStateNetworkAddress{}
+			addr.Address = fields[0]
+			addr.Family = "inet6"
+
+			if strings.HasPrefix(fields[0], "fe80::") {
+				addr.Scope = "link"
+			} else {
+				addr.Scope = "global"
+			}
+
+			addresses = append(addresses, addr)
+		}
+	}
+
+	// Look for DHCP leases.
 	leaseFile := shared.VarPath("networks", networkName, "dnsmasq.leases")
 	if !shared.PathExists(leaseFile) {
 		return addresses, nil


More information about the lxc-devel mailing list