tailscale/wgengine
Brendan Creane bab3f5fce7
wgengine/router/osrouter: remove orphaned tailnet addrs on cleanup (#20304)
* net/tsaddr: unmap IPv4-mapped IPv6 addrs in IsTailscaleIP

IsTailscaleIP branched on ip.Is4() before checking the CGNAT range, so an
IPv4-mapped IPv6 address (e.g. ::ffff:100.64.0.1) took the IPv6 path and was
tested only against the ULA range, wrongly returning false for a Tailscale
CGNAT address. Unmap at the top so both forms are classified identically;
Unmap is cheap and IsTailscaleIPv4 stays IPv4-only for callers that need it.

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

* wgengine/router/osrouter: remove orphaned tailnet addrs on cleanup

The orphan-address sweep added in #20199 ran only inside Router.Set, so the
teardown path (tailscaled --cleanup, and the unconditional cleanup at daemon
start) never removed stale Tailscale addresses a previous instance left on a
persistent tailscale0 -- it only flushed iptables/nftables.

Wire address removal into cleanUp: with no desired config, every Tailscale-range
address on the interface is an orphan, so enumerate and delete them all (IPv4
and IPv6, best-effort) in removeOrphanedAddrsForCleanup.

tailscaleInterfaceAddrs now yields the interface's addresses as an
iter.Seq[netip.Prefix], and the filters compose lazily over it: tailscaleAddrs
(every Tailscale-range address; used by cleanup), deletableAddrs (isDeletableAddr:
Tailscale-range and deletable now, i.e. excluding v6 when v6 is unavailable; used
by the live Set sweep), and orphanedAddrs (drops the desired addresses). The Set
sweep ranges the composed iterator directly, so no throwaway slices are built.
delAddress is made idempotent: it attempts both the loopback-rule teardown and
the address delete and joins their errors, so a missing firewall rule can't leak
the address, and it no longer no-ops on v6 (cleanup relies on that to remove v6
orphans even when this process never brought IPv6 up).

The Set-time sweep is otherwise unchanged; re-running it on network changes
(netmon) for late orphans remains a follow-up (tailscale/corp#43882).

Updates #19974
Fixes tailscale/corp#44173

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

---------

Signed-off-by: Brendan Creane <bcreane@gmail.com>
2026-07-17 14:18:09 -07:00
..
bench wgengine/wgcfg,wgengine,ipn/ipnlocal: remove Peers from wgcfg.Config 2026-07-14 19:57:59 -04:00
filter all: fix more typos caused by unnecessary repetition 2026-07-06 10:36:17 +01:00
magicsock control/controlclient,net/tstun,wgengine/magicsock: fix handling of zero keys in TSMP (#20508) 2026-07-17 14:02:53 -04:00
netlog wgengine/netlog: stop using netmap.NetworkMap type, use LocalBackend 2026-06-17 15:11:57 -07:00
netstack wgengine/netstack: reject unserved ports on Service (VIP) IPs (#20363) 2026-07-10 14:06:15 -04:00
router wgengine/router/osrouter: remove orphaned tailnet addrs on cleanup (#20304) 2026-07-17 14:18:09 -07:00
wgcfg ipn/ipnlocal, wgengine/wgcfg/nmcfg: stop building peer lists on delta path 2026-07-15 11:21:36 -04:00
wgint all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
wglog wgengine/wglog: stop using netmap.NetworkMap here too 2026-06-23 09:06:37 -07:00
winnet all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
bird_hooks.go wgengine,cmd/tailscaled,feature/bird: move BIRD integration to ./feature 2026-07-14 10:48:09 -07:00
mem_ios.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
netlog_hooks.go wgengine,wgcfg,feature/netlog: move network flow logging behind a feature hook 2026-07-09 12:56:37 -07:00
pendopen_omit.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
pendopen.go wgengine,ipn/ipnlocal,tsnet,cmd/tailscaled: remove PeerForIP from the Engine interface 2026-07-13 15:15:16 -07:00
userspace_ext_test.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
userspace_test.go configure DNS even when router.Set fails (#20488) 2026-07-16 14:53:30 -07:00
userspace.go configure DNS even when router.Set fails (#20488) 2026-07-16 14:53:30 -07:00
wgengine.go net/tstun,wgengine,ipn/ipnlocal: make tstun's peerConfigTable use RouteManager table 2026-07-14 12:41:11 -07:00