[GH-ISSUE #6297] [Feature]: Named routing profiles, assignable to inbounds and hosts #4275

Closed
opened 2026-10-31 20:38:27 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @den41apple on GitHub (Aug 24, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6297

All routing settings for subscriptions are global to the panel:

  • subEnableRouting / subRoutingRules go into the Routing-Enable / Routing headers (internal/sub/controller.go:733-772, ApplyCommonHeaders)
  • subIncyEnableRouting / subIncyRoutingRules are appended verbatim to the raw body (internal/sub/controller.go:418-421)
  • subJsonRules is merged into routing.rules once, 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 routing section. But GetJson builds each element with a shallow copy:

newConfigJson := make(map[string]any)
maps.Copy(newConfigJson, s.configJson)   // internal/sub/json_service.go:242-243

newConfigJson["outbounds"] = newOutbounds
newConfigJson["remarks"]   = subReq.endpointRemark(...)

Only outbounds and remarks get replaced. routing is not just identical in every element, it is the same map[string]any behind 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 for ExcludeFromSubTypes, 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:

type RoutingProfile struct {
    Id     int    `json:"id" gorm:"primaryKey;autoIncrement"`
    Name   string `json:"name" gorm:"uniqueIndex;not null" validate:"required,max=64"`
    Remark string `json:"remark" validate:"omitempty,max=256"`

    // Deeplink form, used by raw subscriptions:
    // happ://routing/add/<base64>, incy://routing/onadd/<base64>, ...
    Deeplink string `json:"deeplink" gorm:"type:text"`

    // JSON array of xray routing rules, used by JSON subscriptions.
    // Same shape as the existing global subJsonRules.
    JsonRules string `json:"jsonRules" gorm:"type:text"`

    IsDefault bool `json:"isDefault" gorm:"default:false"`
    IsEnabled bool `json:"isEnabled" gorm:"default:true"`

    CreatedAt int64 `json:"createdAt" gorm:"autoCreateTime:milli"`
    UpdatedAt int64 `json:"updatedAt" gorm:"autoUpdateTime:milli"`
}

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:

ProfileId int    // -> routing_profiles.id
Scope     string // "global" | "inbound" | "host"
TargetId  int    // inbound id or host id, ignored for "global"

Resolution for a subscription entry, most specific first:

host bindings -> inbound bindings -> global bindings -> current settings

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

  1. Raw. Append the Deeplink of every profile resolved for the entries of this subscription, after the share links and before the existing global subIncyRoutingRules, 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.
  2. JSON. Deep-copy configJson["routing"] per entry (needed anyway, see above), then use JsonRules of the resolved profile instead of the global subJsonRules. An element can hold only one routing, so if several profiles resolve to one entry, the one flagged IsDefault wins and the others are skipped for that element.
  3. Clash. Same single-list constraint as JSON (internal/sub/clash_service.go:90-104): take the IsDefault profile, otherwise inherit global. Fine to leave for later.
  4. Routing header. 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

  • No profiles defined: current behaviour, unchanged.
  • Profile filled in one channel only (say Deeplink set, JsonRules empty): that channel inherits the global setting, the other one still applies.
  • Several profiles on one entry: raw emits all of them, JSON and Clash take IsDefault.
  • Deleting a profile cascades its bindings, and affected entries fall back down the chain.
  • Works together with 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 subRoutingRules or subIncyRoutingRules can be lifted into a single profile bound at global scope, which makes the upgrade invisible to current operators.

UI

  • New page "Routing profiles" with name, remark, deeplink, JSON rules and the default flag. Same CRUD layout as Hosts.
  • A multi-select in frontend/src/pages/hosts/HostFormModal.tsx and 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 through link.ParseLink and non-share schemes are dropped (json_service.go:96-100, clash_external.go:14-18).

A reverse proxy rewriting the Routing header. 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:

Name Deeplink JSON rules Default
normal happ://routing/add/eyJOYW1lIjoi… [ ... ] yes
white-list happ://routing/add/eyJOYW1lIjoi… [ ... ] no

Bound to entries of one inbound:

Host Remark Profiles
host A NL-1 normal
host B NL-1 (relay) normal, white-list
host C NL-1 (white list) white-list

Resulting raw body, before base64:

vless://…#NL-1
vless://…#NL-1%20(relay)
vless://…#NL-1%20(white%20list)
happ://routing/add/…      <- normal
happ://routing/add/…      <- white-list, de-duplicated across entries

Resulting JSON subscription: three array elements, identical except remarks, outbounds and, with this feature, routing, each taking the IsDefault profile 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:

  • Level. #4479 asked for the field on the inbound only. My own setup breaks that: a direct entry and a relayed entry are two hosts of one inbound and need different routing. Both scopes are needed, with host winning over inbound.
  • Channels. #4479 treated "header or body" as interchangeable. They are not. The header carries one profile, the body carries many, and separating them removes the conflict for raw subscriptions.
  • JSON. #4479 said nothing about JSON subscriptions, which is where the limitation is structural, since routing is shared by pointer across entries.
  • Shape. #4479 proposed an opaque blob per inbound. This proposes a named object, which is what the clients already assume exists.

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?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
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` / `subRoutingRules` go into the `Routing-Enable` / `Routing` headers (`internal/sub/controller.go:733-772`, `ApplyCommonHeaders`) - `subIncyEnableRouting` / `subIncyRoutingRules` are appended verbatim to the raw body (`internal/sub/controller.go:418-421`) - `subJsonRules` is merged into `routing.rules` once, 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 `routing` section. But `GetJson` builds each element with a shallow copy: ```go newConfigJson := make(map[string]any) maps.Copy(newConfigJson, s.configJson) // internal/sub/json_service.go:242-243 newConfigJson["outbounds"] = newOutbounds newConfigJson["remarks"] = subReq.endpointRemark(...) ``` Only `outbounds` and `remarks` get replaced. `routing` is not just identical in every element, it is the same `map[string]any` behind 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 for `ExcludeFromSubTypes`, 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`: ```go type RoutingProfile struct { Id int `json:"id" gorm:"primaryKey;autoIncrement"` Name string `json:"name" gorm:"uniqueIndex;not null" validate:"required,max=64"` Remark string `json:"remark" validate:"omitempty,max=256"` // Deeplink form, used by raw subscriptions: // happ://routing/add/<base64>, incy://routing/onadd/<base64>, ... Deeplink string `json:"deeplink" gorm:"type:text"` // JSON array of xray routing rules, used by JSON subscriptions. // Same shape as the existing global subJsonRules. JsonRules string `json:"jsonRules" gorm:"type:text"` IsDefault bool `json:"isDefault" gorm:"default:false"` IsEnabled bool `json:"isEnabled" gorm:"default:true"` CreatedAt int64 `json:"createdAt" gorm:"autoCreateTime:milli"` UpdatedAt int64 `json:"updatedAt" gorm:"autoUpdateTime:milli"` } ``` 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`: ```go ProfileId int // -> routing_profiles.id Scope string // "global" | "inbound" | "host" TargetId int // inbound id or host id, ignored for "global" ``` Resolution for a subscription entry, most specific first: ``` host bindings -> inbound bindings -> global bindings -> current settings ``` 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 1. **Raw.** Append the `Deeplink` of every profile resolved for the entries of this subscription, after the share links and before the existing global `subIncyRoutingRules`, 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. 2. **JSON.** Deep-copy `configJson["routing"]` per entry (needed anyway, see above), then use `JsonRules` of the resolved profile instead of the global `subJsonRules`. An element can hold only one `routing`, so if several profiles resolve to one entry, the one flagged `IsDefault` wins and the others are skipped for that element. 3. **Clash.** Same single-list constraint as JSON (`internal/sub/clash_service.go:90-104`): take the `IsDefault` profile, otherwise inherit global. Fine to leave for later. 4. **`Routing` header.** 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 - No profiles defined: current behaviour, unchanged. - Profile filled in one channel only (say `Deeplink` set, `JsonRules` empty): that channel inherits the global setting, the other one still applies. - Several profiles on one entry: raw emits all of them, JSON and Clash take `IsDefault`. - Deleting a profile cascades its bindings, and affected entries fall back down the chain. - Works together with `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 `subRoutingRules` or `subIncyRoutingRules` can be lifted into a single profile bound at global scope, which makes the upgrade invisible to current operators. #### UI - New page "Routing profiles" with name, remark, deeplink, JSON rules and the default flag. Same CRUD layout as Hosts. - A multi-select in `frontend/src/pages/hosts/HostFormModal.tsx` and 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 through `link.ParseLink` and non-share schemes are dropped (`json_service.go:96-100`, `clash_external.go:14-18`). **A reverse proxy rewriting the `Routing` header.** 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: | Name | Deeplink | JSON rules | Default | |--------------|------------------------------------|------------|---------| | `normal` | `happ://routing/add/eyJOYW1lIjoi…` | `[ ... ]` | yes | | `white-list` | `happ://routing/add/eyJOYW1lIjoi…` | `[ ... ]` | no | Bound to entries of one inbound: | Host | Remark | Profiles | |--------|---------------------|------------------------| | host A | `NL-1` | `normal` | | host B | `NL-1 (relay)` | `normal`, `white-list` | | host C | `NL-1 (white list)` | `white-list` | Resulting raw body, before base64: ``` vless://…#NL-1 vless://…#NL-1%20(relay) vless://…#NL-1%20(white%20list) happ://routing/add/… <- normal happ://routing/add/… <- white-list, de-duplicated across entries ``` Resulting JSON subscription: three array elements, identical except `remarks`, `outbounds` and, with this feature, `routing`, each taking the `IsDefault` profile 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: - **Level.** #4479 asked for the field on the inbound only. My own setup breaks that: a direct entry and a relayed entry are two hosts of one inbound and need different routing. Both scopes are needed, with host winning over inbound. - **Channels.** #4479 treated "header or body" as interchangeable. They are not. The header carries one profile, the body carries many, and separating them removes the conflict for raw subscriptions. - **JSON.** #4479 said nothing about JSON subscriptions, which is where the limitation is structural, since `routing` is shared by pointer across entries. - **Shape.** #4479 proposed an opaque blob per inbound. This proposes a named object, which is what the clients already assume exists. 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? - [x] I'd like to implement this feature myself and open a PR. - [x] I can help test once a PR is open. ### Before submitting - [x] I searched existing issues and this feature has not been requested. - [x] This feature request is written in English.
bsakaguchi 2026-10-31 20:38:27 +07:00
Author
Owner

@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 (closedByPullRequestsReferences is 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

  1. Routing is global on all three channels.

    • Happ header: resolveRoutingSource(remoteRoutingHapp, profileRoutingRules) in ApplyCommonHeaders, internal/sub/controller.go:843-849 (you cited 733-772; the function now spans 812-853). Both call sites for raw pass the panel-wide fields — controller.go:429, :752, :800.
    • Incy body append: internal/sub/controller.go:431-437 (you cited 418-421) — if a.subIncyEnableRouting && a.subIncyRoutingRules != "", written straight into the body builder.
    • JSON: subJsonRules is folded into configJson["routing"]["rules"] once in the constructor, internal/sub/json_service.go:48-56 (you cited 41-49), before any request is served.
  2. 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:

    newConfigJson := make(map[string]any)
    maps.Copy(newConfigJson, s.configJson)
    
    transport, _ := newStream["network"].(string)
    newConfigJson["outbounds"] = newOutbounds
    newConfigJson["remarks"] = subReq.endpointRemark(inbound, client.Email, extPrxy, transport)
    

    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 in da01b763 (#6243) already hit exactly the hazard you describe and works around it:

    // The routing subtree in s.configJson is shared by every emitted document;
    // clone it (and each rule map) before pointing rules at the balancer.
    

    internal/sub/json_service.go:392-393

    So the per-entry routing deep 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 mutates routing on the per-inbound path today.

  3. The FinalMask precedent is exactly the contract you describe. Field at internal/database/model/model.go:1094-1096, projected onto the endpoint map at internal/sub/host_sub.go:104-106, consumed at internal/sub/host_sub.go:150-158, global counterpart at internal/sub/json_service.go:580-581 → applyGlobalFinalMask (:614). Per-host wins, empty inherits — as claimed.

  4. The API and Clash points check out. POST /add and POST /update/:groupId are at internal/web/controller/host.go:29-30, and Host is already in the StructAllow allowlist (tools/openapigen/main.go:41), so a new field rides both endpoints after a make gen with no new route entry. Clash really is one rule list per document — "rules": []string{"MATCH,PROXY"} at internal/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

  • The external-subscription filter you quote is at internal/sub/external_subscription.go:197 (if strings.Contains(ln, "://")), not 148-168 — that range is doFetchSubscriptionLinks. The behaviour you describe is right, only the anchor moved.
  • The raw path is materially more expensive than the JSON path, and the proposal reads as though they cost the same. getSubs returns ([]string, []string, int64, xray.ClientTraffic, error) (internal/sub/service.go:296) and the hosts are consumed and discarded inside linkFromHosts (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 of getSubs, 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 why finalMask cost two lines there.
  • Migration: hosts columns come from GORM AutoMigrate, guarded on both drivers by TestHostAutoMigrateCreatesColumns_Postgres (internal/database/host_test.go:49). A plain nullable TEXT column needs no hand-written migration in internal/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.ts fails both on a missing file and on an orphan key), and frontend/public/openapi.json has to be copied to docs/public/openapi.json with cd docs && pnpm gen:api — nothing in CI checks that one.

Related, not duplicates — I am leaving all of these open

  • #5824 (open) asks for the same capability on the JSON side but at the inbound level, with a "Routing" tab in the inbound editor. It overlaps yours heavily and whoever decides one should decide both, but the level differs and one change does not obviously satisfy the other, so I am not closing either.
  • #4479 (closed, your own) — confirmed above that it closed without an implementation.
  • #6062 (open) splits routing by client app via User-Agent, a different axis entirely.

I could not evaluate one thing: whether Happ and Incy actually keep several routing/add deeplinks 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:197 shows 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.

<!-- gh-comment-id:5396458478 --> @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 (`closedByPullRequestsReferences` is 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** 1. Routing is global on all three channels. - Happ header: `resolveRoutingSource(remoteRoutingHapp, profileRoutingRules)` in `ApplyCommonHeaders`, `internal/sub/controller.go:843-849` (you cited `733-772`; the function now spans `812-853`). Both call sites for raw pass the panel-wide fields — `controller.go:429`, `:752`, `:800`. - Incy body append: `internal/sub/controller.go:431-437` (you cited `418-421`) — `if a.subIncyEnableRouting && a.subIncyRoutingRules != ""`, written straight into the body builder. - JSON: `subJsonRules` is folded into `configJson["routing"]["rules"]` once in the constructor, `internal/sub/json_service.go:48-56` (you cited `41-49`), before any request is served. 2. 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`: ```go newConfigJson := make(map[string]any) maps.Copy(newConfigJson, s.configJson) transport, _ := newStream["network"].(string) newConfigJson["outbounds"] = newOutbounds newConfigJson["remarks"] = subReq.endpointRemark(inbound, client.Email, extPrxy, transport) ``` 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 in `da01b763` (#6243) already hit exactly the hazard you describe and works around it: ```go // The routing subtree in s.configJson is shared by every emitted document; // clone it (and each rule map) before pointing rules at the balancer. ``` `internal/sub/json_service.go:392-393` So the per-entry `routing` deep 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 mutates `routing` on the per-inbound path today. 3. The `FinalMask` precedent is exactly the contract you describe. Field at `internal/database/model/model.go:1094-1096`, projected onto the endpoint map at `internal/sub/host_sub.go:104-106`, consumed at `internal/sub/host_sub.go:150-158`, global counterpart at `internal/sub/json_service.go:580-581` → `applyGlobalFinalMask` (`:614`). Per-host wins, empty inherits — as claimed. 4. The API and Clash points check out. `POST /add` and `POST /update/:groupId` are at `internal/web/controller/host.go:29-30`, and `Host` is already in the `StructAllow` allowlist (`tools/openapigen/main.go:41`), so a new field rides both endpoints after a `make gen` with no new route entry. Clash really is one rule list per document — `"rules": []string{"MATCH,PROXY"}` at `internal/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** - The external-subscription filter you quote is at `internal/sub/external_subscription.go:197` (`if strings.Contains(ln, "://")`), not `148-168` — that range is `doFetchSubscriptionLinks`. The behaviour you describe is right, only the anchor moved. - The raw path is materially more expensive than the JSON path, and the proposal reads as though they cost the same. `getSubs` returns `([]string, []string, int64, xray.ClientTraffic, error)` (`internal/sub/service.go:296`) and the hosts are consumed and discarded inside `linkFromHosts` (`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 of `getSubs`, 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 why `finalMask` cost two lines there. - Migration: `hosts` columns come from GORM `AutoMigrate`, guarded on both drivers by `TestHostAutoMigrateCreatesColumns_Postgres` (`internal/database/host_test.go:49`). A plain nullable TEXT column needs no hand-written migration in `internal/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.ts` fails both on a missing file and on an orphan key), and `frontend/public/openapi.json` has to be copied to `docs/public/openapi.json` with `cd docs && pnpm gen:api` — nothing in CI checks that one. **Related, not duplicates — I am leaving all of these open** - #5824 (open) asks for the same capability on the JSON side but at the *inbound* level, with a "Routing" tab in the inbound editor. It overlaps yours heavily and whoever decides one should decide both, but the level differs and one change does not obviously satisfy the other, so I am not closing either. - #4479 (closed, your own) — confirmed above that it closed without an implementation. - #6062 (open) splits routing by client app via User-Agent, a different axis entirely. I could not evaluate one thing: whether Happ and Incy actually keep several `routing/add` deeplinks 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:197` shows 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.* <!-- claude-issue:analyst -->
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#4275
No description provided.