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