net/dns: teach the openresolv manager to read DNS config.

Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson
2021-04-10 19:37:11 -07:00
parent 19eca34f47
commit 61b361bac0
2 changed files with 36 additions and 11 deletions

View File

@@ -8,6 +8,7 @@ import (
"bytes"
"fmt"
"os/exec"
"strings"
)
// resolvconfIsOpenresolv reports whether the `resolvconf` binary on
@@ -48,7 +49,26 @@ func (m openresolvManager) SupportsSplitDNS() bool {
}
func (m openresolvManager) GetBaseConfig() (OSConfig, error) {
return OSConfig{}, ErrGetBaseConfigNotSupported
bs, err := exec.Command("resolvconf", "-i").CombinedOutput()
if err != nil {
return OSConfig{}, err
}
args := []string{"-l"}
for _, f := range strings.Split(strings.TrimSpace(string(bs)), " ") {
if f == "tailscale" {
continue
}
args = append(args, f)
}
var buf bytes.Buffer
cmd := exec.Command("resolvconf", args...)
cmd.Stdout = &buf
if err := cmd.Run(); err != nil {
return OSConfig{}, err
}
return readResolv(&buf)
}
func (m openresolvManager) Close() error {