-/* $KAME: in6_cksum.c,v 1.5 2000/02/22 14:04:17 itojun Exp $ */
+/* $FreeBSD: src/sys/netinet6/in6_cksum.c,v 1.1.2.3 2001/07/03 11:01:52 ume Exp $ */
+/* $KAME: in6_cksum.c,v 1.10 2000/12/03 00:53:59 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
#include <sys/param.h>
#include <sys/mbuf.h>
#include <sys/systm.h>
+#include <kern/debug.h>
#include <netinet/in.h>
#include <netinet/ip6.h>
#define ADDCARRY(x) (x > 65535 ? x -= 65535 : x)
#define REDUCE {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);}
-static union {
- u_int16_t phs[4];
- struct {
- u_int32_t ph_len;
- u_int8_t ph_zero[3];
- u_int8_t ph_nxt;
- } ph;
-} uph;
-
/*
* m MUST contain a continuous IP6 header.
* off is a offset where TCP/UDP/ICMP6 header starts.
* (e.g. TCP header + TCP payload)
*/
-int
-in6_cksum(m, nxt, off, len)
- register struct mbuf *m;
- u_int8_t nxt;
- u_int32_t off, len;
+u_int16_t
+inet6_cksum(struct mbuf *m, unsigned int nxt, unsigned int off,
+ unsigned int len)
{
- register u_int16_t *w;
- register int sum = 0;
- register int mlen = 0;
+ u_int16_t *w;
+ int sum = 0;
+ int mlen = 0;
int byte_swapped = 0;
-#if 0
- int srcifid = 0, dstifid = 0;
-#endif
- struct ip6_hdr *ip6;
-
+ struct ip6_hdr *ip6;
+ union {
+ u_int16_t phs[4];
+ struct {
+ u_int32_t ph_len;
+ u_int8_t ph_zero[3];
+ u_int8_t ph_nxt;
+ } ph __attribute__((__packed__));
+ } uph;
union {
u_int8_t c[2];
u_int16_t s;
/* sanity check */
if (m->m_pkthdr.len < off + len) {
- panic("in6_cksum: mbuf len (%d) < off+len (%d+%d)\n",
- m->m_pkthdr.len, off, len);
+ panic("inet6_cksum: mbuf len (%d) < off+len (%d+%d)\n",
+ m->m_pkthdr.len, off, len);
}
- /*
- * First create IP6 pseudo header and calculate a summary.
- */
- ip6 = mtod(m, struct ip6_hdr *);
-#if 0
- if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_src)) {
- srcifid = ip6->ip6_src.s6_addr16[1];
- ip6->ip6_src.s6_addr16[1] = 0;
- }
- if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_dst)) {
- dstifid = ip6->ip6_dst.s6_addr16[1];
- ip6->ip6_dst.s6_addr16[1] = 0;
- }
-#endif
- w = (u_int16_t *)&ip6->ip6_src;
- uph.ph.ph_len = htonl(len);
- uph.ph.ph_nxt = nxt;
+ if (nxt != 0) {
+ bzero(&uph, sizeof (uph));
- /* IPv6 source address */
- sum += w[0];
- if (!IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_src))
- sum += w[1];
- sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5];
- sum += w[6]; sum += w[7];
- /* IPv6 destination address */
- sum += w[8];
- if (!IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_dst))
- sum += w[9];
- sum += w[10]; sum += w[11]; sum += w[12]; sum += w[13];
- sum += w[14]; sum += w[15];
- /* Payload length and upper layer identifier */
- sum += uph.phs[0]; sum += uph.phs[1];
- sum += uph.phs[2]; sum += uph.phs[3];
+ /*
+ * First create IP6 pseudo header and calculate a summary.
+ */
+ ip6 = mtod(m, struct ip6_hdr *);
+ w = (u_int16_t *)&ip6->ip6_src;
+ uph.ph.ph_len = htonl(len);
+ uph.ph.ph_nxt = nxt;
+
+ /* IPv6 source address */
+ sum += w[0];
+ if (!IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_src))
+ sum += w[1];
+ sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5];
+ sum += w[6]; sum += w[7];
+ /* IPv6 destination address */
+ sum += w[8];
+ if (!IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_dst))
+ sum += w[9];
+ sum += w[10]; sum += w[11]; sum += w[12]; sum += w[13];
+ sum += w[14]; sum += w[15];
+ /* Payload length and upper layer identifier */
+ sum += uph.phs[0]; sum += uph.phs[1];
+ sum += uph.phs[2]; sum += uph.phs[3];
+ }
-#if 0
- if (srcifid)
- ip6->ip6_src.s6_addr16[1] = srcifid;
- if (dstifid)
- ip6->ip6_dst.s6_addr16[1] = dstifid;
-#endif
/*
* Secondly calculate a summary of the first mbuf excluding offset.
*/
/*
* Lastly calculate a summary of the rest of mbufs.
*/
-
+
for (;m && len; m = m->m_next) {
if (m->m_len == 0)
continue;
s_util.c[0] = *(char *)w;
}
if (len)
- panic("in6_cksum: out of data\n");
+ printf("inet6_cksum: out of data by %d\n", len);
if (mlen == -1) {
/* The last mbuf has odd # of bytes. Follow the
standard (the odd byte may be shifted left by 8 bits