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 f41153c..a86f636 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,
 
 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;
 {
        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)
                                {
                        {
                                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
                                        valid = false;
                                }
                                else
@@ -1025,7 +1027,8 @@ fw3_parse_blob_options(void *s, const struct fw3_option *opts,
 
                                                if (!opt->parse(dest, v, true))
                                                {
 
                                                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;
                                                }
                                                        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))
                                        {
                                {
                                        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;
                                        }
                                }
                                                valid = false;
                                        }
                                }
@@ -1060,7 +1064,8 @@ fw3_parse_blob_options(void *s, const struct fw3_option *opts,
                                        {
                                                if (!opt->parse(dest, p, true))
                                                {
                                        {
                                                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;
                                                }
                                                        valid = false;
                                                        continue;
                                                }
@@ -1072,8 +1077,8 @@ fw3_parse_blob_options(void *s, const struct fw3_option *opts,
                        break;
                }
 
                        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;
        }
 
        return valid;
index 8489b8b..a2bacce 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,
 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);
 
 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 (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;
 
        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);
                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;
 
                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 (!(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;
                }
                        fw3_free_rule(rule);
                        continue;
                }
diff --git a/snats.c b/snats.c
index 7dae2ee..0f7d851 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;
 
        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);
                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;
 
                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 (!(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;
                }
                        fw3_free_snat(snat);
                        continue;
                }