Blame SOURCES/dnsmasq-2.76-rh1728698-3.patch

85f98a
From 527029312cbe37c0285240943ad02352d64d403d Mon Sep 17 00:00:00 2001
85f98a
From: Petr Mensik <pemensik@redhat.com>
85f98a
Date: Tue, 9 Jul 2019 14:05:59 +0200
85f98a
Subject: [PATCH 3/5] Cleanup interfaces no longer available
85f98a
85f98a
Clean addresses and interfaces not found after enumerate. Free unused
85f98a
records to speed up checking active interfaces and reduce used memory.
85f98a
---
85f98a
 src/network.c | 32 ++++++++++++++++++++++++++++++--
85f98a
 1 file changed, 30 insertions(+), 2 deletions(-)
85f98a
85f98a
diff --git a/src/network.c b/src/network.c
85f98a
index f247811..d6d4b01 100644
85f98a
--- a/src/network.c
85f98a
+++ b/src/network.c
85f98a
@@ -553,7 +553,30 @@ static int iface_allowed_v4(struct in_addr local, int if_index, char *label,
85f98a
 
85f98a
   return iface_allowed((struct iface_param *)vparam, if_index, label, &addr, netmask, prefix, 0);
85f98a
 }
85f98a
-   
85f98a
+
85f98a
+/*
85f98a
+ * Clean old interfaces no longer found.
85f98a
+ */
85f98a
+static void clean_interfaces()
85f98a
+{
85f98a
+  struct irec *iface;
85f98a
+  struct irec **up = &daemon->interfaces;
85f98a
+
85f98a
+  for (iface = *up; iface; iface = *up)
85f98a
+  {
85f98a
+    if (!iface->found && !iface->done)
85f98a
+      {
85f98a
+        *up = iface->next;
85f98a
+        free(iface->name);
85f98a
+        free(iface);
85f98a
+      }
85f98a
+    else
85f98a
+      {
85f98a
+        up = &iface->next;
85f98a
+      }
85f98a
+  }
85f98a
+}
85f98a
+
85f98a
 int enumerate_interfaces(int reset)
85f98a
 {
85f98a
   static struct addrlist *spare = NULL;
85f98a
@@ -653,6 +676,7 @@ int enumerate_interfaces(int reset)
85f98a
 	 in OPT_CLEVERBIND mode, that at listener will just disappear after
85f98a
 	 a call to enumerate_interfaces, this is checked OK on all calls. */
85f98a
       struct listener *l, *tmp, **up;
85f98a
+      int freed = 0;
85f98a
       
85f98a
       for (up = &daemon->listeners, l = daemon->listeners; l; l = tmp)
85f98a
 	{
85f98a
@@ -682,10 +706,14 @@ int enumerate_interfaces(int reset)
85f98a
 		close(l->tftpfd);
85f98a
 	      
85f98a
 	      free(l);
85f98a
+	      freed = 1;
85f98a
 	    }
85f98a
 	}
85f98a
+
85f98a
+      if (freed)
85f98a
+	clean_interfaces();
85f98a
     }
85f98a
-  
85f98a
+
85f98a
   errno = errsave;
85f98a
   spare = param.spare;
85f98a
     
85f98a
-- 
85f98a
2.20.1
85f98a