feat(socks5): add udp.resolveDomain option for clients incompatible with ATYP=Domain
Add a wrapper that intercepts WriteTo on the client-facing SOCKS5 UDP relay and resolves domain addresses to IPs before the SOCKS5 header is encoded. Controlled via the (or ) handler metadata flag. When enabled, SOCKS5 UDP response datagrams always carry ATYP=IPv4 or ATYP=IPv6 — never ATYP=Domain (0x03) — making them compatible with clients like tun2proxy and Surge that cannot parse domain-typed addresses in UDP. The wrapper resolves domains through the router's infrastructure: host mapper → resolver → system DNS fallback. Unresolvable domains cause the datagram to be silently dropped rather than forwarded in a format the client rejects. Fixes go-gost/gost#434
This commit is contained in:
@@ -26,6 +26,7 @@ type metadata struct {
|
||||
enableBind bool
|
||||
enableUDP bool
|
||||
udpBufferSize int
|
||||
udpResolveDomain bool
|
||||
compatibilityMode bool
|
||||
hash string
|
||||
muxCfg *mux.Config
|
||||
@@ -58,6 +59,7 @@ func (h *socks5Handler) parseMetadata(md mdata.Metadata) (err error) {
|
||||
h.md.enableBind = mdutil.GetBool(md, "bind")
|
||||
h.md.enableUDP = mdutil.GetBool(md, "udp")
|
||||
h.md.udpBufferSize = mdutil.GetInt(md, "udp.bufferSize", "udpBufferSize")
|
||||
h.md.udpResolveDomain = mdutil.GetBool(md, "udp.resolveDomain", "udpResolveDomain")
|
||||
|
||||
h.md.compatibilityMode = mdutil.GetBool(md, "comp")
|
||||
h.md.hash = mdutil.GetString(md, "hash")
|
||||
|
||||
Reference in New Issue
Block a user