macvtap: set transport header before passing skb to lower device
authorJason Wang <jasowang@redhat.com>
Mon, 25 Mar 2013 20:19:55 +0000 (20:19 +0000)
committerDavid S. Miller <davem@davemloft.net>
Tue, 26 Mar 2013 16:44:43 +0000 (12:44 -0400)
Set the transport header for 1) some drivers (e.g ixgbe) needs l4 header 2)
precise packet length estimation (introduced in 1def9238) needs l4 header to
compute header length.

For the packets with partial checksum, the patch just set the transport header
to csum_start. Otherwise tries to use skb_flow_dissect() to get l4 offset, if it
fails, just pretend no l4 header.

Cc: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/macvtap.c

index a449439bd65366e5790037c21a4d3ce3f0e1ce97..acf6450ceff5dda54a5e11360f44ee97432dfb9e 100644 (file)
@@ -21,6 +21,7 @@
 #include <net/rtnetlink.h>
 #include <net/sock.h>
 #include <linux/virtio_net.h>
+#include <net/flow_keys.h>
 
 /*
  * A macvtap queue is the central object of this driver, it connects
@@ -645,6 +646,7 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
        int vnet_hdr_len = 0;
        int copylen = 0;
        bool zerocopy = false;
+       struct flow_keys keys;
 
        if (q->flags & IFF_VNET_HDR) {
                vnet_hdr_len = q->vnet_hdr_sz;
@@ -725,6 +727,13 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
                        goto err_kfree;
        }
 
+       if (skb->ip_summed == CHECKSUM_PARTIAL)
+               skb_set_transport_header(skb, skb_checksum_start_offset(skb));
+       else if (skb_flow_dissect(skb, &keys))
+               skb_set_transport_header(skb, keys.thoff);
+       else
+               skb_set_transport_header(skb, ETH_HLEN);
+
        rcu_read_lock_bh();
        vlan = rcu_dereference_bh(q->vlan);
        /* copy skb_ubuf_info for callback when skb has no error */