Skip to content

Commit bd8699e

Browse files
committed
netfilter: nft_bitwise: add offload support
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>
1 parent 7e59b3f commit bd8699e

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎net/netfilter/nft_bitwise.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/netfilter/nf_tables.h>
1414
#include <net/netfilter/nf_tables_core.h>
1515
#include <net/netfilter/nf_tables.h>
16+
#include <net/netfilter/nf_tables_offload.h>
1617

1718
struct nft_bitwise {
1819
enum nft_registers sreg:8;
@@ -126,12 +127,30 @@ static int nft_bitwise_dump(struct sk_buff *skb, const struct nft_expr *expr)
126127
return -1;
127128
}
128129

130+
static struct nft_data zero;
131+
132+
static int nft_bitwise_offload(struct nft_offload_ctx *ctx,
133+
struct nft_flow_rule *flow,
134+
const struct nft_expr *expr)
135+
{
136+
const struct nft_bitwise *priv = nft_expr_priv(expr);
137+
138+
if (memcmp(&priv->xor, &zero, sizeof(priv->xor) ||
139+
priv->sreg != priv->dreg))
140+
return -EOPNOTSUPP;
141+
142+
memcpy(&ctx->regs[priv->dreg].mask, &priv->mask, sizeof(priv->mask));
143+
144+
return 0;
145+
}
146+
129147
static const struct nft_expr_ops nft_bitwise_ops = {
130148
.type = &nft_bitwise_type,
131149
.size = NFT_EXPR_SIZE(sizeof(struct nft_bitwise)),
132150
.eval = nft_bitwise_eval,
133151
.init = nft_bitwise_init,
134152
.dump = nft_bitwise_dump,
153+
.offload = nft_bitwise_offload,
135154
};
136155

137156
struct nft_expr_type nft_bitwise_type __read_mostly = {

0 commit comments

Comments
 (0)