Improve error reporting by always using a location in netlink operations.
Signed-off-by: Patrick McHardy<kaber@trash.net>
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 */
*
* @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;
*
* @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)
struct chain {
struct list_head list;
struct handle handle;
+ struct location location;
uint32_t flags;
unsigned int hooknum;
unsigned int priority;
};
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>
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);
}
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)
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;
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;
}
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;
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));
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;
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;
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;
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));
}
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;
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;
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;
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;
}
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;
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));
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;
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;
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;
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;
}
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;
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));
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;
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)
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;
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;
}
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));
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;
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;
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;
}
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;
}
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;
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;
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;
}
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;
}
;
}
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;
}
#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) {
}
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) {
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;
}
}
{
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);
{
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:
}
}
-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);
}
/* 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) {
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);
}
{
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);
}
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);
}