From 0fbfd160c9940be59f8fdcfc3ecc7d26b8cb8ecf Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Fri, 24 Jan 2025 01:39:17 +0700 Subject: [PATCH] cmd/cli: log interfaces state after dns set The data will be useful for troubleshooting later. --- cmd/cli/dns_proxy.go | 1 + cmd/cli/prog.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/cmd/cli/dns_proxy.go b/cmd/cli/dns_proxy.go index 5396642..d7eb28a 100644 --- a/cmd/cli/dns_proxy.go +++ b/cmd/cli/dns_proxy.go @@ -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() } } diff --git a/cmd/cli/prog.go b/cmd/cli/prog.go index 46d4d18..331f42a 100644 --- a/cmd/cli/prog.go +++ b/cmd/cli/prog.go @@ -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)