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