Skip to content

Commit 229b30d

Browse files
authored
drop unsupported domain address type in packet addr (v2fly#3186)
1 parent 05345cc commit 229b30d

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

common/net/packetaddr/connection_adaptor.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ func (c *packetConnectionAdaptor) ReadFrom(p []byte) (n int, addr gonet.Addr, er
7979
}
8080

8181
func (c *packetConnectionAdaptor) WriteTo(p []byte, addr gonet.Addr) (n int, err error) {
82+
_, ok := addr.(*gonet.UDPAddr)
83+
if !ok {
84+
// address other than UDPAddr is not supported, and will be dropped.
85+
return 0, nil
86+
}
8287
payloadLen := len(p)
8388
var buffer *buf.Buffer
8489
buffer, err = AttachAddressToPacket(buf.FromBytes(p), addr)

common/net/packetaddr/packetaddr.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package packetaddr
22

33
import (
44
"bytes"
5+
"github.com/v2fly/v2ray-core/v5/common/errors"
56
gonet "net"
67

78
"github.com/v2fly/v2ray-core/v5/common/buf"
@@ -45,6 +46,9 @@ func ExtractAddressFromPacket(data *buf.Buffer) (*buf.Buffer, gonet.Addr, error)
4546
if err != nil {
4647
return nil, nil, err
4748
}
49+
if address.Family().IsDomain() {
50+
return nil, nil, errors.New("invalid address type")
51+
}
4852
addr := &gonet.UDPAddr{
4953
IP: address.IP(),
5054
Port: int(port.Value()),

transport/internet/udp/dispatcher_packetaddr.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ func (p PacketAddrDispatcher) Dispatch(ctx context.Context, destination net.Dest
2727
if destination.Network != net.Network_UDP {
2828
return
2929
}
30+
31+
// Processing of domain address is unsupported as it adds unpredictable overhead, it will be dropped.
32+
if destination.Address.Family().IsDomain() {
33+
return
34+
}
35+
3036
p.conn.WriteTo(payload.Bytes(), &net.UDPAddr{IP: destination.Address.IP(), Port: int(destination.Port.Value())})
3137
}
3238

0 commit comments

Comments
 (0)