]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: store parser location for handle and position specifiers
authorPablo Neira Ayuso <pablo@netfilter.org>
Wed, 30 Mar 2016 11:25:10 +0000 (13:25 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 30 Mar 2016 11:29:08 +0000 (13:29 +0200)
Store the parser location structure for handle and position IDs so we
can use this information from the evaluation step, to provide better
error reporting.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Acked-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
include/rule.h
src/netlink.c
src/netlink_delinearize.c
src/parser_bison.y
src/rule.c

index c848f0fc94410103faf32ae88e5d93c55028d43c..cfe33a734454ed5f1682c2c694063ceb77b0ddc8 100644 (file)
@@ -5,6 +5,28 @@
 #include <nftables.h>
 #include <list.h>
 
+/**
+ * struct handle_spec - handle ID
+ *
+ * @location:  location this handle was defined at
+ * @id:                handle ID value
+ */
+struct handle_spec {
+       struct location         location;
+       uint64_t                id;
+};
+
+/**
+ * struct position_spec - position ID
+ *
+ * @location:  location this position was defined at
+ * @id:                position ID value
+ */
+struct position_spec {
+       struct location         location;
+       uint64_t                id;
+};
+
 /**
  * struct handle - handle for tables, chains, rules and sets
  *
@@ -21,8 +43,8 @@ struct handle {
        const char              *table;
        const char              *chain;
        const char              *set;
-       uint64_t                handle;
-       uint64_t                position;
+       struct handle_spec      handle;
+       struct position_spec    position;
        uint32_t                set_id;
 };
 
index ba0c20a0487f149d0d0675c3e3e3046d9d7b4a0b..e3ba2ed36da403ff41e4c72774f25f20d154f5c2 100644 (file)
@@ -143,8 +143,8 @@ struct nftnl_chain *alloc_nftnl_chain(const struct handle *h)
 
        nftnl_chain_set_u32(nlc, NFTNL_CHAIN_FAMILY, h->family);
        nftnl_chain_set_str(nlc, NFTNL_CHAIN_TABLE, h->table);
-       if (h->handle != 0)
-               nftnl_chain_set_u64(nlc, NFTNL_CHAIN_HANDLE, h->handle);
+       if (h->handle.id != 0)
+               nftnl_chain_set_u64(nlc, NFTNL_CHAIN_HANDLE, h->handle.id);
        if (h->chain != NULL)
                nftnl_chain_set_str(nlc, NFTNL_CHAIN_NAME, h->chain);
 
@@ -163,10 +163,10 @@ struct nftnl_rule *alloc_nftnl_rule(const struct handle *h)
        nftnl_rule_set_str(nlr, NFTNL_RULE_TABLE, h->table);
        if (h->chain != NULL)
                nftnl_rule_set_str(nlr, NFTNL_RULE_CHAIN, h->chain);
-       if (h->handle)
-               nftnl_rule_set_u64(nlr, NFTNL_RULE_HANDLE, h->handle);
-       if (h->position)
-               nftnl_rule_set_u64(nlr, NFTNL_RULE_POSITION, h->position);
+       if (h->handle.id)
+               nftnl_rule_set_u64(nlr, NFTNL_RULE_HANDLE, h->handle.id);
+       if (h->position.id)
+               nftnl_rule_set_u64(nlr, NFTNL_RULE_POSITION, h->position.id);
 
        return nlr;
 }
@@ -700,7 +700,7 @@ static struct chain *netlink_delinearize_chain(struct netlink_ctx *ctx,
                nftnl_chain_get_u32(nlc, NFTNL_CHAIN_FAMILY);
        chain->handle.table  =
                xstrdup(nftnl_chain_get_str(nlc, NFTNL_CHAIN_TABLE));
-       chain->handle.handle =
+       chain->handle.handle.id =
                nftnl_chain_get_u64(nlc, NFTNL_CHAIN_HANDLE);
 
        if (nftnl_chain_is_set(nlc, NFTNL_CHAIN_HOOKNUM) &&
index d431588f8b4f7566a255db8243fe627b030db20c..848acd6668929c1c439732b5ab8975832ed7e77c 100644 (file)
@@ -1759,10 +1759,10 @@ struct rule *netlink_delinearize_rule(struct netlink_ctx *ctx,
        h.family = nftnl_rule_get_u32(nlr, NFTNL_RULE_FAMILY);
        h.table  = xstrdup(nftnl_rule_get_str(nlr, NFTNL_RULE_TABLE));
        h.chain  = xstrdup(nftnl_rule_get_str(nlr, NFTNL_RULE_CHAIN));
-       h.handle = nftnl_rule_get_u64(nlr, NFTNL_RULE_HANDLE);
+       h.handle.id = nftnl_rule_get_u64(nlr, NFTNL_RULE_HANDLE);
 
        if (nftnl_rule_is_set(nlr, NFTNL_RULE_POSITION))
-               h.position = nftnl_rule_get_u64(nlr, NFTNL_RULE_POSITION);
+               h.position.id = nftnl_rule_get_u64(nlr, NFTNL_RULE_POSITION);
 
        pctx->rule = rule_alloc(&netlink_location, &h);
        pctx->table = table_lookup(&h);
index 9e86f2650450555e2574ad7e1edcb26183ae2533..4b7c1f5ab115bb32e7b1a68654c8495b61b41c80 100644 (file)
@@ -133,6 +133,8 @@ static void location_update(struct location *loc, struct location *rhs, int n)
        struct expr             *expr;
        struct set              *set;
        const struct datatype   *datatype;
+       struct handle_spec      handle_spec;
+       struct position_spec    position_spec;
 }
 
 %token TOKEN_EOF 0             "end of file"
@@ -423,7 +425,10 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 %destructor { handle_free(&$$); } table_spec chain_spec chain_identifier ruleid_spec ruleset_spec
 %type <handle>                 set_spec set_identifier
 %destructor { handle_free(&$$); } set_spec set_identifier
-%type <val>                    handle_spec family_spec family_spec_explicit position_spec chain_policy prio_spec
+%type <val>                    family_spec family_spec_explicit chain_policy prio_spec
+
+%type <handle_spec>            handle_spec
+%type <position_spec>          position_spec
 
 %type <string>                 dev_spec
 %destructor { xfree($$); }     dev_spec
@@ -1218,21 +1223,25 @@ set_identifier          :       identifier
 
 handle_spec            :       /* empty */
                        {
-                               $$ = 0;
+                               memset(&$$, 0, sizeof($$));
                        }
                        |       HANDLE          NUM
                        {
-                               $$ = $2;
+                               memset(&$$, 0, sizeof($$));
+                               $$.location     = @$;
+                               $$.id           = $2;
                        }
                        ;
 
 position_spec          :       /* empty */
                        {
-                               $$ = 0;
+                               memset(&$$, 0, sizeof($$));
                        }
                        |       POSITION        NUM
                        {
-                               $$ = $2;
+                               memset(&$$, 0, sizeof($$));
+                               $$.location     = @$;
+                               $$.id           = $2;
                        }
                        ;
 
index 0ed77941e11d3425167352d5c278e9c4b441b570..b7f4a07fe132e7f145f0801f30bce2f440a3ba18 100644 (file)
@@ -44,9 +44,9 @@ void handle_merge(struct handle *dst, const struct handle *src)
                dst->chain = xstrdup(src->chain);
        if (dst->set == NULL && src->set != NULL)
                dst->set = xstrdup(src->set);
-       if (dst->handle == 0)
+       if (dst->handle.id == 0)
                dst->handle = src->handle;
-       if (dst->position == 0)
+       if (dst->position.id == 0)
                dst->position = src->position;
 }
 
@@ -393,7 +393,7 @@ void rule_print(const struct rule *rule)
                printf(" comment \"%s\"", rule->comment);
 
        if (handle_output > 0)
-               printf(" # handle %" PRIu64, rule->handle.handle);
+               printf(" # handle %" PRIu64, rule->handle.handle.id);
 }
 
 struct scope *scope_init(struct scope *scope, const struct scope *parent)