mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
Fixes search domains not being preserved when the resolv.conf file is reverted to its previous state. This ensures that important domain search configuration is maintained during DNS configuration changes. The search domains handling was missing in setResolvConf function, which is responsible for restoring DNS settings.
66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
package cli
|
|
|
|
import (
|
|
"bufio"
|
|
"bytes"
|
|
"io"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"github.com/kardianos/service"
|
|
|
|
"github.com/Control-D-Inc/ctrld/internal/router"
|
|
)
|
|
|
|
func init() {
|
|
if r, err := newLoopbackOSConfigurator(); err == nil {
|
|
useSystemdResolved = r.Mode() == "systemd-resolved"
|
|
}
|
|
// Disable quic-go's ECN support by default, see https://github.com/quic-go/quic-go/issues/3911
|
|
if os.Getenv("QUIC_GO_DISABLE_ECN") == "" {
|
|
os.Setenv("QUIC_GO_DISABLE_ECN", "true")
|
|
}
|
|
}
|
|
|
|
func setDependencies(svc *service.Config) {
|
|
svc.Dependencies = []string{
|
|
"Wants=network-online.target",
|
|
"After=network-online.target",
|
|
"Wants=NetworkManager-wait-online.service",
|
|
"After=NetworkManager-wait-online.service",
|
|
"Wants=nss-lookup.target",
|
|
"After=nss-lookup.target",
|
|
}
|
|
if out, _ := exec.Command("networkctl", "--no-pager").CombinedOutput(); len(out) > 0 {
|
|
if wantsSystemDNetworkdWaitOnline(bytes.NewReader(out)) {
|
|
svc.Dependencies = append(svc.Dependencies, "Wants=systemd-networkd-wait-online.service")
|
|
}
|
|
}
|
|
if routerDeps := router.ServiceDependencies(); len(routerDeps) > 0 {
|
|
svc.Dependencies = append(svc.Dependencies, routerDeps...)
|
|
}
|
|
}
|
|
|
|
func setWorkingDirectory(svc *service.Config, dir string) {
|
|
svc.WorkingDirectory = dir
|
|
}
|
|
|
|
// wantsSystemDNetworkdWaitOnline reports whether "systemd-networkd-wait-online" service
|
|
// is required to be added to ctrld dependencies services.
|
|
// The input reader r is the output of "networkctl --no-pager" command.
|
|
func wantsSystemDNetworkdWaitOnline(r io.Reader) bool {
|
|
scanner := bufio.NewScanner(r)
|
|
// Skip header
|
|
scanner.Scan()
|
|
configured := false
|
|
for scanner.Scan() {
|
|
fields := strings.Fields(scanner.Text())
|
|
if len(fields) > 0 && fields[len(fields)-1] == "configured" {
|
|
configured = true
|
|
break
|
|
}
|
|
}
|
|
return configured
|
|
}
|