]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
cmd/netlink: make sure we always have a location in netlink operations
authorPatrick McHardy <kaber@trash.net>
Thu, 18 Apr 2013 15:53:59 +0000 (17:53 +0200)
committerPatrick McHardy <kaber@trash.net>
Thu, 18 Apr 2013 15:53:59 +0000 (17:53 +0200)
Improve error reporting by always using a location in netlink operations.

Signed-off-by: Patrick McHardy<kaber@trash.net>
include/netlink.h
include/rule.h
src/evaluate.c
src/netlink.c
src/parser.y
src/rule.c

index 3252569bf970fd08d2325d12e86a239cb3a61e81..ccbb872c8542aa4a8c7ed17fd47a90135faf4112 100644 (file)
@@ -52,38 +52,55 @@ extern struct rule *netlink_delinearize_rule(struct netlink_ctx *ctx,
 
 extern int netlink_add_rule(struct netlink_ctx *ctx, const struct handle *h,
                            const struct rule *rule, uint32_t flags);
-extern int netlink_delete_rule(struct netlink_ctx *ctx, const struct handle *h);
-extern int netlink_get_rule(struct netlink_ctx *ctx, const struct handle *h);
+extern int netlink_delete_rule(struct netlink_ctx *ctx, const struct handle *h,
+                              const struct location *loc);
+extern int netlink_get_rule(struct netlink_ctx *ctx, const struct handle *h,
+                           const struct location *loc);
 
 extern int netlink_add_chain(struct netlink_ctx *ctx, const struct handle *h,
+                            const struct location *loc,
                             const struct chain *chain);
 extern int netlink_rename_chain(struct netlink_ctx *ctx, const struct handle *h,
-                               const char *name);
-extern int netlink_delete_chain(struct netlink_ctx *ctx, const struct handle *h);
-extern int netlink_list_chains(struct netlink_ctx *ctx, const struct handle *h);
-extern int netlink_get_chain(struct netlink_ctx *ctx, const struct handle *h);
-extern int netlink_list_chain(struct netlink_ctx *ctx, const struct handle *h);
-extern int netlink_flush_chain(struct netlink_ctx *ctx, const struct handle *h);
+                               const struct location *loc, const char *name);
+extern int netlink_delete_chain(struct netlink_ctx *ctx, const struct handle *h,
+                               const struct location *loc);
+extern int netlink_list_chains(struct netlink_ctx *ctx, const struct handle *h,
+                              const struct location *loc);
+extern int netlink_get_chain(struct netlink_ctx *ctx, const struct handle *h,
+                            const struct location *loc);
+extern int netlink_list_chain(struct netlink_ctx *ctx, const struct handle *h,
+                             const struct location *loc);
+extern int netlink_flush_chain(struct netlink_ctx *ctx, const struct handle *h,
+                              const struct location *loc);
 
 extern int netlink_add_table(struct netlink_ctx *ctx, const struct handle *h,
+                            const struct location *loc,
                             const struct table *table);
-extern int netlink_delete_table(struct netlink_ctx *ctx, const struct handle *h);
-extern int netlink_list_tables(struct netlink_ctx *ctx, const struct handle *h);
-extern int netlink_get_table(struct netlink_ctx *ctx, const struct handle *h);
-extern int netlink_list_table(struct netlink_ctx *ctx, const struct handle *h);
-extern int netlink_flush_table(struct netlink_ctx *ctx, const struct handle *h);
+extern int netlink_delete_table(struct netlink_ctx *ctx, const struct handle *h,
+                               const struct location *loc);
+extern int netlink_list_tables(struct netlink_ctx *ctx, const struct handle *h,
+                              const struct location *loc);
+extern int netlink_get_table(struct netlink_ctx *ctx, const struct handle *h,
+                            const struct location *loc);
+extern int netlink_list_table(struct netlink_ctx *ctx, const struct handle *h,
+                             const struct location *loc);
+extern int netlink_flush_table(struct netlink_ctx *ctx, const struct handle *h,
+                              const struct location *loc);
 
 extern int netlink_add_set(struct netlink_ctx *ctx, const struct handle *h,
                           struct set *set);
-extern int netlink_delete_set(struct netlink_ctx *ctx, const struct handle *h);
-extern int netlink_list_sets(struct netlink_ctx *ctx, const struct handle *h);
-extern int netlink_get_set(struct netlink_ctx *ctx, const struct handle *h);
+extern int netlink_delete_set(struct netlink_ctx *ctx, const struct handle *h,
+                             const struct location *loc);
+extern int netlink_list_sets(struct netlink_ctx *ctx, const struct handle *h,
+                            const struct location *loc);
+extern int netlink_get_set(struct netlink_ctx *ctx, const struct handle *h,
+                          const struct location *loc);
 
 extern int netlink_add_setelems(struct netlink_ctx *ctx, const struct handle *h,
                                const struct expr *expr);
 extern int netlink_delete_setelems(struct netlink_ctx *ctx, const struct handle *h,
                                   const struct expr *expr);
 extern int netlink_get_setelems(struct netlink_ctx *ctx, const struct handle *h,
-                               struct set *set);
+                               const struct location *loc, struct set *set);
 
 #endif /* NFTABLES_NETLINK_H */
index a992489b0e999cdbc693b58311e7bc68b9a400e4..eda6b2c20ee092f76dba70200e8d0e74b69b3d31 100644 (file)
@@ -62,12 +62,14 @@ extern struct symbol *symbol_lookup(const struct scope *scope,
  *
  * @list:      list node
  * @handle:    table handle
+ * @location:  location the table was defined at
  * @chains:    chains contained in the table
  * @sets:      sets contained in the table
  */
 struct table {
        struct list_head        list;
        struct handle           handle;
+       struct location         location;
        struct scope            scope;
        struct list_head        chains;
        struct list_head        sets;
@@ -92,6 +94,7 @@ enum chain_flags {
  *
  * @list:      list node in table list
  * @handle:    chain handle
+ * @location:  location the chain was defined at
  * @flags:     chain flags
  * @hooknum:   hook number (base chains)
  * @priority:  hook priority (base chains)
@@ -100,6 +103,7 @@ enum chain_flags {
 struct chain {
        struct list_head        list;
        struct handle           handle;
+       struct location         location;
        uint32_t                flags;
        unsigned int            hooknum;
        unsigned int            priority;
@@ -253,7 +257,8 @@ struct cmd {
 };
 
 extern struct cmd *cmd_alloc(enum cmd_ops op, enum cmd_obj obj,
-                            const struct handle *h, void *data);
+                            const struct handle *h, const struct location *loc,
+                            void *data);
 extern void cmd_free(struct cmd *cmd);
 
 #include <payload.h>
index 6adf663df82225e38fcbadaa6a935db7ab10ff6d..bf169321fc96d855023f1f2084991fbd8e2a4d58 100644 (file)
@@ -91,7 +91,7 @@ static struct expr *implicit_set_declaration(struct eval_ctx *ctx,
                handle_merge(&set->handle, &ctx->cmd->handle);
                memset(&h, 0, sizeof(h));
                handle_merge(&h, &set->handle);
-               cmd = cmd_alloc(CMD_ADD, CMD_OBJ_SET, &h, set);
+               cmd = cmd_alloc(CMD_ADD, CMD_OBJ_SET, &h, &expr->location, set);
                cmd->location = set->location;
                list_add_tail(&cmd->list, &ctx->cmd->list);
        }
@@ -122,7 +122,7 @@ static struct set *get_set(struct eval_ctx *ctx, const struct handle *h,
        memset(&handle, 0, sizeof(handle));
        handle_merge(&handle, h);
        handle.set = xstrdup(identifier);
-       err = netlink_get_set(&nctx, &handle);
+       err = netlink_get_set(&nctx, &handle, &internal_location);
        handle_free(&handle);
 
        if (err < 0)
index 5b99c2e1fb4b6d5e2d0b88347ae06cfb492c1c86..da290d58b8fd4ff7f9ba8fb9d25387eac4fbfb26 100644 (file)
@@ -311,7 +311,8 @@ int netlink_add_rule(struct netlink_ctx *ctx, const struct handle *h,
        return err;
 }
 
-int netlink_delete_rule(struct netlink_ctx *ctx, const struct handle *h)
+int netlink_delete_rule(struct netlink_ctx *ctx, const struct handle *h,
+                       const struct location *loc)
 {
        struct nfnl_nft_rule *nlr;
        int err;
@@ -321,7 +322,7 @@ int netlink_delete_rule(struct netlink_ctx *ctx, const struct handle *h)
        nfnl_nft_rule_put(nlr);
 
        if (err < 0)
-               netlink_io_error(ctx, NULL, "Could not delete rule: %s",
+               netlink_io_error(ctx, loc, "Could not delete rule: %s",
                                 nl_geterror(err));
        return err;
 }
@@ -345,7 +346,8 @@ static void list_rule_cb(struct nl_object *obj, void *arg)
        list_add_tail(&rule->list, &ctx->list);
 }
 
-static int netlink_list_rules(struct netlink_ctx *ctx, const struct handle *h)
+static int netlink_list_rules(struct netlink_ctx *ctx, const struct handle *h,
+                             const struct location *loc)
 {
        struct nl_cache *rule_cache;
        struct nfnl_nft_rule *nlr;
@@ -353,7 +355,7 @@ static int netlink_list_rules(struct netlink_ctx *ctx, const struct handle *h)
 
        err = nfnl_nft_rule_alloc_cache(nf_sock, &rule_cache);
        if (err < 0)
-               return netlink_io_error(ctx, NULL,
+               return netlink_io_error(ctx, loc,
                                        "Could not receive rules from kernel: %s",
                                        nl_geterror(err));
 
@@ -369,7 +371,8 @@ static int netlink_get_rule_cb(struct nl_msg *msg, void *arg)
        return nl_msg_parse(msg, list_rule_cb, arg);
 }
 
-int netlink_get_rule(struct netlink_ctx *ctx, const struct handle *h)
+int netlink_get_rule(struct netlink_ctx *ctx, const struct handle *h,
+                    const struct location *loc)
 {
        struct nfnl_nft_rule *nlr;
        int err;
@@ -382,7 +385,7 @@ int netlink_get_rule(struct netlink_ctx *ctx, const struct handle *h)
        nfnl_nft_rule_put(nlr);
 
        if (err < 0)
-               return netlink_io_error(ctx, NULL,
+               return netlink_io_error(ctx, loc,
                                        "Could not receive rule from kernel: %s",
                                        nl_geterror(err));
        return err;
@@ -400,7 +403,8 @@ static void flush_rule_cb(struct nl_object *obj, void *arg)
                                 nl_geterror(err));
 }
 
-static int netlink_flush_rules(struct netlink_ctx *ctx, const struct handle *h)
+static int netlink_flush_rules(struct netlink_ctx *ctx, const struct handle *h,
+                              const struct location *loc)
 {
        struct nl_cache *rule_cache;
        struct nfnl_nft_rule *nlr;
@@ -408,7 +412,7 @@ static int netlink_flush_rules(struct netlink_ctx *ctx, const struct handle *h)
 
        err = nfnl_nft_rule_alloc_cache(nf_sock, &rule_cache);
        if (err < 0)
-               return netlink_io_error(ctx, NULL,
+               return netlink_io_error(ctx, loc,
                                        "Could not receive rules from kernel: %s",
                                        nl_geterror(err));
 
@@ -420,7 +424,7 @@ static int netlink_flush_rules(struct netlink_ctx *ctx, const struct handle *h)
 }
 
 int netlink_add_chain(struct netlink_ctx *ctx, const struct handle *h,
-                     const struct chain *chain)
+                     const struct location *loc, const struct chain *chain)
 {
        struct nfnl_nft_chain *nlc;
        int err;
@@ -435,13 +439,13 @@ int netlink_add_chain(struct netlink_ctx *ctx, const struct handle *h,
        nfnl_nft_chain_put(nlc);
 
        if (err < 0)
-               netlink_io_error(ctx, NULL, "Could not add chain: %s",
+               netlink_io_error(ctx, loc, "Could not add chain: %s",
                                 nl_geterror(err));
        return err;
 }
 
 int netlink_rename_chain(struct netlink_ctx *ctx, const struct handle *h,
-                        const char *name)
+                        const struct location *loc, const char *name)
 {
        struct nfnl_nft_chain *nlc;
        int err;
@@ -453,12 +457,13 @@ int netlink_rename_chain(struct netlink_ctx *ctx, const struct handle *h,
        nfnl_nft_chain_put(nlc);
 
        if (err < 0)
-               netlink_io_error(ctx, NULL, "Could not rename chain: %s",
+               netlink_io_error(ctx, loc, "Could not rename chain: %s",
                                 nl_geterror(err));
        return err;
 }
 
-int netlink_delete_chain(struct netlink_ctx *ctx, const struct handle *h)
+int netlink_delete_chain(struct netlink_ctx *ctx, const struct handle *h,
+                        const struct location *loc)
 {
        struct nfnl_nft_chain *nlc;
        int err;
@@ -469,7 +474,7 @@ int netlink_delete_chain(struct netlink_ctx *ctx, const struct handle *h)
        nfnl_nft_chain_put(nlc);
 
        if (err < 0)
-               netlink_io_error(ctx, NULL, "Could not delete chain: %s",
+               netlink_io_error(ctx, loc, "Could not delete chain: %s",
                                 nl_geterror(err));
        return err;
 }
@@ -497,7 +502,8 @@ static void list_chain_cb(struct nl_object *obj, void *arg)
        list_add_tail(&chain->list, &ctx->list);
 }
 
-int netlink_list_chains(struct netlink_ctx *ctx, const struct handle *h)
+int netlink_list_chains(struct netlink_ctx *ctx, const struct handle *h,
+                       const struct location *loc)
 {
        struct nl_cache *chain_cache;
        struct nfnl_nft_chain *nlc;
@@ -506,7 +512,7 @@ int netlink_list_chains(struct netlink_ctx *ctx, const struct handle *h)
 
        err = nfnl_nft_chain_alloc_cache(nf_sock, &chain_cache);
        if (err < 0)
-               return netlink_io_error(ctx, NULL,
+               return netlink_io_error(ctx, loc,
                                        "Could not receive chains from kernel: %s",
                                        nl_geterror(err));
 
@@ -536,7 +542,8 @@ static int netlink_get_chain_cb(struct nl_msg *msg, void *arg)
        return nl_msg_parse(msg, list_chain_cb, arg);
 }
 
-int netlink_get_chain(struct netlink_ctx *ctx, const struct handle *h)
+int netlink_get_chain(struct netlink_ctx *ctx, const struct handle *h,
+                     const struct location *loc)
 {
        struct nfnl_nft_chain *nlc;
        int err;
@@ -550,24 +557,26 @@ int netlink_get_chain(struct netlink_ctx *ctx, const struct handle *h)
        nfnl_nft_chain_put(nlc);
 
        if (err < 0)
-               return netlink_io_error(ctx, NULL,
+               return netlink_io_error(ctx, loc,
                                        "Could not receive chain from kernel: %s",
                                        nl_geterror(err));
        return err;
 }
 
-int netlink_list_chain(struct netlink_ctx *ctx, const struct handle *h)
+int netlink_list_chain(struct netlink_ctx *ctx, const struct handle *h,
+                      const struct location *loc)
 {
-       return netlink_list_rules(ctx, h);
+       return netlink_list_rules(ctx, h, loc);
 }
 
-int netlink_flush_chain(struct netlink_ctx *ctx, const struct handle *h)
+int netlink_flush_chain(struct netlink_ctx *ctx, const struct handle *h,
+                       const struct location *loc)
 {
-       return netlink_flush_rules(ctx, h);
+       return netlink_flush_rules(ctx, h, loc);
 }
 
 int netlink_add_table(struct netlink_ctx *ctx, const struct handle *h,
-                     const struct table *table)
+                     const struct location *loc, const struct table *table)
 {
        struct nfnl_nft_table *nlt;
        int err;
@@ -577,12 +586,13 @@ int netlink_add_table(struct netlink_ctx *ctx, const struct handle *h,
        nfnl_nft_table_put(nlt);
 
        if (err < 0)
-               netlink_io_error(ctx, NULL, "Could not add table: %s",
+               netlink_io_error(ctx, loc, "Could not add table: %s",
                                 nl_geterror(err));
        return err;
 }
 
-int netlink_delete_table(struct netlink_ctx *ctx, const struct handle *h)
+int netlink_delete_table(struct netlink_ctx *ctx, const struct handle *h,
+                        const struct location *loc)
 {
        struct nfnl_nft_table *nlt;
        int err;
@@ -592,7 +602,7 @@ int netlink_delete_table(struct netlink_ctx *ctx, const struct handle *h)
        nfnl_nft_table_put(nlt);
 
        if (err < 0)
-               netlink_io_error(ctx, NULL, "Could not delete table: %s",
+               netlink_io_error(ctx, loc, "Could not delete table: %s",
                                 nl_geterror(err));
        return err;
 }
@@ -616,7 +626,8 @@ static void list_table_cb(struct nl_object *obj, void *arg)
        list_add_tail(&table->list, &ctx->list);
 }
 
-int netlink_list_tables(struct netlink_ctx *ctx, const struct handle *h)
+int netlink_list_tables(struct netlink_ctx *ctx, const struct handle *h,
+                       const struct location *loc)
 {
        struct nl_cache *table_cache;
        struct nfnl_nft_table *nlt;
@@ -624,7 +635,7 @@ int netlink_list_tables(struct netlink_ctx *ctx, const struct handle *h)
 
        err = nfnl_nft_table_alloc_cache(nf_sock, &table_cache);
        if (err < 0)
-               return netlink_io_error(ctx, NULL,
+               return netlink_io_error(ctx, loc,
                                        "Could not receive tables from kernel: %s",
                                        nl_geterror(err));
 
@@ -640,7 +651,8 @@ static int netlink_get_table_cb(struct nl_msg *msg, void *arg)
        return nl_msg_parse(msg, list_table_cb, arg);
 }
 
-int netlink_get_table(struct netlink_ctx *ctx, const struct handle *h)
+int netlink_get_table(struct netlink_ctx *ctx, const struct handle *h,
+                     const struct location *loc)
 {
        struct nfnl_nft_table *nlt;
        int err;
@@ -653,21 +665,23 @@ int netlink_get_table(struct netlink_ctx *ctx, const struct handle *h)
        nfnl_nft_table_put(nlt);
 
        if (err < 0)
-               return netlink_io_error(ctx, NULL,
+               return netlink_io_error(ctx, loc,
                                        "Could not receive table from kernel: %s",
                                        nl_geterror(err));
        return err;
 }
 
 
-int netlink_list_table(struct netlink_ctx *ctx, const struct handle *h)
+int netlink_list_table(struct netlink_ctx *ctx, const struct handle *h,
+                      const struct location *loc)
 {
-       return netlink_list_rules(ctx, h);
+       return netlink_list_rules(ctx, h, loc);
 }
 
-int netlink_flush_table(struct netlink_ctx *ctx, const struct handle *h)
+int netlink_flush_table(struct netlink_ctx *ctx, const struct handle *h,
+                       const struct location *loc)
 {
-       return netlink_flush_rules(ctx, h);
+       return netlink_flush_rules(ctx, h, loc);
 }
 
 static enum nft_data_types dtype_map_to_kernel(const struct datatype *dtype)
@@ -736,7 +750,8 @@ int netlink_add_set(struct netlink_ctx *ctx, const struct handle *h,
        return err;
 }
 
-int netlink_delete_set(struct netlink_ctx *ctx, const struct handle *h)
+int netlink_delete_set(struct netlink_ctx *ctx, const struct handle *h,
+                      const struct location *loc)
 {
        struct nfnl_nft_set *nls;
        int err;
@@ -746,7 +761,7 @@ int netlink_delete_set(struct netlink_ctx *ctx, const struct handle *h)
        nfnl_nft_set_put(nls);
 
        if (err < 0)
-               netlink_io_error(ctx, NULL, "Could not delete set: %s",
+               netlink_io_error(ctx, loc, "Could not delete set: %s",
                                 nl_geterror(err));
        return err;
 }
@@ -799,14 +814,15 @@ static void list_set_cb(struct nl_object *obj, void *arg)
        list_add_tail(&set->list, &ctx->list);
 }
 
-int netlink_list_sets(struct netlink_ctx *ctx, const struct handle *h)
+int netlink_list_sets(struct netlink_ctx *ctx, const struct handle *h,
+                     const struct location *loc)
 {
        struct nl_cache *set_cache;
        int err;
 
        err = nfnl_nft_set_alloc_cache(nf_sock, h->family, h->table, &set_cache);
        if (err < 0)
-               return netlink_io_error(ctx, NULL,
+               return netlink_io_error(ctx, loc,
                                        "Could not receive sets from kernel: %s",
                                        nl_geterror(err));
 
@@ -820,7 +836,8 @@ static int netlink_get_set_cb(struct nl_msg *msg, void *arg)
        return nl_msg_parse(msg, list_set_cb, arg);
 }
 
-int netlink_get_set(struct netlink_ctx *ctx, const struct handle *h)
+int netlink_get_set(struct netlink_ctx *ctx, const struct handle *h,
+                   const struct location *loc)
 {
        struct nfnl_nft_set *nls;
        int err;
@@ -836,7 +853,7 @@ int netlink_get_set(struct netlink_ctx *ctx, const struct handle *h)
        nfnl_nft_set_put(nls);
 
        if (err < 0)
-               return netlink_io_error(ctx, NULL,
+               return netlink_io_error(ctx, loc,
                                        "Could not receive set from kernel: %s",
                                        nl_geterror(err));
        return err;
@@ -881,7 +898,8 @@ int netlink_add_setelems(struct netlink_ctx *ctx, const struct handle *h,
 out:
        nfnl_nft_set_put(nls);
        if (err < 0)
-               netlink_io_error(ctx, NULL, "Could not add set elements: %s",
+               netlink_io_error(ctx, &expr->location,
+                                "Could not add set elements: %s",
                                 nl_geterror(err));
        return err;
 }
@@ -904,7 +922,8 @@ int netlink_delete_setelems(struct netlink_ctx *ctx, const struct handle *h,
 out:
        nfnl_nft_set_put(nls);
        if (err < 0)
-               netlink_io_error(ctx, NULL, "Could not delete set elements: %s",
+               netlink_io_error(ctx, &expr->location,
+                                "Could not delete set elements: %s",
                                 nl_geterror(err));
        return err;
 }
@@ -952,7 +971,7 @@ static void list_setelem_cb(struct nl_object *obj, void *arg)
 extern void interval_map_decompose(struct expr *set);
 
 int netlink_get_setelems(struct netlink_ctx *ctx, const struct handle *h,
-                        struct set *set)
+                        const struct location *loc, struct set *set)
 {
        struct nl_cache *elements;
        struct nfnl_nft_set *nls;
@@ -969,7 +988,7 @@ int netlink_get_setelems(struct netlink_ctx *ctx, const struct handle *h,
                goto out;
 
        ctx->set = set;
-       set->init = set_expr_alloc(&internal_location);
+       set->init = set_expr_alloc(loc);
        nl_cache_foreach(elements, list_setelem_cb, ctx);
        nl_cache_free(elements);
        ctx->set = NULL;
@@ -979,7 +998,7 @@ int netlink_get_setelems(struct netlink_ctx *ctx, const struct handle *h,
 out:
        nfnl_nft_set_put(nls);
        if (err < 0)
-               netlink_io_error(ctx, NULL, "Could not receive set elements: %s",
+               netlink_io_error(ctx, loc, "Could not receive set elements: %s",
                                 nl_geterror(err));
        return err;
 }
index 87602d9f97a4b757c3e7ecc83a053f4355621937..166cbcc551820675ab6dda6dcde8dacf90a84192 100644 (file)
@@ -526,121 +526,121 @@ base_cmd                :       /* empty */     add_cmd         { $$ = $1; }
 
 add_cmd                        :       TABLE           table_spec
                        {
-                               $$ = cmd_alloc(CMD_ADD, CMD_OBJ_TABLE, &$2, NULL);
+                               $$ = cmd_alloc(CMD_ADD, CMD_OBJ_TABLE, &$2, &@$, NULL);
                        }
                        |       TABLE           table_spec      table_block_alloc
                                                '{'     table_block     '}'
                        {
                                handle_merge(&$3->handle, &$2);
                                close_scope(state);
-                               $$ = cmd_alloc(CMD_ADD, CMD_OBJ_TABLE, &$2, $5);
+                               $$ = cmd_alloc(CMD_ADD, CMD_OBJ_TABLE, &$2, &@$, $5);
                        }
                        |       CHAIN           chain_spec
                        {
-                               $$ = cmd_alloc(CMD_ADD, CMD_OBJ_CHAIN, &$2, NULL);
+                               $$ = cmd_alloc(CMD_ADD, CMD_OBJ_CHAIN, &$2, &@$, NULL);
                        }
                        |       CHAIN           chain_spec      chain_block_alloc
                                                '{'     chain_block     '}'
                        {
                                handle_merge(&$3->handle, &$2);
                                close_scope(state);
-                               $$ = cmd_alloc(CMD_ADD, CMD_OBJ_CHAIN, &$2, $5);
+                               $$ = cmd_alloc(CMD_ADD, CMD_OBJ_CHAIN, &$2, &@$, $5);
                        }
                        |       RULE            ruleid_spec     rule
                        {
-                               $$ = cmd_alloc(CMD_ADD, CMD_OBJ_RULE, &$2, $3);
+                               $$ = cmd_alloc(CMD_ADD, CMD_OBJ_RULE, &$2, &@$, $3);
                        }
                        |       /* empty */     ruleid_spec     rule
                        {
-                               $$ = cmd_alloc(CMD_ADD, CMD_OBJ_RULE, &$1, $2);
+                               $$ = cmd_alloc(CMD_ADD, CMD_OBJ_RULE, &$1, &@$, $2);
                        }
                        |       SET             set_spec        set_block_alloc
                                                '{'     set_block       '}'
                        {
                                $5->location = @5;
                                handle_merge(&$3->handle, &$2);
-                               $$ = cmd_alloc(CMD_ADD, CMD_OBJ_SET, &$2, $5);
+                               $$ = cmd_alloc(CMD_ADD, CMD_OBJ_SET, &$2, &@$, $5);
                        }
                        |       MAP             set_spec        map_block_alloc
                                                '{'     map_block       '}'
                        {
                                $5->location = @5;
                                handle_merge(&$3->handle, &$2);
-                               $$ = cmd_alloc(CMD_ADD, CMD_OBJ_SET, &$2, $5);
+                               $$ = cmd_alloc(CMD_ADD, CMD_OBJ_SET, &$2, &@$, $5);
                        }
                        |       ELEMENT         set_spec        set_expr
                        {
-                               $$ = cmd_alloc(CMD_ADD, CMD_OBJ_SETELEM, &$2, $3);
+                               $$ = cmd_alloc(CMD_ADD, CMD_OBJ_SETELEM, &$2, &@$, $3);
                        }
                        ;
 
 insert_cmd             :       RULE            ruleid_spec     rule
                        {
-                               $$ = cmd_alloc(CMD_INSERT, CMD_OBJ_RULE, &$2, $3);
+                               $$ = cmd_alloc(CMD_INSERT, CMD_OBJ_RULE, &$2, &@$, $3);
                        }
                        ;
 
 delete_cmd             :       TABLE           table_spec
                        {
-                               $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_TABLE, &$2, NULL);
+                               $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_TABLE, &$2, &@$, NULL);
                        }
                        |       CHAIN           chain_spec
                        {
-                               $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_CHAIN, &$2, NULL);
+                               $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_CHAIN, &$2, &@$, NULL);
                        }
                        |       RULE            ruleid_spec
                        {
-                               $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_RULE, &$2, NULL);
+                               $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_RULE, &$2, &@$, NULL);
                        }
                        |       SET             set_spec
                        {
-                               $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_SET, &$2, NULL);
+                               $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_SET, &$2, &@$, NULL);
                        }
                        |       ELEMENT         set_spec        set_expr
                        {
-                               $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_SETELEM, &$2, $3);
+                               $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_SETELEM, &$2, &@$, $3);
                        }
                        ;
 
 list_cmd               :       TABLE           table_spec
                        {
-                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_TABLE, &$2, NULL);
+                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_TABLE, &$2, &@$, NULL);
                        }
                        |       TABLES          tables_spec
                        {
-                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_TABLE, &$2, NULL);
+                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_TABLE, &$2, &@$, NULL);
                        }
                        |       CHAIN           chain_spec
                        {
-                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_CHAIN, &$2, NULL);
+                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_CHAIN, &$2, &@$, NULL);
                        }
                        |       SETS            table_spec
                        {
-                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SETS, &$2, NULL);
+                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SETS, &$2, &@$, NULL);
                        }
                        |       SET             set_spec
                        {
-                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SET, &$2, NULL);
+                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SET, &$2, &@$, NULL);
                        }
                        ;
 
 flush_cmd              :       TABLE           table_spec
                        {
-                               $$ = cmd_alloc(CMD_FLUSH, CMD_OBJ_TABLE, &$2, NULL);
+                               $$ = cmd_alloc(CMD_FLUSH, CMD_OBJ_TABLE, &$2, &@$, NULL);
                        }
                        |       CHAIN           chain_spec
                        {
-                               $$ = cmd_alloc(CMD_FLUSH, CMD_OBJ_CHAIN, &$2, NULL);
+                               $$ = cmd_alloc(CMD_FLUSH, CMD_OBJ_CHAIN, &$2, &@$, NULL);
                        }
                        |       SET             set_spec
                        {
-                               $$ = cmd_alloc(CMD_FLUSH, CMD_OBJ_SET, &$2, NULL);
+                               $$ = cmd_alloc(CMD_FLUSH, CMD_OBJ_SET, &$2, &@$, NULL);
                        }
                        ;
 
 rename_cmd             :       CHAIN           chain_spec      identifier
                        {
-                               $$ = cmd_alloc(CMD_RENAME, CMD_OBJ_CHAIN, &$2, NULL);
+                               $$ = cmd_alloc(CMD_RENAME, CMD_OBJ_CHAIN, &$2, &@$, NULL);
                                $$->arg = $3;
                        }
                        ;
index 67ff58425ede73c0412b70bf2b7bfe7e5bf88bee..89c3607c3b910ab07d4e736438810684a063d5ba 100644 (file)
@@ -296,15 +296,17 @@ static void table_print(const struct table *table)
 }
 
 struct cmd *cmd_alloc(enum cmd_ops op, enum cmd_obj obj,
-                     const struct handle *h, void *data)
+                     const struct handle *h, const struct location *loc,
+                     void *data)
 {
        struct cmd *cmd;
 
        cmd = xzalloc(sizeof(*cmd));
-       cmd->op     = op;
-       cmd->obj    = obj;
-       cmd->handle = *h;
-       cmd->data   = data;
+       cmd->op       = op;
+       cmd->obj      = obj;
+       cmd->handle   = *h;
+       cmd->location = *loc;
+       cmd->data     = data;
        return cmd;
 }
 
@@ -339,11 +341,11 @@ void cmd_free(struct cmd *cmd)
 #include <netlink.h>
 
 static int do_add_chain(struct netlink_ctx *ctx, const struct handle *h,
-                       struct chain *chain)
+                       const struct location *loc, struct chain *chain)
 {
        struct rule *rule;
 
-       if (netlink_add_chain(ctx, h, chain) < 0)
+       if (netlink_add_chain(ctx, h, loc, chain) < 0)
                return -1;
        if (chain != NULL) {
                list_for_each_entry(rule, &chain->rules, list) {
@@ -378,12 +380,12 @@ static int do_add_set(struct netlink_ctx *ctx, const struct handle *h,
 }
 
 static int do_add_table(struct netlink_ctx *ctx, const struct handle *h,
-                       struct table *table)
+                       const struct location *loc, struct table *table)
 {
        struct chain *chain;
        struct set *set;
 
-       if (netlink_add_table(ctx, h, table) < 0)
+       if (netlink_add_table(ctx, h, loc, table) < 0)
                return -1;
        if (table != NULL) {
                list_for_each_entry(set, &table->sets, list) {
@@ -392,7 +394,8 @@ static int do_add_table(struct netlink_ctx *ctx, const struct handle *h,
                                return -1;
                }
                list_for_each_entry(chain, &table->chains, list) {
-                       if (do_add_chain(ctx, &chain->handle, chain) < 0)
+                       if (do_add_chain(ctx, &chain->handle, &chain->location,
+                                        chain) < 0)
                                return -1;
                }
        }
@@ -403,9 +406,11 @@ static int do_command_add(struct netlink_ctx *ctx, struct cmd *cmd)
 {
        switch (cmd->obj) {
        case CMD_OBJ_TABLE:
-               return do_add_table(ctx, &cmd->handle, cmd->table);
+               return do_add_table(ctx, &cmd->handle, &cmd->location,
+                                   cmd->table);
        case CMD_OBJ_CHAIN:
-               return do_add_chain(ctx, &cmd->handle, cmd->chain);
+               return do_add_chain(ctx, &cmd->handle, &cmd->location,
+                                   cmd->chain);
        case CMD_OBJ_RULE:
                return netlink_add_rule(ctx, &cmd->handle, cmd->rule,
                                        NLM_F_APPEND);
@@ -434,13 +439,13 @@ static int do_command_delete(struct netlink_ctx *ctx, struct cmd *cmd)
 {
        switch (cmd->obj) {
        case CMD_OBJ_TABLE:
-               return netlink_delete_table(ctx, &cmd->handle);
+               return netlink_delete_table(ctx, &cmd->handle, &cmd->location);
        case CMD_OBJ_CHAIN:
-               return netlink_delete_chain(ctx, &cmd->handle);
+               return netlink_delete_chain(ctx, &cmd->handle, &cmd->location);
        case CMD_OBJ_RULE:
-               return netlink_delete_rule(ctx, &cmd->handle);
+               return netlink_delete_rule(ctx, &cmd->handle, &cmd->location);
        case CMD_OBJ_SET:
-               return netlink_delete_set(ctx, &cmd->handle);
+               return netlink_delete_set(ctx, &cmd->handle, &cmd->location);
        case CMD_OBJ_SETELEM:
                return netlink_delete_setelems(ctx, &cmd->handle, cmd->expr);
        default:
@@ -448,16 +453,17 @@ static int do_command_delete(struct netlink_ctx *ctx, struct cmd *cmd)
        }
 }
 
-static int do_list_sets(struct netlink_ctx *ctx, struct table *table)
+static int do_list_sets(struct netlink_ctx *ctx, const struct location *loc,
+                       struct table *table)
 {
        struct set *set, *nset;
 
-       if (netlink_list_sets(ctx, &table->handle) < 0)
+       if (netlink_list_sets(ctx, &table->handle, loc) < 0)
                return -1;
 
        list_for_each_entry_safe(set, nset, &ctx->list, list) {
                if (set->flags & SET_F_ANONYMOUS &&
-                   netlink_get_setelems(ctx, &set->handle, set) < 0)
+                   netlink_get_setelems(ctx, &set->handle, loc, set) < 0)
                        return -1;
                list_move_tail(&set->list, &table->sets);
        }
@@ -481,7 +487,8 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
                        /* List all existing tables */
                        struct table *table;
 
-                       if (netlink_list_tables(ctx, &cmd->handle) < 0)
+                       if (netlink_list_tables(ctx, &cmd->handle,
+                                               &cmd->location) < 0)
                                return -1;
 
                        list_for_each_entry(table, &ctx->list, list) {
@@ -490,34 +497,35 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
                        return 0;
                }
                /* List content of this table */
-               if (do_list_sets(ctx, table) < 0)
+               if (do_list_sets(ctx, &cmd->location, table) < 0)
                        return -1;
-               if (netlink_list_chains(ctx, &cmd->handle) < 0)
+               if (netlink_list_chains(ctx, &cmd->handle, &cmd->location) < 0)
                        return -1;
                list_splice_tail_init(&ctx->list, &table->chains);
-               if (netlink_list_table(ctx, &cmd->handle) < 0)
+               if (netlink_list_table(ctx, &cmd->handle, &cmd->location) < 0)
                        return -1;
                break;
        case CMD_OBJ_CHAIN:
-               if (do_list_sets(ctx, table) < 0)
+               if (do_list_sets(ctx, &cmd->location, table) < 0)
                        return -1;
-               if (netlink_list_chains(ctx, &cmd->handle) < 0)
+               if (netlink_list_chains(ctx, &cmd->handle, &cmd->location) < 0)
                        return -1;
                list_splice_tail_init(&ctx->list, &table->chains);
-               if (netlink_list_table(ctx, &cmd->handle) < 0)
+               if (netlink_list_table(ctx, &cmd->handle, &cmd->location) < 0)
                        return -1;
                break;
        case CMD_OBJ_SETS:
-               if (netlink_list_sets(ctx, &cmd->handle) < 0)
+               if (netlink_list_sets(ctx, &cmd->handle, &cmd->location) < 0)
                        return -1;
                list_for_each_entry_safe(set, nset, &ctx->list, list)
                        list_move_tail(&set->list, &table->sets);
                break;
        case CMD_OBJ_SET:
-               if (netlink_get_set(ctx, &cmd->handle) < 0)
+               if (netlink_get_set(ctx, &cmd->handle, &cmd->location) < 0)
                        return -1;
                list_for_each_entry(set, &ctx->list, list) {
-                       if (netlink_get_setelems(ctx, &cmd->handle, set) < 0)
+                       if (netlink_get_setelems(ctx, &cmd->handle,
+                                                &cmd->location, set) < 0)
                                return -1;
                        set_print(set);
                }
@@ -545,9 +553,9 @@ static int do_command_flush(struct netlink_ctx *ctx, struct cmd *cmd)
 {
        switch (cmd->obj) {
        case CMD_OBJ_TABLE:
-               return netlink_flush_table(ctx, &cmd->handle);
+               return netlink_flush_table(ctx, &cmd->handle, &cmd->location);
        case CMD_OBJ_CHAIN:
-               return netlink_flush_chain(ctx, &cmd->handle);
+               return netlink_flush_chain(ctx, &cmd->handle, &cmd->location);
        default:
                BUG("invalid command object type %u\n", cmd->obj);
        }
@@ -566,13 +574,14 @@ static int do_command_rename(struct netlink_ctx *ctx, struct cmd *cmd)
 
        switch (cmd->obj) {
        case CMD_OBJ_CHAIN:
-               err = netlink_get_chain(ctx, &cmd->handle);
+               err = netlink_get_chain(ctx, &cmd->handle, &cmd->location);
                if (err < 0)
                        return err;
                list_splice_tail_init(&ctx->list, &table->chains);
                chain = chain_lookup(table, &cmd->handle);
 
-               return netlink_rename_chain(ctx, &chain->handle, cmd->arg);
+               return netlink_rename_chain(ctx, &chain->handle, &cmd->location,
+                                           cmd->arg);
        default:
                BUG("invalid command object type %u\n", cmd->obj);
        }