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