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:
MHSanaei
2026-10-11 11:20:34 +02:00
parent 00aaef386f
commit ec0a57fc4f
22 changed files with 797 additions and 51 deletions
+75 -9
View File
@@ -1282,7 +1282,7 @@ func runSeeders(isUsersEmpty bool) error {
}
if empty && isUsersEmpty {
seeders := []string{"UserPasswordHash", "ClientsTable", "InboundClientsArrayFix", "InboundClientTgIdFix2", "InboundClientSubIdFix", "FreedomFinalRulesReverseFix", "FreedomFinalRulesPrivateEgressBlock", "UppercaseFreedomFinalRulesFix", "InboundRealityFinalmaskTcpStrip", "ApiTokensHash", "LegacyProxySettingsCleanup", "OutboundRemovedKeysFix", "FreedomDomainStrategyFix", "DNSOutboundLegacyKeysFix", "DNSOutboundQTypeZeroFix", "WireguardDomainStrategyFix", "XdnsFinalmaskNamesAddrsFix", "WireguardPeersToClients", "MtprotoSecretsToClients", "NodeInboundsAdopted", "ResetIpLimitNoFail2ban"}
seeders := []string{"UserPasswordHash", "ClientsTable", "InboundClientsArrayFix", "InboundClientTgIdFix2", "InboundClientSubIdFix", "FreedomFinalRulesReverseFix", "FreedomFinalRulesPrivateEgressBlock", "UppercaseFreedomFinalRulesFix", "InboundRealityFinalmaskTcpStrip", "ApiTokensHash", "LegacyProxySettingsCleanup", "OutboundRemovedKeysFix", "FreedomDomainStrategyFix", "DNSOutboundLegacyKeysFix", "DNSOutboundQTypeZeroFix", "WireguardDomainStrategyFix", "XdnsFinalmaskNamesAddrsFix", "UDPHopClientMaskFix", "WireguardPeersToClients", "MtprotoSecretsToClients", "NodeInboundsAdopted", "ResetIpLimitNoFail2ban"}
for _, name := range seeders {
if err := db.Create(&model.HistoryOfSeeders{SeederName: name}).Error; err != nil {
return err
@@ -1429,6 +1429,12 @@ func runSeeders(isUsersEmpty bool) error {
}
}
if !slices.Contains(seedersHistory, "UDPHopClientMaskFix") {
if err := migrateUDPHopClientMasks(); err != nil {
return err
}
}
if !slices.Contains(seedersHistory, "NodeInboundsAdopted") {
if err := seedNodeInboundsAdopted(); err != nil {
return err
@@ -1937,7 +1943,7 @@ func migrateXdnsFinalmaskShape() error {
return err
}
for _, inbound := range inbounds {
if updated, changed := upgradeLegacyXdnsJSON(inbound.StreamSettings, streamFinalmask, false); changed {
if updated, changed := upgradeFinalmasksJSON(inbound.StreamSettings, streamFinalmask, false, maskcompat.UpgradeLegacyXdns); changed {
if err := tx.Model(&model.Inbound{}).Where("id = ?", inbound.Id).
Update("stream_settings", updated).Error; err != nil {
return err
@@ -1949,7 +1955,7 @@ func migrateXdnsFinalmaskShape() error {
return err
}
for _, host := range hosts {
if updated, changed := upgradeLegacyXdnsJSON(host.FinalMask, wholeFinalmask, false); changed {
if updated, changed := upgradeFinalmasksJSON(host.FinalMask, wholeFinalmask, false, maskcompat.UpgradeLegacyXdns); changed {
if err := tx.Model(&model.Host{}).Where("id = ?", host.Id).
Update("final_mask", updated).Error; err != nil {
return err
@@ -1961,7 +1967,7 @@ func migrateXdnsFinalmaskShape() error {
return err
}
for _, sub := range subs {
if updated, changed := upgradeLegacyXdnsJSON(sub.LastFetchedOutbounds, outboundListFinalmasks, false); changed {
if updated, changed := upgradeFinalmasksJSON(sub.LastFetchedOutbounds, outboundListFinalmasks, false, maskcompat.UpgradeLegacyXdns); changed {
if err := tx.Model(&model.OutboundSubscription{}).Where("id = ?", sub.Id).
Update("last_fetched_outbounds", updated).Error; err != nil {
return err
@@ -1984,7 +1990,7 @@ func migrateXdnsFinalmaskShape() error {
if err != nil {
return err
}
if updated, changed := upgradeLegacyXdnsJSON(setting.Value, stored.locate, stored.indent); changed {
if updated, changed := upgradeFinalmasksJSON(setting.Value, stored.locate, stored.indent, maskcompat.UpgradeLegacyXdns); changed {
if err := tx.Model(&model.Setting{}).Where("key = ?", stored.key).
Update("value", updated).Error; err != nil {
return err
@@ -1995,9 +2001,64 @@ func migrateXdnsFinalmaskShape() error {
})
}
// upgradeLegacyXdnsJSON rewrites the finalmasks locate finds in one stored JSON document,
// leaving the document byte-for-byte alone when nothing in it is legacy.
func upgradeLegacyXdnsJSON(raw string, locate func(any) []any, indent bool) (string, bool) {
// migrateUDPHopClientMasks moves the quicParams.udpHop xray-core 26.9.9 ignores into a
// udphop mask in every client-side finalmask; inbounds keep it, udphop refuses to run there.
func migrateUDPHopClientMasks() error {
return db.Transaction(func(tx *gorm.DB) error {
var hosts []model.Host
if err := tx.Select("id", "final_mask").Find(&hosts).Error; err != nil {
return err
}
for _, host := range hosts {
if updated, changed := upgradeFinalmasksJSON(host.FinalMask, wholeFinalmask, false, maskcompat.UpgradeLegacyUDPHop); changed {
if err := tx.Model(&model.Host{}).Where("id = ?", host.Id).
Update("final_mask", updated).Error; err != nil {
return err
}
}
}
var subs []model.OutboundSubscription
if err := tx.Select("id", "last_fetched_outbounds").Find(&subs).Error; err != nil {
return err
}
for _, sub := range subs {
if updated, changed := upgradeFinalmasksJSON(sub.LastFetchedOutbounds, outboundListFinalmasks, false, maskcompat.UpgradeLegacyUDPHop); changed {
if err := tx.Model(&model.OutboundSubscription{}).Where("id = ?", sub.Id).
Update("last_fetched_outbounds", updated).Error; err != nil {
return err
}
}
}
for _, stored := range []struct {
key string
locate func(any) []any
indent bool
}{
{"xrayTemplateConfig", templateOutboundFinalmasks, true},
{"subJsonFinalMask", wholeFinalmask, false},
} {
var setting model.Setting
err := tx.Where("key = ?", stored.key).First(&setting).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
continue
}
if err != nil {
return err
}
if updated, changed := upgradeFinalmasksJSON(setting.Value, stored.locate, stored.indent, maskcompat.UpgradeLegacyUDPHop); changed {
if err := tx.Model(&model.Setting{}).Where("key = ?", stored.key).
Update("value", updated).Error; err != nil {
return err
}
}
}
return tx.Create(&model.HistoryOfSeeders{SeederName: "UDPHopClientMaskFix"}).Error
})
}
// upgradeFinalmasksJSON runs upgrade on the finalmasks locate finds in one stored JSON
// document, leaving the document byte-for-byte alone when nothing in it changed.
func upgradeFinalmasksJSON(raw string, locate func(any) []any, indent bool, upgrade func(any) bool) (string, bool) {
if strings.TrimSpace(raw) == "" {
return raw, false
}
@@ -2007,7 +2068,7 @@ func upgradeLegacyXdnsJSON(raw string, locate func(any) []any, indent bool) (str
}
changed := false
for _, mask := range locate(doc) {
if maskcompat.UpgradeLegacyXdns(mask) {
if upgrade(mask) {
changed = true
}
}
@@ -2044,6 +2105,11 @@ func outboundListFinalmasks(doc any) []any {
return finalmasks
}
func templateOutboundFinalmasks(doc any) []any {
cfg, _ := doc.(map[string]any)
return outboundListFinalmasks(cfg["outbounds"])
}
func templateFinalmasks(doc any) []any {
cfg, _ := doc.(map[string]any)
return append(outboundListFinalmasks(cfg["inbounds"]), outboundListFinalmasks(cfg["outbounds"])...)