From a46bb152af91357b3509087cf9a312484a4ce60e Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Fri, 2 Jun 2023 21:16:49 +0700 Subject: [PATCH] cmd/ctrld: do not mutual net.Addr when spoofing client source IP Otherwise, the original address will be overwritten, causing the connection between the listener and dnsmasq broken. --- cmd/ctrld/dns_proxy.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/ctrld/dns_proxy.go b/cmd/ctrld/dns_proxy.go index 5b2e34b..3498556 100644 --- a/cmd/ctrld/dns_proxy.go +++ b/cmd/ctrld/dns_proxy.go @@ -423,9 +423,19 @@ func spoofRemoteAddr(addr net.Addr, ci *ctrld.ClientInfo) net.Addr { if ci != nil && ci.IP != "" { switch addr := addr.(type) { case *net.UDPAddr: - addr.IP = net.ParseIP(ci.IP) + udpAddr := &net.UDPAddr{ + IP: net.ParseIP(ci.IP), + Port: addr.Port, + Zone: addr.Zone, + } + return udpAddr case *net.TCPAddr: - addr.IP = net.ParseIP(ci.IP) + udpAddr := &net.TCPAddr{ + IP: net.ParseIP(ci.IP), + Port: addr.Port, + Zone: addr.Zone, + } + return udpAddr } } return addr