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"
|
|
|
|
"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) {
|
2022-09-15 12:06:59 +00:00
|
|
|
bs, err := os.ReadFile("/etc/resolv.conf")
|
2021-04-14 22:34:59 +00:00
|
|
|
if os.IsNotExist(err) {
|
2021-10-07 00:49:32 +00:00
|
|
|
return newDirectManager(logf), 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 "":
|
2021-10-07 00:49:32 +00:00
|
|
|
return newDirectManager(logf), nil
|
2021-09-05 06:40:48 +00:00
|
|
|
case "debian":
|
|
|
|
return newDebianResolvconfManager(logf)
|
|
|
|
case "openresolv":
|
|
|
|
return newOpenresolvManager()
|
2021-09-05 06:48:51 +00:00
|
|
|
default:
|
|
|
|
logf("[unexpected] got unknown flavor of resolvconf %q, falling back to direct manager", resolvconfStyle())
|
2021-10-07 00:49:32 +00:00
|
|
|
return newDirectManager(logf), nil
|
2021-09-05 06:40:48 +00:00
|
|
|
}
|
2020-07-31 20:27:09 +00:00
|
|
|
default:
|
2021-10-07 00:49:32 +00:00
|
|
|
return newDirectManager(logf), nil
|
2020-07-31 20:27:09 +00:00
|
|
|
}
|
|
|
|
}
|