2 * firewall3 - 3rd OpenWrt UCI firewall implementation
4 * Copyright (C) 2013 Jo-Philipp Wich <jo@mein.io>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 #define C(f, tbl, tgt, fmt) \
24 { FW3_FAMILY_##f, FW3_TABLE_##tbl, FW3_FLAG_##tgt, fmt }
26 static const struct fw3_chain_spec zone_chains
[] = {
27 C(ANY
, FILTER
, UNSPEC
, "zone_%s_input"),
28 C(ANY
, FILTER
, UNSPEC
, "zone_%s_output"),
29 C(ANY
, FILTER
, UNSPEC
, "zone_%s_forward"),
31 C(ANY
, FILTER
, SRC_ACCEPT
, "zone_%s_src_ACCEPT"),
32 C(ANY
, FILTER
, SRC_REJECT
, "zone_%s_src_REJECT"),
33 C(ANY
, FILTER
, SRC_DROP
, "zone_%s_src_DROP"),
35 C(ANY
, FILTER
, ACCEPT
, "zone_%s_dest_ACCEPT"),
36 C(ANY
, FILTER
, REJECT
, "zone_%s_dest_REJECT"),
37 C(ANY
, FILTER
, DROP
, "zone_%s_dest_DROP"),
39 C(V4
, NAT
, SNAT
, "zone_%s_postrouting"),
40 C(V4
, NAT
, DNAT
, "zone_%s_prerouting"),
42 C(ANY
, RAW
, NOTRACK
, "zone_%s_notrack"),
44 C(ANY
, FILTER
, CUSTOM_CHAINS
, "input_%s_rule"),
45 C(ANY
, FILTER
, CUSTOM_CHAINS
, "output_%s_rule"),
46 C(ANY
, FILTER
, CUSTOM_CHAINS
, "forwarding_%s_rule"),
48 C(V4
, NAT
, CUSTOM_CHAINS
, "prerouting_%s_rule"),
49 C(V4
, NAT
, CUSTOM_CHAINS
, "postrouting_%s_rule"),
54 const struct fw3_option fw3_zone_opts
[] = {
55 FW3_OPT("enabled", bool, zone
, enabled
),
57 FW3_OPT("name", string
, zone
, name
),
58 FW3_OPT("family", family
, zone
, family
),
60 FW3_LIST("network", device
, zone
, networks
),
61 FW3_LIST("device", device
, zone
, devices
),
62 FW3_LIST("subnet", network
, zone
, subnets
),
64 FW3_OPT("input", target
, zone
, policy_input
),
65 FW3_OPT("forward", target
, zone
, policy_forward
),
66 FW3_OPT("output", target
, zone
, policy_output
),
68 FW3_OPT("masq", bool, zone
, masq
),
69 FW3_LIST("masq_src", network
, zone
, masq_src
),
70 FW3_LIST("masq_dest", network
, zone
, masq_dest
),
72 FW3_OPT("extra", string
, zone
, extra_src
),
73 FW3_OPT("extra_src", string
, zone
, extra_src
),
74 FW3_OPT("extra_dest", string
, zone
, extra_dest
),
76 FW3_OPT("mtu_fix", bool, zone
, mtu_fix
),
77 FW3_OPT("custom_chains", bool, zone
, custom_chains
),
79 FW3_OPT("log", bool, zone
, log
),
80 FW3_OPT("log_limit", limit
, zone
, log_limit
),
82 FW3_OPT("__flags_v4", int, zone
, flags
[0]),
83 FW3_OPT("__flags_v6", int, zone
, flags
[1]),
85 FW3_LIST("__addrs", address
, zone
, old_addrs
),
92 check_policy(struct uci_element
*e
, enum fw3_flag
*pol
, enum fw3_flag def
,
95 if (*pol
== FW3_FLAG_UNSPEC
)
97 warn_elem(e
, "has no %s policy specified, using default", name
);
100 else if (*pol
> FW3_FLAG_DROP
)
102 warn_elem(e
, "has invalid %s policy, using default", name
);
108 resolve_networks(struct uci_element
*e
, struct fw3_zone
*zone
)
110 struct fw3_device
*net
, *tmp
;
112 list_for_each_entry(net
, &zone
->networks
, list
)
114 tmp
= fw3_ubus_device(net
->name
);
118 warn_elem(e
, "cannot resolve device of network '%s'", net
->name
);
122 snprintf(tmp
->network
, sizeof(tmp
->network
), "%s", net
->name
);
123 list_add_tail(&tmp
->list
, &zone
->devices
);
130 struct fw3_zone
*zone
;
132 zone
= calloc(1, sizeof(*zone
));
136 INIT_LIST_HEAD(&zone
->networks
);
137 INIT_LIST_HEAD(&zone
->devices
);
138 INIT_LIST_HEAD(&zone
->subnets
);
139 INIT_LIST_HEAD(&zone
->masq_src
);
140 INIT_LIST_HEAD(&zone
->masq_dest
);
142 INIT_LIST_HEAD(&zone
->old_addrs
);
144 zone
->enabled
= true;
145 zone
->custom_chains
= true;
146 zone
->log_limit
.rate
= 10;
152 fw3_load_zones(struct fw3_state
*state
, struct uci_package
*p
)
154 struct uci_section
*s
;
155 struct uci_element
*e
;
156 struct fw3_zone
*zone
;
157 struct fw3_defaults
*defs
= &state
->defaults
;
159 INIT_LIST_HEAD(&state
->zones
);
161 uci_foreach_element(&p
->sections
, e
)
163 s
= uci_to_section(e
);
165 if (strcmp(s
->type
, "zone"))
168 zone
= fw3_alloc_zone();
173 fw3_parse_options(zone
, fw3_zone_opts
, s
);
181 if (!zone
->extra_dest
)
182 zone
->extra_dest
= zone
->extra_src
;
184 if (!defs
->custom_chains
&& zone
->custom_chains
)
185 zone
->custom_chains
= false;
187 if (!zone
->name
|| !*zone
->name
)
189 warn_elem(e
, "has no name - ignoring");
194 if (strlen(zone
->name
) > FW3_ZONE_MAXNAMELEN
)
196 warn_elem(e
, "must not have a name longer than %u characters",
197 FW3_ZONE_MAXNAMELEN
);
202 fw3_ubus_zone_devices(zone
);
204 if (list_empty(&zone
->networks
) && list_empty(&zone
->devices
) &&
205 list_empty(&zone
->subnets
) && !zone
->extra_src
)
207 warn_elem(e
, "has no device, network, subnet or extra options");
210 check_policy(e
, &zone
->policy_input
, defs
->policy_input
, "input");
211 check_policy(e
, &zone
->policy_output
, defs
->policy_output
, "output");
212 check_policy(e
, &zone
->policy_forward
, defs
->policy_forward
, "forward");
214 resolve_networks(e
, zone
);
218 fw3_setbit(zone
->flags
[0], FW3_FLAG_SNAT
);
221 if (zone
->custom_chains
)
223 fw3_setbit(zone
->flags
[0], FW3_FLAG_SNAT
);
224 fw3_setbit(zone
->flags
[0], FW3_FLAG_DNAT
);
227 fw3_setbit(zone
->flags
[0], fw3_to_src_target(zone
->policy_input
));
228 fw3_setbit(zone
->flags
[0], zone
->policy_forward
);
229 fw3_setbit(zone
->flags
[0], zone
->policy_output
);
231 fw3_setbit(zone
->flags
[1], fw3_to_src_target(zone
->policy_input
));
232 fw3_setbit(zone
->flags
[1], zone
->policy_forward
);
233 fw3_setbit(zone
->flags
[1], zone
->policy_output
);
235 list_add_tail(&zone
->list
, &state
->zones
);
241 print_zone_chain(struct fw3_ipt_handle
*handle
, struct fw3_state
*state
,
242 bool reload
, struct fw3_zone
*zone
)
245 struct fw3_ipt_rule
*r
;
246 const struct fw3_chain_spec
*c
;
248 const char *flt_chains
[] = {
251 "forward", "forwarding",
254 const char *nat_chains
[] = {
255 "prerouting", "prerouting",
256 "postrouting", "postrouting",
259 if (!fw3_is_family(zone
, handle
->family
))
262 info(" * Zone '%s'", zone
->name
);
264 set(zone
->flags
, handle
->family
, handle
->table
);
266 if (zone
->custom_chains
)
267 set(zone
->flags
, handle
->family
, FW3_FLAG_CUSTOM_CHAINS
);
269 for (c
= zone_chains
; c
->format
; c
++)
271 /* don't touch user chains on selective stop */
272 if (reload
&& c
->flag
== FW3_FLAG_CUSTOM_CHAINS
)
275 if (!fw3_is_family(c
, handle
->family
))
278 if (c
->table
!= handle
->table
)
282 !fw3_hasbit(zone
->flags
[handle
->family
== FW3_FAMILY_V6
], c
->flag
))
285 fw3_ipt_create_chain(handle
, c
->format
, zone
->name
);
288 if (zone
->custom_chains
)
290 if (handle
->table
== FW3_TABLE_FILTER
)
292 for (i
= 0; i
< sizeof(flt_chains
)/sizeof(flt_chains
[0]); i
+= 2)
294 r
= fw3_ipt_rule_new(handle
);
295 fw3_ipt_rule_comment(r
, "user chain for %s", flt_chains
[i
+1]);
296 fw3_ipt_rule_target(r
, "%s_%s_rule", flt_chains
[i
+1], zone
->name
);
297 fw3_ipt_rule_append(r
, "zone_%s_%s", zone
->name
, flt_chains
[i
]);
300 else if (handle
->table
== FW3_TABLE_NAT
)
302 for (i
= 0; i
< sizeof(nat_chains
)/sizeof(nat_chains
[0]); i
+= 2)
304 r
= fw3_ipt_rule_new(handle
);
305 fw3_ipt_rule_comment(r
, "user chain for %s", nat_chains
[i
+1]);
306 fw3_ipt_rule_target(r
, "%s_%s_rule", nat_chains
[i
+1], zone
->name
);
307 fw3_ipt_rule_append(r
, "zone_%s_%s", zone
->name
, nat_chains
[i
]);
312 set(zone
->flags
, handle
->family
, handle
->table
);
316 print_interface_rule(struct fw3_ipt_handle
*handle
, struct fw3_state
*state
,
317 bool reload
, struct fw3_zone
*zone
,
318 struct fw3_device
*dev
, struct fw3_address
*sub
)
320 struct fw3_protocol tcp
= { .protocol
= 6 };
321 struct fw3_ipt_rule
*r
;
328 const char *chains
[] = {
331 "forward", "FORWARD",
334 #define jump_target(t) \
335 ((t == FW3_FLAG_REJECT) ? "reject" : fw3_flag_names[t])
337 if (handle
->table
== FW3_TABLE_FILTER
)
339 for (t
= FW3_FLAG_ACCEPT
; t
<= FW3_FLAG_DROP
; t
++)
341 if (has(zone
->flags
, handle
->family
, fw3_to_src_target(t
)))
343 r
= fw3_ipt_rule_create(handle
, NULL
, dev
, NULL
, sub
, NULL
);
344 fw3_ipt_rule_target(r
, jump_target(t
));
345 fw3_ipt_rule_extra(r
, zone
->extra_src
);
347 if (t
== FW3_FLAG_ACCEPT
&& !state
->defaults
.drop_invalid
)
348 fw3_ipt_rule_extra(r
,
349 "-m conntrack --ctstate NEW,UNTRACKED");
351 fw3_ipt_rule_replace(r
, "zone_%s_src_%s", zone
->name
,
355 if (has(zone
->flags
, handle
->family
, t
))
357 r
= fw3_ipt_rule_create(handle
, NULL
, NULL
, dev
, NULL
, sub
);
358 fw3_ipt_rule_target(r
, jump_target(t
));
359 fw3_ipt_rule_extra(r
, zone
->extra_dest
);
360 fw3_ipt_rule_replace(r
, "zone_%s_dest_%s", zone
->name
,
365 for (i
= 0; i
< sizeof(chains
)/sizeof(chains
[0]); i
+= 2)
367 if (*chains
[i
] == 'o')
368 r
= fw3_ipt_rule_create(handle
, NULL
, NULL
, dev
, NULL
, sub
);
370 r
= fw3_ipt_rule_create(handle
, NULL
, dev
, NULL
, sub
, NULL
);
372 fw3_ipt_rule_target(r
, "zone_%s_%s", zone
->name
, chains
[i
]);
374 if (*chains
[i
] == 'o')
375 fw3_ipt_rule_extra(r
, zone
->extra_dest
);
377 fw3_ipt_rule_extra(r
, zone
->extra_src
);
379 fw3_ipt_rule_replace(r
, chains
[i
+ 1]);
382 else if (handle
->table
== FW3_TABLE_NAT
)
384 if (has(zone
->flags
, handle
->family
, FW3_FLAG_DNAT
))
386 r
= fw3_ipt_rule_create(handle
, NULL
, dev
, NULL
, sub
, NULL
);
387 fw3_ipt_rule_target(r
, "zone_%s_prerouting", zone
->name
);
388 fw3_ipt_rule_extra(r
, zone
->extra_src
);
389 fw3_ipt_rule_replace(r
, "PREROUTING");
392 if (has(zone
->flags
, handle
->family
, FW3_FLAG_SNAT
))
394 r
= fw3_ipt_rule_create(handle
, NULL
, NULL
, dev
, NULL
, sub
);
395 fw3_ipt_rule_target(r
, "zone_%s_postrouting", zone
->name
);
396 fw3_ipt_rule_extra(r
, zone
->extra_dest
);
397 fw3_ipt_rule_replace(r
, "POSTROUTING");
400 else if (handle
->table
== FW3_TABLE_MANGLE
)
406 snprintf(buf
, sizeof(buf
) - 1, "MSSFIX(%s): ", zone
->name
);
408 r
= fw3_ipt_rule_create(handle
, &tcp
, NULL
, dev
, NULL
, sub
);
409 fw3_ipt_rule_addarg(r
, false, "--tcp-flags", "SYN,RST");
410 fw3_ipt_rule_addarg(r
, false, "SYN", NULL
);
411 fw3_ipt_rule_limit(r
, &zone
->log_limit
);
412 fw3_ipt_rule_comment(r
, "%s (mtu_fix logging)", zone
->name
);
413 fw3_ipt_rule_target(r
, "LOG");
414 fw3_ipt_rule_addarg(r
, false, "--log-prefix", buf
);
415 fw3_ipt_rule_replace(r
, "FORWARD");
418 r
= fw3_ipt_rule_create(handle
, &tcp
, NULL
, dev
, NULL
, sub
);
419 fw3_ipt_rule_addarg(r
, false, "--tcp-flags", "SYN,RST");
420 fw3_ipt_rule_addarg(r
, false, "SYN", NULL
);
421 fw3_ipt_rule_comment(r
, "%s (mtu_fix)", zone
->name
);
422 fw3_ipt_rule_target(r
, "TCPMSS");
423 fw3_ipt_rule_addarg(r
, false, "--clamp-mss-to-pmtu", NULL
);
424 fw3_ipt_rule_replace(r
, "FORWARD");
427 else if (handle
->table
== FW3_TABLE_RAW
)
429 if (has(zone
->flags
, handle
->family
, FW3_FLAG_NOTRACK
))
431 r
= fw3_ipt_rule_create(handle
, NULL
, dev
, NULL
, sub
, NULL
);
432 fw3_ipt_rule_target(r
, "zone_%s_notrack", zone
->name
);
433 fw3_ipt_rule_extra(r
, zone
->extra_src
);
434 fw3_ipt_rule_replace(r
, "PREROUTING");
440 print_interface_rules(struct fw3_ipt_handle
*handle
, struct fw3_state
*state
,
441 bool reload
, struct fw3_zone
*zone
)
443 struct fw3_device
*dev
;
444 struct fw3_address
*sub
;
446 fw3_foreach(dev
, &zone
->devices
)
447 fw3_foreach(sub
, &zone
->subnets
)
449 if (!fw3_is_family(sub
, handle
->family
))
455 print_interface_rule(handle
, state
, reload
, zone
, dev
, sub
);
459 static struct fw3_address
*
460 next_addr(struct fw3_address
*addr
, struct list_head
*list
,
461 enum fw3_family family
, bool invert
)
464 struct fw3_address
*rv
;
466 for (p
= addr
? addr
->list
.next
: list
->next
; p
!= list
; p
= p
->next
)
468 rv
= list_entry(p
, struct fw3_address
, list
);
470 if (fw3_is_family(rv
, family
) && rv
->invert
== invert
)
478 print_zone_rule(struct fw3_ipt_handle
*handle
, struct fw3_state
*state
,
479 bool reload
, struct fw3_zone
*zone
)
481 bool first_src
, first_dest
;
482 struct fw3_address
*msrc
;
483 struct fw3_address
*mdest
;
484 struct fw3_ipt_rule
*r
;
489 if (!fw3_is_family(zone
, handle
->family
))
492 switch (handle
->table
)
494 case FW3_TABLE_FILTER
:
495 if (has(zone
->flags
, handle
->family
, FW3_FLAG_DNAT
))
497 r
= fw3_ipt_rule_new(handle
);
498 fw3_ipt_rule_extra(r
, "-m conntrack --ctstate DNAT");
499 fw3_ipt_rule_comment(r
, "Accept port redirections");
500 fw3_ipt_rule_target(r
, fw3_flag_names
[FW3_FLAG_ACCEPT
]);
501 fw3_ipt_rule_append(r
, "zone_%s_input", zone
->name
);
503 r
= fw3_ipt_rule_new(handle
);
504 fw3_ipt_rule_extra(r
, "-m conntrack --ctstate DNAT");
505 fw3_ipt_rule_comment(r
, "Accept port forwards");
506 fw3_ipt_rule_target(r
, fw3_flag_names
[FW3_FLAG_ACCEPT
]);
507 fw3_ipt_rule_append(r
, "zone_%s_forward", zone
->name
);
510 r
= fw3_ipt_rule_new(handle
);
511 fw3_ipt_rule_target(r
, "zone_%s_src_%s", zone
->name
,
512 fw3_flag_names
[zone
->policy_input
]);
513 fw3_ipt_rule_append(r
, "zone_%s_input", zone
->name
);
515 r
= fw3_ipt_rule_new(handle
);
516 fw3_ipt_rule_target(r
, "zone_%s_dest_%s", zone
->name
,
517 fw3_flag_names
[zone
->policy_forward
]);
518 fw3_ipt_rule_append(r
, "zone_%s_forward", zone
->name
);
520 r
= fw3_ipt_rule_new(handle
);
521 fw3_ipt_rule_target(r
, "zone_%s_dest_%s", zone
->name
,
522 fw3_flag_names
[zone
->policy_output
]);
523 fw3_ipt_rule_append(r
, "zone_%s_output", zone
->name
);
527 for (t
= FW3_FLAG_REJECT
; t
<= FW3_FLAG_DROP
; t
++)
529 if (has(zone
->flags
, handle
->family
, fw3_to_src_target(t
)))
531 r
= fw3_ipt_rule_new(handle
);
533 snprintf(buf
, sizeof(buf
) - 1, "%s(src %s)",
534 fw3_flag_names
[t
], zone
->name
);
536 fw3_ipt_rule_limit(r
, &zone
->log_limit
);
537 fw3_ipt_rule_target(r
, "LOG");
538 fw3_ipt_rule_addarg(r
, false, "--log-prefix", buf
);
539 fw3_ipt_rule_append(r
, "zone_%s_src_%s",
540 zone
->name
, fw3_flag_names
[t
]);
543 if (has(zone
->flags
, handle
->family
, t
))
545 r
= fw3_ipt_rule_new(handle
);
547 snprintf(buf
, sizeof(buf
) - 1, "%s(dest %s)",
548 fw3_flag_names
[t
], zone
->name
);
550 fw3_ipt_rule_limit(r
, &zone
->log_limit
);
551 fw3_ipt_rule_target(r
, "LOG");
552 fw3_ipt_rule_addarg(r
, false, "--log-prefix", buf
);
553 fw3_ipt_rule_append(r
, "zone_%s_dest_%s",
554 zone
->name
, fw3_flag_names
[t
]);
561 if (zone
->masq
&& handle
->family
== FW3_FAMILY_V4
)
563 /* for any negated masq_src ip, emit -s addr -j RETURN rules */
565 (msrc
= next_addr(msrc
, &zone
->masq_src
,
566 handle
->family
, true)) != NULL
; )
568 msrc
->invert
= false;
569 r
= fw3_ipt_rule_new(handle
);
570 fw3_ipt_rule_src_dest(r
, msrc
, NULL
);
571 fw3_ipt_rule_target(r
, "RETURN");
572 fw3_ipt_rule_append(r
, "zone_%s_postrouting", zone
->name
);
576 /* for any negated masq_dest ip, emit -d addr -j RETURN rules */
578 (mdest
= next_addr(mdest
, &zone
->masq_dest
,
579 handle
->family
, true)) != NULL
; )
581 mdest
->invert
= false;
582 r
= fw3_ipt_rule_new(handle
);
583 fw3_ipt_rule_src_dest(r
, NULL
, mdest
);
584 fw3_ipt_rule_target(r
, "RETURN");
585 fw3_ipt_rule_append(r
, "zone_%s_postrouting", zone
->name
);
586 mdest
->invert
= true;
589 /* emit masquerading entries for non-negated addresses
590 and ensure that both src and dest loops run at least once,
591 even if there are no relevant addresses */
592 for (first_src
= true, msrc
= NULL
;
593 (msrc
= next_addr(msrc
, &zone
->masq_src
,
594 handle
->family
, false)) || first_src
;
597 for (first_dest
= true, mdest
= NULL
;
598 (mdest
= next_addr(mdest
, &zone
->masq_dest
,
599 handle
->family
, false)) || first_dest
;
602 r
= fw3_ipt_rule_new(handle
);
603 fw3_ipt_rule_src_dest(r
, msrc
, mdest
);
604 fw3_ipt_rule_target(r
, "MASQUERADE");
605 fw3_ipt_rule_append(r
, "zone_%s_postrouting", zone
->name
);
612 case FW3_TABLE_MANGLE
:
616 print_interface_rules(handle
, state
, reload
, zone
);
620 fw3_print_zone_chains(struct fw3_ipt_handle
*handle
, struct fw3_state
*state
,
623 struct fw3_zone
*zone
;
625 list_for_each_entry(zone
, &state
->zones
, list
)
626 print_zone_chain(handle
, state
, reload
, zone
);
630 fw3_print_zone_rules(struct fw3_ipt_handle
*handle
, struct fw3_state
*state
,
633 struct fw3_zone
*zone
;
635 list_for_each_entry(zone
, &state
->zones
, list
)
636 print_zone_rule(handle
, state
, reload
, zone
);
640 fw3_flush_zones(struct fw3_ipt_handle
*handle
, struct fw3_state
*state
,
643 struct fw3_zone
*z
, *tmp
;
644 const struct fw3_chain_spec
*c
;
647 list_for_each_entry_safe(z
, tmp
, &state
->zones
, list
)
649 if (!has(z
->flags
, handle
->family
, handle
->table
))
652 for (c
= zone_chains
; c
->format
; c
++)
654 /* don't touch user chains on selective stop */
655 if (reload
&& c
->flag
== FW3_FLAG_CUSTOM_CHAINS
)
658 if (!fw3_is_family(c
, handle
->family
))
661 if (c
->table
!= handle
->table
)
664 if (c
->flag
&& !has(z
->flags
, handle
->family
, c
->flag
))
667 snprintf(chain
, sizeof(chain
), c
->format
, z
->name
);
668 fw3_ipt_flush_chain(handle
, chain
);
670 /* keep certain basic chains that do not depend on any settings to
671 avoid purging unrelated user rules pointing to them */
672 if (reload
&& !c
->flag
)
675 fw3_ipt_delete_chain(handle
, chain
);
678 del(z
->flags
, handle
->family
, handle
->table
);
683 fw3_hotplug_zones(struct fw3_state
*state
, bool add
)
686 struct fw3_device
*d
;
688 list_for_each_entry(z
, &state
->zones
, list
)
690 if (add
!= fw3_hasbit(z
->flags
[0], FW3_FLAG_HOTPLUG
))
692 list_for_each_entry(d
, &z
->devices
, list
)
693 fw3_hotplug(add
, z
, d
);
696 fw3_setbit(z
->flags
[0], FW3_FLAG_HOTPLUG
);
698 fw3_delbit(z
->flags
[0], FW3_FLAG_HOTPLUG
);
704 fw3_lookup_zone(struct fw3_state
*state
, const char *name
)
708 if (list_empty(&state
->zones
))
711 list_for_each_entry(z
, &state
->zones
, list
)
713 if (strcmp(z
->name
, name
))
723 fw3_resolve_zone_addresses(struct fw3_zone
*zone
, struct fw3_address
*addr
)
725 struct fw3_device
*net
;
726 struct fw3_address
*cur
, *tmp
;
727 struct list_head
*all
;
729 all
= calloc(1, sizeof(*all
));
735 if (addr
&& addr
->set
)
737 tmp
= malloc(sizeof(*tmp
));
742 list_add_tail(&tmp
->list
, all
);
747 list_for_each_entry(net
, &zone
->networks
, list
)
748 fw3_ubus_address(all
, net
->name
);
750 list_for_each_entry(cur
, &zone
->subnets
, list
)
752 tmp
= malloc(sizeof(*tmp
));
758 list_add_tail(&tmp
->list
, all
);