fingerprint: fix 'default' alias not added to interface specified by network_interface (#18096)

This commit is contained in:
Kevin Schoonover
2023-08-01 05:35:31 -07:00
committed by GitHub
parent 511cb55633
commit 4841791c86
3 changed files with 10 additions and 8 deletions

3
.changelog/18096.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:bug
fingerprint: fix 'default' alias not being added to interface specified by network_interface
```

View File

@@ -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")
}
}

View File

@@ -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", "", ""},
},
}