]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: add obj_spec
authorPablo Neira Ayuso <pablo@netfilter.org>
Thu, 3 May 2018 10:49:39 +0000 (12:49 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Sun, 6 May 2018 20:48:30 +0000 (22:48 +0200)
Store location object in handle to improve error reporting.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/rule.h
src/evaluate.c
src/netlink.c
src/parser_bison.y
src/rule.c

index 68d32f10c353857c18e994b47c45af25214a0e34..b265690d3c964ed97f8efe860eaab34d752a735e 100644 (file)
@@ -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;
index f52ee7a60302f67443b4125e09f065cd4c9ba379..82b1c3b3d4db8ecee08b392c21c90bbcf405df8b 100644 (file)
@@ -3113,9 +3113,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;
 }
 
index e465daa79c841878f1e4a1601b2f8809e64992dc..864947b4d2f07ac8cce35de9f8ebc56fd10da902 100644 (file)
@@ -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;
 
index 28aa6cc1905137c991e682da8e32eddadcde705b..eed60008c70c01aeabc2bcd2be3f95921bf7bf15 100644 (file)
@@ -1924,7 +1924,8 @@ flowtable_identifier      :       identifier
 obj_spec               :       table_spec      identifier
                        {
                                $$              = $1;
-                               $$.obj          = $2;
+                               $$.obj.name     = $2;
+                               $$.obj.location = @2;
                        }
                        ;
 
@@ -1939,7 +1940,8 @@ objid_spec                :       table_spec      HANDLE NUM
 obj_identifier         :       identifier
                        {
                                memset(&$$, 0, sizeof($$));
-                               $$.obj          = $1;
+                               $$.obj.name             = $1;
+                               $$.obj.location         = @1;
                        }
                        ;
 
index 7d18bd08c1fb3439693ea372747357cfa7a4f75b..2f0123b7a4a58c0546be062746c5ad44ee39ce5f 100644 (file)
@@ -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);