+struct list_head *
+fw3_read_state(void)
+{
+ FILE *sf;
+
+ int n;
+ char line[128];
+ const char *p;
+
+ struct list_head *state;
+ struct fw3_statefile_entry *entry;
+
+ state = malloc(sizeof(*state));
+
+ if (!state)
+ return NULL;
+
+ 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));
+
+ if (!entry)
+ continue;
+
+ memset(entry, 0, sizeof(*entry));
+
+ p = strtok(line, " \t\n");
+
+ if (!p)
+ continue;
+
+ entry->type = strtoul(p, NULL, 10);
+
+ p = strtok(NULL, " \t\n");
+
+ if (!p)
+ continue;
+
+ entry->name = strdup(p);
+
+ for (n = 0, p = strtok(NULL, " \t\n");
+ n < ARRAY_SIZE(entry->flags) && p != NULL;
+ n++, p = strtok(NULL, " \t\n"))
+ {
+ entry->flags[n] = strtoul(p, NULL, 10);
+ }
+
+ list_add_tail(&entry->list, state);
+ }
+
+ fclose(sf);
+
+ return state;
+}
+
+void
+fw3_free_state(struct list_head *statefile)
+{
+ fw3_free_list(statefile);
+ free(statefile);
+}
+
+void
+fw3_write_state(void *state)