tailscale/wgengine
Mike O'Driscoll 26ef46bf81
util/linuxfw,wgengine/router: add connmark rules for rp_filter workaround (#18860)
When a Linux system acts as an exit node or subnet router with strict
reverse path filtering (rp_filter=1), reply packets may
be dropped because they fail the RPF check. Reply packets arrive on the
WAN interface but the routing table indicates they should have arrived
on the Tailscale interface, causing the kernel to drop them.

This adds firewall rules in the mangle table to save outbound packet
marks to conntrack and restore them on reply packets before the routing
decision. When reply packets have their marks restored, the kernel uses
the correct routing table (based on the mark) and the packets pass the
rp_filter check.

Implementation adds two rules per address family (IPv4/IPv6):

- mangle/OUTPUT: Save packet marks to conntrack for NEW connections
with non-zero marks in the Tailscale fwmark range (0xff0000)

- mangle/PREROUTING: Restore marks from conntrack to packets for
ESTABLISHED,RELATED connections before routing decision and rp_filter
check

The workaround is automatically enabled when UseConnmarkForRPFilter is
set in the router configuration, which happens when subnet routes are
advertised on Linux systems.

Both iptables and nftables implementations are provided, with automatic
backend detection.

Fixes #3310
Fixes #14409
Fixes #12022
Fixes #15815
Fixes #9612

Signed-off-by: Mike O'Driscoll <mikeo@tailscale.com>
2026-03-04 14:09:11 -05:00
..
bench all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
filter ipnext,ipnlocal,wgengine/filter: add extension hooks for custom filter matchers 2026-02-24 10:54:56 -05:00
magicsock wgengine/magicsoc,net/tstun: put disco key advertisement behind a nob (#18857) 2026-03-03 09:04:37 -05:00
netlog all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
netstack wgengine/netstack: deliver self-addressed packets via loopback 2026-02-27 14:30:41 -08:00
router util/linuxfw,wgengine/router: add connmark rules for rp_filter workaround (#18860) 2026-03-04 14:09:11 -05:00
wgcfg all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
wgint all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
wglog all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
winnet all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
mem_ios.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
pendopen_omit.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
pendopen.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
userspace_ext_test.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
userspace_test.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
userspace.go tstun,wgengine: add new datapath hooks for intercepting Connectors 2025 2026-02-09 17:06:27 -05:00
watchdog_omit.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
watchdog_test.go util/clientmetric, wgengine/watchdog: report watchdog errors in user/client metrics (#18591) 2026-02-13 13:30:48 -05:00
watchdog.go util/clientmetric, wgengine/watchdog: report watchdog errors in user/client metrics (#18591) 2026-02-13 13:30:48 -05:00
wgengine.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00