Skip to contentSkip to conversation

{pktgen, xfrm} re-caculate IPv4 checksum after transformation

PATCH In review Fan Du 2 participants 2 messages Nov 29, 2013 – Nov 30, 2013

Subsystems (2)
lore
Share & tools
lore

Fan Du

author
#0 lore raw

PATCH 1/1 {pktgen, xfrm} re-caculate IPv4 checksum after transformation

I accidently observed incorrect IPv4 checksum by wireshark when armming pktgen with IPsec by ESP transport mode with following pktgen configuration:

pgset "flag IPSEC"
pgset "flows 1"

It seems that after transformation, IPv4 checksum remains the origianl checksum as before, so encrypted packet will never reach receiver's upper layer because of wrong IPv4 checksum value.

Fix this by re-caculate checksum value.

---
 net/core/pktgen.c |    2 ++
 1 file changed, 2 insertions(+)
net/core/pktgen.c +2 -0
index 261357a..8d13b41 100644
@@ -2786,6 +2786,8 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
 #ifdef CONFIG_XFRM
 	if (!process_ipsec(pkt_dev, skb, protocol))
 		return NULL;
+	iph = ip_hdr(skb);
+	ip_send_check(iph);
 #endif
 
 	return skb;
Signature · 1 line
1.7.9.5
maintainer
#1 lore raw

From: Fan Du <[email protected]>
Date: Fri, 29 Nov 2013 10:59:09 +0800

net/core/pktgen.c static struct sk_buff *fill_packet_ipv4(struct net_device *odev, · line 2791

Quoted 7 lines
net/core/pktgen.c +2 -0
@@ -2786,6 +2786,8 @@ static struct sk_buff *fill_packet_ipv4(struct net_device *odev,
 #ifdef CONFIG_XFRM
 	if (!process_ipsec(pkt_dev, skb, protocol))
 		return NULL;
+	iph = ip_hdr(skb);
+	ip_send_check(iph);
 #endif

This is rediculous. You're computing the checksum _twice_ unconditionally, even if process_ipsec() does _nothing_.

Make process_ipsec() fix the checksum, but only if it actually does something which makes the recomputation even necessary.

Thanks.