Repository navigation
Test that detach reaches the endpoint as a nil dispatcher - #89
Open
arpitjain099 wants to merge 67 commits into
Open
arpitjain099 wants to merge 67 commits into
arpitjain099 wants to merge 67 commits into
Conversation
nekohasekai
force-pushed
the
dev
branch
8 times, most recently
from
September 10, 2026 07:16
8e1fb85 to
6655bc2
Compare
nekohasekai
force-pushed
the
dev
branch
7 times, most recently
from
September 17, 2026 14:28
3c37619 to
fbc0c3d
Compare
nekohasekai
force-pushed
the
dev
branch
5 times, most recently
from
September 24, 2026 07:34
44433fb to
3077c70
Compare
nekohasekai
force-pushed
the
dev
branch
3 times, most recently
from
September 29, 2026 15:23
f9cf98a to
8379762
Compare
nekohasekai
force-pushed
the
dev
branch
2 times, most recently
from
October 9, 2026 03:10
7539c98 to
5c2edb1
Compare
nekohasekai
force-pushed
the
dev
branch
4 times, most recently
from
October 20, 2026 15:06
47a4c9b to
a222cfd
Compare
Marks were read and written only within the mask of the auto-redirect marks, so a hijacked packet kept the bits of other programs, and their policy routing rules with a higher priority took it away from the tun. A foreign mark that equals one of the marks under the mask was also taken as a verdict: connections marked by Mullvad were reset. With nftables, the input and reset marks are written as whole values and matched exactly again, and only the output mark, which hands the routing decision back, keeps the other bits. The DNS hijack rules now set the input mark as well. The iptables backend still reads and writes every mark within the mask. The backend is now selected in the constructor, as the routing rule of the input mark is installed before auto-redirect starts.
Restoring the input mark from conntrack was limited to the original direction, so that replies of hijacked flows which other routing rules carried away are not sent into the tun. Replies of flows originated from the tun were no longer routed back into it as a result. These flows now have their own conntrack mark, the whole mark mask, which has no meaning as a packet mark.
The headroom check of packets written back to the tun was lost in the go stack rewrite, so buffers without enough front headroom for the IP and UDP headers panicked in ExtendHeader. They are copied again.
Fragments were reassembled before the forward dispatcher saw them, so a fragmented IPv6 datagram of a forwarded flow was answered with Packet Too Big again after the client had fragmented it to the path MTU. Fragments now pass the return path, local endpoints and the forward dispatcher before local reassembly: the first fragment carries the 5-tuple, later fragments follow its decision and are held briefly while the flow is judged, and fragment entries are removed once all ranges are seen. ICMP errors quoting a first fragment are matched, and no ICMP error is built for non-first IPv4 fragments.
Read frames, iovecs, message headers, GSO segments, UDP session lookups, the single frame scratch and the transmit segments of a failed write kept pointers into read slots and arena slabs after use, which outlive the mapping once it is released. They are cleared once the batch is handled.
The engine slept in its event loop while backing off from recoverable read errors, stalling every timer, socket and control message for up to a second. The device read event is now disabled and restored by a wheel timer instead.
Writes failing with ENOMEM aborted connections like fatal errors, while the same allocation failure reported as ENOBUFS dropped the frame. Both drop the frame now.
The marks now default to bits 26 to 28 on Android as well, which netd leaves free, so the separate Android defaults are gone; the TPROXY mark is the input and output marks together within that window. With strict_route on a single stack, prerouting_udp_icmp no longer marks UDP and ICMP of the disabled family for output, except from excluded interfaces. Stale redirect route rules carrying a mark are deleted by that mark.
The iptables backend wrote and matched the input and reset packet marks under the mark mask, and restored the input mark from conntrack with --restore-mark, which keeps the other bits. On Linux, outside of netd, these marks are now whole values as with nftables, so policy routing rules of other programs with a higher priority no longer take hijacked packets away from the tun. The transparent listener given by VpnService also carries the protectedFromVpn bit, so netd no longer routes its replies back into the tun, and output-tproxy leaves replies alone.
Same as on main for nftables. With iptables, link-local, multicast and broadcast destinations are excluded as well, by address and, outside of Android, by address type. The unreachable chains of the disabled family now let through traffic carrying the output mark or, on Android, the protectedFromVpn bit, established and related flows, and ICMPv6 neighbor discovery and multicast listener messages.
Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
arpitjain099
force-pushed
the
fix/detach-forwards-nil
branch
from
November 27, 2026 09:17
58afdae to
3768c12
Compare
nekohasekai
force-pushed
the
dev
branch
3 times, most recently
from
December 6, 2026 01:24
8b7d7d5 to
95b95fd
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.
The fix this started from landed upstream in be4ce8d, where
Attachnow forwards a literal nil, so the code change is gone and only the tests are left. #85 is still open and the reporter asked for these to be kept, since the detach-must-arrive-as-nil contract is easy to break again in a laterAttachrewrite, and #90 touches that same function.Two tests with a recording endpoint:
Attach(nil)has to arrive as nil, and a real dispatcher still has to arrive wrapped. Taking the nil branch back out fails the first and leaves the second green.go test -tags with_gvisor .and gofmt are clean.