projects
/
project
/
firewall3.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Only run includes and set sysctls if either v4 or v6 firewall was actually started
[project/firewall3.git]
/
utils.c
diff --git
a/utils.c
b/utils.c
index
f01ba73
..
2747a85
100644
(file)
--- a/
utils.c
+++ b/
utils.c
@@
-27,6
+27,9
@@
static int lock_fd = -1;
static pid_t pipe_pid = -1;
static FILE *pipe_fd = NULL;
static pid_t pipe_pid = -1;
static FILE *pipe_fd = NULL;
+bool fw3_pr_debug = false;
+
+
static void
warn_elem_section_name(struct uci_section *s, bool find_name)
{
static void
warn_elem_section_name(struct uci_section *s, bool find_name)
{
@@
-250,10
+253,18
@@
__fw3_command_pipe(bool silent, const char *command, ...)
void
fw3_pr(const char *fmt, ...)
{
void
fw3_pr(const char *fmt, ...)
{
- va_list args;
- va_start(args, fmt);
- vfprintf(pipe_fd, fmt, args);
- va_end(args);
+ va_list args;
+
+ if (fw3_pr_debug && pipe_fd != stdout)
+ {
+ va_start(args, fmt);
+ vfprintf(stderr, fmt, args);
+ va_end(args);
+ }
+
+ va_start(args, fmt);
+ vfprintf(pipe_fd, fmt, args);
+ va_end(args);
}
void
}
void
@@
-341,11
+352,11
@@
fw3_read_statefile(void *state)
{
FILE *sf;
{
FILE *sf;
- int
n,
type;
+ int type;
char line[128];
const char *p, *name;
char line[128];
const char *p, *name;
- uint
16_t flags[2]
;
+ uint
32_t flags
;
struct fw3_state *s = state;
struct fw3_zone *zone;
struct fw3_state *s = state;
struct fw3_zone *zone;
@@
-363,23
+374,23
@@
fw3_read_statefile(void *state)
if (!p)
continue;
if (!p)
continue;
- type = strtoul(p, NULL, 1
0
);
+ type = strtoul(p, NULL, 1
6
);
name = strtok(NULL, " \t\n");
if (!name)
continue;
name = strtok(NULL, " \t\n");
if (!name)
continue;
-
for (n = 0,
p = strtok(NULL, " \t\n");
- n < ARRAY_SIZE(flags) && p != NULL;
-
n++, p = strtok(NULL, " \t\n")
)
- {
- flags[n] = strtoul(p, NULL, 10);
- }
+ p = strtok(NULL, " \t\n");
+
+
if (!p
)
+ continue;
+
+ flags = strtoul(p, NULL, 16);
switch (type)
{
case FW3_TYPE_DEFAULTS:
switch (type)
{
case FW3_TYPE_DEFAULTS:
- s->
running_defaults.flags = flags[0]
;
+ s->
defaults.running_flags = flags
;
break;
case FW3_TYPE_ZONE:
break;
case FW3_TYPE_ZONE:
@@
-394,8
+405,7
@@
fw3_read_statefile(void *state)
list_add_tail(&zone->list, &s->zones);
}
list_add_tail(&zone->list, &s->zones);
}
- zone->src_flags = flags[0];
- zone->dst_flags = flags[1];
+ zone->running_flags = flags;
list_add_tail(&zone->running_list, &s->running_zones);
break;
list_add_tail(&zone->running_list, &s->running_zones);
break;
@@
-411,7
+421,7
@@
fw3_read_statefile(void *state)
list_add_tail(&ipset->list, &s->ipsets);
}
list_add_tail(&ipset->list, &s->ipsets);
}
- ipset->
flags = flags[0]
;
+ ipset->
running_flags = flags
;
list_add_tail(&ipset->running_list, &s->running_ipsets);
break;
}
list_add_tail(&ipset->running_list, &s->running_ipsets);
break;
}
@@
-431,9
+441,7
@@
fw3_write_statefile(void *state)
struct fw3_zone *z;
struct fw3_ipset *i;
struct fw3_zone *z;
struct fw3_ipset *i;
- int mask = (1 << FW3_FAMILY_V4) | (1 << FW3_FAMILY_V6);
-
- if (!(d->flags & mask))
+ if (fw3_no_family(d))
{
if (unlink(FW3_STATEFILE))
warn("Unable to remove state %s: %s",
{
if (unlink(FW3_STATEFILE))
warn("Unable to remove state %s: %s",
@@
-450,17
+458,16
@@
fw3_write_statefile(void *state)
return;
}
return;
}
- fprintf(sf, "%
u - %u
\n", FW3_TYPE_DEFAULTS, d->flags);
+ fprintf(sf, "%
x - %x
\n", FW3_TYPE_DEFAULTS, d->flags);
list_for_each_entry(z, &s->running_zones, running_list)
{
list_for_each_entry(z, &s->running_zones, running_list)
{
- fprintf(sf, "%u %s %u %u\n", FW3_TYPE_ZONE,
- z->name, z->src_flags, z->dst_flags);
+ fprintf(sf, "%x %s %x\n", FW3_TYPE_ZONE, z->name, z->flags);
}
list_for_each_entry(i, &s->running_ipsets, running_list)
{
}
list_for_each_entry(i, &s->running_ipsets, running_list)
{
- fprintf(sf, "%
u %s %u
\n", FW3_TYPE_IPSET, i->name, i->flags);
+ fprintf(sf, "%
x %s %x
\n", FW3_TYPE_IPSET, i->name, i->flags);
}
fclose(sf);
}
fclose(sf);
@@
-488,10
+495,20
@@
void
fw3_free_object(void *obj, const void *opts)
{
const struct fw3_option *ol;
fw3_free_object(void *obj, const void *opts)
{
const struct fw3_option *ol;
+ struct list_head *list, *cur, *tmp;
for (ol = opts; ol->name; ol++)
for (ol = opts; ol->name; ol++)
- if (ol->elem_size)
- fw3_free_list((struct list_head *)((char *)obj + ol->offset));
+ {
+ if (!ol->elem_size)
+ continue;
+
+ list = (struct list_head *)((char *)obj + ol->offset);
+ list_for_each_safe(cur, tmp, list)
+ {
+ list_del(cur);
+ free(cur);
+ }
+ }
free(obj);
}
free(obj);
}