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