mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-09-29 13:51:51 +02:00
cmd/ctrld: make NetworkManger ignore auto dns
So the DNS that set by ctrld won't be override on startup.
This commit is contained in:
1 parent
44bd580e48
commit
8c47ffb5ec
4 files changed
+54
No files matched your search
@@ -223,6 +223,7 @@ func initCLI() {
|
|||||||
{s.Start, true},
|
{s.Start, true},
|
||||||
}
|
}
|
||||||
if doTasks(tasks) {
|
if doTasks(tasks) {
|
||||||
|
disableAutoDNS(iface)
|
||||||
prog.setDNS()
|
prog.setDNS()
|
||||||
mainLog.Info().Msg("Service started")
|
mainLog.Info().Msg("Service started")
|
||||||
}
|
}
|
||||||
@@ -254,6 +255,7 @@ func initCLI() {
|
|||||||
}
|
}
|
||||||
initLogging()
|
initLogging()
|
||||||
if doTasks([]task{{s.Stop, true}}) {
|
if doTasks([]task{{s.Stop, true}}) {
|
||||||
|
enableAutoDNS(iface)
|
||||||
prog.resetDNS()
|
prog.resetDNS()
|
||||||
mainLog.Info().Msg("Service stopped")
|
mainLog.Info().Msg("Service stopped")
|
||||||
}
|
}
|
||||||
@@ -323,6 +325,7 @@ func initCLI() {
|
|||||||
}
|
}
|
||||||
initLogging()
|
initLogging()
|
||||||
if doTasks(tasks) {
|
if doTasks(tasks) {
|
||||||
|
enableAutoDNS(iface)
|
||||||
prog.resetDNS()
|
prog.resetDNS()
|
||||||
mainLog.Info().Msg("Service uninstalled")
|
mainLog.Info().Msg("Service uninstalled")
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"net/netip"
|
"net/netip"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
@@ -174,6 +175,25 @@ func getDNSByNmcli(iface string) []string {
|
|||||||
return dns
|
return dns
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getConnByNmcli(iface string) string {
|
||||||
|
if iface == "auto" {
|
||||||
|
iface = defaultIfaceName()
|
||||||
|
}
|
||||||
|
b, err := exec.Command("nmcli", "dev", "show", iface).Output()
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
s := bufio.NewScanner(bytes.NewReader(b))
|
||||||
|
for s.Scan() {
|
||||||
|
line := s.Text()
|
||||||
|
if _, connName, found := strings.Cut(line, "GENERAL.CONNECTION:"); found {
|
||||||
|
return strings.TrimSpace(connName)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func ignoringEINTR(fn func() error) error {
|
func ignoringEINTR(fn func() error) error {
|
||||||
for {
|
for {
|
||||||
err := fn()
|
err := fn()
|
||||||
@@ -182,3 +202,22 @@ func ignoringEINTR(fn func() error) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func disableAutoDNS(iface string) {
|
||||||
|
networkManagerIgnoreAutoDNS(iface, "yes")
|
||||||
|
}
|
||||||
|
|
||||||
|
func enableAutoDNS(iface string) {
|
||||||
|
networkManagerIgnoreAutoDNS(iface, "no")
|
||||||
|
}
|
||||||
|
|
||||||
|
func networkManagerIgnoreAutoDNS(iface, answer string) {
|
||||||
|
if runtime.GOOS != "linux" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if connName := getConnByNmcli(iface); connName != "" {
|
||||||
|
mainLog.Debug().Msg("enable auto DNS from network manager")
|
||||||
|
_ = exec.Command("nmcli", "con", "mod", connName, "ipv4.ignore-auto-dns", answer).Run()
|
||||||
|
_ = exec.Command("nmcli", "con", "mod", connName, "ipv6.ignore-auto-dns", answer).Run()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -60,3 +60,9 @@ func resetDNS(iface *net.Interface) error {
|
|||||||
func currentDNS(_ *net.Interface) []string {
|
func currentDNS(_ *net.Interface) []string {
|
||||||
return resolvconffile.NameServers("")
|
return resolvconffile.NameServers("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func disableAutoDNS(iface string) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func enableAutoDNS(iface string) {
|
||||||
|
}
|
||||||
@@ -104,3 +104,9 @@ func currentDNS(iface *net.Interface) []string {
|
|||||||
}
|
}
|
||||||
return ns
|
return ns
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func disableAutoDNS(iface string) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func enableAutoDNS(iface string) {
|
||||||
|
}
|
||||||
Reference in new issue
Block a user