Commit bd8699e9 authored by Pablo Neira Ayuso's avatar Pablo Neira Ayuso

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: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 7e59b3fe
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <linux/netfilter/nf_tables.h> #include <linux/netfilter/nf_tables.h>
#include <net/netfilter/nf_tables_core.h> #include <net/netfilter/nf_tables_core.h>
#include <net/netfilter/nf_tables.h> #include <net/netfilter/nf_tables.h>
#include <net/netfilter/nf_tables_offload.h>
struct nft_bitwise { struct nft_bitwise {
enum nft_registers sreg:8; enum nft_registers sreg:8;
...@@ -126,12 +127,30 @@ static int nft_bitwise_dump(struct sk_buff *skb, const struct nft_expr *expr) ...@@ -126,12 +127,30 @@ static int nft_bitwise_dump(struct sk_buff *skb, const struct nft_expr *expr)
return -1; 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 = { static const struct nft_expr_ops nft_bitwise_ops = {
.type = &nft_bitwise_type, .type = &nft_bitwise_type,
.size = NFT_EXPR_SIZE(sizeof(struct nft_bitwise)), .size = NFT_EXPR_SIZE(sizeof(struct nft_bitwise)),
.eval = nft_bitwise_eval, .eval = nft_bitwise_eval,
.init = nft_bitwise_init, .init = nft_bitwise_init,
.dump = nft_bitwise_dump, .dump = nft_bitwise_dump,
.offload = nft_bitwise_offload,
}; };
struct nft_expr_type nft_bitwise_type __read_mostly = { struct nft_expr_type nft_bitwise_type __read_mostly = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment