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