X-Git-Url: http://git.archive.openwrt.org/?p=project%2Ffirewall3.git;a=blobdiff_plain;f=ipsets.c;h=b73c3d28c64d99d7769f44ca9ad0da6a19241111;hp=30c6463ff05a73e73fb9a99b2812f738577f7f86;hb=35b3e74a184b709b8ddfaaa094919a656a6ec059;hpb=5cd4af49acce3c8cdc26003be45a562f82121f09 diff --git a/ipsets.c b/ipsets.c index 30c6463..b73c3d2 100644 --- a/ipsets.c +++ b/ipsets.c @@ -38,6 +38,9 @@ const struct fw3_option fw3_ipset_opts[] = { FW3_OPT("external", string, ipset, external), + FW3_LIST("entry", setentry, ipset, entries), + FW3_OPT("loadfile", string, ipset, loadfile), + { } }; @@ -247,6 +250,7 @@ fw3_alloc_ipset(struct fw3_state *state) return NULL; INIT_LIST_HEAD(&ipset->datatypes); + INIT_LIST_HEAD(&ipset->entries); ipset->enabled = true; ipset->family = FW3_FAMILY_V4; @@ -319,10 +323,34 @@ fw3_load_ipsets(struct fw3_state *state, struct uci_package *p, static void +load_file(struct fw3_ipset *ipset) +{ + FILE *f; + char line[128]; + + if (!ipset->loadfile) + return; + + info(" * Loading file %s", ipset->loadfile); + + f = fopen(ipset->loadfile, "r"); + + if (!f) { + info(" ! Skipping due to open error: %s", strerror(errno)); + return; + } + + while (fgets(line, sizeof(line), f)) + fw3_pr("add %s %s", ipset->name, line); + + fclose(f); +} + +static void create_ipset(struct fw3_ipset *ipset, struct fw3_state *state) { bool first = true; - + struct fw3_setentry *entry; struct fw3_ipset_datatype *type; info(" * Creating ipset %s", ipset->name); @@ -362,6 +390,11 @@ create_ipset(struct fw3_ipset *ipset, struct fw3_state *state) fw3_pr(" hashsize %u", ipset->hashsize); fw3_pr("\n"); + + list_for_each_entry(entry, &ipset->entries, list) + fw3_pr("add %s %s\n", ipset->name, entry->value); + + load_file(ipset); } void