Repository navigation
feat(socks5): per-CONNECT upstream routing (route_target) - #121
Merged
Merged
Conversation
This was referenced Nov 28, 2026
Add uvcpp_socks5_server_options::route_target, consulted once per CONNECT with the requested target. Returning true fills a uvcpp_socks5_upstream (host/port/username/password) and the session dials the upstream first, reusing uvcpp_tcp_client::set_socks5_proxy() for the greeting/auth/CONNECT negotiation; the REP sent to the client comes from the final result. Returning false keeps the existing direct path. Domain targets stay ATYP=DOMAIN so the upstream resolves them, a throwing callback is treated as "direct", and BIND / UDP ASSOCIATE are unchanged. The success reply's BND.ADDR is the local address toward the upstream. Tests: socks5_server_func gains route_target_upstream, which chains an echo through a second SOCKS5 server and then checks that the same server still dials directly when the hook returns false.
The config-contract gate compiles every cpp block that is not marked as a fragment; the new example has no library include, so it failed the 'snippet belongs to a module' check on Linux and Windows.
Antruly
force-pushed
the
feat/socks5-route-upstream
branch
from
November 28, 2026 11:34
8a6f166 to
495e546
Compare
Antruly
added a commit
to Antruly/uvscope
that referenced
this pull request
Nov 28, 2026
Add the decision layer the proxy clients will share:
- src/routing.*: IP/CIDR parsing, range normalisation (sort, merge and
adjacency) and binary-search containment. Pure logic, no I/O, so
--self-check covers it offline.
- Built-in groups: mainland (APNIC CN allocations generated by
scripts/gen-geo-cidrs.py and embedded at configure time from
data/geo/cn-cidrs.txt), overseas (complement of mainland among public
addresses) and loopback. Built-ins are read-only.
- Custom groups store CIDR text under the routing.groups setting; rules
under routing.rules keep an ordered {groupId, action, proxy} list plus a
default action. The first group containing the destination wins.
- API: GET /api/routing, group create/update/delete, PUT
/api/routing/rules and POST /api/routing/match (admin.settings).
- UI: a new Address Groups page with built-in cards, custom group editing,
ordered rule editing and a destination matcher.
- Docs: API.md, ARCHITECTURE.md, README, help page, CHANGELOG.
- Tests: self-check assertions for parsing, containment, the embedded
mainland data, the overseas complement, rule precedence and rejection;
smoke-test assertions for the full API round-trip and the read-only /
referenced-group guards.
Upstream proxy credentials are not persisted yet; a rule that carries a
password is rejected with a clear error instead of dropping the secret.
Wiring the rules into the SOCKS5 server needs libuvcpp's route_target hook
(upstream PR Antruly/libuvcpp#121); until that ships, servers dial directly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
A SOCKS5 server could only allow or deny a target (
allow_target); it had no way to change where a session egresses. uvscope needs a per-destination decision: dial directly, or hand the connection to an upstream proxy (mainland direct / overseas through a proxy).What
uvcpp_socks5_server_options::route_target:true+ a filleduvcpp_socks5_upstream{host, port, username, password}: the session dials the upstream first, reusinguvcpp_tcp_client::set_socks5_proxy()for greeting / auth / CONNECT. The REP sent to the client comes from the final result.false: the existing direct path, unchanged.ATYP=DOMAIN, so the upstream resolves them; a throwing callback is treated asdirect.BND.ADDRis the local address toward the upstream, not toward the target.Compatibility
Additive. A default-constructed
std::functionleaves every existing server byte-for-byte on the old path.Tests
Built with
-DUVCPP_BUILD_TESTS=ON -DUVCPP_BUILD_WEB=OFF -DUVCPP_ENABLE_OPENSSL=OFF:The new case chains an echo through a second SOCKS5 server and then verifies the same server still dials directly when the hook returns false.
test_socks5_client_funcandtest_socks5_udp_funcalso still pass.