Skip to content

Commit 0122bc0

Browse files
committed
Fix PR #323 Reduce spam messages when interface is offline
1 parent 2599577 commit 0122bc0

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

ChangeLog

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
* 2022-12-22: version 0.4.3
2-
* Fix Issue #330: PrivateUsers=false needed in systemd
2+
* Fix Issue #330 and PR#324: PrivateUsers=false needed in systemd
33
stubby.service file for stubby to start.
4+
Thanks Archcan and Petr Menšík
5+
* PR #323: Reduce log messages when interface is offline.
6+
Thanks Russ Bubley and Andre Heider
47

58
* 2022-08-19: version 0.4.2
69
* Fix Issue #320: Stubby doesn't start without "log_level"

src/server.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ static void incoming_request_handler(getdns_context *context,
321321
uint32_t qtype;
322322
uint32_t qclass;
323323
getdns_return_t r;
324+
getdns_return_t *prev_r = (getdns_return_t *)userarg;
324325
getdns_dict *header;
325326
uint32_t n;
326327
getdns_list *list;
@@ -334,7 +335,6 @@ static void incoming_request_handler(getdns_context *context,
334335
uint32_t rr_type;
335336

336337
(void)callback_type;
337-
(void)userarg;
338338

339339
if (!(qext = getdns_dict_create_with_context(context)) ||
340340
!(msg = malloc(sizeof(dns_msg))))
@@ -418,16 +418,22 @@ static void incoming_request_handler(getdns_context *context,
418418
stubby_getdns_strerror(r));
419419

420420
else if ((r = getdns_general(context, qname_str, qtype,
421-
qext, msg, &transaction_id, request_cb)))
422-
stubby_error("Could not schedule query: %s",
423-
stubby_getdns_strerror(r));
424-
else {
421+
qext, msg, &transaction_id, request_cb))) {
422+
if (!prev_r || r != *prev_r
423+
|| r != GETDNS_RETURN_NO_UPSTREAM_AVAILABLE)
424+
stubby_error("Could not schedule query: %s",
425+
stubby_getdns_strerror(r));
426+
} else {
425427
DEBUG_SERVER("scheduled: %p %"PRIu64" for %s %d\n",
426428
(void *)msg, transaction_id, qname_str, (int)qtype);
427429
getdns_dict_destroy(qext);
428430
free(qname_str);
431+
if (prev_r)
432+
*prev_r = r;
429433
return;
430434
}
435+
if (prev_r)
436+
*prev_r = r;
431437
error:
432438
if (qname_str)
433439
free(qname_str);
@@ -459,7 +465,7 @@ static void incoming_request_handler(getdns_context *context,
459465
getdns_dict_destroy(response);
460466
}
461467

462-
int server_listen(getdns_context *context, int validate_dnssec)
468+
int server_listen(getdns_context *context, void *userarg, int validate_dnssec)
463469
{
464470
const getdns_list *listen_list;
465471

@@ -469,7 +475,7 @@ int server_listen(getdns_context *context, int validate_dnssec)
469475
if ( !listen_list )
470476
return 0;
471477
if ( getdns_context_set_listen_addresses(
472-
context, listen_list, NULL, incoming_request_handler) ) {
478+
context, listen_list, userarg, incoming_request_handler) ) {
473479
stubby_error("error: Could not bind on given addresses: %s", strerror(errno));
474480
return 0;
475481
}

src/server.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030

3131
#include <getdns/getdns.h>
3232

33-
int server_listen(getdns_context *context, int validate_dnssec);
33+
int server_listen(getdns_context *context, void *userarg, int validate_dnssec);
3434

3535
#endif

src/stubby.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ main(int argc, char **argv)
115115
#endif
116116
getdns_context *context = NULL;
117117
getdns_return_t r;
118+
getdns_return_t previous_schedule_r = GETDNS_RETURN_GOOD;
118119
int opt;
119120
long config_log_level = NO_LOGGING;
120121
char *ep;
@@ -195,7 +196,7 @@ main(int argc, char **argv)
195196
goto tidy_and_exit;
196197
}
197198

198-
if ( !server_listen(context, dnssec_validation) ) {
199+
if ( !server_listen(context, (void *)&previous_schedule_r, dnssec_validation)) {
199200
r = EXIT_FAILURE;
200201
goto tidy_and_exit;
201202
}

0 commit comments

Comments
 (0)