Skip to content

Commit

Permalink
Merge remote-tracking branch 'nlnet/master'
Browse files Browse the repository at this point in the history
* nlnet/master:
  - Check repinfo in worker_handle_request, if null, drop it.
  - Fix to timeval_add for remaining second in microseconds.
  - Fix to return after failed auth zone http chunk write. - Fix to remove unused test for task_probe existance.
  - Fix NLnetLabs#52 NLnetLabs#53, fix for example fail program.
  - For NLnetLabs#52 NLnetLabs#53, second context does not close logfile override.
  Fix comment.
  - Add hex print of trust anchor pointer to trust anchor file temp   name to make it unique, for libunbound created multiple contexts.
  - Add verbose log message when auth zone file is written, at level 4.
  • Loading branch information
jedisct1 committed Aug 7, 2019
2 parents d7a853f + fa506e3 commit 754f737
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 16 deletions.
2 changes: 1 addition & 1 deletion daemon/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)++;
}
Expand Down
2 changes: 1 addition & 1 deletion daemon/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions doc/Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
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.
- 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.
- 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.

Expand Down
11 changes: 9 additions & 2 deletions libunbound/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 && !ctx->logfile_override) {
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;
Expand Down
3 changes: 3 additions & 0 deletions libunbound/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
11 changes: 9 additions & 2 deletions libunbound/libunbound.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
#include <iphlpapi.h>
#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)
{
Expand All @@ -90,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) {
Expand Down Expand Up @@ -328,8 +332,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();
Expand Down Expand Up @@ -471,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);
Expand Down
8 changes: 7 additions & 1 deletion services/authzone.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -4882,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);
Expand Down Expand Up @@ -6563,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) {
Expand Down
2 changes: 1 addition & 1 deletion services/mesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down
2 changes: 1 addition & 1 deletion testcode/delayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down
2 changes: 1 addition & 1 deletion testcode/fake_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down
2 changes: 1 addition & 1 deletion testcode/perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down
2 changes: 1 addition & 1 deletion util/mini_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down
2 changes: 1 addition & 1 deletion util/winsock_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down
7 changes: 4 additions & 3 deletions validator/autotrust.c
Original file line number Diff line number Diff line change
Expand Up @@ -1181,9 +1181,10 @@ 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 */
snprintf(tempf, sizeof(tempf), "%s.%d-%d", fname, (int)getpid(),
env->worker?*(int*)env->worker:0);
/* 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);
out = fopen(tempf, "w");
if(!out) {
Expand Down

0 comments on commit 754f737

Please sign in to comment.