Fix UDP port forward not working with Yggdrasil client

Signed-off-by: Vasyl Gello <vasek.gello@gmail.com>
This commit is contained in:
Vasyl Gello 2024-08-06 15:35:26 +03:00
parent 08f51fded2
commit bfc106637a

View file

@ -465,13 +465,16 @@ func main() {
for { for {
bytesRead, remoteUdpAddr, err := udpListenConn.ReadFrom(udpBuffer) bytesRead, remoteUdpAddr, err := udpListenConn.ReadFrom(udpBuffer)
if err != nil { if err != nil {
if bytesRead == 0 { logger.Debugf("udp readFrom error: %v", err)
continue }
} if bytesRead == 0 {
continue
} }
remoteUdpAddrStr := remoteUdpAddr.String() remoteUdpAddrStr := remoteUdpAddr.String()
var udpSession *UDPSession = nil
connVal, ok := remoteUdpConnections.Load(remoteUdpAddrStr) connVal, ok := remoteUdpConnections.Load(remoteUdpAddrStr)
if !ok { if !ok {
@ -481,17 +484,18 @@ func main() {
logger.Errorf("Failed to connect to %s: %s", mapping.Mapped, err) logger.Errorf("Failed to connect to %s: %s", mapping.Mapped, err)
continue continue
} }
udpSession := &UDPSession{ udpSession = &UDPSession{
conn: udpFwdConn, conn: udpFwdConn,
remoteAddr: remoteUdpAddr, remoteAddr: remoteUdpAddr,
} }
remoteUdpConnections.Store(remoteUdpAddrStr, udpSession) remoteUdpConnections.Store(remoteUdpAddrStr, udpSession)
go types.ReverseProxyUDP(mtu, udpListenConn, remoteUdpAddr, udpFwdConn) go types.ReverseProxyUDP(mtu, udpListenConn, remoteUdpAddr, udpFwdConn)
} } else {
udpSession, ok = connVal.(*UDPSession)
udpSession, ok := connVal.(*UDPSession) if !ok {
if !ok { continue
continue }
} }
udpFwdConnPtr := udpSession.conn.(*net.UDPConn) udpFwdConnPtr := udpSession.conn.(*net.UDPConn)