wgengine: flush DNS cache after major link change.

Windows has a public dns.Flush used in router_windows.go.
However that won't work for platforms like Linux, where
we need a different flush mechanism for resolved versus
other implementations.

We're instead adding a FlushCaches method to the dns Manager,
which can be made to work on all platforms as needed.

Fixes https://github.com/tailscale/tailscale/issues/2132

Signed-off-by: Denton Gentry <dgentry@tailscale.com>
This commit is contained in:
Denton Gentry
2021-09-18 20:33:21 -07:00
committed by Denton Gentry
parent 280c84e46a
commit 93c2882a2f
4 changed files with 32 additions and 2 deletions

View File

@@ -9,11 +9,20 @@ import (
"os/exec"
)
// Flush clears the local resolver cache.
func Flush() error {
func flushCaches() error {
out, err := exec.Command("ipconfig", "/flushdns").CombinedOutput()
if err != nil {
return fmt.Errorf("%v (output: %s)", err, out)
}
return nil
}
// Flush clears the local resolver cache.
//
// Only Windows has a public dns.Flush, needed in router_windows.go. Other
// platforms like Linux need a different flush implementation depending on
// the DNS manager. There is a FlushCaches method on the manager which
// can be used on all platforms.
func Flush() error {
return flushCaches()
}