The branch main has been updated by sobomax:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=5feb38e37847c10af86f5c75dc768518973c6aaa

commit 5feb38e37847c10af86f5c75dc768518973c6aaa
Author:     Maxim Sobolev <sobo...@freebsd.org>
AuthorDate: 2025-08-25 22:12:56 +0000
Commit:     Maxim Sobolev <sobo...@freebsd.org>
CommitDate: 2025-08-26 04:34:45 +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
    MFC After:      2 weeks
---
 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 ec6ba8d92015..ef08b9cfd3d6 100644
--- a/sys/netinet/ip_output.c
+++ b/sys/netinet/ip_output.c
@@ -1044,14 +1044,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 */
@@ -1078,6 +1078,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 f782ebc53eb0..c113484079a3 100644
--- a/sys/netinet/ip_var.h
+++ b/sys/netinet/ip_var.h
@@ -271,6 +271,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 */
 /*

Reply via email to