Refactor: use native Win32 API to detect interface changed on Windows
This commit is contained in:
@ -385,7 +385,13 @@ func ReCreateTun(tunConf *config.Tun, tcpIn chan<- C.ConnContext, udpIn chan<- *
|
||||
return
|
||||
}
|
||||
|
||||
tunStackListener, err = tun.New(tunConf, tunAddressPrefix, tcpIn, udpIn)
|
||||
callback := &tunChangeCallback{
|
||||
tunConf: *tunConf,
|
||||
tcpIn: tcpIn,
|
||||
udpIn: udpIn,
|
||||
}
|
||||
|
||||
tunStackListener, err = tun.New(tunConf, tunAddressPrefix, tcpIn, udpIn, callback)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -563,6 +569,24 @@ func hasTunConfigChange(tunConf *config.Tun, tunAddressPrefix *netip.Prefix) boo
|
||||
return false
|
||||
}
|
||||
|
||||
type tunChangeCallback struct {
|
||||
tunConf config.Tun
|
||||
tcpIn chan<- C.ConnContext
|
||||
udpIn chan<- *inbound.PacketAdapter
|
||||
}
|
||||
|
||||
func (t *tunChangeCallback) Pause() {
|
||||
conf := t.tunConf
|
||||
conf.Enable = false
|
||||
ReCreateTun(&conf, t.tcpIn, t.udpIn)
|
||||
}
|
||||
|
||||
func (t *tunChangeCallback) Resume() {
|
||||
conf := t.tunConf
|
||||
conf.Enable = true
|
||||
ReCreateTun(&conf, t.tcpIn, t.udpIn)
|
||||
}
|
||||
|
||||
func initCert() error {
|
||||
if _, err := os.Stat(C.Path.RootCA()); os.IsNotExist(err) {
|
||||
log.Infoln("Can't find mitm_ca.crt, start generate")
|
||||
|
Reference in New Issue
Block a user