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 {
logger.Debugf("udp readFrom error: %v", err)
}
if bytesRead == 0 { if bytesRead == 0 {
continue 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,18 +484,19 @@ 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)
udpFwdConn := *udpFwdConnPtr udpFwdConn := *udpFwdConnPtr