From: wenxu@ucloud.cn
To: pablo@netfilter.org, fw@strlen.de
Cc: netfilter-devel@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH nf-next 3/3] netfilter: nft_nat: add nft_bridge_nat_type support
Date: Mon, 8 Jul 2019 16:29:27 +0800 [thread overview]
Message-ID: <1562574567-8293-3-git-send-email-wenxu@ucloud.cn> (raw)
In-Reply-To: <1562574567-8293-1-git-send-email-wenxu@ucloud.cn>
From: wenxu <wenxu@ucloud.cn>
Add nft_bridge_nat_type to configure nat rule in bridge family
Signed-off-by: wenxu <wenxu@ucloud.cn>
---
net/netfilter/nft_nat.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 47 insertions(+), 2 deletions(-)
diff --git a/net/netfilter/nft_nat.c b/net/netfilter/nft_nat.c
index c3c93e9..ba396851 100644
--- a/net/netfilter/nft_nat.c
+++ b/net/netfilter/nft_nat.c
@@ -136,7 +136,9 @@ static int nft_nat_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
return -EINVAL;
family = ntohl(nla_get_be32(tb[NFTA_NAT_FAMILY]));
- if (ctx->family != NFPROTO_INET && ctx->family != family)
+ if (ctx->family != NFPROTO_INET &&
+ ctx->family != NFPROTO_BRIDGE &&
+ ctx->family != family)
return -EOPNOTSUPP;
switch (family) {
@@ -318,6 +320,40 @@ static void nft_nat_inet_module_exit(void)
static void nft_nat_inet_module_exit(void) { }
#endif
+#ifdef CONFIG_NF_TABLES_BRIDGE
+static const struct nft_expr_ops nft_nat_bridge_ops = {
+ .type = &nft_nat_type,
+ .size = NFT_EXPR_SIZE(sizeof(struct nft_nat)),
+ .eval = nft_nat_eval,
+ .init = nft_nat_init,
+ .destroy = nft_nat_destroy,
+ .dump = nft_nat_dump,
+ .validate = nft_nat_validate,
+};
+
+static struct nft_expr_type nft_bridge_nat_type __read_mostly = {
+ .name = "nat",
+ .family = NFPROTO_BRIDGE,
+ .ops = &nft_nat_bridge_ops,
+ .policy = nft_nat_policy,
+ .maxattr = NFTA_NAT_MAX,
+ .owner = THIS_MODULE,
+};
+
+static int nft_nat_bridge_module_init(void)
+{
+ return nft_register_expr(&nft_bridge_nat_type);
+}
+
+static void nft_nat_bridge_module_exit(void)
+{
+ nft_unregister_expr(&nft_bridge_nat_type);
+}
+#else
+static int nft_nat_bridge_module_init(void) { return 0; }
+static void nft_nat_bridge_module_exit(void) { }
+#endif
+
static int __init nft_nat_module_init(void)
{
int ret = nft_nat_inet_module_init();
@@ -325,15 +361,24 @@ static int __init nft_nat_module_init(void)
if (ret)
return ret;
+ ret = nft_nat_bridge_module_init();
+ if (ret) {
+ nft_nat_inet_module_exit();
+ return ret;
+ }
+
ret = nft_register_expr(&nft_nat_type);
- if (ret)
+ if (ret) {
+ nft_nat_bridge_module_exit();
nft_nat_inet_module_exit();
+ }
return ret;
}
static void __exit nft_nat_module_exit(void)
{
+ nft_nat_bridge_module_exit();
nft_nat_inet_module_exit();
nft_unregister_expr(&nft_nat_type);
}
--
1.8.3.1
next prev parent reply other threads:[~2019-07-08 8:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-08 8:29 [PATCH nf-next 1/3] netfilter: nf_nat_proto: add nf_nat_bridge_ops support wenxu
2019-07-08 8:29 ` [PATCH nf-next 2/3] netfilter: nft_chain_nat: add nft_chain_nat_bridge support wenxu
2019-07-08 8:29 ` wenxu [this message]
2019-07-08 14:17 ` [PATCH nf-next 1/3] netfilter: nf_nat_proto: add nf_nat_bridge_ops support Florian Westphal
2019-07-09 2:56 ` wenxu
2019-07-09 10:42 ` Florian Westphal
2019-07-09 13:38 ` wenxu
2019-07-09 7:04 ` kbuild test robot
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=1562574567-8293-3-git-send-email-wenxu@ucloud.cn \
--to=wenxu@ucloud.cn \
--cc=fw@strlen.de \
--cc=netdev@vger.kernel.org \
--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).