Skip to content

Commit

Permalink
ipset-pf-support, simplification of code.
Browse files Browse the repository at this point in the history
  • Loading branch information
wcawijngaards committed Jul 2, 2024
1 parent 03ac902 commit 65e7253
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 31 deletions.
8 changes: 3 additions & 5 deletions daemon/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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++)
Expand Down
12 changes: 3 additions & 9 deletions libunbound/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions libunbound/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
8 changes: 4 additions & 4 deletions libunbound/libunbound.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
19 changes: 14 additions & 5 deletions services/modstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)) {
Expand All @@ -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++;
Expand All @@ -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++) {
Expand Down
12 changes: 9 additions & 3 deletions services/modstack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions testcode/unitzonemd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 65e7253

Please sign in to comment.