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

Co-authored-by: Kevin Schoonover <github@kschoon.me>
This commit is contained in:
hc-github-team-nomad-core 2023-08-01 07:38:03 -05:00 committed by GitHub
parent 9fe88ebefe
commit b75f552246
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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", "", ""},
},
}