Store location object in handle to improve error reporting.

Signed-off-by: Pablo Neira Ayuso <pa...@netfilter.org>
---
 include/rule.h     |  7 ++++++-
 src/evaluate.c     |  4 ++--
 src/netlink.c      |  8 ++++----
 src/parser_bison.y |  6 ++++--
 src/rule.c         | 18 +++++++++---------
 5 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/include/rule.h b/include/rule.h
index 68d32f10c353..b265690d3c96 100644
--- a/include/rule.h
+++ b/include/rule.h
@@ -42,6 +42,11 @@ struct set_spec {
        const char              *name;
 };
 
+struct obj_spec {
+       struct location         location;
+       const char              *name;
+};
+
 /**
  * struct handle - handle for tables, chains, rules and sets
  *
@@ -60,7 +65,7 @@ struct handle {
        struct table_spec       table;
        struct chain_spec       chain;
        struct set_spec         set;
-       const char              *obj;
+       struct obj_spec         obj;
        const char              *flowtable;
        struct handle_spec      handle;
        struct position_spec    position;
diff --git a/src/evaluate.c b/src/evaluate.c
index 79fa3221e20d..fdc536479785 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -3112,9 +3112,9 @@ static int cmd_evaluate_list_obj(struct eval_ctx *ctx, 
const struct cmd *cmd,
        if (table == NULL)
                return cmd_error(ctx, "Could not process rule: Table '%s' does 
not exist",
                                 cmd->handle.table.name);
-       if (obj_lookup(table, cmd->handle.obj, obj_type) == NULL)
+       if (obj_lookup(table, cmd->handle.obj.name, obj_type) == NULL)
                return cmd_error(ctx, "Could not process rule: Object '%s' does 
not exist",
-                                        cmd->handle.obj);
+                                        cmd->handle.obj.name);
        return 0;
 }
 
diff --git a/src/netlink.c b/src/netlink.c
index e465daa79c84..864947b4d2f0 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -293,8 +293,8 @@ __alloc_nftnl_obj(const struct handle *h, uint32_t type)
 
        nftnl_obj_set_u32(nlo, NFTNL_OBJ_FAMILY, h->family);
        nftnl_obj_set_str(nlo, NFTNL_OBJ_TABLE, h->table.name);
-       if (h->obj != NULL)
-               nftnl_obj_set_str(nlo, NFTNL_OBJ_NAME, h->obj);
+       if (h->obj.name != NULL)
+               nftnl_obj_set_str(nlo, NFTNL_OBJ_NAME, h->obj.name);
 
        nftnl_obj_set_u32(nlo, NFTNL_OBJ_TYPE, type);
        if (h->handle.id)
@@ -1410,7 +1410,7 @@ struct obj *netlink_delinearize_obj(struct netlink_ctx 
*ctx,
        obj->handle.family = nftnl_obj_get_u32(nlo, NFTNL_OBJ_FAMILY);
        obj->handle.table.name =
                xstrdup(nftnl_obj_get_str(nlo, NFTNL_OBJ_TABLE));
-       obj->handle.obj =
+       obj->handle.obj.name =
                xstrdup(nftnl_obj_get_str(nlo, NFTNL_OBJ_NAME));
        obj->handle.handle.id =
                nftnl_obj_get_u64(nlo, NFTNL_OBJ_HANDLE);
@@ -1564,7 +1564,7 @@ int netlink_reset_objs(struct netlink_ctx *ctx, const 
struct cmd *cmd,
        int err;
 
        obj_cache = mnl_nft_obj_dump(ctx, h->family,
-                                    h->table.name, h->obj, type, dump, true);
+                                    h->table.name, h->obj.name, type, dump, 
true);
        if (obj_cache == NULL)
                return -1;
 
diff --git a/src/parser_bison.y b/src/parser_bison.y
index e4b83523b411..5b3860368bc5 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -1925,7 +1925,8 @@ flowtable_identifier      :       identifier
 obj_spec               :       table_spec      identifier
                        {
                                $$              = $1;
-                               $$.obj          = $2;
+                               $$.obj.name     = $2;
+                               $$.obj.location = @2;
                        }
                        ;
 
@@ -1940,7 +1941,8 @@ objid_spec                :       table_spec      HANDLE 
NUM
 obj_identifier         :       identifier
                        {
                                memset(&$$, 0, sizeof($$));
-                               $$.obj          = $1;
+                               $$.obj.name             = $1;
+                               $$.obj.location         = @1;
                        }
                        ;
 
diff --git a/src/rule.c b/src/rule.c
index 7d18bd08c1fb..2f0123b7a4a5 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -48,8 +48,8 @@ void handle_merge(struct handle *dst, const struct handle 
*src)
                dst->set.name = xstrdup(src->set.name);
        if (dst->flowtable == NULL && src->flowtable != NULL)
                dst->flowtable = xstrdup(src->flowtable);
-       if (dst->obj == NULL && src->obj != NULL)
-               dst->obj = xstrdup(src->obj);
+       if (dst->obj.name == NULL && src->obj.name != NULL)
+               dst->obj.name = xstrdup(src->obj.name);
        if (dst->handle.id == 0)
                dst->handle = src->handle;
        if (dst->position.id == 0)
@@ -1377,7 +1377,7 @@ struct obj *obj_lookup(const struct table *table, const 
char *name,
        struct obj *obj;
 
        list_for_each_entry(obj, &table->objs, list) {
-               if (!strcmp(obj->handle.obj, name) &&
+               if (!strcmp(obj->handle.obj.name, name) &&
                    obj->type == type)
                        return obj;
        }
@@ -1400,7 +1400,7 @@ static void obj_print_data(const struct obj *obj,
 {
        switch (obj->type) {
        case NFT_OBJECT_COUNTER:
-               nft_print(octx, " %s {", obj->handle.obj);
+               nft_print(octx, " %s {", obj->handle.obj.name);
                if (octx->handle > 0)
                        nft_print(octx, " # handle %" PRIu64, 
obj->handle.handle.id);
                nft_print(octx, "%s%s%s", opts->nl, opts->tab, opts->tab);
@@ -1415,7 +1415,7 @@ static void obj_print_data(const struct obj *obj,
                const char *data_unit;
                uint64_t bytes;
 
-               nft_print(octx, " %s {", obj->handle.obj);
+               nft_print(octx, " %s {", obj->handle.obj.name);
                if (octx->handle > 0)
                        nft_print(octx, " # handle %" PRIu64, 
obj->handle.handle.id);
                nft_print(octx, "%s%s%s", opts->nl, opts->tab, opts->tab);
@@ -1431,7 +1431,7 @@ static void obj_print_data(const struct obj *obj,
                }
                break;
        case NFT_OBJECT_CT_HELPER:
-               nft_print(octx, "ct helper %s {", obj->handle.obj);
+               nft_print(octx, "ct helper %s {", obj->handle.obj.name);
                if (octx->handle > 0)
                        nft_print(octx, " # handle %" PRIu64, 
obj->handle.handle.id);
                nft_print(octx, "%s", opts->nl);
@@ -1446,7 +1446,7 @@ static void obj_print_data(const struct obj *obj,
                const char *data_unit;
                uint64_t rate;
 
-               nft_print(octx, " %s {", obj->handle.obj);
+               nft_print(octx, " %s {", obj->handle.obj.name);
                if (octx->handle > 0)
                        nft_print(octx, " # handle %" PRIu64, 
obj->handle.handle.id);
                nft_print(octx, "%s%s%s", opts->nl, opts->tab, opts->tab);
@@ -1577,8 +1577,8 @@ static int do_list_obj(struct netlink_ctx *ctx, struct 
cmd *cmd, uint32_t type)
 
                list_for_each_entry(obj, &table->objs, list) {
                        if (obj->type != type ||
-                           (cmd->handle.obj != NULL &&
-                            strcmp(cmd->handle.obj, obj->handle.obj)))
+                           (cmd->handle.obj.name != NULL &&
+                            strcmp(cmd->handle.obj.name, 
obj->handle.obj.name)))
                                continue;
 
                        obj_print_declaration(obj, &opts, ctx->octx);
-- 
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to