cmd/ctrld: fix reset DNS when uninstalling

The "--iface" needs to be explicitly passed, otherwise, ctrld does not
know which interface to restore.
This commit is contained in:
Cuong Manh Le
2023-02-01 18:40:10 +07:00
committed by Cuong Manh Le
parent 61156453b2
commit 44bd580e48
3 changed files with 4 additions and 7 deletions
+2
View File
@@ -323,11 +323,13 @@ func initCLI() {
} }
initLogging() initLogging()
if doTasks(tasks) { if doTasks(tasks) {
prog.resetDNS()
mainLog.Info().Msg("Service uninstalled") mainLog.Info().Msg("Service uninstalled")
return return
} }
}, },
} }
uninstallCmd.Flags().StringVarP(&iface, "iface", "", "auto", `Reset DNS setting for iface, "auto" means the default interface gateway`)
listIfacesCmd := &cobra.Command{ listIfacesCmd := &cobra.Command{
Use: "list", Use: "list",
+2 -2
View File
@@ -72,9 +72,10 @@ func setDNS(iface *net.Interface, nameservers []string) error {
} }
currentNS := currentDNS(iface) currentNS := currentDNS(iface)
if reflect.DeepEqual(currentNS, nameservers) { if reflect.DeepEqual(currentNS, nameservers) {
break return nil
} }
} }
mainLog.Debug().Msg("DNS was not set for some reason")
return nil return nil
} }
@@ -105,7 +106,6 @@ func resetDNS(iface *net.Interface) error {
conversation, err := c.Exchange(iface.Name) conversation, err := c.Exchange(iface.Name)
if err != nil { if err != nil {
mainLog.Debug().Err(err).Msg("could not exchange DHCPv6") mainLog.Debug().Err(err).Msg("could not exchange DHCPv6")
return nil
} }
for _, packet := range conversation { for _, packet := range conversation {
if packet.Type() == dhcpv6.MessageTypeReply { if packet.Type() == dhcpv6.MessageTypeReply {
-5
View File
@@ -174,11 +174,6 @@ func (p *prog) Stop(s service.Service) error {
return nil return nil
} }
func (p *prog) Uninstall(s service.Service) error {
p.resetDNS()
return nil
}
func (p *prog) allocateIP(ip string) error { func (p *prog) allocateIP(ip string) error {
if !p.cfg.Service.AllocateIP { if !p.cfg.Service.AllocateIP {
return nil return nil