diff --git a/.changelog/18096.txt b/.changelog/18096.txt new file mode 100644 index 000000000..625bd1f68 --- /dev/null +++ b/.changelog/18096.txt @@ -0,0 +1,3 @@ +```release-note:bug +fingerprint: fix 'default' alias not being added to interface specified by network_interface +``` diff --git a/client/fingerprint/network.go b/client/fingerprint/network.go index 7b2090835..3018f64f8 100644 --- a/client/fingerprint/network.go +++ b/client/fingerprint/network.go @@ -247,18 +247,14 @@ func deriveAddressAliases(iface net.Interface, addr net.IP, config *config.Confi } } - if len(aliases) > 0 { - return - } - if config.NetworkInterface != "" { if config.NetworkInterface == iface.Name { - return []string{"default"} + aliases = append(aliases, "default") } } else if ri, err := sockaddr.NewRouteInfo(); err == nil { defaultIface, err := ri.GetDefaultInterfaceName() if err == nil && iface.Name == defaultIface { - return []string{"default"} + aliases = append(aliases, "default") } } diff --git a/client/fingerprint/network_test.go b/client/fingerprint/network_test.go index 12da2bace..fb247fd79 100644 --- a/client/fingerprint/network_test.go +++ b/client/fingerprint/network_test.go @@ -500,6 +500,9 @@ func TestNetworkFingerPrint_MultipleAliases(t *testing.T) { for alias := range cfg.HostNetworks { expected = append(expected, alias) } + // eth3 matches the NetworkInterface and will then generate the 'default' + // alias + expected = append(expected, "default") sort.Strings(expected) sort.Strings(aliases) require.Equal(t, expected, aliases, "host networks should match aliases") @@ -537,7 +540,7 @@ func TestNetworkFingerPrint_HostNetworkReservedPorts(t *testing.T) { CIDR: "100.64.0.11/10", }, }, - expected: []string{"", "", ""}, + expected: []string{"", "", "", ""}, }, { name: "reserved ports in some aliases", @@ -560,7 +563,7 @@ func TestNetworkFingerPrint_HostNetworkReservedPorts(t *testing.T) { CIDR: "100.64.0.11/10", }, }, - expected: []string{"22", "80,3000-4000", ""}, + expected: []string{"22", "80,3000-4000", "", ""}, }, }