expr: numgen: add counter offset value and rename until by modulus
PATCH 1/1 expr: numgen: add counter offset value and rename until by modulus
Add support to pass through an offset value to the counter initialization. With this feature, the sysadmin is able to send an started value for the counter.
Example:
meta mark set numgen inc mod 2 sum 100
This will generate marks with series 100, 101, 100, 101, ...
The _modulus_ attribute will be reused as _until_, as it's similar to other expressions with value limits (ex. hash).
Signed-off-by Laura Garcia Liebana <[email protected]>
--- include/buffer.h | 2 +- include/libnftnl/expr.h | 3 +- include/linux/netfilter/nf_tables.h | 6 ++- src/expr/numgen.c | 83 ++++++++++++++++++++++++------------- tests/nft-expr_numgen-test.c | 12 ++++-- 5 files changed, 70 insertions(+), 36 deletions(-)
include/buffer.h +1 -1
@@ -78,11 +78,11 @@ int nftnl_buf_reg(struct nftnl_buf *b, int type, union nftnl_data_reg *reg,#define SREG_KEY "sreg_key"#define SREG_DATA "sreg_data"#define SREG "sreg" +#define SUM "sum"#define TABLE "table"#define TOTAL "total"#define TYPE "type"#define UNIT "unit" -#define UNTIL "until"#define USE "use"#define XOR "xor"#define ADD "add"
include/libnftnl/expr.h +2 -1
@@ -52,8 +52,9 @@ enum {enum {NFTNL_EXPR_NG_DREG =NFTNL_EXPR_BASE , -NFTNL_EXPR_NG_UNTIL , +NFTNL_EXPR_NG_MODULUS ,NFTNL_EXPR_NG_TYPE , +NFTNL_EXPR_NG_SUM , };enum {
include/linux/netfilter/nf_tables.h +4 -2
@@ -670,14 +670,16 @@ enum nft_exthdr_attributes {* enum nft_ng_attributes - nf_tables number generator expression attributes * * @NFTA_NG_DREG: destination register (NLA_U32) -* @NFTA_NG_UNTIL: limit value (NLA_U32) +* @NFTA_NG_MODULUS: maximum value to be returned (NLA_U32) * @NFTA_NG_TYPE: type of operation (NLA_U32) +* @NFTA_NG_SUM: offset to be added to the counter (NLA_U32) */ enum nft_ng_attributes {NFTA_NG_UNSPEC ,NFTA_NG_DREG , -NFTA_NG_UNTIL , +NFTA_NG_MODULUS ,NFTA_NG_TYPE , +NFTA_NG_SUM , __NFTA_NG_MAX };#define NFTA_NG_MAX (__NFTA_NG_MAX - 1)
src/expr/numgen.c +55 -28
194 lines not on this page · raw message
tests/nft-expr_numgen-test.c +8 -4
@@ -33,12 +33,15 @@ static void cmp_nftnl_expr(struct nftnl_expr *rule_a,if (nftnl_expr_get_u32 (rule_a,NFTNL_EXPR_NG_DREG ) !=nftnl_expr_get_u32 (rule_b,NFTNL_EXPR_NG_DREG ))print_err ("Expr NFTNL_EXPR_NG_DREG mismatches" ); -if (nftnl_expr_get_u32 (rule_a,NFTNL_EXPR_NG_UNTIL ) != -nftnl_expr_get_u32 (rule_b,NFTNL_EXPR_NG_UNTIL )) -print_err ("Expr NFTNL_EXPR_NG_UNTIL mismatches" ); +if (nftnl_expr_get_u32 (rule_a,NFTNL_EXPR_NG_MODULUS ) != +nftnl_expr_get_u32 (rule_b,NFTNL_EXPR_NG_MODULUS )) +print_err ("Expr NFTNL_EXPR_NG_MODULUS mismatches" );if (nftnl_expr_get_u32 (rule_a,NFTNL_EXPR_NG_TYPE ) !=nftnl_expr_get_u32 (rule_b,NFTNL_EXPR_NG_TYPE ))print_err ("Expr NFTNL_EXPR_NG_TYPE mismatches" ); +if (nftnl_expr_get_u32 (rule_a,NFTNL_EXPR_NG_SUM ) != +nftnl_expr_get_u32 (rule_b,NFTNL_EXPR_NG_SUM )) +print_err ("Expr NFTNL_EXPR_NG_SUM mismatches" ); }int main (int argc,char *argv[])
@@ -59,8 +62,9 @@ int main(int argc, char *argv[])print_err ("OOM" );nftnl_expr_set_u32 (ex,NFTNL_EXPR_NG_DREG ,0x1234568 ); -nftnl_expr_set_u32 (ex,NFTNL_EXPR_NG_UNTIL ,0x78123456 ); +nftnl_expr_set_u32 (ex,NFTNL_EXPR_NG_MODULUS ,0x78123456 );nftnl_expr_set_u32 (ex,NFTNL_EXPR_NG_TYPE ,NFT_NG_INCREMENTAL ); +nftnl_expr_set_u32 (ex,NFTNL_EXPR_NG_SUM ,0x1000000 );nftnl_rule_add_expr (a, ex);
Signature · 1 line
2.8.1