Ignore IPv6 addresses in Docker reporter (#1552)

This commit is contained in:
Tom Wilkie
2016-06-15 16:05:12 +01:00
committed by GitHub
parent d7da63a6e4
commit d888509865

View File

@@ -277,12 +277,15 @@ func (c *container) ports(localAddrs []net.IP) report.StringSet {
continue
}
for _, b := range bindings {
if b.HostIP == "0.0.0.0" {
for _, ip := range localAddrs {
if b.HostIP != "0.0.0.0" {
ports = append(ports, fmt.Sprintf("%s:%s->%s", b.HostIP, b.HostPort, port))
continue
}
for _, ip := range localAddrs {
if ip.To4() != nil {
ports = append(ports, fmt.Sprintf("%s:%s->%s", ip, b.HostPort, port))
}
} else {
ports = append(ports, fmt.Sprintf("%s:%s->%s", b.HostIP, b.HostPort, port))
}
}
}
@@ -307,6 +310,11 @@ func addScopeToIPs(hostID string, ips []string) []string {
return ipsWithScopes
}
func isIPv4(addr string) bool {
ip := net.ParseIP(addr)
return ip != nil && ip.To4() != nil
}
func (c *container) NetworkInfo(localAddrs []net.IP) report.Sets {
c.RLock()
defer c.RUnlock()
@@ -328,13 +336,20 @@ func (c *container) NetworkInfo(localAddrs []net.IP) report.Sets {
}
}
// Filter out IPv6 addresses; nothing works with IPv6 yet
ipv4s := []string{}
for _, ip := range ips {
if isIPv4(ip) {
ipv4s = append(ipv4s, ip)
}
}
// Treat all Docker IPs as local scoped.
ipsWithScopes := addScopeToIPs(c.hostID, ips)
ipsWithScopes := addScopeToIPs(c.hostID, ipv4s)
return report.EmptySets.
Add(ContainerNetworks, report.MakeStringSet(networks...)).
Add(ContainerPorts, c.ports(localAddrs)).
Add(ContainerIPs, report.MakeStringSet(ips...)).
Add(ContainerIPs, report.MakeStringSet(ipv4s...)).
Add(ContainerIPsWithScopes, report.MakeStringSet(ipsWithScopes...))
}