[PATCH] Free interfaces in shutdown state

Lorenz Brun lorenz at brun.one
Tue Jul 12 19:54:59 CEST 2022


When interfaces are created and destroyed by automated systems,
a potentially unbounded amount of interfaces exist.
This results in bird consuming ever-increasing amounts of memory and
CPU time for the list of known interfaces.

This change frees the interface after it is in shutdown state and all
notifications for it have been processed.
---
 nest/iface.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/nest/iface.c b/nest/iface.c
index 682340c5..b4c65512 100644
--- a/nest/iface.c
+++ b/nest/iface.c
@@ -324,7 +324,7 @@ if_update(struct iface *new)
 	if_copy(i, new);
 	if (c)
 	  if_notify_change(c, i);
-
+  
 	i->flags |= IF_UPDATED;
 	return i;
       }
@@ -365,10 +365,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))
 	if_change_flags(i, (i->flags & ~IF_ADMIN_UP) | IF_SHUTDOWN);
@@ -379,6 +379,11 @@ if_end_update(void)
 	      ifa_delete(a);
 	  if_end_partial_update(i);
 	}
+    if ((i->flags & IF_SHUTDOWN)) {
+      WALK_LIST_DELSAFE(a, b, i->addrs)
+        ifa_delete(a);
+      rem_node(&i->n);
+    }
     }
 }
 
-- 
2.36.1



More information about the Bird-users mailing list