tun: Fix csum_start with VLAN acceleration

When VLAN acceleration is in use on the xmit path, we end up
setting csum_start to the wrong place.  The result is that the
whoever ends up doing the checksum setting will corrupt the packet
instead of writing the checksum to the expected location, usually
this means writing the checksum with an offset of -4.

This patch fixes this by adjusting csum_start when VLAN acceleration
is detected.

Fixes: 6680ec68ef ("tuntap: hardware vlan tx support")
Cc: stable@vger.kernel.org
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Herbert Xu 2014-11-03 04:30:13 +08:00 committed by David S. Miller
parent 7071cf7fc4
commit a8f9bfdf98
1 changed files with 9 additions and 7 deletions

View File

@ -1235,6 +1235,10 @@ static ssize_t tun_put_user(struct tun_struct *tun,
struct tun_pi pi = { 0, skb->protocol }; struct tun_pi pi = { 0, skb->protocol };
ssize_t total = 0; ssize_t total = 0;
int vlan_offset = 0, copied; int vlan_offset = 0, copied;
int vlan_hlen = 0;
if (vlan_tx_tag_present(skb))
vlan_hlen = VLAN_HLEN;
if (!(tun->flags & TUN_NO_PI)) { if (!(tun->flags & TUN_NO_PI)) {
if ((len -= sizeof(pi)) < 0) if ((len -= sizeof(pi)) < 0)
@ -1284,7 +1288,8 @@ static ssize_t tun_put_user(struct tun_struct *tun,
if (skb->ip_summed == CHECKSUM_PARTIAL) { if (skb->ip_summed == CHECKSUM_PARTIAL) {
gso.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM; gso.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
gso.csum_start = skb_checksum_start_offset(skb); gso.csum_start = skb_checksum_start_offset(skb) +
vlan_hlen;
gso.csum_offset = skb->csum_offset; gso.csum_offset = skb->csum_offset;
} else if (skb->ip_summed == CHECKSUM_UNNECESSARY) { } else if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
gso.flags = VIRTIO_NET_HDR_F_DATA_VALID; gso.flags = VIRTIO_NET_HDR_F_DATA_VALID;
@ -1297,10 +1302,9 @@ static ssize_t tun_put_user(struct tun_struct *tun,
} }
copied = total; copied = total;
total += skb->len; len = min_t(int, skb->len + vlan_hlen, len);
if (!vlan_tx_tag_present(skb)) { total += skb->len + vlan_hlen;
len = min_t(int, skb->len, len); if (vlan_hlen) {
} else {
int copy, ret; int copy, ret;
struct { struct {
__be16 h_vlan_proto; __be16 h_vlan_proto;
@ -1311,8 +1315,6 @@ static ssize_t tun_put_user(struct tun_struct *tun,
veth.h_vlan_TCI = htons(vlan_tx_tag_get(skb)); veth.h_vlan_TCI = htons(vlan_tx_tag_get(skb));
vlan_offset = offsetof(struct vlan_ethhdr, h_vlan_proto); vlan_offset = offsetof(struct vlan_ethhdr, h_vlan_proto);
len = min_t(int, skb->len + VLAN_HLEN, len);
total += VLAN_HLEN;
copy = min_t(int, vlan_offset, len); copy = min_t(int, vlan_offset, len);
ret = skb_copy_datagram_const_iovec(skb, 0, iv, copied, copy); ret = skb_copy_datagram_const_iovec(skb, 0, iv, copied, copy);