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

View File

@@ -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",

View File

@@ -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 {

View File

@@ -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