202-src-delete-flowtable.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. From: Pablo Neira Ayuso <[email protected]>
  2. Date: Fri, 19 Jan 2018 01:41:38 +0100
  3. Subject: [PATCH] src: delete flowtable
  4. This patch allows you to delete an existing flowtable:
  5. # nft delete flowtable x m
  6. Signed-off-by: Pablo Neira Ayuso <[email protected]>
  7. ---
  8. --- a/include/mnl.h
  9. +++ b/include/mnl.h
  10. @@ -95,6 +95,9 @@ mnl_nft_flowtable_dump(struct netlink_ct
  11. int mnl_nft_flowtable_batch_add(struct nftnl_flowtable *flo,
  12. struct nftnl_batch *batch, unsigned int flags,
  13. uint32_t seqnum);
  14. +int mnl_nft_flowtable_batch_del(struct nftnl_flowtable *flow,
  15. + struct nftnl_batch *batch, unsigned int flags,
  16. + uint32_t seqnum);
  17. struct nftnl_ruleset *mnl_nft_ruleset_dump(struct netlink_ctx *ctx,
  18. uint32_t family);
  19. --- a/include/netlink.h
  20. +++ b/include/netlink.h
  21. @@ -186,6 +186,9 @@ extern int netlink_list_flowtables(struc
  22. extern int netlink_add_flowtable(struct netlink_ctx *ctx,
  23. const struct handle *h, struct flowtable *ft,
  24. uint32_t flags);
  25. +extern int netlink_delete_flowtable(struct netlink_ctx *ctx,
  26. + const struct handle *h,
  27. + struct location *loc);
  28. extern void netlink_dump_chain(const struct nftnl_chain *nlc,
  29. struct netlink_ctx *ctx);
  30. --- a/src/evaluate.c
  31. +++ b/src/evaluate.c
  32. @@ -3121,6 +3121,7 @@ static int cmd_evaluate_delete(struct ev
  33. case CMD_OBJ_RULE:
  34. case CMD_OBJ_CHAIN:
  35. case CMD_OBJ_TABLE:
  36. + case CMD_OBJ_FLOWTABLE:
  37. case CMD_OBJ_COUNTER:
  38. case CMD_OBJ_QUOTA:
  39. case CMD_OBJ_CT_HELPER:
  40. --- a/src/mnl.c
  41. +++ b/src/mnl.c
  42. @@ -1027,6 +1027,22 @@ int mnl_nft_flowtable_batch_add(struct n
  43. return 0;
  44. }
  45. +int mnl_nft_flowtable_batch_del(struct nftnl_flowtable *flo,
  46. + struct nftnl_batch *batch, unsigned int flags,
  47. + uint32_t seqnum)
  48. +{
  49. + struct nlmsghdr *nlh;
  50. +
  51. + nlh = nftnl_nlmsg_build_hdr(nftnl_batch_buffer(batch),
  52. + NFT_MSG_DELFLOWTABLE,
  53. + nftnl_flowtable_get_u32(flo, NFTNL_FLOWTABLE_FAMILY),
  54. + flags, seqnum);
  55. + nftnl_flowtable_nlmsg_build_payload(nlh, flo);
  56. + mnl_nft_batch_continue(batch);
  57. +
  58. + return 0;
  59. +}
  60. +
  61. /*
  62. * ruleset
  63. */
  64. --- a/src/netlink.c
  65. +++ b/src/netlink.c
  66. @@ -1831,6 +1831,24 @@ int netlink_add_flowtable(struct netlink
  67. return err;
  68. }
  69. +int netlink_delete_flowtable(struct netlink_ctx *ctx, const struct handle *h,
  70. + struct location *loc)
  71. +{
  72. + struct nftnl_flowtable *flo;
  73. + int err;
  74. +
  75. + flo = alloc_nftnl_flowtable(h, NULL);
  76. + netlink_dump_flowtable(flo, ctx);
  77. +
  78. + err = mnl_nft_flowtable_batch_del(flo, ctx->batch, 0, ctx->seqnum);
  79. + if (err < 0)
  80. + netlink_io_error(ctx, loc, "Could not delete flowtable: %s",
  81. + strerror(errno));
  82. + nftnl_flowtable_free(flo);
  83. +
  84. + return err;
  85. +}
  86. +
  87. static int list_obj_cb(struct nftnl_obj *nls, void *arg)
  88. {
  89. struct netlink_ctx *ctx = arg;
  90. --- a/src/parser_bison.y
  91. +++ b/src/parser_bison.y
  92. @@ -1024,6 +1024,10 @@ delete_cmd : TABLE table_spec
  93. {
  94. $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_SETELEM, &$2, &@$, $3);
  95. }
  96. + | FLOWTABLE flowtable_spec
  97. + {
  98. + $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_FLOWTABLE, &$2, &@$, NULL);
  99. + }
  100. | COUNTER obj_spec
  101. {
  102. $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_COUNTER, &$2, &@$, NULL);
  103. --- a/src/rule.c
  104. +++ b/src/rule.c
  105. @@ -1177,6 +1177,9 @@ static int do_command_delete(struct netl
  106. case CMD_OBJ_LIMIT:
  107. return netlink_delete_obj(ctx, &cmd->handle, &cmd->location,
  108. NFT_OBJECT_LIMIT);
  109. + case CMD_OBJ_FLOWTABLE:
  110. + return netlink_delete_flowtable(ctx, &cmd->handle,
  111. + &cmd->location);
  112. default:
  113. BUG("invalid command object type %u\n", cmd->obj);
  114. }