Partition fwmark field for routing_mark coexistence with auto_redirect#71
Open
loncharles wants to merge 1 commit into
Open
Partition fwmark field for routing_mark coexistence with auto_redirect#71loncharles wants to merge 1 commit into
loncharles wants to merge 1 commit into
Conversation
All nftables mark operations changed from exact 32-bit match/overwrite to masked operations using the low 16 bits (0x0000FFFF) for auto_redirect loop prevention, leaving the upper 16 bits available for routing_mark. - Add masked comparison helpers for meta mark and ct mark - Add masked set helpers that preserve bits outside the mask - Apply masked operations to all mark sites in redirect rules, pre-match chains, loopback reroute, and prerouting UDP/ICMP - Add fwmark mask to ip rules for consistent masked matching - Preserve routing_mark bits in NFQUEUE verdict marks - Export AutoRedirectMarkMask constant for cross-package use
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
for auto_redirect loop prevention, upper 16 bits available for
routing_mark (WAN selection, policy routing, etc.)
to masked operations via helper functions
AutoRedirectMarkMaskconstant for use by sing-boxMotivation
routing_markandauto_redirectare currently mutually exclusive insing-box.
routing_markworks correctly withoutauto_redirect, andauto_redirectworks correctly withoutrouting_mark— the conflictis purely an implementation limitation. The mark field operations use
full 32-bit equality matching and overwrites, so any routing_mark bits
would be clobbered by auto_redirect's loop prevention marks, and vice
versa.
This patch partitions the mark field so both can coexist. The approach
is the standard technique for fwmark field sharing in Linux netfilter.
Changes
nftables rules (
redirect_nftables_rules.go,redirect_nftables.go):meta mark == value→(meta mark & 0xFFFF) == valuemeta mark set value→meta mark set (meta mark & 0xFFFF0000) | valuemaskedMetaMarkCmp,maskedCtMarkCmp,maskedMetaMarkSet,maskedMetaMarkSetWithCtCopyip rules (
tun_linux.go):FRA_FWMASK = 0xFFFFNFQUEUE (
nfqueue_linux.go):Constant (
redirect.go):AutoRedirectMarkMask = 0x0000FFFFexported for cross-package useTest plan
/0xffffmask confirmed