+
+uint16_t
+m_adj_sum16(struct mbuf *m, uint32_t start, uint32_t ulpoff, uint32_t sum)
+{
+ int len = (ulpoff - start);
+
+ if (len > 0) {
+ uint32_t adj = m_sum16(m, start, len);
+ if (adj >= sum)
+ sum = ~(adj - sum) & 0xffff;
+ else
+ sum -= adj;
+ } else if (len < 0) {
+ sum += m_sum16(m, ulpoff, -len);
+ }
+
+ ADDCARRY(sum);
+
+ return (sum);
+}
+
+extern int cpu_in_cksum(struct mbuf *m, int len, int off, uint32_t initial_sum);
+
+uint16_t
+m_sum16(struct mbuf *m, uint32_t off, uint32_t len)
+{
+ int mlen;
+
+ /*
+ * Sanity check
+ *
+ * Use m_length2() instead of m_length(), as we cannot rely on
+ * the caller setting m_pkthdr.len correctly, if the mbuf is
+ * a M_PKTHDR one.
+ */
+ if ((mlen = m_length2(m, NULL)) < (off + len)) {
+ panic("%s: mbuf len (%d) < off+len (%d+%d)\n", __func__,
+ mlen, off, len);
+ }
+
+ return (~cpu_in_cksum(m, len, off, 0) & 0xffff);
+}