Allow routing_mark when auto_redirect is enabled#4137
Open
loncharles wants to merge 1 commit into
Open
Conversation
Previously routing_mark was unconditionally rejected when auto_redirect was enabled. With the sing-tun mark field partitioned into low 16 bits (auto_redirect) and high 16 bits (routing_mark), the two can coexist. - Change AutoRedirectOutputMarkFunc to read-OR-write pattern, preserving existing mark bits on the socket - Change setMarkWrapper to OR routing_mark onto existing socket mark instead of rejecting when auto_redirect is active - Validate routing_mark against the full reserved mask (low 16 bits), not just the output mark value - Add AutoRedirectMarkMask to NetworkManager interface
057f540 to
6b07a22
Compare
7 tasks
abac453 to
bf9ea6d
Compare
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
routing_markwhenauto_redirectis active — the two can now coexist
routing_markdoes not use the low 16 bits reservedby auto_redirect for loop prevention
routing_mark bits are combined, not overwritten
Depends on: SagerNet/sing-tun#71
Motivation
routing_markis needed for policy routing (e.g., WAN selection) onoutbound connections.
auto_redirectis needed for transparentproxying of forwarded traffic. There is no fundamental conflict — the
previous rejection was a safety measure because the mark field
operations would clobber each other. With sing-tun's mark field now
partitioned (low 16 for auto_redirect, high 16 for routing_mark), the
safety concern is resolved.
Changes
common/dialer/default.go:setMarkWrapper: instead of rejecting, validates no bit overlapwith
AutoRedirectMarkMask, then reads current SO_MARK and ORs inthe routing_mark
route/network.go:AutoRedirectOutputMarkFunc: changed from full overwrite toread-OR-write pattern
AutoRedirectMarkMask(): new getter, returns the mask from sing-tunadapter/network.go:AutoRedirectMarkMask() uint32added toNetworkManagerinterfaceKnown limitation
Inbound listener sockets (
common/listener/) applyrouting_markvia
control.RoutingMark()directly, without the read-OR-writepattern. This is not a functional issue — inbound listeners are server
sockets that don't originate connections through the TUN redirect
chain — but it is a code path that does not participate in mark
coexistence. A future refactor could unify the mark-setting paths.
Test plan