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 /*      $FreeBSD: src/sys/netinet6/route6.c,v 1.10.4.1.4.1 2007/04/26 23:41:27 cperciva Exp $   */
    2 /*      $KAME: route6.c,v 1.24 2001/03/14 03:07:05 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 "opt_inet.h"
   34 #include "opt_inet6.h"
   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 extern int ip6_rthdr0_allowed;
   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         struct ip6aux *ip6a;
   66 
   67         ip6a = ip6_findaux(m);
   68         if (ip6a) {
   69                 /* XXX reject home-address option before rthdr */
   70                 if (ip6a->ip6a_flags & IP6A_SWAP) {
   71                         ip6stat.ip6s_badoptions++;
   72                         m_freem(m);
   73                         return IPPROTO_DONE;
   74                 }
   75         }
   76 
   77 #ifndef PULLDOWN_TEST
   78         IP6_EXTHDR_CHECK(m, off, sizeof(*rh), IPPROTO_DONE);
   79         ip6 = mtod(m, struct ip6_hdr *);
   80         rh = (struct ip6_rthdr *)((caddr_t)ip6 + off);
   81 #else
   82         ip6 = mtod(m, struct ip6_hdr *);
   83         IP6_EXTHDR_GET(rh, struct ip6_rthdr *, m, off, sizeof(*rh));
   84         if (rh == NULL) {
   85                 ip6stat.ip6s_tooshort++;
   86                 return IPPROTO_DONE;
   87         }
   88 #endif
   89 
   90         switch (rh->ip6r_type) {
   91         case IPV6_RTHDR_TYPE_0:
   92                 if (!ip6_rthdr0_allowed)
   93                         return (IPPROTO_DONE);
   94                 rhlen = (rh->ip6r_len + 1) << 3;
   95 #ifndef PULLDOWN_TEST
   96                 /*
   97                  * note on option length:
   98                  * due to IP6_EXTHDR_CHECK assumption, we cannot handle
   99                  * very big routing header (max rhlen == 2048).
  100                  */
  101                 IP6_EXTHDR_CHECK(m, off, rhlen, IPPROTO_DONE);
  102 #else
  103                 /*
  104                  * note on option length:
  105                  * maximum rhlen: 2048
  106                  * max mbuf m_pulldown can handle: MCLBYTES == usually 2048
  107                  * so, here we are assuming that m_pulldown can handle
  108                  * rhlen == 2048 case.  this may not be a good thing to
  109                  * assume - we may want to avoid pulling it up altogether.
  110                  */
  111                 IP6_EXTHDR_GET(rh, struct ip6_rthdr *, m, off, rhlen);
  112                 if (rh == NULL) {
  113                         ip6stat.ip6s_tooshort++;
  114                         return IPPROTO_DONE;
  115                 }
  116 #endif
  117                 if (ip6_rthdr0(m, ip6, (struct ip6_rthdr0 *)rh))
  118                         return (IPPROTO_DONE);
  119                 break;
  120         default:
  121                 /* unknown routing type */
  122                 if (rh->ip6r_segleft == 0) {
  123                         rhlen = (rh->ip6r_len + 1) << 3;
  124                         break;  /* Final dst. Just ignore the header. */
  125                 }
  126                 ip6stat.ip6s_badoptions++;
  127                 icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER,
  128                             (caddr_t)&rh->ip6r_type - (caddr_t)ip6);
  129                 return (IPPROTO_DONE);
  130         }
  131 
  132         *offp += rhlen;
  133         return (rh->ip6r_nxt);
  134 }
  135 
  136 /*
  137  * Type0 routing header processing
  138  *
  139  * RFC2292 backward compatibility warning: no support for strict/loose bitmap,
  140  * as it was dropped between RFC1883 and RFC2460.
  141  */
  142 static int
  143 ip6_rthdr0(m, ip6, rh0)
  144         struct mbuf *m;
  145         struct ip6_hdr *ip6;
  146         struct ip6_rthdr0 *rh0;
  147 {
  148         int addrs, index;
  149         struct in6_addr *nextaddr, tmpaddr;
  150 
  151         if (rh0->ip6r0_segleft == 0)
  152                 return (0);
  153 
  154         if (rh0->ip6r0_len % 2
  155 #ifdef COMPAT_RFC1883
  156             || rh0->ip6r0_len > 46
  157 #endif
  158                 ) {
  159                 /*
  160                  * Type 0 routing header can't contain more than 23 addresses.
  161                  * RFC 2462: this limitation was removed since strict/loose
  162                  * bitmap field was deleted.
  163                  */
  164                 ip6stat.ip6s_badoptions++;
  165                 icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER,
  166                             (caddr_t)&rh0->ip6r0_len - (caddr_t)ip6);
  167                 return (-1);
  168         }
  169 
  170         if ((addrs = rh0->ip6r0_len / 2) < rh0->ip6r0_segleft) {
  171                 ip6stat.ip6s_badoptions++;
  172                 icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER,
  173                             (caddr_t)&rh0->ip6r0_segleft - (caddr_t)ip6);
  174                 return (-1);
  175         }
  176 
  177         index = addrs - rh0->ip6r0_segleft;
  178         rh0->ip6r0_segleft--;
  179         nextaddr = ((struct in6_addr *)(rh0 + 1)) + index;
  180 
  181         /*
  182          * reject invalid addresses.  be proactive about malicious use of
  183          * IPv4 mapped/compat address.
  184          * XXX need more checks?
  185          */
  186         if (IN6_IS_ADDR_MULTICAST(nextaddr) ||
  187             IN6_IS_ADDR_UNSPECIFIED(nextaddr) ||
  188             IN6_IS_ADDR_V4MAPPED(nextaddr) ||
  189             IN6_IS_ADDR_V4COMPAT(nextaddr)) {
  190                 ip6stat.ip6s_badoptions++;
  191                 m_freem(m);
  192                 return (-1);
  193         }
  194         if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) ||
  195             IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_dst) ||
  196             IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst) ||
  197             IN6_IS_ADDR_V4COMPAT(&ip6->ip6_dst)) {
  198                 ip6stat.ip6s_badoptions++;
  199                 m_freem(m);
  200                 return (-1);
  201         }
  202 
  203         /*
  204          * Swap the IPv6 destination address and nextaddr. Forward the packet.
  205          */
  206         tmpaddr = *nextaddr;
  207         *nextaddr = ip6->ip6_dst;
  208         if (IN6_IS_ADDR_LINKLOCAL(nextaddr))
  209                 nextaddr->s6_addr16[1] = 0;
  210         ip6->ip6_dst = tmpaddr;
  211         if (IN6_IS_ADDR_LINKLOCAL(&ip6->ip6_dst))
  212                 ip6->ip6_dst.s6_addr16[1] = htons(m->m_pkthdr.rcvif->if_index);
  213 
  214 #ifdef COMPAT_RFC1883
  215         if (rh0->ip6r0_slmap[index / 8] & (1 << (7 - (index % 8))))
  216                 ip6_forward(m, IPV6_SRCRT_NEIGHBOR);
  217         else
  218                 ip6_forward(m, IPV6_SRCRT_NOTNEIGHBOR);
  219 #else
  220         ip6_forward(m, 1);
  221 #endif
  222 
  223         return (-1);                    /* m would be freed in ip6_forward() */
  224 }

Cache object: d4d81b8ba2dd3811fab4225a8ee60e47


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