shawn1m / overture

A customized DNS relay server
MIT License
1.8k stars 284 forks source link

use udp protocol with socks5 proxy failed #61

Open jemyzhang opened 7 years ago

jemyzhang commented 7 years ago

Error:

WARN[0002] Dial DNS upstream with SOCKS5 proxy failed: proxy: no support for SOCKS5 proxy connections of type udp.

But I confirmed that the socks5 proxy is enabled with udp connections.

Configuration:

  "AlternativeDNS": [
    {
      "Name": "GoogleDNS",
      "Address": "8.8.8.8:53",
      "Protocol": "udp",
      "SOCKS5Address": "127.0.0.1:1080",
      "Timeout": 6,
      "EDNSClientSubnet": {
        "Policy": "auto",
        "ExternalIP": "xxx.xxx.xxx.xxx"
      }
    }
  ],
shawn1m commented 7 years ago

SOCKS5 来自于标准库中 net/proxy/socks5.go 的实现,并不支持 UDP。我简单搜索一了一下相关项目,还没有支持 UDP 的 SOCKS5 client 的实现,可能需要查阅 RFC 对源码进行修改。我近期比较忙可能没有空进行修改,可以暂时搁置一下。如果有哪位能将其实现,我会把它 merge 进 master 分支。

// Dial connects to the address addr on the given network via the SOCKS5 proxy.
func (s *socks5) Dial(network, addr string) (net.Conn, error) {
    switch network {
    case "tcp", "tcp6", "tcp4":
    default:
        return nil, errors.New("proxy: no support for SOCKS5 proxy connections of type " + network)
    }

    conn, err := s.forward.Dial(s.network, s.addr)
    if err != nil {
        return nil, err
    }
    if err := s.connect(conn, addr); err != nil {
        conn.Close()
        return nil, err
    }
    return conn, nil
}
jemyzhang commented 7 years ago
github.com/xtaci/kcp-go/sess.go:    udpconn, err := net.DialUDP("udp", nil, udpaddr)

不知道这个项目用到的DialUDP是哪个net库,标准库是没有看到这个接口。go不太懂,没找到他在哪里定义的

shawn1m commented 7 years ago

这个只是创建一个 UDPConn,不是实现 SOCKS5 的 UDP 支持。