Skip to content

Add TCP Listener support for wireguard outbound#3651

Merged
xiaokangwang merged 1 commit intov2fly:masterfrom
xiaokangwang:dev-wireguard-tcp-listener-t6bdhuiq2t9m4757gvkz9wssl9mdlir9mxnp
Mar 14, 2026
Merged

Add TCP Listener support for wireguard outbound#3651
xiaokangwang merged 1 commit intov2fly:masterfrom
xiaokangwang:dev-wireguard-tcp-listener-t6bdhuiq2t9m4757gvkz9wssl9mdlir9mxnp

Conversation

@xiaokangwang
Copy link
Copy Markdown
Contributor

(Machine Generated)
This pull request introduces support for configurable TCP listeners in the gVisor-based packet switch stack, allowing TCP connections to be accepted and relayed to tagged outbound handlers. The changes include protocol buffer and generated code updates, new listener management logic, and integration with the stack lifecycle.

TCP Listener feature additions:

  • Added a TCPListener message to the protocol buffer definition (config.proto) and updated generated code to support multiple TCP listeners in the Config struct. ([[1]](https://github.com/v2fly/v2ray-core/pull/3651/files#diff-3b84b456b991b8d195155c819727ae4bc72b059d237fe5865b2a6220f10ea936R13-R18), [[2]](https://github.com/v2fly/v2ray-core/pull/3651/files#diff-3b84b456b991b8d195155c819727ae4bc72b059d237fe5865b2a6220f10ea936R29), [[3]](https://github.com/v2fly/v2ray-core/pull/3651/files#diff-6d5f70c28dbc05b46b7773065ff1d592f2a10f50ad2af88d62bfc111bb76e436R21-R80), [[4]](https://github.com/v2fly/v2ray-core/pull/3651/files#diff-6d5f70c28dbc05b46b7773065ff1d592f2a10f50ad2af88d62bfc111bb76e436R92-R99), [[5]](https://github.com/v2fly/v2ray-core/pull/3651/files#diff-6d5f70c28dbc05b46b7773065ff1d592f2a10f50ad2af88d62bfc111bb76e436L50-R111), [[6]](https://github.com/v2fly/v2ray-core/pull/3651/files#diff-6d5f70c28dbc05b46b7773065ff1d592f2a10f50ad2af88d62bfc111bb76e436L63-R124), [[7]](https://github.com/v2fly/v2ray-core/pull/3651/files#diff-6d5f70c28dbc05b46b7773065ff1d592f2a10f50ad2af88d62bfc111bb76e436R190-R205), [[8]](https://github.com/v2fly/v2ray-core/pull/3651/files#diff-6d5f70c28dbc05b46b7773065ff1d592f2a10f50ad2af88d62bfc111bb76e436L145-R218), [[9]](https://github.com/v2fly/v2ray-core/pull/3651/files#diff-6d5f70c28dbc05b46b7773065ff1d592f2a10f50ad2af88d62bfc111bb76e436L160-R250), [[10]](https://github.com/v2fly/v2ray-core/pull/3651/files#diff-6d5f70c28dbc05b46b7773065ff1d592f2a10f50ad2af88d62bfc111bb76e436L188-R264))
  • Implemented listener application logic in ApplyListeners, which creates TCP listeners based on the configuration and starts accept loops for each. ([common/packetswitch/gvisorstack/tcp_listener.goR1-R84](https://github.com/v2fly/v2ray-core/pull/3651/files#diff-8eaabc0ad3338d7bfaee2f6aab569590d708ccfbb5ff755a0eea6ad12134caceR1-R84))
  • Integrated listener creation into stack initialization and ensured proper cleanup of listeners on stack closure. ([[1]](https://github.com/v2fly/v2ray-core/pull/3651/files#diff-e1402106b5770a215ecd84b3b5ea5973f90b0b1cafbfd76656aed4295f16fbd0R25-R26), [[2]](https://github.com/v2fly/v2ray-core/pull/3651/files#diff-e1402106b5770a215ecd84b3b5ea5973f90b0b1cafbfd76656aed4295f16fbd0R64-R67), [[3]](https://github.com/v2fly/v2ray-core/pull/3651/files#diff-e1402106b5770a215ecd84b3b5ea5973f90b0b1cafbfd76656aed4295f16fbd0R169-R172))

TCP connection handling:

  • Added connection accept and relay logic: accepted TCP connections are relayed bidirectionally to outbound handlers identified by tags, using the new handleTCPConn method. ([common/packetswitch/gvisorstack/tcp_listener.goR1-R84](https://github.com/v2fly/v2ray-core/pull/3651/files#diff-8eaabc0ad3338d7bfaee2f6aab569590d708ccfbb5ff755a0eea6ad12134caceR1-R84))

Outbound handler abstraction:

  • Introduced new outbound handler and listener abstractions in the abstactOutbount package, including error handling and context-aware connection management. ([[1]](https://github.com/v2fly/v2ray-core/pull/3651/files#diff-1d5a9a82ae3946b7e9573dfd0b8200f95af236bfd99788f07b628026ae0b2322R1-R9), [[2]](https://github.com/v2fly/v2ray-core/pull/3651/files#diff-2e7cbf8ca60ffe27ff05ae9bd589a01a7d2d64a4827bb5d4be01f91a9b2cfd4dR1-R133))

These changes collectively enable the stack to accept TCP connections on configurable addresses and ports, and relay them to tagged outbound handlers for further processing.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 0.67568% with 147 lines in your changes missing coverage. Please review.
✅ Project coverage is 22.88%. Comparing base (e93e5ac) to head (ff25cad).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
common/net/abstactOutbount/outbound.go 0.00% 61 Missing ⚠️
common/packetswitch/gvisorstack/tcp_listener.go 0.00% 42 Missing ⚠️
common/packetswitch/gvisorstack/config.pb.go 2.63% 37 Missing ⚠️
common/packetswitch/gvisorstack/stack.go 0.00% 5 Missing ⚠️
common/net/abstactOutbount/errors.generated.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3651      +/-   ##
==========================================
+ Coverage   22.37%   22.88%   +0.51%     
==========================================
  Files         864      867       +3     
  Lines       56065    47635    -8430     
==========================================
- Hits        12543    10901    -1642     
+ Misses      42265    35479    -6786     
+ Partials     1257     1255       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xiaokangwang xiaokangwang merged commit 62a9278 into v2fly:master Mar 14, 2026
40 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant