mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6784] [MERGED] feat(sub): support random IP generation from CIDR host addresses #6453
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#6453
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?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6784
Author: @Pejman-Yousefi-Official
Created: 10/10/2026
Status: ✅ Merged
Merged: 10/24/2026
Merged by: @MHSanaei
Base:
main← Head:main📝 Commits (10+)
dd1d9e6feat(sub): support random IP generation from CIDR host addressesd74a57bfix(ui): compute hasCidr without useMemo to satisfy oxlint rules54b15f6fix(ui): format randomCount form field to satisfy oxfmt rules0d631b0Merge branch 'main' into main72f4720Merge branch 'main' into main24cb8f0Merge branch 'main' into main90688d0fix(ci): stop the PR review ending mid-wait and posting its draft1f6b5aeMerge branch 'main' into main32f3618Merge remote-tracking branch 'origin/main' into pr/6784265238ffix(sub): mirror CIDR expansion in frontend and clamp randomCount📊 Changes
33 files changed (+886 additions, -8 deletions)
View changed files
📝
docs/public/openapi.json(+17 -0)📝
frontend/public/openapi.json(+17 -0)📝
frontend/src/generated/examples.ts(+2 -0)📝
frontend/src/generated/schemas.ts(+11 -0)📝
frontend/src/generated/types.ts(+2 -0)📝
frontend/src/generated/zod.ts(+2 -0)➕
frontend/src/lib/hosts/host-cidr.ts(+266 -0)📝
frontend/src/lib/hosts/host-link.ts(+41 -7)📝
frontend/src/pages/hosts/HostFormModal.tsx(+8 -0)📝
frontend/src/schemas/api/host.ts(+2 -0)📝
frontend/src/test/tunnel-host-endpoints.test.ts(+21 -0)📝
internal/database/db.go(+1 -0)📝
internal/database/host_test.go(+1 -1)📝
internal/database/model/model.go(+1 -0)➕
internal/sub/host_cidr.go(+156 -0)➕
internal/sub/host_cidr_test.go(+175 -0)📝
internal/sub/host_sub.go(+23 -0)📝
internal/sub/host_sub_test.go(+111 -0)📝
internal/web/entity/entity.go(+1 -0)📝
internal/web/service/host.go(+15 -0)...and 13 more files
📄 Description
Summary
Add support for IPv4 and IPv6 CIDR notations in Host addresses. When a host address contains a CIDR subnet, subscription feeds (raw links, Clash proxies, and Xray JSON outbounds) dynamically expand it into up to
randomCountdistinct random IPs with numbered remarks.Why
Operators commonly assign broad IPv6 subnets (such as
/64) or IPv4 subnets across inbounds and reverse-proxy frontends. Previously, Host entries only accepted literal IP addresses or domain names, requiring operators to manually create dozens of duplicate host entries to achieve IP diversification. Supporting CIDR blocks enables automatic per-subscription IP rotation without database bloat or manual maintenance.Type of change
Areas affected
How was this tested?
Unit tests:
internal/sub/host_cidr_test.gocovering IPv4 (/32,/31,/24), IPv6 (/128,/64, bracketed[2001:db8::]/64), network/broadcast avoidance, subnet-router anycast exclusion, and collision handling.internal/sub/host_sub_test.goasserting endpoint expansion across raw share links, Clash YAML proxies, and Xray JSON outbounds with remark suffixes (Remark - 1,Remark - 2, etc.).internal/database/host_test.goverifying GORM auto-migration forrandom_countacross both SQLite and PostgreSQL.go test ./....Manual verification:
cdn.example.com) — confirmedrandomCountinput remains hidden.2a01:4f8::/64) — confirmedrandomCountinput dynamically appears below the Address field.randomCount = 3and fetched/sub/...raw, Clash, and JSON endpoints. Verified 3 unique random IPv6 addresses generated with sequential remark suffixes.tools/openapigenanddocs/public/openapi.json).Breaking changes
None. The database field defaults to
1via GORM column default and automatic migration. Hosts without CIDR notation retain identical behavior.Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.