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

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

CVSweb <webmaster@jp.NetBSD.org>