net/dns: exhaustively test DNS selection paths for linux.

Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson
2021-09-04 23:40:48 -07:00
parent c071bcda33
commit 10547d989d
4 changed files with 290 additions and 73 deletions

View File

@ -9,26 +9,19 @@ package dns
import (
"os/exec"
"tailscale.com/types/logger"
)
func getResolvConfVersion() ([]byte, error) {
return exec.Command("resolvconf", "--version").CombinedOutput()
}
func newResolvconfManager(logf logger.Logf, getResolvConfVersion func() ([]byte, error)) (OSConfigurator, error) {
_, err := getResolvConfVersion()
if err != nil {
func resolvconfStyle() string {
if _, err := exec.LookPath("resolvconf"); err != nil {
return ""
}
if _, err := exec.Command("resolvconf", "--version").CombinedOutput(); err != nil {
// Debian resolvconf doesn't understand --version, and
// exits with a specific error code.
if exitErr, ok := err.(*exec.ExitError); ok && exitErr.ExitCode() == 99 {
// Debian resolvconf doesn't understand --version, and
// exits with a specific error code.
return newDebianResolvconfManager(logf)
return "debian"
}
}
// If --version works, or we got some surprising error while
// probing, use openresolv. It's the more common implementation,
// so in cases where we can't figure things out, it's the least
// likely to misbehave.
return newOpenresolvManager()
// Treat everything else as openresolv, by far the more popular implementation.
return "openresolv"
}