}
-bool
-fw3_has_state(void)
-{
- struct stat s;
- return !stat(FW3_STATEFILE, &s);
-}
-
struct list_head *
-fw3_read_state(void)
+fw3_read_statefile(void)
{
FILE *sf;
struct list_head *state;
struct fw3_statefile_entry *entry;
+ sf = fopen(FW3_STATEFILE, "r");
+
+ if (!sf)
+ return NULL;
+
state = malloc(sizeof(*state));
if (!state)
INIT_LIST_HEAD(state);
- sf = fopen(FW3_STATEFILE, "r");
-
- if (!sf)
- {
- warn("Cannot open state %s: %s", FW3_STATEFILE, strerror(errno));
- free(state);
-
- return NULL;
- }
-
while (fgets(line, sizeof(line), sf))
{
entry = malloc(sizeof(*entry));
}
void
-fw3_free_state(struct list_head *statefile)
-{
- fw3_free_list(statefile);
- free(statefile);
-}
-
-void
-fw3_write_state(void *state)
+fw3_write_statefile(void *state)
{
FILE *sf;
struct fw3_state *s = state;
struct fw3_zone *z;
struct fw3_ipset *i;
+ int mask = (1 << FW3_FAMILY_V4) | (1 << FW3_FAMILY_V6);
+
+ if (!(d->flags & mask))
+ {
+ if (unlink(FW3_STATEFILE))
+ warn("Unable to remove state %s: %s",
+ FW3_STATEFILE, strerror(errno));
+
+ return;
+ }
+
sf = fopen(FW3_STATEFILE, "w");
if (!sf)
return;
}
- fprintf(sf, "%u - %u\n", FW3_TYPE_DEFAULTS, d->has_flag);
+ fprintf(sf, "%u - %u\n", FW3_TYPE_DEFAULTS, d->flags);
list_for_each_entry(z, &s->zones, list)
{
fprintf(sf, "%u %s %u %u\n", FW3_TYPE_ZONE,
- z->name, z->has_src_target, z->has_dest_target);
+ z->name, z->src_flags, z->dst_flags);
}
list_for_each_entry(i, &s->ipsets, list)
if (i->external && *i->external)
continue;
- fprintf(sf, "%u %s\n", FW3_TYPE_IPSET, i->name);
+ fprintf(sf, "%u %s %u\n", FW3_TYPE_IPSET, i->name, i->flags);
}
fclose(sf);
}
void
-fw3_remove_state(void)
+fw3_free_statefile(struct list_head *statefile)
{
- if (unlink(FW3_STATEFILE))
- warn("Unable to remove state %s: %s", FW3_STATEFILE, strerror(errno));
+ struct fw3_statefile_entry *e, *tmp;
+
+ if (!statefile)
+ return;
+
+ list_for_each_entry_safe(e, tmp, statefile, list)
+ {
+ list_del(&e->list);
+ free(e->name);
+ free(e);
+ }
+
+ free(statefile);
}