mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #4437] [Bug] v3.0.2: freedom-outbound sendThrough keeps re-adding stale ip rules, breaking custom policy routing #3026
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#3026
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @krugloff89 on GitHub (May 16, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4437
Environment
Setup context
On a host running 3x-ui, I have multiple WireGuard interfaces:
wg-chain-X-0with172.16.X.1/30(inbound side of a multi-hop chain)wg-cX-ext(separate outbound interface to an external WG provider)I manage policy routing myself with explicit priority:
In 3x-ui I create a
freedomoutbound withsendThrough: "172.16.X.1"so xray binds outbound sockets to that source IP, expecting my ownprio 100rule to direct traffic totable 200X→wg-cX-ext.Steps to reproduce
freedomoutbound inxrayTemplateConfigwithsendThrough: "172.16.X.1".restartXrayOnClientDisable=true)ip rule list.Actual behavior
3x-ui injects (via netlink, not
ipCLI) a new policy-routing rule for every freedom-outbound:— with no explicit
pref(kernel default = 0), and into the native routing table numberX(the chain ID), with a corresponding stale route:Each retrigger stacks a new duplicate with a different random pref. After dozens of triggers the routing table looks like:
Because prio 0 < prio 100, the injected rule always wins. Traffic goes into
wg-chain-X-0, which has no0.0.0.0/0peer (it's an inbound-only interface), so packets are dropped.Expected behavior
Either of:
sendThroughshould only bind the socket, not modify host policy routing. Source-IP binding is a userspace concept; pushingip rule/ip routeinto kernel without the user's knowledge violates least surprise.pref≥ 32000 (kernel default formaintable), make it deterministic, and clean up old rules before adding new ones to prevent stacking.Why this is critical
For users who run 3x-ui as part of a larger network setup (multi-hop WG, transit gateways, dual-VPN routing) and have their own policy routing on the host:
prio 0rule silently wins over every user rule withprio > 0Reproduction logs
Workaround
I had to deploy a userspace daemon on the host that listens on
ip monitor rule(kernel netlink stream) and deletes the stale rules in realtime (~50ms latency). Without it, freedom-outbounds break on every Xray restart and the routing table fills up with duplicate rules.This shouldn't be necessary —
sendThroughshould not touch host policy routing.Suspected source in code
Likely in
web/service/xray.go(or whereverfreedom.settings.sendThroughis processed during config-apply): a call tonetlink.RuleAdd()(or equivalent viavishvananda/netlink/x/sys/unix) is made without specifyingPriorityand without idempotency check or cleanup of previous additions.Severity
High for users with multi-hop / transit / dual-VPN setups. Silent loss of VPN egress on every Xray restart, plus unbounded growth of stale entries in kernel routing tables.
Logs: 2026-05-16 14:13:03 watcher start, kernel=6.8.0-111-generic
2026-05-16 14:13:17 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 14:13:17 deleted: pref=5 from=172.16.123.1 lookup=123
2026-05-16 14:13:17 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 14:20:36 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 14:20:36 deleted: pref=0 from=172.16.123.1 lookup=123
2026-05-16 14:20:36 deleted stale default route: dev wg-chain-123-0 table 123
2026-05-16 14:20:36 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 14:21:00 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 14:21:00 deleted: pref=0 from=172.16.123.1 lookup=123
2026-05-16 14:21:00 deleted stale default route: dev wg-chain-123-0 table 123
2026-05-16 14:21:00 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 14:39:47 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 14:39:47 deleted: pref=0 from=172.16.123.1 lookup=123
2026-05-16 14:39:47 deleted stale default route: dev wg-chain-123-0 table 123
2026-05-16 14:39:47 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 14:39:50 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 14:39:50 deleted: pref=0 from=172.16.123.1 lookup=123
2026-05-16 14:39:50 deleted stale default route: dev wg-chain-123-0 table 123
2026-05-16 14:39:50 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 14:40:25 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 14:40:25 deleted: pref=0 from=172.16.123.1 lookup=123
2026-05-16 14:40:25 deleted stale default route: dev wg-chain-123-0 table 123
2026-05-16 14:40:25 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 14:40:27 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 14:40:27 deleted: pref=0 from=172.16.123.1 lookup=123
2026-05-16 14:40:27 deleted stale default route: dev wg-chain-123-0 table 123
2026-05-16 14:40:28 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 14:59:25 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 14:59:25 deleted: pref=0 from=172.16.123.1 lookup=123
2026-05-16 14:59:25 deleted stale default route: dev wg-chain-123-0 table 123
2026-05-16 14:59:25 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 14:59:27 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 14:59:27 deleted: pref=0 from=172.16.123.1 lookup=123
2026-05-16 14:59:27 deleted stale default route: dev wg-chain-123-0 table 123
2026-05-16 14:59:27 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 15:04:41 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 15:04:41 deleted: pref=0 from=172.16.123.1 lookup=123
2026-05-16 15:04:41 deleted stale default route: dev wg-chain-123-0 table 123
2026-05-16 15:04:41 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 15:04:55 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 15:04:55 deleted: pref=0 from=172.16.123.1 lookup=123
2026-05-16 15:04:55 deleted stale default route: dev wg-chain-123-0 table 123
2026-05-16 15:04:55 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 15:05:20 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing
2026-05-16 15:05:20 deleted: pref=0 from=172.16.123.1 lookup=123
2026-05-16 15:05:20 deleted stale default route: dev wg-chain-123-0 table 123
2026-05-16 15:05:20 STALE-DETECTED: from 172.16.123.1 table=123 pref=0 — removing