Skip to content

Socks inbound: Fix stats for UDP Associate traffic - #7101

Merged
RPRX merged 2 commits into
XTLS:mainfrom
IvanTopGaming:fix/socks-udp-inbound-stats
Oct 8, 2026
Merged

RPRX merged 2 commits into
XTLS:mainfrom
IvanTopGaming:fix/socks-udp-inbound-stats

Conversation

@IvanTopGaming

Copy link
Copy Markdown
Contributor

SOCKS5 UDP ASSOCIATE creates a temporary UDP connection that bypasses the inbound stat.CounterConnection. UDP forwarding works, but inbound traffic statistics count only the TCP control handshake.

For a 1200-byte UDP request and a 700-byte response, the unpatched counters remain at 13/12 bytes. Including the SOCKS UDP headers, they should reach 1223/722 bytes.

Reuse the control connection's existing read/write counters when handling the temporary UDP connection. This preserves disabled statistics and the existing UDP source filtering and connection lifetime.

The regression test covers enabled/disabled inbound statistics, two UDP exchanges, exact byte counts, and rejection of a datagram from an unrelated source. It fails on current main without the fix and passes with it.

Validation:

  • go test ./proxy/socks -count=20
  • go test -race ./proxy/socks -count=1
  • go run ./infra/vformat/main.go -mode check -pwd ./

@RPRX
RPRX requested a review from Fangliding October 8, 2026 05:19

@Fangliding Fangliding left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个counter祸患无穷

patterniha pushed a commit to patterniha/Xray-core that referenced this pull request Oct 8, 2026
Early merge of XTLS#7101 (PR head 1c93878), squashed, ahead of
it landing upstream: XTLS#7101

Co-authored-by: 风扇滑翔翼 <[email protected]>
@RPRX RPRX changed the title SOCKS: Account for UDP association traffic in inbound stats Socks inbound: Fix stats for UDP Associate traffic Oct 8, 2026
@RPRX
RPRX merged commit 2a14c50 into XTLS:main Oct 8, 2026
fanymagnet pushed a commit to fanymagnet/Xray-core that referenced this pull request Oct 8, 2026
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.

3 participants