mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 03:36:19 +00:00
[NETNS]: Consolidate kernel netlink socket destruction.
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>
This commit is contained in:
parent
4f84d82f7a
commit
b7c6ba6eb1
16 changed files with 34 additions and 26 deletions
|
@ -420,8 +420,7 @@ static int __devinit cn_init(void)
|
||||||
|
|
||||||
dev->cbdev = cn_queue_alloc_dev("cqueue", dev->nls);
|
dev->cbdev = cn_queue_alloc_dev("cqueue", dev->nls);
|
||||||
if (!dev->cbdev) {
|
if (!dev->cbdev) {
|
||||||
if (dev->nls->sk_socket)
|
netlink_kernel_release(dev->nls);
|
||||||
sock_release(dev->nls->sk_socket);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -431,8 +430,7 @@ static int __devinit cn_init(void)
|
||||||
if (err) {
|
if (err) {
|
||||||
cn_already_initialized = 0;
|
cn_already_initialized = 0;
|
||||||
cn_queue_free_dev(dev->cbdev);
|
cn_queue_free_dev(dev->cbdev);
|
||||||
if (dev->nls->sk_socket)
|
netlink_kernel_release(dev->nls);
|
||||||
sock_release(dev->nls->sk_socket);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,8 +445,7 @@ static void __devexit cn_fini(void)
|
||||||
|
|
||||||
cn_del_callback(&dev->id);
|
cn_del_callback(&dev->id);
|
||||||
cn_queue_free_dev(dev->cbdev);
|
cn_queue_free_dev(dev->cbdev);
|
||||||
if (dev->nls->sk_socket)
|
netlink_kernel_release(dev->nls);
|
||||||
sock_release(dev->nls->sk_socket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
subsys_initcall(cn_init);
|
subsys_initcall(cn_init);
|
||||||
|
|
|
@ -164,7 +164,7 @@ void
|
||||||
scsi_netlink_exit(void)
|
scsi_netlink_exit(void)
|
||||||
{
|
{
|
||||||
if (scsi_nl_sock) {
|
if (scsi_nl_sock) {
|
||||||
sock_release(scsi_nl_sock->sk_socket);
|
netlink_kernel_release(scsi_nl_sock);
|
||||||
netlink_unregister_notifier(&scsi_netlink_notifier);
|
netlink_unregister_notifier(&scsi_netlink_notifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1558,7 +1558,7 @@ static __init int iscsi_transport_init(void)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
release_nls:
|
release_nls:
|
||||||
sock_release(nls->sk_socket);
|
netlink_kernel_release(nls);
|
||||||
unregister_session_class:
|
unregister_session_class:
|
||||||
transport_class_unregister(&iscsi_session_class);
|
transport_class_unregister(&iscsi_session_class);
|
||||||
unregister_conn_class:
|
unregister_conn_class:
|
||||||
|
@ -1573,7 +1573,7 @@ unregister_transport_class:
|
||||||
static void __exit iscsi_transport_exit(void)
|
static void __exit iscsi_transport_exit(void)
|
||||||
{
|
{
|
||||||
destroy_workqueue(iscsi_eh_timer_workq);
|
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_connection_class);
|
||||||
transport_class_unregister(&iscsi_session_class);
|
transport_class_unregister(&iscsi_session_class);
|
||||||
transport_class_unregister(&iscsi_host_class);
|
transport_class_unregister(&iscsi_host_class);
|
||||||
|
|
|
@ -237,7 +237,6 @@ out:
|
||||||
*/
|
*/
|
||||||
void ecryptfs_release_netlink(void)
|
void ecryptfs_release_netlink(void)
|
||||||
{
|
{
|
||||||
if (ecryptfs_nl_sock && ecryptfs_nl_sock->sk_socket)
|
netlink_kernel_release(ecryptfs_nl_sock);
|
||||||
sock_release(ecryptfs_nl_sock->sk_socket);
|
|
||||||
ecryptfs_nl_sock = NULL;
|
ecryptfs_nl_sock = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,6 +178,7 @@ extern struct sock *netlink_kernel_create(struct net *net,
|
||||||
void (*input)(struct sk_buff *skb),
|
void (*input)(struct sk_buff *skb),
|
||||||
struct mutex *cb_mutex,
|
struct mutex *cb_mutex,
|
||||||
struct module *module);
|
struct module *module);
|
||||||
|
extern void netlink_kernel_release(struct sock *sk);
|
||||||
extern int netlink_change_ngroups(struct sock *sk, unsigned int groups);
|
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_clear_multicast_users(struct sock *sk, unsigned int group);
|
||||||
extern void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err);
|
extern void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err);
|
||||||
|
|
|
@ -307,7 +307,7 @@ static int __init ebt_ulog_init(void)
|
||||||
if (!ebtulognl)
|
if (!ebtulognl)
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
else if ((ret = ebt_register_watcher(&ulog)))
|
else if ((ret = ebt_register_watcher(&ulog)))
|
||||||
sock_release(ebtulognl->sk_socket);
|
netlink_kernel_release(ebtulognl);
|
||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
nf_log_register(PF_BRIDGE, &ebt_ulog_logger);
|
nf_log_register(PF_BRIDGE, &ebt_ulog_logger);
|
||||||
|
@ -333,7 +333,7 @@ static void __exit ebt_ulog_fini(void)
|
||||||
}
|
}
|
||||||
spin_unlock_bh(&ub->lock);
|
spin_unlock_bh(&ub->lock);
|
||||||
}
|
}
|
||||||
sock_release(ebtulognl->sk_socket);
|
netlink_kernel_release(ebtulognl);
|
||||||
}
|
}
|
||||||
|
|
||||||
module_init(ebt_ulog_init);
|
module_init(ebt_ulog_init);
|
||||||
|
|
|
@ -1384,7 +1384,7 @@ static void rtnetlink_net_exit(struct net *net)
|
||||||
* free.
|
* free.
|
||||||
*/
|
*/
|
||||||
sk->sk_net = get_net(&init_net);
|
sk->sk_net = get_net(&init_net);
|
||||||
sock_release(net->rtnl->sk_socket);
|
netlink_kernel_release(net->rtnl);
|
||||||
net->rtnl = NULL;
|
net->rtnl = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ static int __init dn_rtmsg_init(void)
|
||||||
|
|
||||||
rv = nf_register_hook(&dnrmg_ops);
|
rv = nf_register_hook(&dnrmg_ops);
|
||||||
if (rv) {
|
if (rv) {
|
||||||
sock_release(dnrmg->sk_socket);
|
netlink_kernel_release(dnrmg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
|
@ -146,7 +146,7 @@ static int __init dn_rtmsg_init(void)
|
||||||
static void __exit dn_rtmsg_fini(void)
|
static void __exit dn_rtmsg_fini(void)
|
||||||
{
|
{
|
||||||
nf_unregister_hook(&dnrmg_ops);
|
nf_unregister_hook(&dnrmg_ops);
|
||||||
sock_release(dnrmg->sk_socket);
|
netlink_kernel_release(dnrmg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -881,7 +881,7 @@ static void nl_fib_lookup_exit(struct net *net)
|
||||||
* initial network namespace. So the socket will be safe to free.
|
* initial network namespace. So the socket will be safe to free.
|
||||||
*/
|
*/
|
||||||
net->ipv4.fibnl->sk_net = get_net(&init_net);
|
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)
|
static void fib_disable_ip(struct net_device *dev, int force)
|
||||||
|
|
|
@ -935,7 +935,7 @@ out_free_table:
|
||||||
|
|
||||||
static void __exit inet_diag_exit(void)
|
static void __exit inet_diag_exit(void)
|
||||||
{
|
{
|
||||||
sock_release(idiagnl->sk_socket);
|
netlink_kernel_release(idiagnl);
|
||||||
kfree(inet_diag_table);
|
kfree(inet_diag_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -605,7 +605,7 @@ cleanup_sysctl:
|
||||||
unregister_netdevice_notifier(&ipq_dev_notifier);
|
unregister_netdevice_notifier(&ipq_dev_notifier);
|
||||||
proc_net_remove(&init_net, IPQ_PROC_FS_NAME);
|
proc_net_remove(&init_net, IPQ_PROC_FS_NAME);
|
||||||
cleanup_ipqnl:
|
cleanup_ipqnl:
|
||||||
sock_release(ipqnl->sk_socket);
|
netlink_kernel_release(ipqnl);
|
||||||
mutex_lock(&ipqnl_mutex);
|
mutex_lock(&ipqnl_mutex);
|
||||||
mutex_unlock(&ipqnl_mutex);
|
mutex_unlock(&ipqnl_mutex);
|
||||||
|
|
||||||
|
@ -624,7 +624,7 @@ static void __exit ip_queue_fini(void)
|
||||||
unregister_netdevice_notifier(&ipq_dev_notifier);
|
unregister_netdevice_notifier(&ipq_dev_notifier);
|
||||||
proc_net_remove(&init_net, IPQ_PROC_FS_NAME);
|
proc_net_remove(&init_net, IPQ_PROC_FS_NAME);
|
||||||
|
|
||||||
sock_release(ipqnl->sk_socket);
|
netlink_kernel_release(ipqnl);
|
||||||
mutex_lock(&ipqnl_mutex);
|
mutex_lock(&ipqnl_mutex);
|
||||||
mutex_unlock(&ipqnl_mutex);
|
mutex_unlock(&ipqnl_mutex);
|
||||||
|
|
||||||
|
|
|
@ -415,7 +415,7 @@ static int __init ulog_tg_init(void)
|
||||||
|
|
||||||
ret = xt_register_target(&ulog_tg_reg);
|
ret = xt_register_target(&ulog_tg_reg);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
sock_release(nflognl->sk_socket);
|
netlink_kernel_release(nflognl);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if (nflog)
|
if (nflog)
|
||||||
|
@ -434,7 +434,7 @@ static void __exit ulog_tg_exit(void)
|
||||||
if (nflog)
|
if (nflog)
|
||||||
nf_log_unregister(&ipt_ulog_logger);
|
nf_log_unregister(&ipt_ulog_logger);
|
||||||
xt_unregister_target(&ulog_tg_reg);
|
xt_unregister_target(&ulog_tg_reg);
|
||||||
sock_release(nflognl->sk_socket);
|
netlink_kernel_release(nflognl);
|
||||||
|
|
||||||
/* remove pending timers and free allocated skb's */
|
/* remove pending timers and free allocated skb's */
|
||||||
for (i = 0; i < ULOG_MAXNLGROUPS; i++) {
|
for (i = 0; i < ULOG_MAXNLGROUPS; i++) {
|
||||||
|
|
|
@ -609,7 +609,7 @@ cleanup_sysctl:
|
||||||
proc_net_remove(&init_net, IPQ_PROC_FS_NAME);
|
proc_net_remove(&init_net, IPQ_PROC_FS_NAME);
|
||||||
|
|
||||||
cleanup_ipqnl:
|
cleanup_ipqnl:
|
||||||
sock_release(ipqnl->sk_socket);
|
netlink_kernel_release(ipqnl);
|
||||||
mutex_lock(&ipqnl_mutex);
|
mutex_lock(&ipqnl_mutex);
|
||||||
mutex_unlock(&ipqnl_mutex);
|
mutex_unlock(&ipqnl_mutex);
|
||||||
|
|
||||||
|
@ -628,7 +628,7 @@ static void __exit ip6_queue_fini(void)
|
||||||
unregister_netdevice_notifier(&ipq_dev_notifier);
|
unregister_netdevice_notifier(&ipq_dev_notifier);
|
||||||
proc_net_remove(&init_net, IPQ_PROC_FS_NAME);
|
proc_net_remove(&init_net, IPQ_PROC_FS_NAME);
|
||||||
|
|
||||||
sock_release(ipqnl->sk_socket);
|
netlink_kernel_release(ipqnl);
|
||||||
mutex_lock(&ipqnl_mutex);
|
mutex_lock(&ipqnl_mutex);
|
||||||
mutex_unlock(&ipqnl_mutex);
|
mutex_unlock(&ipqnl_mutex);
|
||||||
|
|
||||||
|
|
|
@ -179,7 +179,7 @@ static void nfnetlink_rcv(struct sk_buff *skb)
|
||||||
static void __exit nfnetlink_exit(void)
|
static void __exit nfnetlink_exit(void)
|
||||||
{
|
{
|
||||||
printk("Removing netfilter NETLINK layer.\n");
|
printk("Removing netfilter NETLINK layer.\n");
|
||||||
sock_release(nfnl->sk_socket);
|
netlink_kernel_release(nfnl);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1405,6 +1405,17 @@ out_sock_release:
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(netlink_kernel_create);
|
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
|
* netlink_change_ngroups - change number of multicast groups
|
||||||
*
|
*
|
||||||
|
|
|
@ -2420,7 +2420,7 @@ static void __exit xfrm_user_exit(void)
|
||||||
xfrm_unregister_km(&netlink_mgr);
|
xfrm_unregister_km(&netlink_mgr);
|
||||||
rcu_assign_pointer(xfrm_nl, NULL);
|
rcu_assign_pointer(xfrm_nl, NULL);
|
||||||
synchronize_rcu();
|
synchronize_rcu();
|
||||||
sock_release(nlsk->sk_socket);
|
netlink_kernel_release(nlsk);
|
||||||
}
|
}
|
||||||
|
|
||||||
module_init(xfrm_user_init);
|
module_init(xfrm_user_init);
|
||||||
|
|
Loading…
Reference in a new issue