Skip to content

Commit 3868204

Browse files
fan.dudavem330
authored andcommitted
{pktgen, xfrm} Update IPv4 header total len and checksum after tranformation
commit a553e4a ("[PKTGEN]: IPSEC support") tried to support IPsec ESP transport transformation for pktgen, but acctually this doesn't work at all for two reasons(The orignal transformed packet has bad IPv4 checksum value, as well as wrong auth value, reported by wireshark) - After transpormation, IPv4 header total length needs update, because encrypted payload's length is NOT same as that of plain text. - After transformation, IPv4 checksum needs re-caculate because of payload has been changed. With this patch, armmed pktgen with below cofiguration, Wireshark is able to decrypted ESP packet generated by pktgen without any IPv4 checksum error or auth value error. pgset "flag IPSEC" pgset "flows 1" Signed-off-by: Fan Du <fan.du@windriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f121159 commit 3868204

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎net/core/pktgen.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,6 +2527,8 @@ static int process_ipsec(struct pktgen_dev *pkt_dev,
25272527
if (x) {
25282528
int ret;
25292529
__u8 *eth;
2530+
struct iphdr *iph;
2531+
25302532
nhead = x->props.header_len - skb_headroom(skb);
25312533
if (nhead > 0) {
25322534
ret = pskb_expand_head(skb, nhead, 0, GFP_ATOMIC);
@@ -2548,6 +2550,11 @@ static int process_ipsec(struct pktgen_dev *pkt_dev,
25482550
eth = (__u8 *) skb_push(skb, ETH_HLEN);
25492551
memcpy(eth, pkt_dev->hh, 12);
25502552
*(u16 *) &eth[12] = protocol;
2553+
2554+
/* Update IPv4 header len as well as checksum value */
2555+
iph = ip_hdr(skb);
2556+
iph->tot_len = htons(skb->len - ETH_HLEN);
2557+
ip_send_check(iph);
25512558
}
25522559
}
25532560
return 1;

0 commit comments

Comments
 (0)