Skip to contentSkip to conversation

ipv6: Do cleanup for ip_mr_init

PATCH Applied Wang Chen 2 participants 8 messages Jun 24, 2008 – Jul 3, 2008 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

Wang Chen

author
#0 lore raw

PATCH 1/1 ipv6: Do cleanup for ip_mr_init

If do not do it, we will get following issues:
1. Leaving junks after inet6_init failing halfway.
2. Leaving proc and notifier junks after ipv6 modules unloading.

---
 include/linux/mroute6.h |    1 +
 net/ipv6/af_inet6.c     |    5 +++++
 net/ipv6/ip6mr.c        |   10 ++++++++++
 3 files changed, 16 insertions(+), 0 deletions(-)
include/linux/mroute6.h +1 -0
index e798959..05ffaac 100644
@@ -136,6 +136,7 @@ extern int ip6_mroute_getsockopt(struct sock *, int, char __user *, int __user *
 extern int ip6_mr_input(struct sk_buff *skb);
 extern int ip6mr_ioctl(struct sock *sk, int cmd, void __user *arg);
 extern void ip6_mr_init(void);
+extern void ip6_mr_cleanup(void);
 
 struct mif_device
 {
net/ipv6/af_inet6.c +5 -0
index e84b3fd..15d4138 100644
@@ -1061,6 +1061,9 @@ netfilter_fail:
 igmp_fail:
 	ndisc_cleanup();
 ndisc_fail:
+#ifdef CONFIG_IPV6_MROUTE
+	ip6_mr_cleanup();
+#endif
 	icmpv6_cleanup();
 icmp_fail:
 	unregister_pernet_subsys(&inet6_net_ops);
@@ -1115,7 +1118,9 @@ static void __exit inet6_exit(void)
 	ipv6_netfilter_fini();
 	igmp6_cleanup();
 	ndisc_cleanup();
+#ifdef CONFIG_IPV6_MROUTE
 	icmpv6_cleanup();
+#endif
 	rawv6_exit();
 
 	unregister_pernet_subsys(&inet6_net_ops);
net/ipv6/ip6mr.c +10 -0
index 1479618..245c350 100644
@@ -973,6 +973,16 @@ void __init ip6_mr_init(void)
 #endif
 }
 
+void ip6_mr_cleanup(void)
+{
+#ifdef CONFIG_PROC_FS
+	proc_net_remove(&init_net, "ip6_mr_cache");
+	proc_net_remove(&init_net, "ip6_mr_vif");
+#endif
+	unregister_netdevice_notifier(&ip6_mr_notifier);
+	del_timer(&ipmr_expire_timer);
+	kmem_cache_destroy(mrt_cachep);
+}
 
 static int ip6mr_mfc_add(struct mf6cctl *mfc, int mrtsock)
 {
Signature · 1 line
1.5.3.4
author
#1 lore raw

Wang Chen said the following on 2008-6-24 11:42:

Quoted 10 lines

If do not do it, we will get following issues:
1. Leaving junks after inet6_init failing halfway.
2. Leaving proc and notifier junks after ipv6 modules unloading.

---
 include/linux/mroute6.h |    1 +
 net/ipv6/af_inet6.c     |    5 +++++
 net/ipv6/ip6mr.c        |   10 ++++++++++
 3 files changed, 16 insertions(+), 0 deletions(-)

Yoshifuji-san, would please take a look at this patch.

#2 lore raw
In reply to Wang Chen

In article <[email protected]> (at Tue, 24 Jun 2008 11:42:19 +0800), Wang Chen <[email protected]> says:

Quoted 15 lines

If do not do it, we will get following issues:
1. Leaving junks after inet6_init failing halfway.
2. Leaving proc and notifier junks after ipv6 modules unloading.

include/linux/mroute6.h +0 -0
index e798959..05ffaac 100644
net/ipv6/af_inet6.c +0 -0
index e84b3fd..15d4138 100644

net/ipv6/af_inet6.c static void __exit inet6_exit(void) · line 1126

Quoted 9 lines
net/ipv6/af_inet6.c +2 -0
@@ -1115,7 +1118,9 @@ static void __exit inet6_exit(void)
 	ipv6_netfilter_fini();
 	igmp6_cleanup();
 	ndisc_cleanup();
+#ifdef CONFIG_IPV6_MROUTE
 	icmpv6_cleanup();
+#endif
 	rawv6_exit();
 
 	unregister_pernet_subsys(&inet6_net_ops);

Well we really need this #ifdef ... #endif?

And well, would you please make ip6_mr_init() return error and handle it correctly?

We need to fix ipv4-side as well.

--yoshfuji

author
#3 lore raw

YOSHIFUJI Hideaki / 吉藤英明 said the following on 2008-7-2 17:18:

Quoted 25 lines

In article <[email protected]> (at Tue, 24 Jun 2008 11:42:19 +0800), Wang Chen <[email protected]> says:

Quoted 23 lines

If do not do it, we will get following issues:
1. Leaving junks after inet6_init failing halfway.
2. Leaving proc and notifier junks after ipv6 modules unloading.

include/linux/mroute6.h +0 -0
index e798959..05ffaac 100644
net/ipv6/af_inet6.c +2 -0
index e84b3fd..15d4138 100644
@@ -1115,7 +1118,9 @@ static void __exit inet6_exit(void)
 	ipv6_netfilter_fini();
 	igmp6_cleanup();
 	ndisc_cleanup();
+#ifdef CONFIG_IPV6_MROUTE
 	icmpv6_cleanup();
+#endif
 	rawv6_exit();
 
Quoted 4 lines

net/ipv6/af_inet6.c static void __exit inet6_exit(void) · line 1126

Quoted 1 line
net/ipv6/af_inet6.c +0 -0
 	unregister_pernet_subsys(&inet6_net_ops);

Well we really need this #ifdef ... #endif?

My fault.
I meant:
+#ifdef CONFIG_IPV6_MROUTE
+ ip6_mr_cleanup();
+#endif

	icmpv6_cleanup();

I will fix.

Quoted 3 lines

And well, would you please make ip6_mr_init() return error and handle it correctly?

Sure, I will do it.

Quoted 2 lines

We need to fix ipv4-side as well.

Of course, it can be done by me.

Thank you for the comments.

author
#4 lore raw

v2 [PATCH 1/2] ipv6: Do cleanup for ip6_mr_init

In reply to YOSHIFUJI Hideaki / 吉藤英明

If do not do it, we will get following issues:
1. Leaving junks after inet6_init failing halfway.
2. Leaving proc and notifier junks after ipv6 modules unloading.

---

include/linux/mroute6.h +2 -1
index e798959..4c4d6f5 100644
@@ -135,7 +135,8 @@ extern int ip6_mroute_setsockopt(struct sock *, int, char __user *, int);
 extern int ip6_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
 extern int ip6_mr_input(struct sk_buff *skb);
 extern int ip6mr_ioctl(struct sock *sk, int cmd, void __user *arg);
-extern void ip6_mr_init(void);
+extern int ip6_mr_init(void);
+extern void ip6_mr_cleanup(void);
 
 struct mif_device
 {
net/ipv6/af_inet6.c +10 -1
index e84b3fd..5cb7bb4 100644
@@ -957,7 +957,9 @@ static int __init inet6_init(void)
 	if (err)
 		goto icmp_fail;
 #ifdef CONFIG_IPV6_MROUTE
-	ip6_mr_init();
+	err = ip6_mr_init();
+	if (err)
+		goto ipmr_fail;
 #endif
 	err = ndisc_init();
 	if (err)
@@ -1061,6 +1063,10 @@ netfilter_fail:
 igmp_fail:
 	ndisc_cleanup();
 ndisc_fail:
+#ifdef CONFIG_IPV6_MROUTE
+	ip6_mr_cleanup();
+ipmr_fail:
+#endif
 	icmpv6_cleanup();
 icmp_fail:
 	unregister_pernet_subsys(&inet6_net_ops);
@@ -1115,6 +1121,9 @@ static void __exit inet6_exit(void)
 	ipv6_netfilter_fini();
 	igmp6_cleanup();
 	ndisc_cleanup();
+#ifdef CONFIG_IPV6_MROUTE
+	ip6_mr_cleanup();
+#endif
 	icmpv6_cleanup();
 	rawv6_exit();
 
net/ipv6/ip6mr.c +33 -5
index 1479618..3b785db 100644
@@ -956,23 +956,51 @@ static struct notifier_block ip6_mr_notifier = {
  *	Setup for IP multicast routing
  */
 
-void __init ip6_mr_init(void)
+int __init ip6_mr_init(void)
 {
+	int err;
+
 	mrt_cachep = kmem_cache_create("ip6_mrt_cache",
 				       sizeof(struct mfc6_cache),
 				       0, SLAB_HWCACHE_ALIGN,
 				       NULL);
 	if (!mrt_cachep)
-		panic("cannot allocate ip6_mrt_cache");
+		return -ENOMEM;
 
 	setup_timer(&ipmr_expire_timer, ipmr_expire_process, 0);
-	register_netdevice_notifier(&ip6_mr_notifier);
+	err = register_netdevice_notifier(&ip6_mr_notifier);
+	if (err)
+		goto reg_notif_fail;
+#ifdef CONFIG_PROC_FS
+	err = -ENOMEM;
+	if (!proc_net_fops_create(&init_net, "ip6_mr_vif", 0, &ip6mr_vif_fops))
+		goto proc_vif_fail;
+	if (!proc_net_fops_create(&init_net, "ip6_mr_cache",
+				     0, &ip6mr_mfc_fops))
+		goto proc_cache_fail;
+#endif
+	return 0;
+reg_notif_fail:
+	kmem_cache_destroy(mrt_cachep);
 #ifdef CONFIG_PROC_FS
-	proc_net_fops_create(&init_net, "ip6_mr_vif", 0, &ip6mr_vif_fops);
-	proc_net_fops_create(&init_net, "ip6_mr_cache", 0, &ip6mr_mfc_fops);
+proc_vif_fail:
+	unregister_netdevice_notifier(&ip6_mr_notifier);
+proc_cache_fail:
+	proc_net_remove(&init_net, "ip6_mr_vif");
 #endif
+	return err;
 }
 
+void ip6_mr_cleanup(void)
+{
+#ifdef CONFIG_PROC_FS
+	proc_net_remove(&init_net, "ip6_mr_cache");
+	proc_net_remove(&init_net, "ip6_mr_vif");
+#endif
+	unregister_netdevice_notifier(&ip6_mr_notifier);
+	del_timer(&ipmr_expire_timer);
+	kmem_cache_destroy(mrt_cachep);
+}
 
 static int ip6mr_mfc_add(struct mf6cctl *mfc, int mrtsock)
 {
#5 lore raw

Re: v2 [PATCH 1/2] ipv6: Do cleanup for ip6_mr_init

In article <[email protected]> (at Thu, 03 Jul 2008 12:13:30 +0800), Wang Chen <[email protected]> says:

Quoted 5 lines

If do not do it, we will get following issues:
1. Leaving junks after inet6_init failing halfway.
2. Leaving proc and notifier junks after ipv6 modules unloading.

Applied to my linux-2.6-next tree. Thanks.

--yoshfuji

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#7 lore raw

v2 [PATCH 2/2] ipv4: Do cleanup for ip_mr_init

Same as ip6_mr_init(), make ip_mr_init() return errno if fails. But do not do error handling in inet_init(), just print a msg.

---

include/linux/igmp.h +0 -1
index f5a1a0d..7bb3c09 100644
@@ -228,7 +228,6 @@ extern int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
 extern int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
 		struct group_filter __user *optval, int __user *optlen);
 extern int ip_mc_sf_allow(struct sock *sk, __be32 local, __be32 rmt, int dif);
-extern void ip_mr_init(void);
 extern void ip_mc_init_dev(struct in_device *);
 extern void ip_mc_destroy_dev(struct in_device *);
 extern void ip_mc_up(struct in_device *);
include/linux/mroute.h +1 -2
index de4decf..df8efd4 100644
@@ -147,8 +147,7 @@ static inline int ip_mroute_opt(int opt)
 extern int ip_mroute_setsockopt(struct sock *, int, char __user *, int);
 extern int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
 extern int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg);
-extern void ip_mr_init(void);
-
+extern int ip_mr_init(void);
 
 struct vif_device
 {
net/ipv4/af_inet.c +3 -2
index 24eca23..3bb9007 100644
@@ -1481,14 +1481,15 @@ static int __init inet_init(void)
 	 *	Initialise the multicast router
 	 */
 #if defined(CONFIG_IP_MROUTE)
-	ip_mr_init();
+	if (ip_mr_init())
+		printk(KERN_CRIT "inet_init: Cannot init ipv4 mroute\n");
 #endif
 	/*
 	 *	Initialise per-cpu ipv4 mibs
 	 */
 
 	if (init_ipv4_mibs())
-		printk(KERN_CRIT "inet_init: Cannot init ipv4 mibs\n"); ;
+		printk(KERN_CRIT "inet_init: Cannot init ipv4 mibs\n");
 
 	ipv4_proc_init();
 
net/ipv4/ipmr.c +24 -4
index 11700a4..5225587 100644
@@ -1887,16 +1887,36 @@ static struct net_protocol pim_protocol = {
  *	Setup for IP multicast routing
  */
 
-void __init ip_mr_init(void)
+int __init ip_mr_init(void)
 {
+	int err;
+
 	mrt_cachep = kmem_cache_create("ip_mrt_cache",
 				       sizeof(struct mfc_cache),
 				       0, SLAB_HWCACHE_ALIGN|SLAB_PANIC,
 				       NULL);
+	if (!mrt_cachep)
+		return -ENOMEM;
+
 	setup_timer(&ipmr_expire_timer, ipmr_expire_process, 0);
-	register_netdevice_notifier(&ip_mr_notifier);
+	err = register_netdevice_notifier(&ip_mr_notifier);
+	if (err)
+		goto reg_notif_fail;
 #ifdef CONFIG_PROC_FS
-	proc_net_fops_create(&init_net, "ip_mr_vif", 0, &ipmr_vif_fops);
-	proc_net_fops_create(&init_net, "ip_mr_cache", 0, &ipmr_mfc_fops);
+	err = -ENOMEM;
+	if (!proc_net_fops_create(&init_net, "ip_mr_vif", 0, &ipmr_vif_fops))
+		goto proc_vif_fail;
+	if (!proc_net_fops_create(&init_net, "ip_mr_cache", 0, &ipmr_mfc_fops))
+		goto proc_cache_fail;
 #endif
+	return 0;
+reg_notif_fail:
+	kmem_cache_destroy(mrt_cachep);
+#ifdef CONFIG_PROC_FS
+proc_vif_fail:
+	unregister_netdevice_notifier(&ip_mr_notifier);
+proc_cache_fail:
+	proc_net_remove(&init_net, "ip_mr_vif");
+#endif
+	return err;
 }