Lines Matching full:net

6 #include <net/net_namespace.h>
17 /* We don't hold a ref to net in order to auto-detach the link
22 struct net *net; member
23 struct list_head node; /* node in list of links attached to net */
56 static void netns_bpf_run_array_detach(struct net *net, in netns_bpf_run_array_detach() argument
61 run_array = rcu_replace_pointer(net->bpf.run_array[type], NULL, in netns_bpf_run_array_detach()
66 static int link_index(struct net *net, enum netns_bpf_attach_type type, in link_index() argument
72 list_for_each_entry(pos, &net->bpf.links[type], node) { in link_index()
80 static int link_count(struct net *net, enum netns_bpf_attach_type type) in link_count() argument
85 list_for_each(pos, &net->bpf.links[type]) in link_count()
90 static void fill_prog_array(struct net *net, enum netns_bpf_attach_type type, in fill_prog_array() argument
96 list_for_each_entry(pos, &net->bpf.links[type], node) { in fill_prog_array()
108 struct net *net; in bpf_netns_link_release() local
114 * struct net pointer, pre_exit has not run yet and wait for in bpf_netns_link_release()
117 net = net_link->net; in bpf_netns_link_release()
118 if (!net) in bpf_netns_link_release()
125 idx = link_index(net, type, net_link); in bpf_netns_link_release()
128 cnt = link_count(net, type); in bpf_netns_link_release()
130 netns_bpf_run_array_detach(net, type); in bpf_netns_link_release()
134 old_array = rcu_dereference_protected(net->bpf.run_array[type], in bpf_netns_link_release()
141 fill_prog_array(net, type, new_array); in bpf_netns_link_release()
142 rcu_assign_pointer(net->bpf.run_array[type], new_array); in bpf_netns_link_release()
146 net_link->net = NULL; in bpf_netns_link_release()
172 struct net *net; in bpf_netns_link_update_prog() local
182 net = net_link->net; in bpf_netns_link_update_prog()
183 if (!net || !check_net(net)) { in bpf_netns_link_update_prog()
189 run_array = rcu_dereference_protected(net->bpf.run_array[type], in bpf_netns_link_update_prog()
191 idx = link_index(net, type, net_link); in bpf_netns_link_update_prog()
210 struct net *net; in bpf_netns_link_fill_info() local
213 net = net_link->net; in bpf_netns_link_fill_info()
214 if (net && check_net(net)) in bpf_netns_link_fill_info()
215 inum = net->ns.inum; in bpf_netns_link_fill_info()
248 struct net *net, in __netns_bpf_prog_query() argument
255 run_array = rcu_dereference_protected(net->bpf.run_array[type], in __netns_bpf_prog_query()
275 struct net *net; in netns_bpf_prog_query() local
285 net = get_net_ns_by_fd(attr->query.target_fd); in netns_bpf_prog_query()
286 if (IS_ERR(net)) in netns_bpf_prog_query()
287 return PTR_ERR(net); in netns_bpf_prog_query()
290 ret = __netns_bpf_prog_query(attr, uattr, net, type); in netns_bpf_prog_query()
293 put_net(net); in netns_bpf_prog_query()
302 struct net *net; in netns_bpf_prog_attach() local
312 net = current->nsproxy->net_ns; in netns_bpf_prog_attach()
316 if (!list_empty(&net->bpf.links[type])) { in netns_bpf_prog_attach()
323 ret = flow_dissector_bpf_prog_attach_check(net, prog); in netns_bpf_prog_attach()
332 attached = net->bpf.progs[type]; in netns_bpf_prog_attach()
339 run_array = rcu_dereference_protected(net->bpf.run_array[type], in netns_bpf_prog_attach()
350 rcu_assign_pointer(net->bpf.run_array[type], run_array); in netns_bpf_prog_attach()
353 net->bpf.progs[type] = prog; in netns_bpf_prog_attach()
364 static int __netns_bpf_prog_detach(struct net *net, in __netns_bpf_prog_detach() argument
371 if (!list_empty(&net->bpf.links[type])) in __netns_bpf_prog_detach()
374 attached = net->bpf.progs[type]; in __netns_bpf_prog_detach()
377 netns_bpf_run_array_detach(net, type); in __netns_bpf_prog_detach()
378 net->bpf.progs[type] = NULL; in __netns_bpf_prog_detach()
421 static int netns_bpf_link_attach(struct net *net, struct bpf_link *link, in netns_bpf_link_attach() argument
431 cnt = link_count(net, type); in netns_bpf_link_attach()
437 if (net->bpf.progs[type]) { in netns_bpf_link_attach()
444 err = flow_dissector_bpf_prog_attach_check(net, link->prog); in netns_bpf_link_attach()
462 list_add_tail(&net_link->node, &net->bpf.links[type]); in netns_bpf_link_attach()
464 fill_prog_array(net, type, run_array); in netns_bpf_link_attach()
465 run_array = rcu_replace_pointer(net->bpf.run_array[type], run_array, in netns_bpf_link_attach()
483 struct net *net; in netns_bpf_link_create() local
494 net = get_net_ns_by_fd(attr->link_create.target_fd); in netns_bpf_link_create()
495 if (IS_ERR(net)) in netns_bpf_link_create()
496 return PTR_ERR(net); in netns_bpf_link_create()
505 net_link->net = net; in netns_bpf_link_create()
515 err = netns_bpf_link_attach(net, &net_link->link, netns_type); in netns_bpf_link_create()
521 put_net(net); in netns_bpf_link_create()
525 put_net(net); in netns_bpf_link_create()
529 static int __net_init netns_bpf_pernet_init(struct net *net) in netns_bpf_pernet_init() argument
534 INIT_LIST_HEAD(&net->bpf.links[type]); in netns_bpf_pernet_init()
539 static void __net_exit netns_bpf_pernet_pre_exit(struct net *net) in netns_bpf_pernet_pre_exit() argument
546 netns_bpf_run_array_detach(net, type); in netns_bpf_pernet_pre_exit()
547 list_for_each_entry(net_link, &net->bpf.links[type], node) { in netns_bpf_pernet_pre_exit()
548 net_link->net = NULL; /* auto-detach link */ in netns_bpf_pernet_pre_exit()
551 if (net->bpf.progs[type]) in netns_bpf_pernet_pre_exit()
552 bpf_prog_put(net->bpf.progs[type]); in netns_bpf_pernet_pre_exit()