[client] Fix IPv4-only in bind proxy (#5154)

This commit is contained in:
Viktor Liu
2026-01-23 22:15:34 +08:00
committed by GitHub
parent 269d5d1cba
commit 1a32e4c223
2 changed files with 21 additions and 6 deletions

View File

@@ -117,16 +117,29 @@ func (p *ProxyBind) RedirectAs(endpoint *net.UDPAddr) {
p.pausedCond.L.Lock() p.pausedCond.L.Lock()
p.paused = false p.paused = false
p.wgCurrentUsed = addrToEndpoint(endpoint) ep, err := addrToEndpoint(endpoint)
if err != nil {
log.Errorf("failed to convert endpoint address: %v", err)
} else {
p.wgCurrentUsed = ep
}
p.pausedCond.Signal() p.pausedCond.Signal()
p.pausedCond.L.Unlock() p.pausedCond.L.Unlock()
} }
func addrToEndpoint(addr *net.UDPAddr) *bind.Endpoint { func addrToEndpoint(addr *net.UDPAddr) (*bind.Endpoint, error) {
ip, _ := netip.AddrFromSlice(addr.IP.To4()) if addr == nil {
addrPort := netip.AddrPortFrom(ip, uint16(addr.Port)) return nil, errors.New("nil address")
return &bind.Endpoint{AddrPort: addrPort} }
ip, ok := netip.AddrFromSlice(addr.IP)
if !ok {
return nil, fmt.Errorf("convert %s to netip.Addr", addr)
}
addrPort := netip.AddrPortFrom(ip.Unmap(), uint16(addr.Port))
return &bind.Endpoint{AddrPort: addrPort}, nil
} }
func (p *ProxyBind) CloseConn() error { func (p *ProxyBind) CloseConn() error {

View File

@@ -94,7 +94,9 @@ func (p *ProxyWrapper) RedirectAs(endpoint *net.UDPAddr) {
p.pausedCond.L.Lock() p.pausedCond.L.Lock()
p.paused = false p.paused = false
p.wgEndpointCurrentUsedAddr = endpoint if endpoint != nil && endpoint.IP != nil {
p.wgEndpointCurrentUsedAddr = endpoint
}
p.pausedCond.Signal() p.pausedCond.Signal()
p.pausedCond.L.Unlock() p.pausedCond.L.Unlock()