tap.c (415d2b3392d7a80903e0f97f051201aa02bf20e9) tap.c (fe8dd45bb7556246c6b76277b1ba4296c91c2505)
1#include <linux/etherdevice.h>
2#include <linux/if_tap.h>
3#include <linux/if_vlan.h>
4#include <linux/interrupt.h>
5#include <linux/nsproxy.h>
6#include <linux/compat.h>
7#include <linux/if_tun.h>
8#include <linux/module.h>

--- 605 unchanged lines hidden (view full) ---

614
615 return skb;
616}
617
618/* Neighbour code has some assumptions on HH_DATA_MOD alignment */
619#define TAP_RESERVE HH_DATA_OFF(ETH_HLEN)
620
621/* Get packet from user space buffer */
1#include <linux/etherdevice.h>
2#include <linux/if_tap.h>
3#include <linux/if_vlan.h>
4#include <linux/interrupt.h>
5#include <linux/nsproxy.h>
6#include <linux/compat.h>
7#include <linux/if_tun.h>
8#include <linux/module.h>

--- 605 unchanged lines hidden (view full) ---

614
615 return skb;
616}
617
618/* Neighbour code has some assumptions on HH_DATA_MOD alignment */
619#define TAP_RESERVE HH_DATA_OFF(ETH_HLEN)
620
621/* Get packet from user space buffer */
622static ssize_t tap_get_user(struct tap_queue *q, struct msghdr *m,
622static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,
623 struct iov_iter *from, int noblock)
624{
625 int good_linear = SKB_MAX_HEAD(TAP_RESERVE);
626 struct sk_buff *skb;
627 struct tap_dev *tap;
628 unsigned long total_len = iov_iter_count(from);
629 unsigned long len = total_len;
630 int err;

--- 27 unchanged lines hidden (view full) ---

658 if (tap16_to_cpu(q, vnet_hdr.hdr_len) > len)
659 goto err;
660 }
661
662 err = -EINVAL;
663 if (unlikely(len < ETH_HLEN))
664 goto err;
665
623 struct iov_iter *from, int noblock)
624{
625 int good_linear = SKB_MAX_HEAD(TAP_RESERVE);
626 struct sk_buff *skb;
627 struct tap_dev *tap;
628 unsigned long total_len = iov_iter_count(from);
629 unsigned long len = total_len;
630 int err;

--- 27 unchanged lines hidden (view full) ---

658 if (tap16_to_cpu(q, vnet_hdr.hdr_len) > len)
659 goto err;
660 }
661
662 err = -EINVAL;
663 if (unlikely(len < ETH_HLEN))
664 goto err;
665
666 if (m && m->msg_control && sock_flag(&q->sk, SOCK_ZEROCOPY)) {
666 if (msg_control && sock_flag(&q->sk, SOCK_ZEROCOPY)) {
667 struct iov_iter i;
668
669 copylen = vnet_hdr.hdr_len ?
670 tap16_to_cpu(q, vnet_hdr.hdr_len) : GOODCOPY_LEN;
671 if (copylen > good_linear)
672 copylen = good_linear;
673 else if (copylen < ETH_HLEN)
674 copylen = ETH_HLEN;

--- 44 unchanged lines hidden (view full) ---

719 skb->protocol == htons(ETH_P_8021AD)) &&
720 __vlan_get_protocol(skb, skb->protocol, &depth) != 0)
721 skb_set_network_header(skb, depth);
722
723 rcu_read_lock();
724 tap = rcu_dereference(q->tap);
725 /* copy skb_ubuf_info for callback when skb has no error */
726 if (zerocopy) {
667 struct iov_iter i;
668
669 copylen = vnet_hdr.hdr_len ?
670 tap16_to_cpu(q, vnet_hdr.hdr_len) : GOODCOPY_LEN;
671 if (copylen > good_linear)
672 copylen = good_linear;
673 else if (copylen < ETH_HLEN)
674 copylen = ETH_HLEN;

--- 44 unchanged lines hidden (view full) ---

719 skb->protocol == htons(ETH_P_8021AD)) &&
720 __vlan_get_protocol(skb, skb->protocol, &depth) != 0)
721 skb_set_network_header(skb, depth);
722
723 rcu_read_lock();
724 tap = rcu_dereference(q->tap);
725 /* copy skb_ubuf_info for callback when skb has no error */
726 if (zerocopy) {
727 skb_shinfo(skb)->destructor_arg = m->msg_control;
727 skb_shinfo(skb)->destructor_arg = msg_control;
728 skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
729 skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG;
728 skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
729 skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG;
730 } else if (m && m->msg_control) {
731 struct ubuf_info *uarg = m->msg_control;
730 } else if (msg_control) {
731 struct ubuf_info *uarg = msg_control;
732 uarg->callback(uarg, false);
733 }
734
735 if (tap) {
736 skb->dev = tap->dev;
737 dev_queue_xmit(skb);
738 } else {
739 kfree_skb(skb);

--- 405 unchanged lines hidden (view full) ---

1145 .compat_ioctl = tap_compat_ioctl,
1146#endif
1147};
1148
1149static int tap_sendmsg(struct socket *sock, struct msghdr *m,
1150 size_t total_len)
1151{
1152 struct tap_queue *q = container_of(sock, struct tap_queue, sock);
732 uarg->callback(uarg, false);
733 }
734
735 if (tap) {
736 skb->dev = tap->dev;
737 dev_queue_xmit(skb);
738 } else {
739 kfree_skb(skb);

--- 405 unchanged lines hidden (view full) ---

1145 .compat_ioctl = tap_compat_ioctl,
1146#endif
1147};
1148
1149static int tap_sendmsg(struct socket *sock, struct msghdr *m,
1150 size_t total_len)
1151{
1152 struct tap_queue *q = container_of(sock, struct tap_queue, sock);
1153 return tap_get_user(q, m, &m->msg_iter, m->msg_flags & MSG_DONTWAIT);
1153 struct tun_msg_ctl *ctl = m->msg_control;
1154
1155 if (ctl && ctl->type != TUN_MSG_UBUF)
1156 return -EINVAL;
1157
1158 return tap_get_user(q, ctl ? ctl->ptr : NULL, &m->msg_iter,
1159 m->msg_flags & MSG_DONTWAIT);
1154}
1155
1156static int tap_recvmsg(struct socket *sock, struct msghdr *m,
1157 size_t total_len, int flags)
1158{
1159 struct tap_queue *q = container_of(sock, struct tap_queue, sock);
1160 struct sk_buff *skb = m->msg_control;
1161 int ret;

--- 148 unchanged lines hidden ---
1160}
1161
1162static int tap_recvmsg(struct socket *sock, struct msghdr *m,
1163 size_t total_len, int flags)
1164{
1165 struct tap_queue *q = container_of(sock, struct tap_queue, sock);
1166 struct sk_buff *skb = m->msg_control;
1167 int ret;

--- 148 unchanged lines hidden ---