mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-05-27 12:52:27 +02:00
aaf31b6471
By adding a logger field to "prog" struct, and use this field inside its method instead of always accessing global mainLog variable. This at least ensure more consistent usage of the logger during ctrld prog runtime, and also help refactoring the code more easily in the future (like replacing the logger library).
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
//go:build unix && !darwin
|
|
|
|
package cli
|
|
|
|
import (
|
|
"net"
|
|
"net/netip"
|
|
|
|
"tailscale.com/control/controlknobs"
|
|
"tailscale.com/health"
|
|
"tailscale.com/util/dnsname"
|
|
|
|
"github.com/Control-D-Inc/ctrld/internal/dns"
|
|
)
|
|
|
|
// setResolvConf sets the content of the resolv.conf file using the given nameservers list.
|
|
func (p *prog) setResolvConf(iface *net.Interface, ns []netip.Addr) error {
|
|
r, err := newLoopbackOSConfigurator()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
oc := dns.OSConfig{
|
|
Nameservers: ns,
|
|
SearchDomains: []dnsname.FQDN{},
|
|
}
|
|
if sds, err := searchDomains(); err == nil {
|
|
oc.SearchDomains = sds
|
|
} else {
|
|
p.Debug().Err(err).Msg("failed to get search domains list when reverting resolv.conf file")
|
|
}
|
|
return r.SetDNS(oc)
|
|
}
|
|
|
|
// shouldWatchResolvconf reports whether ctrld should watch changes to resolv.conf file with given OS configurator.
|
|
func shouldWatchResolvconf() bool {
|
|
r, err := newLoopbackOSConfigurator()
|
|
if err != nil {
|
|
return false
|
|
}
|
|
switch r.Mode() {
|
|
case "direct", "resolvconf":
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// newLoopbackOSConfigurator creates an OSConfigurator for DNS management using the "lo" interface.
|
|
func newLoopbackOSConfigurator() (dns.OSConfigurator, error) {
|
|
return dns.NewOSConfigurator(noopLogf, &health.Tracker{}, &controlknobs.Knobs{}, "lo")
|
|
}
|