summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2015-04-17 16:12:14 +0200
committerJo-Philipp Wich <jow@openwrt.org>2015-04-18 14:08:41 +0200
commit1d0bd45db042c9dd916f15a5f4e3e5a2f63d0616 (patch)
tree0a02f33f3104a287f54d16d7ee8ecdffd4d9f490
parentdba19a8f14cefdede3cc7d0f8322fdb9a2c44d50 (diff)
downloadfirewall3-1d0bd45db042c9dd916f15a5f4e3e5a2f63d0616.tar.gz
ubus: print rule name when reporting errors
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
-rw-r--r--options.c19
-rw-r--r--options.h2
-rw-r--r--rules.c7
-rw-r--r--snats.c7
4 files changed, 23 insertions, 12 deletions
diff --git a/options.c b/options.c
index f41153c..a86f636 100644
--- a/options.c
+++ b/options.c
@@ -981,7 +981,7 @@ fw3_parse_options(void *s, const struct fw3_option *opts,
bool
fw3_parse_blob_options(void *s, const struct fw3_option *opts,
- struct blob_attr *a)
+ struct blob_attr *a, const char *name)
{
char *p, *v, buf[16];
bool known;
@@ -1007,7 +1007,9 @@ fw3_parse_blob_options(void *s, const struct fw3_option *opts,
{
if (!opt->elem_size)
{
- fprintf(stderr, "%s must not be a list\n", opt->name);
+ fprintf(stderr, "%s: '%s' must not be a list\n",
+ name, opt->name);
+
valid = false;
}
else
@@ -1025,7 +1027,8 @@ fw3_parse_blob_options(void *s, const struct fw3_option *opts,
if (!opt->parse(dest, v, true))
{
- fprintf(stderr, "%s has invalid value '%s'\n", opt->name, v);
+ fprintf(stderr, "%s: '%s' has invalid value '%s'\n",
+ name, opt->name, v);
valid = false;
continue;
}
@@ -1048,7 +1051,8 @@ fw3_parse_blob_options(void *s, const struct fw3_option *opts,
{
if (!opt->parse((char *)s + opt->offset, v, false))
{
- fprintf(stderr, "%s has invalid value '%s'\n", opt->name, v);
+ fprintf(stderr, "%s: '%s' has invalid value '%s'\n",
+ name, opt->name, v);
valid = false;
}
}
@@ -1060,7 +1064,8 @@ fw3_parse_blob_options(void *s, const struct fw3_option *opts,
{
if (!opt->parse(dest, p, true))
{
- fprintf(stderr, "%s has invalid value '%s'\n", opt->name, p);
+ fprintf(stderr, "%s: '%s' has invalid value '%s'\n",
+ name, opt->name, p);
valid = false;
continue;
}
@@ -1072,8 +1077,8 @@ fw3_parse_blob_options(void *s, const struct fw3_option *opts,
break;
}
- if (!known)
- fprintf(stderr, "%s is unknown\n", blobmsg_name(o));
+ if (!known && strcmp(blobmsg_name(o), "type"))
+ fprintf(stderr, "%s: '%s' is unknown\n", name, blobmsg_name(o));
}
return valid;
diff --git a/options.h b/options.h
index 8489b8b..a2bacce 100644
--- a/options.h
+++ b/options.h
@@ -561,7 +561,7 @@ bool fw3_parse_direction(void *ptr, const char *val, bool is_list);
bool fw3_parse_options(void *s, const struct fw3_option *opts,
struct uci_section *section);
bool fw3_parse_blob_options(void *s, const struct fw3_option *opts,
- struct blob_attr *a);
+ struct blob_attr *a, const char *name);
const char * fw3_address_to_string(struct fw3_address *address,
bool allow_invert, bool as_cidr);
diff --git a/rules.c b/rules.c
index f45de6e..a5f3fa9 100644
--- a/rules.c
+++ b/rules.c
@@ -110,9 +110,12 @@ fw3_load_rules(struct fw3_state *state, struct uci_package *p,
blob_for_each_attr(entry, a, rem) {
const char *type = NULL;
+ const char *name = "ubus rule";
blobmsg_for_each_attr(opt, entry, orem)
if (!strcmp(blobmsg_name(opt), "type"))
type = blobmsg_get_string(opt);
+ else if (!strcmp(blobmsg_name(opt), "name"))
+ name = blobmsg_get_string(opt);
if (!type || strcmp(type, "rule"))
continue;
@@ -120,9 +123,9 @@ fw3_load_rules(struct fw3_state *state, struct uci_package *p,
if (!(rule = alloc_rule(state)))
continue;
- if (!fw3_parse_blob_options(rule, fw3_rule_opts, entry))
+ if (!fw3_parse_blob_options(rule, fw3_rule_opts, entry, name))
{
- fprintf(stderr, "ubus section skipped due to invalid options\n");
+ fprintf(stderr, "%s skipped due to invalid options\n", name);
fw3_free_rule(rule);
continue;
}
diff --git a/snats.c b/snats.c
index 7dae2ee..0f7d851 100644
--- a/snats.c
+++ b/snats.c
@@ -133,9 +133,12 @@ fw3_load_snats(struct fw3_state *state, struct uci_package *p, struct blob_attr
blob_for_each_attr(rule, a, rem) {
const char *type = NULL;
+ const char *name = "ubus rule";
blobmsg_for_each_attr(opt, rule, orem)
if (!strcmp(blobmsg_name(opt), "type"))
type = blobmsg_get_string(opt);
+ else if (!strcmp(blobmsg_name(opt), "name"))
+ name = blobmsg_get_string(opt);
if (!type || strcmp(type, "nat"))
continue;
@@ -143,9 +146,9 @@ fw3_load_snats(struct fw3_state *state, struct uci_package *p, struct blob_attr
if (!(snat = alloc_snat(state)))
continue;
- if (!fw3_parse_blob_options(snat, fw3_snat_opts, rule))
+ if (!fw3_parse_blob_options(snat, fw3_snat_opts, rule, name))
{
- fprintf(stderr, "ubus section skipped due to invalid options\n");
+ fprintf(stderr, "%s skipped due to invalid options\n", name);
fw3_free_snat(snat);
continue;
}