mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-09-08 02:08:48 +08:00
Fix domain strategy not taking effect
This commit is contained in:
parent
980e96250b
commit
649163cb7b
@ -13,7 +13,6 @@ import (
|
|||||||
C "github.com/sagernet/sing-box/constant"
|
C "github.com/sagernet/sing-box/constant"
|
||||||
"github.com/sagernet/sing-box/log"
|
"github.com/sagernet/sing-box/log"
|
||||||
"github.com/sagernet/sing-box/option"
|
"github.com/sagernet/sing-box/option"
|
||||||
"github.com/sagernet/sing/common"
|
|
||||||
"github.com/sagernet/sing/common/bufio"
|
"github.com/sagernet/sing/common/bufio"
|
||||||
E "github.com/sagernet/sing/common/exceptions"
|
E "github.com/sagernet/sing/common/exceptions"
|
||||||
"github.com/sagernet/sing/common/logger"
|
"github.com/sagernet/sing/common/logger"
|
||||||
@ -164,26 +163,7 @@ func (h *Outbound) DialParallel(ctx context.Context, network string, destination
|
|||||||
case N.NetworkUDP:
|
case N.NetworkUDP:
|
||||||
h.logger.InfoContext(ctx, "outbound packet connection to ", destination)
|
h.logger.InfoContext(ctx, "outbound packet connection to ", destination)
|
||||||
}
|
}
|
||||||
var domainStrategy C.DomainStrategy
|
return dialer.DialParallelNetwork(ctx, h.dialer, network, destination, destinationAddresses, len(destinationAddresses) > 0 && destinationAddresses[0].Is6(), nil, nil, nil, h.fallbackDelay)
|
||||||
if h.domainStrategy != C.DomainStrategyAsIS {
|
|
||||||
domainStrategy = h.domainStrategy
|
|
||||||
} else {
|
|
||||||
//nolint:staticcheck
|
|
||||||
domainStrategy = C.DomainStrategy(metadata.InboundOptions.DomainStrategy)
|
|
||||||
}
|
|
||||||
switch domainStrategy {
|
|
||||||
case C.DomainStrategyIPv4Only:
|
|
||||||
destinationAddresses = common.Filter(destinationAddresses, netip.Addr.Is4)
|
|
||||||
if len(destinationAddresses) == 0 {
|
|
||||||
return nil, E.New("no IPv4 address available for ", destination)
|
|
||||||
}
|
|
||||||
case C.DomainStrategyIPv6Only:
|
|
||||||
destinationAddresses = common.Filter(destinationAddresses, netip.Addr.Is6)
|
|
||||||
if len(destinationAddresses) == 0 {
|
|
||||||
return nil, E.New("no IPv6 address available for ", destination)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dialer.DialParallelNetwork(ctx, h.dialer, network, destination, destinationAddresses, domainStrategy == C.DomainStrategyPreferIPv6, nil, nil, nil, h.fallbackDelay)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Outbound) DialParallelNetwork(ctx context.Context, network string, destination M.Socksaddr, destinationAddresses []netip.Addr, networkStrategy *C.NetworkStrategy, networkType []C.InterfaceType, fallbackNetworkType []C.InterfaceType, fallbackDelay time.Duration) (net.Conn, error) {
|
func (h *Outbound) DialParallelNetwork(ctx context.Context, network string, destination M.Socksaddr, destinationAddresses []netip.Addr, networkStrategy *C.NetworkStrategy, networkType []C.InterfaceType, fallbackNetworkType []C.InterfaceType, fallbackDelay time.Duration) (net.Conn, error) {
|
||||||
@ -204,26 +184,7 @@ func (h *Outbound) DialParallelNetwork(ctx context.Context, network string, dest
|
|||||||
case N.NetworkUDP:
|
case N.NetworkUDP:
|
||||||
h.logger.InfoContext(ctx, "outbound packet connection to ", destination)
|
h.logger.InfoContext(ctx, "outbound packet connection to ", destination)
|
||||||
}
|
}
|
||||||
var domainStrategy C.DomainStrategy
|
return dialer.DialParallelNetwork(ctx, h.dialer, network, destination, destinationAddresses, len(destinationAddresses) > 0 && destinationAddresses[0].Is6(), networkStrategy, networkType, fallbackNetworkType, fallbackDelay)
|
||||||
if h.domainStrategy != C.DomainStrategyAsIS {
|
|
||||||
domainStrategy = h.domainStrategy
|
|
||||||
} else {
|
|
||||||
//nolint:staticcheck
|
|
||||||
domainStrategy = C.DomainStrategy(metadata.InboundOptions.DomainStrategy)
|
|
||||||
}
|
|
||||||
switch domainStrategy {
|
|
||||||
case C.DomainStrategyIPv4Only:
|
|
||||||
destinationAddresses = common.Filter(destinationAddresses, netip.Addr.Is4)
|
|
||||||
if len(destinationAddresses) == 0 {
|
|
||||||
return nil, E.New("no IPv4 address available for ", destination)
|
|
||||||
}
|
|
||||||
case C.DomainStrategyIPv6Only:
|
|
||||||
destinationAddresses = common.Filter(destinationAddresses, netip.Addr.Is6)
|
|
||||||
if len(destinationAddresses) == 0 {
|
|
||||||
return nil, E.New("no IPv6 address available for ", destination)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dialer.DialParallelNetwork(ctx, h.dialer, network, destination, destinationAddresses, domainStrategy == C.DomainStrategyPreferIPv6, networkStrategy, networkType, fallbackNetworkType, fallbackDelay)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Outbound) ListenSerialNetworkPacket(ctx context.Context, destination M.Socksaddr, destinationAddresses []netip.Addr, networkStrategy *C.NetworkStrategy, networkType []C.InterfaceType, fallbackNetworkType []C.InterfaceType, fallbackDelay time.Duration) (net.PacketConn, netip.Addr, error) {
|
func (h *Outbound) ListenSerialNetworkPacket(ctx context.Context, destination M.Socksaddr, destinationAddresses []netip.Addr, networkStrategy *C.NetworkStrategy, networkType []C.InterfaceType, fallbackNetworkType []C.InterfaceType, fallbackDelay time.Duration) (net.PacketConn, netip.Addr, error) {
|
||||||
|
@ -675,11 +675,6 @@ func (r *Router) actionResolve(ctx context.Context, metadata *adapter.InboundCon
|
|||||||
}
|
}
|
||||||
metadata.DestinationAddresses = addresses
|
metadata.DestinationAddresses = addresses
|
||||||
r.logger.DebugContext(ctx, "resolved [", strings.Join(F.MapToString(metadata.DestinationAddresses), " "), "]")
|
r.logger.DebugContext(ctx, "resolved [", strings.Join(F.MapToString(metadata.DestinationAddresses), " "), "]")
|
||||||
if metadata.Destination.IsIPv4() {
|
|
||||||
metadata.IPVersion = 4
|
|
||||||
} else if metadata.Destination.IsIPv6() {
|
|
||||||
metadata.IPVersion = 6
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user