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