Skip to contentSkip to conversation

bitwise: support for passing mask and xor via registers

PATCH Applied Jeremy Sowden 2 participants 5 messages Feb 24, 2020 – Mar 2, 2020 netfilter

lore
Share & tools
lore
#0 lore raw

cover bitwise: support for passing mask and xor via registers

The kernel supports passing mask and xor values for bitwise boolean operations via registers. These are mutually exclusive with the existing data attributes: e.g., setting both NFTA_EXPR_BITWISE_MASK and NFTA_EXPR_BITWISE_MREG is an error. Add support to libnftnl.

The first patch fixes a typo, the second updates the UAPI header and the last contains the implementation.

Jeremy Sowden (3):
tests: bitwise: fix error message.
include: update nf_tables.h.
bitwise: add support for passing mask and xor via registers.

 include/libnftnl/expr.h             |  2 +
 include/linux/netfilter/nf_tables.h |  4 ++
 src/expr/bitwise.c                  | 60 ++++++++++++++++++++++---
 tests/nft-expr_bitwise-test.c       | 70 +++++++++++++++++++----------
 4 files changed, 106 insertions(+), 30 deletions(-)
Signature · 1 line
2.25.0
#1 lore raw

PATCH 1/3 tests: bitwise: fix error message.

In one case, the boolean test was reporting the wrong mismatched attribute.

---
 tests/nft-expr_bitwise-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/nft-expr_bitwise-test.c +1 -1
index 74a0e2aa6933..f134728fdd86 100644
@@ -44,7 +44,7 @@ static void cmp_nftnl_expr_bool(struct nftnl_expr *rule_a,
 		print_err("bool", "Expr BITWISE_OP mismatches");
 	if (nftnl_expr_get_u16(rule_a, NFTNL_EXPR_BITWISE_LEN) !=
 	    nftnl_expr_get_u16(rule_b, NFTNL_EXPR_BITWISE_LEN))
-		print_err("bool", "Expr BITWISE_DREG mismatches");
+		print_err("bool", "Expr BITWISE_LEN mismatches");
 	nftnl_expr_get(rule_a, NFTNL_EXPR_BITWISE_MASK, &maska);
 	nftnl_expr_get(rule_b, NFTNL_EXPR_BITWISE_MASK, &maskb);
 	if (maska != maskb)
Signature · 1 line
2.25.0
#2 lore raw

PATCH 2/3 include: update nf_tables.h.

In reply to Jeremy Sowden

Pick up a couple of new bitwise netlink attributes.

---
 include/linux/netfilter/nf_tables.h | 4 ++++
 1 file changed, 4 insertions(+)
include/linux/netfilter/nf_tables.h +4 -0
index 065218a20bb7..57e83e152bf3 100644
@@ -526,6 +526,8 @@ enum nft_bitwise_ops {
  * @NFTA_BITWISE_OP: type of operation (NLA_U32: nft_bitwise_ops)
  * @NFTA_BITWISE_DATA: argument for non-boolean operations
  *                     (NLA_NESTED: nft_data_attributes)
+ * @NFTA_BITWISE_MREG: mask register (NLA_U32: nft_registers)
+ * @NFTA_BITWISE_XREG: xor register (NLA_U32: nft_registers)
  *
  * The bitwise expression supports boolean and shift operations.  It implements
  * the boolean operations by performing the following operation:
@@ -549,6 +551,8 @@ enum nft_bitwise_attributes {
 	NFTA_BITWISE_XOR,
 	NFTA_BITWISE_OP,
 	NFTA_BITWISE_DATA,
+	NFTA_BITWISE_MREG,
+	NFTA_BITWISE_XREG,
 	__NFTA_BITWISE_MAX
 };
 #define NFTA_BITWISE_MAX	(__NFTA_BITWISE_MAX - 1)
Signature · 1 line
2.25.0
#3 lore raw

PATCH 3/3 bitwise: add support for passing mask and xor via registers.

In reply to Jeremy Sowden

The kernel supports passing mask and xor values for bitwise boolean operations via registers. These are mutually exclusive with the existing data attributes: e.g., setting both NFTA_EXPR_BITWISE_MASK and NFTA_EXPR_BITWISE_MREG is an error. Add support to libnftnl.

---
 include/libnftnl/expr.h       |  2 +
 src/expr/bitwise.c            | 60 +++++++++++++++++++++++++++---
 tests/nft-expr_bitwise-test.c | 70 +++++++++++++++++++++++------------
 3 files changed, 102 insertions(+), 30 deletions(-)
include/libnftnl/expr.h +2 -0
index cfe456dbc7a5..edeeeb1ec234 100644
@@ -118,6 +118,8 @@ enum {
 	NFTNL_EXPR_BITWISE_XOR,
 	NFTNL_EXPR_BITWISE_OP,
 	NFTNL_EXPR_BITWISE_DATA,
+	NFTNL_EXPR_BITWISE_MREG,
+	NFTNL_EXPR_BITWISE_XREG,
 };
 
 enum {
src/expr/bitwise.c +54 -6

129 lines not on this page · raw message

tests/nft-expr_bitwise-test.c +46 -24

135 lines not on this page · raw message

Signature · 1 line
2.25.0
maintainer Applied
#4 lore raw
In reply to Jeremy Sowden
Quoted 7 lines · Jeremy Sowden

The kernel supports passing mask and xor values for bitwise boolean operations via registers. These are mutually exclusive with the existing data attributes: e.g., setting both NFTA_EXPR_BITWISE_MASK and NFTA_EXPR_BITWISE_MREG is an error. Add support to libnftnl.

The first patch fixes a typo, the second updates the UAPI header and the last contains the implementation.

Applied, thanks.