mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #6043] [CLOSED] feat(clients): add per-client download/upload speed limits via tc HTB #6058
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#6058
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/6043
Author: @HamidRezaSZ
Created: 7/19/2026
Status: ❌ Closed
Base:
main← Head:feat/speed-limit📝 Commits (10+)
c41fb72feat(clients): add per-client download/upload speed limits via tc HTB2bdb585fix(clients): use CommandContext for tc invocationse77f8dcfix(clients): gate tc shaping and share upload police per client2827384fix(clients): avoid int overflow in police index allocation6f0acabdocs(clients): document per-client speed limits and opt-in setting110043cfix(frontend): raise ConfigBlock text contrast for a11yb00743dfix(clients): address Copilot review on tc speed limiting17ac009Merge branch 'main' into feat/speed-limit9ff2a28Merge branch 'main' into feat/speed-limit2e426e5Merge branch 'main' into feat/speed-limit📊 Changes
42 files changed (+1175 additions, -19 deletions)
View changed files
📝
docs/content/docs/en/config/clients.mdx(+8 -0)📝
docs/content/docs/fa/config/clients.mdx(+8 -0)📝
docs/content/docs/ru/config/clients.mdx(+8 -0)📝
docs/content/docs/zh/config/clients.mdx(+6 -0)📝
frontend/public/openapi.json(+24 -0)📝
frontend/src/components/clients/ConfigBlock.css(+1 -0)📝
frontend/src/generated/examples.ts(+6 -0)📝
frontend/src/generated/schemas.ts(+24 -0)📝
frontend/src/generated/types.ts(+6 -0)📝
frontend/src/generated/zod.ts(+6 -0)📝
frontend/src/hooks/useClients.ts(+4 -0)📝
frontend/src/models/setting.ts(+1 -0)📝
frontend/src/pages/clients/ClientBulkAddModal.tsx(+27 -1)📝
frontend/src/pages/clients/ClientFormModal.tsx(+44 -0)📝
frontend/src/pages/clients/ClientsPage.tsx(+2 -1)📝
frontend/src/pages/settings/GeneralTab.tsx(+5 -0)📝
frontend/src/schemas/client.ts(+6 -0)📝
frontend/src/schemas/defaults.ts(+1 -0)📝
frontend/src/schemas/setting.ts(+1 -0)📝
internal/database/db.go(+18 -0)...and 22 more files
📄 Description
Store speedDown/speedUp on clients and shape traffic for observed client IPs on the primary interface so operators can cap bandwidth without Fail2ban.
Summary
Adds optional per-client download/upload speed limits (Mbps), stored on the client record and enforced with Linux
tcHTB (egress) plus a shared ingress police action per client on the primary interface. Shaping is driven by the existing online-IP scan job and is disabled by default behind aspeedLimitEnablesetting.Why
Operators often need to cap a client’s bandwidth without Fail2ban or IP bans. This gives panel-level speed controls that apply to observed client IPs on the host’s primary NIC, without seizing the host qdisc unless an admin explicitly opts in.
Type of change
Areas affected
How was this tested?
make gen.go test ./internal/web/service/ -run 'TestUniqueValidIPs|TestIPMatch|TestTcShaper'(Sync add/update/remove, shared police across multiple IPs).tctakeover on panel start/restart. Enable it, restart panel, then proceed.tcand root (orCAP_NET_ADMIN): connect a limited client, wait for the IP-scan job (~10s), then checktc class show/tc filter show/tc actionsfor HTB (down) and a shared police index referenced by each IP (up).limitIp> 1 and a nonzerospeedUp, confirm multiple observed IPs share one police action (aggregate upload cap).0(or disconnect), wait for the next sync, and confirm classes/filters/actions are removed.Screenshots / recordings
Breaking changes
None for API consumers beyond optional new fields (
speedDown,speedUp; default0= unlimited) and optional settingspeedLimitEnable(defaultfalse).Ops note: Shaping does not run until Client Speed Limit is enabled and the panel is restarted. When enabled on Linux, the panel takes over the primary interface root qdisc with HTB and may install an ingress qdisc—hosts with an existing custom
tc/QoS setup should opt in knowingly. Requirestcand sufficient privileges; unavailable platforms (e.g. Windows) skip shaping. New columns are added via GORM AutoMigrate (speed_down,speed_up).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.