From f11cf6d42f873513f0bb9b80edb6bfad2dda55eb Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Wed, 24 Aug 2016 15:58:57 +0200 Subject: src: add create set command Add support for the 'create' command, we already support this in other existing objects, so support this for sets too, eg. # nft add set x y { type ipv4_addr\; } # nft create set x y { type ipv4_addr\; } :1:1-35: Error: Could not process rule: File exists create set x y { type ipv4_addr; } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # nft add set x y { type ipv4_addr\; } # This command sets the NLM_F_EXCL netlink flag, so if the object already exists, nf_tables returns -EEXIST. This is changing the existing behaviour of 'nft add set' which was setting this flag, this is inconsistent with regards to the way other objects behave. Signed-off-by: Pablo Neira Ayuso --- src/rule.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/rule.c') diff --git a/src/rule.c b/src/rule.c index 14e57f29..54edd8cb 100644 --- a/src/rule.c +++ b/src/rule.c @@ -906,9 +906,9 @@ static int do_add_setelems(struct netlink_ctx *ctx, const struct handle *h, } static int do_add_set(struct netlink_ctx *ctx, const struct handle *h, - struct set *set) + struct set *set, bool excl) { - if (netlink_add_set(ctx, h, set) < 0) + if (netlink_add_set(ctx, h, set, excl) < 0) return -1; if (set->init != NULL) return __do_add_setelems(ctx, &set->handle, set, set->init); @@ -934,7 +934,7 @@ static int do_add_table(struct netlink_ctx *ctx, const struct handle *h, } list_for_each_entry(set, &table->sets, list) { handle_merge(&set->handle, &table->handle); - if (do_add_set(ctx, &set->handle, set) < 0) + if (do_add_set(ctx, &set->handle, set, excl) < 0) return -1; } list_for_each_entry(chain, &table->chains, list) { @@ -958,7 +958,7 @@ static int do_command_add(struct netlink_ctx *ctx, struct cmd *cmd, bool excl) return netlink_add_rule_batch(ctx, &cmd->handle, cmd->rule, NLM_F_APPEND); case CMD_OBJ_SET: - return do_add_set(ctx, &cmd->handle, cmd->set); + return do_add_set(ctx, &cmd->handle, cmd->set, excl); case CMD_OBJ_SETELEM: return do_add_setelems(ctx, &cmd->handle, cmd->expr); default: -- cgit v1.2.3