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/route6.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 /*      $NetBSD: route6.c,v 1.13.4.1 2007/06/04 19:24:35 bouyer Exp $   */
    2 /*      $KAME: route6.c,v 1.22 2000/12/03 00:54:00 itojun 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 <sys/cdefs.h>
   34 __KERNEL_RCSID(0, "$NetBSD: route6.c,v 1.13.4.1 2007/06/04 19:24:35 bouyer Exp $");
   35 
   36 #include <sys/param.h>
   37 #include <sys/mbuf.h>
   38 #include <sys/socket.h>
   39 #include <sys/systm.h>
   40 #include <sys/queue.h>
   41 
   42 #include <net/if.h>
   43 
   44 #include <netinet/in.h>
   45 #include <netinet6/in6_var.h>
   46 #include <netinet/ip6.h>
   47 #include <netinet6/ip6_var.h>
   48 
   49 #include <netinet/icmp6.h>
   50 
   51 int ip6_rht0 = -1;      /* disabled by default */
   52 
   53 static int ip6_rthdr0 __P((struct mbuf *, struct ip6_hdr *,
   54     struct ip6_rthdr0 *));
   55 
   56 int
   57 route6_input(mp, offp, proto)
   58         struct mbuf **mp;
   59         int *offp, proto;       /* proto is unused */
   60 {
   61         struct ip6_hdr *ip6;
   62         struct mbuf *m = *mp;
   63         struct ip6_rthdr *rh;
   64         int off = *offp, rhlen;
   65 
   66         ip6 = mtod(m, struct ip6_hdr *);
   67         IP6_EXTHDR_GET(rh, struct ip6_rthdr *, m, off, sizeof(*rh));
   68         if (rh == NULL) {
   69                 ip6stat.ip6s_tooshort++;
   70                 return IPPROTO_DONE;
   71         }
   72 
   73         switch (rh->ip6r_type) {
   74         case IPV6_RTHDR_TYPE_0:
   75                 if ((ip6_forwarding && ip6_rht0 == 0) || ip6_rht0 > 0) {
   76                         rhlen = (rh->ip6r_len + 1) << 3;
   77                         /*
   78                          * note on option length:
   79                          * maximum rhlen: 2048
   80                          * max mbuf m_pulldown can handle: MCLBYTES == usually
   81                          * 2048 so, here we are assuming that m_pulldown can
   82                          * handle hlen == 2048 case. This may not be a good
   83                          * thing to assume - we may want to avoid pulling it
   84                          * up altogether.
   85                          */
   86                         IP6_EXTHDR_GET(rh, struct ip6_rthdr *, m, off, rhlen);
   87                         if (rh == NULL) {
   88                                 ip6stat.ip6s_tooshort++;
   89                                 return IPPROTO_DONE;
   90                         }
   91                         if (ip6_rthdr0(m, ip6, (struct ip6_rthdr0 *)rh))
   92                                 return IPPROTO_DONE;
   93                         break;
   94                 }
   95                 /*FALLTHROUGH*/
   96         default:
   97                 /* unknown routing type */
   98                 if (rh->ip6r_segleft == 0) {
   99                         rhlen = (rh->ip6r_len + 1) << 3;
  100                         break;  /* Final dst. Just ignore the header. */
  101                 }
  102                 ip6stat.ip6s_badoptions++;
  103                 icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER,
  104                             (caddr_t)&rh->ip6r_type - (caddr_t)ip6);
  105                 return (IPPROTO_DONE);
  106         }
  107 
  108         *offp += rhlen;
  109         return (rh->ip6r_nxt);
  110 }
  111 
  112 /*
  113  * Type0 routing header processing
  114  *
  115  * RFC2292 backward compatibility warning: no support for strict/loose bitmap,
  116  * as it was dropped between RFC1883 and RFC2460.
  117  */
  118 static int
  119 ip6_rthdr0(m, ip6, rh0)
  120         struct mbuf *m;
  121         struct ip6_hdr *ip6;
  122         struct ip6_rthdr0 *rh0;
  123 {
  124         int addrs, index;
  125         struct in6_addr *nextaddr, tmpaddr;
  126 
  127         if (rh0->ip6r0_segleft == 0)
  128                 return (0);
  129 
  130         if (rh0->ip6r0_len % 2
  131 #ifdef COMPAT_RFC1883
  132             || rh0->ip6r0_len > 46
  133 #endif
  134                 ) {
  135                 /*
  136                  * Type 0 routing header can't contain more than 23 addresses.
  137                  * RFC 2462: this limitation was removed since strict/loose
  138                  * bitmap field was deleted.
  139                  */
  140                 ip6stat.ip6s_badoptions++;
  141                 icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER,
  142                             (caddr_t)&rh0->ip6r0_len - (caddr_t)ip6);
  143                 return (-1);
  144         }
  145 
  146         if ((addrs = rh0->ip6r0_len / 2) < rh0->ip6r0_segleft) {
  147                 ip6stat.ip6s_badoptions++;
  148                 icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER,
  149                             (caddr_t)&rh0->ip6r0_segleft - (caddr_t)ip6);
  150                 return (-1);
  151         }
  152 
  153         index = addrs - rh0->ip6r0_segleft;
  154         rh0->ip6r0_segleft--;
  155         nextaddr = ((struct in6_addr *)(rh0 + 1)) + index;
  156 
  157         /*
  158          * reject invalid addresses.  be proactive about malicious use of
  159          * IPv4 mapped/compat address.
  160          * XXX need more checks?
  161          */
  162         if (IN6_IS_ADDR_MULTICAST(nextaddr) ||
  163             IN6_IS_ADDR_UNSPECIFIED(nextaddr) ||
  164             IN6_IS_ADDR_V4MAPPED(nextaddr) ||
  165             IN6_IS_ADDR_V4COMPAT(nextaddr)) {
  166                 ip6stat.ip6s_badoptions++;
  167                 goto bad;
  168         }
  169         if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) ||
  170             IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_dst) ||
  171             IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst) ||
  172             IN6_IS_ADDR_V4COMPAT(&ip6->ip6_dst)) {
  173                 ip6stat.ip6s_badoptions++;
  174                 goto bad;
  175         }
  176 
  177         /*
  178          * Swap the IPv6 destination address and nextaddr. Forward the packet.
  179          */
  180         tmpaddr = *nextaddr;
  181         *nextaddr = ip6->ip6_dst;
  182         if (IN6_IS_ADDR_LINKLOCAL(nextaddr))
  183                 nextaddr->s6_addr16[1] = 0;
  184         ip6->ip6_dst = tmpaddr;
  185         if (IN6_IS_ADDR_LINKLOCAL(&ip6->ip6_dst))
  186                 ip6->ip6_dst.s6_addr16[1] = htons(m->m_pkthdr.rcvif->if_index);
  187 
  188 #ifdef COMPAT_RFC1883
  189         if (rh0->ip6r0_slmap[index / 8] & (1 << (7 - (index % 8))))
  190                 ip6_forward(m, IPV6_SRCRT_NEIGHBOR);
  191         else
  192                 ip6_forward(m, IPV6_SRCRT_NOTNEIGHBOR);
  193 #else
  194         ip6_forward(m, 1);
  195 #endif
  196 
  197         return (-1);                    /* m would be freed in ip6_forward() */
  198 
  199   bad:
  200         m_freem(m);
  201         return (-1);
  202 }

Cache object: 25d782eeba0c7a8a7205adbd6c428d4d


[ 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.