v2ray-core icon indicating copy to clipboard operation
v2ray-core copied to clipboard

Feat: [app/proxyman] [proxy/dokodemo, socks] More accurate inbound gateway detection and behaviors

Open Vigilans opened this issue 3 years ago • 1 comments

In a session context's inbound information we have a Gateway field indicating which inbound listener the connection is from.

Currently, the Gateway field is always set to the tcp/udp worker's configured address and ports, which can be vague and unhelpful when the address is a wildcard 0.0.0.0.

This PR improves the detection of the actual packet destination address when the configured address is 0.0.0.0 or ::, and utilize the accurate gateway address to improve following inbound proxy's behavior:

SOCKS

When UdpAssociate address is unspecified, it returns inbound's gateway address. However if returned address is 0.0.0.0, the client would not send udp packets back to the server.

https://github.com/v2fly/v2ray-core/pull/522 described this issue and solved it by specially handling the wildcard address in the client side. By obtaining the accurate gateway address, we could solve this issue in the server side, to make compatible a wider range of SOCKS clients.

Dokodemo Door

When in transparent proxy mode, the destination will always be rewritten and the forward address in dokodemo's config is not used. However one may expect a following use case:

When setting up v2ray as the main DNS server, the main dokodemo inbound (port 53) could work in both forward mode and transparent proxy mode:

  • If the packet target is v2ray instance itself, serve as a normal DNS server, and forward any non A and AAAA requests (e.g. PTR) to the configured forward address (e.g. 127.0.0.11 in docker container).
  • If the packet target is not v2ray itself (gets redirected by transparent proxy), serve as transparent proxying DNS server, and forward any non A and AAAA requests to its original destination.

Therefore, by utilizing the accurate gateway address, the dokodemo inbound may not overwrite the destination if the packet target is dokodemo itself, therefore reusing the default forward address and working as a non-tproxy server.

Vigilans avatar Sep 12 '22 11:09 Vigilans

Codecov Report

Base: 38.88% // Head: 38.72% // Decreases project coverage by -0.15% :warning:

Coverage data is based on head (5be0b29) compared to base (2e0ea88). Patch coverage: 16.21% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1976      +/-   ##
==========================================
- Coverage   38.88%   38.72%   -0.16%     
==========================================
  Files         616      608       -8     
  Lines       36336    36276      -60     
==========================================
- Hits        14128    14048      -80     
- Misses      20630    20655      +25     
+ Partials     1578     1573       -5     
Impacted Files Coverage Δ
app/proxyman/inbound/dynamic.go 0.00% <0.00%> (ø)
infra/conf/v5cfg/inbound.go 0.00% <0.00%> (ø)
proxy/dokodemo/dokodemo.go 55.20% <0.00%> (ø)
infra/conf/v4/v2ray.go 37.58% <5.88%> (-1.64%) :arrow_down:
app/proxyman/inbound/worker.go 36.61% <28.57%> (-0.54%) :arrow_down:
app/proxyman/inbound/always.go 55.65% <45.45%> (+2.01%) :arrow_up:
app/router/command/errors.generated.go 0.00% <0.00%> (-100.00%) :arrow_down:
testing/servers/tcp/tcp.go 81.81% <0.00%> (-5.46%) :arrow_down:
testing/scenarios/common.go 75.00% <0.00%> (-4.29%) :arrow_down:
transport/internet/udp/hub.go 73.61% <0.00%> (-4.17%) :arrow_down:
... and 18 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov-commenter avatar Sep 12 '22 11:09 codecov-commenter

It has been open 120 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Feb 18 '23 02:02 github-actions[bot]

It has been open 120 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Jul 01 '23 02:07 github-actions[bot]