From f1c81557dcf8251e98f5a474931473dfa630fc1a Mon Sep 17 00:00:00 2001 From: cty123 Date: Tue, 14 Nov 2023 00:00:04 +0100 Subject: [PATCH] #2605: Add safety check for type casting for QUIC dialer Issue #2605 brought up real problem that QUIC dialer doesn't support sockopt at the moment. Inside `internet.DialSystem(...)` function, one of the branch that involves `redirect(...)` returns `cnc.connection` instance that is currently unhandled by the code logic, and thus caused program panic during runtime. It seems the sockopt support for QUIC protocol requires a couple changes including making `cnc.connection` public, such that we can handle in dialer, along with some thorough tests, this commit simply adds safety check to explicity state the fact that QUIC isn't working with sockopt. And the implementation of the feature can be scheduled later on. --- transport/internet/quic/dialer.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/transport/internet/quic/dialer.go b/transport/internet/quic/dialer.go index 1358dac7..c6bc08aa 100644 --- a/transport/internet/quic/dialer.go +++ b/transport/internet/quic/dialer.go @@ -146,10 +146,19 @@ func (s *clientConnections) openConnection(ctx context.Context, destAddr net.Add return qlog.NewConnectionTracer(&QlogWriter{connID: ci}, p, ci) }, } - udpConn, _ := rawConn.(*net.UDPConn) - if udpConn == nil { - udpConn = rawConn.(*internet.PacketConnWrapper).Conn.(*net.UDPConn) + + var udpConn *net.UDPConn + switch conn := rawConn.(type) { + case *net.UDPConn: + udpConn = conn + case *internet.PacketConnWrapper: + udpConn = conn.Conn.(*net.UDPConn) + default: + // TODO: Support sockopt for QUIC + rawConn.Close() + return nil, newError("QUIC with sockopt is unsupported").AtWarning() } + sysConn, err := wrapSysConn(udpConn, config) if err != nil { rawConn.Close()