mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-16 10:05:00 +03:00
fix(finalmask): keep a single udphop mask last in every client finalmask
xray-core reverses finalmask.udp and refuses, at dial time, a mask that dials its own socket (udphop) anywhere but the socket end: "incorrect index". xray run -test still says Configuration OK, so the failure only shows as a client that never connects. UDPHopClientMaskFix turned a global subJsonFinalMask hop and a host hop into udphop masks; the JSON subscription then appended both, leaving two hoppers with the first one misplaced, and a host mask merged after a global hop pushed it off the end too. A hand-ordered template outbound or an imported fm= could carry the same order. maskcompat.NormalizeUDPHop keeps the last-listed udphop alone at the end of udp, and runs wherever a client finalmask is produced: each JSON subscription endpoint, share-link fm=, the Go and frontend link importers and the template outbound heal in GetXrayConfig. The JSON subscription resolves competing hop ranges most specific first: a host hop wins over the inbound's own, which wins over the global default.
This commit is contained in:
@@ -770,6 +770,7 @@ func applyFinalMask(stream map[string]any, p url.Values) {
|
||||
sanitizeFinalMaskQuicParams(parsed)
|
||||
maskcompat.UpgradeLegacyXdns(parsed)
|
||||
maskcompat.UpgradeLegacyUDPHop(parsed)
|
||||
maskcompat.NormalizeUDPHop(parsed)
|
||||
stream["finalmask"] = parsed
|
||||
}
|
||||
}
|
||||
|
||||
@@ -596,3 +596,19 @@ func TestParseLink_UpgradesLegacyUDPHopFinalMask(t *testing.T) {
|
||||
t.Fatalf("imported finalmask\n got: %s\nwant: %s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// A link from a panel that listed udphop before another UDP mask would leave an outbound
|
||||
// whose every dial the core refuses ("incorrect index"); the import puts the hop last.
|
||||
func TestParseLink_PutsUDPHopMaskLast(t *testing.T) {
|
||||
fm := url.QueryEscape(`{"udp":[{"type":"udphop","settings":{"mode":"intervalRemote","remotePorts":"20000-30000"}},{"type":"salamander","settings":{"password":"s3cr3t"}}]}`)
|
||||
res, err := ParseLink("hysteria2://auth@hy.example.com:443?sni=hy.example.com&fm=" + fm + "#hy")
|
||||
if err != nil {
|
||||
t.Fatalf("parse hysteria2 with fm: %v", err)
|
||||
}
|
||||
stream, _ := res.Outbound["streamSettings"].(map[string]any)
|
||||
got, _ := json.Marshal(stream["finalmask"])
|
||||
want := `{"udp":[{"settings":{"password":"s3cr3t"},"type":"salamander"},{"settings":{"mode":"intervalRemote","remotePorts":"20000-30000"},"type":"udphop"}]}`
|
||||
if string(got) != want {
|
||||
t.Fatalf("imported finalmask\n got: %s\nwant: %s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user