mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-18 19:15:03 +03:00
feat(amneziawg): make the Xray TPROXY bridge a per-inbound opt-in
Addresses Finding 10 from the automated PR review: an always-on TPROXY bridge makes every AmneziaWG tunnel hard-depend on Xray being up (all traffic, including DNS, drops whenever Xray restarts), and forces a full awg-quick down+up bounce on any client add/remove/re-IP, permanently losing the syncconf fast path. Adds ServerSettings.RouteThroughXray (off by default): - defaultPostUpDown only emits the TPROXY/policy-route rules when it's on; a plain AmneziaWG tunnel now has zero Xray dependency out of the box. - structuralFingerprint covers it (toggling it changes whether PostUp/ PostDown contain any TPROXY rules at all -- structural, not a per-peer host-rule). hostRulesFingerprint's IPv4 tracking is now itself conditional on RouteThroughXray (and IPv6 tracking on IPv6Enabled), so an instance that never uses either keeps the syncconf fast path for a plain peer re-IP. - injectAmneziawgEgress only creates a bridge for inbounds that opted in; checkAmneziawgEgressConflict (the Finding-7 fix) now parses each candidate through InstanceFromInbound so a non-routed inbound's port is correctly never treated as reserved. - New inbound-level Switch in the AmneziaWG form; the actual outbound decision is still made entirely through the panel's stock Routing page, same as before -- only whether the bridge exists at all is now a choice. Translation keys added to all 13 locales in the same commit this time, not backfilled later (see Finding 9's lesson). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -645,18 +645,21 @@ const amneziawgEgressDokodemoSettings = `{"allowedNetwork":"tcp,udp","followRedi
|
||||
// socket.
|
||||
const amneziawgEgressStreamSettings = `{"sockopt":{"tproxy":"tproxy"}}`
|
||||
|
||||
// injectAmneziawgEgress gives every enabled AmneziaWG inbound with at least
|
||||
// one qualifying peer its own loopback dokodemo-door bridge — tagged with
|
||||
// that inbound's own real tag, so it's already selectable in the panel's
|
||||
// stock Routing page's inbound-tag picker, exactly the way an mtproto
|
||||
// inbound's own bridge already is (see injectMtprotoEgress): the picker's
|
||||
// tag list comes from InboundService.GetInboundTags(), a plain,
|
||||
// injectAmneziawgEgress gives every enabled, RouteThroughXray-opted-in
|
||||
// AmneziaWG inbound with at least one qualifying peer its own loopback
|
||||
// dokodemo-door bridge — tagged with that inbound's own real tag, so it's
|
||||
// already selectable in the panel's stock Routing page's inbound-tag
|
||||
// picker, exactly the way an mtproto inbound's own bridge already is (see
|
||||
// injectMtprotoEgress): the picker's tag list comes from
|
||||
// InboundService.GetInboundTags(), a plain,
|
||||
// protocol-blind SELECT over every inbound row's tag, so reusing a real
|
||||
// inbound's own tag needs no dedicated UI plumbing at all.
|
||||
//
|
||||
// Every peer's traffic always lands on the bridge — internal/amneziawg's
|
||||
// defaultPostUpDown TPROXYs it there unconditionally, there is no per-peer
|
||||
// or per-inbound opt-in flag — but this function never generates a routing
|
||||
// RouteThroughXray is a per-inbound opt-in, off by default: when it's off,
|
||||
// no bridge is created at all and the tunnel has no Xray dependency
|
||||
// whatsoever. When it's on, every peer's traffic lands on the bridge —
|
||||
// internal/amneziawg's defaultPostUpDown TPROXYs it there, there is no
|
||||
// further per-peer opt-in — but this function never generates a routing
|
||||
// rule of its own. Whether that traffic goes anywhere beyond Xray's default
|
||||
// routing is entirely up to whatever rules the admin adds through that same
|
||||
// stock Routing page (inboundTag + an optional sourceIP to target one
|
||||
@@ -680,7 +683,7 @@ func injectAmneziawgEgress(cfg *xray.Config, inbounds []*model.Inbound) {
|
||||
continue
|
||||
}
|
||||
inst, ok := amneziawg.InstanceFromInbound(inbound)
|
||||
if !ok {
|
||||
if !ok || !inst.RouteThroughXray {
|
||||
continue
|
||||
}
|
||||
hasQualifyingPeer := false
|
||||
|
||||
Reference in New Issue
Block a user