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

1.64.2.4! skrll       1: /*     $NetBSD: ip6_input.c,v 1.64.2.3 2004/09/21 13:37:34 skrll 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.64.2.1  skrll      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.64.2.4! skrll      65: __KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.64.2.3 2004/09/21 13:37:34 skrll Exp $");
1.2       itojun     66:
                     67: #include "opt_inet.h"
1.4       thorpej    68: #include "opt_ipsec.h"
1.15      darrenr    69: #include "opt_pfil_hooks.h"
1.2       itojun     70:
                     71: #include <sys/param.h>
                     72: #include <sys/systm.h>
                     73: #include <sys/malloc.h>
                     74: #include <sys/mbuf.h>
                     75: #include <sys/domain.h>
                     76: #include <sys/protosw.h>
                     77: #include <sys/socket.h>
                     78: #include <sys/socketvar.h>
                     79: #include <sys/errno.h>
                     80: #include <sys/time.h>
                     81: #include <sys/kernel.h>
                     82: #include <sys/syslog.h>
                     83: #include <sys/proc.h>
1.46      simonb     84: #include <sys/sysctl.h>
1.2       itojun     85:
                     86: #include <net/if.h>
                     87: #include <net/if_types.h>
                     88: #include <net/if_dl.h>
                     89: #include <net/route.h>
                     90: #include <net/netisr.h>
1.15      darrenr    91: #ifdef PFIL_HOOKS
                     92: #include <net/pfil.h>
                     93: #endif
1.2       itojun     94:
                     95: #include <netinet/in.h>
1.9       itojun     96: #include <netinet/in_systm.h>
                     97: #ifdef INET
                     98: #include <netinet/ip.h>
                     99: #include <netinet/ip_icmp.h>
1.45      itojun    100: #endif /* INET */
1.14      itojun    101: #include <netinet/ip6.h>
1.2       itojun    102: #include <netinet6/in6_var.h>
1.11      itojun    103: #include <netinet6/ip6_var.h>
1.2       itojun    104: #include <netinet6/in6_pcb.h>
1.14      itojun    105: #include <netinet/icmp6.h>
1.2       itojun    106: #include <netinet6/in6_ifattach.h>
                    107: #include <netinet6/nd6.h>
                    108:
1.37      itojun    109: #ifdef IPSEC
                    110: #include <netinet6/ipsec.h>
                    111: #endif
                    112:
1.2       itojun    113: #include <netinet6/ip6protosw.h>
                    114:
                    115: /* we need it for NLOOP. */
                    116: #include "loop.h"
                    117: #include "faith.h"
                    118: #include "gif.h"
1.50      itojun    119:
                    120: #if NGIF > 0
                    121: #include <netinet6/in6_gif.h>
                    122: #endif
1.2       itojun    123:
1.9       itojun    124: #include <net/net_osdep.h>
                    125:
1.2       itojun    126: extern struct domain inet6domain;
                    127:
                    128: u_char ip6_protox[IPPROTO_MAX];
                    129: static int ip6qmaxlen = IFQ_MAXLEN;
                    130: struct in6_ifaddr *in6_ifaddr;
                    131: struct ifqueue ip6intrq;
                    132:
                    133: extern struct ifnet loif[NLOOP];
                    134: int ip6_forward_srcrt;                 /* XXX */
                    135: int ip6_sourcecheck;                   /* XXX */
                    136: int ip6_sourcecheck_interval;          /* XXX */
1.9       itojun    137:
1.29      thorpej   138: #ifdef PFIL_HOOKS
                    139: struct pfil_head inet6_pfil_hook;
                    140: #endif
                    141:
1.2       itojun    142: struct ip6stat ip6stat;
                    143:
                    144: static void ip6_init2 __P((void *));
                    145:
1.5       itojun    146: static int ip6_hopopts_input __P((u_int32_t *, u_int32_t *, struct mbuf **, int *));
1.62      itojun    147: static struct mbuf *ip6_pullexthdr __P((struct mbuf *, size_t, int));
1.2       itojun    148:
                    149: /*
                    150:  * IP6 initialization: fill in IP6 protocol switch table.
                    151:  * All protocols not implemented in kernel go to raw IP6 protocol handler.
                    152:  */
                    153: void
                    154: ip6_init()
                    155: {
1.35      itojun    156:        struct ip6protosw *pr;
                    157:        int i;
1.2       itojun    158:
                    159:        pr = (struct ip6protosw *)pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW);
                    160:        if (pr == 0)
                    161:                panic("ip6_init");
                    162:        for (i = 0; i < IPPROTO_MAX; i++)
                    163:                ip6_protox[i] = pr - inet6sw;
                    164:        for (pr = (struct ip6protosw *)inet6domain.dom_protosw;
                    165:            pr < (struct ip6protosw *)inet6domain.dom_protoswNPROTOSW; pr++)
                    166:                if (pr->pr_domain->dom_family == PF_INET6 &&
                    167:                    pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW)
                    168:                        ip6_protox[pr->pr_protocol] = pr - inet6sw;
                    169:        ip6intrq.ifq_maxlen = ip6qmaxlen;
                    170:        nd6_init();
                    171:        frag6_init();
                    172:
                    173:        ip6_init2((void *)0);
1.29      thorpej   174:
                    175: #ifdef PFIL_HOOKS
                    176:        /* Register our Packet Filter hook. */
1.33      thorpej   177:        inet6_pfil_hook.ph_type = PFIL_TYPE_AF;
                    178:        inet6_pfil_hook.ph_af   = AF_INET6;
1.29      thorpej   179:        i = pfil_head_register(&inet6_pfil_hook);
                    180:        if (i != 0)
                    181:                printf("ip6_init: WARNING: unable to register pfil hook, "
                    182:                    "error %d\n", i);
                    183: #endif /* PFIL_HOOKS */
1.2       itojun    184: }
                    185:
                    186: static void
                    187: ip6_init2(dummy)
                    188:        void *dummy;
                    189: {
                    190:
                    191:        /* nd6_timer_init */
1.19      thorpej   192:        callout_init(&nd6_timer_ch);
                    193:        callout_reset(&nd6_timer_ch, hz, nd6_timer, NULL);
1.2       itojun    194: }
                    195:
                    196: /*
                    197:  * IP6 input interrupt handling. Just pass the packet to ip6_input.
                    198:  */
                    199: void
                    200: ip6intr()
                    201: {
                    202:        int s;
                    203:        struct mbuf *m;
                    204:
                    205:        for (;;) {
1.41      thorpej   206:                s = splnet();
1.2       itojun    207:                IF_DEQUEUE(&ip6intrq, m);
                    208:                splx(s);
                    209:                if (m == 0)
                    210:                        return;
                    211:                ip6_input(m);
                    212:        }
                    213: }
                    214:
                    215: extern struct  route_in6 ip6_forward_rt;
                    216:
                    217: void
                    218: ip6_input(m)
                    219:        struct mbuf *m;
                    220: {
1.9       itojun    221:        struct ip6_hdr *ip6;
1.2       itojun    222:        int off = sizeof(struct ip6_hdr), nest;
                    223:        u_int32_t plen;
1.5       itojun    224:        u_int32_t rtalert = ~0;
1.2       itojun    225:        int nxt, ours = 0;
1.9       itojun    226:        struct ifnet *deliverifp = NULL;
1.64      itojun    227:        int srcrt = 0;
1.2       itojun    228:
                    229: #ifdef IPSEC
                    230:        /*
                    231:         * should the inner packet be considered authentic?
                    232:         * see comment in ah4_input().
                    233:         */
1.49      itojun    234:        m->m_flags &= ~M_AUTHIPHDR;
                    235:        m->m_flags &= ~M_AUTHIPDGM;
1.2       itojun    236: #endif
1.9       itojun    237:
1.2       itojun    238:        /*
1.44      itojun    239:         * mbuf statistics
1.2       itojun    240:         */
                    241:        if (m->m_flags & M_EXT) {
                    242:                if (m->m_next)
                    243:                        ip6stat.ip6s_mext2m++;
                    244:                else
                    245:                        ip6stat.ip6s_mext1++;
                    246:        } else {
1.40      itojun    247: #define M2MMAX (sizeof(ip6stat.ip6s_m2m)/sizeof(ip6stat.ip6s_m2m[0]))
1.2       itojun    248:                if (m->m_next) {
1.9       itojun    249:                        if (m->m_flags & M_LOOP) {
1.44      itojun    250:                                ip6stat.ip6s_m2m[loif[0].if_index]++; /* XXX */
1.40      itojun    251:                        } else if (m->m_pkthdr.rcvif->if_index < M2MMAX)
1.2       itojun    252:                                ip6stat.ip6s_m2m[m->m_pkthdr.rcvif->if_index]++;
                    253:                        else
                    254:                                ip6stat.ip6s_m2m[0]++;
                    255:                } else
                    256:                        ip6stat.ip6s_m1++;
1.40      itojun    257: #undef M2MMAX
1.2       itojun    258:        }
                    259:
1.9       itojun    260:        in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_receive);
                    261:        ip6stat.ip6s_total++;
                    262:
1.57      thorpej   263:        /*
                    264:         * If the IPv6 header is not aligned, slurp it up into a new
                    265:         * mbuf with space for link headers, in the event we forward
                    266:         * it.  OTherwise, if it is aligned, make sure the entire base
                    267:         * IPv6 header is in the first mbuf of the chain.
                    268:         */
                    269:        if (IP6_HDR_ALIGNED_P(mtod(m, caddr_t)) == 0) {
                    270:                struct ifnet *inifp = m->m_pkthdr.rcvif;
                    271:                if ((m = m_copyup(m, sizeof(struct ip6_hdr),
                    272:                                  (max_linkhdr + 3) & ~3)) == NULL) {
                    273:                        /* XXXJRT new stat, please */
                    274:                        ip6stat.ip6s_toosmall++;
                    275:                        in6_ifstat_inc(inifp, ifs6_in_hdrerr);
                    276:                        return;
                    277:                }
                    278:        } else if (__predict_false(m->m_len < sizeof(struct ip6_hdr))) {
                    279:                struct ifnet *inifp = m->m_pkthdr.rcvif;
1.55      itojun    280:                if ((m = m_pullup(m, sizeof(struct ip6_hdr))) == NULL) {
1.9       itojun    281:                        ip6stat.ip6s_toosmall++;
                    282:                        in6_ifstat_inc(inifp, ifs6_in_hdrerr);
                    283:                        return;
                    284:                }
1.2       itojun    285:        }
                    286:
                    287:        ip6 = mtod(m, struct ip6_hdr *);
                    288:
                    289:        if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) {
                    290:                ip6stat.ip6s_badvers++;
1.9       itojun    291:                in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr);
1.2       itojun    292:                goto bad;
                    293:        }
1.15      darrenr   294:
                    295: #ifdef PFIL_HOOKS
                    296:        /*
                    297:         * Run through list of hooks for input packets.  If there are any
                    298:         * filters which require that additional packets in the flow are
                    299:         * not fast-forwarded, they must clear the M_CANFASTFWD flag.
                    300:         * Note that filters must _never_ set this flag, as another filter
                    301:         * in the list may have previously cleared it.
                    302:         */
1.39      itojun    303:        /*
                    304:         * let ipfilter look at packet on the wire,
                    305:         * not the decapsulated packet.
                    306:         */
                    307: #ifdef IPSEC
1.42      itojun    308:        if (!ipsec_getnhist(m))
1.39      itojun    309: #else
                    310:        if (1)
                    311: #endif
                    312:        {
1.64      itojun    313:                struct in6_addr odst;
                    314:
                    315:                odst = ip6->ip6_dst;
1.39      itojun    316:                if (pfil_run_hooks(&inet6_pfil_hook, &m, m->m_pkthdr.rcvif,
                    317:                                   PFIL_IN) != 0)
                    318:                        return;
                    319:                if (m == NULL)
                    320:                        return;
                    321:                ip6 = mtod(m, struct ip6_hdr *);
1.64      itojun    322:                srcrt = !IN6_ARE_ADDR_EQUAL(&odst, &ip6->ip6_dst);
1.39      itojun    323:        }
1.15      darrenr   324: #endif /* PFIL_HOOKS */
                    325:
1.2       itojun    326:        ip6stat.ip6s_nxthist[ip6->ip6_nxt]++;
                    327:
1.30      thorpej   328: #ifdef ALTQ
                    329:        if (altq_input != NULL && (*altq_input)(m, AF_INET6) == 0) {
                    330:                /* packet is dropped by traffic conditioner */
                    331:                return;
1.9       itojun    332:        }
                    333: #endif
                    334:
1.2       itojun    335:        /*
1.44      itojun    336:         * Check against address spoofing/corruption.
1.2       itojun    337:         */
                    338:        if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_src) ||
                    339:            IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_dst)) {
1.55      itojun    340:                /*
                    341:                 * XXX: "badscope" is not very suitable for a multicast source.
                    342:                 */
1.2       itojun    343:                ip6stat.ip6s_badscope++;
1.9       itojun    344:                in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
1.2       itojun    345:                goto bad;
                    346:        }
1.13      itojun    347:        /*
1.44      itojun    348:         * The following check is not documented in specs.  A malicious
                    349:         * party may be able to use IPv4 mapped addr to confuse tcp/udp stack
                    350:         * and bypass security checks (act as if it was from 127.0.0.1 by using
                    351:         * IPv6 src ::ffff:127.0.0.1).  Be cautious.
1.35      itojun    352:         *
1.44      itojun    353:         * This check chokes if we are in an SIIT cloud.  As none of BSDs
                    354:         * support IPv4-less kernel compilation, we cannot support SIIT
                    355:         * environment at all.  So, it makes more sense for us to reject any
                    356:         * malicious packets for non-SIIT environment, than try to do a
1.52      wiz       357:         * partial support for SIIT environment.
1.13      itojun    358:         */
                    359:        if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) ||
                    360:            IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) {
                    361:                ip6stat.ip6s_badscope++;
                    362:                in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
                    363:                goto bad;
                    364:        }
1.17      itojun    365: #if 0
1.13      itojun    366:        /*
1.17      itojun    367:         * Reject packets with IPv4 compatible addresses (auto tunnel).
                    368:         *
                    369:         * The code forbids auto tunnel relay case in RFC1933 (the check is
                    370:         * stronger than RFC1933).  We may want to re-enable it if mech-xx
                    371:         * is revised to forbid relaying case.
1.13      itojun    372:         */
                    373:        if (IN6_IS_ADDR_V4COMPAT(&ip6->ip6_src) ||
                    374:            IN6_IS_ADDR_V4COMPAT(&ip6->ip6_dst)) {
                    375:                ip6stat.ip6s_badscope++;
                    376:                in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
                    377:                goto bad;
                    378:        }
                    379: #endif
1.35      itojun    380:
1.2       itojun    381:        if (IN6_IS_ADDR_LOOPBACK(&ip6->ip6_src) ||
                    382:            IN6_IS_ADDR_LOOPBACK(&ip6->ip6_dst)) {
                    383:                if (m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK) {
                    384:                        ours = 1;
1.9       itojun    385:                        deliverifp = m->m_pkthdr.rcvif;
1.2       itojun    386:                        goto hbhcheck;
                    387:                } else {
                    388:                        ip6stat.ip6s_badscope++;
1.9       itojun    389:                        in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
1.2       itojun    390:                        goto bad;
                    391:                }
                    392:        }
                    393:
1.38      itojun    394:        /* drop packets if interface ID portion is already filled */
                    395:        if ((m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK) == 0) {
                    396:                if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_src) &&
                    397:                    ip6->ip6_src.s6_addr16[1]) {
                    398:                        ip6stat.ip6s_badscope++;
                    399:                        goto bad;
                    400:                }
                    401:                if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_dst) &&
                    402:                    ip6->ip6_dst.s6_addr16[1]) {
                    403:                        ip6stat.ip6s_badscope++;
                    404:                        goto bad;
                    405:                }
                    406:        }
1.2       itojun    407:
1.40      itojun    408:        if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_src))
                    409:                ip6->ip6_src.s6_addr16[1]
                    410:                        = htons(m->m_pkthdr.rcvif->if_index);
                    411:        if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_dst))
                    412:                ip6->ip6_dst.s6_addr16[1]
                    413:                        = htons(m->m_pkthdr.rcvif->if_index);
                    414:
                    415:        /*
                    416:         * We use rt->rt_ifp to determine if the address is ours or not.
                    417:         * If rt_ifp is lo0, the address is ours.
                    418:         * The problem here is, rt->rt_ifp for fe80::%lo0/64 is set to lo0,
                    419:         * so any address under fe80::%lo0/64 will be mistakenly considered
                    420:         * local.  The special case is supplied to handle the case properly
                    421:         * by actually looking at interface addresses
                    422:         * (using in6ifa_ifpwithaddr).
                    423:         */
                    424:        if ((m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK) != 0 &&
                    425:            IN6_IS_ADDR_LINKLOCAL(&ip6->ip6_dst)) {
                    426:                if (!in6ifa_ifpwithaddr(m->m_pkthdr.rcvif, &ip6->ip6_dst)) {
                    427:                        icmp6_error(m, ICMP6_DST_UNREACH,
                    428:                            ICMP6_DST_UNREACH_ADDR, 0);
                    429:                        /* m is already freed */
                    430:                        return;
1.21      itojun    431:                }
1.40      itojun    432:
                    433:                ours = 1;
                    434:                deliverifp = m->m_pkthdr.rcvif;
                    435:                goto hbhcheck;
1.9       itojun    436:        }
                    437:
1.2       itojun    438:        /*
                    439:         * Multicast check
                    440:         */
                    441:        if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
                    442:                struct  in6_multi *in6m = 0;
1.9       itojun    443:
                    444:                in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mcast);
1.2       itojun    445:                /*
                    446:                 * See if we belong to the destination multicast group on the
                    447:                 * arrival interface.
                    448:                 */
                    449:                IN6_LOOKUP_MULTI(ip6->ip6_dst, m->m_pkthdr.rcvif, in6m);
                    450:                if (in6m)
                    451:                        ours = 1;
                    452:                else if (!ip6_mrouter) {
                    453:                        ip6stat.ip6s_notmember++;
                    454:                        ip6stat.ip6s_cantforward++;
1.9       itojun    455:                        in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
1.2       itojun    456:                        goto bad;
                    457:                }
1.9       itojun    458:                deliverifp = m->m_pkthdr.rcvif;
1.2       itojun    459:                goto hbhcheck;
                    460:        }
                    461:
                    462:        /*
                    463:         *  Unicast check
                    464:         */
1.22      itojun    465:        if (ip6_forward_rt.ro_rt != NULL &&
1.55      itojun    466:            (ip6_forward_rt.ro_rt->rt_flags & RTF_UP) != 0 &&
1.22      itojun    467:            IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst,
1.64.2.1  skrll     468:            &((struct sockaddr_in6 *)(&ip6_forward_rt.ro_dst))->sin6_addr))
1.25      itojun    469:                ip6stat.ip6s_forward_cachehit++;
1.22      itojun    470:        else {
1.35      itojun    471:                struct sockaddr_in6 *dst6;
                    472:
1.2       itojun    473:                if (ip6_forward_rt.ro_rt) {
1.22      itojun    474:                        /* route is down or destination is different */
1.25      itojun    475:                        ip6stat.ip6s_forward_cachemiss++;
1.2       itojun    476:                        RTFREE(ip6_forward_rt.ro_rt);
                    477:                        ip6_forward_rt.ro_rt = 0;
                    478:                }
1.22      itojun    479:
1.2       itojun    480:                bzero(&ip6_forward_rt.ro_dst, sizeof(struct sockaddr_in6));
1.35      itojun    481:                dst6 = (struct sockaddr_in6 *)&ip6_forward_rt.ro_dst;
                    482:                dst6->sin6_len = sizeof(struct sockaddr_in6);
                    483:                dst6->sin6_family = AF_INET6;
                    484:                dst6->sin6_addr = ip6->ip6_dst;
1.2       itojun    485:
1.9       itojun    486:                rtalloc((struct route *)&ip6_forward_rt);
1.2       itojun    487:        }
                    488:
                    489: #define rt6_key(r) ((struct sockaddr_in6 *)((r)->rt_nodes->rn_key))
                    490:
                    491:        /*
                    492:         * Accept the packet if the forwarding interface to the destination
                    493:         * according to the routing table is the loopback interface,
                    494:         * unless the associated route has a gateway.
                    495:         * Note that this approach causes to accept a packet if there is a
                    496:         * route to the loopback interface for the destination of the packet.
                    497:         * But we think it's even useful in some situations, e.g. when using
                    498:         * a special daemon which wants to intercept the packet.
                    499:         */
                    500:        if (ip6_forward_rt.ro_rt &&
                    501:            (ip6_forward_rt.ro_rt->rt_flags &
                    502:             (RTF_HOST|RTF_GATEWAY)) == RTF_HOST &&
1.55      itojun    503:            !(ip6_forward_rt.ro_rt->rt_flags & RTF_CLONED) &&
1.2       itojun    504: #if 0
                    505:            /*
                    506:             * The check below is redundant since the comparison of
                    507:             * the destination and the key of the rtentry has
                    508:             * already done through looking up the routing table.
                    509:             */
                    510:            IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst,
1.55      itojun    511:            &rt6_key(ip6_forward_rt.ro_rt)->sin6_addr) &&
1.2       itojun    512: #endif
1.9       itojun    513:            ip6_forward_rt.ro_rt->rt_ifp->if_type == IFT_LOOP) {
1.2       itojun    514:                struct in6_ifaddr *ia6 =
                    515:                        (struct in6_ifaddr *)ip6_forward_rt.ro_rt->rt_ifa;
                    516:                if (ia6->ia6_flags & IN6_IFF_ANYCAST)
                    517:                        m->m_flags |= M_ANYCAST6;
1.24      itojun    518:                /*
                    519:                 * packets to a tentative, duplicated, or somehow invalid
                    520:                 * address must not be accepted.
                    521:                 */
1.2       itojun    522:                if (!(ia6->ia6_flags & IN6_IFF_NOTREADY)) {
1.24      itojun    523:                        /* this address is ready */
1.2       itojun    524:                        ours = 1;
1.9       itojun    525:                        deliverifp = ia6->ia_ifp;       /* correct? */
1.2       itojun    526:                        goto hbhcheck;
                    527:                } else {
1.24      itojun    528:                        /* address is not ready, so discard the packet. */
1.34      itojun    529:                        nd6log((LOG_INFO,
1.27      itojun    530:                            "ip6_input: packet to an unready address %s->%s\n",
1.24      itojun    531:                            ip6_sprintf(&ip6->ip6_src),
1.34      itojun    532:                            ip6_sprintf(&ip6->ip6_dst)));
1.24      itojun    533:
                    534:                        goto bad;
1.2       itojun    535:                }
                    536:        }
                    537:
                    538:        /*
1.55      itojun    539:         * FAITH (Firewall Aided Internet Translator)
1.2       itojun    540:         */
                    541: #if defined(NFAITH) && 0 < NFAITH
                    542:        if (ip6_keepfaith) {
1.64.2.1  skrll     543:                if (ip6_forward_rt.ro_rt && ip6_forward_rt.ro_rt->rt_ifp &&
                    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;
                    561:        for (ifa = m->m_pkthdr.rcvif->if_addrlist.tqh_first;
                    562:             ifa;
                    563:             ifa = ifa->ifa_list.tqe_next) {
                    564:                if (ifa->ifa_addr == NULL)
                    565:                        continue;       /* just for safety */
                    566:                if (ifa->ifa_addr->sa_family != AF_INET6)
                    567:                        continue;
                    568:                if (IN6_ARE_ADDR_EQUAL(IFA_IN6(ifa), &ip6->ip6_dst)) {
                    569:                        ours = 1;
                    570:                        deliverifp = ifa->ifa_ifp;
1.2       itojun    571:                        goto hbhcheck;
                    572:                }
                    573:        }
1.9       itojun    574:     }
1.2       itojun    575: #endif
                    576:
                    577:        /*
                    578:         * Now there is no reason to process the packet if it's not our own
                    579:         * and we're not a router.
                    580:         */
                    581:        if (!ip6_forwarding) {
                    582:                ip6stat.ip6s_cantforward++;
1.9       itojun    583:                in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
1.2       itojun    584:                goto bad;
                    585:        }
                    586:
                    587:   hbhcheck:
                    588:        /*
                    589:         * Process Hop-by-Hop options header if it's contained.
                    590:         * m may be modified in ip6_hopopts_input().
                    591:         * If a JumboPayload option is included, plen will also be modified.
                    592:         */
                    593:        plen = (u_int32_t)ntohs(ip6->ip6_plen);
                    594:        if (ip6->ip6_nxt == IPPROTO_HOPOPTS) {
1.9       itojun    595:                struct ip6_hbh *hbh;
                    596:
                    597:                if (ip6_hopopts_input(&plen, &rtalert, &m, &off)) {
                    598: #if 0  /*touches NULL pointer*/
                    599:                        in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
                    600: #endif
1.2       itojun    601:                        return; /* m have already been freed */
1.9       itojun    602:                }
1.22      itojun    603:
1.2       itojun    604:                /* adjust pointer */
                    605:                ip6 = mtod(m, struct ip6_hdr *);
1.22      itojun    606:
                    607:                /*
1.49      itojun    608:                 * if the payload length field is 0 and the next header field
1.22      itojun    609:                 * indicates Hop-by-Hop Options header, then a Jumbo Payload
                    610:                 * option MUST be included.
                    611:                 */
                    612:                if (ip6->ip6_plen == 0 && plen == 0) {
                    613:                        /*
                    614:                         * Note that if a valid jumbo payload option is
                    615:                         * contained, ip6_hoptops_input() must set a valid
1.55      itojun    616:                         * (non-zero) payload length to the variable plen.
1.22      itojun    617:                         */
                    618:                        ip6stat.ip6s_badoptions++;
                    619:                        in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
                    620:                        in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr);
                    621:                        icmp6_error(m, ICMP6_PARAM_PROB,
                    622:                                    ICMP6_PARAMPROB_HEADER,
                    623:                                    (caddr_t)&ip6->ip6_plen - (caddr_t)ip6);
                    624:                        return;
                    625:                }
1.9       itojun    626:                IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr),
                    627:                        sizeof(struct ip6_hbh));
                    628:                if (hbh == NULL) {
                    629:                        ip6stat.ip6s_tooshort++;
                    630:                        return;
                    631:                }
1.57      thorpej   632:                KASSERT(IP6_HDR_ALIGNED_P(hbh));
1.9       itojun    633:                nxt = hbh->ip6h_nxt;
1.2       itojun    634:
                    635:                /*
                    636:                 * accept the packet if a router alert option is included
                    637:                 * and we act as an IPv6 router.
                    638:                 */
1.5       itojun    639:                if (rtalert != ~0 && ip6_forwarding)
1.2       itojun    640:                        ours = 1;
                    641:        } else
                    642:                nxt = ip6->ip6_nxt;
                    643:
                    644:        /*
                    645:         * Check that the amount of data in the buffers
                    646:         * is as at least much as the IPv6 header would have us expect.
                    647:         * Trim mbufs if longer than we expect.
                    648:         * Drop packet if shorter than we expect.
                    649:         */
                    650:        if (m->m_pkthdr.len - sizeof(struct ip6_hdr) < plen) {
                    651:                ip6stat.ip6s_tooshort++;
1.9       itojun    652:                in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated);
1.2       itojun    653:                goto bad;
                    654:        }
                    655:        if (m->m_pkthdr.len > sizeof(struct ip6_hdr) + plen) {
                    656:                if (m->m_len == m->m_pkthdr.len) {
                    657:                        m->m_len = sizeof(struct ip6_hdr) + plen;
                    658:                        m->m_pkthdr.len = sizeof(struct ip6_hdr) + plen;
                    659:                } else
                    660:                        m_adj(m, sizeof(struct ip6_hdr) + plen - m->m_pkthdr.len);
                    661:        }
                    662:
                    663:        /*
                    664:         * Forward if desirable.
                    665:         */
                    666:        if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
                    667:                /*
                    668:                 * If we are acting as a multicast router, all
                    669:                 * incoming multicast packets are passed to the
                    670:                 * kernel-level multicast forwarding function.
                    671:                 * The packet is returned (relatively) intact; if
                    672:                 * ip6_mforward() returns a non-zero value, the packet
                    673:                 * must be discarded, else it may be accepted below.
                    674:                 */
                    675:                if (ip6_mrouter && ip6_mforward(ip6, m->m_pkthdr.rcvif, m)) {
                    676:                        ip6stat.ip6s_cantforward++;
                    677:                        m_freem(m);
                    678:                        return;
                    679:                }
                    680:                if (!ours) {
                    681:                        m_freem(m);
                    682:                        return;
                    683:                }
1.22      itojun    684:        } else if (!ours) {
1.64      itojun    685:                ip6_forward(m, srcrt);
1.2       itojun    686:                return;
1.56      itojun    687:        }
1.25      itojun    688:
                    689:        ip6 = mtod(m, struct ip6_hdr *);
                    690:
                    691:        /*
                    692:         * Malicious party may be able to use IPv4 mapped addr to confuse
                    693:         * tcp/udp stack and bypass security checks (act as if it was from
                    694:         * 127.0.0.1 by using IPv6 src ::ffff:127.0.0.1).  Be cautious.
                    695:         *
                    696:         * For SIIT end node behavior, you may want to disable the check.
                    697:         * However, you will  become vulnerable to attacks using IPv4 mapped
                    698:         * source.
                    699:         */
                    700:        if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) ||
                    701:            IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) {
                    702:                ip6stat.ip6s_badscope++;
                    703:                in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
                    704:                goto bad;
                    705:        }
1.2       itojun    706:
                    707:        /*
                    708:         * Tell launch routine the next header
                    709:         */
1.12      itojun    710: #ifdef IFA_STATS
1.28      itojun    711:        if (deliverifp != NULL) {
1.9       itojun    712:                struct in6_ifaddr *ia6;
                    713:                ia6 = in6_ifawithifp(deliverifp, &ip6->ip6_dst);
                    714:                if (ia6)
                    715:                        ia6->ia_ifa.ifa_data.ifad_inbytes += m->m_pkthdr.len;
                    716:        }
                    717: #endif
1.2       itojun    718:        ip6stat.ip6s_delivered++;
1.9       itojun    719:        in6_ifstat_inc(deliverifp, ifs6_in_deliver);
1.2       itojun    720:        nest = 0;
1.40      itojun    721:
1.2       itojun    722:        while (nxt != IPPROTO_DONE) {
                    723:                if (ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) {
                    724:                        ip6stat.ip6s_toomanyhdr++;
                    725:                        goto bad;
                    726:                }
1.8       itojun    727:
                    728:                /*
                    729:                 * protection against faulty packet - there should be
                    730:                 * more sanity checks in header chain processing.
                    731:                 */
                    732:                if (m->m_pkthdr.len < off) {
                    733:                        ip6stat.ip6s_tooshort++;
1.9       itojun    734:                        in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated);
1.8       itojun    735:                        goto bad;
                    736:                }
                    737:
1.37      itojun    738: #ifdef IPSEC
                    739:                /*
                    740:                 * enforce IPsec policy checking if we are seeing last header.
                    741:                 * note that we do not visit this with protocols with pcb layer
                    742:                 * code - like udp/tcp/raw ip.
                    743:                 */
                    744:                if ((inet6sw[ip6_protox[nxt]].pr_flags & PR_LASTHDR) != 0 &&
                    745:                    ipsec6_in_reject(m, NULL)) {
                    746:                        ipsec6stat.in_polvio++;
                    747:                        goto bad;
                    748:                }
                    749: #endif
1.56      itojun    750:
1.2       itojun    751:                nxt = (*inet6sw[ip6_protox[nxt]].pr_input)(&m, &off, nxt);
                    752:        }
                    753:        return;
                    754:  bad:
                    755:        m_freem(m);
                    756: }
                    757:
                    758: /*
                    759:  * Hop-by-Hop options header processing. If a valid jumbo payload option is
                    760:  * included, the real payload length will be stored in plenp.
                    761:  */
                    762: static int
                    763: ip6_hopopts_input(plenp, rtalertp, mp, offp)
                    764:        u_int32_t *plenp;
1.5       itojun    765:        u_int32_t *rtalertp;    /* XXX: should be stored more smart way */
1.2       itojun    766:        struct mbuf **mp;
                    767:        int *offp;
                    768: {
1.35      itojun    769:        struct mbuf *m = *mp;
1.2       itojun    770:        int off = *offp, hbhlen;
                    771:        struct ip6_hbh *hbh;
                    772:
                    773:        /* validation of the length of the header */
1.9       itojun    774:        IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m,
                    775:                sizeof(struct ip6_hdr), sizeof(struct ip6_hbh));
                    776:        if (hbh == NULL) {
                    777:                ip6stat.ip6s_tooshort++;
                    778:                return -1;
                    779:        }
                    780:        hbhlen = (hbh->ip6h_len + 1) << 3;
                    781:        IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr),
                    782:                hbhlen);
                    783:        if (hbh == NULL) {
                    784:                ip6stat.ip6s_tooshort++;
                    785:                return -1;
                    786:        }
1.57      thorpej   787:        KASSERT(IP6_HDR_ALIGNED_P(hbh));
1.2       itojun    788:        off += hbhlen;
                    789:        hbhlen -= sizeof(struct ip6_hbh);
                    790:
                    791:        if (ip6_process_hopopts(m, (u_int8_t *)hbh + sizeof(struct ip6_hbh),
                    792:                                hbhlen, rtalertp, plenp) < 0)
1.58      itojun    793:                return (-1);
1.2       itojun    794:
                    795:        *offp = off;
                    796:        *mp = m;
1.58      itojun    797:        return (0);
1.2       itojun    798: }
                    799:
                    800: /*
                    801:  * Search header for all Hop-by-hop options and process each option.
                    802:  * This function is separate from ip6_hopopts_input() in order to
                    803:  * handle a case where the sending node itself process its hop-by-hop
                    804:  * options header. In such a case, the function is called from ip6_output().
1.55      itojun    805:  *
                    806:  * The function assumes that hbh header is located right after the IPv6 header
                    807:  * (RFC2460 p7), opthead is pointer into data content in m, and opthead to
                    808:  * opthead + hbhlen is located in continuous memory region.
1.2       itojun    809:  */
                    810: int
                    811: ip6_process_hopopts(m, opthead, hbhlen, rtalertp, plenp)
                    812:        struct mbuf *m;
                    813:        u_int8_t *opthead;
                    814:        int hbhlen;
1.5       itojun    815:        u_int32_t *rtalertp;
1.2       itojun    816:        u_int32_t *plenp;
                    817: {
                    818:        struct ip6_hdr *ip6;
                    819:        int optlen = 0;
                    820:        u_int8_t *opt = opthead;
                    821:        u_int16_t rtalert_val;
1.22      itojun    822:        u_int32_t jumboplen;
1.55      itojun    823:        const int erroff = sizeof(struct ip6_hdr) + sizeof(struct ip6_hbh);
1.2       itojun    824:
                    825:        for (; hbhlen > 0; hbhlen -= optlen, opt += optlen) {
1.35      itojun    826:                switch (*opt) {
                    827:                case IP6OPT_PAD1:
                    828:                        optlen = 1;
                    829:                        break;
                    830:                case IP6OPT_PADN:
                    831:                        if (hbhlen < IP6OPT_MINLEN) {
                    832:                                ip6stat.ip6s_toosmall++;
                    833:                                goto bad;
                    834:                        }
                    835:                        optlen = *(opt + 1) + 2;
                    836:                        break;
                    837:                case IP6OPT_RTALERT:
                    838:                        /* XXX may need check for alignment */
                    839:                        if (hbhlen < IP6OPT_RTALERT_LEN) {
                    840:                                ip6stat.ip6s_toosmall++;
                    841:                                goto bad;
                    842:                        }
                    843:                        if (*(opt + 1) != IP6OPT_RTALERT_LEN - 2) {
1.55      itojun    844:                                /* XXX stat */
                    845:                                icmp6_error(m, ICMP6_PARAM_PROB,
                    846:                                    ICMP6_PARAMPROB_HEADER,
                    847:                                    erroff + opt + 1 - opthead);
                    848:                                return (-1);
1.35      itojun    849:                        }
                    850:                        optlen = IP6OPT_RTALERT_LEN;
                    851:                        bcopy((caddr_t)(opt + 2), (caddr_t)&rtalert_val, 2);
                    852:                        *rtalertp = ntohs(rtalert_val);
                    853:                        break;
                    854:                case IP6OPT_JUMBO:
1.22      itojun    855:                        /* XXX may need check for alignment */
                    856:                        if (hbhlen < IP6OPT_JUMBO_LEN) {
                    857:                                ip6stat.ip6s_toosmall++;
                    858:                                goto bad;
                    859:                        }
1.35      itojun    860:                        if (*(opt + 1) != IP6OPT_JUMBO_LEN - 2) {
1.55      itojun    861:                                /* XXX stat */
                    862:                                icmp6_error(m, ICMP6_PARAM_PROB,
                    863:                                    ICMP6_PARAMPROB_HEADER,
                    864:                                    erroff + opt + 1 - opthead);
                    865:                                return (-1);
1.35      itojun    866:                        }
1.22      itojun    867:                        optlen = IP6OPT_JUMBO_LEN;
                    868:
                    869:                        /*
                    870:                         * IPv6 packets that have non 0 payload length
1.35      itojun    871:                         * must not contain a jumbo payload option.
1.22      itojun    872:                         */
                    873:                        ip6 = mtod(m, struct ip6_hdr *);
                    874:                        if (ip6->ip6_plen) {
                    875:                                ip6stat.ip6s_badoptions++;
                    876:                                icmp6_error(m, ICMP6_PARAM_PROB,
1.55      itojun    877:                                    ICMP6_PARAMPROB_HEADER,
                    878:                                    erroff + opt - opthead);
                    879:                                return (-1);
1.22      itojun    880:                        }
1.2       itojun    881:
1.22      itojun    882:                        /*
                    883:                         * We may see jumbolen in unaligned location, so
                    884:                         * we'd need to perform bcopy().
                    885:                         */
                    886:                        bcopy(opt + 2, &jumboplen, sizeof(jumboplen));
                    887:                        jumboplen = (u_int32_t)htonl(jumboplen);
                    888:
                    889: #if 1
                    890:                        /*
                    891:                         * if there are multiple jumbo payload options,
                    892:                         * *plenp will be non-zero and the packet will be
                    893:                         * rejected.
                    894:                         * the behavior may need some debate in ipngwg -
                    895:                         * multiple options does not make sense, however,
                    896:                         * there's no explicit mention in specification.
                    897:                         */
                    898:                        if (*plenp != 0) {
                    899:                                ip6stat.ip6s_badoptions++;
                    900:                                icmp6_error(m, ICMP6_PARAM_PROB,
1.55      itojun    901:                                    ICMP6_PARAMPROB_HEADER,
                    902:                                    erroff + opt + 2 - opthead);
                    903:                                return (-1);
1.22      itojun    904:                        }
1.8       itojun    905: #endif
1.2       itojun    906:
1.22      itojun    907:                        /*
                    908:                         * jumbo payload length must be larger than 65535.
                    909:                         */
                    910:                        if (jumboplen <= IPV6_MAXPACKET) {
                    911:                                ip6stat.ip6s_badoptions++;
                    912:                                icmp6_error(m, ICMP6_PARAM_PROB,
1.55      itojun    913:                                    ICMP6_PARAMPROB_HEADER,
                    914:                                    erroff + opt + 2 - opthead);
                    915:                                return (-1);
1.22      itojun    916:                        }
                    917:                        *plenp = jumboplen;
                    918:
                    919:                        break;
1.35      itojun    920:                default:                /* unknown option */
                    921:                        if (hbhlen < IP6OPT_MINLEN) {
                    922:                                ip6stat.ip6s_toosmall++;
                    923:                                goto bad;
                    924:                        }
1.55      itojun    925:                        optlen = ip6_unknown_opt(opt, m,
                    926:                            erroff + opt - opthead);
                    927:                        if (optlen == -1)
                    928:                                return (-1);
1.35      itojun    929:                        optlen += 2;
                    930:                        break;
1.2       itojun    931:                }
                    932:        }
                    933:
1.55      itojun    934:        return (0);
1.2       itojun    935:
                    936:   bad:
                    937:        m_freem(m);
1.55      itojun    938:        return (-1);
1.2       itojun    939: }
                    940:
                    941: /*
                    942:  * Unknown option processing.
                    943:  * The third argument `off' is the offset from the IPv6 header to the option,
                    944:  * which is necessary if the IPv6 header the and option header and IPv6 header
                    945:  * is not continuous in order to return an ICMPv6 error.
                    946:  */
                    947: int
                    948: ip6_unknown_opt(optp, m, off)
                    949:        u_int8_t *optp;
                    950:        struct mbuf *m;
                    951:        int off;
                    952: {
                    953:        struct ip6_hdr *ip6;
                    954:
1.35      itojun    955:        switch (IP6OPT_TYPE(*optp)) {
                    956:        case IP6OPT_TYPE_SKIP: /* ignore the option */
1.58      itojun    957:                return ((int)*(optp + 1));
1.35      itojun    958:        case IP6OPT_TYPE_DISCARD:       /* silently discard */
                    959:                m_freem(m);
1.58      itojun    960:                return (-1);
1.35      itojun    961:        case IP6OPT_TYPE_FORCEICMP: /* send ICMP even if multicasted */
                    962:                ip6stat.ip6s_badoptions++;
                    963:                icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_OPTION, off);
1.58      itojun    964:                return (-1);
1.35      itojun    965:        case IP6OPT_TYPE_ICMP: /* send ICMP if not multicasted */
                    966:                ip6stat.ip6s_badoptions++;
                    967:                ip6 = mtod(m, struct ip6_hdr *);
                    968:                if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) ||
                    969:                    (m->m_flags & (M_BCAST|M_MCAST)))
                    970:                        m_freem(m);
                    971:                else
                    972:                        icmp6_error(m, ICMP6_PARAM_PROB,
                    973:                                    ICMP6_PARAMPROB_OPTION, off);
1.58      itojun    974:                return (-1);
1.2       itojun    975:        }
                    976:
                    977:        m_freem(m);             /* XXX: NOTREACHED */
1.58      itojun    978:        return (-1);
1.2       itojun    979: }
                    980:
                    981: /*
1.9       itojun    982:  * Create the "control" list for this pcb.
                    983:  *
                    984:  * The routine will be called from upper layer handlers like tcp6_input().
                    985:  * Thus the routine assumes that the caller (tcp6_input) have already
                    986:  * called IP6_EXTHDR_CHECK() and all the extension headers are located in the
                    987:  * very first mbuf on the mbuf chain.
                    988:  * We may want to add some infinite loop prevention or sanity checks for safety.
                    989:  * (This applies only when you are using KAME mbuf chain restriction, i.e.
                    990:  * you are using IP6_EXTHDR_CHECK() not m_pulldown())
1.2       itojun    991:  */
                    992: void
                    993: ip6_savecontrol(in6p, mp, ip6, m)
1.35      itojun    994:        struct in6pcb *in6p;
                    995:        struct mbuf **mp;
                    996:        struct ip6_hdr *ip6;
                    997:        struct mbuf *m;
1.2       itojun    998: {
1.9       itojun    999:
                   1000: #ifdef SO_TIMESTAMP
1.2       itojun   1001:        if (in6p->in6p_socket->so_options & SO_TIMESTAMP) {
                   1002:                struct timeval tv;
                   1003:
                   1004:                microtime(&tv);
                   1005:                *mp = sbcreatecontrol((caddr_t) &tv, sizeof(tv),
1.63      itojun   1006:                    SCM_TIMESTAMP, SOL_SOCKET);
1.2       itojun   1007:                if (*mp)
                   1008:                        mp = &(*mp)->m_next;
                   1009:        }
1.9       itojun   1010: #endif
1.2       itojun   1011:        if (in6p->in6p_flags & IN6P_RECVDSTADDR) {
                   1012:                *mp = sbcreatecontrol((caddr_t) &ip6->ip6_dst,
1.63      itojun   1013:                    sizeof(struct in6_addr), IPV6_RECVDSTADDR, IPPROTO_IPV6);
1.2       itojun   1014:                if (*mp)
                   1015:                        mp = &(*mp)->m_next;
                   1016:        }
                   1017:
                   1018: #ifdef noyet
                   1019:        /* options were tossed above */
                   1020:        if (in6p->in6p_flags & IN6P_RECVOPTS)
                   1021:                /* broken */
                   1022:        /* ip6_srcroute doesn't do what we want here, need to fix */
                   1023:        if (in6p->in6p_flags & IPV6P_RECVRETOPTS)
                   1024:                /* broken */
                   1025: #endif
                   1026:
                   1027:        /* RFC 2292 sec. 5 */
1.35      itojun   1028:        if ((in6p->in6p_flags & IN6P_PKTINFO) != 0) {
1.2       itojun   1029:                struct in6_pktinfo pi6;
                   1030:                bcopy(&ip6->ip6_dst, &pi6.ipi6_addr, sizeof(struct in6_addr));
                   1031:                if (IN6_IS_SCOPE_LINKLOCAL(&pi6.ipi6_addr))
                   1032:                        pi6.ipi6_addr.s6_addr16[1] = 0;
                   1033:                pi6.ipi6_ifindex = (m && m->m_pkthdr.rcvif)
                   1034:                                        ? m->m_pkthdr.rcvif->if_index
                   1035:                                        : 0;
                   1036:                *mp = sbcreatecontrol((caddr_t) &pi6,
1.63      itojun   1037:                    sizeof(struct in6_pktinfo), IPV6_PKTINFO, IPPROTO_IPV6);
1.2       itojun   1038:                if (*mp)
                   1039:                        mp = &(*mp)->m_next;
                   1040:        }
                   1041:        if (in6p->in6p_flags & IN6P_HOPLIMIT) {
                   1042:                int hlim = ip6->ip6_hlim & 0xff;
1.63      itojun   1043:                *mp = sbcreatecontrol((caddr_t) &hlim, sizeof(int),
                   1044:                    IPV6_HOPLIMIT, IPPROTO_IPV6);
1.2       itojun   1045:                if (*mp)
                   1046:                        mp = &(*mp)->m_next;
                   1047:        }
                   1048:        /* IN6P_NEXTHOP - for outgoing packet only */
                   1049:
                   1050:        /*
1.64.2.1  skrll    1051:         * IPV6_HOPOPTS socket option.  Recall that we required super-user
                   1052:         * privilege for the option (see ip6_ctloutput), but it might be too
                   1053:         * strict, since there might be some hop-by-hop options which can be
                   1054:         * returned to normal user.
                   1055:         * See also RFC 2292 section 6.
1.2       itojun   1056:         */
1.64.2.1  skrll    1057:        if ((in6p->in6p_flags & IN6P_HOPOPTS) != 0) {
1.2       itojun   1058:                /*
                   1059:                 * Check if a hop-by-hop options header is contatined in the
                   1060:                 * received packet, and if so, store the options as ancillary
                   1061:                 * data. Note that a hop-by-hop options header must be
                   1062:                 * just after the IPv6 header, which fact is assured through
                   1063:                 * the IPv6 input processing.
                   1064:                 */
                   1065:                struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
                   1066:                if (ip6->ip6_nxt == IPPROTO_HOPOPTS) {
1.9       itojun   1067:                        struct ip6_hbh *hbh;
                   1068:                        int hbhlen;
1.62      itojun   1069:                        struct mbuf *ext;
1.9       itojun   1070:
1.62      itojun   1071:                        ext = ip6_pullexthdr(m, sizeof(struct ip6_hdr),
                   1072:                            ip6->ip6_nxt);
                   1073:                        if (ext == NULL) {
1.9       itojun   1074:                                ip6stat.ip6s_tooshort++;
                   1075:                                return;
                   1076:                        }
1.62      itojun   1077:                        hbh = mtod(ext, struct ip6_hbh *);
1.9       itojun   1078:                        hbhlen = (hbh->ip6h_len + 1) << 3;
1.62      itojun   1079:                        if (hbhlen != ext->m_len) {
                   1080:                                m_freem(ext);
1.9       itojun   1081:                                ip6stat.ip6s_tooshort++;
                   1082:                                return;
                   1083:                        }
1.2       itojun   1084:
                   1085:                        /*
                   1086:                         * XXX: We copy whole the header even if a jumbo
                   1087:                         * payload option is included, which option is to
                   1088:                         * be removed before returning in the RFC 2292.
                   1089:                         * But it's too painful operation...
                   1090:                         */
1.9       itojun   1091:                        *mp = sbcreatecontrol((caddr_t)hbh, hbhlen,
1.63      itojun   1092:                            IPV6_HOPOPTS, IPPROTO_IPV6);
1.2       itojun   1093:                        if (*mp)
                   1094:                                mp = &(*mp)->m_next;
1.62      itojun   1095:                        m_freem(ext);
1.2       itojun   1096:                }
                   1097:        }
                   1098:
                   1099:        /* IPV6_DSTOPTS and IPV6_RTHDR socket options */
                   1100:        if (in6p->in6p_flags & (IN6P_DSTOPTS | IN6P_RTHDR)) {
                   1101:                struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
1.60      simonb   1102:                int nxt = ip6->ip6_nxt, off = sizeof(struct ip6_hdr);
1.2       itojun   1103:
                   1104:                /*
                   1105:                 * Search for destination options headers or routing
                   1106:                 * header(s) through the header chain, and stores each
                   1107:                 * header as ancillary data.
                   1108:                 * Note that the order of the headers remains in
                   1109:                 * the chain of ancillary data.
                   1110:                 */
1.35      itojun   1111:                while (1) {     /* is explicit loop prevention necessary? */
1.62      itojun   1112:                        struct ip6_ext *ip6e = NULL;
1.9       itojun   1113:                        int elen;
1.62      itojun   1114:                        struct mbuf *ext = NULL;
1.9       itojun   1115:
1.62      itojun   1116:                        /*
                   1117:                         * if it is not an extension header, don't try to
                   1118:                         * pull it from the chain.
                   1119:                         */
                   1120:                        switch (nxt) {
                   1121:                        case IPPROTO_DSTOPTS:
                   1122:                        case IPPROTO_ROUTING:
                   1123:                        case IPPROTO_HOPOPTS:
                   1124:                        case IPPROTO_AH: /* is it possible? */
                   1125:                                break;
                   1126:                        default:
                   1127:                                goto loopend;
                   1128:                        }
                   1129:
                   1130:                        ext = ip6_pullexthdr(m, off, nxt);
                   1131:                        if (ext == NULL) {
1.9       itojun   1132:                                ip6stat.ip6s_tooshort++;
                   1133:                                return;
                   1134:                        }
1.62      itojun   1135:                        ip6e = mtod(ext, struct ip6_ext *);
1.9       itojun   1136:                        if (nxt == IPPROTO_AH)
                   1137:                                elen = (ip6e->ip6e_len + 2) << 2;
                   1138:                        else
                   1139:                                elen = (ip6e->ip6e_len + 1) << 3;
1.62      itojun   1140:                        if (elen != ext->m_len) {
                   1141:                                m_freem(ext);
1.9       itojun   1142:                                ip6stat.ip6s_tooshort++;
                   1143:                                return;
                   1144:                        }
1.57      thorpej  1145:                        KASSERT(IP6_HDR_ALIGNED_P(ip6e));
1.2       itojun   1146:
1.35      itojun   1147:                        switch (nxt) {
1.62      itojun   1148:                        case IPPROTO_DSTOPTS:
1.35      itojun   1149:                                if (!in6p->in6p_flags & IN6P_DSTOPTS)
                   1150:                                        break;
                   1151:
                   1152:                                *mp = sbcreatecontrol((caddr_t)ip6e, elen,
1.63      itojun   1153:                                    IPV6_DSTOPTS, IPPROTO_IPV6);
1.35      itojun   1154:                                if (*mp)
                   1155:                                        mp = &(*mp)->m_next;
                   1156:                                break;
                   1157:
                   1158:                        case IPPROTO_ROUTING:
                   1159:                                if (!in6p->in6p_flags & IN6P_RTHDR)
                   1160:                                        break;
                   1161:
                   1162:                                *mp = sbcreatecontrol((caddr_t)ip6e, elen,
1.63      itojun   1163:                                    IPV6_RTHDR, IPPROTO_IPV6);
1.35      itojun   1164:                                if (*mp)
                   1165:                                        mp = &(*mp)->m_next;
                   1166:                                break;
                   1167:
1.62      itojun   1168:                        case IPPROTO_HOPOPTS:
                   1169:                        case IPPROTO_AH: /* is it possible? */
                   1170:                                break;
                   1171:
1.35      itojun   1172:                        default:
                   1173:                                /*
1.62      itojun   1174:                                 * other cases have been filtered in the above.
                   1175:                                 * none will visit this case.  here we supply
                   1176:                                 * the code just in case (nxt overwritten or
                   1177:                                 * other cases).
1.35      itojun   1178:                                 */
1.62      itojun   1179:                                m_freem(ext);
1.35      itojun   1180:                                goto loopend;
                   1181:
1.2       itojun   1182:                        }
                   1183:
                   1184:                        /* proceed with the next header. */
1.9       itojun   1185:                        off += elen;
1.2       itojun   1186:                        nxt = ip6e->ip6e_nxt;
1.62      itojun   1187:                        ip6e = NULL;
                   1188:                        m_freem(ext);
                   1189:                        ext = NULL;
1.2       itojun   1190:                }
                   1191:          loopend:
1.62      itojun   1192:                ;
1.2       itojun   1193:        }
1.62      itojun   1194: }
                   1195:
                   1196: /*
                   1197:  * pull single extension header from mbuf chain.  returns single mbuf that
                   1198:  * contains the result, or NULL on error.
                   1199:  */
                   1200: static struct mbuf *
                   1201: ip6_pullexthdr(m, off, nxt)
                   1202:        struct mbuf *m;
                   1203:        size_t off;
                   1204:        int nxt;
                   1205: {
                   1206:        struct ip6_ext ip6e;
                   1207:        size_t elen;
                   1208:        struct mbuf *n;
                   1209:
                   1210: #ifdef DIAGNOSTIC
                   1211:        switch (nxt) {
                   1212:        case IPPROTO_DSTOPTS:
                   1213:        case IPPROTO_ROUTING:
                   1214:        case IPPROTO_HOPOPTS:
                   1215:        case IPPROTO_AH: /* is it possible? */
                   1216:                break;
                   1217:        default:
                   1218:                printf("ip6_pullexthdr: invalid nxt=%d\n", nxt);
1.2       itojun   1219:        }
1.62      itojun   1220: #endif
1.2       itojun   1221:
1.62      itojun   1222:        m_copydata(m, off, sizeof(ip6e), (caddr_t)&ip6e);
                   1223:        if (nxt == IPPROTO_AH)
                   1224:                elen = (ip6e.ip6e_len + 2) << 2;
                   1225:        else
                   1226:                elen = (ip6e.ip6e_len + 1) << 3;
                   1227:
                   1228:        MGET(n, M_DONTWAIT, MT_DATA);
                   1229:        if (n && elen >= MLEN) {
                   1230:                MCLGET(n, M_DONTWAIT);
                   1231:                if ((n->m_flags & M_EXT) == 0) {
                   1232:                        m_free(n);
                   1233:                        n = NULL;
                   1234:                }
                   1235:        }
                   1236:        if (!n)
                   1237:                return NULL;
                   1238:
                   1239:        n->m_len = 0;
                   1240:        if (elen >= M_TRAILINGSPACE(n)) {
                   1241:                m_free(n);
                   1242:                return NULL;
                   1243:        }
                   1244:
                   1245:        m_copydata(m, off, elen, mtod(n, caddr_t));
                   1246:        n->m_len = elen;
                   1247:        return n;
1.2       itojun   1248: }
                   1249:
                   1250: /*
                   1251:  * Get pointer to the previous header followed by the header
                   1252:  * currently processed.
                   1253:  * XXX: This function supposes that
                   1254:  *     M includes all headers,
                   1255:  *     the next header field and the header length field of each header
                   1256:  *     are valid, and
                   1257:  *     the sum of each header length equals to OFF.
                   1258:  * Because of these assumptions, this function must be called very
                   1259:  * carefully. Moreover, it will not be used in the near future when
                   1260:  * we develop `neater' mechanism to process extension headers.
                   1261:  */
1.58      itojun   1262: u_int8_t *
1.2       itojun   1263: ip6_get_prevhdr(m, off)
                   1264:        struct mbuf *m;
                   1265:        int off;
                   1266: {
                   1267:        struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
                   1268:
                   1269:        if (off == sizeof(struct ip6_hdr))
1.58      itojun   1270:                return (&ip6->ip6_nxt);
1.2       itojun   1271:        else {
                   1272:                int len, nxt;
                   1273:                struct ip6_ext *ip6e = NULL;
                   1274:
                   1275:                nxt = ip6->ip6_nxt;
                   1276:                len = sizeof(struct ip6_hdr);
                   1277:                while (len < off) {
                   1278:                        ip6e = (struct ip6_ext *)(mtod(m, caddr_t) + len);
                   1279:
1.35      itojun   1280:                        switch (nxt) {
1.2       itojun   1281:                        case IPPROTO_FRAGMENT:
                   1282:                                len += sizeof(struct ip6_frag);
                   1283:                                break;
                   1284:                        case IPPROTO_AH:
                   1285:                                len += (ip6e->ip6e_len + 2) << 2;
                   1286:                                break;
                   1287:                        default:
                   1288:                                len += (ip6e->ip6e_len + 1) << 3;
                   1289:                                break;
                   1290:                        }
                   1291:                        nxt = ip6e->ip6e_nxt;
                   1292:                }
                   1293:                if (ip6e)
1.58      itojun   1294:                        return (&ip6e->ip6e_nxt);
1.2       itojun   1295:                else
                   1296:                        return NULL;
1.18      itojun   1297:        }
                   1298: }
                   1299:
                   1300: /*
                   1301:  * get next header offset.  m will be retained.
                   1302:  */
                   1303: int
                   1304: ip6_nexthdr(m, off, proto, nxtp)
                   1305:        struct mbuf *m;
                   1306:        int off;
                   1307:        int proto;
                   1308:        int *nxtp;
                   1309: {
                   1310:        struct ip6_hdr ip6;
                   1311:        struct ip6_ext ip6e;
                   1312:        struct ip6_frag fh;
                   1313:
                   1314:        /* just in case */
                   1315:        if (m == NULL)
                   1316:                panic("ip6_nexthdr: m == NULL");
                   1317:        if ((m->m_flags & M_PKTHDR) == 0 || m->m_pkthdr.len < off)
                   1318:                return -1;
                   1319:
                   1320:        switch (proto) {
                   1321:        case IPPROTO_IPV6:
                   1322:                if (m->m_pkthdr.len < off + sizeof(ip6))
                   1323:                        return -1;
                   1324:                m_copydata(m, off, sizeof(ip6), (caddr_t)&ip6);
                   1325:                if (nxtp)
                   1326:                        *nxtp = ip6.ip6_nxt;
                   1327:                off += sizeof(ip6);
                   1328:                return off;
                   1329:
                   1330:        case IPPROTO_FRAGMENT:
                   1331:                /*
                   1332:                 * terminate parsing if it is not the first fragment,
                   1333:                 * it does not make sense to parse through it.
                   1334:                 */
                   1335:                if (m->m_pkthdr.len < off + sizeof(fh))
                   1336:                        return -1;
                   1337:                m_copydata(m, off, sizeof(fh), (caddr_t)&fh);
1.64.2.1  skrll    1338:                if ((fh.ip6f_offlg & IP6F_OFF_MASK) != 0)
1.18      itojun   1339:                        return -1;
                   1340:                if (nxtp)
                   1341:                        *nxtp = fh.ip6f_nxt;
                   1342:                off += sizeof(struct ip6_frag);
                   1343:                return off;
                   1344:
                   1345:        case IPPROTO_AH:
                   1346:                if (m->m_pkthdr.len < off + sizeof(ip6e))
                   1347:                        return -1;
                   1348:                m_copydata(m, off, sizeof(ip6e), (caddr_t)&ip6e);
                   1349:                if (nxtp)
                   1350:                        *nxtp = ip6e.ip6e_nxt;
                   1351:                off += (ip6e.ip6e_len + 2) << 2;
1.47      itojun   1352:                if (m->m_pkthdr.len < off)
                   1353:                        return -1;
1.18      itojun   1354:                return off;
                   1355:
                   1356:        case IPPROTO_HOPOPTS:
                   1357:        case IPPROTO_ROUTING:
                   1358:        case IPPROTO_DSTOPTS:
                   1359:                if (m->m_pkthdr.len < off + sizeof(ip6e))
                   1360:                        return -1;
                   1361:                m_copydata(m, off, sizeof(ip6e), (caddr_t)&ip6e);
                   1362:                if (nxtp)
                   1363:                        *nxtp = ip6e.ip6e_nxt;
                   1364:                off += (ip6e.ip6e_len + 1) << 3;
1.47      itojun   1365:                if (m->m_pkthdr.len < off)
                   1366:                        return -1;
1.18      itojun   1367:                return off;
                   1368:
                   1369:        case IPPROTO_NONE:
                   1370:        case IPPROTO_ESP:
                   1371:        case IPPROTO_IPCOMP:
                   1372:                /* give up */
                   1373:                return -1;
                   1374:
                   1375:        default:
                   1376:                return -1;
                   1377:        }
                   1378: }
                   1379:
                   1380: /*
                   1381:  * get offset for the last header in the chain.  m will be kept untainted.
                   1382:  */
                   1383: int
                   1384: ip6_lasthdr(m, off, proto, nxtp)
                   1385:        struct mbuf *m;
                   1386:        int off;
                   1387:        int proto;
                   1388:        int *nxtp;
                   1389: {
                   1390:        int newoff;
                   1391:        int nxt;
                   1392:
                   1393:        if (!nxtp) {
                   1394:                nxt = -1;
                   1395:                nxtp = &nxt;
                   1396:        }
                   1397:        while (1) {
                   1398:                newoff = ip6_nexthdr(m, off, proto, nxtp);
                   1399:                if (newoff < 0)
                   1400:                        return off;
                   1401:                else if (newoff < off)
                   1402:                        return -1;      /* invalid */
                   1403:                else if (newoff == off)
                   1404:                        return newoff;
                   1405:
                   1406:                off = newoff;
                   1407:                proto = *nxtp;
1.2       itojun   1408:        }
                   1409: }
                   1410:
                   1411: /*
                   1412:  * System control for IP6
                   1413:  */
                   1414:
                   1415: u_char inet6ctlerrmap[PRC_NCMDS] = {
                   1416:        0,              0,              0,              0,
                   1417:        0,              EMSGSIZE,       EHOSTDOWN,      EHOSTUNREACH,
                   1418:        EHOSTUNREACH,   EHOSTUNREACH,   ECONNREFUSED,   ECONNREFUSED,
                   1419:        EMSGSIZE,       EHOSTUNREACH,   0,              0,
                   1420:        0,              0,              0,              0,
                   1421:        ENOPROTOOPT
                   1422: };
                   1423:
1.64.2.1  skrll    1424: SYSCTL_SETUP(sysctl_net_inet6_ip6_setup, "sysctl net.inet6.ip6 subtree setup")
1.2       itojun   1425: {
1.26      itojun   1426:
1.64.2.1  skrll    1427:        sysctl_createv(clog, 0, NULL, NULL,
                   1428:                       CTLFLAG_PERMANENT,
                   1429:                       CTLTYPE_NODE, "net", NULL,
                   1430:                       NULL, 0, NULL, 0,
                   1431:                       CTL_NET, CTL_EOL);
                   1432:        sysctl_createv(clog, 0, NULL, NULL,
                   1433:                       CTLFLAG_PERMANENT,
                   1434:                       CTLTYPE_NODE, "inet6",
                   1435:                       SYSCTL_DESCR("PF_INET6 related settings"),
                   1436:                       NULL, 0, NULL, 0,
                   1437:                       CTL_NET, PF_INET6, CTL_EOL);
                   1438:        sysctl_createv(clog, 0, NULL, NULL,
                   1439:                       CTLFLAG_PERMANENT,
                   1440:                       CTLTYPE_NODE, "ip6",
                   1441:                       SYSCTL_DESCR("IPv6 related settings"),
                   1442:                       NULL, 0, NULL, 0,
                   1443:                       CTL_NET, PF_INET6, IPPROTO_IPV6, CTL_EOL);
                   1444:
                   1445:        sysctl_createv(clog, 0, NULL, NULL,
                   1446:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1447:                       CTLTYPE_INT, "forwarding",
                   1448:                       SYSCTL_DESCR("Enable forwarding of INET6 datagrams"),
                   1449:                       NULL, 0, &ip6_forwarding, 0,
                   1450:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1451:                       IPV6CTL_FORWARDING, CTL_EOL);
                   1452:        sysctl_createv(clog, 0, NULL, NULL,
                   1453:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1454:                       CTLTYPE_INT, "redirect",
                   1455:                       SYSCTL_DESCR("Enable sending of ICMPv6 redirect messages"),
                   1456:                       NULL, 0, &ip6_sendredirects, 0,
                   1457:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1458:                       IPV6CTL_SENDREDIRECTS, CTL_EOL);
                   1459:        sysctl_createv(clog, 0, NULL, NULL,
                   1460:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1461:                       CTLTYPE_INT, "hlim",
                   1462:                       SYSCTL_DESCR("Hop limit for an INET6 datagram"),
                   1463:                       NULL, 0, &ip6_defhlim, 0,
                   1464:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1465:                       IPV6CTL_DEFHLIM, CTL_EOL);
                   1466: #ifdef notyet
                   1467:        sysctl_createv(clog, 0, NULL, NULL,
                   1468:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1469:                       CTLTYPE_INT, "mtu", NULL,
                   1470:                       NULL, 0, &, 0,
                   1471:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1472:                       IPV6CTL_DEFMTU, CTL_EOL);
                   1473: #endif
                   1474: #ifdef __no_idea__
                   1475:        sysctl_createv(clog, 0, NULL, NULL,
                   1476:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1477:                       CTLTYPE_INT, "forwsrcrt", NULL,
                   1478:                       NULL, 0, &?, 0,
                   1479:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1480:                       IPV6CTL_FORWSRCRT, CTL_EOL);
                   1481:        sysctl_createv(clog, 0, NULL, NULL,
                   1482:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1483:                       CTLTYPE_STRUCT, "stats", NULL,
                   1484:                       NULL, 0, &?, sizeof(?),
                   1485:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1486:                       IPV6CTL_STATS, CTL_EOL);
                   1487:        sysctl_createv(clog, 0, NULL, NULL,
                   1488:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1489:                       CTLTYPE_STRUCT, "mrtstats", NULL,
                   1490:                       NULL, 0, &?, sizeof(?),
                   1491:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1492:                       IPV6CTL_MRTSTATS, CTL_EOL);
                   1493:        sysctl_createv(clog, 0, NULL, NULL,
                   1494:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1495:                       CTLTYPE_?, "mrtproto", NULL,
                   1496:                       NULL, 0, &?, sizeof(?),
                   1497:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1498:                       IPV6CTL_MRTPROTO, CTL_EOL);
                   1499: #endif
                   1500:        sysctl_createv(clog, 0, NULL, NULL,
                   1501:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1502:                       CTLTYPE_INT, "maxfragpackets",
                   1503:                       SYSCTL_DESCR("Maximum number of fragments to buffer "
                   1504:                                    "for reassembly"),
                   1505:                       NULL, 0, &ip6_maxfragpackets, 0,
                   1506:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1507:                       IPV6CTL_MAXFRAGPACKETS, CTL_EOL);
                   1508: #ifdef __no_idea__
                   1509:        sysctl_createv(clog, 0, NULL, NULL,
                   1510:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1511:                       CTLTYPE_INT, "sourcecheck", NULL,
                   1512:                       NULL, 0, &?, 0,
                   1513:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1514:                       IPV6CTL_SOURCECHECK, CTL_EOL);
                   1515:        sysctl_createv(clog, 0, NULL, NULL,
                   1516:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1517:                       CTLTYPE_INT, "sourcecheck_logint", NULL,
                   1518:                       NULL, 0, &?, 0,
                   1519:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1520:                       IPV6CTL_SOURCECHECK_LOGINT, CTL_EOL);
                   1521: #endif
                   1522:        sysctl_createv(clog, 0, NULL, NULL,
                   1523:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1524:                       CTLTYPE_INT, "accept_rtadv",
                   1525:                       SYSCTL_DESCR("Accept router advertisements"),
                   1526:                       NULL, 0, &ip6_accept_rtadv, 0,
                   1527:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1528:                       IPV6CTL_ACCEPT_RTADV, CTL_EOL);
                   1529:        sysctl_createv(clog, 0, NULL, NULL,
                   1530:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1531:                       CTLTYPE_INT, "keepfaith",
                   1532:                       SYSCTL_DESCR("Activate faith interface"),
                   1533:                       NULL, 0, &ip6_keepfaith, 0,
                   1534:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1535:                       IPV6CTL_KEEPFAITH, CTL_EOL);
                   1536:        sysctl_createv(clog, 0, NULL, NULL,
                   1537:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1538:                       CTLTYPE_INT, "log_interval",
                   1539:                       SYSCTL_DESCR("Minumum interval between logging "
                   1540:                                    "unroutable packets"),
                   1541:                       NULL, 0, &ip6_log_interval, 0,
                   1542:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1543:                       IPV6CTL_LOG_INTERVAL, CTL_EOL);
                   1544:        sysctl_createv(clog, 0, NULL, NULL,
                   1545:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1546:                       CTLTYPE_INT, "hdrnestlimit",
                   1547:                       SYSCTL_DESCR("Maximum number of nested IPv6 headers"),
                   1548:                       NULL, 0, &ip6_hdrnestlimit, 0,
                   1549:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1550:                       IPV6CTL_HDRNESTLIMIT, CTL_EOL);
                   1551:        sysctl_createv(clog, 0, NULL, NULL,
                   1552:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1553:                       CTLTYPE_INT, "dad_count",
                   1554:                       SYSCTL_DESCR("Number of Duplicate Address Detection "
                   1555:                                    "probes to send"),
                   1556:                       NULL, 0, &ip6_dad_count, 0,
                   1557:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1558:                       IPV6CTL_DAD_COUNT, CTL_EOL);
                   1559:        sysctl_createv(clog, 0, NULL, NULL,
                   1560:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1561:                       CTLTYPE_INT, "auto_flowlabel",
                   1562:                       SYSCTL_DESCR("Assign random IPv6 flow labels"),
                   1563:                       NULL, 0, &ip6_auto_flowlabel, 0,
                   1564:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1565:                       IPV6CTL_AUTO_FLOWLABEL, CTL_EOL);
                   1566:        sysctl_createv(clog, 0, NULL, NULL,
                   1567:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1568:                       CTLTYPE_INT, "defmcasthlim",
                   1569:                       SYSCTL_DESCR("Default multicast hop limit"),
                   1570:                       NULL, 0, &ip6_defmcasthlim, 0,
                   1571:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1572:                       IPV6CTL_DEFMCASTHLIM, CTL_EOL);
1.51      itojun   1573: #if NGIF > 0
1.64.2.1  skrll    1574:        sysctl_createv(clog, 0, NULL, NULL,
                   1575:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1576:                       CTLTYPE_INT, "gifhlim",
                   1577:                       SYSCTL_DESCR("Default hop limit for a gif tunnel datagram"),
                   1578:                       NULL, 0, &ip6_gif_hlim, 0,
                   1579:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1580:                       IPV6CTL_GIF_HLIM, CTL_EOL);
                   1581: #endif /* NGIF */
                   1582:        sysctl_createv(clog, 0, NULL, NULL,
                   1583:                       CTLFLAG_PERMANENT,
                   1584:                       CTLTYPE_STRING, "kame_version",
                   1585:                       SYSCTL_DESCR("KAME Version"),
                   1586:                       NULL, 0, __KAME_VERSION, 0,
                   1587:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1588:                       IPV6CTL_KAME_VERSION, CTL_EOL);
                   1589:        sysctl_createv(clog, 0, NULL, NULL,
                   1590:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1591:                       CTLTYPE_INT, "use_deprecated",
                   1592:                       SYSCTL_DESCR("Allow use of deprecated addresses as "
                   1593:                                    "source addresses"),
                   1594:                       NULL, 0, &ip6_use_deprecated, 0,
                   1595:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1596:                       IPV6CTL_USE_DEPRECATED, CTL_EOL);
                   1597:        sysctl_createv(clog, 0, NULL, NULL,
                   1598:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1599:                       CTLTYPE_INT, "rr_prune", NULL,
                   1600:                       NULL, 0, &ip6_rr_prune, 0,
                   1601:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1602:                       IPV6CTL_RR_PRUNE, CTL_EOL);
                   1603:        sysctl_createv(clog, 0, NULL, NULL,
                   1604:                       CTLFLAG_PERMANENT
                   1605: #ifndef INET6_BINDV6ONLY
                   1606:                       |CTLFLAG_READWRITE,
                   1607: #endif
                   1608:                       CTLTYPE_INT, "v6only",
                   1609:                       SYSCTL_DESCR("Disallow PF_INET6 sockets from connecting "
                   1610:                                    "to PF_INET sockets"),
                   1611:                       NULL, 0, &ip6_v6only, 0,
                   1612:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1613:                       IPV6CTL_V6ONLY, CTL_EOL);
                   1614:        sysctl_createv(clog, 0, NULL, NULL,
                   1615:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1616:                       CTLTYPE_INT, "anonportmin",
                   1617:                       SYSCTL_DESCR("Lowest ephemeral port number to assign"),
                   1618:                       sysctl_net_inet_ip_ports, 0, &ip6_anonportmin, 0,
                   1619:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1620:                       IPV6CTL_ANONPORTMIN, CTL_EOL);
                   1621:        sysctl_createv(clog, 0, NULL, NULL,
                   1622:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1623:                       CTLTYPE_INT, "anonportmax",
                   1624:                       SYSCTL_DESCR("Highest ephemeral port number to assign"),
                   1625:                       sysctl_net_inet_ip_ports, 0, &ip6_anonportmax, 0,
                   1626:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1627:                       IPV6CTL_ANONPORTMAX, CTL_EOL);
1.26      itojun   1628: #ifndef IPNOPRIVPORTS
1.64.2.1  skrll    1629:        sysctl_createv(clog, 0, NULL, NULL,
                   1630:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1631:                       CTLTYPE_INT, "lowportmin",
                   1632:                       SYSCTL_DESCR("Lowest privileged ephemeral port number "
                   1633:                                    "to assign"),
                   1634:                       sysctl_net_inet_ip_ports, 0, &ip6_lowportmin, 0,
                   1635:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1636:                       IPV6CTL_LOWPORTMIN, CTL_EOL);
                   1637:        sysctl_createv(clog, 0, NULL, NULL,
                   1638:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1639:                       CTLTYPE_INT, "lowportmax",
                   1640:                       SYSCTL_DESCR("Highest privileged ephemeral port number "
                   1641:                                    "to assign"),
                   1642:                       sysctl_net_inet_ip_ports, 0, &ip6_lowportmax, 0,
                   1643:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1644:                       IPV6CTL_LOWPORTMAX, CTL_EOL);
                   1645: #endif /* IPNOPRIVPORTS */
                   1646:        sysctl_createv(clog, 0, NULL, NULL,
                   1647:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1648:                       CTLTYPE_INT, "maxfrags",
                   1649:                       SYSCTL_DESCR("Maximum fragments in reassembly queue"),
                   1650:                       NULL, 0, &ip6_maxfrags, 0,
                   1651:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1652:                       IPV6CTL_MAXFRAGS, CTL_EOL);
1.2       itojun   1653: }

CVSweb <webmaster@jp.NetBSD.org>