diff options
author | Florian Obser <florian@cvs.openbsd.org> | 2021-07-25 08:34:44 +0000 |
---|---|---|
committer | Florian Obser <florian@cvs.openbsd.org> | 2021-07-25 08:34:44 +0000 |
commit | 49597f89d66f276987731cb4d0626bad5315466e (patch) | |
tree | f653e2b7dfaf487821bb453db32468ebc7e28287 | |
parent | e7d27d51e4801bd4c130ae25b01fe0aea730d57f (diff) |
We store a list of resolver strategies in order of their preference in
the configuration struct. This is also an implicit list of enabled
resolver strategies. We have also stored an explict lookup array of
enabled strategies outside of the configuration to be able to quickly
answer "is this strategy enabled" without traversing the preferences
list.
Move this table into the configuration so that we don't need to
"repair" it on config reload.
This fixes a bug where on startup the preferences list and enabled
lookup table were not in sync. It didn't matter in practice since we
do a config reload and then pass in DNSSEC trustanchors on startup.
Both actions combined repaired things.
OK benno
-rw-r--r-- | sbin/unwind/parse.y | 9 | ||||
-rw-r--r-- | sbin/unwind/resolver.c | 20 | ||||
-rw-r--r-- | sbin/unwind/unwind.c | 5 | ||||
-rw-r--r-- | sbin/unwind/unwind.h | 3 |
4 files changed, 16 insertions, 21 deletions
diff --git a/sbin/unwind/parse.y b/sbin/unwind/parse.y index 5fb796655b8..d361ae55cae 100644 --- a/sbin/unwind/parse.y +++ b/sbin/unwind/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.25 2021/02/27 10:32:28 florian Exp $ */ +/* $OpenBSD: parse.y,v 1.26 2021/07/25 08:34:43 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -192,7 +192,11 @@ block_list : BLOCK LIST STRING log { } ; -uw_pref : PREFERENCE { conf->res_pref.len = 0; } pref_block +uw_pref : PREFERENCE { + conf->res_pref.len = 0; + memset(conf->enabled_resolvers, 0, + sizeof(conf->enabled_resolvers)); + } pref_block ; pref_block : '{' optnl prefopts_l '}' @@ -211,6 +215,7 @@ prefoptsl : prefopt { YYERROR; } conf->res_pref.types[conf->res_pref.len++] = $1; + conf->enabled_resolvers[$1] = 1; } ; diff --git a/sbin/unwind/resolver.c b/sbin/unwind/resolver.c index 81610f68b3e..705366c7a30 100644 --- a/sbin/unwind/resolver.c +++ b/sbin/unwind/resolver.c @@ -1,4 +1,4 @@ -/* $OpenBSD: resolver.c,v 1.144 2021/07/12 15:09:19 beck Exp $ */ +/* $OpenBSD: resolver.c,v 1.145 2021/07/25 08:34:43 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -211,7 +211,6 @@ static struct imsgev *iev_frontend; static struct imsgev *iev_main; struct uw_forwarder_head autoconf_forwarder_list; struct uw_resolver *resolvers[UW_RES_NONE]; -int enabled_resolvers[UW_RES_NONE]; struct timespec last_network_change; struct event trust_anchor_timer; @@ -672,10 +671,6 @@ resolver_dispatch_main(int fd, short event, void *bula) "IMSG_RECONF_CONF", __func__); restart = resolvers_to_restart(resolver_conf, nconf); merge_config(resolver_conf, nconf); - memset(enabled_resolvers, 0, sizeof(enabled_resolvers)); - for (i = 0; i < resolver_conf->res_pref.len; i++) - enabled_resolvers[ - resolver_conf->res_pref.types[i]] = 1; nconf = NULL; for (i = 0; i < UW_RES_NONE; i++) if (restart[i]) @@ -1088,7 +1083,7 @@ new_resolver(enum uw_resolver_type type, enum uw_resolver_state state) free_resolver(resolvers[type]); resolvers[type] = NULL; - if (!enabled_resolvers[type]) + if (!resolver_conf->enabled_resolvers[type]) return; switch (type) { @@ -2162,8 +2157,6 @@ int * resolvers_to_restart(struct uw_conf *oconf, struct uw_conf *nconf) { static int restart[UW_RES_NONE]; - int o_enabled[UW_RES_NONE]; - int n_enabled[UW_RES_NONE]; int i; memset(&restart, 0, sizeof(restart)); @@ -2176,16 +2169,9 @@ resolvers_to_restart(struct uw_conf *oconf, struct uw_conf *nconf) &nconf->uw_dot_forwarder_list)) { restart[UW_RES_DOT] = 1; } - memset(o_enabled, 0, sizeof(o_enabled)); - memset(n_enabled, 0, sizeof(n_enabled)); - for (i = 0; i < oconf->res_pref.len; i++) - o_enabled[oconf->res_pref.types[i]] = 1; - - for (i = 0; i < nconf->res_pref.len; i++) - n_enabled[nconf->res_pref.types[i]] = 1; for (i = 0; i < UW_RES_NONE; i++) { - if (n_enabled[i] != o_enabled[i]) + if (oconf->enabled_resolvers[i] != nconf->enabled_resolvers[i]) restart[i] = 1; } return restart; diff --git a/sbin/unwind/unwind.c b/sbin/unwind/unwind.c index 4697767ac34..2e3ae7c93e5 100644 --- a/sbin/unwind/unwind.c +++ b/sbin/unwind/unwind.c @@ -1,4 +1,4 @@ -/* $OpenBSD: unwind.c,v 1.61 2021/02/27 10:32:28 florian Exp $ */ +/* $OpenBSD: unwind.c,v 1.62 2021/07/25 08:34:43 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -694,6 +694,7 @@ config_new_empty(void) UW_RES_DHCP, UW_RES_ASR}; struct uw_conf *xconf; + int i; xconf = calloc(1, sizeof(*xconf)); if (xconf == NULL) @@ -702,6 +703,8 @@ config_new_empty(void) memcpy(&xconf->res_pref.types, &default_res_pref, sizeof(default_res_pref)); xconf->res_pref.len = nitems(default_res_pref); + for (i = 0; i < xconf->res_pref.len; i++) + xconf->enabled_resolvers[xconf->res_pref.types[i]] = 1; TAILQ_INIT(&xconf->uw_forwarder_list); TAILQ_INIT(&xconf->uw_dot_forwarder_list); diff --git a/sbin/unwind/unwind.h b/sbin/unwind/unwind.h index 59379a4ba99..42fff966e65 100644 --- a/sbin/unwind/unwind.h +++ b/sbin/unwind/unwind.h @@ -1,4 +1,4 @@ -/* $OpenBSD: unwind.h,v 1.54 2021/02/27 10:32:28 florian Exp $ */ +/* $OpenBSD: unwind.h,v 1.55 2021/07/25 08:34:43 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -154,6 +154,7 @@ struct uw_conf { struct uw_forwarder_head uw_dot_forwarder_list; struct force_tree force; struct resolver_preference res_pref; + int enabled_resolvers[UW_RES_NONE]; char *blocklist_file; int blocklist_log; }; |