git: 4ad84614e490 - stable/14 - ip6_cksum.c: generalize in6_cksum_partial() to allow L2 headers in passed mbuf
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 20 Mar 2025 03:13:57 UTC
The branch stable/14 has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=4ad84614e490cf2d59d670081b1ee1b065d89c15
commit 4ad84614e490cf2d59d670081b1ee1b065d89c15
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-02-19 12:38:34 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-03-20 03:13:36 +0000
ip6_cksum.c: generalize in6_cksum_partial() to allow L2 headers in passed mbuf
(cherry picked from commit fcf81de12f27d34a5c18168fd0c756c371a62076)
---
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 0a4377638de1..b62da99f9293 100644
--- a/sys/netinet6/in6.h
+++ b/sys/netinet6/in6.h
@@ -666,6 +666,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 cb2d89065f74..40d4d80ea4fb 100644
--- a/sys/netinet6/in6_cksum.c
+++ b/sys/netinet6/in6_cksum.c
@@ -250,14 +250,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;
@@ -275,9 +276,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));
/*
@@ -291,7 +293,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);
@@ -315,7 +317,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;
/*
@@ -330,6 +332,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)
{