From e19e0ed6cde3176b7ef519748f893aa1afc86fa7 Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Thu, 18 Apr 2013 17:53:59 +0200 Subject: cmd/netlink: make sure we always have a location in netlink operations Improve error reporting by always using a location in netlink operations. Signed-off-by: Patrick McHardy --- src/evaluate.c | 4 +-- src/netlink.c | 109 +++++++++++++++++++++++++++++++++------------------------ src/parser.y | 48 ++++++++++++------------- src/rule.c | 75 ++++++++++++++++++++++----------------- 4 files changed, 132 insertions(+), 104 deletions(-) (limited to 'src') diff --git a/src/evaluate.c b/src/evaluate.c index 6adf663d..bf169321 100644 --- a/src/evaluate.c +++ b/src/evaluate.c @@ -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) diff --git a/src/netlink.c b/src/netlink.c index 5b99c2e1..da290d58 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -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; } diff --git a/src/parser.y b/src/parser.y index 87602d9f..166cbcc5 100644 --- a/src/parser.y +++ b/src/parser.y @@ -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; } ; diff --git a/src/rule.c b/src/rule.c index 67ff5842..89c3607c 100644 --- a/src/rule.c +++ b/src/rule.c @@ -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 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); } -- cgit v1.2.3