datapath: make skb->csum consistent with rest of networking stack.
authorPravin B Shelar <pshelar@nicira.com>
Wed, 12 Jun 2013 23:59:28 +0000 (16:59 -0700)
committerPravin B Shelar <pshelar@nicira.com>
Wed, 12 Jun 2013 23:59:28 +0000 (16:59 -0700)
As suggested by Jesse in the comment for patch "gre: Restructure
tunneling", following patch keeps skb->csum correct across ovs.

Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
Acked-by: Jesse Gross <jesse@nicira.com>
datapath/actions.c
datapath/flow.c
datapath/vlan.h
datapath/vport-gre.c
datapath/vport-internal_dev.c
datapath/vport-lisp.c
datapath/vport-netdev.c
datapath/vport-vxlan.c
datapath/vport.h

index 0dac658..09d0c3f 100644 (file)
@@ -132,9 +132,17 @@ static int set_eth_addr(struct sk_buff *skb,
        if (unlikely(err))
                return err;
 
+       if (get_ip_summed(skb) == OVS_CSUM_COMPLETE)
+               skb->csum = csum_sub(skb->csum, csum_partial(eth_hdr(skb),
+                                                            ETH_ALEN * 2, 0));
+
        memcpy(eth_hdr(skb)->h_source, eth_key->eth_src, ETH_ALEN);
        memcpy(eth_hdr(skb)->h_dest, eth_key->eth_dst, ETH_ALEN);
 
+       if (get_ip_summed(skb) == OVS_CSUM_COMPLETE)
+               skb->csum = csum_add(skb->csum, csum_partial(eth_hdr(skb),
+                                                            ETH_ALEN * 2, 0));
+
        return 0;
 }
 
index 7f897bd..7604405 100644 (file)
@@ -636,6 +636,8 @@ int ovs_flow_extract(struct sk_buff *skb, u16 in_port, struct sw_flow_key *key,
        memcpy(key->eth.dst, eth->h_dest, ETH_ALEN);
 
        __skb_pull(skb, 2 * ETH_ALEN);
+       /* We are going to push all headers that we pull, so no need to
+        * update skb->csum here. */
 
        if (vlan_tx_tag_present(skb))
                key->eth.tci = htons(vlan_get_tci(skb));
index 5d3573b..46d0db3 100644 (file)
@@ -93,6 +93,11 @@ static inline int vlan_deaccel_tag(struct sk_buff *skb)
        if (unlikely(!skb))
                return -ENOMEM;
 
+       if (get_ip_summed(skb) == OVS_CSUM_COMPLETE)
+               skb->csum = csum_add(skb->csum,
+                                    csum_partial(skb->data + (2 * ETH_ALEN),
+                                                 VLAN_HLEN, 0));
+
        vlan_set_tci(skb, 0);
        return 0;
 }
index add17d9..dae35ac 100644 (file)
@@ -271,8 +271,7 @@ static int gre_rcv(struct sk_buff *skb)
        tnl_flags = gre_flags_to_tunnel_flags(gre_flags, is_gre64);
        tnl_tun_key_init(&tun_key, iph, key, tnl_flags);
 
-       __skb_pull(skb, hdr_len);
-       skb_postpull_rcsum(skb, skb_transport_header(skb), hdr_len + ETH_HLEN);
+       skb_pull_rcsum(skb, hdr_len);
 
        ovs_tnl_rcv(vport, skb, &tun_key);
        return 0;
index 9a159cd..7f0b3c1 100644 (file)
@@ -281,6 +281,7 @@ static int internal_dev_recv(struct vport *vport, struct sk_buff *skb)
        skb->dev = netdev;
        skb->pkt_type = PACKET_HOST;
        skb->protocol = eth_type_trans(skb, netdev);
+       skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN);
        forward_ip_summed(skb, false);
 
        netif_rx(skb);
index 3d0a315..209df59 100644 (file)
@@ -240,6 +240,8 @@ static int lisp_rcv(struct sock *sk, struct sk_buff *skb)
        ethh->h_source[0] = 0x02;
        ethh->h_proto = protocol;
 
+       ovs_skb_postpush_rcsum(skb, skb->data, ETH_HLEN);
+
        ovs_tnl_rcv(vport_from_priv(lisp_port), skb, &tun_key);
        goto out;
 
index 4e7342c..fe7e359 100644 (file)
@@ -256,11 +256,12 @@ static void netdev_port_receive(struct vport *vport, struct sk_buff *skb)
        if (unlikely(!skb))
                return;
 
-       skb_push(skb, ETH_HLEN);
-
        if (unlikely(compute_ip_summed(skb, false)))
                goto error;
 
+       skb_push(skb, ETH_HLEN);
+       ovs_skb_postpush_rcsum(skb, skb->data, ETH_HLEN);
+
        vlan_copy_skb_tci(skb);
 
        ovs_vport_receive(vport, skb, NULL);
index d140c3b..708283e 100644 (file)
@@ -129,8 +129,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)
                     vxh->vx_vni & htonl(0xff)))
                goto error;
 
-       __skb_pull(skb, VXLAN_HLEN);
-       skb_postpull_rcsum(skb, skb_transport_header(skb), VXLAN_HLEN + ETH_HLEN);
+       skb_pull_rcsum(skb, VXLAN_HLEN);
 
        key = cpu_to_be64(ntohl(vxh->vx_vni) >> 8);
 
index 8d262a3..995889c 100644 (file)
@@ -204,4 +204,10 @@ extern const struct vport_ops ovs_gre64_vport_ops;
 extern const struct vport_ops ovs_vxlan_vport_ops;
 extern const struct vport_ops ovs_lisp_vport_ops;
 
+static inline void ovs_skb_postpush_rcsum(struct sk_buff *skb,
+                                     const void *start, unsigned int len)
+{
+       if (skb->ip_summed == CHECKSUM_COMPLETE)
+               skb->csum = csum_add(skb->csum, csum_partial(start, len, 0));
+}
 #endif /* vport.h */