Commit graph

21 commits

Author SHA1 Message Date
世界
99fb96a4c8
Fix missing UDP and ICMP bypass for auto redirect 2026-07-27 23:11:22 +08:00
世界
80ea96e5b4
Reject connections to redirect listener 2026-07-27 23:11:22 +08:00
Andrew Novikov
0e4cdbbc61
fix: use NF_REPEAT for NFQUEUE bypass/reset verdicts
NF_ACCEPT is a terminal verdict in nftables — when a packet returns
from NFQUEUE with NF_ACCEPT, it exits the current chain immediately
and continues to the next hook priority. Rules placed after the queue
statement in the same chain are never evaluated.

This meant that the `ct mark set meta mark` rule (which saves the
bypass decision to conntrack for subsequent packets) was dead code.
The first SYN packet received the correct mark from NFQUEUE, but
conntrack never stored it, so all subsequent packets of the same
connection were redirected to sing-box userspace.

Fix: use NF_REPEAT instead of NF_ACCEPT for bypass and reset verdicts.
NF_REPEAT re-enters the chain from the beginning with the mark already
set on skb->mark. Reorder the prematch chain rules so mark-checking
rules (ct mark set, reject) come before the queue statement:

  1. meta mark == outputMark → ct mark set meta mark, return
  2. meta mark == resetMark → reject with tcp reset
  3. ct mark == outputMark → return
  4. TCP SYN → queue to NFQUEUE

This is the standard pattern used by Suricata and other NFQUEUE-based
systems (NF_REPEAT + mark-based skip).

Tested on Orange Pi Zero 3 (arm64, kernel 6.12.58) with sing-box 1.13.3.
Bypass correctly saves ct mark, subsequent packets skip NFQUEUE entirely.
2026-03-17 10:58:45 +08:00
世界
1ab008e1e6
Improve error messages for Linux TUN and redirect operations 2026-03-15 14:43:38 +08:00
世界
caaf8469e0
Fix auto_redirect dropping SO_BINDTODEVICE traffic
REDIRECT in the OUTPUT chain rewrites the destination to 127.0.0.1,
then ip_route_me_harder() reroutes with the socket's bound interface
constraint (flowi4_oif). Since 127.0.0.1 is only reachable via lo,
the routing lookup fails and the packet is silently dropped.

Add a fallback routing table with `local 127.0.0.1` entries for each
non-loopback interface. When the local table lookup fails due to OIF
mismatch, the fallback table provides a matching RTN_LOCAL route.
The kernel then overrides dev_out to loopback (route.c:2857), so the
packet is delivered locally to the redirect server as intended.

This fixes NetworkManager connectivity checks and other tools that
use SO_BINDTODEVICE (e.g. curl --interface).
2026-03-11 21:15:11 +08:00
世界
5715a3919a
Fix nftablesCreateLocalAddressSets 2026-02-23 17:52:46 +08:00
世界
381bf9d40d
Skip tun interface traffic in prerouting UDP/ICMP chain 2026-01-28 18:27:44 +08:00
世界
a850c4f8a1
Add pre-matching support for auto redirect 2025-12-26 14:44:55 +08:00
世界
b5f3fecc25
ping: Fix linux route rules 2025-08-26 14:30:21 +08:00
世界
07e21b9170
Fix redirect panic 2025-08-01 16:46:29 +08:00
世界
5e343c4b66
Add loopback address support 2025-06-20 13:14:58 +08:00
世界
51ac6b34f1
redirect: Fix handling of local pings 2025-04-12 12:07:56 +08:00
世界
219c612399
redirect: Fix UDP rules 2025-04-09 11:01:57 +08:00
世界
a8ce3838bc
redirect: Only hijack DNS requests from local addresses 2025-04-02 15:47:17 +08:00
世界
d093b82064
auto-redirect: Fetch interfaces 2025-01-07 19:01:54 +08:00
世界
059f5b6aaf
auto-redirect: Let fw4 take precedence over prerouting 2024-10-13 13:26:08 +08:00
世界
1048b277ea
Skip generate nftables output chain if lo in excluded interface list 2024-06-17 13:29:56 +08:00
世界
85f5f2dd58
auto-redirect: Add route address set support for nftables 2024-06-16 15:37:27 +08:00
世界
85fe25a592
Improve nftables rules 2024-06-11 21:12:08 +08:00
世界
65383d3c39
Make DNS hijack optional 2024-06-07 15:49:16 +08:00
世界
67a5b408ef
Add auto-redirect 2024-06-07 15:48:43 +08:00