handle old state missing interface crash

This commit is contained in:
Alex
2025-02-10 19:50:20 -05:00
committed by Cuong Manh Le
parent 41a00c68ac
commit 9e83085f2a

View File

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