2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2020-07-31 20:27:09 +00:00
|
|
|
|
|
|
|
package dns
|
|
|
|
|
2021-04-14 22:34:59 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2021-04-02 06:26:52 +00:00
|
|
|
|
2024-06-11 03:05:15 +00:00
|
|
|
"tailscale.com/control/controlknobs"
|
2024-04-26 17:12:46 +00:00
|
|
|
"tailscale.com/health"
|
2021-04-14 22:34:59 +00:00
|
|
|
"tailscale.com/types/logger"
|
|
|
|
)
|
2021-04-14 00:38:17 +00:00
|
|
|
|
2024-06-11 03:05:15 +00:00
|
|
|
// NewOSConfigurator creates a new OS configurator.
|
|
|
|
//
|
|
|
|
// The health tracker may be nil; the knobs may be nil and are ignored on this platform.
|
|
|
|
func NewOSConfigurator(logf logger.Logf, health *health.Tracker, _ *controlknobs.Knobs, _ 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) {
|
2024-04-26 17:12:46 +00:00
|
|
|
return newDirectManager(logf, health), 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 "":
|
2024-04-26 17:12:46 +00:00
|
|
|
return newDirectManager(logf, health), nil
|
2021-09-05 06:40:48 +00:00
|
|
|
case "debian":
|
|
|
|
return newDebianResolvconfManager(logf)
|
|
|
|
case "openresolv":
|
2024-02-14 01:19:24 +00:00
|
|
|
return newOpenresolvManager(logf)
|
2021-09-05 06:48:51 +00:00
|
|
|
default:
|
|
|
|
logf("[unexpected] got unknown flavor of resolvconf %q, falling back to direct manager", resolvconfStyle())
|
2024-04-26 17:12:46 +00:00
|
|
|
return newDirectManager(logf, health), nil
|
2021-09-05 06:40:48 +00:00
|
|
|
}
|
2020-07-31 20:27:09 +00:00
|
|
|
default:
|
2024-04-26 17:12:46 +00:00
|
|
|
return newDirectManager(logf, health), nil
|
2020-07-31 20:27:09 +00:00
|
|
|
}
|
|
|
|
}
|