Skip to content

Commit

Permalink
Fix SOCKS5 UDP ASSOCIATE bind address
Browse files Browse the repository at this point in the history
  • Loading branch information
dyhkwong committed Dec 10, 2024
1 parent 809d8ec commit 08c203c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions protocol/socks/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ func ClientHandshake5(conn io.ReadWriter, command byte, destination M.Socksaddr,
} else if authResponse.Method != socks5.AuthTypeNotRequired {
return socks5.Response{}, E.New("socks5: unsupported auth method: ", authResponse.Method)
}
if command == socks5.CommandUDPAssociate {
destination = M.SocksaddrFrom(netip.IPv4Unspecified(), 0)
}
err = socks5.WriteRequest(conn, socks5.Request{
Command: command,
Destination: destination,
Expand Down Expand Up @@ -259,15 +262,16 @@ func HandleConnectionEx(
done := make(chan struct{})
go func() {
//nolint:staticcheck
innerError = handler.NewPacketConnection(ctx, associatePacketConn, M.Metadata{Protocol: "socks5", Source: source, Destination: destination})
innerError = handler.NewPacketConnection(ctx, associatePacketConn, M.Metadata{Protocol: "socks5", Source: source, Destination: M.SocksaddrFrom(netip.IPv4Unspecified(), 0)})
close(done)
}()
err = common.Error(io.Copy(io.Discard, conn))
associatePacketConn.Close()
<-done
return E.Errors(innerError, err)
} else {
handlerEx.NewPacketConnectionEx(ctx, NewLazyAssociatePacketConn(bufio.NewServerPacketConn(udpConn), destination, conn), source, destination, onClose)
destination = request.Destination
handlerEx.NewPacketConnectionEx(ctx, NewLazyAssociatePacketConn(bufio.NewServerPacketConn(udpConn), destination, conn), source, M.SocksaddrFrom(netip.IPv4Unspecified(), 0), onClose)
return nil
}
default:
Expand Down

0 comments on commit 08c203c

Please sign in to comment.