expr: add number generation expression
PATCH v2 1/1 expr: add number generation expression
Support for the nft ng expression within libnftnl.
Signed-off-by Laura Garcia Liebana <[email protected]>
---
Changes in V2:
- Add test
- Rename nth expression to numgen
- Add support for types incremental and random
include/buffer.h | 1 + include/libnftnl/expr.h | 6 + include/linux/netfilter/nf_tables.h | 27 ++++ src/Makefile.am | 1 + src/expr/numgen.c | 251 ++++++++++++++++++++++++++++++++++++ src/expr_ops.c | 2 + tests/Makefile.am | 4 + tests/nft-expr_numgen-test.c | 98 ++++++++++++++ 8 files changed, 390 insertions(+) create mode 100644 src/expr/numgen.c create mode 100644 tests/nft-expr_numgen-test.c
include/buffer.h +1 -0
@@ -82,6 +82,7 @@ int nftnl_buf_reg(struct nftnl_buf *b, int type, union nftnl_data_reg *reg,#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 +6 -0
@@ -49,6 +49,12 @@ enum { };enum { +NFTNL_EXPR_NG_DREG =NFTNL_EXPR_BASE , +NFTNL_EXPR_NG_UNTIL , +NFTNL_EXPR_NG_TYPE , +}; + +enum {NFTNL_EXPR_META_KEY =NFTNL_EXPR_BASE ,NFTNL_EXPR_META_DREG ,NFTNL_EXPR_META_SREG ,
include/linux/netfilter/nf_tables.h +27 -0
@@ -667,6 +667,33 @@ enum nft_exthdr_attributes {#define NFTA_EXTHDR_MAX (__NFTA_EXTHDR_MAX - 1)/** +* 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_TYPE: type of operation (NLA_U32) +*/ +enum nft_ng_attributes { +NFTA_NG_UNSPEC , +NFTA_NG_DREG , +NFTA_NG_UNTIL , +NFTA_NG_TYPE , + __NFTA_NG_MAX +}; +#define NFTA_NG_MAX (__NFTA_NG_MAX - 1) + +/** +* enum nft_ng_type - nf_tables number generator expression reject types +* +* @NFT_NG_INCREMENTAL: Incremental number generator +* @NFT_NG_RANDOM: Random number generator +*/ +enum nft_ng_type { +NFT_NG_INCREMENTAL , +NFT_NG_RANDOM +}; + +/** * enum nft_meta_keys - nf_tables meta expression keys * * @NFT_META_LEN: packet length (skb->len)
src/Makefile.am +1 -0
@@ -38,6 +38,7 @@ libnftnl_la_SOURCES = utils.c \ expr/immediate.c \ expr/match.c \ expr/meta.c \ + expr/numgen.c \ expr/nat.c \ expr/payload.c \ expr/queue.c \
src/expr/numgen.c new file +251 -0
251 lines not on this page · raw message
src/expr_ops.c +2 -0
@@ -19,6 +19,7 @@ extern struct expr_ops expr_ops_lookup;extern struct expr_ops expr_ops_masq;extern struct expr_ops expr_ops_match;extern struct expr_ops expr_ops_meta; +extern struct expr_ops expr_ops_ng;extern struct expr_ops expr_ops_nat;extern struct expr_ops expr_ops_payload;extern struct expr_ops expr_ops_redir;
@@ -43,6 +44,7 @@ static struct expr_ops *expr_ops[] = { &expr_ops_masq, &expr_ops_match, &expr_ops_meta, + &expr_ops_ng, &expr_ops_nat, &expr_ops_payload, &expr_ops_redir,
tests/Makefile.am +4 -0
@@ -24,6 +24,7 @@ check_PROGRAMS = nft-parsing-test \ nft-expr_match-test \ nft-expr_masq-test \ nft-expr_meta-test \ + nft-expr_numgen-test \ nft-expr_nat-test \ nft-expr_payload-test \ nft-expr_queue-test \
@@ -91,6 +92,9 @@ nft_expr_masq_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} nft_expr_meta_test_SOURCES = nft-expr_meta-test.c nft_expr_meta_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} +nft_expr_numgen_test_SOURCES = nft-expr_numgen-test.c +nft_expr_numgen_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} + nft_expr_nat_test_SOURCES = nft-expr_nat-test.c nft_expr_nat_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
tests/nft-expr_numgen-test.c new file +98 -0
98 lines not on this page · raw message
Signature · 1 line
2.8.1