Skip to content

Commit a335e60

Browse files
committed
ipset-pf-support, move startup and destartup to the front of the module
func block functions, modstack call deinit function names, and detect module change when no startup functions are needed.
1 parent a19009d commit a335e60

File tree

18 files changed

+96
-61
lines changed

18 files changed

+96
-61
lines changed

cachedb/cachedb.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ cachedb_get_mem(struct module_env* env, int id)
983983
*/
984984
static struct module_func_block cachedb_block = {
985985
"cachedb",
986-
&cachedb_init, &cachedb_deinit, NULL, NULL, &cachedb_operate,
986+
NULL, NULL, &cachedb_init, &cachedb_deinit, &cachedb_operate,
987987
&cachedb_inform_super, &cachedb_clear, &cachedb_get_mem
988988
};
989989

daemon/daemon.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ daemon_privileged(struct daemon* daemon)
450450
daemon->env->cfg = daemon->cfg;
451451
daemon->env->alloc = &daemon->superalloc;
452452
daemon->env->worker = NULL;
453-
if(!modstack_startup(&daemon->mods, daemon->cfg->module_conf,
453+
if(!modstack_call_startup(&daemon->mods, daemon->cfg->module_conf,
454454
daemon->env)) {
455455
fatal_exit("failed to startup modules");
456456
}
@@ -466,11 +466,15 @@ static void daemon_setup_modules(struct daemon* daemon)
466466
daemon->env->cfg = daemon->cfg;
467467
daemon->env->alloc = &daemon->superalloc;
468468
daemon->env->worker = NULL;
469+
if(daemon->mods_inited) {
470+
modstack_call_deinit(&daemon->mods, daemon->env);
471+
}
469472
daemon->env->need_to_validate = 0; /* set by module init below */
470-
if(!modstack_setup(&daemon->mods, daemon->cfg->module_conf,
473+
if(!modstack_call_init(&daemon->mods, daemon->cfg->module_conf,
471474
daemon->env)) {
472-
fatal_exit("failed to setup modules");
475+
fatal_exit("failed to init modules");
473476
}
477+
daemon->mods_inited = 1;
474478
log_edns_known_options(VERB_ALGO, daemon->env);
475479
}
476480

@@ -904,8 +908,9 @@ daemon_delete(struct daemon* daemon)
904908
size_t i;
905909
if(!daemon)
906910
return;
907-
modstack_desetup(&daemon->mods, daemon->env);
908-
modstack_destartup(&daemon->mods, daemon->env);
911+
modstack_call_deinit(&daemon->mods, daemon->env);
912+
modstack_call_destartup(&daemon->mods, daemon->env);
913+
modstack_free(&daemon->mods);
909914
daemon_remote_delete(daemon->rc);
910915
for(i = 0; i < daemon->num_ports; i++)
911916
listening_ports_free(daemon->ports[i]);

daemon/daemon.h

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ struct daemon {
115115
struct module_env* env;
116116
/** stack of module callbacks */
117117
struct module_stack mods;
118+
/** The module stack has been inited */
119+
int mods_inited;
118120
/** access control, which client IPs are allowed to connect */
119121
struct acl_list* acl;
120122
/** access control, which interfaces are allowed to connect */

dns64/dns64.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ dns64_get_mem(struct module_env* env, int id)
10441044
*/
10451045
static struct module_func_block dns64_block = {
10461046
"dns64",
1047-
&dns64_init, &dns64_deinit, NULL, NULL, &dns64_operate,
1047+
NULL, NULL, &dns64_init, &dns64_deinit, &dns64_operate,
10481048
&dns64_inform_super, &dns64_clear, &dns64_get_mem
10491049
};
10501050

dynlibmod/dynlibmod.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ inplace_cb_delete_wrapped(struct module_env* env, enum inplace_cb_list_type type
297297
*/
298298
static struct module_func_block dynlibmod_block = {
299299
"dynlib",
300-
&dynlibmod_init, &dynlibmod_deinit, NULL, NULL, &dynlibmod_operate,
300+
NULL, NULL, &dynlibmod_init, &dynlibmod_deinit, &dynlibmod_operate,
301301
&dynlibmod_inform_super, &dynlibmod_clear, &dynlibmod_get_mem
302302
};
303303

edns-subnet/subnetmod.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ subnetmod_get_mem(struct module_env *env, int id)
996996
*/
997997
static struct module_func_block subnetmod_block = {
998998
"subnetcache",
999-
&subnetmod_init, &subnetmod_deinit, NULL, NULL, &subnetmod_operate,
999+
NULL, NULL, &subnetmod_init, &subnetmod_deinit, &subnetmod_operate,
10001000
&subnetmod_inform_super, &subnetmod_clear, &subnetmod_get_mem
10011001
};
10021002

ipsecmod/ipsecmod.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ ipsecmod_get_mem(struct module_env* env, int id)
615615
*/
616616
static struct module_func_block ipsecmod_block = {
617617
"ipsecmod",
618-
&ipsecmod_init, &ipsecmod_deinit, NULL, NULL, &ipsecmod_operate,
618+
NULL, NULL, &ipsecmod_init, &ipsecmod_deinit, &ipsecmod_operate,
619619
&ipsecmod_inform_super, &ipsecmod_clear, &ipsecmod_get_mem
620620
};
621621

ipset/ipset.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ size_t ipset_get_mem(struct module_env *env, int id) {
491491
*/
492492
static struct module_func_block ipset_block = {
493493
"ipset",
494-
&ipset_init, &ipset_deinit, &ipset_startup, &ipset_destartup,
494+
&ipset_startup, &ipset_destartup, &ipset_init, &ipset_deinit,
495495
&ipset_operate, &ipset_inform_super, &ipset_clear, &ipset_get_mem
496496
};
497497

iterator/iterator.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4489,7 +4489,7 @@ iter_get_mem(struct module_env* env, int id)
44894489
*/
44904490
static struct module_func_block iter_block = {
44914491
"iterator",
4492-
&iter_init, &iter_deinit, NULL, NULL, &iter_operate,
4492+
NULL, NULL, &iter_init, &iter_deinit, &iter_operate,
44934493
&iter_inform_super, &iter_clear, &iter_get_mem
44944494
};
44954495

libunbound/context.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ context_finalize(struct ub_ctx* ctx)
7575
ctx->pipe_pid = getpid();
7676
cfg_apply_local_port_policy(cfg, 65536);
7777
config_apply(cfg);
78-
if(!modstack_startup(&ctx->mods, cfg->module_conf, ctx->env))
78+
if(!modstack_call_startup(&ctx->mods, cfg->module_conf, ctx->env))
7979
return UB_INITFAIL;
80-
if(!modstack_setup(&ctx->mods, cfg->module_conf, ctx->env))
80+
if(!modstack_call_init(&ctx->mods, cfg->module_conf, ctx->env))
8181
return UB_INITFAIL;
8282
listen_setup_locks();
8383
log_edns_known_options(VERB_ALGO, ctx->env);

libunbound/libunbound.c

+9-6
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@ ub_ctx_create(void)
188188
int e = errno;
189189
ub_randfree(ctx->seed_rnd);
190190
config_delete(ctx->env->cfg);
191-
modstack_desetup(&ctx->mods, ctx->env);
192-
modstack_destartup(&ctx->mods, ctx->env);
191+
modstack_call_deinit(&ctx->mods, ctx->env);
192+
modstack_call_destartup(&ctx->mods, ctx->env);
193+
modstack_free(&ctx->mods);
193194
listen_desetup_locks();
194195
edns_known_options_delete(ctx->env);
195196
edns_strings_delete(ctx->env->edns_strings);
@@ -203,8 +204,9 @@ ub_ctx_create(void)
203204
tube_delete(ctx->qq_pipe);
204205
ub_randfree(ctx->seed_rnd);
205206
config_delete(ctx->env->cfg);
206-
modstack_desetup(&ctx->mods, ctx->env);
207-
modstack_destartup(&ctx->mods, ctx->env);
207+
modstack_call_deinit(&ctx->mods, ctx->env);
208+
modstack_call_destartup(&ctx->mods, ctx->env);
209+
modstack_free(&ctx->mods);
208210
listen_desetup_locks();
209211
edns_known_options_delete(ctx->env);
210212
edns_strings_delete(ctx->env->edns_strings);
@@ -362,8 +364,9 @@ ub_ctx_delete(struct ub_ctx* ctx)
362364
}
363365
libworker_delete_event(ctx->event_worker);
364366

365-
modstack_desetup(&ctx->mods, ctx->env);
366-
modstack_destartup(&ctx->mods, ctx->env);
367+
modstack_call_deinit(&ctx->mods, ctx->env);
368+
modstack_call_destartup(&ctx->mods, ctx->env);
369+
modstack_free(&ctx->mods);
367370
a = ctx->alloc_list;
368371
while(a) {
369372
na = a->super;

pythonmod/pythonmod.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ size_t pythonmod_get_mem(struct module_env* env, int id)
777777
*/
778778
static struct module_func_block pythonmod_block = {
779779
"python",
780-
&pythonmod_init, &pythonmod_deinit, NULL, NULL, &pythonmod_operate,
780+
NULL, NULL, &pythonmod_init, &pythonmod_deinit, &pythonmod_operate,
781781
&pythonmod_inform_super, &pythonmod_clear, &pythonmod_get_mem
782782
};
783783

respip/respip.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ respip_get_mem(struct module_env* env, int id)
12591259
*/
12601260
static struct module_func_block respip_block = {
12611261
"respip",
1262-
&respip_init, &respip_deinit, NULL, NULL, &respip_operate,
1262+
NULL, NULL, &respip_init, &respip_deinit, &respip_operate,
12631263
&respip_inform_super, &respip_clear, &respip_get_mem
12641264
};
12651265

services/modstack.c

+30-12
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ modstack_init(struct module_stack* stack)
9595
stack->mod = NULL;
9696
}
9797

98+
void
99+
modstack_free(struct module_stack* stack)
100+
{
101+
if(!stack)
102+
return;
103+
stack->num = 0;
104+
free(stack->mod);
105+
stack->mod = NULL;
106+
}
107+
98108
int
99109
modstack_config(struct module_stack* stack, const char* module_conf)
100110
{
@@ -223,7 +233,7 @@ module_func_block* module_factory(const char** str)
223233
}
224234

225235
int
226-
modstack_startup(struct module_stack* stack, const char* module_conf,
236+
modstack_call_startup(struct module_stack* stack, const char* module_conf,
227237
struct module_env* env)
228238
{
229239
int i;
@@ -249,22 +259,33 @@ modstack_startup(struct module_stack* stack, const char* module_conf,
249259
}
250260

251261
int
252-
modstack_setup(struct module_stack* stack, const char* module_conf,
262+
modstack_call_init(struct module_stack* stack, const char* module_conf,
253263
struct module_env* env)
254264
{
255-
int i;
256-
if(stack->num != 0)
257-
modstack_desetup(stack, env);
265+
int i, changed = 0;
258266
env->need_to_validate = 0; /* set by module init below */
259267
for(i=0; i<stack->num; i++) {
260268
while(*module_conf && isspace(*module_conf))
261269
module_conf++;
262270
if(strncmp(stack->mod[i]->name, module_conf,
263271
strlen(stack->mod[i]->name))) {
264-
log_err("changed module ordering during reload not supported");
265-
return 0;
272+
if(stack->mod[i]->startup || stack->mod[i]->destartup) {
273+
log_err("changed module ordering during reload not supported, for module that needs startup");
274+
return 0;
275+
} else {
276+
changed = 1;
277+
}
266278
}
267279
module_conf += strlen(stack->mod[i]->name);
280+
}
281+
if(changed) {
282+
modstack_free(stack);
283+
if(!modstack_config(stack, module_conf)) {
284+
return 0;
285+
}
286+
}
287+
288+
for(i=0; i<stack->num; i++) {
268289
verbose(VERB_OPS, "init module %d: %s",
269290
i, stack->mod[i]->name);
270291
fptr_ok(fptr_whitelist_mod_init(stack->mod[i]->init));
@@ -278,7 +299,7 @@ modstack_setup(struct module_stack* stack, const char* module_conf,
278299
}
279300

280301
void
281-
modstack_desetup(struct module_stack* stack, struct module_env* env)
302+
modstack_call_deinit(struct module_stack* stack, struct module_env* env)
282303
{
283304
int i;
284305
for(i=0; i<stack->num; i++) {
@@ -288,7 +309,7 @@ modstack_desetup(struct module_stack* stack, struct module_env* env)
288309
}
289310

290311
void
291-
modstack_destartup(struct module_stack* stack, struct module_env* env)
312+
modstack_call_destartup(struct module_stack* stack, struct module_env* env)
292313
{
293314
int i;
294315
for(i=0; i<stack->num; i++) {
@@ -297,9 +318,6 @@ modstack_destartup(struct module_stack* stack, struct module_env* env)
297318
fptr_ok(fptr_whitelist_mod_destartup(stack->mod[i]->destartup));
298319
(*stack->mod[i]->destartup)(env, i);
299320
}
300-
stack->num = 0;
301-
free(stack->mod);
302-
stack->mod = NULL;
303321
}
304322

305323
int

services/modstack.h

+12-6
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,20 @@ struct module_stack {
6161
void modstack_init(struct module_stack* stack);
6262

6363
/**
64-
* Initialises modules and assignes ids.
64+
* Free the stack of modules
65+
* @param stack: stack that frees up memory.
66+
*/
67+
void modstack_free(struct module_stack* stack);
68+
69+
/**
70+
* Initialises modules and assignes ids. Calls module_startup().
6571
* @param stack: Expected empty, filled according to module_conf
6672
* @param module_conf: string what modules to initialize
6773
* @param env: module environment which is inited by the modules.
6874
* environment should have a superalloc, cfg,
6975
* @return on false a module init failed.
7076
*/
71-
int modstack_startup(struct module_stack* stack, const char* module_conf,
77+
int modstack_call_startup(struct module_stack* stack, const char* module_conf,
7278
struct module_env* env);
7379

7480
/**
@@ -103,22 +109,22 @@ const char** module_list_avail(void);
103109
* env.need_to_validate is set by the modules.
104110
* @return on false a module init failed.
105111
*/
106-
int modstack_setup(struct module_stack* stack, const char* module_conf,
112+
int modstack_call_init(struct module_stack* stack, const char* module_conf,
107113
struct module_env* env);
108114

109115
/**
110-
* Desetup the modules, deinit.
116+
* Deinit the modules.
111117
* @param stack: made empty.
112118
* @param env: module env for module deinit() calls.
113119
*/
114-
void modstack_desetup(struct module_stack* stack, struct module_env* env);
120+
void modstack_call_deinit(struct module_stack* stack, struct module_env* env);
115121

116122
/**
117123
* Destartup the modules, close, delete.
118124
* @param stack: made empty.
119125
* @param env: module env for module destartup() calls.
120126
*/
121-
void modstack_destartup(struct module_stack* stack, struct module_env* env);
127+
void modstack_call_destartup(struct module_stack* stack, struct module_env* env);
122128

123129
/**
124130
* Find index of module by name.

testcode/unitzonemd.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ static void zonemd_verify_test(char* zname, char* zfile, char* tastr,
288288
if(!env.auth_zones)
289289
fatal_exit("out of memory");
290290
memset(&mods, 0, sizeof(mods));
291-
if(!modstack_startup(&mods, env.cfg->module_conf, &env))
291+
if(!modstack_call_startup(&mods, env.cfg->module_conf, &env))
292292
fatal_exit("could not modstack_startup");
293-
if(!modstack_setup(&mods, env.cfg->module_conf, &env))
293+
if(!modstack_call_init(&mods, env.cfg->module_conf, &env))
294294
fatal_exit("could not modstack_call_init");
295295
env.mesh = mesh_create(&mods, &env);
296296
if(!env.mesh)
@@ -329,8 +329,9 @@ static void zonemd_verify_test(char* zname, char* zfile, char* tastr,
329329

330330
/* desetup test harness */
331331
mesh_delete(env.mesh);
332-
modstack_desetup(&mods, &env);
333-
modstack_destartup(&mods, &env);
332+
modstack_call_deinit(&mods, &env);
333+
modstack_call_destartup(&mods, &env);
334+
modstack_free(&mods);
334335
auth_zones_delete(env.auth_zones);
335336
anchors_delete(env.anchors);
336337
config_delete(env.cfg);

0 commit comments

Comments
 (0)