2021-04-11 06:31:00 +00:00
|
|
|
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
2020-07-14 13:12:00 +00:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2021-08-05 22:42:39 +00:00
|
|
|
//go:build linux || freebsd || openbsd
|
2021-04-29 19:34:34 +00:00
|
|
|
// +build linux freebsd openbsd
|
|
|
|
|
2020-07-31 20:27:09 +00:00
|
|
|
package dns
|
2020-07-14 13:12:00 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
2021-04-02 06:26:52 +00:00
|
|
|
|
|
|
|
"tailscale.com/types/logger"
|
2020-07-14 13:12:00 +00:00
|
|
|
)
|
|
|
|
|
2021-08-30 20:48:35 +00:00
|
|
|
func getResolvConfVersion() ([]byte, error) {
|
|
|
|
return exec.Command("resolvconf", "--version").CombinedOutput()
|
|
|
|
}
|
|
|
|
|
|
|
|
func newResolvconfManager(logf logger.Logf, getResolvConfVersion func() ([]byte, error)) (OSConfigurator, error) {
|
|
|
|
_, err := getResolvConfVersion()
|
2020-07-14 13:12:00 +00:00
|
|
|
if err != nil {
|
2021-04-11 06:31:00 +00:00
|
|
|
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)
|
2021-04-11 05:37:13 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-11 06:31:00 +00:00
|
|
|
// 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()
|
2020-07-14 13:12:00 +00:00
|
|
|
}
|