Lines Matching refs:net
48 struct net init_net;
82 static int net_assign_generic(struct net *net, unsigned int id, void *data) in net_assign_generic() argument
88 old_ng = rcu_dereference_protected(net->gen, in net_assign_generic()
114 rcu_assign_pointer(net->gen, ng); in net_assign_generic()
119 static int ops_init(const struct pernet_operations *ops, struct net *net) in ops_init() argument
130 err = net_assign_generic(net, *ops->id, data); in ops_init()
136 err = ops->init(net); in ops_init()
141 ng = rcu_dereference_protected(net->gen, in ops_init()
156 struct net *net; in ops_pre_exit_list() local
159 list_for_each_entry(net, net_exit_list, exit_list) in ops_pre_exit_list()
160 ops->pre_exit(net); in ops_pre_exit_list()
167 struct net *net; in ops_exit_list() local
169 list_for_each_entry(net, net_exit_list, exit_list) { in ops_exit_list()
170 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 kfree(net_generic(net, *ops->id)); 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()
215 static int __peernet2id(const struct net *net, struct net *peer) in __peernet2id() argument
217 int id = idr_for_each(&net->netns_ids, net_eq_idr, peer); in __peernet2id()
228 static void rtnl_net_notifyid(struct net *net, int cmd, int id, u32 portid,
233 int peernet2id_alloc(struct net *net, struct net *peer, gfp_t gfp) in peernet2id_alloc() argument
237 if (refcount_read(&net->ns.count) == 0) in peernet2id_alloc()
240 spin_lock_bh(&net->nsid_lock); in peernet2id_alloc()
241 id = __peernet2id(net, peer); in peernet2id_alloc()
243 spin_unlock_bh(&net->nsid_lock); in peernet2id_alloc()
253 spin_unlock_bh(&net->nsid_lock); in peernet2id_alloc()
257 id = alloc_netid(net, peer, -1); in peernet2id_alloc()
258 spin_unlock_bh(&net->nsid_lock); in peernet2id_alloc()
264 rtnl_net_notifyid(net, RTM_NEWNSID, id, 0, NULL, gfp); in peernet2id_alloc()
271 int peernet2id(const struct net *net, struct net *peer) in peernet2id() argument
276 id = __peernet2id(net, peer); in peernet2id()
286 bool peernet_has_id(const struct net *net, struct net *peer) in peernet_has_id() argument
288 return peernet2id(net, peer) >= 0; in peernet_has_id()
291 struct net *get_net_ns_by_id(const struct net *net, int id) in get_net_ns_by_id() argument
293 struct net *peer; in get_net_ns_by_id()
299 peer = idr_find(&net->netns_ids, id); in get_net_ns_by_id()
309 static __net_init void preinit_net(struct net *net) in preinit_net() argument
311 ref_tracker_dir_init(&net->notrefcnt_tracker, 128, "net notrefcnt"); in preinit_net()
317 static __net_init int setup_net(struct net *net, struct user_namespace *user_ns) in setup_net() argument
324 refcount_set(&net->ns.count, 1); in setup_net()
325 ref_tracker_dir_init(&net->refcnt_tracker, 128, "net refcnt"); in setup_net()
327 refcount_set(&net->passive, 1); in setup_net()
328 get_random_bytes(&net->hash_mix, sizeof(u32)); in setup_net()
330 net->net_cookie = gen_cookie_next(&net_cookie); in setup_net()
332 net->dev_base_seq = 1; in setup_net()
333 net->user_ns = user_ns; in setup_net()
334 idr_init(&net->netns_ids); in setup_net()
335 spin_lock_init(&net->nsid_lock); in setup_net()
336 mutex_init(&net->ipv4.ra_mutex); in setup_net()
339 error = ops_init(ops, net); in setup_net()
344 list_add_tail_rcu(&net->list, &net_namespace_list); in setup_net()
353 list_add(&net->exit_list, &net_exit_list); in setup_net()
372 static int __net_init net_defaults_init_net(struct net *net) in net_defaults_init_net() argument
374 net->core.sysctl_somaxconn = SOMAXCONN; in net_defaults_init_net()
375 net->core.sysctl_txrehash = SOCK_TXREHASH_ENABLED; in net_defaults_init_net()
408 static struct net *net_alloc(void) in net_alloc()
410 struct net *net = NULL; in net_alloc() local
417 net = kmem_cache_zalloc(net_cachep, GFP_KERNEL); in net_alloc()
418 if (!net) in net_alloc()
422 net->key_domain = kzalloc(sizeof(struct key_tag), GFP_KERNEL); in net_alloc()
423 if (!net->key_domain) in net_alloc()
425 refcount_set(&net->key_domain->usage, 1); in net_alloc()
428 rcu_assign_pointer(net->gen, ng); in net_alloc()
430 return net; in net_alloc()
434 kmem_cache_free(net_cachep, net); in net_alloc()
435 net = NULL; in net_alloc()
442 static void net_free(struct net *net) in net_free() argument
444 if (refcount_dec_and_test(&net->passive)) { in net_free()
445 kfree(rcu_access_pointer(net->gen)); in net_free()
448 ref_tracker_dir_exit(&net->notrefcnt_tracker); in net_free()
450 kmem_cache_free(net_cachep, net); in net_free()
456 struct net *net = (struct net *)p; in net_drop_ns() local
458 if (net) in net_drop_ns()
459 net_free(net); in net_drop_ns()
462 struct net *copy_net_ns(unsigned long flags, in copy_net_ns()
463 struct user_namespace *user_ns, struct net *old_net) in copy_net_ns()
466 struct net *net; in copy_net_ns() local
476 net = net_alloc(); in copy_net_ns()
477 if (!net) { in copy_net_ns()
482 preinit_net(net); in copy_net_ns()
483 refcount_set(&net->passive, 1); in copy_net_ns()
484 net->ucounts = ucounts; in copy_net_ns()
491 rv = setup_net(net, user_ns); in copy_net_ns()
498 key_remove_domain(net->key_domain); in copy_net_ns()
501 net_free(net); in copy_net_ns()
506 return net; in copy_net_ns()
518 void net_ns_get_ownership(const struct net *net, kuid_t *uid, kgid_t *gid) in net_ns_get_ownership() argument
520 if (net) { in net_ns_get_ownership()
521 kuid_t ns_root_uid = make_kuid(net->user_ns, 0); in net_ns_get_ownership()
522 kgid_t ns_root_gid = make_kgid(net->user_ns, 0); in net_ns_get_ownership()
536 static void unhash_nsid(struct net *net, struct net *last) in unhash_nsid() argument
538 struct net *tmp; in unhash_nsid()
549 id = __peernet2id(tmp, net); in unhash_nsid()
559 spin_lock_bh(&net->nsid_lock); in unhash_nsid()
560 idr_destroy(&net->netns_ids); in unhash_nsid()
561 spin_unlock_bh(&net->nsid_lock); in unhash_nsid()
569 struct net *net, *tmp, *last; in cleanup_net() local
580 llist_for_each_entry(net, net_kill_list, cleanup_list) in cleanup_net()
581 list_del_rcu(&net->list); in cleanup_net()
592 last = list_last_entry(&net_namespace_list, struct net, list); in cleanup_net()
595 llist_for_each_entry(net, net_kill_list, cleanup_list) { in cleanup_net()
596 unhash_nsid(net, last); in cleanup_net()
597 list_add_tail(&net->exit_list, &net_exit_list); in cleanup_net()
628 list_for_each_entry_safe(net, tmp, &net_exit_list, exit_list) { in cleanup_net()
629 list_del_init(&net->exit_list); in cleanup_net()
630 dec_net_namespaces(net->ucounts); in cleanup_net()
632 key_remove_domain(net->key_domain); in cleanup_net()
634 put_user_ns(net->user_ns); in cleanup_net()
635 net_free(net); in cleanup_net()
657 void __put_net(struct net *net) in __put_net() argument
659 ref_tracker_dir_exit(&net->refcnt_tracker); in __put_net()
661 if (llist_add(&net->cleanup_list, &cleanup_list)) in __put_net()
674 return &get_net(container_of(ns, struct net, ns))->ns; in get_net_ns()
678 struct net *get_net_ns_by_fd(int fd) in get_net_ns_by_fd()
681 struct net *net = ERR_PTR(-EINVAL); in get_net_ns_by_fd() local
689 net = get_net(container_of(ns, struct net, ns)); in get_net_ns_by_fd()
693 return net; in get_net_ns_by_fd()
698 struct net *get_net_ns_by_pid(pid_t pid) in get_net_ns_by_pid()
701 struct net *net; in get_net_ns_by_pid() local
704 net = ERR_PTR(-ESRCH); in get_net_ns_by_pid()
712 net = get_net(nsproxy->net_ns); in get_net_ns_by_pid()
716 return net; in get_net_ns_by_pid()
720 static __net_init int net_ns_net_init(struct net *net) in net_ns_net_init() argument
723 net->ns.ops = &netns_operations; in net_ns_net_init()
725 return ns_alloc_inum(&net->ns); in net_ns_net_init()
728 static __net_exit void net_ns_net_exit(struct net *net) in net_ns_net_exit() argument
730 ns_free_inum(&net->ns); in net_ns_net_exit()
749 struct net *net = sock_net(skb->sk); in rtnl_net_newid() local
752 struct net *peer; in rtnl_net_newid()
781 spin_lock_bh(&net->nsid_lock); in rtnl_net_newid()
782 if (__peernet2id(net, peer) >= 0) { in rtnl_net_newid()
783 spin_unlock_bh(&net->nsid_lock); in rtnl_net_newid()
791 err = alloc_netid(net, peer, nsid); in rtnl_net_newid()
792 spin_unlock_bh(&net->nsid_lock); in rtnl_net_newid()
794 rtnl_net_notifyid(net, RTM_NEWNSID, err, NETLINK_CB(skb).portid, in rtnl_net_newid()
893 struct net *net = sock_net(skb->sk); in rtnl_net_getid() local
900 struct net *peer, *target = net; in rtnl_net_getid()
915 peer = get_net_ns_by_id(net, nla_get_s32(tb[NETNSA_NSID])); in rtnl_net_getid()
942 fillargs.ref_nsid = peernet2id(net, peer); in rtnl_net_getid()
956 err = rtnl_unicast(msg, net, NETLINK_CB(skb).portid); in rtnl_net_getid()
969 struct net *tgt_net;
970 struct net *ref_net;
1017 struct net *net; in rtnl_valid_dump_net_req() local
1019 net = rtnl_get_net_ns_capable(sk, nla_get_s32(tb[i])); in rtnl_valid_dump_net_req()
1020 if (IS_ERR(net)) { in rtnl_valid_dump_net_req()
1024 return PTR_ERR(net); in rtnl_valid_dump_net_req()
1028 net_cb->tgt_net = net; in rtnl_valid_dump_net_req()
1073 static void rtnl_net_notifyid(struct net *net, int cmd, int id, u32 portid, in rtnl_net_notifyid() argument
1093 rtnl_notify(msg, net, portid, RTNLGRP_NSID, nlh, gfp); in rtnl_net_notifyid()
1099 rtnl_set_sk_err(net, RTNLGRP_NSID, err); in rtnl_net_notifyid()
1107 net_cachep = kmem_cache_create("net_namespace", sizeof(struct net), in net_ns_init()
1155 struct net *net; in __register_pernet_operations() local
1164 for_each_net(net) { in __register_pernet_operations()
1165 error = ops_init(ops, net); in __register_pernet_operations()
1168 list_add_tail(&net->exit_list, &net_exit_list); in __register_pernet_operations()
1182 struct net *net; in __unregister_pernet_operations() local
1187 for_each_net(net) in __unregister_pernet_operations()
1188 list_add_tail(&net->exit_list, &net_exit_list); in __unregister_pernet_operations()
1351 struct net *net = NULL; in netns_get() local
1357 net = get_net(nsproxy->net_ns); in netns_get()
1360 return net ? &net->ns : NULL; in netns_get()
1363 static inline struct net *to_net_ns(struct ns_common *ns) in to_net_ns()
1365 return container_of(ns, struct net, ns); in to_net_ns()
1376 struct net *net = to_net_ns(ns); in netns_install() local
1378 if (!ns_capable(net->user_ns, CAP_SYS_ADMIN) || in netns_install()
1383 nsproxy->net_ns = get_net(net); in netns_install()