The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/1648
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From ba613e076ca598a16cc2a7262289c8c8273a31a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com> Date: Wed, 24 Feb 2016 15:26:45 -0500 Subject: [PATCH] Export and use the address scope MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber <stgra...@ubuntu.com> --- lxc/list.go | 8 ++++++++ lxd/main.go | 18 ++++++++++++++++++ shared/container.go | 1 + specs/rest-api.md | 27 ++++++++++++++++++--------- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/lxc/list.go b/lxc/list.go index 949222e..06b227e 100644 --- a/lxc/list.go +++ b/lxc/list.go @@ -374,6 +374,10 @@ func (c *listCmd) IP4ColumnData(cInfo shared.ContainerInfo, cState *shared.Conta } for _, addr := range net.Addresses { + if shared.StringInSlice(addr.Scope, []string{"link", "local"}) { + continue + } + if addr.Family == "inet" { ipv4s = append(ipv4s, fmt.Sprintf("%s (%s)", addr.Address, netName)) } @@ -394,6 +398,10 @@ func (c *listCmd) IP6ColumnData(cInfo shared.ContainerInfo, cState *shared.Conta } for _, addr := range net.Addresses { + if shared.StringInSlice(addr.Scope, []string{"link", "local"}) { + continue + } + if addr.Family == "inet6" { ipv6s = append(ipv6s, fmt.Sprintf("%s (%s)", addr.Address, netName)) } diff --git a/lxd/main.go b/lxd/main.go index 2a49ecd..5446033 100644 --- a/lxd/main.go +++ b/lxd/main.go @@ -871,10 +871,28 @@ func printnet() error { family = "inet6" } + scope := "global" + if strings.HasPrefix(fields[0], "127") { + scope = "local" + } + + if fields[0] == "::1" { + scope = "local" + } + + if strings.HasPrefix(fields[0], "169.254") { + scope = "link" + } + + if strings.HasPrefix(fields[0], "fe80:") { + scope = "link" + } + address := shared.ContainerStateNetworkAddress{} address.Family = family address.Address = fields[0] address.Netmask = fields[1] + address.Scope = scope network.Addresses = append(network.Addresses, address) } diff --git a/shared/container.go b/shared/container.go index b7605b6..58bcd8d 100644 --- a/shared/container.go +++ b/shared/container.go @@ -39,6 +39,7 @@ type ContainerStateNetworkAddress struct { Family string `json:"family"` Address string `json:"address"` Netmask string `json:"netmask"` + Scope string `json:"scope"` } type ContainerStateNetworkCounters struct { diff --git a/specs/rest-api.md b/specs/rest-api.md index fe4b4b5..621aca4 100644 --- a/specs/rest-api.md +++ b/specs/rest-api.md @@ -643,12 +643,14 @@ HTTP code for this should be 202 (Accepted). { "family": "inet", "address": "10.0.3.27", - "netmask": "24" + "netmask": "24", + "scope": "global" }, { "family": "inet6", "address": "fe80::216:3eff:feec:65a8", - "netmask": "64" + "netmask": "64", + "scope": "link" } ], "counters": { @@ -668,12 +670,14 @@ HTTP code for this should be 202 (Accepted). { "family": "inet", "address": "127.0.0.1", - "netmask": "8" + "netmask": "8", + "scope": "local" }, { "family": "inet6", "address": "::1", - "netmask": "128" + "netmask": "128", + "scope": "local" } ], "counters": { @@ -693,12 +697,14 @@ HTTP code for this should be 202 (Accepted). { "family": "inet", "address": "10.0.3.1", - "netmask": "24" + "netmask": "24", + "scope": "global" }, { "family": "inet6", "address": "fe80::68d4:87ff:fe40:7769", - "netmask": "64" + "netmask": "64", + "scope": "link" } ], "counters": { @@ -718,17 +724,20 @@ HTTP code for this should be 202 (Accepted). { "family": "inet", "address": "29.17.181.59", - "netmask": "7" + "netmask": "7", + "scope": "global" }, { "family": "inet6", "address": "fd80:56c2:e21c:0:199:9379:e711:b3e1", - "netmask": "88" + "netmask": "88", + "scope": "global" }, { "family": "inet6", "address": "fe80::79:e7ff:fe0d:5123", - "netmask": "64" + "netmask": "64", + "scope": "link" } ], "counters": {
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel