Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet/sctp_crc32.c
Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | #else | ||||
* For LITTLE ENDIAN platforms the result is in already in network | * For LITTLE ENDIAN platforms the result is in already in network | ||||
* byte order. | * byte order. | ||||
*/ | */ | ||||
crc32c = result; | crc32c = result; | ||||
#endif | #endif | ||||
return (crc32c); | 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 | * Compute the SCTP checksum in network byte order for a given mbuf chain m | ||||
* which contains an SCTP packet starting at offset. | * which contains an SCTP packet starting at offset. | ||||
* Since this function is also called by ipfw, don't assume that | * Since this function is also called by ipfw, don't assume that | ||||
* it is compiled on a kernel with SCTP support. | * it is compiled on a kernel with SCTP support. | ||||
*/ | */ | ||||
uint32_t | uint32_t | ||||
sctp_calculate_cksum(struct mbuf *m, uint32_t offset) | sctp_calculate_cksum(struct mbuf *m, uint32_t offset) | ||||
{ | { | ||||
uint32_t base = 0xffffffff; | uint32_t base; | ||||
int len; | |||||
while (offset > 0) { | M_ASSERTPKTHDR(m); | ||||
KASSERT(m != NULL, ("sctp_calculate_cksum, offset > length of mbuf chain")); | KASSERT(offset < m->m_pkthdr.len, | ||||
if (offset < (uint32_t)m->m_len) { | ("%s: invalid offset %u into mbuf %p", __func__, offset, m)); | ||||
break; | |||||
} | base = 0xffffffff; | ||||
offset -= m->m_len; | len = m->m_pkthdr.len - offset; | ||||
m = m->m_next; | (void)m_apply(m, offset, len, sctp_calculate_cksum_cb, &base); | ||||
} | return (sctp_finalize_crc32c(base)); | ||||
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); | |||||
} | } | ||||
#if defined(SCTP) || defined(SCTP_SUPPORT) | #if defined(SCTP) || defined(SCTP_SUPPORT) | ||||
VNET_DEFINE(struct sctp_base_info, system_base_info); | VNET_DEFINE(struct sctp_base_info, system_base_info); | ||||
/* | /* | ||||
* Compute and insert the SCTP checksum in network byte order for a given | * Compute and insert the SCTP checksum in network byte order for a given | ||||
Show All 25 Lines |