Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F109810683
D32941.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D32941.diff
View Options
diff --git a/sys/netinet/sctp_crc32.c b/sys/netinet/sctp_crc32.c
--- a/sys/netinet/sctp_crc32.c
+++ b/sys/netinet/sctp_crc32.c
@@ -80,6 +80,16 @@
return (crc32c);
}
+static int
+sctp_calculate_cksum_cb(void *arg, void *data, u_int len)
+{
+ uint32_t *basep;
+
+ basep = arg;
+ *basep = calculate_crc32c(*basep, data, len);
+ return (0);
+}
+
/*
* Compute the SCTP checksum in network byte order for a given mbuf chain m
* which contains an SCTP packet starting at offset.
@@ -89,30 +99,17 @@
uint32_t
sctp_calculate_cksum(struct mbuf *m, uint32_t offset)
{
- uint32_t base = 0xffffffff;
-
- while (offset > 0) {
- KASSERT(m != NULL, ("sctp_calculate_cksum, offset > length of mbuf chain"));
- if (offset < (uint32_t)m->m_len) {
- break;
- }
- offset -= m->m_len;
- m = m->m_next;
- }
- if (offset > 0) {
- base = calculate_crc32c(base,
- (unsigned char *)(m->m_data + offset),
- (unsigned int)(m->m_len - offset));
- m = m->m_next;
- }
- while (m != NULL) {
- base = calculate_crc32c(base,
- (unsigned char *)m->m_data,
- (unsigned int)m->m_len);
- m = m->m_next;
- }
- base = sctp_finalize_crc32c(base);
- return (base);
+ uint32_t base;
+ int len;
+
+ M_ASSERTPKTHDR(m);
+ KASSERT(offset < m->m_pkthdr.len,
+ ("%s: invalid offset %u into mbuf %p", __func__, offset, m));
+
+ base = 0xffffffff;
+ len = m->m_pkthdr.len - offset;
+ (void)m_apply(m, offset, len, sctp_calculate_cksum_cb, &base);
+ return (sctp_finalize_crc32c(base));
}
#if defined(SCTP) || defined(SCTP_SUPPORT)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Feb 10, 8:19 PM (7 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16574355
Default Alt Text
D32941.diff (1 KB)
Attached To
Mode
D32941: sctp: Use m_apply() to calcuate a checksum for an mbuf chain
Attached
Detach File
Event Timeline
Log In to Comment