expr: add support to math expression
PATCH v5 1/1 expr: add support to math expression
Signed-off-by Fernando Fernandez Mancera <[email protected]>
---
v2: adjusted the new fields and fixed the duplicated "math" on print
v3: removed NFTNL_EXPR_MATH_LEN and simplified printing
v4: adjusted byteordering, both bitmask and op are u32
v5: rebased in top of new changes and adjusted types to be32
--- include/libnftnl/expr.h | 8 ++ include/linux/netfilter/nf_tables.h | 25 ++++ src/Makefile.am | 1 + src/expr/math.c | 178 ++++++++++++++++++++++++++++ src/expr_ops.c | 2 + 5 files changed, 214 insertions(+) create mode 100644 src/expr/math.c
include/libnftnl/expr.h +8 -0
@@ -364,6 +364,14 @@ enum {__NFTNL_EXPR_INNER_MAX }; +enum { +NFTNL_EXPR_MATH_SREG =NFTNL_EXPR_BASE , +NFTNL_EXPR_MATH_DREG , +NFTNL_EXPR_MATH_OP , +NFTNL_EXPR_MATH_BITMASK , + __NFTNL_EXPR_MATH_MAX +}; +#ifdef __cplusplus } /* extern "C" */#endif
include/linux/netfilter/nf_tables.h +25 -0
@@ -2015,4 +2015,29 @@ enum nft_tunnel_attributes { };#define NFTA_TUNNEL_MAX (__NFTA_TUNNEL_MAX - 1) +/** +* enum nft_math_attributes - nftables math expression netlink attributes +* +* @NFTA_MATH_SREG: source register (NLA_U32: nft_registers) +* @NFTA_MATH_DREG: destination register (NLA_U32: nft_registers) +* @NFTA_MATH_OP: operation to be performed (NLA_U32) +* @NFTA_MATH_BITMASK: bitmask to be applied on the operation (NLA_U32) +*/ +enum nft_math_attributes { +NFTA_MATH_UNSPEC , +NFTA_MATH_SREG , +NFTA_MATH_DREG , +NFTA_MATH_OP , +NFTA_MATH_BITMASK , + __NFTA_MATH_MAX, +}; +#define NFTA_MATH_MAX (__NFTA_MATH_MAX - 1) + +enum nft_math_op { +NFT_MATH_OP_INC , +NFT_MATH_OP_DEC , + __NFT_MATH_OP_MAX, +}; +#define NFT_MATH_OP_MAX (__NFT_MATH_OP_MAX - 1) +#endif /* _LINUX_NF_TABLES_H */
src/Makefile.am +1 -0
@@ -62,6 +62,7 @@ libnftnl_la_SOURCES = utils.c \ expr/synproxy.c \ expr/osf.c \ expr/xfrm.c \ + expr/math.c \ obj/counter.c \ obj/ct_helper.c \ obj/quota.c \
src/expr/math.c new file +178 -0
178 lines not on this page · raw message
src/expr_ops.c +2 -0
@@ -43,6 +43,7 @@ extern struct expr_ops expr_ops_synproxy;extern struct expr_ops expr_ops_tunnel;extern struct expr_ops expr_ops_osf;extern struct expr_ops expr_ops_xfrm; +extern struct expr_ops expr_ops_math;static struct expr_ops expr_ops_notrack = { .name ="notrack" ,
@@ -89,6 +90,7 @@ static struct expr_ops *expr_ops[] = { &expr_ops_tunnel, &expr_ops_osf, &expr_ops_xfrm, + &expr_ops_math, NULL, };
Signature · 1 line
2.55.0