Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop unsupported domain address type in packet addr #3186

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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

Check failure on line 5 in common/net/packetaddr/packetaddr.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed with -local github.com/v2fly/v2ray-core (goimports)
gonet "net"

"github.com/v2fly/v2ray-core/v5/common/buf"
Expand Down Expand Up @@ -45,6 +46,9 @@
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
Loading