diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2019-04-22 22:47:50 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2019-04-22 22:47:50 +0000 |
commit | f23bb3dfa0169c1f4e27a045d9c15ba5b86c7fef (patch) | |
tree | 99da46d91a483365f7ac6cf591fbd96ce77d9000 /sys/netinet/in_cksum.c | |
parent | 65d034a2434935d3113128ee18c441069c8b8893 (diff) |
In in_cksum() and in6_cksum() convert types to C99 style and make
both functions consistent. In in_cksum() panic if len is longer
than mbuf, but in in6_cksum() do not panic if off and len match
exactly to the end of mbuf.
OK claudio@
Diffstat (limited to 'sys/netinet/in_cksum.c')
-rw-r--r-- | sys/netinet/in_cksum.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/sys/netinet/in_cksum.c b/sys/netinet/in_cksum.c index cdc188f713a..3131ff67e3f 100644 --- a/sys/netinet/in_cksum.c +++ b/sys/netinet/in_cksum.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_cksum.c,v 1.8 2015/07/17 23:49:03 tedu Exp $ */ +/* $OpenBSD: in_cksum.c,v 1.9 2019/04/22 22:47:49 bluhm Exp $ */ /* $NetBSD: in_cksum.c,v 1.11 1996/04/08 19:55:37 jonathan Exp $ */ /* @@ -49,24 +49,23 @@ int in_cksum(struct mbuf *m, int len) { - u_int16_t *w; + uint16_t *w; int sum = 0; int mlen = 0; int byte_swapped = 0; - union { - u_int8_t c[2]; - u_int16_t s; + uint8_t c[2]; + uint16_t s; } s_util; union { - u_int16_t s[2]; - u_int32_t l; + uint16_t s[2]; + uint32_t l; } l_util; for (;m && len; m = m->m_next) { if (m->m_len == 0) continue; - w = mtod(m, u_int16_t *); + w = mtod(m, uint16_t *); if (mlen == -1) { /* * The first byte of this mbuf is the continuation @@ -76,9 +75,9 @@ in_cksum(struct mbuf *m, int len) * s_util.c[0] is already saved when scanning previous * mbuf. */ - s_util.c[1] = *(u_int8_t *)w; + s_util.c[1] = *(uint8_t *)w; sum += s_util.s; - w = (u_int16_t *)((u_int8_t *)w + 1); + w = (uint16_t *)((uint8_t *)w + 1); mlen = m->m_len - 1; len--; } else @@ -92,8 +91,8 @@ in_cksum(struct mbuf *m, int len) if ((1 & (long) w) && (mlen > 0)) { REDUCE; sum <<= 8; - s_util.c[0] = *(u_int8_t *)w; - w = (u_int16_t *)((int8_t *)w + 1); + s_util.c[0] = *(uint8_t *)w; + w = (uint16_t *)((uint8_t *)w + 1); mlen--; byte_swapped = 1; } @@ -125,16 +124,16 @@ in_cksum(struct mbuf *m, int len) sum <<= 8; byte_swapped = 0; if (mlen == -1) { - s_util.c[1] = *(u_int8_t *)w; + s_util.c[1] = *(uint8_t *)w; sum += s_util.s; mlen = 0; } else mlen = -1; } else if (mlen == -1) - s_util.c[0] = *(u_int8_t *)w; + s_util.c[0] = *(uint8_t *)w; } if (len) - printf("cksum: out of data\n"); + panic("%s: out of data, len %d", __func__, len); if (mlen == -1) { /* The last mbuf has odd # of bytes. Follow the standard (the odd byte may be shifted left by 8 bits |