aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2014-12-10 21:31:59 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2014-12-10 21:31:59 -0500
commit707c5960f102f8cdafb9406047b158abc71b391f (patch)
tree31d195b1c48cefa2d04da7cc801824f87a0a9887 /net
parentba00410b8131b23edfb0e09f8b6dd26c8eb621fb (diff)
parent3d3d35b1e94ec918fc0ae670663235bf197d8609 (diff)
Merge branch 'nsfs' into for-next
Diffstat (limited to 'net')
-rw-r--r--net/core/net_namespace.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 7f155175bba8..ce780c722e48 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -337,17 +337,17 @@ EXPORT_SYMBOL_GPL(__put_net);
337 337
338struct net *get_net_ns_by_fd(int fd) 338struct net *get_net_ns_by_fd(int fd)
339{ 339{
340 struct proc_ns *ei;
341 struct file *file; 340 struct file *file;
341 struct ns_common *ns;
342 struct net *net; 342 struct net *net;
343 343
344 file = proc_ns_fget(fd); 344 file = proc_ns_fget(fd);
345 if (IS_ERR(file)) 345 if (IS_ERR(file))
346 return ERR_CAST(file); 346 return ERR_CAST(file);
347 347
348 ei = get_proc_ns(file_inode(file)); 348 ns = get_proc_ns(file_inode(file));
349 if (ei->ns_ops == &netns_operations) 349 if (ns->ops == &netns_operations)
350 net = get_net(ei->ns); 350 net = get_net(container_of(ns, struct net, ns));
351 else 351 else
352 net = ERR_PTR(-EINVAL); 352 net = ERR_PTR(-EINVAL);
353 353
@@ -386,12 +386,15 @@ EXPORT_SYMBOL_GPL(get_net_ns_by_pid);
386 386
387static __net_init int net_ns_net_init(struct net *net) 387static __net_init int net_ns_net_init(struct net *net)
388{ 388{
389 return proc_alloc_inum(&net->proc_inum); 389#ifdef CONFIG_NET_NS
390 net->ns.ops = &netns_operations;
391#endif
392 return ns_alloc_inum(&net->ns);
390} 393}
391 394
392static __net_exit void net_ns_net_exit(struct net *net) 395static __net_exit void net_ns_net_exit(struct net *net)
393{ 396{
394 proc_free_inum(net->proc_inum); 397 ns_free_inum(&net->ns);
395} 398}
396 399
397static struct pernet_operations __net_initdata net_ns_ops = { 400static struct pernet_operations __net_initdata net_ns_ops = {
@@ -629,7 +632,7 @@ void unregister_pernet_device(struct pernet_operations *ops)
629EXPORT_SYMBOL_GPL(unregister_pernet_device); 632EXPORT_SYMBOL_GPL(unregister_pernet_device);
630 633
631#ifdef CONFIG_NET_NS 634#ifdef CONFIG_NET_NS
632static void *netns_get(struct task_struct *task) 635static struct ns_common *netns_get(struct task_struct *task)
633{ 636{
634 struct net *net = NULL; 637 struct net *net = NULL;
635 struct nsproxy *nsproxy; 638 struct nsproxy *nsproxy;
@@ -640,17 +643,22 @@ static void *netns_get(struct task_struct *task)
640 net = get_net(nsproxy->net_ns); 643 net = get_net(nsproxy->net_ns);
641 task_unlock(task); 644 task_unlock(task);
642 645
643 return net; 646 return net ? &net->ns : NULL;
644} 647}
645 648
646static void netns_put(void *ns) 649static inline struct net *to_net_ns(struct ns_common *ns)
647{ 650{
648 put_net(ns); 651 return container_of(ns, struct net, ns);
649} 652}
650 653
651static int netns_install(struct nsproxy *nsproxy, void *ns) 654static void netns_put(struct ns_common *ns)
652{ 655{
653 struct net *net = ns; 656 put_net(to_net_ns(ns));
657}
658
659static int netns_install(struct nsproxy *nsproxy, struct ns_common *ns)
660{
661 struct net *net = to_net_ns(ns);
654 662
655 if (!ns_capable(net->user_ns, CAP_SYS_ADMIN) || 663 if (!ns_capable(net->user_ns, CAP_SYS_ADMIN) ||
656 !ns_capable(current_user_ns(), CAP_SYS_ADMIN)) 664 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
@@ -661,18 +669,11 @@ static int netns_install(struct nsproxy *nsproxy, void *ns)
661 return 0; 669 return 0;
662} 670}
663 671
664static unsigned int netns_inum(void *ns)
665{
666 struct net *net = ns;
667 return net->proc_inum;
668}
669
670const struct proc_ns_operations netns_operations = { 672const struct proc_ns_operations netns_operations = {
671 .name = "net", 673 .name = "net",
672 .type = CLONE_NEWNET, 674 .type = CLONE_NEWNET,
673 .get = netns_get, 675 .get = netns_get,
674 .put = netns_put, 676 .put = netns_put,
675 .install = netns_install, 677 .install = netns_install,
676 .inum = netns_inum,
677}; 678};
678#endif 679#endif