Skip to contentSkip to conversation

netfilter: bitwise: support variable RHS operands

PATCH In review Jeremy Sowden 2 participants 4 messages Feb 24, 2020 – Mar 2, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover netfilter: bitwise: support variable RHS operands

Currently bitwise boolean operations can only have one variable operand because the mask and xor values have to be passed as immediate data. Support operations with two variable operands by allowing the mask and xor to be passed in registers.

There is a preliminary patch that renames a couple of variables.

Jeremy Sowden (2):
netfilter: bitwise: use more descriptive variable-names.
netfilter: bitwise: add support for passing mask and xor values in
registers.

 include/uapi/linux/netfilter/nf_tables.h |   4 +
 net/netfilter/nft_bitwise.c              | 120 +++++++++++++++++------
 2 files changed, 94 insertions(+), 30 deletions(-)
Signature · 1 line
2.25.0
#1 lore raw

PATCH 1/2 netfilter: bitwise: use more descriptive variable-names.

Name the mask and xor data variables, "mask" and "xor," instead of "d1" and "d2."

---
 net/netfilter/nft_bitwise.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
net/netfilter/nft_bitwise.c +7 -7
index 0ed2281f03be..bc37d6c59db4 100644
@@ -93,7 +93,7 @@ static const struct nla_policy nft_bitwise_policy[NFTA_BITWISE_MAX + 1] = {
 static int nft_bitwise_init_bool(struct nft_bitwise *priv,
 				 const struct nlattr *const tb[])
 {
-	struct nft_data_desc d1, d2;
+	struct nft_data_desc mask, xor;
 	int err;
 
 	if (tb[NFTA_BITWISE_DATA])
@@ -103,29 +103,29 @@ static int nft_bitwise_init_bool(struct nft_bitwise *priv,
 	    !tb[NFTA_BITWISE_XOR])
 		return -EINVAL;
 
-	err = nft_data_init(NULL, &priv->mask, sizeof(priv->mask), &d1,
+	err = nft_data_init(NULL, &priv->mask, sizeof(priv->mask), &mask,
 			    tb[NFTA_BITWISE_MASK]);
 	if (err < 0)
 		return err;
-	if (d1.type != NFT_DATA_VALUE || d1.len != priv->len) {
+	if (mask.type != NFT_DATA_VALUE || mask.len != priv->len) {
 		err = -EINVAL;
 		goto err1;
 	}
 
-	err = nft_data_init(NULL, &priv->xor, sizeof(priv->xor), &d2,
+	err = nft_data_init(NULL, &priv->xor, sizeof(priv->xor), &xor,
 			    tb[NFTA_BITWISE_XOR]);
 	if (err < 0)
 		goto err1;
-	if (d2.type != NFT_DATA_VALUE || d2.len != priv->len) {
+	if (xor.type != NFT_DATA_VALUE || xor.len != priv->len) {
 		err = -EINVAL;
 		goto err2;
 	}
 
 	return 0;
 err2:
-	nft_data_release(&priv->xor, d2.type);
+	nft_data_release(&priv->xor, xor.type);
 err1:
-	nft_data_release(&priv->mask, d1.type);
+	nft_data_release(&priv->mask, mask.type);
 	return err;
 }
 
Signature · 1 line
2.25.0
#2 lore raw

PATCH 2/2 netfilter: bitwise: add support for passing mask and xor values in registers.

In reply to Jeremy Sowden

Currently bitwise boolean operations can only have one variable operand because the mask and xor values have to be passed as immediate data. Support operations with two variable operands by allowing the mask and xor to be passed in registers.

---
 include/uapi/linux/netfilter/nf_tables.h |   4 +
 net/netfilter/nft_bitwise.c              | 118 +++++++++++++++++------
 2 files changed, 93 insertions(+), 29 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +4 -0
index 9c3d2d04d6a1..bd48b5358890 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)
net/netfilter/nft_bitwise.c +89 -29

171 lines not on this page · raw message

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

Currently bitwise boolean operations can only have one variable operand because the mask and xor values have to be passed as immediate data. Support operations with two variable operands by allowing the mask and xor to be passed in registers.

Series applied, thanks.