Skip to content

Commit

Permalink
Merge pull request #3335 from weaveworks/simplify-addrs
Browse files Browse the repository at this point in the history
Simplify fetch of IP addresses in a namespace
  • Loading branch information
bboreham authored Aug 27, 2018
2 parents 75d0893 + ef832eb commit 2215e66
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions probe/docker/network_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,15 @@ func namespaceIPAddresses(processID int) ([]*net.IPNet, error) {
// return all non-local IP addresses from the current namespace
func allNonLocalAddresses() ([]*net.IPNet, error) {
var cidrs []*net.IPNet
links, err := netlink.LinkList()

addrs, err := netlink.AddrList(nil, netlink.FAMILY_ALL)
if err != nil {
return nil, err
}

for _, link := range links {
addrs, err := netlink.AddrList(link, netlink.FAMILY_ALL)
if err != nil {
return nil, err
}
for _, addr := range addrs {
// Exclude link-local ipv6 addresses, localhost, etc. Hope this is the correct test.
if addr.Scope == unix.RT_SCOPE_UNIVERSE {
cidrs = append(cidrs, addr.IPNet)
}
for _, addr := range addrs {
// Exclude link-local ipv6 addresses, localhost, etc. Hope this is the correct test.
if addr.Scope == unix.RT_SCOPE_UNIVERSE {
cidrs = append(cidrs, addr.IPNet)
}
}
return cidrs, nil
Expand Down

0 comments on commit 2215e66

Please sign in to comment.