Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routing rules should support source port matching #86

Closed
Vigilans opened this issue Aug 9, 2020 · 0 comments · Fixed by #87
Closed

Routing rules should support source port matching #86

Vigilans opened this issue Aug 9, 2020 · 0 comments · Fixed by #87

Comments

@Vigilans
Copy link
Contributor

Vigilans commented Aug 9, 2020

你正在使用哪个版本的 V2Ray?

4.27.0

你的使用场景是什么?

P2P类型的服务

你看到的不正常的现象是什么?

P2P服务里,两个主机的地位是对等的,因此当使用固定端口用于交互时,往往各自均会开放一个。由于目前V2Ray只有目标端口匹配,因此可能会出现一方流量直连,另一方流量代理(或更复杂)的现象。

以ZeroTier为例,其是一个构建虚拟局域网的服务,主要使用9993端口,用于在两个主机之间打洞、寻找通路。通过以下路由配置:

    {
      "type": "field",
      "network": "udp",
      "port": 9993,
      "outboundTag": "direct"
    }

可以不代理去向9993端口UDP流量,从而似乎可以保证建立的通道是直连的。但实际日志如下(由于几天前的日志丢失了,这里描述下大概流程……):

local:9993 -> remote:9993 [direct]
local:{dynamic} -> remote:9993 [direct]
local:9993 -> remote:{dynamic} [vps]

第三项从源9993端口到目标动态端口的流量被vps代理了,导致ZeroTier建立的通道不符合预期。最终在ZeroTier Central看到本地设备的Public IP变成了VPS的IP,而非本地运营商IP,也即P2P流量变成通过VPS中转,而非直连。

NTP服务也有这样的问题。尽管透明代理教程中都会设置UDP 123端口直连,但我也在日志中看到了ntpd服务(监听123端口)向远程服务器动态端口发送流量,同时被VPS代理了(虽然对时间同步来说,问题应该不大)。

你期待看到的正确表现是怎样的?

路由配置添加对于源端口匹配的支持,以能够让P2P服务的去程与回程行为一致,同时方便在透明代理中对于自己开放的服务(如SSH)进行路由管理。这也让端口与IP的匹配能力一致了(目前分别有"ip"与"source"以匹配目标ip与源ip)。

客户端配置

一份样例配置如下:

"routing": {
  "balancers": [
    {
      "tag": "zerotier",
      "selector": ["direct"] // for directly connecting two hosts
      // "selector": ["vps"] // for using vps as medium proxy tunnel
    }
  ],
  "rules": [
    {
      "type": "field",
      "network": "udp",
      "port": 9993,
      "balancerTag": "zerotier"
    },
    {
      "type": "field",
      "network": "udp",
      "sourcePort": 9993,
      "balancerTag": "zerotier"
    }
  ]
}
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 a pull request may close this issue.

1 participant