Skip to content

Commit

Permalink
fix 'default' alias not added to NetworkInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinschoonover committed Jul 29, 2023
1 parent 9e98d69 commit 048a576
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
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 048a576

Please sign in to comment.