From 0122bc06a266dad59d1db3b08caaa6c2741ed368 Mon Sep 17 00:00:00 2001 From: Willem Toorop Date: Thu, 22 Dec 2022 12:38:43 +0100 Subject: [PATCH] Fix PR #323 Reduce spam messages when interface is offline --- ChangeLog | 5 ++++- src/server.c | 20 +++++++++++++------- src/server.h | 2 +- src/stubby.c | 3 ++- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0ee4a3f..236052f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ * 2022-12-22: version 0.4.3 - * Fix Issue #330: PrivateUsers=false needed in systemd + * Fix Issue #330 and PR#324: PrivateUsers=false needed in systemd stubby.service file for stubby to start. + Thanks Archcan and Petr Menšík + * PR #323: Reduce log messages when interface is offline. + Thanks Russ Bubley and Andre Heider * 2022-08-19: version 0.4.2 * Fix Issue #320: Stubby doesn't start without "log_level" diff --git a/src/server.c b/src/server.c index 0a62817..29c60fd 100644 --- a/src/server.c +++ b/src/server.c @@ -321,6 +321,7 @@ static void incoming_request_handler(getdns_context *context, uint32_t qtype; uint32_t qclass; getdns_return_t r; + getdns_return_t *prev_r = (getdns_return_t *)userarg; getdns_dict *header; uint32_t n; getdns_list *list; @@ -334,7 +335,6 @@ static void incoming_request_handler(getdns_context *context, uint32_t rr_type; (void)callback_type; - (void)userarg; if (!(qext = getdns_dict_create_with_context(context)) || !(msg = malloc(sizeof(dns_msg)))) @@ -418,16 +418,22 @@ static void incoming_request_handler(getdns_context *context, stubby_getdns_strerror(r)); else if ((r = getdns_general(context, qname_str, qtype, - qext, msg, &transaction_id, request_cb))) - stubby_error("Could not schedule query: %s", - stubby_getdns_strerror(r)); - else { + qext, msg, &transaction_id, request_cb))) { + if (!prev_r || r != *prev_r + || r != GETDNS_RETURN_NO_UPSTREAM_AVAILABLE) + stubby_error("Could not schedule query: %s", + stubby_getdns_strerror(r)); + } else { DEBUG_SERVER("scheduled: %p %"PRIu64" for %s %d\n", (void *)msg, transaction_id, qname_str, (int)qtype); getdns_dict_destroy(qext); free(qname_str); + if (prev_r) + *prev_r = r; return; } + if (prev_r) + *prev_r = r; error: if (qname_str) free(qname_str); @@ -459,7 +465,7 @@ static void incoming_request_handler(getdns_context *context, getdns_dict_destroy(response); } -int server_listen(getdns_context *context, int validate_dnssec) +int server_listen(getdns_context *context, void *userarg, int validate_dnssec) { const getdns_list *listen_list; @@ -469,7 +475,7 @@ int server_listen(getdns_context *context, int validate_dnssec) if ( !listen_list ) return 0; if ( getdns_context_set_listen_addresses( - context, listen_list, NULL, incoming_request_handler) ) { + context, listen_list, userarg, incoming_request_handler) ) { stubby_error("error: Could not bind on given addresses: %s", strerror(errno)); return 0; } diff --git a/src/server.h b/src/server.h index 661b553..04cd459 100644 --- a/src/server.h +++ b/src/server.h @@ -30,6 +30,6 @@ #include -int server_listen(getdns_context *context, int validate_dnssec); +int server_listen(getdns_context *context, void *userarg, int validate_dnssec); #endif diff --git a/src/stubby.c b/src/stubby.c index f100b74..84d5517 100644 --- a/src/stubby.c +++ b/src/stubby.c @@ -115,6 +115,7 @@ main(int argc, char **argv) #endif getdns_context *context = NULL; getdns_return_t r; + getdns_return_t previous_schedule_r = GETDNS_RETURN_GOOD; int opt; long config_log_level = NO_LOGGING; char *ep; @@ -195,7 +196,7 @@ main(int argc, char **argv) goto tidy_and_exit; } - if ( !server_listen(context, dnssec_validation) ) { + if ( !server_listen(context, (void *)&previous_schedule_r, dnssec_validation)) { r = EXIT_FAILURE; goto tidy_and_exit; }