X-Git-Url: http://git.archive.openwrt.org/?p=project%2Ffirewall3.git;a=blobdiff_plain;f=includes.c;h=a2b37a32e09b09bad717783171c04a6807910871;hp=23cfda0f4f73f7e4d99183d84144336763e08237;hb=6039c7f4b0052c4da21520cdd604f04a5a67f50d;hpb=8eb2ce1f936bb27267c9fb312fbb4c3ea008f5af diff --git a/includes.c b/includes.c index 23cfda0..a2b37a3 100644 --- a/includes.c +++ b/includes.c @@ -1,7 +1,7 @@ /* * firewall3 - 3rd OpenWrt UCI firewall implementation * - * Copyright (C) 2013 Jo-Philipp Wich + * Copyright (C) 2013 Jo-Philipp Wich * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -47,17 +47,15 @@ fw3_load_includes(struct fw3_state *state, struct uci_package *p) if (strcmp(s->type, "include")) continue; - include = malloc(sizeof(*include)); - + include = calloc(1, sizeof(*include)); if (!include) continue; - memset(include, 0, sizeof(*include)); - include->name = e->name; include->enabled = true; - fw3_parse_options(include, fw3_include_opts, s); + if (!fw3_parse_options(include, fw3_include_opts, s)) + warn_elem(e, "has invalid options"); if (!include->enabled) { @@ -83,14 +81,11 @@ fw3_load_includes(struct fw3_state *state, struct uci_package *p) static void -print_include(struct fw3_include *include, enum fw3_family family) +print_include(struct fw3_include *include) { FILE *f; char line[1024]; - if (!fw3_is_family(include, family)) - return; - info(" * Loading include '%s'", include->path); if (!(f = fopen(include->path, "r"))) @@ -110,14 +105,36 @@ fw3_print_includes(struct fw3_state *state, enum fw3_family family, bool reload) { struct fw3_include *include; + bool exec = false; + const char *restore = "iptables-restore"; + + if (family == FW3_FAMILY_V6) + restore = "ip6tables-restore"; + list_for_each_entry(include, &state->includes, list) { if (reload && !include->reload) continue; - if (include->type == FW3_INC_TYPE_RESTORE) - print_include(include, family); + if (include->type != FW3_INC_TYPE_RESTORE) + continue; + + if (!fw3_is_family(include, family)) + continue; + + if (!exec) + { + exec = fw3_command_pipe(false, restore, "--noflush"); + + if (!exec) + return; + } + + print_include(include); } + + if (exec) + fw3_command_close(); }