Skip to contentSkip to conversation

include: add new bitwise boolean attributes to nf_tables.h

PATCH Superseded Pablo Neira Ayuso 1 participant 2 messages Nov 19, 2024 netfilter

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/2 include: add new bitwise boolean attributes to nf_tables.h

From: Jeremy Sowden <[email protected]>

The kernel now has native support for AND, OR and XOR bitwise operations.

---
rebase on top of git HEAD

 include/linux/netfilter/nf_tables.h | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
include/linux/netfilter/nf_tables.h +15 -2
index 9e9079321380..1e95b5469f7c 100644
@@ -564,16 +564,27 @@ enum nft_immediate_attributes {
 /**
  * enum nft_bitwise_ops - nf_tables bitwise operations
  *
- * @NFT_BITWISE_BOOL: mask-and-xor operation used to implement NOT, AND, OR and
- *                    XOR boolean operations
+ * @NFT_BITWISE_BOOL: mask-and-xor operation used to implement NOT, AND, OR
+ *                    and XOR boolean operations
  * @NFT_BITWISE_LSHIFT: left-shift operation
  * @NFT_BITWISE_RSHIFT: right-shift operation
+ * @NFT_BITWISE_AND: and operation
+ * @NFT_BITWISE_OR: or operation
+ * @NFT_BITWISE_XOR: xor operation
  */
 enum nft_bitwise_ops {
 	NFT_BITWISE_BOOL,
 	NFT_BITWISE_LSHIFT,
 	NFT_BITWISE_RSHIFT,
+	NFT_BITWISE_AND,
+	NFT_BITWISE_OR,
+	NFT_BITWISE_XOR,
 };
+/*
+ * Old name for NFT_BITWISE_MASK_XOR, predating the addition of NFT_BITWISE_AND,
+ * NFT_BITWISE_OR and NFT_BITWISE_XOR.  Retained for backwards-compatibility.
+ */
+#define NFT_BITWISE_BOOL NFT_BITWISE_MASK_XOR
 
 /**
  * enum nft_bitwise_attributes - nf_tables bitwise expression netlink attributes
@@ -586,6 +597,7 @@ 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_SREG2: second source register (NLA_U32: nft_registers)
  *
  * The bitwise expression supports boolean and shift operations.  It implements
  * the boolean operations by performing the following operation:
@@ -609,6 +621,7 @@ enum nft_bitwise_attributes {
 	NFTA_BITWISE_XOR,
 	NFTA_BITWISE_OP,
 	NFTA_BITWISE_DATA,
+	NFTA_BITWISE_SREG2,
 	__NFTA_BITWISE_MAX
 };
 #define NFTA_BITWISE_MAX	(__NFTA_BITWISE_MAX - 1)
Signature · 1 line
2.30.2
author maintainer
#1 lore raw

PATCH 2/2 expr: bitwise: add support for kernel space AND, OR and XOR operations

From: Jeremy Sowden <[email protected]>

Hitherto, the kernel has only supported boolean operations of the form:

dst = (src & mask) ^ xor

where src is held in a register, and mask and xor are immediate values. User space has converted AND, OR and XOR operations to this form, and so one operand has had to be immediate. The kernel now supports performing AND, OR and XOR operations directly, on one register and an immediate value or on two registers, so we make that support available to user space.

---
rebase on top of git HEAD

 include/libnftnl/expr.h |  1 +
 src/expr/bitwise.c      | 61 +++++++++++++++++++++++++++++++++++++++--
 2 files changed, 60 insertions(+), 2 deletions(-)
include/libnftnl/expr.h +1 -0
index fba121062244..1c07b54139a5 100644
@@ -139,6 +139,7 @@ enum {
 	NFTNL_EXPR_BITWISE_XOR,
 	NFTNL_EXPR_BITWISE_OP,
 	NFTNL_EXPR_BITWISE_DATA,
+	NFTNL_EXPR_BITWISE_SREG2,
 	__NFTNL_EXPR_BITWISE_MAX
 };
 
src/expr/bitwise.c +59 -2

117 lines not on this page · raw message

Signature · 1 line
2.30.2