const struct location *loc);
extern int netlink_add_set(struct netlink_ctx *ctx, const struct handle *h,
- struct set *set);
+ struct set *set, bool excl);
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,
}
static int netlink_add_set_compat(struct netlink_ctx *ctx,
- const struct handle *h, struct set *set)
+ const struct handle *h, struct set *set,
+ bool excl)
{
+ unsigned int flags = excl ? NLM_F_EXCL : 0;
struct nftnl_set *nls;
int err;
}
netlink_dump_set(nls);
- err = mnl_nft_set_add(nf_sock, nls, NLM_F_EXCL | NLM_F_ECHO);
+ err = mnl_nft_set_add(nf_sock, nls, NLM_F_ECHO | flags);
if (err < 0)
netlink_io_error(ctx, &set->location, "Could not add set: %s",
strerror(errno));
}
static int netlink_add_set_batch(struct netlink_ctx *ctx,
- const struct handle *h, struct set *set)
+ const struct handle *h, struct set *set,
+ bool excl)
{
struct nftnl_set *nls;
int err;
netlink_dump_set(nls);
- err = mnl_nft_set_batch_add(nls, NLM_F_EXCL, ctx->seqnum);
+ err = mnl_nft_set_batch_add(nls, excl ? NLM_F_EXCL : 0, ctx->seqnum);
if (err < 0)
netlink_io_error(ctx, &set->location, "Could not add set: %s",
strerror(errno));
}
int netlink_add_set(struct netlink_ctx *ctx, const struct handle *h,
- struct set *set)
+ struct set *set, bool excl)
{
if (ctx->batch_supported)
- return netlink_add_set_batch(ctx, h, set);
+ return netlink_add_set_batch(ctx, h, set, excl);
else
- return netlink_add_set_compat(ctx, h, set);
+ return netlink_add_set_compat(ctx, h, set, excl);
}
static int netlink_del_set_compat(struct netlink_ctx *ctx,
close_scope(state);
$$ = cmd_alloc(CMD_CREATE, CMD_OBJ_CHAIN, &$2, &@$, $5);
}
+ | SET set_spec set_block_alloc
+ '{' set_block '}'
+ {
+ $5->location = @5;
+ handle_merge(&$3->handle, &$2);
+ $$ = cmd_alloc(CMD_CREATE, CMD_OBJ_SET, &$2, &@$, $5);
+ }
+ | MAP set_spec map_block_alloc
+ '{' map_block '}'
+ {
+ $5->location = @5;
+ handle_merge(&$3->handle, &$2);
+ $$ = cmd_alloc(CMD_CREATE, CMD_OBJ_SET, &$2, &@$, $5);
+ }
;
insert_cmd : RULE rule_position rule
}
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);
}
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) {
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: