[BACK]Return to ip6_input.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / netinet6

Annotation of src/sys/netinet6/ip6_input.c, Revision 1.95

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

CVSweb <webmaster@jp.NetBSD.org>