firewall3: check the return value of fw3_parse_options()
[project/firewall3.git] / defaults.c
index ccd320c..85a3750 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * firewall3 - 3rd OpenWrt UCI firewall implementation
  *
- *   Copyright (C) 2013 Jo-Philipp Wich <jow@openwrt.org>
+ *   Copyright (C) 2013 Jo-Philipp Wich <jo@mein.io>
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
        { FW3_FAMILY_##f, FW3_TABLE_##tbl, FW3_FLAG_##def, fmt }
 
 static const struct fw3_chain_spec default_chains[] = {
-       //C(ANY, FILTER, UNSPEC,        "delegate_input"),
-       //C(ANY, FILTER, UNSPEC,        "delegate_output"),
-       //C(ANY, FILTER, UNSPEC,        "delegate_forward"),
        C(ANY, FILTER, UNSPEC,        "reject"),
        C(ANY, FILTER, CUSTOM_CHAINS, "input_rule"),
        C(ANY, FILTER, CUSTOM_CHAINS, "output_rule"),
        C(ANY, FILTER, CUSTOM_CHAINS, "forwarding_rule"),
        C(ANY, FILTER, SYN_FLOOD,     "syn_flood"),
 
-       //C(V4,  NAT,    UNSPEC,        "delegate_prerouting"),
-       //C(V4,  NAT,    UNSPEC,        "delegate_postrouting"),
        C(V4,  NAT,    CUSTOM_CHAINS, "prerouting_rule"),
        C(V4,  NAT,    CUSTOM_CHAINS, "postrouting_rule"),
 
-       //C(ANY, MANGLE, UNSPEC,        "mssfix"),
-       //C(ANY, MANGLE, UNSPEC,        "fwmark"),
-
-       //C(ANY, RAW,    UNSPEC,        "delegate_notrack"),
-
        { }
 };
 
@@ -117,7 +107,8 @@ fw3_load_defaults(struct fw3_state *state, struct uci_package *p)
                        continue;
                }
 
-               fw3_parse_options(&state->defaults, fw3_flag_opts, s);
+               if(!fw3_parse_options(&state->defaults, fw3_flag_opts, s))
+                       warn_elem(e, "has invalid options");
 
                check_policy(e, &defs->policy_input, "input");
                check_policy(e, &defs->policy_output, "output");
@@ -164,7 +155,7 @@ fw3_print_default_chains(struct fw3_ipt_handle *handle, struct fw3_state *state,
                        continue;
 
                if (c->flag &&
-                   !hasbit(defs->flags[handle->family == FW3_FAMILY_V6], c->flag))
+                   !fw3_hasbit(defs->flags[handle->family == FW3_FAMILY_V6], c->flag))
                        continue;
 
                fw3_ipt_create_chain(handle, c->format);
@@ -173,13 +164,6 @@ fw3_print_default_chains(struct fw3_ipt_handle *handle, struct fw3_state *state,
        set(defs->flags, handle->family, handle->table);
 }
 
-
-struct toplevel_rule {
-       enum fw3_table table;
-       const char *chain;
-       const char *target;
-};
-
 void
 fw3_print_default_head_rules(struct fw3_ipt_handle *handle,
                              struct fw3_state *state, bool reload)
@@ -189,7 +173,6 @@ fw3_print_default_head_rules(struct fw3_ipt_handle *handle,
        struct fw3_device lodev = { .set = true };
        struct fw3_protocol tcp = { .protocol = 6 };
        struct fw3_ipt_rule *r;
-       //struct toplevel_rule *tr;
 
        const char *chains[] = {
                "INPUT", "input",
@@ -197,32 +180,6 @@ fw3_print_default_head_rules(struct fw3_ipt_handle *handle,
                "FORWARD", "forwarding",
        };
 
-       //struct toplevel_rule rules[] = {
-       //      { FW3_TABLE_FILTER, "INPUT",       "delegate_input" },
-       //      { FW3_TABLE_FILTER, "OUTPUT",      "delegate_output" },
-       //      { FW3_TABLE_FILTER, "FORWARD",     "delegate_forward" },
-       //
-       //      { FW3_TABLE_NAT,    "PREROUTING",  "delegate_prerouting" },
-       //      { FW3_TABLE_NAT,    "POSTROUTING", "delegate_postrouting" },
-       //
-       //      { FW3_TABLE_MANGLE, "FORWARD",     "mssfix" },
-       //      { FW3_TABLE_MANGLE, "PREROUTING",  "fwmark" },
-       //
-       //      { FW3_TABLE_RAW,    "PREROUTING",  "delegate_notrack" },
-       //
-       //      { 0, NULL },
-       //};
-       //
-       //for (tr = rules; tr->chain; tr++)
-       //{
-       //      if (tr->table != handle->table)
-       //              continue;
-       //
-       //      r = fw3_ipt_rule_new(handle);
-       //      fw3_ipt_rule_target(r, tr->target);
-       //      fw3_ipt_rule_replace(r, tr->chain);
-       //}
-
        switch (handle->table)
        {
        case FW3_TABLE_FILTER: