Lines Matching refs:tfile

328 			    struct tun_file *tfile)  in tun_flow_update()  argument
333 u16 queue_index = tfile->queue_index; in tun_flow_update()
344 if (tun->numqueues == 1 || tfile->detached) in tun_flow_update()
432 static void tun_disable_queue(struct tun_struct *tun, struct tun_file *tfile) in tun_disable_queue() argument
434 tfile->detached = tun; in tun_disable_queue()
435 list_add_tail(&tfile->next, &tun->disabled); in tun_disable_queue()
439 static struct tun_struct *tun_enable_queue(struct tun_file *tfile) in tun_enable_queue() argument
441 struct tun_struct *tun = tfile->detached; in tun_enable_queue()
443 tfile->detached = NULL; in tun_enable_queue()
444 list_del_init(&tfile->next); in tun_enable_queue()
449 static void tun_queue_purge(struct tun_file *tfile) in tun_queue_purge() argument
451 skb_queue_purge(&tfile->sk.sk_receive_queue); in tun_queue_purge()
452 skb_queue_purge(&tfile->sk.sk_error_queue); in tun_queue_purge()
455 static void __tun_detach(struct tun_file *tfile, bool clean) in __tun_detach() argument
460 tun = rtnl_dereference(tfile->tun); in __tun_detach()
462 if (tun && !tfile->detached) { in __tun_detach()
463 u16 index = tfile->queue_index; in __tun_detach()
473 RCU_INIT_POINTER(tfile->tun, NULL); in __tun_detach()
474 sock_put(&tfile->sk); in __tun_detach()
476 tun_disable_queue(tun, tfile); in __tun_detach()
481 tun_queue_purge(tfile); in __tun_detach()
483 } else if (tfile->detached && clean) { in __tun_detach()
484 tun = tun_enable_queue(tfile); in __tun_detach()
485 sock_put(&tfile->sk); in __tun_detach()
498 &tfile->socket.flags)); in __tun_detach()
499 sk_release_kernel(&tfile->sk); in __tun_detach()
503 static void tun_detach(struct tun_file *tfile, bool clean) in tun_detach() argument
506 __tun_detach(tfile, clean); in tun_detach()
513 struct tun_file *tfile, *tmp; in tun_detach_all() local
517 tfile = rtnl_dereference(tun->tfiles[i]); in tun_detach_all()
518 BUG_ON(!tfile); in tun_detach_all()
519 tfile->socket.sk->sk_data_ready(tfile->socket.sk); in tun_detach_all()
520 RCU_INIT_POINTER(tfile->tun, NULL); in tun_detach_all()
523 list_for_each_entry(tfile, &tun->disabled, next) { in tun_detach_all()
524 tfile->socket.sk->sk_data_ready(tfile->socket.sk); in tun_detach_all()
525 RCU_INIT_POINTER(tfile->tun, NULL); in tun_detach_all()
531 tfile = rtnl_dereference(tun->tfiles[i]); in tun_detach_all()
533 tun_queue_purge(tfile); in tun_detach_all()
534 sock_put(&tfile->sk); in tun_detach_all()
536 list_for_each_entry_safe(tfile, tmp, &tun->disabled, next) { in tun_detach_all()
537 tun_enable_queue(tfile); in tun_detach_all()
538 tun_queue_purge(tfile); in tun_detach_all()
539 sock_put(&tfile->sk); in tun_detach_all()
549 struct tun_file *tfile = file->private_data; in tun_attach() local
552 err = security_tun_dev_attach(tfile->socket.sk, tun->security); in tun_attach()
557 if (rtnl_dereference(tfile->tun) && !tfile->detached) in tun_attach()
565 if (!tfile->detached && in tun_attach()
573 err = sk_attach_filter(&tun->fprog, tfile->socket.sk); in tun_attach()
577 tfile->queue_index = tun->numqueues; in tun_attach()
578 rcu_assign_pointer(tfile->tun, tun); in tun_attach()
579 rcu_assign_pointer(tun->tfiles[tun->numqueues], tfile); in tun_attach()
582 if (tfile->detached) in tun_attach()
583 tun_enable_queue(tfile); in tun_attach()
585 sock_hold(&tfile->sk); in tun_attach()
597 static struct tun_struct *__tun_get(struct tun_file *tfile) in __tun_get() argument
602 tun = rcu_dereference(tfile->tun); in __tun_get()
759 struct tun_file *tfile; in tun_net_xmit() local
763 tfile = rcu_dereference(tun->tfiles[txq]); in tun_net_xmit()
788 BUG_ON(!tfile); in tun_net_xmit()
796 if (tfile->socket.sk->sk_filter && in tun_net_xmit()
797 sk_filter(tfile->socket.sk, skb)) in tun_net_xmit()
803 if (skb_queue_len(&tfile->socket.sk->sk_receive_queue) * numqueues in tun_net_xmit()
823 skb_queue_tail(&tfile->socket.sk->sk_receive_queue, skb); in tun_net_xmit()
826 if (tfile->flags & TUN_FASYNC) in tun_net_xmit()
827 kill_fasync(&tfile->fasync, SIGIO, POLL_IN); in tun_net_xmit()
828 tfile->socket.sk->sk_data_ready(tfile->socket.sk); in tun_net_xmit()
973 struct tun_file *tfile = file->private_data; in tun_chr_poll() local
974 struct tun_struct *tun = __tun_get(tfile); in tun_chr_poll()
981 sk = tfile->socket.sk; in tun_chr_poll()
1004 static struct sk_buff *tun_alloc_skb(struct tun_file *tfile, in tun_alloc_skb() argument
1008 struct sock *sk = tfile->socket.sk; in tun_alloc_skb()
1030 static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, in tun_get_user() argument
1107 skb = tun_alloc_skb(tfile, align, copylen, linear, noblock); in tun_get_user()
1214 tun_flow_update(tun, rxhash, tfile); in tun_get_user()
1222 struct tun_file *tfile = file->private_data; in tun_chr_write_iter() local
1228 result = tun_get_user(tun, tfile, NULL, from, file->f_flags & O_NONBLOCK); in tun_chr_write_iter()
1236 struct tun_file *tfile, in tun_put_user() argument
1347 static ssize_t tun_do_read(struct tun_struct *tun, struct tun_file *tfile, in tun_do_read() argument
1364 skb = __skb_recv_datagram(tfile->socket.sk, noblock ? MSG_DONTWAIT : 0, in tun_do_read()
1369 ret = tun_put_user(tun, tfile, skb, to); in tun_do_read()
1381 struct tun_file *tfile = file->private_data; in tun_chr_read_iter() local
1382 struct tun_struct *tun = __tun_get(tfile); in tun_chr_read_iter()
1387 ret = tun_do_read(tun, tfile, to, file->f_flags & O_NONBLOCK); in tun_chr_read_iter()
1433 struct tun_file *tfile; in tun_sock_write_space() local
1447 tfile = container_of(sk, struct tun_file, sk); in tun_sock_write_space()
1448 kill_fasync(&tfile->fasync, SIGIO, POLL_OUT); in tun_sock_write_space()
1454 struct tun_file *tfile = container_of(sock, struct tun_file, socket); in tun_sendmsg() local
1455 struct tun_struct *tun = __tun_get(tfile); in tun_sendmsg()
1460 ret = tun_get_user(tun, tfile, m->msg_control, &m->msg_iter, in tun_sendmsg()
1469 struct tun_file *tfile = container_of(sock, struct tun_file, socket); in tun_recvmsg() local
1470 struct tun_struct *tun = __tun_get(tfile); in tun_recvmsg()
1485 ret = tun_do_read(tun, tfile, &m->msg_iter, flags & MSG_DONTWAIT); in tun_recvmsg()
1565 struct tun_file *tfile = file->private_data; in tun_set_iff() local
1569 if (tfile->detached) in tun_set_iff()
1641 dev->ifindex = tfile->ifindex; in tun_set_iff()
1651 tun->sndbuf = tfile->socket.sk->sk_sndbuf; in tun_set_iff()
1759 struct tun_file *tfile; in tun_detach_filter() local
1762 tfile = rtnl_dereference(tun->tfiles[i]); in tun_detach_filter()
1763 sk_detach_filter(tfile->socket.sk); in tun_detach_filter()
1772 struct tun_file *tfile; in tun_attach_filter() local
1775 tfile = rtnl_dereference(tun->tfiles[i]); in tun_attach_filter()
1776 ret = sk_attach_filter(&tun->fprog, tfile->socket.sk); in tun_attach_filter()
1789 struct tun_file *tfile; in tun_set_sndbuf() local
1793 tfile = rtnl_dereference(tun->tfiles[i]); in tun_set_sndbuf()
1794 tfile->socket.sk->sk_sndbuf = tun->sndbuf; in tun_set_sndbuf()
1800 struct tun_file *tfile = file->private_data; in tun_set_queue() local
1807 tun = tfile->detached; in tun_set_queue()
1817 tun = rtnl_dereference(tfile->tun); in tun_set_queue()
1818 if (!tun || !(tun->flags & IFF_MULTI_QUEUE) || tfile->detached) in tun_set_queue()
1821 __tun_detach(tfile, false); in tun_set_queue()
1833 struct tun_file *tfile = file->private_data; in __tun_chr_ioctl() local
1864 tun = __tun_get(tfile); in __tun_chr_ioctl()
1868 ret = tun_set_iff(tfile->net, file, &ifr); in __tun_chr_ioctl()
1887 tfile->ifindex = ifindex; in __tun_chr_ioctl()
1902 if (tfile->detached) in __tun_chr_ioctl()
1904 if (!tfile->socket.sk->sk_filter) in __tun_chr_ioctl()
2008 sndbuf = tfile->socket.sk->sk_sndbuf; in __tun_chr_ioctl()
2139 struct tun_file *tfile = file->private_data; in tun_chr_fasync() local
2142 if ((ret = fasync_helper(fd, file, on, &tfile->fasync)) < 0) in tun_chr_fasync()
2147 tfile->flags |= TUN_FASYNC; in tun_chr_fasync()
2149 tfile->flags &= ~TUN_FASYNC; in tun_chr_fasync()
2157 struct tun_file *tfile; in tun_chr_open() local
2161 tfile = (struct tun_file *)sk_alloc(&init_net, AF_UNSPEC, GFP_KERNEL, in tun_chr_open()
2163 if (!tfile) in tun_chr_open()
2165 RCU_INIT_POINTER(tfile->tun, NULL); in tun_chr_open()
2166 tfile->net = get_net(current->nsproxy->net_ns); in tun_chr_open()
2167 tfile->flags = 0; in tun_chr_open()
2168 tfile->ifindex = 0; in tun_chr_open()
2170 init_waitqueue_head(&tfile->wq.wait); in tun_chr_open()
2171 RCU_INIT_POINTER(tfile->socket.wq, &tfile->wq); in tun_chr_open()
2173 tfile->socket.file = file; in tun_chr_open()
2174 tfile->socket.ops = &tun_socket_ops; in tun_chr_open()
2176 sock_init_data(&tfile->socket, &tfile->sk); in tun_chr_open()
2177 sk_change_net(&tfile->sk, tfile->net); in tun_chr_open()
2179 tfile->sk.sk_write_space = tun_sock_write_space; in tun_chr_open()
2180 tfile->sk.sk_sndbuf = INT_MAX; in tun_chr_open()
2182 file->private_data = tfile; in tun_chr_open()
2183 set_bit(SOCK_EXTERNALLY_ALLOCATED, &tfile->socket.flags); in tun_chr_open()
2184 INIT_LIST_HEAD(&tfile->next); in tun_chr_open()
2186 sock_set_flag(&tfile->sk, SOCK_ZEROCOPY); in tun_chr_open()
2193 struct tun_file *tfile = file->private_data; in tun_chr_close() local
2194 struct net *net = tfile->net; in tun_chr_close()
2196 tun_detach(tfile, true); in tun_chr_close()
2347 struct tun_file *tfile; in tun_get_socket() local
2350 tfile = file->private_data; in tun_get_socket()
2351 if (!tfile) in tun_get_socket()
2353 return &tfile->socket; in tun_get_socket()