• Home
  • Raw
  • Download

Lines Matching refs:tfile

272 	struct tun_file *tfile = container_of(napi, struct tun_file, napi);  in tun_napi_receive()  local
273 struct sk_buff_head *queue = &tfile->sk.sk_write_queue; in tun_napi_receive()
310 static void tun_napi_init(struct tun_struct *tun, struct tun_file *tfile, in tun_napi_init() argument
313 tfile->napi_enabled = napi_en; in tun_napi_init()
314 tfile->napi_frags_enabled = napi_en && napi_frags; in tun_napi_init()
316 netif_tx_napi_add(tun->dev, &tfile->napi, tun_napi_poll, in tun_napi_init()
318 napi_enable(&tfile->napi); in tun_napi_init()
322 static void tun_napi_disable(struct tun_file *tfile) in tun_napi_disable() argument
324 if (tfile->napi_enabled) in tun_napi_disable()
325 napi_disable(&tfile->napi); in tun_napi_disable()
328 static void tun_napi_del(struct tun_file *tfile) in tun_napi_del() argument
330 if (tfile->napi_enabled) in tun_napi_del()
331 netif_napi_del(&tfile->napi); in tun_napi_del()
334 static bool tun_napi_frags_enabled(const struct tun_file *tfile) in tun_napi_frags_enabled() argument
336 return tfile->napi_frags_enabled; in tun_napi_frags_enabled()
515 struct tun_file *tfile) in tun_flow_update() argument
520 u16 queue_index = tfile->queue_index; in tun_flow_update()
635 static void tun_disable_queue(struct tun_struct *tun, struct tun_file *tfile) in tun_disable_queue() argument
637 tfile->detached = tun; in tun_disable_queue()
638 list_add_tail(&tfile->next, &tun->disabled); in tun_disable_queue()
642 static struct tun_struct *tun_enable_queue(struct tun_file *tfile) in tun_enable_queue() argument
644 struct tun_struct *tun = tfile->detached; in tun_enable_queue()
646 tfile->detached = NULL; in tun_enable_queue()
647 list_del_init(&tfile->next); in tun_enable_queue()
666 static void tun_queue_purge(struct tun_file *tfile) in tun_queue_purge() argument
670 while ((ptr = ptr_ring_consume(&tfile->tx_ring)) != NULL) in tun_queue_purge()
673 skb_queue_purge(&tfile->sk.sk_write_queue); in tun_queue_purge()
674 skb_queue_purge(&tfile->sk.sk_error_queue); in tun_queue_purge()
677 static void __tun_detach(struct tun_file *tfile, bool clean) in __tun_detach() argument
682 tun = rtnl_dereference(tfile->tun); in __tun_detach()
685 tun_napi_disable(tfile); in __tun_detach()
686 tun_napi_del(tfile); in __tun_detach()
689 if (tun && !tfile->detached) { in __tun_detach()
690 u16 index = tfile->queue_index; in __tun_detach()
702 RCU_INIT_POINTER(tfile->tun, NULL); in __tun_detach()
703 sock_put(&tfile->sk); in __tun_detach()
705 tun_disable_queue(tun, tfile); in __tun_detach()
710 tun_queue_purge(tfile); in __tun_detach()
712 } else if (tfile->detached && clean) { in __tun_detach()
713 tun = tun_enable_queue(tfile); in __tun_detach()
714 sock_put(&tfile->sk); in __tun_detach()
726 xdp_rxq_info_unreg(&tfile->xdp_rxq); in __tun_detach()
727 ptr_ring_cleanup(&tfile->tx_ring, tun_ptr_free); in __tun_detach()
728 sock_put(&tfile->sk); in __tun_detach()
732 static void tun_detach(struct tun_file *tfile, bool clean) in tun_detach() argument
738 tun = rtnl_dereference(tfile->tun); in tun_detach()
740 __tun_detach(tfile, clean); in tun_detach()
749 struct tun_file *tfile, *tmp; in tun_detach_all() local
753 tfile = rtnl_dereference(tun->tfiles[i]); in tun_detach_all()
754 BUG_ON(!tfile); in tun_detach_all()
755 tun_napi_disable(tfile); in tun_detach_all()
756 tfile->socket.sk->sk_shutdown = RCV_SHUTDOWN; in tun_detach_all()
757 tfile->socket.sk->sk_data_ready(tfile->socket.sk); in tun_detach_all()
758 RCU_INIT_POINTER(tfile->tun, NULL); in tun_detach_all()
761 list_for_each_entry(tfile, &tun->disabled, next) { in tun_detach_all()
762 tfile->socket.sk->sk_shutdown = RCV_SHUTDOWN; in tun_detach_all()
763 tfile->socket.sk->sk_data_ready(tfile->socket.sk); in tun_detach_all()
764 RCU_INIT_POINTER(tfile->tun, NULL); in tun_detach_all()
770 tfile = rtnl_dereference(tun->tfiles[i]); in tun_detach_all()
771 tun_napi_del(tfile); in tun_detach_all()
773 tun_queue_purge(tfile); in tun_detach_all()
774 xdp_rxq_info_unreg(&tfile->xdp_rxq); in tun_detach_all()
775 sock_put(&tfile->sk); in tun_detach_all()
777 list_for_each_entry_safe(tfile, tmp, &tun->disabled, next) { in tun_detach_all()
778 tun_enable_queue(tfile); in tun_detach_all()
779 tun_queue_purge(tfile); in tun_detach_all()
780 xdp_rxq_info_unreg(&tfile->xdp_rxq); in tun_detach_all()
781 sock_put(&tfile->sk); in tun_detach_all()
793 struct tun_file *tfile = file->private_data; in tun_attach() local
797 err = security_tun_dev_attach(tfile->socket.sk, tun->security); in tun_attach()
802 if (rtnl_dereference(tfile->tun) && !tfile->detached) in tun_attach()
810 if (!tfile->detached && in tun_attach()
818 lock_sock(tfile->socket.sk); in tun_attach()
819 err = sk_attach_filter(&tun->fprog, tfile->socket.sk); in tun_attach()
820 release_sock(tfile->socket.sk); in tun_attach()
825 if (!tfile->detached && in tun_attach()
826 ptr_ring_resize(&tfile->tx_ring, dev->tx_queue_len, in tun_attach()
832 tfile->queue_index = tun->numqueues; in tun_attach()
833 tfile->socket.sk->sk_shutdown &= ~RCV_SHUTDOWN; in tun_attach()
835 if (tfile->detached) { in tun_attach()
837 WARN_ON(!xdp_rxq_info_is_reg(&tfile->xdp_rxq)); in tun_attach()
839 if (tfile->xdp_rxq.queue_index != tfile->queue_index) in tun_attach()
840 tfile->xdp_rxq.queue_index = tfile->queue_index; in tun_attach()
843 err = xdp_rxq_info_reg(&tfile->xdp_rxq, in tun_attach()
844 tun->dev, tfile->queue_index); in tun_attach()
847 err = xdp_rxq_info_reg_mem_model(&tfile->xdp_rxq, in tun_attach()
850 xdp_rxq_info_unreg(&tfile->xdp_rxq); in tun_attach()
856 if (tfile->detached) { in tun_attach()
857 tun_enable_queue(tfile); in tun_attach()
859 sock_hold(&tfile->sk); in tun_attach()
860 tun_napi_init(tun, tfile, napi, napi_frags); in tun_attach()
864 sock_set_flag(&tfile->sk, SOCK_XDP); in tun_attach()
875 rcu_assign_pointer(tfile->tun, tun); in tun_attach()
876 rcu_assign_pointer(tun->tfiles[tun->numqueues], tfile); in tun_attach()
883 static struct tun_struct *tun_get(struct tun_file *tfile) in tun_get() argument
888 tun = rcu_dereference(tfile->tun); in tun_get()
1066 struct tun_file *tfile; in tun_net_xmit() local
1070 tfile = rcu_dereference(tun->tfiles[txq]); in tun_net_xmit()
1073 if (!tfile) in tun_net_xmit()
1081 BUG_ON(!tfile); in tun_net_xmit()
1089 if (tfile->socket.sk->sk_filter && in tun_net_xmit()
1090 sk_filter(tfile->socket.sk, skb)) in tun_net_xmit()
1109 if (ptr_ring_produce(&tfile->tx_ring, skb)) in tun_net_xmit()
1113 if (tfile->flags & TUN_FASYNC) in tun_net_xmit()
1114 kill_fasync(&tfile->fasync, SIGIO, POLL_IN); in tun_net_xmit()
1115 tfile->socket.sk->sk_data_ready(tfile->socket.sk); in tun_net_xmit()
1195 struct tun_file *tfile; in tun_xdp_set() local
1205 tfile = rtnl_dereference(tun->tfiles[i]); in tun_xdp_set()
1207 sock_set_flag(&tfile->sk, SOCK_XDP); in tun_xdp_set()
1209 sock_reset_flag(&tfile->sk, SOCK_XDP); in tun_xdp_set()
1211 list_for_each_entry(tfile, &tun->disabled, next) { in tun_xdp_set()
1213 sock_set_flag(&tfile->sk, SOCK_XDP); in tun_xdp_set()
1215 sock_reset_flag(&tfile->sk, SOCK_XDP); in tun_xdp_set()
1273 static void __tun_xdp_flush_tfile(struct tun_file *tfile) in __tun_xdp_flush_tfile() argument
1276 if (tfile->flags & TUN_FASYNC) in __tun_xdp_flush_tfile()
1277 kill_fasync(&tfile->fasync, SIGIO, POLL_IN); in __tun_xdp_flush_tfile()
1278 tfile->socket.sk->sk_data_ready(tfile->socket.sk); in __tun_xdp_flush_tfile()
1285 struct tun_file *tfile; in tun_xdp_xmit() local
1303 tfile = rcu_dereference(tun->tfiles[smp_processor_id() % in tun_xdp_xmit()
1305 if (unlikely(!tfile)) in tun_xdp_xmit()
1308 spin_lock(&tfile->tx_ring.producer_lock); in tun_xdp_xmit()
1316 if (__ptr_ring_produce(&tfile->tx_ring, frame)) { in tun_xdp_xmit()
1322 spin_unlock(&tfile->tx_ring.producer_lock); in tun_xdp_xmit()
1325 __tun_xdp_flush_tfile(tfile); in tun_xdp_xmit()
1416 static bool tun_sock_writeable(struct tun_struct *tun, struct tun_file *tfile) in tun_sock_writeable() argument
1418 struct sock *sk = tfile->socket.sk; in tun_sock_writeable()
1428 struct tun_file *tfile = file->private_data; in tun_chr_poll() local
1429 struct tun_struct *tun = tun_get(tfile); in tun_chr_poll()
1436 sk = tfile->socket.sk; in tun_chr_poll()
1442 if (!ptr_ring_empty(&tfile->tx_ring)) in tun_chr_poll()
1450 if (tun_sock_writeable(tun, tfile) || in tun_chr_poll()
1452 tun_sock_writeable(tun, tfile))) in tun_chr_poll()
1462 static struct sk_buff *tun_napi_alloc_frags(struct tun_file *tfile, in tun_napi_alloc_frags() argument
1475 skb = napi_get_frags(&tfile->napi); in tun_napi_alloc_frags()
1511 napi_free_frags(&tfile->napi); in tun_napi_alloc_frags()
1517 static struct sk_buff *tun_alloc_skb(struct tun_file *tfile, in tun_alloc_skb() argument
1521 struct sock *sk = tfile->socket.sk; in tun_alloc_skb()
1542 static void tun_rx_batched(struct tun_struct *tun, struct tun_file *tfile, in tun_rx_batched() argument
1545 struct sk_buff_head *queue = &tfile->sk.sk_write_queue; in tun_rx_batched()
1552 skb_record_rx_queue(skb, tfile->queue_index); in tun_rx_batched()
1573 skb_record_rx_queue(nskb, tfile->queue_index); in tun_rx_batched()
1576 skb_record_rx_queue(skb, tfile->queue_index); in tun_rx_batched()
1582 static bool tun_can_build_skb(struct tun_struct *tun, struct tun_file *tfile, in tun_can_build_skb() argument
1588 if (tfile->socket.sk->sk_sndbuf != INT_MAX) in tun_can_build_skb()
1604 static struct sk_buff *__tun_build_skb(struct tun_file *tfile, in __tun_build_skb() argument
1615 skb_set_owner_w(skb, tfile->socket.sk); in __tun_build_skb()
1656 struct tun_file *tfile, in tun_build_skb() argument
1693 return __tun_build_skb(tfile, alloc_frag, buf, buflen, len, in tun_build_skb()
1710 xdp.rxq = &tfile->xdp_rxq; in tun_build_skb()
1731 return __tun_build_skb(tfile, alloc_frag, buf, buflen, len, pad); in tun_build_skb()
1742 static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, in tun_get_user() argument
1758 bool frags = tun_napi_frags_enabled(tfile); in tun_get_user()
1813 if (!frags && tun_can_build_skb(tun, tfile, len, noblock, zerocopy)) { in tun_get_user()
1818 skb = tun_build_skb(tun, tfile, from, &gso, len, &skb_xdp); in tun_get_user()
1835 mutex_lock(&tfile->napi_mutex); in tun_get_user()
1836 skb = tun_napi_alloc_frags(tfile, copylen, from); in tun_get_user()
1843 skb = tun_alloc_skb(tfile, align, copylen, linear, in tun_get_user()
1851 mutex_unlock(&tfile->napi_mutex); in tun_get_user()
1866 tfile->napi.skb = NULL; in tun_get_user()
1867 mutex_unlock(&tfile->napi_mutex); in tun_get_user()
1878 tfile->napi.skb = NULL; in tun_get_user()
1879 mutex_unlock(&tfile->napi_mutex); in tun_get_user()
1940 tfile->napi.skb = NULL; in tun_get_user()
1941 mutex_unlock(&tfile->napi_mutex); in tun_get_user()
1955 !tfile->detached) in tun_get_user()
1972 napi_free_frags(&tfile->napi); in tun_get_user()
1974 mutex_unlock(&tfile->napi_mutex); in tun_get_user()
1980 napi_gro_frags(&tfile->napi); in tun_get_user()
1982 mutex_unlock(&tfile->napi_mutex); in tun_get_user()
1983 } else if (tfile->napi_enabled) { in tun_get_user()
1984 struct sk_buff_head *queue = &tfile->sk.sk_write_queue; in tun_get_user()
1993 napi_schedule(&tfile->napi); in tun_get_user()
1997 tun_rx_batched(tun, tfile, skb, more); in tun_get_user()
2011 tun_flow_update(tun, rxhash, tfile); in tun_get_user()
2019 struct tun_file *tfile = file->private_data; in tun_chr_write_iter() local
2020 struct tun_struct *tun = tun_get(tfile); in tun_chr_write_iter()
2026 result = tun_get_user(tun, tfile, NULL, from, in tun_chr_write_iter()
2034 struct tun_file *tfile, in tun_put_user_xdp() argument
2069 struct tun_file *tfile, in tun_put_user() argument
2162 static void *tun_ring_recv(struct tun_file *tfile, int noblock, int *err) in tun_ring_recv() argument
2168 ptr = ptr_ring_consume(&tfile->tx_ring); in tun_ring_recv()
2176 add_wait_queue(&tfile->socket.wq.wait, &wait); in tun_ring_recv()
2180 ptr = ptr_ring_consume(&tfile->tx_ring); in tun_ring_recv()
2187 if (tfile->socket.sk->sk_shutdown & RCV_SHUTDOWN) { in tun_ring_recv()
2196 remove_wait_queue(&tfile->socket.wq.wait, &wait); in tun_ring_recv()
2203 static ssize_t tun_do_read(struct tun_struct *tun, struct tun_file *tfile, in tun_do_read() argument
2219 ptr = tun_ring_recv(tfile, noblock, &err); in tun_do_read()
2227 ret = tun_put_user_xdp(tun, tfile, xdpf, to); in tun_do_read()
2232 ret = tun_put_user(tun, tfile, skb, to); in tun_do_read()
2245 struct tun_file *tfile = file->private_data; in tun_chr_read_iter() local
2246 struct tun_struct *tun = tun_get(tfile); in tun_chr_read_iter()
2251 ret = tun_do_read(tun, tfile, to, file->f_flags & O_NONBLOCK, NULL); in tun_chr_read_iter()
2395 struct tun_file *tfile; in tun_sock_write_space() local
2409 tfile = container_of(sk, struct tun_file, sk); in tun_sock_write_space()
2410 kill_fasync(&tfile->fasync, SIGIO, POLL_OUT); in tun_sock_write_space()
2420 struct tun_file *tfile, in tun_xdp_one() argument
2443 xdp->rxq = &tfile->xdp_rxq; in tun_xdp_one()
2501 !tfile->detached) in tun_xdp_one()
2504 skb_record_rx_queue(skb, tfile->queue_index); in tun_xdp_one()
2517 tun_flow_update(tun, rxhash, tfile); in tun_xdp_one()
2526 struct tun_file *tfile = container_of(sock, struct tun_file, socket); in tun_sendmsg() local
2527 struct tun_struct *tun = tun_get(tfile); in tun_sendmsg()
2546 tun_xdp_one(tun, tfile, xdp, &flush, &tpage); in tun_sendmsg()
2561 ret = tun_get_user(tun, tfile, ctl ? ctl->ptr : NULL, &m->msg_iter, in tun_sendmsg()
2572 struct tun_file *tfile = container_of(sock, struct tun_file, socket); in tun_recvmsg() local
2573 struct tun_struct *tun = tun_get(tfile); in tun_recvmsg()
2591 ret = tun_do_read(tun, tfile, &m->msg_iter, flags & MSG_DONTWAIT, ptr); in tun_recvmsg()
2623 struct tun_file *tfile = container_of(sock, struct tun_file, socket); in tun_peek_len() local
2627 tun = tun_get(tfile); in tun_peek_len()
2631 ret = PTR_RING_PEEK_CALL(&tfile->tx_ring, tun_ptr_peek_len); in tun_peek_len()
2700 struct tun_file *tfile = file->private_data; in tun_set_iff() local
2704 if (tfile->detached) in tun_set_iff()
2795 dev->ifindex = tfile->ifindex; in tun_set_iff()
2806 tun->sndbuf = tfile->socket.sk->sk_sndbuf; in tun_set_iff()
2848 rcu_assign_pointer(tfile->tun, tun); in tun_set_iff()
2930 struct tun_file *tfile; in tun_detach_filter() local
2933 tfile = rtnl_dereference(tun->tfiles[i]); in tun_detach_filter()
2934 lock_sock(tfile->socket.sk); in tun_detach_filter()
2935 sk_detach_filter(tfile->socket.sk); in tun_detach_filter()
2936 release_sock(tfile->socket.sk); in tun_detach_filter()
2945 struct tun_file *tfile; in tun_attach_filter() local
2948 tfile = rtnl_dereference(tun->tfiles[i]); in tun_attach_filter()
2949 lock_sock(tfile->socket.sk); in tun_attach_filter()
2950 ret = sk_attach_filter(&tun->fprog, tfile->socket.sk); in tun_attach_filter()
2951 release_sock(tfile->socket.sk); in tun_attach_filter()
2964 struct tun_file *tfile; in tun_set_sndbuf() local
2968 tfile = rtnl_dereference(tun->tfiles[i]); in tun_set_sndbuf()
2969 tfile->socket.sk->sk_sndbuf = tun->sndbuf; in tun_set_sndbuf()
2975 struct tun_file *tfile = file->private_data; in tun_set_queue() local
2982 tun = tfile->detached; in tun_set_queue()
2993 tun = rtnl_dereference(tfile->tun); in tun_set_queue()
2994 if (!tun || !(tun->flags & IFF_MULTI_QUEUE) || tfile->detached) in tun_set_queue()
2997 __tun_detach(tfile, false); in tun_set_queue()
3032 struct tun_file *tfile = file->private_data; in __tun_chr_ioctl() local
3033 struct net *net = sock_net(&tfile->sk); in __tun_chr_ioctl()
3071 tun = tun_get(tfile); in __tun_chr_ioctl()
3098 tfile->ifindex = ifindex; in __tun_chr_ioctl()
3114 if (tfile->detached) in __tun_chr_ioctl()
3116 if (!tfile->socket.sk->sk_filter) in __tun_chr_ioctl()
3224 sndbuf = tfile->socket.sk->sk_sndbuf; in __tun_chr_ioctl()
3393 struct tun_file *tfile = file->private_data; in tun_chr_fasync() local
3396 if ((ret = fasync_helper(fd, file, on, &tfile->fasync)) < 0) in tun_chr_fasync()
3401 tfile->flags |= TUN_FASYNC; in tun_chr_fasync()
3403 tfile->flags &= ~TUN_FASYNC; in tun_chr_fasync()
3412 struct tun_file *tfile; in tun_chr_open() local
3416 tfile = (struct tun_file *)sk_alloc(net, AF_UNSPEC, GFP_KERNEL, in tun_chr_open()
3418 if (!tfile) in tun_chr_open()
3420 if (ptr_ring_init(&tfile->tx_ring, 0, GFP_KERNEL)) { in tun_chr_open()
3421 sk_free(&tfile->sk); in tun_chr_open()
3425 mutex_init(&tfile->napi_mutex); in tun_chr_open()
3426 RCU_INIT_POINTER(tfile->tun, NULL); in tun_chr_open()
3427 tfile->flags = 0; in tun_chr_open()
3428 tfile->ifindex = 0; in tun_chr_open()
3430 init_waitqueue_head(&tfile->socket.wq.wait); in tun_chr_open()
3432 tfile->socket.file = file; in tun_chr_open()
3433 tfile->socket.ops = &tun_socket_ops; in tun_chr_open()
3435 sock_init_data(&tfile->socket, &tfile->sk); in tun_chr_open()
3437 tfile->sk.sk_write_space = tun_sock_write_space; in tun_chr_open()
3438 tfile->sk.sk_sndbuf = INT_MAX; in tun_chr_open()
3440 file->private_data = tfile; in tun_chr_open()
3441 INIT_LIST_HEAD(&tfile->next); in tun_chr_open()
3443 sock_set_flag(&tfile->sk, SOCK_ZEROCOPY); in tun_chr_open()
3450 struct tun_file *tfile = file->private_data; in tun_chr_close() local
3452 tun_detach(tfile, true); in tun_chr_close()
3460 struct tun_file *tfile = file->private_data; in tun_chr_show_fdinfo() local
3467 tun = tun_get(tfile); in tun_chr_show_fdinfo()
3609 struct tun_file *tfile; in tun_queue_resize() local
3619 tfile = rtnl_dereference(tun->tfiles[i]); in tun_queue_resize()
3620 rings[i] = &tfile->tx_ring; in tun_queue_resize()
3622 list_for_each_entry(tfile, &tun->disabled, next) in tun_queue_resize()
3623 rings[i++] = &tfile->tx_ring; in tun_queue_resize()
3650 struct tun_file *tfile; in tun_device_event() local
3652 tfile = rtnl_dereference(tun->tfiles[i]); in tun_device_event()
3653 tfile->socket.sk->sk_write_space(tfile->socket.sk); in tun_device_event()
3714 struct tun_file *tfile; in tun_get_socket() local
3717 tfile = file->private_data; in tun_get_socket()
3718 if (!tfile) in tun_get_socket()
3720 return &tfile->socket; in tun_get_socket()
3726 struct tun_file *tfile; in tun_get_tx_ring() local
3730 tfile = file->private_data; in tun_get_tx_ring()
3731 if (!tfile) in tun_get_tx_ring()
3733 return &tfile->tx_ring; in tun_get_tx_ring()