src: add cache level flags
Pablo Neira Ayuso
maintainerPATCH v3 5/5 src: add cache level flags
The score approach based on command type is confusing.
This patch introduces cache level flags, each flag specifies what kind of object type is needed. These flags are set on/off depending on the list of commands coming in this batch.
cache_is_complete() now checks if the cache contains the objects that are needed through these new flags.
Signed-off-by Pablo Neira Ayuso <[email protected]>
---
v3: adjust rule_evaluate() to use NFT_CACHE_RULE, per Phil Sutter.
include/Makefile.am | 1 + include/cache.h | 35 +++++++++++++++++ include/nftables.h | 2 +- include/rule.h | 3 +- src/cache.c | 86 ++++++++++++++++++++++-------------------- src/evaluate.c | 3 +- src/libnftables.c | 6 +-- src/rule.c | 106 +++++++++++++++++++++++----------------------------- 8 files changed, 135 insertions(+), 107 deletions(-) create mode 100644 include/cache.h
include/Makefile.am +1 -0
@@ -2,6 +2,7 @@ SUBDIRS = linux \ nftables noinst_HEADERS = cli.h \ + cache.h \ datatype.h \ expression.h \ fib.h \
include/cache.h new file +35 -0
@@ -0,0 +1,35 @@ +#ifndef _NFT_CACHE_H_ +#define _NFT_CACHE_H_ + +enum cache_level_bits { +NFT_CACHE_TABLE_BIT = (1 <<0 ), +NFT_CACHE_CHAIN_BIT = (1 <<1 ), +NFT_CACHE_SET_BIT = (1 <<2 ), +NFT_CACHE_FLOWTABLE_BIT = (1 <<3 ), +NFT_CACHE_OBJECT_BIT = (1 <<4 ), +NFT_CACHE_SETELEM_BIT = (1 <<5 ), +NFT_CACHE_RULE_BIT = (1 <<6 ), + __NFT_CACHE_MAX_BIT = (1 <<7 ), +}; + +enum cache_level_flags { +NFT_CACHE_EMPTY =0 , +NFT_CACHE_TABLE =NFT_CACHE_TABLE_BIT , +NFT_CACHE_CHAIN =NFT_CACHE_TABLE_BIT | +NFT_CACHE_CHAIN_BIT , +NFT_CACHE_SET =NFT_CACHE_TABLE_BIT | +NFT_CACHE_SET_BIT , +NFT_CACHE_FLOWTABLE =NFT_CACHE_TABLE_BIT | +NFT_CACHE_FLOWTABLE_BIT , +NFT_CACHE_OBJECT =NFT_CACHE_TABLE_BIT | +NFT_CACHE_OBJECT_BIT , +NFT_CACHE_SETELEM =NFT_CACHE_TABLE_BIT | +NFT_CACHE_SET_BIT | +NFT_CACHE_SETELEM_BIT , +NFT_CACHE_RULE =NFT_CACHE_TABLE_BIT | +NFT_CACHE_CHAIN_BIT | +NFT_CACHE_RULE_BIT , +NFT_CACHE_FULL = __NFT_CACHE_MAX_BIT -1 , +}; + +#endif /* _NFT_CACHE_H_ */
include/nftables.h +1 -1
@@ -81,7 +81,7 @@ struct nft_cache {uint32_t genid;struct list_head list;uint32_t seqnum; -uint32_t cmd; +uint32_t flags; };struct mnl_socket ;
include/rule.h +1 -2
@@ -462,7 +462,6 @@ enum cmd_ops {CMD_EXPORT ,CMD_MONITOR , CMD_DESCRIBE, - __CMD_FLUSH_RULESET, };/**
@@ -636,7 +635,7 @@ extern struct error_record *rule_postprocess(struct rule *rule);struct netlink_ctx ;extern int do_command (struct netlink_ctx *ctx,struct cmd *cmd); -extern int cache_evaluate (struct nft_ctx *nft,struct list_head *cmds); +extern unsigned int cache_evaluate (struct nft_ctx *nft,struct list_head *cmds);extern int cache_update (struct nft_ctx *ctx,enum cmd_ops cmd,struct list_head *msgs);extern void cache_flush (struct nft_ctx *ctx,struct list_head *msgs);
src/cache.c +45 -41
162 lines not on this page · raw message
src/evaluate.c +2 -1
@@ -29,6 +29,7 @@#include <netlink.h> #include <time.h> #include <rule.h> +#include <cache.h> #include <erec.h> #include <gmputil.h> #include <utils.h>
@@ -3294,7 +3295,7 @@ static int rule_evaluate(struct eval_ctx *ctx, struct rule *rule, }/* add rules to cache only if it is complete enough to contain them */ -if (!cache_is_complete (&ctx->nft->cache,CMD_LIST )) +if (!cache_is_complete (&ctx->nft->cache,NFT_CACHE_RULE ))return 0 ;return rule_cache_update (ctx, op);
src/libnftables.c +3 -3
@@ -381,11 +381,11 @@ static int nft_parse_bison_filename(struct nft_ctx *nft, const char *filename,static int nft_evaluate (struct nft_ctx *nft,struct list_head *msgs,struct list_head *cmds) { -unsigned int completeness; +unsigned int flags;struct cmd *cmd; - completeness =cache_evaluate (nft, cmds); -if (cache_update (nft, completeness, msgs) <0 ) + flags =cache_evaluate (nft, cmds); +if (cache_update (nft, flags, msgs) <0 )return -1 ;list_for_each_entry (cmd, cmds, list) {
src/rule.c +47 -59
193 lines not on this page · raw message
Signature · 1 line
2.11.0