From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Nikita Koptev Date: Fri, 13 Nov 2026 20:00:00 +0300 Subject: [PATCH ip-iface-inactive] Nest: Keep interfaces in the right list when they change state Two problems with moving interfaces between iface_list and dead_iface_list: 1) if_update() moves an interface between the lists only in the IF_CHANGE_TOO_MUCH branch. IF_SHUTDOWN is masked in if_what_changed(), so an interface which comes back with the same index is revived in place but stays in dead_iface_list. It is then invisible to if_find_by_index(), scans and CLI. This happens e.g. after if_flush_ifaces() (device protocol restart), where all interfaces are marked as shut down and moved to the dead list, and come back with the same index on the next scan. Move the interface to the list matching its IF_SHUTDOWN flag whenever the flag changes. 2) if_end_update() moves interfaces to dead_iface_list while walking iface_list with WALK_LIST(). After add_tail() the next pointer leads to the tail sentinel of the other list, so the walk stops after the first disappeared interface and the rest of the interfaces are not processed in this scan. Use WALK_LIST_DELSAFE(). --- nest/iface.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/nest/iface.c b/nest/iface.c --- a/nest/iface.c +++ b/nest/iface.c @@ -300,8 +300,17 @@ if_update(struct iface *new) goto newif; } + uint was_shutdown = i->flags & IF_SHUTDOWN; rta_free(i->attrs); if_copy(i, new); + + /* Revived or shut down without IF_CHANGE_TOO_MUCH: fix list membership */ + if ((i->flags & IF_SHUTDOWN) != was_shutdown) + { + rem_node(&i->n); + add_tail((i->flags & IF_SHUTDOWN) ? &dead_iface_list : &iface_list, &i->n); + } + if (c) if_notify_change(c, i); @@ -350,10 +359,10 @@ if_end_partial_update(struct iface *i) void if_end_update(void) { - struct iface *i; + struct iface *i, *x; struct ifa *a, *b; - WALK_LIST(i, iface_list) + WALK_LIST_DELSAFE(i, x, iface_list) { if (!(i->flags & IF_UPDATED)) { -- 2.43.0