From 9e83085f2a8719b3c0c73a1d564a6984503b919d Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 10 Feb 2025 19:50:20 -0500 Subject: [PATCH] handle old state missing interface crash --- cmd/cli/dns_proxy.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/cmd/cli/dns_proxy.go b/cmd/cli/dns_proxy.go index 44582c5..b7b5c5f 100644 --- a/cmd/cli/dns_proxy.go +++ b/cmd/cli/dns_proxy.go @@ -1183,14 +1183,32 @@ func (p *prog) monitorNetworkChanges(ctx context.Context) error { var changeIPs []netip.Prefix // Check each valid interface for changes for ifaceName := range validIfaces { - oldIface := delta.Old.Interface[ifaceName] - newIface, exists := delta.New.Interface[ifaceName] - if !exists { + oldIface, oldExists := delta.Old.Interface[ifaceName] + newIface, newExists := delta.New.Interface[ifaceName] + if !newExists { continue } + oldIPs := delta.Old.InterfaceIPs[ifaceName] newIPs := delta.New.InterfaceIPs[ifaceName] + // if a valid interface did not exist in old + // check that its up and has usable IPs + if !oldExists { + // The interface is new (was not present in the old state). + usableNewIPs := filterUsableIPs(newIPs) + if newIface.IsUp() && len(usableNewIPs) > 0 { + changed = true + changeIPs = usableNewIPs + mainLog.Load().Debug(). + Str("interface", ifaceName). + Interface("new_ips", usableNewIPs). + Msg("Interface newly appeared (was not present in old state)") + break + } + continue + } + // Filter new IPs to only those that are usable. usableNewIPs := filterUsableIPs(newIPs)