[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: frag6.c 270 2017-02-09 04:03:47Z coas-nagasima $
|
---|
| 44 | */
|
---|
| 45 |
|
---|
| 46 | /* $FreeBSD: src/sys/netinet6/frag6.c,v 1.9 2002/04/19 04:46:22 suz Exp $ */
|
---|
| 47 | /* $KAME: frag6.c,v 1.33 2002/01/07 11:34:48 kjc 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 | #include <string.h>
|
---|
| 79 |
|
---|
| 80 | #ifdef TARGET_KERNEL_ASP
|
---|
| 81 |
|
---|
| 82 | #include <kernel.h>
|
---|
| 83 | #include <sil.h>
|
---|
| 84 | #include "kernel_cfg.h"
|
---|
| 85 |
|
---|
| 86 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
| 87 |
|
---|
| 88 | #ifdef TARGET_KERNEL_JSP
|
---|
| 89 |
|
---|
| 90 | #include <s_services.h>
|
---|
| 91 | #include <t_services.h>
|
---|
| 92 | #include "kernel_id.h"
|
---|
| 93 |
|
---|
| 94 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
| 95 |
|
---|
| 96 | #include <tinet_defs.h>
|
---|
| 97 | #include <tinet_config.h>
|
---|
| 98 |
|
---|
| 99 | #include <net/if.h>
|
---|
| 100 | #include <net/if_loop.h>
|
---|
| 101 | #include <net/if_ppp.h>
|
---|
| 102 | #include <net/ethernet.h>
|
---|
| 103 | #include <net/if_arp.h>
|
---|
| 104 | #include <net/ppp_ipcp.h>
|
---|
| 105 | #include <net/net.h>
|
---|
| 106 | #include <net/net_buf.h>
|
---|
| 107 | #include <net/net_var.h>
|
---|
| 108 | #include <net/net_count.h>
|
---|
| 109 |
|
---|
| 110 | #include <netinet/in.h>
|
---|
| 111 | #include <netinet6/in6.h>
|
---|
| 112 | #include <netinet6/in6_var.h>
|
---|
| 113 | #include <netinet6/nd6.h>
|
---|
| 114 | #include <netinet/ip6.h>
|
---|
| 115 | #include <netinet6/ip6_var.h>
|
---|
| 116 | #include <netinet/icmp6.h>
|
---|
| 117 |
|
---|
| 118 | #ifdef SUPPORT_INET6
|
---|
| 119 |
|
---|
| 120 | #ifdef IP6_CFG_FRAGMENT
|
---|
| 121 |
|
---|
| 122 | /*
|
---|
| 123 | * ãã¼ã¿ã°ã©ã åæ§æãã¥ã¼é
|
---|
| 124 | å
|
---|
| 125 | */
|
---|
| 126 |
|
---|
| 127 | static T_NET_BUF *ip6_frag_queue[NUM_IP6_FRAG_QUEUE];
|
---|
| 128 | static T_IN6_ADDR ip6_frag_dest [NUM_IP6_FRAG_QUEUE];
|
---|
| 129 |
|
---|
| 130 | /*
|
---|
| 131 | * ip6_get_frag_queue -- ãã¼ã¿ã°ã©ã åæ§æãã¥ã¼ãç²å¾ããã
|
---|
| 132 | */
|
---|
| 133 |
|
---|
| 134 | const T_NET_BUF **
|
---|
| 135 | ip6_get_frag_queue (void)
|
---|
| 136 | {
|
---|
| 137 | return (const T_NET_BUF **)ip6_frag_queue;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | /*
|
---|
| 141 | * frag6_free_queue -- ãã¼ã¿ã°ã©ã åæ§æãã¥ã¼ã解æ¾ããã
|
---|
| 142 | *
|
---|
| 143 | * 注æ: ãã¼ã¿ã°ã©ã åæ§æãã¥ã¼é
|
---|
| 144 | åãããã¯ãã¦ããå¼ã³åºããã¨ã
|
---|
| 145 | */
|
---|
| 146 |
|
---|
| 147 | static void
|
---|
| 148 | frag6_free_queue (T_NET_BUF **queue)
|
---|
| 149 | {
|
---|
| 150 | T_NET_BUF *frag, *next;
|
---|
| 151 | T_QIP6_HDR *qip6h;
|
---|
| 152 |
|
---|
| 153 | frag = *queue;
|
---|
| 154 | while (frag != NULL) {
|
---|
| 155 | qip6h = GET_QIP6_HDR(frag);
|
---|
| 156 | next = qip6h->next_frag;
|
---|
| 157 | syscall(rel_net_buf(frag));
|
---|
| 158 | frag = next;
|
---|
| 159 | }
|
---|
| 160 | *queue = NULL;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | /*
|
---|
| 164 | * frag6_timer -- ãã¼ã¿ã°ã©ã åæ§æ管çã¿ã¤ã
|
---|
| 165 | */
|
---|
| 166 |
|
---|
| 167 | void
|
---|
| 168 | frag6_timer (void)
|
---|
| 169 | {
|
---|
| 170 | T_NET_BUF *frag;
|
---|
| 171 | T_QIP6_HDR *qip6h;
|
---|
| 172 | T_IP6_FRAG_HDR *qip6fh;
|
---|
| 173 | int_t ix;
|
---|
| 174 |
|
---|
| 175 | syscall(wai_sem(SEM_IP6_FRAG_QUEUE));
|
---|
| 176 | for (ix = NUM_IP6_FRAG_QUEUE; ix -- > 0; ) {
|
---|
| 177 | frag = ip6_frag_queue[ix];
|
---|
| 178 | if (frag != NULL) {
|
---|
| 179 | qip6h = GET_QIP6_HDR(frag);
|
---|
| 180 | if (qip6h->ftim > 0 && -- qip6h->ftim == 0) {
|
---|
| 181 |
|
---|
| 182 | qip6fh = (T_IP6_FRAG_HDR *)(frag->buf + qip6h->foff);
|
---|
| 183 | if (ntohs(qip6fh->off_flag & IP6F_OFF_MASK) == 0) {
|
---|
| 184 |
|
---|
| 185 | /*
|
---|
| 186 | * å
|
---|
| 187 | é ã®æçã®ãªãã»ããã 0 ã®æã®ã¿
|
---|
| 188 | * ICMPv6 ã¨ã©ã¼ã¡ãã»ã¼ã¸ãéä¿¡ããã
|
---|
| 189 | */
|
---|
| 190 |
|
---|
| 191 | /* å
|
---|
| 192 | é ã®æçããã¼ã¿ã°ã©ã åæ§æãã¥ã¼ããå¤ãã*/
|
---|
| 193 | ip6_frag_queue[ix] = qip6h->next_frag;
|
---|
| 194 |
|
---|
| 195 | /* ãã¦å
|
---|
| 196 | ã¢ãã¬ã¹ãå
|
---|
| 197 | ã«æ»ãã*/
|
---|
| 198 | GET_IP6_HDR(frag)->dst = ip6_frag_dest[ix];
|
---|
| 199 |
|
---|
| 200 | /* ICMPv6 ã¨ã©ã¼ã¡ãã»ã¼ã¸ãéä¿¡ããã*/
|
---|
| 201 | icmp6_error(frag, ICMP6_TIME_EXCEEDED,
|
---|
| 202 | ICMP6_TIME_EXCEED_REASSEMBLY, 0);
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | /* ãã¼ã¿ã°ã©ã åæ§æãã¥ã¼ã解æ¾ããã*/
|
---|
| 206 | NET_COUNT_IP6(net_count_ip6[NC_IP6_FRAG_IN_TMOUT], 1);
|
---|
| 207 | NET_COUNT_IP6(net_count_ip6[NC_IP6_FRAG_IN_DROP], 1);
|
---|
| 208 | frag6_free_queue(&ip6_frag_queue[ix]);
|
---|
| 209 | }
|
---|
| 210 | }
|
---|
| 211 | }
|
---|
| 212 | syscall(sig_sem(SEM_IP6_FRAG_QUEUE));
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | #endif /* #ifdef IP6_CFG_FRAGMENT */
|
---|
| 216 |
|
---|
| 217 | /*
|
---|
| 218 | * frag6_input -- æçãããã®å
|
---|
| 219 | ¥åé¢æ°
|
---|
| 220 | */
|
---|
| 221 |
|
---|
| 222 | uint_t
|
---|
| 223 | frag6_input (T_NET_BUF **inputp, uint_t *offp, uint_t *nextp)
|
---|
| 224 | {
|
---|
| 225 | T_IP6_HDR *ip6h;
|
---|
| 226 | T_IP6_FRAG_HDR *ip6fh;
|
---|
| 227 | T_NET_BUF *input = *inputp;
|
---|
| 228 | uint_t off = *offp;
|
---|
| 229 |
|
---|
| 230 | #ifdef IP6_CFG_FRAGMENT
|
---|
| 231 |
|
---|
| 232 | T_QIP6_HDR *qip6h, *rip6h;
|
---|
| 233 | T_IP6_FRAG_HDR *qip6fh = NULL;
|
---|
| 234 | T_NET_BUF **ip6fq = NULL, *prev, *next, *frag;
|
---|
| 235 | int_t ix;
|
---|
| 236 | int32_t unfraglen, diff;
|
---|
| 237 | uint16_t fragpartlen, qfragpartlen, fragoff, qfragoff, plen;
|
---|
| 238 | uint8_t ftim, *prev_next;
|
---|
| 239 | uint_t nextproto = IPPROTO_DONE;
|
---|
| 240 |
|
---|
| 241 | #endif /* #ifdef IP6_CFG_FRAGMENT */
|
---|
| 242 |
|
---|
| 243 | /* ãããã¯ã¼ã¯ãããã¡ã®æ®ãã®é·ãããã§ãã¯ããã*/
|
---|
| 244 | if (input->len - off < sizeof(T_IP6_FRAG_HDR))
|
---|
| 245 | goto buf_rel;
|
---|
| 246 |
|
---|
| 247 | /*
|
---|
| 248 | * 巨大ãã¤ãã¼ããªãã·ã§ã³ã¨æçããããåæã«ä½¿ç¨ãããã¨ã¯
|
---|
| 249 | * ã§ããªãããã¤ãã¼ãé·ãã 0 ãªãã巨大ãã¤ãã¼ããªãã·ã§ã³ã
|
---|
| 250 | * æå®ããã¦ãããã¨ã«ãªãã®ã§ ICMP ã§ã¨ã©ã¼ãéä¿¡è
|
---|
| 251 | ã«
|
---|
| 252 | * éç¥ããã
|
---|
| 253 | */
|
---|
| 254 | ip6h = GET_IP6_HDR(input);
|
---|
| 255 | if (ip6h->plen == 0) {
|
---|
| 256 | icmp6_error(input, ICMP6_PARAM_PROB,
|
---|
| 257 | ICMP6_PARAMPROB_HEADER,
|
---|
| 258 | off - IF_HDR_SIZE);
|
---|
| 259 | NET_COUNT_MIB(in6_stats.ipv6IfStatsReasmFails, 1);
|
---|
| 260 | return IPPROTO_DONE;
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 | /*
|
---|
| 264 | * ãªãã»ããã 0 ã§ãæçµãã©ã°ã¡ã³ãã§ããã°ã
|
---|
| 265 | * åå²ä¸è¦ã®ãã¼ã¿ã°ã©ã ãªã®ã§ã
|
---|
| 266 | * 次ããããæãå¤æ°ã調æ´ãã¦çµäºããã
|
---|
| 267 | */
|
---|
| 268 | ip6fh = (T_IP6_FRAG_HDR *)(input->buf + off);
|
---|
| 269 | if (ip6fh->off_flag == 0) {
|
---|
| 270 | *nextp = *offp - IF_HDR_SIZE + offsetof(T_IP6_FRAG_HDR, next);
|
---|
| 271 | *offp = off + sizeof(T_IP6_FRAG_HDR);
|
---|
| 272 | return ip6fh->next;
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | #ifdef IP6_CFG_FRAGMENT
|
---|
| 276 |
|
---|
| 277 | /*
|
---|
| 278 | * ãã¤ãã¼ãé·ããã§ãã¯ããã
|
---|
| 279 | */
|
---|
| 280 | if ((ip6fh->off_flag & IP6F_MORE_FRAG) &&
|
---|
| 281 | ((ntohs(ip6h->plen) - (off - IF_HDR_SIZE)) & 0x7) != 0) {
|
---|
| 282 | icmp6_error(input, ICMP6_PARAM_PROB,
|
---|
| 283 | ICMP6_PARAMPROB_HEADER,
|
---|
| 284 | offsetof(T_IP6_HDR, plen));
|
---|
| 285 | NET_COUNT_MIB(in6_stats.ipv6IfStatsReasmFails, 1);
|
---|
| 286 | return nextproto;
|
---|
| 287 | }
|
---|
| 288 | NET_COUNT_MIB(in6_stats.ipv6IfStatsReasmReqds, 1);
|
---|
| 289 |
|
---|
| 290 | syscall(wai_sem(SEM_IP6_FRAG_QUEUE));
|
---|
| 291 |
|
---|
| 292 | /*
|
---|
| 293 | * ãã¼ã¿ã°ã©ã åæ§æãã¥ã¼é
|
---|
| 294 | åããã対å¿ããã¨ã³ããªãæ¢ãã
|
---|
| 295 | */
|
---|
| 296 | for (ix = NUM_IP6_FRAG_QUEUE; ix -- > 0; ) {
|
---|
| 297 | if (ip6_frag_queue[ix] != NULL) {
|
---|
| 298 | qip6h = GET_QIP6_HDR(ip6_frag_queue[ix]);
|
---|
| 299 | qip6fh = (T_IP6_FRAG_HDR *)(ip6_frag_queue[ix]->buf + qip6h->foff);
|
---|
| 300 | if (ip6fh->ident == qip6fh->ident &&
|
---|
| 301 | IN6_ARE_ADDR_EQUAL(&ip6h->src, &qip6h->src) &&
|
---|
| 302 | IN6_ARE_ADDR_EQUAL(&ip6h->dst, &ip6_frag_dest[ix])) {
|
---|
| 303 | ip6fq = &ip6_frag_queue[ix];
|
---|
| 304 | break;
|
---|
| 305 | }
|
---|
| 306 | }
|
---|
| 307 | }
|
---|
| 308 |
|
---|
| 309 | if (ip6fq == NULL) {
|
---|
| 310 |
|
---|
| 311 | /*
|
---|
| 312 | * æçã®æ£å½æ§ããã§ãã¯ããã
|
---|
| 313 | */
|
---|
| 314 | unfraglen = 0;
|
---|
| 315 | fragoff = ntohs(ip6fh->off_flag & IP6F_OFF_MASK);
|
---|
| 316 | if (fragoff == 0) {
|
---|
| 317 |
|
---|
| 318 | /*
|
---|
| 319 | * å
|
---|
| 320 | ¥åããæçãå
|
---|
| 321 | é ã®æç
|
---|
| 322 | * åå²ã§ããªãé¨åã®é·ã unfraglen ãè¨ç®ããã
|
---|
| 323 | */
|
---|
| 324 | unfraglen = (off - IF_HDR_SIZE) - sizeof(T_IP6_HDR);
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | /*
|
---|
| 328 | * off
|
---|
| 329 | * |<--------------------------->|
|
---|
| 330 | * | off - IF_HDR_SIZE |
|
---|
| 331 | * | |<------------------>|
|
---|
| 332 | * | | off - IF_HDR_SIZE + IP6_FRAG_HDR_SIZE |
|
---|
| 333 | * | |<------------------------------------->|
|
---|
| 334 | * +--------+----------+---------+------------------+-------------+
|
---|
| 335 | * | IF HDR | IPv6 HDR | EXT HDR | FRAG HDR | Payload |
|
---|
| 336 | * +--------+----------+---------+------------------+-------------+
|
---|
| 337 | * |<---------------------------------------->|
|
---|
| 338 | * | Payload Size |
|
---|
| 339 | * |<--------------------------------------------------->|
|
---|
| 340 | * | IP6_HDR_SIZE + Payload Size |
|
---|
| 341 | * |<----------->|
|
---|
| 342 | * | fragpartlen |
|
---|
| 343 | */
|
---|
| 344 | fragpartlen = sizeof(T_IP6_HDR) + ntohs(ip6h->plen) - (off - IF_HDR_SIZE + sizeof(T_IP6_FRAG_HDR));
|
---|
| 345 | if (unfraglen + fragoff + fragpartlen > IPV6_MAXPACKET) {
|
---|
| 346 | icmp6_error(input, ICMP6_PARAM_PROB,
|
---|
| 347 | ICMP6_PARAMPROB_HEADER,
|
---|
| 348 | (off - IF_HDR_SIZE) +
|
---|
| 349 | offsetof(T_IP6_FRAG_HDR, off_flag));
|
---|
| 350 | goto sig_ret;
|
---|
| 351 | }
|
---|
| 352 |
|
---|
| 353 | /*
|
---|
| 354 | * ip6fq == NULL ã§ããã°ã対å¿ããã¨ã³ããªã¯ç¡ãã®ã§ã
|
---|
| 355 | * ãã¼ã¿ã°ã©ã åæ§æãã¥ã¼é
|
---|
| 356 | åã«ãã¨ã³ããªã追å ããã
|
---|
| 357 | */
|
---|
| 358 | for (ix = NUM_IP6_FRAG_QUEUE; ix -- > 0; ) {
|
---|
| 359 |
|
---|
| 360 | /* 空ãã¨ã³ããªãæ¢ãã*/
|
---|
| 361 | if (ip6_frag_queue[ix] == NULL) {
|
---|
| 362 | ip6fq = &ip6_frag_queue[ix];
|
---|
| 363 | break;
|
---|
| 364 | }
|
---|
| 365 | }
|
---|
| 366 |
|
---|
| 367 | /*
|
---|
| 368 | * ip6fq == NULL ã§ããã°ã空ãã¨ã³ããªãç¡ãã®ã§ã
|
---|
| 369 | * ã¿ã¤ã ã¢ã¦ãï¼hlimï¼ãçãã¨ã³ããªãéæ¾ããã
|
---|
| 370 | */
|
---|
| 371 | if (ip6fq == NULL) {
|
---|
| 372 |
|
---|
| 373 | ftim = IPV6_MAXHLIM;
|
---|
| 374 | for (ix = NUM_IP6_FRAG_QUEUE; ix -- > 0; ) {
|
---|
| 375 | if (ip6_frag_queue[ix] != NULL) {
|
---|
| 376 | rip6h = GET_QIP6_HDR(ip6_frag_queue[ix]);
|
---|
| 377 | if (rip6h->ftim < ftim) {
|
---|
| 378 | ftim = rip6h->ftim;
|
---|
| 379 | ip6fq = &ip6_frag_queue[ix];
|
---|
| 380 | }
|
---|
| 381 | }
|
---|
| 382 | }
|
---|
| 383 | frag6_free_queue(ip6fq);
|
---|
| 384 | }
|
---|
| 385 |
|
---|
| 386 | /*
|
---|
| 387 | * ã¨ã³ããªãè¨å®ããã
|
---|
| 388 | */
|
---|
| 389 | *ip6fq = input;
|
---|
| 390 | ip6_frag_dest[ip6fq - ip6_frag_queue] = ip6h->dst;
|
---|
| 391 | qip6h = GET_QIP6_HDR(*ip6fq);
|
---|
| 392 | qip6h->ftim = IPV6_FRAGTTL;
|
---|
| 393 | qip6h->foff = off;
|
---|
| 394 | qip6h->flen = fragpartlen;
|
---|
| 395 | qip6h->next_frag = NULL;
|
---|
| 396 | }
|
---|
| 397 | else {
|
---|
| 398 |
|
---|
| 399 | /*
|
---|
| 400 | * æçã®æ£å½æ§ããã§ãã¯ããã
|
---|
| 401 | */
|
---|
| 402 | unfraglen = 0;
|
---|
| 403 | fragoff = ntohs(((T_IP6_FRAG_HDR *)((*ip6fq)->buf + GET_QIP6_HDR(*ip6fq)->foff))->off_flag & IP6F_OFF_MASK);
|
---|
| 404 | if (fragoff == 0) {
|
---|
| 405 |
|
---|
| 406 | /*
|
---|
| 407 | * ãã¼ã¿ã°ã©ã åæ§æãã¥ã¼ã®æåã®æçãå
|
---|
| 408 | é ã®æç
|
---|
| 409 | * åå²ã§ããªãé¨åã®é·ã unfraglen ãè¨ç®ããã
|
---|
| 410 | */
|
---|
| 411 | unfraglen = (GET_QIP6_HDR(*ip6fq)->foff - IF_HDR_SIZE) - sizeof(T_IP6_HDR);
|
---|
| 412 | }
|
---|
| 413 |
|
---|
| 414 | fragoff = ntohs(ip6fh->off_flag & IP6F_OFF_MASK);
|
---|
| 415 | if (fragoff == 0) {
|
---|
| 416 |
|
---|
| 417 | /*
|
---|
| 418 | * å
|
---|
| 419 | ¥åããæçãå
|
---|
| 420 | é ã®æç
|
---|
| 421 | * åå²ã§ããªãé¨åã®é·ã unfraglen ãè¨ç®ããã
|
---|
| 422 | */
|
---|
| 423 | unfraglen = (off - IF_HDR_SIZE) - sizeof(T_IP6_HDR);
|
---|
| 424 | }
|
---|
| 425 |
|
---|
| 426 | /*
|
---|
| 427 | * off
|
---|
| 428 | * |<--------------------------->|
|
---|
| 429 | * | off - IF_HDR_SIZE |
|
---|
| 430 | * | |<------------------>|
|
---|
| 431 | * | | off - IF_HDR_SIZE + IP6_FRAG_HDR_SIZE |
|
---|
| 432 | * | |<------------------------------------->|
|
---|
| 433 | * +--------+----------+---------+------------------+-------------+
|
---|
| 434 | * | IF HDR | IPv6 HDR | EXT HDR | FRAG HDR | Payload |
|
---|
| 435 | * +--------+----------+---------+------------------+-------------+
|
---|
| 436 | * |<---------------------------------------->|
|
---|
| 437 | * | Payload Size |
|
---|
| 438 | * |<--------------------------------------------------->|
|
---|
| 439 | * | IP6_HDR_SIZE + Payload Size |
|
---|
| 440 | * |<----------->|
|
---|
| 441 | * | fragpartlen |
|
---|
| 442 | */
|
---|
| 443 | fragpartlen = sizeof(T_IP6_HDR) + ntohs(ip6h->plen) - (off - IF_HDR_SIZE + sizeof(T_IP6_FRAG_HDR));
|
---|
| 444 | if (unfraglen + fragoff + fragpartlen > IPV6_MAXPACKET) {
|
---|
| 445 | icmp6_error(input, ICMP6_PARAM_PROB,
|
---|
| 446 | ICMP6_PARAMPROB_HEADER,
|
---|
| 447 | (off - IF_HDR_SIZE) +
|
---|
| 448 | offsetof(T_IP6_FRAG_HDR, off_flag));
|
---|
| 449 | goto sig_ret;
|
---|
| 450 | }
|
---|
| 451 |
|
---|
| 452 | if (ntohs(ip6fh->off_flag & IP6F_OFF_MASK) == 0) {
|
---|
| 453 |
|
---|
| 454 | /*
|
---|
| 455 | * å
|
---|
| 456 | ¥åããæçãå
|
---|
| 457 | é ã®æç
|
---|
| 458 | * ãã¼ã¿ã°ã©ã åæ§æãã¥ã¼ã®æå¾ã®æçãã
|
---|
| 459 | * ãã¼ã¿ã°ã©ã ã®æ大é·ãè¶
|
---|
| 460 | ãã¦ããªãããã§ãã¯ããã
|
---|
| 461 | */
|
---|
| 462 |
|
---|
| 463 | /* æå¾ã®æçãæ¢ç´¢ããã*/
|
---|
| 464 | next = *ip6fq;
|
---|
| 465 | while ((qip6h = GET_QIP6_HDR(next))->next_frag != NULL)
|
---|
| 466 | next = qip6h->next_frag;
|
---|
| 467 |
|
---|
| 468 | /* æå¾ã®æçã®ãªãã»ããã¨æçãµã¤ãºãè¨ç®ããã*/
|
---|
| 469 | qip6fh = (T_IP6_FRAG_HDR *)(next->buf + qip6h->foff);
|
---|
| 470 | fragoff = ntohs(qip6fh->off_flag & IP6F_OFF_MASK);
|
---|
| 471 | fragpartlen = sizeof(T_IP6_HDR) + ntohs(qip6h->plen) - (qip6h->foff - IF_HDR_SIZE + sizeof(T_IP6_FRAG_HDR));
|
---|
| 472 | if (unfraglen + fragoff + fragpartlen > IPV6_MAXPACKET) {
|
---|
| 473 |
|
---|
| 474 | /*
|
---|
| 475 | * ãã¼ã¿ã°ã©ã ã®æ大é·ãè¶
|
---|
| 476 | ãã¦ããå ´åã¯ã
|
---|
| 477 | * ãã¼ã¿ã°ã©ã åæ§æãã¥ã¼å
|
---|
| 478 | ¨ä½ãç ´æ£ããã
|
---|
| 479 | */
|
---|
| 480 | frag6_free_queue(ip6fq);
|
---|
| 481 | syscall(rel_net_buf(input));
|
---|
| 482 | goto sig_ret;
|
---|
| 483 | }
|
---|
| 484 | }
|
---|
| 485 |
|
---|
| 486 | /* ECN ã®æ£å½æ§ãã§ãã¯ã¯æªå®è£
|
---|
| 487 | */
|
---|
| 488 |
|
---|
| 489 | /*
|
---|
| 490 | * æçãã¨ã³ããªã«æ¿å
|
---|
| 491 | ¥ããã
|
---|
| 492 | * ãã¼ã¿ã°ã©ã åæ§æãã¥ã¼ãããå
|
---|
| 493 | ¥åããæçããåã®æçãæ¢ç´¢ããã
|
---|
| 494 | */
|
---|
| 495 | prev = NULL;
|
---|
| 496 | next = *ip6fq;
|
---|
| 497 | while (next != NULL) {
|
---|
| 498 | qip6h = GET_QIP6_HDR(next);
|
---|
| 499 | qip6fh = (T_IP6_FRAG_HDR *)(next->buf + qip6h->foff);
|
---|
| 500 | if (ntohs(ip6fh->off_flag & IP6F_OFF_MASK) <= ntohs(qip6fh->off_flag & IP6F_OFF_MASK))
|
---|
| 501 | break;
|
---|
| 502 | prev = next;
|
---|
| 503 | next = qip6h->next_frag;
|
---|
| 504 | }
|
---|
| 505 |
|
---|
| 506 | /*
|
---|
| 507 | * prev ã¯ãå
|
---|
| 508 | ¥åããæçããåã®æçããã ã NULL ã®å ´åã¯ã
|
---|
| 509 | * å
|
---|
| 510 | ¥åããæçããã¼ã¿ã°ã©ã åæ§æãã¥ã¼ã®ä¸ã§æãåã®æçã
|
---|
| 511 | * next ã¯ãå
|
---|
| 512 | ¥åããæçããå¾ã®æçããã ã NULL ã®å ´åã¯ã
|
---|
| 513 | * å
|
---|
| 514 | ¥åããæçããã¼ã¿ã°ã©ã åæ§æãã¥ã¼ã®ä¸ã§æãå¾ã®æçã
|
---|
| 515 | */
|
---|
| 516 | fragoff = ntohs(ip6fh->off_flag & IP6F_OFF_MASK);
|
---|
| 517 | if (prev != NULL) {
|
---|
| 518 |
|
---|
| 519 | /*
|
---|
| 520 | * åã®æçã¨ãå
|
---|
| 521 | ¥åããæçãéãªã£ã¦ããªãããã§ãã¯ããã
|
---|
| 522 | *
|
---|
| 523 | * qfragoff
|
---|
| 524 | * | qfragparglen
|
---|
| 525 | * |<------------------>|
|
---|
| 526 | * +--------------------+
|
---|
| 527 | * | prev |
|
---|
| 528 | * +--------------------+
|
---|
| 529 | *
|
---|
| 530 | * +--------------------+
|
---|
| 531 | * | input |
|
---|
| 532 | * +--------------------+
|
---|
| 533 | * |
|
---|
| 534 | * fragoff
|
---|
| 535 | */
|
---|
| 536 | qip6h = GET_QIP6_HDR(prev);
|
---|
| 537 | qip6fh = (T_IP6_FRAG_HDR *)(prev->buf + qip6h->foff);
|
---|
| 538 | qfragoff = ntohs(qip6fh->off_flag & IP6F_OFF_MASK);
|
---|
| 539 | qfragpartlen = sizeof(T_IP6_HDR) + ntohs(qip6h->plen) - (off - IF_HDR_SIZE + sizeof(T_IP6_FRAG_HDR));
|
---|
| 540 |
|
---|
| 541 | diff = ((int32_t)qfragoff + qfragpartlen) - fragoff;
|
---|
| 542 | if (diff > 0) {
|
---|
| 543 |
|
---|
| 544 | /* éãªã£ã¦ããã°ãå
|
---|
| 545 | ¥åããæçãç ´æ£ãã¦çµäºããã*/
|
---|
| 546 | syscall(rel_net_buf(input));
|
---|
| 547 | goto sig_ret;
|
---|
| 548 | }
|
---|
| 549 | }
|
---|
| 550 |
|
---|
| 551 | if (next != NULL) {
|
---|
| 552 |
|
---|
| 553 | /*
|
---|
| 554 | * å¾ã®æçã¨ãå
|
---|
| 555 | ¥åããæçãéãªã£ã¦ããªãããã§ãã¯ããã
|
---|
| 556 | *
|
---|
| 557 | * fragoff
|
---|
| 558 | * | fragparglen
|
---|
| 559 | * |<------------------>|
|
---|
| 560 | * +--------------------+
|
---|
| 561 | * | input |
|
---|
| 562 | * +--------------------+
|
---|
| 563 | *
|
---|
| 564 | * +--------------------+
|
---|
| 565 | * | next |
|
---|
| 566 | * +--------------------+
|
---|
| 567 | * |
|
---|
| 568 | * qfragoff
|
---|
| 569 | */
|
---|
| 570 | qip6h = GET_QIP6_HDR(next);
|
---|
| 571 | qip6fh = (T_IP6_FRAG_HDR *)(next->buf + qip6h->foff);
|
---|
| 572 | qfragoff = ntohs(qip6fh->off_flag & IP6F_OFF_MASK);
|
---|
| 573 | fragpartlen = sizeof(T_IP6_HDR) + ntohs(ip6h->plen) - (off - IF_HDR_SIZE + sizeof(T_IP6_FRAG_HDR));
|
---|
| 574 |
|
---|
| 575 | diff = ((int32_t)fragoff + fragpartlen) - qfragoff;
|
---|
| 576 | if (diff > 0) {
|
---|
| 577 |
|
---|
| 578 | /* éãªã£ã¦ããã°ãå
|
---|
| 579 | ¥åããæçãç ´æ£ãã¦çµäºããã*/
|
---|
| 580 | syscall(rel_net_buf(input));
|
---|
| 581 | goto sig_ret;
|
---|
| 582 | }
|
---|
| 583 | }
|
---|
| 584 |
|
---|
| 585 | /* å
|
---|
| 586 | ¥åããæçãè¨å®ããã*/
|
---|
| 587 | qip6h = GET_QIP6_HDR(input);
|
---|
| 588 | qip6h->foff = off;
|
---|
| 589 | qip6h->flen = sizeof(T_IP6_HDR) + ntohs(qip6h->plen) - (off - IF_HDR_SIZE + sizeof(T_IP6_FRAG_HDR));
|
---|
| 590 |
|
---|
| 591 | if (prev == NULL) {
|
---|
| 592 | *ip6fq = input;
|
---|
| 593 | qip6h->ftim = IPV6_FRAGTTL;
|
---|
| 594 | }
|
---|
| 595 | else
|
---|
| 596 | GET_QIP6_HDR(prev)->next_frag = input;
|
---|
| 597 | qip6h->next_frag = next;
|
---|
| 598 |
|
---|
| 599 | /*
|
---|
| 600 | * å
|
---|
| 601 | ¨ã¦ã®æçãåä¿¡ããããã§ãã¯ããã
|
---|
| 602 | */
|
---|
| 603 | plen = 0;
|
---|
| 604 | frag = *ip6fq;
|
---|
| 605 | while (frag != NULL) {
|
---|
| 606 | qip6h = GET_QIP6_HDR(frag);
|
---|
| 607 | qip6fh = (T_IP6_FRAG_HDR *)(frag->buf + qip6h->foff);
|
---|
| 608 | if (ntohs(qip6fh->off_flag & IP6F_OFF_MASK) != plen) {
|
---|
| 609 |
|
---|
| 610 | /* æçãé£ç¶ãã¦ããªãã*/
|
---|
| 611 | goto sig_ret;
|
---|
| 612 | }
|
---|
| 613 | plen += qip6h->flen;
|
---|
| 614 | frag = qip6h->next_frag;
|
---|
| 615 | }
|
---|
| 616 | if (ntohs(qip6fh->off_flag & IP6F_MORE_FRAG) != 0) {
|
---|
| 617 |
|
---|
| 618 | /* æå¾ã®æçãåä¿¡ãã¦ããªãã*/
|
---|
| 619 | goto sig_ret;
|
---|
| 620 | }
|
---|
| 621 |
|
---|
| 622 | /*
|
---|
| 623 | * å
|
---|
| 624 | ¨ã¦ã®æçãåä¿¡ããã®ã§ãåæ§æããã
|
---|
| 625 | */
|
---|
| 626 |
|
---|
| 627 | /* ãããã¯ã¼ã¯ãããã¡ãç²å¾ããã*/
|
---|
| 628 | qip6h = GET_QIP6_HDR(*ip6fq);
|
---|
| 629 | qip6fh = (T_IP6_FRAG_HDR *)((*ip6fq)->buf + qip6h->foff);
|
---|
| 630 | if (tget_net_buf(inputp, qip6h->foff + plen, TMO_IP6_FRAG_GET_NET_BUF) == E_OK) {
|
---|
| 631 |
|
---|
| 632 | /*
|
---|
| 633 | * æçãããã®ç´åã®ãããã® NEXT ãã£ã¼ã«ãã®ã¢ãã¬ã¹ãç²å¾ãã
|
---|
| 634 | * å
|
---|
| 635 | ã«æ»ãã
|
---|
| 636 | */
|
---|
| 637 | if ((prev_next = ip6_get_prev_hdr(*ip6fq, qip6h->foff)) == NULL) {
|
---|
| 638 | syscall(rel_net_buf(input));
|
---|
| 639 | goto sig_ret;
|
---|
| 640 | }
|
---|
| 641 | *prev_next = qip6fh->next;
|
---|
| 642 | input = *inputp;
|
---|
| 643 |
|
---|
| 644 | NET_COUNT_IP6(net_count_ip6[NC_IP6_FRAG_IN_OK], 1);
|
---|
| 645 | NET_COUNT_MIB(in6_stats.ipv6IfStatsReasmOKs, 1);
|
---|
| 646 |
|
---|
| 647 | /*
|
---|
| 648 | * IPv6 ãããã¨åå²ã§ããªãé¨åã
|
---|
| 649 | * ãã¼ã¿ã°ã©ã åæ§æãã¥ã¼ã®ä¸ã®å
|
---|
| 650 | é ã®æçããã³ãã¼ããã
|
---|
| 651 | */
|
---|
| 652 | memcpy(input->buf, (*ip6fq)->buf, qip6h->foff);
|
---|
| 653 |
|
---|
| 654 | /* éä¿¡å
|
---|
| 655 | ã¢ãã¬ã¹ãå
|
---|
| 656 | ã«æ»ãã*/
|
---|
| 657 | ip6h = GET_IP6_HDR(input);
|
---|
| 658 | ip6h->dst = ip6_frag_dest[ip6fq - ip6_frag_queue];
|
---|
| 659 |
|
---|
| 660 | /* offp ããåæ§æããæçã®å
|
---|
| 661 | é ã«è¨å®ããã*/
|
---|
| 662 | *offp = qip6h->foff;
|
---|
| 663 |
|
---|
| 664 | /* ãããã¯ã¼ã¯ãããã¡é·ãè¨å®ããã*/
|
---|
| 665 | input->len = plen + qip6h->foff;
|
---|
| 666 |
|
---|
| 667 | /*
|
---|
| 668 | * å
|
---|
| 669 | ¨ã¦ã®æçãã³ãã¼ããã
|
---|
| 670 | */
|
---|
| 671 | frag = *ip6fq;
|
---|
| 672 | off = qip6h->foff;
|
---|
| 673 | while (frag != NULL) {
|
---|
| 674 | qip6h = GET_QIP6_HDR(frag);
|
---|
| 675 | memcpy(input->buf + off,
|
---|
| 676 | frag->buf + qip6h->foff + sizeof(T_IP6_FRAG_HDR),
|
---|
| 677 | qip6h->flen);
|
---|
| 678 | off += qip6h->flen;
|
---|
| 679 | frag = qip6h->next_frag;
|
---|
| 680 | }
|
---|
| 681 |
|
---|
| 682 | /* ãã¤ãã¼ãé·ãè¨å®ããã*/
|
---|
| 683 | ip6h->plen = htons(plen);
|
---|
| 684 |
|
---|
| 685 | *nextp = offsetof(T_IP6_HDR, next);
|
---|
| 686 | nextproto = ip6h->next;
|
---|
| 687 | }
|
---|
| 688 | else {
|
---|
| 689 | NET_COUNT_IP6(net_count_ip6[NC_IP6_FRAG_IN_NO_BUF], 1);
|
---|
| 690 | NET_COUNT_IP6(net_count_ip6[NC_IP6_FRAG_IN_DROP], 1);
|
---|
| 691 | NET_COUNT_MIB(in6_stats.ipv6IfStatsReasmFails, 1);
|
---|
| 692 | }
|
---|
| 693 |
|
---|
| 694 | /* ãã¼ã¿ã°ã©ã åæ§æãã¥ã¼ã解æ¾ããã*/
|
---|
| 695 | frag6_free_queue(ip6fq);
|
---|
| 696 | }
|
---|
| 697 |
|
---|
| 698 | sig_ret:
|
---|
| 699 | syscall(sig_sem(SEM_IP6_FRAG_QUEUE));
|
---|
| 700 | return nextproto;
|
---|
| 701 |
|
---|
| 702 | #else /* #ifdef IP6_CFG_FRAGMENT */
|
---|
| 703 |
|
---|
| 704 | /*
|
---|
| 705 | * ãã¼ã¿ã°ã©ã ã®åå²ã»åæ§æè¡ããªãå ´åã¯ãå
|
---|
| 706 | ¨æçãç ´æ£ãã
|
---|
| 707 | * æå¾ã®æçãåä¿¡ããã¨ãã
|
---|
| 708 | * ICMP ã¨ã©ã¼ãéä¿¡è
|
---|
| 709 | ã«éç¥ããã
|
---|
| 710 | */
|
---|
| 711 | if ((ip6fh->off_flag & IP6F_MORE_FRAG) == 0) {
|
---|
| 712 | icmp6_error(input, ICMP6_TIME_EXCEEDED,
|
---|
| 713 | ICMP6_TIME_EXCEED_REASSEMBLY, 0);
|
---|
| 714 | NET_COUNT_MIB(in6_stats.ipv6IfStatsReasmFails, 1);
|
---|
| 715 | return IPPROTO_DONE;
|
---|
| 716 | }
|
---|
| 717 |
|
---|
| 718 | #endif /* #ifdef IP6_CFG_FRAGMENT */
|
---|
| 719 |
|
---|
| 720 | buf_rel:
|
---|
| 721 | syscall(rel_net_buf(input));
|
---|
| 722 | return IPPROTO_DONE;
|
---|
| 723 | }
|
---|
| 724 |
|
---|
| 725 | #endif /* of #ifdef SUPPORT_INET6 */
|
---|