From: wenxu@ucloud.cn
To: pablo@netfilter.org, fw@strlen.de
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH nf-next v2 06/11] netfilter: nft_payload: add nft_set_payload offload support
Date: Thu, 25 Jul 2019 21:34:01 +0800 [thread overview]
Message-ID: <1564061644-31189-7-git-send-email-wenxu@ucloud.cn> (raw)
In-Reply-To: <1564061644-31189-1-git-send-email-wenxu@ucloud.cn>
From: wenxu <wenxu@ucloud.cn>
currently payload set only support ll header
nft --debug=netlink add rule netdev firewall aclout ip daddr 10.0.1.7 @ll,0,48
set 0x00002e9ca06e2596 @ll,48,48 set 0xfaffffffffff fwd to eth0
Signed-off-by: wenxu <wenxu@ucloud.cn>
---
net/netfilter/nft_payload.c | 56 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
index 36efa1c..544fc40 100644
--- a/net/netfilter/nft_payload.c
+++ b/net/netfilter/nft_payload.c
@@ -572,12 +572,68 @@ static int nft_payload_set_dump(struct sk_buff *skb, const struct nft_expr *expr
return -1;
}
+static int nft_payload_set_offload(struct nft_offload_ctx *ctx,
+ struct nft_flow_rule *flow,
+ const struct nft_expr *expr)
+{
+ const struct nft_payload_set *priv = nft_expr_priv(expr);
+ struct nft_offload_reg *reg = &ctx->regs[priv->sreg];
+ const struct nft_data *data = ®->action.data;
+ struct flow_action_entry *entry;
+ u32 len = priv->len;
+ u32 offset, last;
+ int n_actions, i;
+
+ if (priv->base != NFT_PAYLOAD_LL_HEADER || len > 16)
+ return -EOPNOTSUPP;
+
+ offset = priv->offset;
+ n_actions = len >> 2;
+ last = len & 0x3;
+
+ for (i = 0; i < n_actions; i++) {
+ entry = &flow->rule->action.entries[ctx->num_actions++];
+
+ entry->id = FLOW_ACTION_MANGLE;
+ entry->mangle.htype = FLOW_ACT_MANGLE_HDR_TYPE_ETH;
+ entry->mangle.mask = 0;
+ entry->mangle.val = data->data[i];
+ entry->mangle.offset = offset;
+ offset = offset + 4;
+ }
+
+ if (last) {
+ entry = &flow->rule->action.entries[ctx->num_actions++];
+
+ entry->id = FLOW_ACTION_MANGLE;
+ entry->mangle.htype = FLOW_ACT_MANGLE_HDR_TYPE_ETH;
+ entry->mangle.mask = ~((1 << (last * 8)) - 1);
+ entry->mangle.val = data->data[i];
+ entry->mangle.offset = offset;
+ }
+
+ return 0;
+}
+
+static int nft_payload_set_offload_actions(const struct nft_expr *expr)
+{
+ const struct nft_payload_set *priv = nft_expr_priv(expr);
+ u32 len = priv->len;
+
+ if (priv->base != NFT_PAYLOAD_LL_HEADER || len > 16)
+ return 0;
+
+ return (len >> 2) + !!(len & 3);
+}
+
static const struct nft_expr_ops nft_payload_set_ops = {
.type = &nft_payload_type,
.size = NFT_EXPR_SIZE(sizeof(struct nft_payload_set)),
.eval = nft_payload_set_eval,
.init = nft_payload_set_init,
.dump = nft_payload_set_dump,
+ .offload = nft_payload_set_offload,
+ .offload_actions = nft_payload_set_offload_actions,
};
static const struct nft_expr_ops *
--
1.8.3.1
next prev parent reply other threads:[~2019-07-25 13:34 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-25 13:33 [PATCH nf-next v2 00/11] netfilter: nf_tables_offload: support more expr and obj offload wenxu
2019-07-25 13:33 ` [PATCH nf-next v2 01/11] netfilter: nf_flow_offload: add net in offload_ctx wenxu
2019-07-25 13:33 ` [PATCH nf-next v2 02/11] netfilter: nf_tables_offload: add offload_actions callback wenxu
2019-07-25 13:33 ` [PATCH nf-next v2 03/11] netfilter: nf_tables_offload: split nft_offload_reg to match and action type wenxu
2019-08-01 12:15 ` Pablo Neira Ayuso
2019-08-01 13:41 ` wenxu
2019-07-25 13:33 ` [PATCH nf-next v2 04/11] netfilter: nft_immediate: add offload support for actions wenxu
2019-07-25 13:34 ` [PATCH nf-next v2 05/11] netfilter: nft_fwd_netdev: add fw_netdev action support wenxu
2019-07-25 13:34 ` wenxu [this message]
2019-07-25 13:34 ` [PATCH nf-next v2 07/11] netfilter: nft_tunnel: support NFT_TUNNEL_SRC/DST_IP match wenxu
2019-07-25 13:34 ` [PATCH nf-next v2 08/11] netfilter: nft_tunnel: support tunnel meta match offload wenxu
2019-07-25 13:34 ` [PATCH nf-next v2 09/11] netfilter: nft_tunnel: add NFTA_TUNNEL_KEY_RELEASE action wenxu
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=1564061644-31189-7-git-send-email-wenxu@ucloud.cn \
--to=wenxu@ucloud.cn \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.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).