We store a list of resolver strategies in order of their preference in
authorflorian <florian@openbsd.org>
Sun, 25 Jul 2021 08:34:43 +0000 (08:34 +0000)
committerflorian <florian@openbsd.org>
Sun, 25 Jul 2021 08:34:43 +0000 (08:34 +0000)
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

sbin/unwind/parse.y
sbin/unwind/resolver.c
sbin/unwind/unwind.c
sbin/unwind/unwind.h

index 5fb7966..d361ae5 100644 (file)
@@ -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;
                        }
                        ;
 
index 81610f6..705366c 100644 (file)
@@ -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;
index 4697767..2e3ae7c 100644 (file)
@@ -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);
index 59379a4..42fff96 100644 (file)
@@ -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;
 };