From nobody Sun Apr 26 08:16:38 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4g3KKl46sQz6bDrq for ; Sun, 26 Apr 2026 08:16:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4g3KKl1Vkgz46rD for ; Sun, 26 Apr 2026 08:16:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777191403; 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=D3PI0woB51zxrsov1zfa48ectcYoc589FQS/5SjEhXs=; b=lMQm4M3shWI2hkodjBxYsKpHL4ymwijnjZgBQpxglgqgTzvxqvT+IIMvbLuWkHZT5RWAOq o1PrWwFcEA+avNwNJmT577YjGs3LgO04ZGGLc/mfeUYENCjC8u6IUbsni/t1eBmZe5SXNa UQIEjTOXE2DwILuCaxfP430WJIqrNCy4FeaotRSxSb+2WDpGUGMypLVpW/bDq979H58dp0 0Q4eZ+34lbqDrUEqF01VlfhDMu2766oK04jXlOdcTZYeMpwkEX/aSrvFd4weQAb1lbL5he MWliiPDKG/zS8SRCuHyee+WZtDll6FSfb2woDGLSGD7XV5k0GJaLv+/mWx+paA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1777191403; a=rsa-sha256; cv=none; b=MRyHlMjD21Z7ylfXCJM8+0ie9f6lMlves0YxQqHxGXSr92rJj8O9ohdPOGfL9FD6hQsWVE qCGp+4rOMJU/CRJeraTu/metARypV1ePuVu9EgxY/P3gbEPz0u/WDY7ttfwyM2N4OTy9s1 /3/ogwW65dtTod45JA/lhigJYW1jnOzqQ/4lNMxpKjUmpdaEgatYVpiDoR1cFCcPWnjNH2 0U+v9FfWdZ6HHXTvIEqsFTjTCs1+Ri2X300Ehf1gi0NegpLnyyPrqX+QmcuKjELIp0YiAq Gur9S1pEUvA76gN+HLUDvUNi5DgTKUrss9vA5kJM0RhjGf6yM4YU1qTdaFpmWQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777191403; 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=D3PI0woB51zxrsov1zfa48ectcYoc589FQS/5SjEhXs=; b=jCxRg0xSBfbH4T9xWDqWfU7C44vjl7OjBSuh2jTLZpdpdm7h9vuJrAMu6cIuPXs7ic6GQI 2h91G9jPU0JFQfUbhCZafYN+Ohw0Tsqlj0FyYK3dJDzFS6b+N08DNb0rWs/nlrV9HifcGB C9YplQRWyVOgei6Xg6IawAYjXFrh0faNwgoCa7Yq9HKR369jzhz7bHvKEJK9ysKe2WjmiN jaAWnR1gImMMpEK36OEjKUxf/D7xacf+3mJbMq7jOxhQFiue1jmritfNAnfiNdroZHKy1Y cnqdCUzJHoEb0yXas3FaBpo833YsH7XziMxZb4qLWad5OH+h+jQfL+yR5W9nDA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g3KKl0rHTz1BBx for ; Sun, 26 Apr 2026 08:16:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 31438 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 26 Apr 2026 08:16:38 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Timo =?utf-8?Q?V=C3=B6lker?= From: Michael Tuexen Subject: git: 453958b8d889 - stable/14 - ip: improve deferred computation of checksums List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tuexen X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 453958b8d8890f707215cb6641df6865d662b9d9 Auto-Submitted: auto-generated Date: Sun, 26 Apr 2026 08:16:38 +0000 Message-Id: <69edc9e6.31438.468db525@gitrepo.freebsd.org> The branch stable/14 has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=453958b8d8890f707215cb6641df6865d662b9d9 commit 453958b8d8890f707215cb6641df6865d662b9d9 Author: Timo Völker AuthorDate: 2026-01-20 10:30:19 +0000 Commit: Michael Tuexen CommitDate: 2026-04-26 06:14:20 +0000 ip: improve deferred computation of checksums This patch adds the same functionality for the IPv4 header checksum as was done erlier for the SCTP/TCP/UDP transport checksum. When the IP implementation sends a packet, it does not compute the corresponding checksum but defers that. It will determine whether the network interface selected for the packet has the requested capability and computes the checksum in software, if the selected network interface does not have the requested capability. Do this not only for packets being sent by the local IP stack, but also when forwarding packets. Furthermore, when such packets are delivered to a local IP stack, do not compute or validate the checksum, since such packets have never been on the wire. This allows to support checksum offloading also in the case of local virtual machines or jails. Support for epair interfaces will be added in a separate commit. Reviewed by: pouria, tuexen Differential Revision: https://reviews.freebsd.org/D54455 Event: Wiesbaden Hackathon 2026 (cherry picked from commit 6f15ba8004c3fdc2fb12f0cd6618d1b3a40aab7d) --- share/man/man9/mbuf.9 | 5 +++-- sys/netinet/ip_fastfwd.c | 32 +++++++++++++++++++++++--------- sys/netinet/ip_input.c | 6 ++++++ 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/share/man/man9/mbuf.9 b/share/man/man9/mbuf.9 index e4f30962ccab..265a6dddda98 100644 --- a/share/man/man9/mbuf.9 +++ b/share/man/man9/mbuf.9 @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd August 1, 2025 +.Dd January 20, 2026 .Dt MBUF 9 .Os .\" @@ -1216,13 +1216,14 @@ in is not set, since SCTP does not use a pseudo header checksum. .Pp If IP delivers a packet with the flags +.Dv CSUM_IP , .Dv CSUM_SCTP , .Dv CSUM_TCP , or .Dv CSUM_UDP set in .Va csum_flags -to a local SCTP, TCP, or UDP stack, the packet will be processed without +to a local IP, SCTP, TCP, or UDP stack, the packet will be processed without computing or validating the checksum, since the packet has not been on the wire. This can happen if the packet was handled by a virtual interface such as diff --git a/sys/netinet/ip_fastfwd.c b/sys/netinet/ip_fastfwd.c index eb1dd5c3e17f..e99ac47fe988 100644 --- a/sys/netinet/ip_fastfwd.c +++ b/sys/netinet/ip_fastfwd.c @@ -362,15 +362,20 @@ passin: } /* - * Decrement the TTL and incrementally change the IP header checksum. - * Don't bother doing this with hw checksum offloading, it's faster - * doing it right here. + * Decrement the TTL. + * If the IP header checksum field contains a valid value, incrementally + * change this value. Don't use hw checksum offloading, which would + * recompute the checksum. It's faster to just change it here + * according to the decremented TTL. + * If the checksum still needs to be computed, don't touch it. */ ip->ip_ttl -= IPTTLDEC; - if (ip->ip_sum >= (u_int16_t) ~htons(IPTTLDEC << 8)) - ip->ip_sum -= ~htons(IPTTLDEC << 8); - else - ip->ip_sum += htons(IPTTLDEC << 8); + if (__predict_true((m->m_pkthdr.csum_flags & CSUM_IP) == 0)) { + if (ip->ip_sum >= (u_int16_t) ~htons(IPTTLDEC << 8)) + ip->ip_sum -= ~htons(IPTTLDEC << 8); + else + ip->ip_sum += htons(IPTTLDEC << 8); + } #ifdef IPSTEALTH } #endif @@ -468,9 +473,18 @@ passout: gw = (const struct sockaddr *)dst; /* - * If TCP/UDP header still needs a valid checksum and interface will not - * calculate it for us, do it here. + * If the IP/SCTP/TCP/UDP header still needs a valid checksum and the + * interface will not calculate it for us, do it here. + * Note that if we defer checksum calculation, we might send an ICMP + * message later that reflects this packet, which still has an + * invalid checksum. */ + if (__predict_false(m->m_pkthdr.csum_flags & CSUM_IP & + ~nh->nh_ifp->if_hwassist)) { + ip->ip_sum = 0; + ip->ip_sum = in_cksum(m, (ip->ip_hl << 2)); + m->m_pkthdr.csum_flags &= ~CSUM_IP; + } if (__predict_false(m->m_pkthdr.csum_flags & CSUM_DELAY_DATA & ~nh->nh_ifp->if_hwassist)) { in_delayed_cksum(m); diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index 7c01c4959841..ba7a9802c0db 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -526,6 +526,12 @@ ip_input(struct mbuf *m) if (m->m_pkthdr.csum_flags & CSUM_IP_CHECKED) { sum = !(m->m_pkthdr.csum_flags & CSUM_IP_VALID); + } else if (m->m_pkthdr.csum_flags & CSUM_IP) { + /* + * Packet from local host that offloaded checksum computation. + * Checksum not required since the packet wasn't on the wire. + */ + sum = 0; } else { if (hlen == sizeof(struct ip)) { sum = in_cksum_hdr(ip);