From f61afcfc7004d3ecae401e8c3b506b9b40e89611 Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Wed, 7 Apr 2021 20:54:36 +0100 Subject: [PATCH] Tidy error logging in 961daf8f921503457d1f539f79b3a2def7d479e2 --- src/forward.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/forward.c b/src/forward.c index 2d13de5..40c9723 100644 --- a/src/forward.c +++ b/src/forward.c @@ -21,6 +21,7 @@ static struct frec *lookup_frec_by_query(void *hash, unsigned int flags); static unsigned short get_id(void); static void free_frec(struct frec *f); +static void query_full(time_t now); /* Send a UDP packet with its source address set as "source" unless nowild is true, when we just send it with the kernel default */ @@ -355,14 +356,7 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr, /* If we've been spammed with many duplicates, return REFUSED. */ if (!daemon->free_frec_src) { - static time_t last_log = 0; - - if ((int)difftime(now, last_log) > 5) - { - last_log = now; - my_syslog(LOG_WARNING, _("Maximum number of concurrent DNS queries reached (max: %d)"), daemon->ftabsize); - } - + query_full(now); goto frec_err; } @@ -2463,17 +2457,11 @@ struct frec *get_new_frec(time_t now, int *wait, struct frec *force) /* none available, calculate time 'till oldest record expires */ if (!force && count > daemon->ftabsize) { - static time_t last_log = 0; - if (oldest && wait) *wait = oldest->time + (time_t)TIMEOUT - now; - if ((int)difftime(now, last_log) > 5) - { - last_log = now; - my_syslog(LOG_WARNING, _("Maximum number of concurrent DNS queries reached (max: %d)"), daemon->ftabsize); - } - + query_full(now); + return NULL; } @@ -2484,6 +2472,18 @@ struct frec *get_new_frec(time_t now, int *wait, struct frec *force) return f; /* OK if malloc fails and this is NULL */ } +static void query_full(time_t now) +{ + static time_t last_log = 0; + + if ((int)difftime(now, last_log) > 5) + { + last_log = now; + my_syslog(LOG_WARNING, _("Maximum number of concurrent DNS queries reached (max: %d)"), daemon->ftabsize); + } +} + + static struct frec *lookup_frec(unsigned short id, int fd, void *hash) { struct frec *f;