From: wenxu@ucloud.cn
To: pablo@netfilter.org, fw@strlen.de
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH nf-next v5 2/2] netfilter: nft_fwd_netdev: add fw_netdev action support
Date: Wed, 21 Aug 2019 12:56:39 +0800 [thread overview]
Message-ID: <1566363399-30976-3-git-send-email-wenxu@ucloud.cn> (raw)
In-Reply-To: <1566363399-30976-1-git-send-email-wenxu@ucloud.cn>
From: wenxu <wenxu@ucloud.cn>
fwd_netdev action offload:
nft --debug=netlink add rule netdev firewall aclout ip daddr 10.0.1.7 fwd to eth0
Signed-off-by: wenxu <wenxu@ucloud.cn>
---
v5: no offload_actions callback
net/netfilter/nft_fwd_netdev.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/net/netfilter/nft_fwd_netdev.c b/net/netfilter/nft_fwd_netdev.c
index 61b7f93..8c52765 100644
--- a/net/netfilter/nft_fwd_netdev.c
+++ b/net/netfilter/nft_fwd_netdev.c
@@ -15,6 +15,7 @@
#include <net/netfilter/nf_dup_netdev.h>
#include <net/neighbour.h>
#include <net/ip.h>
+#include <net/netfilter/nf_tables_offload.h>
struct nft_fwd_netdev {
enum nft_registers sreg_dev:8;
@@ -63,6 +64,30 @@ static int nft_fwd_netdev_dump(struct sk_buff *skb, const struct nft_expr *expr)
return -1;
}
+static int nft_fwd_netdev_offload(struct nft_offload_ctx *ctx,
+ struct nft_flow_rule *flow,
+ const struct nft_expr *expr)
+{
+ const struct nft_fwd_netdev *priv = nft_expr_priv(expr);
+ struct nft_offload_reg *reg = &ctx->regs[priv->sreg_dev];
+ const struct nft_data *data = ®->data;
+ struct flow_action_entry *entry;
+ struct net_device *dev;
+ int oif = -1;
+
+ entry = &flow->rule->action.entries[ctx->num_actions++];
+
+ memcpy(&oif, data->data, sizeof(oif));
+ dev = __dev_get_by_index(ctx->net, oif);
+ if (!dev)
+ return -EOPNOTSUPP;
+
+ entry->id = FLOW_ACTION_REDIRECT;
+ entry->dev = dev;
+
+ return 0;
+}
+
struct nft_fwd_neigh {
enum nft_registers sreg_dev:8;
enum nft_registers sreg_addr:8;
@@ -194,6 +219,7 @@ static int nft_fwd_neigh_dump(struct sk_buff *skb, const struct nft_expr *expr)
.eval = nft_fwd_netdev_eval,
.init = nft_fwd_netdev_init,
.dump = nft_fwd_netdev_dump,
+ .offload = nft_fwd_netdev_offload,
};
static const struct nft_expr_ops *
--
1.8.3.1
prev parent reply other threads:[~2019-08-21 4:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-21 4:56 [PATCH nf-next v5 0/2] netfilter: nf_tables_offload: support fwd_netdev offload wenxu
2019-08-21 4:56 ` [PATCH nf-next v5 1/2] netfilter: nf_flow_offload: add net in offload_ctx wenxu
2019-09-02 6:12 ` wenxu
2019-08-21 4:56 ` wenxu [this message]
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=1566363399-30976-3-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).