frag6.c revision 120891
1/* $FreeBSD: head/sys/netinet6/frag6.c 120891 2003-10-07 17:46:18Z ume $ */ 2/* $KAME: frag6.c,v 1.33 2002/01/07 11:34:48 kjc Exp $ */ 3 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 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the project nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 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. 31 */ 32 33#include "opt_random_ip_id.h" 34 35#include <sys/param.h> 36#include <sys/systm.h> 37#include <sys/malloc.h> 38#include <sys/mbuf.h> 39#include <sys/domain.h> 40#include <sys/protosw.h> 41#include <sys/socket.h> 42#include <sys/errno.h> 43#include <sys/time.h> 44#include <sys/kernel.h> 45#include <sys/syslog.h> 46 47#include <net/if.h> 48#include <net/route.h> 49 50#include <netinet/in.h> 51#include <netinet/in_var.h> 52#include <netinet/ip6.h> 53#include <netinet6/ip6_var.h> 54#include <netinet/icmp6.h> 55 56#include <net/net_osdep.h> 57 58/* 59 * Define it to get a correct behavior on per-interface statistics. 60 * You will need to perform an extra routing table lookup, per fragment, 61 * to do it. This may, or may not be, a performance hit. 62 */ 63#define IN6_IFSTAT_STRICT 64 65static void frag6_enq __P((struct ip6asfrag *, struct ip6asfrag *)); 66static void frag6_deq __P((struct ip6asfrag *)); 67static void frag6_insque __P((struct ip6q *, struct ip6q *)); 68static void frag6_remque __P((struct ip6q *)); 69static void frag6_freef __P((struct ip6q *)); 70 71/* XXX we eventually need splreass6, or some real semaphore */ 72int frag6_doing_reass; 73u_int frag6_nfragpackets; 74struct ip6q ip6q; /* ip6 reassemble queue */ 75 76/* FreeBSD tweak */ 77static MALLOC_DEFINE(M_FTABLE, "fragment", "fragment reassembly header"); 78 79/* 80 * Initialise reassembly queue and fragment identifier. 81 */ 82void 83frag6_init() 84{ 85 86 ip6_maxfragpackets = nmbclusters / 4; 87 88#ifndef RANDOM_IP_ID 89 ip6_id = arc4random(); 90#endif 91 ip6q.ip6q_next = ip6q.ip6q_prev = &ip6q; 92} 93 94/* 95 * In RFC2460, fragment and reassembly rule do not agree with each other, 96 * in terms of next header field handling in fragment header. 97 * While the sender will use the same value for all of the fragmented packets, 98 * receiver is suggested not to check the consistency. 99 * 100 * fragment rule (p20): 101 * (2) A Fragment header containing: 102 * The Next Header value that identifies the first header of 103 * the Fragmentable Part of the original packet. 104 * -> next header field is same for all fragments 105 * 106 * reassembly rule (p21): 107 * The Next Header field of the last header of the Unfragmentable 108 * Part is obtained from the Next Header field of the first 109 * fragment's Fragment header. 110 * -> should grab it from the first fragment only 111 * 112 * The following note also contradicts with fragment rule - noone is going to 113 * send different fragment with different next header field. 114 * 115 * additional note (p22): 116 * The Next Header values in the Fragment headers of different 117 * fragments of the same original packet may differ. Only the value 118 * from the Offset zero fragment packet is used for reassembly. 119 * -> should grab it from the first fragment only 120 * 121 * There is no explicit reason given in the RFC. Historical reason maybe? 122 */ 123/* 124 * Fragment input 125 */ 126int 127frag6_input(mp, offp, proto) 128 struct mbuf **mp; 129 int *offp, proto; 130{ 131 struct mbuf *m = *mp, *t; 132 struct ip6_hdr *ip6; 133 struct ip6_frag *ip6f; 134 struct ip6q *q6; 135 struct ip6asfrag *af6, *ip6af, *af6dwn; 136 int offset = *offp, nxt, i, next; 137 int first_frag = 0; 138 int fragoff, frgpartlen; /* must be larger than u_int16_t */ 139 struct ifnet *dstifp; 140#ifdef IN6_IFSTAT_STRICT 141 static struct route_in6 ro; 142 struct sockaddr_in6 *dst; 143#endif 144 145 ip6 = mtod(m, struct ip6_hdr *); 146#ifndef PULLDOWN_TEST 147 IP6_EXTHDR_CHECK(m, offset, sizeof(struct ip6_frag), IPPROTO_DONE); 148 ip6f = (struct ip6_frag *)((caddr_t)ip6 + offset); 149#else 150 IP6_EXTHDR_GET(ip6f, struct ip6_frag *, m, offset, sizeof(*ip6f)); 151 if (ip6f == NULL) 152 return (IPPROTO_DONE); 153#endif 154 155 dstifp = NULL; 156#ifdef IN6_IFSTAT_STRICT 157 /* find the destination interface of the packet. */ 158 dst = (struct sockaddr_in6 *)&ro.ro_dst; 159 if (ro.ro_rt 160 && ((ro.ro_rt->rt_flags & RTF_UP) == 0 161 || !IN6_ARE_ADDR_EQUAL(&dst->sin6_addr, &ip6->ip6_dst))) { 162 RTFREE(ro.ro_rt); 163 ro.ro_rt = (struct rtentry *)0; 164 } 165 if (ro.ro_rt == NULL) { 166 bzero(dst, sizeof(*dst)); 167 dst->sin6_family = AF_INET6; 168 dst->sin6_len = sizeof(struct sockaddr_in6); 169 dst->sin6_addr = ip6->ip6_dst; 170 } 171 rtalloc((struct route *)&ro); 172 if (ro.ro_rt != NULL && ro.ro_rt->rt_ifa != NULL) 173 dstifp = ((struct in6_ifaddr *)ro.ro_rt->rt_ifa)->ia_ifp; 174#else 175 /* we are violating the spec, this is not the destination interface */ 176 if ((m->m_flags & M_PKTHDR) != 0) 177 dstifp = m->m_pkthdr.rcvif; 178#endif 179 180 /* jumbo payload can't contain a fragment header */ 181 if (ip6->ip6_plen == 0) { 182 icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, offset); 183 in6_ifstat_inc(dstifp, ifs6_reass_fail); 184 return IPPROTO_DONE; 185 } 186 187 /* 188 * check whether fragment packet's fragment length is 189 * multiple of 8 octets. 190 * sizeof(struct ip6_frag) == 8 191 * sizeof(struct ip6_hdr) = 40 192 */ 193 if ((ip6f->ip6f_offlg & IP6F_MORE_FRAG) && 194 (((ntohs(ip6->ip6_plen) - offset) & 0x7) != 0)) { 195 icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, 196 offsetof(struct ip6_hdr, ip6_plen)); 197 in6_ifstat_inc(dstifp, ifs6_reass_fail); 198 return IPPROTO_DONE; 199 } 200 201 ip6stat.ip6s_fragments++; 202 in6_ifstat_inc(dstifp, ifs6_reass_reqd); 203 204 /* offset now points to data portion */ 205 offset += sizeof(struct ip6_frag); 206 207 frag6_doing_reass = 1; 208 209 for (q6 = ip6q.ip6q_next; q6 != &ip6q; q6 = q6->ip6q_next) 210 if (ip6f->ip6f_ident == q6->ip6q_ident && 211 IN6_ARE_ADDR_EQUAL(&ip6->ip6_src, &q6->ip6q_src) && 212 IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, &q6->ip6q_dst)) 213 break; 214 215 if (q6 == &ip6q) { 216 /* 217 * the first fragment to arrive, create a reassembly queue. 218 */ 219 first_frag = 1; 220 221 /* 222 * Enforce upper bound on number of fragmented packets 223 * for which we attempt reassembly; 224 * If maxfrag is 0, never accept fragments. 225 * If maxfrag is -1, accept all fragments without limitation. 226 */ 227 if (ip6_maxfragpackets < 0) 228 ; 229 else if (frag6_nfragpackets >= (u_int)ip6_maxfragpackets) 230 goto dropfrag; 231 frag6_nfragpackets++; 232 q6 = (struct ip6q *)malloc(sizeof(struct ip6q), M_FTABLE, 233 M_DONTWAIT); 234 if (q6 == NULL) 235 goto dropfrag; 236 bzero(q6, sizeof(*q6)); 237 238 frag6_insque(q6, &ip6q); 239 240 /* ip6q_nxt will be filled afterwards, from 1st fragment */ 241 q6->ip6q_down = q6->ip6q_up = (struct ip6asfrag *)q6; 242#ifdef notyet 243 q6->ip6q_nxtp = (u_char *)nxtp; 244#endif 245 q6->ip6q_ident = ip6f->ip6f_ident; 246 q6->ip6q_arrive = 0; /* Is it used anywhere? */ 247 q6->ip6q_ttl = IPV6_FRAGTTL; 248 q6->ip6q_src = ip6->ip6_src; 249 q6->ip6q_dst = ip6->ip6_dst; 250 q6->ip6q_unfrglen = -1; /* The 1st fragment has not arrived. */ 251 } 252 253 /* 254 * If it's the 1st fragment, record the length of the 255 * unfragmentable part and the next header of the fragment header. 256 */ 257 fragoff = ntohs(ip6f->ip6f_offlg & IP6F_OFF_MASK); 258 if (fragoff == 0) { 259 q6->ip6q_unfrglen = offset - sizeof(struct ip6_hdr) - 260 sizeof(struct ip6_frag); 261 q6->ip6q_nxt = ip6f->ip6f_nxt; 262 } 263 264 /* 265 * Check that the reassembled packet would not exceed 65535 bytes 266 * in size. 267 * If it would exceed, discard the fragment and return an ICMP error. 268 */ 269 frgpartlen = sizeof(struct ip6_hdr) + ntohs(ip6->ip6_plen) - offset; 270 if (q6->ip6q_unfrglen >= 0) { 271 /* The 1st fragment has already arrived. */ 272 if (q6->ip6q_unfrglen + fragoff + frgpartlen > IPV6_MAXPACKET) { 273 icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, 274 offset - sizeof(struct ip6_frag) + 275 offsetof(struct ip6_frag, ip6f_offlg)); 276 frag6_doing_reass = 0; 277 return (IPPROTO_DONE); 278 } 279 } else if (fragoff + frgpartlen > IPV6_MAXPACKET) { 280 icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, 281 offset - sizeof(struct ip6_frag) + 282 offsetof(struct ip6_frag, ip6f_offlg)); 283 frag6_doing_reass = 0; 284 return (IPPROTO_DONE); 285 } 286 /* 287 * If it's the first fragment, do the above check for each 288 * fragment already stored in the reassembly queue. 289 */ 290 if (fragoff == 0) { 291 for (af6 = q6->ip6q_down; af6 != (struct ip6asfrag *)q6; 292 af6 = af6dwn) { 293 af6dwn = af6->ip6af_down; 294 295 if (q6->ip6q_unfrglen + af6->ip6af_off + af6->ip6af_frglen > 296 IPV6_MAXPACKET) { 297 struct mbuf *merr = IP6_REASS_MBUF(af6); 298 struct ip6_hdr *ip6err; 299 int erroff = af6->ip6af_offset; 300 301 /* dequeue the fragment. */ 302 frag6_deq(af6); 303 free(af6, M_FTABLE); 304 305 /* adjust pointer. */ 306 ip6err = mtod(merr, struct ip6_hdr *); 307 308 /* 309 * Restore source and destination addresses 310 * in the erroneous IPv6 header. 311 */ 312 ip6err->ip6_src = q6->ip6q_src; 313 ip6err->ip6_dst = q6->ip6q_dst; 314 315 icmp6_error(merr, ICMP6_PARAM_PROB, 316 ICMP6_PARAMPROB_HEADER, 317 erroff - sizeof(struct ip6_frag) + 318 offsetof(struct ip6_frag, ip6f_offlg)); 319 } 320 } 321 } 322 323 ip6af = (struct ip6asfrag *)malloc(sizeof(struct ip6asfrag), M_FTABLE, 324 M_DONTWAIT); 325 if (ip6af == NULL) 326 goto dropfrag; 327 bzero(ip6af, sizeof(*ip6af)); 328 ip6af->ip6af_head = ip6->ip6_flow; 329 ip6af->ip6af_len = ip6->ip6_plen; 330 ip6af->ip6af_nxt = ip6->ip6_nxt; 331 ip6af->ip6af_hlim = ip6->ip6_hlim; 332 ip6af->ip6af_mff = ip6f->ip6f_offlg & IP6F_MORE_FRAG; 333 ip6af->ip6af_off = fragoff; 334 ip6af->ip6af_frglen = frgpartlen; 335 ip6af->ip6af_offset = offset; 336 IP6_REASS_MBUF(ip6af) = m; 337 338 if (first_frag) { 339 af6 = (struct ip6asfrag *)q6; 340 goto insert; 341 } 342 343 /* 344 * Find a segment which begins after this one does. 345 */ 346 for (af6 = q6->ip6q_down; af6 != (struct ip6asfrag *)q6; 347 af6 = af6->ip6af_down) 348 if (af6->ip6af_off > ip6af->ip6af_off) 349 break; 350 351#if 0 352 /* 353 * If there is a preceding segment, it may provide some of 354 * our data already. If so, drop the data from the incoming 355 * segment. If it provides all of our data, drop us. 356 */ 357 if (af6->ip6af_up != (struct ip6asfrag *)q6) { 358 i = af6->ip6af_up->ip6af_off + af6->ip6af_up->ip6af_frglen 359 - ip6af->ip6af_off; 360 if (i > 0) { 361 if (i >= ip6af->ip6af_frglen) 362 goto dropfrag; 363 m_adj(IP6_REASS_MBUF(ip6af), i); 364 ip6af->ip6af_off += i; 365 ip6af->ip6af_frglen -= i; 366 } 367 } 368 369 /* 370 * While we overlap succeeding segments trim them or, 371 * if they are completely covered, dequeue them. 372 */ 373 while (af6 != (struct ip6asfrag *)q6 && 374 ip6af->ip6af_off + ip6af->ip6af_frglen > af6->ip6af_off) { 375 i = (ip6af->ip6af_off + ip6af->ip6af_frglen) - af6->ip6af_off; 376 if (i < af6->ip6af_frglen) { 377 af6->ip6af_frglen -= i; 378 af6->ip6af_off += i; 379 m_adj(IP6_REASS_MBUF(af6), i); 380 break; 381 } 382 af6 = af6->ip6af_down; 383 m_freem(IP6_REASS_MBUF(af6->ip6af_up)); 384 frag6_deq(af6->ip6af_up); 385 } 386#else 387 /* 388 * If the incoming framgent overlaps some existing fragments in 389 * the reassembly queue, drop it, since it is dangerous to override 390 * existing fragments from a security point of view. 391 */ 392 if (af6->ip6af_up != (struct ip6asfrag *)q6) { 393 i = af6->ip6af_up->ip6af_off + af6->ip6af_up->ip6af_frglen 394 - ip6af->ip6af_off; 395 if (i > 0) { 396#if 0 /* suppress the noisy log */ 397 log(LOG_ERR, "%d bytes of a fragment from %s " 398 "overlaps the previous fragment\n", 399 i, ip6_sprintf(&q6->ip6q_src)); 400#endif 401 free(ip6af, M_FTABLE); 402 goto dropfrag; 403 } 404 } 405 if (af6 != (struct ip6asfrag *)q6) { 406 i = (ip6af->ip6af_off + ip6af->ip6af_frglen) - af6->ip6af_off; 407 if (i > 0) { 408#if 0 /* suppress the noisy log */ 409 log(LOG_ERR, "%d bytes of a fragment from %s " 410 "overlaps the succeeding fragment", 411 i, ip6_sprintf(&q6->ip6q_src)); 412#endif 413 free(ip6af, M_FTABLE); 414 goto dropfrag; 415 } 416 } 417#endif 418 419insert: 420 421 /* 422 * Stick new segment in its place; 423 * check for complete reassembly. 424 * Move to front of packet queue, as we are 425 * the most recently active fragmented packet. 426 */ 427 frag6_enq(ip6af, af6->ip6af_up); 428#if 0 /* xxx */ 429 if (q6 != ip6q.ip6q_next) { 430 frag6_remque(q6); 431 frag6_insque(q6, &ip6q); 432 } 433#endif 434 next = 0; 435 for (af6 = q6->ip6q_down; af6 != (struct ip6asfrag *)q6; 436 af6 = af6->ip6af_down) { 437 if (af6->ip6af_off != next) { 438 frag6_doing_reass = 0; 439 return IPPROTO_DONE; 440 } 441 next += af6->ip6af_frglen; 442 } 443 if (af6->ip6af_up->ip6af_mff) { 444 frag6_doing_reass = 0; 445 return IPPROTO_DONE; 446 } 447 448 /* 449 * Reassembly is complete; concatenate fragments. 450 */ 451 ip6af = q6->ip6q_down; 452 t = m = IP6_REASS_MBUF(ip6af); 453 af6 = ip6af->ip6af_down; 454 frag6_deq(ip6af); 455 while (af6 != (struct ip6asfrag *)q6) { 456 af6dwn = af6->ip6af_down; 457 frag6_deq(af6); 458 while (t->m_next) 459 t = t->m_next; 460 t->m_next = IP6_REASS_MBUF(af6); 461 m_adj(t->m_next, af6->ip6af_offset); 462 free(af6, M_FTABLE); 463 af6 = af6dwn; 464 } 465 466 /* adjust offset to point where the original next header starts */ 467 offset = ip6af->ip6af_offset - sizeof(struct ip6_frag); 468 free(ip6af, M_FTABLE); 469 ip6 = mtod(m, struct ip6_hdr *); 470 ip6->ip6_plen = htons((u_short)next + offset - sizeof(struct ip6_hdr)); 471 ip6->ip6_src = q6->ip6q_src; 472 ip6->ip6_dst = q6->ip6q_dst; 473 nxt = q6->ip6q_nxt; 474#ifdef notyet 475 *q6->ip6q_nxtp = (u_char)(nxt & 0xff); 476#endif 477 478 /* 479 * Delete frag6 header with as a few cost as possible. 480 */ 481 if (offset < m->m_len) { 482 ovbcopy((caddr_t)ip6, (caddr_t)ip6 + sizeof(struct ip6_frag), 483 offset); 484 m->m_data += sizeof(struct ip6_frag); 485 m->m_len -= sizeof(struct ip6_frag); 486 } else { 487 /* this comes with no copy if the boundary is on cluster */ 488 if ((t = m_split(m, offset, M_DONTWAIT)) == NULL) { 489 frag6_remque(q6); 490 free(q6, M_FTABLE); 491 frag6_nfragpackets--; 492 goto dropfrag; 493 } 494 m_adj(t, sizeof(struct ip6_frag)); 495 m_cat(m, t); 496 } 497 498 /* 499 * Store NXT to the original. 500 */ 501 { 502 char *prvnxtp = ip6_get_prevhdr(m, offset); /* XXX */ 503 *prvnxtp = nxt; 504 } 505 506 frag6_remque(q6); 507 free(q6, M_FTABLE); 508 frag6_nfragpackets--; 509 510 if (m->m_flags & M_PKTHDR) { /* Isn't it always true? */ 511 int plen = 0; 512 for (t = m; t; t = t->m_next) 513 plen += t->m_len; 514 m->m_pkthdr.len = plen; 515 } 516 517 ip6stat.ip6s_reassembled++; 518 in6_ifstat_inc(dstifp, ifs6_reass_ok); 519 520 /* 521 * Tell launch routine the next header 522 */ 523 524 *mp = m; 525 *offp = offset; 526 527 frag6_doing_reass = 0; 528 return nxt; 529 530 dropfrag: 531 in6_ifstat_inc(dstifp, ifs6_reass_fail); 532 ip6stat.ip6s_fragdropped++; 533 m_freem(m); 534 frag6_doing_reass = 0; 535 return IPPROTO_DONE; 536} 537 538/* 539 * Free a fragment reassembly header and all 540 * associated datagrams. 541 */ 542void 543frag6_freef(q6) 544 struct ip6q *q6; 545{ 546 struct ip6asfrag *af6, *down6; 547 548 for (af6 = q6->ip6q_down; af6 != (struct ip6asfrag *)q6; 549 af6 = down6) { 550 struct mbuf *m = IP6_REASS_MBUF(af6); 551 552 down6 = af6->ip6af_down; 553 frag6_deq(af6); 554 555 /* 556 * Return ICMP time exceeded error for the 1st fragment. 557 * Just free other fragments. 558 */ 559 if (af6->ip6af_off == 0) { 560 struct ip6_hdr *ip6; 561 562 /* adjust pointer */ 563 ip6 = mtod(m, struct ip6_hdr *); 564 565 /* restore source and destination addresses */ 566 ip6->ip6_src = q6->ip6q_src; 567 ip6->ip6_dst = q6->ip6q_dst; 568 569 icmp6_error(m, ICMP6_TIME_EXCEEDED, 570 ICMP6_TIME_EXCEED_REASSEMBLY, 0); 571 } else 572 m_freem(m); 573 free(af6, M_FTABLE); 574 } 575 frag6_remque(q6); 576 free(q6, M_FTABLE); 577 frag6_nfragpackets--; 578} 579 580/* 581 * Put an ip fragment on a reassembly chain. 582 * Like insque, but pointers in middle of structure. 583 */ 584void 585frag6_enq(af6, up6) 586 struct ip6asfrag *af6, *up6; 587{ 588 af6->ip6af_up = up6; 589 af6->ip6af_down = up6->ip6af_down; 590 up6->ip6af_down->ip6af_up = af6; 591 up6->ip6af_down = af6; 592} 593 594/* 595 * To frag6_enq as remque is to insque. 596 */ 597void 598frag6_deq(af6) 599 struct ip6asfrag *af6; 600{ 601 af6->ip6af_up->ip6af_down = af6->ip6af_down; 602 af6->ip6af_down->ip6af_up = af6->ip6af_up; 603} 604 605void 606frag6_insque(new, old) 607 struct ip6q *new, *old; 608{ 609 new->ip6q_prev = old; 610 new->ip6q_next = old->ip6q_next; 611 old->ip6q_next->ip6q_prev= new; 612 old->ip6q_next = new; 613} 614 615void 616frag6_remque(p6) 617 struct ip6q *p6; 618{ 619 p6->ip6q_prev->ip6q_next = p6->ip6q_next; 620 p6->ip6q_next->ip6q_prev = p6->ip6q_prev; 621} 622 623/* 624 * IPv6 reassembling timer processing; 625 * if a timer expires on a reassembly 626 * queue, discard it. 627 */ 628void 629frag6_slowtimo() 630{ 631 struct ip6q *q6; 632 int s = splnet(); 633 634 frag6_doing_reass = 1; 635 q6 = ip6q.ip6q_next; 636 if (q6) 637 while (q6 != &ip6q) { 638 --q6->ip6q_ttl; 639 q6 = q6->ip6q_next; 640 if (q6->ip6q_prev->ip6q_ttl == 0) { 641 ip6stat.ip6s_fragtimeout++; 642 /* XXX in6_ifstat_inc(ifp, ifs6_reass_fail) */ 643 frag6_freef(q6->ip6q_prev); 644 } 645 } 646 /* 647 * If we are over the maximum number of fragments 648 * (due to the limit being lowered), drain off 649 * enough to get down to the new limit. 650 */ 651 while (frag6_nfragpackets > (u_int)ip6_maxfragpackets && 652 ip6q.ip6q_prev) { 653 ip6stat.ip6s_fragoverflow++; 654 /* XXX in6_ifstat_inc(ifp, ifs6_reass_fail) */ 655 frag6_freef(ip6q.ip6q_prev); 656 } 657 frag6_doing_reass = 0; 658 659#if 0 660 /* 661 * Routing changes might produce a better route than we last used; 662 * make sure we notice eventually, even if forwarding only for one 663 * destination and the cache is never replaced. 664 */ 665 if (ip6_forward_rt.ro_rt) { 666 RTFREE(ip6_forward_rt.ro_rt); 667 ip6_forward_rt.ro_rt = 0; 668 } 669 if (ipsrcchk_rt.ro_rt) { 670 RTFREE(ipsrcchk_rt.ro_rt); 671 ipsrcchk_rt.ro_rt = 0; 672 } 673#endif 674 675 splx(s); 676} 677 678/* 679 * Drain off all datagram fragments. 680 */ 681void 682frag6_drain() 683{ 684 if (frag6_doing_reass) 685 return; 686 while (ip6q.ip6q_next != &ip6q) { 687 ip6stat.ip6s_fragdropped++; 688 /* XXX in6_ifstat_inc(ifp, ifs6_reass_fail) */ 689 frag6_freef(ip6q.ip6q_next); 690 } 691} 692