From 14190986f87301b18bcc473c842bd82d778d87a2 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Sat, 18 Jun 2011 21:18:29 +0200 Subject: iptables: consolidate target/match init call This is useful for the upcoming patch about per-instance auxiliary data. Signed-off-by: Jan Engelhardt --- iptables/xshared.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'iptables/xshared.c') diff --git a/iptables/xshared.c b/iptables/xshared.c index 0e3857bb..55ce5504 100644 --- a/iptables/xshared.c +++ b/iptables/xshared.c @@ -145,8 +145,7 @@ int command_default(struct iptables_command_state *cs, m->m->u.match_size = size; strcpy(m->m->u.user.name, m->name); m->m->u.user.revision = m->revision; - if (m->init != NULL) - m->init(m->m); + xs_init_match(m); if (m->x6_options != NULL) gl->opts = xtables_options_xfrm(gl->orig_opts, @@ -207,3 +206,15 @@ int subcmd_main(int argc, char **argv, const struct subcommand *cb) fprintf(stderr, " * %s\n", cb->name); exit(EXIT_FAILURE); } + +void xs_init_target(struct xtables_target *target) +{ + if (target->init != NULL) + target->init(target->t); +} + +void xs_init_match(struct xtables_match *match) +{ + if (match->init != NULL) + match->init(match->m); +} -- cgit v1.2.3 From 2dba676b68ef842025f3afecba26cb0b2ae4c09b Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Sat, 18 Jun 2011 21:34:25 +0200 Subject: extensions: support for per-extension instance "global" variable space Signed-off-by: Jan Engelhardt --- iptables/xshared.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'iptables/xshared.c') diff --git a/iptables/xshared.c b/iptables/xshared.c index 55ce5504..79da507d 100644 --- a/iptables/xshared.c +++ b/iptables/xshared.c @@ -209,12 +209,30 @@ int subcmd_main(int argc, char **argv, const struct subcommand *cb) void xs_init_target(struct xtables_target *target) { + if (target->udata_size != 0) { + free(target->udata); + target->udata = calloc(1, target->udata_size); + if (target->udata == NULL) + xtables_error(RESOURCE_PROBLEM, "malloc"); + } if (target->init != NULL) target->init(target->t); } void xs_init_match(struct xtables_match *match) { + if (match->udata_size != 0) { + /* + * As soon as a subsequent instance of the same match + * is used, e.g. "-m time -m time", the first instance + * is no longer reachable anyway, so we can free udata. + * Same goes for target. + */ + free(match->udata); + match->udata = calloc(1, match->udata_size); + if (match->udata == NULL) + xtables_error(RESOURCE_PROBLEM, "malloc"); + } if (match->init != NULL) match->init(match->m); } -- cgit v1.2.3