mirror of
https://github.com/fosrl/newt.git
synced 2026-03-04 09:46:44 +00:00
Fix some ipv4 in v6 issues
This commit is contained in:
@@ -196,6 +196,11 @@ func (b *SharedBind) InjectPacket(data []byte, fromAddr netip.AddrPort) error {
|
|||||||
return net.ErrClosed
|
return net.ErrClosed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unmap IPv4-in-IPv6 addresses to ensure consistency with parsed endpoints
|
||||||
|
if fromAddr.Addr().Is4In6() {
|
||||||
|
fromAddr = netip.AddrPortFrom(fromAddr.Addr().Unmap(), fromAddr.Port())
|
||||||
|
}
|
||||||
|
|
||||||
// Track this endpoint as coming from netstack so responses go back the same way
|
// Track this endpoint as coming from netstack so responses go back the same way
|
||||||
// Use AddrPort directly as key (more efficient than string)
|
// Use AddrPort directly as key (more efficient than string)
|
||||||
b.netstackEndpoints.Store(fromAddr, struct{}{})
|
b.netstackEndpoints.Store(fromAddr, struct{}{})
|
||||||
@@ -471,6 +476,10 @@ func (b *SharedBind) receiveIPv4Batch(pc *ipv4.PacketConn, bufs [][]byte, sizes
|
|||||||
if b.ipv4Msgs[i].Addr != nil {
|
if b.ipv4Msgs[i].Addr != nil {
|
||||||
if udpAddr, ok := b.ipv4Msgs[i].Addr.(*net.UDPAddr); ok {
|
if udpAddr, ok := b.ipv4Msgs[i].Addr.(*net.UDPAddr); ok {
|
||||||
addrPort := udpAddr.AddrPort()
|
addrPort := udpAddr.AddrPort()
|
||||||
|
// Unmap IPv4-in-IPv6 addresses to ensure consistency with parsed endpoints
|
||||||
|
if addrPort.Addr().Is4In6() {
|
||||||
|
addrPort = netip.AddrPortFrom(addrPort.Addr().Unmap(), addrPort.Port())
|
||||||
|
}
|
||||||
eps[writeIdx] = &wgConn.StdNetEndpoint{AddrPort: addrPort}
|
eps[writeIdx] = &wgConn.StdNetEndpoint{AddrPort: addrPort}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -497,6 +506,10 @@ func (b *SharedBind) receiveIPv4Simple(conn *net.UDPConn, bufs [][]byte, sizes [
|
|||||||
sizes[0] = n
|
sizes[0] = n
|
||||||
if addr != nil {
|
if addr != nil {
|
||||||
addrPort := addr.AddrPort()
|
addrPort := addr.AddrPort()
|
||||||
|
// Unmap IPv4-in-IPv6 addresses to ensure consistency with parsed endpoints
|
||||||
|
if addrPort.Addr().Is4In6() {
|
||||||
|
addrPort = netip.AddrPortFrom(addrPort.Addr().Unmap(), addrPort.Port())
|
||||||
|
}
|
||||||
eps[0] = &wgConn.StdNetEndpoint{AddrPort: addrPort}
|
eps[0] = &wgConn.StdNetEndpoint{AddrPort: addrPort}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -538,7 +551,12 @@ func (b *SharedBind) handleMagicPacket(data []byte, addr *net.UDPAddr) bool {
|
|||||||
callbackPtr := b.magicResponseCallback.Load()
|
callbackPtr := b.magicResponseCallback.Load()
|
||||||
if callbackPtr != nil {
|
if callbackPtr != nil {
|
||||||
callback := *callbackPtr
|
callback := *callbackPtr
|
||||||
callback(addr.AddrPort(), echoData)
|
addrPort := addr.AddrPort()
|
||||||
|
// Unmap IPv4-in-IPv6 addresses to ensure consistency
|
||||||
|
if addrPort.Addr().Is4In6() {
|
||||||
|
addrPort = netip.AddrPortFrom(addrPort.Addr().Unmap(), addrPort.Port())
|
||||||
|
}
|
||||||
|
callback(addrPort, echoData)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -371,6 +371,10 @@ func (s *WireGuardService) runDirectUDPRelay(listener net.PacketConn) {
|
|||||||
var srcAddrPort netip.AddrPort
|
var srcAddrPort netip.AddrPort
|
||||||
if udpAddr, ok := remoteAddr.(*net.UDPAddr); ok {
|
if udpAddr, ok := remoteAddr.(*net.UDPAddr); ok {
|
||||||
srcAddrPort = udpAddr.AddrPort()
|
srcAddrPort = udpAddr.AddrPort()
|
||||||
|
// Unmap IPv4-in-IPv6 addresses to ensure consistency with parsed endpoints
|
||||||
|
if srcAddrPort.Addr().Is4In6() {
|
||||||
|
srcAddrPort = netip.AddrPortFrom(srcAddrPort.Addr().Unmap(), srcAddrPort.Port())
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.Debug("Unexpected address type in relay: %T", remoteAddr)
|
logger.Debug("Unexpected address type in relay: %T", remoteAddr)
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user