FW3_OPT("external", string, ipset, external),
+ FW3_LIST("entry", setentry, ipset, entries),
+ FW3_OPT("loadfile", string, ipset, loadfile),
+
{ }
};
return NULL;
INIT_LIST_HEAD(&ipset->datatypes);
+ INIT_LIST_HEAD(&ipset->entries);
ipset->enabled = true;
ipset->family = FW3_FAMILY_V4;
}
+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);
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
return false;
}
+bool
+fw3_parse_setentry(void *ptr, const char *val, bool is_list)
+{
+ struct fw3_setentry e = { };
+
+ e.value = val;
+ put_value(ptr, &e, sizeof(e), is_list);
+
+ return true;
+}
+
bool
fw3_parse_options(void *s, const struct fw3_option *opts,
const char *external;
+ struct list_head entries;
+ const char *loadfile;
+
uint32_t flags[2];
};
struct fw3_port port;
};
+struct fw3_setentry
+{
+ struct list_head list;
+ const char *value;
+};
+
struct fw3_state
{
struct uci_context *uci;
bool fw3_parse_setmatch(void *ptr, const char *val, bool is_list);
bool fw3_parse_direction(void *ptr, const char *val, bool is_list);
bool fw3_parse_cthelper(void *ptr, const char *val, bool is_list);
+bool fw3_parse_setentry(void *ptr, const char *val, bool is_list);
bool fw3_parse_options(void *s, const struct fw3_option *opts,
struct uci_section *section);