summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhev <r@hev.cc>2021-09-19 18:56:08 +0800
committerSimon Kelley <simon@thekelleys.org.uk>2021-09-20 20:12:50 +0100
commiteb88eed1fc8ed246e9355531c2715fa2f7738afc (patch)
tree54a6f1d774917340c4f07a8524c93be4570c507a
parent8312a3ba4f06141647e86a2c5c4ccfb2e32582ab (diff)
downloaddnsmasq-eb88eed1fc8ed246e9355531c2715fa2f7738afc.tar.gz
Optimize inserting records into server list.
Signed-off-by: hev <r@hev.cc>
-rw-r--r--src/dnsmasq.h2
-rw-r--r--src/domain-match.c17
2 files changed, 9 insertions, 10 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..3f1cc74 100644
--- a/src/domain-match.c
+++ b/src/domain-match.c
@@ -576,7 +576,10 @@ void cleanup_servers(void)
free(serv);
}
else
- up = &serv->next;
+ {
+ up = &serv->next;
+ daemon->servers_tail = serv;
+ }
}
for (serv = daemon->local_domains, up = &daemon->local_domains; serv; serv = tmp)
@@ -673,18 +676,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();