#define C(f, tbl, tgt, fmt) \
{ FW3_FAMILY_##f, FW3_TABLE_##tbl, FW3_FLAG_##tgt, fmt }
-static const struct fw3_rule_spec zone_chains[] = {
+static const struct fw3_chain_spec zone_chains[] = {
C(ANY, FILTER, UNSPEC, "zone_%s_input"),
C(ANY, FILTER, UNSPEC, "zone_%s_output"),
C(ANY, FILTER, UNSPEC, "zone_%s_forward"),
continue;
}
+ if (strlen(zone->name) > FW3_ZONE_MAXNAMELEN)
+ {
+ warn_elem(e, "must not have a name longer than %u characters",
+ FW3_ZONE_MAXNAMELEN);
+ fw3_free_zone(zone);
+ continue;
+ }
+
if (list_empty(&zone->networks) && list_empty(&zone->devices) &&
list_empty(&zone->subnets) && !zone->extra_src)
{
{
int i;
struct fw3_ipt_rule *r;
- const struct fw3_rule_spec *c;
+ const struct fw3_chain_spec *c;
const char *flt_chains[] = {
"input", "input",
bool reload)
{
struct fw3_zone *z, *tmp;
- const struct fw3_rule_spec *c;
+ const struct fw3_chain_spec *c;
char chain[32];
list_for_each_entry_safe(z, tmp, &state->zones, list)
for (c = zone_chains; c->format; c++)
{
/* don't touch user chains on selective stop */
- if (reload && hasbit(c->flag, FW3_FLAG_CUSTOM_CHAINS))
+ if (reload && c->flag == FW3_FLAG_CUSTOM_CHAINS)
continue;
if (!fw3_is_family(c, handle->family))
if (c->table != handle->table)
continue;
+ if (c->flag && !has(z->flags, handle->family, c->flag))
+ continue;
+
snprintf(chain, sizeof(chain), c->format, z->name);
fw3_ipt_delete_rules(handle, chain);
fw3_ipt_delete_chain(handle, chain);
return NULL;
}
+struct list_head *
+fw3_resolve_zone_addresses(struct fw3_zone *zone)
+{
+ struct fw3_device *net;
+ struct fw3_address *addr, *tmp;
+ struct list_head *addrs, *all;
+
+ all = malloc(sizeof(*all));
+
+ if (!all)
+ return NULL;
+
+ memset(all, 0, sizeof(*all));
+ INIT_LIST_HEAD(all);
+
+ list_for_each_entry(net, &zone->networks, list)
+ {
+ addrs = fw3_ubus_address(net->name);
+
+ if (!addrs)
+ continue;
+
+ list_for_each_entry_safe(addr, tmp, addrs, list)
+ {
+ list_del(&addr->list);
+ list_add_tail(&addr->list, all);
+ }
+
+ free(addrs);
+ }
+
+ list_for_each_entry(addr, &zone->subnets, list)
+ {
+ tmp = malloc(sizeof(*tmp));
+
+ if (!tmp)
+ continue;
+
+ memcpy(tmp, addr, sizeof(*tmp));
+ list_add_tail(&tmp->list, all);
+ }
+
+ return all;
+}
+
void
fw3_free_zone(struct fw3_zone *zone)
{