tailscale/util
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
..
backoff all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
checkchange all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
cibuild all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
clientmetric all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
cloudenv all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
cloudinfo all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
cmpver all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
codegen all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
cstruct all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
ctxkey all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
deephash all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
dirwalk all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
dnsname net/dns,ipn/ipnlocal: add nodecap to resolve subdomains (#18258) 2026-01-30 13:32:34 -05:00
eventbus all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
execqueue all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
expvarx all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
goroutines all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
groupmember all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
hashx all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
httphdr all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
httpm all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
limiter all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
lineiter all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
lineread all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
linuxfw util/linuxfw,wgengine/router: add connmark rules for rp_filter workaround (#18860) 2026-03-04 14:09:11 -05:00
lru all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
mak all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
multierr all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
must all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
nocasemaps all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
osdiag all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
osshare all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
osuser all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
pidowner all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
pool all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
precompress all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
progresstracking all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
prompt all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
qrcodes all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
quarantine all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
race all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
racebuild all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
rands all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
reload all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
ringlog all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
safediff all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
set util/set: make Set.Slice return elements in sorted order for ordered types 2026-02-26 08:40:06 -08:00
singleflight all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
slicesx all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
stringsx all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
syspolicy all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
sysresources all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
testenv all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
topk all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
truncate all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
usermetric all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
vizerror all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
winutil all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
zstdframe all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00