configure DNS even when router.Set fails (#20488)

* wgengine: configure DNS even when router.Set fails

Reconfig configured the router first and returned on any router.Set error,
before the DNS block ran. On a host where router config fails on every
reconfig -- e.g. a tun MTU below 1280 that breaks IPv6, or a kernel missing
netfilter features -- the OS resolver was never told about MagicDNS or the
tailnet search domain, so tailnet names failed to resolve with no DNS error
in the logs.

Record the router error and continue instead of returning on it, still
attempt dns.Set, and join the router, DNS, and VPN-reconfigure errors into
the return value. DNS stays after router config (still needed: some DNS
managers refuse to apply settings before the device has an address); only
the error coupling is broken. Fixes a regression from 84430cdfa (v1.8.0).

Updates #20447

Signed-off-by: Brendan Creane <bcreane@gmail.com>

* wgengine/router/osrouter: gate IPv6 on per-interface support, not just global

getV6Available reported IPv6 usable whenever the netfilter runner reported
global IPv6 support, missing the case where the kernel has IPv6 but has not
enabled it on tailscale0 specifically -- e.g. when the tun MTU is below the
1280-byte IPv6 minimum, so /proc/sys/net/ipv6/conf/tailscale0 never exists
and the v6 address and route adds fail, aborting the whole Set. See #20447.

AND a per-interface check into getV6Available, evaluated per call so a later
Set picks up v6 if the interface gains it. All v6-gated operations funnel
through getV6Available, so Set now skips v6 gracefully instead of erroring.
Also remove the dead r.v6Available field that masked this with its global
name.

Updates #20447

Signed-off-by: Brendan Creane <bcreane@gmail.com>

---------

Signed-off-by: Brendan Creane <bcreane@gmail.com>
This commit is contained in:
Brendan Creane
2026-07-16 14:53:30 -07:00
committed by GitHub
parent b2de420e3d
commit cfd101f9d7
4 changed files with 234 additions and 20 deletions
+67
View File
@@ -4,6 +4,7 @@
package wgengine
import (
"errors"
"fmt"
"math/rand"
"net/netip"
@@ -116,6 +117,72 @@ func TestUserspaceEngineReconfig(t *testing.T) {
}
}
// failingRouter is a router.Router whose Set always fails, used to verify that
// DNS configuration is still attempted when router configuration fails.
type failingRouter struct {
err error
}
func (failingRouter) Up() error { return nil }
func (r failingRouter) Set(*router.Config) error { return r.err }
func (failingRouter) Close() error { return nil }
// recordingOSConfigurator is a dns.OSConfigurator that records whether SetDNS
// was called.
type recordingOSConfigurator struct {
setDNSCalled bool
}
func (c *recordingOSConfigurator) SetDNS(dns.OSConfig) error { c.setDNSCalled = true; return nil }
func (c *recordingOSConfigurator) SupportsSplitDNS() bool { return false }
func (c *recordingOSConfigurator) Close() error { return nil }
func (c *recordingOSConfigurator) GetBaseConfig() (dns.OSConfig, error) {
return dns.OSConfig{}, dns.ErrGetBaseConfigNotSupported
}
// TestUserspaceEngineReconfigDNSAfterRouterError verifies that a router.Set
// failure does not prevent DNS from being configured. Historically Reconfig
// returned on router error before dns.Set ran, so MagicDNS was never
// configured on hosts where router config failed on every reconfig. See
// tailscale/tailscale#20447.
func TestUserspaceEngineReconfigDNSAfterRouterError(t *testing.T) {
bus := eventbustest.NewBus(t)
ht := health.NewTracker(bus)
reg := new(usermetric.Registry)
e, err := NewFakeUserspaceEngine(t.Logf, 0, ht, reg, bus)
if err != nil {
t.Fatal(err)
}
t.Cleanup(e.Close)
ue := e.(*userspaceEngine)
routerErr := fmt.Errorf("router boom")
ue.router = failingRouter{err: routerErr}
osCfg := &recordingOSConfigurator{}
ue.dns = dns.NewManager(t.Logf, osCfg, ht, ue.dialer, nil, nil, runtime.GOOS, bus)
nm := &netmap.NetworkMap{
Peers: nodeViews([]*tailcfg.Node{{ID: 1, Key: nkFromHex("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")}}),
}
cfg := &wgcfg.Config{
Addresses: []netip.Prefix{netip.PrefixFrom(netaddr.IPv4(100, 100, 99, 1), 32)},
}
e.SetSelfNode(nm.SelfNode)
err = e.Reconfig(cfg, &router.Config{}, &dns.Config{})
if !osCfg.setDNSCalled {
t.Error("SetDNS was not called after router.Set failed; DNS config must be independent of router success")
}
if err == nil {
t.Error("Reconfig returned nil; want the router error to be surfaced")
} else if !errors.Is(err, routerErr) {
t.Errorf("Reconfig error = %v; want it to wrap the router error %v", err, routerErr)
}
}
func TestUserspaceEnginePortReconfig(t *testing.T) {
flakytest.Mark(t, "https://github.com/tailscale/tailscale/issues/2855")
const defaultPort = 49983