Skip to content

Commit

Permalink
drop unsupported domain address type in packet addr (#3186)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaokangwang authored Oct 12, 2024
1 parent 05345cc commit 229b30d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions common/net/packetaddr/connection_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ func (c *packetConnectionAdaptor) ReadFrom(p []byte) (n int, addr gonet.Addr, er
}

func (c *packetConnectionAdaptor) WriteTo(p []byte, addr gonet.Addr) (n int, err error) {
_, ok := addr.(*gonet.UDPAddr)
if !ok {
// address other than UDPAddr is not supported, and will be dropped.
return 0, nil
}
payloadLen := len(p)
var buffer *buf.Buffer
buffer, err = AttachAddressToPacket(buf.FromBytes(p), addr)
Expand Down
4 changes: 4 additions & 0 deletions common/net/packetaddr/packetaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package packetaddr

import (
"bytes"
"github.com/v2fly/v2ray-core/v5/common/errors"
gonet "net"

"github.com/v2fly/v2ray-core/v5/common/buf"
Expand Down Expand Up @@ -45,6 +46,9 @@ func ExtractAddressFromPacket(data *buf.Buffer) (*buf.Buffer, gonet.Addr, error)
if err != nil {
return nil, nil, err
}
if address.Family().IsDomain() {
return nil, nil, errors.New("invalid address type")
}
addr := &gonet.UDPAddr{
IP: address.IP(),
Port: int(port.Value()),
Expand Down
6 changes: 6 additions & 0 deletions transport/internet/udp/dispatcher_packetaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ func (p PacketAddrDispatcher) Dispatch(ctx context.Context, destination net.Dest
if destination.Network != net.Network_UDP {
return
}

// Processing of domain address is unsupported as it adds unpredictable overhead, it will be dropped.
if destination.Address.Family().IsDomain() {
return
}

p.conn.WriteTo(payload.Bytes(), &net.UDPAddr{IP: destination.Address.IP(), Port: int(destination.Port.Value())})
}

Expand Down

0 comments on commit 229b30d

Please sign in to comment.