You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailscale/net/interfaces
Andrew Dunham c4ccdd1bd1 net/interfaces: ensure we return valid 'self' IP in LikelyHomeRouterIP
Before this fix, LikelyHomeRouterIP could return a 'self' IP that
doesn't correspond to the gateway address, since it picks the first
private address when iterating over the set interfaces as the 'self' IP,
without checking that the address corresponds with the
previously-detected gateway.

This behaviour was introduced by accident in aaf2df7, where we deleted
the following code:

    for _, prefix := range privatev4s {
        if prefix.Contains(gateway) && prefix.Contains(ip) {
            myIP = ip
            ok = true
            return
        }
    }

Other than checking that 'gateway' and 'ip' were private IP addresses
(which were correctly replaced with a call to the netip.Addr.IsPrivate
method), it also implicitly checked that both 'gateway' and 'ip' were a
part of the *same* prefix, and thus likely to be the same interface.

Restore that behaviour by explicitly checking pfx.Contains(gateway),
which, given that the 'ip' variable is derived from our prefix 'pfx',
ensures that the 'self' IP will correspond to the returned 'gateway'.

Fixes #10466

Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
Change-Id: Iddd2ee70cefb9fb40071986fefeace9ca2441ee6
11 months ago
..
interfaces.go net/interfaces: ensure we return valid 'self' IP in LikelyHomeRouterIP 11 months ago
interfaces_bsd.go net/netns: don't log errors when we can't get the default route on Darwin 2 years ago
interfaces_darwin.go ipn/ipnlocal: add delegated interface information to /interfaces PeerAPI handler 2 years ago
interfaces_darwin_test.go all: update copyright and license headers 2 years ago
interfaces_default_route_test.go all: update copyright and license headers 2 years ago
interfaces_defaultrouteif_todo.go all: update copyright and license headers 2 years ago
interfaces_freebsd.go net/interfaces: redo how we get the default interface on macOS and iOS 2 years ago
interfaces_linux.go all: move network monitoring from wgengine/monitor to net/netmon 2 years ago
interfaces_linux_test.go all: use tstest.Replace more 2 years ago
interfaces_test.go net/interfaces: ensure we return valid 'self' IP in LikelyHomeRouterIP 11 months ago
interfaces_windows.go all: update copyright and license headers 2 years ago
interfaces_windows_test.go all: update copyright and license headers 2 years ago