/*
* firewall3 - 3rd OpenWrt UCI firewall implementation
*
- * Copyright (C) 2013 Jo-Philipp Wich <jow@openwrt.org>
+ * Copyright (C) 2013-2014 Jo-Philipp Wich <jow@openwrt.org>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
"MARK",
"DNAT",
"SNAT",
+ "MASQUERADE",
"ACCEPT",
"REJECT",
bool
fw3_parse_int(void *ptr, const char *val, bool is_list)
{
- int n = strtol(val, NULL, 0);
+ char *e;
+ int n = strtol(val, &e, 0);
- if (errno == ERANGE || errno == EINVAL)
+ if (e == val || *e)
return false;
*((int *)ptr) = n;
fw3_parse_target(void *ptr, const char *val, bool is_list)
{
return parse_enum(ptr, val, &fw3_flag_names[FW3_FLAG_ACCEPT],
- FW3_FLAG_ACCEPT, FW3_FLAG_SNAT);
+ FW3_FLAG_ACCEPT, FW3_FLAG_MASQUERADE);
}
bool
{
struct fw3_protocol proto = { };
struct protoent *ent;
+ char *e;
if (*val == '!')
{
return true;
}
- proto.protocol = strtoul(val, NULL, 10);
+ proto.protocol = strtoul(val, &e, 10);
- if (errno == ERANGE || errno == EINVAL)
+ if ((e == val) || (*e != 0))
return false;
put_value(ptr, &proto, sizeof(proto), is_list);
}
-void
+bool
fw3_parse_options(void *s, const struct fw3_option *opts,
struct uci_section *section)
{
struct uci_option *o;
const struct fw3_option *opt;
struct list_head *dest;
+ bool valid = true;
uci_foreach_element(§ion->options, e)
{
if (!opt->elem_size)
{
warn_elem(e, "must not be a list");
+ valid = false;
}
else
{
if (!opt->parse(dest, l->name, true))
{
warn_elem(e, "has invalid value '%s'", l->name);
+ valid = false;
continue;
}
}
if (!opt->elem_size)
{
if (!opt->parse((char *)s + opt->offset, o->v.string, false))
+ {
warn_elem(e, "has invalid value '%s'", o->v.string);
+ valid = false;
+ }
}
else
{
if (!opt->parse(dest, p, true))
{
warn_elem(e, "has invalid value '%s'", p);
+ valid = false;
continue;
}
}
if (!known)
warn_elem(e, "is unknown");
}
+
+ return valid;
}