[NETNS]: Consolidate kernel netlink socket destruction.
authorDenis V. Lunev <den@openvz.org>
Mon, 28 Jan 2008 22:41:19 +0000 (14:41 -0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Jan 2008 23:08:07 +0000 (15:08 -0800)
Create a specific helper for netlink kernel socket disposal. This just
let the code look better and provides a ground for proper disposal
inside a namespace.

Signed-off-by: Denis V. Lunev <den@openvz.org>
Tested-by: Alexey Dobriyan <adobriyan@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
16 files changed:
drivers/connector/connector.c
drivers/scsi/scsi_netlink.c
drivers/scsi/scsi_transport_iscsi.c
fs/ecryptfs/netlink.c
include/linux/netlink.h
net/bridge/netfilter/ebt_ulog.c
net/core/rtnetlink.c
net/decnet/netfilter/dn_rtmsg.c
net/ipv4/fib_frontend.c
net/ipv4/inet_diag.c
net/ipv4/netfilter/ip_queue.c
net/ipv4/netfilter/ipt_ULOG.c
net/ipv6/netfilter/ip6_queue.c
net/netfilter/nfnetlink.c
net/netlink/af_netlink.c
net/xfrm/xfrm_user.c

index 37976dcf044b0ea96b2f6e731e4221a9d0a8e664..fea2d3ed9cbdacd57661f5a1a5227a1bde2ffeb2 100644 (file)
@@ -420,8 +420,7 @@ static int __devinit cn_init(void)
 
        dev->cbdev = cn_queue_alloc_dev("cqueue", dev->nls);
        if (!dev->cbdev) {
-               if (dev->nls->sk_socket)
-                       sock_release(dev->nls->sk_socket);
+               netlink_kernel_release(dev->nls);
                return -EINVAL;
        }
        
@@ -431,8 +430,7 @@ static int __devinit cn_init(void)
        if (err) {
                cn_already_initialized = 0;
                cn_queue_free_dev(dev->cbdev);
-               if (dev->nls->sk_socket)
-                       sock_release(dev->nls->sk_socket);
+               netlink_kernel_release(dev->nls);
                return -EINVAL;
        }
 
@@ -447,8 +445,7 @@ static void __devexit cn_fini(void)
 
        cn_del_callback(&dev->id);
        cn_queue_free_dev(dev->cbdev);
-       if (dev->nls->sk_socket)
-               sock_release(dev->nls->sk_socket);
+       netlink_kernel_release(dev->nls);
 }
 
 subsys_initcall(cn_init);
index 3e15918281719b5faddd5186314ab85ba8b52b05..370c78cc1cb562f20af68017489a78b6650374a0 100644 (file)
@@ -164,7 +164,7 @@ void
 scsi_netlink_exit(void)
 {
        if (scsi_nl_sock) {
-               sock_release(scsi_nl_sock->sk_socket);
+               netlink_kernel_release(scsi_nl_sock);
                netlink_unregister_notifier(&scsi_netlink_notifier);
        }
 
index ef0e74264880625ffc78687e1603c1823ca0c6f3..0d7b4e79415c6b141256e7f91328c12d2a86c56d 100644 (file)
@@ -1558,7 +1558,7 @@ static __init int iscsi_transport_init(void)
        return 0;
 
 release_nls:
-       sock_release(nls->sk_socket);
+       netlink_kernel_release(nls);
 unregister_session_class:
        transport_class_unregister(&iscsi_session_class);
 unregister_conn_class:
@@ -1573,7 +1573,7 @@ unregister_transport_class:
 static void __exit iscsi_transport_exit(void)
 {
        destroy_workqueue(iscsi_eh_timer_workq);
-       sock_release(nls->sk_socket);
+       netlink_kernel_release(nls);
        transport_class_unregister(&iscsi_connection_class);
        transport_class_unregister(&iscsi_session_class);
        transport_class_unregister(&iscsi_host_class);
index 9aa345121e09cf2bf2f600259f95a03557f85de3..f638a698dc525350bc44054f567217d52c0fca71 100644 (file)
@@ -237,7 +237,6 @@ out:
  */
 void ecryptfs_release_netlink(void)
 {
-       if (ecryptfs_nl_sock && ecryptfs_nl_sock->sk_socket)
-               sock_release(ecryptfs_nl_sock->sk_socket);
+       netlink_kernel_release(ecryptfs_nl_sock);
        ecryptfs_nl_sock = NULL;
 }
index 2aee0f51087646361f89d0c2bc32adb6ca27c3cf..bd13b6f4a98ec0932503273858988795bcc5bf35 100644 (file)
@@ -178,6 +178,7 @@ extern struct sock *netlink_kernel_create(struct net *net,
                                          void (*input)(struct sk_buff *skb),
                                          struct mutex *cb_mutex,
                                          struct module *module);
+extern void netlink_kernel_release(struct sock *sk);
 extern int netlink_change_ngroups(struct sock *sk, unsigned int groups);
 extern void netlink_clear_multicast_users(struct sock *sk, unsigned int group);
 extern void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err);
index b73ba28bcbe85e3c79a842f0ec2d65b80064d2ba..8e7b00b68d3868107dd52f01a82a9262f2f34f49 100644 (file)
@@ -307,7 +307,7 @@ static int __init ebt_ulog_init(void)
        if (!ebtulognl)
                ret = -ENOMEM;
        else if ((ret = ebt_register_watcher(&ulog)))
-               sock_release(ebtulognl->sk_socket);
+               netlink_kernel_release(ebtulognl);
 
        if (ret == 0)
                nf_log_register(PF_BRIDGE, &ebt_ulog_logger);
@@ -333,7 +333,7 @@ static void __exit ebt_ulog_fini(void)
                }
                spin_unlock_bh(&ub->lock);
        }
-       sock_release(ebtulognl->sk_socket);
+       netlink_kernel_release(ebtulognl);
 }
 
 module_init(ebt_ulog_init);
index a5f4f661fa62c55427021d1becbc699519b03053..02cf848f71d23205b79384361af3fde819517fd3 100644 (file)
@@ -1384,7 +1384,7 @@ static void rtnetlink_net_exit(struct net *net)
                 * free.
                 */
                sk->sk_net = get_net(&init_net);
-               sock_release(net->rtnl->sk_socket);
+               netlink_kernel_release(net->rtnl);
                net->rtnl = NULL;
        }
 }
index 96375f2e64ff912818f185615d992c3dc73a8d1a..6d2bd3202048a8c8b36e17ef707278cc806d89e4 100644 (file)
@@ -137,7 +137,7 @@ static int __init dn_rtmsg_init(void)
 
        rv = nf_register_hook(&dnrmg_ops);
        if (rv) {
-               sock_release(dnrmg->sk_socket);
+               netlink_kernel_release(dnrmg);
        }
 
        return rv;
@@ -146,7 +146,7 @@ static int __init dn_rtmsg_init(void)
 static void __exit dn_rtmsg_fini(void)
 {
        nf_unregister_hook(&dnrmg_ops);
-       sock_release(dnrmg->sk_socket);
+       netlink_kernel_release(dnrmg);
 }
 
 
index 4e5216e9aacb3739787138fe4db8b6ef523226e9..e787d215115217492ab31bda0ee7df2010bfe82e 100644 (file)
@@ -881,7 +881,7 @@ static void nl_fib_lookup_exit(struct net *net)
         * initial network namespace. So the socket will  be safe to free.
         */
        net->ipv4.fibnl->sk_net = get_net(&init_net);
-       sock_release(net->ipv4.fibnl->sk_socket);
+       netlink_kernel_release(net->ipv4.fibnl);
 }
 
 static void fib_disable_ip(struct net_device *dev, int force)
index e468e7a7aac4d8c7940955eac466af2e6303858f..605ed2cd79724b461e933ed4e00ca694f0797bf9 100644 (file)
@@ -935,7 +935,7 @@ out_free_table:
 
 static void __exit inet_diag_exit(void)
 {
-       sock_release(idiagnl->sk_socket);
+       netlink_kernel_release(idiagnl);
        kfree(inet_diag_table);
 }
 
index 7361315f20c6ec44a5596e0bb4c1a297b3a07e60..5109839da222b28f6f1c255d16f45d729cf87ff2 100644 (file)
@@ -605,7 +605,7 @@ cleanup_sysctl:
        unregister_netdevice_notifier(&ipq_dev_notifier);
        proc_net_remove(&init_net, IPQ_PROC_FS_NAME);
 cleanup_ipqnl:
-       sock_release(ipqnl->sk_socket);
+       netlink_kernel_release(ipqnl);
        mutex_lock(&ipqnl_mutex);
        mutex_unlock(&ipqnl_mutex);
 
@@ -624,7 +624,7 @@ static void __exit ip_queue_fini(void)
        unregister_netdevice_notifier(&ipq_dev_notifier);
        proc_net_remove(&init_net, IPQ_PROC_FS_NAME);
 
-       sock_release(ipqnl->sk_socket);
+       netlink_kernel_release(ipqnl);
        mutex_lock(&ipqnl_mutex);
        mutex_unlock(&ipqnl_mutex);
 
index fa24efaf3eaa54756f26839e4325e0daec83155e..b192756c6d0dfa57cd7fa6b9befc43420e823f45 100644 (file)
@@ -415,7 +415,7 @@ static int __init ulog_tg_init(void)
 
        ret = xt_register_target(&ulog_tg_reg);
        if (ret < 0) {
-               sock_release(nflognl->sk_socket);
+               netlink_kernel_release(nflognl);
                return ret;
        }
        if (nflog)
@@ -434,7 +434,7 @@ static void __exit ulog_tg_exit(void)
        if (nflog)
                nf_log_unregister(&ipt_ulog_logger);
        xt_unregister_target(&ulog_tg_reg);
-       sock_release(nflognl->sk_socket);
+       netlink_kernel_release(nflognl);
 
        /* remove pending timers and free allocated skb's */
        for (i = 0; i < ULOG_MAXNLGROUPS; i++) {
index a20db0bb5a1f1c3c2c218c0b8c6c82c63c057751..56b4ea6d29ed3c9780f0081d1a922899f92ba6f7 100644 (file)
@@ -609,7 +609,7 @@ cleanup_sysctl:
        proc_net_remove(&init_net, IPQ_PROC_FS_NAME);
 
 cleanup_ipqnl:
-       sock_release(ipqnl->sk_socket);
+       netlink_kernel_release(ipqnl);
        mutex_lock(&ipqnl_mutex);
        mutex_unlock(&ipqnl_mutex);
 
@@ -628,7 +628,7 @@ static void __exit ip6_queue_fini(void)
        unregister_netdevice_notifier(&ipq_dev_notifier);
        proc_net_remove(&init_net, IPQ_PROC_FS_NAME);
 
-       sock_release(ipqnl->sk_socket);
+       netlink_kernel_release(ipqnl);
        mutex_lock(&ipqnl_mutex);
        mutex_unlock(&ipqnl_mutex);
 
index 2128542995f79279fb026bcc4688eef46b434305..b75c9c4a995d885c1ac12339b0afff9d1d24db31 100644 (file)
@@ -179,7 +179,7 @@ static void nfnetlink_rcv(struct sk_buff *skb)
 static void __exit nfnetlink_exit(void)
 {
        printk("Removing netfilter NETLINK layer.\n");
-       sock_release(nfnl->sk_socket);
+       netlink_kernel_release(nfnl);
        return;
 }
 
index 29fef558aab60e56e8304219262f45cf3b405a3a..626a58206298e1f31c81aed14f8fdbe4ffa76089 100644 (file)
@@ -1405,6 +1405,17 @@ out_sock_release:
 }
 EXPORT_SYMBOL(netlink_kernel_create);
 
+
+void
+netlink_kernel_release(struct sock *sk)
+{
+       if (sk == NULL || sk->sk_socket == NULL)
+               return;
+       sock_release(sk->sk_socket);
+}
+EXPORT_SYMBOL(netlink_kernel_release);
+
+
 /**
  * netlink_change_ngroups - change number of multicast groups
  *
index 35fc16ae50ac717cbaf1f314aa8e8ec1299366cc..e0ccdf26781360fc8c2860ddbb3b33ec0dafc7d0 100644 (file)
@@ -2420,7 +2420,7 @@ static void __exit xfrm_user_exit(void)
        xfrm_unregister_km(&netlink_mgr);
        rcu_assign_pointer(xfrm_nl, NULL);
        synchronize_rcu();
-       sock_release(nlsk->sk_socket);
+       netlink_kernel_release(nlsk);
 }
 
 module_init(xfrm_user_init);