mirror of
https://github.com/tailscale/tailscale.git
synced 2026-12-01 14:12:32 -08:00
ipn/ipnlocal: update LAN routes on link change with any exit node
linkChange only reconfigured the router after a network change if LAN access was allowed, but the router config depends on the local interfaces whenever an exit node is in use. Fixes #22739 Signed-off-by: Nick Khyl <[email protected]>
This commit is contained in:
1 parent
00a8cd1ef2
commit
737964a71d
2 files changed
+92
-2
No files matched your search
@@ -1265,8 +1265,10 @@ func (b *LocalBackend) linkChange(delta *netmon.ChangeDelta) {
|
||||
}
|
||||
|
||||
var needReconfig bool
|
||||
// If the network changed and we're using an exit node and allowing LAN access, we may need to reconfigure.
|
||||
if delta.RebindLikelyRequired && prefs.ExitNodeID() != "" && prefs.ExitNodeAllowLANAccess() {
|
||||
// If the network changed and we're using an exit node, we may need to reconfigure.
|
||||
// The LAN routes are either excluded from the tunnel or explicitly routed into it,
|
||||
// depending on whether LAN access is allowed.
|
||||
if delta.RebindLikelyRequired && prefs.ExitNodeID() != "" {
|
||||
b.logf("linkChange: in state %v; updating LAN routes", b.state)
|
||||
needReconfig = true
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand/v2"
|
||||
"net"
|
||||
"net/netip"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -20,6 +21,7 @@ import (
|
||||
"github.com/gaissmai/bart"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"go4.org/netipx"
|
||||
|
||||
"tailscale.com/control/controlclient"
|
||||
"tailscale.com/envknob"
|
||||
@@ -1857,6 +1859,92 @@ func TestPeerConfigUpdatedOnPeerRouteDelta(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestExitNodeLANRoutesOnLinkChange tests that the LAN routes in the router
|
||||
// config follow the device from one network to another while an exit node is
|
||||
// in use, whether or not LAN access is allowed.
|
||||
func TestExitNodeLANRoutesOnLinkChange(t *testing.T) {
|
||||
oldLAN := netip.MustParsePrefix("192.168.1.0/24")
|
||||
newLAN := netip.MustParsePrefix("192.168.2.0/24")
|
||||
|
||||
// setNetwork makes pfx the address of the device's only network interface,
|
||||
// and returns the resulting interface state.
|
||||
setNetwork := func(pfx netip.Prefix) *netmon.State {
|
||||
iface := netmon.Interface{
|
||||
Interface: &net.Interface{Index: 2, MTU: 1500, Name: "eth0", Flags: net.FlagUp | net.FlagRunning},
|
||||
AltAddrs: []net.Addr{netipx.PrefixIPNet(pfx)},
|
||||
}
|
||||
netmon.RegisterInterfaceGetter(func() ([]netmon.Interface, error) {
|
||||
return []netmon.Interface{iface}, nil
|
||||
})
|
||||
return &netmon.State{
|
||||
Interface: map[string]netmon.Interface{"eth0": iface},
|
||||
InterfaceIPs: map[string][]netip.Prefix{"eth0": {pfx}},
|
||||
DefaultRouteInterface: "eth0",
|
||||
HaveV4: true,
|
||||
}
|
||||
}
|
||||
t.Cleanup(func() { netmon.RegisterInterfaceGetter(nil) })
|
||||
|
||||
exitNode := makeExitNode(2, withName("exit-node"), withAddresses(netip.MustParsePrefix("100.64.1.2/32")))
|
||||
nm := buildNetmapWithPeers(
|
||||
makePeer(1, withName("node-1"), withAddresses(netip.MustParsePrefix("100.64.1.1/32"))),
|
||||
exitNode,
|
||||
)
|
||||
|
||||
for _, allowLANAccess := range []bool{false, true} {
|
||||
t.Run(fmt.Sprintf("AllowLANAccess=%v", allowLANAccess), func(t *testing.T) {
|
||||
// lanRoutes returns the routes that carry LAN traffic:
|
||||
// around the tunnel if LAN access is allowed, and into it otherwise.
|
||||
lanRoutes := func(cfg *router.Config) []netip.Prefix {
|
||||
if allowLANAccess {
|
||||
return cfg.LocalRoutes
|
||||
}
|
||||
return cfg.Routes
|
||||
}
|
||||
|
||||
oldState := setNetwork(netip.PrefixFrom(oldLAN.Addr().Next(), oldLAN.Bits()))
|
||||
|
||||
lb, engine, cc := newLocalBackendWithMockEngineAndControl(t, false)
|
||||
mustDo(t)(lb.Start(ipn.Options{}))
|
||||
mustDo2(t)(lb.EditPrefs(&ipn.MaskedPrefs{
|
||||
Prefs: ipn.Prefs{
|
||||
WantRunning: true,
|
||||
ExitNodeID: exitNode.StableID(),
|
||||
ExitNodeAllowLANAccess: allowLANAccess,
|
||||
},
|
||||
WantRunningSet: true,
|
||||
ExitNodeIDSet: true,
|
||||
ExitNodeAllowLANAccessSet: true,
|
||||
}))
|
||||
cc().authenticated(nm)
|
||||
waitForGoroutinesToStop(lb)
|
||||
|
||||
if routes := lanRoutes(engine.RouterConfig()); !slices.Contains(routes, oldLAN) {
|
||||
t.Fatalf("routes before network change = %v; want %v included", routes, oldLAN)
|
||||
}
|
||||
|
||||
newState := setNetwork(netip.PrefixFrom(newLAN.Addr().Next(), newLAN.Bits()))
|
||||
delta, err := netmon.NewChangeDelta(oldState, newState, 0, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !delta.RebindLikelyRequired {
|
||||
t.Fatal("test setup bug: network change is not a major one")
|
||||
}
|
||||
lb.linkChange(delta)
|
||||
waitForGoroutinesToStop(lb)
|
||||
|
||||
routes := lanRoutes(engine.RouterConfig())
|
||||
if !slices.Contains(routes, newLAN) {
|
||||
t.Errorf("routes after network change = %v; want %v included", routes, newLAN)
|
||||
}
|
||||
if slices.Contains(routes, oldLAN) {
|
||||
t.Errorf("routes after network change = %v; want %v removed", routes, oldLAN)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestSendPreservesAuthURL tests that wgengine updates arriving in the middle of
|
||||
// processing an auth URL doesn't result in the auth URL being cleared.
|
||||
func TestSendPreservesAuthURL(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user