[PR #4169] [MERGED] inbound: allow tcp and udp on the same port #5617

Closed
opened 2026-10-31 20:48:11 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/4169
Author: @pwnnex
Created: 5/6/2026
Status: ✅ Merged
Merged: 5/6/2026
Merged by: @MHSanaei

Base: main ← Head: fix/port-conflict-by-transport


📝 Commits (1)

  • 3ab8069 inbound: check transport in port conflict, allow tcp and udp on same port

📊 Changes

3 files changed (+614 additions, -36 deletions)

View changed files

📝 web/service/inbound.go (+17 -36)
➕ web/service/port_conflict.go (+234 -0)
➕ web/service/port_conflict_test.go (+363 -0)

📄 Description

closes #4103.

what users see

before: trying to add hysteria2 on udp/443 while vless reality already
listens on tcp/443 fails with Port already exists: 443. the only
workaround is moving one of them off 443. this is the standard
"reality cover + hy2 on the same port" deployment a lot of users want.

after: the panel accepts tcp/443 + udp/443 as two separate inbounds.
two tcp inbounds on the same port still conflict, two udp inbounds
still conflict, shadowsocks listening on tcp,udp still blocks both
transports. listen-overlap rule (specific addr vs any-addr on the
same port) is kept exactly as it was.

what changed

  1. inboundTransports(protocol, streamSettings, settings) classifies
    each inbound by L4 transport:
    • hysteria/hysteria2/wireguard: udp
    • streamSettings.network=kcp: udp
    • shadowsocks: whatever settings.network says (tcp/udp/tcp,udp)
    • mixed (socks/http combo): tcp + udp when settings.udp is true
    • everything else: tcp
  2. checkPortConflict replaces checkPortExist. it pulls every row on
    the same port, applies the existing listen-overlap rule, and only
    flags a conflict when the transport masks share a bit.
  3. inbounds.tag has a unique DB constraint and the controller derives
    tags from port (inbound-443). without disambiguation a second
    inbound on the same port would still hit a unique-constraint error
    even after the port check passes. generateInboundTag keeps the
    historical inbound-<port> shape when the base tag is free, so
    existing routing rules survive the upgrade unchanged, and appends
    -tcp/-udp only when the base is already taken.

tests

web/service/port_conflict_test.go:

  • TestInboundTransports: 17 cases covering vless tcp/ws/kcp, vmess,
    trojan grpc, hysteria, hysteria2, wireguard, shadowsocks all variants,
    mixed udp on/off, garbage json, empty inputs.
  • TestListenOverlaps: pins the any-vs-specific listen rules.
  • TestCheckPortConflict_* (sqlite-backed): tcp/udp coexist on same
    port, tcp+tcp still conflict, udp+udp still conflict, shadowsocks
    dual-listen blocks both, different ports never conflict, listen
    overlap preserved, ignoreId works on update.
  • TestGenerateInboundTag_*: disambiguates by transport when base tag
    is taken, keeps base tag when free, ignores self on update, specific
    listen address gets the same disambiguation rules.

go build ./..., go vet, gofmt all clean.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/4169 **Author:** [@pwnnex](https://github.com/pwnnex) **Created:** 5/6/2026 **Status:** ✅ Merged **Merged:** 5/6/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/port-conflict-by-transport` --- ### 📝 Commits (1) - [`3ab8069`](https://github.com/MHSanaei/3x-ui/commit/3ab80699b1d4e98e9a75766e4840973a7eb90385) inbound: check transport in port conflict, allow tcp and udp on same port ### 📊 Changes **3 files changed** (+614 additions, -36 deletions) <details> <summary>View changed files</summary> 📝 `web/service/inbound.go` (+17 -36) ➕ `web/service/port_conflict.go` (+234 -0) ➕ `web/service/port_conflict_test.go` (+363 -0) </details> ### 📄 Description closes #4103. ## what users see before: trying to add hysteria2 on udp/443 while vless reality already listens on tcp/443 fails with `Port already exists: 443`. the only workaround is moving one of them off 443. this is the standard "reality cover + hy2 on the same port" deployment a lot of users want. after: the panel accepts tcp/443 + udp/443 as two separate inbounds. two tcp inbounds on the same port still conflict, two udp inbounds still conflict, shadowsocks listening on `tcp,udp` still blocks both transports. listen-overlap rule (specific addr vs any-addr on the same port) is kept exactly as it was. ## what changed 1. `inboundTransports(protocol, streamSettings, settings)` classifies each inbound by L4 transport: - hysteria/hysteria2/wireguard: udp - `streamSettings.network=kcp`: udp - shadowsocks: whatever `settings.network` says (`tcp`/`udp`/`tcp,udp`) - mixed (socks/http combo): tcp + udp when `settings.udp` is true - everything else: tcp 2. `checkPortConflict` replaces `checkPortExist`. it pulls every row on the same port, applies the existing listen-overlap rule, and only flags a conflict when the transport masks share a bit. 3. `inbounds.tag` has a unique DB constraint and the controller derives tags from port (`inbound-443`). without disambiguation a second inbound on the same port would still hit a unique-constraint error even after the port check passes. `generateInboundTag` keeps the historical `inbound-<port>` shape when the base tag is free, so existing routing rules survive the upgrade unchanged, and appends `-tcp`/`-udp` only when the base is already taken. ## tests `web/service/port_conflict_test.go`: - `TestInboundTransports`: 17 cases covering vless tcp/ws/kcp, vmess, trojan grpc, hysteria, hysteria2, wireguard, shadowsocks all variants, mixed udp on/off, garbage json, empty inputs. - `TestListenOverlaps`: pins the any-vs-specific listen rules. - `TestCheckPortConflict_*` (sqlite-backed): tcp/udp coexist on same port, tcp+tcp still conflict, udp+udp still conflict, shadowsocks dual-listen blocks both, different ports never conflict, listen overlap preserved, ignoreId works on update. - `TestGenerateInboundTag_*`: disambiguates by transport when base tag is taken, keeps base tag when free, ignores self on update, specific listen address gets the same disambiguation rules. `go build ./...`, `go vet`, `gofmt` all clean. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 20:48:11 +07:00
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#5617
No description provided.