linuxfw.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) Tailscale Inc & contributors
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. package tsconst
  4. // Linux firewall constants used by Tailscale.
  5. // The following bits are added to packet marks for Tailscale use.
  6. //
  7. // We tried to pick bits sufficiently out of the way that it's
  8. // unlikely to collide with existing uses. We have 4 bytes of mark
  9. // bits to play with. We leave the lower byte alone on the assumption
  10. // that sysadmins would use those. Kubernetes uses a few bits in the
  11. // second byte, so we steer clear of that too.
  12. //
  13. // Empirically, most of the documentation on packet marks on the
  14. // internet gives the impression that the marks are 16 bits
  15. // wide. Based on this, we theorize that the upper two bytes are
  16. // relatively unused in the wild, and so we consume bits 16:23 (the
  17. // third byte).
  18. //
  19. // The constants are in the iptables/iproute2 string format for
  20. // matching and setting the bits, so they can be directly embedded in
  21. // commands.
  22. const (
  23. // The mask for reading/writing the 'firewall mask' bits on a packet.
  24. // See the comment on the const block on why we only use the third byte.
  25. //
  26. // We claim bits 16:23 entirely. For now we only use the lower four
  27. // bits, leaving the higher 4 bits for future use.
  28. LinuxFwmarkMask = "0xff0000"
  29. LinuxFwmarkMaskNum = 0xff0000
  30. // Packet is from Tailscale and to a subnet route destination, so
  31. // is allowed to be routed through this machine.
  32. LinuxSubnetRouteMark = "0x40000"
  33. LinuxSubnetRouteMarkNum = 0x40000
  34. // Packet was originated by tailscaled itself, and must not be
  35. // routed over the Tailscale network.
  36. LinuxBypassMark = "0x80000"
  37. LinuxBypassMarkNum = 0x80000
  38. )