Replace fw3_free_zone() with the generic implementation
[project/firewall3.git] / iptables.c
index 56f68c3..2684933 100644 (file)
@@ -54,32 +54,17 @@ get_kernel_version(void)
        kernel_version = LINUX_VERSION(x, y, z);
 }
 
        kernel_version = LINUX_VERSION(x, y, z);
 }
 
+#undef __ipt_module
+#define __ipt_module(x) libxt_##x##_init, libipt_##x##_init, libip6t_##x##_init,
+
 static void fw3_init_extensions(void)
 {
 static void fw3_init_extensions(void)
 {
-       libip6t_icmp6_init();
-       libip6t_LOG_init();
-       libip6t_REJECT_init();
-       libipt_DNAT_init();
-       libipt_icmp_init();
-       libipt_LOG_init();
-       libipt_MASQUERADE_init();
-       libipt_REDIRECT_init();
-       libipt_REJECT_init();
-       libipt_SNAT_init();
-       libxt_comment_init();
-       libxt_conntrack_init();
-       libxt_CT_init();
-       libxt_limit_init();
-       libxt_mac_init();
-       libxt_mark_init();
-       libxt_MARK_init();
-       libxt_set_init();
-       libxt_SET_init();
-       libxt_standard_init();
-       libxt_TCPMSS_init();
-       libxt_tcp_init();
-       libxt_time_init();
-       libxt_udp_init();
+       int i;
+       void (*initfuncs[])(void) = { FW3_IPT_MODULES };
+
+       for (i = 0; i < sizeof(initfuncs)/sizeof(initfuncs[0]); i++)
+               if (initfuncs[i])
+                       initfuncs[i]();
 }
 
 struct fw3_ipt_handle *
 }
 
 struct fw3_ipt_handle *
@@ -1177,7 +1162,7 @@ fw3_ipt_rule_append(struct fw3_ipt_rule *r, const char *fmt, ...)
                        if (!em)
                        {
                                fprintf(stderr, "fw3_ipt_rule_append(): Can't find match '%s'\n", optarg);
                        if (!em)
                        {
                                fprintf(stderr, "fw3_ipt_rule_append(): Can't find match '%s'\n", optarg);
-                               return;
+                               goto free;
                        }
 
                        init_match(r, em, true);
                        }
 
                        init_match(r, em, true);
@@ -1189,7 +1174,7 @@ fw3_ipt_rule_append(struct fw3_ipt_rule *r, const char *fmt, ...)
                        if (!et)
                        {
                                fprintf(stderr, "fw3_ipt_rule_append(): Can't find target '%s'\n", optarg);
                        if (!et)
                        {
                                fprintf(stderr, "fw3_ipt_rule_append(): Can't find target '%s'\n", optarg);
-                               return;
+                               goto free;
                        }
 
                        break;
                        }
 
                        break;
@@ -1278,6 +1263,7 @@ fw3_ipt_rule_append(struct fw3_ipt_rule *r, const char *fmt, ...)
                free(e);
        }
 
                free(e);
        }
 
+free:
        for (i = 1; i < r->argc; i++)
                free(r->argv[i]);
 
        for (i = 1; i < r->argc; i++)
                free(r->argv[i]);
 
@@ -1285,7 +1271,9 @@ fw3_ipt_rule_append(struct fw3_ipt_rule *r, const char *fmt, ...)
 
        xtables_rule_matches_free(&r->matches);
 
 
        xtables_rule_matches_free(&r->matches);
 
-       free(r->target->t);
+       if (r->target)
+               free(r->target->t);
+
        free(r);
 
        /* reset all targets and matches */
        free(r);
 
        /* reset all targets and matches */