mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-09-15 22:10:26 +00:00
Transport: Bind the UDP outbound socket in the destination family (#6688)
https://github.com/XTLS/Xray-core/pull/6688#issuecomment-5445559197 Completes https://github.com/XTLS/Xray-core/pull/6624#issuecomment-5430488664 --------- Co-authored-by: 风扇滑翔翼 <Fangliding.fshxy@outlook.com>
This commit is contained in:
co-authored by
风扇滑翔翼
parent
ada99a4eb0
commit
540b9070f5
@@ -50,18 +50,24 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
|
|||||||
errors.LogDebug(ctx, "dialing to "+dest.String())
|
errors.LogDebug(ctx, "dialing to "+dest.String())
|
||||||
|
|
||||||
if dest.Network == net.Network_UDP {
|
if dest.Network == net.Network_UDP {
|
||||||
srcAddr := resolveSrcAddr(net.Network_UDP, src)
|
|
||||||
if srcAddr == nil {
|
|
||||||
srcAddr = &net.UDPAddr{
|
|
||||||
IP: []byte{0, 0, 0, 0},
|
|
||||||
Port: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var lc net.ListenConfig
|
|
||||||
destAddr, err := net.ResolveUDPAddr("udp", dest.NetAddr())
|
destAddr, err := net.ResolveUDPAddr("udp", dest.NetAddr())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
srcAddr := resolveSrcAddr(net.Network_UDP, src)
|
||||||
|
if srcAddr == nil {
|
||||||
|
// some OS don't support mapped IPv4 dual stack
|
||||||
|
// and need to select 0.0.0.0 or [::] manually based on the destination
|
||||||
|
wildcard := net.AnyIP.IP()
|
||||||
|
if destAddr.IP.To4() == nil {
|
||||||
|
wildcard = net.AnyIPv6.IP()
|
||||||
|
}
|
||||||
|
srcAddr = &net.UDPAddr{
|
||||||
|
IP: wildcard,
|
||||||
|
Port: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var lc net.ListenConfig
|
||||||
lc.Control = func(network, address string, c syscall.RawConn) error {
|
lc.Control = func(network, address string, c syscall.RawConn) error {
|
||||||
for _, ctl := range Controllers {
|
for _, ctl := range Controllers {
|
||||||
if err := ctl(network, address, c); err != nil {
|
if err := ctl(network, address, c); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user