diff --git a/integration-tests/pkg/mock_sensor/server.go b/integration-tests/pkg/mock_sensor/server.go index 3b5d228afd..5b99e5fcda 100644 --- a/integration-tests/pkg/mock_sensor/server.go +++ b/integration-tests/pkg/mock_sensor/server.go @@ -489,9 +489,29 @@ func (m *MockSensor) pushEndpoint(containerID string, endpoint *sensorAPI.Networ // translateAddress is a helper function for converting binary representations // of network addresses (in the signals) to usable forms for testing func (m *MockSensor) translateAddress(addr *sensorAPI.NetworkAddress) string { - ipPortPair := utils.NetworkPeerID{ - Address: utils.IPFromBytes(addr.GetAddressData()), - Port: uint16(addr.GetPort()), + peerId := utils.NetworkPeerID{Port: uint16(addr.GetPort())} + addressData := addr.GetAddressData() + if len(addressData) > 0 { + peerId.Address = utils.IPFromBytes(addressData) + return peerId.String() } - return ipPortPair.String() + + // If there is no address data, this is either the source address or + // IpNetwork should be set and represent a CIDR block or external IP address. + ipNetworkData := addr.GetIpNetwork() + if len(ipNetworkData) == 0 { + return peerId.String() + } + + ipNetwork := utils.IPNetworkFromCIDRBytes(ipNetworkData) + prefixLen := ipNetwork.PrefixLen() + // If this is IPv4 and the prefix length is 32 or this is IPv6 and the prefix length + // is 128 this is a regular IP address and not a CIDR block + if (ipNetwork.Family() == utils.IPv4 && prefixLen == byte(32)) || + (ipNetwork.Family() == utils.IPv6 && prefixLen == byte(128)) { + peerId.Address = ipNetwork.IP() + } else { + peerId.IPNetwork = ipNetwork + } + return peerId.String() }