net/dns: create a new hosts file if it doesn't exist on Windows
A missing hosts file is not a fatal error. We should log it, but still proceed and create a new one instead of failing the DNS reconfiguration completely. Fixes #19733 Signed-off-by: Nick Khyl <nickk@tailscale.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"maps"
|
"maps"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"os"
|
"os"
|
||||||
@@ -246,7 +247,13 @@ func (m *windowsManager) setHosts(hosts []*HostEntry) error {
|
|||||||
}
|
}
|
||||||
hostsFile := filepath.Join(systemDir, "drivers", "etc", "hosts")
|
hostsFile := filepath.Join(systemDir, "drivers", "etc", "hosts")
|
||||||
b, err := os.ReadFile(hostsFile)
|
b, err := os.ReadFile(hostsFile)
|
||||||
if err != nil {
|
switch {
|
||||||
|
case err == nil:
|
||||||
|
// Continue.
|
||||||
|
case errors.Is(err, fs.ErrNotExist):
|
||||||
|
// Non-fatal, we'll just create a new hosts file.
|
||||||
|
m.logf("failed to read the hosts file: %v", err)
|
||||||
|
default:
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
outB, err := setTailscaleHosts(m.logf, b, hosts)
|
outB, err := setTailscaleHosts(m.logf, b, hosts)
|
||||||
|
|||||||
Reference in New Issue
Block a user