2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <netinet/sctp_os.h>
38 #include <netinet/sctp_pcb.h>
39 #include <netinet/sctp_header.h>
40 #include <netinet/sctp_var.h>
42 #include <netinet6/sctp6_var.h>
44 #include <netinet/sctp_sysctl.h>
45 #include <netinet/sctp_output.h>
46 #include <netinet/sctp_uio.h>
47 #include <netinet/sctp_asconf.h>
48 #include <netinet/sctputil.h>
49 #include <netinet/sctp_indata.h>
50 #include <netinet/sctp_timer.h>
51 #include <netinet/sctp_auth.h>
52 #include <netinet/sctp_bsd_addr.h>
53 #include <netinet/udp.h>
57 extern const struct sctp_cc_functions sctp_cc_functions[];
58 extern const struct sctp_ss_functions sctp_ss_functions[];
65 /* Initialize and modify the sysctled variables */
67 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
68 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
70 * Allow a user to take no more than 1/2 the number of clusters or
71 * the SB_MAX whichever is smaller for the send window.
73 sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
74 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
75 (((uint32_t) nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
77 * Now for the recv window, should we take the same amount? or
78 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
79 * now I will just copy.
81 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
82 SCTP_BASE_VAR(first_time) = 0;
83 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
85 #if defined(SCTP_PACKET_LOGGING)
86 SCTP_BASE_VAR(packet_log_writers) = 0;
87 SCTP_BASE_VAR(packet_log_end) = 0;
88 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
101 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
103 struct sctp_tmit_chunk *chk;
106 /* Adjust that too */
107 stcb->asoc.smallest_mtu = nxtsz;
108 /* now off to subtract IP_DF flag if needed */
109 overhead = IP_HDR_SIZE;
110 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
111 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
113 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
114 if ((chk->send_size + overhead) > nxtsz) {
115 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
118 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
119 if ((chk->send_size + overhead) > nxtsz) {
121 * For this guy we also mark for immediate resend
122 * since we sent to big of chunk
124 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
125 if (chk->sent < SCTP_DATAGRAM_RESEND) {
126 sctp_flight_size_decrease(chk);
127 sctp_total_flight_decrease(stcb, chk);
128 chk->sent = SCTP_DATAGRAM_RESEND;
129 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
130 chk->rec.data.doing_fast_retransmit = 0;
131 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
132 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
133 chk->whoTo->flight_size,
135 (uint32_t) (uintptr_t) chk->whoTo,
136 chk->rec.data.TSN_seq);
138 /* Clear any time so NO RTT is being done */
147 sctp_notify_mbuf(struct sctp_inpcb *inp,
148 struct sctp_tcb *stcb,
149 struct sctp_nets *net,
154 int totsz, tmr_stopped = 0;
158 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
159 (ip == NULL) || (sh == NULL)) {
161 SCTP_TCB_UNLOCK(stcb);
165 /* First job is to verify the vtag matches what I would send */
166 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
167 SCTP_TCB_UNLOCK(stcb);
170 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
172 if (icmph->icmp_type != ICMP_UNREACH) {
173 /* We only care about unreachable */
174 SCTP_TCB_UNLOCK(stcb);
177 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
178 /* not a unreachable message due to frag. */
179 SCTP_TCB_UNLOCK(stcb);
182 totsz = ntohs(ip->ip_len);
184 nxtsz = ntohs(icmph->icmp_nextmtu);
187 * old type router that does not tell us what the next size
188 * mtu is. Rats we will have to guess (in a educated fashion
191 nxtsz = sctp_get_prev_mtu(totsz);
193 /* Stop any PMTU timer */
194 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
196 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
197 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
199 /* Adjust destination size limit */
200 if (net->mtu > nxtsz) {
203 net->mtu -= sizeof(struct udphdr);
206 /* now what about the ep? */
207 if (stcb->asoc.smallest_mtu > nxtsz) {
208 sctp_pathmtu_adjustment(stcb, nxtsz);
211 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
213 SCTP_TCB_UNLOCK(stcb);
217 sctp_notify(struct sctp_inpcb *inp,
221 struct sctp_tcb *stcb,
222 struct sctp_nets *net)
224 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
231 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
232 (sh == NULL) || (to == NULL)) {
234 SCTP_TCB_UNLOCK(stcb);
237 /* First job is to verify the vtag matches what I would send */
238 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
239 SCTP_TCB_UNLOCK(stcb);
242 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
244 if (icmph->icmp_type != ICMP_UNREACH) {
245 /* We only care about unreachable */
246 SCTP_TCB_UNLOCK(stcb);
249 if ((icmph->icmp_code == ICMP_UNREACH_NET) ||
250 (icmph->icmp_code == ICMP_UNREACH_HOST) ||
251 (icmph->icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
252 (icmph->icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
253 (icmph->icmp_code == ICMP_UNREACH_ISOLATED) ||
254 (icmph->icmp_code == ICMP_UNREACH_NET_PROHIB) ||
255 (icmph->icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
256 (icmph->icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
259 * Hmm reachablity problems we must examine closely. If its
260 * not reachable, we may have lost a network. Or if there is
261 * NO protocol at the other end named SCTP. well we consider
264 if (net->dest_state & SCTP_ADDR_REACHABLE) {
265 /* Ok that destination is NOT reachable */
266 net->dest_state &= ~SCTP_ADDR_REACHABLE;
267 net->dest_state &= ~SCTP_ADDR_PF;
268 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
270 (void *)net, SCTP_SO_NOT_LOCKED);
272 SCTP_TCB_UNLOCK(stcb);
273 } else if ((icmph->icmp_code == ICMP_UNREACH_PROTOCOL) ||
274 (icmph->icmp_code == ICMP_UNREACH_PORT)) {
276 * Here the peer is either playing tricks on us, including
277 * an address that belongs to someone who does not support
278 * SCTP OR was a userland implementation that shutdown and
279 * now is dead. In either case treat it like a OOTB abort
282 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
283 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
284 so = SCTP_INP_SO(inp);
285 atomic_add_int(&stcb->asoc.refcnt, 1);
286 SCTP_TCB_UNLOCK(stcb);
287 SCTP_SOCKET_LOCK(so, 1);
289 atomic_subtract_int(&stcb->asoc.refcnt, 1);
291 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
292 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
293 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
294 SCTP_SOCKET_UNLOCK(so, 1);
295 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
297 /* no need to unlock here, since the TCB is gone */
299 SCTP_TCB_UNLOCK(stcb);
307 sctp_ctlinput(cmd, sa, vip)
316 /* FIX, for non-bsd is this right? */
317 vrf_id = SCTP_DEFAULT_VRFID;
318 if (sa->sa_family != AF_INET ||
319 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
322 if (PRC_IS_REDIRECT(cmd)) {
324 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
328 struct sctp_inpcb *inp = NULL;
329 struct sctp_tcb *stcb = NULL;
330 struct sctp_nets *net = NULL;
331 struct sockaddr_in to, from;
333 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
334 bzero(&to, sizeof(to));
335 bzero(&from, sizeof(from));
336 from.sin_family = to.sin_family = AF_INET;
337 from.sin_len = to.sin_len = sizeof(to);
338 from.sin_port = sh->src_port;
339 from.sin_addr = ip->ip_src;
340 to.sin_port = sh->dest_port;
341 to.sin_addr = ip->ip_dst;
344 * 'to' holds the dest of the packet that failed to be sent.
345 * 'from' holds our local endpoint address. Thus we reverse
346 * the to and the from in the lookup.
348 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&to,
349 (struct sockaddr *)&from,
350 &inp, &net, 1, vrf_id);
351 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
352 if (cmd != PRC_MSGSIZE) {
353 sctp_notify(inp, ip, sh,
354 (struct sockaddr *)&to, stcb,
357 /* handle possible ICMP size messages */
358 sctp_notify_mbuf(inp, stcb, net, ip, sh);
361 if ((stcb == NULL) && (inp != NULL)) {
362 /* reduce ref-count */
364 SCTP_INP_DECR_REF(inp);
365 SCTP_INP_WUNLOCK(inp);
368 SCTP_TCB_UNLOCK(stcb);
378 sctp_getcred(SYSCTL_HANDLER_ARGS)
381 struct sockaddr_in addrs[2];
382 struct sctp_inpcb *inp;
383 struct sctp_nets *net;
384 struct sctp_tcb *stcb;
388 /* FIX, for non-bsd is this right? */
389 vrf_id = SCTP_DEFAULT_VRFID;
391 error = priv_check(req->td, PRIV_NETINET_GETCRED);
396 error = SYSCTL_IN(req, addrs, sizeof(addrs));
400 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
402 &inp, &net, 1, vrf_id);
403 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
404 if ((inp != NULL) && (stcb == NULL)) {
405 /* reduce ref-count */
407 SCTP_INP_DECR_REF(inp);
410 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
414 SCTP_TCB_UNLOCK(stcb);
416 * We use the write lock here, only since in the error leg we need
417 * it. If we used RLOCK, then we would have to
418 * wlock/decr/unlock/rlock. Which in theory could create a hole.
419 * Better to use higher wlock.
423 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
425 SCTP_INP_WUNLOCK(inp);
428 cru2x(inp->sctp_socket->so_cred, &xuc);
429 SCTP_INP_WUNLOCK(inp);
430 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
435 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
436 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
441 sctp_abort(struct socket *so)
443 struct sctp_inpcb *inp;
446 inp = (struct sctp_inpcb *)so->so_pcb;
451 flags = inp->sctp_flags;
452 #ifdef SCTP_LOG_CLOSING
453 sctp_log_closing(inp, NULL, 17);
455 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
456 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
457 #ifdef SCTP_LOG_CLOSING
458 sctp_log_closing(inp, NULL, 16);
460 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
461 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
463 SCTP_SB_CLEAR(so->so_snd);
465 * same for the rcv ones, they are only here for the
468 SCTP_SB_CLEAR(so->so_rcv);
470 /* Now null out the reference, we are completely detached. */
474 flags = inp->sctp_flags;
475 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
476 goto sctp_must_try_again;
483 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
485 struct sctp_inpcb *inp;
486 struct inpcb *ip_inp;
488 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
490 inp = (struct sctp_inpcb *)so->so_pcb;
492 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
495 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
496 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
501 error = sctp_inpcb_alloc(so, vrf_id);
505 inp = (struct sctp_inpcb *)so->so_pcb;
507 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
508 ip_inp = &inp->ip_inp.inp;
509 ip_inp->inp_vflag |= INP_IPV4;
510 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
511 SCTP_INP_WUNLOCK(inp);
516 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
518 struct sctp_inpcb *inp;
520 inp = (struct sctp_inpcb *)so->so_pcb;
522 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
526 if ((addr->sa_family != AF_INET) ||
527 (addr->sa_len != sizeof(struct sockaddr_in))) {
528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
532 return (sctp_inpcb_bind(so, addr, NULL, p));
537 sctp_close(struct socket *so)
539 struct sctp_inpcb *inp;
542 inp = (struct sctp_inpcb *)so->so_pcb;
547 * Inform all the lower layer assoc that we are done.
550 flags = inp->sctp_flags;
551 #ifdef SCTP_LOG_CLOSING
552 sctp_log_closing(inp, NULL, 17);
554 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
555 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
556 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
557 (so->so_rcv.sb_cc > 0)) {
558 #ifdef SCTP_LOG_CLOSING
559 sctp_log_closing(inp, NULL, 13);
561 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
562 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
564 #ifdef SCTP_LOG_CLOSING
565 sctp_log_closing(inp, NULL, 14);
567 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
568 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
571 * The socket is now detached, no matter what the state of
572 * the SCTP association.
575 SCTP_SB_CLEAR(so->so_snd);
577 * same for the rcv ones, they are only here for the
580 SCTP_SB_CLEAR(so->so_rcv);
582 /* Now null out the reference, we are completely detached. */
586 flags = inp->sctp_flags;
587 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
588 goto sctp_must_try_again;
596 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
597 struct mbuf *control, struct thread *p);
601 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
602 struct mbuf *control, struct thread *p)
604 struct sctp_inpcb *inp;
607 inp = (struct sctp_inpcb *)so->so_pcb;
610 sctp_m_freem(control);
613 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
617 /* Got to have an to address if we are NOT a connected socket */
618 if ((addr == NULL) &&
619 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
620 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
622 } else if (addr == NULL) {
623 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
624 error = EDESTADDRREQ;
627 sctp_m_freem(control);
633 if (addr->sa_family != AF_INET) {
634 /* must be a v4 address! */
635 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
638 sctp_m_freem(control);
641 error = EDESTADDRREQ;
646 /* now what about control */
649 SCTP_PRINTF("huh? control set?\n");
650 sctp_m_freem(inp->control);
653 inp->control = control;
657 SCTP_BUF_NEXT(inp->pkt_last) = m;
660 inp->pkt_last = inp->pkt = m;
663 /* FreeBSD uses a flag passed */
664 ((flags & PRUS_MORETOCOME) == 0)
667 * note with the current version this code will only be used
668 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
669 * re-defining sosend to use the sctp_sosend. One can
670 * optionally switch back to this code (by changing back the
671 * definitions) but this is not advisable. This code is used
672 * by FreeBSD when sending a file with sendfile() though.
676 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
686 sctp_disconnect(struct socket *so)
688 struct sctp_inpcb *inp;
690 inp = (struct sctp_inpcb *)so->so_pcb;
692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
696 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
697 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
698 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
700 SCTP_INP_RUNLOCK(inp);
703 struct sctp_association *asoc;
704 struct sctp_tcb *stcb;
706 stcb = LIST_FIRST(&inp->sctp_asoc_list);
708 SCTP_INP_RUNLOCK(inp);
709 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
714 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
715 /* We are about to be freed, out of here */
716 SCTP_TCB_UNLOCK(stcb);
717 SCTP_INP_RUNLOCK(inp);
720 if (((so->so_options & SO_LINGER) &&
721 (so->so_linger == 0)) ||
722 (so->so_rcv.sb_cc > 0)) {
723 if (SCTP_GET_STATE(asoc) !=
724 SCTP_STATE_COOKIE_WAIT) {
725 /* Left with Data unread */
728 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_NOWAIT, 1, MT_DATA);
734 struct sctp_paramhdr *ph;
736 ph = mtod(err, struct sctp_paramhdr *);
737 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
738 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
739 ph->param_length = htons(SCTP_BUF_LEN(err));
741 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
742 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
744 SCTP_INP_RUNLOCK(inp);
745 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
746 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
747 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
749 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
750 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
751 /* No unlock tcb assoc is gone */
754 if (TAILQ_EMPTY(&asoc->send_queue) &&
755 TAILQ_EMPTY(&asoc->sent_queue) &&
756 (asoc->stream_queue_cnt == 0)) {
757 /* there is nothing queued to send, so done */
758 if (asoc->locked_on_sending) {
761 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
762 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
763 /* only send SHUTDOWN 1st time thru */
764 struct sctp_nets *netp;
766 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
767 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
768 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
770 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
771 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
772 sctp_stop_timers_for_shutdown(stcb);
773 if (stcb->asoc.alternate) {
774 netp = stcb->asoc.alternate;
776 netp = stcb->asoc.primary_destination;
778 sctp_send_shutdown(stcb, netp);
779 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
780 stcb->sctp_ep, stcb, netp);
781 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
782 stcb->sctp_ep, stcb, netp);
783 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
787 * we still got (or just got) data to send,
788 * so set SHUTDOWN_PENDING
791 * XXX sockets draft says that SCTP_EOF
792 * should be sent with no data. currently,
793 * we will allow user data to be sent first
794 * and move to SHUTDOWN-PENDING
796 struct sctp_nets *netp;
798 if (stcb->asoc.alternate) {
799 netp = stcb->asoc.alternate;
801 netp = stcb->asoc.primary_destination;
804 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
805 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
807 if (asoc->locked_on_sending) {
808 /* Locked to send out the data */
809 struct sctp_stream_queue_pending *sp;
811 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
813 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
814 asoc->locked_on_sending->stream_no);
816 if ((sp->length == 0) && (sp->msg_is_complete == 0))
817 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
820 if (TAILQ_EMPTY(&asoc->send_queue) &&
821 TAILQ_EMPTY(&asoc->sent_queue) &&
822 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
826 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
827 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
828 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
829 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
830 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
831 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
832 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
834 SCTP_INP_RUNLOCK(inp);
835 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
836 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
839 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
842 soisdisconnecting(so);
843 SCTP_TCB_UNLOCK(stcb);
844 SCTP_INP_RUNLOCK(inp);
849 /* UDP model does not support this */
850 SCTP_INP_RUNLOCK(inp);
851 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
857 sctp_flush(struct socket *so, int how)
860 * We will just clear out the values and let subsequent close clear
861 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
862 * they will not be able to read the data, the socket will block
863 * that from happening.
865 struct sctp_inpcb *inp;
867 inp = (struct sctp_inpcb *)so->so_pcb;
869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
873 /* For the 1 to many model this does nothing */
874 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
875 SCTP_INP_RUNLOCK(inp);
878 SCTP_INP_RUNLOCK(inp);
879 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
881 * First make sure the sb will be happy, we don't use these
882 * except maybe the count
885 SCTP_INP_READ_LOCK(inp);
886 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
887 SCTP_INP_READ_UNLOCK(inp);
888 SCTP_INP_WUNLOCK(inp);
889 so->so_rcv.sb_cc = 0;
890 so->so_rcv.sb_mbcnt = 0;
891 so->so_rcv.sb_mb = NULL;
893 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
895 * First make sure the sb will be happy, we don't use these
896 * except maybe the count
898 so->so_snd.sb_cc = 0;
899 so->so_snd.sb_mbcnt = 0;
900 so->so_snd.sb_mb = NULL;
907 sctp_shutdown(struct socket *so)
909 struct sctp_inpcb *inp;
911 inp = (struct sctp_inpcb *)so->so_pcb;
913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
917 /* For UDP model this is a invalid call */
918 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
919 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
920 /* Restore the flags that the soshutdown took away. */
921 SOCKBUF_LOCK(&so->so_rcv);
922 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
923 SOCKBUF_UNLOCK(&so->so_rcv);
924 /* This proc will wakeup for read and do nothing (I hope) */
925 SCTP_INP_RUNLOCK(inp);
926 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
930 * Ok, if we reach here its the TCP model and it is either a
931 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
934 struct sctp_tcb *stcb;
935 struct sctp_association *asoc;
936 struct sctp_nets *netp;
939 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
940 SCTP_INP_RUNLOCK(inp);
945 stcb = LIST_FIRST(&inp->sctp_asoc_list);
948 * Ok, we hit the case that the shutdown call was
949 * made after an abort or something. Nothing to do
952 SCTP_INP_RUNLOCK(inp);
957 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
958 SCTP_TCB_UNLOCK(stcb);
959 SCTP_INP_RUNLOCK(inp);
962 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_WAIT) &&
963 (SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_ECHOED) &&
964 (SCTP_GET_STATE(asoc) != SCTP_STATE_OPEN)) {
966 * If we are not in or before ESTABLISHED, there is
967 * no protocol action required.
969 SCTP_TCB_UNLOCK(stcb);
970 SCTP_INP_RUNLOCK(inp);
973 if (stcb->asoc.alternate) {
974 netp = stcb->asoc.alternate;
976 netp = stcb->asoc.primary_destination;
978 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) &&
979 TAILQ_EMPTY(&asoc->send_queue) &&
980 TAILQ_EMPTY(&asoc->sent_queue) &&
981 (asoc->stream_queue_cnt == 0)) {
982 if (asoc->locked_on_sending) {
985 /* there is nothing queued to send, so I'm done... */
986 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
987 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
988 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
989 sctp_stop_timers_for_shutdown(stcb);
990 sctp_send_shutdown(stcb, netp);
991 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
992 stcb->sctp_ep, stcb, netp);
995 * We still got (or just got) data to send, so set
998 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
999 if (asoc->locked_on_sending) {
1000 /* Locked to send out the data */
1001 struct sctp_stream_queue_pending *sp;
1003 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1005 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1006 asoc->locked_on_sending->stream_no);
1008 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1009 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_PARTIAL_MSG_LEFT);
1013 if (TAILQ_EMPTY(&asoc->send_queue) &&
1014 TAILQ_EMPTY(&asoc->sent_queue) &&
1015 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1016 struct mbuf *op_err;
1019 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
1020 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1021 sctp_abort_an_association(stcb->sctp_ep, stcb,
1022 op_err, SCTP_SO_LOCKED);
1023 SCTP_INP_RUNLOCK(inp);
1027 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp);
1029 * XXX: Why do this in the case where we have still data
1032 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1033 SCTP_TCB_UNLOCK(stcb);
1034 SCTP_INP_RUNLOCK(inp);
1040 * copies a "user" presentable address and removes embedded scope, etc.
1041 * returns 0 on success, 1 on error
1044 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1047 struct sockaddr_in6 lsa6;
1049 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1052 memcpy(ss, sa, sa->sa_len);
1059 * NOTE: assumes addr lock is held
1062 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1063 struct sctp_tcb *stcb,
1065 struct sockaddr_storage *sas,
1068 struct sctp_ifn *sctp_ifn;
1069 struct sctp_ifa *sctp_ifa;
1074 int ipv4_local_scope, ipv4_addr_legal;
1078 int local_scope, site_scope, ipv6_addr_legal;
1081 struct sctp_vrf *vrf;
1088 /* Turn on all the appropriate scope */
1089 loopback_scope = stcb->asoc.scope.loopback_scope;
1091 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1092 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1095 local_scope = stcb->asoc.scope.local_scope;
1096 site_scope = stcb->asoc.scope.site_scope;
1097 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1100 /* Use generic values for endpoints. */
1103 ipv4_local_scope = 1;
1109 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1111 ipv6_addr_legal = 1;
1114 if (SCTP_IPV6_V6ONLY(inp)) {
1115 ipv4_addr_legal = 0;
1117 ipv4_addr_legal = 1;
1122 ipv6_addr_legal = 0;
1125 ipv4_addr_legal = 1;
1129 vrf = sctp_find_vrf(vrf_id);
1133 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1134 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1135 if ((loopback_scope == 0) &&
1136 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1137 /* Skip loopback if loopback_scope not set */
1140 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1143 * For the BOUND-ALL case, the list
1144 * associated with a TCB is Always
1145 * considered a reverse list.. i.e.
1146 * it lists addresses that are NOT
1147 * part of the association. If this
1148 * is one of those we must skip it.
1150 if (sctp_is_addr_restricted(stcb,
1155 switch (sctp_ifa->address.sa.sa_family) {
1158 if (ipv4_addr_legal) {
1159 struct sockaddr_in *sin;
1161 sin = &sctp_ifa->address.sin;
1162 if (sin->sin_addr.s_addr == 0) {
1170 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1171 &sin->sin_addr) != 0) {
1174 if ((ipv4_local_scope == 0) &&
1175 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1179 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1180 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1181 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1182 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1183 actual += sizeof(struct sockaddr_in6);
1186 memcpy(sas, sin, sizeof(*sin));
1187 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1188 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1189 actual += sizeof(*sin);
1193 if (actual >= limit) {
1203 if (ipv6_addr_legal) {
1204 struct sockaddr_in6 *sin6;
1206 sin6 = &sctp_ifa->address.sin6;
1207 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1215 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1216 &sin6->sin6_addr) != 0) {
1219 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1220 if (local_scope == 0)
1222 if (sin6->sin6_scope_id == 0) {
1223 if (sa6_recoverscope(sin6) != 0)
1241 if ((site_scope == 0) &&
1242 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1245 memcpy(sas, sin6, sizeof(*sin6));
1246 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1247 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1248 actual += sizeof(*sin6);
1249 if (actual >= limit) {
1264 struct sctp_laddr *laddr;
1266 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1268 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1272 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1274 switch (laddr->ifa->address.sa.sa_family) {
1277 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1282 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1289 sas = (struct sockaddr_storage *)((caddr_t)sas +
1290 laddr->ifa->address.sa.sa_len);
1291 actual += laddr->ifa->address.sa.sa_len;
1292 if (actual >= limit) {
1301 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1302 struct sctp_tcb *stcb,
1304 struct sockaddr_storage *sas)
1308 SCTP_IPI_ADDR_RLOCK();
1309 /* fill up addresses for the endpoint's default vrf */
1310 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1312 SCTP_IPI_ADDR_RUNLOCK();
1317 * NOTE: assumes addr lock is held
1320 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1323 struct sctp_vrf *vrf = NULL;
1326 * In both sub-set bound an bound_all cases we return the MAXIMUM
1327 * number of addresses that you COULD get. In reality the sub-set
1328 * bound may have an exclusion list for a given TCB OR in the
1329 * bound-all case a TCB may NOT include the loopback or other
1330 * addresses as well.
1332 vrf = sctp_find_vrf(vrf_id);
1336 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1337 struct sctp_ifn *sctp_ifn;
1338 struct sctp_ifa *sctp_ifa;
1340 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1341 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1342 /* Count them if they are the right type */
1343 switch (sctp_ifa->address.sa.sa_family) {
1347 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1348 cnt += sizeof(struct sockaddr_in6);
1350 cnt += sizeof(struct sockaddr_in);
1352 cnt += sizeof(struct sockaddr_in);
1358 cnt += sizeof(struct sockaddr_in6);
1367 struct sctp_laddr *laddr;
1369 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1370 switch (laddr->ifa->address.sa.sa_family) {
1374 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1375 cnt += sizeof(struct sockaddr_in6);
1377 cnt += sizeof(struct sockaddr_in);
1379 cnt += sizeof(struct sockaddr_in);
1385 cnt += sizeof(struct sockaddr_in6);
1397 sctp_count_max_addresses(struct sctp_inpcb *inp)
1401 SCTP_IPI_ADDR_RLOCK();
1402 /* count addresses for the endpoint's default VRF */
1403 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1404 SCTP_IPI_ADDR_RUNLOCK();
1409 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1410 size_t optsize, void *p, int delay)
1413 int creat_lock_on = 0;
1414 struct sctp_tcb *stcb = NULL;
1415 struct sockaddr *sa;
1416 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1418 int bad_addresses = 0;
1421 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1423 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1424 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1425 /* We are already connected AND the TCP model */
1426 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1427 return (EADDRINUSE);
1429 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1430 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1431 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1434 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1435 SCTP_INP_RLOCK(inp);
1436 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1437 SCTP_INP_RUNLOCK(inp);
1440 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1443 SCTP_INP_INCR_REF(inp);
1444 SCTP_ASOC_CREATE_LOCK(inp);
1446 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1447 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1448 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1452 totaddrp = (unsigned int *)optval;
1453 totaddr = *totaddrp;
1454 sa = (struct sockaddr *)(totaddrp + 1);
1455 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (unsigned int)(optsize - sizeof(int)), &bad_addresses);
1456 if ((stcb != NULL) || bad_addresses) {
1457 /* Already have or am bring up an association */
1458 SCTP_ASOC_CREATE_UNLOCK(inp);
1461 SCTP_TCB_UNLOCK(stcb);
1462 if (bad_addresses == 0) {
1463 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1469 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1474 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1476 struct in6pcb *inp6;
1478 inp6 = (struct in6pcb *)inp;
1479 if (SCTP_IPV6_V6ONLY(inp6)) {
1481 * if IPV6_V6ONLY flag, ignore connections destined
1482 * to a v4 addr or v4-mapped addr
1484 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1490 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1491 SCTP_PCB_FLAGS_UNBOUND) {
1492 /* Bind a ephemeral port */
1493 error = sctp_inpcb_bind(so, NULL, NULL, p);
1498 /* FIX ME: do we want to pass in a vrf on the connect call? */
1499 vrf_id = inp->def_vrf_id;
1502 /* We are GOOD to go */
1503 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1504 inp->sctp_ep.pre_open_stream_count,
1508 /* Gak! no memory */
1511 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1512 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1513 /* Set the connected flag so we can queue data */
1516 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1517 /* move to second address */
1518 switch (sa->sa_family) {
1521 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1526 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1534 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1535 /* Fill in the return id */
1537 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE,
1538 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
1541 a_id = (sctp_assoc_t *) optval;
1542 *a_id = sctp_get_associd(stcb);
1544 /* initialize authentication parameters for the assoc */
1545 sctp_initialize_auth_params(inp, stcb);
1548 /* doing delayed connection */
1549 stcb->asoc.delayed_connection = 1;
1550 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1552 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1553 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1555 SCTP_TCB_UNLOCK(stcb);
1556 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1557 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1558 /* Set the connected flag so we can queue data */
1562 if (creat_lock_on) {
1563 SCTP_ASOC_CREATE_UNLOCK(inp);
1565 SCTP_INP_DECR_REF(inp);
1569 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1570 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1571 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1572 SCTP_INP_RLOCK(inp); \
1573 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1575 SCTP_TCB_LOCK(stcb); \
1577 SCTP_INP_RUNLOCK(inp); \
1578 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1579 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1580 if (stcb == NULL) { \
1581 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1591 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1592 if (size < sizeof(type)) { \
1593 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1597 destp = (type *)srcp; \
1602 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1605 struct sctp_inpcb *inp = NULL;
1607 struct sctp_tcb *stcb = NULL;
1609 if (optval == NULL) {
1610 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1613 inp = (struct sctp_inpcb *)so->so_pcb;
1615 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1622 case SCTP_AUTOCLOSE:
1623 case SCTP_EXPLICIT_EOR:
1624 case SCTP_AUTO_ASCONF:
1625 case SCTP_DISABLE_FRAGMENTS:
1626 case SCTP_I_WANT_MAPPED_V4_ADDR:
1627 case SCTP_USE_EXT_RCVINFO:
1628 SCTP_INP_RLOCK(inp);
1630 case SCTP_DISABLE_FRAGMENTS:
1631 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1633 case SCTP_I_WANT_MAPPED_V4_ADDR:
1634 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1636 case SCTP_AUTO_ASCONF:
1637 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1638 /* only valid for bound all sockets */
1639 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1641 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1646 case SCTP_EXPLICIT_EOR:
1647 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1650 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1652 case SCTP_USE_EXT_RCVINFO:
1653 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1655 case SCTP_AUTOCLOSE:
1656 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1657 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1663 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1664 error = ENOPROTOOPT;
1665 } /* end switch (sopt->sopt_name) */
1666 if (*optsize < sizeof(val)) {
1667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1671 SCTP_INP_RUNLOCK(inp);
1673 /* return the option value */
1674 *(int *)optval = val;
1675 *optsize = sizeof(val);
1678 case SCTP_GET_PACKET_LOG:
1680 #ifdef SCTP_PACKET_LOGGING
1684 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1685 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1688 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1693 case SCTP_REUSE_PORT:
1697 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1698 /* Can't do this for a 1-m socket */
1702 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1703 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1704 *optsize = sizeof(uint32_t);
1707 case SCTP_PARTIAL_DELIVERY_POINT:
1711 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1712 *value = inp->partial_delivery_point;
1713 *optsize = sizeof(uint32_t);
1716 case SCTP_FRAGMENT_INTERLEAVE:
1720 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1721 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1722 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1723 *value = SCTP_FRAG_LEVEL_2;
1725 *value = SCTP_FRAG_LEVEL_1;
1728 *value = SCTP_FRAG_LEVEL_0;
1730 *optsize = sizeof(uint32_t);
1733 case SCTP_CMT_ON_OFF:
1735 struct sctp_assoc_value *av;
1737 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1738 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1740 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1741 SCTP_TCB_UNLOCK(stcb);
1743 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1744 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1745 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1746 SCTP_INP_RLOCK(inp);
1747 av->assoc_value = inp->sctp_cmt_on_off;
1748 SCTP_INP_RUNLOCK(inp);
1750 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1755 *optsize = sizeof(struct sctp_assoc_value);
1759 case SCTP_PLUGGABLE_CC:
1761 struct sctp_assoc_value *av;
1763 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1764 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1766 av->assoc_value = stcb->asoc.congestion_control_module;
1767 SCTP_TCB_UNLOCK(stcb);
1769 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1770 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1771 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1772 SCTP_INP_RLOCK(inp);
1773 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1774 SCTP_INP_RUNLOCK(inp);
1776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1781 *optsize = sizeof(struct sctp_assoc_value);
1785 case SCTP_CC_OPTION:
1787 struct sctp_cc_option *cc_opt;
1789 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1790 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1794 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1797 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1798 *optsize = sizeof(struct sctp_cc_option);
1800 SCTP_TCB_UNLOCK(stcb);
1804 case SCTP_PLUGGABLE_SS:
1806 struct sctp_assoc_value *av;
1808 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1809 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1811 av->assoc_value = stcb->asoc.stream_scheduling_module;
1812 SCTP_TCB_UNLOCK(stcb);
1814 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1815 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1816 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1817 SCTP_INP_RLOCK(inp);
1818 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1819 SCTP_INP_RUNLOCK(inp);
1821 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1826 *optsize = sizeof(struct sctp_assoc_value);
1832 struct sctp_stream_value *av;
1834 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1835 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1837 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1838 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1839 &av->stream_value) < 0)) {
1840 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1843 *optsize = sizeof(struct sctp_stream_value);
1845 SCTP_TCB_UNLOCK(stcb);
1848 * Can't get stream value without
1851 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1856 case SCTP_GET_ADDR_LEN:
1858 struct sctp_assoc_value *av;
1860 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1863 if (av->assoc_value == AF_INET) {
1864 av->assoc_value = sizeof(struct sockaddr_in);
1869 if (av->assoc_value == AF_INET6) {
1870 av->assoc_value = sizeof(struct sockaddr_in6);
1875 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1877 *optsize = sizeof(struct sctp_assoc_value);
1881 case SCTP_GET_ASSOC_NUMBER:
1883 uint32_t *value, cnt;
1885 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1886 SCTP_INP_RLOCK(inp);
1887 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1888 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1889 /* Can't do this for a 1-1 socket */
1891 SCTP_INP_RUNLOCK(inp);
1895 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1898 SCTP_INP_RUNLOCK(inp);
1900 *optsize = sizeof(uint32_t);
1903 case SCTP_GET_ASSOC_ID_LIST:
1905 struct sctp_assoc_ids *ids;
1909 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1910 SCTP_INP_RLOCK(inp);
1911 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1912 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1913 /* Can't do this for a 1-1 socket */
1915 SCTP_INP_RUNLOCK(inp);
1919 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1920 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1922 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1925 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1934 SCTP_INP_RUNLOCK(inp);
1936 ids->gaids_number_of_ids = at;
1937 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1943 struct sctp_assoc_value *av;
1945 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1946 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1949 av->assoc_value = stcb->asoc.context;
1950 SCTP_TCB_UNLOCK(stcb);
1952 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1953 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1954 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1955 SCTP_INP_RLOCK(inp);
1956 av->assoc_value = inp->sctp_context;
1957 SCTP_INP_RUNLOCK(inp);
1959 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1964 *optsize = sizeof(struct sctp_assoc_value);
1970 uint32_t *default_vrfid;
1972 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1973 *default_vrfid = inp->def_vrf_id;
1974 *optsize = sizeof(uint32_t);
1977 case SCTP_GET_ASOC_VRF:
1979 struct sctp_assoc_value *id;
1981 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1982 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1985 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1987 id->assoc_value = stcb->asoc.vrf_id;
1988 *optsize = sizeof(struct sctp_assoc_value);
1992 case SCTP_GET_VRF_IDS:
1994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1998 case SCTP_GET_NONCE_VALUES:
2000 struct sctp_get_nonce_values *gnv;
2002 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2003 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2006 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2007 gnv->gn_local_tag = stcb->asoc.my_vtag;
2008 SCTP_TCB_UNLOCK(stcb);
2009 *optsize = sizeof(struct sctp_get_nonce_values);
2011 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2016 case SCTP_DELAYED_SACK:
2018 struct sctp_sack_info *sack;
2020 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2021 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2023 sack->sack_delay = stcb->asoc.delayed_ack;
2024 sack->sack_freq = stcb->asoc.sack_freq;
2025 SCTP_TCB_UNLOCK(stcb);
2027 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2028 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2029 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2030 SCTP_INP_RLOCK(inp);
2031 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2032 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2033 SCTP_INP_RUNLOCK(inp);
2035 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2040 *optsize = sizeof(struct sctp_sack_info);
2044 case SCTP_GET_SNDBUF_USE:
2046 struct sctp_sockstat *ss;
2048 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2049 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2052 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2053 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2054 stcb->asoc.size_on_all_streams);
2055 SCTP_TCB_UNLOCK(stcb);
2056 *optsize = sizeof(struct sctp_sockstat);
2058 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2063 case SCTP_MAX_BURST:
2065 struct sctp_assoc_value *av;
2067 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2068 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2071 av->assoc_value = stcb->asoc.max_burst;
2072 SCTP_TCB_UNLOCK(stcb);
2074 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2075 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2076 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2077 SCTP_INP_RLOCK(inp);
2078 av->assoc_value = inp->sctp_ep.max_burst;
2079 SCTP_INP_RUNLOCK(inp);
2081 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2086 *optsize = sizeof(struct sctp_assoc_value);
2092 struct sctp_assoc_value *av;
2095 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2096 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2099 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2100 SCTP_TCB_UNLOCK(stcb);
2102 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2103 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2104 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2105 SCTP_INP_RLOCK(inp);
2106 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2107 ovh = SCTP_MED_OVERHEAD;
2109 ovh = SCTP_MED_V4_OVERHEAD;
2111 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2112 av->assoc_value = 0;
2114 av->assoc_value = inp->sctp_frag_point - ovh;
2115 SCTP_INP_RUNLOCK(inp);
2117 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2122 *optsize = sizeof(struct sctp_assoc_value);
2126 case SCTP_GET_STAT_LOG:
2127 error = sctp_fill_stat_log(optval, optsize);
2131 struct sctp_event_subscribe *events;
2133 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2134 memset(events, 0, sizeof(struct sctp_event_subscribe));
2135 SCTP_INP_RLOCK(inp);
2136 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2137 events->sctp_data_io_event = 1;
2139 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2140 events->sctp_association_event = 1;
2142 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2143 events->sctp_address_event = 1;
2145 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2146 events->sctp_send_failure_event = 1;
2148 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2149 events->sctp_peer_error_event = 1;
2151 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2152 events->sctp_shutdown_event = 1;
2154 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2155 events->sctp_partial_delivery_event = 1;
2157 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2158 events->sctp_adaptation_layer_event = 1;
2160 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2161 events->sctp_authentication_event = 1;
2163 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2164 events->sctp_sender_dry_event = 1;
2166 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2167 events->sctp_stream_reset_event = 1;
2168 SCTP_INP_RUNLOCK(inp);
2169 *optsize = sizeof(struct sctp_event_subscribe);
2172 case SCTP_ADAPTATION_LAYER:
2176 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2178 SCTP_INP_RLOCK(inp);
2179 *value = inp->sctp_ep.adaptation_layer_indicator;
2180 SCTP_INP_RUNLOCK(inp);
2181 *optsize = sizeof(uint32_t);
2184 case SCTP_SET_INITIAL_DBG_SEQ:
2188 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2189 SCTP_INP_RLOCK(inp);
2190 *value = inp->sctp_ep.initial_sequence_debug;
2191 SCTP_INP_RUNLOCK(inp);
2192 *optsize = sizeof(uint32_t);
2195 case SCTP_GET_LOCAL_ADDR_SIZE:
2199 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2200 SCTP_INP_RLOCK(inp);
2201 *value = sctp_count_max_addresses(inp);
2202 SCTP_INP_RUNLOCK(inp);
2203 *optsize = sizeof(uint32_t);
2206 case SCTP_GET_REMOTE_ADDR_SIZE:
2210 struct sctp_nets *net;
2212 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2213 /* FIXME MT: change to sctp_assoc_value? */
2214 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2218 /* Count the sizes */
2219 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2220 switch (net->ro._l_addr.sa.sa_family) {
2224 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2225 size += sizeof(struct sockaddr_in6);
2227 size += sizeof(struct sockaddr_in);
2230 size += sizeof(struct sockaddr_in);
2236 size += sizeof(struct sockaddr_in6);
2243 SCTP_TCB_UNLOCK(stcb);
2244 *value = (uint32_t) size;
2245 *optsize = sizeof(uint32_t);
2247 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2252 case SCTP_GET_PEER_ADDRESSES:
2254 * Get the address information, an array is passed in to
2255 * fill up we pack it.
2259 struct sockaddr_storage *sas;
2260 struct sctp_nets *net;
2261 struct sctp_getaddresses *saddr;
2263 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2264 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2267 left = (*optsize) - sizeof(struct sctp_getaddresses);
2268 *optsize = sizeof(struct sctp_getaddresses);
2269 sas = (struct sockaddr_storage *)&saddr->addr[0];
2271 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2272 switch (net->ro._l_addr.sa.sa_family) {
2276 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2277 cpsz = sizeof(struct sockaddr_in6);
2279 cpsz = sizeof(struct sockaddr_in);
2282 cpsz = sizeof(struct sockaddr_in);
2288 cpsz = sizeof(struct sockaddr_in6);
2299 /* not enough room. */
2302 #if defined(INET) && defined(INET6)
2303 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2304 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2305 /* Must map the address */
2306 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2307 (struct sockaddr_in6 *)sas);
2309 memcpy(sas, &net->ro._l_addr, cpsz);
2312 memcpy(sas, &net->ro._l_addr, cpsz);
2314 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2316 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2320 SCTP_TCB_UNLOCK(stcb);
2322 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2327 case SCTP_GET_LOCAL_ADDRESSES:
2329 size_t limit, actual;
2330 struct sockaddr_storage *sas;
2331 struct sctp_getaddresses *saddr;
2333 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2334 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2336 sas = (struct sockaddr_storage *)&saddr->addr[0];
2337 limit = *optsize - sizeof(sctp_assoc_t);
2338 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2340 SCTP_TCB_UNLOCK(stcb);
2342 *optsize = sizeof(struct sockaddr_storage) + actual;
2345 case SCTP_PEER_ADDR_PARAMS:
2347 struct sctp_paddrparams *paddrp;
2348 struct sctp_nets *net;
2349 struct sockaddr *addr;
2351 #if defined(INET) && defined(INET6)
2352 struct sockaddr_in sin_store;
2356 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2357 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2359 #if defined(INET) && defined(INET6)
2360 if (paddrp->spp_address.ss_family == AF_INET6) {
2361 struct sockaddr_in6 *sin6;
2363 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2364 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2365 in6_sin6_2_sin(&sin_store, sin6);
2366 addr = (struct sockaddr *)&sin_store;
2368 addr = (struct sockaddr *)&paddrp->spp_address;
2371 addr = (struct sockaddr *)&paddrp->spp_address;
2374 addr = (struct sockaddr *)&paddrp->spp_address;
2377 net = sctp_findnet(stcb, addr);
2380 * We increment here since
2381 * sctp_findassociation_ep_addr() wil do a
2382 * decrement if it finds the stcb as long as
2383 * the locked tcb (last argument) is NOT a
2387 SCTP_INP_INCR_REF(inp);
2388 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2390 SCTP_INP_DECR_REF(inp);
2393 if ((stcb != NULL) && (net == NULL)) {
2395 if (addr->sa_family == AF_INET) {
2396 struct sockaddr_in *sin;
2398 sin = (struct sockaddr_in *)addr;
2399 if (sin->sin_addr.s_addr != INADDR_ANY) {
2401 SCTP_TCB_UNLOCK(stcb);
2402 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2408 if (addr->sa_family == AF_INET6) {
2409 struct sockaddr_in6 *sin6;
2411 sin6 = (struct sockaddr_in6 *)addr;
2412 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2414 SCTP_TCB_UNLOCK(stcb);
2415 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2421 error = EAFNOSUPPORT;
2422 SCTP_TCB_UNLOCK(stcb);
2423 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2428 /* Applies to the specific association */
2429 paddrp->spp_flags = 0;
2431 paddrp->spp_hbinterval = net->heart_beat_delay;
2432 paddrp->spp_pathmaxrxt = net->failure_threshold;
2433 paddrp->spp_pathmtu = net->mtu;
2434 switch (net->ro._l_addr.sa.sa_family) {
2437 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2442 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2448 /* get flags for HB */
2449 if (net->dest_state & SCTP_ADDR_NOHB) {
2450 paddrp->spp_flags |= SPP_HB_DISABLE;
2452 paddrp->spp_flags |= SPP_HB_ENABLE;
2454 /* get flags for PMTU */
2455 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2456 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2458 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2460 if (net->dscp & 0x01) {
2461 paddrp->spp_dscp = net->dscp & 0xfc;
2462 paddrp->spp_flags |= SPP_DSCP;
2465 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2466 (net->flowlabel & 0x80000000)) {
2467 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2468 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2473 * No destination so return default
2476 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2477 paddrp->spp_pathmtu = 0;
2478 if (stcb->asoc.default_dscp & 0x01) {
2479 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2480 paddrp->spp_flags |= SPP_DSCP;
2483 if (stcb->asoc.default_flowlabel & 0x80000000) {
2484 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2485 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2488 /* default settings should be these */
2489 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2490 paddrp->spp_flags |= SPP_HB_DISABLE;
2492 paddrp->spp_flags |= SPP_HB_ENABLE;
2494 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2495 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2497 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2499 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2501 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2502 SCTP_TCB_UNLOCK(stcb);
2504 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2505 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2506 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2507 /* Use endpoint defaults */
2508 SCTP_INP_RLOCK(inp);
2509 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2510 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2511 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2512 /* get inp's default */
2513 if (inp->sctp_ep.default_dscp & 0x01) {
2514 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2515 paddrp->spp_flags |= SPP_DSCP;
2518 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2519 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2520 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2521 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2524 /* can't return this */
2525 paddrp->spp_pathmtu = 0;
2527 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2528 paddrp->spp_flags |= SPP_HB_ENABLE;
2530 paddrp->spp_flags |= SPP_HB_DISABLE;
2532 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2533 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2535 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2537 SCTP_INP_RUNLOCK(inp);
2539 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2544 *optsize = sizeof(struct sctp_paddrparams);
2548 case SCTP_GET_PEER_ADDR_INFO:
2550 struct sctp_paddrinfo *paddri;
2551 struct sctp_nets *net;
2552 struct sockaddr *addr;
2554 #if defined(INET) && defined(INET6)
2555 struct sockaddr_in sin_store;
2559 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2560 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2562 #if defined(INET) && defined(INET6)
2563 if (paddri->spinfo_address.ss_family == AF_INET6) {
2564 struct sockaddr_in6 *sin6;
2566 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2567 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2568 in6_sin6_2_sin(&sin_store, sin6);
2569 addr = (struct sockaddr *)&sin_store;
2571 addr = (struct sockaddr *)&paddri->spinfo_address;
2574 addr = (struct sockaddr *)&paddri->spinfo_address;
2577 addr = (struct sockaddr *)&paddri->spinfo_address;
2580 net = sctp_findnet(stcb, addr);
2583 * We increment here since
2584 * sctp_findassociation_ep_addr() wil do a
2585 * decrement if it finds the stcb as long as
2586 * the locked tcb (last argument) is NOT a
2590 SCTP_INP_INCR_REF(inp);
2591 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2593 SCTP_INP_DECR_REF(inp);
2597 if ((stcb != NULL) && (net != NULL)) {
2598 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2599 /* It's unconfirmed */
2600 paddri->spinfo_state = SCTP_UNCONFIRMED;
2601 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2603 paddri->spinfo_state = SCTP_ACTIVE;
2606 paddri->spinfo_state = SCTP_INACTIVE;
2608 paddri->spinfo_cwnd = net->cwnd;
2609 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2610 paddri->spinfo_rto = net->RTO;
2611 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2612 paddri->spinfo_mtu = net->mtu;
2613 switch (addr->sa_family) {
2616 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2621 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2627 SCTP_TCB_UNLOCK(stcb);
2628 *optsize = sizeof(struct sctp_paddrinfo);
2631 SCTP_TCB_UNLOCK(stcb);
2633 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2638 case SCTP_PCB_STATUS:
2640 struct sctp_pcbinfo *spcb;
2642 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2643 sctp_fill_pcbinfo(spcb);
2644 *optsize = sizeof(struct sctp_pcbinfo);
2649 struct sctp_nets *net;
2650 struct sctp_status *sstat;
2652 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2653 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2656 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2660 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2661 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2662 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2663 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2665 * We can't include chunks that have been passed to
2666 * the socket layer. Only things in queue.
2668 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2669 stcb->asoc.cnt_on_all_streams);
2672 sstat->sstat_instrms = stcb->asoc.streamincnt;
2673 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2674 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2675 memcpy(&sstat->sstat_primary.spinfo_address,
2676 &stcb->asoc.primary_destination->ro._l_addr,
2677 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2678 net = stcb->asoc.primary_destination;
2679 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2681 * Again the user can get info from sctp_constants.h
2682 * for what the state of the network is.
2684 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2685 /* It's unconfirmed */
2686 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2687 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2689 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2692 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2694 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2695 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2696 sstat->sstat_primary.spinfo_rto = net->RTO;
2697 sstat->sstat_primary.spinfo_mtu = net->mtu;
2698 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2701 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2706 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2712 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2713 SCTP_TCB_UNLOCK(stcb);
2714 *optsize = sizeof(struct sctp_status);
2719 struct sctp_rtoinfo *srto;
2721 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2722 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2725 srto->srto_initial = stcb->asoc.initial_rto;
2726 srto->srto_max = stcb->asoc.maxrto;
2727 srto->srto_min = stcb->asoc.minrto;
2728 SCTP_TCB_UNLOCK(stcb);
2730 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2731 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2732 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2733 SCTP_INP_RLOCK(inp);
2734 srto->srto_initial = inp->sctp_ep.initial_rto;
2735 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2736 srto->srto_min = inp->sctp_ep.sctp_minrto;
2737 SCTP_INP_RUNLOCK(inp);
2739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2744 *optsize = sizeof(struct sctp_rtoinfo);
2750 struct sctp_timeouts *stimo;
2752 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2753 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2756 stimo->stimo_init = stcb->asoc.timoinit;
2757 stimo->stimo_data = stcb->asoc.timodata;
2758 stimo->stimo_sack = stcb->asoc.timosack;
2759 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2760 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2761 stimo->stimo_cookie = stcb->asoc.timocookie;
2762 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2763 SCTP_TCB_UNLOCK(stcb);
2764 *optsize = sizeof(struct sctp_timeouts);
2766 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2771 case SCTP_ASSOCINFO:
2773 struct sctp_assocparams *sasoc;
2775 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2776 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2779 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2780 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2781 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2782 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2783 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2784 SCTP_TCB_UNLOCK(stcb);
2786 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2787 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2788 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2789 SCTP_INP_RLOCK(inp);
2790 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2791 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2792 sasoc->sasoc_number_peer_destinations = 0;
2793 sasoc->sasoc_peer_rwnd = 0;
2794 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2795 SCTP_INP_RUNLOCK(inp);
2797 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2802 *optsize = sizeof(struct sctp_assocparams);
2806 case SCTP_DEFAULT_SEND_PARAM:
2808 struct sctp_sndrcvinfo *s_info;
2810 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2811 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2814 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2815 SCTP_TCB_UNLOCK(stcb);
2817 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2818 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2819 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2820 SCTP_INP_RLOCK(inp);
2821 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2822 SCTP_INP_RUNLOCK(inp);
2824 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2829 *optsize = sizeof(struct sctp_sndrcvinfo);
2835 struct sctp_initmsg *sinit;
2837 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2838 SCTP_INP_RLOCK(inp);
2839 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2840 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2841 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2842 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2843 SCTP_INP_RUNLOCK(inp);
2844 *optsize = sizeof(struct sctp_initmsg);
2847 case SCTP_PRIMARY_ADDR:
2848 /* we allow a "get" operation on this */
2850 struct sctp_setprim *ssp;
2852 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2853 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2856 union sctp_sockstore *addr;
2858 addr = &stcb->asoc.primary_destination->ro._l_addr;
2859 switch (addr->sa.sa_family) {
2863 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2864 in6_sin_2_v4mapsin6(&addr->sin,
2865 (struct sockaddr_in6 *)&ssp->ssp_addr);
2867 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2870 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2876 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2882 SCTP_TCB_UNLOCK(stcb);
2883 *optsize = sizeof(struct sctp_setprim);
2885 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2890 case SCTP_HMAC_IDENT:
2892 struct sctp_hmacalgo *shmac;
2893 sctp_hmaclist_t *hmaclist;
2897 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2899 SCTP_INP_RLOCK(inp);
2900 hmaclist = inp->sctp_ep.local_hmacs;
2901 if (hmaclist == NULL) {
2902 /* no HMACs to return */
2903 *optsize = sizeof(*shmac);
2904 SCTP_INP_RUNLOCK(inp);
2907 /* is there room for all of the hmac ids? */
2908 size = sizeof(*shmac) + (hmaclist->num_algo *
2909 sizeof(shmac->shmac_idents[0]));
2910 if ((size_t)(*optsize) < size) {
2911 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2913 SCTP_INP_RUNLOCK(inp);
2916 /* copy in the list */
2917 shmac->shmac_number_of_idents = hmaclist->num_algo;
2918 for (i = 0; i < hmaclist->num_algo; i++) {
2919 shmac->shmac_idents[i] = hmaclist->hmac[i];
2921 SCTP_INP_RUNLOCK(inp);
2925 case SCTP_AUTH_ACTIVE_KEY:
2927 struct sctp_authkeyid *scact;
2929 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2930 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2933 /* get the active key on the assoc */
2934 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2935 SCTP_TCB_UNLOCK(stcb);
2937 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2938 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2939 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2940 /* get the endpoint active key */
2941 SCTP_INP_RLOCK(inp);
2942 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2943 SCTP_INP_RUNLOCK(inp);
2945 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2950 *optsize = sizeof(struct sctp_authkeyid);
2954 case SCTP_LOCAL_AUTH_CHUNKS:
2956 struct sctp_authchunks *sac;
2957 sctp_auth_chklist_t *chklist = NULL;
2960 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2961 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2964 /* get off the assoc */
2965 chklist = stcb->asoc.local_auth_chunks;
2966 /* is there enough space? */
2967 size = sctp_auth_get_chklist_size(chklist);
2968 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2970 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2972 /* copy in the chunks */
2973 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2974 sac->gauth_number_of_chunks = (uint32_t) size;
2975 *optsize = sizeof(struct sctp_authchunks) + size;
2977 SCTP_TCB_UNLOCK(stcb);
2979 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2980 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2981 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2982 /* get off the endpoint */
2983 SCTP_INP_RLOCK(inp);
2984 chklist = inp->sctp_ep.local_auth_chunks;
2985 /* is there enough space? */
2986 size = sctp_auth_get_chklist_size(chklist);
2987 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2991 /* copy in the chunks */
2992 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2993 sac->gauth_number_of_chunks = (uint32_t) size;
2994 *optsize = sizeof(struct sctp_authchunks) + size;
2996 SCTP_INP_RUNLOCK(inp);
2998 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3004 case SCTP_PEER_AUTH_CHUNKS:
3006 struct sctp_authchunks *sac;
3007 sctp_auth_chklist_t *chklist = NULL;
3010 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
3011 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
3014 /* get off the assoc */
3015 chklist = stcb->asoc.peer_auth_chunks;
3016 /* is there enough space? */
3017 size = sctp_auth_get_chklist_size(chklist);
3018 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
3020 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3022 /* copy in the chunks */
3023 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3024 sac->gauth_number_of_chunks = (uint32_t) size;
3025 *optsize = sizeof(struct sctp_authchunks) + size;
3027 SCTP_TCB_UNLOCK(stcb);
3029 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3036 struct sctp_event *event;
3037 uint32_t event_type;
3039 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3040 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3042 switch (event->se_type) {
3043 case SCTP_ASSOC_CHANGE:
3044 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3046 case SCTP_PEER_ADDR_CHANGE:
3047 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3049 case SCTP_REMOTE_ERROR:
3050 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3052 case SCTP_SEND_FAILED:
3053 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3055 case SCTP_SHUTDOWN_EVENT:
3056 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3058 case SCTP_ADAPTATION_INDICATION:
3059 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3061 case SCTP_PARTIAL_DELIVERY_EVENT:
3062 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3064 case SCTP_AUTHENTICATION_EVENT:
3065 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3067 case SCTP_STREAM_RESET_EVENT:
3068 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3070 case SCTP_SENDER_DRY_EVENT:
3071 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3073 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3075 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3078 case SCTP_ASSOC_RESET_EVENT:
3079 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3081 case SCTP_STREAM_CHANGE_EVENT:
3082 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3084 case SCTP_SEND_FAILED_EVENT:
3085 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3089 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3093 if (event_type > 0) {
3095 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3096 SCTP_TCB_UNLOCK(stcb);
3098 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3099 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3100 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3101 SCTP_INP_RLOCK(inp);
3102 event->se_on = sctp_is_feature_on(inp, event_type);
3103 SCTP_INP_RUNLOCK(inp);
3105 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3111 *optsize = sizeof(struct sctp_event);
3115 case SCTP_RECVRCVINFO:
3119 if (*optsize < sizeof(int)) {
3120 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3123 SCTP_INP_RLOCK(inp);
3124 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3125 SCTP_INP_RUNLOCK(inp);
3128 /* return the option value */
3129 *(int *)optval = onoff;
3130 *optsize = sizeof(int);
3134 case SCTP_RECVNXTINFO:
3138 if (*optsize < sizeof(int)) {
3139 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3142 SCTP_INP_RLOCK(inp);
3143 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3144 SCTP_INP_RUNLOCK(inp);
3147 /* return the option value */
3148 *(int *)optval = onoff;
3149 *optsize = sizeof(int);
3153 case SCTP_DEFAULT_SNDINFO:
3155 struct sctp_sndinfo *info;
3157 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3158 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3161 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3162 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3163 info->snd_flags &= 0xfff0;
3164 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3165 info->snd_context = stcb->asoc.def_send.sinfo_context;
3166 SCTP_TCB_UNLOCK(stcb);
3168 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3169 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3170 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3171 SCTP_INP_RLOCK(inp);
3172 info->snd_sid = inp->def_send.sinfo_stream;
3173 info->snd_flags = inp->def_send.sinfo_flags;
3174 info->snd_flags &= 0xfff0;
3175 info->snd_ppid = inp->def_send.sinfo_ppid;
3176 info->snd_context = inp->def_send.sinfo_context;
3177 SCTP_INP_RUNLOCK(inp);
3179 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3184 *optsize = sizeof(struct sctp_sndinfo);
3188 case SCTP_DEFAULT_PRINFO:
3190 struct sctp_default_prinfo *info;
3192 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3193 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3196 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3197 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3198 SCTP_TCB_UNLOCK(stcb);
3200 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3201 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3202 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3203 SCTP_INP_RLOCK(inp);
3204 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3205 info->pr_value = inp->def_send.sinfo_timetolive;
3206 SCTP_INP_RUNLOCK(inp);
3208 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3213 *optsize = sizeof(struct sctp_default_prinfo);
3217 case SCTP_PEER_ADDR_THLDS:
3219 struct sctp_paddrthlds *thlds;
3220 struct sctp_nets *net;
3221 struct sockaddr *addr;
3223 #if defined(INET) && defined(INET6)
3224 struct sockaddr_in sin_store;
3228 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3229 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3231 #if defined(INET) && defined(INET6)
3232 if (thlds->spt_address.ss_family == AF_INET6) {
3233 struct sockaddr_in6 *sin6;
3235 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3236 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3237 in6_sin6_2_sin(&sin_store, sin6);
3238 addr = (struct sockaddr *)&sin_store;
3240 addr = (struct sockaddr *)&thlds->spt_address;
3243 addr = (struct sockaddr *)&thlds->spt_address;
3246 addr = (struct sockaddr *)&thlds->spt_address;
3249 net = sctp_findnet(stcb, addr);
3252 * We increment here since
3253 * sctp_findassociation_ep_addr() wil do a
3254 * decrement if it finds the stcb as long as
3255 * the locked tcb (last argument) is NOT a
3259 SCTP_INP_INCR_REF(inp);
3260 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3262 SCTP_INP_DECR_REF(inp);
3265 if ((stcb != NULL) && (net == NULL)) {
3267 if (addr->sa_family == AF_INET) {
3268 struct sockaddr_in *sin;
3270 sin = (struct sockaddr_in *)addr;
3271 if (sin->sin_addr.s_addr != INADDR_ANY) {
3273 SCTP_TCB_UNLOCK(stcb);
3274 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3280 if (addr->sa_family == AF_INET6) {
3281 struct sockaddr_in6 *sin6;
3283 sin6 = (struct sockaddr_in6 *)addr;
3284 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3286 SCTP_TCB_UNLOCK(stcb);
3287 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3293 error = EAFNOSUPPORT;
3294 SCTP_TCB_UNLOCK(stcb);
3295 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3301 thlds->spt_pathmaxrxt = net->failure_threshold;
3302 thlds->spt_pathpfthld = net->pf_threshold;
3304 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3305 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3307 thlds->spt_assoc_id = sctp_get_associd(stcb);
3308 SCTP_TCB_UNLOCK(stcb);
3310 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3311 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3312 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3313 /* Use endpoint defaults */
3314 SCTP_INP_RLOCK(inp);
3315 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3316 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3317 SCTP_INP_RUNLOCK(inp);
3319 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3324 *optsize = sizeof(struct sctp_paddrthlds);
3328 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3330 struct sctp_udpencaps *encaps;
3331 struct sctp_nets *net;
3332 struct sockaddr *addr;
3334 #if defined(INET) && defined(INET6)
3335 struct sockaddr_in sin_store;
3339 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3340 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3342 #if defined(INET) && defined(INET6)
3343 if (encaps->sue_address.ss_family == AF_INET6) {
3344 struct sockaddr_in6 *sin6;
3346 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3347 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3348 in6_sin6_2_sin(&sin_store, sin6);
3349 addr = (struct sockaddr *)&sin_store;
3351 addr = (struct sockaddr *)&encaps->sue_address;
3354 addr = (struct sockaddr *)&encaps->sue_address;
3357 addr = (struct sockaddr *)&encaps->sue_address;
3360 net = sctp_findnet(stcb, addr);
3363 * We increment here since
3364 * sctp_findassociation_ep_addr() wil do a
3365 * decrement if it finds the stcb as long as
3366 * the locked tcb (last argument) is NOT a
3370 SCTP_INP_INCR_REF(inp);
3371 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3373 SCTP_INP_DECR_REF(inp);
3376 if ((stcb != NULL) && (net == NULL)) {
3378 if (addr->sa_family == AF_INET) {
3379 struct sockaddr_in *sin;
3381 sin = (struct sockaddr_in *)addr;
3382 if (sin->sin_addr.s_addr != INADDR_ANY) {
3384 SCTP_TCB_UNLOCK(stcb);
3385 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3391 if (addr->sa_family == AF_INET6) {
3392 struct sockaddr_in6 *sin6;
3394 sin6 = (struct sockaddr_in6 *)addr;
3395 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3397 SCTP_TCB_UNLOCK(stcb);
3398 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3404 error = EAFNOSUPPORT;
3405 SCTP_TCB_UNLOCK(stcb);
3406 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3412 encaps->sue_port = net->port;
3414 encaps->sue_port = stcb->asoc.port;
3416 SCTP_TCB_UNLOCK(stcb);
3418 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3419 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3420 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3421 SCTP_INP_RLOCK(inp);
3422 encaps->sue_port = inp->sctp_ep.port;
3423 SCTP_INP_RUNLOCK(inp);
3425 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3430 *optsize = sizeof(struct sctp_udpencaps);
3434 case SCTP_ECN_SUPPORTED:
3436 struct sctp_assoc_value *av;
3438 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3439 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3442 av->assoc_value = stcb->asoc.ecn_supported;
3443 SCTP_TCB_UNLOCK(stcb);
3445 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3446 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3447 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3448 SCTP_INP_RLOCK(inp);
3449 av->assoc_value = inp->ecn_supported;
3450 SCTP_INP_RUNLOCK(inp);
3452 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3457 *optsize = sizeof(struct sctp_assoc_value);
3461 case SCTP_PR_SUPPORTED:
3463 struct sctp_assoc_value *av;
3465 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3466 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3469 av->assoc_value = stcb->asoc.prsctp_supported;
3470 SCTP_TCB_UNLOCK(stcb);
3472 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3473 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3474 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3475 SCTP_INP_RLOCK(inp);
3476 av->assoc_value = inp->prsctp_supported;
3477 SCTP_INP_RUNLOCK(inp);
3479 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3484 *optsize = sizeof(struct sctp_assoc_value);
3488 case SCTP_AUTH_SUPPORTED:
3490 struct sctp_assoc_value *av;
3492 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3493 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3496 av->assoc_value = stcb->asoc.auth_supported;
3497 SCTP_TCB_UNLOCK(stcb);
3499 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3500 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3501 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3502 SCTP_INP_RLOCK(inp);
3503 av->assoc_value = inp->auth_supported;
3504 SCTP_INP_RUNLOCK(inp);
3506 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3511 *optsize = sizeof(struct sctp_assoc_value);
3515 case SCTP_ASCONF_SUPPORTED:
3517 struct sctp_assoc_value *av;
3519 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3520 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3523 av->assoc_value = stcb->asoc.asconf_supported;
3524 SCTP_TCB_UNLOCK(stcb);
3526 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3527 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3528 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3529 SCTP_INP_RLOCK(inp);
3530 av->assoc_value = inp->asconf_supported;
3531 SCTP_INP_RUNLOCK(inp);
3533 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3538 *optsize = sizeof(struct sctp_assoc_value);
3542 case SCTP_RECONFIG_SUPPORTED:
3544 struct sctp_assoc_value *av;
3546 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3547 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3550 av->assoc_value = stcb->asoc.reconfig_supported;
3551 SCTP_TCB_UNLOCK(stcb);
3553 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3554 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3555 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3556 SCTP_INP_RLOCK(inp);
3557 av->assoc_value = inp->reconfig_supported;
3558 SCTP_INP_RUNLOCK(inp);
3560 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3565 *optsize = sizeof(struct sctp_assoc_value);
3569 case SCTP_NRSACK_SUPPORTED:
3571 struct sctp_assoc_value *av;
3573 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3574 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3577 av->assoc_value = stcb->asoc.nrsack_supported;
3578 SCTP_TCB_UNLOCK(stcb);
3580 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3581 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3582 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3583 SCTP_INP_RLOCK(inp);
3584 av->assoc_value = inp->nrsack_supported;
3585 SCTP_INP_RUNLOCK(inp);
3587 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3592 *optsize = sizeof(struct sctp_assoc_value);
3596 case SCTP_PKTDROP_SUPPORTED:
3598 struct sctp_assoc_value *av;
3600 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3601 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3604 av->assoc_value = stcb->asoc.pktdrop_supported;
3605 SCTP_TCB_UNLOCK(stcb);
3607 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3608 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3609 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3610 SCTP_INP_RLOCK(inp);
3611 av->assoc_value = inp->pktdrop_supported;
3612 SCTP_INP_RUNLOCK(inp);
3614 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3619 *optsize = sizeof(struct sctp_assoc_value);
3623 case SCTP_ENABLE_STREAM_RESET:
3625 struct sctp_assoc_value *av;
3627 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3628 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3631 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3632 SCTP_TCB_UNLOCK(stcb);
3634 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3635 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3636 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3637 SCTP_INP_RLOCK(inp);
3638 av->assoc_value = (uint32_t) inp->local_strreset_support;
3639 SCTP_INP_RUNLOCK(inp);
3641 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3646 *optsize = sizeof(struct sctp_assoc_value);
3650 case SCTP_PR_STREAM_STATUS:
3652 struct sctp_prstatus *sprstat;
3656 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3657 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3659 sid = sprstat->sprstat_sid;
3660 policy = sprstat->sprstat_policy;
3661 #if defined(SCTP_DETAILED_STR_STATS)
3662 if ((stcb != NULL) &&
3663 (sid < stcb->asoc.streamoutcnt) &&
3664 (policy != SCTP_PR_SCTP_NONE) &&
3665 ((policy <= SCTP_PR_SCTP_MAX) ||
3666 (policy == SCTP_PR_SCTP_ALL))) {
3667 if (policy == SCTP_PR_SCTP_ALL) {
3668 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3669 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3671 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3672 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3675 if ((stcb != NULL) &&
3676 (sid < stcb->asoc.streamoutcnt) &&
3677 (policy == SCTP_PR_SCTP_ALL)) {
3678 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3679 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3681 SCTP_TCB_UNLOCK(stcb);
3682 *optsize = sizeof(struct sctp_prstatus);
3684 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3689 case SCTP_PR_ASSOC_STATUS:
3691 struct sctp_prstatus *sprstat;
3694 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3695 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3697 policy = sprstat->sprstat_policy;
3698 if ((stcb != NULL) &&
3699 (policy != SCTP_PR_SCTP_NONE) &&
3700 ((policy <= SCTP_PR_SCTP_MAX) ||
3701 (policy == SCTP_PR_SCTP_ALL))) {
3702 if (policy == SCTP_PR_SCTP_ALL) {
3703 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3704 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3706 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3707 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3709 SCTP_TCB_UNLOCK(stcb);
3710 *optsize = sizeof(struct sctp_prstatus);
3712 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3719 struct sctp_assoc_value *av;
3721 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3722 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3725 av->assoc_value = stcb->asoc.max_cwnd;
3726 SCTP_TCB_UNLOCK(stcb);
3728 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3729 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3730 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3731 SCTP_INP_RLOCK(inp);
3732 av->assoc_value = inp->max_cwnd;
3733 SCTP_INP_RUNLOCK(inp);
3735 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3740 *optsize = sizeof(struct sctp_assoc_value);
3745 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3746 error = ENOPROTOOPT;
3748 } /* end switch (sopt->sopt_name) */
3756 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3761 struct sctp_tcb *stcb = NULL;
3762 struct sctp_inpcb *inp = NULL;
3765 if (optval == NULL) {
3766 SCTP_PRINTF("optval is NULL\n");
3767 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3770 inp = (struct sctp_inpcb *)so->so_pcb;
3772 SCTP_PRINTF("inp is NULL?\n");
3773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3776 vrf_id = inp->def_vrf_id;
3781 case SCTP_AUTOCLOSE:
3782 case SCTP_AUTO_ASCONF:
3783 case SCTP_EXPLICIT_EOR:
3784 case SCTP_DISABLE_FRAGMENTS:
3785 case SCTP_USE_EXT_RCVINFO:
3786 case SCTP_I_WANT_MAPPED_V4_ADDR:
3787 /* copy in the option value */
3788 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3793 case SCTP_DISABLE_FRAGMENTS:
3794 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3796 case SCTP_AUTO_ASCONF:
3798 * NOTE: we don't really support this flag
3800 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3801 /* only valid for bound all sockets */
3802 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3804 /* forbidden by admin */
3805 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3808 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3810 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3814 case SCTP_EXPLICIT_EOR:
3815 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3817 case SCTP_USE_EXT_RCVINFO:
3818 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3820 case SCTP_I_WANT_MAPPED_V4_ADDR:
3821 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3822 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3824 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3829 set_opt = SCTP_PCB_FLAGS_NODELAY;
3831 case SCTP_AUTOCLOSE:
3832 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3833 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3834 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3837 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3839 * The value is in ticks. Note this does not effect
3840 * old associations, only new ones.
3842 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3845 SCTP_INP_WLOCK(inp);
3847 sctp_feature_on(inp, set_opt);
3849 sctp_feature_off(inp, set_opt);
3851 SCTP_INP_WUNLOCK(inp);
3853 case SCTP_REUSE_PORT:
3855 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3856 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3857 /* Can't set it after we are bound */
3861 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3862 /* Can't do this for a 1-m socket */
3867 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3869 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3872 case SCTP_PARTIAL_DELIVERY_POINT:
3876 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3877 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3878 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3882 inp->partial_delivery_point = *value;
3885 case SCTP_FRAGMENT_INTERLEAVE:
3886 /* not yet until we re-write sctp_recvmsg() */
3890 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3891 if (*level == SCTP_FRAG_LEVEL_2) {
3892 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3893 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3894 } else if (*level == SCTP_FRAG_LEVEL_1) {
3895 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3896 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3897 } else if (*level == SCTP_FRAG_LEVEL_0) {
3898 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3899 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3907 case SCTP_CMT_ON_OFF:
3908 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3909 struct sctp_assoc_value *av;
3911 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3912 if (av->assoc_value > SCTP_CMT_MAX) {
3913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3917 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3919 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3920 SCTP_TCB_UNLOCK(stcb);
3922 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3923 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3924 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3925 (av->assoc_id == SCTP_ALL_ASSOC)) {
3926 SCTP_INP_WLOCK(inp);
3927 inp->sctp_cmt_on_off = av->assoc_value;
3928 SCTP_INP_WUNLOCK(inp);
3930 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3931 (av->assoc_id == SCTP_ALL_ASSOC)) {
3932 SCTP_INP_RLOCK(inp);
3933 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3934 SCTP_TCB_LOCK(stcb);
3935 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3936 SCTP_TCB_UNLOCK(stcb);
3938 SCTP_INP_RUNLOCK(inp);
3942 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3943 error = ENOPROTOOPT;
3946 case SCTP_PLUGGABLE_CC:
3948 struct sctp_assoc_value *av;
3949 struct sctp_nets *net;
3951 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3952 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3953 (av->assoc_value != SCTP_CC_HSTCP) &&
3954 (av->assoc_value != SCTP_CC_HTCP) &&
3955 (av->assoc_value != SCTP_CC_RTCC)) {
3956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3960 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3962 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3963 stcb->asoc.congestion_control_module = av->assoc_value;
3964 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3965 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3966 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3969 SCTP_TCB_UNLOCK(stcb);
3971 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3972 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3973 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3974 (av->assoc_id == SCTP_ALL_ASSOC)) {
3975 SCTP_INP_WLOCK(inp);
3976 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3977 SCTP_INP_WUNLOCK(inp);
3979 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3980 (av->assoc_id == SCTP_ALL_ASSOC)) {
3981 SCTP_INP_RLOCK(inp);
3982 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3983 SCTP_TCB_LOCK(stcb);
3984 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3985 stcb->asoc.congestion_control_module = av->assoc_value;
3986 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3987 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3988 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3991 SCTP_TCB_UNLOCK(stcb);
3993 SCTP_INP_RUNLOCK(inp);
3998 case SCTP_CC_OPTION:
4000 struct sctp_cc_option *cc_opt;
4002 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4003 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4005 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4006 SCTP_INP_RLOCK(inp);
4007 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4008 SCTP_TCB_LOCK(stcb);
4009 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4010 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4012 SCTP_TCB_UNLOCK(stcb);
4014 SCTP_INP_RUNLOCK(inp);
4019 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4022 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4025 SCTP_TCB_UNLOCK(stcb);
4029 case SCTP_PLUGGABLE_SS:
4031 struct sctp_assoc_value *av;
4033 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4034 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4035 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4036 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4037 (av->assoc_value != SCTP_SS_PRIORITY) &&
4038 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4039 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4040 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4044 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4046 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4047 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4048 stcb->asoc.stream_scheduling_module = av->assoc_value;
4049 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4050 SCTP_TCB_UNLOCK(stcb);
4052 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4053 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4054 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4055 (av->assoc_id == SCTP_ALL_ASSOC)) {
4056 SCTP_INP_WLOCK(inp);
4057 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4058 SCTP_INP_WUNLOCK(inp);
4060 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4061 (av->assoc_id == SCTP_ALL_ASSOC)) {
4062 SCTP_INP_RLOCK(inp);
4063 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4064 SCTP_TCB_LOCK(stcb);
4065 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4066 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4067 stcb->asoc.stream_scheduling_module = av->assoc_value;
4068 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4069 SCTP_TCB_UNLOCK(stcb);
4071 SCTP_INP_RUNLOCK(inp);
4078 struct sctp_stream_value *av;
4080 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4081 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4083 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4084 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4085 av->stream_value) < 0)) {
4086 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4089 SCTP_TCB_UNLOCK(stcb);
4091 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4092 SCTP_INP_RLOCK(inp);
4093 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4094 SCTP_TCB_LOCK(stcb);
4095 if (av->stream_id < stcb->asoc.streamoutcnt) {
4096 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4098 &stcb->asoc.strmout[av->stream_id],
4101 SCTP_TCB_UNLOCK(stcb);
4103 SCTP_INP_RUNLOCK(inp);
4106 * Can't set stream value without
4109 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4115 case SCTP_CLR_STAT_LOG:
4116 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4121 struct sctp_assoc_value *av;
4123 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4124 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4127 stcb->asoc.context = av->assoc_value;
4128 SCTP_TCB_UNLOCK(stcb);
4130 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4131 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4132 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4133 (av->assoc_id == SCTP_ALL_ASSOC)) {
4134 SCTP_INP_WLOCK(inp);
4135 inp->sctp_context = av->assoc_value;
4136 SCTP_INP_WUNLOCK(inp);
4138 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4139 (av->assoc_id == SCTP_ALL_ASSOC)) {
4140 SCTP_INP_RLOCK(inp);
4141 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4142 SCTP_TCB_LOCK(stcb);
4143 stcb->asoc.context = av->assoc_value;
4144 SCTP_TCB_UNLOCK(stcb);
4146 SCTP_INP_RUNLOCK(inp);
4153 uint32_t *default_vrfid;
4155 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4156 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4157 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4161 inp->def_vrf_id = *default_vrfid;
4164 case SCTP_DEL_VRF_ID:
4166 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4170 case SCTP_ADD_VRF_ID:
4172 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4176 case SCTP_DELAYED_SACK:
4178 struct sctp_sack_info *sack;
4180 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4181 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4182 if (sack->sack_delay) {
4183 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4184 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4185 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4186 sack->sack_delay = TICKS_TO_MSEC(1);
4190 if (sack->sack_delay) {
4191 stcb->asoc.delayed_ack = sack->sack_delay;
4193 if (sack->sack_freq) {
4194 stcb->asoc.sack_freq = sack->sack_freq;
4196 SCTP_TCB_UNLOCK(stcb);
4198 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4199 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4200 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4201 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4202 SCTP_INP_WLOCK(inp);
4203 if (sack->sack_delay) {
4204 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4206 if (sack->sack_freq) {
4207 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4209 SCTP_INP_WUNLOCK(inp);
4211 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4212 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4213 SCTP_INP_RLOCK(inp);
4214 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4215 SCTP_TCB_LOCK(stcb);
4216 if (sack->sack_delay) {
4217 stcb->asoc.delayed_ack = sack->sack_delay;
4219 if (sack->sack_freq) {
4220 stcb->asoc.sack_freq = sack->sack_freq;
4222 SCTP_TCB_UNLOCK(stcb);
4224 SCTP_INP_RUNLOCK(inp);
4229 case SCTP_AUTH_CHUNK:
4231 struct sctp_authchunk *sauth;
4233 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4235 SCTP_INP_WLOCK(inp);
4236 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4237 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4240 SCTP_INP_WUNLOCK(inp);
4245 struct sctp_authkey *sca;
4246 struct sctp_keyhead *shared_keys;
4247 sctp_sharedkey_t *shared_key;
4248 sctp_key_t *key = NULL;
4251 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4252 if (sca->sca_keylength == 0) {
4253 size = optsize - sizeof(struct sctp_authkey);
4255 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4256 size = sca->sca_keylength;
4258 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4263 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4266 shared_keys = &stcb->asoc.shared_keys;
4267 /* clear the cached keys for this key id */
4268 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4270 * create the new shared key and
4274 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4276 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4278 SCTP_TCB_UNLOCK(stcb);
4282 shared_key = sctp_alloc_sharedkey();
4283 if (shared_key == NULL) {
4285 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4287 SCTP_TCB_UNLOCK(stcb);
4290 shared_key->key = key;
4291 shared_key->keyid = sca->sca_keynumber;
4292 error = sctp_insert_sharedkey(shared_keys, shared_key);
4293 SCTP_TCB_UNLOCK(stcb);
4295 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4296 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4297 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4298 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4299 SCTP_INP_WLOCK(inp);
4300 shared_keys = &inp->sctp_ep.shared_keys;
4302 * clear the cached keys on all
4303 * assocs for this key id
4305 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4307 * create the new shared key and
4311 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4313 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4315 SCTP_INP_WUNLOCK(inp);
4319 shared_key = sctp_alloc_sharedkey();
4320 if (shared_key == NULL) {
4322 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4324 SCTP_INP_WUNLOCK(inp);
4327 shared_key->key = key;
4328 shared_key->keyid = sca->sca_keynumber;
4329 error = sctp_insert_sharedkey(shared_keys, shared_key);
4330 SCTP_INP_WUNLOCK(inp);
4332 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4333 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4334 SCTP_INP_RLOCK(inp);
4335 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4336 SCTP_TCB_LOCK(stcb);
4337 shared_keys = &stcb->asoc.shared_keys;
4339 * clear the cached keys for
4342 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4344 * create the new shared key
4345 * and insert/replace it
4348 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4350 SCTP_TCB_UNLOCK(stcb);
4354 shared_key = sctp_alloc_sharedkey();
4355 if (shared_key == NULL) {
4357 SCTP_TCB_UNLOCK(stcb);
4360 shared_key->key = key;
4361 shared_key->keyid = sca->sca_keynumber;
4362 error = sctp_insert_sharedkey(shared_keys, shared_key);
4363 SCTP_TCB_UNLOCK(stcb);
4365 SCTP_INP_RUNLOCK(inp);
4370 case SCTP_HMAC_IDENT:
4372 struct sctp_hmacalgo *shmac;
4373 sctp_hmaclist_t *hmaclist;
4377 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4378 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4379 (shmac->shmac_number_of_idents > 0xffff)) {
4380 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4384 hmaclist = sctp_alloc_hmaclist((uint16_t) shmac->shmac_number_of_idents);
4385 if (hmaclist == NULL) {
4386 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4390 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4391 hmacid = shmac->shmac_idents[i];
4392 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4393 /* invalid HMACs were found */ ;
4394 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4396 sctp_free_hmaclist(hmaclist);
4397 goto sctp_set_hmac_done;
4400 for (i = 0; i < hmaclist->num_algo; i++) {
4401 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4402 /* already in list */
4406 if (i == hmaclist->num_algo) {
4407 /* not found in list */
4408 sctp_free_hmaclist(hmaclist);
4409 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4413 /* set it on the endpoint */
4414 SCTP_INP_WLOCK(inp);
4415 if (inp->sctp_ep.local_hmacs)
4416 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4417 inp->sctp_ep.local_hmacs = hmaclist;
4418 SCTP_INP_WUNLOCK(inp);
4422 case SCTP_AUTH_ACTIVE_KEY:
4424 struct sctp_authkeyid *scact;
4426 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4427 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4429 /* set the active key on the right place */
4431 /* set the active key on the assoc */
4432 if (sctp_auth_setactivekey(stcb,
4433 scact->scact_keynumber)) {
4434 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4435 SCTP_FROM_SCTP_USRREQ,
4439 SCTP_TCB_UNLOCK(stcb);
4441 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4442 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4443 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4444 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4445 SCTP_INP_WLOCK(inp);
4446 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4447 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4450 SCTP_INP_WUNLOCK(inp);
4452 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4453 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4454 SCTP_INP_RLOCK(inp);
4455 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4456 SCTP_TCB_LOCK(stcb);
4457 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4458 SCTP_TCB_UNLOCK(stcb);
4460 SCTP_INP_RUNLOCK(inp);
4465 case SCTP_AUTH_DELETE_KEY:
4467 struct sctp_authkeyid *scdel;
4469 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4470 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4472 /* delete the key from the right place */
4474 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4475 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4478 SCTP_TCB_UNLOCK(stcb);
4480 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4481 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4482 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4483 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4484 SCTP_INP_WLOCK(inp);
4485 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4486 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4489 SCTP_INP_WUNLOCK(inp);
4491 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4492 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4493 SCTP_INP_RLOCK(inp);
4494 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4495 SCTP_TCB_LOCK(stcb);
4496 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4497 SCTP_TCB_UNLOCK(stcb);
4499 SCTP_INP_RUNLOCK(inp);
4504 case SCTP_AUTH_DEACTIVATE_KEY:
4506 struct sctp_authkeyid *keyid;
4508 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4509 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4511 /* deactivate the key from the right place */
4513 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4514 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4517 SCTP_TCB_UNLOCK(stcb);
4519 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4520 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4521 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4522 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4523 SCTP_INP_WLOCK(inp);
4524 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4525 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4528 SCTP_INP_WUNLOCK(inp);
4530 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4531 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4532 SCTP_INP_RLOCK(inp);
4533 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4534 SCTP_TCB_LOCK(stcb);
4535 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4536 SCTP_TCB_UNLOCK(stcb);
4538 SCTP_INP_RUNLOCK(inp);
4543 case SCTP_ENABLE_STREAM_RESET:
4545 struct sctp_assoc_value *av;
4547 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4548 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4549 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4553 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4555 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4556 SCTP_TCB_UNLOCK(stcb);
4558 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4559 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4560 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4561 (av->assoc_id == SCTP_ALL_ASSOC)) {
4562 SCTP_INP_WLOCK(inp);
4563 inp->local_strreset_support = (uint8_t) av->assoc_value;
4564 SCTP_INP_WUNLOCK(inp);
4566 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4567 (av->assoc_id == SCTP_ALL_ASSOC)) {
4568 SCTP_INP_RLOCK(inp);
4569 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4570 SCTP_TCB_LOCK(stcb);
4571 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4572 SCTP_TCB_UNLOCK(stcb);
4574 SCTP_INP_RUNLOCK(inp);
4579 case SCTP_RESET_STREAMS:
4581 struct sctp_reset_streams *strrst;
4582 int i, send_out = 0;
4585 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4586 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4588 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4592 if (stcb->asoc.reconfig_supported == 0) {
4594 * Peer does not support the chunk type.
4596 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4598 SCTP_TCB_UNLOCK(stcb);
4601 if (sizeof(struct sctp_reset_streams) +
4602 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4604 SCTP_TCB_UNLOCK(stcb);
4607 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4609 if (stcb->asoc.stream_reset_outstanding) {
4610 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4612 SCTP_TCB_UNLOCK(stcb);
4616 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4619 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4620 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4622 SCTP_TCB_UNLOCK(stcb);
4625 if ((send_in == 0) && (send_out == 0)) {
4626 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4628 SCTP_TCB_UNLOCK(stcb);
4631 for (i = 0; i < strrst->srs_number_streams; i++) {
4633 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4634 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4639 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4640 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4646 SCTP_TCB_UNLOCK(stcb);
4653 if (strrst->srs_number_streams) {
4654 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4655 strm = strrst->srs_stream_list[i];
4656 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4657 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4663 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4664 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4665 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4672 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4673 strrst->srs_stream_list,
4674 send_in, 0, 0, 0, 0, 0);
4676 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4679 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4682 * For outgoing streams don't report any
4683 * problems in sending the request to the
4684 * application. XXX: Double check resetting
4689 SCTP_TCB_UNLOCK(stcb);
4692 case SCTP_ADD_STREAMS:
4694 struct sctp_add_streams *stradd;
4695 uint8_t addstream = 0;
4696 uint16_t add_o_strmcnt = 0;
4697 uint16_t add_i_strmcnt = 0;
4699 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4700 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4702 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4706 if (stcb->asoc.reconfig_supported == 0) {
4708 * Peer does not support the chunk type.
4710 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4712 SCTP_TCB_UNLOCK(stcb);
4715 if (stcb->asoc.stream_reset_outstanding) {
4716 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4718 SCTP_TCB_UNLOCK(stcb);
4721 if ((stradd->sas_outstrms == 0) &&
4722 (stradd->sas_instrms == 0)) {
4726 if (stradd->sas_outstrms) {
4728 /* We allocate here */
4729 add_o_strmcnt = stradd->sas_outstrms;
4730 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4731 /* You can't have more than 64k */
4736 if (stradd->sas_instrms) {
4741 * We allocate inside
4742 * sctp_send_str_reset_req()
4744 add_i_strmcnt = stradd->sas_instrms;
4745 cnt = add_i_strmcnt;
4746 cnt += stcb->asoc.streamincnt;
4747 if (cnt > 0x0000ffff) {
4748 /* You can't have more than 64k */
4752 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4753 /* More than you are allowed */
4758 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4759 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4761 SCTP_TCB_UNLOCK(stcb);
4764 case SCTP_RESET_ASSOC:
4769 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4770 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4772 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4776 if (stcb->asoc.reconfig_supported == 0) {
4778 * Peer does not support the chunk type.
4780 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4782 SCTP_TCB_UNLOCK(stcb);
4785 if (stcb->asoc.stream_reset_outstanding) {
4786 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4788 SCTP_TCB_UNLOCK(stcb);
4792 * Is there any data pending in the send or sent
4795 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4796 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4799 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4800 SCTP_TCB_UNLOCK(stcb);
4803 /* Do any streams have data queued? */
4804 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4805 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4809 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4810 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4811 SCTP_TCB_UNLOCK(stcb);
4814 case SCTP_CONNECT_X:
4815 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4816 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4820 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4822 case SCTP_CONNECT_X_DELAYED:
4823 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4824 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4828 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4830 case SCTP_CONNECT_X_COMPLETE:
4832 struct sockaddr *sa;
4834 /* FIXME MT: check correct? */
4835 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4838 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4839 SCTP_INP_RLOCK(inp);
4840 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4842 SCTP_TCB_LOCK(stcb);
4844 SCTP_INP_RUNLOCK(inp);
4847 * We increment here since
4848 * sctp_findassociation_ep_addr() wil do a
4849 * decrement if it finds the stcb as long as
4850 * the locked tcb (last argument) is NOT a
4853 SCTP_INP_INCR_REF(inp);
4854 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4856 SCTP_INP_DECR_REF(inp);
4861 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4865 if (stcb->asoc.delayed_connection == 1) {
4866 stcb->asoc.delayed_connection = 0;
4867 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4868 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4869 stcb->asoc.primary_destination,
4870 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4871 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4874 * already expired or did not use delayed
4877 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4880 SCTP_TCB_UNLOCK(stcb);
4883 case SCTP_MAX_BURST:
4885 struct sctp_assoc_value *av;
4887 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4888 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4891 stcb->asoc.max_burst = av->assoc_value;
4892 SCTP_TCB_UNLOCK(stcb);
4894 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4895 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4896 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4897 (av->assoc_id == SCTP_ALL_ASSOC)) {
4898 SCTP_INP_WLOCK(inp);
4899 inp->sctp_ep.max_burst = av->assoc_value;
4900 SCTP_INP_WUNLOCK(inp);
4902 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4903 (av->assoc_id == SCTP_ALL_ASSOC)) {
4904 SCTP_INP_RLOCK(inp);
4905 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4906 SCTP_TCB_LOCK(stcb);
4907 stcb->asoc.max_burst = av->assoc_value;
4908 SCTP_TCB_UNLOCK(stcb);
4910 SCTP_INP_RUNLOCK(inp);
4917 struct sctp_assoc_value *av;
4920 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4921 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4923 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4924 ovh = SCTP_MED_OVERHEAD;
4926 ovh = SCTP_MED_V4_OVERHEAD;
4929 if (av->assoc_value) {
4930 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4932 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4934 SCTP_TCB_UNLOCK(stcb);
4936 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4937 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4938 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4939 SCTP_INP_WLOCK(inp);
4941 * FIXME MT: I think this is not in
4942 * tune with the API ID
4944 if (av->assoc_value) {
4945 inp->sctp_frag_point = (av->assoc_value + ovh);
4947 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4949 SCTP_INP_WUNLOCK(inp);
4951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4959 struct sctp_event_subscribe *events;
4961 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4963 SCTP_INP_WLOCK(inp);
4964 if (events->sctp_data_io_event) {
4965 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4967 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4970 if (events->sctp_association_event) {
4971 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4973 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4976 if (events->sctp_address_event) {
4977 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4979 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4982 if (events->sctp_send_failure_event) {
4983 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4985 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4988 if (events->sctp_peer_error_event) {
4989 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4991 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4994 if (events->sctp_shutdown_event) {
4995 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4997 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5000 if (events->sctp_partial_delivery_event) {
5001 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5003 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5006 if (events->sctp_adaptation_layer_event) {
5007 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5009 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5012 if (events->sctp_authentication_event) {
5013 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5015 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5018 if (events->sctp_sender_dry_event) {
5019 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5021 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5024 if (events->sctp_stream_reset_event) {
5025 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5027 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5029 SCTP_INP_WUNLOCK(inp);
5031 SCTP_INP_RLOCK(inp);
5032 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5033 SCTP_TCB_LOCK(stcb);
5034 if (events->sctp_association_event) {
5035 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5037 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5039 if (events->sctp_address_event) {
5040 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5042 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5044 if (events->sctp_send_failure_event) {
5045 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5047 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5049 if (events->sctp_peer_error_event) {
5050 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5052 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5054 if (events->sctp_shutdown_event) {
5055 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5057 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5059 if (events->sctp_partial_delivery_event) {
5060 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5062 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5064 if (events->sctp_adaptation_layer_event) {
5065 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5067 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5069 if (events->sctp_authentication_event) {
5070 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5072 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5074 if (events->sctp_sender_dry_event) {
5075 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5077 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5079 if (events->sctp_stream_reset_event) {
5080 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5082 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5084 SCTP_TCB_UNLOCK(stcb);
5087 * Send up the sender dry event only for 1-to-1
5090 if (events->sctp_sender_dry_event) {
5091 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5092 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5093 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5095 SCTP_TCB_LOCK(stcb);
5096 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5097 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5098 (stcb->asoc.stream_queue_cnt == 0)) {
5099 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5101 SCTP_TCB_UNLOCK(stcb);
5105 SCTP_INP_RUNLOCK(inp);
5108 case SCTP_ADAPTATION_LAYER:
5110 struct sctp_setadaptation *adap_bits;
5112 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5113 SCTP_INP_WLOCK(inp);
5114 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5115 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5116 SCTP_INP_WUNLOCK(inp);
5120 case SCTP_SET_INITIAL_DBG_SEQ:
5124 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5125 SCTP_INP_WLOCK(inp);
5126 inp->sctp_ep.initial_sequence_debug = *vvv;
5127 SCTP_INP_WUNLOCK(inp);
5131 case SCTP_DEFAULT_SEND_PARAM:
5133 struct sctp_sndrcvinfo *s_info;
5135 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5136 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5139 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5140 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5142 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5145 SCTP_TCB_UNLOCK(stcb);
5147 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5148 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5149 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5150 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5151 SCTP_INP_WLOCK(inp);
5152 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5153 SCTP_INP_WUNLOCK(inp);
5155 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5156 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5157 SCTP_INP_RLOCK(inp);
5158 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5159 SCTP_TCB_LOCK(stcb);
5160 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5161 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5163 SCTP_TCB_UNLOCK(stcb);
5165 SCTP_INP_RUNLOCK(inp);
5170 case SCTP_PEER_ADDR_PARAMS:
5172 struct sctp_paddrparams *paddrp;
5173 struct sctp_nets *net;
5174 struct sockaddr *addr;
5176 #if defined(INET) && defined(INET6)
5177 struct sockaddr_in sin_store;
5181 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5182 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5184 #if defined(INET) && defined(INET6)
5185 if (paddrp->spp_address.ss_family == AF_INET6) {
5186 struct sockaddr_in6 *sin6;
5188 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5189 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5190 in6_sin6_2_sin(&sin_store, sin6);
5191 addr = (struct sockaddr *)&sin_store;
5193 addr = (struct sockaddr *)&paddrp->spp_address;
5196 addr = (struct sockaddr *)&paddrp->spp_address;
5199 addr = (struct sockaddr *)&paddrp->spp_address;
5202 net = sctp_findnet(stcb, addr);
5205 * We increment here since
5206 * sctp_findassociation_ep_addr() wil do a
5207 * decrement if it finds the stcb as long as
5208 * the locked tcb (last argument) is NOT a
5212 SCTP_INP_INCR_REF(inp);
5213 stcb = sctp_findassociation_ep_addr(&inp, addr,
5216 SCTP_INP_DECR_REF(inp);
5219 if ((stcb != NULL) && (net == NULL)) {
5221 if (addr->sa_family == AF_INET) {
5223 struct sockaddr_in *sin;
5225 sin = (struct sockaddr_in *)addr;
5226 if (sin->sin_addr.s_addr != INADDR_ANY) {
5227 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5228 SCTP_TCB_UNLOCK(stcb);
5235 if (addr->sa_family == AF_INET6) {
5236 struct sockaddr_in6 *sin6;
5238 sin6 = (struct sockaddr_in6 *)addr;
5239 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5240 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5241 SCTP_TCB_UNLOCK(stcb);
5248 error = EAFNOSUPPORT;
5249 SCTP_TCB_UNLOCK(stcb);
5250 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5255 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5257 SCTP_TCB_UNLOCK(stcb);
5258 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5261 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5263 SCTP_TCB_UNLOCK(stcb);
5264 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5268 /************************TCB SPECIFIC SET ******************/
5270 /************************NET SPECIFIC SET ******************/
5271 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5272 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5273 !(net->dest_state & SCTP_ADDR_NOHB)) {
5274 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5275 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5277 net->dest_state |= SCTP_ADDR_NOHB;
5279 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5280 if (paddrp->spp_hbinterval) {
5281 net->heart_beat_delay = paddrp->spp_hbinterval;
5282 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5283 net->heart_beat_delay = 0;
5285 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5286 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5287 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5288 net->dest_state &= ~SCTP_ADDR_NOHB;
5290 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5292 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5293 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5294 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5296 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5297 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5298 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5299 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5301 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5302 net->mtu = paddrp->spp_pathmtu;
5303 switch (net->ro._l_addr.sa.sa_family) {
5306 net->mtu += SCTP_MIN_V4_OVERHEAD;
5311 net->mtu += SCTP_MIN_OVERHEAD;
5317 if (net->mtu < stcb->asoc.smallest_mtu) {
5318 sctp_pathmtu_adjustment(stcb, net->mtu);
5321 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5322 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5323 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5325 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5327 if (paddrp->spp_pathmaxrxt) {
5328 if (net->dest_state & SCTP_ADDR_PF) {
5329 if (net->error_count > paddrp->spp_pathmaxrxt) {
5330 net->dest_state &= ~SCTP_ADDR_PF;
5333 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5334 (net->error_count > net->pf_threshold)) {
5335 net->dest_state |= SCTP_ADDR_PF;
5336 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5337 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5338 stcb->sctp_ep, stcb, net,
5339 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5340 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5343 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5344 if (net->error_count > paddrp->spp_pathmaxrxt) {
5345 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5346 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5349 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5350 net->dest_state |= SCTP_ADDR_REACHABLE;
5351 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5354 net->failure_threshold = paddrp->spp_pathmaxrxt;
5356 if (paddrp->spp_flags & SPP_DSCP) {
5357 net->dscp = paddrp->spp_dscp & 0xfc;
5361 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5362 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5363 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5364 net->flowlabel |= 0x80000000;
5369 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5370 if (paddrp->spp_pathmaxrxt != 0) {
5371 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5372 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5373 if (net->dest_state & SCTP_ADDR_PF) {
5374 if (net->error_count > paddrp->spp_pathmaxrxt) {
5375 net->dest_state &= ~SCTP_ADDR_PF;
5378 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5379 (net->error_count > net->pf_threshold)) {
5380 net->dest_state |= SCTP_ADDR_PF;
5381 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5382 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5383 stcb->sctp_ep, stcb, net,
5384 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5385 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5388 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5389 if (net->error_count > paddrp->spp_pathmaxrxt) {
5390 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5391 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5394 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5395 net->dest_state |= SCTP_ADDR_REACHABLE;
5396 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5399 net->failure_threshold = paddrp->spp_pathmaxrxt;
5402 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5403 if (paddrp->spp_hbinterval != 0) {
5404 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5405 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5406 stcb->asoc.heart_beat_delay = 0;
5408 /* Turn back on the timer */
5409 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5410 if (paddrp->spp_hbinterval != 0) {
5411 net->heart_beat_delay = paddrp->spp_hbinterval;
5412 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5413 net->heart_beat_delay = 0;
5415 if (net->dest_state & SCTP_ADDR_NOHB) {
5416 net->dest_state &= ~SCTP_ADDR_NOHB;
5418 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5419 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5420 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5422 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5424 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5425 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5426 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5427 net->dest_state |= SCTP_ADDR_NOHB;
5428 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5429 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5431 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5435 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5437 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5438 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5439 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5440 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5441 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5443 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5444 net->mtu = paddrp->spp_pathmtu;
5445 switch (net->ro._l_addr.sa.sa_family) {
5448 net->mtu += SCTP_MIN_V4_OVERHEAD;
5453 net->mtu += SCTP_MIN_OVERHEAD;
5459 if (net->mtu < stcb->asoc.smallest_mtu) {
5460 sctp_pathmtu_adjustment(stcb, net->mtu);
5463 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5465 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5466 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5467 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5468 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5470 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5472 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5474 if (paddrp->spp_flags & SPP_DSCP) {
5475 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5476 net->dscp = paddrp->spp_dscp & 0xfc;
5479 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5480 stcb->asoc.default_dscp |= 0x01;
5483 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5484 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5485 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5486 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5487 net->flowlabel |= 0x80000000;
5490 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5491 stcb->asoc.default_flowlabel |= 0x80000000;
5495 SCTP_TCB_UNLOCK(stcb);
5497 /************************NO TCB, SET TO default stuff ******************/
5498 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5499 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5500 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5501 SCTP_INP_WLOCK(inp);
5503 * For the TOS/FLOWLABEL stuff you
5504 * set it with the options on the
5507 if (paddrp->spp_pathmaxrxt != 0) {
5508 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5510 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5511 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5512 else if (paddrp->spp_hbinterval != 0) {
5513 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5514 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5515 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5517 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5518 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5519 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5520 } else if (paddrp->spp_hbinterval) {
5521 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5523 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5524 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5525 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5527 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5528 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5529 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5530 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5532 if (paddrp->spp_flags & SPP_DSCP) {
5533 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5534 inp->sctp_ep.default_dscp |= 0x01;
5537 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5538 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5539 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5540 inp->sctp_ep.default_flowlabel |= 0x80000000;
5544 SCTP_INP_WUNLOCK(inp);
5546 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5554 struct sctp_rtoinfo *srto;
5555 uint32_t new_init, new_min, new_max;
5557 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5558 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5561 if (srto->srto_initial)
5562 new_init = srto->srto_initial;
5564 new_init = stcb->asoc.initial_rto;
5566 new_max = srto->srto_max;
5568 new_max = stcb->asoc.maxrto;
5570 new_min = srto->srto_min;
5572 new_min = stcb->asoc.minrto;
5573 if ((new_min <= new_init) && (new_init <= new_max)) {
5574 stcb->asoc.initial_rto = new_init;
5575 stcb->asoc.maxrto = new_max;
5576 stcb->asoc.minrto = new_min;
5578 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5581 SCTP_TCB_UNLOCK(stcb);
5583 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5584 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5585 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5586 SCTP_INP_WLOCK(inp);
5587 if (srto->srto_initial)
5588 new_init = srto->srto_initial;
5590 new_init = inp->sctp_ep.initial_rto;
5592 new_max = srto->srto_max;
5594 new_max = inp->sctp_ep.sctp_maxrto;
5596 new_min = srto->srto_min;
5598 new_min = inp->sctp_ep.sctp_minrto;
5599 if ((new_min <= new_init) && (new_init <= new_max)) {
5600 inp->sctp_ep.initial_rto = new_init;
5601 inp->sctp_ep.sctp_maxrto = new_max;
5602 inp->sctp_ep.sctp_minrto = new_min;
5604 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5607 SCTP_INP_WUNLOCK(inp);
5609 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5615 case SCTP_ASSOCINFO:
5617 struct sctp_assocparams *sasoc;
5619 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5620 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5621 if (sasoc->sasoc_cookie_life) {
5622 /* boundary check the cookie life */
5623 if (sasoc->sasoc_cookie_life < 1000)
5624 sasoc->sasoc_cookie_life = 1000;
5625 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5626 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5630 if (sasoc->sasoc_asocmaxrxt)
5631 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5632 if (sasoc->sasoc_cookie_life) {
5633 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5635 SCTP_TCB_UNLOCK(stcb);
5637 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5638 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5639 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5640 SCTP_INP_WLOCK(inp);
5641 if (sasoc->sasoc_asocmaxrxt)
5642 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5643 if (sasoc->sasoc_cookie_life) {
5644 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5646 SCTP_INP_WUNLOCK(inp);
5648 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5656 struct sctp_initmsg *sinit;
5658 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5659 SCTP_INP_WLOCK(inp);
5660 if (sinit->sinit_num_ostreams)
5661 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5663 if (sinit->sinit_max_instreams)
5664 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5666 if (sinit->sinit_max_attempts)
5667 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5669 if (sinit->sinit_max_init_timeo)
5670 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5671 SCTP_INP_WUNLOCK(inp);
5674 case SCTP_PRIMARY_ADDR:
5676 struct sctp_setprim *spa;
5677 struct sctp_nets *net;
5678 struct sockaddr *addr;
5680 #if defined(INET) && defined(INET6)
5681 struct sockaddr_in sin_store;
5685 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5686 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5688 #if defined(INET) && defined(INET6)
5689 if (spa->ssp_addr.ss_family == AF_INET6) {
5690 struct sockaddr_in6 *sin6;
5692 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5693 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5694 in6_sin6_2_sin(&sin_store, sin6);
5695 addr = (struct sockaddr *)&sin_store;
5697 addr = (struct sockaddr *)&spa->ssp_addr;
5700 addr = (struct sockaddr *)&spa->ssp_addr;
5703 addr = (struct sockaddr *)&spa->ssp_addr;
5706 net = sctp_findnet(stcb, addr);
5709 * We increment here since
5710 * sctp_findassociation_ep_addr() wil do a
5711 * decrement if it finds the stcb as long as
5712 * the locked tcb (last argument) is NOT a
5716 SCTP_INP_INCR_REF(inp);
5717 stcb = sctp_findassociation_ep_addr(&inp, addr,
5720 SCTP_INP_DECR_REF(inp);
5724 if ((stcb != NULL) && (net != NULL)) {
5725 if (net != stcb->asoc.primary_destination) {
5726 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5727 /* Ok we need to set it */
5728 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5729 if ((stcb->asoc.alternate) &&
5730 (!(net->dest_state & SCTP_ADDR_PF)) &&
5731 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5732 sctp_free_remote_addr(stcb->asoc.alternate);
5733 stcb->asoc.alternate = NULL;
5736 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5740 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5745 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5749 SCTP_TCB_UNLOCK(stcb);
5753 case SCTP_SET_DYNAMIC_PRIMARY:
5755 union sctp_sockstore *ss;
5757 error = priv_check(curthread,
5758 PRIV_NETINET_RESERVEDPORT);
5762 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5763 /* SUPER USER CHECK? */
5764 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5767 case SCTP_SET_PEER_PRIMARY_ADDR:
5769 struct sctp_setpeerprim *sspp;
5770 struct sockaddr *addr;
5772 #if defined(INET) && defined(INET6)
5773 struct sockaddr_in sin_store;
5777 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5778 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5780 struct sctp_ifa *ifa;
5782 #if defined(INET) && defined(INET6)
5783 if (sspp->sspp_addr.ss_family == AF_INET6) {
5784 struct sockaddr_in6 *sin6;
5786 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5787 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5788 in6_sin6_2_sin(&sin_store, sin6);
5789 addr = (struct sockaddr *)&sin_store;
5791 addr = (struct sockaddr *)&sspp->sspp_addr;
5794 addr = (struct sockaddr *)&sspp->sspp_addr;
5797 addr = (struct sockaddr *)&sspp->sspp_addr;
5799 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5801 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5805 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5807 * Must validate the ifa found is in
5810 struct sctp_laddr *laddr;
5813 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5814 if (laddr->ifa == NULL) {
5815 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5819 if (laddr->ifa == ifa) {
5825 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5830 switch (addr->sa_family) {
5834 struct sockaddr_in *sin;
5836 sin = (struct sockaddr_in *)addr;
5837 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5838 &sin->sin_addr) != 0) {
5839 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5849 struct sockaddr_in6 *sin6;
5851 sin6 = (struct sockaddr_in6 *)addr;
5852 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5853 &sin6->sin6_addr) != 0) {
5854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5862 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5867 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5868 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5871 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5873 SCTP_TCB_UNLOCK(stcb);
5875 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5880 case SCTP_BINDX_ADD_ADDR:
5882 struct sctp_getaddresses *addrs;
5885 td = (struct thread *)p;
5886 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5889 if (addrs->addr->sa_family == AF_INET) {
5890 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5895 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5896 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5902 if (addrs->addr->sa_family == AF_INET6) {
5903 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5904 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5908 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5909 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5910 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5916 error = EAFNOSUPPORT;
5919 sctp_bindx_add_address(so, inp, addrs->addr,
5920 addrs->sget_assoc_id, vrf_id,
5924 case SCTP_BINDX_REM_ADDR:
5926 struct sctp_getaddresses *addrs;
5929 td = (struct thread *)p;
5931 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5933 if (addrs->addr->sa_family == AF_INET) {
5934 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5935 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5939 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5940 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5946 if (addrs->addr->sa_family == AF_INET6) {
5947 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5953 (error = prison_local_ip6(td->td_ucred,
5954 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5955 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5956 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5962 error = EAFNOSUPPORT;
5965 sctp_bindx_delete_address(inp, addrs->addr,
5966 addrs->sget_assoc_id, vrf_id,
5972 struct sctp_event *event;
5973 uint32_t event_type;
5975 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5976 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5977 switch (event->se_type) {
5978 case SCTP_ASSOC_CHANGE:
5979 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5981 case SCTP_PEER_ADDR_CHANGE:
5982 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5984 case SCTP_REMOTE_ERROR:
5985 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5987 case SCTP_SEND_FAILED:
5988 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5990 case SCTP_SHUTDOWN_EVENT:
5991 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5993 case SCTP_ADAPTATION_INDICATION:
5994 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5996 case SCTP_PARTIAL_DELIVERY_EVENT:
5997 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5999 case SCTP_AUTHENTICATION_EVENT:
6000 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6002 case SCTP_STREAM_RESET_EVENT:
6003 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6005 case SCTP_SENDER_DRY_EVENT:
6006 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6008 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6010 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6013 case SCTP_ASSOC_RESET_EVENT:
6014 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6016 case SCTP_STREAM_CHANGE_EVENT:
6017 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6019 case SCTP_SEND_FAILED_EVENT:
6020 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6024 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6028 if (event_type > 0) {
6031 sctp_stcb_feature_on(inp, stcb, event_type);
6032 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6033 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6034 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6035 (stcb->asoc.stream_queue_cnt == 0)) {
6036 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6040 sctp_stcb_feature_off(inp, stcb, event_type);
6042 SCTP_TCB_UNLOCK(stcb);
6045 * We don't want to send up a storm
6046 * of events, so return an error for
6049 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6050 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6051 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6052 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6053 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6054 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6058 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6059 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6060 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6061 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6062 SCTP_INP_WLOCK(inp);
6064 sctp_feature_on(inp, event_type);
6066 sctp_feature_off(inp, event_type);
6068 SCTP_INP_WUNLOCK(inp);
6070 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6071 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6072 SCTP_INP_RLOCK(inp);
6073 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6074 SCTP_TCB_LOCK(stcb);
6076 sctp_stcb_feature_on(inp, stcb, event_type);
6078 sctp_stcb_feature_off(inp, stcb, event_type);
6080 SCTP_TCB_UNLOCK(stcb);
6082 SCTP_INP_RUNLOCK(inp);
6088 case SCTP_RECVRCVINFO:
6092 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6093 SCTP_INP_WLOCK(inp);
6095 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6097 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6099 SCTP_INP_WUNLOCK(inp);
6102 case SCTP_RECVNXTINFO:
6106 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6107 SCTP_INP_WLOCK(inp);
6109 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6111 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6113 SCTP_INP_WUNLOCK(inp);
6116 case SCTP_DEFAULT_SNDINFO:
6118 struct sctp_sndinfo *info;
6121 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6122 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6125 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6126 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6127 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6128 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6129 stcb->asoc.def_send.sinfo_flags |= policy;
6130 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6131 stcb->asoc.def_send.sinfo_context = info->snd_context;
6133 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6136 SCTP_TCB_UNLOCK(stcb);
6138 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6139 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6140 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6141 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6142 SCTP_INP_WLOCK(inp);
6143 inp->def_send.sinfo_stream = info->snd_sid;
6144 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6145 inp->def_send.sinfo_flags = info->snd_flags;
6146 inp->def_send.sinfo_flags |= policy;
6147 inp->def_send.sinfo_ppid = info->snd_ppid;
6148 inp->def_send.sinfo_context = info->snd_context;
6149 SCTP_INP_WUNLOCK(inp);
6151 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6152 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6153 SCTP_INP_RLOCK(inp);
6154 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6155 SCTP_TCB_LOCK(stcb);
6156 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6157 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6158 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6159 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6160 stcb->asoc.def_send.sinfo_flags |= policy;
6161 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6162 stcb->asoc.def_send.sinfo_context = info->snd_context;
6164 SCTP_TCB_UNLOCK(stcb);
6166 SCTP_INP_RUNLOCK(inp);
6171 case SCTP_DEFAULT_PRINFO:
6173 struct sctp_default_prinfo *info;
6175 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6176 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6178 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6179 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6184 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6185 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6186 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6187 SCTP_TCB_UNLOCK(stcb);
6189 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6190 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6191 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6192 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6193 SCTP_INP_WLOCK(inp);
6194 inp->def_send.sinfo_flags &= 0xfff0;
6195 inp->def_send.sinfo_flags |= info->pr_policy;
6196 inp->def_send.sinfo_timetolive = info->pr_value;
6197 SCTP_INP_WUNLOCK(inp);
6199 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6200 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6201 SCTP_INP_RLOCK(inp);
6202 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6203 SCTP_TCB_LOCK(stcb);
6204 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6205 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6206 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6207 SCTP_TCB_UNLOCK(stcb);
6209 SCTP_INP_RUNLOCK(inp);
6214 case SCTP_PEER_ADDR_THLDS:
6215 /* Applies to the specific association */
6217 struct sctp_paddrthlds *thlds;
6218 struct sctp_nets *net;
6219 struct sockaddr *addr;
6221 #if defined(INET) && defined(INET6)
6222 struct sockaddr_in sin_store;
6226 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6227 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6229 #if defined(INET) && defined(INET6)
6230 if (thlds->spt_address.ss_family == AF_INET6) {
6231 struct sockaddr_in6 *sin6;
6233 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6234 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6235 in6_sin6_2_sin(&sin_store, sin6);
6236 addr = (struct sockaddr *)&sin_store;
6238 addr = (struct sockaddr *)&thlds->spt_address;
6241 addr = (struct sockaddr *)&thlds->spt_address;
6244 addr = (struct sockaddr *)&thlds->spt_address;
6247 net = sctp_findnet(stcb, addr);
6250 * We increment here since
6251 * sctp_findassociation_ep_addr() wil do a
6252 * decrement if it finds the stcb as long as
6253 * the locked tcb (last argument) is NOT a
6257 SCTP_INP_INCR_REF(inp);
6258 stcb = sctp_findassociation_ep_addr(&inp, addr,
6261 SCTP_INP_DECR_REF(inp);
6264 if ((stcb != NULL) && (net == NULL)) {
6266 if (addr->sa_family == AF_INET) {
6268 struct sockaddr_in *sin;
6270 sin = (struct sockaddr_in *)addr;
6271 if (sin->sin_addr.s_addr != INADDR_ANY) {
6272 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6273 SCTP_TCB_UNLOCK(stcb);
6280 if (addr->sa_family == AF_INET6) {
6281 struct sockaddr_in6 *sin6;
6283 sin6 = (struct sockaddr_in6 *)addr;
6284 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6285 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6286 SCTP_TCB_UNLOCK(stcb);
6293 error = EAFNOSUPPORT;
6294 SCTP_TCB_UNLOCK(stcb);
6295 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6301 net->failure_threshold = thlds->spt_pathmaxrxt;
6302 net->pf_threshold = thlds->spt_pathpfthld;
6303 if (net->dest_state & SCTP_ADDR_PF) {
6304 if ((net->error_count > net->failure_threshold) ||
6305 (net->error_count <= net->pf_threshold)) {
6306 net->dest_state &= ~SCTP_ADDR_PF;
6309 if ((net->error_count > net->pf_threshold) &&
6310 (net->error_count <= net->failure_threshold)) {
6311 net->dest_state |= SCTP_ADDR_PF;
6312 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6313 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6314 stcb->sctp_ep, stcb, net,
6315 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6316 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6319 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6320 if (net->error_count > net->failure_threshold) {
6321 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6322 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6325 if (net->error_count <= net->failure_threshold) {
6326 net->dest_state |= SCTP_ADDR_REACHABLE;
6327 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6331 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6332 net->failure_threshold = thlds->spt_pathmaxrxt;
6333 net->pf_threshold = thlds->spt_pathpfthld;
6334 if (net->dest_state & SCTP_ADDR_PF) {
6335 if ((net->error_count > net->failure_threshold) ||
6336 (net->error_count <= net->pf_threshold)) {
6337 net->dest_state &= ~SCTP_ADDR_PF;
6340 if ((net->error_count > net->pf_threshold) &&
6341 (net->error_count <= net->failure_threshold)) {
6342 net->dest_state |= SCTP_ADDR_PF;
6343 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6344 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6345 stcb->sctp_ep, stcb, net,
6346 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6347 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6350 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6351 if (net->error_count > net->failure_threshold) {
6352 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6353 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6356 if (net->error_count <= net->failure_threshold) {
6357 net->dest_state |= SCTP_ADDR_REACHABLE;
6358 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6362 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6363 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6365 SCTP_TCB_UNLOCK(stcb);
6367 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6368 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6369 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6370 SCTP_INP_WLOCK(inp);
6371 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6372 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6373 SCTP_INP_WUNLOCK(inp);
6375 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6381 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6383 struct sctp_udpencaps *encaps;
6384 struct sctp_nets *net;
6385 struct sockaddr *addr;
6387 #if defined(INET) && defined(INET6)
6388 struct sockaddr_in sin_store;
6392 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6393 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6395 #if defined(INET) && defined(INET6)
6396 if (encaps->sue_address.ss_family == AF_INET6) {
6397 struct sockaddr_in6 *sin6;
6399 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6400 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6401 in6_sin6_2_sin(&sin_store, sin6);
6402 addr = (struct sockaddr *)&sin_store;
6404 addr = (struct sockaddr *)&encaps->sue_address;
6407 addr = (struct sockaddr *)&encaps->sue_address;
6410 addr = (struct sockaddr *)&encaps->sue_address;
6413 net = sctp_findnet(stcb, addr);
6416 * We increment here since
6417 * sctp_findassociation_ep_addr() wil do a
6418 * decrement if it finds the stcb as long as
6419 * the locked tcb (last argument) is NOT a
6423 SCTP_INP_INCR_REF(inp);
6424 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6426 SCTP_INP_DECR_REF(inp);
6429 if ((stcb != NULL) && (net == NULL)) {
6431 if (addr->sa_family == AF_INET) {
6433 struct sockaddr_in *sin;
6435 sin = (struct sockaddr_in *)addr;
6436 if (sin->sin_addr.s_addr != INADDR_ANY) {
6437 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6438 SCTP_TCB_UNLOCK(stcb);
6445 if (addr->sa_family == AF_INET6) {
6446 struct sockaddr_in6 *sin6;
6448 sin6 = (struct sockaddr_in6 *)addr;
6449 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6450 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6451 SCTP_TCB_UNLOCK(stcb);
6458 error = EAFNOSUPPORT;
6459 SCTP_TCB_UNLOCK(stcb);
6460 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6466 net->port = encaps->sue_port;
6468 stcb->asoc.port = encaps->sue_port;
6470 SCTP_TCB_UNLOCK(stcb);
6472 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6473 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6474 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6475 SCTP_INP_WLOCK(inp);
6476 inp->sctp_ep.port = encaps->sue_port;
6477 SCTP_INP_WUNLOCK(inp);
6479 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6485 case SCTP_ECN_SUPPORTED:
6487 struct sctp_assoc_value *av;
6489 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6490 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6493 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6495 SCTP_TCB_UNLOCK(stcb);
6497 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6498 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6499 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6500 SCTP_INP_WLOCK(inp);
6501 if (av->assoc_value == 0) {
6502 inp->ecn_supported = 0;
6504 inp->ecn_supported = 1;
6506 SCTP_INP_WUNLOCK(inp);
6508 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6514 case SCTP_PR_SUPPORTED:
6516 struct sctp_assoc_value *av;
6518 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6519 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6522 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6524 SCTP_TCB_UNLOCK(stcb);
6526 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6527 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6528 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6529 SCTP_INP_WLOCK(inp);
6530 if (av->assoc_value == 0) {
6531 inp->prsctp_supported = 0;
6533 inp->prsctp_supported = 1;
6535 SCTP_INP_WUNLOCK(inp);
6537 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6543 case SCTP_AUTH_SUPPORTED:
6545 struct sctp_assoc_value *av;
6547 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6548 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6551 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6553 SCTP_TCB_UNLOCK(stcb);
6555 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6556 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6557 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6558 if ((av->assoc_value == 0) &&
6559 (inp->asconf_supported == 1)) {
6561 * AUTH is required for
6564 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6567 SCTP_INP_WLOCK(inp);
6568 if (av->assoc_value == 0) {
6569 inp->auth_supported = 0;
6571 inp->auth_supported = 1;
6573 SCTP_INP_WUNLOCK(inp);
6576 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6582 case SCTP_ASCONF_SUPPORTED:
6584 struct sctp_assoc_value *av;
6586 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6587 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6590 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6592 SCTP_TCB_UNLOCK(stcb);
6594 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6595 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6596 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6597 if ((av->assoc_value != 0) &&
6598 (inp->auth_supported == 0)) {
6600 * AUTH is required for
6603 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6606 SCTP_INP_WLOCK(inp);
6607 if (av->assoc_value == 0) {
6608 inp->asconf_supported = 0;
6609 sctp_auth_delete_chunk(SCTP_ASCONF,
6610 inp->sctp_ep.local_auth_chunks);
6611 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6612 inp->sctp_ep.local_auth_chunks);
6614 inp->asconf_supported = 1;
6615 sctp_auth_add_chunk(SCTP_ASCONF,
6616 inp->sctp_ep.local_auth_chunks);
6617 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6618 inp->sctp_ep.local_auth_chunks);
6620 SCTP_INP_WUNLOCK(inp);
6623 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6629 case SCTP_RECONFIG_SUPPORTED:
6631 struct sctp_assoc_value *av;
6633 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6634 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6637 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6639 SCTP_TCB_UNLOCK(stcb);
6641 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6642 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6643 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6644 SCTP_INP_WLOCK(inp);
6645 if (av->assoc_value == 0) {
6646 inp->reconfig_supported = 0;
6648 inp->reconfig_supported = 1;
6650 SCTP_INP_WUNLOCK(inp);
6652 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6658 case SCTP_NRSACK_SUPPORTED:
6660 struct sctp_assoc_value *av;
6662 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6663 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6668 SCTP_TCB_UNLOCK(stcb);
6670 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6671 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6672 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6673 SCTP_INP_WLOCK(inp);
6674 if (av->assoc_value == 0) {
6675 inp->nrsack_supported = 0;
6677 inp->nrsack_supported = 1;
6679 SCTP_INP_WUNLOCK(inp);
6681 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6687 case SCTP_PKTDROP_SUPPORTED:
6689 struct sctp_assoc_value *av;
6691 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6692 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6695 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6697 SCTP_TCB_UNLOCK(stcb);
6699 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6700 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6701 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6702 SCTP_INP_WLOCK(inp);
6703 if (av->assoc_value == 0) {
6704 inp->pktdrop_supported = 0;
6706 inp->pktdrop_supported = 1;
6708 SCTP_INP_WUNLOCK(inp);
6710 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6718 struct sctp_assoc_value *av;
6719 struct sctp_nets *net;
6721 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6722 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6725 stcb->asoc.max_cwnd = av->assoc_value;
6726 if (stcb->asoc.max_cwnd > 0) {
6727 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6728 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6729 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6730 net->cwnd = stcb->asoc.max_cwnd;
6731 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6732 net->cwnd = net->mtu - sizeof(struct sctphdr);
6737 SCTP_TCB_UNLOCK(stcb);
6739 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6740 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6741 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6742 SCTP_INP_WLOCK(inp);
6743 inp->max_cwnd = av->assoc_value;
6744 SCTP_INP_WUNLOCK(inp);
6746 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6753 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6754 error = ENOPROTOOPT;
6756 } /* end switch (opt) */
6761 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6763 void *optval = NULL;
6767 struct sctp_inpcb *inp;
6769 if ((sopt->sopt_level == SOL_SOCKET) &&
6770 (sopt->sopt_name == SO_SETFIB)) {
6771 inp = (struct sctp_inpcb *)so->so_pcb;
6773 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6776 SCTP_INP_WLOCK(inp);
6777 inp->fibnum = so->so_fibnum;
6778 SCTP_INP_WUNLOCK(inp);
6781 if (sopt->sopt_level != IPPROTO_SCTP) {
6782 /* wrong proto level... send back up to IP */
6784 if (INP_CHECK_SOCKAF(so, AF_INET6))
6785 error = ip6_ctloutput(so, sopt);
6787 #if defined(INET) && defined(INET6)
6791 error = ip_ctloutput(so, sopt);
6795 optsize = sopt->sopt_valsize;
6797 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6798 if (optval == NULL) {
6799 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6802 error = sooptcopyin(sopt, optval, optsize, optsize);
6804 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6808 p = (void *)sopt->sopt_td;
6809 if (sopt->sopt_dir == SOPT_SET) {
6810 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6811 } else if (sopt->sopt_dir == SOPT_GET) {
6812 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6814 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6817 if ((error == 0) && (optval != NULL)) {
6818 error = sooptcopyout(sopt, optval, optsize);
6819 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6820 } else if (optval != NULL) {
6821 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6829 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6832 int create_lock_on = 0;
6834 struct sctp_inpcb *inp;
6835 struct sctp_tcb *stcb = NULL;
6837 inp = (struct sctp_inpcb *)so->so_pcb;
6839 /* I made the same as TCP since we are not setup? */
6840 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6841 return (ECONNRESET);
6844 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6847 switch (addr->sa_family) {
6851 struct sockaddr_in6 *sin6p;
6853 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6857 sin6p = (struct sockaddr_in6 *)addr;
6858 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6859 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6868 struct sockaddr_in *sinp;
6870 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6871 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6874 sinp = (struct sockaddr_in *)addr;
6875 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6883 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6884 return (EAFNOSUPPORT);
6886 SCTP_INP_INCR_REF(inp);
6887 SCTP_ASOC_CREATE_LOCK(inp);
6891 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6892 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6893 /* Should I really unlock ? */
6894 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6899 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6900 (addr->sa_family == AF_INET6)) {
6901 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6906 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6907 SCTP_PCB_FLAGS_UNBOUND) {
6908 /* Bind a ephemeral port */
6909 error = sctp_inpcb_bind(so, NULL, NULL, p);
6914 /* Now do we connect? */
6915 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6916 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6917 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6921 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6922 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6923 /* We are already connected AND the TCP model */
6924 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6928 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6929 SCTP_INP_RLOCK(inp);
6930 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6931 SCTP_INP_RUNLOCK(inp);
6934 * We increment here since sctp_findassociation_ep_addr()
6935 * will do a decrement if it finds the stcb as long as the
6936 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6938 SCTP_INP_INCR_REF(inp);
6939 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6941 SCTP_INP_DECR_REF(inp);
6943 SCTP_TCB_UNLOCK(stcb);
6947 /* Already have or am bring up an association */
6948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6952 vrf_id = inp->def_vrf_id;
6953 /* We are GOOD to go */
6954 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, inp->sctp_ep.pre_open_stream_count, p);
6956 /* Gak! no memory */
6959 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6960 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6961 /* Set the connected flag so we can queue data */
6964 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6965 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6967 /* initialize authentication parameters for the assoc */
6968 sctp_initialize_auth_params(inp, stcb);
6970 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6971 SCTP_TCB_UNLOCK(stcb);
6973 if (create_lock_on) {
6974 SCTP_ASOC_CREATE_UNLOCK(inp);
6976 SCTP_INP_DECR_REF(inp);
6983 sctp_listen(struct socket *so, int backlog, struct thread *p)
6986 * Note this module depends on the protocol processing being called
6987 * AFTER any socket level flags and backlog are applied to the
6988 * socket. The traditional way that the socket flags are applied is
6989 * AFTER protocol processing. We have made a change to the
6990 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6991 * place if the socket API for SCTP is to work properly.
6995 struct sctp_inpcb *inp;
6997 inp = (struct sctp_inpcb *)so->so_pcb;
6999 /* I made the same as TCP since we are not setup? */
7000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7001 return (ECONNRESET);
7003 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7004 /* See if we have a listener */
7005 struct sctp_inpcb *tinp;
7006 union sctp_sockstore store;
7008 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7010 struct sctp_laddr *laddr;
7012 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7013 memcpy(&store, &laddr->ifa->address, sizeof(store));
7014 switch (store.sa.sa_family) {
7017 store.sin.sin_port = inp->sctp_lport;
7022 store.sin6.sin6_port = inp->sctp_lport;
7028 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7029 if (tinp && (tinp != inp) &&
7030 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7031 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7032 (tinp->sctp_socket->so_qlimit)) {
7034 * we have a listener already and
7037 SCTP_INP_DECR_REF(tinp);
7038 return (EADDRINUSE);
7040 SCTP_INP_DECR_REF(tinp);
7044 /* Setup a local addr bound all */
7045 memset(&store, 0, sizeof(store));
7047 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7048 store.sa.sa_family = AF_INET6;
7049 store.sa.sa_len = sizeof(struct sockaddr_in6);
7053 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7054 store.sa.sa_family = AF_INET;
7055 store.sa.sa_len = sizeof(struct sockaddr_in);
7058 switch (store.sa.sa_family) {
7061 store.sin.sin_port = inp->sctp_lport;
7066 store.sin6.sin6_port = inp->sctp_lport;
7072 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7073 if (tinp && (tinp != inp) &&
7074 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7075 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7076 (tinp->sctp_socket->so_qlimit)) {
7078 * we have a listener already and its not
7081 SCTP_INP_DECR_REF(tinp);
7082 return (EADDRINUSE);
7084 SCTP_INP_DECR_REF(tinp);
7088 SCTP_INP_RLOCK(inp);
7089 #ifdef SCTP_LOCK_LOGGING
7090 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7091 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7095 error = solisten_proto_check(so);
7098 SCTP_INP_RUNLOCK(inp);
7101 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7102 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7104 * The unlucky case - We are in the tcp pool with this guy.
7105 * - Someone else is in the main inp slot. - We must move
7106 * this guy (the listener) to the main slot - We must then
7107 * move the guy that was listener to the TCP Pool.
7109 if (sctp_swap_inpcb_for_listen(inp)) {
7110 SCTP_INP_RUNLOCK(inp);
7111 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7112 return (EADDRINUSE);
7115 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7116 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7117 /* We are already connected AND the TCP model */
7118 SCTP_INP_RUNLOCK(inp);
7119 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7120 return (EADDRINUSE);
7122 SCTP_INP_RUNLOCK(inp);
7123 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7124 /* We must do a bind. */
7125 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7126 /* bind error, probably perm */
7131 /* It appears for 7.0 and on, we must always call this. */
7132 solisten_proto(so, backlog);
7133 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7134 /* remove the ACCEPTCONN flag for one-to-many sockets */
7135 so->so_options &= ~SO_ACCEPTCONN;
7138 /* turning off listen */
7139 so->so_options &= ~SO_ACCEPTCONN;
7145 static int sctp_defered_wakeup_cnt = 0;
7148 sctp_accept(struct socket *so, struct sockaddr **addr)
7150 struct sctp_tcb *stcb;
7151 struct sctp_inpcb *inp;
7152 union sctp_sockstore store;
7158 inp = (struct sctp_inpcb *)so->so_pcb;
7161 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7162 return (ECONNRESET);
7164 SCTP_INP_RLOCK(inp);
7165 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7166 SCTP_INP_RUNLOCK(inp);
7167 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7168 return (EOPNOTSUPP);
7170 if (so->so_state & SS_ISDISCONNECTED) {
7171 SCTP_INP_RUNLOCK(inp);
7172 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7173 return (ECONNABORTED);
7175 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7177 SCTP_INP_RUNLOCK(inp);
7178 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7179 return (ECONNRESET);
7181 SCTP_TCB_LOCK(stcb);
7182 SCTP_INP_RUNLOCK(inp);
7183 store = stcb->asoc.primary_destination->ro._l_addr;
7184 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7185 SCTP_TCB_UNLOCK(stcb);
7186 switch (store.sa.sa_family) {
7190 struct sockaddr_in *sin;
7192 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7195 sin->sin_family = AF_INET;
7196 sin->sin_len = sizeof(*sin);
7197 sin->sin_port = store.sin.sin_port;
7198 sin->sin_addr = store.sin.sin_addr;
7199 *addr = (struct sockaddr *)sin;
7206 struct sockaddr_in6 *sin6;
7208 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7211 sin6->sin6_family = AF_INET6;
7212 sin6->sin6_len = sizeof(*sin6);
7213 sin6->sin6_port = store.sin6.sin6_port;
7214 sin6->sin6_addr = store.sin6.sin6_addr;
7215 if ((error = sa6_recoverscope(sin6)) != 0) {
7216 SCTP_FREE_SONAME(sin6);
7219 *addr = (struct sockaddr *)sin6;
7227 /* Wake any delayed sleep action */
7228 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7229 SCTP_INP_WLOCK(inp);
7230 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7231 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7232 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7233 SCTP_INP_WUNLOCK(inp);
7234 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7235 if (sowriteable(inp->sctp_socket)) {
7236 sowwakeup_locked(inp->sctp_socket);
7238 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7240 SCTP_INP_WLOCK(inp);
7242 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7243 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7244 SCTP_INP_WUNLOCK(inp);
7245 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7246 if (soreadable(inp->sctp_socket)) {
7247 sctp_defered_wakeup_cnt++;
7248 sorwakeup_locked(inp->sctp_socket);
7250 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7252 SCTP_INP_WLOCK(inp);
7254 SCTP_INP_WUNLOCK(inp);
7256 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7257 SCTP_TCB_LOCK(stcb);
7258 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7259 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7266 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7268 struct sockaddr_in *sin;
7270 struct sctp_inpcb *inp;
7271 struct sctp_ifa *sctp_ifa;
7274 * Do the malloc first in case it blocks.
7276 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7279 sin->sin_family = AF_INET;
7280 sin->sin_len = sizeof(*sin);
7281 inp = (struct sctp_inpcb *)so->so_pcb;
7283 SCTP_FREE_SONAME(sin);
7284 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7285 return (ECONNRESET);
7287 SCTP_INP_RLOCK(inp);
7288 sin->sin_port = inp->sctp_lport;
7289 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7290 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7291 struct sctp_tcb *stcb;
7292 struct sockaddr_in *sin_a;
7293 struct sctp_nets *net;
7296 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7302 SCTP_TCB_LOCK(stcb);
7303 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7304 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7306 /* this will make coverity happy */
7309 if (sin_a->sin_family == AF_INET) {
7314 if ((!fnd) || (sin_a == NULL)) {
7316 SCTP_TCB_UNLOCK(stcb);
7319 vrf_id = inp->def_vrf_id;
7320 sctp_ifa = sctp_source_address_selection(inp,
7322 (sctp_route_t *) & net->ro,
7325 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7326 sctp_free_ifa(sctp_ifa);
7328 SCTP_TCB_UNLOCK(stcb);
7330 /* For the bound all case you get back 0 */
7332 sin->sin_addr.s_addr = 0;
7336 /* Take the first IPv4 address in the list */
7337 struct sctp_laddr *laddr;
7340 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7341 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7342 struct sockaddr_in *sin_a;
7344 sin_a = &laddr->ifa->address.sin;
7345 sin->sin_addr = sin_a->sin_addr;
7351 SCTP_FREE_SONAME(sin);
7352 SCTP_INP_RUNLOCK(inp);
7353 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7357 SCTP_INP_RUNLOCK(inp);
7358 (*addr) = (struct sockaddr *)sin;
7363 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7365 struct sockaddr_in *sin;
7367 struct sockaddr_in *sin_a;
7368 struct sctp_inpcb *inp;
7369 struct sctp_tcb *stcb;
7370 struct sctp_nets *net;
7372 /* Do the malloc first in case it blocks. */
7373 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7376 sin->sin_family = AF_INET;
7377 sin->sin_len = sizeof(*sin);
7379 inp = (struct sctp_inpcb *)so->so_pcb;
7380 if ((inp == NULL) ||
7381 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7382 /* UDP type and listeners will drop out here */
7383 SCTP_FREE_SONAME(sin);
7384 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7387 SCTP_INP_RLOCK(inp);
7388 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7390 SCTP_TCB_LOCK(stcb);
7392 SCTP_INP_RUNLOCK(inp);
7394 SCTP_FREE_SONAME(sin);
7395 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7396 return (ECONNRESET);
7399 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7400 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7401 if (sin_a->sin_family == AF_INET) {
7403 sin->sin_port = stcb->rport;
7404 sin->sin_addr = sin_a->sin_addr;
7408 SCTP_TCB_UNLOCK(stcb);
7410 /* No IPv4 address */
7411 SCTP_FREE_SONAME(sin);
7412 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7415 (*addr) = (struct sockaddr *)sin;
7419 struct pr_usrreqs sctp_usrreqs = {
7420 .pru_abort = sctp_abort,
7421 .pru_accept = sctp_accept,
7422 .pru_attach = sctp_attach,
7423 .pru_bind = sctp_bind,
7424 .pru_connect = sctp_connect,
7425 .pru_control = in_control,
7426 .pru_close = sctp_close,
7427 .pru_detach = sctp_close,
7428 .pru_sopoll = sopoll_generic,
7429 .pru_flush = sctp_flush,
7430 .pru_disconnect = sctp_disconnect,
7431 .pru_listen = sctp_listen,
7432 .pru_peeraddr = sctp_peeraddr,
7433 .pru_send = sctp_sendm,
7434 .pru_shutdown = sctp_shutdown,
7435 .pru_sockaddr = sctp_ingetaddr,
7436 .pru_sosend = sctp_sosend,
7437 .pru_soreceive = sctp_soreceive