intervals: support to partial deletion with automerge
Pablo Neira Ayuso
maintainerPATCH v5 7/7 intervals: support to partial deletion with automerge
Splice the existing set element cache with the elements to be deleted and merge sort it. The elements to be deleted are identified by the EXPR_F_REMOVE flag.
The set elements to be deleted is automerged in first place if the automerge flag is set on.
There are four possible deletion scenarios:
- Exact match, eg. delete [a-b] and there is a [a-b] range in the kernel set.
- Adjust left side of range, eg. delete [a-b] from range [a-x] where x > b.
- Adjust right side of range, eg. delete [a-b] from range [x-b] where x < a.
- Split range, eg. delete [a-b] from range [x-y] where x < a and b < y.
Update nft_evaluate() to use the safe list variant since new commands are dynamically registered to the list to update ranges.
This patch also restores the set element existence check for Linux kernels <= 5.7.
---
v5: fix double removal of entries when adjusting left/right intervals.
rename init parameter to add in adjust_elem_left,right() and split_interval() for clarity.
include/expression.h | 1 + include/intervals.h | 2 + src/evaluate.c | 3 +- src/intervals.c | 250 +++++++++++++++++++++++++++++++++++++++++++ src/libnftables.c | 4 +- 5 files changed, 257 insertions(+), 3 deletions(-)
include/expression.h +1 -0
@@ -202,6 +202,7 @@ enum expr_flags {EXPR_F_BOOLEAN =0x10 ,EXPR_F_INTERVAL =0x20 ,EXPR_F_KERNEL =0x40 , + EXPR_F_REMOVE = 0x80, };#include <payload.h>
include/intervals.h +2 -0
@@ -4,6 +4,8 @@void set_to_range (struct expr *init);int set_automerge (struct list_head *msgs,struct cmd *cmd,struct set *set,struct expr *init,unsigned int debug_mask); +int set_delete (struct list_head *msgs,struct cmd *cmd,struct set *set, +struct expr *init,unsigned int debug_mask);int set_overlap (struct list_head *msgs,struct set *set,struct expr *init);int set_to_intervals (const struct set *set,struct expr *init,bool add);
src/evaluate.c +2 -1
@@ -1474,7 +1474,8 @@ static int interval_set_eval(struct eval_ctx *ctx, struct set *set, }break ;case CMD_DELETE : -set_to_range (init); + ret =set_delete (ctx->msgs, ctx->cmd, set, init, + ctx->nft->debug_mask);break ;case CMD_GET :break ;
src/intervals.c +250 -0
256 lines not on this page · raw message
src/libnftables.c +2 -2
@@ -500,8 +500,8 @@ static int nft_evaluate(struct nft_ctx *nft, struct list_head *msgs, struct list_head *cmds) {struct nft_cache_filter *filter; +struct cmd *cmd, *next;unsigned int flags; -struct cmd *cmd; filter =nft_cache_filter_init (); flags =nft_cache_evaluate (nft, cmds, filter);
@@ -512,7 +512,7 @@ static int nft_evaluate(struct nft_ctx *nft, struct list_head *msgs,nft_cache_filter_fini (filter); -list_for_each_entry (cmd, cmds, list) { +list_for_each_entry_safe (cmd, next, cmds, list) {struct eval_ctx ectx = { .nft = nft, .msgs = msgs,
Signature · 1 line
2.30.2