2020-07-31 20:27:09 +00:00
|
|
|
// Copyright (c) 2020 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
|
|
|
|
|
2021-04-14 22:34:59 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2021-04-02 06:26:52 +00:00
|
|
|
|
2021-04-14 22:34:59 +00:00
|
|
|
"tailscale.com/types/logger"
|
|
|
|
)
|
2021-04-14 00:38:17 +00:00
|
|
|
|
2021-04-12 22:51:37 +00:00
|
|
|
func NewOSConfigurator(logf logger.Logf, _ string) (OSConfigurator, error) {
|
2021-04-14 22:34:59 +00:00
|
|
|
bs, err := ioutil.ReadFile("/etc/resolv.conf")
|
|
|
|
if os.IsNotExist(err) {
|
2021-06-25 16:43:13 +00:00
|
|
|
return newDirectManager(), nil
|
2021-04-14 22:34:59 +00:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("reading /etc/resolv.conf: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch resolvOwner(bs) {
|
|
|
|
case "resolvconf":
|
2021-09-05 06:40:48 +00:00
|
|
|
switch resolvconfStyle() {
|
|
|
|
case "":
|
|
|
|
return newDirectManager(), nil
|
|
|
|
case "debian":
|
|
|
|
return newDebianResolvconfManager(logf)
|
|
|
|
case "openresolv":
|
|
|
|
return newOpenresolvManager()
|
|
|
|
}
|
2020-07-31 20:27:09 +00:00
|
|
|
default:
|
2021-06-25 16:43:13 +00:00
|
|
|
return newDirectManager(), nil
|
2020-07-31 20:27:09 +00:00
|
|
|
}
|
|
|
|
}
|