diff options
author | Andrey Vagin <avagin@openvz.org> | 2012-07-16 00:28:49 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-07-17 01:31:34 -0400 |
commit | 51d7cccf07238f5236c5b9269231a30dd5f8e714 (patch) | |
tree | 1155d43b810d0f163276182be610d69c50e862d9 /net/core | |
parent | cbc89c8cf279b85edc95b4ae40a9e7e1edf2dfae (diff) |
net: make sock diag per-namespace
Before this patch sock_diag works for init_net only and dumps
information about sockets from all namespaces.
This patch expands sock_diag for all name-spaces.
It creates a netlink kernel socket for each netns and filters
data during dumping.
v2: filter accoding with netns in all places
remove an unused variable.
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
Cc: James Morris <jmorris@namei.org>
Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
Cc: Patrick McHardy <kaber@trash.net>
Cc: Pavel Emelyanov <xemul@parallels.com>
CC: Eric Dumazet <eric.dumazet@gmail.com>
Cc: linux-kernel@vger.kernel.org
Cc: netdev@vger.kernel.org
Signed-off-by: Andrew Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r-- | net/core/sock_diag.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c index 07a29eb34a41..9d8755e4a7a5 100644 --- a/net/core/sock_diag.c +++ b/net/core/sock_diag.c | |||
@@ -166,23 +166,36 @@ static void sock_diag_rcv(struct sk_buff *skb) | |||
166 | mutex_unlock(&sock_diag_mutex); | 166 | mutex_unlock(&sock_diag_mutex); |
167 | } | 167 | } |
168 | 168 | ||
169 | struct sock *sock_diag_nlsk; | 169 | static int __net_init diag_net_init(struct net *net) |
170 | EXPORT_SYMBOL_GPL(sock_diag_nlsk); | ||
171 | |||
172 | static int __init sock_diag_init(void) | ||
173 | { | 170 | { |
174 | struct netlink_kernel_cfg cfg = { | 171 | struct netlink_kernel_cfg cfg = { |
175 | .input = sock_diag_rcv, | 172 | .input = sock_diag_rcv, |
176 | }; | 173 | }; |
177 | 174 | ||
178 | sock_diag_nlsk = netlink_kernel_create(&init_net, NETLINK_SOCK_DIAG, | 175 | net->diag_nlsk = netlink_kernel_create(net, NETLINK_SOCK_DIAG, |
179 | THIS_MODULE, &cfg); | 176 | THIS_MODULE, &cfg); |
180 | return sock_diag_nlsk == NULL ? -ENOMEM : 0; | 177 | return net->diag_nlsk == NULL ? -ENOMEM : 0; |
178 | } | ||
179 | |||
180 | static void __net_exit diag_net_exit(struct net *net) | ||
181 | { | ||
182 | netlink_kernel_release(net->diag_nlsk); | ||
183 | net->diag_nlsk = NULL; | ||
184 | } | ||
185 | |||
186 | static struct pernet_operations diag_net_ops = { | ||
187 | .init = diag_net_init, | ||
188 | .exit = diag_net_exit, | ||
189 | }; | ||
190 | |||
191 | static int __init sock_diag_init(void) | ||
192 | { | ||
193 | return register_pernet_subsys(&diag_net_ops); | ||
181 | } | 194 | } |
182 | 195 | ||
183 | static void __exit sock_diag_exit(void) | 196 | static void __exit sock_diag_exit(void) |
184 | { | 197 | { |
185 | netlink_kernel_release(sock_diag_nlsk); | 198 | unregister_pernet_subsys(&diag_net_ops); |
186 | } | 199 | } |
187 | 200 | ||
188 | module_init(sock_diag_init); | 201 | module_init(sock_diag_init); |