1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * Copyright (c) 2010-2011 Juniper Networks, Inc. 6 * Copyright (c) 2014 Kevin Lo 7 * All rights reserved. 8 * 9 * Portions of this software were developed by Robert N. M. Watson under 10 * contract to Juniper Networks, Inc. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. Neither the name of the project nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * $KAME: udp6_usrreq.c,v 1.27 2001/05/21 05:45:10 jinmei Exp $ 37 * $KAME: udp6_output.c,v 1.31 2001/05/21 16:39:15 jinmei Exp $ 38 */ 39 40 /*- 41 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995 42 * The Regents of the University of California. 43 * All rights reserved. 44 * 45 * Redistribution and use in source and binary forms, with or without 46 * modification, are permitted provided that the following conditions 47 * are met: 48 * 1. Redistributions of source code must retain the above copyright 49 * notice, this list of conditions and the following disclaimer. 50 * 2. Redistributions in binary form must reproduce the above copyright 51 * notice, this list of conditions and the following disclaimer in the 52 * documentation and/or other materials provided with the distribution. 53 * 3. Neither the name of the University nor the names of its contributors 54 * may be used to endorse or promote products derived from this software 55 * without specific prior written permission. 56 * 57 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 58 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * SUCH DAMAGE. 68 */ 69 70 #include "opt_inet.h" 71 #include "opt_inet6.h" 72 #include "opt_ipsec.h" 73 #include "opt_rss.h" 74 75 #include <sys/param.h> 76 #include <sys/domain.h> 77 #include <sys/jail.h> 78 #include <sys/kernel.h> 79 #include <sys/lock.h> 80 #include <sys/mbuf.h> 81 #include <sys/priv.h> 82 #include <sys/proc.h> 83 #include <sys/protosw.h> 84 #include <sys/sdt.h> 85 #include <sys/signalvar.h> 86 #include <sys/socket.h> 87 #include <sys/socketvar.h> 88 #include <sys/sx.h> 89 #include <sys/sysctl.h> 90 #include <sys/syslog.h> 91 #include <sys/systm.h> 92 93 #include <net/if.h> 94 #include <net/if_var.h> 95 #include <net/if_types.h> 96 #include <net/route.h> 97 #include <net/rss_config.h> 98 99 #include <netinet/in.h> 100 #include <netinet/in_kdtrace.h> 101 #include <netinet/in_pcb.h> 102 #include <netinet/in_systm.h> 103 #include <netinet/in_var.h> 104 #include <netinet/ip.h> 105 #include <netinet/ip6.h> 106 #include <netinet/icmp6.h> 107 #include <netinet/ip_var.h> 108 #include <netinet/udp.h> 109 #include <netinet/udp_var.h> 110 #include <netinet/udplite.h> 111 112 #include <netinet6/ip6_var.h> 113 #include <netinet6/in6_fib.h> 114 #include <netinet6/in6_pcb.h> 115 #include <netinet6/in6_rss.h> 116 #include <netinet6/udp6_var.h> 117 #include <netinet6/scope6_var.h> 118 119 #include <netipsec/ipsec_support.h> 120 121 #include <security/mac/mac_framework.h> 122 123 VNET_DEFINE(int, zero_checksum_port) = 0; 124 #define V_zero_checksum_port VNET(zero_checksum_port) 125 SYSCTL_INT(_net_inet6_udp6, OID_AUTO, rfc6935_port, CTLFLAG_VNET | CTLFLAG_RW, 126 &VNET_NAME(zero_checksum_port), 0, 127 "Zero UDP checksum allowed for traffic to/from this port."); 128 129 /* 130 * UDP protocol implementation. 131 * Per RFC 768, August, 1980. 132 */ 133 134 static void udp6_detach(struct socket *so); 135 136 static int 137 udp6_append(struct inpcb *inp, struct mbuf *n, int off, 138 struct sockaddr_in6 *fromsa) 139 { 140 struct socket *so; 141 struct mbuf *opts = NULL, *tmp_opts; 142 struct udpcb *up; 143 144 INP_LOCK_ASSERT(inp); 145 146 /* 147 * Engage the tunneling protocol. 148 */ 149 up = intoudpcb(inp); 150 if (up->u_tun_func != NULL) { 151 bool filtered; 152 153 in_pcbref(inp); 154 INP_RUNLOCK(inp); 155 filtered = (*up->u_tun_func)(n, off, inp, 156 (struct sockaddr *)&fromsa[0], up->u_tun_ctx); 157 INP_RLOCK(inp); 158 if (in_pcbrele_rlocked(inp)) 159 return (1); 160 if (filtered) { 161 INP_RUNLOCK(inp); 162 return (1); 163 } 164 } 165 166 off += sizeof(struct udphdr); 167 168 #if defined(IPSEC) || defined(IPSEC_SUPPORT) 169 /* Check AH/ESP integrity. */ 170 if (IPSEC_ENABLED(ipv6)) { 171 if (IPSEC_CHECK_POLICY(ipv6, n, inp) != 0) { 172 m_freem(n); 173 return (0); 174 } 175 176 /* IPSec UDP encaps. */ 177 if ((up->u_flags & UF_ESPINUDP) != 0 && 178 UDPENCAP_INPUT(ipv6, n, off, AF_INET6) != 0) { 179 return (0); /* Consumed. */ 180 } 181 } 182 #endif /* IPSEC */ 183 #ifdef MAC 184 if (mac_inpcb_check_deliver(inp, n) != 0) { 185 m_freem(n); 186 return (0); 187 } 188 #endif 189 opts = NULL; 190 if (inp->inp_flags & INP_CONTROLOPTS || 191 inp->inp_socket->so_options & SO_TIMESTAMP) 192 ip6_savecontrol(inp, n, &opts); 193 if ((inp->inp_vflag & INP_IPV6) && (inp->inp_flags2 & INP_ORIGDSTADDR)) { 194 tmp_opts = sbcreatecontrol(&fromsa[1], 195 sizeof(struct sockaddr_in6), IPV6_ORIGDSTADDR, 196 IPPROTO_IPV6, M_NOWAIT); 197 if (tmp_opts) { 198 if (opts) { 199 tmp_opts->m_next = opts; 200 opts = tmp_opts; 201 } else 202 opts = tmp_opts; 203 } 204 } 205 m_adj(n, off); 206 207 so = inp->inp_socket; 208 SOCKBUF_LOCK(&so->so_rcv); 209 if (sbappendaddr_locked(&so->so_rcv, (struct sockaddr *)&fromsa[0], n, 210 opts) == 0) { 211 soroverflow_locked(so); 212 m_freem(n); 213 if (opts) 214 m_freem(opts); 215 UDPSTAT_INC(udps_fullsock); 216 } else 217 sorwakeup_locked(so); 218 return (0); 219 } 220 221 struct udp6_multi_match_ctx { 222 struct ip6_hdr *ip6; 223 struct udphdr *uh; 224 }; 225 226 static bool 227 udp6_multi_match(const struct inpcb *inp, void *v) 228 { 229 struct udp6_multi_match_ctx *ctx = v; 230 231 if ((inp->inp_vflag & INP_IPV6) == 0) 232 return(false); 233 if (inp->inp_lport != ctx->uh->uh_dport) 234 return(false); 235 if (inp->inp_fport != 0 && inp->inp_fport != ctx->uh->uh_sport) 236 return(false); 237 if (!IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr) && 238 !IN6_ARE_ADDR_EQUAL(&inp->in6p_laddr, &ctx->ip6->ip6_dst)) 239 return (false); 240 if (!IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr) && 241 (!IN6_ARE_ADDR_EQUAL(&inp->in6p_faddr, &ctx->ip6->ip6_src) || 242 inp->inp_fport != ctx->uh->uh_sport)) 243 return (false); 244 245 return (true); 246 } 247 248 static int 249 udp6_multi_input(struct mbuf *m, int off, int proto, 250 struct sockaddr_in6 *fromsa) 251 { 252 struct udp6_multi_match_ctx ctx; 253 struct inpcb_iterator inpi = INP_ITERATOR(udp_get_inpcbinfo(proto), 254 INPLOOKUP_RLOCKPCB, udp6_multi_match, &ctx); 255 struct inpcb *inp; 256 struct ip6_moptions *imo; 257 struct mbuf *n; 258 int appends = 0; 259 260 /* 261 * In the event that laddr should be set to the link-local 262 * address (this happens in RIPng), the multicast address 263 * specified in the received packet will not match laddr. To 264 * handle this situation, matching is relaxed if the 265 * receiving interface is the same as one specified in the 266 * socket and if the destination multicast address matches 267 * one of the multicast groups specified in the socket. 268 */ 269 270 /* 271 * KAME note: traditionally we dropped udpiphdr from mbuf 272 * here. We need udphdr for IPsec processing so we do that 273 * later. 274 */ 275 ctx.ip6 = mtod(m, struct ip6_hdr *); 276 ctx.uh = (struct udphdr *)((char *)ctx.ip6 + off); 277 while ((inp = inp_next(&inpi)) != NULL) { 278 INP_RLOCK_ASSERT(inp); 279 /* 280 * XXXRW: Because we weren't holding either the inpcb 281 * or the hash lock when we checked for a match 282 * before, we should probably recheck now that the 283 * inpcb lock is (supposed to be) held. 284 */ 285 /* 286 * Handle socket delivery policy for any-source 287 * and source-specific multicast. [RFC3678] 288 */ 289 if ((imo = inp->in6p_moptions) != NULL) { 290 struct sockaddr_in6 mcaddr; 291 int blocked; 292 293 bzero(&mcaddr, sizeof(struct sockaddr_in6)); 294 mcaddr.sin6_len = sizeof(struct sockaddr_in6); 295 mcaddr.sin6_family = AF_INET6; 296 mcaddr.sin6_addr = ctx.ip6->ip6_dst; 297 298 blocked = im6o_mc_filter(imo, m->m_pkthdr.rcvif, 299 (struct sockaddr *)&mcaddr, 300 (struct sockaddr *)&fromsa[0]); 301 if (blocked != MCAST_PASS) { 302 if (blocked == MCAST_NOTGMEMBER) 303 IP6STAT_INC(ip6s_notmember); 304 if (blocked == MCAST_NOTSMEMBER || 305 blocked == MCAST_MUTED) 306 UDPSTAT_INC(udps_filtermcast); 307 continue; 308 } 309 } 310 if ((n = m_copym(m, 0, M_COPYALL, M_NOWAIT)) != NULL) { 311 if (proto == IPPROTO_UDPLITE) 312 UDPLITE_PROBE(receive, NULL, inp, ctx.ip6, 313 inp, ctx.uh); 314 else 315 UDP_PROBE(receive, NULL, inp, ctx.ip6, inp, 316 ctx.uh); 317 if (udp6_append(inp, n, off, fromsa)) { 318 break; 319 } else 320 appends++; 321 } 322 /* 323 * Don't look for additional matches if this one does 324 * not have either the SO_REUSEPORT or SO_REUSEADDR 325 * socket options set. This heuristic avoids 326 * searching through all pcbs in the common case of a 327 * non-shared port. It assumes that an application 328 * will never clear these options after setting them. 329 */ 330 if ((inp->inp_socket->so_options & 331 (SO_REUSEPORT|SO_REUSEPORT_LB|SO_REUSEADDR)) == 0) { 332 INP_RUNLOCK(inp); 333 break; 334 } 335 } 336 m_freem(m); 337 338 if (appends == 0) { 339 /* 340 * No matching pcb found; discard datagram. (No need 341 * to send an ICMP Port Unreachable for a broadcast 342 * or multicast datagram.) 343 */ 344 UDPSTAT_INC(udps_noport); 345 UDPSTAT_INC(udps_noportmcast); 346 } 347 348 return (IPPROTO_DONE); 349 } 350 351 int 352 udp6_input(struct mbuf **mp, int *offp, int proto) 353 { 354 struct mbuf *m = *mp; 355 struct ip6_hdr *ip6; 356 struct udphdr *uh; 357 struct inpcb *inp; 358 struct inpcbinfo *pcbinfo; 359 struct udpcb *up; 360 int off = *offp; 361 int cscov_partial; 362 int plen, ulen; 363 int lookupflags; 364 struct sockaddr_in6 fromsa[2]; 365 struct m_tag *fwd_tag; 366 uint16_t uh_sum; 367 uint8_t nxt; 368 369 NET_EPOCH_ASSERT(); 370 371 if (m->m_len < off + sizeof(struct udphdr)) { 372 m = m_pullup(m, off + sizeof(struct udphdr)); 373 if (m == NULL) { 374 IP6STAT_INC(ip6s_exthdrtoolong); 375 *mp = NULL; 376 return (IPPROTO_DONE); 377 } 378 } 379 ip6 = mtod(m, struct ip6_hdr *); 380 uh = (struct udphdr *)((caddr_t)ip6 + off); 381 382 UDPSTAT_INC(udps_ipackets); 383 384 /* 385 * Destination port of 0 is illegal, based on RFC768. 386 */ 387 if (uh->uh_dport == 0) 388 goto badunlocked; 389 390 plen = ntohs(ip6->ip6_plen) - off + sizeof(*ip6); 391 ulen = ntohs((u_short)uh->uh_ulen); 392 393 nxt = proto; 394 cscov_partial = (nxt == IPPROTO_UDPLITE) ? 1 : 0; 395 if (nxt == IPPROTO_UDPLITE) { 396 /* Zero means checksum over the complete packet. */ 397 if (ulen == 0) 398 ulen = plen; 399 if (ulen == plen) 400 cscov_partial = 0; 401 if ((ulen < sizeof(struct udphdr)) || (ulen > plen)) { 402 /* XXX: What is the right UDPLite MIB counter? */ 403 goto badunlocked; 404 } 405 if (uh->uh_sum == 0) { 406 /* XXX: What is the right UDPLite MIB counter? */ 407 goto badunlocked; 408 } 409 } else { 410 if ((ulen < sizeof(struct udphdr)) || (plen != ulen)) { 411 UDPSTAT_INC(udps_badlen); 412 goto badunlocked; 413 } 414 if (uh->uh_sum == 0) { 415 UDPSTAT_INC(udps_nosum); 416 /* 417 * dport 0 was rejected earlier so this is OK even if 418 * zero_checksum_port is 0 (which is its default value). 419 */ 420 if (ntohs(uh->uh_dport) == V_zero_checksum_port) 421 goto skip_checksum; 422 else 423 goto badunlocked; 424 } 425 } 426 427 if ((m->m_pkthdr.csum_flags & CSUM_DATA_VALID_IPV6) && 428 !cscov_partial) { 429 if (m->m_pkthdr.csum_flags & CSUM_PSEUDO_HDR) 430 uh_sum = m->m_pkthdr.csum_data; 431 else 432 uh_sum = in6_cksum_pseudo(ip6, ulen, nxt, 433 m->m_pkthdr.csum_data); 434 uh_sum ^= 0xffff; 435 } else if (m->m_pkthdr.csum_flags & CSUM_IP6_UDP) { 436 /* 437 * Packet from local host (maybe from a VM). 438 * Checksum not required. 439 */ 440 uh_sum = 0; 441 } else 442 uh_sum = in6_cksum_partial(m, nxt, off, plen, ulen); 443 444 if (uh_sum != 0) { 445 UDPSTAT_INC(udps_badsum); 446 goto badunlocked; 447 } 448 449 skip_checksum: 450 /* 451 * Construct sockaddr format source address. 452 */ 453 init_sin6(&fromsa[0], m, 0); 454 fromsa[0].sin6_port = uh->uh_sport; 455 init_sin6(&fromsa[1], m, 1); 456 fromsa[1].sin6_port = uh->uh_dport; 457 458 pcbinfo = udp_get_inpcbinfo(nxt); 459 if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { 460 *mp = NULL; 461 return (udp6_multi_input(m, off, proto, fromsa)); 462 } 463 464 /* 465 * Locate pcb for datagram. 466 */ 467 lookupflags = INPLOOKUP_RLOCKPCB | 468 (V_udp_bind_all_fibs ? 0 : INPLOOKUP_FIB); 469 470 /* 471 * Grab info from PACKET_TAG_IPFORWARD tag prepended to the chain. 472 */ 473 if ((m->m_flags & M_IP6_NEXTHOP) && 474 (fwd_tag = m_tag_find(m, PACKET_TAG_IPFORWARD, NULL)) != NULL) { 475 struct sockaddr_in6 *next_hop6; 476 477 next_hop6 = (struct sockaddr_in6 *)(fwd_tag + 1); 478 479 /* 480 * Transparently forwarded. Pretend to be the destination. 481 * Already got one like this? 482 */ 483 inp = in6_pcblookup_mbuf(pcbinfo, &ip6->ip6_src, 484 uh->uh_sport, &ip6->ip6_dst, uh->uh_dport, 485 lookupflags, m->m_pkthdr.rcvif, m); 486 if (!inp) { 487 /* 488 * It's new. Try to find the ambushing socket. 489 * Because we've rewritten the destination address, 490 * any hardware-generated hash is ignored. 491 */ 492 inp = in6_pcblookup(pcbinfo, &ip6->ip6_src, 493 uh->uh_sport, &next_hop6->sin6_addr, 494 next_hop6->sin6_port ? htons(next_hop6->sin6_port) : 495 uh->uh_dport, INPLOOKUP_WILDCARD | lookupflags, 496 m->m_pkthdr.rcvif); 497 } 498 /* Remove the tag from the packet. We don't need it anymore. */ 499 m_tag_delete(m, fwd_tag); 500 m->m_flags &= ~M_IP6_NEXTHOP; 501 } else 502 inp = in6_pcblookup_mbuf(pcbinfo, &ip6->ip6_src, 503 uh->uh_sport, &ip6->ip6_dst, uh->uh_dport, 504 INPLOOKUP_WILDCARD | lookupflags, 505 m->m_pkthdr.rcvif, m); 506 if (inp == NULL) { 507 if (V_udp_log_in_vain) { 508 char ip6bufs[INET6_ADDRSTRLEN]; 509 char ip6bufd[INET6_ADDRSTRLEN]; 510 511 log(LOG_INFO, 512 "Connection attempt to UDP [%s]:%d from [%s]:%d\n", 513 ip6_sprintf(ip6bufd, &ip6->ip6_dst), 514 ntohs(uh->uh_dport), 515 ip6_sprintf(ip6bufs, &ip6->ip6_src), 516 ntohs(uh->uh_sport)); 517 } 518 if (nxt == IPPROTO_UDPLITE) 519 UDPLITE_PROBE(receive, NULL, NULL, ip6, NULL, uh); 520 else 521 UDP_PROBE(receive, NULL, NULL, ip6, NULL, uh); 522 UDPSTAT_INC(udps_noport); 523 if (m->m_flags & M_MCAST) { 524 printf("UDP6: M_MCAST is set in a unicast packet.\n"); 525 UDPSTAT_INC(udps_noportmcast); 526 goto badunlocked; 527 } 528 if (V_udp_blackhole && (V_udp_blackhole_local || 529 !in6_localip(&ip6->ip6_src))) 530 goto badunlocked; 531 icmp6_error(m, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOPORT, 0); 532 *mp = NULL; 533 return (IPPROTO_DONE); 534 } 535 INP_RLOCK_ASSERT(inp); 536 up = intoudpcb(inp); 537 if (cscov_partial) { 538 if (up->u_rxcslen == 0 || up->u_rxcslen > ulen) { 539 INP_RUNLOCK(inp); 540 m_freem(m); 541 *mp = NULL; 542 return (IPPROTO_DONE); 543 } 544 } 545 if (nxt == IPPROTO_UDPLITE) 546 UDPLITE_PROBE(receive, NULL, inp, ip6, inp, uh); 547 else 548 UDP_PROBE(receive, NULL, inp, ip6, inp, uh); 549 if (udp6_append(inp, m, off, fromsa) == 0) 550 INP_RUNLOCK(inp); 551 *mp = NULL; 552 return (IPPROTO_DONE); 553 554 badunlocked: 555 m_freem(m); 556 *mp = NULL; 557 return (IPPROTO_DONE); 558 } 559 560 static void 561 udp6_common_ctlinput(struct ip6ctlparam *ip6cp, struct inpcbinfo *pcbinfo) 562 { 563 struct udphdr uh; 564 struct ip6_hdr *ip6; 565 struct mbuf *m; 566 struct inpcb *inp; 567 int errno, off = 0; 568 struct udp_portonly { 569 u_int16_t uh_sport; 570 u_int16_t uh_dport; 571 } *uhp; 572 573 if ((errno = icmp6_errmap(ip6cp->ip6c_icmp6)) == 0) 574 return; 575 576 m = ip6cp->ip6c_m; 577 ip6 = ip6cp->ip6c_ip6; 578 off = ip6cp->ip6c_off; 579 580 /* Check if we can safely examine src and dst ports. */ 581 if (m->m_pkthdr.len < off + sizeof(*uhp)) 582 return; 583 584 bzero(&uh, sizeof(uh)); 585 m_copydata(m, off, sizeof(*uhp), (caddr_t)&uh); 586 587 /* Check to see if its tunneled */ 588 inp = in6_pcblookup_mbuf(pcbinfo, &ip6->ip6_dst, uh.uh_dport, 589 &ip6->ip6_src, uh.uh_sport, INPLOOKUP_WILDCARD | INPLOOKUP_RLOCKPCB, 590 m->m_pkthdr.rcvif, m); 591 if (inp != NULL) { 592 struct udpcb *up; 593 udp_tun_icmp_t *func; 594 595 up = intoudpcb(inp); 596 func = up->u_icmp_func; 597 INP_RUNLOCK(inp); 598 if (func != NULL) 599 func(ip6cp); 600 } 601 in6_pcbnotify(pcbinfo, ip6cp->ip6c_finaldst, uh.uh_dport, 602 ip6cp->ip6c_src, uh.uh_sport, errno, ip6cp->ip6c_cmdarg, 603 udp_notify); 604 } 605 606 static void 607 udp6_ctlinput(struct ip6ctlparam *ctl) 608 { 609 610 return (udp6_common_ctlinput(ctl, &V_udbinfo)); 611 } 612 613 static void 614 udplite6_ctlinput(struct ip6ctlparam *ctl) 615 { 616 617 return (udp6_common_ctlinput(ctl, &V_ulitecbinfo)); 618 } 619 620 static int 621 udp6_getcred(SYSCTL_HANDLER_ARGS) 622 { 623 struct xucred xuc; 624 struct sockaddr_in6 addrs[2]; 625 struct epoch_tracker et; 626 struct inpcb *inp; 627 int error; 628 629 if (req->newptr == NULL) 630 return (EINVAL); 631 error = priv_check(req->td, PRIV_NETINET_GETCRED); 632 if (error) 633 return (error); 634 635 if (req->newlen != sizeof(addrs)) 636 return (EINVAL); 637 if (req->oldlen != sizeof(struct xucred)) 638 return (EINVAL); 639 error = SYSCTL_IN(req, addrs, sizeof(addrs)); 640 if (error) 641 return (error); 642 if ((error = sa6_embedscope(&addrs[0], V_ip6_use_defzone)) != 0 || 643 (error = sa6_embedscope(&addrs[1], V_ip6_use_defzone)) != 0) { 644 return (error); 645 } 646 NET_EPOCH_ENTER(et); 647 inp = in6_pcblookup(&V_udbinfo, &addrs[1].sin6_addr, 648 addrs[1].sin6_port, &addrs[0].sin6_addr, addrs[0].sin6_port, 649 INPLOOKUP_WILDCARD | INPLOOKUP_RLOCKPCB, NULL); 650 NET_EPOCH_EXIT(et); 651 if (inp != NULL) { 652 INP_RLOCK_ASSERT(inp); 653 if (inp->inp_socket == NULL) 654 error = ENOENT; 655 if (error == 0) 656 error = cr_canseesocket(req->td->td_ucred, 657 inp->inp_socket); 658 if (error == 0) 659 cru2x(inp->inp_cred, &xuc); 660 INP_RUNLOCK(inp); 661 } else 662 error = ENOENT; 663 if (error == 0) 664 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred)); 665 return (error); 666 } 667 668 SYSCTL_PROC(_net_inet6_udp6, OID_AUTO, getcred, 669 CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_MPSAFE, 670 0, 0, udp6_getcred, "S,xucred", 671 "Get the xucred of a UDP6 connection"); 672 673 static int 674 udp6_send(struct socket *so, int flags_arg, struct mbuf *m, 675 struct sockaddr *addr6, struct mbuf *control, struct thread *td) 676 { 677 struct inpcb *inp; 678 struct ip6_hdr *ip6; 679 struct udphdr *udp6; 680 struct in6_addr *laddr, *faddr, in6a; 681 struct ip6_pktopts *optp, opt; 682 struct sockaddr_in6 *sin6, tmp; 683 struct epoch_tracker et; 684 int cscov_partial, error, flags, hlen, scope_ambiguous; 685 u_int32_t ulen, plen; 686 uint16_t cscov; 687 u_short fport; 688 uint8_t nxt; 689 690 if (addr6) { 691 error = 0; 692 if (addr6->sa_family != AF_INET6) 693 error = EAFNOSUPPORT; 694 else if (addr6->sa_len != sizeof(struct sockaddr_in6)) 695 error = EINVAL; 696 if (__predict_false(error != 0)) { 697 m_freem(control); 698 m_freem(m); 699 return (error); 700 } 701 } 702 703 sin6 = (struct sockaddr_in6 *)addr6; 704 705 scope_ambiguous = 0; 706 if (sin6) { 707 /* Protect *addr6 from overwrites. */ 708 tmp = *sin6; 709 sin6 = &tmp; 710 711 /* 712 * Application should provide a proper zone ID or the use of 713 * default zone IDs should be enabled. Unfortunately, some 714 * applications do not behave as it should, so we need a 715 * workaround. Even if an appropriate ID is not determined, 716 * we'll see if we can determine the outgoing interface. If we 717 * can, determine the zone ID based on the interface below. 718 */ 719 if (sin6->sin6_scope_id == 0 && !V_ip6_use_defzone) 720 scope_ambiguous = 1; 721 if ((error = sa6_embedscope(sin6, V_ip6_use_defzone)) != 0) { 722 if (control) 723 m_freem(control); 724 m_freem(m); 725 return (error); 726 } 727 } 728 729 inp = sotoinpcb(so); 730 KASSERT(inp != NULL, ("%s: inp == NULL", __func__)); 731 /* 732 * In the following cases we want a write lock on the inp for either 733 * local operations or for possible route cache updates in the IPv6 734 * output path: 735 * - on connected sockets (sin6 is NULL) for route cache updates, 736 * - when we are not bound to an address and source port (it is 737 * in6_pcbsetport() which will require the write lock). 738 * 739 * We check the inp fields before actually locking the inp, so 740 * here exists a race, and we may WLOCK the inp and end with already 741 * bound one by other thread. This is fine. 742 */ 743 if (sin6 == NULL || (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr) && 744 inp->inp_lport == 0)) 745 INP_WLOCK(inp); 746 else 747 INP_RLOCK(inp); 748 749 nxt = (inp->inp_socket->so_proto->pr_protocol == IPPROTO_UDP) ? 750 IPPROTO_UDP : IPPROTO_UDPLITE; 751 752 #ifdef INET 753 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) { 754 int hasv4addr; 755 756 if (sin6 == NULL) 757 hasv4addr = (inp->inp_vflag & INP_IPV4); 758 else 759 hasv4addr = IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr) 760 ? 1 : 0; 761 if (hasv4addr) { 762 /* 763 * XXXRW: We release UDP-layer locks before calling 764 * udp_send() in order to avoid recursion. However, 765 * this does mean there is a short window where inp's 766 * fields are unstable. Could this lead to a 767 * potential race in which the factors causing us to 768 * select the UDPv4 output routine are invalidated? 769 */ 770 INP_UNLOCK(inp); 771 if (sin6) 772 in6_sin6_2_sin_in_sock((struct sockaddr *)sin6); 773 /* addr will just be freed in sendit(). */ 774 return (udp_send(so, flags_arg | PRUS_IPV6, m, 775 (struct sockaddr *)sin6, control, td)); 776 } 777 } else 778 #endif 779 if (sin6 && IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { 780 /* 781 * Given this is either an IPv6-only socket or no INET is 782 * supported we will fail the send if the given destination 783 * address is a v4mapped address. 784 */ 785 INP_UNLOCK(inp); 786 m_freem(m); 787 m_freem(control); 788 return (EINVAL); 789 } 790 791 NET_EPOCH_ENTER(et); 792 if (control) { 793 if ((error = ip6_setpktopts(control, &opt, 794 inp->in6p_outputopts, td->td_ucred, nxt)) != 0) { 795 goto release; 796 } 797 optp = &opt; 798 } else 799 optp = inp->in6p_outputopts; 800 801 if (sin6) { 802 /* 803 * Since we saw no essential reason for calling in_pcbconnect, 804 * we get rid of such kind of logic, and call in6_selectsrc 805 * and in6_pcbsetport in order to fill in the local address 806 * and the local port. 807 */ 808 if (sin6->sin6_port == 0) { 809 error = EADDRNOTAVAIL; 810 goto release; 811 } 812 813 if (!IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) { 814 /* how about ::ffff:0.0.0.0 case? */ 815 error = EISCONN; 816 goto release; 817 } 818 819 /* 820 * Given we handle the v4mapped case in the INET block above 821 * assert here that it must not happen anymore. 822 */ 823 KASSERT(!IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr), 824 ("%s: sin6(%p)->sin6_addr is v4mapped which we " 825 "should have handled.", __func__, sin6)); 826 827 error = prison_remote_ip6(td->td_ucred, &sin6->sin6_addr); 828 if (error != 0) 829 goto release; 830 831 /* This only requires read-locking. */ 832 error = in6_selectsrc_socket(sin6, optp, inp, 833 td->td_ucred, scope_ambiguous, &in6a, NULL); 834 if (error) 835 goto release; 836 laddr = &in6a; 837 838 if (inp->inp_lport == 0) { 839 INP_WLOCK_ASSERT(inp); 840 841 error = in6_pcbsetport(laddr, inp, td->td_ucred); 842 if (error != 0) { 843 /* Undo an address bind that may have occurred. */ 844 inp->in6p_laddr = in6addr_any; 845 goto release; 846 } 847 } 848 faddr = &sin6->sin6_addr; 849 fport = sin6->sin6_port; /* allow 0 port */ 850 851 } else { 852 if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) { 853 error = ENOTCONN; 854 goto release; 855 } 856 laddr = &inp->in6p_laddr; 857 faddr = &inp->in6p_faddr; 858 fport = inp->inp_fport; 859 } 860 861 862 /* 863 * We do not support IPv6 Jumbograms (RFC2675), so validate the payload 864 * length fits in a normal gram. 865 */ 866 ulen = m->m_pkthdr.len; 867 plen = sizeof(struct udphdr) + ulen; 868 hlen = sizeof(struct ip6_hdr); 869 if (plen > IPV6_MAXPAYLOAD) { 870 error = EMSGSIZE; 871 goto release; 872 } 873 874 /* 875 * Calculate data length and get a mbuf for UDP, IP6, and possible 876 * link-layer headers. Immediate slide the data pointer back forward 877 * since we won't use that space at this layer. 878 */ 879 M_PREPEND(m, hlen + sizeof(struct udphdr) + max_linkhdr, M_NOWAIT); 880 if (m == NULL) { 881 error = ENOBUFS; 882 goto release; 883 } 884 m->m_data += max_linkhdr; 885 m->m_len -= max_linkhdr; 886 m->m_pkthdr.len -= max_linkhdr; 887 888 /* 889 * Stuff checksum and output datagram. 890 */ 891 cscov = cscov_partial = 0; 892 udp6 = (struct udphdr *)(mtod(m, caddr_t) + hlen); 893 udp6->uh_sport = inp->inp_lport; /* lport is always set in the PCB */ 894 udp6->uh_dport = fport; 895 if (nxt == IPPROTO_UDPLITE) { 896 struct udpcb *up; 897 898 up = intoudpcb(inp); 899 cscov = up->u_txcslen; 900 if (cscov >= plen) 901 cscov = 0; 902 udp6->uh_ulen = htons(cscov); 903 /* 904 * For UDP-Lite, checksum coverage length of zero means 905 * the entire UDPLite packet is covered by the checksum. 906 */ 907 cscov_partial = (cscov == 0) ? 0 : 1; 908 } else { 909 MPASS(plen <= IPV6_MAXPAYLOAD); 910 udp6->uh_ulen = htons((u_short)plen); 911 } 912 udp6->uh_sum = 0; 913 914 ip6 = mtod(m, struct ip6_hdr *); 915 ip6->ip6_flow = inp->inp_flow & IPV6_FLOWINFO_MASK; 916 ip6->ip6_vfc &= ~IPV6_VERSION_MASK; 917 ip6->ip6_vfc |= IPV6_VERSION; 918 ip6->ip6_plen = htons((u_short)plen); 919 ip6->ip6_nxt = nxt; 920 ip6->ip6_hlim = in6_selecthlim(inp, NULL); 921 ip6->ip6_src = *laddr; 922 ip6->ip6_dst = *faddr; 923 924 #ifdef MAC 925 mac_inpcb_create_mbuf(inp, m); 926 #endif 927 928 if (cscov_partial) { 929 if ((udp6->uh_sum = in6_cksum_partial(m, nxt, 930 sizeof(struct ip6_hdr), plen, cscov)) == 0) 931 udp6->uh_sum = 0xffff; 932 } else { 933 udp6->uh_sum = in6_cksum_pseudo(ip6, plen, nxt, 0); 934 m->m_pkthdr.csum_flags = CSUM_UDP_IPV6; 935 m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum); 936 } 937 938 flags = 0; 939 if (CALC_FLOWID_OUTBOUND_SENDTO) { 940 uint32_t hash_type, hash_val; 941 uint8_t pr; 942 943 pr = inp->inp_socket->so_proto->pr_protocol; 944 945 hash_val = fib6_calc_packet_hash(laddr, faddr, 946 inp->inp_lport, fport, pr, &hash_type); 947 m->m_pkthdr.flowid = hash_val; 948 M_HASHTYPE_SET(m, hash_type); 949 } 950 /* do not use inp flowid */ 951 flags |= IP_NODEFAULTFLOWID; 952 953 UDPSTAT_INC(udps_opackets); 954 if (nxt == IPPROTO_UDPLITE) 955 UDPLITE_PROBE(send, NULL, inp, ip6, inp, udp6); 956 else 957 UDP_PROBE(send, NULL, inp, ip6, inp, udp6); 958 error = ip6_output(m, optp, 959 INP_WLOCKED(inp) ? &inp->inp_route6 : NULL, flags, 960 inp->in6p_moptions, NULL, inp); 961 INP_UNLOCK(inp); 962 NET_EPOCH_EXIT(et); 963 964 if (control) { 965 ip6_clearpktopts(&opt, -1); 966 m_freem(control); 967 } 968 return (error); 969 970 release: 971 INP_UNLOCK(inp); 972 NET_EPOCH_EXIT(et); 973 if (control) { 974 ip6_clearpktopts(&opt, -1); 975 m_freem(control); 976 } 977 m_freem(m); 978 979 return (error); 980 } 981 982 static void 983 udp6_abort(struct socket *so) 984 { 985 struct inpcb *inp; 986 987 inp = sotoinpcb(so); 988 KASSERT(inp != NULL, ("udp6_abort: inp == NULL")); 989 990 INP_WLOCK(inp); 991 #ifdef INET 992 if (inp->inp_vflag & INP_IPV4) { 993 INP_WUNLOCK(inp); 994 udp_abort(so); 995 return; 996 } 997 #endif 998 999 if (!IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) { 1000 in6_pcbdisconnect(inp); 1001 memset(&inp->in6p_laddr, 0, sizeof(inp->in6p_laddr)); 1002 soisdisconnected(so); 1003 } 1004 INP_WUNLOCK(inp); 1005 } 1006 1007 static int 1008 udp6_attach(struct socket *so, int proto, struct thread *td) 1009 { 1010 struct inpcbinfo *pcbinfo; 1011 struct inpcb *inp; 1012 struct udpcb *up; 1013 int error; 1014 1015 pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol); 1016 inp = sotoinpcb(so); 1017 KASSERT(inp == NULL, ("udp6_attach: inp != NULL")); 1018 1019 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { 1020 error = soreserve(so, udp_sendspace, udp_recvspace); 1021 if (error) 1022 return (error); 1023 } 1024 error = in_pcballoc(so, pcbinfo); 1025 if (error) 1026 return (error); 1027 inp = (struct inpcb *)so->so_pcb; 1028 inp->in6p_cksum = -1; /* just to be sure */ 1029 /* 1030 * XXX: ugly!! 1031 * IPv4 TTL initialization is necessary for an IPv6 socket as well, 1032 * because the socket may be bound to an IPv6 wildcard address, 1033 * which may match an IPv4-mapped IPv6 address. 1034 */ 1035 inp->inp_ip_ttl = V_ip_defttl; 1036 up = intoudpcb(inp); 1037 bzero(&up->u_start_zero, u_zero_size); 1038 INP_WUNLOCK(inp); 1039 return (0); 1040 } 1041 1042 static int 1043 udp6_bind(struct socket *so, struct sockaddr *nam, struct thread *td) 1044 { 1045 struct sockaddr_in6 *sin6_p; 1046 struct inpcb *inp; 1047 int error; 1048 u_char vflagsav; 1049 1050 inp = sotoinpcb(so); 1051 KASSERT(inp != NULL, ("udp6_bind: inp == NULL")); 1052 1053 if (nam->sa_family != AF_INET6) 1054 return (EAFNOSUPPORT); 1055 if (nam->sa_len != sizeof(struct sockaddr_in6)) 1056 return (EINVAL); 1057 1058 sin6_p = (struct sockaddr_in6 *)nam; 1059 1060 INP_WLOCK(inp); 1061 vflagsav = inp->inp_vflag; 1062 inp->inp_vflag &= ~INP_IPV4; 1063 inp->inp_vflag |= INP_IPV6; 1064 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) { 1065 if (IN6_IS_ADDR_UNSPECIFIED(&sin6_p->sin6_addr)) 1066 inp->inp_vflag |= INP_IPV4; 1067 #ifdef INET 1068 else if (IN6_IS_ADDR_V4MAPPED(&sin6_p->sin6_addr)) { 1069 struct sockaddr_in sin; 1070 1071 in6_sin6_2_sin(&sin, sin6_p); 1072 inp->inp_vflag |= INP_IPV4; 1073 inp->inp_vflag &= ~INP_IPV6; 1074 error = in_pcbbind(inp, &sin, 1075 V_udp_bind_all_fibs ? 0 : INPBIND_FIB, 1076 td->td_ucred); 1077 goto out; 1078 } 1079 #endif 1080 } 1081 1082 error = in6_pcbbind(inp, sin6_p, V_udp_bind_all_fibs ? 0 : INPBIND_FIB, 1083 td->td_ucred); 1084 #ifdef INET 1085 out: 1086 #endif 1087 if (error != 0) 1088 inp->inp_vflag = vflagsav; 1089 INP_WUNLOCK(inp); 1090 return (error); 1091 } 1092 1093 static void 1094 udp6_close(struct socket *so) 1095 { 1096 struct inpcb *inp; 1097 1098 inp = sotoinpcb(so); 1099 KASSERT(inp != NULL, ("udp6_close: inp == NULL")); 1100 1101 INP_WLOCK(inp); 1102 #ifdef INET 1103 if (inp->inp_vflag & INP_IPV4) { 1104 INP_WUNLOCK(inp); 1105 (void)udp_disconnect(so); 1106 return; 1107 } 1108 #endif 1109 if (!IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) { 1110 in6_pcbdisconnect(inp); 1111 memset(&inp->in6p_laddr, 0, sizeof(inp->in6p_laddr)); 1112 soisdisconnected(so); 1113 } 1114 INP_WUNLOCK(inp); 1115 } 1116 1117 static int 1118 udp6_connect(struct socket *so, struct sockaddr *nam, struct thread *td) 1119 { 1120 struct epoch_tracker et; 1121 struct inpcb *inp; 1122 struct sockaddr_in6 *sin6; 1123 int error; 1124 u_char vflagsav; 1125 1126 inp = sotoinpcb(so); 1127 KASSERT(inp != NULL, ("udp6_connect: inp == NULL")); 1128 1129 sin6 = (struct sockaddr_in6 *)nam; 1130 if (sin6->sin6_family != AF_INET6) 1131 return (EAFNOSUPPORT); 1132 if (sin6->sin6_len != sizeof(*sin6)) 1133 return (EINVAL); 1134 1135 /* 1136 * XXXRW: Need to clarify locking of v4/v6 flags. 1137 */ 1138 INP_WLOCK(inp); 1139 #ifdef INET 1140 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { 1141 struct sockaddr_in sin; 1142 1143 if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) { 1144 error = EINVAL; 1145 goto out; 1146 } 1147 if ((inp->inp_vflag & INP_IPV4) == 0) { 1148 error = EAFNOSUPPORT; 1149 goto out; 1150 } 1151 if (inp->inp_faddr.s_addr != INADDR_ANY) { 1152 error = EISCONN; 1153 goto out; 1154 } 1155 in6_sin6_2_sin(&sin, sin6); 1156 error = prison_remote_ip4(td->td_ucred, &sin.sin_addr); 1157 if (error != 0) 1158 goto out; 1159 vflagsav = inp->inp_vflag; 1160 inp->inp_vflag |= INP_IPV4; 1161 inp->inp_vflag &= ~INP_IPV6; 1162 NET_EPOCH_ENTER(et); 1163 error = in_pcbconnect(inp, &sin, td->td_ucred); 1164 NET_EPOCH_EXIT(et); 1165 /* 1166 * If connect succeeds, mark socket as connected. If 1167 * connect fails and socket is unbound, reset inp_vflag 1168 * field. 1169 */ 1170 if (error == 0) 1171 soisconnected(so); 1172 else if (inp->inp_laddr.s_addr == INADDR_ANY && 1173 inp->inp_lport == 0) 1174 inp->inp_vflag = vflagsav; 1175 goto out; 1176 } else { 1177 if ((inp->inp_vflag & INP_IPV6) == 0) { 1178 error = EAFNOSUPPORT; 1179 goto out; 1180 } 1181 } 1182 #endif 1183 if (!IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) { 1184 error = EISCONN; 1185 goto out; 1186 } 1187 error = prison_remote_ip6(td->td_ucred, &sin6->sin6_addr); 1188 if (error != 0) 1189 goto out; 1190 vflagsav = inp->inp_vflag; 1191 inp->inp_vflag &= ~INP_IPV4; 1192 inp->inp_vflag |= INP_IPV6; 1193 NET_EPOCH_ENTER(et); 1194 error = in6_pcbconnect(inp, sin6, td->td_ucred, true); 1195 NET_EPOCH_EXIT(et); 1196 /* 1197 * If connect succeeds, mark socket as connected. If 1198 * connect fails and socket is unbound, reset inp_vflag 1199 * field. 1200 */ 1201 if (error == 0) 1202 soisconnected(so); 1203 else if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr) && 1204 inp->inp_lport == 0) 1205 inp->inp_vflag = vflagsav; 1206 out: 1207 INP_WUNLOCK(inp); 1208 return (error); 1209 } 1210 1211 static void 1212 udp6_detach(struct socket *so) 1213 { 1214 struct inpcb *inp; 1215 1216 inp = sotoinpcb(so); 1217 KASSERT(inp != NULL, ("udp6_detach: inp == NULL")); 1218 1219 INP_WLOCK(inp); 1220 in_pcbfree(inp); 1221 } 1222 1223 static int 1224 udp6_disconnect(struct socket *so) 1225 { 1226 struct inpcb *inp; 1227 1228 inp = sotoinpcb(so); 1229 KASSERT(inp != NULL, ("udp6_disconnect: inp == NULL")); 1230 1231 INP_WLOCK(inp); 1232 #ifdef INET 1233 if (inp->inp_vflag & INP_IPV4) { 1234 INP_WUNLOCK(inp); 1235 (void)udp_disconnect(so); 1236 return (0); 1237 } 1238 #endif 1239 1240 if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) { 1241 INP_WUNLOCK(inp); 1242 return (ENOTCONN); 1243 } 1244 1245 in6_pcbdisconnect(inp); 1246 memset(&inp->in6p_laddr, 0, sizeof(inp->in6p_laddr)); 1247 SOCK_LOCK(so); 1248 so->so_state &= ~SS_ISCONNECTED; /* XXX */ 1249 SOCK_UNLOCK(so); 1250 INP_WUNLOCK(inp); 1251 return (0); 1252 } 1253 1254 #define UDP6_PROTOSW \ 1255 .pr_type = SOCK_DGRAM, \ 1256 .pr_flags = PR_ATOMIC|PR_ADDR|PR_CAPATTACH, \ 1257 .pr_ctloutput = udp_ctloutput, \ 1258 .pr_abort = udp6_abort, \ 1259 .pr_attach = udp6_attach, \ 1260 .pr_bind = udp6_bind, \ 1261 .pr_connect = udp6_connect, \ 1262 .pr_control = in6_control, \ 1263 .pr_detach = udp6_detach, \ 1264 .pr_disconnect = udp6_disconnect, \ 1265 .pr_peeraddr = in6_mapped_peeraddr, \ 1266 .pr_send = udp6_send, \ 1267 .pr_shutdown = udp_shutdown, \ 1268 .pr_sockaddr = in6_mapped_sockaddr, \ 1269 .pr_soreceive = soreceive_dgram, \ 1270 .pr_sosend = sosend_dgram, \ 1271 .pr_sosetlabel = in_pcbsosetlabel, \ 1272 .pr_close = udp6_close 1273 1274 struct protosw udp6_protosw = { 1275 .pr_protocol = IPPROTO_UDP, 1276 UDP6_PROTOSW 1277 }; 1278 1279 struct protosw udplite6_protosw = { 1280 .pr_protocol = IPPROTO_UDPLITE, 1281 UDP6_PROTOSW 1282 }; 1283 1284 static void 1285 udp6_init(void *arg __unused) 1286 { 1287 1288 IP6PROTO_REGISTER(IPPROTO_UDP, udp6_input, udp6_ctlinput); 1289 IP6PROTO_REGISTER(IPPROTO_UDPLITE, udp6_input, udplite6_ctlinput); 1290 } 1291 SYSINIT(udp6_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, udp6_init, NULL); 1292