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