fix: some default value in dialer not restore in tun when config reload

This commit is contained in:
wwqgtxx 2025-03-10 11:10:39 +08:00
parent 4bd3ae52bd
commit c0de3c0e42
2 changed files with 17 additions and 2 deletions

View file

@ -512,6 +512,9 @@ func ReCreateTun(tunConf LC.Tun, tunnel C.Tunnel) {
}()
if tunConf.Equal(LastTunConf) {
if tunLister != nil { // some default value in dialer maybe changed when config reload, reset at here
tunLister.OnReload()
}
return
}

View file

@ -307,7 +307,7 @@ func New(options LC.Tun, tunnel C.Tunnel, additions ...inbound.Addition) (l *Lis
defaultInterfaceMonitor: defaultInterfaceMonitor,
}
if !dialer.DefaultInterfaceFinder.CompareAndSwap(nil, l.cDialerInterfaceFinder) {
err = E.New("don't allowed two tun listener using auto-detect-interface")
err = E.New("not allowed two tun listener using auto-detect-interface")
return
}
}
@ -450,7 +450,10 @@ func New(options LC.Tun, tunnel C.Tunnel, additions ...inbound.Addition) (l *Lis
}
if tunOptions.AutoRedirectMarkMode {
l.autoRedirectOutputMark = int32(outputMark)
dialer.DefaultRoutingMark.Store(l.autoRedirectOutputMark)
if !dialer.DefaultRoutingMark.CompareAndSwap(0, l.autoRedirectOutputMark) {
err = E.New("not allowed setting global routing-mark when working with autoRedirectMarkMode")
return
}
l.autoRedirect.UpdateRouteAddressSet()
l.ruleUpdateCallbackCloser = rpTunnel.RuleUpdateCallback().Register(l.ruleUpdateCallback)
}
@ -517,6 +520,15 @@ func (l *Listener) updateRule(ruleProvider provider.RuleProvider, exclude bool,
}
}
func (l *Listener) OnReload() {
if l.autoRedirectOutputMark != 0 {
dialer.DefaultRoutingMark.CompareAndSwap(0, l.autoRedirectOutputMark)
}
if l.cDialerInterfaceFinder != nil {
dialer.DefaultInterfaceFinder.CompareAndSwap(nil, l.cDialerInterfaceFinder)
}
}
type cDialerInterfaceFinder struct {
tunName string
defaultInterfaceMonitor tun.DefaultInterfaceMonitor