mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-13 09:25:14 +03:00
fix(finalmask): hop client UDP through the udphop mask
xray-core 26.9.9 dropped finalmask.quicParams.udpHop for the client-only
"udphop" UDP mask {mode, interval, remoteIPs, remotePorts}. The panel kept
writing the old key, so hysteria/xhttp outbounds and JSON-subscription
clients silently stopped hopping ports.
An inbound keeps quicParams.udpHop: it is panel metadata advertised as the
link's mport, and a udphop mask on a listener fails with "udphop: client
only". The conversion (maskcompat.UpgradeLegacyUDPHop, intervalRemote mode)
runs only where a client config is produced:
- UDPHopClientMaskFix seeder over hosts, sub-JSON finalmask, cached
outbound-subscription outbounds and template outbounds (never inbounds);
- GetXrayConfig heals template outbounds at build time;
- the JSON subscription upgrades each generated client stream;
- the Go and frontend link importers upgrade a legacy fm= param.
The finalmask editor gains a side prop: the client side lifts the dead key
on mount and offers a udphop mask editor (also for xhttp's HTTP/3 dial);
the inbound side keeps the UDP Hop switch, labelled as advertised.
This commit is contained in:
@@ -113,3 +113,38 @@ func TestGetXrayConfig_UpgradesTemplateOutboundXdnsMask(t *testing.T) {
|
||||
}
|
||||
t.Fatal("outbound dns-tunnel not found in the generated config")
|
||||
}
|
||||
|
||||
// A hysteria outbound pasted from a pre-26.9.9 template still carries quicParams.udpHop,
|
||||
// which the core now ignores; the build heal hands it the udphop mask instead.
|
||||
func TestGetXrayConfig_UpgradesTemplateOutboundUDPHop(t *testing.T) {
|
||||
setupConflictDB(t)
|
||||
template := `{"outbounds":[{"protocol":"freedom","tag":"direct"},{"protocol":"hysteria","tag":"hy-out",
|
||||
"settings":{"version":2,"address":"hy.example.com","port":443},
|
||||
"streamSettings":{"network":"hysteria","security":"tls","hysteriaSettings":{"version":2,"auth":"a"},
|
||||
"finalmask":{"quicParams":{"udpHop":{"ports":"20000-30000","interval":"5-10"}}}}}]}`
|
||||
if err := (&SettingService{}).saveSetting("xrayTemplateConfig", template); err != nil {
|
||||
t.Fatalf("seed template: %v", err)
|
||||
}
|
||||
|
||||
cfg, err := (&XrayService{}).GetXrayConfig()
|
||||
if err != nil {
|
||||
t.Fatalf("GetXrayConfig: %v", err)
|
||||
}
|
||||
var outbounds []map[string]any
|
||||
if err := json.Unmarshal(cfg.OutboundConfigs, &outbounds); err != nil {
|
||||
t.Fatalf("decode emitted outbounds: %v", err)
|
||||
}
|
||||
for _, outbound := range outbounds {
|
||||
if outbound["tag"] != "hy-out" {
|
||||
continue
|
||||
}
|
||||
stream, _ := outbound["streamSettings"].(map[string]any)
|
||||
got, _ := json.Marshal(stream["finalmask"])
|
||||
const want = `{"udp":[{"settings":{"interval":"5-10","mode":"intervalRemote","remotePorts":"20000-30000"},"type":"udphop"}]}`
|
||||
if string(got) != want {
|
||||
t.Fatalf("emitted finalmask\n got: %s\nwant: %s", got, want)
|
||||
}
|
||||
return
|
||||
}
|
||||
t.Fatal("outbound hy-out not found in the generated config")
|
||||
}
|
||||
|
||||
@@ -180,10 +180,10 @@ func (s *XrayService) GetXrayConfig() (*xray.Config, error) {
|
||||
xrayConfig.API = ensureAPIServices(xrayConfig.API)
|
||||
xrayConfig.Policy = ensureStatsPolicy(xrayConfig.Policy)
|
||||
xrayConfig.RouterConfig = stripDisabledRules(xrayConfig.RouterConfig)
|
||||
// A pasted or restored template can still carry pre-#6258 XHTTP session keys or a
|
||||
// pre-26.10.10 xdns mask the core silently empties; heal them like the inbounds below.
|
||||
// A pasted or restored template can still carry pre-#6258 XHTTP session keys, a pre-26.10.10
|
||||
// xdns mask or a pre-26.9.9 quicParams.udpHop, all of which the core silently ignores.
|
||||
xrayConfig.OutboundConfigs = healOutboundStreams(xrayConfig.OutboundConfigs,
|
||||
liftXhttpSessionIDKeys, upgradeStreamLegacyXdns)
|
||||
liftXhttpSessionIDKeys, upgradeStreamLegacyXdns, upgradeStreamLegacyUDPHop)
|
||||
// Bridge amneziawg outbounds before anything else reads OutboundConfigs;
|
||||
// the core has no amneziawg proxy and would reject the raw entry.
|
||||
if err := transformAmneziaWGOutbounds(xrayConfig); err != nil {
|
||||
@@ -1748,3 +1748,7 @@ func healOutboundStreams(raw json_util.RawMessage, heals ...func(stream map[stri
|
||||
func upgradeStreamLegacyXdns(stream map[string]any) bool {
|
||||
return maskcompat.UpgradeLegacyXdns(stream["finalmask"])
|
||||
}
|
||||
|
||||
func upgradeStreamLegacyUDPHop(stream map[string]any) bool {
|
||||
return maskcompat.UpgradeLegacyUDPHop(stream["finalmask"])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user