/*
* 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
{
for (i = 0; i < ARRAY_SIZE(ipset_types); i++)
{
+ /* skip type for v6 if it does not support family */
+ if (ipset->family != FW3_FAMILY_V4 &&
+ !(ipset_types[i].optional & OPT_FAMILY))
+ continue;
+
if (ipset_types[i].types == typelist)
{
ipset->method = ipset_types[i].method;
{
struct fw3_ipset *ipset;
- ipset = malloc(sizeof(*ipset));
-
+ ipset = calloc(1, sizeof(*ipset));
if (!ipset)
return NULL;
- memset(ipset, 0, sizeof(*ipset));
-
INIT_LIST_HEAD(&ipset->datatypes);
ipset->enabled = true;
{
warn_elem(e, "must not have family 'any'");
}
+ else if (ipset->iprange.set && ipset->family != ipset->iprange.family)
+ {
+ warn_elem(e, "has iprange of wrong address family");
+ }
else if (list_empty(&ipset->datatypes))
{
warn_elem(e, "has no datatypes assigned");
first = false;
}
+ if (ipset->method == FW3_IPSET_METHOD_HASH)
+ fw3_pr(" family inet%s", (ipset->family == FW3_FAMILY_V4) ? "" : "6");
+
if (ipset->iprange.set)
{
- fw3_pr(" range %s", fw3_address_to_string(&ipset->iprange, false));
+ fw3_pr(" range %s", fw3_address_to_string(&ipset->iprange, false, true));
}
else if (ipset->portrange.set)
{
ipset->portrange.port_min, ipset->portrange.port_max);
}
- fw3_pr(" family inet%s", (ipset->family == FW3_FAMILY_V4) ? "" : "6");
-
if (ipset->timeout > 0)
fw3_pr(" timeout %u", ipset->timeout);
create_ipset(ipset, state);
}
- fw3_pr("quit\n");
- fw3_command_close();
+ if (exec)
+ {
+ fw3_pr("quit\n");
+ fw3_command_close();
+ }
/* wait for ipsets to appear */
list_for_each_entry(ipset, &state->ipsets, list)
fw3_pr("destroy %s\n", ipset->name);
}
- fw3_pr("quit\n");
- fw3_command_close();
+ if (exec)
+ {
+ fw3_pr("quit\n");
+ fw3_command_close();
+ }
/* wait for ipsets to disappear */
list_for_each_entry(ipset, &state->ipsets, list)