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

1.208.2.3! martin      1: /*     $NetBSD: ip6_input.c,v 1.208.2.2 2019/09/24 03:10:35 martin 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.208.2.3! martin     65: __KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.208.2.2 2019/09/24 03:10:35 martin Exp $");
1.2       itojun     66:
1.152     pooka      67: #ifdef _KERNEL_OPT
1.129     joerg      68: #include "opt_gateway.h"
1.2       itojun     69: #include "opt_inet.h"
1.85      rpaulo     70: #include "opt_inet6.h"
1.4       thorpej    71: #include "opt_ipsec.h"
1.169     ozaki-r    72: #include "opt_net_mpsafe.h"
1.152     pooka      73: #endif
1.2       itojun     74:
                     75: #include <sys/param.h>
                     76: #include <sys/systm.h>
                     77: #include <sys/mbuf.h>
                     78: #include <sys/domain.h>
                     79: #include <sys/protosw.h>
                     80: #include <sys/socket.h>
                     81: #include <sys/socketvar.h>
                     82: #include <sys/errno.h>
                     83: #include <sys/time.h>
                     84: #include <sys/kernel.h>
                     85: #include <sys/syslog.h>
                     86: #include <sys/proc.h>
1.46      simonb     87: #include <sys/sysctl.h>
1.133     tls        88: #include <sys/cprng.h>
1.167     ozaki-r    89: #include <sys/percpu.h>
1.2       itojun     90:
                     91: #include <net/if.h>
                     92: #include <net/if_types.h>
                     93: #include <net/if_dl.h>
                     94: #include <net/route.h>
1.148     rmind      95: #include <net/pktqueue.h>
1.15      darrenr    96: #include <net/pfil.h>
1.2       itojun     97:
                     98: #include <netinet/in.h>
1.9       itojun     99: #include <netinet/in_systm.h>
                    100: #ifdef INET
                    101: #include <netinet/ip.h>
1.148     rmind     102: #include <netinet/ip_var.h>
1.9       itojun    103: #include <netinet/ip_icmp.h>
1.45      itojun    104: #endif /* INET */
1.14      itojun    105: #include <netinet/ip6.h>
1.140     christos  106: #include <netinet/portalgo.h>
1.2       itojun    107: #include <netinet6/in6_var.h>
1.11      itojun    108: #include <netinet6/ip6_var.h>
1.116     thorpej   109: #include <netinet6/ip6_private.h>
1.2       itojun    110: #include <netinet6/in6_pcb.h>
1.14      itojun    111: #include <netinet/icmp6.h>
1.81      rpaulo    112: #include <netinet6/scope6_var.h>
1.2       itojun    113: #include <netinet6/in6_ifattach.h>
                    114: #include <netinet6/nd6.h>
                    115:
1.142     christos  116: #ifdef IPSEC
1.94      degroote  117: #include <netipsec/ipsec.h>
                    118: #include <netipsec/ipsec6.h>
                    119: #include <netipsec/key.h>
1.142     christos  120: #endif /* IPSEC */
1.94      degroote  121:
1.2       itojun    122: #include <netinet6/ip6protosw.h>
                    123:
                    124: #include "faith.h"
                    125:
                    126: extern struct domain inet6domain;
                    127:
                    128: u_char ip6_protox[IPPROTO_MAX];
1.148     rmind     129: pktqueue_t *ip6_pktq __read_mostly;
1.2       itojun    130:
1.143     rmind     131: pfil_head_t *inet6_pfil_hook;
1.29      thorpej   132:
1.116     thorpej   133: percpu_t *ip6stat_percpu;
1.2       itojun    134:
1.167     ozaki-r   135: percpu_t *ip6_forward_rt_percpu __cacheline_aligned;
                    136:
1.148     rmind     137: static void ip6intr(void *);
1.199     maxv      138: static bool ip6_badaddr(struct ip6_hdr *);
1.112     dyoung    139: static struct m_tag *ip6_setdstifaddr(struct mbuf *, const struct in6_ifaddr *);
1.2       itojun    140:
1.136     drochner  141: static int ip6_process_hopopts(struct mbuf *, u_int8_t *, int, u_int32_t *,
1.189     maxv      142:     u_int32_t *);
1.111     dyoung    143: static struct mbuf *ip6_pullexthdr(struct mbuf *, size_t, int);
1.128     pooka     144: static void sysctl_net_inet6_ip6_setup(struct sysctllog **);
1.2       itojun    145:
1.169     ozaki-r   146: #ifdef NET_MPSAFE
                    147: #define        SOFTNET_LOCK()          mutex_enter(softnet_lock)
                    148: #define        SOFTNET_UNLOCK()        mutex_exit(softnet_lock)
                    149: #else
                    150: #define        SOFTNET_LOCK()          KASSERT(mutex_owned(softnet_lock))
                    151: #define        SOFTNET_UNLOCK()        KASSERT(mutex_owned(softnet_lock))
                    152: #endif
                    153:
1.2       itojun    154: /*
                    155:  * IP6 initialization: fill in IP6 protocol switch table.
                    156:  * All protocols not implemented in kernel go to raw IP6 protocol handler.
                    157:  */
                    158: void
1.114     matt      159: ip6_init(void)
1.2       itojun    160: {
1.78      christos  161:        const struct ip6protosw *pr;
1.35      itojun    162:        int i;
1.2       itojun    163:
1.163     ozaki-r   164:        in6_init();
1.162     ozaki-r   165:
1.128     pooka     166:        sysctl_net_inet6_ip6_setup(NULL);
1.78      christos  167:        pr = (const struct ip6protosw *)pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW);
1.2       itojun    168:        if (pr == 0)
                    169:                panic("ip6_init");
                    170:        for (i = 0; i < IPPROTO_MAX; i++)
                    171:                ip6_protox[i] = pr - inet6sw;
1.78      christos  172:        for (pr = (const struct ip6protosw *)inet6domain.dom_protosw;
                    173:            pr < (const struct ip6protosw *)inet6domain.dom_protoswNPROTOSW; pr++)
1.2       itojun    174:                if (pr->pr_domain->dom_family == PF_INET6 &&
                    175:                    pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW)
                    176:                        ip6_protox[pr->pr_protocol] = pr - inet6sw;
1.148     rmind     177:
1.149     ozaki-r   178:        ip6_pktq = pktq_create(IFQ_MAXLEN, ip6intr, NULL);
1.148     rmind     179:        KASSERT(ip6_pktq != NULL);
                    180:
1.81      rpaulo    181:        scope6_init();
                    182:        addrsel_policy_init();
1.2       itojun    183:        nd6_init();
                    184:        frag6_init();
1.133     tls       185:        ip6_desync_factor = cprng_fast32() % MAX_TEMP_DESYNC_FACTOR;
1.2       itojun    186:
1.208.2.3! martin    187:        in6_tmpaddrtimer_init();
1.98      liamjfoy  188: #ifdef GATEWAY
1.99      liamjfoy  189:        ip6flow_init(ip6_hashsize);
1.98      liamjfoy  190: #endif
1.29      thorpej   191:        /* Register our Packet Filter hook. */
1.143     rmind     192:        inet6_pfil_hook = pfil_head_create(PFIL_TYPE_AF, (void *)AF_INET6);
                    193:        KASSERT(inet6_pfil_hook != NULL);
1.116     thorpej   194:
                    195:        ip6stat_percpu = percpu_alloc(sizeof(uint64_t) * IP6_NSTATS);
1.208.2.2  martin    196:        ip6_forward_rt_percpu = rtcache_percpu_alloc();
1.2       itojun    197: }
                    198:
                    199: /*
                    200:  * IP6 input interrupt handling. Just pass the packet to ip6_input.
                    201:  */
1.148     rmind     202: static void
                    203: ip6intr(void *arg __unused)
1.2       itojun    204: {
                    205:        struct mbuf *m;
                    206:
1.193     ozaki-r   207:        SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
1.148     rmind     208:        while ((m = pktq_dequeue(ip6_pktq)) != NULL) {
1.160     ozaki-r   209:                struct psref psref;
                    210:                struct ifnet *rcvif = m_get_rcvif_psref(m, &psref);
1.148     rmind     211:
1.160     ozaki-r   212:                if (rcvif == NULL) {
                    213:                        m_freem(m);
                    214:                        continue;
                    215:                }
1.148     rmind     216:                /*
                    217:                 * Drop the packet if IPv6 is disabled on the interface.
                    218:                 */
1.160     ozaki-r   219:                if ((ND_IFINFO(rcvif)->flags & ND6_IFF_IFDISABLED)) {
                    220:                        m_put_rcvif_psref(rcvif, &psref);
1.83      rpaulo    221:                        m_freem(m);
1.148     rmind     222:                        continue;
1.83      rpaulo    223:                }
1.160     ozaki-r   224:                ip6_input(m, rcvif);
                    225:                m_put_rcvif_psref(rcvif, &psref);
1.2       itojun    226:        }
1.193     ozaki-r   227:        SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
1.2       itojun    228: }
                    229:
                    230: void
1.160     ozaki-r   231: ip6_input(struct mbuf *m, struct ifnet *rcvif)
1.2       itojun    232: {
1.9       itojun    233:        struct ip6_hdr *ip6;
1.105     dyoung    234:        int hit, off = sizeof(struct ip6_hdr), nest;
1.2       itojun    235:        u_int32_t plen;
1.5       itojun    236:        u_int32_t rtalert = ~0;
1.188     maxv      237:        int nxt, ours = 0, rh_present = 0, frg_present;
1.9       itojun    238:        struct ifnet *deliverifp = NULL;
1.64      itojun    239:        int srcrt = 0;
1.171     ozaki-r   240:        struct rtentry *rt = NULL;
1.105     dyoung    241:        union {
                    242:                struct sockaddr         dst;
                    243:                struct sockaddr_in6     dst6;
                    244:        } u;
1.167     ozaki-r   245:        struct route *ro;
1.2       itojun    246:
1.186     maxv      247:        KASSERT(rcvif != NULL);
                    248:
1.2       itojun    249:        /*
1.81      rpaulo    250:         * make sure we don't have onion peering information into m_tag.
                    251:         */
                    252:        ip6_delaux(m);
                    253:
                    254:        /*
1.44      itojun    255:         * mbuf statistics
1.2       itojun    256:         */
                    257:        if (m->m_flags & M_EXT) {
                    258:                if (m->m_next)
1.116     thorpej   259:                        IP6_STATINC(IP6_STAT_MEXT2M);
1.2       itojun    260:                else
1.116     thorpej   261:                        IP6_STATINC(IP6_STAT_MEXT1);
1.2       itojun    262:        } else {
1.115     thorpej   263: #define M2MMAX 32
1.2       itojun    264:                if (m->m_next) {
1.159     ozaki-r   265:                        if (m->m_flags & M_LOOP)
1.116     thorpej   266:                        /*XXX*/ IP6_STATINC(IP6_STAT_M2M + lo0ifp->if_index);
1.159     ozaki-r   267:                        else if (rcvif->if_index < M2MMAX)
                    268:                                IP6_STATINC(IP6_STAT_M2M + rcvif->if_index);
                    269:                        else
1.116     thorpej   270:                                IP6_STATINC(IP6_STAT_M2M);
1.2       itojun    271:                } else
1.116     thorpej   272:                        IP6_STATINC(IP6_STAT_M1);
1.40      itojun    273: #undef M2MMAX
1.2       itojun    274:        }
                    275:
1.159     ozaki-r   276:        in6_ifstat_inc(rcvif, ifs6_in_receive);
1.116     thorpej   277:        IP6_STATINC(IP6_STAT_TOTAL);
1.9       itojun    278:
1.57      thorpej   279:        /*
                    280:         * If the IPv6 header is not aligned, slurp it up into a new
                    281:         * mbuf with space for link headers, in the event we forward
1.81      rpaulo    282:         * it.  Otherwise, if it is aligned, make sure the entire base
1.57      thorpej   283:         * IPv6 header is in the first mbuf of the chain.
                    284:         */
1.97      christos  285:        if (IP6_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
1.57      thorpej   286:                if ((m = m_copyup(m, sizeof(struct ip6_hdr),
1.186     maxv      287:                    (max_linkhdr + 3) & ~3)) == NULL) {
1.57      thorpej   288:                        /* XXXJRT new stat, please */
1.116     thorpej   289:                        IP6_STATINC(IP6_STAT_TOOSMALL);
1.159     ozaki-r   290:                        in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
1.57      thorpej   291:                        return;
                    292:                }
                    293:        } else if (__predict_false(m->m_len < sizeof(struct ip6_hdr))) {
1.55      itojun    294:                if ((m = m_pullup(m, sizeof(struct ip6_hdr))) == NULL) {
1.116     thorpej   295:                        IP6_STATINC(IP6_STAT_TOOSMALL);
1.159     ozaki-r   296:                        in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
1.9       itojun    297:                        return;
                    298:                }
1.2       itojun    299:        }
                    300:
                    301:        ip6 = mtod(m, struct ip6_hdr *);
                    302:
                    303:        if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) {
1.116     thorpej   304:                IP6_STATINC(IP6_STAT_BADVERS);
1.159     ozaki-r   305:                in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
1.2       itojun    306:                goto bad;
                    307:        }
1.15      darrenr   308:
1.199     maxv      309:        if (ip6_badaddr(ip6)) {
1.194     maxv      310:                IP6_STATINC(IP6_STAT_BADSCOPE);
                    311:                in6_ifstat_inc(rcvif, ifs6_in_addrerr);
                    312:                goto bad;
                    313:        }
                    314:
                    315:        /*
1.98      liamjfoy  316:         * Assume that we can create a fast-forward IP flow entry
                    317:         * based on this packet.
                    318:         */
                    319:        m->m_flags |= M_CANFASTFWD;
                    320:
1.15      darrenr   321:        /*
                    322:         * Run through list of hooks for input packets.  If there are any
                    323:         * filters which require that additional packets in the flow are
                    324:         * not fast-forwarded, they must clear the M_CANFASTFWD flag.
                    325:         * Note that filters must _never_ set this flag, as another filter
                    326:         * in the list may have previously cleared it.
1.196     maxv      327:         *
                    328:         * Don't call hooks if the packet has already been processed by
                    329:         * IPsec (encapsulated, tunnel mode).
1.39      itojun    330:         */
1.142     christos  331: #if defined(IPSEC)
1.207     knakahar  332:        if (!ipsec_used || !ipsec_skip_pfil(m))
1.39      itojun    333: #else
                    334:        if (1)
                    335: #endif
                    336:        {
1.64      itojun    337:                struct in6_addr odst;
1.208     ozaki-r   338:                int error;
1.64      itojun    339:
                    340:                odst = ip6->ip6_dst;
1.208     ozaki-r   341:                error = pfil_run_hooks(inet6_pfil_hook, &m, rcvif, PFIL_IN);
                    342:                if (error != 0 || m == NULL) {
                    343:                        IP6_STATINC(IP6_STAT_PFILDROP_IN);
1.39      itojun    344:                        return;
1.208     ozaki-r   345:                }
1.208.2.1  martin    346:                if (m->m_len < sizeof(struct ip6_hdr)) {
                    347:                        if ((m = m_pullup(m, sizeof(struct ip6_hdr))) == NULL) {
                    348:                                IP6_STATINC(IP6_STAT_TOOSMALL);
                    349:                                in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
                    350:                                return;
                    351:                        }
                    352:                }
1.39      itojun    353:                ip6 = mtod(m, struct ip6_hdr *);
1.64      itojun    354:                srcrt = !IN6_ARE_ADDR_EQUAL(&odst, &ip6->ip6_dst);
1.39      itojun    355:        }
1.15      darrenr   356:
1.116     thorpej   357:        IP6_STATINC(IP6_STAT_NXTHIST + ip6->ip6_nxt);
1.2       itojun    358:
1.30      thorpej   359: #ifdef ALTQ
1.169     ozaki-r   360:        if (altq_input != NULL) {
                    361:                SOFTNET_LOCK();
                    362:                if ((*altq_input)(m, AF_INET6) == 0) {
                    363:                        SOFTNET_UNLOCK();
                    364:                        /* packet is dropped by traffic conditioner */
                    365:                        return;
                    366:                }
                    367:                SOFTNET_UNLOCK();
1.9       itojun    368:        }
                    369: #endif
                    370:
1.2       itojun    371:        /*
1.82      yamt      372:         * Disambiguate address scope zones (if there is ambiguity).
                    373:         * We first make sure that the original source or destination address
                    374:         * is not in our internal form for scoped addresses.  Such addresses
                    375:         * are not necessarily invalid spec-wise, but we cannot accept them due
                    376:         * to the usage conflict.
                    377:         * in6_setscope() then also checks and rejects the cases where src or
                    378:         * dst are the loopback address and the receiving interface
1.186     maxv      379:         * is not loopback.
1.82      yamt      380:         */
1.88      bouyer    381:        if (__predict_false(
                    382:            m_makewritable(&m, 0, sizeof(struct ip6_hdr), M_DONTWAIT)))
                    383:                goto bad;
                    384:        ip6 = mtod(m, struct ip6_hdr *);
1.82      yamt      385:        if (in6_clearscope(&ip6->ip6_src) || in6_clearscope(&ip6->ip6_dst)) {
1.116     thorpej   386:                IP6_STATINC(IP6_STAT_BADSCOPE); /* XXX */
1.82      yamt      387:                goto bad;
                    388:        }
1.159     ozaki-r   389:        if (in6_setscope(&ip6->ip6_src, rcvif, NULL) ||
                    390:            in6_setscope(&ip6->ip6_dst, rcvif, NULL)) {
1.116     thorpej   391:                IP6_STATINC(IP6_STAT_BADSCOPE);
1.82      yamt      392:                goto bad;
                    393:        }
                    394:
1.208.2.2  martin    395:        ro = rtcache_percpu_getref(ip6_forward_rt_percpu);
1.186     maxv      396:
1.82      yamt      397:        /*
1.2       itojun    398:         * Multicast check
                    399:         */
                    400:        if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
1.176     ozaki-r   401:                bool ingroup;
1.9       itojun    402:
1.159     ozaki-r   403:                in6_ifstat_inc(rcvif, ifs6_in_mcast);
1.2       itojun    404:                /*
                    405:                 * See if we belong to the destination multicast group on the
                    406:                 * arrival interface.
                    407:                 */
1.176     ozaki-r   408:                ingroup = in6_multi_group(&ip6->ip6_dst, rcvif);
1.186     maxv      409:                if (ingroup) {
1.2       itojun    410:                        ours = 1;
1.186     maxv      411:                } else if (!ip6_mrouter) {
1.116     thorpej   412:                        uint64_t *ip6s = IP6_STAT_GETREF();
                    413:                        ip6s[IP6_STAT_NOTMEMBER]++;
                    414:                        ip6s[IP6_STAT_CANTFORWARD]++;
                    415:                        IP6_STAT_PUTREF();
1.159     ozaki-r   416:                        in6_ifstat_inc(rcvif, ifs6_in_discard);
1.171     ozaki-r   417:                        goto bad_unref;
1.2       itojun    418:                }
1.159     ozaki-r   419:                deliverifp = rcvif;
1.2       itojun    420:                goto hbhcheck;
                    421:        }
                    422:
1.105     dyoung    423:        sockaddr_in6_init(&u.dst6, &ip6->ip6_dst, 0, 0, 0);
                    424:
1.2       itojun    425:        /*
1.186     maxv      426:         * Unicast check
1.2       itojun    427:         */
1.167     ozaki-r   428:        rt = rtcache_lookup2(ro, &u.dst, 1, &hit);
1.105     dyoung    429:        if (hit)
1.116     thorpej   430:                IP6_STATINC(IP6_STAT_FORWARD_CACHEHIT);
1.93      joerg     431:        else
1.116     thorpej   432:                IP6_STATINC(IP6_STAT_FORWARD_CACHEMISS);
1.22      itojun    433:
1.2       itojun    434:        /*
                    435:         * Accept the packet if the forwarding interface to the destination
1.186     maxv      436:         * (according to the routing table) is the loopback interface,
1.2       itojun    437:         * unless the associated route has a gateway.
1.186     maxv      438:         *
                    439:         * We don't explicitly match ip6_dst against an interface here. It
                    440:         * is already done in rtcache_lookup2: rt->rt_ifp->if_type will be
                    441:         * IFT_LOOP if the packet is for us.
                    442:         *
1.2       itojun    443:         * Note that this approach causes to accept a packet if there is a
                    444:         * route to the loopback interface for the destination of the packet.
                    445:         * But we think it's even useful in some situations, e.g. when using
                    446:         * a special daemon which wants to intercept the packet.
                    447:         */
1.105     dyoung    448:        if (rt != NULL &&
                    449:            (rt->rt_flags & (RTF_HOST|RTF_GATEWAY)) == RTF_HOST &&
                    450:            rt->rt_ifp->if_type == IFT_LOOP) {
                    451:                struct in6_ifaddr *ia6 = (struct in6_ifaddr *)rt->rt_ifa;
1.184     roy       452:                int addrok;
                    453:
1.2       itojun    454:                if (ia6->ia6_flags & IN6_IFF_ANYCAST)
                    455:                        m->m_flags |= M_ANYCAST6;
1.24      itojun    456:                /*
                    457:                 * packets to a tentative, duplicated, or somehow invalid
                    458:                 * address must not be accepted.
                    459:                 */
1.184     roy       460:                if (ia6->ia6_flags & IN6_IFF_NOTREADY)
                    461:                        addrok = 0;
                    462:                else if (ia6->ia6_flags & IN6_IFF_DETACHED &&
                    463:                    !IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src))
                    464:                {
                    465:                        /* Allow internal traffic to DETACHED addresses */
                    466:                        struct sockaddr_in6 sin6;
                    467:                        int s;
                    468:
                    469:                        memset(&sin6, 0, sizeof(sin6));
                    470:                        sin6.sin6_family = AF_INET6;
                    471:                        sin6.sin6_len = sizeof(sin6);
                    472:                        sin6.sin6_addr = ip6->ip6_src;
                    473:                        s = pserialize_read_enter();
                    474:                        addrok = (ifa_ifwithaddr(sin6tosa(&sin6)) != NULL);
                    475:                        pserialize_read_exit(s);
                    476:                } else
1.185     kre       477:                        addrok = 1;
1.184     roy       478:                if (addrok) {
1.24      itojun    479:                        /* this address is ready */
1.2       itojun    480:                        ours = 1;
1.9       itojun    481:                        deliverifp = ia6->ia_ifp;       /* correct? */
1.2       itojun    482:                        goto hbhcheck;
                    483:                } else {
1.24      itojun    484:                        /* address is not ready, so discard the packet. */
1.172     ryo       485:                        char ip6bufs[INET6_ADDRSTRLEN];
                    486:                        char ip6bufd[INET6_ADDRSTRLEN];
1.157     ozaki-r   487:                        nd6log(LOG_INFO, "packet to an unready address %s->%s\n",
1.173     christos  488:                            IN6_PRINT(ip6bufs, &ip6->ip6_src),
                    489:                            IN6_PRINT(ip6bufd, &ip6->ip6_dst));
1.24      itojun    490:
1.171     ozaki-r   491:                        goto bad_unref;
1.2       itojun    492:                }
                    493:        }
                    494:
                    495:        /*
1.55      itojun    496:         * FAITH (Firewall Aided Internet Translator)
1.2       itojun    497:         */
                    498: #if defined(NFAITH) && 0 < NFAITH
                    499:        if (ip6_keepfaith) {
1.105     dyoung    500:                if (rt != NULL && rt->rt_ifp != NULL &&
                    501:                    rt->rt_ifp->if_type == IFT_FAITH) {
1.2       itojun    502:                        /* XXX do we need more sanity checks? */
                    503:                        ours = 1;
1.105     dyoung    504:                        deliverifp = rt->rt_ifp; /* faith */
1.9       itojun    505:                        goto hbhcheck;
                    506:                }
                    507:        }
                    508: #endif
                    509:
1.2       itojun    510:        /*
                    511:         * Now there is no reason to process the packet if it's not our own
                    512:         * and we're not a router.
                    513:         */
                    514:        if (!ip6_forwarding) {
1.116     thorpej   515:                IP6_STATINC(IP6_STAT_CANTFORWARD);
1.159     ozaki-r   516:                in6_ifstat_inc(rcvif, ifs6_in_discard);
1.171     ozaki-r   517:                goto bad_unref;
1.2       itojun    518:        }
                    519:
1.186     maxv      520: hbhcheck:
1.2       itojun    521:        /*
1.186     maxv      522:         * Record address information into m_tag, if we don't have one yet.
                    523:         * Note that we are unable to record it, if the address is not listed
1.81      rpaulo    524:         * as our interface address (e.g. multicast addresses, addresses
                    525:         * within FAITH prefixes and such).
                    526:         */
1.111     dyoung    527:        if (deliverifp && ip6_getdstifaddr(m) == NULL) {
1.81      rpaulo    528:                struct in6_ifaddr *ia6;
1.165     ozaki-r   529:                int s = pserialize_read_enter();
1.81      rpaulo    530:
                    531:                ia6 = in6_ifawithifp(deliverifp, &ip6->ip6_dst);
1.165     ozaki-r   532:                /* Depends on ip6_setdstifaddr never sleep */
1.111     dyoung    533:                if (ia6 != NULL && ip6_setdstifaddr(m, ia6) == NULL) {
                    534:                        /*
                    535:                         * XXX maybe we should drop the packet here,
                    536:                         * as we could not provide enough information
                    537:                         * to the upper layers.
                    538:                         */
1.81      rpaulo    539:                }
1.165     ozaki-r   540:                pserialize_read_exit(s);
1.81      rpaulo    541:        }
                    542:
                    543:        /*
1.2       itojun    544:         * Process Hop-by-Hop options header if it's contained.
                    545:         * m may be modified in ip6_hopopts_input().
                    546:         * If a JumboPayload option is included, plen will also be modified.
                    547:         */
                    548:        plen = (u_int32_t)ntohs(ip6->ip6_plen);
                    549:        if (ip6->ip6_nxt == IPPROTO_HOPOPTS) {
1.9       itojun    550:                struct ip6_hbh *hbh;
                    551:
                    552:                if (ip6_hopopts_input(&plen, &rtalert, &m, &off)) {
1.186     maxv      553:                        /* m already freed */
1.159     ozaki-r   554:                        in6_ifstat_inc(rcvif, ifs6_in_discard);
1.171     ozaki-r   555:                        rtcache_unref(rt, ro);
1.208.2.2  martin    556:                        rtcache_percpu_putref(ip6_forward_rt_percpu);
1.186     maxv      557:                        return;
1.9       itojun    558:                }
1.22      itojun    559:
1.2       itojun    560:                /* adjust pointer */
                    561:                ip6 = mtod(m, struct ip6_hdr *);
1.22      itojun    562:
                    563:                /*
1.49      itojun    564:                 * if the payload length field is 0 and the next header field
1.22      itojun    565:                 * indicates Hop-by-Hop Options header, then a Jumbo Payload
                    566:                 * option MUST be included.
                    567:                 */
                    568:                if (ip6->ip6_plen == 0 && plen == 0) {
                    569:                        /*
                    570:                         * Note that if a valid jumbo payload option is
1.83      rpaulo    571:                         * contained, ip6_hopopts_input() must set a valid
1.55      itojun    572:                         * (non-zero) payload length to the variable plen.
1.22      itojun    573:                         */
1.116     thorpej   574:                        IP6_STATINC(IP6_STAT_BADOPTIONS);
1.159     ozaki-r   575:                        in6_ifstat_inc(rcvif, ifs6_in_discard);
                    576:                        in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
1.22      itojun    577:                        icmp6_error(m, ICMP6_PARAM_PROB,
                    578:                                    ICMP6_PARAMPROB_HEADER,
1.97      christos  579:                                    (char *)&ip6->ip6_plen - (char *)ip6);
1.171     ozaki-r   580:                        rtcache_unref(rt, ro);
1.208.2.2  martin    581:                        rtcache_percpu_putref(ip6_forward_rt_percpu);
1.22      itojun    582:                        return;
                    583:                }
1.9       itojun    584:                IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr),
                    585:                        sizeof(struct ip6_hbh));
                    586:                if (hbh == NULL) {
1.116     thorpej   587:                        IP6_STATINC(IP6_STAT_TOOSHORT);
1.171     ozaki-r   588:                        rtcache_unref(rt, ro);
1.208.2.2  martin    589:                        rtcache_percpu_putref(ip6_forward_rt_percpu);
1.9       itojun    590:                        return;
                    591:                }
1.57      thorpej   592:                KASSERT(IP6_HDR_ALIGNED_P(hbh));
1.9       itojun    593:                nxt = hbh->ip6h_nxt;
1.2       itojun    594:
                    595:                /*
                    596:                 * accept the packet if a router alert option is included
                    597:                 * and we act as an IPv6 router.
                    598:                 */
1.5       itojun    599:                if (rtalert != ~0 && ip6_forwarding)
1.2       itojun    600:                        ours = 1;
                    601:        } else
                    602:                nxt = ip6->ip6_nxt;
                    603:
                    604:        /*
1.186     maxv      605:         * Check that the amount of data in the buffers is at least much as
                    606:         * the IPv6 header would have us expect. Trim mbufs if longer than we
                    607:         * expect. Drop packet if shorter than we expect.
1.2       itojun    608:         */
                    609:        if (m->m_pkthdr.len - sizeof(struct ip6_hdr) < plen) {
1.116     thorpej   610:                IP6_STATINC(IP6_STAT_TOOSHORT);
1.159     ozaki-r   611:                in6_ifstat_inc(rcvif, ifs6_in_truncated);
1.171     ozaki-r   612:                goto bad_unref;
1.2       itojun    613:        }
                    614:        if (m->m_pkthdr.len > sizeof(struct ip6_hdr) + plen) {
                    615:                if (m->m_len == m->m_pkthdr.len) {
                    616:                        m->m_len = sizeof(struct ip6_hdr) + plen;
                    617:                        m->m_pkthdr.len = sizeof(struct ip6_hdr) + plen;
                    618:                } else
                    619:                        m_adj(m, sizeof(struct ip6_hdr) + plen - m->m_pkthdr.len);
                    620:        }
                    621:
                    622:        /*
                    623:         * Forward if desirable.
                    624:         */
                    625:        if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
                    626:                /*
                    627:                 * If we are acting as a multicast router, all
                    628:                 * incoming multicast packets are passed to the
                    629:                 * kernel-level multicast forwarding function.
                    630:                 * The packet is returned (relatively) intact; if
                    631:                 * ip6_mforward() returns a non-zero value, the packet
                    632:                 * must be discarded, else it may be accepted below.
                    633:                 */
1.169     ozaki-r   634:                if (ip6_mrouter != NULL) {
                    635:                        int error;
                    636:
                    637:                        SOFTNET_LOCK();
                    638:                        error = ip6_mforward(ip6, rcvif, m);
                    639:                        SOFTNET_UNLOCK();
                    640:
                    641:                        if (error != 0) {
1.171     ozaki-r   642:                                rtcache_unref(rt, ro);
1.208.2.2  martin    643:                                rtcache_percpu_putref(ip6_forward_rt_percpu);
1.169     ozaki-r   644:                                IP6_STATINC(IP6_STAT_CANTFORWARD);
1.170     ozaki-r   645:                                goto bad;
1.169     ozaki-r   646:                        }
1.2       itojun    647:                }
1.170     ozaki-r   648:                if (!ours)
1.171     ozaki-r   649:                        goto bad_unref;
1.22      itojun    650:        } else if (!ours) {
1.171     ozaki-r   651:                rtcache_unref(rt, ro);
1.208.2.2  martin    652:                rtcache_percpu_putref(ip6_forward_rt_percpu);
1.64      itojun    653:                ip6_forward(m, srcrt);
1.2       itojun    654:                return;
1.56      itojun    655:        }
1.25      itojun    656:
                    657:        ip6 = mtod(m, struct ip6_hdr *);
                    658:
                    659:        /*
                    660:         * Malicious party may be able to use IPv4 mapped addr to confuse
                    661:         * tcp/udp stack and bypass security checks (act as if it was from
                    662:         * 127.0.0.1 by using IPv6 src ::ffff:127.0.0.1).  Be cautious.
                    663:         *
                    664:         * For SIIT end node behavior, you may want to disable the check.
                    665:         * However, you will  become vulnerable to attacks using IPv4 mapped
                    666:         * source.
                    667:         */
                    668:        if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) ||
                    669:            IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) {
1.116     thorpej   670:                IP6_STATINC(IP6_STAT_BADSCOPE);
1.159     ozaki-r   671:                in6_ifstat_inc(rcvif, ifs6_in_addrerr);
1.171     ozaki-r   672:                goto bad_unref;
1.25      itojun    673:        }
1.2       itojun    674:
1.12      itojun    675: #ifdef IFA_STATS
1.28      itojun    676:        if (deliverifp != NULL) {
1.9       itojun    677:                struct in6_ifaddr *ia6;
1.165     ozaki-r   678:                int s = pserialize_read_enter();
1.9       itojun    679:                ia6 = in6_ifawithifp(deliverifp, &ip6->ip6_dst);
                    680:                if (ia6)
                    681:                        ia6->ia_ifa.ifa_data.ifad_inbytes += m->m_pkthdr.len;
1.165     ozaki-r   682:                pserialize_read_exit(s);
1.9       itojun    683:        }
                    684: #endif
1.116     thorpej   685:        IP6_STATINC(IP6_STAT_DELIVERED);
1.9       itojun    686:        in6_ifstat_inc(deliverifp, ifs6_in_deliver);
1.2       itojun    687:        nest = 0;
1.40      itojun    688:
1.171     ozaki-r   689:        if (rt != NULL) {
                    690:                rtcache_unref(rt, ro);
                    691:                rt = NULL;
                    692:        }
1.208.2.2  martin    693:        rtcache_percpu_putref(ip6_forward_rt_percpu);
1.171     ozaki-r   694:
1.104     yamt      695:        rh_present = 0;
1.188     maxv      696:        frg_present = 0;
1.2       itojun    697:        while (nxt != IPPROTO_DONE) {
                    698:                if (ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) {
1.116     thorpej   699:                        IP6_STATINC(IP6_STAT_TOOMANYHDR);
1.159     ozaki-r   700:                        in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
1.2       itojun    701:                        goto bad;
                    702:                }
1.8       itojun    703:
1.197     maxv      704:                M_VERIFY_PACKET(m);
                    705:
1.8       itojun    706:                /*
                    707:                 * protection against faulty packet - there should be
                    708:                 * more sanity checks in header chain processing.
                    709:                 */
                    710:                if (m->m_pkthdr.len < off) {
1.116     thorpej   711:                        IP6_STATINC(IP6_STAT_TOOSHORT);
1.159     ozaki-r   712:                        in6_ifstat_inc(rcvif, ifs6_in_truncated);
1.8       itojun    713:                        goto bad;
                    714:                }
                    715:
1.104     yamt      716:                if (nxt == IPPROTO_ROUTING) {
                    717:                        if (rh_present++) {
1.159     ozaki-r   718:                                in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
1.116     thorpej   719:                                IP6_STATINC(IP6_STAT_BADOPTIONS);
1.104     yamt      720:                                goto bad;
                    721:                        }
1.188     maxv      722:                } else if (nxt == IPPROTO_FRAGMENT) {
                    723:                        if (frg_present++) {
                    724:                                in6_ifstat_inc(rcvif, ifs6_in_hdrerr);
                    725:                                IP6_STATINC(IP6_STAT_BADOPTIONS);
                    726:                                goto bad;
                    727:                        }
1.104     yamt      728:                }
                    729:
1.142     christos  730: #ifdef IPSEC
1.146     christos  731:                if (ipsec_used) {
1.94      degroote  732:                        /*
1.186     maxv      733:                         * Enforce IPsec policy checking if we are seeing last
                    734:                         * header. Note that we do not visit this with
1.146     christos  735:                         * protocols with pcb layer code - like udp/tcp/raw ip.
1.94      degroote  736:                         */
1.206     maxv      737:                        if ((inet6sw[ip6_protox[nxt]].pr_flags
1.146     christos  738:                            & PR_LASTHDR) != 0) {
1.169     ozaki-r   739:                                int error;
                    740:
1.202     maxv      741:                                error = ipsec_ip_input(m, false);
1.146     christos  742:                                if (error)
                    743:                                        goto bad;
                    744:                        }
1.94      degroote  745:                }
1.186     maxv      746: #endif
1.94      degroote  747:
1.2       itojun    748:                nxt = (*inet6sw[ip6_protox[nxt]].pr_input)(&m, &off, nxt);
                    749:        }
                    750:        return;
1.171     ozaki-r   751:
1.186     maxv      752: bad_unref:
1.171     ozaki-r   753:        rtcache_unref(rt, ro);
1.208.2.2  martin    754:        rtcache_percpu_putref(ip6_forward_rt_percpu);
1.186     maxv      755: bad:
1.2       itojun    756:        m_freem(m);
1.171     ozaki-r   757:        return;
1.2       itojun    758: }
                    759:
1.199     maxv      760: static bool
                    761: ip6_badaddr(struct ip6_hdr *ip6)
                    762: {
                    763:        /* Check against address spoofing/corruption. */
                    764:        if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_src) ||
                    765:            IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_dst)) {
                    766:                return true;
                    767:        }
                    768:
                    769:        /*
                    770:         * The following check is not documented in specs.  A malicious
                    771:         * party may be able to use IPv4 mapped addr to confuse tcp/udp stack
                    772:         * and bypass security checks (act as if it was from 127.0.0.1 by using
                    773:         * IPv6 src ::ffff:127.0.0.1).  Be cautious.
                    774:         *
                    775:         * This check chokes if we are in an SIIT cloud.  As none of BSDs
                    776:         * support IPv4-less kernel compilation, we cannot support SIIT
                    777:         * environment at all.  So, it makes more sense for us to reject any
                    778:         * malicious packets for non-SIIT environment, than try to do a
                    779:         * partial support for SIIT environment.
                    780:         */
                    781:        if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) ||
                    782:            IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) {
                    783:                return true;
                    784:        }
                    785:
                    786:        /*
                    787:         * Reject packets with IPv4-compatible IPv6 addresses (RFC4291).
                    788:         */
                    789:        if (IN6_IS_ADDR_V4COMPAT(&ip6->ip6_src) ||
                    790:            IN6_IS_ADDR_V4COMPAT(&ip6->ip6_dst)) {
                    791:                return true;
                    792:        }
                    793:
                    794:        return false;
                    795: }
                    796:
1.2       itojun    797: /*
1.81      rpaulo    798:  * set/grab in6_ifaddr correspond to IPv6 destination address.
                    799:  */
                    800: static struct m_tag *
1.112     dyoung    801: ip6_setdstifaddr(struct mbuf *m, const struct in6_ifaddr *ia)
1.81      rpaulo    802: {
                    803:        struct m_tag *mtag;
1.144     christos  804:        struct ip6aux *ip6a;
1.81      rpaulo    805:
                    806:        mtag = ip6_addaux(m);
1.144     christos  807:        if (mtag == NULL)
                    808:                return NULL;
1.112     dyoung    809:
1.144     christos  810:        ip6a = (struct ip6aux *)(mtag + 1);
                    811:        if (in6_setscope(&ip6a->ip6a_src, ia->ia_ifp, &ip6a->ip6a_scope_id)) {
                    812:                IP6_STATINC(IP6_STAT_BADSCOPE);
                    813:                return NULL;
1.112     dyoung    814:        }
1.144     christos  815:
                    816:        ip6a->ip6a_src = ia->ia_addr.sin6_addr;
                    817:        ip6a->ip6a_flags = ia->ia6_flags;
                    818:        return mtag;
1.81      rpaulo    819: }
                    820:
1.112     dyoung    821: const struct ip6aux *
1.107     christos  822: ip6_getdstifaddr(struct mbuf *m)
1.81      rpaulo    823: {
                    824:        struct m_tag *mtag;
                    825:
                    826:        mtag = ip6_findaux(m);
1.112     dyoung    827:        if (mtag != NULL)
                    828:                return (struct ip6aux *)(mtag + 1);
1.81      rpaulo    829:        else
                    830:                return NULL;
                    831: }
                    832:
                    833: /*
1.2       itojun    834:  * Hop-by-Hop options header processing. If a valid jumbo payload option is
                    835:  * included, the real payload length will be stored in plenp.
1.107     christos  836:  *
                    837:  * rtalertp - XXX: should be stored more smart way
1.2       itojun    838:  */
1.136     drochner  839: int
1.107     christos  840: ip6_hopopts_input(u_int32_t *plenp, u_int32_t *rtalertp,
                    841:        struct mbuf **mp, int *offp)
1.2       itojun    842: {
1.35      itojun    843:        struct mbuf *m = *mp;
1.2       itojun    844:        int off = *offp, hbhlen;
                    845:        struct ip6_hbh *hbh;
                    846:
                    847:        /* validation of the length of the header */
1.9       itojun    848:        IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m,
1.189     maxv      849:            sizeof(struct ip6_hdr), sizeof(struct ip6_hbh));
1.9       itojun    850:        if (hbh == NULL) {
1.116     thorpej   851:                IP6_STATINC(IP6_STAT_TOOSHORT);
1.9       itojun    852:                return -1;
                    853:        }
                    854:        hbhlen = (hbh->ip6h_len + 1) << 3;
                    855:        IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr),
1.189     maxv      856:            hbhlen);
1.9       itojun    857:        if (hbh == NULL) {
1.116     thorpej   858:                IP6_STATINC(IP6_STAT_TOOSHORT);
1.9       itojun    859:                return -1;
                    860:        }
1.57      thorpej   861:        KASSERT(IP6_HDR_ALIGNED_P(hbh));
1.2       itojun    862:        off += hbhlen;
                    863:        hbhlen -= sizeof(struct ip6_hbh);
                    864:
                    865:        if (ip6_process_hopopts(m, (u_int8_t *)hbh + sizeof(struct ip6_hbh),
1.189     maxv      866:            hbhlen, rtalertp, plenp) < 0)
                    867:                return -1;
1.2       itojun    868:
                    869:        *offp = off;
                    870:        *mp = m;
1.189     maxv      871:        return 0;
1.2       itojun    872: }
                    873:
                    874: /*
                    875:  * Search header for all Hop-by-hop options and process each option.
                    876:  * This function is separate from ip6_hopopts_input() in order to
                    877:  * handle a case where the sending node itself process its hop-by-hop
                    878:  * options header. In such a case, the function is called from ip6_output().
1.55      itojun    879:  *
                    880:  * The function assumes that hbh header is located right after the IPv6 header
                    881:  * (RFC2460 p7), opthead is pointer into data content in m, and opthead to
                    882:  * opthead + hbhlen is located in continuous memory region.
1.2       itojun    883:  */
1.136     drochner  884: static int
1.107     christos  885: ip6_process_hopopts(struct mbuf *m, u_int8_t *opthead, int hbhlen,
                    886:        u_int32_t *rtalertp, u_int32_t *plenp)
1.2       itojun    887: {
                    888:        struct ip6_hdr *ip6;
                    889:        int optlen = 0;
                    890:        u_int8_t *opt = opthead;
                    891:        u_int16_t rtalert_val;
1.22      itojun    892:        u_int32_t jumboplen;
1.55      itojun    893:        const int erroff = sizeof(struct ip6_hdr) + sizeof(struct ip6_hbh);
1.2       itojun    894:
                    895:        for (; hbhlen > 0; hbhlen -= optlen, opt += optlen) {
1.35      itojun    896:                switch (*opt) {
                    897:                case IP6OPT_PAD1:
                    898:                        optlen = 1;
                    899:                        break;
                    900:                case IP6OPT_PADN:
                    901:                        if (hbhlen < IP6OPT_MINLEN) {
1.116     thorpej   902:                                IP6_STATINC(IP6_STAT_TOOSMALL);
1.35      itojun    903:                                goto bad;
                    904:                        }
                    905:                        optlen = *(opt + 1) + 2;
                    906:                        break;
                    907:                case IP6OPT_RTALERT:
                    908:                        /* XXX may need check for alignment */
                    909:                        if (hbhlen < IP6OPT_RTALERT_LEN) {
1.116     thorpej   910:                                IP6_STATINC(IP6_STAT_TOOSMALL);
1.35      itojun    911:                                goto bad;
                    912:                        }
                    913:                        if (*(opt + 1) != IP6OPT_RTALERT_LEN - 2) {
1.55      itojun    914:                                /* XXX stat */
                    915:                                icmp6_error(m, ICMP6_PARAM_PROB,
                    916:                                    ICMP6_PARAMPROB_HEADER,
                    917:                                    erroff + opt + 1 - opthead);
                    918:                                return (-1);
1.35      itojun    919:                        }
                    920:                        optlen = IP6OPT_RTALERT_LEN;
1.126     tsutsui   921:                        memcpy((void *)&rtalert_val, (void *)(opt + 2), 2);
1.35      itojun    922:                        *rtalertp = ntohs(rtalert_val);
                    923:                        break;
                    924:                case IP6OPT_JUMBO:
1.22      itojun    925:                        /* XXX may need check for alignment */
                    926:                        if (hbhlen < IP6OPT_JUMBO_LEN) {
1.116     thorpej   927:                                IP6_STATINC(IP6_STAT_TOOSMALL);
1.22      itojun    928:                                goto bad;
                    929:                        }
1.35      itojun    930:                        if (*(opt + 1) != IP6OPT_JUMBO_LEN - 2) {
1.55      itojun    931:                                /* XXX stat */
                    932:                                icmp6_error(m, ICMP6_PARAM_PROB,
                    933:                                    ICMP6_PARAMPROB_HEADER,
                    934:                                    erroff + opt + 1 - opthead);
                    935:                                return (-1);
1.35      itojun    936:                        }
1.22      itojun    937:                        optlen = IP6OPT_JUMBO_LEN;
                    938:
                    939:                        /*
                    940:                         * IPv6 packets that have non 0 payload length
1.35      itojun    941:                         * must not contain a jumbo payload option.
1.22      itojun    942:                         */
                    943:                        ip6 = mtod(m, struct ip6_hdr *);
                    944:                        if (ip6->ip6_plen) {
1.116     thorpej   945:                                IP6_STATINC(IP6_STAT_BADOPTIONS);
1.22      itojun    946:                                icmp6_error(m, ICMP6_PARAM_PROB,
1.55      itojun    947:                                    ICMP6_PARAMPROB_HEADER,
                    948:                                    erroff + opt - opthead);
                    949:                                return (-1);
1.22      itojun    950:                        }
1.2       itojun    951:
1.22      itojun    952:                        /*
                    953:                         * We may see jumbolen in unaligned location, so
1.191     maxv      954:                         * we'd need to perform memcpy().
1.22      itojun    955:                         */
1.126     tsutsui   956:                        memcpy(&jumboplen, opt + 2, sizeof(jumboplen));
1.22      itojun    957:                        jumboplen = (u_int32_t)htonl(jumboplen);
                    958:
                    959: #if 1
                    960:                        /*
                    961:                         * if there are multiple jumbo payload options,
                    962:                         * *plenp will be non-zero and the packet will be
                    963:                         * rejected.
                    964:                         * the behavior may need some debate in ipngwg -
                    965:                         * multiple options does not make sense, however,
                    966:                         * there's no explicit mention in specification.
                    967:                         */
                    968:                        if (*plenp != 0) {
1.116     thorpej   969:                                IP6_STATINC(IP6_STAT_BADOPTIONS);
1.22      itojun    970:                                icmp6_error(m, ICMP6_PARAM_PROB,
1.55      itojun    971:                                    ICMP6_PARAMPROB_HEADER,
                    972:                                    erroff + opt + 2 - opthead);
                    973:                                return (-1);
1.22      itojun    974:                        }
1.8       itojun    975: #endif
1.2       itojun    976:
1.22      itojun    977:                        /*
                    978:                         * jumbo payload length must be larger than 65535.
                    979:                         */
                    980:                        if (jumboplen <= IPV6_MAXPACKET) {
1.116     thorpej   981:                                IP6_STATINC(IP6_STAT_BADOPTIONS);
1.22      itojun    982:                                icmp6_error(m, ICMP6_PARAM_PROB,
1.55      itojun    983:                                    ICMP6_PARAMPROB_HEADER,
                    984:                                    erroff + opt + 2 - opthead);
                    985:                                return (-1);
1.22      itojun    986:                        }
                    987:                        *plenp = jumboplen;
                    988:
                    989:                        break;
1.35      itojun    990:                default:                /* unknown option */
                    991:                        if (hbhlen < IP6OPT_MINLEN) {
1.116     thorpej   992:                                IP6_STATINC(IP6_STAT_TOOSMALL);
1.35      itojun    993:                                goto bad;
                    994:                        }
1.55      itojun    995:                        optlen = ip6_unknown_opt(opt, m,
                    996:                            erroff + opt - opthead);
                    997:                        if (optlen == -1)
                    998:                                return (-1);
1.35      itojun    999:                        optlen += 2;
                   1000:                        break;
1.2       itojun   1001:                }
                   1002:        }
                   1003:
1.55      itojun   1004:        return (0);
1.2       itojun   1005:
                   1006:   bad:
                   1007:        m_freem(m);
1.55      itojun   1008:        return (-1);
1.2       itojun   1009: }
                   1010:
                   1011: /*
                   1012:  * Unknown option processing.
                   1013:  * The third argument `off' is the offset from the IPv6 header to the option,
                   1014:  * which is necessary if the IPv6 header the and option header and IPv6 header
                   1015:  * is not continuous in order to return an ICMPv6 error.
                   1016:  */
                   1017: int
1.107     christos 1018: ip6_unknown_opt(u_int8_t *optp, struct mbuf *m, int off)
1.2       itojun   1019: {
                   1020:        struct ip6_hdr *ip6;
                   1021:
1.35      itojun   1022:        switch (IP6OPT_TYPE(*optp)) {
                   1023:        case IP6OPT_TYPE_SKIP: /* ignore the option */
1.58      itojun   1024:                return ((int)*(optp + 1));
1.35      itojun   1025:        case IP6OPT_TYPE_DISCARD:       /* silently discard */
                   1026:                m_freem(m);
1.58      itojun   1027:                return (-1);
1.35      itojun   1028:        case IP6OPT_TYPE_FORCEICMP: /* send ICMP even if multicasted */
1.116     thorpej  1029:                IP6_STATINC(IP6_STAT_BADOPTIONS);
1.35      itojun   1030:                icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_OPTION, off);
1.58      itojun   1031:                return (-1);
1.35      itojun   1032:        case IP6OPT_TYPE_ICMP: /* send ICMP if not multicasted */
1.116     thorpej  1033:                IP6_STATINC(IP6_STAT_BADOPTIONS);
1.35      itojun   1034:                ip6 = mtod(m, struct ip6_hdr *);
                   1035:                if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) ||
                   1036:                    (m->m_flags & (M_BCAST|M_MCAST)))
                   1037:                        m_freem(m);
                   1038:                else
                   1039:                        icmp6_error(m, ICMP6_PARAM_PROB,
                   1040:                                    ICMP6_PARAMPROB_OPTION, off);
1.58      itojun   1041:                return (-1);
1.2       itojun   1042:        }
                   1043:
                   1044:        m_freem(m);             /* XXX: NOTREACHED */
1.58      itojun   1045:        return (-1);
1.2       itojun   1046: }
                   1047:
                   1048: void
1.107     christos 1049: ip6_savecontrol(struct in6pcb *in6p, struct mbuf **mp,
                   1050:        struct ip6_hdr *ip6, struct mbuf *m)
1.2       itojun   1051: {
1.179     christos 1052:        struct socket *so = in6p->in6p_socket;
1.85      rpaulo   1053: #ifdef RFC2292
                   1054: #define IS2292(x, y)   ((in6p->in6p_flags & IN6P_RFC2292) ? (x) : (y))
                   1055: #else
                   1056: #define IS2292(x, y)   (y)
                   1057: #endif
                   1058:
1.179     christos 1059:        if (SOOPT_TIMESTAMP(so->so_options))
1.200     maxv     1060:                mp = sbsavetimestamp(so->so_options, mp);
1.87      rpaulo   1061:
                   1062:        /* some OSes call this logic with IPv4 packet, for SO_TIMESTAMP */
                   1063:        if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION)
                   1064:                return;
                   1065:
1.2       itojun   1066:        /* RFC 2292 sec. 5 */
1.35      itojun   1067:        if ((in6p->in6p_flags & IN6P_PKTINFO) != 0) {
1.2       itojun   1068:                struct in6_pktinfo pi6;
1.85      rpaulo   1069:
1.126     tsutsui  1070:                memcpy(&pi6.ipi6_addr, &ip6->ip6_dst, sizeof(struct in6_addr));
1.81      rpaulo   1071:                in6_clearscope(&pi6.ipi6_addr); /* XXX */
1.160     ozaki-r  1072:                pi6.ipi6_ifindex = m->m_pkthdr.rcvif_index;
1.180     christos 1073:                *mp = sbcreatecontrol(&pi6, sizeof(pi6),
1.85      rpaulo   1074:                    IS2292(IPV6_2292PKTINFO, IPV6_PKTINFO), IPPROTO_IPV6);
1.2       itojun   1075:                if (*mp)
                   1076:                        mp = &(*mp)->m_next;
                   1077:        }
1.85      rpaulo   1078:
1.2       itojun   1079:        if (in6p->in6p_flags & IN6P_HOPLIMIT) {
                   1080:                int hlim = ip6->ip6_hlim & 0xff;
1.85      rpaulo   1081:
1.180     christos 1082:                *mp = sbcreatecontrol(&hlim, sizeof(hlim),
1.85      rpaulo   1083:                    IS2292(IPV6_2292HOPLIMIT, IPV6_HOPLIMIT), IPPROTO_IPV6);
                   1084:                if (*mp)
                   1085:                        mp = &(*mp)->m_next;
                   1086:        }
                   1087:
                   1088:        if ((in6p->in6p_flags & IN6P_TCLASS) != 0) {
                   1089:                u_int32_t flowinfo;
                   1090:                int tclass;
                   1091:
                   1092:                flowinfo = (u_int32_t)ntohl(ip6->ip6_flow & IPV6_FLOWINFO_MASK);
                   1093:                flowinfo >>= 20;
                   1094:
                   1095:                tclass = flowinfo & 0xff;
1.180     christos 1096:                *mp = sbcreatecontrol(&tclass, sizeof(tclass),
1.85      rpaulo   1097:                    IPV6_TCLASS, IPPROTO_IPV6);
                   1098:
1.2       itojun   1099:                if (*mp)
                   1100:                        mp = &(*mp)->m_next;
                   1101:        }
                   1102:
                   1103:        /*
1.75      itojun   1104:         * IPV6_HOPOPTS socket option.  Recall that we required super-user
                   1105:         * privilege for the option (see ip6_ctloutput), but it might be too
                   1106:         * strict, since there might be some hop-by-hop options which can be
                   1107:         * returned to normal user.
1.85      rpaulo   1108:         * See also RFC3542 section 8 (or RFC2292 section 6).
1.2       itojun   1109:         */
1.75      itojun   1110:        if ((in6p->in6p_flags & IN6P_HOPOPTS) != 0) {
1.2       itojun   1111:                /*
                   1112:                 * Check if a hop-by-hop options header is contatined in the
                   1113:                 * received packet, and if so, store the options as ancillary
                   1114:                 * data. Note that a hop-by-hop options header must be
                   1115:                 * just after the IPv6 header, which fact is assured through
                   1116:                 * the IPv6 input processing.
                   1117:                 */
1.78      christos 1118:                struct ip6_hdr *xip6 = mtod(m, struct ip6_hdr *);
                   1119:                if (xip6->ip6_nxt == IPPROTO_HOPOPTS) {
1.9       itojun   1120:                        struct ip6_hbh *hbh;
                   1121:                        int hbhlen;
1.62      itojun   1122:                        struct mbuf *ext;
1.9       itojun   1123:
1.62      itojun   1124:                        ext = ip6_pullexthdr(m, sizeof(struct ip6_hdr),
1.78      christos 1125:                            xip6->ip6_nxt);
1.62      itojun   1126:                        if (ext == NULL) {
1.116     thorpej  1127:                                IP6_STATINC(IP6_STAT_TOOSHORT);
1.9       itojun   1128:                                return;
                   1129:                        }
1.62      itojun   1130:                        hbh = mtod(ext, struct ip6_hbh *);
1.9       itojun   1131:                        hbhlen = (hbh->ip6h_len + 1) << 3;
1.62      itojun   1132:                        if (hbhlen != ext->m_len) {
                   1133:                                m_freem(ext);
1.116     thorpej  1134:                                IP6_STATINC(IP6_STAT_TOOSHORT);
1.9       itojun   1135:                                return;
                   1136:                        }
1.2       itojun   1137:
                   1138:                        /*
                   1139:                         * XXX: We copy whole the header even if a jumbo
                   1140:                         * payload option is included, which option is to
                   1141:                         * be removed before returning in the RFC 2292.
1.85      rpaulo   1142:                         * Note: this constraint is removed in RFC3542.
1.2       itojun   1143:                         */
1.180     christos 1144:                        *mp = sbcreatecontrol(hbh, hbhlen,
1.85      rpaulo   1145:                            IS2292(IPV6_2292HOPOPTS, IPV6_HOPOPTS),
                   1146:                            IPPROTO_IPV6);
1.2       itojun   1147:                        if (*mp)
                   1148:                                mp = &(*mp)->m_next;
1.62      itojun   1149:                        m_freem(ext);
1.2       itojun   1150:                }
                   1151:        }
                   1152:
                   1153:        /* IPV6_DSTOPTS and IPV6_RTHDR socket options */
                   1154:        if (in6p->in6p_flags & (IN6P_DSTOPTS | IN6P_RTHDR)) {
1.78      christos 1155:                struct ip6_hdr *xip6 = mtod(m, struct ip6_hdr *);
                   1156:                int nxt = xip6->ip6_nxt, off = sizeof(struct ip6_hdr);
1.2       itojun   1157:
                   1158:                /*
                   1159:                 * Search for destination options headers or routing
                   1160:                 * header(s) through the header chain, and stores each
                   1161:                 * header as ancillary data.
                   1162:                 * Note that the order of the headers remains in
                   1163:                 * the chain of ancillary data.
                   1164:                 */
1.86      rpaulo   1165:                for (;;) {      /* is explicit loop prevention necessary? */
1.62      itojun   1166:                        struct ip6_ext *ip6e = NULL;
1.9       itojun   1167:                        int elen;
1.62      itojun   1168:                        struct mbuf *ext = NULL;
1.9       itojun   1169:
1.62      itojun   1170:                        /*
                   1171:                         * if it is not an extension header, don't try to
                   1172:                         * pull it from the chain.
                   1173:                         */
                   1174:                        switch (nxt) {
                   1175:                        case IPPROTO_DSTOPTS:
                   1176:                        case IPPROTO_ROUTING:
                   1177:                        case IPPROTO_HOPOPTS:
                   1178:                        case IPPROTO_AH: /* is it possible? */
                   1179:                                break;
                   1180:                        default:
                   1181:                                goto loopend;
                   1182:                        }
                   1183:
                   1184:                        ext = ip6_pullexthdr(m, off, nxt);
                   1185:                        if (ext == NULL) {
1.116     thorpej  1186:                                IP6_STATINC(IP6_STAT_TOOSHORT);
1.9       itojun   1187:                                return;
                   1188:                        }
1.62      itojun   1189:                        ip6e = mtod(ext, struct ip6_ext *);
1.9       itojun   1190:                        if (nxt == IPPROTO_AH)
                   1191:                                elen = (ip6e->ip6e_len + 2) << 2;
                   1192:                        else
                   1193:                                elen = (ip6e->ip6e_len + 1) << 3;
1.62      itojun   1194:                        if (elen != ext->m_len) {
                   1195:                                m_freem(ext);
1.116     thorpej  1196:                                IP6_STATINC(IP6_STAT_TOOSHORT);
1.9       itojun   1197:                                return;
                   1198:                        }
1.57      thorpej  1199:                        KASSERT(IP6_HDR_ALIGNED_P(ip6e));
1.2       itojun   1200:
1.35      itojun   1201:                        switch (nxt) {
1.62      itojun   1202:                        case IPPROTO_DSTOPTS:
1.127     martin   1203:                                if (!(in6p->in6p_flags & IN6P_DSTOPTS))
1.35      itojun   1204:                                        break;
                   1205:
1.180     christos 1206:                                *mp = sbcreatecontrol(ip6e, elen,
1.85      rpaulo   1207:                                    IS2292(IPV6_2292DSTOPTS, IPV6_DSTOPTS),
                   1208:                                    IPPROTO_IPV6);
1.35      itojun   1209:                                if (*mp)
                   1210:                                        mp = &(*mp)->m_next;
                   1211:                                break;
                   1212:
                   1213:                        case IPPROTO_ROUTING:
1.127     martin   1214:                                if (!(in6p->in6p_flags & IN6P_RTHDR))
1.35      itojun   1215:                                        break;
                   1216:
1.180     christos 1217:                                *mp = sbcreatecontrol(ip6e, elen,
1.85      rpaulo   1218:                                    IS2292(IPV6_2292RTHDR, IPV6_RTHDR),
                   1219:                                    IPPROTO_IPV6);
1.35      itojun   1220:                                if (*mp)
                   1221:                                        mp = &(*mp)->m_next;
                   1222:                                break;
                   1223:
1.62      itojun   1224:                        case IPPROTO_HOPOPTS:
                   1225:                        case IPPROTO_AH: /* is it possible? */
                   1226:                                break;
                   1227:
1.35      itojun   1228:                        default:
                   1229:                                /*
1.62      itojun   1230:                                 * other cases have been filtered in the above.
                   1231:                                 * none will visit this case.  here we supply
                   1232:                                 * the code just in case (nxt overwritten or
                   1233:                                 * other cases).
1.35      itojun   1234:                                 */
1.62      itojun   1235:                                m_freem(ext);
1.35      itojun   1236:                                goto loopend;
                   1237:
1.2       itojun   1238:                        }
                   1239:
                   1240:                        /* proceed with the next header. */
1.9       itojun   1241:                        off += elen;
1.2       itojun   1242:                        nxt = ip6e->ip6e_nxt;
1.62      itojun   1243:                        ip6e = NULL;
                   1244:                        m_freem(ext);
                   1245:                        ext = NULL;
1.2       itojun   1246:                }
                   1247:          loopend:
1.62      itojun   1248:                ;
1.2       itojun   1249:        }
1.62      itojun   1250: }
1.85      rpaulo   1251: #undef IS2292
                   1252:
                   1253:
                   1254: void
1.95      dyoung   1255: ip6_notify_pmtu(struct in6pcb *in6p, const struct sockaddr_in6 *dst,
                   1256:     uint32_t *mtu)
1.85      rpaulo   1257: {
                   1258:        struct socket *so;
                   1259:        struct mbuf *m_mtu;
                   1260:        struct ip6_mtuinfo mtuctl;
                   1261:
                   1262:        so = in6p->in6p_socket;
                   1263:
                   1264:        if (mtu == NULL)
                   1265:                return;
                   1266:
1.177     ozaki-r  1267:        KASSERT(so != NULL);
1.85      rpaulo   1268:
                   1269:        memset(&mtuctl, 0, sizeof(mtuctl));     /* zero-clear for safety */
                   1270:        mtuctl.ip6m_mtu = *mtu;
                   1271:        mtuctl.ip6m_addr = *dst;
                   1272:        if (sa6_recoverscope(&mtuctl.ip6m_addr))
                   1273:                return;
                   1274:
1.180     christos 1275:        if ((m_mtu = sbcreatecontrol(&mtuctl, sizeof(mtuctl),
1.85      rpaulo   1276:            IPV6_PATHMTU, IPPROTO_IPV6)) == NULL)
                   1277:                return;
                   1278:
1.95      dyoung   1279:        if (sbappendaddr(&so->so_rcv, (const struct sockaddr *)dst, NULL, m_mtu)
1.85      rpaulo   1280:            == 0) {
1.195     roy      1281:                soroverflow(so);
1.85      rpaulo   1282:                m_freem(m_mtu);
                   1283:        } else
                   1284:                sorwakeup(so);
                   1285:
                   1286:        return;
                   1287: }
1.62      itojun   1288:
                   1289: /*
                   1290:  * pull single extension header from mbuf chain.  returns single mbuf that
                   1291:  * contains the result, or NULL on error.
                   1292:  */
                   1293: static struct mbuf *
1.107     christos 1294: ip6_pullexthdr(struct mbuf *m, size_t off, int nxt)
1.62      itojun   1295: {
                   1296:        struct ip6_ext ip6e;
                   1297:        size_t elen;
                   1298:        struct mbuf *n;
                   1299:
1.97      christos 1300:        m_copydata(m, off, sizeof(ip6e), (void *)&ip6e);
1.62      itojun   1301:        if (nxt == IPPROTO_AH)
                   1302:                elen = (ip6e.ip6e_len + 2) << 2;
                   1303:        else
                   1304:                elen = (ip6e.ip6e_len + 1) << 3;
                   1305:
                   1306:        MGET(n, M_DONTWAIT, MT_DATA);
                   1307:        if (n && elen >= MLEN) {
                   1308:                MCLGET(n, M_DONTWAIT);
                   1309:                if ((n->m_flags & M_EXT) == 0) {
                   1310:                        m_free(n);
                   1311:                        n = NULL;
                   1312:                }
                   1313:        }
                   1314:        if (!n)
                   1315:                return NULL;
                   1316:
                   1317:        n->m_len = 0;
                   1318:        if (elen >= M_TRAILINGSPACE(n)) {
                   1319:                m_free(n);
                   1320:                return NULL;
                   1321:        }
                   1322:
1.97      christos 1323:        m_copydata(m, off, elen, mtod(n, void *));
1.62      itojun   1324:        n->m_len = elen;
                   1325:        return n;
1.2       itojun   1326: }
                   1327:
                   1328: /*
1.187     maxv     1329:  * Get offset to the previous header followed by the header
1.2       itojun   1330:  * currently processed.
                   1331:  */
1.187     maxv     1332: int
1.107     christos 1333: ip6_get_prevhdr(struct mbuf *m, int off)
1.2       itojun   1334: {
                   1335:        struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
                   1336:
1.187     maxv     1337:        if (off == sizeof(struct ip6_hdr)) {
                   1338:                return offsetof(struct ip6_hdr, ip6_nxt);
                   1339:        } else if (off < sizeof(struct ip6_hdr)) {
                   1340:                panic("%s: off < sizeof(struct ip6_hdr)", __func__);
                   1341:        } else {
                   1342:                int len, nlen, nxt;
                   1343:                struct ip6_ext ip6e;
1.2       itojun   1344:
                   1345:                nxt = ip6->ip6_nxt;
                   1346:                len = sizeof(struct ip6_hdr);
1.187     maxv     1347:                nlen = 0;
1.2       itojun   1348:                while (len < off) {
1.187     maxv     1349:                        m_copydata(m, len, sizeof(ip6e), &ip6e);
1.2       itojun   1350:
1.35      itojun   1351:                        switch (nxt) {
1.2       itojun   1352:                        case IPPROTO_FRAGMENT:
1.187     maxv     1353:                                nlen = sizeof(struct ip6_frag);
1.2       itojun   1354:                                break;
                   1355:                        case IPPROTO_AH:
1.187     maxv     1356:                                nlen = (ip6e.ip6e_len + 2) << 2;
1.2       itojun   1357:                                break;
                   1358:                        default:
1.187     maxv     1359:                                nlen = (ip6e.ip6e_len + 1) << 3;
1.2       itojun   1360:                                break;
                   1361:                        }
1.187     maxv     1362:                        len += nlen;
                   1363:                        nxt = ip6e.ip6e_nxt;
1.2       itojun   1364:                }
1.187     maxv     1365:
                   1366:                return (len - nlen);
1.18      itojun   1367:        }
                   1368: }
                   1369:
                   1370: /*
                   1371:  * get next header offset.  m will be retained.
                   1372:  */
1.192     maxv     1373: int
1.107     christos 1374: ip6_nexthdr(struct mbuf *m, int off, int proto, int *nxtp)
1.18      itojun   1375: {
                   1376:        struct ip6_hdr ip6;
                   1377:        struct ip6_ext ip6e;
                   1378:        struct ip6_frag fh;
                   1379:
                   1380:        /* just in case */
                   1381:        if (m == NULL)
1.189     maxv     1382:                panic("%s: m == NULL", __func__);
1.18      itojun   1383:        if ((m->m_flags & M_PKTHDR) == 0 || m->m_pkthdr.len < off)
                   1384:                return -1;
                   1385:
                   1386:        switch (proto) {
                   1387:        case IPPROTO_IPV6:
1.83      rpaulo   1388:                /* do not chase beyond intermediate IPv6 headers */
                   1389:                if (off != 0)
                   1390:                        return -1;
1.18      itojun   1391:                if (m->m_pkthdr.len < off + sizeof(ip6))
                   1392:                        return -1;
1.97      christos 1393:                m_copydata(m, off, sizeof(ip6), (void *)&ip6);
1.18      itojun   1394:                if (nxtp)
                   1395:                        *nxtp = ip6.ip6_nxt;
                   1396:                off += sizeof(ip6);
                   1397:                return off;
                   1398:
                   1399:        case IPPROTO_FRAGMENT:
                   1400:                /*
                   1401:                 * terminate parsing if it is not the first fragment,
                   1402:                 * it does not make sense to parse through it.
                   1403:                 */
                   1404:                if (m->m_pkthdr.len < off + sizeof(fh))
                   1405:                        return -1;
1.97      christos 1406:                m_copydata(m, off, sizeof(fh), (void *)&fh);
1.67      itojun   1407:                if ((fh.ip6f_offlg & IP6F_OFF_MASK) != 0)
1.18      itojun   1408:                        return -1;
                   1409:                if (nxtp)
                   1410:                        *nxtp = fh.ip6f_nxt;
                   1411:                off += sizeof(struct ip6_frag);
                   1412:                return off;
                   1413:
                   1414:        case IPPROTO_AH:
                   1415:                if (m->m_pkthdr.len < off + sizeof(ip6e))
                   1416:                        return -1;
1.97      christos 1417:                m_copydata(m, off, sizeof(ip6e), (void *)&ip6e);
1.18      itojun   1418:                if (nxtp)
                   1419:                        *nxtp = ip6e.ip6e_nxt;
                   1420:                off += (ip6e.ip6e_len + 2) << 2;
1.47      itojun   1421:                if (m->m_pkthdr.len < off)
                   1422:                        return -1;
1.18      itojun   1423:                return off;
                   1424:
                   1425:        case IPPROTO_HOPOPTS:
                   1426:        case IPPROTO_ROUTING:
                   1427:        case IPPROTO_DSTOPTS:
                   1428:                if (m->m_pkthdr.len < off + sizeof(ip6e))
                   1429:                        return -1;
1.97      christos 1430:                m_copydata(m, off, sizeof(ip6e), (void *)&ip6e);
1.18      itojun   1431:                if (nxtp)
                   1432:                        *nxtp = ip6e.ip6e_nxt;
                   1433:                off += (ip6e.ip6e_len + 1) << 3;
1.47      itojun   1434:                if (m->m_pkthdr.len < off)
                   1435:                        return -1;
1.18      itojun   1436:                return off;
                   1437:
                   1438:        case IPPROTO_NONE:
                   1439:        case IPPROTO_ESP:
                   1440:        case IPPROTO_IPCOMP:
                   1441:                /* give up */
                   1442:                return -1;
                   1443:
                   1444:        default:
                   1445:                return -1;
                   1446:        }
                   1447: }
                   1448:
                   1449: /*
                   1450:  * get offset for the last header in the chain.  m will be kept untainted.
                   1451:  */
                   1452: int
1.107     christos 1453: ip6_lasthdr(struct mbuf *m, int off, int proto, int *nxtp)
1.18      itojun   1454: {
                   1455:        int newoff;
                   1456:        int nxt;
                   1457:
                   1458:        if (!nxtp) {
                   1459:                nxt = -1;
                   1460:                nxtp = &nxt;
                   1461:        }
1.86      rpaulo   1462:        for (;;) {
1.18      itojun   1463:                newoff = ip6_nexthdr(m, off, proto, nxtp);
                   1464:                if (newoff < 0)
                   1465:                        return off;
                   1466:                else if (newoff < off)
                   1467:                        return -1;      /* invalid */
                   1468:                else if (newoff == off)
                   1469:                        return newoff;
                   1470:
                   1471:                off = newoff;
                   1472:                proto = *nxtp;
1.2       itojun   1473:        }
                   1474: }
                   1475:
1.81      rpaulo   1476: struct m_tag *
1.107     christos 1477: ip6_addaux(struct mbuf *m)
1.81      rpaulo   1478: {
                   1479:        struct m_tag *mtag;
                   1480:
1.205     maxv     1481:        mtag = m_tag_find(m, PACKET_TAG_INET6);
1.81      rpaulo   1482:        if (!mtag) {
                   1483:                mtag = m_tag_get(PACKET_TAG_INET6, sizeof(struct ip6aux),
                   1484:                    M_NOWAIT);
                   1485:                if (mtag) {
                   1486:                        m_tag_prepend(m, mtag);
1.124     cegger   1487:                        memset(mtag + 1, 0, sizeof(struct ip6aux));
1.81      rpaulo   1488:                }
                   1489:        }
                   1490:        return mtag;
                   1491: }
                   1492:
                   1493: struct m_tag *
1.107     christos 1494: ip6_findaux(struct mbuf *m)
1.81      rpaulo   1495: {
                   1496:        struct m_tag *mtag;
                   1497:
1.205     maxv     1498:        mtag = m_tag_find(m, PACKET_TAG_INET6);
1.81      rpaulo   1499:        return mtag;
                   1500: }
                   1501:
                   1502: void
1.107     christos 1503: ip6_delaux(struct mbuf *m)
1.81      rpaulo   1504: {
                   1505:        struct m_tag *mtag;
                   1506:
1.205     maxv     1507:        mtag = m_tag_find(m, PACKET_TAG_INET6);
1.81      rpaulo   1508:        if (mtag)
                   1509:                m_tag_delete(m, mtag);
                   1510: }
                   1511:
1.2       itojun   1512: /*
                   1513:  * System control for IP6
                   1514:  */
                   1515:
1.120     matt     1516: const u_char inet6ctlerrmap[PRC_NCMDS] = {
1.2       itojun   1517:        0,              0,              0,              0,
                   1518:        0,              EMSGSIZE,       EHOSTDOWN,      EHOSTUNREACH,
                   1519:        EHOSTUNREACH,   EHOSTUNREACH,   ECONNREFUSED,   ECONNREFUSED,
                   1520:        EMSGSIZE,       EHOSTUNREACH,   0,              0,
                   1521:        0,              0,              0,              0,
                   1522:        ENOPROTOOPT
                   1523: };
                   1524:
1.153     christos 1525: extern int sysctl_net_inet6_addrctlpolicy(SYSCTLFN_ARGS);
                   1526:
1.116     thorpej  1527: static int
                   1528: sysctl_net_inet6_ip6_stats(SYSCTLFN_ARGS)
                   1529: {
                   1530:
1.119     thorpej  1531:        return (NETSTAT_SYSCTL(ip6stat_percpu, IP6_NSTATS));
1.116     thorpej  1532: }
                   1533:
1.208.2.3! martin   1534: static int
        !          1535: sysctl_net_inet6_ip6_temppltime(SYSCTLFN_ARGS)
        !          1536: {
        !          1537:        int error;
        !          1538:        uint32_t pltime;
        !          1539:        struct sysctlnode node;
        !          1540:
        !          1541:        node = *rnode;
        !          1542:        node.sysctl_data = &pltime;
        !          1543:        pltime = ip6_temp_preferred_lifetime;
        !          1544:        error = sysctl_lookup(SYSCTLFN_CALL(&node));
        !          1545:        if (error || newp == NULL)
        !          1546:                return error;
        !          1547:
        !          1548:        if (pltime <= (MAX_TEMP_DESYNC_FACTOR + TEMPADDR_REGEN_ADVANCE))
        !          1549:                return EINVAL;
        !          1550:
        !          1551:        ip6_temp_preferred_lifetime = pltime;
        !          1552:
        !          1553:        in6_tmpaddrtimer_schedule();
        !          1554:
        !          1555:        return 0;
        !          1556: }
        !          1557:
1.128     pooka    1558: static void
                   1559: sysctl_net_inet6_ip6_setup(struct sysctllog **clog)
1.2       itojun   1560: {
1.26      itojun   1561:
1.73      atatat   1562:        sysctl_createv(clog, 0, NULL, NULL,
                   1563:                       CTLFLAG_PERMANENT,
1.74      atatat   1564:                       CTLTYPE_NODE, "inet6",
                   1565:                       SYSCTL_DESCR("PF_INET6 related settings"),
1.70      atatat   1566:                       NULL, 0, NULL, 0,
                   1567:                       CTL_NET, PF_INET6, CTL_EOL);
1.73      atatat   1568:        sysctl_createv(clog, 0, NULL, NULL,
                   1569:                       CTLFLAG_PERMANENT,
1.74      atatat   1570:                       CTLTYPE_NODE, "ip6",
                   1571:                       SYSCTL_DESCR("IPv6 related settings"),
1.70      atatat   1572:                       NULL, 0, NULL, 0,
                   1573:                       CTL_NET, PF_INET6, IPPROTO_IPV6, CTL_EOL);
                   1574:
1.73      atatat   1575:        sysctl_createv(clog, 0, NULL, NULL,
                   1576:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74      atatat   1577:                       CTLTYPE_INT, "forwarding",
                   1578:                       SYSCTL_DESCR("Enable forwarding of INET6 datagrams"),
1.70      atatat   1579:                       NULL, 0, &ip6_forwarding, 0,
                   1580:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1581:                       IPV6CTL_FORWARDING, CTL_EOL);
1.73      atatat   1582:        sysctl_createv(clog, 0, NULL, NULL,
                   1583:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74      atatat   1584:                       CTLTYPE_INT, "redirect",
                   1585:                       SYSCTL_DESCR("Enable sending of ICMPv6 redirect messages"),
1.70      atatat   1586:                       NULL, 0, &ip6_sendredirects, 0,
                   1587:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1588:                       IPV6CTL_SENDREDIRECTS, CTL_EOL);
1.73      atatat   1589:        sysctl_createv(clog, 0, NULL, NULL,
                   1590:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74      atatat   1591:                       CTLTYPE_INT, "hlim",
                   1592:                       SYSCTL_DESCR("Hop limit for an INET6 datagram"),
1.70      atatat   1593:                       NULL, 0, &ip6_defhlim, 0,
                   1594:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1595:                       IPV6CTL_DEFHLIM, CTL_EOL);
1.73      atatat   1596:        sysctl_createv(clog, 0, NULL, NULL,
                   1597:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74      atatat   1598:                       CTLTYPE_INT, "maxfragpackets",
                   1599:                       SYSCTL_DESCR("Maximum number of fragments to buffer "
                   1600:                                    "for reassembly"),
1.70      atatat   1601:                       NULL, 0, &ip6_maxfragpackets, 0,
                   1602:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1603:                       IPV6CTL_MAXFRAGPACKETS, CTL_EOL);
1.73      atatat   1604:        sysctl_createv(clog, 0, NULL, NULL,
                   1605:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74      atatat   1606:                       CTLTYPE_INT, "accept_rtadv",
                   1607:                       SYSCTL_DESCR("Accept router advertisements"),
1.70      atatat   1608:                       NULL, 0, &ip6_accept_rtadv, 0,
                   1609:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1610:                       IPV6CTL_ACCEPT_RTADV, CTL_EOL);
1.73      atatat   1611:        sysctl_createv(clog, 0, NULL, NULL,
                   1612:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.131     spz      1613:                       CTLTYPE_INT, "rtadv_maxroutes",
                   1614:                       SYSCTL_DESCR("Maximum number of routes accepted via router advertisements"),
                   1615:                       NULL, 0, &ip6_rtadv_maxroutes, 0,
                   1616:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1617:                       IPV6CTL_RTADV_MAXROUTES, CTL_EOL);
                   1618:        sysctl_createv(clog, 0, NULL, NULL,
                   1619:                       CTLFLAG_PERMANENT,
                   1620:                       CTLTYPE_INT, "rtadv_numroutes",
                   1621:                       SYSCTL_DESCR("Current number of routes accepted via router advertisements"),
                   1622:                       NULL, 0, &nd6_numroutes, 0,
                   1623:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1624:                       IPV6CTL_RTADV_NUMROUTES, CTL_EOL);
                   1625:        sysctl_createv(clog, 0, NULL, NULL,
                   1626:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74      atatat   1627:                       CTLTYPE_INT, "keepfaith",
                   1628:                       SYSCTL_DESCR("Activate faith interface"),
1.70      atatat   1629:                       NULL, 0, &ip6_keepfaith, 0,
                   1630:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1631:                       IPV6CTL_KEEPFAITH, CTL_EOL);
1.73      atatat   1632:        sysctl_createv(clog, 0, NULL, NULL,
                   1633:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74      atatat   1634:                       CTLTYPE_INT, "log_interval",
1.189     maxv     1635:                       SYSCTL_DESCR("Minimum interval between logging "
1.74      atatat   1636:                                    "unroutable packets"),
1.70      atatat   1637:                       NULL, 0, &ip6_log_interval, 0,
                   1638:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1639:                       IPV6CTL_LOG_INTERVAL, CTL_EOL);
1.73      atatat   1640:        sysctl_createv(clog, 0, NULL, NULL,
                   1641:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74      atatat   1642:                       CTLTYPE_INT, "hdrnestlimit",
                   1643:                       SYSCTL_DESCR("Maximum number of nested IPv6 headers"),
1.70      atatat   1644:                       NULL, 0, &ip6_hdrnestlimit, 0,
                   1645:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1646:                       IPV6CTL_HDRNESTLIMIT, CTL_EOL);
1.73      atatat   1647:        sysctl_createv(clog, 0, NULL, NULL,
                   1648:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74      atatat   1649:                       CTLTYPE_INT, "dad_count",
                   1650:                       SYSCTL_DESCR("Number of Duplicate Address Detection "
                   1651:                                    "probes to send"),
1.70      atatat   1652:                       NULL, 0, &ip6_dad_count, 0,
                   1653:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1654:                       IPV6CTL_DAD_COUNT, CTL_EOL);
1.73      atatat   1655:        sysctl_createv(clog, 0, NULL, NULL,
                   1656:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74      atatat   1657:                       CTLTYPE_INT, "auto_flowlabel",
                   1658:                       SYSCTL_DESCR("Assign random IPv6 flow labels"),
1.70      atatat   1659:                       NULL, 0, &ip6_auto_flowlabel, 0,
                   1660:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1661:                       IPV6CTL_AUTO_FLOWLABEL, CTL_EOL);
1.73      atatat   1662:        sysctl_createv(clog, 0, NULL, NULL,
                   1663:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74      atatat   1664:                       CTLTYPE_INT, "defmcasthlim",
                   1665:                       SYSCTL_DESCR("Default multicast hop limit"),
1.70      atatat   1666:                       NULL, 0, &ip6_defmcasthlim, 0,
                   1667:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1668:                       IPV6CTL_DEFMCASTHLIM, CTL_EOL);
1.73      atatat   1669:        sysctl_createv(clog, 0, NULL, NULL,
                   1670:                       CTLFLAG_PERMANENT,
1.74      atatat   1671:                       CTLTYPE_STRING, "kame_version",
                   1672:                       SYSCTL_DESCR("KAME Version"),
1.78      christos 1673:                       NULL, 0, __UNCONST(__KAME_VERSION), 0,
1.70      atatat   1674:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1675:                       IPV6CTL_KAME_VERSION, CTL_EOL);
1.73      atatat   1676:        sysctl_createv(clog, 0, NULL, NULL,
                   1677:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74      atatat   1678:                       CTLTYPE_INT, "use_deprecated",
                   1679:                       SYSCTL_DESCR("Allow use of deprecated addresses as "
                   1680:                                    "source addresses"),
1.70      atatat   1681:                       NULL, 0, &ip6_use_deprecated, 0,
                   1682:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1683:                       IPV6CTL_USE_DEPRECATED, CTL_EOL);
1.73      atatat   1684:        sysctl_createv(clog, 0, NULL, NULL,
                   1685:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.70      atatat   1686:                       CTLTYPE_INT, "rr_prune", NULL,
                   1687:                       NULL, 0, &ip6_rr_prune, 0,
                   1688:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1689:                       IPV6CTL_RR_PRUNE, CTL_EOL);
1.73      atatat   1690:        sysctl_createv(clog, 0, NULL, NULL,
                   1691:                       CTLFLAG_PERMANENT
1.70      atatat   1692: #ifndef INET6_BINDV6ONLY
1.73      atatat   1693:                       |CTLFLAG_READWRITE,
1.70      atatat   1694: #endif
1.74      atatat   1695:                       CTLTYPE_INT, "v6only",
                   1696:                       SYSCTL_DESCR("Disallow PF_INET6 sockets from connecting "
                   1697:                                    "to PF_INET sockets"),
1.70      atatat   1698:                       NULL, 0, &ip6_v6only, 0,
                   1699:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1700:                       IPV6CTL_V6ONLY, CTL_EOL);
1.73      atatat   1701:        sysctl_createv(clog, 0, NULL, NULL,
                   1702:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74      atatat   1703:                       CTLTYPE_INT, "anonportmin",
                   1704:                       SYSCTL_DESCR("Lowest ephemeral port number to assign"),
1.70      atatat   1705:                       sysctl_net_inet_ip_ports, 0, &ip6_anonportmin, 0,
                   1706:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1707:                       IPV6CTL_ANONPORTMIN, CTL_EOL);
1.73      atatat   1708:        sysctl_createv(clog, 0, NULL, NULL,
                   1709:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74      atatat   1710:                       CTLTYPE_INT, "anonportmax",
                   1711:                       SYSCTL_DESCR("Highest ephemeral port number to assign"),
1.70      atatat   1712:                       sysctl_net_inet_ip_ports, 0, &ip6_anonportmax, 0,
                   1713:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1714:                       IPV6CTL_ANONPORTMAX, CTL_EOL);
1.26      itojun   1715: #ifndef IPNOPRIVPORTS
1.73      atatat   1716:        sysctl_createv(clog, 0, NULL, NULL,
                   1717:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74      atatat   1718:                       CTLTYPE_INT, "lowportmin",
                   1719:                       SYSCTL_DESCR("Lowest privileged ephemeral port number "
                   1720:                                    "to assign"),
1.70      atatat   1721:                       sysctl_net_inet_ip_ports, 0, &ip6_lowportmin, 0,
                   1722:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1723:                       IPV6CTL_LOWPORTMIN, CTL_EOL);
1.73      atatat   1724:        sysctl_createv(clog, 0, NULL, NULL,
                   1725:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74      atatat   1726:                       CTLTYPE_INT, "lowportmax",
                   1727:                       SYSCTL_DESCR("Highest privileged ephemeral port number "
                   1728:                                    "to assign"),
1.70      atatat   1729:                       sysctl_net_inet_ip_ports, 0, &ip6_lowportmax, 0,
                   1730:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1731:                       IPV6CTL_LOWPORTMAX, CTL_EOL);
                   1732: #endif /* IPNOPRIVPORTS */
1.73      atatat   1733:        sysctl_createv(clog, 0, NULL, NULL,
                   1734:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.153     christos 1735:                       CTLTYPE_INT, "auto_linklocal",
                   1736:                       SYSCTL_DESCR("Default value of per-interface flag for "
                   1737:                                    "adding an IPv6 link-local address to "
                   1738:                                    "interfaces when attached"),
                   1739:                       NULL, 0, &ip6_auto_linklocal, 0,
                   1740:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1741:                       IPV6CTL_AUTO_LINKLOCAL, CTL_EOL);
                   1742:        sysctl_createv(clog, 0, NULL, NULL,
                   1743:                       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
                   1744:                       CTLTYPE_STRUCT, "addctlpolicy",
                   1745:                       SYSCTL_DESCR("Return the current address control"
                   1746:                           " policy"),
                   1747:                       sysctl_net_inet6_addrctlpolicy, 0, NULL, 0,
                   1748:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1749:                       IPV6CTL_ADDRCTLPOLICY, CTL_EOL);
                   1750:        sysctl_createv(clog, 0, NULL, NULL,
                   1751:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.83      rpaulo   1752:                       CTLTYPE_INT, "use_tempaddr",
                   1753:                       SYSCTL_DESCR("Use temporary address"),
                   1754:                       NULL, 0, &ip6_use_tempaddr, 0,
                   1755:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1756:                       CTL_CREATE, CTL_EOL);
                   1757:        sysctl_createv(clog, 0, NULL, NULL,
                   1758:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.150     roy      1759:                       CTLTYPE_INT, "prefer_tempaddr",
                   1760:                       SYSCTL_DESCR("Prefer temporary address as source "
                   1761:                                    "address"),
                   1762:                       NULL, 0, &ip6_prefer_tempaddr, 0,
                   1763:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1764:                       CTL_CREATE, CTL_EOL);
                   1765:        sysctl_createv(clog, 0, NULL, NULL,
                   1766:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.83      rpaulo   1767:                       CTLTYPE_INT, "temppltime",
                   1768:                       SYSCTL_DESCR("preferred lifetime of a temporary address"),
1.208.2.3! martin   1769:                       sysctl_net_inet6_ip6_temppltime, 0, NULL, 0,
1.83      rpaulo   1770:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1771:                       CTL_CREATE, CTL_EOL);
                   1772:        sysctl_createv(clog, 0, NULL, NULL,
                   1773:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1774:                       CTLTYPE_INT, "tempvltime",
                   1775:                       SYSCTL_DESCR("valid lifetime of a temporary address"),
                   1776:                       NULL, 0, &ip6_temp_valid_lifetime, 0,
                   1777:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1778:                       CTL_CREATE, CTL_EOL);
                   1779:        sysctl_createv(clog, 0, NULL, NULL,
                   1780:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74      atatat   1781:                       CTLTYPE_INT, "maxfrags",
                   1782:                       SYSCTL_DESCR("Maximum fragments in reassembly queue"),
1.70      atatat   1783:                       NULL, 0, &ip6_maxfrags, 0,
                   1784:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1785:                       IPV6CTL_MAXFRAGS, CTL_EOL);
1.79      rpaulo   1786:        sysctl_createv(clog, 0, NULL, NULL,
                   1787:                       CTLFLAG_PERMANENT,
                   1788:                       CTLTYPE_STRUCT, "stats",
                   1789:                       SYSCTL_DESCR("IPv6 statistics"),
1.116     thorpej  1790:                       sysctl_net_inet6_ip6_stats, 0, NULL, 0,
1.79      rpaulo   1791:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1792:                       IPV6CTL_STATS, CTL_EOL);
1.81      rpaulo   1793:        sysctl_createv(clog, 0, NULL, NULL,
                   1794:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1795:                       CTLTYPE_INT, "use_defaultzone",
                   1796:                       SYSCTL_DESCR("Whether to use the default scope zones"),
                   1797:                       NULL, 0, &ip6_use_defzone, 0,
                   1798:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1799:                       IPV6CTL_USE_DEFAULTZONE, CTL_EOL);
1.83      rpaulo   1800:        sysctl_createv(clog, 0, NULL, NULL,
                   1801:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1802:                       CTLTYPE_INT, "mcast_pmtu",
                   1803:                       SYSCTL_DESCR("Enable pMTU discovery for multicast packet"),
                   1804:                       NULL, 0, &ip6_mcast_pmtu, 0,
                   1805:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1806:                       CTL_CREATE, CTL_EOL);
1.138     christos 1807:        /* anonportalgo RFC6056 subtree */
1.140     christos 1808:        const struct sysctlnode *portalgo_node;
                   1809:        sysctl_createv(clog, 0, NULL, &portalgo_node,
1.138     christos 1810:                       CTLFLAG_PERMANENT,
                   1811:                       CTLTYPE_NODE, "anonportalgo",
                   1812:                       SYSCTL_DESCR("Anonymous port algorithm selection (RFC 6056)"),
                   1813:                       NULL, 0, NULL, 0,
                   1814:                       CTL_NET, PF_INET6, IPPROTO_IPV6, CTL_CREATE, CTL_EOL);
1.140     christos 1815:        sysctl_createv(clog, 0, &portalgo_node, NULL,
1.138     christos 1816:                       CTLFLAG_PERMANENT,
                   1817:                       CTLTYPE_STRING, "available",
                   1818:                       SYSCTL_DESCR("available algorithms"),
1.140     christos 1819:                       sysctl_portalgo_available, 0, NULL, PORTALGO_MAXLEN,
1.138     christos 1820:                       CTL_CREATE, CTL_EOL);
1.140     christos 1821:        sysctl_createv(clog, 0, &portalgo_node, NULL,
1.138     christos 1822:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1823:                       CTLTYPE_STRING, "selected",
                   1824:                       SYSCTL_DESCR("selected algorithm"),
1.140     christos 1825:                       sysctl_portalgo_selected6, 0, NULL, PORTALGO_MAXLEN,
1.138     christos 1826:                       CTL_CREATE, CTL_EOL);
1.141     christos 1827:        sysctl_createv(clog, 0, &portalgo_node, NULL,
                   1828:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1829:                       CTLTYPE_STRUCT, "reserve",
                   1830:                       SYSCTL_DESCR("bitmap of reserved ports"),
                   1831:                       sysctl_portalgo_reserve6, 0, NULL, 0,
                   1832:                       CTL_CREATE, CTL_EOL);
1.139     christos 1833:        sysctl_createv(clog, 0, NULL, NULL,
                   1834:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1835:                       CTLTYPE_INT, "neighborgcthresh",
                   1836:                       SYSCTL_DESCR("Maximum number of entries in neighbor"
                   1837:                        " cache"),
                   1838:                       NULL, 1, &ip6_neighborgcthresh, 0,
                   1839:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1840:                       CTL_CREATE, CTL_EOL);
                   1841:        sysctl_createv(clog, 0, NULL, NULL,
                   1842:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1843:                       CTLTYPE_INT, "maxifprefixes",
                   1844:                       SYSCTL_DESCR("Maximum number of prefixes created by"
                   1845:                           " route advertisement per interface"),
                   1846:                       NULL, 1, &ip6_maxifprefixes, 0,
                   1847:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1848:                       CTL_CREATE, CTL_EOL);
                   1849:        sysctl_createv(clog, 0, NULL, NULL,
                   1850:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1851:                       CTLTYPE_INT, "maxifdefrouters",
                   1852:                       SYSCTL_DESCR("Maximum number of default routers created"
                   1853:                           " by route advertisement per interface"),
                   1854:                       NULL, 1, &ip6_maxifdefrouters, 0,
                   1855:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1856:                       CTL_CREATE, CTL_EOL);
                   1857:        sysctl_createv(clog, 0, NULL, NULL,
                   1858:                       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                   1859:                       CTLTYPE_INT, "maxdynroutes",
                   1860:                       SYSCTL_DESCR("Maximum number of routes created via"
                   1861:                           " redirect"),
                   1862:                       NULL, 1, &ip6_maxdynroutes, 0,
                   1863:                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                   1864:                       CTL_CREATE, CTL_EOL);
1.2       itojun   1865: }
1.116     thorpej  1866:
                   1867: void
                   1868: ip6_statinc(u_int stat)
                   1869: {
                   1870:
                   1871:        KASSERT(stat < IP6_NSTATS);
                   1872:        IP6_STATINC(stat);
                   1873: }

CVSweb <webmaster@jp.NetBSD.org>