Mike O'Driscoll 1aad7a1386 wgengine/router/osrouter,util/linuxfw: add rp_filter source rules
With an exit node, table 52's default route makes strict reverse path
filtering drop replies to tailscaled's own sockets: the kernel checks a
reply's source with a reverse lookup, as uid 0 from the underlay
address, which finds the default route via the Tailscale interface
rather than the one the reply arrived on (#3310). The reverted
src_valid_mark=1 workaround fixed that for the whole host and broke
every other fwmark user (#19796).

Instead, while 0.0.0.0/0 or ::/0 is routed into table 52, install per
address family:

	pref base+55: not fwmark <bypass> lookup 52 suppress_prefixlength 0
	pref base+60: from A uidrange 0-0 lookup main

with a base+60 rule for each underlay address A. base+60 sends the
reverse lookup to the main table, and base+55 keeps table 52's tailnet
and LAN routes ahead of it, so tailnet peers still reach A through the
tunnel and ExitNodeAllowLANAccess=false still blocks the LAN. IPv6,
which has no kernel rp_filter, gets its rules whenever ::/0 is routed.
The IPv4 rules only exist while rp_filter is strict somewhere, re-read
every 10s while an exit node is in use since a sysctl write raises no
event.

The rules are added before the exit node's default route and removed
after it is gone, and in Close. They follow netmon's interface state,
for at most 128 addresses per family and never for our own Tailscale
addresses. They carry rule protocol 52; Up and tailscaled's startup
cleanup sweep away any a previous instance left. They don't use
netfilter, so they work in every netfilter mode.
TS_DEBUG_DISABLE_RPFILTER_SRC_RULES=true turns them off. The router
ignores deletions at their priorities instead of restoring the base
rules, since those deletions are its own.

linuxfw documents that the connmark rules only help reverse path checks
that are mark-aware.

Follow-ups cover replies from LAN peers to the magicsock port with LAN
access off, and rules other processes delete. Not covered, and pinned
by tests: remotes that a more specific table 52 route covers, such as
an accepted subnet route, and IPv4 netfilter reverse path checks
without a strict kernel rp_filter. Nor are hosts whose underlay default
route is not in main.

Behavior change: while an exit node is in use, sockets of root
processes bound to an underlay address, and packets the kernel itself
sends from one, leave by the physical interface rather than the exit
node; non-root processes are unaffected. That holds for IPv6 on every
host and for IPv4 where rp_filter is strict. Hosts that ran a release
with the reverted change keep src_valid_mark=1 until reboot or reset.

RELNOTE: Linux: exit nodes no longer set src_valid_mark=1; root sockets
bound to a physical interface's address now bypass the exit node.

Updates #3310
Updates #19796

Signed-off-by: Mike O'Driscoll <[email protected]>
2026-11-23 11:39:16 -05:00
2026-11-18 08:28:39 -08:00
2026-11-16 18:55:09 -08:00
2026-10-22 10:52:43 -04:00
2026-01-27 16:15:17 -08:00
2026-08-28 12:47:04 -07:00
2026-11-22 21:39:11 -08:00
2026-11-22 21:39:11 -08:00
2026-11-22 21:39:11 -08:00
2026-11-22 21:39:11 -08:00
…
2026-11-22 21:39:11 -08:00

Tailscale

https://tailscale.com

Private WireGuard® networks made easy

Overview

This repository contains the majority of Tailscale's open source code. Notably, it includes the tailscaled daemon and the tailscale CLI tool. The tailscaled daemon runs on Linux, Windows, macOS, and to varying degrees on FreeBSD and OpenBSD. The Tailscale iOS and Android apps use this repo's code, but this repo doesn't contain the mobile GUI code.

Other Tailscale repos of note:

For background on which parts of Tailscale are open source and why, see https://tailscale.com/opensource/.

Using

We serve packages for a variety of distros and platforms at https://pkgs.tailscale.com.

Other clients

The macOS, iOS, and Windows clients use the code in this repository but additionally include small GUI wrappers. The GUI wrappers on non-open source platforms are themselves not open source.

Building

We always require the latest Go release, currently Go 1.27. (While we build releases with our Go fork, its use is not required.)

go install tailscale.com/cmd/tailscale{,d}

If you're packaging Tailscale for distribution, use build_dist.sh instead, to burn commit IDs and version info into the binaries:

./build_dist.sh tailscale.com/cmd/tailscale
./build_dist.sh tailscale.com/cmd/tailscaled

If your distro has conventions that preclude the use of build_dist.sh, please do the equivalent of what it does in your distro's way, so that bug reports contain useful version information.

Bugs

Please file any issues about this code or the hosted service on the issue tracker.

Contributing

PRs welcome! But please file bugs. Commit messages should reference bugs.

We require Developer Certificate of Origin Signed-off-by lines in commits.

See commit-messages.md (or skim git log) for our commit message style.

About Us

Tailscale is primarily developed by the people at https://github.com/orgs/tailscale/people. For other contributors, see:

WireGuard is a registered trademark of Jason A. Donenfeld.

Languages
Go 96.5%
C 1.2%
TypeScript 0.8%
Shell 0.5%
Swift 0.3%
Other 0.4%