From 7d5ab2f4de71a0891f528e20bb272af0b2b297c6 Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Mon, 29 Jul 2019 09:25:49 +0200 Subject: [PATCH 1/8] - Add verbose log message when auth zone file is written, at level 4. --- doc/Changelog | 3 +++ services/authzone.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/doc/Changelog b/doc/Changelog index 089c4de65..3b9845c4d 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,6 @@ +29 July 2019: Wouter + - Add verbose log message when auth zone file is written, at level 4. + 23 July 2019: Wouter - Fix question section mismatch in local zone redirect. diff --git a/services/authzone.c b/services/authzone.c index 312abad8b..523a2cdca 100644 --- a/services/authzone.c +++ b/services/authzone.c @@ -4867,6 +4867,11 @@ xfr_write_after_update(struct auth_xfer* xfr, struct module_env* env) if(cfg->chrootdir && cfg->chrootdir[0] && strncmp(zfilename, cfg->chrootdir, strlen(cfg->chrootdir)) == 0) zfilename += strlen(cfg->chrootdir); + if(verbosity >= VERB_ALGO) { + char nm[255+1]; + dname_str(z->name, nm); + verbose(VERB_ALGO, "write zonefile %s for %s", zfilename, nm); + } /* write to tempfile first */ if((size_t)strlen(zfilename) + 16 > sizeof(tmpfile)) { From 27811ffaa9a5f4e5e00219eba72216b20925ddbb Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Mon, 29 Jul 2019 16:51:40 +0200 Subject: [PATCH 2/8] - Add hex print of trust anchor pointer to trust anchor file temp name to make it unique, for libunbound created multiple contexts. --- doc/Changelog | 2 ++ validator/autotrust.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 3b9845c4d..6100d9a04 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,7 @@ 29 July 2019: Wouter - Add verbose log message when auth zone file is written, at level 4. + - Add hex print of trust anchor pointer to trust anchor file temp + name to make it unique, for libunbound created multiple contexts. 23 July 2019: Wouter - Fix question section mismatch in local zone redirect. diff --git a/validator/autotrust.c b/validator/autotrust.c index a72967302..dceb2dcf5 100644 --- a/validator/autotrust.c +++ b/validator/autotrust.c @@ -1182,8 +1182,8 @@ void autr_write_file(struct module_env* env, struct trust_anchor* tp) return; } /* unique name with pid number and thread number */ - snprintf(tempf, sizeof(tempf), "%s.%d-%d", fname, (int)getpid(), - env->worker?*(int*)env->worker:0); + snprintf(tempf, sizeof(tempf), "%s.%d-%d-%llx", fname, (int)getpid(), + env->worker?*(int*)env->worker:0, (long long int)tp); verbose(VERB_ALGO, "autotrust: write to disk: %s", tempf); out = fopen(tempf, "w"); if(!out) { From fe0b1da859a1327fe103d28e151d0add1aacfdf3 Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Mon, 29 Jul 2019 16:58:23 +0200 Subject: [PATCH 3/8] Fix comment. --- validator/autotrust.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/validator/autotrust.c b/validator/autotrust.c index dceb2dcf5..5f20bf5f5 100644 --- a/validator/autotrust.c +++ b/validator/autotrust.c @@ -1181,7 +1181,8 @@ void autr_write_file(struct module_env* env, struct trust_anchor* tp) log_err("autr_write_file: Module environment is NULL."); return; } - /* unique name with pid number and thread number */ + /* unique name with pid number, thread number, and struct pointer + * (the pointer uniquifies for multiple libunbound contexts) */ snprintf(tempf, sizeof(tempf), "%s.%d-%d-%llx", fname, (int)getpid(), env->worker?*(int*)env->worker:0, (long long int)tp); verbose(VERB_ALGO, "autotrust: write to disk: %s", tempf); From e860d39f54210749e55cda90d89cab681cd00bc2 Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Thu, 1 Aug 2019 09:15:33 +0200 Subject: [PATCH 4/8] - For #52 #53, second context does not close logfile override. --- doc/Changelog | 3 +++ libunbound/context.c | 11 +++++++++-- libunbound/context.h | 3 +++ libunbound/libunbound.c | 7 ++++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 6100d9a04..50175902e 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,6 @@ +1 August 2019: Wouter + - For #52 #53, second context does not close logfile override. + 29 July 2019: Wouter - Add verbose log message when auth zone file is written, at level 4. - Add hex print of trust anchor pointer to trust anchor file temp diff --git a/libunbound/context.c b/libunbound/context.c index 20e3680ec..6d8b7b7b5 100644 --- a/libunbound/context.c +++ b/libunbound/context.c @@ -57,9 +57,16 @@ context_finalize(struct ub_ctx* ctx) { struct config_file* cfg = ctx->env->cfg; verbosity = cfg->verbosity; - if(ctx->logfile_override) + if(ctx_logfile_overridden) { + log_file(NULL); /* clear that override */ + ctx_logfile_overridden = 0; + } + if(ctx->logfile_override) { + ctx_logfile_overridden = 1; log_file(ctx->log_out); - else log_init(cfg->logfile, cfg->use_syslog, NULL); + } else { + log_init(cfg->logfile, cfg->use_syslog, NULL); + } config_apply(cfg); if(!modstack_setup(&ctx->mods, cfg->module_conf, ctx->env)) return UB_INITFAIL; diff --git a/libunbound/context.h b/libunbound/context.h index 11147226a..c3900154f 100644 --- a/libunbound/context.h +++ b/libunbound/context.h @@ -52,6 +52,9 @@ struct tube; struct sldns_buffer; struct ub_event_base; +/** store that the logfile has a debug override */ +extern int ctx_logfile_overridden; + /** * The context structure * diff --git a/libunbound/libunbound.c b/libunbound/libunbound.c index 9dd7d6dbe..b5f1137b8 100644 --- a/libunbound/libunbound.c +++ b/libunbound/libunbound.c @@ -79,6 +79,9 @@ #include #endif /* UB_ON_WINDOWS */ +/** store that the logfile has a debug override */ +int ctx_logfile_overridden = 0; + /** create context functionality, but no pipes */ static struct ub_ctx* ub_ctx_create_nopipe(void) { @@ -328,8 +331,10 @@ ub_ctx_delete(struct ub_ctx* ctx) ub_randfree(ctx->seed_rnd); alloc_clear(&ctx->superalloc); traverse_postorder(&ctx->queries, delq, NULL); - if(ctx->logfile_override) + if(ctx_logfile_overridden) { log_file(NULL); + ctx_logfile_overridden = 0; + } free(ctx); #ifdef USE_WINSOCK WSACleanup(); From 21f740d3134eb4158606e7ebdef45c93024e33fd Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Thu, 1 Aug 2019 09:34:44 +0200 Subject: [PATCH 5/8] - Fix #52 #53, fix for example fail program. --- doc/Changelog | 1 + libunbound/context.c | 2 +- libunbound/libunbound.c | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 50175902e..7042734d8 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,6 @@ 1 August 2019: Wouter - For #52 #53, second context does not close logfile override. + - Fix #52 #53, fix for example fail program. 29 July 2019: Wouter - Add verbose log message when auth zone file is written, at level 4. diff --git a/libunbound/context.c b/libunbound/context.c index 6d8b7b7b5..b8fe87d2e 100644 --- a/libunbound/context.c +++ b/libunbound/context.c @@ -57,7 +57,7 @@ context_finalize(struct ub_ctx* ctx) { struct config_file* cfg = ctx->env->cfg; verbosity = cfg->verbosity; - if(ctx_logfile_overridden) { + if(ctx_logfile_overridden && !ctx->logfile_override) { log_file(NULL); /* clear that override */ ctx_logfile_overridden = 0; } diff --git a/libunbound/libunbound.c b/libunbound/libunbound.c index b5f1137b8..263dde5a4 100644 --- a/libunbound/libunbound.c +++ b/libunbound/libunbound.c @@ -93,7 +93,8 @@ static struct ub_ctx* ub_ctx_create_nopipe(void) #endif checklock_start(); - log_init(NULL, 0, NULL); /* logs to stderr */ + if(!ctx_logfile_overridden) + log_init(NULL, 0, NULL); /* logs to stderr */ log_ident_set("libunbound"); #ifdef USE_WINSOCK if((r = WSAStartup(MAKEWORD(2,2), &wsa_data)) != 0) { @@ -476,6 +477,7 @@ int ub_ctx_debugout(struct ub_ctx* ctx, void* out) { lock_basic_lock(&ctx->cfglock); log_file((FILE*)out); + ctx_logfile_overridden = 1; ctx->logfile_override = 1; ctx->log_out = out; lock_basic_unlock(&ctx->cfglock); From 199e6c586b1616ed0ad8f6e872a40219309cf011 Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Thu, 1 Aug 2019 16:40:52 +0200 Subject: [PATCH 6/8] - Fix to return after failed auth zone http chunk write. - Fix to remove unused test for task_probe existance. --- doc/Changelog | 2 ++ services/authzone.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/Changelog b/doc/Changelog index 7042734d8..e6b0de40d 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,6 +1,8 @@ 1 August 2019: Wouter - For #52 #53, second context does not close logfile override. - Fix #52 #53, fix for example fail program. + - Fix to return after failed auth zone http chunk write. + - Fix to remove unused test for task_probe existance. 29 July 2019: Wouter - Add verbose log message when auth zone file is written, at level 4. diff --git a/services/authzone.c b/services/authzone.c index 523a2cdca..792dc2049 100644 --- a/services/authzone.c +++ b/services/authzone.c @@ -4887,6 +4887,7 @@ xfr_write_after_update(struct auth_xfer* xfr, struct module_env* env) if(!auth_zone_write_chunks(xfr, tmpfile)) { unlink(tmpfile); lock_rw_unlock(&z->lock); + return; } } else if(!auth_zone_write_file(z, tmpfile)) { unlink(tmpfile); @@ -6568,7 +6569,7 @@ xfr_set_timeout(struct auth_xfer* xfr, struct module_env* env, /* don't lookup_only, if lookup timeout is 0 anyway, * or if we don't have masters to lookup */ tv.tv_sec = 0; - if(xfr->task_probe && xfr->task_probe->worker == NULL) + if(xfr->task_probe->worker == NULL) xfr->task_probe->only_lookup = 1; } if(verbosity >= VERB_ALGO) { From df0c844eed5459a20ce5304547cbe7cbd5864002 Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Thu, 1 Aug 2019 16:48:41 +0200 Subject: [PATCH 7/8] - Fix to timeval_add for remaining second in microseconds. --- daemon/stats.c | 2 +- doc/Changelog | 1 + services/mesh.c | 2 +- testcode/delayer.c | 2 +- testcode/fake_event.c | 2 +- testcode/perf.c | 2 +- util/mini_event.c | 2 +- util/winsock_event.c | 2 +- 8 files changed, 8 insertions(+), 7 deletions(-) diff --git a/daemon/stats.c b/daemon/stats.c index 504b0efcc..a01fb6d34 100644 --- a/daemon/stats.c +++ b/daemon/stats.c @@ -77,7 +77,7 @@ stats_timeval_add(long long* d_sec, long long* d_usec, long long add_sec, long l #ifndef S_SPLINT_S (*d_sec) += add_sec; (*d_usec) += add_usec; - if((*d_usec) > 1000000) { + if((*d_usec) >= 1000000) { (*d_usec) -= 1000000; (*d_sec)++; } diff --git a/doc/Changelog b/doc/Changelog index e6b0de40d..4348a3d0e 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -3,6 +3,7 @@ - Fix #52 #53, fix for example fail program. - Fix to return after failed auth zone http chunk write. - Fix to remove unused test for task_probe existance. + - Fix to timeval_add for remaining second in microseconds. 29 July 2019: Wouter - Add verbose log message when auth zone file is written, at level 4. diff --git a/services/mesh.c b/services/mesh.c index 0d7118af9..27f919401 100644 --- a/services/mesh.c +++ b/services/mesh.c @@ -85,7 +85,7 @@ timeval_add(struct timeval* d, const struct timeval* add) #ifndef S_SPLINT_S d->tv_sec += add->tv_sec; d->tv_usec += add->tv_usec; - if(d->tv_usec > 1000000 ) { + if(d->tv_usec >= 1000000 ) { d->tv_usec -= 1000000; d->tv_sec++; } diff --git a/testcode/delayer.c b/testcode/delayer.c index 4abcfc235..655e4a1e7 100644 --- a/testcode/delayer.c +++ b/testcode/delayer.c @@ -174,7 +174,7 @@ dl_tv_add(struct timeval* t1, const struct timeval* t2) #ifndef S_SPLINT_S t1->tv_sec += t2->tv_sec; t1->tv_usec += t2->tv_usec; - while(t1->tv_usec > 1000000) { + while(t1->tv_usec >= 1000000) { t1->tv_usec -= 1000000; t1->tv_sec++; } diff --git a/testcode/fake_event.c b/testcode/fake_event.c index 713e24759..d6e904a4d 100644 --- a/testcode/fake_event.c +++ b/testcode/fake_event.c @@ -100,7 +100,7 @@ timeval_add(struct timeval* d, const struct timeval* add) #ifndef S_SPLINT_S d->tv_sec += add->tv_sec; d->tv_usec += add->tv_usec; - if(d->tv_usec > 1000000) { + if(d->tv_usec >= 1000000) { d->tv_usec -= 1000000; d->tv_sec++; } diff --git a/testcode/perf.c b/testcode/perf.c index d6d2b0529..5b170ca57 100644 --- a/testcode/perf.c +++ b/testcode/perf.c @@ -177,7 +177,7 @@ perf_tv_add(struct timeval* t1, struct timeval* t2) #ifndef S_SPLINT_S t1->tv_sec += t2->tv_sec; t1->tv_usec += t2->tv_usec; - while(t1->tv_usec > 1000000) { + while(t1->tv_usec >= 1000000) { t1->tv_usec -= 1000000; t1->tv_sec++; } diff --git a/util/mini_event.c b/util/mini_event.c index faadf1a23..661d88d2e 100644 --- a/util/mini_event.c +++ b/util/mini_event.c @@ -313,7 +313,7 @@ int event_add(struct event* ev, struct timeval* tv) struct timeval *now = ev->ev_base->time_tv; ev->ev_timeout.tv_sec = tv->tv_sec + now->tv_sec; ev->ev_timeout.tv_usec = tv->tv_usec + now->tv_usec; - while(ev->ev_timeout.tv_usec > 1000000) { + while(ev->ev_timeout.tv_usec >= 1000000) { ev->ev_timeout.tv_usec -= 1000000; ev->ev_timeout.tv_sec++; } diff --git a/util/winsock_event.c b/util/winsock_event.c index 63d98796d..de6c28ecb 100644 --- a/util/winsock_event.c +++ b/util/winsock_event.c @@ -558,7 +558,7 @@ int event_add(struct event *ev, struct timeval *tv) struct timeval *now = ev->ev_base->time_tv; ev->ev_timeout.tv_sec = tv->tv_sec + now->tv_sec; ev->ev_timeout.tv_usec = tv->tv_usec + now->tv_usec; - while(ev->ev_timeout.tv_usec > 1000000) { + while(ev->ev_timeout.tv_usec >= 1000000) { ev->ev_timeout.tv_usec -= 1000000; ev->ev_timeout.tv_sec++; } From fa506e3cdae217a32a15994e7612980a152c7462 Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Thu, 1 Aug 2019 16:57:36 +0200 Subject: [PATCH 8/8] - Check repinfo in worker_handle_request, if null, drop it. --- daemon/worker.c | 2 +- doc/Changelog | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/daemon/worker.c b/daemon/worker.c index bc2ca5aa0..263fcddfe 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -1095,7 +1095,7 @@ worker_handle_request(struct comm_point* c, void* arg, int error, struct respip_client_info* cinfo = NULL, cinfo_tmp; memset(&qinfo, 0, sizeof(qinfo)); - if(error != NETEVENT_NOERROR) { + if(error != NETEVENT_NOERROR || !repinfo) { /* some bad tcp query DNS formats give these error calls */ verbose(VERB_ALGO, "handle request called with err=%d", error); return 0; diff --git a/doc/Changelog b/doc/Changelog index 4348a3d0e..33c7fdfea 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -4,6 +4,7 @@ - Fix to return after failed auth zone http chunk write. - Fix to remove unused test for task_probe existance. - Fix to timeval_add for remaining second in microseconds. + - Check repinfo in worker_handle_request, if null, drop it. 29 July 2019: Wouter - Add verbose log message when auth zone file is written, at level 4.