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