From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: [PATCH 10/22] netfilter: nft_masq: add inet support
Date: Mon, 15 Apr 2019 19:00:16 +0200 [thread overview]
Message-ID: <20190415170028.3470-11-pablo@netfilter.org> (raw)
In-Reply-To: <20190415170028.3470-1-pablo@netfilter.org>
From: Florian Westphal <fw@strlen.de>
This allows use of a single masquerade rule in nat inet family
to handle both ipv4 and ipv6.
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nft_masq.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/net/netfilter/nft_masq.c b/net/netfilter/nft_masq.c
index bee156eaa400..35a1794acf4c 100644
--- a/net/netfilter/nft_masq.c
+++ b/net/netfilter/nft_masq.c
@@ -218,6 +218,61 @@ static inline int nft_masq_module_init_ipv6(void) { return 0; }
static inline void nft_masq_module_exit_ipv6(void) {}
#endif
+#ifdef CONFIG_NF_TABLES_INET
+static void nft_masq_inet_eval(const struct nft_expr *expr,
+ struct nft_regs *regs,
+ const struct nft_pktinfo *pkt)
+{
+ switch (nft_pf(pkt)) {
+ case NFPROTO_IPV4:
+ return nft_masq_ipv4_eval(expr, regs, pkt);
+ case NFPROTO_IPV6:
+ return nft_masq_ipv6_eval(expr, regs, pkt);
+ }
+
+ WARN_ON_ONCE(1);
+}
+
+static void
+nft_masq_inet_destroy(const struct nft_ctx *ctx, const struct nft_expr *expr)
+{
+ nf_ct_netns_put(ctx->net, NFPROTO_INET);
+}
+
+static struct nft_expr_type nft_masq_inet_type;
+static const struct nft_expr_ops nft_masq_inet_ops = {
+ .type = &nft_masq_inet_type,
+ .size = NFT_EXPR_SIZE(sizeof(struct nft_masq)),
+ .eval = nft_masq_inet_eval,
+ .init = nft_masq_init,
+ .destroy = nft_masq_inet_destroy,
+ .dump = nft_masq_dump,
+ .validate = nft_masq_validate,
+};
+
+static struct nft_expr_type nft_masq_inet_type __read_mostly = {
+ .family = NFPROTO_INET,
+ .name = "masq",
+ .ops = &nft_masq_inet_ops,
+ .policy = nft_masq_policy,
+ .maxattr = NFTA_MASQ_MAX,
+ .owner = THIS_MODULE,
+};
+
+static int __init nft_masq_module_init_inet(void)
+{
+ return nft_register_expr(&nft_masq_inet_type);
+}
+
+static void nft_masq_module_exit_inet(void)
+{
+ nft_unregister_expr(&nft_masq_inet_type);
+}
+#else
+static inline int nft_masq_module_init_inet(void) { return 0; }
+static inline void nft_masq_module_exit_inet(void) {}
+#endif
+
static int __init nft_masq_module_init(void)
{
int ret;
@@ -226,8 +281,15 @@ static int __init nft_masq_module_init(void)
if (ret < 0)
return ret;
+ ret = nft_masq_module_init_inet();
+ if (ret < 0) {
+ nft_masq_module_exit_ipv6();
+ return ret;
+ }
+
ret = nft_register_expr(&nft_masq_ipv4_type);
if (ret < 0) {
+ nft_masq_module_exit_inet();
nft_masq_module_exit_ipv6();
return ret;
}
@@ -235,6 +297,7 @@ static int __init nft_masq_module_init(void)
ret = nf_nat_masquerade_ipv4_register_notifier();
if (ret < 0) {
nft_masq_module_exit_ipv6();
+ nft_masq_module_exit_inet();
nft_unregister_expr(&nft_masq_ipv4_type);
return ret;
}
@@ -245,6 +308,7 @@ static int __init nft_masq_module_init(void)
static void __exit nft_masq_module_exit(void)
{
nft_masq_module_exit_ipv6();
+ nft_masq_module_exit_inet();
nft_unregister_expr(&nft_masq_ipv4_type);
nf_nat_masquerade_ipv4_unregister_notifier();
}
--
2.11.0
next prev parent reply other threads:[~2019-04-15 17:01 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-15 17:00 [PATCH 00/22] Netfilter/IPVS updates for net-next Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 01/22] time: Introduce jiffies64_to_msecs() Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 02/22] netfilter: nf_tables: remove unused parameter ctx Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 03/22] netfilter: nft_redir: Make nft_redir_dump static Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 04/22] netfilter: nf_flowtable: skip device lookup from interface index Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 05/22] ipvs: allow tunneling with gue encapsulation Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 06/22] netfilter: optimize nf_inet_addr_cmp Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 07/22] netfilter: nat: add inet family nat support Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 08/22] netfilter: nf_tables: merge route type into core Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 09/22] netfilter: replace NF_NAT_NEEDED with IS_ENABLED(CONFIG_NF_NAT) Pablo Neira Ayuso
2019-04-15 17:00 ` Pablo Neira Ayuso [this message]
2019-04-15 17:00 ` [PATCH 11/22] netfilter: nft_redir: add inet support Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 12/22] kselftests: extend nft_nat with inet family based nat hooks Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 13/22] netfilter: nft_osf: Add version option support Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 14/22] netfilter: make two functions static Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 15/22] netfilter: nf_nat: merge ip/ip6 masquerade headers Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 16/22] netfilter: x_tables: merge ip and ipv6 masquerade modules Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 17/22] netfilter: nf_nat_masquerade: unify ipv4/6 notifier registration Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 18/22] selftests: netfilter: add ebtables broute test case Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 19/22] bridge: reduce size of input cb to 16 bytes Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 20/22] bridge: netfilter: unroll NF_HOOK helper in bridge input path Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 21/22] bridge: broute: make broute a real ebtables table Pablo Neira Ayuso
2019-04-15 17:00 ` [PATCH 22/22] bridge: only include nf_queue.h if needed Pablo Neira Ayuso
2019-04-15 19:14 ` [PATCH 00/22] Netfilter/IPVS updates for net-next David Miller
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=20190415170028.3470-11-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.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).