]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
ipset-pf-support, simplification of code.
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Tue, 2 Jul 2024 07:08:27 +0000 (09:08 +0200)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Tue, 2 Jul 2024 07:08:27 +0000 (09:08 +0200)
daemon/daemon.c
libunbound/context.c
libunbound/context.h
libunbound/libunbound.c
services/modstack.c
services/modstack.h
testcode/unitzonemd.c

index eb933cc939ddc19615bd9a8bc8143c5902042985..ab3d182c312113bec774790cb89e530c57291b28 100644 (file)
@@ -259,7 +259,7 @@ daemon_init(void)
        tzset();
 #endif
        daemon->need_to_exit = 0;
-       memset(&daemon->mods, 0, sizeof(daemon->mods));
+       modstack_init(&daemon->mods);
        if(!(daemon->env = (struct module_env*)calloc(1, 
                sizeof(*daemon->env)))) {
                free(daemon);
@@ -467,9 +467,7 @@ static void daemon_setup_modules(struct daemon* daemon)
        daemon->env->alloc = &daemon->superalloc;
        daemon->env->worker = NULL;
        daemon->env->need_to_validate = 0; /* set by module init below */
-       if(daemon->mods.num != 0)
-               modstack_deinit(&daemon->mods, daemon->env);
-       if(!modstack_call_init(&daemon->mods, daemon->cfg->module_conf,
+       if(!modstack_setup(&daemon->mods, daemon->cfg->module_conf,
                daemon->env)) {
                fatal_exit("failed to setup modules");
        }
@@ -906,7 +904,7 @@ daemon_delete(struct daemon* daemon)
        size_t i;
        if(!daemon)
                return;
-       modstack_deinit(&daemon->mods, daemon->env);
+       modstack_desetup(&daemon->mods, daemon->env);
        modstack_destartup(&daemon->mods, daemon->env);
        daemon_remote_delete(daemon->rc);
        for(i = 0; i < daemon->num_ports; i++)
index f55aeb6667743dcd65c166cc140606a2e2c3ca8d..5b2d36b2d318cabe3847f8d90c5468efc07856c8 100644 (file)
@@ -56,9 +56,6 @@
 #include "iterator/iter_fwd.h"
 #include "iterator/iter_hints.h"
 
-/** If the modules have started, once. */
-int modstack_started = 0;
-
 int 
 context_finalize(struct ub_ctx* ctx)
 {
@@ -78,12 +75,9 @@ context_finalize(struct ub_ctx* ctx)
        ctx->pipe_pid = getpid();
        cfg_apply_local_port_policy(cfg, 65536);
        config_apply(cfg);
-       if(!modstack_started) {
-               modstack_started = 1;
-               if(!modstack_startup(&ctx->mods, cfg->module_conf, ctx->env))
-                       return UB_INITFAIL;
-       }
-       if(!modstack_call_init(&ctx->mods, cfg->module_conf, ctx->env))
+       if(!modstack_startup(&ctx->mods, cfg->module_conf, ctx->env))
+               return UB_INITFAIL;
+       if(!modstack_setup(&ctx->mods, cfg->module_conf, ctx->env))
                return UB_INITFAIL;
        listen_setup_locks();
        log_edns_known_options(VERB_ALGO, ctx->env);
index 0a48db72d4d36cba7a3dfe4da8bf8d9575104b17..c0fc80e57be4d2e425cf9f1b65d10aeb7e142bbe 100644 (file)
@@ -337,7 +337,4 @@ struct ctx_query* context_deserialize_answer(struct ub_ctx* ctx,
 struct ctx_query* context_deserialize_cancel(struct ub_ctx* ctx, 
        uint8_t* p, uint32_t len);
 
-/** If the modules have started. */
-extern int modstack_started;
-
 #endif /* LIBUNBOUND_CONTEXT_H */
index 4b6e60c08a86981817f6ab6997a12ca50b361f46..561e41fba8d1f9b1dca9cf2d2fe2b4025cfc5d2b 100644 (file)
@@ -172,7 +172,7 @@ static struct ub_ctx* ub_ctx_create_nopipe(void)
        ctx->env->alloc = &ctx->superalloc;
        ctx->env->worker = NULL;
        ctx->env->need_to_validate = 0;
-       memset(&ctx->mods, 0, sizeof(ctx->mods));
+       modstack_init(&ctx->mods);
        ctx->env->modstack = &ctx->mods;
        rbtree_init(&ctx->queries, &context_query_cmp);
        return ctx;
@@ -188,7 +188,7 @@ ub_ctx_create(void)
                int e = errno;
                ub_randfree(ctx->seed_rnd);
                config_delete(ctx->env->cfg);
-               modstack_deinit(&ctx->mods, ctx->env);
+               modstack_desetup(&ctx->mods, ctx->env);
                modstack_destartup(&ctx->mods, ctx->env);
                listen_desetup_locks();
                edns_known_options_delete(ctx->env);
@@ -203,7 +203,7 @@ ub_ctx_create(void)
                tube_delete(ctx->qq_pipe);
                ub_randfree(ctx->seed_rnd);
                config_delete(ctx->env->cfg);
-               modstack_deinit(&ctx->mods, ctx->env);
+               modstack_desetup(&ctx->mods, ctx->env);
                modstack_destartup(&ctx->mods, ctx->env);
                listen_desetup_locks();
                edns_known_options_delete(ctx->env);
@@ -362,7 +362,7 @@ ub_ctx_delete(struct ub_ctx* ctx)
        }
        libworker_delete_event(ctx->event_worker);
 
-       modstack_deinit(&ctx->mods, ctx->env);
+       modstack_desetup(&ctx->mods, ctx->env);
        modstack_destartup(&ctx->mods, ctx->env);
        a = ctx->alloc_list;
        while(a) {
index 85f0afc5db921cc1adb2694d5d026976c74b726b..f32f942c8fc3115b7fbd1d5f224f358b0be53fe7 100644 (file)
@@ -88,6 +88,13 @@ count_modules(const char* s)
         return num;
 }
 
+void
+modstack_init(struct module_stack* stack)
+{
+       stack->num = 0;
+       stack->mod = NULL;
+}
+
 int
 modstack_config(struct module_stack* stack, const char* module_conf)
 {
@@ -219,8 +226,8 @@ int
 modstack_startup(struct module_stack* stack, const char* module_conf,
        struct module_env* env)
 {
-       int i;
-       if (stack->num != 0)
+        int i;
+        if(stack->num != 0)
                fatal_exit("unexpected already initialised modules");
         /* fixed setup of the modules */
         if(!modstack_config(stack, module_conf)) {
@@ -242,11 +249,13 @@ modstack_startup(struct module_stack* stack, const char* module_conf,
 }
 
 int
-modstack_call_init(struct module_stack* stack, const char* module_conf,
+modstack_setup(struct module_stack* stack, const char* module_conf,
        struct module_env* env)
 {
         int i;
-        env->need_to_validate = 0; /* set by module setup below */
+       if(stack->num != 0)
+               modstack_desetup(stack, env);
+        env->need_to_validate = 0; /* set by module init below */
         for(i=0; i<stack->num; i++) {
                while(*module_conf && isspace(*module_conf))
                        module_conf++;
@@ -269,7 +278,7 @@ modstack_call_init(struct module_stack* stack, const char* module_conf,
 }
 
 void
-modstack_deinit(struct module_stack* stack, struct module_env* env)
+modstack_desetup(struct module_stack* stack, struct module_env* env)
 {
         int i;
         for(i=0; i<stack->num; i++) {
index 3f01be619d0cfb9512cfcce34be2a08f38cbd453..deb8b634b279bdc737bd8ec09f3553396de73af3 100644 (file)
@@ -54,6 +54,12 @@ struct module_stack {
        struct module_func_block** mod;
 };
 
+/**
+ * Init a stack of modules
+ * @param stack: initialised as empty.
+ */
+void modstack_init(struct module_stack* stack);
+
 /**
  * Initialises modules and assignes ids.
  * @param stack: Expected empty, filled according to module_conf
@@ -97,15 +103,15 @@ const char** module_list_avail(void);
  *     env.need_to_validate is set by the modules.
  * @return on false a module init failed.
  */
-int modstack_call_init(struct module_stack* stack, const char* module_conf,
+int modstack_setup(struct module_stack* stack, const char* module_conf,
        struct module_env* env);
 
 /**
- * Deinint the modules
+ * Desetup the modules, deinit.
  * @param stack: made empty.
  * @param env: module env for module deinit() calls.
  */
-void modstack_deinit(struct module_stack* stack, struct module_env* env);
+void modstack_desetup(struct module_stack* stack, struct module_env* env);
 
 /**
  * Destartup the modules, close, delete.
index 5336a1224cb200789346966bc3b8e2aed626c3fe..6ae29cdc4b5c190b47a873e96d13bb41f7dea782 100644 (file)
@@ -290,7 +290,7 @@ static void zonemd_verify_test(char* zname, char* zfile, char* tastr,
        memset(&mods, 0, sizeof(mods));
        if(!modstack_startup(&mods, env.cfg->module_conf, &env))
                fatal_exit("could not modstack_startup");
-       if(!modstack_call_init(&mods, env.cfg->module_conf, &env))
+       if(!modstack_setup(&mods, env.cfg->module_conf, &env))
                fatal_exit("could not modstack_call_init");
        env.mesh = mesh_create(&mods, &env);
        if(!env.mesh)
@@ -329,7 +329,7 @@ static void zonemd_verify_test(char* zname, char* zfile, char* tastr,
 
        /* desetup test harness */
        mesh_delete(env.mesh);
-       modstack_deinit(&mods, &env);
+       modstack_desetup(&mods, &env);
        modstack_destartup(&mods, &env);
        auth_zones_delete(env.auth_zones);
        anchors_delete(env.anchors);