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