1/* $FreeBSD: head/sys/netinet6/in6_cksum.c 62587 2000-07-04 16:35:15Z itojun $ */ 2/* $KAME: in6_cksum.c,v 1.6 2000/03/25 07:23:43 sumikawa Exp $ */ 3 |
4/* 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. |
31 */ 32 33/* 34 * Copyright (c) 1988, 1992, 1993 35 * The Regents of the University of California. All rights reserved. 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions --- 25 unchanged lines hidden (view full) --- 64 * 65 * @(#)in_cksum.c 8.1 (Berkeley) 6/10/93 66 */ 67 68#include <sys/param.h> 69#include <sys/mbuf.h> 70#include <sys/systm.h> 71#include <netinet/in.h> |
72#include |
73 74#include <net/net_osdep.h> 75 76/* 77 * Checksum routine for Internet Protocol family headers (Portable Version). 78 * 79 * This routine is very heavily used in the network 80 * code and should be modified for each CPU to be as fast as possible. 81 */ 82 |
83#define ADDCARRY(x) (x > 65535 ? x -= 65535 : x) 84#define REDUCE {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);} |
85 86static union { |
87 u_int16_t phs[4]; |
88 struct { 89 u_int32_t ph_len; 90 u_int8_t ph_zero[3]; 91 u_int8_t ph_nxt; 92 } ph; 93} uph; 94 95/* 96 * m MUST contain a continuous IP6 header. 97 * off is a offset where TCP/UDP/ICMP6 header starts. 98 * len is a total length of a transport segment. 99 * (e.g. TCP header + TCP payload) 100 */ 101 102int 103in6_cksum(m, nxt, off, len) 104 register struct mbuf *m; 105 u_int8_t nxt; |
106 u_int32_t off, len; |
107{ 108 register u_int16_t *w; 109 register int sum = 0; 110 register int mlen = 0; 111 int byte_swapped = 0; |
112#if 0 113 int srcifid = 0, dstifid = 0; 114#endif |
115 struct ip6_hdr *ip6; 116 117 union { 118 u_int8_t c[2]; 119 u_int16_t s; 120 } s_util; 121 union { 122 u_int16_t s[2]; --- 5 unchanged lines hidden (view full) --- 128 panic("in6_cksum: mbuf len (%d) < off+len (%d+%d)\n", 129 m->m_pkthdr.len, off, len); 130 } 131 132 /* 133 * First create IP6 pseudo header and calculate a summary. 134 */ 135 ip6 = mtod(m, struct ip6_hdr *); |
136#if 0 137 if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_src)) { 138 srcifid = ip6->ip6_src.s6_addr16[1]; 139 ip6->ip6_src.s6_addr16[1] = 0; 140 } 141 if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_dst)) { 142 dstifid = ip6->ip6_dst.s6_addr16[1]; 143 ip6->ip6_dst.s6_addr16[1] = 0; 144 } 145#endif |
146 w = (u_int16_t *)&ip6->ip6_src; 147 uph.ph.ph_len = htonl(len); 148 uph.ph.ph_nxt = nxt; 149 150 /* IPv6 source address */ 151 sum += w[0]; 152 if (!IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_src)) 153 sum += w[1]; --- 4 unchanged lines hidden (view full) --- 158 if (!IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_dst)) 159 sum += w[9]; 160 sum += w[10]; sum += w[11]; sum += w[12]; sum += w[13]; 161 sum += w[14]; sum += w[15]; 162 /* Payload length and upper layer identifier */ 163 sum += uph.phs[0]; sum += uph.phs[1]; 164 sum += uph.phs[2]; sum += uph.phs[3]; 165 |
166#if 0 167 if (srcifid) 168 ip6->ip6_src.s6_addr16[1] = srcifid; 169 if (dstifid) 170 ip6->ip6_dst.s6_addr16[1] = dstifid; 171#endif |
172 /* 173 * Secondly calculate a summary of the first mbuf excluding offset. 174 */ 175 while (m != NULL && off > 0) { 176 if (m->m_len <= off) 177 off -= m->m_len; 178 else 179 break; --- 142 unchanged lines hidden --- |