mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6297] [Feature]: Named routing profiles, assignable to inbounds and hosts #4275
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#4275
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 @den41apple on GitHub (Aug 24, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6297
Is your feature request related to a problem?
All routing settings for subscriptions are global to the panel:
subEnableRouting/subRoutingRulesgo into theRouting-Enable/Routingheaders (internal/sub/controller.go:733-772,ApplyCommonHeaders)subIncyEnableRouting/subIncyRoutingRulesare appended verbatim to the raw body (internal/sub/controller.go:418-421)subJsonRulesis merged intorouting.rulesonce, in the service constructor, before any request is served (internal/sub/json_service.go:41-49)So a panel can hand out one routing profile and nothing else. I cannot say "this entry uses profile A, that entry uses profile B". I also cannot store a profile once and reuse it: the rules live as an opaque blob inside a single settings field, and if I want them in two places I paste them twice.
Note that a routing profile already has a name, and clients use that name to recognise the profile and update it independently of the others. It behaves like an object everywhere except in the panel, where it is a text field.
For JSON subscriptions the limitation is not just missing UI. Every array element is a full xray config that the client passes to the core as-is, so it could carry its own
routingsection. ButGetJsonbuilds each element with a shallow copy:Only
outboundsandremarksget replaced.routingis not just identical in every element, it is the samemap[string]anybehind the same pointer. Mutating it for one entry would corrupt the rest, so right now there is no way to express per-entry routing at all.Describe the solution you'd like
Make routing profiles named objects that can be assigned to inbounds and to hosts. The override chain is the same one the panel already uses for
FinalMask(global default, per-host override) and forExcludeFromSubTypes, except the payload is stored once instead of being copied into every place that needs it.This splits into two phases. Phase 1 is useful on its own if phase 2 is not wanted.
Phase 1: the profile object
New table
routing_profiles:One row covers both delivery channels, so the rules are edited in one place and every subscription that references the profile picks up the change.
CRUD under
/panel/api/routing-profiles(list,get/:id,add,update/:id,del/:id,setEnable/:id), same shape as the host controller (internal/web/controller/host.go:24-36).Phase 2: assignment
Join table
routing_profile_bindings:Resolution for a subscription entry, most specific first:
The last step keeps installs that never create a profile working exactly as they do now.
The relation is many-to-many on purpose. One entry can legitimately offer more than one profile and let the user pick in the client.
Behaviour per subscription format
Deeplinkof every profile resolved for the entries of this subscription, after the share links and before the existing globalsubIncyRoutingRules, de-duplicated by name. Several routing links in one body are already valid and the panel already writes one that way, so there is nothing to resolve here.configJson["routing"]per entry (needed anyway, see above), then useJsonRulesof the resolved profile instead of the globalsubJsonRules. An element can hold only onerouting, so if several profiles resolve to one entry, the one flaggedIsDefaultwins and the others are skipped for that element.internal/sub/clash_service.go:90-104): take theIsDefaultprofile, otherwise inherit global. Fine to leave for later.Routingheader. Stays global, unchanged. Only one header can be sent, so a per-entry value means nothing there. This is the ambiguity that killed #4479.Edge cases
Deeplinkset,JsonRulesempty): that channel inherits the global setting, the other one still applies.IsDefault.ExcludeFromSubTypes, so a whitelist-only entry can go to JSON clients and stay hidden from raw ones.Migration
One migration for the two tables. Optionally a non-empty
subRoutingRulesorsubIncyRoutingRulescan be lifted into a single profile bound at global scope, which makes the upgrade invisible to current operators.UI
frontend/src/pages/hosts/HostFormModal.tsxand in the inbound form, labelled "Routing profiles, leave empty to inherit".Alternatives you've considered
A plain text field on the host. That was my first idea and it does work, but the same base64 blob ends up stored in every host that needs it. With 15 nodes and two entries each, changing one rule set means editing about 30 fields by hand. A named object avoids that and gives the panel the name the clients already rely on.
A field on the inbound (#4479). Does not cover my own setup. One server is reachable directly and through a relay in Russia, and those are two hosts of the same inbound. An inbound-level field cannot tell them apart, and that is exactly the pair that needs different routing.
A second panel plus external subscription merge. This does deliver two profiles: raw external subscription bodies are copied line by line with the only filter being
strings.Contains(ln, "://")(internal/sub/external_subscription.go:148-168), so a routing deeplink from a second panel does reach the client. But it costs a second xray process, a second database, a second backup and upgrade path, plus a port conflict to sort out, and it still cannot bind a profile to a specific entry. It also fails for JSON and Clash, where external links go throughlink.ParseLinkand non-share schemes are dropped (json_service.go:96-100,clash_external.go:14-18).A reverse proxy rewriting the
Routingheader. Covers the header only. It needs a separate subscription URL per profile, so the same person ends up with duplicate server lists, and it does nothing for JSON subscriptions where routing sits inside the config.One shared profile for everyone. Whitelist users get broad rules or everyone else gets narrow ones. That is what I run today and it is why I am writing this.
Concrete use case
I run about 15 nodes and hand out one subscription per client, roughly 300 clients.
Russian mobile carriers periodically cut everything except a government "white list" of some 500 domains: banks, government services, marketplaces. During a cut those domains have to go direct, because they are the only ones that still resolve. Route them through the tunnel and they go down with it. Outside a cut the same person wants the usual split, all of Russia direct and the rest proxied. Two rule sets, both needed by the same people.
On top of that every server is published twice, once directly and once through a relay hosted in Russia. Those two entries share one inbound and one UUID, only the path differs, and they need different routing because the relay is what survives a cut. So assignment has to reach the host level, while still being convenient to apply in bulk on the inbound. That is why both scopes are in the proposal.
Today I ask each of those 300 people to import a second routing deeplink by hand and switch it in app settings, because the panel can attach one profile to the subscription it serves and no more. With named profiles I define "normal" and "white list" once, bind them to the right hosts, and the choice becomes one tap in the client.
Mockups, screenshots, or examples
Profiles, defined once:
normalhapp://routing/add/eyJOYW1lIjoi…[ ... ]white-listhapp://routing/add/eyJOYW1lIjoi…[ ... ]Bound to entries of one inbound:
NL-1normalNL-1 (relay)normal,white-listNL-1 (white list)white-listResulting raw body, before base64:
Resulting JSON subscription: three array elements, identical except
remarks,outboundsand, with this feature,routing, each taking theIsDefaultprofile bound to its host.Relation to #4479
I opened #4479 myself and it was closed. This one is deliberately different, because the old request was under-specified:
routingis shared by pointer across entries.Happy to close this one in favour of reopening #4479 if you prefer that thread.
Which parts of the panel would this affect?
Subscription (share links / Clash / JSON), Backend (API endpoints, login, settings), Frontend (UI / panel pages), Database / migrations
Are you willing to help?
Before submitting
@github-actions[bot] commented on GitHub (Aug 24, 2026):
This is a valid, well-scoped feature request, and every technical claim in it holds against the default branch today — there is no per-host or per-inbound routing override anywhere in the tree, and #4479 was closed on 2026-05-29 with no linked pull request (
closedByPullRequestsReferencesis empty), so nothing was implemented for it. Whether to take the feature is a maintainer call; below is the source confirmation so that decision does not need re-derivation. Your line numbers have drifted since you wrote them, so I have re-anchored each one at the current tip.What I confirmed
Routing is global on all three channels.
resolveRoutingSource(remoteRoutingHapp, profileRoutingRules)inApplyCommonHeaders,internal/sub/controller.go:843-849(you cited733-772; the function now spans812-853). Both call sites for raw pass the panel-wide fields —controller.go:429,:752,:800.internal/sub/controller.go:431-437(you cited418-421) —if a.subIncyEnableRouting && a.subIncyRoutingRules != "", written straight into the body builder.subJsonRulesis folded intoconfigJson["routing"]["rules"]once in the constructor,internal/sub/json_service.go:48-56(you cited41-49), before any request is served.The shallow-copy point is correct, and the repo already agrees with it in a comment. Per-inbound entries are built at
internal/sub/json_service.go:544-549:The external-link entries do the same at
:142-145. There is a third site,:426-430, and it is the interesting one — the client-side balancer path added inda01b763(#6243) already hit exactly the hazard you describe and works around it:internal/sub/json_service.go:392-393So the per-entry
routingdeep copy is not new work to invent; it exists for balancer documents and would be generalised. Note this is a latent hazard, not a live output bug: each document is marshalled immediately and nothing mutatesroutingon the per-inbound path today.The
FinalMaskprecedent is exactly the contract you describe. Field atinternal/database/model/model.go:1094-1096, projected onto the endpoint map atinternal/sub/host_sub.go:104-106, consumed atinternal/sub/host_sub.go:150-158, global counterpart atinternal/sub/json_service.go:580-581→applyGlobalFinalMask(:614). Per-host wins, empty inherits — as claimed.The API and Clash points check out.
POST /addandPOST /update/:groupIdare atinternal/web/controller/host.go:29-30, andHostis already in theStructAllowallowlist (tools/openapigen/main.go:41), so a new field rides both endpoints after amake genwith no new route entry. Clash really is one rule list per document —"rules": []string{"MATCH,PROXY"}atinternal/sub/clash_service.go:98, merged globally at:101-109— so "inherit global, out of scope" is the right call.Two corrections and one cost you did not price in
internal/sub/external_subscription.go:197(if strings.Contains(ln, "://")), not148-168— that range isdoFetchSubscriptionLinks. The behaviour you describe is right, only the anchor moved.getSubsreturns([]string, []string, int64, xray.ClientTraffic, error)(internal/sub/service.go:296) and the hosts are consumed and discarded insidelinkFromHosts(internal/sub/service.go:323-333). The controller that would emit the deeplink (controller.go:419-437) never sees a host. So raw needs a new channel out ofgetSubs, whereas JSON gets it for free —hostToExternalProxyMap(internal/sub/host_sub.go:45-110) already carries per-host keys all the way into the renderer, which is whyfinalMaskcost two lines there.hostscolumns come from GORMAutoMigrate, guarded on both drivers byTestHostAutoMigrateCreatesColumns_Postgres(internal/database/host_test.go:49). A plain nullable TEXT column needs no hand-written migration ininternal/database/db.go— only a type change or a backfill would. Adding the column to that test is the cheap way to keep the Postgres CI job honest.If you do open a PR, the two steps that most often get missed here: the UI label needs a key in all 13 locale files under
internal/web/translation/in the same commit (frontend/src/test/i18n-dead-keys.test.tsfails both on a missing file and on an orphan key), andfrontend/public/openapi.jsonhas to be copied todocs/public/openapi.jsonwithcd docs && pnpm gen:api— nothing in CI checks that one.Related, not duplicates — I am leaving all of these open
I could not evaluate one thing: whether Happ and Incy actually keep several
routing/adddeeplinks from a single subscription body as separate selectable profiles. That is client-side behaviour outside this repo, and it is the assumption the whole raw half of the proposal rests on. The panel-side half of it is sound —internal/sub/external_subscription.go:197shows a routing deeplink already survives the raw copy path — but a report of two profiles landing side by side in Happ from one body would settle it.Verdict: Feature request
This reply was generated automatically; a maintainer may follow up.