git: 7f4c2bf8ea6c - stable/14 - netinet: provide "at offset" variant of the in_delayed_cksum() API

From: Maxim Sobolev <sobomax_at_FreeBSD.org>
Date: Wed, 05 Nov 2025 07:15:45 UTC
The branch stable/14 has been updated by sobomax:

URL: https://cgit.FreeBSD.org/src/commit/?id=7f4c2bf8ea6cdbdcca1eccce9508206e2cf05cce

commit 7f4c2bf8ea6cdbdcca1eccce9508206e2cf05cce
Author:     Maxim Sobolev <sobomax@FreeBSD.org>
AuthorDate: 2025-08-25 22:12:56 +0000
Commit:     Maxim Sobolev <sobomax@FreeBSD.org>
CommitDate: 2025-11-05 07:14:04 +0000

    netinet: provide "at offset" variant of the in_delayed_cksum() API
    
    The need for such a variant comes from the fact that we need to
    re-calculate checksum aftet ng_nat(4) transformations while getting
    mbufs from the layer 2 (ethernet) directly.
    
    Reviewed by:    markj, tuexen
    Approved by:    tuexen
    Sponsored by:   Sippy Software, Inc.
    Differential Revision:  https://reviews.freebsd.org/D49677
    
    (cherry picked from commit 5feb38e37847c10af86f5c75dc768518973c6aaa)
---
 sys/netinet/ip_output.c | 13 ++++++++++---
 sys/netinet/ip_var.h    |  1 +
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c
index 66051c9c711c..e3ef8e2c7dd9 100644
--- a/sys/netinet/ip_output.c
+++ b/sys/netinet/ip_output.c
@@ -1045,14 +1045,14 @@ done:
 }
 
 void
-in_delayed_cksum(struct mbuf *m)
+in_delayed_cksum_o(struct mbuf *m, uint16_t iph_offset)
 {
 	struct ip *ip;
 	struct udphdr *uh;
 	uint16_t cklen, csum, offset;
 
-	ip = mtod(m, struct ip *);
-	offset = ip->ip_hl << 2 ;
+	ip = (struct ip *)mtodo(m, iph_offset);
+	offset = iph_offset + (ip->ip_hl << 2);
 
 	if (m->m_pkthdr.csum_flags & CSUM_UDP) {
 		/* if udp header is not in the first mbuf copy udplen */
@@ -1079,6 +1079,13 @@ in_delayed_cksum(struct mbuf *m)
 		*(u_short *)mtodo(m, offset) = csum;
 }
 
+void
+in_delayed_cksum(struct mbuf *m)
+{
+
+	in_delayed_cksum_o(m, 0);
+}
+
 /*
  * IP socket option processing.
  */
diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h
index 3220679d749f..a1402f4fa268 100644
--- a/sys/netinet/ip_var.h
+++ b/sys/netinet/ip_var.h
@@ -259,6 +259,7 @@ VNET_DECLARE(struct pfil_head *, inet_local_pfil_head);
 #define	PFIL_INET_LOCAL_NAME	"inet-local"
 
 void	in_delayed_cksum(struct mbuf *m);
+void	in_delayed_cksum_o(struct mbuf *m, uint16_t o);
 
 /* Hooks for ipfw, dummynet, divert etc. Most are declared in raw_ip.c */
 /*