diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2018-01-19 01:41:38 +0100 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2018-03-05 16:30:15 +0100 |
commit | f1f6c326d78594fd0dc279d4870502addcd6fcc2 (patch) | |
tree | 79750c93b413e4f31fdbd96baa60d45b0c0d6646 /src | |
parent | 92911b362e9067a9a335ac1a63e15119fb69a47d (diff) |
src: delete flowtable
This patch allows you to delete an existing flowtable:
# nft delete flowtable x m
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/evaluate.c | 1 | ||||
-rw-r--r-- | src/mnl.c | 16 | ||||
-rw-r--r-- | src/netlink.c | 18 | ||||
-rw-r--r-- | src/parser_bison.y | 4 | ||||
-rw-r--r-- | src/rule.c | 3 |
5 files changed, 42 insertions, 0 deletions
diff --git a/src/evaluate.c b/src/evaluate.c index 9da185c9..51841136 100644 --- a/src/evaluate.c +++ b/src/evaluate.c @@ -3134,6 +3134,7 @@ static int cmd_evaluate_delete(struct eval_ctx *ctx, struct cmd *cmd) case CMD_OBJ_RULE: case CMD_OBJ_CHAIN: case CMD_OBJ_TABLE: + case CMD_OBJ_FLOWTABLE: case CMD_OBJ_COUNTER: case CMD_OBJ_QUOTA: case CMD_OBJ_CT_HELPER: @@ -1027,6 +1027,22 @@ int mnl_nft_flowtable_batch_add(struct nftnl_flowtable *flo, return 0; } +int mnl_nft_flowtable_batch_del(struct nftnl_flowtable *flo, + struct nftnl_batch *batch, unsigned int flags, + uint32_t seqnum) +{ + struct nlmsghdr *nlh; + + nlh = nftnl_nlmsg_build_hdr(nftnl_batch_buffer(batch), + NFT_MSG_DELFLOWTABLE, + nftnl_flowtable_get_u32(flo, NFTNL_FLOWTABLE_FAMILY), + flags, seqnum); + nftnl_flowtable_nlmsg_build_payload(nlh, flo); + mnl_nft_batch_continue(batch); + + return 0; +} + /* * ruleset */ diff --git a/src/netlink.c b/src/netlink.c index 5b2d5e16..d4ed09bf 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -1547,6 +1547,24 @@ int netlink_add_flowtable(struct netlink_ctx *ctx, const struct handle *h, return err; } +int netlink_delete_flowtable(struct netlink_ctx *ctx, const struct handle *h, + struct location *loc) +{ + struct nftnl_flowtable *flo; + int err; + + flo = alloc_nftnl_flowtable(h, NULL); + netlink_dump_flowtable(flo, ctx); + + err = mnl_nft_flowtable_batch_del(flo, ctx->batch, 0, ctx->seqnum); + if (err < 0) + netlink_io_error(ctx, loc, "Could not delete flowtable: %s", + strerror(errno)); + nftnl_flowtable_free(flo); + + return err; +} + static int list_obj_cb(struct nftnl_obj *nls, void *arg) { struct netlink_ctx *ctx = arg; diff --git a/src/parser_bison.y b/src/parser_bison.y index c73eddde..15d2432a 100644 --- a/src/parser_bison.y +++ b/src/parser_bison.y @@ -1047,6 +1047,10 @@ delete_cmd : TABLE table_spec { $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_SETELEM, &$2, &@$, $3); } + | FLOWTABLE flowtable_spec + { + $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_FLOWTABLE, &$2, &@$, NULL); + } | COUNTER obj_spec { $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_COUNTER, &$2, &@$, NULL); @@ -1221,6 +1221,9 @@ static int do_command_delete(struct netlink_ctx *ctx, struct cmd *cmd) case CMD_OBJ_LIMIT: return netlink_delete_obj(ctx, &cmd->handle, &cmd->location, NFT_OBJECT_LIMIT); + case CMD_OBJ_FLOWTABLE: + return netlink_delete_flowtable(ctx, &cmd->handle, + &cmd->location); default: BUG("invalid command object type %u\n", cmd->obj); } |