1 | /*
|
---|
2 | * TINET (TCP/IP Protocol Stack)
|
---|
3 | *
|
---|
4 | * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
|
---|
5 | * Tomakomai National College of Technology, JAPAN
|
---|
6 | *
|
---|
7 | * ä¸è¨èä½æ¨©è
|
---|
8 | ã¯ï¼ä»¥ä¸ã® (1)ï½(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
9 | * ã«ãã£ã¦å
|
---|
10 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
11 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
12 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
13 | å¸ï¼ä»¥ä¸ï¼
|
---|
14 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
15 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
16 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
17 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
18 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
19 | * ç¨ã§ããå½¢ã§åé
|
---|
20 | å¸ããå ´åã«ã¯ï¼åé
|
---|
21 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
22 | * è
|
---|
23 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
24 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
25 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
26 | * ç¨ã§ããªãå½¢ã§åé
|
---|
27 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®æ¡ä»¶ãæºãããã¨ï¼
|
---|
28 | * (a) åé
|
---|
29 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
30 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
31 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
32 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
33 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
34 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
35 | 責ãããã¨ï¼
|
---|
36 | *
|
---|
37 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
38 | ã
|
---|
39 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
40 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
41 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
42 | *
|
---|
43 | * @(#) $Id: ip6_input.c 388 2019-05-22 11:25:18Z coas-nagasima $
|
---|
44 | */
|
---|
45 |
|
---|
46 | /* $FreeBSD: src/sys/netinet6/ip6_input.c,v 1.11.2.10 2001/07/24 19:10:18 brooks Exp $ */
|
---|
47 | /* $KAME: ip6_input.c,v 1.194 2001/05/27 13:28:35 itojun Exp $ */
|
---|
48 |
|
---|
49 | /*
|
---|
50 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
---|
51 | * All rights reserved.
|
---|
52 | *
|
---|
53 | * Redistribution and use in source and binary forms, with or without
|
---|
54 | * modification, are permitted provided that the following conditions
|
---|
55 | * are met:
|
---|
56 | * 1. Redistributions of source code must retain the above copyright
|
---|
57 | * notice, this list of conditions and the following disclaimer.
|
---|
58 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
59 | * notice, this list of conditions and the following disclaimer in the
|
---|
60 | * documentation and/or other materials provided with the distribution.
|
---|
61 | * 3. Neither the name of the project nor the names of its contributors
|
---|
62 | * may be used to endorse or promote products derived from this software
|
---|
63 | * without specific prior written permission.
|
---|
64 | *
|
---|
65 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
---|
66 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
67 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
68 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
---|
69 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
70 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
71 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
72 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
73 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
74 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
75 | * SUCH DAMAGE.
|
---|
76 | */
|
---|
77 |
|
---|
78 | /*
|
---|
79 | * Copyright (c) 1982, 1986, 1988, 1993
|
---|
80 | * The Regents of the University of California. All rights reserved.
|
---|
81 | *
|
---|
82 | * Redistribution and use in source and binary forms, with or without
|
---|
83 | * modification, are permitted provided that the following conditions
|
---|
84 | * are met:
|
---|
85 | * 1. Redistributions of source code must retain the above copyright
|
---|
86 | * notice, this list of conditions and the following disclaimer.
|
---|
87 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
88 | * notice, this list of conditions and the following disclaimer in the
|
---|
89 | * documentation and/or other materials provided with the distribution.
|
---|
90 | * 3. All advertising materials mentioning features or use of this software
|
---|
91 | * must display the following acknowledgement:
|
---|
92 | * This product includes software developed by the University of
|
---|
93 | * California, Berkeley and its contributors.
|
---|
94 | * 4. Neither the name of the University nor the names of its contributors
|
---|
95 | * may be used to endorse or promote products derived from this software
|
---|
96 | * without specific prior written permission.
|
---|
97 | *
|
---|
98 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
---|
99 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
100 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
101 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
---|
102 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
103 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
104 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
105 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
106 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
107 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
108 | * SUCH DAMAGE.
|
---|
109 | *
|
---|
110 | * @(#)ip_input.c 8.2 (Berkeley) 1/4/94
|
---|
111 | */
|
---|
112 |
|
---|
113 | #include <string.h>
|
---|
114 |
|
---|
115 | #ifdef TARGET_KERNEL_ASP
|
---|
116 |
|
---|
117 | #include <kernel.h>
|
---|
118 | #include <sil.h>
|
---|
119 | #include <t_syslog.h>
|
---|
120 | #include "tinet_cfg.h"
|
---|
121 |
|
---|
122 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
123 |
|
---|
124 | #ifdef TARGET_KERNEL_JSP
|
---|
125 |
|
---|
126 | #include <s_services.h>
|
---|
127 | #include <t_services.h>
|
---|
128 | #include "tinet_id.h"
|
---|
129 |
|
---|
130 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
131 |
|
---|
132 | #include <tinet_defs.h>
|
---|
133 | #include <tinet_config.h>
|
---|
134 |
|
---|
135 | #include <net/if.h>
|
---|
136 | #include <net/if_loop.h>
|
---|
137 | #include <net/if_ppp.h>
|
---|
138 | #include <net/ethernet.h>
|
---|
139 | #include <net/ppp_ipcp.h>
|
---|
140 | #include <net/net.h>
|
---|
141 | #include <net/net_endian.h>
|
---|
142 | #include <net/net_buf.h>
|
---|
143 | #include <net/net_count.h>
|
---|
144 |
|
---|
145 | #include <netinet/in.h>
|
---|
146 | #include <netinet/in_var.h>
|
---|
147 | #include <netinet/ip.h>
|
---|
148 | #include <netinet/ip_var.h>
|
---|
149 | #include <netinet/ip_icmp.h>
|
---|
150 | #include <netinet/tcp.h>
|
---|
151 | #include <netinet/tcp_var.h>
|
---|
152 | #include <netinet/udp_var.h>
|
---|
153 |
|
---|
154 | #include <netinet6/nd6.h>
|
---|
155 | #include <netinet6/ah6.h>
|
---|
156 | #include <netinet6/esp6.h>
|
---|
157 |
|
---|
158 | #include <net/if_var.h>
|
---|
159 |
|
---|
160 | #ifdef _IP6_CFG
|
---|
161 |
|
---|
162 | /*
|
---|
163 | * é¢æ°
|
---|
164 | */
|
---|
165 |
|
---|
166 | static uint_t ip6_no_header_input (T_NET_BUF **inputp, uint_t *offp, uint_t *nextp);
|
---|
167 |
|
---|
168 | /*
|
---|
169 | * ä¸ä½ãããã³ã«é¸ææ§é ä½
|
---|
170 | */
|
---|
171 |
|
---|
172 | typedef struct t_proto_switch {
|
---|
173 | uint_t (*func)(T_NET_BUF **, uint_t *, uint_t *); /* å
|
---|
174 | ¥åé¢æ° */
|
---|
175 | uint_t proto; /* ãããã³ã«çªå· */
|
---|
176 | } T_PROTO_SWITCH;
|
---|
177 |
|
---|
178 | static const T_PROTO_SWITCH proto_switch[] = {
|
---|
179 | { esp6_input, IPPROTO_ESP }, /* IPv6 æå·åããã */
|
---|
180 | { ah6_input, IPPROTO_AH }, /* IPv6 èªè¨¼ããã */
|
---|
181 | { frag6_input, IPPROTO_FRAGMENT }, /* æçããã */
|
---|
182 | { route6_input, IPPROTO_ROUTING }, /* çµè·¯å¶å¾¡ããã */
|
---|
183 | { dest6_input, IPPROTO_DSTOPTS }, /* IPv6 çµç¹ãªãã·ã§ã³ */
|
---|
184 | { ip6_no_header_input,
|
---|
185 | IPPROTO_NONE }, /* 次ãããç¡ã */
|
---|
186 | { icmp6_input, IPPROTO_ICMPV6 },
|
---|
187 |
|
---|
188 | #if defined(SUPPORT_TCP)
|
---|
189 |
|
---|
190 | { tcp_input, IPPROTO_TCP },
|
---|
191 |
|
---|
192 | #endif /* of #if defined(SUPPORT_TCP) */
|
---|
193 |
|
---|
194 | #if defined(SUPPORT_UDP) && TNUM_UDP6_CEPID > 0
|
---|
195 |
|
---|
196 | { udp6_input, IPPROTO_UDP },
|
---|
197 |
|
---|
198 | #endif /* of #if defined(SUPPORT_UDP) && TNUM_UDP6_CEPID > 0 */
|
---|
199 |
|
---|
200 | };
|
---|
201 |
|
---|
202 | #ifdef SUPPORT_MIB
|
---|
203 |
|
---|
204 | T_IN6_IFSTAT in6_ifstat;
|
---|
205 |
|
---|
206 | #endif /* of #ifdef SUPPORT_MIB */
|
---|
207 |
|
---|
208 | /*
|
---|
209 | * get_upper_proto -- ä¸ä½ãããã³ã«å¦çé¢æ°ãè¿ãã
|
---|
210 | */
|
---|
211 |
|
---|
212 | static uint_t (*
|
---|
213 | get_upper_proto(uint_t proto))(T_NET_BUF **, uint_t *, uint_t *)
|
---|
214 | {
|
---|
215 | int_t ix;
|
---|
216 |
|
---|
217 | for (ix = sizeof(proto_switch) / sizeof(T_PROTO_SWITCH); ix -- > 0; )
|
---|
218 | if (proto_switch[ix].proto == proto)
|
---|
219 | return proto_switch[ix].func;
|
---|
220 | return NULL;
|
---|
221 | }
|
---|
222 |
|
---|
223 | /*
|
---|
224 | * ip6_no_header_input -- 次ããããç¡ãã®å ´åã®å
|
---|
225 | ¥åå¦ç
|
---|
226 | */
|
---|
227 |
|
---|
228 | static uint_t
|
---|
229 | ip6_no_header_input (T_NET_BUF **input, uint_t *offp, uint_t *nextp)
|
---|
230 | {
|
---|
231 | syscall(rel_net_buf(*input));
|
---|
232 | return IPPROTO_DONE;
|
---|
233 | }
|
---|
234 |
|
---|
235 | /*
|
---|
236 | * ip6_hopopts_input -- ä¸ç¶ç¹ãªãã·ã§ã³å
|
---|
237 | ¥åå¦ç
|
---|
238 | *
|
---|
239 | * æ¬å®è£
|
---|
240 | ã§ã¯ãããã£ã³ã°ä»¥å¤ã®ãªãã·ã§ã³ãå
|
---|
241 | ¨ã¦æªç¥ãªãã·ã§ã³ã¨ãã¦å¦çããã
|
---|
242 | *
|
---|
243 | * æ»ãå¤:
|
---|
244 | *
|
---|
245 | * 0 ä»¥ä¸ æ£å¸¸
|
---|
246 | * IP6_OPT_RET_ERR (-1) ã¨ã©ã¼ãå¼åºå´ã§ãããã¯ã¼ã¯ãããã¡ãéæ¾ããã
|
---|
247 | * IP6_OPT_RET_REL (-2) ã¨ã©ã¼ããããã¯ã¼ã¯ãããã¡ã¯éæ¾ããã¦ããã
|
---|
248 | */
|
---|
249 |
|
---|
250 | static ER_UINT
|
---|
251 | ip6_hopopts_input (T_NET_BUF *input, uint_t *offp, uint_t *nextp)
|
---|
252 | {
|
---|
253 | T_IP6_HBH_HDR *hbh;
|
---|
254 | ER_UINT optlen;
|
---|
255 | uint_t len;
|
---|
256 | uint8_t *opt;
|
---|
257 |
|
---|
258 | hbh = (T_IP6_HBH_HDR *)(input->buf + *offp);
|
---|
259 | len = (hbh->len + 1) << 3;
|
---|
260 | *nextp = *offp - IF_HDR_SIZE + offsetof(T_IP6_HBH_HDR, next);
|
---|
261 | *offp += len;
|
---|
262 | opt = (uint8_t *)hbh + sizeof(T_IP6_HBH_HDR);
|
---|
263 |
|
---|
264 | for (len -= sizeof(T_IP6_HBH_HDR); len > 0; len -= optlen) {
|
---|
265 | switch (*opt) {
|
---|
266 | case IP6OPT_PAD1:
|
---|
267 | optlen = 1;
|
---|
268 | break;
|
---|
269 | case IP6OPT_PADN:
|
---|
270 | if (len < IP6OPT_MINLEN)
|
---|
271 | return IP6_OPT_RET_ERR;
|
---|
272 | optlen = *(opt + 1) + 2;
|
---|
273 | break;
|
---|
274 | case IP6OPT_JUMBO:
|
---|
275 | case IP6OPT_NSAP_ADDR:
|
---|
276 | case IP6OPT_TUNNEL_LIMIT:
|
---|
277 | case IP6OPT_RTR_ALERT:
|
---|
278 | default:
|
---|
279 | if (len < IP6OPT_MINLEN)
|
---|
280 | return IP6_OPT_RET_ERR;
|
---|
281 | optlen = ip6_unknown_opt(input, opt);
|
---|
282 | if (optlen < 0)
|
---|
283 | return optlen;
|
---|
284 | optlen += 2;
|
---|
285 | break;
|
---|
286 | }
|
---|
287 |
|
---|
288 | opt += optlen;
|
---|
289 | }
|
---|
290 |
|
---|
291 | return *offp;
|
---|
292 | }
|
---|
293 |
|
---|
294 | /*
|
---|
295 | * ip6_get_prev_hdr -- ç´åã®æ¡å¼µãããã® next ãã£ã¼ã«ãã®ã¢ãã¬ã¹ãè¿ãã
|
---|
296 | *
|
---|
297 | * 注æ: off ã«ã¯ IF_HDR_SIZE ãå«ã¾ãã¦ããã
|
---|
298 | */
|
---|
299 |
|
---|
300 | uint8_t *
|
---|
301 | ip6_get_prev_hdr (T_NET_BUF *nbuf, uint_t off)
|
---|
302 | {
|
---|
303 | T_IP6_HDR *ip6h;
|
---|
304 | T_IP6_EXT_HDR *ip6eh;
|
---|
305 | uint_t len;
|
---|
306 | uint8_t next;
|
---|
307 |
|
---|
308 | ip6h = GET_IP6_HDR(nbuf);
|
---|
309 | if (off == IF_HDR_SIZE + sizeof(T_IP6_HDR))
|
---|
310 | return &ip6h->next;
|
---|
311 | else {
|
---|
312 | next = ip6h->next;
|
---|
313 | len = IF_HDR_SIZE + sizeof(T_IP6_HDR);
|
---|
314 | ip6eh = NULL;
|
---|
315 |
|
---|
316 | while (len < off) {
|
---|
317 | ip6eh = (T_IP6_EXT_HDR *)(nbuf->buf + len);
|
---|
318 |
|
---|
319 | switch (next) {
|
---|
320 | case IPPROTO_FRAGMENT:
|
---|
321 | len += sizeof(T_IP6_FRAG_HDR);
|
---|
322 | break;
|
---|
323 | case IPPROTO_AH:
|
---|
324 | len += (ip6eh->len + 2) << 2;
|
---|
325 | break;
|
---|
326 | default:
|
---|
327 | len += (ip6eh->len + 2) << 3;
|
---|
328 | break;
|
---|
329 | }
|
---|
330 | next = ip6eh->next;
|
---|
331 | }
|
---|
332 |
|
---|
333 | if (ip6eh == NULL)
|
---|
334 | return NULL;
|
---|
335 | else
|
---|
336 | return &ip6eh->next;
|
---|
337 | }
|
---|
338 | }
|
---|
339 |
|
---|
340 | /*
|
---|
341 | * ip6_init -- IPv6 ã®åæåé¢æ°
|
---|
342 | */
|
---|
343 |
|
---|
344 | void
|
---|
345 | ip6_init (void)
|
---|
346 | {
|
---|
347 | in6_init();
|
---|
348 | in6_ifainit();
|
---|
349 | }
|
---|
350 |
|
---|
351 | /*
|
---|
352 | * ip6_input -- IPv6 ã®å
|
---|
353 | ¥åé¢æ°
|
---|
354 | */
|
---|
355 |
|
---|
356 | void
|
---|
357 | ip6_input (T_NET_BUF *input)
|
---|
358 | {
|
---|
359 | T_IP6_HDR *ip6h;
|
---|
360 | T_IN6_IFADDR *ia6;
|
---|
361 | T_IFNET *ifp;
|
---|
362 | ER_UINT noff;
|
---|
363 | uint_t next, nest, plen, offp, nextp;
|
---|
364 | uint_t (*func)(T_NET_BUF **, uint_t *, uint_t *);
|
---|
365 |
|
---|
366 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_OCTETS], input->len - IF_HDR_SIZE);
|
---|
367 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_PACKETS], 1);
|
---|
368 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInReceives, 1);
|
---|
369 |
|
---|
370 | /* IP ãããã®é·ãããã§ãã¯ããã*/
|
---|
371 | if (input->len < IF_IP6_HDR_SIZE) {
|
---|
372 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_SHORT], 1);
|
---|
373 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInHdrErrors, 1);
|
---|
374 | goto buf_rel;
|
---|
375 | }
|
---|
376 |
|
---|
377 | ip6h = GET_IP6_HDR(input);
|
---|
378 |
|
---|
379 | /* ãã¼ã¸ã§ã³ããã§ãã¯ããã*/
|
---|
380 | if (IP6_VCF_V(ntohl(ip6h->vcf)) != IPV6_VERSION) {
|
---|
381 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_VER], 1);
|
---|
382 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInHdrErrors, 1);
|
---|
383 | goto buf_rel;
|
---|
384 | }
|
---|
385 |
|
---|
386 | /*
|
---|
387 | * 次ã®ãã¼ã¿ã°ã©ã ã¯ç ´æ£ããã
|
---|
388 | *
|
---|
389 | * ã»å§ç¹ã¢ãã¬ã¹ããã«ããã£ã¹ã
|
---|
390 | * ã»çµç¹ã¢ãã¬ã¹ãæªå®ç¾©
|
---|
391 | *
|
---|
392 | * ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ãã«ã¼ãããã¯ã§ãªãã¨ãã
|
---|
393 | * 次ã®ãã¼ã¿ã°ã©ã ãç ´æ£ããã
|
---|
394 | *
|
---|
395 | * ã»å§ç¹ã¢ãã¬ã¹ãã«ã¼ãããã¯
|
---|
396 | * ã»çµç¹ã¢ãã¬ã¹ãã«ã¼ãããã¯
|
---|
397 | *
|
---|
398 | * æªæã®ããã¦ã¼ã¶ã TCP/UDP ã¹ã¿ãã¯ã®æ··ä¹±ã
|
---|
399 | * ã»ãã¥ãªãã£ãã§ãã¯ããã¤ãã¹ãããããIPv4
|
---|
400 | * ãããã¢ãã¬ã¹ãæªç¨ãããã¨ãé²ããã
|
---|
401 | * 以ä¸ã®ãã¼ã¿ã°ã©ã ã¯ç ´æ£ããã
|
---|
402 | *
|
---|
403 | * ã»å§ç¹ã¢ãã¬ã¹ã ::ffff:127.0.0.1
|
---|
404 | * ã»çµç¹ã¢ãã¬ã¹ã ::ffff:127.0.0.1
|
---|
405 | */
|
---|
406 |
|
---|
407 | if (IN6_IS_ADDR_MULTICAST(&ip6h->src) ||
|
---|
408 | IN6_IS_ADDR_UNSPECIFIED(&ip6h->dst)) {
|
---|
409 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_ADDR], 1);
|
---|
410 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInAddrErrors, 1);
|
---|
411 | goto buf_rel;
|
---|
412 | }
|
---|
413 |
|
---|
414 | if (IN6_IS_ADDR_V4MAPPED(&ip6h->src) ||
|
---|
415 | IN6_IS_ADDR_V4MAPPED(&ip6h->dst)) {
|
---|
416 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_ADDR], 1);
|
---|
417 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInAddrErrors, 1);
|
---|
418 | goto buf_rel;
|
---|
419 | }
|
---|
420 |
|
---|
421 | #ifdef SUPPORT_LOOP
|
---|
422 |
|
---|
423 | #else /* of #ifdef SUPPORT_LOOP */
|
---|
424 |
|
---|
425 | if (IN6_IS_ADDR_LOOPBACK(&ip6h->src) ||
|
---|
426 | IN6_IS_ADDR_LOOPBACK(&ip6h->dst)) {
|
---|
427 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_ADDR], 1);
|
---|
428 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInAddrErrors, 1);
|
---|
429 | goto buf_rel;
|
---|
430 | }
|
---|
431 |
|
---|
432 | #endif /* of #ifdef SUPPORT_LOOP */
|
---|
433 |
|
---|
434 | ifp = IF_GET_IFNET();
|
---|
435 |
|
---|
436 | if (IN6_IS_ADDR_MULTICAST(&ip6h->dst)) {
|
---|
437 | /* å®å
|
---|
438 | ããã«ããã£ã¹ãã®å ´åã®å¦ç */
|
---|
439 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInMcastPkts, 1);
|
---|
440 | if (!in6_lookup_multi(ifp, &ip6h->dst)) {
|
---|
441 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_ADDR], 1);
|
---|
442 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInAddrErrors, 1);
|
---|
443 | goto buf_rel;
|
---|
444 | }
|
---|
445 | }
|
---|
446 | else {
|
---|
447 | if ((ia6 = in6_lookup_ifaddr(ifp, &ip6h->dst)) == NULL) {
|
---|
448 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_ADDR], 1);
|
---|
449 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInAddrErrors, 1);
|
---|
450 | goto buf_rel;
|
---|
451 | }
|
---|
452 |
|
---|
453 | /* ã¢ãã¬ã¹ãæªè§£æ±ºã®å ´åã¯ãã¼ã¿ã°ã©ã ãç ´æ£ããã*/
|
---|
454 | if (IFA6_IS_NOTREADY(ia6)) {
|
---|
455 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_ADDR], 1);
|
---|
456 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInAddrErrors, 1);
|
---|
457 | goto buf_rel;
|
---|
458 | }
|
---|
459 | }
|
---|
460 |
|
---|
461 | /* ãªãã»ãããè¨å®ããã*/
|
---|
462 | offp = GET_IP6_NEXT_HDR(input) - input->buf;
|
---|
463 |
|
---|
464 | /* ãã¤ãã¼ãé·ãåãåºãã*/
|
---|
465 | plen = ntohs(ip6h->plen);
|
---|
466 |
|
---|
467 |
|
---|
468 | /* 次ãããã®ä½ç½®ãåæåããã*/
|
---|
469 | nextp = offsetof(T_IP6_HDR, next);
|
---|
470 |
|
---|
471 | /*
|
---|
472 | * ä¸ç¶ç¹ (Hop-by-Hop) ãªãã·ã§ã³ãããã®ãã§ãã¯
|
---|
473 | */
|
---|
474 | if (ip6h->next == IPPROTO_HOPOPTS) {
|
---|
475 |
|
---|
476 | /* ä¸ç¶ç¹ãããã®é·ãããã§ãã¯ããã*/
|
---|
477 | if (plen < sizeof(T_IP6_HBH_HDR)) {
|
---|
478 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_SHORT], 1);
|
---|
479 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInHdrErrors, 1);
|
---|
480 | goto buf_rel;
|
---|
481 | }
|
---|
482 |
|
---|
483 | if ((noff = ip6_hopopts_input(input, &offp, &nextp)) < 0) {
|
---|
484 | if (noff == IP6_OPT_RET_ERR) {
|
---|
485 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_PACKETS], 1);
|
---|
486 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInHdrErrors, 1);
|
---|
487 | goto buf_rel;
|
---|
488 | }
|
---|
489 | else if (noff == IP6_OPT_RET_REL) {
|
---|
490 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_PACKETS], 1);
|
---|
491 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInHdrErrors, 1);
|
---|
492 | return;
|
---|
493 | }
|
---|
494 | }
|
---|
495 |
|
---|
496 | /*
|
---|
497 | * ãã¤ãã¼ãé·ã 0 ã§ãä¸ç¶ç¹ãªãã·ã§ã³ãããã¨ãã¯ã
|
---|
498 | * 巨大ãã¤ãã¼ãã»ãªãã·ã§ã³ãå«ã¾ããªããã°ãªããªãã
|
---|
499 | * ãã®ã¨ãã巨大ãã¤ãã¼ãã»ãªãã·ã§ã³ã«ãã
|
---|
500 | * ãã¤ãã¼ãé·ããã§ãã¯ããå¿
|
---|
501 | è¦ãããããæ¬å®è£
|
---|
502 | ã§ã¯ã
|
---|
503 | * 巨大ãã¤ãã¼ãã»ãªãã·ã§ã³ãæªç¥ã®ãªãã·ã§ã³ã¨ãã¦
|
---|
504 | * æ±ãã®ã§ãä½ãããªãã
|
---|
505 | */
|
---|
506 | next = ((T_IP6_HBH_HDR *)(ip6h + 1))->next;
|
---|
507 | }
|
---|
508 | else
|
---|
509 | next = ip6h->next;
|
---|
510 |
|
---|
511 | /* IPv6 ãã¼ã¿ã°ã©ã é·ããã§ãã¯ããã*/
|
---|
512 | if (input->len - IF_IP6_HDR_SIZE < plen) {
|
---|
513 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_SHORT], 1);
|
---|
514 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInTruncatedPkts, 1);
|
---|
515 | goto buf_rel;
|
---|
516 | }
|
---|
517 | else if (input->len > IF_IP6_HDR_SIZE + plen)
|
---|
518 | input->len = IF_IP6_HDR_SIZE + plen;
|
---|
519 |
|
---|
520 | /* ä¸ä½ãããã³ã«å¦çé¢æ°ãå¼ã³åºãã*/
|
---|
521 | nest = 0;
|
---|
522 | while (next != IPPROTO_DONE) {
|
---|
523 | if (++ nest > IP6_HDR_NEST_LIMIT) {
|
---|
524 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_PROTO], 1);
|
---|
525 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInUnknownProtos, 1);
|
---|
526 | goto buf_rel;
|
---|
527 | }
|
---|
528 | else if ((func = get_upper_proto(next)) == NULL) {
|
---|
529 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_PROTO], 1);
|
---|
530 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_PACKETS], 1);
|
---|
531 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInUnknownProtos, 1);
|
---|
532 |
|
---|
533 | /* icmp6_error ã§ãããã¯ã¼ã¯ãããã¡ãéæ¾ããã*/
|
---|
534 | icmp6_error(input, ICMP6_PARAM_PROB,
|
---|
535 | ICMP6_PARAMPROB_NEXT_HEADER, nextp);
|
---|
536 | return;
|
---|
537 | }
|
---|
538 | else {
|
---|
539 | next = (*func)(&input, &offp, &nextp);
|
---|
540 | }
|
---|
541 | }
|
---|
542 | return;
|
---|
543 |
|
---|
544 | buf_rel:
|
---|
545 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_PACKETS], 1);
|
---|
546 | syscall(rel_net_buf(input));
|
---|
547 | }
|
---|
548 |
|
---|
549 | /*
|
---|
550 | * ip6_nexthdr -- 次ã®ãããã®ãªãã»ãããè¿ãã
|
---|
551 | *
|
---|
552 | * æ»ãå¤ == -1 : æå¾ã®ããããã¾ãã¯ã¨ã©ã¼ã
|
---|
553 | * æ»ãå¤ > 0 : ããã«ããããç¶ãã
|
---|
554 | */
|
---|
555 |
|
---|
556 | ER_UINT
|
---|
557 | ip6_nexthdr (T_NET_BUF *nbuf, uint_t off, uint_t proto, uint_t *nextp)
|
---|
558 | {
|
---|
559 | T_IP6_FRAG_HDR *ip6fh;
|
---|
560 | T_IP6_EXT_HDR *ip6eh;
|
---|
561 |
|
---|
562 | switch (proto) {
|
---|
563 |
|
---|
564 | case IPPROTO_IPV6: /* IPv6 */
|
---|
565 | if (nbuf->len < off + IP6_HDR_SIZE)
|
---|
566 | return (ER_UINT)-1;
|
---|
567 | *nextp = ((T_IP6_HDR *)(nbuf->buf + off))->next;
|
---|
568 | return off + IP6_HDR_SIZE;
|
---|
569 | break;
|
---|
570 |
|
---|
571 | case IPPROTO_FRAGMENT: /* æçããã */
|
---|
572 | if (nbuf->len < off + sizeof(T_IP6_FRAG_HDR))
|
---|
573 | return (ER_UINT)-1;
|
---|
574 |
|
---|
575 | /* ä¸éã®ãã©ã°ã¡ã³ãã®å ´åã¯å¦çããããã*/
|
---|
576 | ip6fh = (T_IP6_FRAG_HDR *)(nbuf->buf + off);
|
---|
577 | if (ntohs(ip6fh->off_flag) & IP6F_MORE_FRAG)
|
---|
578 | return (ER_UINT)-1;
|
---|
579 |
|
---|
580 | *nextp = ip6fh->next;
|
---|
581 | return off + sizeof(T_IP6_FRAG_HDR);
|
---|
582 | break;
|
---|
583 |
|
---|
584 | case IPPROTO_AH: /* IPv6 èªè¨¼ããã */
|
---|
585 | case IPPROTO_HOPOPTS: /* IPv6 ä¸ç¶ç¹ (Hop-by-Hop) ãªãã·ã§ã³ */
|
---|
586 | case IPPROTO_ROUTING: /* çµè·¯å¶å¾¡ããã */
|
---|
587 | case IPPROTO_DSTOPTS: /* IPv6 çµç¹ãªãã·ã§ã³ */
|
---|
588 | if (nbuf->len < off + sizeof(T_IP6_EXT_HDR))
|
---|
589 | return (ER_UINT)-1;
|
---|
590 |
|
---|
591 | ip6eh = (T_IP6_EXT_HDR *)(nbuf->buf + off);
|
---|
592 | *nextp = ip6eh->next;
|
---|
593 | if (proto == IPPROTO_AH)
|
---|
594 | return off + ((ip6eh->len + 2) << 2);
|
---|
595 | else
|
---|
596 | return off + ((ip6eh->len + 1) << 3);
|
---|
597 | break;
|
---|
598 | }
|
---|
599 |
|
---|
600 | return (ER_UINT)-1;
|
---|
601 | }
|
---|
602 |
|
---|
603 | /*
|
---|
604 | * ip6_lasthdr -- æå¾ã®ãããã®ãªãã»ãããè¿ãã
|
---|
605 | */
|
---|
606 |
|
---|
607 | ER_UINT
|
---|
608 | ip6_lasthdr (T_NET_BUF *nbuf, uint_t off, uint_t proto, uint_t *nextp)
|
---|
609 | {
|
---|
610 | ER_UINT newoff;
|
---|
611 |
|
---|
612 | while (1) {
|
---|
613 | newoff = ip6_nexthdr(nbuf, off, proto, nextp);
|
---|
614 | if (newoff < 0)
|
---|
615 | return (ER_UINT)off;
|
---|
616 | off = newoff;
|
---|
617 | proto = *nextp;
|
---|
618 | }
|
---|
619 | return (ER_UINT)0u;
|
---|
620 | }
|
---|
621 |
|
---|
622 | /*
|
---|
623 | * ip6_unknown_opt -- æªç¥ã®ãªãã·ã§ã³ã®å¦ç
|
---|
624 | *
|
---|
625 | * æ»ãå¤:
|
---|
626 | *
|
---|
627 | * 0 ä»¥ä¸ æ£å¸¸ããªãã·ã§ã³é·ã
|
---|
628 | * IP6_OPT_RET_ERR (-1) ã¨ã©ã¼ãå¼åºå´ã§ãããã¯ã¼ã¯ãããã¡ãéæ¾ããã
|
---|
629 | * IP6_OPT_RET_REL (-2) ã¨ã©ã¼ããããã¯ã¼ã¯ãããã¡ã¯éæ¾ããã¦ããã
|
---|
630 | */
|
---|
631 |
|
---|
632 | ER_UINT
|
---|
633 | ip6_unknown_opt (T_NET_BUF *input, uint8_t *opt)
|
---|
634 | {
|
---|
635 | switch (IP6OPT_TYPE(*opt)) {
|
---|
636 | case IP6OPT_TYPE_SKIP: /* ç¡è¦ããã */
|
---|
637 | return *(opt + 1);
|
---|
638 | break;
|
---|
639 | case IP6OPT_TYPE_ICMP: /* ç ´æ£ãã¦ããã«ããã£ã¹ãã§ãªããã° ICMP ãè¿éããã */
|
---|
640 | if (IN6_IS_ADDR_MULTICAST(&GET_IP6_HDR(input)->dst))
|
---|
641 | return IP6_OPT_RET_ERR;
|
---|
642 | /* no break; */
|
---|
643 | case IP6OPT_TYPE_FORCEICMP: /* ç ´æ£ãã¦ãICMP ãè¿éããã */
|
---|
644 | icmp6_error(input, ICMP6_PARAM_PROB,
|
---|
645 | ICMP6_PARAMPROB_OPTION,
|
---|
646 | (opt - input->buf) - IF_HDR_SIZE);
|
---|
647 | return IP6_OPT_RET_REL;
|
---|
648 | break;
|
---|
649 | /*case IP6OPT_TYPE_DISCARD: ãã¼ã¿ã°ã©ã ãç ´æ£ããã */
|
---|
650 | }
|
---|
651 |
|
---|
652 | return IP6_OPT_RET_ERR;
|
---|
653 | }
|
---|
654 |
|
---|
655 | /*
|
---|
656 | * ip6_remove_exthdrs -- IPv6 æ¡å¼µããããåé¤ãã以éãåã«è©°ããã
|
---|
657 | */
|
---|
658 |
|
---|
659 | ER
|
---|
660 | ip6_remove_exthdrs (T_NET_BUF *nbuf)
|
---|
661 | {
|
---|
662 | ER_UINT off;
|
---|
663 | uint_t next;
|
---|
664 |
|
---|
665 | /* éå§ãªãã»ããã IP ãããã«è¨å®ããã*/
|
---|
666 | off = ((uint8_t *)GET_IP6_HDR(nbuf)) - nbuf->buf;
|
---|
667 |
|
---|
668 | /* æçµããããæ¢ç´¢ããã*/
|
---|
669 | off = ip6_lasthdr(nbuf, off, IPPROTO_IPV6, &next);
|
---|
670 |
|
---|
671 | if (off <= 0)
|
---|
672 | return E_OBJ;
|
---|
673 | else {
|
---|
674 | uint_t sdu;
|
---|
675 |
|
---|
676 | sdu = GET_IP6_SDU(nbuf) - nbuf->buf;
|
---|
677 | if (off > sdu) {
|
---|
678 | memmove(nbuf->buf + sdu, nbuf->buf + off, off - sdu);
|
---|
679 | GET_IP6_HDR(nbuf)->plen -= off - sdu;
|
---|
680 | nbuf->len -= off - sdu;
|
---|
681 | }
|
---|
682 | }
|
---|
683 | return E_OK;
|
---|
684 | }
|
---|
685 |
|
---|
686 | #endif /* of #ifdef _IP6_CFG */
|
---|