Lines Matching refs:net

41 struct net init_net = {
76 static int net_assign_generic(struct net *net, unsigned int id, void *data) in net_assign_generic() argument
82 old_ng = rcu_dereference_protected(net->gen, in net_assign_generic()
108 rcu_assign_pointer(net->gen, ng); in net_assign_generic()
113 static int ops_init(const struct pernet_operations *ops, struct net *net) in ops_init() argument
123 err = net_assign_generic(net, *ops->id, data); in ops_init()
129 err = ops->init(net); in ops_init()
140 static void ops_free(const struct pernet_operations *ops, struct net *net) in ops_free() argument
143 kfree(net_generic(net, *ops->id)); in ops_free()
150 struct net *net; in ops_exit_list() local
152 list_for_each_entry(net, net_exit_list, exit_list) in ops_exit_list()
153 ops->exit(net); in ops_exit_list()
162 struct net *net; in ops_free_list() local
164 list_for_each_entry(net, net_exit_list, exit_list) in ops_free_list()
165 ops_free(ops, net); in ops_free_list()
170 static int alloc_netid(struct net *net, struct net *peer, int reqid) in alloc_netid() argument
179 return idr_alloc(&net->netns_ids, peer, min, max, GFP_ATOMIC); in alloc_netid()
188 static int net_eq_idr(int id, void *net, void *peer) in net_eq_idr() argument
190 if (net_eq(net, peer)) in net_eq_idr()
199 static int __peernet2id_alloc(struct net *net, struct net *peer, bool *alloc) in __peernet2id_alloc() argument
201 int id = idr_for_each(&net->netns_ids, net_eq_idr, peer); in __peernet2id_alloc()
213 id = alloc_netid(net, peer, -1); in __peernet2id_alloc()
222 static int __peernet2id(struct net *net, struct net *peer) in __peernet2id() argument
226 return __peernet2id_alloc(net, peer, &no); in __peernet2id()
229 static void rtnl_net_notifyid(struct net *net, int cmd, int id);
233 int peernet2id_alloc(struct net *net, struct net *peer) in peernet2id_alloc() argument
238 if (refcount_read(&net->count) == 0) in peernet2id_alloc()
240 spin_lock_bh(&net->nsid_lock); in peernet2id_alloc()
249 id = __peernet2id_alloc(net, peer, &alloc); in peernet2id_alloc()
250 spin_unlock_bh(&net->nsid_lock); in peernet2id_alloc()
252 rtnl_net_notifyid(net, RTM_NEWNSID, id); in peernet2id_alloc()
260 int peernet2id(struct net *net, struct net *peer) in peernet2id() argument
264 spin_lock_bh(&net->nsid_lock); in peernet2id()
265 id = __peernet2id(net, peer); in peernet2id()
266 spin_unlock_bh(&net->nsid_lock); in peernet2id()
274 bool peernet_has_id(struct net *net, struct net *peer) in peernet_has_id() argument
276 return peernet2id(net, peer) >= 0; in peernet_has_id()
279 struct net *get_net_ns_by_id(struct net *net, int id) in get_net_ns_by_id() argument
281 struct net *peer; in get_net_ns_by_id()
287 peer = idr_find(&net->netns_ids, id); in get_net_ns_by_id()
298 static __net_init int setup_net(struct net *net, struct user_namespace *user_ns) in setup_net() argument
305 refcount_set(&net->count, 1); in setup_net()
306 refcount_set(&net->passive, 1); in setup_net()
307 net->dev_base_seq = 1; in setup_net()
308 net->user_ns = user_ns; in setup_net()
309 idr_init(&net->netns_ids); in setup_net()
310 spin_lock_init(&net->nsid_lock); in setup_net()
311 mutex_init(&net->ipv4.ra_mutex); in setup_net()
314 error = ops_init(ops, net); in setup_net()
319 list_add_tail_rcu(&net->list, &net_namespace_list); in setup_net()
328 list_add(&net->exit_list, &net_exit_list); in setup_net()
341 static int __net_init net_defaults_init_net(struct net *net) in net_defaults_init_net() argument
343 net->core.sysctl_somaxconn = SOMAXCONN; in net_defaults_init_net()
375 static struct net *net_alloc(void) in net_alloc()
377 struct net *net = NULL; in net_alloc() local
384 net = kmem_cache_zalloc(net_cachep, GFP_KERNEL); in net_alloc()
385 if (!net) in net_alloc()
388 rcu_assign_pointer(net->gen, ng); in net_alloc()
390 return net; in net_alloc()
397 static void net_free(struct net *net) in net_free() argument
399 kfree(rcu_access_pointer(net->gen)); in net_free()
400 kmem_cache_free(net_cachep, net); in net_free()
405 struct net *ns = p; in net_drop_ns()
410 struct net *copy_net_ns(unsigned long flags, in copy_net_ns()
411 struct user_namespace *user_ns, struct net *old_net) in copy_net_ns()
414 struct net *net; in copy_net_ns() local
424 net = net_alloc(); in copy_net_ns()
425 if (!net) { in copy_net_ns()
429 refcount_set(&net->passive, 1); in copy_net_ns()
430 net->ucounts = ucounts; in copy_net_ns()
437 rv = setup_net(net, user_ns); in copy_net_ns()
444 net_drop_ns(net); in copy_net_ns()
449 return net; in copy_net_ns()
461 void net_ns_get_ownership(const struct net *net, kuid_t *uid, kgid_t *gid) in net_ns_get_ownership() argument
463 if (net) { in net_ns_get_ownership()
464 kuid_t ns_root_uid = make_kuid(net->user_ns, 0); in net_ns_get_ownership()
465 kgid_t ns_root_gid = make_kgid(net->user_ns, 0); in net_ns_get_ownership()
479 static void unhash_nsid(struct net *net, struct net *last) in unhash_nsid() argument
481 struct net *tmp; in unhash_nsid()
492 id = __peernet2id(tmp, net); in unhash_nsid()
501 spin_lock_bh(&net->nsid_lock); in unhash_nsid()
502 idr_destroy(&net->netns_ids); in unhash_nsid()
503 spin_unlock_bh(&net->nsid_lock); in unhash_nsid()
511 struct net *net, *tmp, *last; in cleanup_net() local
522 llist_for_each_entry(net, net_kill_list, cleanup_list) in cleanup_net()
523 list_del_rcu(&net->list); in cleanup_net()
534 last = list_last_entry(&net_namespace_list, struct net, list); in cleanup_net()
537 llist_for_each_entry(net, net_kill_list, cleanup_list) { in cleanup_net()
538 unhash_nsid(net, last); in cleanup_net()
539 list_add_tail(&net->exit_list, &net_exit_list); in cleanup_net()
565 list_for_each_entry_safe(net, tmp, &net_exit_list, exit_list) { in cleanup_net()
566 list_del_init(&net->exit_list); in cleanup_net()
567 dec_net_namespaces(net->ucounts); in cleanup_net()
568 put_user_ns(net->user_ns); in cleanup_net()
569 net_drop_ns(net); in cleanup_net()
591 void __put_net(struct net *net) in __put_net() argument
594 if (llist_add(&net->cleanup_list, &cleanup_list)) in __put_net()
599 struct net *get_net_ns_by_fd(int fd) in get_net_ns_by_fd()
603 struct net *net; in get_net_ns_by_fd() local
611 net = get_net(container_of(ns, struct net, ns)); in get_net_ns_by_fd()
613 net = ERR_PTR(-EINVAL); in get_net_ns_by_fd()
616 return net; in get_net_ns_by_fd()
620 struct net *get_net_ns_by_fd(int fd) in get_net_ns_by_fd()
627 struct net *get_net_ns_by_pid(pid_t pid) in get_net_ns_by_pid()
630 struct net *net; in get_net_ns_by_pid() local
633 net = ERR_PTR(-ESRCH); in get_net_ns_by_pid()
641 net = get_net(nsproxy->net_ns); in get_net_ns_by_pid()
645 return net; in get_net_ns_by_pid()
649 static __net_init int net_ns_net_init(struct net *net) in net_ns_net_init() argument
652 net->ns.ops = &netns_operations; in net_ns_net_init()
654 return ns_alloc_inum(&net->ns); in net_ns_net_init()
657 static __net_exit void net_ns_net_exit(struct net *net) in net_ns_net_exit() argument
659 ns_free_inum(&net->ns); in net_ns_net_exit()
677 struct net *net = sock_net(skb->sk); in rtnl_net_newid() local
680 struct net *peer; in rtnl_net_newid()
709 spin_lock_bh(&net->nsid_lock); in rtnl_net_newid()
710 if (__peernet2id(net, peer) >= 0) { in rtnl_net_newid()
711 spin_unlock_bh(&net->nsid_lock); in rtnl_net_newid()
719 err = alloc_netid(net, peer, nsid); in rtnl_net_newid()
720 spin_unlock_bh(&net->nsid_lock); in rtnl_net_newid()
722 rtnl_net_notifyid(net, RTM_NEWNSID, err); in rtnl_net_newid()
742 int cmd, struct net *net, int nsid) in rtnl_net_fill() argument
768 struct net *net = sock_net(skb->sk); in rtnl_net_getid() local
772 struct net *peer; in rtnl_net_getid()
802 id = peernet2id(net, peer); in rtnl_net_getid()
804 RTM_NEWNSID, net, id); in rtnl_net_getid()
808 err = rtnl_unicast(msg, net, NETLINK_CB(skb).portid); in rtnl_net_getid()
819 struct net *net; member
836 RTM_NEWNSID, net_cb->net, id); in rtnl_net_dumpid_one()
847 struct net *net = sock_net(skb->sk); in rtnl_net_dumpid() local
849 .net = net, in rtnl_net_dumpid()
856 spin_lock_bh(&net->nsid_lock); in rtnl_net_dumpid()
857 idr_for_each(&net->netns_ids, rtnl_net_dumpid_one, &net_cb); in rtnl_net_dumpid()
858 spin_unlock_bh(&net->nsid_lock); in rtnl_net_dumpid()
864 static void rtnl_net_notifyid(struct net *net, int cmd, int id) in rtnl_net_notifyid() argument
873 err = rtnl_net_fill(msg, 0, 0, 0, cmd, net, id); in rtnl_net_notifyid()
877 rtnl_notify(msg, net, 0, RTNLGRP_NSID, NULL, 0); in rtnl_net_notifyid()
883 rtnl_set_sk_err(net, RTNLGRP_NSID, err); in rtnl_net_notifyid()
891 net_cachep = kmem_cache_create("net_namespace", sizeof(struct net), in net_ns_init()
930 struct net *net; in __register_pernet_operations() local
939 for_each_net(net) { in __register_pernet_operations()
940 error = ops_init(ops, net); in __register_pernet_operations()
943 list_add_tail(&net->exit_list, &net_exit_list); in __register_pernet_operations()
958 struct net *net; in __unregister_pernet_operations() local
963 for_each_net(net) in __unregister_pernet_operations()
964 list_add_tail(&net->exit_list, &net_exit_list); in __unregister_pernet_operations()
1128 struct net *net = NULL; in netns_get() local
1134 net = get_net(nsproxy->net_ns); in netns_get()
1137 return net ? &net->ns : NULL; in netns_get()
1140 static inline struct net *to_net_ns(struct ns_common *ns) in to_net_ns()
1142 return container_of(ns, struct net, ns); in to_net_ns()
1152 struct net *net = to_net_ns(ns); in netns_install() local
1154 if (!ns_capable(net->user_ns, CAP_SYS_ADMIN) || in netns_install()
1159 nsproxy->net_ns = get_net(net); in netns_install()