Call module init init again, and new function startup and destartup.

NULL can be used if the function is not used. Open shared ports during
reload. Deinit is called during reload.
This commit is contained in:
W.C.A. Wijngaards 2024-07-01 16:10:07 +02:00
parent fd11cd9182
commit ff653a7ef8
32 changed files with 209 additions and 187 deletions

View File

@ -241,7 +241,7 @@ cachedb_apply_cfg(struct cachedb_env* cachedb_env, struct config_file* cfg)
}
int
cachedb_setup(struct module_env* env, int id)
cachedb_init(struct module_env* env, int id)
{
struct cachedb_env* cachedb_env = (struct cachedb_env*)calloc(1,
sizeof(struct cachedb_env));
@ -271,7 +271,7 @@ cachedb_setup(struct module_env* env, int id)
}
void
cachedb_desetup(struct module_env* env, int id)
cachedb_deinit(struct module_env* env, int id)
{
struct cachedb_env* cachedb_env;
if(!env || !env->modinfo[id])
@ -983,7 +983,7 @@ cachedb_get_mem(struct module_env* env, int id)
*/
static struct module_func_block cachedb_block = {
"cachedb",
&module_dummy_init, &module_dummy_init, &cachedb_setup, &cachedb_desetup, &cachedb_operate,
&cachedb_init, &cachedb_deinit, NULL, NULL, &cachedb_operate,
&cachedb_inform_super, &cachedb_clear, &cachedb_get_mem
};

View File

@ -91,9 +91,9 @@ struct cachedb_backend {
#define CACHEDB_HASHSIZE 256 /* bit hash */
/** Init the cachedb module */
int cachedb_setup(struct module_env* env, int id);
int cachedb_init(struct module_env* env, int id);
/** Deinit the cachedb module */
void cachedb_desetup(struct module_env* env, int id);
void cachedb_deinit(struct module_env* env, int id);
/** Operate on an event on a query (in qstate). */
void cachedb_operate(struct module_qstate* qstate, enum module_ev event,
int id, struct outbound_entry* outbound);

View File

@ -447,15 +447,12 @@ daemon_open_shared_ports(struct daemon* daemon)
int
daemon_privileged(struct daemon* daemon)
{
if(!daemon_open_shared_ports(daemon))
fatal_exit("could not open ports");
daemon->env->cfg = daemon->cfg;
daemon->env->alloc = &daemon->superalloc;
daemon->env->worker = NULL;
if(!modstack_init(&daemon->mods, daemon->cfg->module_conf,
if(!modstack_startup(&daemon->mods, daemon->cfg->module_conf,
daemon->env)) {
fatal_exit("failed to init modules");
fatal_exit("failed to startup modules");
}
return 1;
}
@ -470,7 +467,9 @@ 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(!modstack_setup(&daemon->mods, daemon->cfg->module_conf,
if(daemon->mods.num != 0)
modstack_deinit(&daemon->mods, daemon->env);
if(!modstack_call_init(&daemon->mods, daemon->cfg->module_conf,
daemon->env)) {
fatal_exit("failed to setup modules");
}
@ -877,7 +876,7 @@ daemon_cleanup(struct daemon* daemon)
daemon->views = NULL;
if(daemon->env->auth_zones)
auth_zones_cleanup(daemon->env->auth_zones);
/* key cache is cleared by module desetup during next daemon_fork() */
/* key cache is cleared by module deinit during next daemon_fork() */
daemon_remote_clear(daemon->rc);
for(i=0; i<daemon->num; i++)
worker_delete(daemon->workers[i]);
@ -907,7 +906,8 @@ daemon_delete(struct daemon* daemon)
size_t i;
if(!daemon)
return;
modstack_desetup(&daemon->mods, daemon->env);
modstack_deinit(&daemon->mods, daemon->env);
modstack_destartup(&daemon->mods, daemon->env);
daemon_remote_delete(daemon->rc);
for(i = 0; i < daemon->num_ports; i++)
listening_ports_free(daemon->ports[i]);

View File

@ -154,6 +154,14 @@ struct daemon {
*/
struct daemon* daemon_init(void);
/**
* Open shared listening ports (if needed).
* The cfg member pointer must have been set for the daemon.
* @param daemon: the daemon.
* @return: false on error.
*/
int daemon_open_shared_ports(struct daemon* daemon);
/**
* Do daemon setup that needs privileges
* like opening privileged ports or opening device files.

View File

@ -473,7 +473,11 @@ perform_setup(struct daemon* daemon, struct config_file* cfg, int debug_mode,
#endif
#ifdef HAVE_GETPWNAM
struct passwd *pwd = NULL;
#endif
if(!daemon_privileged(daemon))
fatal_exit("could not do privileged setup");
#ifdef HAVE_GETPWNAM
if(cfg->username && cfg->username[0]) {
if((pwd = getpwnam(cfg->username)) == NULL)
fatal_exit("user '%s' does not exist.", cfg->username);
@ -717,9 +721,9 @@ run_daemon(const char* cfgfile, int cmdline_verbose, int debug_mode, int need_pi
config_lookup_uid(cfg);
/* prepare */
if(!daemon_open_shared_ports(daemon))
fatal_exit("could not open ports");
if(!done_setup) {
if(!daemon_privileged(daemon))
fatal_exit("could not do privileged setup");
perform_setup(daemon, cfg, debug_mode, &cfgfile, need_pidfile);
done_setup = 1;
} else {

View File

@ -399,7 +399,7 @@ dns64_apply_cfg(struct dns64_env* dns64_env, struct config_file* cfg)
* \param id This instance's ID number.
*/
int
dns64_setup(struct module_env* env, int id)
dns64_init(struct module_env* env, int id)
{
struct dns64_env* dns64_env =
(struct dns64_env*)calloc(1, sizeof(struct dns64_env));
@ -433,7 +433,7 @@ free_ignore_aaaa_node(rbnode_type* node, void* ATTR_UNUSED(arg))
* \param id This instance's ID number.
*/
void
dns64_desetup(struct module_env* env, int id)
dns64_deinit(struct module_env* env, int id)
{
struct dns64_env* dns64_env;
if (!env)
@ -1044,8 +1044,8 @@ dns64_get_mem(struct module_env* env, int id)
*/
static struct module_func_block dns64_block = {
"dns64",
&module_dummy_init, &module_dummy_init, &dns64_setup, &dns64_desetup,
&dns64_operate, &dns64_inform_super, &dns64_clear, &dns64_get_mem
&dns64_init, &dns64_deinit, NULL, NULL, &dns64_operate,
&dns64_inform_super, &dns64_clear, &dns64_get_mem
};
/**

View File

@ -50,10 +50,10 @@
struct module_func_block *dns64_get_funcblock(void);
/** dns64 init */
int dns64_setup(struct module_env* env, int id);
int dns64_init(struct module_env* env, int id);
/** dns64 deinit */
void dns64_desetup(struct module_env* env, int id);
void dns64_deinit(struct module_env* env, int id);
/** dns64 operate on a query */
void dns64_operate(struct module_qstate* qstate, enum module_ev event, int id,

View File

@ -297,8 +297,8 @@ inplace_cb_delete_wrapped(struct module_env* env, enum inplace_cb_list_type type
*/
static struct module_func_block dynlibmod_block = {
"dynlib",
&dynlibmod_init, &dynlibmod_deinit, &dynlibmod_operate, &dynlibmod_inform_super,
&dynlibmod_clear, &dynlibmod_get_mem
&dynlibmod_init, &dynlibmod_deinit, NULL, NULL, &dynlibmod_operate,
&dynlibmod_inform_super, &dynlibmod_clear, &dynlibmod_get_mem
};
struct module_func_block* dynlibmod_get_funcblock(void)

View File

@ -206,7 +206,7 @@ subnet_markdel(void* key)
}
int
subnetmod_setup(struct module_env *env, int id)
subnetmod_init(struct module_env *env, int id)
{
struct subnet_env *sn_env = (struct subnet_env*)calloc(1,
sizeof(struct subnet_env));
@ -275,7 +275,7 @@ subnetmod_setup(struct module_env *env, int id)
}
void
subnetmod_desetup(struct module_env *env, int id)
subnetmod_deinit(struct module_env *env, int id)
{
struct subnet_env *sn_env;
if(!env || !env->modinfo[id])
@ -996,9 +996,8 @@ subnetmod_get_mem(struct module_env *env, int id)
*/
static struct module_func_block subnetmod_block = {
"subnetcache",
&module_dummy_init, &module_dummy_init, &subnetmod_setup,
&subnetmod_desetup, &subnetmod_operate, &subnetmod_inform_super,
&subnetmod_clear, &subnetmod_get_mem
&subnetmod_init, &subnetmod_deinit, NULL, NULL, &subnetmod_operate,
&subnetmod_inform_super, &subnetmod_clear, &subnetmod_get_mem
};
struct module_func_block*

View File

@ -114,10 +114,10 @@ size_t msg_cache_sizefunc(void* k, void* d);
struct module_func_block* subnetmod_get_funcblock(void);
/** subnet module init */
int subnetmod_setup(struct module_env* env, int id);
int subnetmod_init(struct module_env* env, int id);
/** subnet module deinit */
void subnetmod_desetup(struct module_env* env, int id);
void subnetmod_deinit(struct module_env* env, int id);
/** subnet module operate on a query */
void subnetmod_operate(struct module_qstate* qstate, enum module_ev event,

View File

@ -67,7 +67,7 @@ ipsecmod_apply_cfg(struct ipsecmod_env* ipsecmod_env, struct config_file* cfg)
}
int
ipsecmod_setup(struct module_env* env, int id)
ipsecmod_init(struct module_env* env, int id)
{
struct ipsecmod_env* ipsecmod_env = (struct ipsecmod_env*)calloc(1,
sizeof(struct ipsecmod_env));
@ -85,7 +85,7 @@ ipsecmod_setup(struct module_env* env, int id)
}
void
ipsecmod_desetup(struct module_env* env, int id)
ipsecmod_deinit(struct module_env* env, int id)
{
struct ipsecmod_env* ipsecmod_env;
if(!env || !env->modinfo[id])
@ -615,9 +615,8 @@ ipsecmod_get_mem(struct module_env* env, int id)
*/
static struct module_func_block ipsecmod_block = {
"ipsecmod",
&module_dummy_init, &module_dummy_init, &ipsecmod_setup,
&ipsecmod_desetup, &ipsecmod_operate, &ipsecmod_inform_super,
&ipsecmod_clear, &ipsecmod_get_mem
&ipsecmod_init, &ipsecmod_deinit, NULL, NULL, &ipsecmod_operate,
&ipsecmod_inform_super, &ipsecmod_clear, &ipsecmod_get_mem
};
struct module_func_block*

View File

@ -74,9 +74,9 @@ struct ipsecmod_qstate {
};
/** Init the ipsecmod module */
int ipsecmod_setup(struct module_env* env, int id);
int ipsecmod_init(struct module_env* env, int id);
/** Deinit the ipsecmod module */
void ipsecmod_desetup(struct module_env* env, int id);
void ipsecmod_deinit(struct module_env* env, int id);
/** Operate on an event on a query (in qstate). */
void ipsecmod_operate(struct module_qstate* qstate, enum module_ev event,
int id, struct outbound_entry* outbound);

View File

@ -320,10 +320,10 @@ static int ipset_update(struct module_env *env, struct dns_msg *return_msg,
return 0;
}
int ipset_init(struct module_env* env, int id) {
int ipset_startup(struct module_env* env, int id) {
struct ipset_env *ipset_env;
ipset_env = (struct ipset_env *)malloc(sizeof(struct ipset_env));
ipset_env = (struct ipset_env *)calloc(1, sizeof(struct ipset_env));
if (!ipset_env) {
log_err("malloc failure");
return 0;
@ -343,17 +343,16 @@ int ipset_init(struct module_env* env, int id) {
return 1;
}
int ipset_deinit(struct module_env* env, int id) {
void ipset_destartup(struct module_env* env, int id) {
struct ipset_env *ipset_env = env->modinfo[id];
#ifdef HAVE_NET_PFVAR_H
close((filter_dev)ipset_env->dev);
#endif
free(ipset_env);
env->modinfo[id] = NULL;
return 1;
}
int ipset_setup(struct module_env* env, int id) {
int ipset_init(struct module_env* env, int id) {
struct ipset_env *ipset_env = env->modinfo[id];
ipset_env->name_v4 = env->cfg->ipset_name_v4;
@ -370,7 +369,7 @@ int ipset_setup(struct module_env* env, int id) {
return 1;
}
void ipset_desetup(struct module_env *env, int id) {
void ipset_deinit(struct module_env *env, int id) {
filter_dev dev;
struct ipset_env *ipset_env;
@ -497,7 +496,7 @@ size_t ipset_get_mem(struct module_env *env, int id) {
*/
static struct module_func_block ipset_block = {
"ipset",
&ipset_init, &ipset_deinit, &ipset_setup, &ipset_desetup,
&ipset_init, &ipset_deinit, &ipset_startup, &ipset_destartup,
&ipset_operate, &ipset_inform_super, &ipset_clear, &ipset_get_mem
};

View File

@ -50,14 +50,14 @@ struct ipset_qstate {
int dummy;
};
/** Startup the ipset module */
int ipset_startup(struct module_env* env, int id);
/** Destartup the ipset module */
void ipset_destartup(struct module_env* env, int id);
/** Init the ipset module */
int ipset_init(struct module_env* env, int id);
/** Deinit the ipset module */
int ipset_deinit(struct module_env* env, int id);
/** Setup the ipset module */
int ipset_setup(struct module_env* env, int id);
/** Desetup the ipset module */
void ipset_desetup(struct module_env* env, int id);
void ipset_deinit(struct module_env* env, int id);
/** Operate on an event on a query (in qstate). */
void ipset_operate(struct module_qstate* qstate, enum module_ev event,
int id, struct outbound_entry* outbound);

View File

@ -80,7 +80,7 @@ int BLACKLIST_PENALTY = (120000*4);
static void target_count_increase_nx(struct iter_qstate* iq, int num);
int
iter_setup(struct module_env* env, int id)
iter_init(struct module_env* env, int id)
{
struct iter_env* iter_env = (struct iter_env*)calloc(1,
sizeof(struct iter_env));
@ -114,7 +114,7 @@ caps_free(struct rbnode_type* n, void* ATTR_UNUSED(d))
}
void
iter_desetup(struct module_env* env, int id)
iter_deinit(struct module_env* env, int id)
{
struct iter_env* iter_env;
if(!env || !env->modinfo[id])
@ -4489,8 +4489,8 @@ iter_get_mem(struct module_env* env, int id)
*/
static struct module_func_block iter_block = {
"iterator",
&module_dummy_init, &module_dummy_init, &iter_setup, &iter_desetup,
&iter_operate, &iter_inform_super, &iter_clear, &iter_get_mem
&iter_init, &iter_deinit, NULL, NULL, &iter_operate,
&iter_inform_super, &iter_clear, &iter_get_mem
};
struct module_func_block*

View File

@ -499,10 +499,10 @@ const char* iter_state_to_string(enum iter_state state);
int iter_state_is_responsestate(enum iter_state s);
/** iterator init */
int iter_setup(struct module_env* env, int id);
int iter_init(struct module_env* env, int id);
/** iterator deinit */
void iter_desetup(struct module_env* env, int id);
void iter_deinit(struct module_env* env, int id);
/** iterator operate on a query */
void iter_operate(struct module_qstate* qstate, enum module_ev event, int id,

View File

@ -56,6 +56,9 @@
#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)
{
@ -75,9 +78,12 @@ context_finalize(struct ub_ctx* ctx)
ctx->pipe_pid = getpid();
cfg_apply_local_port_policy(cfg, 65536);
config_apply(cfg);
if(!modstack_init(&ctx->mods, cfg->module_conf, ctx->env))
if(!modstack_started) {
modstack_started = 1;
if(!modstack_startup(&ctx->mods, cfg->module_conf, ctx->env))
return UB_INITFAIL;
if(!modstack_setup(&ctx->mods, cfg->module_conf, ctx->env))
}
if(!modstack_call_init(&ctx->mods, cfg->module_conf, ctx->env))
return UB_INITFAIL;
listen_setup_locks();
log_edns_known_options(VERB_ALGO, ctx->env);

View File

@ -337,4 +337,7 @@ 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

@ -188,7 +188,8 @@ ub_ctx_create(void)
int e = errno;
ub_randfree(ctx->seed_rnd);
config_delete(ctx->env->cfg);
modstack_desetup(&ctx->mods, ctx->env);
modstack_deinit(&ctx->mods, ctx->env);
modstack_destartup(&ctx->mods, ctx->env);
listen_desetup_locks();
edns_known_options_delete(ctx->env);
edns_strings_delete(ctx->env->edns_strings);
@ -202,7 +203,8 @@ ub_ctx_create(void)
tube_delete(ctx->qq_pipe);
ub_randfree(ctx->seed_rnd);
config_delete(ctx->env->cfg);
modstack_desetup(&ctx->mods, ctx->env);
modstack_deinit(&ctx->mods, ctx->env);
modstack_destartup(&ctx->mods, ctx->env);
listen_desetup_locks();
edns_known_options_delete(ctx->env);
edns_strings_delete(ctx->env->edns_strings);
@ -360,8 +362,8 @@ ub_ctx_delete(struct ub_ctx* ctx)
}
libworker_delete_event(ctx->event_worker);
modstack_desetup(&ctx->mods, ctx->env);
modstack_deinit(&ctx->mods, ctx->env);
modstack_destartup(&ctx->mods, ctx->env);
a = ctx->alloc_list;
while(a) {
na = a->super;

View File

@ -777,8 +777,8 @@ size_t pythonmod_get_mem(struct module_env* env, int id)
*/
static struct module_func_block pythonmod_block = {
"python",
&module_dummy_init, &module_dummy_init, &pythonmod_init, &pythonmod_deinit, &pythonmod_operate, &pythonmod_inform_super,
&pythonmod_clear, &pythonmod_get_mem
&pythonmod_init, &pythonmod_deinit, NULL, NULL, &pythonmod_operate,
&pythonmod_inform_super, &pythonmod_clear, &pythonmod_get_mem
};
struct module_func_block* pythonmod_get_funcblock(void)

View File

@ -548,7 +548,7 @@ respip_copy_rrset(const struct ub_packed_rrset_key* key, struct regional* region
}
int
respip_setup(struct module_env* env, int id)
respip_init(struct module_env* env, int id)
{
(void)env;
(void)id;
@ -556,7 +556,7 @@ respip_setup(struct module_env* env, int id)
}
void
respip_desetup(struct module_env* env, int id)
respip_deinit(struct module_env* env, int id)
{
(void)env;
(void)id;
@ -1259,7 +1259,7 @@ respip_get_mem(struct module_env* env, int id)
*/
static struct module_func_block respip_block = {
"respip",
&module_dummy_init, &module_dummy_init, &respip_setup, &respip_desetup, &respip_operate,
&respip_init, &respip_deinit, NULL, NULL, &respip_operate,
&respip_inform_super, &respip_clear, &respip_get_mem
};

View File

@ -195,10 +195,10 @@ int respip_rewrite_reply(const struct query_info* qinfo,
struct module_func_block* respip_get_funcblock(void);
/** response-ip init */
int respip_setup(struct module_env* env, int id);
int respip_init(struct module_env* env, int id);
/** response-ip deinit */
void respip_desetup(struct module_env* env, int id);
void respip_deinit(struct module_env* env, int id);
/** response-ip operate on a query */
void respip_operate(struct module_qstate* qstate, enum module_ev event, int id,

View File

@ -216,7 +216,7 @@ module_func_block* module_factory(const char** str)
}
int
modstack_init(struct module_stack* stack, const char* module_conf,
modstack_startup(struct module_stack* stack, const char* module_conf,
struct module_env* env)
{
int i;
@ -227,11 +227,13 @@ modstack_init(struct module_stack* stack, const char* module_conf,
return 0;
}
for(i=0; i<stack->num; i++) {
verbose(VERB_OPS, "init module %d: %s",
if(stack->mod[i]->startup == NULL)
continue;
verbose(VERB_OPS, "startup module %d: %s",
i, stack->mod[i]->name);
fptr_ok(fptr_whitelist_mod_init(stack->mod[i]->init));
if(!(*stack->mod[i]->init)(env, i)) {
log_err("module init for module %s failed",
fptr_ok(fptr_whitelist_mod_startup(stack->mod[i]->startup));
if(!(*stack->mod[i]->startup)(env, i)) {
log_err("module startup for module %s failed",
stack->mod[i]->name);
return 0;
}
@ -240,7 +242,7 @@ modstack_init(struct module_stack* stack, const char* module_conf,
}
int
modstack_setup(struct module_stack* stack, const char* module_conf,
modstack_call_init(struct module_stack* stack, const char* module_conf,
struct module_env* env)
{
int i;
@ -254,11 +256,11 @@ modstack_setup(struct module_stack* stack, const char* module_conf,
return 0;
}
module_conf += strlen(stack->mod[i]->name);
verbose(VERB_OPS, "setup module %d: %s",
verbose(VERB_OPS, "init module %d: %s",
i, stack->mod[i]->name);
fptr_ok(fptr_whitelist_mod_setup(stack->mod[i]->setup));
if(!(*stack->mod[i]->setup)(env, i)) {
log_err("module setup for module %s failed",
fptr_ok(fptr_whitelist_mod_init(stack->mod[i]->init));
if(!(*stack->mod[i]->init)(env, i)) {
log_err("module init for module %s failed",
stack->mod[i]->name);
return 0;
}
@ -266,16 +268,6 @@ modstack_setup(struct module_stack* stack, const char* module_conf,
return 1;
}
void
modstack_desetup(struct module_stack* stack, struct module_env* env)
{
int i;
for(i=0; i<stack->num; i++) {
fptr_ok(fptr_whitelist_mod_desetup(stack->mod[i]->desetup));
(*stack->mod[i]->desetup)(env, i);
}
}
void
modstack_deinit(struct module_stack* stack, struct module_env* env)
{
@ -284,6 +276,18 @@ modstack_deinit(struct module_stack* stack, struct module_env* env)
fptr_ok(fptr_whitelist_mod_deinit(stack->mod[i]->deinit));
(*stack->mod[i]->deinit)(env, i);
}
}
void
modstack_destartup(struct module_stack* stack, struct module_env* env)
{
int i;
for(i=0; i<stack->num; i++) {
if(stack->mod[i]->destartup == NULL)
continue;
fptr_ok(fptr_whitelist_mod_destartup(stack->mod[i]->destartup));
(*stack->mod[i]->destartup)(env, i);
}
stack->num = 0;
free(stack->mod);
stack->mod = NULL;

View File

@ -60,10 +60,9 @@ struct module_stack {
* @param module_conf: string what modules to initialize
* @param env: module environment which is inited by the modules.
* environment should have a superalloc, cfg,
* env.need_to_validate is set by the modules.
* @return on false a module init failed.
*/
int modstack_init(struct module_stack* stack, const char* module_conf,
int modstack_startup(struct module_stack* stack, const char* module_conf,
struct module_env* env);
/**
@ -89,7 +88,7 @@ struct module_func_block* module_factory(const char** str);
const char** module_list_avail(void);
/**
* Setup modules. Calls module_setup().
* Init modules. Calls module_init().
* @param stack: It is modstack_setupped().
* @param module_conf: module ordering to check against the ordering in stack.
* fails on changed ordering.
@ -98,23 +97,23 @@ const char** module_list_avail(void);
* env.need_to_validate is set by the modules.
* @return on false a module init failed.
*/
int modstack_setup(struct module_stack* stack, const char* module_conf,
int modstack_call_init(struct module_stack* stack, const char* module_conf,
struct module_env* env);
/**
* Desetup the modules
* @param stack: made empty.
* @param env: module env for module deinit() calls.
*/
void modstack_desetup(struct module_stack* stack, struct module_env* env);
/**
* Deinit the modules, deinit, delete.
* Deinint the modules
* @param stack: made empty.
* @param env: module env for module deinit() calls.
*/
void modstack_deinit(struct module_stack* stack, struct module_env* env);
/**
* Destartup the modules, close, delete.
* @param stack: made empty.
* @param env: module env for module destartup() calls.
*/
void modstack_destartup(struct module_stack* stack, struct module_env* env);
/**
* Find index of module by name.
* @param stack: to look in

View File

@ -140,12 +140,13 @@ check_mod(struct config_file* cfg, struct module_func_block* fb)
fatal_exit("out of memory");
if(!edns_known_options_init(&env))
fatal_exit("out of memory");
if(!(*fb->setup)(&env, 0))
fatal_exit("bad config for %s module", fb->name);
if(!(*fb->setup)(&env, 0))
fatal_exit("bad config for %s module", fb->name);
(*fb->desetup)(&env, 0);
if(fb->startup && !(*fb->startup)(&env, 0))
fatal_exit("bad config during startup for %s module", fb->name);
if(!(*fb->init)(&env, 0))
fatal_exit("bad config during init for %s module", fb->name);
(*fb->deinit)(&env, 0);
if(fb->destartup)
(*fb->destartup)(&env, 0);
sldns_buffer_free(env.scratch_buffer);
regional_destroy(env.scratch);
edns_known_options_delete(&env);

View File

@ -287,9 +287,11 @@ static void zonemd_verify_test(char* zname, char* zfile, char* tastr,
env.auth_zones = auth_zones_create();
if(!env.auth_zones)
fatal_exit("out of memory");
modstack_init(&mods);
if(!modstack_setup(&mods, env.cfg->module_conf, &env))
fatal_exit("could not modstack_setup");
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))
fatal_exit("could not modstack_call_init");
env.mesh = mesh_create(&mods, &env);
if(!env.mesh)
fatal_exit("out of memory");
@ -327,7 +329,8 @@ static void zonemd_verify_test(char* zname, char* zfile, char* tastr,
/* desetup test harness */
mesh_delete(env.mesh);
modstack_desetup(&mods, &env);
modstack_deinit(&mods, &env);
modstack_destartup(&mods, &env);
auth_zones_delete(env.auth_zones);
anchors_delete(env.anchors);
config_delete(env.cfg);

View File

@ -395,30 +395,10 @@ fptr_whitelist_modenv_detect_cycle(int (*fptr)(
int
fptr_whitelist_mod_init(int (*fptr)(struct module_env* env, int id))
{
if(fptr == &module_dummy_init) return 1;
#ifdef USE_IPSET
else if(fptr == &ipset_init) return 1;
#endif
return 0;
}
int
fptr_whitelist_mod_deinit(int (*fptr)(struct module_env* env, int id))
{
if(fptr == &module_dummy_init) return 1;
#ifdef USE_IPSET
else if(fptr == &ipset_deinit) return 1;
#endif
return 0;
}
int
fptr_whitelist_mod_setup(int (*fptr)(struct module_env* env, int id))
{
if(fptr == &iter_setup) return 1;
else if(fptr == &val_setup) return 1;
else if(fptr == &dns64_setup) return 1;
else if(fptr == &respip_setup) return 1;
if(fptr == &iter_init) return 1;
else if(fptr == &val_init) return 1;
else if(fptr == &dns64_init) return 1;
else if(fptr == &respip_init) return 1;
#ifdef WITH_PYTHONMODULE
else if(fptr == &pythonmod_init) return 1;
#endif
@ -426,27 +406,28 @@ fptr_whitelist_mod_setup(int (*fptr)(struct module_env* env, int id))
else if(fptr == &dynlibmod_init) return 1;
#endif
#ifdef USE_CACHEDB
else if(fptr == &cachedb_setup) return 1;
else if(fptr == &cachedb_init) return 1;
#endif
#ifdef USE_IPSECMOD
else if(fptr == &ipsecmod_setup) return 1;
else if(fptr == &ipsecmod_init) return 1;
#endif
#ifdef CLIENT_SUBNET
else if(fptr == &subnetmod_setup) return 1;
else if(fptr == &subnetmod_init) return 1;
#endif
#ifdef USE_IPSET
else if(fptr == &ipset_setup) return 1;
else if(fptr == &ipset_init) return 1;
#endif
return 0;
}
int
fptr_whitelist_mod_desetup(void (*fptr)(struct module_env* env, int id))
fptr_whitelist_mod_deinit(void (*fptr)(struct module_env* env, int id))
{
if(fptr == &iter_desetup) return 1;
else if(fptr == &val_desetup) return 1;
else if(fptr == &dns64_desetup) return 1;
else if(fptr == &respip_desetup) return 1;
if(fptr == &iter_deinit) return 1;
else if(fptr == &val_deinit) return 1;
else if(fptr == &dns64_deinit) return 1;
else if(fptr == &respip_deinit) return 1;
#ifdef WITH_PYTHONMODULE
else if(fptr == &pythonmod_deinit) return 1;
#endif
@ -454,16 +435,34 @@ fptr_whitelist_mod_desetup(void (*fptr)(struct module_env* env, int id))
else if(fptr == &dynlibmod_deinit) return 1;
#endif
#ifdef USE_CACHEDB
else if(fptr == &cachedb_desetup) return 1;
else if(fptr == &cachedb_deinit) return 1;
#endif
#ifdef USE_IPSECMOD
else if(fptr == &ipsecmod_desetup) return 1;
else if(fptr == &ipsecmod_deinit) return 1;
#endif
#ifdef CLIENT_SUBNET
else if(fptr == &subnetmod_desetup) return 1;
else if(fptr == &subnetmod_deinit) return 1;
#endif
#ifdef USE_IPSET
else if(fptr == &ipset_desetup) return 1;
else if(fptr == &ipset_deinit) return 1;
#endif
return 0;
}
int
fptr_whitelist_mod_startup(int (*fptr)(struct module_env* env, int id))
{
#ifdef USE_IPSET
if(fptr == &ipset_startup) return 1;
#endif
return 0;
}
int
fptr_whitelist_mod_destartup(void (*fptr)(struct module_env* env, int id))
{
#ifdef USE_IPSET
if(fptr == &ipset_destartup) return 1;
#endif
return 0;
}

View File

@ -276,23 +276,23 @@ int fptr_whitelist_mod_init(int (*fptr)(struct module_env* env, int id));
* @param fptr: function pointer to check.
* @return false if not in whitelist.
*/
int fptr_whitelist_mod_deinit(int (*fptr)(struct module_env* env, int id));
int fptr_whitelist_mod_deinit(void (*fptr)(struct module_env* env, int id));
/**
* Check function pointer whitelist for module setup call values.
* Check function pointer whitelist for module startup call values.
*
* @param fptr: function pointer to check.
* @return false if not in whitelist.
*/
int fptr_whitelist_mod_setup(int (*fptr)(struct module_env* env, int id));
int fptr_whitelist_mod_startup(int (*fptr)(struct module_env* env, int id));
/**
* Check function pointer whitelist for module desetup call values.
* Check function pointer whitelist for module destartup call values.
*
* @param fptr: function pointer to check.
* @return false if not in whitelist.
*/
int fptr_whitelist_mod_desetup(void (*fptr)(struct module_env* env, int id));
int fptr_whitelist_mod_destartup(void (*fptr)(struct module_env* env, int id));
/**
* Check function pointer whitelist for module operate call values.

View File

@ -415,8 +415,3 @@ copy_state_to_super(struct module_qstate* qstate, int ATTR_UNUSED(id),
super->was_ratelimited = qstate->was_ratelimited;
}
}
int module_dummy_init(struct module_env* env, int id)
{
return 1;
}

View File

@ -713,39 +713,42 @@ struct module_func_block {
const char* name;
/**
* initialise the module. This is called only once at startup.
* Privileged operations like opening device files may be done here.
* @param id: module id number.
* return: 0 on error
*/
int (*init)(struct module_env* env, int id);
/**
* deinitialise the module. This is called only once before shutdown to
* free resources allocated during init().
* Closing privileged ports or files must be done here.
* @param id: module id number.
* return: 0 on error
*/
int (*deinit)(struct module_env* env, int id);
/**
* setup the module. Called when restarting or reloading the
* Initialise the module. Called when restarting or reloading the
* daemon.
* This is the place to apply settings from the config file.
* @param env: module environment.
* @param id: module id number.
* return: 0 on error
*/
int (*setup)(struct module_env* env, int id);
int (*init)(struct module_env* env, int id);
/**
* de-setup, undo stuff done during setup().
* Deinitialise the module, undo stuff done during init().
* Called before reloading the daemon.
* @param env: module environment.
* @param id: module id number.
*/
void (*desetup)(struct module_env* env, int id);
void (*deinit)(struct module_env* env, int id);
/**
* Set up the module for start. This is called only once at startup.
* Privileged operations like opening device files may be done here.
* The function ptr can be NULL, if it is not used.
* @param env: module environment.
* @param id: module id number.
* return: 0 on error
*/
int (*startup)(struct module_env* env, int id);
/**
* Close down the module for stop. This is called only once before
* shutdown to free resources allocated during startup().
* Closing privileged ports or files must be done here.
* The function ptr can be NULL, if it is not used.
* @param env: module environment.
* @param id: module id number.
*/
void (*destartup)(struct module_env* env, int id);
/**
* accept a new query, or work further on existing query.
@ -983,6 +986,4 @@ void log_edns_known_options(enum verbosity_value level,
void copy_state_to_super(struct module_qstate* qstate, int id,
struct module_qstate* super);
int module_dummy_init(struct module_env* env, int id);
#endif /* UTIL_MODULE_H */

View File

@ -185,7 +185,7 @@ val_apply_cfg(struct module_env* env, struct val_env* val_env,
void ecdsa_evp_workaround_init(void);
#endif
int
val_setup(struct module_env* env, int id)
val_init(struct module_env* env, int id)
{
struct val_env* val_env = (struct val_env*)calloc(1,
sizeof(struct val_env));
@ -221,7 +221,7 @@ val_setup(struct module_env* env, int id)
}
void
val_desetup(struct module_env* env, int id)
val_deinit(struct module_env* env, int id)
{
struct val_env* val_env;
if(!env || !env->modinfo[id])
@ -3344,8 +3344,8 @@ val_get_mem(struct module_env* env, int id)
*/
static struct module_func_block val_block = {
"validator",
&module_dummy_init, &module_dummy_init, &val_setup, &val_desetup,
&val_operate, &val_inform_super, &val_clear, &val_get_mem
&val_init, &val_deinit, NULL, NULL, &val_operate, &val_inform_super,
&val_clear, &val_get_mem
};
struct module_func_block*

View File

@ -246,10 +246,10 @@ struct module_func_block* val_get_funcblock(void);
const char* val_state_to_string(enum val_state state);
/** validator init */
int val_setup(struct module_env* env, int id);
int val_init(struct module_env* env, int id);
/** validator deinit */
void val_desetup(struct module_env* env, int id);
void val_deinit(struct module_env* env, int id);
/** validator operate on a query */
void val_operate(struct module_qstate* qstate, enum module_ev event, int id,