From 427a377c2a19aca095f1b39da332d5dc882f5033 Mon Sep 17 00:00:00 2001 From: YanceyChiew <35898533+YanceyChiew@users.noreply.github.com> 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() }