ipset-pf-support, simplification of code.

This commit is contained in:
W.C.A. Wijngaards 2024-07-02 09:08:27 +02:00
parent 03ac902296
commit 65e7253d19
7 changed files with 35 additions and 31 deletions

View 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++)

View 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_setup(&ctx->mods, cfg->module_conf, ctx->env))
return UB_INITFAIL;
listen_setup_locks();
log_edns_known_options(VERB_ALGO, ctx->env);

View 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 */

View 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) {

View 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)
{
@ -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++) {

View 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.

View 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);