mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-01 19:26:39 +00:00
Dialer: Do not use ListenSystemPacket() when dialing UDP
https://github.com/XTLS/Xray-core/pull/4530#issuecomment-2765744961
This commit is contained in:
parent
17207fc5e4
commit
8284a0ef8f
@ -59,7 +59,17 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
|
||||
Port: 0,
|
||||
}
|
||||
}
|
||||
packetConn, err := ListenSystemPacket(ctx, srcAddr, sockopt)
|
||||
var lc net.ListenConfig
|
||||
lc.Control = func(network, address string, c syscall.RawConn) error {
|
||||
return c.Control(func(fd uintptr) {
|
||||
if sockopt != nil {
|
||||
if err := applyOutboundSocketOptions(network, "", fd, sockopt); err != nil {
|
||||
errors.LogInfo(ctx, err, "failed to apply socket options")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
packetConn, err := lc.ListenPacket(ctx, srcAddr.Network(), srcAddr.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -67,23 +77,6 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if sockopt != nil {
|
||||
sys, err := packetConn.(*net.UDPConn).SyscallConn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sys.Control(func(fd uintptr) {
|
||||
var network string
|
||||
if destAddr.IP.To4() != nil {
|
||||
network = "udp4"
|
||||
} else {
|
||||
network = "udp6"
|
||||
}
|
||||
if err := applyOutboundSocketOptions(network, dest.NetAddr(), fd, sockopt); err != nil {
|
||||
errors.LogInfo(ctx, err, "failed to apply socket options")
|
||||
}
|
||||
})
|
||||
}
|
||||
return &PacketConnWrapper{
|
||||
Conn: packetConn,
|
||||
Dest: destAddr,
|
||||
|
Loading…
x
Reference in New Issue
Block a user