[270] | 1 | /*
|
---|
| 2 | * TINET (TCP/IP Protocol Stack)
|
---|
| 3 | *
|
---|
| 4 | * Copyright (C) 2001-2009 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 270 2017-02-09 04:03:47Z 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 |
|
---|
| 120 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
| 121 |
|
---|
| 122 | #ifdef TARGET_KERNEL_JSP
|
---|
| 123 |
|
---|
| 124 | #include <s_services.h>
|
---|
| 125 | #include <t_services.h>
|
---|
| 126 |
|
---|
| 127 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
| 128 |
|
---|
| 129 | #include <tinet_defs.h>
|
---|
| 130 | #include <tinet_config.h>
|
---|
| 131 |
|
---|
| 132 | #include <net/if.h>
|
---|
| 133 | #include <net/if_loop.h>
|
---|
| 134 | #include <net/if_ppp.h>
|
---|
| 135 | #include <net/ethernet.h>
|
---|
| 136 | #include <net/ppp_ipcp.h>
|
---|
| 137 | #include <net/net.h>
|
---|
| 138 | #include <net/net_buf.h>
|
---|
| 139 | #include <net/net_count.h>
|
---|
| 140 |
|
---|
| 141 | #include <netinet/in.h>
|
---|
| 142 | #include <netinet6/in6.h>
|
---|
| 143 | #include <netinet6/in6_var.h>
|
---|
| 144 | #include <netinet6/nd6.h>
|
---|
| 145 | #include <netinet/ip6.h>
|
---|
| 146 | #include <netinet6/ip6_var.h>
|
---|
| 147 | #include <netinet/icmp6.h>
|
---|
| 148 | #include <netinet6/ah6.h>
|
---|
| 149 | #include <netinet6/esp6.h>
|
---|
| 150 | #include <netinet/tcp.h>
|
---|
| 151 | #include <netinet/tcp_timer.h>
|
---|
| 152 | #include <netinet/tcp_var.h>
|
---|
| 153 | #include <netinet/udp_var.h>
|
---|
| 154 |
|
---|
| 155 | #include <net/if6_var.h>
|
---|
| 156 |
|
---|
| 157 | #ifdef SUPPORT_INET6
|
---|
| 158 |
|
---|
| 159 | /*
|
---|
| 160 | * é¢æ°
|
---|
| 161 | */
|
---|
| 162 |
|
---|
| 163 | static uint_t ip6_no_header_input (T_NET_BUF **inputp, uint_t *offp, uint_t *nextp);
|
---|
| 164 |
|
---|
| 165 | /*
|
---|
| 166 | * ä¸ä½ãããã³ã«é¸ææ§é ä½
|
---|
| 167 | */
|
---|
| 168 |
|
---|
| 169 | typedef struct t_proto_switch {
|
---|
| 170 | uint_t (*func)(T_NET_BUF **, uint_t *, uint_t *); /* å
|
---|
| 171 | ¥åé¢æ° */
|
---|
| 172 | uint_t proto; /* ãããã³ã«çªå· */
|
---|
| 173 | } T_PROTO_SWITCH;
|
---|
| 174 |
|
---|
| 175 | static const T_PROTO_SWITCH proto_switch[] = {
|
---|
| 176 | { esp6_input, IPPROTO_ESP }, /* IPv6 æå·åããã */
|
---|
| 177 | { ah6_input, IPPROTO_AH }, /* IPv6 èªè¨¼ããã */
|
---|
| 178 | { frag6_input, IPPROTO_FRAGMENT }, /* æçããã */
|
---|
| 179 | { route6_input, IPPROTO_ROUTING }, /* çµè·¯å¶å¾¡ããã */
|
---|
| 180 | { dest6_input, IPPROTO_DSTOPTS }, /* IPv6 çµç¹ãªãã·ã§ã³ */
|
---|
| 181 | { ip6_no_header_input,
|
---|
| 182 | IPPROTO_NONE }, /* 次ãããç¡ã */
|
---|
| 183 | { icmp6_input, IPPROTO_ICMPV6 },
|
---|
| 184 |
|
---|
| 185 | #ifdef SUPPORT_UDP
|
---|
| 186 |
|
---|
| 187 | { udp_input, IPPROTO_UDP },
|
---|
| 188 |
|
---|
| 189 | #endif /* of #ifdef SUPPORT_UDP */
|
---|
| 190 |
|
---|
| 191 | #ifdef SUPPORT_TCP
|
---|
| 192 |
|
---|
| 193 | { tcp_input, IPPROTO_TCP },
|
---|
| 194 |
|
---|
| 195 | #endif /* of #ifdef SUPPORT_TCP */
|
---|
| 196 |
|
---|
| 197 | };
|
---|
| 198 |
|
---|
| 199 | #ifdef SUPPORT_MIB
|
---|
| 200 |
|
---|
| 201 | T_IN6_IFSTAT in6_ifstat;
|
---|
| 202 |
|
---|
| 203 | #endif /* of #ifdef SUPPORT_MIB */
|
---|
| 204 |
|
---|
| 205 | /*
|
---|
| 206 | * get_upper_proto -- ä¸ä½ãããã³ã«å¦çé¢æ°ãè¿ãã
|
---|
| 207 | */
|
---|
| 208 |
|
---|
| 209 | static uint_t (*
|
---|
| 210 | get_upper_proto(uint_t proto))(T_NET_BUF **, uint_t *, uint_t *)
|
---|
| 211 | {
|
---|
| 212 | int_t ix;
|
---|
| 213 |
|
---|
| 214 | for (ix = sizeof(proto_switch) / sizeof(T_PROTO_SWITCH); ix -- > 0; )
|
---|
| 215 | if (proto_switch[ix].proto == proto)
|
---|
| 216 | return proto_switch[ix].func;
|
---|
| 217 | return NULL;
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | /*
|
---|
| 221 | * ip6_no_header_input -- 次ããããç¡ãã®å ´åã®å
|
---|
| 222 | ¥åå¦ç
|
---|
| 223 | */
|
---|
| 224 |
|
---|
| 225 | static uint_t
|
---|
| 226 | ip6_no_header_input (T_NET_BUF **input, uint_t *offp, uint_t *nextp)
|
---|
| 227 | {
|
---|
| 228 | syscall(rel_net_buf(*input));
|
---|
| 229 | return IPPROTO_DONE;
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | /*
|
---|
| 233 | * ip6_hopopts_input -- ä¸ç¶ç¹ãªãã·ã§ã³å
|
---|
| 234 | ¥åå¦ç
|
---|
| 235 | *
|
---|
| 236 | * æ¬å®è£
|
---|
| 237 | ã§ã¯ãããã£ã³ã°ä»¥å¤ã®ãªãã·ã§ã³ãå
|
---|
| 238 | ¨ã¦æªç¥ãªãã·ã§ã³ã¨ãã¦å¦çããã
|
---|
| 239 | *
|
---|
| 240 | * æ»ãå¤:
|
---|
| 241 | *
|
---|
| 242 | * 0 ä»¥ä¸ æ£å¸¸
|
---|
| 243 | * IP6_OPT_RET_ERR (-1) ã¨ã©ã¼ãå¼åºå´ã§ãããã¯ã¼ã¯ãããã¡ãéæ¾ããã
|
---|
| 244 | * IP6_OPT_RET_REL (-2) ã¨ã©ã¼ããããã¯ã¼ã¯ãããã¡ã¯éæ¾ããã¦ããã
|
---|
| 245 | */
|
---|
| 246 |
|
---|
| 247 | static ER_UINT
|
---|
| 248 | ip6_hopopts_input (T_NET_BUF *input, uint_t *offp, uint_t *nextp)
|
---|
| 249 | {
|
---|
| 250 | T_IP6_HBH_HDR *hbh;
|
---|
| 251 | ER_UINT optlen;
|
---|
| 252 | uint_t len;
|
---|
| 253 | uint8_t *opt;
|
---|
| 254 |
|
---|
| 255 | hbh = (T_IP6_HBH_HDR *)(input->buf + *offp);
|
---|
| 256 | len = (hbh->len + 1) << 3;
|
---|
| 257 | *nextp = *offp - IF_HDR_SIZE + offsetof(T_IP6_HBH_HDR, next);
|
---|
| 258 | *offp += len;
|
---|
| 259 | opt = (uint8_t *)hbh + sizeof(T_IP6_HBH_HDR);
|
---|
| 260 |
|
---|
| 261 | for (len -= sizeof(T_IP6_HBH_HDR); len > 0; len -= optlen) {
|
---|
| 262 | switch (*opt) {
|
---|
| 263 | case IP6OPT_PAD1:
|
---|
| 264 | optlen = 1;
|
---|
| 265 | break;
|
---|
| 266 | case IP6OPT_PADN:
|
---|
| 267 | if (len < IP6OPT_MINLEN)
|
---|
| 268 | return IP6_OPT_RET_ERR;
|
---|
| 269 | optlen = *(opt + 1) + 2;
|
---|
| 270 | break;
|
---|
| 271 | case IP6OPT_JUMBO:
|
---|
| 272 | case IP6OPT_NSAP_ADDR:
|
---|
| 273 | case IP6OPT_TUNNEL_LIMIT:
|
---|
| 274 | case IP6OPT_RTR_ALERT:
|
---|
| 275 | default:
|
---|
| 276 | if (len < IP6OPT_MINLEN)
|
---|
| 277 | return IP6_OPT_RET_ERR;
|
---|
| 278 | optlen = ip6_unknown_opt(input, opt);
|
---|
| 279 | if (optlen < 0)
|
---|
| 280 | return optlen;
|
---|
| 281 | optlen += 2;
|
---|
| 282 | break;
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 | opt += optlen;
|
---|
| 286 | }
|
---|
| 287 |
|
---|
| 288 | return *offp;
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | /*
|
---|
| 292 | * ip6_get_prev_hdr -- ç´åã®æ¡å¼µãããã® next ãã£ã¼ã«ãã®ã¢ãã¬ã¹ãè¿ãã
|
---|
| 293 | *
|
---|
| 294 | * 注æ: off ã«ã¯ IF_HDR_SIZE ãå«ã¾ãã¦ããã
|
---|
| 295 | */
|
---|
| 296 |
|
---|
| 297 | uint8_t *
|
---|
| 298 | ip6_get_prev_hdr (T_NET_BUF *nbuf, uint_t off)
|
---|
| 299 | {
|
---|
| 300 | T_IP6_HDR *ip6h;
|
---|
| 301 | T_IP6_EXT_HDR *ip6eh;
|
---|
| 302 | uint_t len;
|
---|
| 303 | uint8_t next;
|
---|
| 304 |
|
---|
| 305 | ip6h = GET_IP6_HDR(nbuf);
|
---|
| 306 | if (off == IF_HDR_SIZE + sizeof(T_IP6_HDR))
|
---|
| 307 | return &ip6h->next;
|
---|
| 308 | else {
|
---|
| 309 | next = ip6h->next;
|
---|
| 310 | len = IF_HDR_SIZE + sizeof(T_IP6_HDR);
|
---|
| 311 | ip6eh = NULL;
|
---|
| 312 |
|
---|
| 313 | while (len < off) {
|
---|
| 314 | ip6eh = (T_IP6_EXT_HDR *)(nbuf->buf + len);
|
---|
| 315 |
|
---|
| 316 | switch (next) {
|
---|
| 317 | case IPPROTO_FRAGMENT:
|
---|
| 318 | len += sizeof(T_IP6_FRAG_HDR);
|
---|
| 319 | break;
|
---|
| 320 | case IPPROTO_AH:
|
---|
| 321 | len += (ip6eh->len + 2) << 2;
|
---|
| 322 | break;
|
---|
| 323 | default:
|
---|
| 324 | len += (ip6eh->len + 2) << 3;
|
---|
| 325 | break;
|
---|
| 326 | }
|
---|
| 327 | next = ip6eh->next;
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 | if (ip6eh == NULL)
|
---|
| 331 | return NULL;
|
---|
| 332 | else
|
---|
| 333 | return &ip6eh->next;
|
---|
| 334 | }
|
---|
| 335 | }
|
---|
| 336 |
|
---|
| 337 | /*
|
---|
| 338 | * ip6_init -- IPv6 ã®åæåé¢æ°
|
---|
| 339 | */
|
---|
| 340 |
|
---|
| 341 | void
|
---|
| 342 | ip6_init (void)
|
---|
| 343 | {
|
---|
| 344 | in6_init();
|
---|
| 345 | in6_ifainit();
|
---|
| 346 | }
|
---|
| 347 |
|
---|
| 348 | /*
|
---|
| 349 | * ip6_input -- IPv6 ã®å
|
---|
| 350 | ¥åé¢æ°
|
---|
| 351 | */
|
---|
| 352 |
|
---|
| 353 | void
|
---|
| 354 | ip6_input (T_NET_BUF *input)
|
---|
| 355 | {
|
---|
| 356 | T_IP6_HDR *ip6h;
|
---|
| 357 | T_IN6_IFADDR *ia6;
|
---|
| 358 | T_IFNET *ifp;
|
---|
| 359 | ER_UINT noff;
|
---|
| 360 | uint_t next, nest, plen, offp, nextp;
|
---|
| 361 | uint_t (*func)(T_NET_BUF **, uint_t *, uint_t *);
|
---|
| 362 |
|
---|
| 363 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_OCTETS], input->len - IF_HDR_SIZE);
|
---|
| 364 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_PACKETS], 1);
|
---|
| 365 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInReceives, 1);
|
---|
| 366 |
|
---|
| 367 | /* IP ãããã®é·ãããã§ãã¯ããã*/
|
---|
| 368 | if (input->len < IF_IP6_HDR_SIZE) {
|
---|
| 369 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_SHORT], 1);
|
---|
| 370 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInHdrErrors, 1);
|
---|
| 371 | goto buf_rel;
|
---|
| 372 | }
|
---|
| 373 |
|
---|
| 374 | ip6h = GET_IP6_HDR(input);
|
---|
| 375 |
|
---|
| 376 | /* ãã¼ã¸ã§ã³ããã§ãã¯ããã*/
|
---|
| 377 | if (IP6_VCF_V(ntohl(ip6h->vcf)) != IPV6_VERSION) {
|
---|
| 378 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_VER], 1);
|
---|
| 379 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInHdrErrors, 1);
|
---|
| 380 | goto buf_rel;
|
---|
| 381 | }
|
---|
| 382 |
|
---|
| 383 | /*
|
---|
| 384 | * 次ã®ãã¼ã¿ã°ã©ã ã¯ç ´æ£ããã
|
---|
| 385 | *
|
---|
| 386 | * ã»å§ç¹ã¢ãã¬ã¹ããã«ããã£ã¹ã
|
---|
| 387 | * ã»çµç¹ã¢ãã¬ã¹ãæªå®ç¾©
|
---|
| 388 | *
|
---|
| 389 | * ãããã¯ã¼ã¯ã¤ã³ã¿ãã§ã¼ã¹ãã«ã¼ãããã¯ã§ãªãã¨ãã
|
---|
| 390 | * 次ã®ãã¼ã¿ã°ã©ã ãç ´æ£ããã
|
---|
| 391 | *
|
---|
| 392 | * ã»å§ç¹ã¢ãã¬ã¹ãã«ã¼ãããã¯
|
---|
| 393 | * ã»çµç¹ã¢ãã¬ã¹ãã«ã¼ãããã¯
|
---|
| 394 | *
|
---|
| 395 | * æªæã®ããã¦ã¼ã¶ã TCP/UDP ã¹ã¿ãã¯ã®æ··ä¹±ã
|
---|
| 396 | * ã»ãã¥ãªãã£ãã§ãã¯ããã¤ãã¹ãããããIPv4
|
---|
| 397 | * ãããã¢ãã¬ã¹ãæªç¨ãããã¨ãé²ããã
|
---|
| 398 | * 以ä¸ã®ãã¼ã¿ã°ã©ã ã¯ç ´æ£ããã
|
---|
| 399 | *
|
---|
| 400 | * ã»å§ç¹ã¢ãã¬ã¹ã ::ffff:127.0.0.1
|
---|
| 401 | * ã»çµç¹ã¢ãã¬ã¹ã ::ffff:127.0.0.1
|
---|
| 402 | */
|
---|
| 403 |
|
---|
| 404 | if (IN6_IS_ADDR_MULTICAST(&ip6h->src) ||
|
---|
| 405 | IN6_IS_ADDR_UNSPECIFIED(&ip6h->dst)) {
|
---|
| 406 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_ADDR], 1);
|
---|
| 407 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInAddrErrors, 1);
|
---|
| 408 | goto buf_rel;
|
---|
| 409 | }
|
---|
| 410 |
|
---|
| 411 | if (IN6_IS_ADDR_V4MAPPED(&ip6h->src) ||
|
---|
| 412 | IN6_IS_ADDR_V4MAPPED(&ip6h->dst)) {
|
---|
| 413 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_ADDR], 1);
|
---|
| 414 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInAddrErrors, 1);
|
---|
| 415 | goto buf_rel;
|
---|
| 416 | }
|
---|
| 417 |
|
---|
| 418 | #ifdef SUPPORT_LOOP
|
---|
| 419 |
|
---|
| 420 | #else /* of #ifdef SUPPORT_LOOP */
|
---|
| 421 |
|
---|
| 422 | if (IN6_IS_ADDR_LOOPBACK(&ip6h->src) ||
|
---|
| 423 | IN6_IS_ADDR_LOOPBACK(&ip6h->dst)) {
|
---|
| 424 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_ADDR], 1);
|
---|
| 425 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInAddrErrors, 1);
|
---|
| 426 | goto buf_rel;
|
---|
| 427 | }
|
---|
| 428 |
|
---|
| 429 | #endif /* of #ifdef SUPPORT_LOOP */
|
---|
| 430 |
|
---|
| 431 | ifp = IF_GET_IFNET();
|
---|
| 432 |
|
---|
| 433 | if (IN6_IS_ADDR_MULTICAST(&ip6h->dst)) {
|
---|
| 434 | /* å®å
|
---|
| 435 | ããã«ããã£ã¹ãã®å ´åã®å¦ç */
|
---|
| 436 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInMcastPkts, 1);
|
---|
| 437 | if (!in6_lookup_multi(ifp, &ip6h->dst)) {
|
---|
| 438 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_ADDR], 1);
|
---|
| 439 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInAddrErrors, 1);
|
---|
| 440 | goto buf_rel;
|
---|
| 441 | }
|
---|
| 442 | }
|
---|
| 443 | else {
|
---|
| 444 | if ((ia6 = in6_lookup_ifaddr(ifp, &ip6h->dst)) == NULL) {
|
---|
| 445 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_ADDR], 1);
|
---|
| 446 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInAddrErrors, 1);
|
---|
| 447 | goto buf_rel;
|
---|
| 448 | }
|
---|
| 449 |
|
---|
| 450 | /* ã¢ãã¬ã¹ãæªè§£æ±ºã®å ´åã¯ãã¼ã¿ã°ã©ã ãç ´æ£ããã*/
|
---|
| 451 | if (IFA6_IS_NOTREADY(ia6)) {
|
---|
| 452 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_ADDR], 1);
|
---|
| 453 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInAddrErrors, 1);
|
---|
| 454 | goto buf_rel;
|
---|
| 455 | }
|
---|
| 456 | }
|
---|
| 457 |
|
---|
| 458 | /* ãªãã»ãããè¨å®ããã*/
|
---|
| 459 | offp = GET_IP6_NEXT_HDR(input) - input->buf;
|
---|
| 460 |
|
---|
| 461 | /* ãã¤ãã¼ãé·ãåãåºãã*/
|
---|
| 462 | plen = ntohs(ip6h->plen);
|
---|
| 463 |
|
---|
| 464 |
|
---|
| 465 | /* 次ãããã®ä½ç½®ãåæåããã*/
|
---|
| 466 | nextp = offsetof(T_IP6_HDR, next);
|
---|
| 467 |
|
---|
| 468 | /*
|
---|
| 469 | * ä¸ç¶ç¹ (Hop-by-Hop) ãªãã·ã§ã³ãããã®ãã§ãã¯
|
---|
| 470 | */
|
---|
| 471 | if (ip6h->next == IPPROTO_HOPOPTS) {
|
---|
| 472 |
|
---|
| 473 | /* ä¸ç¶ç¹ãããã®é·ãããã§ãã¯ããã*/
|
---|
| 474 | if (plen < sizeof(T_IP6_HBH_HDR)) {
|
---|
| 475 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_SHORT], 1);
|
---|
| 476 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInHdrErrors, 1);
|
---|
| 477 | goto buf_rel;
|
---|
| 478 | }
|
---|
| 479 |
|
---|
| 480 | if ((noff = ip6_hopopts_input(input, &offp, &nextp)) < 0) {
|
---|
| 481 | if (noff == IP6_OPT_RET_ERR) {
|
---|
| 482 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_PACKETS], 1);
|
---|
| 483 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInHdrErrors, 1);
|
---|
| 484 | goto buf_rel;
|
---|
| 485 | }
|
---|
| 486 | else if (noff == IP6_OPT_RET_REL) {
|
---|
| 487 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_PACKETS], 1);
|
---|
| 488 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInHdrErrors, 1);
|
---|
| 489 | return;
|
---|
| 490 | }
|
---|
| 491 | }
|
---|
| 492 |
|
---|
| 493 | /*
|
---|
| 494 | * ãã¤ãã¼ãé·ã 0 ã§ãä¸ç¶ç¹ãªãã·ã§ã³ãããã¨ãã¯ã
|
---|
| 495 | * 巨大ãã¤ãã¼ãã»ãªãã·ã§ã³ãå«ã¾ããªããã°ãªããªãã
|
---|
| 496 | * ãã®ã¨ãã巨大ãã¤ãã¼ãã»ãªãã·ã§ã³ã«ãã
|
---|
| 497 | * ãã¤ãã¼ãé·ããã§ãã¯ããå¿
|
---|
| 498 | è¦ãããããæ¬å®è£
|
---|
| 499 | ã§ã¯ã
|
---|
| 500 | * 巨大ãã¤ãã¼ãã»ãªãã·ã§ã³ãæªç¥ã®ãªãã·ã§ã³ã¨ãã¦
|
---|
| 501 | * æ±ãã®ã§ãä½ãããªãã
|
---|
| 502 | */
|
---|
| 503 | next = ((T_IP6_HBH_HDR *)(ip6h + 1))->next;
|
---|
| 504 | }
|
---|
| 505 | else
|
---|
| 506 | next = ip6h->next;
|
---|
| 507 |
|
---|
| 508 | /* IPv6 ãã¼ã¿ã°ã©ã é·ããã§ãã¯ããã*/
|
---|
| 509 | if (input->len - IF_IP6_HDR_SIZE < plen) {
|
---|
| 510 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_SHORT], 1);
|
---|
| 511 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInTruncatedPkts, 1);
|
---|
| 512 | goto buf_rel;
|
---|
| 513 | }
|
---|
| 514 | else if (input->len > IF_IP6_HDR_SIZE + plen)
|
---|
| 515 | input->len = IF_IP6_HDR_SIZE + plen;
|
---|
| 516 |
|
---|
| 517 | /* ä¸ä½ãããã³ã«å¦çé¢æ°ãå¼ã³åºãã*/
|
---|
| 518 | nest = 0;
|
---|
| 519 | while (next != IPPROTO_DONE) {
|
---|
| 520 | if (++ nest > IP6_HDR_NEST_LIMIT) {
|
---|
| 521 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_PROTO], 1);
|
---|
| 522 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInUnknownProtos, 1);
|
---|
| 523 | goto buf_rel;
|
---|
| 524 | }
|
---|
| 525 | else if ((func = get_upper_proto(next)) == NULL) {
|
---|
| 526 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_PROTO], 1);
|
---|
| 527 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_PACKETS], 1);
|
---|
| 528 | NET_COUNT_MIB(in6_ifstat.ipv6IfStatsInUnknownProtos, 1);
|
---|
| 529 |
|
---|
| 530 | /* icmp6_error ã§ãããã¯ã¼ã¯ãããã¡ãéæ¾ããã*/
|
---|
| 531 | icmp6_error(input, ICMP6_PARAM_PROB,
|
---|
| 532 | ICMP6_PARAMPROB_NEXT_HEADER, nextp);
|
---|
| 533 | return;
|
---|
| 534 | }
|
---|
| 535 | else {
|
---|
| 536 | next = (*func)(&input, &offp, &nextp);
|
---|
| 537 | }
|
---|
| 538 | }
|
---|
| 539 | return;
|
---|
| 540 |
|
---|
| 541 | buf_rel:
|
---|
| 542 | NET_COUNT_IP6(net_count_ip6[NC_IP6_IN_ERR_PACKETS], 1);
|
---|
| 543 | syscall(rel_net_buf(input));
|
---|
| 544 | }
|
---|
| 545 |
|
---|
| 546 | /*
|
---|
| 547 | * ip6_nexthdr -- 次ã®ãããã®ãªãã»ãããè¿ãã
|
---|
| 548 | *
|
---|
| 549 | * æ»ãå¤ == -1 : æå¾ã®ããããã¾ãã¯ã¨ã©ã¼ã
|
---|
| 550 | * æ»ãå¤ > 0 : ããã«ããããç¶ãã
|
---|
| 551 | */
|
---|
| 552 |
|
---|
| 553 | ER_UINT
|
---|
| 554 | ip6_nexthdr (T_NET_BUF *nbuf, uint_t off, uint_t proto, uint_t *nextp)
|
---|
| 555 | {
|
---|
| 556 | T_IP6_FRAG_HDR *ip6fh;
|
---|
| 557 | T_IP6_EXT_HDR *ip6eh;
|
---|
| 558 |
|
---|
| 559 | switch (proto) {
|
---|
| 560 |
|
---|
| 561 | case IPPROTO_IPV6: /* IPv6 */
|
---|
| 562 | if (nbuf->len < off + IP6_HDR_SIZE)
|
---|
| 563 | return (ER_UINT)-1;
|
---|
| 564 | *nextp = ((T_IP6_HDR *)(nbuf->buf + off))->next;
|
---|
| 565 | return off + IP6_HDR_SIZE;
|
---|
| 566 | break;
|
---|
| 567 |
|
---|
| 568 | case IPPROTO_FRAGMENT: /* æçããã */
|
---|
| 569 | if (nbuf->len < off + sizeof(T_IP6_FRAG_HDR))
|
---|
| 570 | return (ER_UINT)-1;
|
---|
| 571 |
|
---|
| 572 | /* ä¸éã®ãã©ã°ã¡ã³ãã®å ´åã¯å¦çããããã*/
|
---|
| 573 | ip6fh = (T_IP6_FRAG_HDR *)(nbuf->buf + off);
|
---|
| 574 | if (ntohs(ip6fh->off_flag) & IP6F_MORE_FRAG)
|
---|
| 575 | return (ER_UINT)-1;
|
---|
| 576 |
|
---|
| 577 | *nextp = ip6fh->next;
|
---|
| 578 | return off + sizeof(T_IP6_FRAG_HDR);
|
---|
| 579 | break;
|
---|
| 580 |
|
---|
| 581 | case IPPROTO_AH: /* IPv6 èªè¨¼ããã */
|
---|
| 582 | case IPPROTO_HOPOPTS: /* IPv6 ä¸ç¶ç¹ (Hop-by-Hop) ãªãã·ã§ã³ */
|
---|
| 583 | case IPPROTO_ROUTING: /* çµè·¯å¶å¾¡ããã */
|
---|
| 584 | case IPPROTO_DSTOPTS: /* IPv6 çµç¹ãªãã·ã§ã³ */
|
---|
| 585 | if (nbuf->len < off + sizeof(T_IP6_EXT_HDR))
|
---|
| 586 | return (ER_UINT)-1;
|
---|
| 587 |
|
---|
| 588 | ip6eh = (T_IP6_EXT_HDR *)(nbuf->buf + off);
|
---|
| 589 | *nextp = ip6eh->next;
|
---|
| 590 | if (proto == IPPROTO_AH)
|
---|
| 591 | return off + ((ip6eh->len + 2) << 2);
|
---|
| 592 | else
|
---|
| 593 | return off + ((ip6eh->len + 1) << 3);
|
---|
| 594 | break;
|
---|
| 595 | }
|
---|
| 596 |
|
---|
| 597 | return (ER_UINT)-1;
|
---|
| 598 | }
|
---|
| 599 |
|
---|
| 600 | /*
|
---|
| 601 | * ip6_lasthdr -- æå¾ã®ãããã®ãªãã»ãããè¿ãã
|
---|
| 602 | */
|
---|
| 603 |
|
---|
| 604 | ER_UINT
|
---|
| 605 | ip6_lasthdr (T_NET_BUF *nbuf, uint_t off, uint_t proto, uint_t *nextp)
|
---|
| 606 | {
|
---|
| 607 | ER_UINT newoff;
|
---|
| 608 |
|
---|
| 609 | while (1) {
|
---|
| 610 | newoff = ip6_nexthdr(nbuf, off, proto, nextp);
|
---|
| 611 | if (newoff < 0)
|
---|
| 612 | return (ER_UINT)off;
|
---|
| 613 | off = newoff;
|
---|
| 614 | proto = *nextp;
|
---|
| 615 | }
|
---|
| 616 | return (ER_UINT)0u;
|
---|
| 617 | }
|
---|
| 618 |
|
---|
| 619 | /*
|
---|
| 620 | * ip6_unknown_opt -- æªç¥ã®ãªãã·ã§ã³ã®å¦ç
|
---|
| 621 | *
|
---|
| 622 | * æ»ãå¤:
|
---|
| 623 | *
|
---|
| 624 | * 0 ä»¥ä¸ æ£å¸¸ããªãã·ã§ã³é·ã
|
---|
| 625 | * IP6_OPT_RET_ERR (-1) ã¨ã©ã¼ãå¼åºå´ã§ãããã¯ã¼ã¯ãããã¡ãéæ¾ããã
|
---|
| 626 | * IP6_OPT_RET_REL (-2) ã¨ã©ã¼ããããã¯ã¼ã¯ãããã¡ã¯éæ¾ããã¦ããã
|
---|
| 627 | */
|
---|
| 628 |
|
---|
| 629 | ER_UINT
|
---|
| 630 | ip6_unknown_opt (T_NET_BUF *input, uint8_t *opt)
|
---|
| 631 | {
|
---|
| 632 | switch (IP6OPT_TYPE(*opt)) {
|
---|
| 633 | case IP6OPT_TYPE_SKIP: /* ç¡è¦ããã */
|
---|
| 634 | return *(opt + 1);
|
---|
| 635 | break;
|
---|
| 636 | case IP6OPT_TYPE_ICMP: /* ç ´æ£ãã¦ããã«ããã£ã¹ãã§ãªããã° ICMP ãè¿éããã */
|
---|
| 637 | if (IN6_IS_ADDR_MULTICAST(&GET_IP6_HDR(input)->dst))
|
---|
| 638 | return IP6_OPT_RET_ERR;
|
---|
| 639 | /* no break; */
|
---|
| 640 | case IP6OPT_TYPE_FORCEICMP: /* ç ´æ£ãã¦ãICMP ãè¿éããã */
|
---|
| 641 | icmp6_error(input, ICMP6_PARAM_PROB,
|
---|
| 642 | ICMP6_PARAMPROB_OPTION,
|
---|
| 643 | (opt - input->buf) - IF_HDR_SIZE);
|
---|
| 644 | return IP6_OPT_RET_REL;
|
---|
| 645 | break;
|
---|
| 646 | /*case IP6OPT_TYPE_DISCARD: ãã¼ã¿ã°ã©ã ãç ´æ£ããã */
|
---|
| 647 | }
|
---|
| 648 |
|
---|
| 649 | return IP6_OPT_RET_ERR;
|
---|
| 650 | }
|
---|
| 651 |
|
---|
| 652 | /*
|
---|
| 653 | * ip6_remove_exthdrs -- IPv6 æ¡å¼µããããåé¤ãã以éãåã«è©°ããã
|
---|
| 654 | */
|
---|
| 655 |
|
---|
| 656 | ER
|
---|
| 657 | ip6_remove_exthdrs (T_NET_BUF *nbuf)
|
---|
| 658 | {
|
---|
| 659 | ER_UINT off;
|
---|
| 660 | uint_t next;
|
---|
| 661 |
|
---|
| 662 | /* éå§ãªãã»ããã IP ãããã«è¨å®ããã*/
|
---|
| 663 | off = ((uint8_t *)GET_IP_HDR(nbuf)) - nbuf->buf;
|
---|
| 664 |
|
---|
| 665 | /* æçµããããæ¢ç´¢ããã*/
|
---|
| 666 | off = ip6_lasthdr(nbuf, off, IPPROTO_IPV6, &next);
|
---|
| 667 |
|
---|
| 668 | if (off <= 0)
|
---|
| 669 | return E_OBJ;
|
---|
| 670 | else {
|
---|
| 671 | uint_t sdu;
|
---|
| 672 |
|
---|
| 673 | sdu = GET_IP_SDU(nbuf) - nbuf->buf;
|
---|
| 674 | if (off > sdu) {
|
---|
| 675 | memmove(nbuf->buf + sdu, nbuf->buf + off, off - sdu);
|
---|
| 676 | GET_IP_HDR(nbuf)->plen -= off - sdu;
|
---|
| 677 | nbuf->len -= off - sdu;
|
---|
| 678 | }
|
---|
| 679 | }
|
---|
| 680 | return E_OK;
|
---|
| 681 | }
|
---|
| 682 |
|
---|
| 683 | #endif /* of #ifdef SUPPORT_INET6 */
|
---|