Skip to content

Commit

Permalink
Fix PR #323 Reduce spam messages when interface is offline
Browse files Browse the repository at this point in the history
  • Loading branch information
wtoorop committed Dec 22, 2022
1 parent 2599577 commit 0122bc0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
5 changes: 4 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
20 changes: 13 additions & 7 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))))
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@

#include <getdns/getdns.h>

int server_listen(getdns_context *context, int validate_dnssec);
int server_listen(getdns_context *context, void *userarg, int validate_dnssec);

#endif
3 changes: 2 additions & 1 deletion src/stubby.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 0122bc0

Please sign in to comment.