ginuerzh / gost

GO Simple Tunnel - a simple tunnel written in golang
MIT License
15.45k stars 2.42k forks source link

use outgoing interface's IP for UDP relay port #1030

Closed ge9 closed 2 weeks ago

ge9 commented 2 weeks ago

(resending without an unnecessary file; cf. https://github.com/ginuerzh/gost/pull/1029) Currently relay ports for SOCKS UDP associate are obtained with nil ([::]:0), and then replied to clients with the IP replaced by TCP local address. My implementation uses the TCP local address instead of nil when getting UDP relay ports. This solves possible problems in situations where the SOCKS server can be seen through more than one IP addresses. For example, if we use some external interface address (like 10.0.0.1) to access gost SOCKS5 proxy running on the same machine as client, only my implementation will work, because current implementation will send back UDP packets using localhost (127.0.0.1), which is different from the replied relay port. Also, the current implementation typically replies IPv4-mapped IPv6 address to IPv4 clients (like ::ffff:10.0.0.1), which is incompatible with redsocks (https://github.com/semigodking/redsocks) which is one of the most widely-used transparent SOCKS5 proxy clients. My implementation will also fix this.