Do not infer short-lived connections for host-networking containers

This commit is contained in:
Alfonso Acosta
2016-07-07 15:44:13 +00:00
parent 6d527821e7
commit c843d24f6f
2 changed files with 18 additions and 8 deletions
+13 -7
View File
@@ -17,6 +17,7 @@ const (
ImageName = "docker_image_name"
ImageLabelPrefix = "docker_image_label_"
OverlayPeerPrefix = "docker_peer_"
IsInHostNetwork = "docker_is_in_host_network"
)
// Exposed for testing
@@ -191,21 +192,21 @@ func (r *Reporter) containerTopology(localAddrs []net.IP) report.Topology {
Add(ContainerIPsWithScopes, report.MakeStringSet(hostIPsWithScopes...))
}
var networkInfo func(prefix string) report.Sets
networkInfo = func(prefix string) report.Sets {
var networkInfo func(prefix string) (report.Sets, bool)
networkInfo = func(prefix string) (ips report.Sets, isHostMapped bool) {
container, ok := r.registry.GetContainerByPrefix(prefix)
if !ok {
return report.EmptySets
return report.EmptySets, false
}
networkMode, ok := container.NetworkMode()
if ok && strings.HasPrefix(networkMode, "container:") {
return networkInfo(networkMode[10:])
} else if ok && networkMode == NetworkModeHost {
return hostNetworkInfo
return hostNetworkInfo, true
}
return container.NetworkInfo(localAddrs)
return container.NetworkInfo(localAddrs), false
}
for _, node := range nodes {
@@ -213,8 +214,13 @@ func (r *Reporter) containerTopology(localAddrs []net.IP) report.Topology {
if !ok {
continue
}
networkInfo := networkInfo(id)
result.AddNode(node.WithSets(networkInfo))
networkInfo, isHostMapped := networkInfo(id)
node = node.WithSets(networkInfo)
if isHostMapped {
node = node.WithLatests(map[string]string{IsInHostNetwork: "true"})
}
result.AddNode(node)
}
}
+5 -1
View File
@@ -249,7 +249,11 @@ var portMappingMatch = regexp.MustCompile(`([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.
func MapContainer2IP(m report.Node) []string {
// if this container doesn't make connections, we can ignore it
_, doesntMakeConnections := m.Latest.Lookup(report.DoesNotMakeConnections)
if doesntMakeConnections {
// if this container belongs to the host's networking namespace
// we cannot use its IP to attribute connections
// (they could come from any other process on the host or DNAT-ed IPs)
_, isInHostNetwork := m.Latest.Lookup(docker.IsInHostNetwork)
if doesntMakeConnections || isInHostNetwork {
return nil
}