From: Jo-Philipp Wich Date: Fri, 17 May 2013 13:17:48 +0000 (+0200) Subject: Wait for ipsets to appear before continuing X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=28df94a5e01fe3309eb664cae419a6fd4e5eab40;p=oweals%2Ffirewall3.git Wait for ipsets to appear before continuing --- diff --git a/ipsets.c b/ipsets.c index 955d434..e149b5b 100644 --- a/ipsets.c +++ b/ipsets.c @@ -281,9 +281,6 @@ create_ipset(struct fw3_ipset *ipset, struct fw3_state *state) struct fw3_ipset_datatype *type; - if (ipset->external) - return; - info(" * Creating ipset %s", ipset->name); first = true; @@ -325,31 +322,80 @@ create_ipset(struct fw3_ipset *ipset, struct fw3_state *state) void fw3_create_ipsets(struct fw3_state *state) { + int tries; + bool exec = false; struct fw3_ipset *ipset; if (state->disable_ipsets) return; + /* spawn ipsets */ list_for_each_entry(ipset, &state->ipsets, list) + { + if (ipset->external) + continue; + + if (!exec) + { + exec = fw3_command_pipe(false, "ipset", "-exist", "-"); + + if (!exec) + return; + } + create_ipset(ipset, state); + } fw3_pr("quit\n"); + fw3_command_close(); + + /* wait for ipsets to appear */ + list_for_each_entry(ipset, &state->ipsets, list) + { + if (ipset->external) + continue; + + for (tries = 0; !fw3_check_ipset(ipset) && tries < 10; tries++) + usleep(50000); + } } void fw3_destroy_ipsets(struct fw3_state *state) { - struct fw3_ipset *s; + int tries; + bool exec = false; + struct fw3_ipset *ipset; - list_for_each_entry(s, &state->ipsets, list) + /* destroy ipsets */ + list_for_each_entry(ipset, &state->ipsets, list) { - info(" * Deleting ipset %s", s->name); + if (!exec) + { + exec = fw3_command_pipe(false, "ipset", "-exist", "-"); + + if (!exec) + return; + } - fw3_pr("flush %s\n", s->name); - fw3_pr("destroy %s\n", s->name); + info(" * Deleting ipset %s", ipset->name); + + fw3_pr("flush %s\n", ipset->name); + fw3_pr("destroy %s\n", ipset->name); } fw3_pr("quit\n"); + fw3_command_close(); + + /* wait for ipsets to disappear */ + list_for_each_entry(ipset, &state->ipsets, list) + { + if (ipset->external) + continue; + + for (tries = 0; fw3_check_ipset(ipset) && tries < 10; tries++) + usleep(50000); + } } struct fw3_ipset * diff --git a/main.c b/main.c index 7a8969f..8305f9f 100644 --- a/main.c +++ b/main.c @@ -214,13 +214,7 @@ stop(bool complete) } if (run_state) - { - if (fw3_command_pipe(false, "ipset", "-exist", "-")) - { - fw3_destroy_ipsets(run_state); - fw3_command_close(); - } - } + fw3_destroy_ipsets(run_state); if (complete && (ct = fopen("/proc/net/nf_conntrack", "w")) != NULL) { @@ -245,13 +239,7 @@ start(void) struct fw3_ipt_handle *handle; if (!print_family) - { - if (fw3_command_pipe(false, "ipset", "-exist", "-")) - { - fw3_create_ipsets(cfg_state); - fw3_command_close(); - } - } + fw3_create_ipsets(cfg_state); for (family = FW3_FAMILY_V4; family <= FW3_FAMILY_V6; family++) {