Skip to content

Commit

Permalink
Remove unbound DNS context from global variable structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
brendonj committed Aug 27, 2020
1 parent 355d7a4 commit 33053da
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 0 additions & 2 deletions src/common/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#define _COMMON_GLOBAL_H

#include <stdint.h>
#include <unbound.h>

#include "ssl.h"

Expand All @@ -58,7 +57,6 @@ struct amp_global_t {
int ssl;
int control_port;
amp_ssl_opt_t amqp_ssl;
struct ub_ctx *ctx;
char *asnsock;
char *nssock;
int nssock_fd;
Expand Down
7 changes: 4 additions & 3 deletions src/measured/measured.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ int main(int argc, char *argv[]) {
struct event *signal_usr1 = NULL;
struct event *signal_tmax = NULL;
const char *event_noepoll = "1";
struct ub_ctx *dns_ctx;

memset(&meta, 0, sizeof(meta));
meta.inter_packet_delay = MIN_INTER_PACKET_DELAY;
Expand Down Expand Up @@ -494,7 +495,7 @@ int main(int argc, char *argv[]) {
meta.ampname = vars.ampname;

/* set up the dns resolver context */
if ( (vars.ctx = get_dns_context_config(cfg, &meta)) == NULL ) {
if ( (dns_ctx = get_dns_context_config(cfg, &meta)) == NULL ) {
Log(LOG_ALERT, "Failed to configure resolver, aborting.");
cfg_free(cfg);
exit(EXIT_FAILURE);
Expand Down Expand Up @@ -669,7 +670,7 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE);
}
resolver_socket_event = event_new(meta.base, vars.nssock_fd,
EV_READ|EV_PERSIST, resolver_socket_event_callback, vars.ctx);
EV_READ|EV_PERSIST, resolver_socket_event_callback, dns_ctx);
event_add(resolver_socket_event, NULL);

/* create the asn lookup unix socket and add event listener for it */
Expand Down Expand Up @@ -771,7 +772,7 @@ int main(int argc, char *argv[]) {

Log(LOG_DEBUG, "Shutting down DNS resolver");
close(vars.nssock_fd);
amp_resolver_context_delete(vars.ctx);
amp_resolver_context_delete(dns_ctx);

Log(LOG_DEBUG, "Cleaning up SSL");
ssl_cleanup();
Expand Down
14 changes: 8 additions & 6 deletions src/tests/testmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <pthread.h>
#include <unbound.h>
#include <sys/socket.h>

#include "debug.h"
Expand Down Expand Up @@ -103,6 +104,7 @@ int main(int argc, char *argv[]) {
int test_argc;
char **test_argv;
int do_ssl;
struct ub_ctx *dns_ctx;

/* there should be only a single test linked, so register it directly */
test_info = register_test();
Expand Down Expand Up @@ -192,12 +194,12 @@ int main(int argc, char *argv[]) {
/* set the nameserver to our custom one if specified */
if ( nameserver ) {
/* TODO we could parse the string and get up to MAXNS servers */
vars.ctx = amp_resolver_context_init(&nameserver, 1, sourcev4,sourcev6);
dns_ctx = amp_resolver_context_init(&nameserver, 1, sourcev4,sourcev6);
} else {
vars.ctx = amp_resolver_context_init(NULL, 0, sourcev4, sourcev6);
dns_ctx = amp_resolver_context_init(NULL, 0, sourcev4, sourcev6);
}

if ( vars.ctx == NULL ) {
if ( dns_ctx == NULL ) {
Log(LOG_ALERT, "Failed to configure resolver, aborting.");
exit(EXIT_FAILURE);
}
Expand Down Expand Up @@ -229,13 +231,13 @@ int main(int argc, char *argv[]) {
}

/* TODO update max targets and pass through to the resolver? */
amp_resolve_add(vars.ctx, &addrlist, &addrlist_lock, argv[i],
amp_resolve_add(dns_ctx, &addrlist, &addrlist_lock, argv[i],
family, -1);
}

if ( optind < argc ) {
/* wait for all the responses to come in */
ub_wait(vars.ctx);
ub_wait(dns_ctx);
}

/* add all the results of to the list of destinations */
Expand Down Expand Up @@ -332,7 +334,7 @@ int main(int argc, char *argv[]) {

free(test_argv);

ub_ctx_delete(vars.ctx);
ub_ctx_delete(dns_ctx);

if ( ssl_ctx != NULL ) {
ssl_cleanup();
Expand Down

0 comments on commit 33053da

Please sign in to comment.