summaryrefslogtreecommitdiffstats
path: root/iptables/xshared.c
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2011-06-30 13:35:56 +0200
committerPatrick McHardy <kaber@trash.net>2011-06-30 13:35:56 +0200
commit411b390f3ffcd4708a0dfc0f2824a637de511cea (patch)
tree50645beb44d0a617d17eb15636f149720061e31f /iptables/xshared.c
parent3b7a22b44d74b9b05d5e4b0529ebf72c49dcbff5 (diff)
parent1c9508e1f3f853f33683eb7118e19b193a6c80b7 (diff)
Merge branch 'master' of git://dev.medozas.de/iptables
Diffstat (limited to 'iptables/xshared.c')
-rw-r--r--iptables/xshared.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/iptables/xshared.c b/iptables/xshared.c
index 0e3857bb..79da507d 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,33 @@ 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->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);
+}