Fix DNS not revert while close tun

This commit is contained in:
eronez 2026-02-13 03:40:09 +00:00 committed by 世界
parent 5715a3919a
commit 1fb8456021
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -328,6 +328,7 @@ func (t *NativeTun) Close() error {
if t.options.EXP_ExternalConfiguration {
return common.Close(common.PtrOrNil(t.tunFile))
}
t.unsetSearchDomainForSystemdResolved()
t.unsetAddresses()
return E.Errors(t.unsetRoute(), t.unsetRules(), common.Close(common.PtrOrNil(t.tunFile)))
}
@ -1094,3 +1095,14 @@ func (t *NativeTun) setSearchDomainForSystemdResolved() {
_ = shell.Exec(ctlPath, append([]string{"dns", t.options.Name}, common.Map(dnsServer, netip.Addr.String)...)...).Run()
}()
}
func (t *NativeTun) unsetSearchDomainForSystemdResolved() {
if t.options.EXP_DisableDNSHijack {
return
}
ctlPath, err := exec.LookPath("resolvectl")
if err != nil {
return
}
_ = shell.Exec(ctlPath, "revert", t.options.Name).Run()
}