Skip to content

Commit

Permalink
Fix UDP port forward not working with Yggdrasil client
Browse files Browse the repository at this point in the history
Signed-off-by: Vasyl Gello <[email protected]>
  • Loading branch information
basilgello committed Aug 6, 2024
1 parent 08f51fd commit 04e3769
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions cmd/yggstack/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,16 @@ func main() {
for {
bytesRead, remoteUdpAddr, err := udpListenConn.ReadFrom(udpBuffer)
if err != nil {
if bytesRead == 0 {
continue
}
logger.Debugf("udp readFrom error: %v", err)
}
if bytesRead == 0 {
continue
}

remoteUdpAddrStr := remoteUdpAddr.String()

var udpSession *UDPSession = nil

connVal, ok := remoteUdpConnections.Load(remoteUdpAddrStr)

if !ok {
Expand All @@ -481,23 +484,24 @@ func main() {
logger.Errorf("Failed to connect to %s: %s", mapping.Mapped, err)
continue
}
udpSession := &UDPSession{
udpSession = &UDPSession{
conn: udpFwdConn,
remoteAddr: remoteUdpAddr,
}
remoteUdpConnections.Store(remoteUdpAddrStr, udpSession)
go types.ReverseProxyUDP(mtu, udpListenConn, remoteUdpAddr, udpFwdConn)
}
} else {
udpSession, ok = connVal.(*UDPSession)

udpSession, ok := connVal.(*UDPSession)
if !ok {
continue
if !ok {
continue
}
}

udpFwdConnPtr := udpSession.conn.(*net.UDPConn)
udpFwdConn := *udpFwdConnPtr

_, err = udpFwdConn.Write(udpBuffer[:bytesRead])
bytesWritten, err := udpFwdConn.Write(udpBuffer[:bytesRead])
if err != nil {
logger.Debugf("Cannot write from yggdrasil to udp listener: %q", err)
udpFwdConn.Close()
Expand Down

0 comments on commit 04e3769

Please sign in to comment.