expr: add hash expression
PATCH v2 1/1 expr: add hash expression
Support for the nft hash expression in libnftnl.
Signed-off-by Laura Garcia Liebana <[email protected]>
--- include/buffer.h | 2 + include/libnftnl/expr.h | 8 + include/linux/netfilter/nf_tables.h | 21 +++ src/Makefile.am | 1 + src/expr/hash.c | 294 ++++++++++++++++++++++++++++++++++++ src/expr_ops.c | 2 + tests/Makefile.am | 6 +- tests/nft-expr_hash-test.c | 102 +++++++++++++ tests/test-script.sh | 1 + 9 files changed, 436 insertions(+), 1 deletion(-) create mode 100644 src/expr/hash.c create mode 100644 tests/nft-expr_hash-test.c
include/buffer.h +2 -0
@@ -89,5 +89,7 @@ int nftnl_buf_reg(struct nftnl_buf *b, int type, union nftnl_data_reg *reg,#define DELETE "delete"#define REPLACE "replace"#define FLUSH "flush" +#define MODULUS "modulus" +#define SEED "seed"#endif
include/libnftnl/expr.h +8 -0
@@ -197,6 +197,14 @@ enum { NFTNL_EXPR_FWD_SREG_DEV = NFTNL_EXPR_BASE, }; +enum { +NFTNL_EXPR_HASH_SREG =NFTNL_EXPR_BASE , +NFTNL_EXPR_HASH_DREG , +NFTNL_EXPR_HASH_LEN , +NFTNL_EXPR_HASH_MODULUS , +NFTNL_EXPR_HASH_SEED , +}; +/* * Compat */
include/linux/netfilter/nf_tables.h +21 -0
@@ -1109,4 +1109,25 @@ enum nft_trace_types {__NFT_TRACETYPE_MAX };#define NFT_TRACETYPE_MAX (__NFT_TRACETYPE_MAX - 1) + +/** +* enum nft_hash_attributes - nf_tables hash expression attributes +* +* @NFTA_HASH_SREG: source register (NLA_U32) +* @NFTA_HASH_DREG: destination register (NLA_U32) +* @NFTA_HASH_LEN: data length (NLA_U32) +* @NFTA_HASH_MODULUS: Modulus value (NLA_U32) +* @NFTA_HASH_SEED: hash initial value (NLA_U32) +*/ +enum nft_hash_attributes { +NFTA_HASH_UNSPEC , +NFTA_HASH_SREG , +NFTA_HASH_DREG , +NFTA_HASH_LEN , +NFTA_HASH_MODULUS , +NFTA_HASH_SEED , + __NFTA_HASH_MAX +}; +#define NFTA_HASH_MAX (__NFTA_HASH_MAX - 1) +#endif /* _LINUX_NF_TABLES_H */
src/Makefile.am +1 -0
@@ -46,4 +46,5 @@ libnftnl_la_SOURCES = utils.c \ expr/target.c \ expr/masq.c \ expr/redir.c \ + expr/hash.c \ libnftnl.map
src/expr/hash.c new file +294 -0
294 lines not on this page · raw message
src/expr_ops.c +2 -0
@@ -27,6 +27,7 @@ extern struct expr_ops expr_ops_reject;extern struct expr_ops expr_ops_queue;extern struct expr_ops expr_ops_target;extern struct expr_ops expr_ops_dynset; +extern struct expr_ops expr_ops_hash;static struct expr_ops *expr_ops[] = { &expr_ops_bitwise,
@@ -52,6 +53,7 @@ static struct expr_ops *expr_ops[] = { &expr_ops_queue, &expr_ops_target, &expr_ops_dynset, + &expr_ops_hash, NULL, };
tests/Makefile.am +5 -1
@@ -29,7 +29,8 @@ check_PROGRAMS = nft-parsing-test \ nft-expr_queue-test \ nft-expr_redir-test \ nft-expr_reject-test \ - nft-expr_target-test + nft-expr_target-test \ + nft-expr_hash-test nft_parsing_test_SOURCES = nft-parsing-test.c nft_parsing_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} ${LIBXML_LIBS} ${LIBJSON_LIBS}
@@ -108,3 +109,6 @@ nft_expr_redir_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} nft_expr_target_test_SOURCES = nft-expr_target-test.c nft_expr_target_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} + +nft_expr_hash_test_SOURCES = nft-expr_hash-test.c +nft_expr_hash_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
tests/nft-expr_hash-test.c new file +102 -0
102 lines not on this page · raw message
tests/test-script.sh +1 -0
@@ -20,6 +20,7 @@ ./nft-expr_payload-test ./nft-expr_reject-test ./nft-expr_target-test +./nft-expr_hash-test ./nft-rule-test ./nft-set-test ./nft-table-test
Signature · 1 line
2.8.1
Quoted 1 line · Laura Garcia Liebana
Support for the nft hash expression in libnftnl.
Applied, thanks Laura.