Deleted Added
sdiff udiff text old ( 53541 ) new ( 62587 )
full compact
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.
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>
71#include <netinet6/ip6.h>
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
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);}
84
85static union {
86 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;
105 register int off, len;
106{
107 register u_int16_t *w;
108 register int sum = 0;
109 register int mlen = 0;
110 int byte_swapped = 0;
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 *);
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
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 ---