mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-09-17 01:45:27 +02:00
handle old state missing interface crash
This commit is contained in:
+21
-3
@@ -1183,14 +1183,32 @@ func (p *prog) monitorNetworkChanges(ctx context.Context) error {
|
|||||||
var changeIPs []netip.Prefix
|
var changeIPs []netip.Prefix
|
||||||
// Check each valid interface for changes
|
// Check each valid interface for changes
|
||||||
for ifaceName := range validIfaces {
|
for ifaceName := range validIfaces {
|
||||||
oldIface := delta.Old.Interface[ifaceName]
|
oldIface, oldExists := delta.Old.Interface[ifaceName]
|
||||||
newIface, exists := delta.New.Interface[ifaceName]
|
newIface, newExists := delta.New.Interface[ifaceName]
|
||||||
if !exists {
|
if !newExists {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
oldIPs := delta.Old.InterfaceIPs[ifaceName]
|
oldIPs := delta.Old.InterfaceIPs[ifaceName]
|
||||||
newIPs := delta.New.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.
|
// Filter new IPs to only those that are usable.
|
||||||
usableNewIPs := filterUsableIPs(newIPs)
|
usableNewIPs := filterUsableIPs(newIPs)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user