sctp6_usrreq.c revision 166086
1/*- 2 * Copyright (c) 2001-2006, Cisco Systems, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * 7 * a) Redistributions of source code must retain the above copyright notice, 8 * this list of conditions and the following disclaimer. 9 * 10 * b) Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in 12 * the documentation and/or other materials provided with the distribution. 13 * 14 * c) Neither the name of Cisco Systems, Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived 16 * from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 * THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30/* $KAME: sctp6_usrreq.c,v 1.38 2005/08/24 08:08:56 suz Exp $ */ 31#include <sys/cdefs.h> 32__FBSDID("$FreeBSD: head/sys/netinet6/sctp6_usrreq.c 166086 2007-01-18 09:58:43Z rrs $"); 33 34#include <netinet/sctp_os.h> 35#include <sys/proc.h> 36#include <netinet/sctp_pcb.h> 37#include <netinet/sctp_header.h> 38#include <netinet/sctp_var.h> 39#include <netinet/sctp_output.h> 40#include <netinet/sctp_input.h> 41#include <netinet/sctp_bsd_addr.h> 42#include <netinet/sctp_uio.h> 43#include <netinet/sctp_asconf.h> 44#include <netinet/sctputil.h> 45#include <netinet/sctp_indata.h> 46#include <netinet/sctp_asconf.h> 47#include <netinet/sctp_timer.h> 48#include <netinet/sctp_auth.h> 49#include <netinet6/sctp6_var.h> 50 51 52 53#ifdef SCTP_DEBUG 54extern uint32_t sctp_debug_on; 55 56#endif /* SCTP_DEBUG */ 57 58extern struct protosw inetsw[]; 59 60 61 62extern int sctp_no_csum_on_loopback; 63 64int 65sctp6_input(mp, offp, proto) 66 struct mbuf **mp; 67 int *offp; 68 69 int proto; 70 71{ 72 struct mbuf *m; 73 struct ip6_hdr *ip6; 74 struct sctphdr *sh; 75 struct sctp_inpcb *in6p = NULL; 76 struct sctp_nets *net; 77 int refcount_up = 0; 78 u_int32_t check, calc_check; 79 struct inpcb *in6p_ip; 80 struct sctp_chunkhdr *ch; 81 int length, mlen, offset, iphlen; 82 u_int8_t ecn_bits; 83 struct sctp_tcb *stcb = NULL; 84 int off = *offp; 85 86 m = SCTP_HEADER_TO_CHAIN(*mp); 87 88 ip6 = mtod(m, struct ip6_hdr *); 89#ifndef PULLDOWN_TEST 90 /* If PULLDOWN_TEST off, must be in a single mbuf. */ 91 IP6_EXTHDR_CHECK(m, off, (int)(sizeof(*sh) + sizeof(*ch)), IPPROTO_DONE); 92 sh = (struct sctphdr *)((caddr_t)ip6 + off); 93 ch = (struct sctp_chunkhdr *)((caddr_t)sh + sizeof(*sh)); 94#else 95 /* Ensure that (sctphdr + sctp_chunkhdr) in a row. */ 96 IP6_EXTHDR_GET(sh, struct sctphdr *, m, off, sizeof(*sh) + sizeof(*ch)); 97 if (sh == NULL) { 98 SCTP_STAT_INCR(sctps_hdrops); 99 return IPPROTO_DONE; 100 } 101 ch = (struct sctp_chunkhdr *)((caddr_t)sh + sizeof(struct sctphdr)); 102#endif 103 104 iphlen = off; 105 offset = iphlen + sizeof(*sh) + sizeof(*ch); 106 107#if defined(NFAITH) && NFAITH > 0 108 109 if (faithprefix_p != NULL && (*faithprefix_p) (&ip6->ip6_dst)) { 110 /* XXX send icmp6 host/port unreach? */ 111 goto bad; 112 } 113#endif /* NFAITH defined and > 0 */ 114 SCTP_STAT_INCR(sctps_recvpackets); 115 SCTP_STAT_INCR_COUNTER64(sctps_inpackets); 116#ifdef SCTP_DEBUG 117 if (sctp_debug_on & SCTP_DEBUG_INPUT1) { 118 printf("V6 input gets a packet iphlen:%d pktlen:%d\n", iphlen, SCTP_HEADER_LEN((*mp))); 119 } 120#endif 121 if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { 122 /* No multi-cast support in SCTP */ 123 goto bad; 124 } 125 /* destination port of 0 is illegal, based on RFC2960. */ 126 if (sh->dest_port == 0) 127 goto bad; 128 if ((sctp_no_csum_on_loopback == 0) || 129 (!SCTP_IS_IT_LOOPBACK(m))) { 130 /* 131 * we do NOT validate things from the loopback if the sysctl 132 * is set to 1. 133 */ 134 check = sh->checksum; /* save incoming checksum */ 135 if ((check == 0) && (sctp_no_csum_on_loopback)) { 136 /* 137 * special hook for where we got a local address 138 * somehow routed across a non IFT_LOOP type 139 * interface 140 */ 141 if (IN6_ARE_ADDR_EQUAL(&ip6->ip6_src, &ip6->ip6_dst)) 142 goto sctp_skip_csum; 143 } 144 sh->checksum = 0; /* prepare for calc */ 145 calc_check = sctp_calculate_sum(m, &mlen, iphlen); 146 if (calc_check != check) { 147#ifdef SCTP_DEBUG 148 if (sctp_debug_on & SCTP_DEBUG_INPUT1) { 149 printf("Bad CSUM on SCTP packet calc_check:%x check:%x m:%p mlen:%d iphlen:%d\n", 150 calc_check, check, m, 151 mlen, iphlen); 152 } 153#endif 154 stcb = sctp_findassociation_addr(m, iphlen, offset - sizeof(*ch), 155 sh, ch, &in6p, &net); 156 /* in6p's ref-count increased && stcb locked */ 157 if ((in6p) && (stcb)) { 158 sctp_send_packet_dropped(stcb, net, m, iphlen, 1); 159 sctp_chunk_output((struct sctp_inpcb *)in6p, stcb, 2); 160 } else if ((in6p != NULL) && (stcb == NULL)) { 161 refcount_up = 1; 162 } 163 SCTP_STAT_INCR(sctps_badsum); 164 SCTP_STAT_INCR_COUNTER32(sctps_checksumerrors); 165 goto bad; 166 } 167 sh->checksum = calc_check; 168 } 169sctp_skip_csum: 170 net = NULL; 171 /* 172 * Locate pcb and tcb for datagram sctp_findassociation_addr() wants 173 * IP/SCTP/first chunk header... 174 */ 175 stcb = sctp_findassociation_addr(m, iphlen, offset - sizeof(*ch), 176 sh, ch, &in6p, &net); 177 /* in6p's ref-count increased */ 178 if (in6p == NULL) { 179 struct sctp_init_chunk *init_chk, chunk_buf; 180 181 SCTP_STAT_INCR(sctps_noport); 182 if (ch->chunk_type == SCTP_INITIATION) { 183 /* 184 * we do a trick here to get the INIT tag, dig in 185 * and get the tag from the INIT and put it in the 186 * common header. 187 */ 188 init_chk = (struct sctp_init_chunk *)sctp_m_getptr(m, 189 iphlen + sizeof(*sh), sizeof(*init_chk), 190 (u_int8_t *) & chunk_buf); 191 sh->v_tag = init_chk->init.initiate_tag; 192 } 193 if (ch->chunk_type == SCTP_SHUTDOWN_ACK) { 194 sctp_send_shutdown_complete2(m, iphlen, sh); 195 goto bad; 196 } 197 if (ch->chunk_type == SCTP_SHUTDOWN_COMPLETE) { 198 goto bad; 199 } 200 if (ch->chunk_type != SCTP_ABORT_ASSOCIATION) 201 sctp_send_abort(m, iphlen, sh, 0, NULL); 202 goto bad; 203 } else if (stcb == NULL) { 204 refcount_up = 1; 205 } 206 in6p_ip = (struct inpcb *)in6p; 207#ifdef IPSEC 208 /* 209 * Check AH/ESP integrity. 210 */ 211 if (in6p_ip && (ipsec6_in_reject(m, in6p_ip))) { 212/* XXX */ 213 ipsec6stat.in_polvio++; 214 goto bad; 215 } 216#endif /* IPSEC */ 217 218 219 /* 220 * CONTROL chunk processing 221 */ 222 offset -= sizeof(*ch); 223 ecn_bits = ((ntohl(ip6->ip6_flow) >> 20) & 0x000000ff); 224 225 /* Length now holds the total packet length payload + iphlen */ 226 length = ntohs(ip6->ip6_plen) + iphlen; 227 228 (void)sctp_common_input_processing(&m, iphlen, offset, length, sh, ch, 229 in6p, stcb, net, ecn_bits); 230 /* inp's ref-count reduced && stcb unlocked */ 231 /* XXX this stuff below gets moved to appropriate parts later... */ 232 if (m) 233 m_freem(m); 234 if ((in6p) && refcount_up) { 235 /* reduce ref-count */ 236 SCTP_INP_WLOCK(in6p); 237 SCTP_INP_DECR_REF(in6p); 238 SCTP_INP_WUNLOCK(in6p); 239 } 240 return IPPROTO_DONE; 241 242bad: 243 if (stcb) 244 SCTP_TCB_UNLOCK(stcb); 245 246 if ((in6p) && refcount_up) { 247 /* reduce ref-count */ 248 SCTP_INP_WLOCK(in6p); 249 SCTP_INP_DECR_REF(in6p); 250 SCTP_INP_WUNLOCK(in6p); 251 } 252 if (m) 253 m_freem(m); 254 return IPPROTO_DONE; 255} 256 257 258static void 259sctp6_notify_mbuf(struct sctp_inpcb *inp, 260 struct icmp6_hdr *icmp6, 261 struct sctphdr *sh, 262 struct sctp_tcb *stcb, 263 struct sctp_nets *net) 264{ 265 u_int32_t nxtsz; 266 267 if ((inp == NULL) || (stcb == NULL) || (net == NULL) || 268 (icmp6 == NULL) || (sh == NULL)) { 269 goto out; 270 } 271 /* First do we even look at it? */ 272 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) 273 goto out; 274 275 if (icmp6->icmp6_type != ICMP6_PACKET_TOO_BIG) { 276 /* not PACKET TO BIG */ 277 goto out; 278 } 279 /* 280 * ok we need to look closely. We could even get smarter and look at 281 * anyone that we sent to in case we get a different ICMP that tells 282 * us there is no way to reach a host, but for this impl, all we 283 * care about is MTU discovery. 284 */ 285 nxtsz = ntohl(icmp6->icmp6_mtu); 286 /* Stop any PMTU timer */ 287 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, NULL, SCTP_FROM_SCTP6_USRREQ + SCTP_LOC_1); 288 289 /* Adjust destination size limit */ 290 if (net->mtu > nxtsz) { 291 net->mtu = nxtsz; 292 } 293 /* now what about the ep? */ 294 if (stcb->asoc.smallest_mtu > nxtsz) { 295 struct sctp_tmit_chunk *chk; 296 297 /* Adjust that too */ 298 stcb->asoc.smallest_mtu = nxtsz; 299 /* now off to subtract IP_DF flag if needed */ 300 301 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) { 302 if ((u_int32_t) (chk->send_size + IP_HDR_SIZE) > nxtsz) { 303 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK; 304 } 305 } 306 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) { 307 if ((u_int32_t) (chk->send_size + IP_HDR_SIZE) > nxtsz) { 308 /* 309 * For this guy we also mark for immediate 310 * resend since we sent to big of chunk 311 */ 312 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK; 313 if (chk->sent != SCTP_DATAGRAM_RESEND) 314 stcb->asoc.sent_queue_retran_cnt++; 315 chk->sent = SCTP_DATAGRAM_RESEND; 316 chk->rec.data.doing_fast_retransmit = 0; 317 318 chk->sent = SCTP_DATAGRAM_RESEND; 319 /* Clear any time so NO RTT is being done */ 320 chk->sent_rcv_time.tv_sec = 0; 321 chk->sent_rcv_time.tv_usec = 0; 322 stcb->asoc.total_flight -= chk->send_size; 323 net->flight_size -= chk->send_size; 324 } 325 } 326 } 327 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, NULL); 328out: 329 if (stcb) 330 SCTP_TCB_UNLOCK(stcb); 331} 332 333 334void 335sctp6_ctlinput(cmd, pktdst, d) 336 int cmd; 337 struct sockaddr *pktdst; 338 void *d; 339{ 340 struct sctphdr sh; 341 struct ip6ctlparam *ip6cp = NULL; 342 int cm; 343 344 if (pktdst->sa_family != AF_INET6 || 345 pktdst->sa_len != sizeof(struct sockaddr_in6)) 346 return; 347 348 if ((unsigned)cmd >= PRC_NCMDS) 349 return; 350 if (PRC_IS_REDIRECT(cmd)) { 351 d = NULL; 352 } else if (inet6ctlerrmap[cmd] == 0) { 353 return; 354 } 355 /* if the parameter is from icmp6, decode it. */ 356 if (d != NULL) { 357 ip6cp = (struct ip6ctlparam *)d; 358 } else { 359 ip6cp = (struct ip6ctlparam *)NULL; 360 } 361 362 if (ip6cp) { 363 /* 364 * XXX: We assume that when IPV6 is non NULL, M and OFF are 365 * valid. 366 */ 367 /* check if we can safely examine src and dst ports */ 368 struct sctp_inpcb *inp = NULL; 369 struct sctp_tcb *stcb = NULL; 370 struct sctp_nets *net = NULL; 371 struct sockaddr_in6 final; 372 373 if (ip6cp->ip6c_m == NULL) 374 return; 375 376 bzero(&sh, sizeof(sh)); 377 bzero(&final, sizeof(final)); 378 inp = NULL; 379 net = NULL; 380 m_copydata(ip6cp->ip6c_m, ip6cp->ip6c_off, sizeof(sh), 381 (caddr_t)&sh); 382 ip6cp->ip6c_src->sin6_port = sh.src_port; 383 final.sin6_len = sizeof(final); 384 final.sin6_family = AF_INET6; 385 final.sin6_addr = ((struct sockaddr_in6 *)pktdst)->sin6_addr; 386 final.sin6_port = sh.dest_port; 387 stcb = sctp_findassociation_addr_sa((struct sockaddr *)ip6cp->ip6c_src, 388 (struct sockaddr *)&final, 389 &inp, &net, 1); 390 /* inp's ref-count increased && stcb locked */ 391 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) { 392 if (cmd == PRC_MSGSIZE) { 393 sctp6_notify_mbuf(inp, 394 ip6cp->ip6c_icmp6, 395 &sh, 396 stcb, 397 net); 398 /* inp's ref-count reduced && stcb unlocked */ 399 } else { 400 if (cmd == PRC_HOSTDEAD) { 401 cm = EHOSTUNREACH; 402 } else { 403 cm = inet6ctlerrmap[cmd]; 404 } 405 sctp_notify(inp, cm, &sh, 406 (struct sockaddr *)&final, 407 stcb, net); 408 /* inp's ref-count reduced && stcb unlocked */ 409 } 410 } else { 411 if (PRC_IS_REDIRECT(cmd) && inp) { 412 in6_rtchange((struct in6pcb *)inp, 413 inet6ctlerrmap[cmd]); 414 } 415 if (inp) { 416 /* reduce inp's ref-count */ 417 SCTP_INP_WLOCK(inp); 418 SCTP_INP_DECR_REF(inp); 419 SCTP_INP_WUNLOCK(inp); 420 } 421 if (stcb) 422 SCTP_TCB_UNLOCK(stcb); 423 } 424 } 425} 426 427/* 428 * this routine can probably be collasped into the one in sctp_userreq.c 429 * since they do the same thing and now we lookup with a sockaddr 430 */ 431static int 432sctp6_getcred(SYSCTL_HANDLER_ARGS) 433{ 434 struct xucred xuc; 435 struct sockaddr_in6 addrs[2]; 436 struct sctp_inpcb *inp; 437 struct sctp_nets *net; 438 struct sctp_tcb *stcb; 439 int error; 440 441 /* 442 * XXXRW: Other instances of getcred use SUSER_ALLOWJAIL, as socket 443 * visibility is scoped using cr_canseesocket(), which it is not 444 * here. 445 */ 446 error = priv_check_cred(req->td->td_ucred, PRIV_NETINET_RESERVEDPORT, 447 0); 448 if (error) 449 return (error); 450 451 if (req->newlen != sizeof(addrs)) 452 return (EINVAL); 453 if (req->oldlen != sizeof(struct ucred)) 454 return (EINVAL); 455 error = SYSCTL_IN(req, addrs, sizeof(addrs)); 456 if (error) 457 return (error); 458 459 stcb = sctp_findassociation_addr_sa(sin6tosa(&addrs[0]), 460 sin6tosa(&addrs[1]), 461 &inp, &net, 1); 462 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) { 463 if ((inp != NULL) && (stcb == NULL)) { 464 /* reduce ref-count */ 465 SCTP_INP_WLOCK(inp); 466 SCTP_INP_DECR_REF(inp); 467 goto cred_can_cont; 468 } 469 error = ENOENT; 470 goto out; 471 } 472 SCTP_TCB_UNLOCK(stcb); 473 /* 474 * We use the write lock here, only since in the error leg we need 475 * it. If we used RLOCK, then we would have to 476 * wlock/decr/unlock/rlock. Which in theory could create a hole. 477 * Better to use higher wlock. 478 */ 479 SCTP_INP_WLOCK(inp); 480cred_can_cont: 481 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket); 482 if (error) { 483 SCTP_INP_WUNLOCK(inp); 484 goto out; 485 } 486 cru2x(inp->sctp_socket->so_cred, &xuc); 487 SCTP_INP_WUNLOCK(inp); 488 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred)); 489out: 490 return (error); 491} 492 493SYSCTL_PROC(_net_inet6_sctp6, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW, 494 0, 0, 495 sctp6_getcred, "S,ucred", "Get the ucred of a SCTP6 connection"); 496 497 498/* This is the same as the sctp_abort() could be made common */ 499static void 500sctp6_abort(struct socket *so) 501{ 502 struct sctp_inpcb *inp; 503 uint32_t flags; 504 505 inp = (struct sctp_inpcb *)so->so_pcb; 506 if (inp == 0) 507 return; 508sctp_must_try_again: 509 flags = inp->sctp_flags; 510#ifdef SCTP_LOG_CLOSING 511 sctp_log_closing(inp, NULL, 17); 512#endif 513 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) && 514 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) { 515#ifdef SCTP_LOG_CLOSING 516 sctp_log_closing(inp, NULL, 16); 517#endif 518 sctp_inpcb_free(inp, 1, 0); 519 SOCK_LOCK(so); 520 so->so_snd.sb_cc = 0; 521 so->so_snd.sb_mb = NULL; 522 so->so_snd.sb_mbcnt = 0; 523 524 /* 525 * same for the rcv ones, they are only here for the 526 * accounting/select. 527 */ 528 so->so_rcv.sb_cc = 0; 529 so->so_rcv.sb_mb = NULL; 530 so->so_rcv.sb_mbcnt = 0; 531 /* 532 * Now null out the reference, we are completely detached. 533 */ 534 so->so_pcb = NULL; 535 SOCK_UNLOCK(so); 536 } else { 537 flags = inp->sctp_flags; 538 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) { 539 goto sctp_must_try_again; 540 } 541 } 542 return; 543} 544 545static int 546sctp6_attach(struct socket *so, int proto, struct thread *p) 547{ 548 struct in6pcb *inp6; 549 int error; 550 struct sctp_inpcb *inp; 551 552 inp = (struct sctp_inpcb *)so->so_pcb; 553 if (inp != NULL) 554 return EINVAL; 555 556 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { 557 error = soreserve(so, sctp_sendspace, sctp_recvspace); 558 if (error) 559 return error; 560 } 561 error = sctp_inpcb_alloc(so); 562 if (error) 563 return error; 564 inp = (struct sctp_inpcb *)so->so_pcb; 565 inp->sctp_flags |= SCTP_PCB_FLAGS_BOUND_V6; /* I'm v6! */ 566 inp6 = (struct in6pcb *)inp; 567 568 inp6->inp_vflag |= INP_IPV6; 569 inp6->in6p_hops = -1; /* use kernel default */ 570 inp6->in6p_cksum = -1; /* just to be sure */ 571#ifdef INET 572 /* 573 * XXX: ugly!! IPv4 TTL initialization is necessary for an IPv6 574 * socket as well, because the socket may be bound to an IPv6 575 * wildcard address, which may match an IPv4-mapped IPv6 address. 576 */ 577 inp6->inp_ip_ttl = ip_defttl; 578#endif 579 /* 580 * Hmm what about the IPSEC stuff that is missing here but in 581 * sctp_attach()? 582 */ 583 return 0; 584} 585 586static int 587sctp6_bind(struct socket *so, struct sockaddr *addr, struct thread *p) 588{ 589 struct sctp_inpcb *inp; 590 struct in6pcb *inp6; 591 int error; 592 593 inp = (struct sctp_inpcb *)so->so_pcb; 594 if (inp == 0) 595 return EINVAL; 596 597 inp6 = (struct in6pcb *)inp; 598 inp6->inp_vflag &= ~INP_IPV4; 599 inp6->inp_vflag |= INP_IPV6; 600 if ((addr != NULL) && (SCTP_IPV6_V6ONLY(inp6) == 0)) { 601 if (addr->sa_family == AF_INET) { 602 /* binding v4 addr to v6 socket, so reset flags */ 603 inp6->inp_vflag |= INP_IPV4; 604 inp6->inp_vflag &= ~INP_IPV6; 605 } else { 606 struct sockaddr_in6 *sin6_p; 607 608 sin6_p = (struct sockaddr_in6 *)addr; 609 610 if (IN6_IS_ADDR_UNSPECIFIED(&sin6_p->sin6_addr)) { 611 inp6->inp_vflag |= INP_IPV4; 612 } else if (IN6_IS_ADDR_V4MAPPED(&sin6_p->sin6_addr)) { 613 struct sockaddr_in sin; 614 615 in6_sin6_2_sin(&sin, sin6_p); 616 inp6->inp_vflag |= INP_IPV4; 617 inp6->inp_vflag &= ~INP_IPV6; 618 error = sctp_inpcb_bind(so, (struct sockaddr *)&sin, p); 619 return error; 620 } 621 } 622 } else if (addr != NULL) { 623 /* IPV6_V6ONLY socket */ 624 if (addr->sa_family == AF_INET) { 625 /* can't bind v4 addr to v6 only socket! */ 626 return EINVAL; 627 } else { 628 struct sockaddr_in6 *sin6_p; 629 630 sin6_p = (struct sockaddr_in6 *)addr; 631 632 if (IN6_IS_ADDR_V4MAPPED(&sin6_p->sin6_addr)) 633 /* can't bind v4-mapped addrs either! */ 634 /* NOTE: we don't support SIIT */ 635 return EINVAL; 636 } 637 } 638 error = sctp_inpcb_bind(so, addr, p); 639 return error; 640} 641 642 643static void 644sctp6_close(struct socket *so) 645{ 646 struct sctp_inpcb *inp; 647 uint32_t flags; 648 649 inp = (struct sctp_inpcb *)so->so_pcb; 650 if (inp == 0) 651 return; 652 653 /* 654 * Inform all the lower layer assoc that we are done. 655 */ 656sctp_must_try_again: 657 flags = inp->sctp_flags; 658#ifdef SCTP_LOG_CLOSING 659 sctp_log_closing(inp, NULL, 17); 660#endif 661 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) && 662 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) { 663 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) || 664 (so->so_rcv.sb_cc > 0)) { 665#ifdef SCTP_LOG_CLOSING 666 sctp_log_closing(inp, NULL, 13); 667#endif 668 sctp_inpcb_free(inp, 1, 1); 669 } else { 670#ifdef SCTP_LOG_CLOSING 671 sctp_log_closing(inp, NULL, 14); 672#endif 673 sctp_inpcb_free(inp, 0, 1); 674 } 675 /* 676 * The socket is now detached, no matter what the state of 677 * the SCTP association. 678 */ 679 SOCK_LOCK(so); 680 so->so_snd.sb_cc = 0; 681 so->so_snd.sb_mb = NULL; 682 so->so_snd.sb_mbcnt = 0; 683 684 /* 685 * same for the rcv ones, they are only here for the 686 * accounting/select. 687 */ 688 so->so_rcv.sb_cc = 0; 689 so->so_rcv.sb_mb = NULL; 690 so->so_rcv.sb_mbcnt = 0; 691 /* 692 * Now null out the reference, we are completely detached. 693 */ 694 so->so_pcb = NULL; 695 SOCK_UNLOCK(so); 696 } else { 697 flags = inp->sctp_flags; 698 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) { 699 goto sctp_must_try_again; 700 } 701 } 702 return; 703 704} 705 706 707static int 708sctp6_disconnect(struct socket *so) 709{ 710 struct sctp_inpcb *inp; 711 712 inp = (struct sctp_inpcb *)so->so_pcb; 713 if (inp == NULL) { 714 return (ENOTCONN); 715 } 716 SCTP_INP_RLOCK(inp); 717 if (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) { 718 if (LIST_EMPTY(&inp->sctp_asoc_list)) { 719 /* No connection */ 720 SCTP_INP_RUNLOCK(inp); 721 return (ENOTCONN); 722 } else { 723 int some_on_streamwheel = 0; 724 struct sctp_association *asoc; 725 struct sctp_tcb *stcb; 726 727 stcb = LIST_FIRST(&inp->sctp_asoc_list); 728 if (stcb == NULL) { 729 SCTP_INP_RUNLOCK(inp); 730 return (EINVAL); 731 } 732 SCTP_TCB_LOCK(stcb); 733 asoc = &stcb->asoc; 734 if (((so->so_options & SO_LINGER) && 735 (so->so_linger == 0)) || 736 (so->so_rcv.sb_cc > 0)) { 737 if (SCTP_GET_STATE(asoc) != 738 SCTP_STATE_COOKIE_WAIT) { 739 /* Left with Data unread */ 740 struct mbuf *err; 741 742 err = NULL; 743 MGET(err, M_DONTWAIT, MT_DATA); 744 if (err) { 745 /* 746 * Fill in the user 747 * initiated abort 748 */ 749 struct sctp_paramhdr *ph; 750 751 ph = mtod(err, struct sctp_paramhdr *); 752 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr); 753 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT); 754 ph->param_length = htons(SCTP_BUF_LEN(err)); 755 } 756 sctp_send_abort_tcb(stcb, err); 757 SCTP_STAT_INCR_COUNTER32(sctps_aborted); 758 } 759 SCTP_INP_RUNLOCK(inp); 760 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) || 761 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) { 762 SCTP_STAT_DECR_GAUGE32(sctps_currestab); 763 } 764 sctp_free_assoc(inp, stcb, SCTP_DONOT_SETSCOPE, 765 SCTP_FROM_SCTP6_USRREQ + SCTP_LOC_2); 766 /* No unlock tcb assoc is gone */ 767 return (0); 768 } 769 if (!TAILQ_EMPTY(&asoc->out_wheel)) { 770 /* Check to see if some data queued */ 771 struct sctp_stream_out *outs; 772 773 TAILQ_FOREACH(outs, &asoc->out_wheel, 774 next_spoke) { 775 if (!TAILQ_EMPTY(&outs->outqueue)) { 776 some_on_streamwheel = 1; 777 break; 778 } 779 } 780 } 781 if (TAILQ_EMPTY(&asoc->send_queue) && 782 TAILQ_EMPTY(&asoc->sent_queue) && 783 (some_on_streamwheel == 0)) { 784 /* nothing queued to send, so I'm done... */ 785 if ((SCTP_GET_STATE(asoc) != 786 SCTP_STATE_SHUTDOWN_SENT) && 787 (SCTP_GET_STATE(asoc) != 788 SCTP_STATE_SHUTDOWN_ACK_SENT)) { 789 /* only send SHUTDOWN the first time */ 790 sctp_send_shutdown(stcb, stcb->asoc.primary_destination); 791 sctp_chunk_output(stcb->sctp_ep, stcb, 1); 792 asoc->state = SCTP_STATE_SHUTDOWN_SENT; 793 SCTP_STAT_DECR_GAUGE32(sctps_currestab); 794 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, 795 stcb->sctp_ep, stcb, 796 asoc->primary_destination); 797 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, 798 stcb->sctp_ep, stcb, 799 asoc->primary_destination); 800 } 801 } else { 802 /* 803 * we still got (or just got) data to send, 804 * so set SHUTDOWN_PENDING 805 */ 806 /* 807 * XXX sockets draft says that MSG_EOF 808 * should be sent with no data. currently, 809 * we will allow user data to be sent first 810 * and move to SHUTDOWN-PENDING 811 */ 812 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING; 813 } 814 SCTP_TCB_UNLOCK(stcb); 815 SCTP_INP_RUNLOCK(inp); 816 return (0); 817 } 818 } else { 819 /* UDP model does not support this */ 820 SCTP_INP_RUNLOCK(inp); 821 return EOPNOTSUPP; 822 } 823} 824 825int 826sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, 827 struct mbuf *control, struct thread *p); 828 829 830 831static int 832sctp6_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, 833 struct mbuf *control, struct thread *p) 834{ 835 struct sctp_inpcb *inp; 836 struct inpcb *in_inp; 837 struct in6pcb *inp6; 838 839#ifdef INET 840 struct sockaddr_in6 *sin6; 841 842#endif /* INET */ 843 /* No SPL needed since sctp_output does this */ 844 845 inp = (struct sctp_inpcb *)so->so_pcb; 846 if (inp == NULL) { 847 if (control) { 848 m_freem(control); 849 control = NULL; 850 } 851 m_freem(m); 852 return EINVAL; 853 } 854 in_inp = (struct inpcb *)inp; 855 inp6 = (struct in6pcb *)inp; 856 /* 857 * For the TCP model we may get a NULL addr, if we are a connected 858 * socket thats ok. 859 */ 860 if ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) && 861 (addr == NULL)) { 862 goto connected_type; 863 } 864 if (addr == NULL) { 865 m_freem(m); 866 if (control) { 867 m_freem(control); 868 control = NULL; 869 } 870 return (EDESTADDRREQ); 871 } 872#ifdef INET 873 sin6 = (struct sockaddr_in6 *)addr; 874 if (SCTP_IPV6_V6ONLY(inp6)) { 875 /* 876 * if IPV6_V6ONLY flag, we discard datagrams destined to a 877 * v4 addr or v4-mapped addr 878 */ 879 if (addr->sa_family == AF_INET) { 880 return EINVAL; 881 } 882 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { 883 return EINVAL; 884 } 885 } 886 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { 887 if (!ip6_v6only) { 888 struct sockaddr_in sin; 889 890 /* convert v4-mapped into v4 addr and send */ 891 in6_sin6_2_sin(&sin, sin6); 892 return sctp_sendm(so, flags, m, (struct sockaddr *)&sin, 893 control, p); 894 } else { 895 /* mapped addresses aren't enabled */ 896 return EINVAL; 897 } 898 } 899#endif /* INET */ 900connected_type: 901 /* now what about control */ 902 if (control) { 903 if (inp->control) { 904 printf("huh? control set?\n"); 905 m_freem(inp->control); 906 inp->control = NULL; 907 } 908 inp->control = control; 909 } 910 /* Place the data */ 911 if (inp->pkt) { 912 SCTP_BUF_NEXT(inp->pkt_last) = m; 913 inp->pkt_last = m; 914 } else { 915 inp->pkt_last = inp->pkt = m; 916 } 917 if ( 918 /* FreeBSD and MacOSX uses a flag passed */ 919 ((flags & PRUS_MORETOCOME) == 0) 920 ) { 921 /* 922 * note with the current version this code will only be used 923 * by OpenBSD, NetBSD and FreeBSD have methods for 924 * re-defining sosend() to use sctp_sosend(). One can 925 * optionaly switch back to this code (by changing back the 926 * defininitions but this is not advisable. 927 */ 928 int ret; 929 930 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags); 931 inp->pkt = NULL; 932 inp->control = NULL; 933 return (ret); 934 } else { 935 return (0); 936 } 937} 938 939static int 940sctp6_connect(struct socket *so, struct sockaddr *addr, struct thread *p) 941{ 942 int error = 0; 943 struct sctp_inpcb *inp; 944 struct in6pcb *inp6; 945 struct sctp_tcb *stcb; 946 947#ifdef INET 948 struct sockaddr_in6 *sin6; 949 struct sockaddr_storage ss; 950 951#endif /* INET */ 952 953 inp6 = (struct in6pcb *)so->so_pcb; 954 inp = (struct sctp_inpcb *)so->so_pcb; 955 if (inp == 0) { 956 return (ECONNRESET); /* I made the same as TCP since we are 957 * not setup? */ 958 } 959 SCTP_ASOC_CREATE_LOCK(inp); 960 SCTP_INP_RLOCK(inp); 961 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 962 SCTP_PCB_FLAGS_UNBOUND) { 963 /* Bind a ephemeral port */ 964 SCTP_INP_RUNLOCK(inp); 965 error = sctp6_bind(so, NULL, p); 966 if (error) { 967 SCTP_ASOC_CREATE_UNLOCK(inp); 968 969 return (error); 970 } 971 SCTP_INP_RLOCK(inp); 972 } 973 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) && 974 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) { 975 /* We are already connected AND the TCP model */ 976 SCTP_INP_RUNLOCK(inp); 977 SCTP_ASOC_CREATE_UNLOCK(inp); 978 return (EADDRINUSE); 979 } 980#ifdef INET 981 sin6 = (struct sockaddr_in6 *)addr; 982 if (SCTP_IPV6_V6ONLY(inp6)) { 983 /* 984 * if IPV6_V6ONLY flag, ignore connections destined to a v4 985 * addr or v4-mapped addr 986 */ 987 if (addr->sa_family == AF_INET) { 988 SCTP_INP_RUNLOCK(inp); 989 SCTP_ASOC_CREATE_UNLOCK(inp); 990 return EINVAL; 991 } 992 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { 993 SCTP_INP_RUNLOCK(inp); 994 SCTP_ASOC_CREATE_UNLOCK(inp); 995 return EINVAL; 996 } 997 } 998 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { 999 if (!ip6_v6only) { 1000 /* convert v4-mapped into v4 addr */ 1001 in6_sin6_2_sin((struct sockaddr_in *)&ss, sin6); 1002 addr = (struct sockaddr *)&ss; 1003 } else { 1004 /* mapped addresses aren't enabled */ 1005 SCTP_INP_RUNLOCK(inp); 1006 SCTP_ASOC_CREATE_UNLOCK(inp); 1007 return EINVAL; 1008 } 1009 } else 1010#endif /* INET */ 1011 addr = addr; /* for true v6 address case */ 1012 1013 /* Now do we connect? */ 1014 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) { 1015 stcb = LIST_FIRST(&inp->sctp_asoc_list); 1016 if (stcb) 1017 SCTP_TCB_UNLOCK(stcb); 1018 SCTP_INP_RUNLOCK(inp); 1019 } else { 1020 SCTP_INP_RUNLOCK(inp); 1021 SCTP_INP_WLOCK(inp); 1022 SCTP_INP_INCR_REF(inp); 1023 SCTP_INP_WUNLOCK(inp); 1024 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL); 1025 if (stcb == NULL) { 1026 SCTP_INP_WLOCK(inp); 1027 SCTP_INP_DECR_REF(inp); 1028 SCTP_INP_WUNLOCK(inp); 1029 } 1030 } 1031 1032 if (stcb != NULL) { 1033 /* Already have or am bring up an association */ 1034 SCTP_ASOC_CREATE_UNLOCK(inp); 1035 SCTP_TCB_UNLOCK(stcb); 1036 return (EALREADY); 1037 } 1038 /* We are GOOD to go */ 1039 stcb = sctp_aloc_assoc(inp, addr, 1, &error, 0); 1040 SCTP_ASOC_CREATE_UNLOCK(inp); 1041 if (stcb == NULL) { 1042 /* Gak! no memory */ 1043 return (error); 1044 } 1045 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) { 1046 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED; 1047 /* Set the connected flag so we can queue data */ 1048 soisconnecting(so); 1049 } 1050 stcb->asoc.state = SCTP_STATE_COOKIE_WAIT; 1051 SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered); 1052 1053 /* initialize authentication parameters for the assoc */ 1054 sctp_initialize_auth_params(inp, stcb); 1055 1056 sctp_send_initiate(inp, stcb); 1057 SCTP_TCB_UNLOCK(stcb); 1058 return error; 1059} 1060 1061static int 1062sctp6_getaddr(struct socket *so, struct sockaddr **addr) 1063{ 1064 struct sockaddr_in6 *sin6; 1065 1066 struct sctp_inpcb *inp; 1067 1068 int error; 1069 1070 1071 /* 1072 * Do the malloc first in case it blocks. 1073 */ 1074 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6); 1075 sin6->sin6_family = AF_INET6; 1076 sin6->sin6_len = sizeof(*sin6); 1077 1078 inp = (struct sctp_inpcb *)so->so_pcb; 1079 if (inp == NULL) { 1080 SCTP_FREE_SONAME(sin6); 1081 return ECONNRESET; 1082 } 1083 SCTP_INP_RLOCK(inp); 1084 sin6->sin6_port = inp->sctp_lport; 1085 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { 1086 /* For the bound all case you get back 0 */ 1087 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) { 1088 struct sctp_tcb *stcb; 1089 struct sockaddr_in6 *sin_a6; 1090 struct sctp_nets *net; 1091 int fnd; 1092 1093 stcb = LIST_FIRST(&inp->sctp_asoc_list); 1094 if (stcb == NULL) { 1095 goto notConn6; 1096 } 1097 fnd = 0; 1098 sin_a6 = NULL; 1099 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 1100 sin_a6 = (struct sockaddr_in6 *)&net->ro._l_addr; 1101 if (sin_a6 == NULL) 1102 /* this will make coverity happy */ 1103 continue; 1104 1105 if (sin_a6->sin6_family == AF_INET6) { 1106 fnd = 1; 1107 break; 1108 } 1109 } 1110 if ((!fnd) || (sin_a6 == NULL)) { 1111 /* punt */ 1112 goto notConn6; 1113 } 1114 sin6->sin6_addr = sctp_ipv6_source_address_selection( 1115 inp, stcb, (struct route *)&net->ro, net, 0); 1116 1117 } else { 1118 /* For the bound all case you get back 0 */ 1119 notConn6: 1120 memset(&sin6->sin6_addr, 0, sizeof(sin6->sin6_addr)); 1121 } 1122 } else { 1123 /* Take the first IPv6 address in the list */ 1124 struct sctp_laddr *laddr; 1125 int fnd = 0; 1126 1127 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) { 1128 if (laddr->ifa->ifa_addr->sa_family == AF_INET6) { 1129 struct sockaddr_in6 *sin_a; 1130 1131 sin_a = (struct sockaddr_in6 *)laddr->ifa->ifa_addr; 1132 sin6->sin6_addr = sin_a->sin6_addr; 1133 fnd = 1; 1134 break; 1135 } 1136 } 1137 if (!fnd) { 1138 SCTP_FREE_SONAME(sin6); 1139 SCTP_INP_RUNLOCK(inp); 1140 return ENOENT; 1141 } 1142 } 1143 SCTP_INP_RUNLOCK(inp); 1144 /* Scoping things for v6 */ 1145 if ((error = sa6_recoverscope(sin6)) != 0) { 1146 SCTP_FREE_SONAME(sin6); 1147 return (error); 1148 } 1149 (*addr) = (struct sockaddr *)sin6; 1150 return (0); 1151} 1152 1153static int 1154sctp6_peeraddr(struct socket *so, struct sockaddr **addr) 1155{ 1156 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)*addr; 1157 1158 int fnd; 1159 struct sockaddr_in6 *sin_a6; 1160 struct sctp_inpcb *inp; 1161 struct sctp_tcb *stcb; 1162 struct sctp_nets *net; 1163 1164 int error; 1165 1166 1167 /* 1168 * Do the malloc first in case it blocks. 1169 */ 1170 inp = (struct sctp_inpcb *)so->so_pcb; 1171 if ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0) { 1172 /* UDP type and listeners will drop out here */ 1173 return (ENOTCONN); 1174 } 1175 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6); 1176 sin6->sin6_family = AF_INET6; 1177 sin6->sin6_len = sizeof(*sin6); 1178 1179 /* We must recapture incase we blocked */ 1180 inp = (struct sctp_inpcb *)so->so_pcb; 1181 if (inp == NULL) { 1182 SCTP_FREE_SONAME(sin6); 1183 return ECONNRESET; 1184 } 1185 SCTP_INP_RLOCK(inp); 1186 stcb = LIST_FIRST(&inp->sctp_asoc_list); 1187 if (stcb) 1188 SCTP_TCB_LOCK(stcb); 1189 SCTP_INP_RUNLOCK(inp); 1190 if (stcb == NULL) { 1191 SCTP_FREE_SONAME(sin6); 1192 return ECONNRESET; 1193 } 1194 fnd = 0; 1195 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 1196 sin_a6 = (struct sockaddr_in6 *)&net->ro._l_addr; 1197 if (sin_a6->sin6_family == AF_INET6) { 1198 fnd = 1; 1199 sin6->sin6_port = stcb->rport; 1200 sin6->sin6_addr = sin_a6->sin6_addr; 1201 break; 1202 } 1203 } 1204 SCTP_TCB_UNLOCK(stcb); 1205 if (!fnd) { 1206 /* No IPv4 address */ 1207 SCTP_FREE_SONAME(sin6); 1208 return ENOENT; 1209 } 1210 if ((error = sa6_recoverscope(sin6)) != 0) 1211 return (error); 1212 *addr = (struct sockaddr *)sin6; 1213 return (0); 1214} 1215 1216static int 1217sctp6_in6getaddr(struct socket *so, struct sockaddr **nam) 1218{ 1219 struct sockaddr *addr; 1220 1221 struct in6pcb *inp6 = sotoin6pcb(so); 1222 int error; 1223 1224 if (inp6 == NULL) 1225 return EINVAL; 1226 1227 /* allow v6 addresses precedence */ 1228 error = sctp6_getaddr(so, nam); 1229 if (error) { 1230 /* try v4 next if v6 failed */ 1231 error = sctp_ingetaddr(so, nam); 1232 if (error) { 1233 return (error); 1234 } 1235 addr = *nam; 1236 /* if I'm V6ONLY, convert it to v4-mapped */ 1237 if (SCTP_IPV6_V6ONLY(inp6)) { 1238 struct sockaddr_in6 sin6; 1239 1240 in6_sin_2_v4mapsin6((struct sockaddr_in *)addr, &sin6); 1241 memcpy(addr, &sin6, sizeof(struct sockaddr_in6)); 1242 } 1243 } 1244 return (error); 1245} 1246 1247 1248static int 1249sctp6_getpeeraddr(struct socket *so, struct sockaddr **nam) 1250{ 1251 struct sockaddr *addr = *nam; 1252 1253 struct in6pcb *inp6 = sotoin6pcb(so); 1254 int error; 1255 1256 if (inp6 == NULL) 1257 return EINVAL; 1258 1259 /* allow v6 addresses precedence */ 1260 error = sctp6_peeraddr(so, nam); 1261 if (error) { 1262 /* try v4 next if v6 failed */ 1263 error = sctp_peeraddr(so, nam); 1264 if (error) { 1265 return (error); 1266 } 1267 /* if I'm V6ONLY, convert it to v4-mapped */ 1268 if (SCTP_IPV6_V6ONLY(inp6)) { 1269 struct sockaddr_in6 sin6; 1270 1271 in6_sin_2_v4mapsin6((struct sockaddr_in *)addr, &sin6); 1272 memcpy(addr, &sin6, sizeof(struct sockaddr_in6)); 1273 } 1274 } 1275 return error; 1276} 1277 1278struct pr_usrreqs sctp6_usrreqs = { 1279 .pru_abort = sctp6_abort, 1280 .pru_accept = sctp_accept, 1281 .pru_attach = sctp6_attach, 1282 .pru_bind = sctp6_bind, 1283 .pru_connect = sctp6_connect, 1284 .pru_control = in6_control, 1285 .pru_close = sctp6_close, 1286 .pru_detach = sctp6_close, 1287 .pru_sopoll = sopoll_generic, 1288 .pru_disconnect = sctp6_disconnect, 1289 .pru_listen = sctp_listen, 1290 .pru_peeraddr = sctp6_getpeeraddr, 1291 .pru_send = sctp6_send, 1292 .pru_shutdown = sctp_shutdown, 1293 .pru_sockaddr = sctp6_in6getaddr, 1294 .pru_sosend = sctp_sosend, 1295 .pru_soreceive = sctp_soreceive 1296}; 1297