Lines Matching refs:net
46 struct net init_net = {
84 static int net_assign_generic(struct net *net, unsigned int id, void *data) in net_assign_generic() argument
90 old_ng = rcu_dereference_protected(net->gen, in net_assign_generic()
116 rcu_assign_pointer(net->gen, ng); in net_assign_generic()
121 static int ops_init(const struct pernet_operations *ops, struct net *net) in ops_init() argument
131 err = net_assign_generic(net, *ops->id, data); in ops_init()
137 err = ops->init(net); in ops_init()
148 static void ops_free(const struct pernet_operations *ops, struct net *net) in ops_free() argument
151 kfree(net_generic(net, *ops->id)); in ops_free()
158 struct net *net; in ops_pre_exit_list() local
161 list_for_each_entry(net, net_exit_list, exit_list) in ops_pre_exit_list()
162 ops->pre_exit(net); in ops_pre_exit_list()
169 struct net *net; in ops_exit_list() local
171 list_for_each_entry(net, net_exit_list, exit_list) in ops_exit_list()
172 ops->exit(net); in ops_exit_list()
181 struct net *net; in ops_free_list() local
183 list_for_each_entry(net, net_exit_list, exit_list) in ops_free_list()
184 ops_free(ops, net); in ops_free_list()
189 static int alloc_netid(struct net *net, struct net *peer, int reqid) in alloc_netid() argument
198 return idr_alloc(&net->netns_ids, peer, min, max, GFP_ATOMIC); in alloc_netid()
207 static int net_eq_idr(int id, void *net, void *peer) in net_eq_idr() argument
209 if (net_eq(net, peer)) in net_eq_idr()
218 static int __peernet2id_alloc(struct net *net, struct net *peer, bool *alloc) in __peernet2id_alloc() argument
220 int id = idr_for_each(&net->netns_ids, net_eq_idr, peer); in __peernet2id_alloc()
232 id = alloc_netid(net, peer, -1); in __peernet2id_alloc()
241 static int __peernet2id(struct net *net, struct net *peer) in __peernet2id() argument
245 return __peernet2id_alloc(net, peer, &no); in __peernet2id()
248 static void rtnl_net_notifyid(struct net *net, int cmd, int id, u32 portid,
253 int peernet2id_alloc(struct net *net, struct net *peer, gfp_t gfp) in peernet2id_alloc() argument
258 if (refcount_read(&net->count) == 0) in peernet2id_alloc()
260 spin_lock_bh(&net->nsid_lock); in peernet2id_alloc()
269 id = __peernet2id_alloc(net, peer, &alloc); in peernet2id_alloc()
270 spin_unlock_bh(&net->nsid_lock); in peernet2id_alloc()
272 rtnl_net_notifyid(net, RTM_NEWNSID, id, 0, NULL, gfp); in peernet2id_alloc()
280 int peernet2id(struct net *net, struct net *peer) in peernet2id() argument
284 spin_lock_bh(&net->nsid_lock); in peernet2id()
285 id = __peernet2id(net, peer); in peernet2id()
286 spin_unlock_bh(&net->nsid_lock); in peernet2id()
294 bool peernet_has_id(struct net *net, struct net *peer) in peernet_has_id() argument
296 return peernet2id(net, peer) >= 0; in peernet_has_id()
299 struct net *get_net_ns_by_id(struct net *net, int id) in get_net_ns_by_id() argument
301 struct net *peer; in get_net_ns_by_id()
307 peer = idr_find(&net->netns_ids, id); in get_net_ns_by_id()
318 static __net_init int setup_net(struct net *net, struct user_namespace *user_ns) in setup_net() argument
325 refcount_set(&net->count, 1); in setup_net()
326 refcount_set(&net->passive, 1); in setup_net()
327 get_random_bytes(&net->hash_mix, sizeof(u32)); in setup_net()
328 net->dev_base_seq = 1; in setup_net()
329 net->user_ns = user_ns; in setup_net()
330 idr_init(&net->netns_ids); in setup_net()
331 spin_lock_init(&net->nsid_lock); in setup_net()
332 mutex_init(&net->ipv4.ra_mutex); in setup_net()
335 error = ops_init(ops, net); in setup_net()
340 list_add_tail_rcu(&net->list, &net_namespace_list); in setup_net()
349 list_add(&net->exit_list, &net_exit_list); in setup_net()
368 static int __net_init net_defaults_init_net(struct net *net) in net_defaults_init_net() argument
370 net->core.sysctl_somaxconn = SOMAXCONN; in net_defaults_init_net()
402 static struct net *net_alloc(void) in net_alloc()
404 struct net *net = NULL; in net_alloc() local
411 net = kmem_cache_zalloc(net_cachep, GFP_KERNEL); in net_alloc()
412 if (!net) in net_alloc()
416 net->key_domain = kzalloc(sizeof(struct key_tag), GFP_KERNEL); in net_alloc()
417 if (!net->key_domain) in net_alloc()
419 refcount_set(&net->key_domain->usage, 1); in net_alloc()
422 rcu_assign_pointer(net->gen, ng); in net_alloc()
424 return net; in net_alloc()
428 kmem_cache_free(net_cachep, net); in net_alloc()
429 net = NULL; in net_alloc()
436 static void net_free(struct net *net) in net_free() argument
438 kfree(rcu_access_pointer(net->gen)); in net_free()
439 kmem_cache_free(net_cachep, net); in net_free()
444 struct net *ns = p; in net_drop_ns()
449 struct net *copy_net_ns(unsigned long flags, in copy_net_ns()
450 struct user_namespace *user_ns, struct net *old_net) in copy_net_ns()
453 struct net *net; in copy_net_ns() local
463 net = net_alloc(); in copy_net_ns()
464 if (!net) { in copy_net_ns()
468 refcount_set(&net->passive, 1); in copy_net_ns()
469 net->ucounts = ucounts; in copy_net_ns()
476 rv = setup_net(net, user_ns); in copy_net_ns()
482 key_remove_domain(net->key_domain); in copy_net_ns()
484 net_drop_ns(net); in copy_net_ns()
489 return net; in copy_net_ns()
501 void net_ns_get_ownership(const struct net *net, kuid_t *uid, kgid_t *gid) in net_ns_get_ownership() argument
503 if (net) { in net_ns_get_ownership()
504 kuid_t ns_root_uid = make_kuid(net->user_ns, 0); in net_ns_get_ownership()
505 kgid_t ns_root_gid = make_kgid(net->user_ns, 0); in net_ns_get_ownership()
519 static void unhash_nsid(struct net *net, struct net *last) in unhash_nsid() argument
521 struct net *tmp; in unhash_nsid()
532 id = __peernet2id(tmp, net); in unhash_nsid()
542 spin_lock_bh(&net->nsid_lock); in unhash_nsid()
543 idr_destroy(&net->netns_ids); in unhash_nsid()
544 spin_unlock_bh(&net->nsid_lock); in unhash_nsid()
552 struct net *net, *tmp, *last; in cleanup_net() local
563 llist_for_each_entry(net, net_kill_list, cleanup_list) in cleanup_net()
564 list_del_rcu(&net->list); in cleanup_net()
575 last = list_last_entry(&net_namespace_list, struct net, list); in cleanup_net()
578 llist_for_each_entry(net, net_kill_list, cleanup_list) { in cleanup_net()
579 unhash_nsid(net, last); in cleanup_net()
580 list_add_tail(&net->exit_list, &net_exit_list); in cleanup_net()
611 list_for_each_entry_safe(net, tmp, &net_exit_list, exit_list) { in cleanup_net()
612 list_del_init(&net->exit_list); in cleanup_net()
613 dec_net_namespaces(net->ucounts); in cleanup_net()
614 key_remove_domain(net->key_domain); in cleanup_net()
615 put_user_ns(net->user_ns); in cleanup_net()
616 net_drop_ns(net); in cleanup_net()
638 void __put_net(struct net *net) in __put_net() argument
641 if (llist_add(&net->cleanup_list, &cleanup_list)) in __put_net()
646 struct net *get_net_ns_by_fd(int fd) in get_net_ns_by_fd()
650 struct net *net; in get_net_ns_by_fd() local
658 net = get_net(container_of(ns, struct net, ns)); in get_net_ns_by_fd()
660 net = ERR_PTR(-EINVAL); in get_net_ns_by_fd()
663 return net; in get_net_ns_by_fd()
667 struct net *get_net_ns_by_fd(int fd) in get_net_ns_by_fd()
674 struct net *get_net_ns_by_pid(pid_t pid) in get_net_ns_by_pid()
677 struct net *net; in get_net_ns_by_pid() local
680 net = ERR_PTR(-ESRCH); in get_net_ns_by_pid()
688 net = get_net(nsproxy->net_ns); in get_net_ns_by_pid()
692 return net; in get_net_ns_by_pid()
696 static __net_init int net_ns_net_init(struct net *net) in net_ns_net_init() argument
699 net->ns.ops = &netns_operations; in net_ns_net_init()
701 return ns_alloc_inum(&net->ns); in net_ns_net_init()
704 static __net_exit void net_ns_net_exit(struct net *net) in net_ns_net_exit() argument
706 ns_free_inum(&net->ns); in net_ns_net_exit()
725 struct net *net = sock_net(skb->sk); in rtnl_net_newid() local
728 struct net *peer; in rtnl_net_newid()
757 spin_lock_bh(&net->nsid_lock); in rtnl_net_newid()
758 if (__peernet2id(net, peer) >= 0) { in rtnl_net_newid()
759 spin_unlock_bh(&net->nsid_lock); in rtnl_net_newid()
767 err = alloc_netid(net, peer, nsid); in rtnl_net_newid()
768 spin_unlock_bh(&net->nsid_lock); in rtnl_net_newid()
770 rtnl_net_notifyid(net, RTM_NEWNSID, err, NETLINK_CB(skb).portid, in rtnl_net_newid()
869 struct net *net = sock_net(skb->sk); in rtnl_net_getid() local
876 struct net *peer, *target = net; in rtnl_net_getid()
891 peer = get_net_ns_by_id(net, nla_get_s32(tb[NETNSA_NSID])); in rtnl_net_getid()
918 fillargs.ref_nsid = peernet2id(net, peer); in rtnl_net_getid()
932 err = rtnl_unicast(msg, net, NETLINK_CB(skb).portid); in rtnl_net_getid()
945 struct net *tgt_net;
946 struct net *ref_net;
992 struct net *net; in rtnl_valid_dump_net_req() local
994 net = rtnl_get_net_ns_capable(sk, nla_get_s32(tb[i])); in rtnl_valid_dump_net_req()
995 if (IS_ERR(net)) { in rtnl_valid_dump_net_req()
999 return PTR_ERR(net); in rtnl_valid_dump_net_req()
1003 net_cb->tgt_net = net; in rtnl_valid_dump_net_req()
1058 static void rtnl_net_notifyid(struct net *net, int cmd, int id, u32 portid, in rtnl_net_notifyid() argument
1078 rtnl_notify(msg, net, portid, RTNLGRP_NSID, nlh, gfp); in rtnl_net_notifyid()
1084 rtnl_set_sk_err(net, RTNLGRP_NSID, err); in rtnl_net_notifyid()
1092 net_cachep = kmem_cache_create("net_namespace", sizeof(struct net), in net_ns_init()
1132 struct net *net; in __register_pernet_operations() local
1141 for_each_net(net) { in __register_pernet_operations()
1142 error = ops_init(ops, net); in __register_pernet_operations()
1145 list_add_tail(&net->exit_list, &net_exit_list); in __register_pernet_operations()
1162 struct net *net; in __unregister_pernet_operations() local
1167 for_each_net(net) in __unregister_pernet_operations()
1168 list_add_tail(&net->exit_list, &net_exit_list); in __unregister_pernet_operations()
1336 struct net *net = NULL; in netns_get() local
1342 net = get_net(nsproxy->net_ns); in netns_get()
1345 return net ? &net->ns : NULL; in netns_get()
1348 static inline struct net *to_net_ns(struct ns_common *ns) in to_net_ns()
1350 return container_of(ns, struct net, ns); in to_net_ns()
1360 struct net *net = to_net_ns(ns); in netns_install() local
1362 if (!ns_capable(net->user_ns, CAP_SYS_ADMIN) || in netns_install()
1367 nsproxy->net_ns = get_net(net); in netns_install()