refactor: Decouple .Cleanup from ReCreateTun

The listener.Cleanup method will be called during
executor.Shutdown and route.restart, so it should serve
all kinds of listeners rather than a single tun device.

Currently listener.ReCreateTun will call it to handle
some internal affairs, This should be decoupled.

In this way, the cleanup tasks for data outside the
process life cycle that other listeners will add here
in the future will not be accidentally triggered
by configuring tun.
This commit is contained in:
gVisor bot 2023-09-02 03:27:48 +08:00
parent 76ea420764
commit 9bd834b34a

View file

@ -515,7 +515,6 @@ func ReCreateTun(tunConf LC.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- C.Pack
if err != nil {
log.Errorln("Start TUN listening error: %s", err.Error())
tunConf.Enable = false
Cleanup(false)
}
}()
@ -526,7 +525,7 @@ func ReCreateTun(tunConf LC.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- C.Pack
return
}
Cleanup(true)
closeTunListener()
if !tunConf.Enable {
return
@ -896,10 +895,13 @@ func hasTunConfigChange(tunConf *LC.Tun) bool {
return false
}
func Cleanup(wait bool) {
func closeTunListener() {
if tunLister != nil {
tunLister.Close()
tunLister = nil
}
LastTunConf = LC.Tun{}
}
func Cleanup(wait bool) {
closeTunListener()
}