mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-08 09:07:44 +00:00
net/dns: fix freebsd DNS manager selection.
Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
parent
5ea53891fe
commit
1f9b73a531
@ -92,6 +92,36 @@ func readResolvConf() (OSConfig, error) {
|
|||||||
return readResolvFile(resolvConf)
|
return readResolvFile(resolvConf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// resolvOwner returns the apparent owner of the resolv.conf
|
||||||
|
// configuration in bs - one of "resolvconf", "systemd-resolved" or
|
||||||
|
// "NetworkManager", or "" if no known owner was found.
|
||||||
|
func resolvOwner(bs []byte) string {
|
||||||
|
b := bytes.NewBuffer(bs)
|
||||||
|
for {
|
||||||
|
line, err := b.ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
line = strings.TrimSpace(line)
|
||||||
|
if line == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if line[0] != '#' {
|
||||||
|
// First non-empty, non-comment line. Assume the owner
|
||||||
|
// isn't hiding further down.
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.Contains(line, "systemd-resolved") {
|
||||||
|
return "systemd-resolved"
|
||||||
|
} else if strings.Contains(line, "NetworkManager") {
|
||||||
|
return "NetworkManager"
|
||||||
|
} else if strings.Contains(line, "resolvconf") {
|
||||||
|
return "resolvconf"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// isResolvedRunning reports whether systemd-resolved is running on the system,
|
// isResolvedRunning reports whether systemd-resolved is running on the system,
|
||||||
// even if it is not managing the system DNS settings.
|
// even if it is not managing the system DNS settings.
|
||||||
func isResolvedRunning() bool {
|
func isResolvedRunning() bool {
|
||||||
|
@ -4,16 +4,25 @@
|
|||||||
|
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
import "tailscale.com/types/logger"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
|
||||||
func isResolvconfActive() bool {
|
"tailscale.com/types/logger"
|
||||||
// TODO(danderson): implement somewhere.
|
)
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewOSConfigurator(logf logger.Logf, _ string) (OSConfigurator, error) {
|
func NewOSConfigurator(logf logger.Logf, _ string) (OSConfigurator, error) {
|
||||||
switch {
|
bs, err := ioutil.ReadFile("/etc/resolv.conf")
|
||||||
case isResolvconfActive():
|
if os.IsNotExist(err) {
|
||||||
|
return newDirectManager()
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("reading /etc/resolv.conf: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch resolvOwner(bs) {
|
||||||
|
case "resolvconf":
|
||||||
return newResolvconfManager(logf)
|
return newResolvconfManager(logf)
|
||||||
default:
|
default:
|
||||||
return newDirectManager()
|
return newDirectManager()
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/godbus/dbus/v5"
|
"github.com/godbus/dbus/v5"
|
||||||
@ -132,33 +131,3 @@ func dbusPing(name, objectPath string) error {
|
|||||||
call := obj.CallWithContext(ctx, "org.freedesktop.DBus.Peer.Ping", 0)
|
call := obj.CallWithContext(ctx, "org.freedesktop.DBus.Peer.Ping", 0)
|
||||||
return call.Err
|
return call.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolvOwner returns the apparent owner of the resolv.conf
|
|
||||||
// configuration in bs - one of "resolvconf", "systemd-resolved" or
|
|
||||||
// "NetworkManager", or "" if no known owner was found.
|
|
||||||
func resolvOwner(bs []byte) string {
|
|
||||||
b := bytes.NewBuffer(bs)
|
|
||||||
for {
|
|
||||||
line, err := b.ReadString('\n')
|
|
||||||
if err != nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
line = strings.TrimSpace(line)
|
|
||||||
if line == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if line[0] != '#' {
|
|
||||||
// First non-empty, non-comment line. Assume the owner
|
|
||||||
// isn't hiding further down.
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.Contains(line, "systemd-resolved") {
|
|
||||||
return "systemd-resolved"
|
|
||||||
} else if strings.Contains(line, "NetworkManager") {
|
|
||||||
return "NetworkManager"
|
|
||||||
} else if strings.Contains(line, "resolvconf") {
|
|
||||||
return "resolvconf"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user