mirror of
https://github.com/netbirdio/netbird.git
synced 2026-07-16 11:39:57 +00:00
* [client] Filter link-local and multicast from network addresses Skip IPv6 link-local and multicast addresses when building the peer network_addresses list on non-iOS platforms, matching the existing iOS behavior. A flapping NIC's link-local address otherwise churns the peer meta on every interface up/down. * [client] Skip engine restart when default route is unchanged After the network monitor's debounce window, re-check the default next hop before triggering a client restart. A flapping NIC that returns to the same default route no longer forces a restart, avoiding redundant sync stream reconnects and peer meta churn. * [client] Exclude own overlay address from reported network addresses The peer's own WireGuard overlay address (v4 and v6) was reported in network_addresses. As the interface comes and goes during reconnects it churned the peer meta on the management server. Drop it in GetInfoWithChecks, matching the IP regardless of prefix length since the engine knows the overlay address with the network mask while the interface reports it as a host address. * [client] Treat missing default route per protocol in next-hop check A failed GetNextHop lookup is now treated as an absent route (zero Nexthop) and compared per protocol, instead of forcing a restart. In a single-stack network the missing IPv6 default route no longer counts as a change on every debounce, which previously defeated the unchanged-route check. * [client] Make next-hop check injectable for network monitor tests Move the next-hop comparison behind a NetworkMonitor field set by New(), so tests can supply a stub instead of hitting the host's real default route. Fixes the Event/MultiEvent tests hanging after the unchanged-route check was added. * Revert "[client] Make next-hop check injectable for network monitor tests" This reverts commit88a9d96e8f. * Revert "[client] Treat missing default route per protocol in next-hop check" This reverts commit0fb531e4bc. * Revert "[client] Skip engine restart when default route is unchanged" This reverts commita071b55f35.
86 lines
2.3 KiB
Go
86 lines
2.3 KiB
Go
package system
|
|
|
|
import (
|
|
"context"
|
|
"net/netip"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"google.golang.org/grpc/metadata"
|
|
)
|
|
|
|
func Test_LocalWTVersion(t *testing.T) {
|
|
got := GetInfo(context.TODO())
|
|
want := "development"
|
|
assert.Equal(t, want, got.NetbirdVersion)
|
|
}
|
|
|
|
func Test_UIVersion(t *testing.T) {
|
|
ctx := context.Background()
|
|
want := "netbird-desktop-ui/development"
|
|
ctx = metadata.NewOutgoingContext(ctx, map[string][]string{
|
|
"user-agent": {want},
|
|
})
|
|
|
|
got := GetInfo(ctx)
|
|
assert.Equal(t, want, got.UIVersion)
|
|
}
|
|
|
|
func Test_CustomHostname(t *testing.T) {
|
|
// nolint
|
|
ctx := context.WithValue(context.Background(), DeviceNameCtxKey, "custom-host")
|
|
want := "custom-host"
|
|
|
|
got := GetInfo(ctx)
|
|
assert.Equal(t, want, got.Hostname)
|
|
}
|
|
|
|
func Test_NetAddresses(t *testing.T) {
|
|
addr, err := networkAddresses()
|
|
if err != nil {
|
|
t.Errorf("failed to discover network addresses: %s", err)
|
|
}
|
|
if len(addr) == 0 {
|
|
t.Errorf("no network addresses found")
|
|
}
|
|
}
|
|
|
|
func TestInfo_RemoveAddresses(t *testing.T) {
|
|
addr := func(cidr string) NetworkAddress {
|
|
return NetworkAddress{NetIP: netip.MustParsePrefix(cidr)}
|
|
}
|
|
|
|
info := &Info{
|
|
NetworkAddresses: []NetworkAddress{
|
|
addr("192.168.1.7/24"),
|
|
addr("100.76.70.97/32"), // overlay v4 (host mask /32)
|
|
addr("2001:818:c51b:4800:845:a65d:ae6f:623f/64"), // real global v6
|
|
addr("fd00:1234::1/64"), // overlay v6
|
|
},
|
|
}
|
|
|
|
// Overlay addresses as the engine knows them, with a different mask (/16, /64).
|
|
info.removeAddresses(
|
|
netip.MustParseAddr("100.76.70.97"),
|
|
netip.MustParseAddr("fd00:1234::1"),
|
|
)
|
|
|
|
want := []string{"192.168.1.7/24", "2001:818:c51b:4800:845:a65d:ae6f:623f/64"}
|
|
if len(info.NetworkAddresses) != len(want) {
|
|
t.Fatalf("got %d addresses, want %d: %v", len(info.NetworkAddresses), len(want), info.NetworkAddresses)
|
|
}
|
|
for i, w := range want {
|
|
if got := info.NetworkAddresses[i].NetIP.String(); got != w {
|
|
t.Errorf("address[%d] = %s, want %s", i, got, w)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestInfo_RemoveAddresses_NoOp(t *testing.T) {
|
|
info := &Info{NetworkAddresses: []NetworkAddress{{NetIP: netip.MustParsePrefix("10.0.0.1/24")}}}
|
|
info.removeAddresses()
|
|
if len(info.NetworkAddresses) != 1 {
|
|
t.Errorf("expected no change with empty input, got %v", info.NetworkAddresses)
|
|
}
|
|
}
|