Annotation of src/sys/netinet6/ip6_input.c, Revision 1.149.4.4
1.149.4.4! skrll 1: /* $NetBSD: ip6_input.c,v 1.149.4.3 2015/12/27 12:10:07 skrll 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.149.4.4! skrll 65: __KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.149.4.3 2015/12/27 12:10:07 skrll Exp $");
1.2 itojun 66:
1.149.4.2 skrll 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.149.4.2 skrll 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];
136: struct in6_ifaddr *in6_ifaddr;
1.148 rmind 137: pktqueue_t *ip6_pktq __read_mostly;
1.2 itojun 138:
139: int ip6_forward_srcrt; /* XXX */
140: int ip6_sourcecheck; /* XXX */
141: int ip6_sourcecheck_interval; /* XXX */
1.9 itojun 142:
1.143 rmind 143: pfil_head_t *inet6_pfil_hook;
1.29 thorpej 144:
1.116 thorpej 145: percpu_t *ip6stat_percpu;
1.2 itojun 146:
1.111 dyoung 147: static void ip6_init2(void *);
1.148 rmind 148: static void ip6intr(void *);
1.112 dyoung 149: static struct m_tag *ip6_setdstifaddr(struct mbuf *, const struct in6_ifaddr *);
1.2 itojun 150:
1.136 drochner 151: static int ip6_process_hopopts(struct mbuf *, u_int8_t *, int, u_int32_t *,
152: u_int32_t *);
1.111 dyoung 153: static struct mbuf *ip6_pullexthdr(struct mbuf *, size_t, int);
1.128 pooka 154: static void sysctl_net_inet6_ip6_setup(struct sysctllog **);
1.2 itojun 155:
156: /*
157: * IP6 initialization: fill in IP6 protocol switch table.
158: * All protocols not implemented in kernel go to raw IP6 protocol handler.
159: */
160: void
1.114 matt 161: ip6_init(void)
1.2 itojun 162: {
1.78 christos 163: const struct ip6protosw *pr;
1.35 itojun 164: int i;
1.2 itojun 165:
1.128 pooka 166: sysctl_net_inet6_ip6_setup(NULL);
1.78 christos 167: pr = (const struct ip6protosw *)pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW);
1.2 itojun 168: if (pr == 0)
169: panic("ip6_init");
170: for (i = 0; i < IPPROTO_MAX; i++)
171: ip6_protox[i] = pr - inet6sw;
1.78 christos 172: for (pr = (const struct ip6protosw *)inet6domain.dom_protosw;
173: pr < (const struct ip6protosw *)inet6domain.dom_protoswNPROTOSW; pr++)
1.2 itojun 174: if (pr->pr_domain->dom_family == PF_INET6 &&
175: pr->pr_protocol && pr->pr_protocol != IPPROTO_RAW)
176: ip6_protox[pr->pr_protocol] = pr - inet6sw;
1.148 rmind 177:
1.149 ozaki-r 178: ip6_pktq = pktq_create(IFQ_MAXLEN, ip6intr, NULL);
1.148 rmind 179: KASSERT(ip6_pktq != NULL);
180:
1.81 rpaulo 181: scope6_init();
182: addrsel_policy_init();
1.2 itojun 183: nd6_init();
184: frag6_init();
1.133 tls 185: ip6_desync_factor = cprng_fast32() % MAX_TEMP_DESYNC_FACTOR;
1.2 itojun 186:
1.135 christos 187: ip6_init2(NULL);
1.98 liamjfoy 188: #ifdef GATEWAY
1.99 liamjfoy 189: ip6flow_init(ip6_hashsize);
1.98 liamjfoy 190: #endif
1.29 thorpej 191: /* Register our Packet Filter hook. */
1.143 rmind 192: inet6_pfil_hook = pfil_head_create(PFIL_TYPE_AF, (void *)AF_INET6);
193: KASSERT(inet6_pfil_hook != NULL);
1.116 thorpej 194:
195: ip6stat_percpu = percpu_alloc(sizeof(uint64_t) * IP6_NSTATS);
1.2 itojun 196: }
197:
198: static void
1.90 christos 199: ip6_init2(void *dummy)
1.2 itojun 200: {
201:
202: /* nd6_timer_init */
1.118 ad 203: callout_init(&nd6_timer_ch, CALLOUT_MPSAFE);
1.19 thorpej 204: callout_reset(&nd6_timer_ch, hz, nd6_timer, NULL);
1.83 rpaulo 205:
206: /* timer for regeneranation of temporary addresses randomize ID */
1.118 ad 207: callout_init(&in6_tmpaddrtimer_ch, CALLOUT_MPSAFE);
1.83 rpaulo 208: callout_reset(&in6_tmpaddrtimer_ch,
209: (ip6_temp_preferred_lifetime - ip6_desync_factor -
210: ip6_temp_regen_advance) * hz,
211: in6_tmpaddrtimer, NULL);
1.2 itojun 212: }
213:
214: /*
215: * IP6 input interrupt handling. Just pass the packet to ip6_input.
216: */
1.148 rmind 217: static void
218: ip6intr(void *arg __unused)
1.2 itojun 219: {
220: struct mbuf *m;
221:
1.118 ad 222: mutex_enter(softnet_lock);
1.148 rmind 223: while ((m = pktq_dequeue(ip6_pktq)) != NULL) {
224: const ifnet_t *ifp = m->m_pkthdr.rcvif;
225:
226: /*
227: * Drop the packet if IPv6 is disabled on the interface.
228: */
229: if ((ND_IFINFO(ifp)->flags & ND6_IFF_IFDISABLED)) {
1.83 rpaulo 230: m_freem(m);
1.148 rmind 231: continue;
1.83 rpaulo 232: }
1.2 itojun 233: ip6_input(m);
234: }
1.118 ad 235: mutex_exit(softnet_lock);
1.2 itojun 236: }
237:
1.103 dyoung 238: extern struct route ip6_forward_rt;
1.2 itojun 239:
240: void
1.96 dyoung 241: ip6_input(struct mbuf *m)
1.2 itojun 242: {
1.9 itojun 243: struct ip6_hdr *ip6;
1.105 dyoung 244: int hit, off = sizeof(struct ip6_hdr), nest;
1.2 itojun 245: u_int32_t plen;
1.5 itojun 246: u_int32_t rtalert = ~0;
1.104 yamt 247: int nxt, ours = 0, rh_present = 0;
1.9 itojun 248: struct ifnet *deliverifp = NULL;
1.64 itojun 249: int srcrt = 0;
1.105 dyoung 250: const struct rtentry *rt;
251: union {
252: struct sockaddr dst;
253: struct sockaddr_in6 dst6;
254: } u;
1.2 itojun 255:
256: /*
1.81 rpaulo 257: * make sure we don't have onion peering information into m_tag.
258: */
259: ip6_delaux(m);
260:
261: /*
1.44 itojun 262: * mbuf statistics
1.2 itojun 263: */
264: if (m->m_flags & M_EXT) {
265: if (m->m_next)
1.116 thorpej 266: IP6_STATINC(IP6_STAT_MEXT2M);
1.2 itojun 267: else
1.116 thorpej 268: IP6_STATINC(IP6_STAT_MEXT1);
1.2 itojun 269: } else {
1.115 thorpej 270: #define M2MMAX 32
1.2 itojun 271: if (m->m_next) {
1.9 itojun 272: if (m->m_flags & M_LOOP) {
1.116 thorpej 273: /*XXX*/ IP6_STATINC(IP6_STAT_M2M + lo0ifp->if_index);
1.115 thorpej 274: } else if (m->m_pkthdr.rcvif->if_index < M2MMAX) {
1.116 thorpej 275: IP6_STATINC(IP6_STAT_M2M +
276: m->m_pkthdr.rcvif->if_index);
1.115 thorpej 277: } else
1.116 thorpej 278: IP6_STATINC(IP6_STAT_M2M);
1.2 itojun 279: } else
1.116 thorpej 280: IP6_STATINC(IP6_STAT_M1);
1.40 itojun 281: #undef M2MMAX
1.2 itojun 282: }
283:
1.9 itojun 284: in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_receive);
1.116 thorpej 285: IP6_STATINC(IP6_STAT_TOTAL);
1.9 itojun 286:
1.57 thorpej 287: /*
288: * If the IPv6 header is not aligned, slurp it up into a new
289: * mbuf with space for link headers, in the event we forward
1.81 rpaulo 290: * it. Otherwise, if it is aligned, make sure the entire base
1.57 thorpej 291: * IPv6 header is in the first mbuf of the chain.
292: */
1.97 christos 293: if (IP6_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
1.57 thorpej 294: struct ifnet *inifp = m->m_pkthdr.rcvif;
295: if ((m = m_copyup(m, sizeof(struct ip6_hdr),
296: (max_linkhdr + 3) & ~3)) == NULL) {
297: /* XXXJRT new stat, please */
1.116 thorpej 298: IP6_STATINC(IP6_STAT_TOOSMALL);
1.57 thorpej 299: in6_ifstat_inc(inifp, ifs6_in_hdrerr);
300: return;
301: }
302: } else if (__predict_false(m->m_len < sizeof(struct ip6_hdr))) {
303: struct ifnet *inifp = m->m_pkthdr.rcvif;
1.55 itojun 304: if ((m = m_pullup(m, sizeof(struct ip6_hdr))) == NULL) {
1.116 thorpej 305: IP6_STATINC(IP6_STAT_TOOSMALL);
1.9 itojun 306: in6_ifstat_inc(inifp, ifs6_in_hdrerr);
307: return;
308: }
1.2 itojun 309: }
310:
311: ip6 = mtod(m, struct ip6_hdr *);
312:
313: if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) {
1.116 thorpej 314: IP6_STATINC(IP6_STAT_BADVERS);
1.9 itojun 315: in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr);
1.2 itojun 316: goto bad;
317: }
1.15 darrenr 318:
1.98 liamjfoy 319: /*
320: * Assume that we can create a fast-forward IP flow entry
321: * based on this packet.
322: */
323: m->m_flags |= M_CANFASTFWD;
324:
1.15 darrenr 325: /*
326: * Run through list of hooks for input packets. If there are any
327: * filters which require that additional packets in the flow are
328: * not fast-forwarded, they must clear the M_CANFASTFWD flag.
329: * Note that filters must _never_ set this flag, as another filter
330: * in the list may have previously cleared it.
331: */
1.39 itojun 332: /*
333: * let ipfilter look at packet on the wire,
334: * not the decapsulated packet.
335: */
1.142 christos 336: #if defined(IPSEC)
1.146 christos 337: if (!ipsec_used || !ipsec_indone(m))
1.39 itojun 338: #else
339: if (1)
340: #endif
341: {
1.64 itojun 342: struct in6_addr odst;
343:
344: odst = ip6->ip6_dst;
1.143 rmind 345: if (pfil_run_hooks(inet6_pfil_hook, &m, m->m_pkthdr.rcvif,
1.39 itojun 346: PFIL_IN) != 0)
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.9 itojun 372: in6_ifstat_inc(m->m_pkthdr.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.13 itojun 390: in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
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.13 itojun 404: in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
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
1.149.4.2 skrll 417: * is not loopback.
1.82 yamt 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: }
427: if (in6_setscope(&ip6->ip6_src, m->m_pkthdr.rcvif, NULL) ||
428: in6_setscope(&ip6->ip6_dst, m->m_pkthdr.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:
439: in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mcast);
1.2 itojun 440: /*
441: * See if we belong to the destination multicast group on the
442: * arrival interface.
443: */
444: IN6_LOOKUP_MULTI(ip6->ip6_dst, m->m_pkthdr.rcvif, in6m);
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.9 itojun 452: in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
1.2 itojun 453: goto bad;
454: }
1.9 itojun 455: deliverifp = m->m_pkthdr.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 &&
483: !(rt->rt_flags & RTF_CLONED) &&
1.2 itojun 484: #if 0
485: /*
486: * The check below is redundant since the comparison of
487: * the destination and the key of the rtentry has
488: * already done through looking up the routing table.
489: */
1.109 dyoung 490: IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, &rt6_getkey(rt)->sin6_addr) &&
1.2 itojun 491: #endif
1.105 dyoung 492: rt->rt_ifp->if_type == IFT_LOOP) {
493: struct in6_ifaddr *ia6 = (struct in6_ifaddr *)rt->rt_ifa;
1.2 itojun 494: if (ia6->ia6_flags & IN6_IFF_ANYCAST)
495: m->m_flags |= M_ANYCAST6;
1.24 itojun 496: /*
497: * packets to a tentative, duplicated, or somehow invalid
498: * address must not be accepted.
499: */
1.2 itojun 500: if (!(ia6->ia6_flags & IN6_IFF_NOTREADY)) {
1.24 itojun 501: /* this address is ready */
1.2 itojun 502: ours = 1;
1.9 itojun 503: deliverifp = ia6->ia_ifp; /* correct? */
1.2 itojun 504: goto hbhcheck;
505: } else {
1.24 itojun 506: /* address is not ready, so discard the packet. */
1.34 itojun 507: nd6log((LOG_INFO,
1.27 itojun 508: "ip6_input: packet to an unready address %s->%s\n",
1.24 itojun 509: ip6_sprintf(&ip6->ip6_src),
1.34 itojun 510: ip6_sprintf(&ip6->ip6_dst)));
1.24 itojun 511:
512: goto bad;
1.2 itojun 513: }
514: }
515:
516: /*
1.55 itojun 517: * FAITH (Firewall Aided Internet Translator)
1.2 itojun 518: */
519: #if defined(NFAITH) && 0 < NFAITH
520: if (ip6_keepfaith) {
1.105 dyoung 521: if (rt != NULL && rt->rt_ifp != NULL &&
522: rt->rt_ifp->if_type == IFT_FAITH) {
1.2 itojun 523: /* XXX do we need more sanity checks? */
524: ours = 1;
1.105 dyoung 525: deliverifp = rt->rt_ifp; /* faith */
1.9 itojun 526: goto hbhcheck;
527: }
528: }
529: #endif
530:
531: #if 0
532: {
533: /*
534: * Last resort: check in6_ifaddr for incoming interface.
535: * The code is here until I update the "goto ours hack" code above
536: * working right.
537: */
538: struct ifaddr *ifa;
1.113 dyoung 539: IFADDR_FOREACH(ifa, m->m_pkthdr.rcvif) {
1.9 itojun 540: if (ifa->ifa_addr == NULL)
541: continue; /* just for safety */
542: if (ifa->ifa_addr->sa_family != AF_INET6)
543: continue;
544: if (IN6_ARE_ADDR_EQUAL(IFA_IN6(ifa), &ip6->ip6_dst)) {
545: ours = 1;
546: deliverifp = ifa->ifa_ifp;
1.2 itojun 547: goto hbhcheck;
548: }
549: }
1.9 itojun 550: }
1.2 itojun 551: #endif
552:
553: /*
554: * Now there is no reason to process the packet if it's not our own
555: * and we're not a router.
556: */
557: if (!ip6_forwarding) {
1.116 thorpej 558: IP6_STATINC(IP6_STAT_CANTFORWARD);
1.9 itojun 559: in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
1.2 itojun 560: goto bad;
561: }
562:
563: hbhcheck:
564: /*
1.81 rpaulo 565: * record address information into m_tag, if we don't have one yet.
566: * note that we are unable to record it, if the address is not listed
567: * as our interface address (e.g. multicast addresses, addresses
568: * within FAITH prefixes and such).
569: */
1.111 dyoung 570: if (deliverifp && ip6_getdstifaddr(m) == NULL) {
1.81 rpaulo 571: struct in6_ifaddr *ia6;
572:
573: ia6 = in6_ifawithifp(deliverifp, &ip6->ip6_dst);
1.111 dyoung 574: if (ia6 != NULL && ip6_setdstifaddr(m, ia6) == NULL) {
575: /*
576: * XXX maybe we should drop the packet here,
577: * as we could not provide enough information
578: * to the upper layers.
579: */
1.81 rpaulo 580: }
581: }
582:
583: /*
1.2 itojun 584: * Process Hop-by-Hop options header if it's contained.
585: * m may be modified in ip6_hopopts_input().
586: * If a JumboPayload option is included, plen will also be modified.
587: */
588: plen = (u_int32_t)ntohs(ip6->ip6_plen);
589: if (ip6->ip6_nxt == IPPROTO_HOPOPTS) {
1.9 itojun 590: struct ip6_hbh *hbh;
591:
592: if (ip6_hopopts_input(&plen, &rtalert, &m, &off)) {
593: #if 0 /*touches NULL pointer*/
594: in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
595: #endif
1.2 itojun 596: return; /* m have already been freed */
1.9 itojun 597: }
1.22 itojun 598:
1.2 itojun 599: /* adjust pointer */
600: ip6 = mtod(m, struct ip6_hdr *);
1.22 itojun 601:
602: /*
1.49 itojun 603: * if the payload length field is 0 and the next header field
1.22 itojun 604: * indicates Hop-by-Hop Options header, then a Jumbo Payload
605: * option MUST be included.
606: */
607: if (ip6->ip6_plen == 0 && plen == 0) {
608: /*
609: * Note that if a valid jumbo payload option is
1.83 rpaulo 610: * contained, ip6_hopopts_input() must set a valid
1.55 itojun 611: * (non-zero) payload length to the variable plen.
1.22 itojun 612: */
1.116 thorpej 613: IP6_STATINC(IP6_STAT_BADOPTIONS);
1.22 itojun 614: in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard);
615: in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr);
616: icmp6_error(m, ICMP6_PARAM_PROB,
617: ICMP6_PARAMPROB_HEADER,
1.97 christos 618: (char *)&ip6->ip6_plen - (char *)ip6);
1.22 itojun 619: return;
620: }
1.9 itojun 621: IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr),
622: sizeof(struct ip6_hbh));
623: if (hbh == NULL) {
1.116 thorpej 624: IP6_STATINC(IP6_STAT_TOOSHORT);
1.9 itojun 625: return;
626: }
1.57 thorpej 627: KASSERT(IP6_HDR_ALIGNED_P(hbh));
1.9 itojun 628: nxt = hbh->ip6h_nxt;
1.2 itojun 629:
630: /*
631: * accept the packet if a router alert option is included
632: * and we act as an IPv6 router.
633: */
1.5 itojun 634: if (rtalert != ~0 && ip6_forwarding)
1.2 itojun 635: ours = 1;
636: } else
637: nxt = ip6->ip6_nxt;
638:
639: /*
640: * Check that the amount of data in the buffers
641: * is as at least much as the IPv6 header would have us expect.
642: * Trim mbufs if longer than we expect.
643: * Drop packet if shorter than we expect.
644: */
645: if (m->m_pkthdr.len - sizeof(struct ip6_hdr) < plen) {
1.116 thorpej 646: IP6_STATINC(IP6_STAT_TOOSHORT);
1.9 itojun 647: in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated);
1.2 itojun 648: goto bad;
649: }
650: if (m->m_pkthdr.len > sizeof(struct ip6_hdr) + plen) {
651: if (m->m_len == m->m_pkthdr.len) {
652: m->m_len = sizeof(struct ip6_hdr) + plen;
653: m->m_pkthdr.len = sizeof(struct ip6_hdr) + plen;
654: } else
655: m_adj(m, sizeof(struct ip6_hdr) + plen - m->m_pkthdr.len);
656: }
657:
658: /*
659: * Forward if desirable.
660: */
661: if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
662: /*
663: * If we are acting as a multicast router, all
664: * incoming multicast packets are passed to the
665: * kernel-level multicast forwarding function.
666: * The packet is returned (relatively) intact; if
667: * ip6_mforward() returns a non-zero value, the packet
668: * must be discarded, else it may be accepted below.
669: */
670: if (ip6_mrouter && ip6_mforward(ip6, m->m_pkthdr.rcvif, m)) {
1.116 thorpej 671: IP6_STATINC(IP6_STAT_CANTFORWARD);
1.2 itojun 672: m_freem(m);
673: return;
674: }
675: if (!ours) {
676: m_freem(m);
677: return;
678: }
1.22 itojun 679: } else if (!ours) {
1.64 itojun 680: ip6_forward(m, srcrt);
1.2 itojun 681: return;
1.56 itojun 682: }
1.25 itojun 683:
684: ip6 = mtod(m, struct ip6_hdr *);
685:
686: /*
687: * Malicious party may be able to use IPv4 mapped addr to confuse
688: * tcp/udp stack and bypass security checks (act as if it was from
689: * 127.0.0.1 by using IPv6 src ::ffff:127.0.0.1). Be cautious.
690: *
691: * For SIIT end node behavior, you may want to disable the check.
692: * However, you will become vulnerable to attacks using IPv4 mapped
693: * source.
694: */
695: if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) ||
696: IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) {
1.116 thorpej 697: IP6_STATINC(IP6_STAT_BADSCOPE);
1.25 itojun 698: in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr);
699: goto bad;
700: }
1.2 itojun 701:
702: /*
703: * Tell launch routine the next header
704: */
1.12 itojun 705: #ifdef IFA_STATS
1.28 itojun 706: if (deliverifp != NULL) {
1.9 itojun 707: struct in6_ifaddr *ia6;
708: ia6 = in6_ifawithifp(deliverifp, &ip6->ip6_dst);
709: if (ia6)
710: ia6->ia_ifa.ifa_data.ifad_inbytes += m->m_pkthdr.len;
711: }
712: #endif
1.116 thorpej 713: IP6_STATINC(IP6_STAT_DELIVERED);
1.9 itojun 714: in6_ifstat_inc(deliverifp, ifs6_in_deliver);
1.2 itojun 715: nest = 0;
1.40 itojun 716:
1.104 yamt 717: rh_present = 0;
1.2 itojun 718: while (nxt != IPPROTO_DONE) {
719: if (ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) {
1.116 thorpej 720: IP6_STATINC(IP6_STAT_TOOMANYHDR);
1.104 yamt 721: in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr);
1.2 itojun 722: goto bad;
723: }
1.8 itojun 724:
725: /*
726: * protection against faulty packet - there should be
727: * more sanity checks in header chain processing.
728: */
729: if (m->m_pkthdr.len < off) {
1.116 thorpej 730: IP6_STATINC(IP6_STAT_TOOSHORT);
1.9 itojun 731: in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated);
1.8 itojun 732: goto bad;
733: }
734:
1.104 yamt 735: if (nxt == IPPROTO_ROUTING) {
736: if (rh_present++) {
737: in6_ifstat_inc(m->m_pkthdr.rcvif,
738: 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.149.4.1 skrll 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.149.4.2 skrll 810: ip6_hopopts_input(u_int32_t *plenp, u_int32_t *rtalertp,
1.107 christos 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.149.4.2 skrll 855: ip6_process_hopopts(struct mbuf *m, u_int8_t *opthead, int hbhlen,
1.107 christos 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.149.4.2 skrll 1030: ip6_savecontrol(struct in6pcb *in6p, struct mbuf **mp,
1.107 christos 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.84 christos 1071: pi6.ipi6_ifindex = m->m_pkthdr.rcvif ?
1072: m->m_pkthdr.rcvif->if_index : 0;
1.97 christos 1073: *mp = sbcreatecontrol((void *) &pi6,
1.85 rpaulo 1074: sizeof(struct in6_pktinfo),
1075: IS2292(IPV6_2292PKTINFO, IPV6_PKTINFO), IPPROTO_IPV6);
1.2 itojun 1076: if (*mp)
1077: mp = &(*mp)->m_next;
1078: }
1.85 rpaulo 1079:
1.2 itojun 1080: if (in6p->in6p_flags & IN6P_HOPLIMIT) {
1081: int hlim = ip6->ip6_hlim & 0xff;
1.85 rpaulo 1082:
1.97 christos 1083: *mp = sbcreatecontrol((void *) &hlim, sizeof(int),
1.85 rpaulo 1084: IS2292(IPV6_2292HOPLIMIT, IPV6_HOPLIMIT), IPPROTO_IPV6);
1085: if (*mp)
1086: mp = &(*mp)->m_next;
1087: }
1088:
1089: if ((in6p->in6p_flags & IN6P_TCLASS) != 0) {
1090: u_int32_t flowinfo;
1091: int tclass;
1092:
1093: flowinfo = (u_int32_t)ntohl(ip6->ip6_flow & IPV6_FLOWINFO_MASK);
1094: flowinfo >>= 20;
1095:
1096: tclass = flowinfo & 0xff;
1.97 christos 1097: *mp = sbcreatecontrol((void *)&tclass, sizeof(tclass),
1.85 rpaulo 1098: IPV6_TCLASS, IPPROTO_IPV6);
1099:
1.2 itojun 1100: if (*mp)
1101: mp = &(*mp)->m_next;
1102: }
1103:
1104: /*
1.75 itojun 1105: * IPV6_HOPOPTS socket option. Recall that we required super-user
1106: * privilege for the option (see ip6_ctloutput), but it might be too
1107: * strict, since there might be some hop-by-hop options which can be
1108: * returned to normal user.
1.85 rpaulo 1109: * See also RFC3542 section 8 (or RFC2292 section 6).
1.2 itojun 1110: */
1.75 itojun 1111: if ((in6p->in6p_flags & IN6P_HOPOPTS) != 0) {
1.2 itojun 1112: /*
1113: * Check if a hop-by-hop options header is contatined in the
1114: * received packet, and if so, store the options as ancillary
1115: * data. Note that a hop-by-hop options header must be
1116: * just after the IPv6 header, which fact is assured through
1117: * the IPv6 input processing.
1118: */
1.78 christos 1119: struct ip6_hdr *xip6 = mtod(m, struct ip6_hdr *);
1120: if (xip6->ip6_nxt == IPPROTO_HOPOPTS) {
1.9 itojun 1121: struct ip6_hbh *hbh;
1122: int hbhlen;
1.62 itojun 1123: struct mbuf *ext;
1.9 itojun 1124:
1.62 itojun 1125: ext = ip6_pullexthdr(m, sizeof(struct ip6_hdr),
1.78 christos 1126: xip6->ip6_nxt);
1.62 itojun 1127: if (ext == NULL) {
1.116 thorpej 1128: IP6_STATINC(IP6_STAT_TOOSHORT);
1.9 itojun 1129: return;
1130: }
1.62 itojun 1131: hbh = mtod(ext, struct ip6_hbh *);
1.9 itojun 1132: hbhlen = (hbh->ip6h_len + 1) << 3;
1.62 itojun 1133: if (hbhlen != ext->m_len) {
1134: m_freem(ext);
1.116 thorpej 1135: IP6_STATINC(IP6_STAT_TOOSHORT);
1.9 itojun 1136: return;
1137: }
1.2 itojun 1138:
1139: /*
1140: * XXX: We copy whole the header even if a jumbo
1141: * payload option is included, which option is to
1142: * be removed before returning in the RFC 2292.
1.85 rpaulo 1143: * Note: this constraint is removed in RFC3542.
1.2 itojun 1144: */
1.97 christos 1145: *mp = sbcreatecontrol((void *)hbh, hbhlen,
1.85 rpaulo 1146: IS2292(IPV6_2292HOPOPTS, IPV6_HOPOPTS),
1147: IPPROTO_IPV6);
1.2 itojun 1148: if (*mp)
1149: mp = &(*mp)->m_next;
1.62 itojun 1150: m_freem(ext);
1.2 itojun 1151: }
1152: }
1153:
1154: /* IPV6_DSTOPTS and IPV6_RTHDR socket options */
1155: if (in6p->in6p_flags & (IN6P_DSTOPTS | IN6P_RTHDR)) {
1.78 christos 1156: struct ip6_hdr *xip6 = mtod(m, struct ip6_hdr *);
1157: int nxt = xip6->ip6_nxt, off = sizeof(struct ip6_hdr);
1.2 itojun 1158:
1159: /*
1160: * Search for destination options headers or routing
1161: * header(s) through the header chain, and stores each
1162: * header as ancillary data.
1163: * Note that the order of the headers remains in
1164: * the chain of ancillary data.
1165: */
1.86 rpaulo 1166: for (;;) { /* is explicit loop prevention necessary? */
1.62 itojun 1167: struct ip6_ext *ip6e = NULL;
1.9 itojun 1168: int elen;
1.62 itojun 1169: struct mbuf *ext = NULL;
1.9 itojun 1170:
1.62 itojun 1171: /*
1172: * if it is not an extension header, don't try to
1173: * pull it from the chain.
1174: */
1175: switch (nxt) {
1176: case IPPROTO_DSTOPTS:
1177: case IPPROTO_ROUTING:
1178: case IPPROTO_HOPOPTS:
1179: case IPPROTO_AH: /* is it possible? */
1180: break;
1181: default:
1182: goto loopend;
1183: }
1184:
1185: ext = ip6_pullexthdr(m, off, nxt);
1186: if (ext == NULL) {
1.116 thorpej 1187: IP6_STATINC(IP6_STAT_TOOSHORT);
1.9 itojun 1188: return;
1189: }
1.62 itojun 1190: ip6e = mtod(ext, struct ip6_ext *);
1.9 itojun 1191: if (nxt == IPPROTO_AH)
1192: elen = (ip6e->ip6e_len + 2) << 2;
1193: else
1194: elen = (ip6e->ip6e_len + 1) << 3;
1.62 itojun 1195: if (elen != ext->m_len) {
1196: m_freem(ext);
1.116 thorpej 1197: IP6_STATINC(IP6_STAT_TOOSHORT);
1.9 itojun 1198: return;
1199: }
1.57 thorpej 1200: KASSERT(IP6_HDR_ALIGNED_P(ip6e));
1.2 itojun 1201:
1.35 itojun 1202: switch (nxt) {
1.62 itojun 1203: case IPPROTO_DSTOPTS:
1.127 martin 1204: if (!(in6p->in6p_flags & IN6P_DSTOPTS))
1.35 itojun 1205: break;
1206:
1.97 christos 1207: *mp = sbcreatecontrol((void *)ip6e, elen,
1.85 rpaulo 1208: IS2292(IPV6_2292DSTOPTS, IPV6_DSTOPTS),
1209: IPPROTO_IPV6);
1.35 itojun 1210: if (*mp)
1211: mp = &(*mp)->m_next;
1212: break;
1213:
1214: case IPPROTO_ROUTING:
1.127 martin 1215: if (!(in6p->in6p_flags & IN6P_RTHDR))
1.35 itojun 1216: break;
1217:
1.97 christos 1218: *mp = sbcreatecontrol((void *)ip6e, elen,
1.85 rpaulo 1219: IS2292(IPV6_2292RTHDR, IPV6_RTHDR),
1220: IPPROTO_IPV6);
1.35 itojun 1221: if (*mp)
1222: mp = &(*mp)->m_next;
1223: break;
1224:
1.62 itojun 1225: case IPPROTO_HOPOPTS:
1226: case IPPROTO_AH: /* is it possible? */
1227: break;
1228:
1.35 itojun 1229: default:
1230: /*
1.62 itojun 1231: * other cases have been filtered in the above.
1232: * none will visit this case. here we supply
1233: * the code just in case (nxt overwritten or
1234: * other cases).
1.35 itojun 1235: */
1.62 itojun 1236: m_freem(ext);
1.35 itojun 1237: goto loopend;
1238:
1.2 itojun 1239: }
1240:
1241: /* proceed with the next header. */
1.9 itojun 1242: off += elen;
1.2 itojun 1243: nxt = ip6e->ip6e_nxt;
1.62 itojun 1244: ip6e = NULL;
1245: m_freem(ext);
1246: ext = NULL;
1.2 itojun 1247: }
1248: loopend:
1.62 itojun 1249: ;
1.2 itojun 1250: }
1.62 itojun 1251: }
1.85 rpaulo 1252: #undef IS2292
1253:
1254:
1255: void
1.95 dyoung 1256: ip6_notify_pmtu(struct in6pcb *in6p, const struct sockaddr_in6 *dst,
1257: uint32_t *mtu)
1.85 rpaulo 1258: {
1259: struct socket *so;
1260: struct mbuf *m_mtu;
1261: struct ip6_mtuinfo mtuctl;
1262:
1263: so = in6p->in6p_socket;
1264:
1265: if (mtu == NULL)
1266: return;
1267:
1268: #ifdef DIAGNOSTIC
1269: if (so == NULL) /* I believe this is impossible */
1270: panic("ip6_notify_pmtu: socket is NULL");
1271: #endif
1272:
1273: memset(&mtuctl, 0, sizeof(mtuctl)); /* zero-clear for safety */
1274: mtuctl.ip6m_mtu = *mtu;
1275: mtuctl.ip6m_addr = *dst;
1276: if (sa6_recoverscope(&mtuctl.ip6m_addr))
1277: return;
1278:
1.97 christos 1279: if ((m_mtu = sbcreatecontrol((void *)&mtuctl, sizeof(mtuctl),
1.85 rpaulo 1280: IPV6_PATHMTU, IPPROTO_IPV6)) == NULL)
1281: return;
1282:
1.95 dyoung 1283: if (sbappendaddr(&so->so_rcv, (const struct sockaddr *)dst, NULL, m_mtu)
1.85 rpaulo 1284: == 0) {
1285: m_freem(m_mtu);
1286: /* XXX: should count statistics */
1287: } else
1288: sorwakeup(so);
1289:
1290: return;
1291: }
1.62 itojun 1292:
1293: /*
1294: * pull single extension header from mbuf chain. returns single mbuf that
1295: * contains the result, or NULL on error.
1296: */
1297: static struct mbuf *
1.107 christos 1298: ip6_pullexthdr(struct mbuf *m, size_t off, int nxt)
1.62 itojun 1299: {
1300: struct ip6_ext ip6e;
1301: size_t elen;
1302: struct mbuf *n;
1303:
1304: #ifdef DIAGNOSTIC
1305: switch (nxt) {
1306: case IPPROTO_DSTOPTS:
1307: case IPPROTO_ROUTING:
1308: case IPPROTO_HOPOPTS:
1309: case IPPROTO_AH: /* is it possible? */
1310: break;
1311: default:
1312: printf("ip6_pullexthdr: invalid nxt=%d\n", nxt);
1.2 itojun 1313: }
1.62 itojun 1314: #endif
1.2 itojun 1315:
1.97 christos 1316: m_copydata(m, off, sizeof(ip6e), (void *)&ip6e);
1.62 itojun 1317: if (nxt == IPPROTO_AH)
1318: elen = (ip6e.ip6e_len + 2) << 2;
1319: else
1320: elen = (ip6e.ip6e_len + 1) << 3;
1321:
1322: MGET(n, M_DONTWAIT, MT_DATA);
1323: if (n && elen >= MLEN) {
1324: MCLGET(n, M_DONTWAIT);
1325: if ((n->m_flags & M_EXT) == 0) {
1326: m_free(n);
1327: n = NULL;
1328: }
1329: }
1330: if (!n)
1331: return NULL;
1332:
1333: n->m_len = 0;
1334: if (elen >= M_TRAILINGSPACE(n)) {
1335: m_free(n);
1336: return NULL;
1337: }
1338:
1.97 christos 1339: m_copydata(m, off, elen, mtod(n, void *));
1.62 itojun 1340: n->m_len = elen;
1341: return n;
1.2 itojun 1342: }
1343:
1344: /*
1345: * Get pointer to the previous header followed by the header
1346: * currently processed.
1347: * XXX: This function supposes that
1348: * M includes all headers,
1349: * the next header field and the header length field of each header
1350: * are valid, and
1351: * the sum of each header length equals to OFF.
1352: * Because of these assumptions, this function must be called very
1353: * carefully. Moreover, it will not be used in the near future when
1354: * we develop `neater' mechanism to process extension headers.
1355: */
1.58 itojun 1356: u_int8_t *
1.107 christos 1357: ip6_get_prevhdr(struct mbuf *m, int off)
1.2 itojun 1358: {
1359: struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
1360:
1361: if (off == sizeof(struct ip6_hdr))
1.58 itojun 1362: return (&ip6->ip6_nxt);
1.2 itojun 1363: else {
1364: int len, nxt;
1365: struct ip6_ext *ip6e = NULL;
1366:
1367: nxt = ip6->ip6_nxt;
1368: len = sizeof(struct ip6_hdr);
1369: while (len < off) {
1.97 christos 1370: ip6e = (struct ip6_ext *)(mtod(m, char *) + len);
1.2 itojun 1371:
1.35 itojun 1372: switch (nxt) {
1.2 itojun 1373: case IPPROTO_FRAGMENT:
1374: len += sizeof(struct ip6_frag);
1375: break;
1376: case IPPROTO_AH:
1377: len += (ip6e->ip6e_len + 2) << 2;
1378: break;
1379: default:
1380: len += (ip6e->ip6e_len + 1) << 3;
1381: break;
1382: }
1383: nxt = ip6e->ip6e_nxt;
1384: }
1385: if (ip6e)
1.58 itojun 1386: return (&ip6e->ip6e_nxt);
1.2 itojun 1387: else
1388: return NULL;
1.18 itojun 1389: }
1390: }
1391:
1392: /*
1393: * get next header offset. m will be retained.
1394: */
1395: int
1.107 christos 1396: ip6_nexthdr(struct mbuf *m, int off, int proto, int *nxtp)
1.18 itojun 1397: {
1398: struct ip6_hdr ip6;
1399: struct ip6_ext ip6e;
1400: struct ip6_frag fh;
1401:
1402: /* just in case */
1403: if (m == NULL)
1404: panic("ip6_nexthdr: m == NULL");
1405: if ((m->m_flags & M_PKTHDR) == 0 || m->m_pkthdr.len < off)
1406: return -1;
1407:
1408: switch (proto) {
1409: case IPPROTO_IPV6:
1.83 rpaulo 1410: /* do not chase beyond intermediate IPv6 headers */
1411: if (off != 0)
1412: return -1;
1.18 itojun 1413: if (m->m_pkthdr.len < off + sizeof(ip6))
1414: return -1;
1.97 christos 1415: m_copydata(m, off, sizeof(ip6), (void *)&ip6);
1.18 itojun 1416: if (nxtp)
1417: *nxtp = ip6.ip6_nxt;
1418: off += sizeof(ip6);
1419: return off;
1420:
1421: case IPPROTO_FRAGMENT:
1422: /*
1423: * terminate parsing if it is not the first fragment,
1424: * it does not make sense to parse through it.
1425: */
1426: if (m->m_pkthdr.len < off + sizeof(fh))
1427: return -1;
1.97 christos 1428: m_copydata(m, off, sizeof(fh), (void *)&fh);
1.67 itojun 1429: if ((fh.ip6f_offlg & IP6F_OFF_MASK) != 0)
1.18 itojun 1430: return -1;
1431: if (nxtp)
1432: *nxtp = fh.ip6f_nxt;
1433: off += sizeof(struct ip6_frag);
1434: return off;
1435:
1436: case IPPROTO_AH:
1437: if (m->m_pkthdr.len < off + sizeof(ip6e))
1438: return -1;
1.97 christos 1439: m_copydata(m, off, sizeof(ip6e), (void *)&ip6e);
1.18 itojun 1440: if (nxtp)
1441: *nxtp = ip6e.ip6e_nxt;
1442: off += (ip6e.ip6e_len + 2) << 2;
1.47 itojun 1443: if (m->m_pkthdr.len < off)
1444: return -1;
1.18 itojun 1445: return off;
1446:
1447: case IPPROTO_HOPOPTS:
1448: case IPPROTO_ROUTING:
1449: case IPPROTO_DSTOPTS:
1450: if (m->m_pkthdr.len < off + sizeof(ip6e))
1451: return -1;
1.97 christos 1452: m_copydata(m, off, sizeof(ip6e), (void *)&ip6e);
1.18 itojun 1453: if (nxtp)
1454: *nxtp = ip6e.ip6e_nxt;
1455: off += (ip6e.ip6e_len + 1) << 3;
1.47 itojun 1456: if (m->m_pkthdr.len < off)
1457: return -1;
1.18 itojun 1458: return off;
1459:
1460: case IPPROTO_NONE:
1461: case IPPROTO_ESP:
1462: case IPPROTO_IPCOMP:
1463: /* give up */
1464: return -1;
1465:
1466: default:
1467: return -1;
1468: }
1469: }
1470:
1471: /*
1472: * get offset for the last header in the chain. m will be kept untainted.
1473: */
1474: int
1.107 christos 1475: ip6_lasthdr(struct mbuf *m, int off, int proto, int *nxtp)
1.18 itojun 1476: {
1477: int newoff;
1478: int nxt;
1479:
1480: if (!nxtp) {
1481: nxt = -1;
1482: nxtp = &nxt;
1483: }
1.86 rpaulo 1484: for (;;) {
1.18 itojun 1485: newoff = ip6_nexthdr(m, off, proto, nxtp);
1486: if (newoff < 0)
1487: return off;
1488: else if (newoff < off)
1489: return -1; /* invalid */
1490: else if (newoff == off)
1491: return newoff;
1492:
1493: off = newoff;
1494: proto = *nxtp;
1.2 itojun 1495: }
1496: }
1497:
1.81 rpaulo 1498: struct m_tag *
1.107 christos 1499: ip6_addaux(struct mbuf *m)
1.81 rpaulo 1500: {
1501: struct m_tag *mtag;
1502:
1503: mtag = m_tag_find(m, PACKET_TAG_INET6, NULL);
1504: if (!mtag) {
1505: mtag = m_tag_get(PACKET_TAG_INET6, sizeof(struct ip6aux),
1506: M_NOWAIT);
1507: if (mtag) {
1508: m_tag_prepend(m, mtag);
1.124 cegger 1509: memset(mtag + 1, 0, sizeof(struct ip6aux));
1.81 rpaulo 1510: }
1511: }
1512: return mtag;
1513: }
1514:
1515: struct m_tag *
1.107 christos 1516: ip6_findaux(struct mbuf *m)
1.81 rpaulo 1517: {
1518: struct m_tag *mtag;
1519:
1520: mtag = m_tag_find(m, PACKET_TAG_INET6, NULL);
1521: return mtag;
1522: }
1523:
1524: void
1.107 christos 1525: ip6_delaux(struct mbuf *m)
1.81 rpaulo 1526: {
1527: struct m_tag *mtag;
1528:
1529: mtag = m_tag_find(m, PACKET_TAG_INET6, NULL);
1530: if (mtag)
1531: m_tag_delete(m, mtag);
1532: }
1533:
1.98 liamjfoy 1534: #ifdef GATEWAY
1.149.4.2 skrll 1535: /*
1.98 liamjfoy 1536: * sysctl helper routine for net.inet.ip6.maxflows. Since
1537: * we could reduce this value, call ip6flow_reap();
1538: */
1539: static int
1.101 liamjfoy 1540: sysctl_net_inet6_ip6_maxflows(SYSCTLFN_ARGS)
1.149.4.2 skrll 1541: {
1.121 simonb 1542: int error;
1.149.4.2 skrll 1543:
1.121 simonb 1544: error = sysctl_lookup(SYSCTLFN_CALL(rnode));
1545: if (error || newp == NULL)
1546: return (error);
1.149.4.2 skrll 1547:
1.121 simonb 1548: mutex_enter(softnet_lock);
1.122 matt 1549: KERNEL_LOCK(1, NULL);
1.120 matt 1550:
1.121 simonb 1551: ip6flow_reap(0);
1.120 matt 1552:
1553: KERNEL_UNLOCK_ONE(NULL);
1.121 simonb 1554: mutex_exit(softnet_lock);
1.149.4.2 skrll 1555:
1.121 simonb 1556: return (0);
1.98 liamjfoy 1557: }
1.99 liamjfoy 1558:
1559: static int
1560: sysctl_net_inet6_ip6_hashsize(SYSCTLFN_ARGS)
1.149.4.2 skrll 1561: {
1.99 liamjfoy 1562: int error, tmp;
1563: struct sysctlnode node;
1564:
1565: node = *rnode;
1566: tmp = ip6_hashsize;
1567: node.sysctl_data = &tmp;
1568: error = sysctl_lookup(SYSCTLFN_CALL(&node));
1569: if (error || newp == NULL)
1570: return (error);
1571:
1572: if ((tmp & (tmp - 1)) == 0 && tmp != 0) {
1573: /*
1574: * Can only fail due to malloc()
1575: */
1.120 matt 1576: mutex_enter(softnet_lock);
1.122 matt 1577: KERNEL_LOCK(1, NULL);
1.120 matt 1578:
1579: error = ip6flow_invalidate_all(tmp);
1580:
1581: KERNEL_UNLOCK_ONE(NULL);
1582: mutex_exit(softnet_lock);
1.99 liamjfoy 1583: } else {
1584: /*
1585: * EINVAL if not a power of 2
1.121 simonb 1586: */
1.120 matt 1587: error = EINVAL;
1.149.4.2 skrll 1588: }
1.99 liamjfoy 1589:
1.120 matt 1590: return error;
1.99 liamjfoy 1591: }
1.98 liamjfoy 1592: #endif /* GATEWAY */
1593:
1.2 itojun 1594: /*
1595: * System control for IP6
1596: */
1597:
1.120 matt 1598: const u_char inet6ctlerrmap[PRC_NCMDS] = {
1.2 itojun 1599: 0, 0, 0, 0,
1600: 0, EMSGSIZE, EHOSTDOWN, EHOSTUNREACH,
1601: EHOSTUNREACH, EHOSTUNREACH, ECONNREFUSED, ECONNREFUSED,
1602: EMSGSIZE, EHOSTUNREACH, 0, 0,
1603: 0, 0, 0, 0,
1604: ENOPROTOOPT
1605: };
1606:
1.149.4.3 skrll 1607: extern int sysctl_net_inet6_addrctlpolicy(SYSCTLFN_ARGS);
1608:
1.116 thorpej 1609: static int
1610: sysctl_net_inet6_ip6_stats(SYSCTLFN_ARGS)
1611: {
1612:
1.119 thorpej 1613: return (NETSTAT_SYSCTL(ip6stat_percpu, IP6_NSTATS));
1.116 thorpej 1614: }
1615:
1.128 pooka 1616: static void
1617: sysctl_net_inet6_ip6_setup(struct sysctllog **clog)
1.2 itojun 1618: {
1.85 rpaulo 1619: #ifdef RFC2292
1620: #define IS2292(x, y) ((in6p->in6p_flags & IN6P_RFC2292) ? (x) : (y))
1621: #else
1622: #define IS2292(x, y) (y)
1623: #endif
1.26 itojun 1624:
1.73 atatat 1625: sysctl_createv(clog, 0, NULL, NULL,
1626: CTLFLAG_PERMANENT,
1.74 atatat 1627: CTLTYPE_NODE, "inet6",
1628: SYSCTL_DESCR("PF_INET6 related settings"),
1.70 atatat 1629: NULL, 0, NULL, 0,
1630: CTL_NET, PF_INET6, CTL_EOL);
1.73 atatat 1631: sysctl_createv(clog, 0, NULL, NULL,
1632: CTLFLAG_PERMANENT,
1.74 atatat 1633: CTLTYPE_NODE, "ip6",
1634: SYSCTL_DESCR("IPv6 related settings"),
1.70 atatat 1635: NULL, 0, NULL, 0,
1636: CTL_NET, PF_INET6, IPPROTO_IPV6, CTL_EOL);
1637:
1.73 atatat 1638: sysctl_createv(clog, 0, NULL, NULL,
1639: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74 atatat 1640: CTLTYPE_INT, "forwarding",
1641: SYSCTL_DESCR("Enable forwarding of INET6 datagrams"),
1.70 atatat 1642: NULL, 0, &ip6_forwarding, 0,
1643: CTL_NET, PF_INET6, IPPROTO_IPV6,
1644: IPV6CTL_FORWARDING, CTL_EOL);
1.73 atatat 1645: sysctl_createv(clog, 0, NULL, NULL,
1646: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74 atatat 1647: CTLTYPE_INT, "redirect",
1648: SYSCTL_DESCR("Enable sending of ICMPv6 redirect messages"),
1.70 atatat 1649: NULL, 0, &ip6_sendredirects, 0,
1650: CTL_NET, PF_INET6, IPPROTO_IPV6,
1651: IPV6CTL_SENDREDIRECTS, CTL_EOL);
1.73 atatat 1652: sysctl_createv(clog, 0, NULL, NULL,
1653: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74 atatat 1654: CTLTYPE_INT, "hlim",
1655: SYSCTL_DESCR("Hop limit for an INET6 datagram"),
1.70 atatat 1656: NULL, 0, &ip6_defhlim, 0,
1657: CTL_NET, PF_INET6, IPPROTO_IPV6,
1658: IPV6CTL_DEFHLIM, CTL_EOL);
1659: #ifdef notyet
1.73 atatat 1660: sysctl_createv(clog, 0, NULL, NULL,
1661: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.70 atatat 1662: CTLTYPE_INT, "mtu", NULL,
1663: NULL, 0, &, 0,
1664: CTL_NET, PF_INET6, IPPROTO_IPV6,
1665: IPV6CTL_DEFMTU, CTL_EOL);
1666: #endif
1667: #ifdef __no_idea__
1.73 atatat 1668: sysctl_createv(clog, 0, NULL, NULL,
1669: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.70 atatat 1670: CTLTYPE_INT, "forwsrcrt", NULL,
1671: NULL, 0, &?, 0,
1672: CTL_NET, PF_INET6, IPPROTO_IPV6,
1673: IPV6CTL_FORWSRCRT, CTL_EOL);
1.73 atatat 1674: sysctl_createv(clog, 0, NULL, NULL,
1675: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.70 atatat 1676: CTLTYPE_STRUCT, "mrtstats", NULL,
1677: NULL, 0, &?, sizeof(?),
1678: CTL_NET, PF_INET6, IPPROTO_IPV6,
1679: IPV6CTL_MRTSTATS, CTL_EOL);
1.73 atatat 1680: sysctl_createv(clog, 0, NULL, NULL,
1681: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.70 atatat 1682: CTLTYPE_?, "mrtproto", NULL,
1683: NULL, 0, &?, sizeof(?),
1684: CTL_NET, PF_INET6, IPPROTO_IPV6,
1685: IPV6CTL_MRTPROTO, CTL_EOL);
1686: #endif
1.73 atatat 1687: sysctl_createv(clog, 0, NULL, NULL,
1688: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74 atatat 1689: CTLTYPE_INT, "maxfragpackets",
1690: SYSCTL_DESCR("Maximum number of fragments to buffer "
1691: "for reassembly"),
1.70 atatat 1692: NULL, 0, &ip6_maxfragpackets, 0,
1693: CTL_NET, PF_INET6, IPPROTO_IPV6,
1694: IPV6CTL_MAXFRAGPACKETS, CTL_EOL);
1695: #ifdef __no_idea__
1.73 atatat 1696: sysctl_createv(clog, 0, NULL, NULL,
1697: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.70 atatat 1698: CTLTYPE_INT, "sourcecheck", NULL,
1699: NULL, 0, &?, 0,
1700: CTL_NET, PF_INET6, IPPROTO_IPV6,
1701: IPV6CTL_SOURCECHECK, CTL_EOL);
1.73 atatat 1702: sysctl_createv(clog, 0, NULL, NULL,
1703: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.70 atatat 1704: CTLTYPE_INT, "sourcecheck_logint", NULL,
1705: NULL, 0, &?, 0,
1706: CTL_NET, PF_INET6, IPPROTO_IPV6,
1707: IPV6CTL_SOURCECHECK_LOGINT, CTL_EOL);
1708: #endif
1.73 atatat 1709: sysctl_createv(clog, 0, NULL, NULL,
1710: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74 atatat 1711: CTLTYPE_INT, "accept_rtadv",
1712: SYSCTL_DESCR("Accept router advertisements"),
1.70 atatat 1713: NULL, 0, &ip6_accept_rtadv, 0,
1714: CTL_NET, PF_INET6, IPPROTO_IPV6,
1715: IPV6CTL_ACCEPT_RTADV, CTL_EOL);
1.73 atatat 1716: sysctl_createv(clog, 0, NULL, NULL,
1717: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.131 spz 1718: CTLTYPE_INT, "rtadv_maxroutes",
1719: SYSCTL_DESCR("Maximum number of routes accepted via router advertisements"),
1720: NULL, 0, &ip6_rtadv_maxroutes, 0,
1721: CTL_NET, PF_INET6, IPPROTO_IPV6,
1722: IPV6CTL_RTADV_MAXROUTES, CTL_EOL);
1723: sysctl_createv(clog, 0, NULL, NULL,
1724: CTLFLAG_PERMANENT,
1725: CTLTYPE_INT, "rtadv_numroutes",
1726: SYSCTL_DESCR("Current number of routes accepted via router advertisements"),
1727: NULL, 0, &nd6_numroutes, 0,
1728: CTL_NET, PF_INET6, IPPROTO_IPV6,
1729: IPV6CTL_RTADV_NUMROUTES, CTL_EOL);
1730: sysctl_createv(clog, 0, NULL, NULL,
1731: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74 atatat 1732: CTLTYPE_INT, "keepfaith",
1733: SYSCTL_DESCR("Activate faith interface"),
1.70 atatat 1734: NULL, 0, &ip6_keepfaith, 0,
1735: CTL_NET, PF_INET6, IPPROTO_IPV6,
1736: IPV6CTL_KEEPFAITH, CTL_EOL);
1.73 atatat 1737: sysctl_createv(clog, 0, NULL, NULL,
1738: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74 atatat 1739: CTLTYPE_INT, "log_interval",
1740: SYSCTL_DESCR("Minumum interval between logging "
1741: "unroutable packets"),
1.70 atatat 1742: NULL, 0, &ip6_log_interval, 0,
1743: CTL_NET, PF_INET6, IPPROTO_IPV6,
1744: IPV6CTL_LOG_INTERVAL, CTL_EOL);
1.73 atatat 1745: sysctl_createv(clog, 0, NULL, NULL,
1746: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74 atatat 1747: CTLTYPE_INT, "hdrnestlimit",
1748: SYSCTL_DESCR("Maximum number of nested IPv6 headers"),
1.70 atatat 1749: NULL, 0, &ip6_hdrnestlimit, 0,
1750: CTL_NET, PF_INET6, IPPROTO_IPV6,
1751: IPV6CTL_HDRNESTLIMIT, CTL_EOL);
1.73 atatat 1752: sysctl_createv(clog, 0, NULL, NULL,
1753: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74 atatat 1754: CTLTYPE_INT, "dad_count",
1755: SYSCTL_DESCR("Number of Duplicate Address Detection "
1756: "probes to send"),
1.70 atatat 1757: NULL, 0, &ip6_dad_count, 0,
1758: CTL_NET, PF_INET6, IPPROTO_IPV6,
1759: IPV6CTL_DAD_COUNT, CTL_EOL);
1.73 atatat 1760: sysctl_createv(clog, 0, NULL, NULL,
1761: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74 atatat 1762: CTLTYPE_INT, "auto_flowlabel",
1763: SYSCTL_DESCR("Assign random IPv6 flow labels"),
1.70 atatat 1764: NULL, 0, &ip6_auto_flowlabel, 0,
1765: CTL_NET, PF_INET6, IPPROTO_IPV6,
1766: IPV6CTL_AUTO_FLOWLABEL, CTL_EOL);
1.73 atatat 1767: sysctl_createv(clog, 0, NULL, NULL,
1768: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74 atatat 1769: CTLTYPE_INT, "defmcasthlim",
1770: SYSCTL_DESCR("Default multicast hop limit"),
1.70 atatat 1771: NULL, 0, &ip6_defmcasthlim, 0,
1772: CTL_NET, PF_INET6, IPPROTO_IPV6,
1773: IPV6CTL_DEFMCASTHLIM, CTL_EOL);
1.73 atatat 1774: sysctl_createv(clog, 0, NULL, NULL,
1775: CTLFLAG_PERMANENT,
1.74 atatat 1776: CTLTYPE_STRING, "kame_version",
1777: SYSCTL_DESCR("KAME Version"),
1.78 christos 1778: NULL, 0, __UNCONST(__KAME_VERSION), 0,
1.70 atatat 1779: CTL_NET, PF_INET6, IPPROTO_IPV6,
1780: IPV6CTL_KAME_VERSION, CTL_EOL);
1.73 atatat 1781: sysctl_createv(clog, 0, NULL, NULL,
1782: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74 atatat 1783: CTLTYPE_INT, "use_deprecated",
1784: SYSCTL_DESCR("Allow use of deprecated addresses as "
1785: "source addresses"),
1.70 atatat 1786: NULL, 0, &ip6_use_deprecated, 0,
1787: CTL_NET, PF_INET6, IPPROTO_IPV6,
1788: IPV6CTL_USE_DEPRECATED, CTL_EOL);
1.73 atatat 1789: sysctl_createv(clog, 0, NULL, NULL,
1790: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.70 atatat 1791: CTLTYPE_INT, "rr_prune", NULL,
1792: NULL, 0, &ip6_rr_prune, 0,
1793: CTL_NET, PF_INET6, IPPROTO_IPV6,
1794: IPV6CTL_RR_PRUNE, CTL_EOL);
1.73 atatat 1795: sysctl_createv(clog, 0, NULL, NULL,
1796: CTLFLAG_PERMANENT
1.70 atatat 1797: #ifndef INET6_BINDV6ONLY
1.73 atatat 1798: |CTLFLAG_READWRITE,
1.70 atatat 1799: #endif
1.74 atatat 1800: CTLTYPE_INT, "v6only",
1801: SYSCTL_DESCR("Disallow PF_INET6 sockets from connecting "
1802: "to PF_INET sockets"),
1.70 atatat 1803: NULL, 0, &ip6_v6only, 0,
1804: CTL_NET, PF_INET6, IPPROTO_IPV6,
1805: IPV6CTL_V6ONLY, CTL_EOL);
1.73 atatat 1806: sysctl_createv(clog, 0, NULL, NULL,
1807: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74 atatat 1808: CTLTYPE_INT, "anonportmin",
1809: SYSCTL_DESCR("Lowest ephemeral port number to assign"),
1.70 atatat 1810: sysctl_net_inet_ip_ports, 0, &ip6_anonportmin, 0,
1811: CTL_NET, PF_INET6, IPPROTO_IPV6,
1812: IPV6CTL_ANONPORTMIN, CTL_EOL);
1.73 atatat 1813: sysctl_createv(clog, 0, NULL, NULL,
1814: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74 atatat 1815: CTLTYPE_INT, "anonportmax",
1816: SYSCTL_DESCR("Highest ephemeral port number to assign"),
1.70 atatat 1817: sysctl_net_inet_ip_ports, 0, &ip6_anonportmax, 0,
1818: CTL_NET, PF_INET6, IPPROTO_IPV6,
1819: IPV6CTL_ANONPORTMAX, CTL_EOL);
1.26 itojun 1820: #ifndef IPNOPRIVPORTS
1.73 atatat 1821: sysctl_createv(clog, 0, NULL, NULL,
1822: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74 atatat 1823: CTLTYPE_INT, "lowportmin",
1824: SYSCTL_DESCR("Lowest privileged ephemeral port number "
1825: "to assign"),
1.70 atatat 1826: sysctl_net_inet_ip_ports, 0, &ip6_lowportmin, 0,
1827: CTL_NET, PF_INET6, IPPROTO_IPV6,
1828: IPV6CTL_LOWPORTMIN, CTL_EOL);
1.73 atatat 1829: sysctl_createv(clog, 0, NULL, NULL,
1830: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74 atatat 1831: CTLTYPE_INT, "lowportmax",
1832: SYSCTL_DESCR("Highest privileged ephemeral port number "
1833: "to assign"),
1.70 atatat 1834: sysctl_net_inet_ip_ports, 0, &ip6_lowportmax, 0,
1835: CTL_NET, PF_INET6, IPPROTO_IPV6,
1836: IPV6CTL_LOWPORTMAX, CTL_EOL);
1837: #endif /* IPNOPRIVPORTS */
1.73 atatat 1838: sysctl_createv(clog, 0, NULL, NULL,
1839: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.149.4.3 skrll 1840: CTLTYPE_INT, "auto_linklocal",
1841: SYSCTL_DESCR("Default value of per-interface flag for "
1842: "adding an IPv6 link-local address to "
1843: "interfaces when attached"),
1844: NULL, 0, &ip6_auto_linklocal, 0,
1845: CTL_NET, PF_INET6, IPPROTO_IPV6,
1846: IPV6CTL_AUTO_LINKLOCAL, CTL_EOL);
1847: sysctl_createv(clog, 0, NULL, NULL,
1848: CTLFLAG_PERMANENT|CTLFLAG_READONLY,
1849: CTLTYPE_STRUCT, "addctlpolicy",
1850: SYSCTL_DESCR("Return the current address control"
1851: " policy"),
1852: sysctl_net_inet6_addrctlpolicy, 0, NULL, 0,
1853: CTL_NET, PF_INET6, IPPROTO_IPV6,
1854: IPV6CTL_ADDRCTLPOLICY, CTL_EOL);
1855: sysctl_createv(clog, 0, NULL, NULL,
1856: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.83 rpaulo 1857: CTLTYPE_INT, "use_tempaddr",
1858: SYSCTL_DESCR("Use temporary address"),
1859: NULL, 0, &ip6_use_tempaddr, 0,
1860: CTL_NET, PF_INET6, IPPROTO_IPV6,
1861: CTL_CREATE, CTL_EOL);
1862: sysctl_createv(clog, 0, NULL, NULL,
1863: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.149.4.1 skrll 1864: CTLTYPE_INT, "prefer_tempaddr",
1865: SYSCTL_DESCR("Prefer temporary address as source "
1866: "address"),
1867: NULL, 0, &ip6_prefer_tempaddr, 0,
1868: CTL_NET, PF_INET6, IPPROTO_IPV6,
1869: CTL_CREATE, CTL_EOL);
1870: sysctl_createv(clog, 0, NULL, NULL,
1871: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.83 rpaulo 1872: CTLTYPE_INT, "temppltime",
1873: SYSCTL_DESCR("preferred lifetime of a temporary address"),
1874: NULL, 0, &ip6_temp_preferred_lifetime, 0,
1875: CTL_NET, PF_INET6, IPPROTO_IPV6,
1876: CTL_CREATE, CTL_EOL);
1877: sysctl_createv(clog, 0, NULL, NULL,
1878: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1879: CTLTYPE_INT, "tempvltime",
1880: SYSCTL_DESCR("valid lifetime of a temporary address"),
1881: NULL, 0, &ip6_temp_valid_lifetime, 0,
1882: CTL_NET, PF_INET6, IPPROTO_IPV6,
1883: CTL_CREATE, CTL_EOL);
1884: sysctl_createv(clog, 0, NULL, NULL,
1885: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1.74 atatat 1886: CTLTYPE_INT, "maxfrags",
1887: SYSCTL_DESCR("Maximum fragments in reassembly queue"),
1.70 atatat 1888: NULL, 0, &ip6_maxfrags, 0,
1889: CTL_NET, PF_INET6, IPPROTO_IPV6,
1890: IPV6CTL_MAXFRAGS, CTL_EOL);
1.79 rpaulo 1891: sysctl_createv(clog, 0, NULL, NULL,
1892: CTLFLAG_PERMANENT,
1893: CTLTYPE_STRUCT, "stats",
1894: SYSCTL_DESCR("IPv6 statistics"),
1.116 thorpej 1895: sysctl_net_inet6_ip6_stats, 0, NULL, 0,
1.79 rpaulo 1896: CTL_NET, PF_INET6, IPPROTO_IPV6,
1897: IPV6CTL_STATS, CTL_EOL);
1.81 rpaulo 1898: sysctl_createv(clog, 0, NULL, NULL,
1899: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1900: CTLTYPE_INT, "use_defaultzone",
1901: SYSCTL_DESCR("Whether to use the default scope zones"),
1902: NULL, 0, &ip6_use_defzone, 0,
1903: CTL_NET, PF_INET6, IPPROTO_IPV6,
1904: IPV6CTL_USE_DEFAULTZONE, CTL_EOL);
1.83 rpaulo 1905: sysctl_createv(clog, 0, NULL, NULL,
1906: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1907: CTLTYPE_INT, "mcast_pmtu",
1908: SYSCTL_DESCR("Enable pMTU discovery for multicast packet"),
1909: NULL, 0, &ip6_mcast_pmtu, 0,
1910: CTL_NET, PF_INET6, IPPROTO_IPV6,
1911: CTL_CREATE, CTL_EOL);
1.149.4.2 skrll 1912: #ifdef GATEWAY
1.98 liamjfoy 1913: sysctl_createv(clog, 0, NULL, NULL,
1914: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1915: CTLTYPE_INT, "maxflows",
1916: SYSCTL_DESCR("Number of flows for fast forwarding (IPv6)"),
1.101 liamjfoy 1917: sysctl_net_inet6_ip6_maxflows, 0, &ip6_maxflows, 0,
1.98 liamjfoy 1918: CTL_NET, PF_INET6, IPPROTO_IPV6,
1919: CTL_CREATE, CTL_EOL);
1.99 liamjfoy 1920: sysctl_createv(clog, 0, NULL, NULL,
1921: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1922: CTLTYPE_INT, "hashsize",
1923: SYSCTL_DESCR("Size of hash table for fast forwarding (IPv6)"),
1924: sysctl_net_inet6_ip6_hashsize, 0, &ip6_hashsize, 0,
1925: CTL_NET, PF_INET6, IPPROTO_IPV6,
1926: CTL_CREATE, CTL_EOL);
1.98 liamjfoy 1927: #endif
1.138 christos 1928: /* anonportalgo RFC6056 subtree */
1.140 christos 1929: const struct sysctlnode *portalgo_node;
1930: sysctl_createv(clog, 0, NULL, &portalgo_node,
1.138 christos 1931: CTLFLAG_PERMANENT,
1932: CTLTYPE_NODE, "anonportalgo",
1933: SYSCTL_DESCR("Anonymous port algorithm selection (RFC 6056)"),
1934: NULL, 0, NULL, 0,
1935: CTL_NET, PF_INET6, IPPROTO_IPV6, CTL_CREATE, CTL_EOL);
1.140 christos 1936: sysctl_createv(clog, 0, &portalgo_node, NULL,
1.138 christos 1937: CTLFLAG_PERMANENT,
1938: CTLTYPE_STRING, "available",
1939: SYSCTL_DESCR("available algorithms"),
1.140 christos 1940: sysctl_portalgo_available, 0, NULL, PORTALGO_MAXLEN,
1.138 christos 1941: CTL_CREATE, CTL_EOL);
1.140 christos 1942: sysctl_createv(clog, 0, &portalgo_node, NULL,
1.138 christos 1943: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1944: CTLTYPE_STRING, "selected",
1945: SYSCTL_DESCR("selected algorithm"),
1.140 christos 1946: sysctl_portalgo_selected6, 0, NULL, PORTALGO_MAXLEN,
1.138 christos 1947: CTL_CREATE, CTL_EOL);
1.141 christos 1948: sysctl_createv(clog, 0, &portalgo_node, NULL,
1949: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1950: CTLTYPE_STRUCT, "reserve",
1951: SYSCTL_DESCR("bitmap of reserved ports"),
1952: sysctl_portalgo_reserve6, 0, NULL, 0,
1953: CTL_CREATE, CTL_EOL);
1.139 christos 1954: sysctl_createv(clog, 0, NULL, NULL,
1955: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1956: CTLTYPE_INT, "neighborgcthresh",
1957: SYSCTL_DESCR("Maximum number of entries in neighbor"
1958: " cache"),
1959: NULL, 1, &ip6_neighborgcthresh, 0,
1960: CTL_NET, PF_INET6, IPPROTO_IPV6,
1961: CTL_CREATE, CTL_EOL);
1962: sysctl_createv(clog, 0, NULL, NULL,
1963: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1964: CTLTYPE_INT, "maxifprefixes",
1965: SYSCTL_DESCR("Maximum number of prefixes created by"
1966: " route advertisement per interface"),
1967: NULL, 1, &ip6_maxifprefixes, 0,
1968: CTL_NET, PF_INET6, IPPROTO_IPV6,
1969: CTL_CREATE, CTL_EOL);
1970: sysctl_createv(clog, 0, NULL, NULL,
1971: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1972: CTLTYPE_INT, "maxifdefrouters",
1973: SYSCTL_DESCR("Maximum number of default routers created"
1974: " by route advertisement per interface"),
1975: NULL, 1, &ip6_maxifdefrouters, 0,
1976: CTL_NET, PF_INET6, IPPROTO_IPV6,
1977: CTL_CREATE, CTL_EOL);
1978: sysctl_createv(clog, 0, NULL, NULL,
1979: CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1980: CTLTYPE_INT, "maxdynroutes",
1981: SYSCTL_DESCR("Maximum number of routes created via"
1982: " redirect"),
1983: NULL, 1, &ip6_maxdynroutes, 0,
1984: CTL_NET, PF_INET6, IPPROTO_IPV6,
1985: CTL_CREATE, CTL_EOL);
1.2 itojun 1986: }
1.116 thorpej 1987:
1988: void
1989: ip6_statinc(u_int stat)
1990: {
1991:
1992: KASSERT(stat < IP6_NSTATS);
1993: IP6_STATINC(stat);
1994: }
CVSweb <webmaster@jp.NetBSD.org>