2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2020-07-31 21:27:09 +01:00
|
|
|
|
|
|
|
package dns
|
|
|
|
|
2021-04-14 23:34:59 +01:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2021-04-02 07:26:52 +01:00
|
|
|
|
2021-04-14 23:34:59 +01:00
|
|
|
"tailscale.com/types/logger"
|
|
|
|
)
|
2021-04-14 01:38:17 +01:00
|
|
|
|
2021-04-12 23:51:37 +01:00
|
|
|
func NewOSConfigurator(logf logger.Logf, _ string) (OSConfigurator, error) {
|
2022-09-15 13:06:59 +01:00
|
|
|
bs, err := os.ReadFile("/etc/resolv.conf")
|
2021-04-14 23:34:59 +01:00
|
|
|
if os.IsNotExist(err) {
|
2021-10-07 01:49:32 +01:00
|
|
|
return newDirectManager(logf), nil
|
2021-04-14 23:34:59 +01:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("reading /etc/resolv.conf: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch resolvOwner(bs) {
|
|
|
|
case "resolvconf":
|
2021-09-05 07:40:48 +01:00
|
|
|
switch resolvconfStyle() {
|
|
|
|
case "":
|
2021-10-07 01:49:32 +01:00
|
|
|
return newDirectManager(logf), nil
|
2021-09-05 07:40:48 +01:00
|
|
|
case "debian":
|
|
|
|
return newDebianResolvconfManager(logf)
|
|
|
|
case "openresolv":
|
|
|
|
return newOpenresolvManager()
|
2021-09-05 07:48:51 +01:00
|
|
|
default:
|
|
|
|
logf("[unexpected] got unknown flavor of resolvconf %q, falling back to direct manager", resolvconfStyle())
|
2021-10-07 01:49:32 +01:00
|
|
|
return newDirectManager(logf), nil
|
2021-09-05 07:40:48 +01:00
|
|
|
}
|
2020-07-31 21:27:09 +01:00
|
|
|
default:
|
2021-10-07 01:49:32 +01:00
|
|
|
return newDirectManager(logf), nil
|
2020-07-31 21:27:09 +01:00
|
|
|
}
|
|
|
|
}
|