[ovs-dev] [PATCH 07/19] datapath: Correctly update update IP checksum with actions.

Jesse Gross jesse at nicira.com
Thu Dec 9 06:14:05 UTC 2010


The update_csum() function that we currently use to update
checksums on actions is really intended for L4 checksums.  In
particular, if the packet has a partial checksum and the field
is not in the pseudo header, it doesn't do anything at all.
This doesn't make sense for the IP header because Linux doesn't
use hardware offload for it, so we always need to recompute the
checksum.  Instead, we can use the kernel function csum_replace4(),
which will always do the right thing.

Signed-off-by: Jesse Gross <jesse at nicira.com>
---
 datapath/actions.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/datapath/actions.c b/datapath/actions.c
index ec6a460..d7c571a 100644
--- a/datapath/actions.c
+++ b/datapath/actions.c
@@ -273,7 +273,7 @@ static struct sk_buff *set_nw_addr(struct sk_buff *skb,
 	check = get_l4_checksum(skb, key);
 	if (likely(check))
 		update_csum(check, skb, *nwaddr, a->nw_addr, 1);
-	update_csum(&nh->check, skb, *nwaddr, a->nw_addr, 0);
+	csum_replace4(&nh->check, *nwaddr, a->nw_addr);
 
 	*nwaddr = a->nw_addr;
 
@@ -296,8 +296,8 @@ static struct sk_buff *set_nw_tos(struct sk_buff *skb,
 
 		/* Set the DSCP bits and preserve the ECN bits. */
 		new = a->nw_tos | (nh->tos & INET_ECN_MASK);
-		update_csum(&nh->check, skb, htons((u16)old),
-			    htons((u16)new), 0);
+		csum_replace4(&nh->check, (__force __be32)old,
+					  (__force __be32)new);
 		*f = new;
 	}
 	return skb;
-- 
1.7.1





More information about the dev mailing list