The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/netinet6/frag6.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: 463b293c4854f9aa13c2ba0506178f2a


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.