mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-05-12 21:18:03 +08:00
fix: race at interfaceName setting
This commit is contained in:
parent
14217e7847
commit
e3d4ec2476
@ -88,21 +88,22 @@ func ListenPacket(ctx context.Context, network, address string, rAddrPort netip.
|
|||||||
if DefaultSocketHook != nil { // ignore interfaceName, routingMark when DefaultSocketHook not null (in CMFA)
|
if DefaultSocketHook != nil { // ignore interfaceName, routingMark when DefaultSocketHook not null (in CMFA)
|
||||||
socketHookToListenConfig(lc)
|
socketHookToListenConfig(lc)
|
||||||
} else {
|
} else {
|
||||||
if cfg.interfaceName == "" {
|
interfaceName := cfg.interfaceName
|
||||||
|
if interfaceName == "" {
|
||||||
if finder := DefaultInterfaceFinder.Load(); finder != nil {
|
if finder := DefaultInterfaceFinder.Load(); finder != nil {
|
||||||
cfg.interfaceName = finder.FindInterfaceName(rAddrPort.Addr())
|
interfaceName = finder.FindInterfaceName(rAddrPort.Addr())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if rAddrPort.Addr().Unmap().IsLoopback() {
|
if rAddrPort.Addr().Unmap().IsLoopback() {
|
||||||
// avoid "The requested address is not valid in its context."
|
// avoid "The requested address is not valid in its context."
|
||||||
cfg.interfaceName = ""
|
interfaceName = ""
|
||||||
}
|
}
|
||||||
if cfg.interfaceName != "" {
|
if interfaceName != "" {
|
||||||
bind := bindIfaceToListenConfig
|
bind := bindIfaceToListenConfig
|
||||||
if cfg.fallbackBind {
|
if cfg.fallbackBind {
|
||||||
bind = fallbackBindIfaceToListenConfig
|
bind = fallbackBindIfaceToListenConfig
|
||||||
}
|
}
|
||||||
addr, err := bind(cfg.interfaceName, lc, network, address, rAddrPort)
|
addr, err := bind(interfaceName, lc, network, address, rAddrPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -162,17 +163,18 @@ func dialContext(ctx context.Context, network string, destination netip.Addr, po
|
|||||||
if DefaultSocketHook != nil { // ignore interfaceName, routingMark and tfo when DefaultSocketHook not null (in CMFA)
|
if DefaultSocketHook != nil { // ignore interfaceName, routingMark and tfo when DefaultSocketHook not null (in CMFA)
|
||||||
socketHookToToDialer(dialer)
|
socketHookToToDialer(dialer)
|
||||||
} else {
|
} else {
|
||||||
if opt.interfaceName == "" {
|
interfaceName := opt.interfaceName // don't change the "opt", it's a pointer
|
||||||
|
if interfaceName == "" {
|
||||||
if finder := DefaultInterfaceFinder.Load(); finder != nil {
|
if finder := DefaultInterfaceFinder.Load(); finder != nil {
|
||||||
opt.interfaceName = finder.FindInterfaceName(destination)
|
interfaceName = finder.FindInterfaceName(destination)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if opt.interfaceName != "" {
|
if interfaceName != "" {
|
||||||
bind := bindIfaceToDialer
|
bind := bindIfaceToDialer
|
||||||
if opt.fallbackBind {
|
if opt.fallbackBind {
|
||||||
bind = fallbackBindIfaceToDialer
|
bind = fallbackBindIfaceToDialer
|
||||||
}
|
}
|
||||||
if err := bind(opt.interfaceName, dialer, network, destination); err != nil {
|
if err := bind(interfaceName, dialer, network, destination); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user