コード例 #1
0
ファイル: container.go プロジェクト: dilgerma/scope
// MapEndpoint2IP maps endpoint nodes to their IP address, for joining
// with container nodes.  We drop endpoint nodes with pids, as they
// will be joined to containers through the process topology, and we
// don't want to double count edges.
func MapEndpoint2IP(m report.Node, local report.Networks) report.Nodes {
	// Don't include procspied connections, to prevent double counting
	_, ok := m.Latest.Lookup(endpoint.Procspied)
	if ok {
		return report.Nodes{}
	}
	scope, addr, port, ok := report.ParseEndpointNodeID(m.ID)
	if !ok {
		return report.Nodes{}
	}
	if ip := net.ParseIP(addr); ip != nil && !local.Contains(ip) {
		return report.Nodes{TheInternetID: theInternetNode(m)}
	}

	// We don't always know what port a container is listening on, and
	// container-to-container communications can be unambiguously identified
	// without ports. OTOH, connections to the host IPs which have been port
	// mapped to a container can only be unambiguously identified with the port.
	// So we need to emit two nodes, for two different cases.
	id := report.MakeScopedEndpointNodeID(scope, addr, "")
	idWithPort := report.MakeScopedEndpointNodeID(scope, addr, port)
	return report.Nodes{
		id:         NewDerivedNode(id, m).WithTopology(IP),
		idWithPort: NewDerivedNode(idWithPort, m).WithTopology(IP),
	}
}
コード例 #2
0
ファイル: process.go プロジェクト: dilgerma/scope
// MapEndpoint2Pseudo makes internet of host pesudo nodes from a endpoint node.
func MapEndpoint2Pseudo(n report.Node, local report.Networks) report.Nodes {
	var node report.Node

	addr, ok := n.Latest.Lookup(endpoint.Addr)
	if !ok {
		return report.Nodes{}
	}

	if ip := net.ParseIP(addr); ip != nil && !local.Contains(ip) {
		// If the dstNodeAddr is not in a network local to this report, we emit an
		// internet node
		node = theInternetNode(n)
	} else {
		// due to https://$GITHUB_URI/issues/1323 we are dropping
		// all non-internet pseudo nodes for now.
		// node = NewDerivedPseudoNode(MakePseudoNodeID(addr), n)
		return report.Nodes{}
	}
	return report.Nodes{node.ID: node}
}