2 * firewall3 - 3rd OpenWrt UCI firewall implementation
4 * Copyright (C) 2013 Jo-Philipp Wich <jow@openwrt.org>
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("conntrack", bool, zone
, conntrack
),
77 FW3_OPT("mtu_fix", bool, zone
, mtu_fix
),
78 FW3_OPT("custom_chains", bool, zone
, custom_chains
),
80 FW3_OPT("log", bool, zone
, log
),
81 FW3_OPT("log_limit", limit
, zone
, log_limit
),
83 FW3_OPT("__flags_v4", int, zone
, flags
[0]),
84 FW3_OPT("__flags_v6", int, zone
, flags
[1]),
91 check_policy(struct uci_element
*e
, enum fw3_flag
*pol
, enum fw3_flag def
,
94 if (*pol
== FW3_FLAG_UNSPEC
)
96 warn_elem(e
, "has no %s policy specified, using default", name
);
99 else if (*pol
> FW3_FLAG_DROP
)
101 warn_elem(e
, "has invalid %s policy, using default", name
);
107 resolve_networks(struct uci_element
*e
, struct fw3_zone
*zone
)
109 struct fw3_device
*net
, *tmp
;
111 list_for_each_entry(net
, &zone
->networks
, list
)
113 tmp
= fw3_ubus_device(net
->name
);
117 warn_elem(e
, "cannot resolve device of network '%s'", net
->name
);
121 snprintf(tmp
->network
, sizeof(tmp
->network
), "%s", net
->name
);
122 list_add_tail(&tmp
->list
, &zone
->devices
);
129 struct fw3_zone
*zone
;
131 zone
= malloc(sizeof(*zone
));
136 memset(zone
, 0, sizeof(*zone
));
138 INIT_LIST_HEAD(&zone
->networks
);
139 INIT_LIST_HEAD(&zone
->devices
);
140 INIT_LIST_HEAD(&zone
->subnets
);
141 INIT_LIST_HEAD(&zone
->masq_src
);
142 INIT_LIST_HEAD(&zone
->masq_dest
);
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 setbit(zone
->flags
[0], FW3_FLAG_SNAT
);
219 zone
->conntrack
= true;
222 if (zone
->custom_chains
)
224 setbit(zone
->flags
[0], FW3_FLAG_SNAT
);
225 setbit(zone
->flags
[0], FW3_FLAG_DNAT
);
228 setbit(zone
->flags
[0], fw3_to_src_target(zone
->policy_input
));
229 setbit(zone
->flags
[0], fw3_to_src_target(zone
->policy_forward
));
230 setbit(zone
->flags
[0], zone
->policy_output
);
232 setbit(zone
->flags
[1], fw3_to_src_target(zone
->policy_input
));
233 setbit(zone
->flags
[1], fw3_to_src_target(zone
->policy_forward
));
234 setbit(zone
->flags
[1], zone
->policy_output
);
236 list_add_tail(&zone
->list
, &state
->zones
);
242 print_zone_chain(struct fw3_ipt_handle
*handle
, struct fw3_state
*state
,
243 bool reload
, struct fw3_zone
*zone
)
246 struct fw3_ipt_rule
*r
;
247 const struct fw3_chain_spec
*c
;
249 const char *flt_chains
[] = {
252 "forward", "forwarding",
255 const char *nat_chains
[] = {
256 "prerouting", "prerouting",
257 "postrouting", "postrouting",
260 if (!fw3_is_family(zone
, handle
->family
))
263 info(" * Zone '%s'", zone
->name
);
265 set(zone
->flags
, handle
->family
, handle
->table
);
267 if (zone
->custom_chains
)
268 set(zone
->flags
, handle
->family
, FW3_FLAG_CUSTOM_CHAINS
);
270 if (!zone
->conntrack
&& !state
->defaults
.drop_invalid
)
271 set(zone
->flags
, handle
->family
, FW3_FLAG_NOTRACK
);
273 for (c
= zone_chains
; c
->format
; c
++)
275 /* don't touch user chains on selective stop */
276 if (reload
&& c
->flag
== FW3_FLAG_CUSTOM_CHAINS
)
279 if (!fw3_is_family(c
, handle
->family
))
282 if (c
->table
!= handle
->table
)
286 !hasbit(zone
->flags
[handle
->family
== FW3_FAMILY_V6
], c
->flag
))
289 fw3_ipt_create_chain(handle
, c
->format
, zone
->name
);
292 if (zone
->custom_chains
)
294 if (handle
->table
== FW3_TABLE_FILTER
)
296 for (i
= 0; i
< sizeof(flt_chains
)/sizeof(flt_chains
[0]); i
+= 2)
298 r
= fw3_ipt_rule_new(handle
);
299 fw3_ipt_rule_comment(r
, "user chain for %s", flt_chains
[i
+1]);
300 fw3_ipt_rule_target(r
, "%s_%s_rule", flt_chains
[i
+1], zone
->name
);
301 fw3_ipt_rule_append(r
, "zone_%s_%s", zone
->name
, flt_chains
[i
]);
304 else if (handle
->table
== FW3_TABLE_NAT
)
306 for (i
= 0; i
< sizeof(nat_chains
)/sizeof(nat_chains
[0]); i
+= 2)
308 r
= fw3_ipt_rule_new(handle
);
309 fw3_ipt_rule_comment(r
, "user chain for %s", nat_chains
[i
+1]);
310 fw3_ipt_rule_target(r
, "%s_%s_rule", nat_chains
[i
+1], zone
->name
);
311 fw3_ipt_rule_append(r
, "zone_%s_%s", zone
->name
, nat_chains
[i
]);
316 set(zone
->flags
, handle
->family
, handle
->table
);
320 print_interface_rule(struct fw3_ipt_handle
*handle
, struct fw3_state
*state
,
321 bool reload
, struct fw3_zone
*zone
,
322 struct fw3_device
*dev
, struct fw3_address
*sub
)
324 struct fw3_protocol tcp
= { .protocol
= 6 };
325 struct fw3_ipt_rule
*r
;
332 const char *chains
[] = {
338 #define jump_target(t) \
339 ((t == FW3_FLAG_REJECT) ? "reject" : fw3_flag_names[t])
341 if (handle
->table
== FW3_TABLE_FILTER
)
343 for (t
= FW3_FLAG_ACCEPT
; t
<= FW3_FLAG_DROP
; t
++)
345 if (has(zone
->flags
, handle
->family
, fw3_to_src_target(t
)))
347 r
= fw3_ipt_rule_create(handle
, NULL
, dev
, NULL
, sub
, NULL
);
348 fw3_ipt_rule_target(r
, jump_target(t
));
349 fw3_ipt_rule_extra(r
, zone
->extra_src
);
350 fw3_ipt_rule_replace(r
, "zone_%s_src_%s", zone
->name
,
354 if (has(zone
->flags
, handle
->family
, t
))
356 r
= fw3_ipt_rule_create(handle
, NULL
, NULL
, dev
, NULL
, sub
);
357 fw3_ipt_rule_target(r
, jump_target(t
));
358 fw3_ipt_rule_extra(r
, zone
->extra_dest
);
359 fw3_ipt_rule_replace(r
, "zone_%s_dest_%s", zone
->name
,
364 for (i
= 0; i
< sizeof(chains
)/sizeof(chains
[0]); i
++)
366 if (*chains
[i
] == 'o')
367 r
= fw3_ipt_rule_create(handle
, NULL
, NULL
, dev
, NULL
, sub
);
369 r
= fw3_ipt_rule_create(handle
, NULL
, dev
, NULL
, sub
, NULL
);
371 fw3_ipt_rule_target(r
, "zone_%s_%s", zone
->name
, chains
[i
]);
373 if (*chains
[i
] == 'o')
374 fw3_ipt_rule_extra(r
, zone
->extra_dest
);
376 fw3_ipt_rule_extra(r
, zone
->extra_src
);
378 fw3_ipt_rule_replace(r
, "delegate_%s", chains
[i
]);
381 else if (handle
->table
== FW3_TABLE_NAT
)
383 if (has(zone
->flags
, handle
->family
, FW3_FLAG_DNAT
))
385 r
= fw3_ipt_rule_create(handle
, NULL
, dev
, NULL
, sub
, NULL
);
386 fw3_ipt_rule_target(r
, "zone_%s_prerouting", zone
->name
);
387 fw3_ipt_rule_extra(r
, zone
->extra_src
);
388 fw3_ipt_rule_replace(r
, "delegate_prerouting");
391 if (has(zone
->flags
, handle
->family
, FW3_FLAG_SNAT
))
393 r
= fw3_ipt_rule_create(handle
, NULL
, NULL
, dev
, NULL
, sub
);
394 fw3_ipt_rule_target(r
, "zone_%s_postrouting", zone
->name
);
395 fw3_ipt_rule_extra(r
, zone
->extra_dest
);
396 fw3_ipt_rule_replace(r
, "delegate_postrouting");
399 else if (handle
->table
== FW3_TABLE_MANGLE
)
405 snprintf(buf
, sizeof(buf
) - 1, "MSSFIX(%s): ", zone
->name
);
407 r
= fw3_ipt_rule_create(handle
, &tcp
, NULL
, dev
, NULL
, sub
);
408 fw3_ipt_rule_addarg(r
, false, "--tcp-flags", "SYN,RST");
409 fw3_ipt_rule_addarg(r
, false, "SYN", NULL
);
410 fw3_ipt_rule_limit(r
, &zone
->log_limit
);
411 fw3_ipt_rule_comment(r
, "%s (mtu_fix logging)", zone
->name
);
412 fw3_ipt_rule_target(r
, "LOG");
413 fw3_ipt_rule_addarg(r
, false, "--log-prefix", buf
);
414 fw3_ipt_rule_replace(r
, "mssfix");
417 r
= fw3_ipt_rule_create(handle
, &tcp
, NULL
, dev
, NULL
, sub
);
418 fw3_ipt_rule_addarg(r
, false, "--tcp-flags", "SYN,RST");
419 fw3_ipt_rule_addarg(r
, false, "SYN", NULL
);
420 fw3_ipt_rule_comment(r
, "%s (mtu_fix)", zone
->name
);
421 fw3_ipt_rule_target(r
, "TCPMSS");
422 fw3_ipt_rule_addarg(r
, false, "--clamp-mss-to-pmtu", NULL
);
423 fw3_ipt_rule_replace(r
, "mssfix");
426 else if (handle
->table
== FW3_TABLE_RAW
)
428 if (has(zone
->flags
, handle
->family
, FW3_FLAG_NOTRACK
))
430 r
= fw3_ipt_rule_create(handle
, NULL
, dev
, NULL
, sub
, NULL
);
431 fw3_ipt_rule_target(r
, "zone_%s_notrack", zone
->name
);
432 fw3_ipt_rule_extra(r
, zone
->extra_src
);
433 fw3_ipt_rule_replace(r
, "delegate_notrack");
439 print_interface_rules(struct fw3_ipt_handle
*handle
, struct fw3_state
*state
,
440 bool reload
, struct fw3_zone
*zone
)
442 struct fw3_device
*dev
;
443 struct fw3_address
*sub
;
445 fw3_foreach(dev
, &zone
->devices
)
446 fw3_foreach(sub
, &zone
->subnets
)
448 if (!fw3_is_family(sub
, handle
->family
))
454 print_interface_rule(handle
, state
, reload
, zone
, dev
, sub
);
459 print_zone_rule(struct fw3_ipt_handle
*handle
, struct fw3_state
*state
,
460 bool reload
, struct fw3_zone
*zone
)
462 bool disable_notrack
= state
->defaults
.drop_invalid
;
463 struct fw3_address
*msrc
;
464 struct fw3_address
*mdest
;
465 struct fw3_ipt_rule
*r
;
470 if (!fw3_is_family(zone
, handle
->family
))
473 switch (handle
->table
)
475 case FW3_TABLE_FILTER
:
476 if (has(zone
->flags
, handle
->family
, FW3_FLAG_DNAT
))
478 r
= fw3_ipt_rule_new(handle
);
479 fw3_ipt_rule_extra(r
, "-m conntrack --ctstate DNAT");
480 fw3_ipt_rule_comment(r
, "Accept port redirections");
481 fw3_ipt_rule_target(r
, fw3_flag_names
[FW3_FLAG_ACCEPT
]);
482 fw3_ipt_rule_append(r
, "zone_%s_input", zone
->name
);
484 r
= fw3_ipt_rule_new(handle
);
485 fw3_ipt_rule_extra(r
, "-m conntrack --ctstate DNAT");
486 fw3_ipt_rule_comment(r
, "Accept port forwards");
487 fw3_ipt_rule_target(r
, fw3_flag_names
[FW3_FLAG_ACCEPT
]);
488 fw3_ipt_rule_append(r
, "zone_%s_forward", zone
->name
);
491 r
= fw3_ipt_rule_new(handle
);
492 fw3_ipt_rule_target(r
, "zone_%s_src_%s", zone
->name
,
493 fw3_flag_names
[zone
->policy_input
]);
494 fw3_ipt_rule_append(r
, "zone_%s_input", zone
->name
);
496 r
= fw3_ipt_rule_new(handle
);
497 fw3_ipt_rule_target(r
, "zone_%s_src_%s", zone
->name
,
498 fw3_flag_names
[zone
->policy_forward
]);
499 fw3_ipt_rule_append(r
, "zone_%s_forward", zone
->name
);
501 r
= fw3_ipt_rule_new(handle
);
502 fw3_ipt_rule_target(r
, "zone_%s_dest_%s", zone
->name
,
503 fw3_flag_names
[zone
->policy_output
]);
504 fw3_ipt_rule_append(r
, "zone_%s_output", zone
->name
);
508 for (t
= FW3_FLAG_REJECT
; t
<= FW3_FLAG_DROP
; t
++)
510 if (has(zone
->flags
, handle
->family
, fw3_to_src_target(t
)))
512 r
= fw3_ipt_rule_new(handle
);
514 snprintf(buf
, sizeof(buf
) - 1, "%s(src %s)",
515 fw3_flag_names
[t
], zone
->name
);
517 fw3_ipt_rule_limit(r
, &zone
->log_limit
);
518 fw3_ipt_rule_target(r
, "LOG");
519 fw3_ipt_rule_addarg(r
, false, "--log-prefix", buf
);
520 fw3_ipt_rule_append(r
, "zone_%s_src_%s",
521 zone
->name
, fw3_flag_names
[t
]);
524 if (has(zone
->flags
, handle
->family
, t
))
526 r
= fw3_ipt_rule_new(handle
);
528 snprintf(buf
, sizeof(buf
) - 1, "%s(dest %s)",
529 fw3_flag_names
[t
], zone
->name
);
531 fw3_ipt_rule_limit(r
, &zone
->log_limit
);
532 fw3_ipt_rule_target(r
, "LOG");
533 fw3_ipt_rule_addarg(r
, false, "--log-prefix", buf
);
534 fw3_ipt_rule_append(r
, "zone_%s_dest_%s",
535 zone
->name
, fw3_flag_names
[t
]);
542 if (zone
->masq
&& handle
->family
== FW3_FAMILY_V4
)
544 fw3_foreach(msrc
, &zone
->masq_src
)
545 fw3_foreach(mdest
, &zone
->masq_dest
)
547 if (!fw3_is_family(msrc
, handle
->family
) ||
548 !fw3_is_family(mdest
, handle
->family
))
551 r
= fw3_ipt_rule_new(handle
);
552 fw3_ipt_rule_src_dest(r
, msrc
, mdest
);
553 fw3_ipt_rule_target(r
, "MASQUERADE");
554 fw3_ipt_rule_append(r
, "zone_%s_postrouting", zone
->name
);
560 if (!zone
->conntrack
&& !disable_notrack
)
562 r
= fw3_ipt_rule_new(handle
);
563 fw3_ipt_rule_target(r
, "CT");
564 fw3_ipt_rule_addarg(r
, false, "--notrack", NULL
);
565 fw3_ipt_rule_append(r
, "zone_%s_notrack", zone
->name
);
569 case FW3_TABLE_MANGLE
:
573 print_interface_rules(handle
, state
, reload
, zone
);
577 fw3_print_zone_chains(struct fw3_ipt_handle
*handle
, struct fw3_state
*state
,
580 struct fw3_zone
*zone
;
582 list_for_each_entry(zone
, &state
->zones
, list
)
583 print_zone_chain(handle
, state
, reload
, zone
);
587 fw3_print_zone_rules(struct fw3_ipt_handle
*handle
, struct fw3_state
*state
,
590 struct fw3_zone
*zone
;
592 list_for_each_entry(zone
, &state
->zones
, list
)
593 print_zone_rule(handle
, state
, reload
, zone
);
597 fw3_flush_zones(struct fw3_ipt_handle
*handle
, struct fw3_state
*state
,
600 struct fw3_zone
*z
, *tmp
;
601 const struct fw3_chain_spec
*c
;
604 list_for_each_entry_safe(z
, tmp
, &state
->zones
, list
)
606 if (!has(z
->flags
, handle
->family
, handle
->table
))
609 for (c
= zone_chains
; c
->format
; c
++)
611 /* don't touch user chains on selective stop */
612 if (reload
&& c
->flag
== FW3_FLAG_CUSTOM_CHAINS
)
615 if (!fw3_is_family(c
, handle
->family
))
618 if (c
->table
!= handle
->table
)
621 if (c
->flag
&& !has(z
->flags
, handle
->family
, c
->flag
))
624 snprintf(chain
, sizeof(chain
), c
->format
, z
->name
);
625 fw3_ipt_flush_chain(handle
, chain
);
627 /* keep certain basic chains that do not depend on any settings to
628 avoid purging unrelated user rules pointing to them */
629 if (reload
&& !c
->flag
)
632 fw3_ipt_delete_chain(handle
, chain
);
635 del(z
->flags
, handle
->family
, handle
->table
);
640 fw3_hotplug_zones(struct fw3_state
*state
, bool add
)
643 struct fw3_device
*d
;
645 list_for_each_entry(z
, &state
->zones
, list
)
647 if (add
!= hasbit(z
->flags
[0], FW3_FLAG_HOTPLUG
))
649 list_for_each_entry(d
, &z
->devices
, list
)
650 fw3_hotplug(add
, z
, d
);
653 setbit(z
->flags
[0], FW3_FLAG_HOTPLUG
);
655 delbit(z
->flags
[0], FW3_FLAG_HOTPLUG
);
661 fw3_lookup_zone(struct fw3_state
*state
, const char *name
)
665 if (list_empty(&state
->zones
))
668 list_for_each_entry(z
, &state
->zones
, list
)
670 if (strcmp(z
->name
, name
))
680 fw3_resolve_zone_addresses(struct fw3_zone
*zone
)
682 struct fw3_device
*net
;
683 struct fw3_address
*addr
, *tmp
;
684 struct list_head
*addrs
, *all
;
686 all
= malloc(sizeof(*all
));
691 memset(all
, 0, sizeof(*all
));
694 list_for_each_entry(net
, &zone
->networks
, list
)
696 addrs
= fw3_ubus_address(net
->name
);
701 list_for_each_entry_safe(addr
, tmp
, addrs
, list
)
703 list_del(&addr
->list
);
704 list_add_tail(&addr
->list
, all
);
710 list_for_each_entry(addr
, &zone
->subnets
, list
)
712 tmp
= malloc(sizeof(*tmp
));
717 memcpy(tmp
, addr
, sizeof(*tmp
));
718 list_add_tail(&tmp
->list
, all
);