From patchwork Thu Aug 15 20:03:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Pattrick X-Patchwork-Id: 1972898 X-Patchwork-Delegate: i.maximets@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JHDnaOrE; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WlGKH66YTz1yYl for ; Fri, 16 Aug 2024 06:03:47 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id A8B8240FFF; Thu, 15 Aug 2024 20:03:45 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id I5XHlUMyYTWv; Thu, 15 Aug 2024 20:03:44 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 17D22400B5 Authentication-Results: smtp2.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JHDnaOrE Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id 17D22400B5; Thu, 15 Aug 2024 20:03:44 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id CC445C000E; Thu, 15 Aug 2024 20:03:43 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 8AE08C000D for ; Thu, 15 Aug 2024 20:03:42 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 7A7908407E for ; Thu, 15 Aug 2024 20:03:42 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 2FkDt_YBpqiJ for ; Thu, 15 Aug 2024 20:03:41 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=mkp@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp1.osuosl.org 8525280D30 Authentication-Results: smtp1.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 8525280D30 Authentication-Results: smtp1.osuosl.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JHDnaOrE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id 8525280D30 for ; Thu, 15 Aug 2024 20:03:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723752219; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wMp3XyiaI2AmaFxgtsB4ZIlbCIx4eAuhewl5iUGy+JA=; b=JHDnaOrEOeQ+P8KNQhTIER5DpAnlehOa5dAhRC4aZv/a+FUQy6vYUCUXraorXxok0Wy4db lVaftLMJwjAUaNElqtPSV903zd5q3ssuS6zy1tZe7jtyfwoDX7Vf6qBc0i7O0bDOunm8uv 6xcPOtaJTp5CYfOQjmjxsaLWr84sd64= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-433-8ycKLoV0M9mvktQ_wkU1qA-1; Thu, 15 Aug 2024 16:03:38 -0400 X-MC-Unique: 8ycKLoV0M9mvktQ_wkU1qA-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D8E1E19560A2; Thu, 15 Aug 2024 20:03:36 +0000 (UTC) Received: from mpattric.remote.csb (unknown [10.22.33.24]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5B9FF19560AE; Thu, 15 Aug 2024 20:03:35 +0000 (UTC) From: Mike Pattrick To: dev@openvswitch.org Date: Thu, 15 Aug 2024 16:03:31 -0400 Message-ID: <20240815200331.1460372-1-mkp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH branch-3.2 v4] dp-packet: Correct IPv4 checksum calculation. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jun Wang Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" During the transition towards checksum offloading, the function to handle software fallback of IPv4 checksums didn't account for the options field. Fixes: 5d11c47d3ebe ("userspace: Enable IP checksum offloading by default.") Reported-by: Jun Wang Signed-off-by: Mike Pattrick --- NB: In 3.2 the early checksum offloading patches caused packets from the netdev-dummy/receive appctl command to resolve checksums prior to odp-execute. This fixed in 3.3, but that can't easily be backported without also backporting unrelated code. To enable this patch to be backported, I gave one of the packets a correct checksum and changed the comment so it was correct but also the same number of lines as in the previous patch. --- lib/dp-packet.h | 11 +++++++++-- tests/dpif-netdev.at | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) -- 2.43.5 diff --git a/lib/dp-packet.h b/lib/dp-packet.h index 70ddf8aa4..25a0d31a1 100644 --- a/lib/dp-packet.h +++ b/lib/dp-packet.h @@ -1142,10 +1142,17 @@ static inline void dp_packet_ip_set_header_csum(struct dp_packet *p) { struct ip_header *ip = dp_packet_l3(p); + size_t l3_size = dp_packet_l3_size(p); + size_t ip_len; ovs_assert(ip); - ip->ip_csum = 0; - ip->ip_csum = csum(ip, sizeof *ip); + + ip_len = IP_IHL(ip->ip_ihl_ver) * 4; + + if (OVS_LIKELY(ip_len >= IP_HEADER_LEN && ip_len < l3_size)) { + ip->ip_csum = 0; + ip->ip_csum = csum(ip, ip_len); + } } /* Returns 'true' if the packet 'p' has good integrity and the diff --git a/tests/dpif-netdev.at b/tests/dpif-netdev.at index 061e13af8..93226521a 100644 --- a/tests/dpif-netdev.at +++ b/tests/dpif-netdev.at @@ -807,6 +807,41 @@ AT_CHECK([ovs-appctl netdev-dummy/receive p1 ${bad_frame}]) AT_CHECK([ovs-pcap p2.pcap > p2.pcap.txt 2>&1]) AT_CHECK_UNQUOTED([tail -n 1 p2.pcap.txt], [0], [${good_expected} ]) + +dnl Test with IP optional fields in a valid packet. Note that this packet +dnl contains a correct checksum, but the following packet doesn't. This is +dnl because the dummy interface resets checksum offload on packet recipt. +m4_define([OPT_PKT], m4_join([], +dnl eth(dst=aa:aa:aa:aa:aa:aa,src=bb:bb:bb:bb:bb:bb,type=0x0800) +[aaaaaaaaaaaabbbbbbbbbbbb0800], +dnl ipv4(dst=10.0.0.2,src=10.0.0.1,proto=1,len=60,tot_len=68,csum=0x94d6) +[4f000044abab0000400194d60a0000010a000002], +dnl IPv4 Opt: type 7 (Record Route) len 39 + type 0 (EOL). +[07270c010203040a000003000000000000000000], +[0000000000000000000000000000000000000000], +dnl icmp(type=8,code=0), csum 0x3e2f incorrect, should be 0x412f. +[08003e2fb6d00000])) + +dnl IP header indicates optional fields but doesn't contain any. +m4_define([MICROGRAM], m4_join([], +dnl eth(dst=aa:aa:aa:aa:aa:aa,src=bb:bb:bb:bb:bb:bb,type=0x0800) +[aaaaaaaaaaaabbbbbbbbbbbb0800], +dnl ipv4(dst=10.0.0.2,src=10.0.0.1,proto=1,len=60,tot_len=68,csum=0xeeee) +[4f000044abab00004001eeee0a0000010a000002])) + +AT_CHECK([ovs-vsctl set Interface p1 options:ol_ip_csum=true]) +AT_CHECK([ovs-vsctl set Interface p1 options:ol_ip_csum_set_good=true]) +AT_CHECK([ovs-appctl netdev-dummy/receive p1 OPT_PKT]) +AT_CHECK([ovs-appctl netdev-dummy/receive p1 MICROGRAM]) +AT_CHECK([ovs-pcap p2.pcap > p2.pcap.txt 2>&1]) + +dnl Build the expected modified packets. The first packet has a valid IPv4 +dnl checksum and modified destination IP address. The second packet isn't +dnl expected to change. +AT_CHECK([echo "OPT_PKT" | sed -e "s/0a000002/c0a80101/" -e "s/94d6/dd2e/" > expout]) +AT_CHECK([echo "MICROGRAM" >> expout]) +AT_CHECK([tail -n 2 p2.pcap.txt], [0], [expout]) + OVS_VSWITCHD_STOP AT_CLEANUP