netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: [PATCH 05/17] netfilter: nft_bitwise: add offload support
Date: Tue, 13 Aug 2019 20:36:49 +0200	[thread overview]
Message-ID: <20190813183701.4002-6-pablo@netfilter.org> (raw)
In-Reply-To: <20190813183701.4002-1-pablo@netfilter.org>

Extract mask from bitwise operation and store it into the corresponding
context register so the cmp instruction can set the mask accordingly.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nft_bitwise.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/net/netfilter/nft_bitwise.c b/net/netfilter/nft_bitwise.c
index b310b637b550..1f04ed5c518c 100644
--- a/net/netfilter/nft_bitwise.c
+++ b/net/netfilter/nft_bitwise.c
@@ -13,6 +13,7 @@
 #include <linux/netfilter/nf_tables.h>
 #include <net/netfilter/nf_tables_core.h>
 #include <net/netfilter/nf_tables.h>
+#include <net/netfilter/nf_tables_offload.h>
 
 struct nft_bitwise {
 	enum nft_registers	sreg:8;
@@ -126,12 +127,30 @@ static int nft_bitwise_dump(struct sk_buff *skb, const struct nft_expr *expr)
 	return -1;
 }
 
+static struct nft_data zero;
+
+static int nft_bitwise_offload(struct nft_offload_ctx *ctx,
+                               struct nft_flow_rule *flow,
+                               const struct nft_expr *expr)
+{
+	const struct nft_bitwise *priv = nft_expr_priv(expr);
+
+	if (memcmp(&priv->xor, &zero, sizeof(priv->xor) ||
+	    priv->sreg != priv->dreg))
+		return -EOPNOTSUPP;
+
+	memcpy(&ctx->regs[priv->dreg].mask, &priv->mask, sizeof(priv->mask));
+
+	return 0;
+}
+
 static const struct nft_expr_ops nft_bitwise_ops = {
 	.type		= &nft_bitwise_type,
 	.size		= NFT_EXPR_SIZE(sizeof(struct nft_bitwise)),
 	.eval		= nft_bitwise_eval,
 	.init		= nft_bitwise_init,
 	.dump		= nft_bitwise_dump,
+	.offload	= nft_bitwise_offload,
 };
 
 struct nft_expr_type nft_bitwise_type __read_mostly = {
-- 
2.11.0



  parent reply	other threads:[~2019-08-13 18:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-13 18:36 [PATCH 00/17] Netfilter/IPVS updates for net-next Pablo Neira Ayuso
2019-08-13 18:36 ` [PATCH 01/17] netfilter: synproxy: rename mss synproxy_options field Pablo Neira Ayuso
2019-08-13 18:36 ` [PATCH 02/17] netfilter: conntrack: use shared sysctl constants Pablo Neira Ayuso
2019-08-13 18:36 ` [PATCH 03/17] ipvs: Improve robustness to the ipvs sysctl Pablo Neira Ayuso
2019-08-13 18:36 ` [PATCH 04/17] netfilter: remove unnecessary spaces Pablo Neira Ayuso
2019-08-13 18:36 ` Pablo Neira Ayuso [this message]
2019-08-13 18:36 ` [PATCH 06/17] netfilter: nf_tables: store data in offload context registers Pablo Neira Ayuso
2019-08-13 18:36 ` [PATCH 07/17] netfilter: inline four headers files into another one Pablo Neira Ayuso
2019-08-13 18:36 ` [PATCH 08/17] netfilter: add missing includes to a number of header-files Pablo Neira Ayuso
2019-08-13 18:36 ` [PATCH 09/17] netfilter: add missing IS_ENABLED(CONFIG_BRIDGE_NETFILTER) checks to header-file Pablo Neira Ayuso
2019-08-14  1:44 ` [PATCH 00/17] Netfilter/IPVS updates for net-next Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190813183701.4002-6-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).