diff options
Diffstat (limited to 'drivers/net/macvtap.c')
-rw-r--r-- | drivers/net/macvtap.c | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c index 0427c6561c84..cb8fd5069dbe 100644 --- a/drivers/net/macvtap.c +++ b/drivers/net/macvtap.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #include <linux/etherdevice.h> | 1 | #include <linux/etherdevice.h> |
2 | #include <linux/if_macvlan.h> | 2 | #include <linux/if_macvlan.h> |
3 | #include <linux/if_vlan.h> | ||
3 | #include <linux/interrupt.h> | 4 | #include <linux/interrupt.h> |
4 | #include <linux/nsproxy.h> | 5 | #include <linux/nsproxy.h> |
5 | #include <linux/compat.h> | 6 | #include <linux/compat.h> |
@@ -759,6 +760,8 @@ static ssize_t macvtap_put_user(struct macvtap_queue *q, | |||
759 | struct macvlan_dev *vlan; | 760 | struct macvlan_dev *vlan; |
760 | int ret; | 761 | int ret; |
761 | int vnet_hdr_len = 0; | 762 | int vnet_hdr_len = 0; |
763 | int vlan_offset = 0; | ||
764 | int copied; | ||
762 | 765 | ||
763 | if (q->flags & IFF_VNET_HDR) { | 766 | if (q->flags & IFF_VNET_HDR) { |
764 | struct virtio_net_hdr vnet_hdr; | 767 | struct virtio_net_hdr vnet_hdr; |
@@ -773,18 +776,48 @@ static ssize_t macvtap_put_user(struct macvtap_queue *q, | |||
773 | if (memcpy_toiovecend(iv, (void *)&vnet_hdr, 0, sizeof(vnet_hdr))) | 776 | if (memcpy_toiovecend(iv, (void *)&vnet_hdr, 0, sizeof(vnet_hdr))) |
774 | return -EFAULT; | 777 | return -EFAULT; |
775 | } | 778 | } |
779 | copied = vnet_hdr_len; | ||
780 | |||
781 | if (!vlan_tx_tag_present(skb)) | ||
782 | len = min_t(int, skb->len, len); | ||
783 | else { | ||
784 | int copy; | ||
785 | struct { | ||
786 | __be16 h_vlan_proto; | ||
787 | __be16 h_vlan_TCI; | ||
788 | } veth; | ||
789 | veth.h_vlan_proto = htons(ETH_P_8021Q); | ||
790 | veth.h_vlan_TCI = htons(vlan_tx_tag_get(skb)); | ||
791 | |||
792 | vlan_offset = offsetof(struct vlan_ethhdr, h_vlan_proto); | ||
793 | len = min_t(int, skb->len + VLAN_HLEN, len); | ||
794 | |||
795 | copy = min_t(int, vlan_offset, len); | ||
796 | ret = skb_copy_datagram_const_iovec(skb, 0, iv, copied, copy); | ||
797 | len -= copy; | ||
798 | copied += copy; | ||
799 | if (ret || !len) | ||
800 | goto done; | ||
801 | |||
802 | copy = min_t(int, sizeof(veth), len); | ||
803 | ret = memcpy_toiovecend(iv, (void *)&veth, copied, copy); | ||
804 | len -= copy; | ||
805 | copied += copy; | ||
806 | if (ret || !len) | ||
807 | goto done; | ||
808 | } | ||
776 | 809 | ||
777 | len = min_t(int, skb->len, len); | 810 | ret = skb_copy_datagram_const_iovec(skb, vlan_offset, iv, copied, len); |
778 | 811 | copied += len; | |
779 | ret = skb_copy_datagram_const_iovec(skb, 0, iv, vnet_hdr_len, len); | ||
780 | 812 | ||
813 | done: | ||
781 | rcu_read_lock_bh(); | 814 | rcu_read_lock_bh(); |
782 | vlan = rcu_dereference_bh(q->vlan); | 815 | vlan = rcu_dereference_bh(q->vlan); |
783 | if (vlan) | 816 | if (vlan) |
784 | macvlan_count_rx(vlan, len, ret == 0, 0); | 817 | macvlan_count_rx(vlan, copied - vnet_hdr_len, ret == 0, 0); |
785 | rcu_read_unlock_bh(); | 818 | rcu_read_unlock_bh(); |
786 | 819 | ||
787 | return ret ? ret : (len + vnet_hdr_len); | 820 | return ret ? ret : copied; |
788 | } | 821 | } |
789 | 822 | ||
790 | static ssize_t macvtap_do_read(struct macvtap_queue *q, struct kiocb *iocb, | 823 | static ssize_t macvtap_do_read(struct macvtap_queue *q, struct kiocb *iocb, |