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

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

Version: -  FREEBSD  -  FREEBSD10  -  FREEBSD9  -  FREEBSD92  -  FREEBSD91  -  FREEBSD90  -  FREEBSD8  -  FREEBSD82  -  FREEBSD81  -  FREEBSD80  -  FREEBSD7  -  FREEBSD74  -  FREEBSD73  -  FREEBSD72  -  FREEBSD71  -  FREEBSD70  -  FREEBSD6  -  FREEBSD64  -  FREEBSD63  -  FREEBSD62  -  FREEBSD61  -  FREEBSD60  -  FREEBSD5  -  FREEBSD55  -  FREEBSD54  -  FREEBSD53  -  FREEBSD52  -  FREEBSD51  -  FREEBSD50  -  FREEBSD4  -  FREEBSD3  -  FREEBSD22  -  cheribsd  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1  -  FREEBSD-LIBC  -  FREEBSD8-LIBC  -  FREEBSD7-LIBC  -  FREEBSD6-LIBC  -  GLIBC27 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: ip6_input.c,v 1.90.2.3 2007/09/16 15:34:59 xtraeme Exp $       */
    2 /*      $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 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 /*
   34  * Copyright (c) 1982, 1986, 1988, 1993
   35  *      The Regents of the University of California.  All rights reserved.
   36  *
   37  * Redistribution and use in source and binary forms, with or without
   38  * modification, are permitted provided that the following conditions
   39  * are met:
   40  * 1. Redistributions of source code must retain the above copyright
   41  *    notice, this list of conditions and the following disclaimer.
   42  * 2. Redistributions in binary form must reproduce the above copyright
   43  *    notice, this list of conditions and the following disclaimer in the
   44  *    documentation and/or other materials provided with the distribution.
   45  * 3. Neither the name of the University nor the names of its contributors
   46  *    may be used to endorse or promote products derived from this software
   47  *    without specific prior written permission.
   48  *
   49  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   50  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   51  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   52  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   53  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   54  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   55  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   56  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   57  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   58  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   59  * SUCH DAMAGE.
   60  *
   61  *      @(#)ip_input.c  8.2 (Berkeley) 1/4/94
   62  */
   63 
   64 #include <sys/cdefs.h>
   65 __KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.90.2.3 2007/09/16 15:34:59 xtraeme Exp $");
   66 
   67 #include "opt_inet.h"
   68 #include "opt_inet6.h"
   69 #include "opt_ipsec.h"
   70 #include "opt_pfil_hooks.h"
   71 
   72 #include <sys/param.h>
   73 #include <sys/systm.h>
   74 #include <sys/malloc.h>
   75 #include <sys/mbuf.h>
   76 #include <sys/domain.h>
   77 #include <sys/protosw.h>
   78 #include <sys/socket.h>
   79 #include <sys/socketvar.h>
   80 #include <sys/errno.h>
   81 #include <sys/time.h>
   82 #include <sys/kernel.h>
   83 #include <sys/syslog.h>
   84 #include <sys/proc.h>
   85 #include <sys/sysctl.h>
   86 
   87 #include <net/if.h>
   88 #include <net/if_types.h>
   89 #include <net/if_dl.h>
   90 #include <net/route.h>
   91 #include <net/netisr.h>
   92 #ifdef PFIL_HOOKS
   93 #include <net/pfil.h>
   94 #endif
   95 
   96 #include <netinet/in.h>
   97 #include <netinet/in_systm.h>
   98 #ifdef INET
   99 #include <netinet/ip.h>
  100 #include <netinet/ip_icmp.h>
  101 #endif /* INET */
  102 #include <netinet/ip6.h>
  103 #include <netinet6/in6_var.h>
  104 #include <netinet6/ip6_var.h>
  105 #include <netinet6/in6_pcb.h>
  106 #include <netinet/icmp6.h>
  107 #include <netinet6/scope6_var.h>
  108 #include <netinet6/in6_ifattach.h>
  109 #include <netinet6/nd6.h>
  110 
  111 #ifdef IPSEC
  112 #include <netinet6/ipsec.h>
  113 #endif
  114 
  115 #ifdef FAST_IPSEC
  116 #include <netipsec/ipsec.h>
  117 #include <netipsec/ipsec6.h>
  118 #include <netipsec/key.h>
  119 #endif /* FAST_IPSEC */
  120 
  121 #include <netinet6/ip6protosw.h>
  122 
  123 #include "faith.h"
  124 #include "gif.h"
  125 
  126 #if NGIF > 0
  127 #include <netinet6/in6_gif.h>
  128 #endif
  129 
  130 #include <net/net_osdep.h>
  131 
  132 extern struct domain inet6domain;
  133 
  134 u_char ip6_protox[IPPROTO_MAX];
  135 static int ip6qmaxlen = IFQ_MAXLEN;
  136 struct in6_ifaddr *in6_ifaddr;
  137 struct ifqueue ip6intrq;
  138 
  139 extern struct callout in6_tmpaddrtimer_ch;
  140 
  141 int ip6_forward_srcrt;                  /* XXX */
  142 int ip6_sourcecheck;                    /* XXX */
  143 int ip6_sourcecheck_interval;           /* XXX */
  144 
  145 #ifdef PFIL_HOOKS
  146 struct pfil_head inet6_pfil_hook;
  147 #endif
  148 
  149 struct ip6stat ip6stat;
  150 
  151 static void ip6_init2 __P((void *));
  152 static struct m_tag *ip6_setdstifaddr __P((struct mbuf *, struct in6_ifaddr *));
  153 
  154 static int ip6_hopopts_input __P((u_int32_t *, u_int32_t *, struct mbuf **, int *));
  155 static struct mbuf *ip6_pullexthdr __P((struct mbuf *, size_t, int));
  156 
  157 /*
  158  * IP6 initialization: fill in IP6 protocol switch table.
  159  * All protocols not implemented in kernel go to raw IP6 protocol handler.
  160  */
  161 void
  162 ip6_init()
  163 {
  164         const struct ip6protosw *pr;
  165         int i;
  166 
  167         pr = (const struct ip6protosw *)pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW);
  168         if (pr == 0)
  169                 panic("ip6_init");
  170         for (i = 0; i < IPPROTO_MAX; i++)
  171                 ip6_protox[i] = pr - inet6sw;
  172         for (pr = (const struct ip6protosw *)inet6domain.dom_protosw;
  173             pr < (const struct ip6protosw *)inet6domain.dom_protoswNPROTOSW; pr++)
  174                 if (pr->pr_domain->dom_family == PF_INET6 &&
  175                     pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW)
  176                         ip6_protox[pr->pr_protocol] = pr - inet6sw;
  177         ip6intrq.ifq_maxlen = ip6qmaxlen;
  178         scope6_init();
  179         addrsel_policy_init();
  180         nd6_init();
  181         frag6_init();
  182         ip6_desync_factor = arc4random() % MAX_TEMP_DESYNC_FACTOR;
  183 
  184         ip6_init2((void *)0);
  185 
  186 #ifdef PFIL_HOOKS
  187         /* Register our Packet Filter hook. */
  188         inet6_pfil_hook.ph_type = PFIL_TYPE_AF;
  189         inet6_pfil_hook.ph_af   = AF_INET6;
  190         i = pfil_head_register(&inet6_pfil_hook);
  191         if (i != 0)
  192                 printf("ip6_init: WARNING: unable to register pfil hook, "
  193                     "error %d\n", i);
  194 #endif /* PFIL_HOOKS */
  195 }
  196 
  197 static void
  198 ip6_init2(void *dummy)
  199 {
  200 
  201         /* nd6_timer_init */
  202         callout_init(&nd6_timer_ch);
  203         callout_reset(&nd6_timer_ch, hz, nd6_timer, NULL);
  204 
  205         /* timer for regeneranation of temporary addresses randomize ID */
  206         callout_init(&in6_tmpaddrtimer_ch);
  207         callout_reset(&in6_tmpaddrtimer_ch,
  208                       (ip6_temp_preferred_lifetime - ip6_desync_factor -
  209                        ip6_temp_regen_advance) * hz,
  210                       in6_tmpaddrtimer, NULL);
  211 }
  212 
  213 /*
  214  * IP6 input interrupt handling. Just pass the packet to ip6_input.
  215  */
  216 void
  217 ip6intr()
  218 {
  219         int s;
  220         struct mbuf *m;
  221 
  222         for (;;) {
  223                 s = splnet();
  224                 IF_DEQUEUE(&ip6intrq, m);
  225                 splx(s);
  226                 if (m == 0)
  227                         return;
  228                 /* drop the packet if IPv6 operation is disabled on the IF */
  229                 if ((ND_IFINFO(m->m_pkthdr.rcvif)->flags & ND6_IFF_IFDISABLED)) {
  230                         m_freem(m);
  231                         return;
  232                 }
  233                 ip6_input(m);
  234         }
  235 }
  236 
  237 extern struct   route_in6 ip6_forward_rt;
  238 
  239 void
  240 ip6_input(m)
  241         struct mbuf *m;
  242 {
  243         struct ip6_hdr *ip6;
  244         int off = sizeof(struct ip6_hdr), nest;
  245         u_int32_t plen;
  246         u_int32_t rtalert = ~0;
  247         int nxt, ours = 0;
  248         struct ifnet *deliverifp = NULL;
  249         int srcrt = 0;
  250 #ifdef FAST_IPSEC
  251         struct m_tag *mtag;
  252         struct tdb_ident *tdbi;
  253         struct secpolicy *sp;
  254         int s, error;
  255 #endif
  256 
  257 #ifdef IPSEC
  258         /*
  259          * should the inner packet be considered authentic?
  260          * see comment in ah4_input().
  261          */
  262         m->m_flags &= ~M_AUTHIPHDR;
  263         m->m_flags &= ~M_AUTHIPDGM;
  264 #endif
  265 
  266         /*
  267          * make sure we don't have onion peering information into m_tag.
  268          */
  269         ip6_delaux(m);
  270 
  271         /*
  272          * mbuf statistics
  273          */
  274         if (m->m_flags & M_EXT) {
  275                 if (m->m_next)
  276                         ip6stat.ip6s_mext2m++;
  277                 else
  278                         ip6stat.ip6s_mext1++;
  279         } else {
  280 #define M2MMAX  (sizeof(ip6stat.ip6s_m2m)/sizeof(ip6stat.ip6s_m2m[0]))
  281                 if (m->m_next) {
  282                         if (m->m_flags & M_LOOP) {
  283                                 ip6stat.ip6s_m2m[lo0ifp->if_index]++; /* XXX */
  284                         } else if (m->m_pkthdr.rcvif->if_index < M2MMAX)
  285                                 ip6stat.ip6s_m2m[m->m_pkthdr.rcvif->if_index]++;
  286                         else
  287                                 ip6stat.ip6s_m2m[0]++;
  288                 } else
  289                         ip6stat.ip6s_m1++;
  290 #undef M2MMAX
  291         }
  292 
  293         in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_receive);
  294         ip6stat.ip6s_total++;
  295 
  296         /*
  297          * If the IPv6 header is not aligned, slurp it up into a new
  298          * mbuf with space for link headers, in the event we forward
  299          * it.  Otherwise, if it is aligned, make sure the entire base
  300          * IPv6 header is in the first mbuf of the chain.
  301          */
  302         if (IP6_HDR_ALIGNED_P(mtod(m, caddr_t)) == 0) {
  303                 struct ifnet *inifp = m->m_pkthdr.rcvif;
  304                 if ((m = m_copyup(m, sizeof(struct ip6_hdr),
  305                                   (max_linkhdr + 3) & ~3)) == NULL) {
  306                         /* XXXJRT new stat, please */
  307                         ip6stat.ip6s_toosmall++;
  308                         in6_ifstat_inc(inifp, ifs6_in_hdrerr);
  309                         return;
  310                 }
  311         } else if (__predict_false(m->m_len < sizeof(struct ip6_hdr))) {
  312                 struct ifnet *inifp = m->m_pkthdr.rcvif;
  313                 if ((m = m_pullup(m, sizeof(struct ip6_hdr))) == NULL) {
  314                         ip6stat.ip6s_toosmall++;
  315                         in6_ifstat_inc(inifp, ifs6_in_hdrerr);
  316                         return;
  317                 }
  318         }
  319 
  320         ip6 = mtod(m, struct ip6_hdr *);
  321 
  322         if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) {
  323                 ip6stat.ip6s_badvers++;
  324                 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr);
  325                 goto bad;
  326         }
  327 
  328 #ifdef PFIL_HOOKS
  329         /*
  330          * Run through list of hooks for input packets.  If there are any
  331          * filters which require that additional packets in the flow are
  332          * not fast-forwarded, they must clear the M_CANFASTFWD flag.
  333          * Note that filters must _never_ set this flag, as another filter
  334          * in the list may have previously cleared it.
  335          */
  336         /*
  337          * let ipfilter look at packet on the wire,
  338          * not the decapsulated packet.
  339          */
  340 #ifdef IPSEC
  341         if (!ipsec_getnhist(m))
  342 #elif defined(FAST_IPSEC)
  343         if (!ipsec_indone(m))
  344 #else
  345         if (1)
  346 #endif
  347         {
  348                 struct in6_addr odst;
  349 
  350                 odst = ip6->ip6_dst;
  351                 if (pfil_run_hooks(&inet6_pfil_hook, &m, m->m_pkthdr.rcvif,
  352                                    PFIL_IN) != 0)
  353                         return;
  354                 if (m == NULL)
  355                         return;
  356                 ip6 = mtod(m, struct ip6_hdr *);
  357                 srcrt = !IN6_ARE_ADDR_EQUAL(&odst, &ip6->ip6_dst);
  358         }
  359 #endif /* PFIL_HOOKS */
  360 
  361         ip6stat.ip6s_nxthist[ip6->ip6_nxt]++;
  362 
  363 #ifdef ALTQ
  364         if (altq_input != NULL && (*altq_input)(m, AF_INET6) == 0) {
  365                 /* packet is dropped by traffic conditioner */
  366                 return;
  367         }
  368 #endif
  369 
  370         /*
  371          * Check against address spoofing/corruption.
  372          */
  373         if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_src) ||
  374             IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_dst)) {
  375                 /*
  376                  * XXX: "badscope" is not very suitable for a multicast source.
  377                  */
  378                 ip6stat.ip6s_badscope++;
  379                 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
  380                 goto bad;
  381         }
  382         /*
  383          * The following check is not documented in specs.  A malicious
  384          * party may be able to use IPv4 mapped addr to confuse tcp/udp stack
  385          * and bypass security checks (act as if it was from 127.0.0.1 by using
  386          * IPv6 src ::ffff:127.0.0.1).  Be cautious.
  387          *
  388          * This check chokes if we are in an SIIT cloud.  As none of BSDs
  389          * support IPv4-less kernel compilation, we cannot support SIIT
  390          * environment at all.  So, it makes more sense for us to reject any
  391          * malicious packets for non-SIIT environment, than try to do a
  392          * partial support for SIIT environment.
  393          */
  394         if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) ||
  395             IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) {
  396                 ip6stat.ip6s_badscope++;
  397                 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
  398                 goto bad;
  399         }
  400 #if 0
  401         /*
  402          * Reject packets with IPv4 compatible addresses (auto tunnel).
  403          *
  404          * The code forbids auto tunnel relay case in RFC1933 (the check is
  405          * stronger than RFC1933).  We may want to re-enable it if mech-xx
  406          * is revised to forbid relaying case.
  407          */
  408         if (IN6_IS_ADDR_V4COMPAT(&ip6->ip6_src) ||
  409             IN6_IS_ADDR_V4COMPAT(&ip6->ip6_dst)) {
  410                 ip6stat.ip6s_badscope++;
  411                 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
  412                 goto bad;
  413         }
  414 #endif
  415 
  416         /*
  417          * Disambiguate address scope zones (if there is ambiguity).
  418          * We first make sure that the original source or destination address
  419          * is not in our internal form for scoped addresses.  Such addresses
  420          * are not necessarily invalid spec-wise, but we cannot accept them due
  421          * to the usage conflict.
  422          * in6_setscope() then also checks and rejects the cases where src or
  423          * dst are the loopback address and the receiving interface
  424          * is not loopback. 
  425          */
  426         if (__predict_false(
  427             m_makewritable(&m, 0, sizeof(struct ip6_hdr), M_DONTWAIT)))
  428                 goto bad;
  429         ip6 = mtod(m, struct ip6_hdr *);
  430         if (in6_clearscope(&ip6->ip6_src) || in6_clearscope(&ip6->ip6_dst)) {
  431                 ip6stat.ip6s_badscope++; /* XXX */
  432                 goto bad;
  433         }
  434         if (in6_setscope(&ip6->ip6_src, m->m_pkthdr.rcvif, NULL) ||
  435             in6_setscope(&ip6->ip6_dst, m->m_pkthdr.rcvif, NULL)) {
  436                 ip6stat.ip6s_badscope++;
  437                 goto bad;
  438         }
  439 
  440         /*
  441          * Multicast check
  442          */
  443         if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
  444                 struct  in6_multi *in6m = 0;
  445 
  446                 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mcast);
  447                 /*
  448                  * See if we belong to the destination multicast group on the
  449                  * arrival interface.
  450                  */
  451                 IN6_LOOKUP_MULTI(ip6->ip6_dst, m->m_pkthdr.rcvif, in6m);
  452                 if (in6m)
  453                         ours = 1;
  454                 else if (!ip6_mrouter) {
  455                         ip6stat.ip6s_notmember++;
  456                         ip6stat.ip6s_cantforward++;
  457                         in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
  458                         goto bad;
  459                 }
  460                 deliverifp = m->m_pkthdr.rcvif;
  461                 goto hbhcheck;
  462         }
  463 
  464         /*
  465          *  Unicast check
  466          */
  467         if (ip6_forward_rt.ro_rt != NULL &&
  468             (ip6_forward_rt.ro_rt->rt_flags & RTF_UP) != 0 &&
  469             IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst,
  470             &((struct sockaddr_in6 *)(&ip6_forward_rt.ro_dst))->sin6_addr))
  471                 ip6stat.ip6s_forward_cachehit++;
  472         else {
  473                 struct sockaddr_in6 *dst6;
  474 
  475                 if (ip6_forward_rt.ro_rt) {
  476                         /* route is down or destination is different */
  477                         ip6stat.ip6s_forward_cachemiss++;
  478                         RTFREE(ip6_forward_rt.ro_rt);
  479                         ip6_forward_rt.ro_rt = 0;
  480                 }
  481 
  482                 bzero(&ip6_forward_rt.ro_dst, sizeof(struct sockaddr_in6));
  483                 dst6 = (struct sockaddr_in6 *)&ip6_forward_rt.ro_dst;
  484                 dst6->sin6_len = sizeof(struct sockaddr_in6);
  485                 dst6->sin6_family = AF_INET6;
  486                 dst6->sin6_addr = ip6->ip6_dst;
  487 
  488                 rtalloc((struct route *)&ip6_forward_rt);
  489         }
  490 
  491 #define rt6_key(r) ((struct sockaddr_in6 *)((r)->rt_nodes->rn_key))
  492 
  493         /*
  494          * Accept the packet if the forwarding interface to the destination
  495          * according to the routing table is the loopback interface,
  496          * unless the associated route has a gateway.
  497          * Note that this approach causes to accept a packet if there is a
  498          * route to the loopback interface for the destination of the packet.
  499          * But we think it's even useful in some situations, e.g. when using
  500          * a special daemon which wants to intercept the packet.
  501          */
  502         if (ip6_forward_rt.ro_rt &&
  503             (ip6_forward_rt.ro_rt->rt_flags &
  504              (RTF_HOST|RTF_GATEWAY)) == RTF_HOST &&
  505             !(ip6_forward_rt.ro_rt->rt_flags & RTF_CLONED) &&
  506 #if 0
  507             /*
  508              * The check below is redundant since the comparison of
  509              * the destination and the key of the rtentry has
  510              * already done through looking up the routing table.
  511              */
  512             IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst,
  513             &rt6_key(ip6_forward_rt.ro_rt)->sin6_addr) &&
  514 #endif
  515             ip6_forward_rt.ro_rt->rt_ifp->if_type == IFT_LOOP) {
  516                 struct in6_ifaddr *ia6 =
  517                         (struct in6_ifaddr *)ip6_forward_rt.ro_rt->rt_ifa;
  518                 if (ia6->ia6_flags & IN6_IFF_ANYCAST)
  519                         m->m_flags |= M_ANYCAST6;
  520                 /*
  521                  * packets to a tentative, duplicated, or somehow invalid
  522                  * address must not be accepted.
  523                  */
  524                 if (!(ia6->ia6_flags & IN6_IFF_NOTREADY)) {
  525                         /* this address is ready */
  526                         ours = 1;
  527                         deliverifp = ia6->ia_ifp;       /* correct? */
  528                         goto hbhcheck;
  529                 } else {
  530                         /* address is not ready, so discard the packet. */
  531                         nd6log((LOG_INFO,
  532                             "ip6_input: packet to an unready address %s->%s\n",
  533                             ip6_sprintf(&ip6->ip6_src),
  534                             ip6_sprintf(&ip6->ip6_dst)));
  535 
  536                         goto bad;
  537                 }
  538         }
  539 
  540         /*
  541          * FAITH (Firewall Aided Internet Translator)
  542          */
  543 #if defined(NFAITH) && 0 < NFAITH
  544         if (ip6_keepfaith) {
  545                 if (ip6_forward_rt.ro_rt && ip6_forward_rt.ro_rt->rt_ifp &&
  546                     ip6_forward_rt.ro_rt->rt_ifp->if_type == IFT_FAITH) {
  547                         /* XXX do we need more sanity checks? */
  548                         ours = 1;
  549                         deliverifp = ip6_forward_rt.ro_rt->rt_ifp; /* faith */
  550                         goto hbhcheck;
  551                 }
  552         }
  553 #endif
  554 
  555 #if 0
  556     {
  557         /*
  558          * Last resort: check in6_ifaddr for incoming interface.
  559          * The code is here until I update the "goto ours hack" code above
  560          * working right.
  561          */
  562         struct ifaddr *ifa;
  563         for (ifa = m->m_pkthdr.rcvif->if_addrlist.tqh_first;
  564              ifa;
  565              ifa = ifa->ifa_list.tqe_next) {
  566                 if (ifa->ifa_addr == NULL)
  567                         continue;       /* just for safety */
  568                 if (ifa->ifa_addr->sa_family != AF_INET6)
  569                         continue;
  570                 if (IN6_ARE_ADDR_EQUAL(IFA_IN6(ifa), &ip6->ip6_dst)) {
  571                         ours = 1;
  572                         deliverifp = ifa->ifa_ifp;
  573                         goto hbhcheck;
  574                 }
  575         }
  576     }
  577 #endif
  578 
  579         /*
  580          * Now there is no reason to process the packet if it's not our own
  581          * and we're not a router.
  582          */
  583         if (!ip6_forwarding) {
  584                 ip6stat.ip6s_cantforward++;
  585                 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
  586                 goto bad;
  587         }
  588 
  589   hbhcheck:
  590         /*
  591          * record address information into m_tag, if we don't have one yet.
  592          * note that we are unable to record it, if the address is not listed
  593          * as our interface address (e.g. multicast addresses, addresses
  594          * within FAITH prefixes and such).
  595          */
  596         if (deliverifp && !ip6_getdstifaddr(m)) {
  597                 struct in6_ifaddr *ia6;
  598 
  599                 ia6 = in6_ifawithifp(deliverifp, &ip6->ip6_dst);
  600                 if (ia6) {
  601                         if (!ip6_setdstifaddr(m, ia6)) {
  602                                 /*
  603                                  * XXX maybe we should drop the packet here,
  604                                  * as we could not provide enough information
  605                                  * to the upper layers.
  606                                  */
  607                         }
  608                 }
  609         }
  610 
  611         /*
  612          * Process Hop-by-Hop options header if it's contained.
  613          * m may be modified in ip6_hopopts_input().
  614          * If a JumboPayload option is included, plen will also be modified.
  615          */
  616         plen = (u_int32_t)ntohs(ip6->ip6_plen);
  617         if (ip6->ip6_nxt == IPPROTO_HOPOPTS) {
  618                 struct ip6_hbh *hbh;
  619 
  620                 if (ip6_hopopts_input(&plen, &rtalert, &m, &off)) {
  621 #if 0   /*touches NULL pointer*/
  622                         in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
  623 #endif
  624                         return; /* m have already been freed */
  625                 }
  626 
  627                 /* adjust pointer */
  628                 ip6 = mtod(m, struct ip6_hdr *);
  629 
  630                 /*
  631                  * if the payload length field is 0 and the next header field
  632                  * indicates Hop-by-Hop Options header, then a Jumbo Payload
  633                  * option MUST be included.
  634                  */
  635                 if (ip6->ip6_plen == 0 && plen == 0) {
  636                         /*
  637                          * Note that if a valid jumbo payload option is
  638                          * contained, ip6_hopopts_input() must set a valid
  639                          * (non-zero) payload length to the variable plen.
  640                          */
  641                         ip6stat.ip6s_badoptions++;
  642                         in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
  643                         in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr);
  644                         icmp6_error(m, ICMP6_PARAM_PROB,
  645                                     ICMP6_PARAMPROB_HEADER,
  646                                     (caddr_t)&ip6->ip6_plen - (caddr_t)ip6);
  647                         return;
  648                 }
  649                 IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr),
  650                         sizeof(struct ip6_hbh));
  651                 if (hbh == NULL) {
  652                         ip6stat.ip6s_tooshort++;
  653                         return;
  654                 }
  655                 KASSERT(IP6_HDR_ALIGNED_P(hbh));
  656                 nxt = hbh->ip6h_nxt;
  657 
  658                 /*
  659                  * accept the packet if a router alert option is included
  660                  * and we act as an IPv6 router.
  661                  */
  662                 if (rtalert != ~0 && ip6_forwarding)
  663                         ours = 1;
  664         } else
  665                 nxt = ip6->ip6_nxt;
  666 
  667         /*
  668          * Check that the amount of data in the buffers
  669          * is as at least much as the IPv6 header would have us expect.
  670          * Trim mbufs if longer than we expect.
  671          * Drop packet if shorter than we expect.
  672          */
  673         if (m->m_pkthdr.len - sizeof(struct ip6_hdr) < plen) {
  674                 ip6stat.ip6s_tooshort++;
  675                 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated);
  676                 goto bad;
  677         }
  678         if (m->m_pkthdr.len > sizeof(struct ip6_hdr) + plen) {
  679                 if (m->m_len == m->m_pkthdr.len) {
  680                         m->m_len = sizeof(struct ip6_hdr) + plen;
  681                         m->m_pkthdr.len = sizeof(struct ip6_hdr) + plen;
  682                 } else
  683                         m_adj(m, sizeof(struct ip6_hdr) + plen - m->m_pkthdr.len);
  684         }
  685 
  686         /*
  687          * Forward if desirable.
  688          */
  689         if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
  690                 /*
  691                  * If we are acting as a multicast router, all
  692                  * incoming multicast packets are passed to the
  693                  * kernel-level multicast forwarding function.
  694                  * The packet is returned (relatively) intact; if
  695                  * ip6_mforward() returns a non-zero value, the packet
  696                  * must be discarded, else it may be accepted below.
  697                  */
  698                 if (ip6_mrouter && ip6_mforward(ip6, m->m_pkthdr.rcvif, m)) {
  699                         ip6stat.ip6s_cantforward++;
  700                         m_freem(m);
  701                         return;
  702                 }
  703                 if (!ours) {
  704                         m_freem(m);
  705                         return;
  706                 }
  707         } else if (!ours) {
  708                 ip6_forward(m, srcrt);
  709                 return;
  710         }
  711 
  712         ip6 = mtod(m, struct ip6_hdr *);
  713 
  714         /*
  715          * Malicious party may be able to use IPv4 mapped addr to confuse
  716          * tcp/udp stack and bypass security checks (act as if it was from
  717          * 127.0.0.1 by using IPv6 src ::ffff:127.0.0.1).  Be cautious.
  718          *
  719          * For SIIT end node behavior, you may want to disable the check.
  720          * However, you will  become vulnerable to attacks using IPv4 mapped
  721          * source.
  722          */
  723         if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) ||
  724             IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) {
  725                 ip6stat.ip6s_badscope++;
  726                 in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
  727                 goto bad;
  728         }
  729 
  730         /*
  731          * Tell launch routine the next header
  732          */
  733 #ifdef IFA_STATS
  734         if (deliverifp != NULL) {
  735                 struct in6_ifaddr *ia6;
  736                 ia6 = in6_ifawithifp(deliverifp, &ip6->ip6_dst);
  737                 if (ia6)
  738                         ia6->ia_ifa.ifa_data.ifad_inbytes += m->m_pkthdr.len;
  739         }
  740 #endif
  741         ip6stat.ip6s_delivered++;
  742         in6_ifstat_inc(deliverifp, ifs6_in_deliver);
  743         nest = 0;
  744 
  745         while (nxt != IPPROTO_DONE) {
  746                 if (ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) {
  747                         ip6stat.ip6s_toomanyhdr++;
  748                         goto bad;
  749                 }
  750 
  751                 /*
  752                  * protection against faulty packet - there should be
  753                  * more sanity checks in header chain processing.
  754                  */
  755                 if (m->m_pkthdr.len < off) {
  756                         ip6stat.ip6s_tooshort++;
  757                         in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated);
  758                         goto bad;
  759                 }
  760 
  761 #ifdef IPSEC
  762                 /*
  763                  * enforce IPsec policy checking if we are seeing last header.
  764                  * note that we do not visit this with protocols with pcb layer
  765                  * code - like udp/tcp/raw ip.
  766                  */
  767                 if ((inet6sw[ip6_protox[nxt]].pr_flags & PR_LASTHDR) != 0 &&
  768                     ipsec6_in_reject(m, NULL)) {
  769                         ipsec6stat.in_polvio++;
  770                         goto bad;
  771                 }
  772 #endif
  773 #ifdef FAST_IPSEC
  774         /*
  775          * enforce IPsec policy checking if we are seeing last header.
  776          * note that we do not visit this with protocols with pcb layer
  777          * code - like udp/tcp/raw ip.
  778          */
  779         if ((inet6sw[ip_protox[nxt]].pr_flags & PR_LASTHDR) != 0) {
  780                 /*
  781                  * Check if the packet has already had IPsec processing
  782                  * done.  If so, then just pass it along.  This tag gets
  783                  * set during AH, ESP, etc. input handling, before the
  784                  * packet is returned to the ip input queue for delivery.
  785                  */
  786                 mtag = m_tag_find(m, PACKET_TAG_IPSEC_IN_DONE, NULL);
  787                 s = splsoftnet();
  788                 if (mtag != NULL) {
  789                         tdbi = (struct tdb_ident *)(mtag + 1);
  790                         sp = ipsec_getpolicy(tdbi, IPSEC_DIR_INBOUND);
  791                 } else {
  792                         sp = ipsec_getpolicybyaddr(m, IPSEC_DIR_INBOUND,
  793                                                                         IP_FORWARDING, &error);
  794                 }
  795                 if (sp != NULL) {
  796                         /*
  797                          * Check security policy against packet attributes.
  798                          */
  799                         error = ipsec_in_reject(sp, m);
  800                         KEY_FREESP(&sp);
  801                 } else {
  802                         /* XXX error stat??? */
  803                         error = EINVAL;
  804                         DPRINTF(("ip6_input: no SP, packet discarded\n"));/*XXX*/
  805                 }
  806                 splx(s);
  807                 if (error)
  808                         goto bad;
  809         }
  810 #endif /* FAST_IPSEC */
  811 
  812 
  813                 nxt = (*inet6sw[ip6_protox[nxt]].pr_input)(&m, &off, nxt);
  814         }
  815         return;
  816  bad:
  817         m_freem(m);
  818 }
  819 
  820 /*
  821  * set/grab in6_ifaddr correspond to IPv6 destination address.
  822  */
  823 static struct m_tag *
  824 ip6_setdstifaddr(m, ia6)
  825         struct mbuf *m;
  826         struct in6_ifaddr *ia6;
  827 {
  828         struct m_tag *mtag;
  829 
  830         mtag = ip6_addaux(m);
  831         if (mtag)
  832                 ((struct ip6aux *)(mtag + 1))->ip6a_dstia6 = ia6;
  833         return mtag;    /* NULL if failed to set */
  834 }
  835 
  836 struct in6_ifaddr *
  837 ip6_getdstifaddr(m)
  838         struct mbuf *m;
  839 {
  840         struct m_tag *mtag;
  841 
  842         mtag = ip6_findaux(m);
  843         if (mtag)
  844                 return ((struct ip6aux *)(mtag + 1))->ip6a_dstia6;
  845         else
  846                 return NULL;
  847 }
  848 
  849 /*
  850  * Hop-by-Hop options header processing. If a valid jumbo payload option is
  851  * included, the real payload length will be stored in plenp.
  852  */
  853 static int
  854 ip6_hopopts_input(plenp, rtalertp, mp, offp)
  855         u_int32_t *plenp;
  856         u_int32_t *rtalertp;    /* XXX: should be stored more smart way */
  857         struct mbuf **mp;
  858         int *offp;
  859 {
  860         struct mbuf *m = *mp;
  861         int off = *offp, hbhlen;
  862         struct ip6_hbh *hbh;
  863 
  864         /* validation of the length of the header */
  865         IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m,
  866                 sizeof(struct ip6_hdr), sizeof(struct ip6_hbh));
  867         if (hbh == NULL) {
  868                 ip6stat.ip6s_tooshort++;
  869                 return -1;
  870         }
  871         hbhlen = (hbh->ip6h_len + 1) << 3;
  872         IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr),
  873                 hbhlen);
  874         if (hbh == NULL) {
  875                 ip6stat.ip6s_tooshort++;
  876                 return -1;
  877         }
  878         KASSERT(IP6_HDR_ALIGNED_P(hbh));
  879         off += hbhlen;
  880         hbhlen -= sizeof(struct ip6_hbh);
  881 
  882         if (ip6_process_hopopts(m, (u_int8_t *)hbh + sizeof(struct ip6_hbh),
  883                                 hbhlen, rtalertp, plenp) < 0)
  884                 return (-1);
  885 
  886         *offp = off;
  887         *mp = m;
  888         return (0);
  889 }
  890 
  891 /*
  892  * Search header for all Hop-by-hop options and process each option.
  893  * This function is separate from ip6_hopopts_input() in order to
  894  * handle a case where the sending node itself process its hop-by-hop
  895  * options header. In such a case, the function is called from ip6_output().
  896  *
  897  * The function assumes that hbh header is located right after the IPv6 header
  898  * (RFC2460 p7), opthead is pointer into data content in m, and opthead to
  899  * opthead + hbhlen is located in continuous memory region.
  900  */
  901 int
  902 ip6_process_hopopts(m, opthead, hbhlen, rtalertp, plenp)
  903         struct mbuf *m;
  904         u_int8_t *opthead;
  905         int hbhlen;
  906         u_int32_t *rtalertp;
  907         u_int32_t *plenp;
  908 {
  909         struct ip6_hdr *ip6;
  910         int optlen = 0;
  911         u_int8_t *opt = opthead;
  912         u_int16_t rtalert_val;
  913         u_int32_t jumboplen;
  914         const int erroff = sizeof(struct ip6_hdr) + sizeof(struct ip6_hbh);
  915 
  916         for (; hbhlen > 0; hbhlen -= optlen, opt += optlen) {
  917                 switch (*opt) {
  918                 case IP6OPT_PAD1:
  919                         optlen = 1;
  920                         break;
  921                 case IP6OPT_PADN:
  922                         if (hbhlen < IP6OPT_MINLEN) {
  923                                 ip6stat.ip6s_toosmall++;
  924                                 goto bad;
  925                         }
  926                         optlen = *(opt + 1) + 2;
  927                         break;
  928                 case IP6OPT_RTALERT:
  929                         /* XXX may need check for alignment */
  930                         if (hbhlen < IP6OPT_RTALERT_LEN) {
  931                                 ip6stat.ip6s_toosmall++;
  932                                 goto bad;
  933                         }
  934                         if (*(opt + 1) != IP6OPT_RTALERT_LEN - 2) {
  935                                 /* XXX stat */
  936                                 icmp6_error(m, ICMP6_PARAM_PROB,
  937                                     ICMP6_PARAMPROB_HEADER,
  938                                     erroff + opt + 1 - opthead);
  939                                 return (-1);
  940                         }
  941                         optlen = IP6OPT_RTALERT_LEN;
  942                         bcopy((caddr_t)(opt + 2), (caddr_t)&rtalert_val, 2);
  943                         *rtalertp = ntohs(rtalert_val);
  944                         break;
  945                 case IP6OPT_JUMBO:
  946                         /* XXX may need check for alignment */
  947                         if (hbhlen < IP6OPT_JUMBO_LEN) {
  948                                 ip6stat.ip6s_toosmall++;
  949                                 goto bad;
  950                         }
  951                         if (*(opt + 1) != IP6OPT_JUMBO_LEN - 2) {
  952                                 /* XXX stat */
  953                                 icmp6_error(m, ICMP6_PARAM_PROB,
  954                                     ICMP6_PARAMPROB_HEADER,
  955                                     erroff + opt + 1 - opthead);
  956                                 return (-1);
  957                         }
  958                         optlen = IP6OPT_JUMBO_LEN;
  959 
  960                         /*
  961                          * IPv6 packets that have non 0 payload length
  962                          * must not contain a jumbo payload option.
  963                          */
  964                         ip6 = mtod(m, struct ip6_hdr *);
  965                         if (ip6->ip6_plen) {
  966                                 ip6stat.ip6s_badoptions++;
  967                                 icmp6_error(m, ICMP6_PARAM_PROB,
  968                                     ICMP6_PARAMPROB_HEADER,
  969                                     erroff + opt - opthead);
  970                                 return (-1);
  971                         }
  972 
  973                         /*
  974                          * We may see jumbolen in unaligned location, so
  975                          * we'd need to perform bcopy().
  976                          */
  977                         bcopy(opt + 2, &jumboplen, sizeof(jumboplen));
  978                         jumboplen = (u_int32_t)htonl(jumboplen);
  979 
  980 #if 1
  981                         /*
  982                          * if there are multiple jumbo payload options,
  983                          * *plenp will be non-zero and the packet will be
  984                          * rejected.
  985                          * the behavior may need some debate in ipngwg -
  986                          * multiple options does not make sense, however,
  987                          * there's no explicit mention in specification.
  988                          */
  989                         if (*plenp != 0) {
  990                                 ip6stat.ip6s_badoptions++;
  991                                 icmp6_error(m, ICMP6_PARAM_PROB,
  992                                     ICMP6_PARAMPROB_HEADER,
  993                                     erroff + opt + 2 - opthead);
  994                                 return (-1);
  995                         }
  996 #endif
  997 
  998                         /*
  999                          * jumbo payload length must be larger than 65535.
 1000                          */
 1001                         if (jumboplen <= IPV6_MAXPACKET) {
 1002                                 ip6stat.ip6s_badoptions++;
 1003                                 icmp6_error(m, ICMP6_PARAM_PROB,
 1004                                     ICMP6_PARAMPROB_HEADER,
 1005                                     erroff + opt + 2 - opthead);
 1006                                 return (-1);
 1007                         }
 1008                         *plenp = jumboplen;
 1009 
 1010                         break;
 1011                 default:                /* unknown option */
 1012                         if (hbhlen < IP6OPT_MINLEN) {
 1013                                 ip6stat.ip6s_toosmall++;
 1014                                 goto bad;
 1015                         }
 1016                         optlen = ip6_unknown_opt(opt, m,
 1017                             erroff + opt - opthead);
 1018                         if (optlen == -1)
 1019                                 return (-1);
 1020                         optlen += 2;
 1021                         break;
 1022                 }
 1023         }
 1024 
 1025         return (0);
 1026 
 1027   bad:
 1028         m_freem(m);
 1029         return (-1);
 1030 }
 1031 
 1032 /*
 1033  * Unknown option processing.
 1034  * The third argument `off' is the offset from the IPv6 header to the option,
 1035  * which is necessary if the IPv6 header the and option header and IPv6 header
 1036  * is not continuous in order to return an ICMPv6 error.
 1037  */
 1038 int
 1039 ip6_unknown_opt(optp, m, off)
 1040         u_int8_t *optp;
 1041         struct mbuf *m;
 1042         int off;
 1043 {
 1044         struct ip6_hdr *ip6;
 1045 
 1046         switch (IP6OPT_TYPE(*optp)) {
 1047         case IP6OPT_TYPE_SKIP: /* ignore the option */
 1048                 return ((int)*(optp + 1));
 1049         case IP6OPT_TYPE_DISCARD:       /* silently discard */
 1050                 m_freem(m);
 1051                 return (-1);
 1052         case IP6OPT_TYPE_FORCEICMP: /* send ICMP even if multicasted */
 1053                 ip6stat.ip6s_badoptions++;
 1054                 icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_OPTION, off);
 1055                 return (-1);
 1056         case IP6OPT_TYPE_ICMP: /* send ICMP if not multicasted */
 1057                 ip6stat.ip6s_badoptions++;
 1058                 ip6 = mtod(m, struct ip6_hdr *);
 1059                 if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) ||
 1060                     (m->m_flags & (M_BCAST|M_MCAST)))
 1061                         m_freem(m);
 1062                 else
 1063                         icmp6_error(m, ICMP6_PARAM_PROB,
 1064                                     ICMP6_PARAMPROB_OPTION, off);
 1065                 return (-1);
 1066         }
 1067 
 1068         m_freem(m);             /* XXX: NOTREACHED */
 1069         return (-1);
 1070 }
 1071 
 1072 /*
 1073  * Create the "control" list for this pcb.
 1074  *
 1075  * The routine will be called from upper layer handlers like tcp6_input().
 1076  * Thus the routine assumes that the caller (tcp6_input) have already
 1077  * called IP6_EXTHDR_CHECK() and all the extension headers are located in the
 1078  * very first mbuf on the mbuf chain.
 1079  * We may want to add some infinite loop prevention or sanity checks for safety.
 1080  * (This applies only when you are using KAME mbuf chain restriction, i.e.
 1081  * you are using IP6_EXTHDR_CHECK() not m_pulldown())
 1082  */
 1083 void
 1084 ip6_savecontrol(in6p, mp, ip6, m)
 1085         struct in6pcb *in6p;
 1086         struct mbuf **mp;
 1087         struct ip6_hdr *ip6;
 1088         struct mbuf *m;
 1089 {
 1090 #ifdef RFC2292
 1091 #define IS2292(x, y)    ((in6p->in6p_flags & IN6P_RFC2292) ? (x) : (y))
 1092 #else
 1093 #define IS2292(x, y)    (y)
 1094 #endif
 1095 
 1096 #ifdef SO_TIMESTAMP
 1097         if (in6p->in6p_socket->so_options & SO_TIMESTAMP) {
 1098                 struct timeval tv;
 1099 
 1100                 microtime(&tv);
 1101                 *mp = sbcreatecontrol((caddr_t) &tv, sizeof(tv),
 1102                     SCM_TIMESTAMP, SOL_SOCKET);
 1103                 if (*mp)
 1104                         mp = &(*mp)->m_next;
 1105         }
 1106 #endif
 1107 
 1108         /* some OSes call this logic with IPv4 packet, for SO_TIMESTAMP */
 1109         if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION)
 1110                 return;
 1111 
 1112         /* RFC 2292 sec. 5 */
 1113         if ((in6p->in6p_flags & IN6P_PKTINFO) != 0) {
 1114                 struct in6_pktinfo pi6;
 1115 
 1116                 bcopy(&ip6->ip6_dst, &pi6.ipi6_addr, sizeof(struct in6_addr));
 1117                 in6_clearscope(&pi6.ipi6_addr); /* XXX */
 1118                 pi6.ipi6_ifindex = m->m_pkthdr.rcvif ?
 1119                     m->m_pkthdr.rcvif->if_index : 0;
 1120                 *mp = sbcreatecontrol((caddr_t) &pi6,
 1121                     sizeof(struct in6_pktinfo),
 1122                     IS2292(IPV6_2292PKTINFO, IPV6_PKTINFO), IPPROTO_IPV6);
 1123                 if (*mp)
 1124                         mp = &(*mp)->m_next;
 1125         }
 1126 
 1127         if (in6p->in6p_flags & IN6P_HOPLIMIT) {
 1128                 int hlim = ip6->ip6_hlim & 0xff;
 1129 
 1130                 *mp = sbcreatecontrol((caddr_t) &hlim, sizeof(int),
 1131                     IS2292(IPV6_2292HOPLIMIT, IPV6_HOPLIMIT), IPPROTO_IPV6);
 1132                 if (*mp)
 1133                         mp = &(*mp)->m_next;
 1134         }
 1135 
 1136         if ((in6p->in6p_flags & IN6P_TCLASS) != 0) {
 1137                 u_int32_t flowinfo;
 1138                 int tclass;
 1139 
 1140                 flowinfo = (u_int32_t)ntohl(ip6->ip6_flow & IPV6_FLOWINFO_MASK);
 1141                 flowinfo >>= 20;
 1142 
 1143                 tclass = flowinfo & 0xff;
 1144                 *mp = sbcreatecontrol((caddr_t)&tclass, sizeof(tclass),
 1145                     IPV6_TCLASS, IPPROTO_IPV6);
 1146 
 1147                 if (*mp)
 1148                         mp = &(*mp)->m_next;
 1149         }
 1150 
 1151         /*
 1152          * IPV6_HOPOPTS socket option.  Recall that we required super-user
 1153          * privilege for the option (see ip6_ctloutput), but it might be too
 1154          * strict, since there might be some hop-by-hop options which can be
 1155          * returned to normal user.
 1156          * See also RFC3542 section 8 (or RFC2292 section 6).
 1157          */
 1158         if ((in6p->in6p_flags & IN6P_HOPOPTS) != 0) {
 1159                 /*
 1160                  * Check if a hop-by-hop options header is contatined in the
 1161                  * received packet, and if so, store the options as ancillary
 1162                  * data. Note that a hop-by-hop options header must be
 1163                  * just after the IPv6 header, which fact is assured through
 1164                  * the IPv6 input processing.
 1165                  */
 1166                 struct ip6_hdr *xip6 = mtod(m, struct ip6_hdr *);
 1167                 if (xip6->ip6_nxt == IPPROTO_HOPOPTS) {
 1168                         struct ip6_hbh *hbh;
 1169                         int hbhlen;
 1170                         struct mbuf *ext;
 1171 
 1172                         ext = ip6_pullexthdr(m, sizeof(struct ip6_hdr),
 1173                             xip6->ip6_nxt);
 1174                         if (ext == NULL) {
 1175                                 ip6stat.ip6s_tooshort++;
 1176                                 return;
 1177                         }
 1178                         hbh = mtod(ext, struct ip6_hbh *);
 1179                         hbhlen = (hbh->ip6h_len + 1) << 3;
 1180                         if (hbhlen != ext->m_len) {
 1181                                 m_freem(ext);
 1182                                 ip6stat.ip6s_tooshort++;
 1183                                 return;
 1184                         }
 1185 
 1186                         /*
 1187                          * XXX: We copy whole the header even if a jumbo
 1188                          * payload option is included, which option is to
 1189                          * be removed before returning in the RFC 2292.
 1190                          * Note: this constraint is removed in RFC3542.
 1191                          */
 1192                         *mp = sbcreatecontrol((caddr_t)hbh, hbhlen,
 1193                             IS2292(IPV6_2292HOPOPTS, IPV6_HOPOPTS),
 1194                             IPPROTO_IPV6);
 1195                         if (*mp)
 1196                                 mp = &(*mp)->m_next;
 1197                         m_freem(ext);
 1198                 }
 1199         }
 1200 
 1201         /* IPV6_DSTOPTS and IPV6_RTHDR socket options */
 1202         if (in6p->in6p_flags & (IN6P_DSTOPTS | IN6P_RTHDR)) {
 1203                 struct ip6_hdr *xip6 = mtod(m, struct ip6_hdr *);
 1204                 int nxt = xip6->ip6_nxt, off = sizeof(struct ip6_hdr);
 1205 
 1206                 /*
 1207                  * Search for destination options headers or routing
 1208                  * header(s) through the header chain, and stores each
 1209                  * header as ancillary data.
 1210                  * Note that the order of the headers remains in
 1211                  * the chain of ancillary data.
 1212                  */
 1213                 for (;;) {      /* is explicit loop prevention necessary? */
 1214                         struct ip6_ext *ip6e = NULL;
 1215                         int elen;
 1216                         struct mbuf *ext = NULL;
 1217 
 1218                         /*
 1219                          * if it is not an extension header, don't try to
 1220                          * pull it from the chain.
 1221                          */
 1222                         switch (nxt) {
 1223                         case IPPROTO_DSTOPTS:
 1224                         case IPPROTO_ROUTING:
 1225                         case IPPROTO_HOPOPTS:
 1226                         case IPPROTO_AH: /* is it possible? */
 1227                                 break;
 1228                         default:
 1229                                 goto loopend;
 1230                         }
 1231 
 1232                         ext = ip6_pullexthdr(m, off, nxt);
 1233                         if (ext == NULL) {
 1234                                 ip6stat.ip6s_tooshort++;
 1235                                 return;
 1236                         }
 1237                         ip6e = mtod(ext, struct ip6_ext *);
 1238                         if (nxt == IPPROTO_AH)
 1239                                 elen = (ip6e->ip6e_len + 2) << 2;
 1240                         else
 1241                                 elen = (ip6e->ip6e_len + 1) << 3;
 1242                         if (elen != ext->m_len) {
 1243                                 m_freem(ext);
 1244                                 ip6stat.ip6s_tooshort++;
 1245                                 return;
 1246                         }
 1247                         KASSERT(IP6_HDR_ALIGNED_P(ip6e));
 1248 
 1249                         switch (nxt) {
 1250                         case IPPROTO_DSTOPTS:
 1251                                 if (!in6p->in6p_flags & IN6P_DSTOPTS)
 1252                                         break;
 1253 
 1254                                 *mp = sbcreatecontrol((caddr_t)ip6e, elen,
 1255                                     IS2292(IPV6_2292DSTOPTS, IPV6_DSTOPTS),
 1256                                     IPPROTO_IPV6);
 1257                                 if (*mp)
 1258                                         mp = &(*mp)->m_next;
 1259                                 break;
 1260 
 1261                         case IPPROTO_ROUTING:
 1262                                 if (!in6p->in6p_flags & IN6P_RTHDR)
 1263                                         break;
 1264 
 1265                                 *mp = sbcreatecontrol((caddr_t)ip6e, elen,
 1266                                     IS2292(IPV6_2292RTHDR, IPV6_RTHDR),
 1267                                     IPPROTO_IPV6);
 1268                                 if (*mp)
 1269                                         mp = &(*mp)->m_next;
 1270                                 break;
 1271 
 1272                         case IPPROTO_HOPOPTS:
 1273                         case IPPROTO_AH: /* is it possible? */
 1274                                 break;
 1275 
 1276                         default:
 1277                                 /*
 1278                                  * other cases have been filtered in the above.
 1279                                  * none will visit this case.  here we supply
 1280                                  * the code just in case (nxt overwritten or
 1281                                  * other cases).
 1282                                  */
 1283                                 m_freem(ext);
 1284                                 goto loopend;
 1285 
 1286                         }
 1287 
 1288                         /* proceed with the next header. */
 1289                         off += elen;
 1290                         nxt = ip6e->ip6e_nxt;
 1291                         ip6e = NULL;
 1292                         m_freem(ext);
 1293                         ext = NULL;
 1294                 }
 1295           loopend:
 1296                 ;
 1297         }
 1298 }
 1299 #undef IS2292
 1300 
 1301 
 1302 void
 1303 ip6_notify_pmtu(struct in6pcb *in6p, struct sockaddr_in6 *dst, uint32_t *mtu)
 1304 {
 1305         struct socket *so;
 1306         struct mbuf *m_mtu;
 1307         struct ip6_mtuinfo mtuctl;
 1308 
 1309         so = in6p->in6p_socket;
 1310 
 1311         if (mtu == NULL)
 1312                 return;
 1313 
 1314 #ifdef DIAGNOSTIC
 1315         if (so == NULL)         /* I believe this is impossible */
 1316                 panic("ip6_notify_pmtu: socket is NULL");
 1317 #endif
 1318 
 1319         memset(&mtuctl, 0, sizeof(mtuctl));     /* zero-clear for safety */
 1320         mtuctl.ip6m_mtu = *mtu;
 1321         mtuctl.ip6m_addr = *dst;
 1322         if (sa6_recoverscope(&mtuctl.ip6m_addr))
 1323                 return;
 1324 
 1325         if ((m_mtu = sbcreatecontrol((caddr_t)&mtuctl, sizeof(mtuctl),
 1326             IPV6_PATHMTU, IPPROTO_IPV6)) == NULL)
 1327                 return;
 1328 
 1329         if (sbappendaddr(&so->so_rcv, (struct sockaddr *)dst, NULL, m_mtu)
 1330             == 0) {
 1331                 m_freem(m_mtu);
 1332                 /* XXX: should count statistics */
 1333         } else
 1334                 sorwakeup(so);
 1335 
 1336         return;
 1337 }
 1338 
 1339 /*
 1340  * pull single extension header from mbuf chain.  returns single mbuf that
 1341  * contains the result, or NULL on error.
 1342  */
 1343 static struct mbuf *
 1344 ip6_pullexthdr(m, off, nxt)
 1345         struct mbuf *m;
 1346         size_t off;
 1347         int nxt;
 1348 {
 1349         struct ip6_ext ip6e;
 1350         size_t elen;
 1351         struct mbuf *n;
 1352 
 1353 #ifdef DIAGNOSTIC
 1354         switch (nxt) {
 1355         case IPPROTO_DSTOPTS:
 1356         case IPPROTO_ROUTING:
 1357         case IPPROTO_HOPOPTS:
 1358         case IPPROTO_AH: /* is it possible? */
 1359                 break;
 1360         default:
 1361                 printf("ip6_pullexthdr: invalid nxt=%d\n", nxt);
 1362         }
 1363 #endif
 1364 
 1365         m_copydata(m, off, sizeof(ip6e), (caddr_t)&ip6e);
 1366         if (nxt == IPPROTO_AH)
 1367                 elen = (ip6e.ip6e_len + 2) << 2;
 1368         else
 1369                 elen = (ip6e.ip6e_len + 1) << 3;
 1370 
 1371         MGET(n, M_DONTWAIT, MT_DATA);
 1372         if (n && elen >= MLEN) {
 1373                 MCLGET(n, M_DONTWAIT);
 1374                 if ((n->m_flags & M_EXT) == 0) {
 1375                         m_free(n);
 1376                         n = NULL;
 1377                 }
 1378         }
 1379         if (!n)
 1380                 return NULL;
 1381 
 1382         n->m_len = 0;
 1383         if (elen >= M_TRAILINGSPACE(n)) {
 1384                 m_free(n);
 1385                 return NULL;
 1386         }
 1387 
 1388         m_copydata(m, off, elen, mtod(n, caddr_t));
 1389         n->m_len = elen;
 1390         return n;
 1391 }
 1392 
 1393 /*
 1394  * Get pointer to the previous header followed by the header
 1395  * currently processed.
 1396  * XXX: This function supposes that
 1397  *      M includes all headers,
 1398  *      the next header field and the header length field of each header
 1399  *      are valid, and
 1400  *      the sum of each header length equals to OFF.
 1401  * Because of these assumptions, this function must be called very
 1402  * carefully. Moreover, it will not be used in the near future when
 1403  * we develop `neater' mechanism to process extension headers.
 1404  */
 1405 u_int8_t *
 1406 ip6_get_prevhdr(m, off)
 1407         struct mbuf *m;
 1408         int off;
 1409 {
 1410         struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
 1411 
 1412         if (off == sizeof(struct ip6_hdr))
 1413                 return (&ip6->ip6_nxt);
 1414         else {
 1415                 int len, nxt;
 1416                 struct ip6_ext *ip6e = NULL;
 1417 
 1418                 nxt = ip6->ip6_nxt;
 1419                 len = sizeof(struct ip6_hdr);
 1420                 while (len < off) {
 1421                         ip6e = (struct ip6_ext *)(mtod(m, caddr_t) + len);
 1422 
 1423                         switch (nxt) {
 1424                         case IPPROTO_FRAGMENT:
 1425                                 len += sizeof(struct ip6_frag);
 1426                                 break;
 1427                         case IPPROTO_AH:
 1428                                 len += (ip6e->ip6e_len + 2) << 2;
 1429                                 break;
 1430                         default:
 1431                                 len += (ip6e->ip6e_len + 1) << 3;
 1432                                 break;
 1433                         }
 1434                         nxt = ip6e->ip6e_nxt;
 1435                 }
 1436                 if (ip6e)
 1437                         return (&ip6e->ip6e_nxt);
 1438                 else
 1439                         return NULL;
 1440         }
 1441 }
 1442 
 1443 /*
 1444  * get next header offset.  m will be retained.
 1445  */
 1446 int
 1447 ip6_nexthdr(m, off, proto, nxtp)
 1448         struct mbuf *m;
 1449         int off;
 1450         int proto;
 1451         int *nxtp;
 1452 {
 1453         struct ip6_hdr ip6;
 1454         struct ip6_ext ip6e;
 1455         struct ip6_frag fh;
 1456 
 1457         /* just in case */
 1458         if (m == NULL)
 1459                 panic("ip6_nexthdr: m == NULL");
 1460         if ((m->m_flags & M_PKTHDR) == 0 || m->m_pkthdr.len < off)
 1461                 return -1;
 1462 
 1463         switch (proto) {
 1464         case IPPROTO_IPV6:
 1465                 /* do not chase beyond intermediate IPv6 headers */
 1466                 if (off != 0)
 1467                         return -1;
 1468                 if (m->m_pkthdr.len < off + sizeof(ip6))
 1469                         return -1;
 1470                 m_copydata(m, off, sizeof(ip6), (caddr_t)&ip6);
 1471                 if (nxtp)
 1472                         *nxtp = ip6.ip6_nxt;
 1473                 off += sizeof(ip6);
 1474                 return off;
 1475 
 1476         case IPPROTO_FRAGMENT:
 1477                 /*
 1478                  * terminate parsing if it is not the first fragment,
 1479                  * it does not make sense to parse through it.
 1480                  */
 1481                 if (m->m_pkthdr.len < off + sizeof(fh))
 1482                         return -1;
 1483                 m_copydata(m, off, sizeof(fh), (caddr_t)&fh);
 1484                 if ((fh.ip6f_offlg & IP6F_OFF_MASK) != 0)
 1485                         return -1;
 1486                 if (nxtp)
 1487                         *nxtp = fh.ip6f_nxt;
 1488                 off += sizeof(struct ip6_frag);
 1489                 return off;
 1490 
 1491         case IPPROTO_AH:
 1492                 if (m->m_pkthdr.len < off + sizeof(ip6e))
 1493                         return -1;
 1494                 m_copydata(m, off, sizeof(ip6e), (caddr_t)&ip6e);
 1495                 if (nxtp)
 1496                         *nxtp = ip6e.ip6e_nxt;
 1497                 off += (ip6e.ip6e_len + 2) << 2;
 1498                 if (m->m_pkthdr.len < off)
 1499                         return -1;
 1500                 return off;
 1501 
 1502         case IPPROTO_HOPOPTS:
 1503         case IPPROTO_ROUTING:
 1504         case IPPROTO_DSTOPTS:
 1505                 if (m->m_pkthdr.len < off + sizeof(ip6e))
 1506                         return -1;
 1507                 m_copydata(m, off, sizeof(ip6e), (caddr_t)&ip6e);
 1508                 if (nxtp)
 1509                         *nxtp = ip6e.ip6e_nxt;
 1510                 off += (ip6e.ip6e_len + 1) << 3;
 1511                 if (m->m_pkthdr.len < off)
 1512                         return -1;
 1513                 return off;
 1514 
 1515         case IPPROTO_NONE:
 1516         case IPPROTO_ESP:
 1517         case IPPROTO_IPCOMP:
 1518                 /* give up */
 1519                 return -1;
 1520 
 1521         default:
 1522                 return -1;
 1523         }
 1524 }
 1525 
 1526 /*
 1527  * get offset for the last header in the chain.  m will be kept untainted.
 1528  */
 1529 int
 1530 ip6_lasthdr(m, off, proto, nxtp)
 1531         struct mbuf *m;
 1532         int off;
 1533         int proto;
 1534         int *nxtp;
 1535 {
 1536         int newoff;
 1537         int nxt;
 1538 
 1539         if (!nxtp) {
 1540                 nxt = -1;
 1541                 nxtp = &nxt;
 1542         }
 1543         for (;;) {
 1544                 newoff = ip6_nexthdr(m, off, proto, nxtp);
 1545                 if (newoff < 0)
 1546                         return off;
 1547                 else if (newoff < off)
 1548                         return -1;      /* invalid */
 1549                 else if (newoff == off)
 1550                         return newoff;
 1551 
 1552                 off = newoff;
 1553                 proto = *nxtp;
 1554         }
 1555 }
 1556 
 1557 struct m_tag *
 1558 ip6_addaux(m)
 1559         struct mbuf *m;
 1560 {
 1561         struct m_tag *mtag;
 1562 
 1563         mtag = m_tag_find(m, PACKET_TAG_INET6, NULL);
 1564         if (!mtag) {
 1565                 mtag = m_tag_get(PACKET_TAG_INET6, sizeof(struct ip6aux),
 1566                     M_NOWAIT);
 1567                 if (mtag) {
 1568                         m_tag_prepend(m, mtag);
 1569                         bzero(mtag + 1, sizeof(struct ip6aux));
 1570                 }
 1571         }
 1572         return mtag;
 1573 }
 1574 
 1575 struct m_tag *
 1576 ip6_findaux(m)
 1577         struct mbuf *m;
 1578 {
 1579         struct m_tag *mtag;
 1580 
 1581         mtag = m_tag_find(m, PACKET_TAG_INET6, NULL);
 1582         return mtag;
 1583 }
 1584 
 1585 void
 1586 ip6_delaux(m)
 1587         struct mbuf *m;
 1588 {
 1589         struct m_tag *mtag;
 1590 
 1591         mtag = m_tag_find(m, PACKET_TAG_INET6, NULL);
 1592         if (mtag)
 1593                 m_tag_delete(m, mtag);
 1594 }
 1595 
 1596 static int
 1597 sysctl_net_inet6_ip6_rht0(SYSCTLFN_ARGS)
 1598 {  
 1599         int error, tmp;
 1600         struct sysctlnode node;
 1601 
 1602         node = *rnode;
 1603         tmp = ip6_rht0;
 1604         node.sysctl_data = &tmp;
 1605         error = sysctl_lookup(SYSCTLFN_CALL(&node));
 1606         if (error || newp == NULL)
 1607                 return error;
 1608 
 1609         switch (tmp) {
 1610         case -1:        /* disable processing */
 1611         case 0:         /* disable for host, enable for router */
 1612         case 1:         /* enable for all */
 1613                 break;
 1614         default:
 1615                 return EINVAL;
 1616         }
 1617         ip6_rht0 = tmp;
 1618         return 0;
 1619 }
 1620 
 1621 /*
 1622  * System control for IP6
 1623  */
 1624 
 1625 u_char  inet6ctlerrmap[PRC_NCMDS] = {
 1626         0,              0,              0,              0,
 1627         0,              EMSGSIZE,       EHOSTDOWN,      EHOSTUNREACH,
 1628         EHOSTUNREACH,   EHOSTUNREACH,   ECONNREFUSED,   ECONNREFUSED,
 1629         EMSGSIZE,       EHOSTUNREACH,   0,              0,
 1630         0,              0,              0,              0,
 1631         ENOPROTOOPT
 1632 };
 1633 
 1634 SYSCTL_SETUP(sysctl_net_inet6_ip6_setup, "sysctl net.inet6.ip6 subtree setup")
 1635 {
 1636 #ifdef RFC2292
 1637 #define IS2292(x, y)    ((in6p->in6p_flags & IN6P_RFC2292) ? (x) : (y))
 1638 #else
 1639 #define IS2292(x, y)    (y)
 1640 #endif
 1641 
 1642         sysctl_createv(clog, 0, NULL, NULL,
 1643                        CTLFLAG_PERMANENT,
 1644                        CTLTYPE_NODE, "net", NULL,
 1645                        NULL, 0, NULL, 0,
 1646                        CTL_NET, CTL_EOL);
 1647         sysctl_createv(clog, 0, NULL, NULL,
 1648                        CTLFLAG_PERMANENT,
 1649                        CTLTYPE_NODE, "inet6",
 1650                        SYSCTL_DESCR("PF_INET6 related settings"),
 1651                        NULL, 0, NULL, 0,
 1652                        CTL_NET, PF_INET6, CTL_EOL);
 1653         sysctl_createv(clog, 0, NULL, NULL,
 1654                        CTLFLAG_PERMANENT,
 1655                        CTLTYPE_NODE, "ip6",
 1656                        SYSCTL_DESCR("IPv6 related settings"),
 1657                        NULL, 0, NULL, 0,
 1658                        CTL_NET, PF_INET6, IPPROTO_IPV6, CTL_EOL);
 1659 
 1660         sysctl_createv(clog, 0, NULL, NULL,
 1661                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1662                        CTLTYPE_INT, "forwarding",
 1663                        SYSCTL_DESCR("Enable forwarding of INET6 datagrams"),
 1664                        NULL, 0, &ip6_forwarding, 0,
 1665                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1666                        IPV6CTL_FORWARDING, CTL_EOL);
 1667         sysctl_createv(clog, 0, NULL, NULL,
 1668                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1669                        CTLTYPE_INT, "redirect",
 1670                        SYSCTL_DESCR("Enable sending of ICMPv6 redirect messages"),
 1671                        NULL, 0, &ip6_sendredirects, 0,
 1672                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1673                        IPV6CTL_SENDREDIRECTS, CTL_EOL);
 1674         sysctl_createv(clog, 0, NULL, NULL,
 1675                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1676                        CTLTYPE_INT, "hlim",
 1677                        SYSCTL_DESCR("Hop limit for an INET6 datagram"),
 1678                        NULL, 0, &ip6_defhlim, 0,
 1679                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1680                        IPV6CTL_DEFHLIM, CTL_EOL);
 1681 #ifdef notyet
 1682         sysctl_createv(clog, 0, NULL, NULL,
 1683                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1684                        CTLTYPE_INT, "mtu", NULL,
 1685                        NULL, 0, &, 0,
 1686                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1687                        IPV6CTL_DEFMTU, CTL_EOL);
 1688 #endif
 1689 #ifdef __no_idea__
 1690         sysctl_createv(clog, 0, NULL, NULL,
 1691                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1692                        CTLTYPE_INT, "forwsrcrt", NULL,
 1693                        NULL, 0, &?, 0,
 1694                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1695                        IPV6CTL_FORWSRCRT, CTL_EOL);
 1696         sysctl_createv(clog, 0, NULL, NULL,
 1697                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1698                        CTLTYPE_STRUCT, "mrtstats", NULL,
 1699                        NULL, 0, &?, sizeof(?),
 1700                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1701                        IPV6CTL_MRTSTATS, CTL_EOL);
 1702         sysctl_createv(clog, 0, NULL, NULL,
 1703                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1704                        CTLTYPE_?, "mrtproto", NULL,
 1705                        NULL, 0, &?, sizeof(?),
 1706                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1707                        IPV6CTL_MRTPROTO, CTL_EOL);
 1708 #endif
 1709         sysctl_createv(clog, 0, NULL, NULL,
 1710                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1711                        CTLTYPE_INT, "maxfragpackets",
 1712                        SYSCTL_DESCR("Maximum number of fragments to buffer "
 1713                                     "for reassembly"),
 1714                        NULL, 0, &ip6_maxfragpackets, 0,
 1715                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1716                        IPV6CTL_MAXFRAGPACKETS, CTL_EOL);
 1717 #ifdef __no_idea__
 1718         sysctl_createv(clog, 0, NULL, NULL,
 1719                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1720                        CTLTYPE_INT, "sourcecheck", NULL,
 1721                        NULL, 0, &?, 0,
 1722                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1723                        IPV6CTL_SOURCECHECK, CTL_EOL);
 1724         sysctl_createv(clog, 0, NULL, NULL,
 1725                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1726                        CTLTYPE_INT, "sourcecheck_logint", NULL,
 1727                        NULL, 0, &?, 0,
 1728                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1729                        IPV6CTL_SOURCECHECK_LOGINT, CTL_EOL);
 1730 #endif
 1731         sysctl_createv(clog, 0, NULL, NULL,
 1732                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1733                        CTLTYPE_INT, "accept_rtadv",
 1734                        SYSCTL_DESCR("Accept router advertisements"),
 1735                        NULL, 0, &ip6_accept_rtadv, 0,
 1736                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1737                        IPV6CTL_ACCEPT_RTADV, CTL_EOL);
 1738         sysctl_createv(clog, 0, NULL, NULL,
 1739                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1740                        CTLTYPE_INT, "keepfaith",
 1741                        SYSCTL_DESCR("Activate faith interface"),
 1742                        NULL, 0, &ip6_keepfaith, 0,
 1743                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1744                        IPV6CTL_KEEPFAITH, CTL_EOL);
 1745         sysctl_createv(clog, 0, NULL, NULL,
 1746                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1747                        CTLTYPE_INT, "log_interval",
 1748                        SYSCTL_DESCR("Minumum interval between logging "
 1749                                     "unroutable packets"),
 1750                        NULL, 0, &ip6_log_interval, 0,
 1751                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1752                        IPV6CTL_LOG_INTERVAL, CTL_EOL);
 1753         sysctl_createv(clog, 0, NULL, NULL,
 1754                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1755                        CTLTYPE_INT, "hdrnestlimit",
 1756                        SYSCTL_DESCR("Maximum number of nested IPv6 headers"),
 1757                        NULL, 0, &ip6_hdrnestlimit, 0,
 1758                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1759                        IPV6CTL_HDRNESTLIMIT, CTL_EOL);
 1760         sysctl_createv(clog, 0, NULL, NULL,
 1761                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1762                        CTLTYPE_INT, "dad_count",
 1763                        SYSCTL_DESCR("Number of Duplicate Address Detection "
 1764                                     "probes to send"),
 1765                        NULL, 0, &ip6_dad_count, 0,
 1766                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1767                        IPV6CTL_DAD_COUNT, CTL_EOL);
 1768         sysctl_createv(clog, 0, NULL, NULL,
 1769                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1770                        CTLTYPE_INT, "auto_flowlabel",
 1771                        SYSCTL_DESCR("Assign random IPv6 flow labels"),
 1772                        NULL, 0, &ip6_auto_flowlabel, 0,
 1773                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1774                        IPV6CTL_AUTO_FLOWLABEL, CTL_EOL);
 1775         sysctl_createv(clog, 0, NULL, NULL,
 1776                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1777                        CTLTYPE_INT, "defmcasthlim",
 1778                        SYSCTL_DESCR("Default multicast hop limit"),
 1779                        NULL, 0, &ip6_defmcasthlim, 0,
 1780                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1781                        IPV6CTL_DEFMCASTHLIM, CTL_EOL);
 1782 #if NGIF > 0
 1783         sysctl_createv(clog, 0, NULL, NULL,
 1784                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1785                        CTLTYPE_INT, "gifhlim",
 1786                        SYSCTL_DESCR("Default hop limit for a gif tunnel datagram"),
 1787                        NULL, 0, &ip6_gif_hlim, 0,
 1788                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1789                        IPV6CTL_GIF_HLIM, CTL_EOL);
 1790 #endif /* NGIF */
 1791         sysctl_createv(clog, 0, NULL, NULL,
 1792                        CTLFLAG_PERMANENT,
 1793                        CTLTYPE_STRING, "kame_version",
 1794                        SYSCTL_DESCR("KAME Version"),
 1795                        NULL, 0, __UNCONST(__KAME_VERSION), 0,
 1796                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1797                        IPV6CTL_KAME_VERSION, CTL_EOL);
 1798         sysctl_createv(clog, 0, NULL, NULL,
 1799                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1800                        CTLTYPE_INT, "use_deprecated",
 1801                        SYSCTL_DESCR("Allow use of deprecated addresses as "
 1802                                     "source addresses"),
 1803                        NULL, 0, &ip6_use_deprecated, 0,
 1804                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1805                        IPV6CTL_USE_DEPRECATED, CTL_EOL);
 1806         sysctl_createv(clog, 0, NULL, NULL,
 1807                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1808                        CTLTYPE_INT, "rr_prune", NULL,
 1809                        NULL, 0, &ip6_rr_prune, 0,
 1810                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1811                        IPV6CTL_RR_PRUNE, CTL_EOL);
 1812         sysctl_createv(clog, 0, NULL, NULL,
 1813                        CTLFLAG_PERMANENT
 1814 #ifndef INET6_BINDV6ONLY
 1815                        |CTLFLAG_READWRITE,
 1816 #endif
 1817                        CTLTYPE_INT, "v6only",
 1818                        SYSCTL_DESCR("Disallow PF_INET6 sockets from connecting "
 1819                                     "to PF_INET sockets"),
 1820                        NULL, 0, &ip6_v6only, 0,
 1821                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1822                        IPV6CTL_V6ONLY, CTL_EOL);
 1823         sysctl_createv(clog, 0, NULL, NULL,
 1824                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1825                        CTLTYPE_INT, "anonportmin",
 1826                        SYSCTL_DESCR("Lowest ephemeral port number to assign"),
 1827                        sysctl_net_inet_ip_ports, 0, &ip6_anonportmin, 0,
 1828                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1829                        IPV6CTL_ANONPORTMIN, CTL_EOL);
 1830         sysctl_createv(clog, 0, NULL, NULL,
 1831                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1832                        CTLTYPE_INT, "anonportmax",
 1833                        SYSCTL_DESCR("Highest ephemeral port number to assign"),
 1834                        sysctl_net_inet_ip_ports, 0, &ip6_anonportmax, 0,
 1835                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1836                        IPV6CTL_ANONPORTMAX, CTL_EOL);
 1837 #ifndef IPNOPRIVPORTS
 1838         sysctl_createv(clog, 0, NULL, NULL,
 1839                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1840                        CTLTYPE_INT, "lowportmin",
 1841                        SYSCTL_DESCR("Lowest privileged ephemeral port number "
 1842                                     "to assign"),
 1843                        sysctl_net_inet_ip_ports, 0, &ip6_lowportmin, 0,
 1844                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1845                        IPV6CTL_LOWPORTMIN, CTL_EOL);
 1846         sysctl_createv(clog, 0, NULL, NULL,
 1847                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1848                        CTLTYPE_INT, "lowportmax",
 1849                        SYSCTL_DESCR("Highest privileged ephemeral port number "
 1850                                     "to assign"),
 1851                        sysctl_net_inet_ip_ports, 0, &ip6_lowportmax, 0,
 1852                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1853                        IPV6CTL_LOWPORTMAX, CTL_EOL);
 1854 #endif /* IPNOPRIVPORTS */
 1855         sysctl_createv(clog, 0, NULL, NULL,
 1856                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1857                        CTLTYPE_INT, "use_tempaddr",
 1858                        SYSCTL_DESCR("Use temporary address"),
 1859                        NULL, 0, &ip6_use_tempaddr, 0,
 1860                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1861                        CTL_CREATE, CTL_EOL);
 1862         sysctl_createv(clog, 0, NULL, NULL,
 1863                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1864                        CTLTYPE_INT, "temppltime",
 1865                        SYSCTL_DESCR("preferred lifetime of a temporary address"),
 1866                        NULL, 0, &ip6_temp_preferred_lifetime, 0,
 1867                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1868                        CTL_CREATE, CTL_EOL);
 1869         sysctl_createv(clog, 0, NULL, NULL,
 1870                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1871                        CTLTYPE_INT, "tempvltime",
 1872                        SYSCTL_DESCR("valid lifetime of a temporary address"),
 1873                        NULL, 0, &ip6_temp_valid_lifetime, 0,
 1874                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1875                        CTL_CREATE, CTL_EOL);
 1876         sysctl_createv(clog, 0, NULL, NULL,
 1877                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1878                        CTLTYPE_INT, "maxfrags",
 1879                        SYSCTL_DESCR("Maximum fragments in reassembly queue"),
 1880                        NULL, 0, &ip6_maxfrags, 0,
 1881                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1882                        IPV6CTL_MAXFRAGS, CTL_EOL);
 1883         sysctl_createv(clog, 0, NULL, NULL,
 1884                        CTLFLAG_PERMANENT,
 1885                        CTLTYPE_STRUCT, "stats",
 1886                        SYSCTL_DESCR("IPv6 statistics"),
 1887                        NULL, 0, &ip6stat, sizeof(ip6stat),
 1888                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1889                        IPV6CTL_STATS, CTL_EOL);
 1890         sysctl_createv(clog, 0, NULL, NULL,
 1891                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1892                        CTLTYPE_INT, "use_defaultzone",
 1893                        SYSCTL_DESCR("Whether to use the default scope zones"),
 1894                        NULL, 0, &ip6_use_defzone, 0,
 1895                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1896                        IPV6CTL_USE_DEFAULTZONE, CTL_EOL);
 1897         sysctl_createv(clog, 0, NULL, NULL,
 1898                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1899                        CTLTYPE_INT, "mcast_pmtu",
 1900                        SYSCTL_DESCR("Enable pMTU discovery for multicast packet"),
 1901                        NULL, 0, &ip6_mcast_pmtu, 0,
 1902                        CTL_NET, PF_INET6, IPPROTO_IPV6,
 1903                        CTL_CREATE, CTL_EOL);
 1904         sysctl_createv(clog, 0, NULL, NULL,
 1905                         CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 1906                         CTLTYPE_INT, "rht0",
 1907                         SYSCTL_DESCR("Processing of routing header type 0 (IPv6)"),
 1908                         sysctl_net_inet6_ip6_rht0, 0, &ip6_rht0, 0,
 1909                         CTL_NET, PF_INET6, IPPROTO_IPV6,
 1910                         CTL_CREATE, CTL_EOL);
 1911 }

Cache object: 1ee86f07de7f2f534fb070e3cd11f999


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