From 6521f02ff6df460fe79009441decbf2c5e9aa457 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 25 Mar 2021 17:40:52 -0700 Subject: [PATCH] Move DNS flush logic to net/dns. Signed-off-by: David Anderson --- net/dns/flush_windows.go | 19 +++++++++++++++++++ wgengine/router/router_windows.go | 9 +++------ 2 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 net/dns/flush_windows.go diff --git a/net/dns/flush_windows.go b/net/dns/flush_windows.go new file mode 100644 index 000000000..3c7e7d645 --- /dev/null +++ b/net/dns/flush_windows.go @@ -0,0 +1,19 @@ +// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package dns + +import ( + "fmt" + "os/exec" +) + +// Flush clears the local resolver cache. +func Flush() error { + out, err := exec.Command("ipconfig", "/flushdns").CombinedOutput() + if err != nil { + return fmt.Errorf("%v (output: %s)", err, out) + } + return nil +} diff --git a/wgengine/router/router_windows.go b/wgengine/router/router_windows.go index 935ab77db..cbe0ec316 100644 --- a/wgengine/router/router_windows.go +++ b/wgengine/router/router_windows.go @@ -22,8 +22,8 @@ import ( "golang.zx2c4.com/wireguard/windows/tunnel/winipcfg" "inet.af/netaddr" "tailscale.com/logtail/backoff" - "tailscale.com/types/logger" "tailscale.com/net/dns" + "tailscale.com/types/logger" ) type winRouter struct { @@ -112,11 +112,8 @@ func (r *winRouter) Set(cfg *Config) error { } // Flush DNS on router config change to clear cached DNS entries (solves #1430) - out, err := exec.Command("ipconfig", "/flushdns").CombinedOutput() - if err != nil { - r.logf("flushdns error: %v; output: %s", err, out) - } else { - r.logf("flushdns successful") + if err := dns.Flush(); err != nil { + r.logf("flushdns error: %v", err) } return nil