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
2023-12-05 10:29:37 -05:00
..
interfaces_bsd.go net/netns: don't log errors when we can't get the default route on Darwin 2023-04-18 09:57:15 -07:00
interfaces_darwin_test.go all: update copyright and license headers 2023-01-27 15:36:29 -08:00
interfaces_darwin.go ipn/ipnlocal: add delegated interface information to /interfaces PeerAPI handler 2023-02-27 09:39:49 -08:00
interfaces_default_route_test.go all: update copyright and license headers 2023-01-27 15:36:29 -08:00
interfaces_defaultrouteif_todo.go all: update copyright and license headers 2023-01-27 15:36:29 -08:00
interfaces_freebsd.go net/interfaces: redo how we get the default interface on macOS and iOS 2023-02-10 16:23:37 -08:00
interfaces_linux_test.go all: use tstest.Replace more 2023-03-04 12:24:55 -08:00
interfaces_linux.go all: move network monitoring from wgengine/monitor to net/netmon 2023-04-20 10:15:59 -07:00
interfaces_test.go net/interfaces: ensure we return valid 'self' IP in LikelyHomeRouterIP 2023-12-05 10:29:37 -05:00
interfaces_windows_test.go all: update copyright and license headers 2023-01-27 15:36:29 -08:00
interfaces_windows.go all: update copyright and license headers 2023-01-27 15:36:29 -08:00
interfaces.go net/interfaces: ensure we return valid 'self' IP in LikelyHomeRouterIP 2023-12-05 10:29:37 -05:00