The branch main has been updated by kib:

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

commit fcf81de12f27d34a5c18168fd0c756c371a62076
Author:     Konstantin Belousov <k...@freebsd.org>
AuthorDate: 2025-02-19 12:38:34 +0000
Commit:     Konstantin Belousov <k...@freebsd.org>
CommitDate: 2025-03-13 15:56:22 +0000

    ip6_cksum.c: generalize in6_cksum_partial() to allow L2 headers in passed 
mbuf
    
    Reviewed by:    Ariel Ehrenberg <aehrenb...@nvidia.com>, Slava Shwartsman 
<slav...@nvidia.com>
    Sponsored by:   NVidia networking
    MFC after:      1 week
---
 sys/netinet6/in6.h       |  2 ++
 sys/netinet6/in6_cksum.c | 25 +++++++++++++++++--------
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/sys/netinet6/in6.h b/sys/netinet6/in6.h
index effd33787e7e..1ca846ebf514 100644
--- a/sys/netinet6/in6.h
+++ b/sys/netinet6/in6.h
@@ -664,6 +664,8 @@ struct ip6_hdr;
 
 int    in6_cksum(struct mbuf *, uint8_t, uint32_t, uint32_t);
 int    in6_cksum_partial(struct mbuf *, uint8_t, uint32_t, uint32_t, uint32_t);
+int    in6_cksum_partial_l2(struct mbuf *m, uint8_t nxt, uint32_t off_l3,
+           uint32_t off_l4, uint32_t len, uint32_t cov);
 int    in6_cksum_pseudo(struct ip6_hdr *, uint32_t, uint8_t, uint16_t);
 
 int    in6_localaddr(struct in6_addr *);
diff --git a/sys/netinet6/in6_cksum.c b/sys/netinet6/in6_cksum.c
index 2fb532d78013..70a9666a0c05 100644
--- a/sys/netinet6/in6_cksum.c
+++ b/sys/netinet6/in6_cksum.c
@@ -247,14 +247,15 @@ in6_cksum_partial_one(void *_arg, void *data, u_int len)
 
 /*
  * m MUST contain a contiguous IP6 header.
- * off is an offset where TCP/UDP/ICMP6 header starts.
+ * off_l3 is an offset where ipv6 header starts.
+ * off_l4 is an offset where TCP/UDP/ICMP6 header starts.
  * len is a total length of a transport segment.
  * (e.g. TCP header + TCP payload)
  * cov is the number of bytes to be taken into account for the checksum
  */
 int
-in6_cksum_partial(struct mbuf *m, uint8_t nxt, uint32_t off, uint32_t len,
-    uint32_t cov)
+in6_cksum_partial_l2(struct mbuf *m, uint8_t nxt, uint32_t off_l3,
+    uint32_t off_l4, uint32_t len, uint32_t cov)
 {
        struct in6_cksum_partial_arg arg;
        union l_util l_util;
@@ -272,9 +273,10 @@ in6_cksum_partial(struct mbuf *m, uint8_t nxt, uint32_t 
off, uint32_t len,
        } uph;
 
        /* Sanity check. */
-       KASSERT(m->m_pkthdr.len >= off + len, ("%s: mbuf len (%d) < off(%d)+"
-           "len(%d)", __func__, m->m_pkthdr.len, off, len));
-       KASSERT(m->m_len >= sizeof(*ip6),
+       KASSERT(m->m_pkthdr.len >= off_l4 + len,
+           ("%s: mbuf len (%d) < off(%d)+len(%d)",
+           __func__, m->m_pkthdr.len, off_l4, len));
+       KASSERT(m->m_len >= off_l3 + sizeof(*ip6),
            ("%s: mbuf len %d < sizeof(ip6)", __func__, m->m_len));
 
        /*
@@ -288,7 +290,7 @@ in6_cksum_partial(struct mbuf *m, uint8_t nxt, uint32_t 
off, uint32_t len,
        sum = uph.phs[0];  sum += uph.phs[1];
        sum += uph.phs[2];  sum += uph.phs[3];
 
-       ip6 = mtod(m, struct ip6_hdr *);
+       ip6 = mtodo(m, off_l3);
 
        /* IPv6 source address. */
        scope = in6_getscope(&ip6->ip6_src);
@@ -312,7 +314,7 @@ in6_cksum_partial(struct mbuf *m, uint8_t nxt, uint32_t 
off, uint32_t len,
         */
        arg.sum = sum;
        arg.rlen = 0;
-       (void)m_apply(m, off, cov, in6_cksum_partial_one, &arg);
+       (void)m_apply(m, off_l4, cov, in6_cksum_partial_one, &arg);
        sum = arg.sum;
 
        /*
@@ -327,6 +329,13 @@ in6_cksum_partial(struct mbuf *m, uint8_t nxt, uint32_t 
off, uint32_t len,
        return (~sum & 0xffff);
 }
 
+int
+in6_cksum_partial(struct mbuf *m, uint8_t nxt, uint32_t off, uint32_t len,
+    uint32_t cov)
+{
+       return (in6_cksum_partial_l2(m, nxt, 0, off, len, cov));
+}
+
 int
 in6_cksum(struct mbuf *m, uint8_t nxt, uint32_t off, uint32_t len)
 {

Reply via email to