1 From: Pablo Neira Ayuso <pablo@netfilter.org>
2 Date: Fri, 19 Jan 2018 01:41:38 +0100
3 Subject: [PATCH] src: delete flowtable
5 This patch allows you to delete an existing flowtable:
7 # nft delete flowtable x m
9 Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
14 @@ -95,6 +95,9 @@ mnl_nft_flowtable_dump(struct netlink_ct
15 int mnl_nft_flowtable_batch_add(struct nftnl_flowtable *flo,
16 struct nftnl_batch *batch, unsigned int flags,
18 +int mnl_nft_flowtable_batch_del(struct nftnl_flowtable *flow,
19 + struct nftnl_batch *batch, unsigned int flags,
22 struct nftnl_ruleset *mnl_nft_ruleset_dump(struct netlink_ctx *ctx,
24 --- a/include/netlink.h
25 +++ b/include/netlink.h
26 @@ -186,6 +186,9 @@ extern int netlink_list_flowtables(struc
27 extern int netlink_add_flowtable(struct netlink_ctx *ctx,
28 const struct handle *h, struct flowtable *ft,
30 +extern int netlink_delete_flowtable(struct netlink_ctx *ctx,
31 + const struct handle *h,
32 + struct location *loc);
34 extern void netlink_dump_chain(const struct nftnl_chain *nlc,
35 struct netlink_ctx *ctx);
38 @@ -3121,6 +3121,7 @@ static int cmd_evaluate_delete(struct ev
42 + case CMD_OBJ_FLOWTABLE:
45 case CMD_OBJ_CT_HELPER:
48 @@ -1027,6 +1027,22 @@ int mnl_nft_flowtable_batch_add(struct n
52 +int mnl_nft_flowtable_batch_del(struct nftnl_flowtable *flo,
53 + struct nftnl_batch *batch, unsigned int flags,
56 + struct nlmsghdr *nlh;
58 + nlh = nftnl_nlmsg_build_hdr(nftnl_batch_buffer(batch),
59 + NFT_MSG_DELFLOWTABLE,
60 + nftnl_flowtable_get_u32(flo, NFTNL_FLOWTABLE_FAMILY),
62 + nftnl_flowtable_nlmsg_build_payload(nlh, flo);
63 + mnl_nft_batch_continue(batch);
73 @@ -1831,6 +1831,24 @@ int netlink_add_flowtable(struct netlink
77 +int netlink_delete_flowtable(struct netlink_ctx *ctx, const struct handle *h,
78 + struct location *loc)
80 + struct nftnl_flowtable *flo;
83 + flo = alloc_nftnl_flowtable(h, NULL);
84 + netlink_dump_flowtable(flo, ctx);
86 + err = mnl_nft_flowtable_batch_del(flo, ctx->batch, 0, ctx->seqnum);
88 + netlink_io_error(ctx, loc, "Could not delete flowtable: %s",
90 + nftnl_flowtable_free(flo);
95 static int list_obj_cb(struct nftnl_obj *nls, void *arg)
97 struct netlink_ctx *ctx = arg;
98 --- a/src/parser_bison.y
99 +++ b/src/parser_bison.y
100 @@ -1024,6 +1024,10 @@ delete_cmd : TABLE table_spec
102 $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_SETELEM, &$2, &@$, $3);
104 + | FLOWTABLE flowtable_spec
106 + $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_FLOWTABLE, &$2, &@$, NULL);
110 $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_COUNTER, &$2, &@$, NULL);
113 @@ -1177,6 +1177,9 @@ static int do_command_delete(struct netl
115 return netlink_delete_obj(ctx, &cmd->handle, &cmd->location,
117 + case CMD_OBJ_FLOWTABLE:
118 + return netlink_delete_flowtable(ctx, &cmd->handle,
121 BUG("invalid command object type %u\n", cmd->obj);