From 9bd834b34a8760adb2e31cbaed10da7121889c53 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sat, 2 Sep 2023 03:27:48 +0800 Subject: [PATCH] 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. --- listener/listener.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/listener/listener.go b/listener/listener.go index a340d3a2..9b4840e1 100644 --- a/listener/listener.go +++ b/listener/listener.go @@ -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() }