[Dnsmasq-discuss] [PATCH v2] Optimize inserting records into server list.

hev r at hev.cc
Sun Sep 19 10:56:08 UTC 2021


Signed-off-by: hev <r at hev.cc>
---
 src/dnsmasq.h      |  2 +-
 src/domain-match.c | 12 ++++--------
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index 327ad65..639c568 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -1105,7 +1105,7 @@ extern struct daemon {
   char *lease_change_command;
   struct iname *if_names, *if_addrs, *if_except, *dhcp_except, *auth_peers, *tftp_interfaces;
   struct bogus_addr *bogus_addr, *ignore_addr;
-  struct server *servers, *local_domains, **serverarray, *no_rebind;
+  struct server *servers, *servers_tail, *local_domains, **serverarray, *no_rebind;
   int server_has_wildcard;
   int serverarraysz, serverarrayhwm;
   struct ipsets *ipsets;
diff --git a/src/domain-match.c b/src/domain-match.c
index 8f29621..7483782 100644
--- a/src/domain-match.c
+++ b/src/domain-match.c
@@ -673,18 +673,14 @@ int add_update_server(int flags,
 	}
       else
 	{
-	  struct server *s;
-
 	  memset(serv, 0, sizeof(struct server));
 	  
 	  /* Add to the end of the chain, for order */
-	  if (!daemon->servers)
-	    daemon->servers = serv;
+	  if (daemon->servers_tail)
+	    daemon->servers_tail->next = serv;
 	  else
-	    {
-	      for (s = daemon->servers; s->next; s = s->next);
-	      s->next = serv;
-	    }
+	    daemon->servers = serv;
+	  daemon->servers_tail = serv;
 	  
 #ifdef HAVE_LOOP
 	  serv->uid = rand32();
-- 
2.33.0




More information about the Dnsmasq-discuss mailing list