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

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

CVSweb <webmaster@jp.NetBSD.org>