From 44bd580e48e747774bdae395076dac568d2da660 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Wed, 1 Feb 2023 18:40:10 +0700 Subject: [PATCH] cmd/ctrld: fix reset DNS when uninstalling The "--iface" needs to be explicitly passed, otherwise, ctrld does not know which interface to restore. --- cmd/ctrld/cli.go | 2 ++ cmd/ctrld/os_linux.go | 4 ++-- cmd/ctrld/prog.go | 5 ----- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/cmd/ctrld/cli.go b/cmd/ctrld/cli.go index f83d281..dc8470d 100644 --- a/cmd/ctrld/cli.go +++ b/cmd/ctrld/cli.go @@ -323,11 +323,13 @@ func initCLI() { } initLogging() if doTasks(tasks) { + prog.resetDNS() mainLog.Info().Msg("Service uninstalled") return } }, } + uninstallCmd.Flags().StringVarP(&iface, "iface", "", "auto", `Reset DNS setting for iface, "auto" means the default interface gateway`) listIfacesCmd := &cobra.Command{ Use: "list", diff --git a/cmd/ctrld/os_linux.go b/cmd/ctrld/os_linux.go index 110a23b..582ae3c 100644 --- a/cmd/ctrld/os_linux.go +++ b/cmd/ctrld/os_linux.go @@ -72,9 +72,10 @@ func setDNS(iface *net.Interface, nameservers []string) error { } currentNS := currentDNS(iface) if reflect.DeepEqual(currentNS, nameservers) { - break + return nil } } + mainLog.Debug().Msg("DNS was not set for some reason") return nil } @@ -105,7 +106,6 @@ func resetDNS(iface *net.Interface) error { conversation, err := c.Exchange(iface.Name) if err != nil { mainLog.Debug().Err(err).Msg("could not exchange DHCPv6") - return nil } for _, packet := range conversation { if packet.Type() == dhcpv6.MessageTypeReply { diff --git a/cmd/ctrld/prog.go b/cmd/ctrld/prog.go index fa11dfc..532f57e 100644 --- a/cmd/ctrld/prog.go +++ b/cmd/ctrld/prog.go @@ -174,11 +174,6 @@ func (p *prog) Stop(s service.Service) error { return nil } -func (p *prog) Uninstall(s service.Service) error { - p.resetDNS() - return nil -} - func (p *prog) allocateIP(ip string) error { if !p.cfg.Service.AllocateIP { return nil