@@ -165,7 +165,7 @@ func (h *associationHandler) HandleAssociation(ctx context.Context, clientConn n
165
165
166
166
connError := func () * onet.ConnectionError {
167
167
var payload []byte
168
- var tgtAddr net.Addr
168
+ var tgtAddr * net.UDPAddr
169
169
if targetConn == nil {
170
170
ip := clientConn .RemoteAddr ().(* net.UDPAddr ).AddrPort ().Addr ()
171
171
var textData []byte
@@ -211,7 +211,7 @@ func (h *associationHandler) HandleAssociation(ctx context.Context, clientConn n
211
211
}
212
212
213
213
debugUDP (l , "Proxy exit." )
214
- proxyTargetBytes , err = targetConn .WriteTo (payload , tgtAddr )
214
+ proxyTargetBytes , err = targetConn .WriteTo (payload , tgtAddr ) // accept only `net.UDPAddr` despite the signature
215
215
if err != nil {
216
216
return ensureConnectionError (err , "ERR_WRITE" , "Failed to write to target" )
217
217
}
@@ -229,7 +229,7 @@ func (h *associationHandler) HandleAssociation(ctx context.Context, clientConn n
229
229
230
230
// extractPayloadAndDestination processes a decrypted Shadowsocks UDP packet and
231
231
// extracts the payload data and destination address.
232
- func (h * associationHandler ) extractPayloadAndDestination (textData []byte ) ([]byte , net.Addr , * onet.ConnectionError ) {
232
+ func (h * associationHandler ) extractPayloadAndDestination (textData []byte ) ([]byte , * net.UDPAddr , * onet.ConnectionError ) {
233
233
tgtAddr := socks .SplitAddr (textData )
234
234
if tgtAddr == nil {
235
235
return nil , nil , onet .NewConnectionError ("ERR_READ_ADDRESS" , "Failed to get target address" , nil )
@@ -391,14 +391,22 @@ type validatingPacketConn struct {
391
391
}
392
392
393
393
func (vpc * validatingPacketConn ) WriteTo (p []byte , addr net.Addr ) (int , error ) {
394
- udpAddr , err := net .ResolveUDPAddr ("udp" , addr .String ())
395
- if err != nil {
396
- return 0 , fmt .Errorf ("failed to resolve target address %v" , udpAddr )
394
+ var (
395
+ udpAddr * net.UDPAddr
396
+ ok bool
397
+ )
398
+ if udpAddr , ok = addr .(* net.UDPAddr ); ! ok {
399
+ var err error
400
+ udpAddr , err = net .ResolveUDPAddr ("udp" , addr .String ())
401
+ if err != nil {
402
+ return 0 , fmt .Errorf ("failed to resolve target address %v" , addr )
403
+ }
397
404
}
398
405
if err := vpc .targetIPValidator (udpAddr .IP ); err != nil {
399
406
return 0 , ensureConnectionError (err , "ERR_ADDRESS_INVALID" , "invalid address" )
400
407
}
401
- return vpc .PacketConn .WriteTo (p , addr )
408
+
409
+ return vpc .PacketConn .WriteTo (p , udpAddr ) // accept only `net.UDPAddr` despite the signature
402
410
}
403
411
404
412
type timedPacketConn struct {
0 commit comments