netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: [PATCH 05/20] netfilter: ipt_CLUSTERIP: make proc directory per net namespace
Date: Mon,  4 Nov 2013 22:50:27 +0100	[thread overview]
Message-ID: <1383601842-4570-6-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1383601842-4570-1-git-send-email-pablo@netfilter.org>

From: Gao feng <gaofeng@cn.fujitsu.com>

Create /proc/net/ipt_CLUSTERIP directory for per net namespace.
Right now,only allow to create entries under the ipt_CLUSTERIP
in init net namespace.

Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/ipv4/netfilter/ipt_CLUSTERIP.c |   70 ++++++++++++++++++++++++++----------
 1 file changed, 51 insertions(+), 19 deletions(-)

diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
index 0b732ef..e66b91b 100644
--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
@@ -28,6 +28,7 @@
 #include <linux/netfilter_ipv4/ipt_CLUSTERIP.h>
 #include <net/netfilter/nf_conntrack.h>
 #include <net/net_namespace.h>
+#include <net/netns/generic.h>
 #include <net/checksum.h>
 #include <net/ip.h>
 
@@ -64,9 +65,16 @@ static DEFINE_SPINLOCK(clusterip_lock);
 
 #ifdef CONFIG_PROC_FS
 static const struct file_operations clusterip_proc_fops;
-static struct proc_dir_entry *clusterip_procdir;
 #endif
 
+static int clusterip_net_id __read_mostly;
+
+struct clusterip_net {
+#ifdef CONFIG_PROC_FS
+	struct proc_dir_entry *procdir;
+#endif
+};
+
 static inline void
 clusterip_config_get(struct clusterip_config *c)
 {
@@ -158,6 +166,7 @@ clusterip_config_init(const struct ipt_clusterip_tgt_info *i, __be32 ip,
 			struct net_device *dev)
 {
 	struct clusterip_config *c;
+	struct clusterip_net *cn = net_generic(&init_net, clusterip_net_id);
 
 	c = kzalloc(sizeof(*c), GFP_ATOMIC);
 	if (!c)
@@ -180,7 +189,7 @@ clusterip_config_init(const struct ipt_clusterip_tgt_info *i, __be32 ip,
 		/* create proc dir entry */
 		sprintf(buffer, "%pI4", &ip);
 		c->pde = proc_create_data(buffer, S_IWUSR|S_IRUSR,
-					  clusterip_procdir,
+					  cn->procdir,
 					  &clusterip_proc_fops, c);
 		if (!c->pde) {
 			kfree(c);
@@ -698,48 +707,71 @@ static const struct file_operations clusterip_proc_fops = {
 
 #endif /* CONFIG_PROC_FS */
 
+static int clusterip_net_init(struct net *net)
+{
+#ifdef CONFIG_PROC_FS
+	struct clusterip_net *cn = net_generic(net, clusterip_net_id);
+
+	cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
+	if (!cn->procdir) {
+		pr_err("Unable to proc dir entry\n");
+		return -ENOMEM;
+	}
+#endif /* CONFIG_PROC_FS */
+
+	return 0;
+}
+
+static void clusterip_net_exit(struct net *net)
+{
+#ifdef CONFIG_PROC_FS
+	struct clusterip_net *cn = net_generic(net, clusterip_net_id);
+	proc_remove(cn->procdir);
+#endif
+}
+
+static struct pernet_operations clusterip_net_ops = {
+	.init = clusterip_net_init,
+	.exit = clusterip_net_exit,
+	.id   = &clusterip_net_id,
+	.size = sizeof(struct clusterip_net),
+};
+
 static int __init clusterip_tg_init(void)
 {
 	int ret;
 
-	ret = xt_register_target(&clusterip_tg_reg);
+	ret = register_pernet_subsys(&clusterip_net_ops);
 	if (ret < 0)
 		return ret;
 
+	ret = xt_register_target(&clusterip_tg_reg);
+	if (ret < 0)
+		goto cleanup_subsys;
+
 	ret = nf_register_hook(&cip_arp_ops);
 	if (ret < 0)
 		goto cleanup_target;
 
-#ifdef CONFIG_PROC_FS
-	clusterip_procdir = proc_mkdir("ipt_CLUSTERIP", init_net.proc_net);
-	if (!clusterip_procdir) {
-		pr_err("Unable to proc dir entry\n");
-		ret = -ENOMEM;
-		goto cleanup_hook;
-	}
-#endif /* CONFIG_PROC_FS */
-
 	pr_info("ClusterIP Version %s loaded successfully\n",
 		CLUSTERIP_VERSION);
+
 	return 0;
 
-#ifdef CONFIG_PROC_FS
-cleanup_hook:
-	nf_unregister_hook(&cip_arp_ops);
-#endif /* CONFIG_PROC_FS */
 cleanup_target:
 	xt_unregister_target(&clusterip_tg_reg);
+cleanup_subsys:
+	unregister_pernet_subsys(&clusterip_net_ops);
 	return ret;
 }
 
 static void __exit clusterip_tg_exit(void)
 {
 	pr_info("ClusterIP Version %s unloading\n", CLUSTERIP_VERSION);
-#ifdef CONFIG_PROC_FS
-	proc_remove(clusterip_procdir);
-#endif
+
 	nf_unregister_hook(&cip_arp_ops);
 	xt_unregister_target(&clusterip_tg_reg);
+	unregister_pernet_subsys(&clusterip_net_ops);
 
 	/* Wait for completion of call_rcu_bh()'s (clusterip_config_rcu_free) */
 	rcu_barrier_bh();
-- 
1.7.10.4

  parent reply	other threads:[~2013-11-04 21:50 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-04 21:50 [PATCH 00/20] Netfilter/IPVS updates for net-next Pablo Neira Ayuso
2013-11-04 21:50 ` [PATCH 01/20] ipvs: fix the IPVS_CMD_ATTR_MAX definition Pablo Neira Ayuso
2013-11-04 21:50 ` [PATCH 02/20] ipvs: avoid rcu_barrier during netns cleanup Pablo Neira Ayuso
2013-11-04 21:50 ` [PATCH 03/20] ipvs: improved SH fallback strategy Pablo Neira Ayuso
2013-11-04 21:50 ` [PATCH 04/20] netfilter: xt_socket: use sock_gen_put() Pablo Neira Ayuso
2013-11-04 21:50 ` Pablo Neira Ayuso [this message]
2013-11-04 21:50 ` [PATCH 06/20] netfilter: ipt_CLUSTERIP: make clusterip_list per net namespace Pablo Neira Ayuso
2013-11-04 21:50 ` [PATCH 07/20] netfilter: ipt_CLUSTERIP: make clusterip_lock " Pablo Neira Ayuso
2013-11-04 21:50 ` [PATCH 08/20] netfilter: ipt_CLUSTERIP: add parameter net in clusterip_config_find_get Pablo Neira Ayuso
2013-11-04 21:50 ` [PATCH 09/20] netfilter: ipt_CLUSTERIP: create proc entry under proper ipt_CLUSTERIP directory Pablo Neira Ayuso
2013-11-04 21:50 ` [PATCH 10/20] netfilter: ipt_CLUSTERIP: use proper net namespace to operate CLUSTERIP Pablo Neira Ayuso
2013-11-04 21:50 ` [PATCH 11/20] netfilter: ipset: Use netlink callback dump args only Pablo Neira Ayuso
2013-11-04 21:50 ` [PATCH 12/20] netfilter: ipset: The unnamed union initialization may lead to compilation error Pablo Neira Ayuso
2013-11-04 21:50 ` [PATCH 13/20] netfilter: ip6t_REJECT: skip checksum verification for outgoing ipv6 packets Pablo Neira Ayuso
2013-11-04 21:50 ` [PATCH 14/20] netfilter:ipset: Fix memory allocation for bitmap:port Pablo Neira Ayuso
2013-11-04 21:50 ` [PATCH 15/20] netfilter: ipset: remove duplicate define Pablo Neira Ayuso
2013-11-04 21:50 ` [PATCH 16/20] bridge: netfilter: orphan skb before invoking ip netfilter hooks Pablo Neira Ayuso
2013-11-04 21:50 ` [PATCH 17/20] net: ipvs: sctp: add missing verdict assignments in sctp_conn_schedule Pablo Neira Ayuso
2013-11-04 21:50 ` [PATCH 18/20] net: ipvs: sctp: do not recalc sctp csum when ports didn't change Pablo Neira Ayuso
2013-11-04 21:50 ` [PATCH 19/20] netfilter: introduce nf_conn_acct structure Pablo Neira Ayuso
2013-11-04 21:50 ` [PATCH 20/20] netfilter: ctnetlink: account both directions in one step Pablo Neira Ayuso
2013-11-05  0:47 ` [PATCH 00/20] 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=1383601842-4570-6-git-send-email-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).