Skip to content

Commit

Permalink
fingerprint: fix 'default' alias not added to interface specified by …
Browse files Browse the repository at this point in the history
…`network_interface` (#18096)
  • Loading branch information
kevinschoonover committed Aug 1, 2023
1 parent 511cb55 commit 4841791
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .changelog/18096.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
fingerprint: fix 'default' alias not being added to interface specified by network_interface
```
8 changes: 2 additions & 6 deletions client/fingerprint/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down
7 changes: 5 additions & 2 deletions client/fingerprint/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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",
Expand All @@ -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", "", ""},
},
}

Expand Down

0 comments on commit 4841791

Please sign in to comment.