From 305cb79c5754d5554729b18a2c06fe7ce699687a Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Thu, 18 Feb 2021 21:35:09 +0000 Subject: [PATCH] Simplify preceding fix. Remove distinction between retry with same QID/SP and retry for same query with different QID/SP. If the QID/SP are the same as an existing one, simply retry, if a new QID/SP is seen, add to the list to be replied to. --- src/forward.c | 64 ++++++++++++++++++++--------------------------------------- 1 file changed, 22 insertions(+), 42 deletions(-) diff --git a/src/forward.c b/src/forward.c index e82e14a..6bbf8a4 100644 --- a/src/forward.c +++ b/src/forward.c @@ -17,9 +17,6 @@ #include "dnsmasq.h" static struct frec *lookup_frec(unsigned short id, int fd, int family, void *hash); -static struct frec *lookup_frec_by_sender(unsigned short id, - union mysockaddr *addr, - void *hash); static struct frec *lookup_frec_by_query(void *hash, unsigned int flags); static unsigned short get_id(void); @@ -278,18 +275,20 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr, fwd_flags |= FREC_DO_QUESTION; #endif - /* Check for retry on existing query from same source */ - if (!forward && (!(forward = lookup_frec_by_sender(ntohs(header->id), udpaddr, hash)))) + /* Check for retry on existing query */ + if (!forward && (forward = lookup_frec_by_query(hash, fwd_flags))) { - /* Maybe query from new source, but the same query may be in progress - from another source. If so, just add this client to the - list that will get the reply.*/ - - if (!option_bool(OPT_ADD_MAC) && !option_bool(OPT_MAC_B64) && - (forward = lookup_frec_by_query(hash, fwd_flags))) - { - struct frec_src *new; + struct frec_src *src; + + for (src = &forward->frec_src; src; src = src->next) + if (src->orig_id == ntohs(header->id) && + sockaddr_isequal(&src->source, udpaddr)) + break; + /* Existing query, but from new source, just add this + client to the list that will get the reply.*/ + if (!src) + { /* Note whine_malloc() zeros memory. */ if (!daemon->free_frec_src && daemon->frec_src_count < daemon->ftabsize && @@ -303,16 +302,16 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr, if (!daemon->free_frec_src) return 0; - new = daemon->free_frec_src; - daemon->free_frec_src = new->next; - new->next = forward->frec_src.next; - forward->frec_src.next = new; - new->orig_id = ntohs(header->id); - new->source = *udpaddr; - new->dest = *dst_addr; - new->log_id = daemon->log_id; - new->iface = dst_iface; - new->fd = udpfd; + src = daemon->free_frec_src; + daemon->free_frec_src = src->next; + src->next = forward->frec_src.next; + forward->frec_src.next = src; + src->orig_id = ntohs(header->id); + src->source = *udpaddr; + src->dest = *dst_addr; + src->log_id = daemon->log_id; + src->iface = dst_iface; + src->fd = udpfd; } } @@ -2433,25 +2432,6 @@ static struct frec *lookup_frec(unsigned short id, int fd, int family, void *has return NULL; } -static struct frec *lookup_frec_by_sender(unsigned short id, - union mysockaddr *addr, - void *hash) -{ - struct frec *f; - struct frec_src *src; - - for (f = daemon->frec_list; f; f = f->next) - if (f->sentto && - !(f->flags & (FREC_DNSKEY_QUERY | FREC_DS_QUERY)) && - memcmp(hash, f->hash, HASH_SIZE) == 0) - for (src = &f->frec_src; src; src = src->next) - if (src->orig_id == id && - sockaddr_isequal(&src->source, addr)) - return f; - - return NULL; -} - static struct frec *lookup_frec_by_query(void *hash, unsigned int flags) { struct frec *f; -- 1.8.3.1