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