cmd/cli: log interfaces state after dns set

The data will be useful for troubleshooting later.
This commit is contained in:
Cuong Manh Le
2025-01-24 01:39:17 +07:00
committed by Cuong Manh Le
parent 20759017e6
commit 0fbfd160c9
2 changed files with 24 additions and 0 deletions

View File

@@ -1251,6 +1251,7 @@ func (p *prog) reinitializeOSResolver() {
mainLog.Load().Debug().Msg("setting DNS configuration")
p.setDNS()
mainLog.Load().Debug().Msg("DNS configuration set successfully")
p.logInterfacesState()
}
}

View File

@@ -273,6 +273,7 @@ func (p *prog) postRun() {
p.setDNS()
p.csSetDnsDone <- struct{}{}
close(p.csSetDnsDone)
p.logInterfacesState()
}
}
@@ -815,6 +816,28 @@ func (p *prog) resetDNS() {
}
}
func (p *prog) logInterfacesState() {
withEachPhysicalInterfaces("", "", func(i *net.Interface) error {
addrs, err := i.Addrs()
if err != nil {
mainLog.Load().Warn().Str("interface", i.Name).Err(err).Msg("failed to get addresses")
}
nss, err := currentStaticDNS(i)
if err != nil {
mainLog.Load().Warn().Str("interface", i.Name).Err(err).Msg("failed to get DNS")
}
if len(nss) == 0 {
nss = currentDNS(i)
}
mainLog.Load().Debug().
Any("addrs", addrs).
Strs("nameservers", nss).
Int("index", i.Index).
Msgf("interface state: %s", i.Name)
return nil
})
}
// findWorkingInterface looks for a network interface with a valid IP configuration
func findWorkingInterface(currentIface string) string {
// Helper to check if IP is valid (not link-local)