ubus: print rule name when reporting errors
authorJo-Philipp Wich <jow@openwrt.org>
Fri, 17 Apr 2015 14:12:14 +0000 (16:12 +0200)
committerJo-Philipp Wich <jow@openwrt.org>
Sat, 18 Apr 2015 12:08:41 +0000 (14:08 +0200)
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
options.c
options.h
rules.c
snats.c

index f41153c693f35e509a3c531e2a7afa437ae67ddf..a86f636c0a40409491ed2759a8cdc00208409c63 100644 (file)
--- 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;
index 8489b8bc24d9ea6ca40a7701523c01f087708ace..a2baccec8fc6309d71c0610ee356dad3b7c7fbb9 100644 (file)
--- 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 f45de6eb6e864f7d881ec95c19bbe36bbde18580..a5f3fa9328f02eeb76188ba6ddf42c0505269503 100644 (file)
--- 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 7dae2eef0774871d47d0e8f2e6baa946aa743af0..0f7d851bc8e3153512d1a9bc9cbfda4c3918af11 100644 (file)
--- 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;
                }