2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
5 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
6 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * a) Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
14 * b) Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the distribution.
18 * c) Neither the name of Cisco Systems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <netinet/sctp_os.h>
40 #include <netinet/sctp_pcb.h>
41 #include <netinet/sctp_header.h>
42 #include <netinet/sctp_var.h>
44 #include <netinet6/sctp6_var.h>
46 #include <netinet/sctp_sysctl.h>
47 #include <netinet/sctp_output.h>
48 #include <netinet/sctp_uio.h>
49 #include <netinet/sctp_asconf.h>
50 #include <netinet/sctputil.h>
51 #include <netinet/sctp_indata.h>
52 #include <netinet/sctp_timer.h>
53 #include <netinet/sctp_auth.h>
54 #include <netinet/sctp_bsd_addr.h>
55 #include <netinet/udp.h>
56 #include <sys/eventhandler.h>
60 extern const struct sctp_cc_functions sctp_cc_functions[];
61 extern const struct sctp_ss_functions sctp_ss_functions[];
68 /* Initialize and modify the sysctled variables */
70 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
71 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
73 * Allow a user to take no more than 1/2 the number of clusters or
74 * the SB_MAX whichever is smaller for the send window.
76 sb_max_adj = (u_long)((u_quad_t)(SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
77 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
78 (((uint32_t)nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
80 * Now for the recv window, should we take the same amount? or
81 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
82 * now I will just copy.
84 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
85 SCTP_BASE_VAR(first_time) = 0;
86 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
88 #if defined(SCTP_PACKET_LOGGING)
89 SCTP_BASE_VAR(packet_log_writers) = 0;
90 SCTP_BASE_VAR(packet_log_end) = 0;
91 memset(&SCTP_BASE_VAR(packet_log_buffer), 0, SCTP_PACKET_LOG_SIZE);
93 SCTP_BASE_VAR(eh_tag) = EVENTHANDLER_REGISTER(rt_addrmsg,
94 sctp_addr_change_event_handler, NULL, EVENTHANDLER_PRI_FIRST);
99 sctp_finish(void *unused __unused)
104 VNET_SYSUNINIT(sctp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, sctp_finish, NULL);
108 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
110 struct sctp_tmit_chunk *chk;
113 /* Adjust that too */
114 stcb->asoc.smallest_mtu = nxtsz;
115 /* now off to subtract IP_DF flag if needed */
116 overhead = IP_HDR_SIZE + sizeof(struct sctphdr);
117 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
118 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
120 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
121 if ((chk->send_size + overhead) > nxtsz) {
122 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
125 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
126 if ((chk->send_size + overhead) > nxtsz) {
128 * For this guy we also mark for immediate resend
129 * since we sent to big of chunk
131 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
132 if (chk->sent < SCTP_DATAGRAM_RESEND) {
133 sctp_flight_size_decrease(chk);
134 sctp_total_flight_decrease(stcb, chk);
135 chk->sent = SCTP_DATAGRAM_RESEND;
136 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
137 chk->rec.data.doing_fast_retransmit = 0;
138 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
139 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
140 chk->whoTo->flight_size,
142 (uint32_t)(uintptr_t)chk->whoTo,
145 /* Clear any time so NO RTT is being done */
146 if (chk->do_rtt == 1) {
148 chk->whoTo->rto_needed = 1;
157 sctp_notify(struct sctp_inpcb *inp,
158 struct sctp_tcb *stcb,
159 struct sctp_nets *net,
165 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
170 if (icmp_type != ICMP_UNREACH) {
171 /* We only care about unreachable */
172 SCTP_TCB_UNLOCK(stcb);
175 if ((icmp_code == ICMP_UNREACH_NET) ||
176 (icmp_code == ICMP_UNREACH_HOST) ||
177 (icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
178 (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
179 (icmp_code == ICMP_UNREACH_ISOLATED) ||
180 (icmp_code == ICMP_UNREACH_NET_PROHIB) ||
181 (icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
182 (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
183 /* Mark the net unreachable. */
184 if (net->dest_state & SCTP_ADDR_REACHABLE) {
185 /* OK, that destination is NOT reachable. */
186 net->dest_state &= ~SCTP_ADDR_REACHABLE;
187 net->dest_state &= ~SCTP_ADDR_PF;
188 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
190 (void *)net, SCTP_SO_NOT_LOCKED);
192 SCTP_TCB_UNLOCK(stcb);
193 } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) ||
194 (icmp_code == ICMP_UNREACH_PORT)) {
195 /* Treat it like an ABORT. */
196 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
197 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
198 so = SCTP_INP_SO(inp);
199 atomic_add_int(&stcb->asoc.refcnt, 1);
200 SCTP_TCB_UNLOCK(stcb);
201 SCTP_SOCKET_LOCK(so, 1);
203 atomic_subtract_int(&stcb->asoc.refcnt, 1);
205 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
206 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
207 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
208 SCTP_SOCKET_UNLOCK(so, 1);
209 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
211 /* no need to unlock here, since the TCB is gone */
212 } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) {
213 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
214 SCTP_TCB_UNLOCK(stcb);
217 /* Find the next (smaller) MTU */
220 * Old type router that does not tell us what the
221 * next MTU is. Rats we will have to guess (in a
222 * educated fashion of course).
224 next_mtu = sctp_get_prev_mtu(ip_len);
226 /* Stop the PMTU timer. */
227 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
229 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
230 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
234 /* Update the path MTU. */
236 next_mtu -= sizeof(struct udphdr);
238 if (net->mtu > next_mtu) {
241 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu + sizeof(struct udphdr));
243 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu);
246 /* Update the association MTU */
247 if (stcb->asoc.smallest_mtu > next_mtu) {
248 sctp_pathmtu_adjustment(stcb, next_mtu);
250 /* Finally, start the PMTU timer if it was running before. */
252 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
254 SCTP_TCB_UNLOCK(stcb);
256 SCTP_TCB_UNLOCK(stcb);
261 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
267 struct sctp_inpcb *inp;
268 struct sctp_tcb *stcb;
269 struct sctp_nets *net;
270 struct sctp_init_chunk *ch;
271 struct sockaddr_in src, dst;
273 if (sa->sa_family != AF_INET ||
274 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
277 if (PRC_IS_REDIRECT(cmd)) {
279 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
283 inner_ip = (struct ip *)vip;
284 icmp = (struct icmp *)((caddr_t)inner_ip -
285 (sizeof(struct icmp) - sizeof(struct ip)));
286 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
287 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
288 memset(&src, 0, sizeof(struct sockaddr_in));
289 src.sin_family = AF_INET;
290 src.sin_len = sizeof(struct sockaddr_in);
291 src.sin_port = sh->src_port;
292 src.sin_addr = inner_ip->ip_src;
293 memset(&dst, 0, sizeof(struct sockaddr_in));
294 dst.sin_family = AF_INET;
295 dst.sin_len = sizeof(struct sockaddr_in);
296 dst.sin_port = sh->dest_port;
297 dst.sin_addr = inner_ip->ip_dst;
299 * 'dst' holds the dest of the packet that failed to be
300 * sent. 'src' holds our local endpoint address. Thus we
301 * reverse the dst and the src in the lookup.
305 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
306 (struct sockaddr *)&src,
309 if ((stcb != NULL) &&
312 /* Check the verification tag */
313 if (ntohl(sh->v_tag) != 0) {
315 * This must be the verification tag used
316 * for sending out packets. We don't
317 * consider packets reflecting the
320 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
321 SCTP_TCB_UNLOCK(stcb);
325 if (ntohs(outer_ip->ip_len) >=
327 8 + (inner_ip->ip_hl << 2) + 20) {
329 * In this case we can check if we
330 * got an INIT chunk and if the
331 * initiate tag matches.
333 ch = (struct sctp_init_chunk *)(sh + 1);
334 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
335 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
336 SCTP_TCB_UNLOCK(stcb);
340 SCTP_TCB_UNLOCK(stcb);
344 sctp_notify(inp, stcb, net,
347 ntohs(inner_ip->ip_len),
348 (uint32_t)ntohs(icmp->icmp_nextmtu));
350 if ((stcb == NULL) && (inp != NULL)) {
351 /* reduce ref-count */
353 SCTP_INP_DECR_REF(inp);
354 SCTP_INP_WUNLOCK(inp);
357 SCTP_TCB_UNLOCK(stcb);
366 sctp_getcred(SYSCTL_HANDLER_ARGS)
369 struct sockaddr_in addrs[2];
370 struct sctp_inpcb *inp;
371 struct sctp_nets *net;
372 struct sctp_tcb *stcb;
376 /* FIX, for non-bsd is this right? */
377 vrf_id = SCTP_DEFAULT_VRFID;
379 error = priv_check(req->td, PRIV_NETINET_GETCRED);
384 error = SYSCTL_IN(req, addrs, sizeof(addrs));
388 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
390 &inp, &net, 1, vrf_id);
391 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
392 if ((inp != NULL) && (stcb == NULL)) {
393 /* reduce ref-count */
395 SCTP_INP_DECR_REF(inp);
399 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
403 SCTP_TCB_UNLOCK(stcb);
405 * We use the write lock here, only since in the error leg we need
406 * it. If we used RLOCK, then we would have to
407 * wlock/decr/unlock/rlock. Which in theory could create a hole.
408 * Better to use higher wlock.
412 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
414 SCTP_INP_WUNLOCK(inp);
417 cru2x(inp->sctp_socket->so_cred, &xuc);
418 SCTP_INP_WUNLOCK(inp);
419 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
424 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
425 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
430 sctp_abort(struct socket *so)
432 struct sctp_inpcb *inp;
435 inp = (struct sctp_inpcb *)so->so_pcb;
441 flags = inp->sctp_flags;
442 #ifdef SCTP_LOG_CLOSING
443 sctp_log_closing(inp, NULL, 17);
445 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
446 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
447 #ifdef SCTP_LOG_CLOSING
448 sctp_log_closing(inp, NULL, 16);
450 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
451 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
453 SCTP_SB_CLEAR(so->so_snd);
455 * same for the rcv ones, they are only here for the
458 SCTP_SB_CLEAR(so->so_rcv);
460 /* Now null out the reference, we are completely detached. */
464 flags = inp->sctp_flags;
465 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
466 goto sctp_must_try_again;
473 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
475 struct sctp_inpcb *inp;
476 struct inpcb *ip_inp;
478 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
480 inp = (struct sctp_inpcb *)so->so_pcb;
482 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
485 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
486 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
491 error = sctp_inpcb_alloc(so, vrf_id);
495 inp = (struct sctp_inpcb *)so->so_pcb;
497 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
498 ip_inp = &inp->ip_inp.inp;
499 ip_inp->inp_vflag |= INP_IPV4;
500 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
501 SCTP_INP_WUNLOCK(inp);
506 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
508 struct sctp_inpcb *inp;
510 inp = (struct sctp_inpcb *)so->so_pcb;
512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
516 if ((addr->sa_family != AF_INET) ||
517 (addr->sa_len != sizeof(struct sockaddr_in))) {
518 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
522 return (sctp_inpcb_bind(so, addr, NULL, p));
527 sctp_close(struct socket *so)
529 struct sctp_inpcb *inp;
532 inp = (struct sctp_inpcb *)so->so_pcb;
537 * Inform all the lower layer assoc that we are done.
540 flags = inp->sctp_flags;
541 #ifdef SCTP_LOG_CLOSING
542 sctp_log_closing(inp, NULL, 17);
544 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
545 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
546 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
547 (so->so_rcv.sb_cc > 0)) {
548 #ifdef SCTP_LOG_CLOSING
549 sctp_log_closing(inp, NULL, 13);
551 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
552 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
554 #ifdef SCTP_LOG_CLOSING
555 sctp_log_closing(inp, NULL, 14);
557 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
558 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
561 * The socket is now detached, no matter what the state of
562 * the SCTP association.
565 SCTP_SB_CLEAR(so->so_snd);
567 * same for the rcv ones, they are only here for the
570 SCTP_SB_CLEAR(so->so_rcv);
572 /* Now null out the reference, we are completely detached. */
576 flags = inp->sctp_flags;
577 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
578 goto sctp_must_try_again;
586 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
587 struct mbuf *control, struct thread *p);
591 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
592 struct mbuf *control, struct thread *p)
594 struct sctp_inpcb *inp;
597 inp = (struct sctp_inpcb *)so->so_pcb;
600 sctp_m_freem(control);
603 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
607 /* Got to have an to address if we are NOT a connected socket */
608 if ((addr == NULL) &&
609 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
610 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
612 } else if (addr == NULL) {
613 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
614 error = EDESTADDRREQ;
617 sctp_m_freem(control);
623 if (addr->sa_family != AF_INET) {
624 /* must be a v4 address! */
625 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
628 sctp_m_freem(control);
631 error = EDESTADDRREQ;
636 /* now what about control */
639 sctp_m_freem(inp->control);
642 inp->control = control;
646 SCTP_BUF_NEXT(inp->pkt_last) = m;
649 inp->pkt_last = inp->pkt = m;
652 /* FreeBSD uses a flag passed */
653 ((flags & PRUS_MORETOCOME) == 0)
656 * note with the current version this code will only be used
657 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
658 * re-defining sosend to use the sctp_sosend. One can
659 * optionally switch back to this code (by changing back the
660 * definitions) but this is not advisable. This code is used
661 * by FreeBSD when sending a file with sendfile() though.
665 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
675 sctp_disconnect(struct socket *so)
677 struct sctp_inpcb *inp;
679 inp = (struct sctp_inpcb *)so->so_pcb;
681 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
685 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
686 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
687 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
689 SCTP_INP_RUNLOCK(inp);
692 struct sctp_association *asoc;
693 struct sctp_tcb *stcb;
695 stcb = LIST_FIRST(&inp->sctp_asoc_list);
697 SCTP_INP_RUNLOCK(inp);
698 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
703 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
704 /* We are about to be freed, out of here */
705 SCTP_TCB_UNLOCK(stcb);
706 SCTP_INP_RUNLOCK(inp);
709 if (((so->so_options & SO_LINGER) &&
710 (so->so_linger == 0)) ||
711 (so->so_rcv.sb_cc > 0)) {
712 if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) {
713 /* Left with Data unread */
716 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
717 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
718 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
720 SCTP_INP_RUNLOCK(inp);
721 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
722 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
723 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
725 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
726 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
727 /* No unlock tcb assoc is gone */
730 if (TAILQ_EMPTY(&asoc->send_queue) &&
731 TAILQ_EMPTY(&asoc->sent_queue) &&
732 (asoc->stream_queue_cnt == 0)) {
733 /* there is nothing queued to send, so done */
734 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
737 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) &&
738 (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
739 /* only send SHUTDOWN 1st time thru */
740 struct sctp_nets *netp;
742 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
743 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
744 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
746 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
747 sctp_stop_timers_for_shutdown(stcb);
748 if (stcb->asoc.alternate) {
749 netp = stcb->asoc.alternate;
751 netp = stcb->asoc.primary_destination;
753 sctp_send_shutdown(stcb, netp);
754 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
755 stcb->sctp_ep, stcb, netp);
756 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
757 stcb->sctp_ep, stcb, netp);
758 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
762 * we still got (or just got) data to send,
763 * so set SHUTDOWN_PENDING
766 * XXX sockets draft says that SCTP_EOF
767 * should be sent with no data. currently,
768 * we will allow user data to be sent first
769 * and move to SHUTDOWN-PENDING
771 struct sctp_nets *netp;
773 if (stcb->asoc.alternate) {
774 netp = stcb->asoc.alternate;
776 netp = stcb->asoc.primary_destination;
779 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
780 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
782 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
783 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
785 if (TAILQ_EMPTY(&asoc->send_queue) &&
786 TAILQ_EMPTY(&asoc->sent_queue) &&
787 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
791 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
792 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
793 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
794 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
795 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
796 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
797 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
799 SCTP_INP_RUNLOCK(inp);
800 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
801 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
804 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
807 soisdisconnecting(so);
808 SCTP_TCB_UNLOCK(stcb);
809 SCTP_INP_RUNLOCK(inp);
814 /* UDP model does not support this */
815 SCTP_INP_RUNLOCK(inp);
816 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
822 sctp_flush(struct socket *so, int how)
825 * We will just clear out the values and let subsequent close clear
826 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
827 * they will not be able to read the data, the socket will block
828 * that from happening.
830 struct sctp_inpcb *inp;
832 inp = (struct sctp_inpcb *)so->so_pcb;
834 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
838 /* For the 1 to many model this does nothing */
839 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
840 SCTP_INP_RUNLOCK(inp);
843 SCTP_INP_RUNLOCK(inp);
844 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
846 * First make sure the sb will be happy, we don't use these
847 * except maybe the count
850 SCTP_INP_READ_LOCK(inp);
851 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
852 SCTP_INP_READ_UNLOCK(inp);
853 SCTP_INP_WUNLOCK(inp);
854 so->so_rcv.sb_cc = 0;
855 so->so_rcv.sb_mbcnt = 0;
856 so->so_rcv.sb_mb = NULL;
858 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
860 * First make sure the sb will be happy, we don't use these
861 * except maybe the count
863 so->so_snd.sb_cc = 0;
864 so->so_snd.sb_mbcnt = 0;
865 so->so_snd.sb_mb = NULL;
872 sctp_shutdown(struct socket *so)
874 struct sctp_inpcb *inp;
876 inp = (struct sctp_inpcb *)so->so_pcb;
878 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
882 /* For UDP model this is a invalid call */
883 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
884 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
885 /* Restore the flags that the soshutdown took away. */
886 SOCKBUF_LOCK(&so->so_rcv);
887 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
888 SOCKBUF_UNLOCK(&so->so_rcv);
889 /* This proc will wakeup for read and do nothing (I hope) */
890 SCTP_INP_RUNLOCK(inp);
891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
895 * Ok, if we reach here its the TCP model and it is either a
896 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
899 struct sctp_tcb *stcb;
900 struct sctp_association *asoc;
901 struct sctp_nets *netp;
904 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
905 SCTP_INP_RUNLOCK(inp);
910 stcb = LIST_FIRST(&inp->sctp_asoc_list);
913 * Ok, we hit the case that the shutdown call was
914 * made after an abort or something. Nothing to do
917 SCTP_INP_RUNLOCK(inp);
922 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
923 SCTP_TCB_UNLOCK(stcb);
924 SCTP_INP_RUNLOCK(inp);
927 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) &&
928 (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) &&
929 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) {
931 * If we are not in or before ESTABLISHED, there is
932 * no protocol action required.
934 SCTP_TCB_UNLOCK(stcb);
935 SCTP_INP_RUNLOCK(inp);
938 if (stcb->asoc.alternate) {
939 netp = stcb->asoc.alternate;
941 netp = stcb->asoc.primary_destination;
943 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) &&
944 TAILQ_EMPTY(&asoc->send_queue) &&
945 TAILQ_EMPTY(&asoc->sent_queue) &&
946 (asoc->stream_queue_cnt == 0)) {
947 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
950 /* there is nothing queued to send, so I'm done... */
951 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
952 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
953 sctp_stop_timers_for_shutdown(stcb);
954 sctp_send_shutdown(stcb, netp);
955 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
956 stcb->sctp_ep, stcb, netp);
959 * We still got (or just got) data to send, so set
962 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
963 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
964 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
966 if (TAILQ_EMPTY(&asoc->send_queue) &&
967 TAILQ_EMPTY(&asoc->sent_queue) &&
968 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
972 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
973 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
974 SCTP_INP_RUNLOCK(inp);
975 sctp_abort_an_association(stcb->sctp_ep, stcb,
976 op_err, SCTP_SO_LOCKED);
980 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp);
982 * XXX: Why do this in the case where we have still data
985 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
986 SCTP_TCB_UNLOCK(stcb);
987 SCTP_INP_RUNLOCK(inp);
993 * copies a "user" presentable address and removes embedded scope, etc.
994 * returns 0 on success, 1 on error
997 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1000 struct sockaddr_in6 lsa6;
1002 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1005 memcpy(ss, sa, sa->sa_len);
1012 * NOTE: assumes addr lock is held
1015 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1016 struct sctp_tcb *stcb,
1018 struct sockaddr_storage *sas,
1021 struct sctp_ifn *sctp_ifn;
1022 struct sctp_ifa *sctp_ifa;
1026 int ipv4_local_scope, ipv4_addr_legal;
1029 int local_scope, site_scope, ipv6_addr_legal;
1031 struct sctp_vrf *vrf;
1038 /* Turn on all the appropriate scope */
1039 loopback_scope = stcb->asoc.scope.loopback_scope;
1041 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1042 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1045 local_scope = stcb->asoc.scope.local_scope;
1046 site_scope = stcb->asoc.scope.site_scope;
1047 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1050 /* Use generic values for endpoints. */
1053 ipv4_local_scope = 1;
1059 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1061 ipv6_addr_legal = 1;
1064 if (SCTP_IPV6_V6ONLY(inp)) {
1065 ipv4_addr_legal = 0;
1067 ipv4_addr_legal = 1;
1072 ipv6_addr_legal = 0;
1075 ipv4_addr_legal = 1;
1079 vrf = sctp_find_vrf(vrf_id);
1083 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1084 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1085 if ((loopback_scope == 0) &&
1086 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1087 /* Skip loopback if loopback_scope not set */
1090 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1093 * For the BOUND-ALL case, the list
1094 * associated with a TCB is Always
1095 * considered a reverse list.. i.e.
1096 * it lists addresses that are NOT
1097 * part of the association. If this
1098 * is one of those we must skip it.
1100 if (sctp_is_addr_restricted(stcb,
1105 switch (sctp_ifa->address.sa.sa_family) {
1108 if (ipv4_addr_legal) {
1109 struct sockaddr_in *sin;
1111 sin = &sctp_ifa->address.sin;
1112 if (sin->sin_addr.s_addr == 0) {
1120 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1121 &sin->sin_addr) != 0) {
1124 if ((ipv4_local_scope == 0) &&
1125 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1129 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1130 if (actual + sizeof(struct sockaddr_in6) > limit) {
1133 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1134 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1135 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1136 actual += sizeof(struct sockaddr_in6);
1139 if (actual + sizeof(struct sockaddr_in) > limit) {
1142 memcpy(sas, sin, sizeof(struct sockaddr_in));
1143 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1144 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in));
1145 actual += sizeof(struct sockaddr_in);
1156 if (ipv6_addr_legal) {
1157 struct sockaddr_in6 *sin6;
1159 sin6 = &sctp_ifa->address.sin6;
1160 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1168 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1169 &sin6->sin6_addr) != 0) {
1172 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1173 if (local_scope == 0)
1175 if (sin6->sin6_scope_id == 0) {
1176 if (sa6_recoverscope(sin6) != 0)
1189 if ((site_scope == 0) &&
1190 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1193 if (actual + sizeof(struct sockaddr_in6) > limit) {
1196 memcpy(sas, sin6, sizeof(struct sockaddr_in6));
1197 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1198 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1199 actual += sizeof(struct sockaddr_in6);
1212 struct sctp_laddr *laddr;
1215 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1217 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1221 sa_len = laddr->ifa->address.sa.sa_len;
1222 if (actual + sa_len > limit) {
1225 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1227 switch (laddr->ifa->address.sa.sa_family) {
1230 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1235 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1242 sas = (struct sockaddr_storage *)((caddr_t)sas + sa_len);
1250 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1251 struct sctp_tcb *stcb,
1253 struct sockaddr_storage *sas)
1257 SCTP_IPI_ADDR_RLOCK();
1258 /* fill up addresses for the endpoint's default vrf */
1259 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1261 SCTP_IPI_ADDR_RUNLOCK();
1266 * NOTE: assumes addr lock is held
1269 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1272 struct sctp_vrf *vrf = NULL;
1275 * In both sub-set bound an bound_all cases we return the MAXIMUM
1276 * number of addresses that you COULD get. In reality the sub-set
1277 * bound may have an exclusion list for a given TCB OR in the
1278 * bound-all case a TCB may NOT include the loopback or other
1279 * addresses as well.
1281 vrf = sctp_find_vrf(vrf_id);
1285 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1286 struct sctp_ifn *sctp_ifn;
1287 struct sctp_ifa *sctp_ifa;
1289 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1290 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1291 /* Count them if they are the right type */
1292 switch (sctp_ifa->address.sa.sa_family) {
1296 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1297 cnt += sizeof(struct sockaddr_in6);
1299 cnt += sizeof(struct sockaddr_in);
1301 cnt += sizeof(struct sockaddr_in);
1307 cnt += sizeof(struct sockaddr_in6);
1316 struct sctp_laddr *laddr;
1318 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1319 switch (laddr->ifa->address.sa.sa_family) {
1323 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1324 cnt += sizeof(struct sockaddr_in6);
1326 cnt += sizeof(struct sockaddr_in);
1328 cnt += sizeof(struct sockaddr_in);
1334 cnt += sizeof(struct sockaddr_in6);
1346 sctp_count_max_addresses(struct sctp_inpcb *inp)
1350 SCTP_IPI_ADDR_RLOCK();
1351 /* count addresses for the endpoint's default VRF */
1352 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1353 SCTP_IPI_ADDR_RUNLOCK();
1358 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1359 size_t optsize, void *p, int delay)
1362 int creat_lock_on = 0;
1363 struct sctp_tcb *stcb = NULL;
1364 struct sockaddr *sa;
1365 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1369 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1371 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1372 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1373 /* We are already connected AND the TCP model */
1374 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1375 return (EADDRINUSE);
1378 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1379 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1380 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1384 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1385 SCTP_INP_RLOCK(inp);
1386 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1387 SCTP_INP_RUNLOCK(inp);
1390 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1393 SCTP_INP_INCR_REF(inp);
1394 SCTP_ASOC_CREATE_LOCK(inp);
1396 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1397 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1398 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1402 totaddrp = (unsigned int *)optval;
1403 totaddr = *totaddrp;
1404 sa = (struct sockaddr *)(totaddrp + 1);
1405 error = sctp_connectx_helper_find(inp, sa, totaddr, &num_v4, &num_v6, (unsigned int)(optsize - sizeof(int)));
1407 /* Already have or am bring up an association */
1408 SCTP_ASOC_CREATE_UNLOCK(inp);
1410 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1414 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1419 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1421 if (SCTP_IPV6_V6ONLY(inp)) {
1423 * if IPV6_V6ONLY flag, ignore connections destined
1424 * to a v4 addr or v4-mapped addr
1426 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1432 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1433 SCTP_PCB_FLAGS_UNBOUND) {
1434 /* Bind a ephemeral port */
1435 error = sctp_inpcb_bind(so, NULL, NULL, p);
1441 /* FIX ME: do we want to pass in a vrf on the connect call? */
1442 vrf_id = inp->def_vrf_id;
1445 /* We are GOOD to go */
1446 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1447 inp->sctp_ep.pre_open_stream_count,
1450 SCTP_INITIALIZE_AUTH_PARAMS);
1452 /* Gak! no memory */
1455 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1456 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1457 /* Set the connected flag so we can queue data */
1460 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1461 /* move to second address */
1462 switch (sa->sa_family) {
1465 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1470 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1478 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1479 /* Fill in the return id */
1483 a_id = (sctp_assoc_t *)optval;
1484 *a_id = sctp_get_associd(stcb);
1487 /* doing delayed connection */
1488 stcb->asoc.delayed_connection = 1;
1489 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1491 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1492 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1494 SCTP_TCB_UNLOCK(stcb);
1496 if (creat_lock_on) {
1497 SCTP_ASOC_CREATE_UNLOCK(inp);
1499 SCTP_INP_DECR_REF(inp);
1503 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1504 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1505 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1506 SCTP_INP_RLOCK(inp); \
1507 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1509 SCTP_TCB_LOCK(stcb); \
1511 SCTP_INP_RUNLOCK(inp); \
1512 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1513 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1514 if (stcb == NULL) { \
1515 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1525 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1526 if (size < sizeof(type)) { \
1527 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1531 destp = (type *)srcp; \
1536 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1539 struct sctp_inpcb *inp = NULL;
1541 struct sctp_tcb *stcb = NULL;
1543 if (optval == NULL) {
1544 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1548 inp = (struct sctp_inpcb *)so->so_pcb;
1550 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1557 case SCTP_AUTOCLOSE:
1558 case SCTP_EXPLICIT_EOR:
1559 case SCTP_AUTO_ASCONF:
1560 case SCTP_DISABLE_FRAGMENTS:
1561 case SCTP_I_WANT_MAPPED_V4_ADDR:
1562 case SCTP_USE_EXT_RCVINFO:
1563 SCTP_INP_RLOCK(inp);
1565 case SCTP_DISABLE_FRAGMENTS:
1566 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1568 case SCTP_I_WANT_MAPPED_V4_ADDR:
1569 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1571 case SCTP_AUTO_ASCONF:
1572 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1573 /* only valid for bound all sockets */
1574 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1576 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1581 case SCTP_EXPLICIT_EOR:
1582 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1585 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1587 case SCTP_USE_EXT_RCVINFO:
1588 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1590 case SCTP_AUTOCLOSE:
1591 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1592 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1598 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1599 error = ENOPROTOOPT;
1600 } /* end switch (sopt->sopt_name) */
1601 if (*optsize < sizeof(val)) {
1602 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1606 SCTP_INP_RUNLOCK(inp);
1608 /* return the option value */
1609 *(int *)optval = val;
1610 *optsize = sizeof(val);
1613 case SCTP_GET_PACKET_LOG:
1615 #ifdef SCTP_PACKET_LOGGING
1619 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1620 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1623 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1628 case SCTP_REUSE_PORT:
1632 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1633 /* Can't do this for a 1-m socket */
1637 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1638 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1639 *optsize = sizeof(uint32_t);
1642 case SCTP_PARTIAL_DELIVERY_POINT:
1646 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1647 *value = inp->partial_delivery_point;
1648 *optsize = sizeof(uint32_t);
1651 case SCTP_FRAGMENT_INTERLEAVE:
1655 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1656 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1657 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1658 *value = SCTP_FRAG_LEVEL_2;
1660 *value = SCTP_FRAG_LEVEL_1;
1663 *value = SCTP_FRAG_LEVEL_0;
1665 *optsize = sizeof(uint32_t);
1668 case SCTP_INTERLEAVING_SUPPORTED:
1670 struct sctp_assoc_value *av;
1672 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1673 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1676 av->assoc_value = stcb->asoc.idata_supported;
1677 SCTP_TCB_UNLOCK(stcb);
1679 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1680 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1681 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1682 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1683 SCTP_INP_RLOCK(inp);
1684 if (inp->idata_supported) {
1685 av->assoc_value = 1;
1687 av->assoc_value = 0;
1689 SCTP_INP_RUNLOCK(inp);
1691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1696 *optsize = sizeof(struct sctp_assoc_value);
1700 case SCTP_CMT_ON_OFF:
1702 struct sctp_assoc_value *av;
1704 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1705 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1707 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1708 SCTP_TCB_UNLOCK(stcb);
1710 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1711 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1712 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1713 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1714 SCTP_INP_RLOCK(inp);
1715 av->assoc_value = inp->sctp_cmt_on_off;
1716 SCTP_INP_RUNLOCK(inp);
1718 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1723 *optsize = sizeof(struct sctp_assoc_value);
1727 case SCTP_PLUGGABLE_CC:
1729 struct sctp_assoc_value *av;
1731 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1732 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1734 av->assoc_value = stcb->asoc.congestion_control_module;
1735 SCTP_TCB_UNLOCK(stcb);
1737 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1738 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1739 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1740 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1741 SCTP_INP_RLOCK(inp);
1742 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1743 SCTP_INP_RUNLOCK(inp);
1745 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1750 *optsize = sizeof(struct sctp_assoc_value);
1754 case SCTP_CC_OPTION:
1756 struct sctp_cc_option *cc_opt;
1758 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1759 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1763 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1766 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1767 *optsize = sizeof(struct sctp_cc_option);
1769 SCTP_TCB_UNLOCK(stcb);
1773 case SCTP_PLUGGABLE_SS:
1775 struct sctp_assoc_value *av;
1777 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1778 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1780 av->assoc_value = stcb->asoc.stream_scheduling_module;
1781 SCTP_TCB_UNLOCK(stcb);
1783 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1784 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1785 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1786 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1787 SCTP_INP_RLOCK(inp);
1788 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1789 SCTP_INP_RUNLOCK(inp);
1791 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1796 *optsize = sizeof(struct sctp_assoc_value);
1802 struct sctp_stream_value *av;
1804 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1805 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1807 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1808 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1809 &av->stream_value) < 0)) {
1810 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1813 *optsize = sizeof(struct sctp_stream_value);
1815 SCTP_TCB_UNLOCK(stcb);
1818 * Can't get stream value without
1821 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1826 case SCTP_GET_ADDR_LEN:
1828 struct sctp_assoc_value *av;
1830 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1833 if (av->assoc_value == AF_INET) {
1834 av->assoc_value = sizeof(struct sockaddr_in);
1839 if (av->assoc_value == AF_INET6) {
1840 av->assoc_value = sizeof(struct sockaddr_in6);
1845 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1847 *optsize = sizeof(struct sctp_assoc_value);
1851 case SCTP_GET_ASSOC_NUMBER:
1853 uint32_t *value, cnt;
1855 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1856 SCTP_INP_RLOCK(inp);
1857 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1858 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1859 /* Can't do this for a 1-1 socket */
1861 SCTP_INP_RUNLOCK(inp);
1865 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1868 SCTP_INP_RUNLOCK(inp);
1870 *optsize = sizeof(uint32_t);
1873 case SCTP_GET_ASSOC_ID_LIST:
1875 struct sctp_assoc_ids *ids;
1879 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1880 SCTP_INP_RLOCK(inp);
1881 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1882 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1883 /* Can't do this for a 1-1 socket */
1885 SCTP_INP_RUNLOCK(inp);
1889 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1890 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1892 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1895 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1900 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1904 SCTP_INP_RUNLOCK(inp);
1906 ids->gaids_number_of_ids = at;
1907 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1913 struct sctp_assoc_value *av;
1915 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1916 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1919 av->assoc_value = stcb->asoc.context;
1920 SCTP_TCB_UNLOCK(stcb);
1922 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1923 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1924 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1925 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1926 SCTP_INP_RLOCK(inp);
1927 av->assoc_value = inp->sctp_context;
1928 SCTP_INP_RUNLOCK(inp);
1930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1935 *optsize = sizeof(struct sctp_assoc_value);
1941 uint32_t *default_vrfid;
1943 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1944 *default_vrfid = inp->def_vrf_id;
1945 *optsize = sizeof(uint32_t);
1948 case SCTP_GET_ASOC_VRF:
1950 struct sctp_assoc_value *id;
1952 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1953 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1958 id->assoc_value = stcb->asoc.vrf_id;
1959 SCTP_TCB_UNLOCK(stcb);
1960 *optsize = sizeof(struct sctp_assoc_value);
1964 case SCTP_GET_VRF_IDS:
1966 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1970 case SCTP_GET_NONCE_VALUES:
1972 struct sctp_get_nonce_values *gnv;
1974 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1975 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1978 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1979 gnv->gn_local_tag = stcb->asoc.my_vtag;
1980 SCTP_TCB_UNLOCK(stcb);
1981 *optsize = sizeof(struct sctp_get_nonce_values);
1983 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1988 case SCTP_DELAYED_SACK:
1990 struct sctp_sack_info *sack;
1992 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1993 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1995 sack->sack_delay = stcb->asoc.delayed_ack;
1996 sack->sack_freq = stcb->asoc.sack_freq;
1997 SCTP_TCB_UNLOCK(stcb);
1999 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2000 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2001 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2002 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC))) {
2003 SCTP_INP_RLOCK(inp);
2004 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2005 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2006 SCTP_INP_RUNLOCK(inp);
2008 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2013 *optsize = sizeof(struct sctp_sack_info);
2017 case SCTP_GET_SNDBUF_USE:
2019 struct sctp_sockstat *ss;
2021 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2022 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2025 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2026 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2027 stcb->asoc.size_on_all_streams);
2028 SCTP_TCB_UNLOCK(stcb);
2029 *optsize = sizeof(struct sctp_sockstat);
2031 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2036 case SCTP_MAX_BURST:
2038 struct sctp_assoc_value *av;
2040 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2041 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2044 av->assoc_value = stcb->asoc.max_burst;
2045 SCTP_TCB_UNLOCK(stcb);
2047 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2048 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2049 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2050 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2051 SCTP_INP_RLOCK(inp);
2052 av->assoc_value = inp->sctp_ep.max_burst;
2053 SCTP_INP_RUNLOCK(inp);
2055 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2060 *optsize = sizeof(struct sctp_assoc_value);
2066 struct sctp_assoc_value *av;
2069 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2070 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2073 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2074 SCTP_TCB_UNLOCK(stcb);
2076 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2077 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2078 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2079 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2080 SCTP_INP_RLOCK(inp);
2081 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2082 ovh = SCTP_MED_OVERHEAD;
2084 ovh = SCTP_MED_V4_OVERHEAD;
2086 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2087 av->assoc_value = 0;
2089 av->assoc_value = inp->sctp_frag_point - ovh;
2090 SCTP_INP_RUNLOCK(inp);
2092 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2097 *optsize = sizeof(struct sctp_assoc_value);
2101 case SCTP_GET_STAT_LOG:
2102 error = sctp_fill_stat_log(optval, optsize);
2106 struct sctp_event_subscribe *events;
2108 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2109 memset(events, 0, sizeof(struct sctp_event_subscribe));
2110 SCTP_INP_RLOCK(inp);
2111 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2112 events->sctp_data_io_event = 1;
2114 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2115 events->sctp_association_event = 1;
2117 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2118 events->sctp_address_event = 1;
2120 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2121 events->sctp_send_failure_event = 1;
2123 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2124 events->sctp_peer_error_event = 1;
2126 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2127 events->sctp_shutdown_event = 1;
2129 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2130 events->sctp_partial_delivery_event = 1;
2132 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2133 events->sctp_adaptation_layer_event = 1;
2135 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2136 events->sctp_authentication_event = 1;
2138 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2139 events->sctp_sender_dry_event = 1;
2141 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2142 events->sctp_stream_reset_event = 1;
2143 SCTP_INP_RUNLOCK(inp);
2144 *optsize = sizeof(struct sctp_event_subscribe);
2147 case SCTP_ADAPTATION_LAYER:
2151 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2153 SCTP_INP_RLOCK(inp);
2154 *value = inp->sctp_ep.adaptation_layer_indicator;
2155 SCTP_INP_RUNLOCK(inp);
2156 *optsize = sizeof(uint32_t);
2159 case SCTP_SET_INITIAL_DBG_SEQ:
2163 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2164 SCTP_INP_RLOCK(inp);
2165 *value = inp->sctp_ep.initial_sequence_debug;
2166 SCTP_INP_RUNLOCK(inp);
2167 *optsize = sizeof(uint32_t);
2170 case SCTP_GET_LOCAL_ADDR_SIZE:
2174 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2175 SCTP_INP_RLOCK(inp);
2176 *value = sctp_count_max_addresses(inp);
2177 SCTP_INP_RUNLOCK(inp);
2178 *optsize = sizeof(uint32_t);
2181 case SCTP_GET_REMOTE_ADDR_SIZE:
2185 struct sctp_nets *net;
2187 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2188 /* FIXME MT: change to sctp_assoc_value? */
2189 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2193 /* Count the sizes */
2194 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2195 switch (net->ro._l_addr.sa.sa_family) {
2199 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2200 size += sizeof(struct sockaddr_in6);
2202 size += sizeof(struct sockaddr_in);
2205 size += sizeof(struct sockaddr_in);
2211 size += sizeof(struct sockaddr_in6);
2218 SCTP_TCB_UNLOCK(stcb);
2219 *value = (uint32_t)size;
2220 *optsize = sizeof(uint32_t);
2222 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2227 case SCTP_GET_PEER_ADDRESSES:
2229 * Get the address information, an array is passed in to
2230 * fill up we pack it.
2234 struct sockaddr_storage *sas;
2235 struct sctp_nets *net;
2236 struct sctp_getaddresses *saddr;
2238 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2239 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2242 left = (*optsize) - sizeof(sctp_assoc_t);
2243 *optsize = sizeof(sctp_assoc_t);
2244 sas = (struct sockaddr_storage *)&saddr->addr[0];
2246 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2247 switch (net->ro._l_addr.sa.sa_family) {
2251 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2252 cpsz = sizeof(struct sockaddr_in6);
2254 cpsz = sizeof(struct sockaddr_in);
2257 cpsz = sizeof(struct sockaddr_in);
2263 cpsz = sizeof(struct sockaddr_in6);
2274 /* not enough room. */
2277 #if defined(INET) && defined(INET6)
2278 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2279 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2280 /* Must map the address */
2281 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2282 (struct sockaddr_in6 *)sas);
2284 memcpy(sas, &net->ro._l_addr, cpsz);
2287 memcpy(sas, &net->ro._l_addr, cpsz);
2289 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2291 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2295 SCTP_TCB_UNLOCK(stcb);
2297 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2302 case SCTP_GET_LOCAL_ADDRESSES:
2304 size_t limit, actual;
2305 struct sockaddr_storage *sas;
2306 struct sctp_getaddresses *saddr;
2308 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2309 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2311 sas = (struct sockaddr_storage *)&saddr->addr[0];
2312 limit = *optsize - sizeof(sctp_assoc_t);
2313 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2315 SCTP_TCB_UNLOCK(stcb);
2317 *optsize = sizeof(sctp_assoc_t) + actual;
2320 case SCTP_PEER_ADDR_PARAMS:
2322 struct sctp_paddrparams *paddrp;
2323 struct sctp_nets *net;
2324 struct sockaddr *addr;
2325 #if defined(INET) && defined(INET6)
2326 struct sockaddr_in sin_store;
2329 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2330 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2332 #if defined(INET) && defined(INET6)
2333 if (paddrp->spp_address.ss_family == AF_INET6) {
2334 struct sockaddr_in6 *sin6;
2336 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2337 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2338 in6_sin6_2_sin(&sin_store, sin6);
2339 addr = (struct sockaddr *)&sin_store;
2341 addr = (struct sockaddr *)&paddrp->spp_address;
2344 addr = (struct sockaddr *)&paddrp->spp_address;
2347 addr = (struct sockaddr *)&paddrp->spp_address;
2350 net = sctp_findnet(stcb, addr);
2353 * We increment here since
2354 * sctp_findassociation_ep_addr() wil do a
2355 * decrement if it finds the stcb as long as
2356 * the locked tcb (last argument) is NOT a
2360 SCTP_INP_INCR_REF(inp);
2361 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2363 SCTP_INP_DECR_REF(inp);
2366 if ((stcb != NULL) && (net == NULL)) {
2368 if (addr->sa_family == AF_INET) {
2369 struct sockaddr_in *sin;
2371 sin = (struct sockaddr_in *)addr;
2372 if (sin->sin_addr.s_addr != INADDR_ANY) {
2374 SCTP_TCB_UNLOCK(stcb);
2375 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2381 if (addr->sa_family == AF_INET6) {
2382 struct sockaddr_in6 *sin6;
2384 sin6 = (struct sockaddr_in6 *)addr;
2385 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2387 SCTP_TCB_UNLOCK(stcb);
2388 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2394 error = EAFNOSUPPORT;
2395 SCTP_TCB_UNLOCK(stcb);
2396 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2402 /* Applies to the specific association */
2403 paddrp->spp_flags = 0;
2405 paddrp->spp_hbinterval = net->heart_beat_delay;
2406 paddrp->spp_pathmaxrxt = net->failure_threshold;
2407 paddrp->spp_pathmtu = net->mtu;
2408 switch (net->ro._l_addr.sa.sa_family) {
2411 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2416 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2422 /* get flags for HB */
2423 if (net->dest_state & SCTP_ADDR_NOHB) {
2424 paddrp->spp_flags |= SPP_HB_DISABLE;
2426 paddrp->spp_flags |= SPP_HB_ENABLE;
2428 /* get flags for PMTU */
2429 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2430 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2432 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2434 if (net->dscp & 0x01) {
2435 paddrp->spp_dscp = net->dscp & 0xfc;
2436 paddrp->spp_flags |= SPP_DSCP;
2439 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2440 (net->flowlabel & 0x80000000)) {
2441 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2442 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2447 * No destination so return default
2450 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2451 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2452 if (stcb->asoc.default_dscp & 0x01) {
2453 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2454 paddrp->spp_flags |= SPP_DSCP;
2457 if (stcb->asoc.default_flowlabel & 0x80000000) {
2458 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2459 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2462 /* default settings should be these */
2463 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2464 paddrp->spp_flags |= SPP_HB_DISABLE;
2466 paddrp->spp_flags |= SPP_HB_ENABLE;
2468 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2469 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2471 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2473 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2475 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2476 SCTP_TCB_UNLOCK(stcb);
2478 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2479 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2480 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2481 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
2482 /* Use endpoint defaults */
2483 SCTP_INP_RLOCK(inp);
2484 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2485 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2486 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2487 /* get inp's default */
2488 if (inp->sctp_ep.default_dscp & 0x01) {
2489 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2490 paddrp->spp_flags |= SPP_DSCP;
2493 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2494 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2495 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2496 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2499 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2501 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2502 paddrp->spp_flags |= SPP_HB_ENABLE;
2504 paddrp->spp_flags |= SPP_HB_DISABLE;
2506 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2507 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2509 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2511 SCTP_INP_RUNLOCK(inp);
2513 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2518 *optsize = sizeof(struct sctp_paddrparams);
2522 case SCTP_GET_PEER_ADDR_INFO:
2524 struct sctp_paddrinfo *paddri;
2525 struct sctp_nets *net;
2526 struct sockaddr *addr;
2527 #if defined(INET) && defined(INET6)
2528 struct sockaddr_in sin_store;
2531 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2532 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2534 #if defined(INET) && defined(INET6)
2535 if (paddri->spinfo_address.ss_family == AF_INET6) {
2536 struct sockaddr_in6 *sin6;
2538 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2539 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2540 in6_sin6_2_sin(&sin_store, sin6);
2541 addr = (struct sockaddr *)&sin_store;
2543 addr = (struct sockaddr *)&paddri->spinfo_address;
2546 addr = (struct sockaddr *)&paddri->spinfo_address;
2549 addr = (struct sockaddr *)&paddri->spinfo_address;
2552 net = sctp_findnet(stcb, addr);
2555 * We increment here since
2556 * sctp_findassociation_ep_addr() wil do a
2557 * decrement if it finds the stcb as long as
2558 * the locked tcb (last argument) is NOT a
2562 SCTP_INP_INCR_REF(inp);
2563 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2565 SCTP_INP_DECR_REF(inp);
2569 if ((stcb != NULL) && (net != NULL)) {
2570 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2571 /* It's unconfirmed */
2572 paddri->spinfo_state = SCTP_UNCONFIRMED;
2573 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2575 paddri->spinfo_state = SCTP_ACTIVE;
2578 paddri->spinfo_state = SCTP_INACTIVE;
2580 paddri->spinfo_cwnd = net->cwnd;
2581 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2582 paddri->spinfo_rto = net->RTO;
2583 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2584 paddri->spinfo_mtu = net->mtu;
2585 switch (addr->sa_family) {
2588 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2593 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2599 SCTP_TCB_UNLOCK(stcb);
2600 *optsize = sizeof(struct sctp_paddrinfo);
2603 SCTP_TCB_UNLOCK(stcb);
2605 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2610 case SCTP_PCB_STATUS:
2612 struct sctp_pcbinfo *spcb;
2614 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2615 sctp_fill_pcbinfo(spcb);
2616 *optsize = sizeof(struct sctp_pcbinfo);
2621 struct sctp_nets *net;
2622 struct sctp_status *sstat;
2624 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2625 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2628 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2632 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2633 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2634 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2635 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2637 * We can't include chunks that have been passed to
2638 * the socket layer. Only things in queue.
2640 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2641 stcb->asoc.cnt_on_all_streams);
2644 sstat->sstat_instrms = stcb->asoc.streamincnt;
2645 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2646 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2647 net = stcb->asoc.primary_destination;
2649 memcpy(&sstat->sstat_primary.spinfo_address,
2650 &stcb->asoc.primary_destination->ro._l_addr,
2651 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2652 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2654 * Again the user can get info from
2655 * sctp_constants.h for what the state of
2658 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2659 /* It's unconfirmed */
2660 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2661 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2663 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2666 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2668 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2669 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2670 sstat->sstat_primary.spinfo_rto = net->RTO;
2671 sstat->sstat_primary.spinfo_mtu = net->mtu;
2672 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2675 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2680 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2687 memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo));
2689 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2690 SCTP_TCB_UNLOCK(stcb);
2691 *optsize = sizeof(struct sctp_status);
2696 struct sctp_rtoinfo *srto;
2698 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2699 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2702 srto->srto_initial = stcb->asoc.initial_rto;
2703 srto->srto_max = stcb->asoc.maxrto;
2704 srto->srto_min = stcb->asoc.minrto;
2705 SCTP_TCB_UNLOCK(stcb);
2707 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2708 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2709 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2710 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
2711 SCTP_INP_RLOCK(inp);
2712 srto->srto_initial = inp->sctp_ep.initial_rto;
2713 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2714 srto->srto_min = inp->sctp_ep.sctp_minrto;
2715 SCTP_INP_RUNLOCK(inp);
2717 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2722 *optsize = sizeof(struct sctp_rtoinfo);
2728 struct sctp_timeouts *stimo;
2730 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2731 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2734 stimo->stimo_init = stcb->asoc.timoinit;
2735 stimo->stimo_data = stcb->asoc.timodata;
2736 stimo->stimo_sack = stcb->asoc.timosack;
2737 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2738 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2739 stimo->stimo_cookie = stcb->asoc.timocookie;
2740 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2741 SCTP_TCB_UNLOCK(stcb);
2742 *optsize = sizeof(struct sctp_timeouts);
2744 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2749 case SCTP_ASSOCINFO:
2751 struct sctp_assocparams *sasoc;
2753 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2754 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2757 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2758 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2759 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2760 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2761 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2762 SCTP_TCB_UNLOCK(stcb);
2764 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2765 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2766 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2767 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
2768 SCTP_INP_RLOCK(inp);
2769 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2770 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2771 sasoc->sasoc_number_peer_destinations = 0;
2772 sasoc->sasoc_peer_rwnd = 0;
2773 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2774 SCTP_INP_RUNLOCK(inp);
2776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2781 *optsize = sizeof(struct sctp_assocparams);
2785 case SCTP_DEFAULT_SEND_PARAM:
2787 struct sctp_sndrcvinfo *s_info;
2789 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2790 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2793 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2794 SCTP_TCB_UNLOCK(stcb);
2796 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2797 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2798 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2799 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC))) {
2800 SCTP_INP_RLOCK(inp);
2801 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2802 SCTP_INP_RUNLOCK(inp);
2804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2809 *optsize = sizeof(struct sctp_sndrcvinfo);
2815 struct sctp_initmsg *sinit;
2817 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2818 SCTP_INP_RLOCK(inp);
2819 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2820 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2821 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2822 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2823 SCTP_INP_RUNLOCK(inp);
2824 *optsize = sizeof(struct sctp_initmsg);
2827 case SCTP_PRIMARY_ADDR:
2828 /* we allow a "get" operation on this */
2830 struct sctp_setprim *ssp;
2832 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2833 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2836 union sctp_sockstore *addr;
2838 addr = &stcb->asoc.primary_destination->ro._l_addr;
2839 switch (addr->sa.sa_family) {
2843 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2844 in6_sin_2_v4mapsin6(&addr->sin,
2845 (struct sockaddr_in6 *)&ssp->ssp_addr);
2847 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2850 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2856 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2862 SCTP_TCB_UNLOCK(stcb);
2863 *optsize = sizeof(struct sctp_setprim);
2865 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2870 case SCTP_HMAC_IDENT:
2872 struct sctp_hmacalgo *shmac;
2873 sctp_hmaclist_t *hmaclist;
2877 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2879 SCTP_INP_RLOCK(inp);
2880 hmaclist = inp->sctp_ep.local_hmacs;
2881 if (hmaclist == NULL) {
2882 /* no HMACs to return */
2883 *optsize = sizeof(*shmac);
2884 SCTP_INP_RUNLOCK(inp);
2887 /* is there room for all of the hmac ids? */
2888 size = sizeof(*shmac) + (hmaclist->num_algo *
2889 sizeof(shmac->shmac_idents[0]));
2890 if ((size_t)(*optsize) < size) {
2891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2893 SCTP_INP_RUNLOCK(inp);
2896 /* copy in the list */
2897 shmac->shmac_number_of_idents = hmaclist->num_algo;
2898 for (i = 0; i < hmaclist->num_algo; i++) {
2899 shmac->shmac_idents[i] = hmaclist->hmac[i];
2901 SCTP_INP_RUNLOCK(inp);
2905 case SCTP_AUTH_ACTIVE_KEY:
2907 struct sctp_authkeyid *scact;
2909 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2910 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2913 /* get the active key on the assoc */
2914 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2915 SCTP_TCB_UNLOCK(stcb);
2917 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2918 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2919 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2920 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC))) {
2921 /* get the endpoint active key */
2922 SCTP_INP_RLOCK(inp);
2923 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2924 SCTP_INP_RUNLOCK(inp);
2926 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2931 *optsize = sizeof(struct sctp_authkeyid);
2935 case SCTP_LOCAL_AUTH_CHUNKS:
2937 struct sctp_authchunks *sac;
2938 sctp_auth_chklist_t *chklist = NULL;
2941 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2942 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2945 /* get off the assoc */
2946 chklist = stcb->asoc.local_auth_chunks;
2947 /* is there enough space? */
2948 size = sctp_auth_get_chklist_size(chklist);
2949 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2953 /* copy in the chunks */
2954 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2955 sac->gauth_number_of_chunks = (uint32_t)size;
2956 *optsize = sizeof(struct sctp_authchunks) + size;
2958 SCTP_TCB_UNLOCK(stcb);
2960 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2961 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2962 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2963 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC))) {
2964 /* get off the endpoint */
2965 SCTP_INP_RLOCK(inp);
2966 chklist = inp->sctp_ep.local_auth_chunks;
2967 /* is there enough space? */
2968 size = sctp_auth_get_chklist_size(chklist);
2969 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2971 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2973 /* copy in the chunks */
2974 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2975 sac->gauth_number_of_chunks = (uint32_t)size;
2976 *optsize = sizeof(struct sctp_authchunks) + size;
2978 SCTP_INP_RUNLOCK(inp);
2980 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2986 case SCTP_PEER_AUTH_CHUNKS:
2988 struct sctp_authchunks *sac;
2989 sctp_auth_chklist_t *chklist = NULL;
2992 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2993 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2996 /* get off the assoc */
2997 chklist = stcb->asoc.peer_auth_chunks;
2998 /* is there enough space? */
2999 size = sctp_auth_get_chklist_size(chklist);
3000 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
3002 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3004 /* copy in the chunks */
3005 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3006 sac->gauth_number_of_chunks = (uint32_t)size;
3007 *optsize = sizeof(struct sctp_authchunks) + size;
3009 SCTP_TCB_UNLOCK(stcb);
3011 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3018 struct sctp_event *event;
3019 uint32_t event_type;
3021 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3022 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3024 switch (event->se_type) {
3025 case SCTP_ASSOC_CHANGE:
3026 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3028 case SCTP_PEER_ADDR_CHANGE:
3029 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3031 case SCTP_REMOTE_ERROR:
3032 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3034 case SCTP_SEND_FAILED:
3035 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3037 case SCTP_SHUTDOWN_EVENT:
3038 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3040 case SCTP_ADAPTATION_INDICATION:
3041 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3043 case SCTP_PARTIAL_DELIVERY_EVENT:
3044 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3046 case SCTP_AUTHENTICATION_EVENT:
3047 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3049 case SCTP_STREAM_RESET_EVENT:
3050 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3052 case SCTP_SENDER_DRY_EVENT:
3053 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3055 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3057 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3060 case SCTP_ASSOC_RESET_EVENT:
3061 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3063 case SCTP_STREAM_CHANGE_EVENT:
3064 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3066 case SCTP_SEND_FAILED_EVENT:
3067 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3071 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3075 if (event_type > 0) {
3077 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3079 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3080 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3081 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3082 (event->se_assoc_id == SCTP_FUTURE_ASSOC))) {
3083 SCTP_INP_RLOCK(inp);
3084 event->se_on = sctp_is_feature_on(inp, event_type);
3085 SCTP_INP_RUNLOCK(inp);
3087 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3093 SCTP_TCB_UNLOCK(stcb);
3096 *optsize = sizeof(struct sctp_event);
3100 case SCTP_RECVRCVINFO:
3104 if (*optsize < sizeof(int)) {
3105 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3108 SCTP_INP_RLOCK(inp);
3109 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3110 SCTP_INP_RUNLOCK(inp);
3113 /* return the option value */
3114 *(int *)optval = onoff;
3115 *optsize = sizeof(int);
3119 case SCTP_RECVNXTINFO:
3123 if (*optsize < sizeof(int)) {
3124 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3127 SCTP_INP_RLOCK(inp);
3128 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3129 SCTP_INP_RUNLOCK(inp);
3132 /* return the option value */
3133 *(int *)optval = onoff;
3134 *optsize = sizeof(int);
3138 case SCTP_DEFAULT_SNDINFO:
3140 struct sctp_sndinfo *info;
3142 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3143 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3146 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3147 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3148 info->snd_flags &= 0xfff0;
3149 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3150 info->snd_context = stcb->asoc.def_send.sinfo_context;
3151 SCTP_TCB_UNLOCK(stcb);
3153 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3154 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3155 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3156 (info->snd_assoc_id == SCTP_FUTURE_ASSOC))) {
3157 SCTP_INP_RLOCK(inp);
3158 info->snd_sid = inp->def_send.sinfo_stream;
3159 info->snd_flags = inp->def_send.sinfo_flags;
3160 info->snd_flags &= 0xfff0;
3161 info->snd_ppid = inp->def_send.sinfo_ppid;
3162 info->snd_context = inp->def_send.sinfo_context;
3163 SCTP_INP_RUNLOCK(inp);
3165 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3170 *optsize = sizeof(struct sctp_sndinfo);
3174 case SCTP_DEFAULT_PRINFO:
3176 struct sctp_default_prinfo *info;
3178 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3179 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3182 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3183 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3184 SCTP_TCB_UNLOCK(stcb);
3186 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3187 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3188 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3189 (info->pr_assoc_id == SCTP_FUTURE_ASSOC))) {
3190 SCTP_INP_RLOCK(inp);
3191 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3192 info->pr_value = inp->def_send.sinfo_timetolive;
3193 SCTP_INP_RUNLOCK(inp);
3195 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3200 *optsize = sizeof(struct sctp_default_prinfo);
3204 case SCTP_PEER_ADDR_THLDS:
3206 struct sctp_paddrthlds *thlds;
3207 struct sctp_nets *net;
3208 struct sockaddr *addr;
3209 #if defined(INET) && defined(INET6)
3210 struct sockaddr_in sin_store;
3213 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3214 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3216 #if defined(INET) && defined(INET6)
3217 if (thlds->spt_address.ss_family == AF_INET6) {
3218 struct sockaddr_in6 *sin6;
3220 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3221 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3222 in6_sin6_2_sin(&sin_store, sin6);
3223 addr = (struct sockaddr *)&sin_store;
3225 addr = (struct sockaddr *)&thlds->spt_address;
3228 addr = (struct sockaddr *)&thlds->spt_address;
3231 addr = (struct sockaddr *)&thlds->spt_address;
3234 net = sctp_findnet(stcb, addr);
3237 * We increment here since
3238 * sctp_findassociation_ep_addr() wil do a
3239 * decrement if it finds the stcb as long as
3240 * the locked tcb (last argument) is NOT a
3244 SCTP_INP_INCR_REF(inp);
3245 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3247 SCTP_INP_DECR_REF(inp);
3250 if ((stcb != NULL) && (net == NULL)) {
3252 if (addr->sa_family == AF_INET) {
3253 struct sockaddr_in *sin;
3255 sin = (struct sockaddr_in *)addr;
3256 if (sin->sin_addr.s_addr != INADDR_ANY) {
3258 SCTP_TCB_UNLOCK(stcb);
3259 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3265 if (addr->sa_family == AF_INET6) {
3266 struct sockaddr_in6 *sin6;
3268 sin6 = (struct sockaddr_in6 *)addr;
3269 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3271 SCTP_TCB_UNLOCK(stcb);
3272 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3278 error = EAFNOSUPPORT;
3279 SCTP_TCB_UNLOCK(stcb);
3280 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3287 thlds->spt_pathmaxrxt = net->failure_threshold;
3288 thlds->spt_pathpfthld = net->pf_threshold;
3289 thlds->spt_pathcpthld = 0xffff;
3291 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3292 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3293 thlds->spt_pathcpthld = 0xffff;
3295 thlds->spt_assoc_id = sctp_get_associd(stcb);
3296 SCTP_TCB_UNLOCK(stcb);
3298 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3299 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3300 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3301 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
3302 /* Use endpoint defaults */
3303 SCTP_INP_RLOCK(inp);
3304 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3305 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3306 thlds->spt_pathcpthld = 0xffff;
3307 SCTP_INP_RUNLOCK(inp);
3309 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3314 *optsize = sizeof(struct sctp_paddrthlds);
3318 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3320 struct sctp_udpencaps *encaps;
3321 struct sctp_nets *net;
3322 struct sockaddr *addr;
3323 #if defined(INET) && defined(INET6)
3324 struct sockaddr_in sin_store;
3327 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3328 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3330 #if defined(INET) && defined(INET6)
3331 if (encaps->sue_address.ss_family == AF_INET6) {
3332 struct sockaddr_in6 *sin6;
3334 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3335 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3336 in6_sin6_2_sin(&sin_store, sin6);
3337 addr = (struct sockaddr *)&sin_store;
3339 addr = (struct sockaddr *)&encaps->sue_address;
3342 addr = (struct sockaddr *)&encaps->sue_address;
3345 addr = (struct sockaddr *)&encaps->sue_address;
3348 net = sctp_findnet(stcb, addr);
3351 * We increment here since
3352 * sctp_findassociation_ep_addr() wil do a
3353 * decrement if it finds the stcb as long as
3354 * the locked tcb (last argument) is NOT a
3358 SCTP_INP_INCR_REF(inp);
3359 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3361 SCTP_INP_DECR_REF(inp);
3364 if ((stcb != NULL) && (net == NULL)) {
3366 if (addr->sa_family == AF_INET) {
3367 struct sockaddr_in *sin;
3369 sin = (struct sockaddr_in *)addr;
3370 if (sin->sin_addr.s_addr != INADDR_ANY) {
3372 SCTP_TCB_UNLOCK(stcb);
3373 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3379 if (addr->sa_family == AF_INET6) {
3380 struct sockaddr_in6 *sin6;
3382 sin6 = (struct sockaddr_in6 *)addr;
3383 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3385 SCTP_TCB_UNLOCK(stcb);
3386 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3392 error = EAFNOSUPPORT;
3393 SCTP_TCB_UNLOCK(stcb);
3394 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3401 encaps->sue_port = net->port;
3403 encaps->sue_port = stcb->asoc.port;
3405 SCTP_TCB_UNLOCK(stcb);
3407 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3408 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3409 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3410 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
3411 SCTP_INP_RLOCK(inp);
3412 encaps->sue_port = inp->sctp_ep.port;
3413 SCTP_INP_RUNLOCK(inp);
3415 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3420 *optsize = sizeof(struct sctp_udpencaps);
3424 case SCTP_ECN_SUPPORTED:
3426 struct sctp_assoc_value *av;
3428 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3429 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3432 av->assoc_value = stcb->asoc.ecn_supported;
3433 SCTP_TCB_UNLOCK(stcb);
3435 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3436 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3437 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3438 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3439 SCTP_INP_RLOCK(inp);
3440 av->assoc_value = inp->ecn_supported;
3441 SCTP_INP_RUNLOCK(inp);
3443 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3448 *optsize = sizeof(struct sctp_assoc_value);
3452 case SCTP_PR_SUPPORTED:
3454 struct sctp_assoc_value *av;
3456 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3457 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3460 av->assoc_value = stcb->asoc.prsctp_supported;
3461 SCTP_TCB_UNLOCK(stcb);
3463 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3464 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3465 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3466 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3467 SCTP_INP_RLOCK(inp);
3468 av->assoc_value = inp->prsctp_supported;
3469 SCTP_INP_RUNLOCK(inp);
3471 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3476 *optsize = sizeof(struct sctp_assoc_value);
3480 case SCTP_AUTH_SUPPORTED:
3482 struct sctp_assoc_value *av;
3484 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3485 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3488 av->assoc_value = stcb->asoc.auth_supported;
3489 SCTP_TCB_UNLOCK(stcb);
3491 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3492 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3493 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3494 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3495 SCTP_INP_RLOCK(inp);
3496 av->assoc_value = inp->auth_supported;
3497 SCTP_INP_RUNLOCK(inp);
3499 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3504 *optsize = sizeof(struct sctp_assoc_value);
3508 case SCTP_ASCONF_SUPPORTED:
3510 struct sctp_assoc_value *av;
3512 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3513 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3516 av->assoc_value = stcb->asoc.asconf_supported;
3517 SCTP_TCB_UNLOCK(stcb);
3519 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3520 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3521 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3522 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3523 SCTP_INP_RLOCK(inp);
3524 av->assoc_value = inp->asconf_supported;
3525 SCTP_INP_RUNLOCK(inp);
3527 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3532 *optsize = sizeof(struct sctp_assoc_value);
3536 case SCTP_RECONFIG_SUPPORTED:
3538 struct sctp_assoc_value *av;
3540 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3541 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3544 av->assoc_value = stcb->asoc.reconfig_supported;
3545 SCTP_TCB_UNLOCK(stcb);
3547 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3548 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3549 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3550 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3551 SCTP_INP_RLOCK(inp);
3552 av->assoc_value = inp->reconfig_supported;
3553 SCTP_INP_RUNLOCK(inp);
3555 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3560 *optsize = sizeof(struct sctp_assoc_value);
3564 case SCTP_NRSACK_SUPPORTED:
3566 struct sctp_assoc_value *av;
3568 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3569 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3572 av->assoc_value = stcb->asoc.nrsack_supported;
3573 SCTP_TCB_UNLOCK(stcb);
3575 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3576 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3577 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3578 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3579 SCTP_INP_RLOCK(inp);
3580 av->assoc_value = inp->nrsack_supported;
3581 SCTP_INP_RUNLOCK(inp);
3583 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3588 *optsize = sizeof(struct sctp_assoc_value);
3592 case SCTP_PKTDROP_SUPPORTED:
3594 struct sctp_assoc_value *av;
3596 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3597 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3600 av->assoc_value = stcb->asoc.pktdrop_supported;
3601 SCTP_TCB_UNLOCK(stcb);
3603 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3604 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3605 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3606 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3607 SCTP_INP_RLOCK(inp);
3608 av->assoc_value = inp->pktdrop_supported;
3609 SCTP_INP_RUNLOCK(inp);
3611 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3616 *optsize = sizeof(struct sctp_assoc_value);
3620 case SCTP_ENABLE_STREAM_RESET:
3622 struct sctp_assoc_value *av;
3624 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3625 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3628 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3629 SCTP_TCB_UNLOCK(stcb);
3631 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3632 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3633 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3634 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3635 SCTP_INP_RLOCK(inp);
3636 av->assoc_value = (uint32_t)inp->local_strreset_support;
3637 SCTP_INP_RUNLOCK(inp);
3639 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3644 *optsize = sizeof(struct sctp_assoc_value);
3648 case SCTP_PR_STREAM_STATUS:
3650 struct sctp_prstatus *sprstat;
3654 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3655 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3657 sid = sprstat->sprstat_sid;
3658 policy = sprstat->sprstat_policy;
3659 #if defined(SCTP_DETAILED_STR_STATS)
3660 if ((stcb != NULL) &&
3661 (sid < stcb->asoc.streamoutcnt) &&
3662 (policy != SCTP_PR_SCTP_NONE) &&
3663 ((policy <= SCTP_PR_SCTP_MAX) ||
3664 (policy == SCTP_PR_SCTP_ALL))) {
3665 if (policy == SCTP_PR_SCTP_ALL) {
3666 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3667 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3669 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3670 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3673 if ((stcb != NULL) &&
3674 (sid < stcb->asoc.streamoutcnt) &&
3675 (policy == SCTP_PR_SCTP_ALL)) {
3676 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3677 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3680 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3684 SCTP_TCB_UNLOCK(stcb);
3687 *optsize = sizeof(struct sctp_prstatus);
3691 case SCTP_PR_ASSOC_STATUS:
3693 struct sctp_prstatus *sprstat;
3696 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3697 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3699 policy = sprstat->sprstat_policy;
3700 if ((stcb != NULL) &&
3701 (policy != SCTP_PR_SCTP_NONE) &&
3702 ((policy <= SCTP_PR_SCTP_MAX) ||
3703 (policy == SCTP_PR_SCTP_ALL))) {
3704 if (policy == SCTP_PR_SCTP_ALL) {
3705 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3706 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3708 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3709 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3712 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3716 SCTP_TCB_UNLOCK(stcb);
3719 *optsize = sizeof(struct sctp_prstatus);
3725 struct sctp_assoc_value *av;
3727 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3728 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3731 av->assoc_value = stcb->asoc.max_cwnd;
3732 SCTP_TCB_UNLOCK(stcb);
3734 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3735 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3736 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3737 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3738 SCTP_INP_RLOCK(inp);
3739 av->assoc_value = inp->max_cwnd;
3740 SCTP_INP_RUNLOCK(inp);
3742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3747 *optsize = sizeof(struct sctp_assoc_value);
3752 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3753 error = ENOPROTOOPT;
3755 } /* end switch (sopt->sopt_name) */
3763 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3768 struct sctp_tcb *stcb = NULL;
3769 struct sctp_inpcb *inp = NULL;
3772 if (optval == NULL) {
3773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3776 inp = (struct sctp_inpcb *)so->so_pcb;
3778 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3781 vrf_id = inp->def_vrf_id;
3786 case SCTP_AUTOCLOSE:
3787 case SCTP_AUTO_ASCONF:
3788 case SCTP_EXPLICIT_EOR:
3789 case SCTP_DISABLE_FRAGMENTS:
3790 case SCTP_USE_EXT_RCVINFO:
3791 case SCTP_I_WANT_MAPPED_V4_ADDR:
3792 /* copy in the option value */
3793 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3798 case SCTP_DISABLE_FRAGMENTS:
3799 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3801 case SCTP_AUTO_ASCONF:
3803 * NOTE: we don't really support this flag
3805 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3806 /* only valid for bound all sockets */
3807 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3809 /* forbidden by admin */
3810 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3813 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3815 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3819 case SCTP_EXPLICIT_EOR:
3820 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3822 case SCTP_USE_EXT_RCVINFO:
3823 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3825 case SCTP_I_WANT_MAPPED_V4_ADDR:
3826 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3827 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3829 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3834 set_opt = SCTP_PCB_FLAGS_NODELAY;
3836 case SCTP_AUTOCLOSE:
3837 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3838 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3839 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3842 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3844 * The value is in ticks. Note this does not effect
3845 * old associations, only new ones.
3847 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3850 SCTP_INP_WLOCK(inp);
3852 sctp_feature_on(inp, set_opt);
3854 sctp_feature_off(inp, set_opt);
3856 SCTP_INP_WUNLOCK(inp);
3858 case SCTP_REUSE_PORT:
3860 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3861 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3862 /* Can't set it after we are bound */
3866 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3867 /* Can't do this for a 1-m socket */
3872 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3874 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3877 case SCTP_PARTIAL_DELIVERY_POINT:
3881 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3882 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3883 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3887 inp->partial_delivery_point = *value;
3890 case SCTP_FRAGMENT_INTERLEAVE:
3891 /* not yet until we re-write sctp_recvmsg() */
3895 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3896 if (*level == SCTP_FRAG_LEVEL_2) {
3897 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3898 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3899 } else if (*level == SCTP_FRAG_LEVEL_1) {
3900 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3901 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3902 } else if (*level == SCTP_FRAG_LEVEL_0) {
3903 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3904 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3907 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3912 case SCTP_INTERLEAVING_SUPPORTED:
3914 struct sctp_assoc_value *av;
3916 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3917 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3920 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3922 SCTP_TCB_UNLOCK(stcb);
3924 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3925 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3926 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3927 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3928 SCTP_INP_WLOCK(inp);
3929 if (av->assoc_value == 0) {
3930 inp->idata_supported = 0;
3932 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3933 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3934 inp->idata_supported = 1;
3942 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3946 SCTP_INP_WUNLOCK(inp);
3948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3954 case SCTP_CMT_ON_OFF:
3955 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3956 struct sctp_assoc_value *av;
3958 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3959 if (av->assoc_value > SCTP_CMT_MAX) {
3960 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3964 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3966 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3967 SCTP_TCB_UNLOCK(stcb);
3969 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3970 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3971 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3972 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3973 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3974 SCTP_INP_WLOCK(inp);
3975 inp->sctp_cmt_on_off = av->assoc_value;
3976 SCTP_INP_WUNLOCK(inp);
3978 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3979 ((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.sctp_cmt_on_off = av->assoc_value;
3985 SCTP_TCB_UNLOCK(stcb);
3987 SCTP_INP_RUNLOCK(inp);
3991 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3992 error = ENOPROTOOPT;
3995 case SCTP_PLUGGABLE_CC:
3997 struct sctp_assoc_value *av;
3998 struct sctp_nets *net;
4000 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4001 if ((av->assoc_value != SCTP_CC_RFC2581) &&
4002 (av->assoc_value != SCTP_CC_HSTCP) &&
4003 (av->assoc_value != SCTP_CC_HTCP) &&
4004 (av->assoc_value != SCTP_CC_RTCC)) {
4005 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4009 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4011 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4012 stcb->asoc.congestion_control_module = av->assoc_value;
4013 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4014 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4015 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4018 SCTP_TCB_UNLOCK(stcb);
4020 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4021 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4022 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4023 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4024 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4025 SCTP_INP_WLOCK(inp);
4026 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
4027 SCTP_INP_WUNLOCK(inp);
4029 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4030 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4031 (av->assoc_id == SCTP_ALL_ASSOC))) {
4032 SCTP_INP_RLOCK(inp);
4033 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4034 SCTP_TCB_LOCK(stcb);
4035 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4036 stcb->asoc.congestion_control_module = av->assoc_value;
4037 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4038 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4039 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4042 SCTP_TCB_UNLOCK(stcb);
4044 SCTP_INP_RUNLOCK(inp);
4049 case SCTP_CC_OPTION:
4051 struct sctp_cc_option *cc_opt;
4053 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4054 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4056 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4057 (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC)) {
4058 SCTP_INP_RLOCK(inp);
4059 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4060 SCTP_TCB_LOCK(stcb);
4061 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4062 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4064 SCTP_TCB_UNLOCK(stcb);
4066 SCTP_INP_RUNLOCK(inp);
4071 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4074 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4077 SCTP_TCB_UNLOCK(stcb);
4081 case SCTP_PLUGGABLE_SS:
4083 struct sctp_assoc_value *av;
4085 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4086 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4087 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4088 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4089 (av->assoc_value != SCTP_SS_PRIORITY) &&
4090 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4091 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4092 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4096 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4098 SCTP_TCB_SEND_LOCK(stcb);
4099 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4100 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4101 stcb->asoc.stream_scheduling_module = av->assoc_value;
4102 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4103 SCTP_TCB_SEND_UNLOCK(stcb);
4104 SCTP_TCB_UNLOCK(stcb);
4106 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4107 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4108 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4109 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4110 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4111 SCTP_INP_WLOCK(inp);
4112 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4113 SCTP_INP_WUNLOCK(inp);
4115 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4116 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4117 (av->assoc_id == SCTP_ALL_ASSOC))) {
4118 SCTP_INP_RLOCK(inp);
4119 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4120 SCTP_TCB_LOCK(stcb);
4121 SCTP_TCB_SEND_LOCK(stcb);
4122 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4123 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4124 stcb->asoc.stream_scheduling_module = av->assoc_value;
4125 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4126 SCTP_TCB_SEND_UNLOCK(stcb);
4127 SCTP_TCB_UNLOCK(stcb);
4129 SCTP_INP_RUNLOCK(inp);
4136 struct sctp_stream_value *av;
4138 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4139 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4141 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4142 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4143 av->stream_value) < 0)) {
4144 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4147 SCTP_TCB_UNLOCK(stcb);
4149 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4150 (av->assoc_id == SCTP_CURRENT_ASSOC)) {
4151 SCTP_INP_RLOCK(inp);
4152 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4153 SCTP_TCB_LOCK(stcb);
4154 if (av->stream_id < stcb->asoc.streamoutcnt) {
4155 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4157 &stcb->asoc.strmout[av->stream_id],
4160 SCTP_TCB_UNLOCK(stcb);
4162 SCTP_INP_RUNLOCK(inp);
4165 * Can't set stream value without
4168 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4174 case SCTP_CLR_STAT_LOG:
4175 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4180 struct sctp_assoc_value *av;
4182 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4183 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4186 stcb->asoc.context = av->assoc_value;
4187 SCTP_TCB_UNLOCK(stcb);
4189 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4190 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4191 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4192 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4193 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4194 SCTP_INP_WLOCK(inp);
4195 inp->sctp_context = av->assoc_value;
4196 SCTP_INP_WUNLOCK(inp);
4198 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4199 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4200 (av->assoc_id == SCTP_ALL_ASSOC))) {
4201 SCTP_INP_RLOCK(inp);
4202 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4203 SCTP_TCB_LOCK(stcb);
4204 stcb->asoc.context = av->assoc_value;
4205 SCTP_TCB_UNLOCK(stcb);
4207 SCTP_INP_RUNLOCK(inp);
4214 uint32_t *default_vrfid;
4216 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4217 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4218 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4222 inp->def_vrf_id = *default_vrfid;
4225 case SCTP_DEL_VRF_ID:
4227 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4231 case SCTP_ADD_VRF_ID:
4233 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4237 case SCTP_DELAYED_SACK:
4239 struct sctp_sack_info *sack;
4241 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4242 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4243 if (sack->sack_delay) {
4244 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4245 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4246 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4247 sack->sack_delay = TICKS_TO_MSEC(1);
4251 if (sack->sack_delay) {
4252 stcb->asoc.delayed_ack = sack->sack_delay;
4254 if (sack->sack_freq) {
4255 stcb->asoc.sack_freq = sack->sack_freq;
4257 SCTP_TCB_UNLOCK(stcb);
4259 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4260 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4261 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4262 ((sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4263 (sack->sack_assoc_id == SCTP_ALL_ASSOC)))) {
4264 SCTP_INP_WLOCK(inp);
4265 if (sack->sack_delay) {
4266 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4268 if (sack->sack_freq) {
4269 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4271 SCTP_INP_WUNLOCK(inp);
4273 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4274 ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4275 (sack->sack_assoc_id == SCTP_ALL_ASSOC))) {
4276 SCTP_INP_RLOCK(inp);
4277 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4278 SCTP_TCB_LOCK(stcb);
4279 if (sack->sack_delay) {
4280 stcb->asoc.delayed_ack = sack->sack_delay;
4282 if (sack->sack_freq) {
4283 stcb->asoc.sack_freq = sack->sack_freq;
4285 SCTP_TCB_UNLOCK(stcb);
4287 SCTP_INP_RUNLOCK(inp);
4292 case SCTP_AUTH_CHUNK:
4294 struct sctp_authchunk *sauth;
4296 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4298 SCTP_INP_WLOCK(inp);
4299 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4300 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4303 inp->auth_supported = 1;
4305 SCTP_INP_WUNLOCK(inp);
4310 struct sctp_authkey *sca;
4311 struct sctp_keyhead *shared_keys;
4312 sctp_sharedkey_t *shared_key;
4313 sctp_key_t *key = NULL;
4316 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4317 if (sca->sca_keylength == 0) {
4318 size = optsize - sizeof(struct sctp_authkey);
4320 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4321 size = sca->sca_keylength;
4323 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4328 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4331 shared_keys = &stcb->asoc.shared_keys;
4332 /* clear the cached keys for this key id */
4333 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4335 * create the new shared key and
4339 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4341 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4343 SCTP_TCB_UNLOCK(stcb);
4347 shared_key = sctp_alloc_sharedkey();
4348 if (shared_key == NULL) {
4350 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4352 SCTP_TCB_UNLOCK(stcb);
4355 shared_key->key = key;
4356 shared_key->keyid = sca->sca_keynumber;
4357 error = sctp_insert_sharedkey(shared_keys, shared_key);
4358 SCTP_TCB_UNLOCK(stcb);
4360 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4361 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4362 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4363 ((sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4364 (sca->sca_assoc_id == SCTP_ALL_ASSOC)))) {
4365 SCTP_INP_WLOCK(inp);
4366 shared_keys = &inp->sctp_ep.shared_keys;
4368 * clear the cached keys on all
4369 * assocs for this key id
4371 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4373 * create the new shared key and
4377 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4379 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4381 SCTP_INP_WUNLOCK(inp);
4385 shared_key = sctp_alloc_sharedkey();
4386 if (shared_key == NULL) {
4388 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4390 SCTP_INP_WUNLOCK(inp);
4393 shared_key->key = key;
4394 shared_key->keyid = sca->sca_keynumber;
4395 error = sctp_insert_sharedkey(shared_keys, shared_key);
4396 SCTP_INP_WUNLOCK(inp);
4398 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4399 ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4400 (sca->sca_assoc_id == SCTP_ALL_ASSOC))) {
4401 SCTP_INP_RLOCK(inp);
4402 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4403 SCTP_TCB_LOCK(stcb);
4404 shared_keys = &stcb->asoc.shared_keys;
4406 * clear the cached keys for
4409 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4411 * create the new shared key
4412 * and insert/replace it
4415 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4417 SCTP_TCB_UNLOCK(stcb);
4421 shared_key = sctp_alloc_sharedkey();
4422 if (shared_key == NULL) {
4424 SCTP_TCB_UNLOCK(stcb);
4427 shared_key->key = key;
4428 shared_key->keyid = sca->sca_keynumber;
4429 error = sctp_insert_sharedkey(shared_keys, shared_key);
4430 SCTP_TCB_UNLOCK(stcb);
4432 SCTP_INP_RUNLOCK(inp);
4437 case SCTP_HMAC_IDENT:
4439 struct sctp_hmacalgo *shmac;
4440 sctp_hmaclist_t *hmaclist;
4444 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4445 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4446 (shmac->shmac_number_of_idents > 0xffff)) {
4447 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4452 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4453 if (hmaclist == NULL) {
4454 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4458 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4459 hmacid = shmac->shmac_idents[i];
4460 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4461 /* invalid HMACs were found */ ;
4462 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4464 sctp_free_hmaclist(hmaclist);
4465 goto sctp_set_hmac_done;
4468 for (i = 0; i < hmaclist->num_algo; i++) {
4469 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4470 /* already in list */
4474 if (i == hmaclist->num_algo) {
4475 /* not found in list */
4476 sctp_free_hmaclist(hmaclist);
4477 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4481 /* set it on the endpoint */
4482 SCTP_INP_WLOCK(inp);
4483 if (inp->sctp_ep.local_hmacs)
4484 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4485 inp->sctp_ep.local_hmacs = hmaclist;
4486 SCTP_INP_WUNLOCK(inp);
4490 case SCTP_AUTH_ACTIVE_KEY:
4492 struct sctp_authkeyid *scact;
4494 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4495 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4497 /* set the active key on the right place */
4499 /* set the active key on the assoc */
4500 if (sctp_auth_setactivekey(stcb,
4501 scact->scact_keynumber)) {
4502 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4503 SCTP_FROM_SCTP_USRREQ,
4507 SCTP_TCB_UNLOCK(stcb);
4509 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4510 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4511 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4512 ((scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4513 (scact->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4514 SCTP_INP_WLOCK(inp);
4515 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4516 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4519 SCTP_INP_WUNLOCK(inp);
4521 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4522 ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4523 (scact->scact_assoc_id == SCTP_ALL_ASSOC))) {
4524 SCTP_INP_RLOCK(inp);
4525 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4526 SCTP_TCB_LOCK(stcb);
4527 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4528 SCTP_TCB_UNLOCK(stcb);
4530 SCTP_INP_RUNLOCK(inp);
4535 case SCTP_AUTH_DELETE_KEY:
4537 struct sctp_authkeyid *scdel;
4539 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4540 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4542 /* delete the key from the right place */
4544 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4545 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4548 SCTP_TCB_UNLOCK(stcb);
4550 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4551 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4552 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4553 ((scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4554 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4555 SCTP_INP_WLOCK(inp);
4556 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4557 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4560 SCTP_INP_WUNLOCK(inp);
4562 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4563 ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4564 (scdel->scact_assoc_id == SCTP_ALL_ASSOC))) {
4565 SCTP_INP_RLOCK(inp);
4566 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4567 SCTP_TCB_LOCK(stcb);
4568 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4569 SCTP_TCB_UNLOCK(stcb);
4571 SCTP_INP_RUNLOCK(inp);
4576 case SCTP_AUTH_DEACTIVATE_KEY:
4578 struct sctp_authkeyid *keyid;
4580 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4581 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4583 /* deactivate the key from the right place */
4585 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4586 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4589 SCTP_TCB_UNLOCK(stcb);
4591 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4592 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4593 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4594 ((keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4595 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4596 SCTP_INP_WLOCK(inp);
4597 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4598 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4601 SCTP_INP_WUNLOCK(inp);
4603 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4604 ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4605 (keyid->scact_assoc_id == SCTP_ALL_ASSOC))) {
4606 SCTP_INP_RLOCK(inp);
4607 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4608 SCTP_TCB_LOCK(stcb);
4609 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4610 SCTP_TCB_UNLOCK(stcb);
4612 SCTP_INP_RUNLOCK(inp);
4617 case SCTP_ENABLE_STREAM_RESET:
4619 struct sctp_assoc_value *av;
4621 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4622 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4623 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4627 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4629 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4630 SCTP_TCB_UNLOCK(stcb);
4632 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4633 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4634 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4635 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4636 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4637 SCTP_INP_WLOCK(inp);
4638 inp->local_strreset_support = (uint8_t)av->assoc_value;
4639 SCTP_INP_WUNLOCK(inp);
4641 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4642 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4643 (av->assoc_id == SCTP_ALL_ASSOC))) {
4644 SCTP_INP_RLOCK(inp);
4645 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4646 SCTP_TCB_LOCK(stcb);
4647 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4648 SCTP_TCB_UNLOCK(stcb);
4650 SCTP_INP_RUNLOCK(inp);
4656 case SCTP_RESET_STREAMS:
4658 struct sctp_reset_streams *strrst;
4659 int i, send_out = 0;
4662 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4663 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4665 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4669 if (stcb->asoc.reconfig_supported == 0) {
4671 * Peer does not support the chunk type.
4673 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4675 SCTP_TCB_UNLOCK(stcb);
4678 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4679 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4681 SCTP_TCB_UNLOCK(stcb);
4684 if (sizeof(struct sctp_reset_streams) +
4685 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4687 SCTP_TCB_UNLOCK(stcb);
4690 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4692 if (stcb->asoc.stream_reset_outstanding) {
4693 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4695 SCTP_TCB_UNLOCK(stcb);
4699 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4702 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4703 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4705 SCTP_TCB_UNLOCK(stcb);
4708 if ((send_in == 0) && (send_out == 0)) {
4709 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4711 SCTP_TCB_UNLOCK(stcb);
4714 for (i = 0; i < strrst->srs_number_streams; i++) {
4716 (strrst->srs_stream_list[i] >= stcb->asoc.streamincnt)) {
4717 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4722 (strrst->srs_stream_list[i] >= stcb->asoc.streamoutcnt)) {
4723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4729 SCTP_TCB_UNLOCK(stcb);
4736 if (strrst->srs_number_streams) {
4737 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4738 strm = strrst->srs_stream_list[i];
4739 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4740 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4746 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4747 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4748 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4755 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4756 strrst->srs_stream_list,
4757 send_in, 0, 0, 0, 0, 0);
4759 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4762 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4765 * For outgoing streams don't report any
4766 * problems in sending the request to the
4767 * application. XXX: Double check resetting
4772 SCTP_TCB_UNLOCK(stcb);
4775 case SCTP_ADD_STREAMS:
4777 struct sctp_add_streams *stradd;
4778 uint8_t addstream = 0;
4779 uint16_t add_o_strmcnt = 0;
4780 uint16_t add_i_strmcnt = 0;
4782 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4783 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4785 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4789 if (stcb->asoc.reconfig_supported == 0) {
4791 * Peer does not support the chunk type.
4793 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4795 SCTP_TCB_UNLOCK(stcb);
4798 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4799 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4801 SCTP_TCB_UNLOCK(stcb);
4804 if (stcb->asoc.stream_reset_outstanding) {
4805 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4807 SCTP_TCB_UNLOCK(stcb);
4810 if ((stradd->sas_outstrms == 0) &&
4811 (stradd->sas_instrms == 0)) {
4815 if (stradd->sas_outstrms) {
4817 /* We allocate here */
4818 add_o_strmcnt = stradd->sas_outstrms;
4819 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4820 /* You can't have more than 64k */
4825 if (stradd->sas_instrms) {
4830 * We allocate inside
4831 * sctp_send_str_reset_req()
4833 add_i_strmcnt = stradd->sas_instrms;
4834 cnt = add_i_strmcnt;
4835 cnt += stcb->asoc.streamincnt;
4836 if (cnt > 0x0000ffff) {
4837 /* You can't have more than 64k */
4841 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4842 /* More than you are allowed */
4847 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4848 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4850 SCTP_TCB_UNLOCK(stcb);
4853 case SCTP_RESET_ASSOC:
4858 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4859 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4861 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4865 if (stcb->asoc.reconfig_supported == 0) {
4867 * Peer does not support the chunk type.
4869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4871 SCTP_TCB_UNLOCK(stcb);
4874 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4875 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4877 SCTP_TCB_UNLOCK(stcb);
4880 if (stcb->asoc.stream_reset_outstanding) {
4881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4883 SCTP_TCB_UNLOCK(stcb);
4887 * Is there any data pending in the send or sent
4890 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4891 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4894 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4895 SCTP_TCB_UNLOCK(stcb);
4898 /* Do any streams have data queued? */
4899 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4900 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4904 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4905 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4906 SCTP_TCB_UNLOCK(stcb);
4909 case SCTP_CONNECT_X:
4910 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4911 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4915 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4917 case SCTP_CONNECT_X_DELAYED:
4918 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4919 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4923 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4925 case SCTP_CONNECT_X_COMPLETE:
4927 struct sockaddr *sa;
4929 /* FIXME MT: check correct? */
4930 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4933 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4934 SCTP_INP_RLOCK(inp);
4935 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4937 SCTP_TCB_LOCK(stcb);
4939 SCTP_INP_RUNLOCK(inp);
4942 * We increment here since
4943 * sctp_findassociation_ep_addr() wil do a
4944 * decrement if it finds the stcb as long as
4945 * the locked tcb (last argument) is NOT a
4948 SCTP_INP_INCR_REF(inp);
4949 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4951 SCTP_INP_DECR_REF(inp);
4956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4960 if (stcb->asoc.delayed_connection == 1) {
4961 stcb->asoc.delayed_connection = 0;
4962 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4963 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4964 stcb->asoc.primary_destination,
4965 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4966 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4969 * already expired or did not use delayed
4972 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4975 SCTP_TCB_UNLOCK(stcb);
4978 case SCTP_MAX_BURST:
4980 struct sctp_assoc_value *av;
4982 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4983 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4986 stcb->asoc.max_burst = av->assoc_value;
4987 SCTP_TCB_UNLOCK(stcb);
4989 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4990 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4991 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4992 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4993 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4994 SCTP_INP_WLOCK(inp);
4995 inp->sctp_ep.max_burst = av->assoc_value;
4996 SCTP_INP_WUNLOCK(inp);
4998 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4999 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
5000 (av->assoc_id == SCTP_ALL_ASSOC))) {
5001 SCTP_INP_RLOCK(inp);
5002 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5003 SCTP_TCB_LOCK(stcb);
5004 stcb->asoc.max_burst = av->assoc_value;
5005 SCTP_TCB_UNLOCK(stcb);
5007 SCTP_INP_RUNLOCK(inp);
5014 struct sctp_assoc_value *av;
5017 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
5018 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
5020 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5021 ovh = SCTP_MED_OVERHEAD;
5023 ovh = SCTP_MED_V4_OVERHEAD;
5026 if (av->assoc_value) {
5027 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
5029 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
5031 SCTP_TCB_UNLOCK(stcb);
5033 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5034 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5035 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5036 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
5037 SCTP_INP_WLOCK(inp);
5039 * FIXME MT: I think this is not in
5040 * tune with the API ID
5042 if (av->assoc_value) {
5043 inp->sctp_frag_point = (av->assoc_value + ovh);
5045 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
5047 SCTP_INP_WUNLOCK(inp);
5049 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5057 struct sctp_event_subscribe *events;
5059 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5061 SCTP_INP_WLOCK(inp);
5062 if (events->sctp_data_io_event) {
5063 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5065 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5068 if (events->sctp_association_event) {
5069 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5071 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5074 if (events->sctp_address_event) {
5075 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5077 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5080 if (events->sctp_send_failure_event) {
5081 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5083 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5086 if (events->sctp_peer_error_event) {
5087 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5089 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5092 if (events->sctp_shutdown_event) {
5093 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5095 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5098 if (events->sctp_partial_delivery_event) {
5099 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5101 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5104 if (events->sctp_adaptation_layer_event) {
5105 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5107 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5110 if (events->sctp_authentication_event) {
5111 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5113 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5116 if (events->sctp_sender_dry_event) {
5117 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5119 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5122 if (events->sctp_stream_reset_event) {
5123 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5125 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5127 SCTP_INP_WUNLOCK(inp);
5129 SCTP_INP_RLOCK(inp);
5130 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5131 SCTP_TCB_LOCK(stcb);
5132 if (events->sctp_association_event) {
5133 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5135 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5137 if (events->sctp_address_event) {
5138 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5140 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5142 if (events->sctp_send_failure_event) {
5143 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5145 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5147 if (events->sctp_peer_error_event) {
5148 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5150 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5152 if (events->sctp_shutdown_event) {
5153 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5155 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5157 if (events->sctp_partial_delivery_event) {
5158 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5160 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5162 if (events->sctp_adaptation_layer_event) {
5163 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5165 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5167 if (events->sctp_authentication_event) {
5168 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5170 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5172 if (events->sctp_sender_dry_event) {
5173 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5175 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5177 if (events->sctp_stream_reset_event) {
5178 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5180 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5182 SCTP_TCB_UNLOCK(stcb);
5185 * Send up the sender dry event only for 1-to-1
5188 if (events->sctp_sender_dry_event) {
5189 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5190 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5191 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5193 SCTP_TCB_LOCK(stcb);
5194 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5195 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5196 (stcb->asoc.stream_queue_cnt == 0)) {
5197 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5199 SCTP_TCB_UNLOCK(stcb);
5203 SCTP_INP_RUNLOCK(inp);
5206 case SCTP_ADAPTATION_LAYER:
5208 struct sctp_setadaptation *adap_bits;
5210 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5211 SCTP_INP_WLOCK(inp);
5212 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5213 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5214 SCTP_INP_WUNLOCK(inp);
5218 case SCTP_SET_INITIAL_DBG_SEQ:
5222 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5223 SCTP_INP_WLOCK(inp);
5224 inp->sctp_ep.initial_sequence_debug = *vvv;
5225 SCTP_INP_WUNLOCK(inp);
5229 case SCTP_DEFAULT_SEND_PARAM:
5231 struct sctp_sndrcvinfo *s_info;
5233 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5234 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5237 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5238 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5240 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5243 SCTP_TCB_UNLOCK(stcb);
5245 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5246 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5247 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5248 ((s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5249 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)))) {
5250 SCTP_INP_WLOCK(inp);
5251 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5252 SCTP_INP_WUNLOCK(inp);
5254 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5255 ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5256 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC))) {
5257 SCTP_INP_RLOCK(inp);
5258 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5259 SCTP_TCB_LOCK(stcb);
5260 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5261 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5263 SCTP_TCB_UNLOCK(stcb);
5265 SCTP_INP_RUNLOCK(inp);
5270 case SCTP_PEER_ADDR_PARAMS:
5272 struct sctp_paddrparams *paddrp;
5273 struct sctp_nets *net;
5274 struct sockaddr *addr;
5275 #if defined(INET) && defined(INET6)
5276 struct sockaddr_in sin_store;
5279 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5280 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5282 #if defined(INET) && defined(INET6)
5283 if (paddrp->spp_address.ss_family == AF_INET6) {
5284 struct sockaddr_in6 *sin6;
5286 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5287 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5288 in6_sin6_2_sin(&sin_store, sin6);
5289 addr = (struct sockaddr *)&sin_store;
5291 addr = (struct sockaddr *)&paddrp->spp_address;
5294 addr = (struct sockaddr *)&paddrp->spp_address;
5297 addr = (struct sockaddr *)&paddrp->spp_address;
5300 net = sctp_findnet(stcb, addr);
5303 * We increment here since
5304 * sctp_findassociation_ep_addr() wil do a
5305 * decrement if it finds the stcb as long as
5306 * the locked tcb (last argument) is NOT a
5310 SCTP_INP_INCR_REF(inp);
5311 stcb = sctp_findassociation_ep_addr(&inp, addr,
5314 SCTP_INP_DECR_REF(inp);
5317 if ((stcb != NULL) && (net == NULL)) {
5319 if (addr->sa_family == AF_INET) {
5321 struct sockaddr_in *sin;
5323 sin = (struct sockaddr_in *)addr;
5324 if (sin->sin_addr.s_addr != INADDR_ANY) {
5325 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5326 SCTP_TCB_UNLOCK(stcb);
5333 if (addr->sa_family == AF_INET6) {
5334 struct sockaddr_in6 *sin6;
5336 sin6 = (struct sockaddr_in6 *)addr;
5337 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5338 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5339 SCTP_TCB_UNLOCK(stcb);
5346 error = EAFNOSUPPORT;
5347 SCTP_TCB_UNLOCK(stcb);
5348 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5353 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5355 SCTP_TCB_UNLOCK(stcb);
5356 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5360 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5362 SCTP_TCB_UNLOCK(stcb);
5363 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5366 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) &&
5367 ((paddrp->spp_pathmtu < SCTP_SMALLEST_PMTU) ||
5368 (paddrp->spp_pathmtu > SCTP_LARGEST_PMTU))) {
5370 SCTP_TCB_UNLOCK(stcb);
5371 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5376 /************************TCB SPECIFIC SET ******************/
5378 /************************NET SPECIFIC SET ******************/
5379 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5380 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5381 !(net->dest_state & SCTP_ADDR_NOHB)) {
5382 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5383 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5385 net->dest_state |= SCTP_ADDR_NOHB;
5387 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5388 if (paddrp->spp_hbinterval) {
5389 net->heart_beat_delay = paddrp->spp_hbinterval;
5390 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5391 net->heart_beat_delay = 0;
5393 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5394 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5395 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5396 net->dest_state &= ~SCTP_ADDR_NOHB;
5398 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5399 if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
5400 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5401 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5402 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5405 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5406 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5407 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5408 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5410 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5411 net->mtu = paddrp->spp_pathmtu;
5412 switch (net->ro._l_addr.sa.sa_family) {
5415 net->mtu += SCTP_MIN_V4_OVERHEAD;
5420 net->mtu += SCTP_MIN_OVERHEAD;
5426 if (net->mtu < stcb->asoc.smallest_mtu) {
5427 sctp_pathmtu_adjustment(stcb, net->mtu);
5430 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5431 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5432 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5434 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5436 if (paddrp->spp_pathmaxrxt) {
5437 if (net->dest_state & SCTP_ADDR_PF) {
5438 if (net->error_count > paddrp->spp_pathmaxrxt) {
5439 net->dest_state &= ~SCTP_ADDR_PF;
5442 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5443 (net->error_count > net->pf_threshold)) {
5444 net->dest_state |= SCTP_ADDR_PF;
5445 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5446 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5447 stcb->sctp_ep, stcb, net,
5448 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5449 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5452 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5453 if (net->error_count > paddrp->spp_pathmaxrxt) {
5454 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5455 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5458 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5459 net->dest_state |= SCTP_ADDR_REACHABLE;
5460 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5463 net->failure_threshold = paddrp->spp_pathmaxrxt;
5465 if (paddrp->spp_flags & SPP_DSCP) {
5466 net->dscp = paddrp->spp_dscp & 0xfc;
5470 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5471 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5472 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5473 net->flowlabel |= 0x80000000;
5478 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5479 if (paddrp->spp_pathmaxrxt != 0) {
5480 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5481 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5482 if (net->dest_state & SCTP_ADDR_PF) {
5483 if (net->error_count > paddrp->spp_pathmaxrxt) {
5484 net->dest_state &= ~SCTP_ADDR_PF;
5487 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5488 (net->error_count > net->pf_threshold)) {
5489 net->dest_state |= SCTP_ADDR_PF;
5490 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5491 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5492 stcb->sctp_ep, stcb, net,
5493 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5494 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5497 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5498 if (net->error_count > paddrp->spp_pathmaxrxt) {
5499 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5500 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5503 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5504 net->dest_state |= SCTP_ADDR_REACHABLE;
5505 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5508 net->failure_threshold = paddrp->spp_pathmaxrxt;
5512 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5513 if (paddrp->spp_hbinterval != 0) {
5514 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5515 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5516 stcb->asoc.heart_beat_delay = 0;
5518 /* Turn back on the timer */
5519 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5520 if (paddrp->spp_hbinterval != 0) {
5521 net->heart_beat_delay = paddrp->spp_hbinterval;
5522 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5523 net->heart_beat_delay = 0;
5525 if (net->dest_state & SCTP_ADDR_NOHB) {
5526 net->dest_state &= ~SCTP_ADDR_NOHB;
5528 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5529 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5530 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5532 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5534 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5535 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5536 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5537 net->dest_state |= SCTP_ADDR_NOHB;
5538 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5539 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5541 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5545 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5547 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5548 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5549 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5550 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5551 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5553 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5554 net->mtu = paddrp->spp_pathmtu;
5555 switch (net->ro._l_addr.sa.sa_family) {
5558 net->mtu += SCTP_MIN_V4_OVERHEAD;
5563 net->mtu += SCTP_MIN_OVERHEAD;
5569 if (net->mtu < stcb->asoc.smallest_mtu) {
5570 sctp_pathmtu_adjustment(stcb, net->mtu);
5573 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5574 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5576 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5577 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5578 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5579 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5581 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5583 stcb->asoc.default_mtu = 0;
5584 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5586 if (paddrp->spp_flags & SPP_DSCP) {
5587 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5588 net->dscp = paddrp->spp_dscp & 0xfc;
5591 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5592 stcb->asoc.default_dscp |= 0x01;
5595 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5596 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5597 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5598 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5599 net->flowlabel |= 0x80000000;
5602 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5603 stcb->asoc.default_flowlabel |= 0x80000000;
5607 SCTP_TCB_UNLOCK(stcb);
5609 /************************NO TCB, SET TO default stuff ******************/
5610 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5611 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5612 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5613 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
5614 SCTP_INP_WLOCK(inp);
5616 * For the TOS/FLOWLABEL stuff you
5617 * set it with the options on the
5620 if (paddrp->spp_pathmaxrxt != 0) {
5621 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5624 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5625 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5626 else if (paddrp->spp_hbinterval != 0) {
5627 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5628 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5629 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5632 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5633 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5634 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5635 } else if (paddrp->spp_hbinterval) {
5636 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5638 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5639 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5640 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5642 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5643 inp->sctp_ep.default_mtu = 0;
5644 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5645 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5646 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5647 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5649 if (paddrp->spp_flags & SPP_DSCP) {
5650 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5651 inp->sctp_ep.default_dscp |= 0x01;
5654 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5655 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5656 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5657 inp->sctp_ep.default_flowlabel |= 0x80000000;
5661 SCTP_INP_WUNLOCK(inp);
5663 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5671 struct sctp_rtoinfo *srto;
5672 uint32_t new_init, new_min, new_max;
5674 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5675 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5678 if (srto->srto_initial)
5679 new_init = srto->srto_initial;
5681 new_init = stcb->asoc.initial_rto;
5683 new_max = srto->srto_max;
5685 new_max = stcb->asoc.maxrto;
5687 new_min = srto->srto_min;
5689 new_min = stcb->asoc.minrto;
5690 if ((new_min <= new_init) && (new_init <= new_max)) {
5691 stcb->asoc.initial_rto = new_init;
5692 stcb->asoc.maxrto = new_max;
5693 stcb->asoc.minrto = new_min;
5695 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5698 SCTP_TCB_UNLOCK(stcb);
5700 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5701 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5702 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5703 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
5704 SCTP_INP_WLOCK(inp);
5705 if (srto->srto_initial)
5706 new_init = srto->srto_initial;
5708 new_init = inp->sctp_ep.initial_rto;
5710 new_max = srto->srto_max;
5712 new_max = inp->sctp_ep.sctp_maxrto;
5714 new_min = srto->srto_min;
5716 new_min = inp->sctp_ep.sctp_minrto;
5717 if ((new_min <= new_init) && (new_init <= new_max)) {
5718 inp->sctp_ep.initial_rto = new_init;
5719 inp->sctp_ep.sctp_maxrto = new_max;
5720 inp->sctp_ep.sctp_minrto = new_min;
5722 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5725 SCTP_INP_WUNLOCK(inp);
5727 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5733 case SCTP_ASSOCINFO:
5735 struct sctp_assocparams *sasoc;
5737 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5738 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5739 if (sasoc->sasoc_cookie_life) {
5740 /* boundary check the cookie life */
5741 if (sasoc->sasoc_cookie_life < 1000)
5742 sasoc->sasoc_cookie_life = 1000;
5743 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5744 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5748 if (sasoc->sasoc_asocmaxrxt)
5749 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5750 if (sasoc->sasoc_cookie_life) {
5751 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5753 SCTP_TCB_UNLOCK(stcb);
5755 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5756 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5757 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5758 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
5759 SCTP_INP_WLOCK(inp);
5760 if (sasoc->sasoc_asocmaxrxt)
5761 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5762 if (sasoc->sasoc_cookie_life) {
5763 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5765 SCTP_INP_WUNLOCK(inp);
5767 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5775 struct sctp_initmsg *sinit;
5777 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5778 SCTP_INP_WLOCK(inp);
5779 if (sinit->sinit_num_ostreams)
5780 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5782 if (sinit->sinit_max_instreams)
5783 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5785 if (sinit->sinit_max_attempts)
5786 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5788 if (sinit->sinit_max_init_timeo)
5789 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5790 SCTP_INP_WUNLOCK(inp);
5793 case SCTP_PRIMARY_ADDR:
5795 struct sctp_setprim *spa;
5796 struct sctp_nets *net;
5797 struct sockaddr *addr;
5798 #if defined(INET) && defined(INET6)
5799 struct sockaddr_in sin_store;
5802 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5803 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5805 #if defined(INET) && defined(INET6)
5806 if (spa->ssp_addr.ss_family == AF_INET6) {
5807 struct sockaddr_in6 *sin6;
5809 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5810 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5811 in6_sin6_2_sin(&sin_store, sin6);
5812 addr = (struct sockaddr *)&sin_store;
5814 addr = (struct sockaddr *)&spa->ssp_addr;
5817 addr = (struct sockaddr *)&spa->ssp_addr;
5820 addr = (struct sockaddr *)&spa->ssp_addr;
5823 net = sctp_findnet(stcb, addr);
5826 * We increment here since
5827 * sctp_findassociation_ep_addr() wil do a
5828 * decrement if it finds the stcb as long as
5829 * the locked tcb (last argument) is NOT a
5833 SCTP_INP_INCR_REF(inp);
5834 stcb = sctp_findassociation_ep_addr(&inp, addr,
5837 SCTP_INP_DECR_REF(inp);
5841 if ((stcb != NULL) && (net != NULL)) {
5842 if (net != stcb->asoc.primary_destination) {
5843 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5844 /* Ok we need to set it */
5845 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5846 if ((stcb->asoc.alternate) &&
5847 (!(net->dest_state & SCTP_ADDR_PF)) &&
5848 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5849 sctp_free_remote_addr(stcb->asoc.alternate);
5850 stcb->asoc.alternate = NULL;
5853 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5857 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);
5866 SCTP_TCB_UNLOCK(stcb);
5870 case SCTP_SET_DYNAMIC_PRIMARY:
5872 union sctp_sockstore *ss;
5874 error = priv_check(curthread,
5875 PRIV_NETINET_RESERVEDPORT);
5879 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5880 /* SUPER USER CHECK? */
5881 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5884 case SCTP_SET_PEER_PRIMARY_ADDR:
5886 struct sctp_setpeerprim *sspp;
5887 struct sockaddr *addr;
5888 #if defined(INET) && defined(INET6)
5889 struct sockaddr_in sin_store;
5892 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5893 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5895 struct sctp_ifa *ifa;
5897 #if defined(INET) && defined(INET6)
5898 if (sspp->sspp_addr.ss_family == AF_INET6) {
5899 struct sockaddr_in6 *sin6;
5901 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5902 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5903 in6_sin6_2_sin(&sin_store, sin6);
5904 addr = (struct sockaddr *)&sin_store;
5906 addr = (struct sockaddr *)&sspp->sspp_addr;
5909 addr = (struct sockaddr *)&sspp->sspp_addr;
5912 addr = (struct sockaddr *)&sspp->sspp_addr;
5914 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5920 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5922 * Must validate the ifa found is in
5925 struct sctp_laddr *laddr;
5928 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5929 if (laddr->ifa == NULL) {
5930 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5934 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5935 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5938 if (laddr->ifa == ifa) {
5944 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5949 switch (addr->sa_family) {
5953 struct sockaddr_in *sin;
5955 sin = (struct sockaddr_in *)addr;
5956 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5957 &sin->sin_addr) != 0) {
5958 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5968 struct sockaddr_in6 *sin6;
5970 sin6 = (struct sockaddr_in6 *)addr;
5971 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5972 &sin6->sin6_addr) != 0) {
5973 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5986 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5987 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5990 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5992 SCTP_TCB_UNLOCK(stcb);
5994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5999 case SCTP_BINDX_ADD_ADDR:
6001 struct sctp_getaddresses *addrs;
6004 td = (struct thread *)p;
6005 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
6008 if (addrs->addr->sa_family == AF_INET) {
6009 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
6010 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6014 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
6015 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6021 if (addrs->addr->sa_family == AF_INET6) {
6022 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
6023 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6027 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
6028 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6029 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6035 error = EAFNOSUPPORT;
6038 sctp_bindx_add_address(so, inp, addrs->addr,
6039 addrs->sget_assoc_id, vrf_id,
6043 case SCTP_BINDX_REM_ADDR:
6045 struct sctp_getaddresses *addrs;
6048 td = (struct thread *)p;
6050 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
6052 if (addrs->addr->sa_family == AF_INET) {
6053 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
6054 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6058 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
6059 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6065 if (addrs->addr->sa_family == AF_INET6) {
6066 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
6067 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6072 (error = prison_local_ip6(td->td_ucred,
6073 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
6074 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6075 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6081 error = EAFNOSUPPORT;
6084 sctp_bindx_delete_address(inp, addrs->addr,
6085 addrs->sget_assoc_id, vrf_id,
6091 struct sctp_event *event;
6092 uint32_t event_type;
6094 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6095 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6096 switch (event->se_type) {
6097 case SCTP_ASSOC_CHANGE:
6098 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6100 case SCTP_PEER_ADDR_CHANGE:
6101 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6103 case SCTP_REMOTE_ERROR:
6104 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6106 case SCTP_SEND_FAILED:
6107 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6109 case SCTP_SHUTDOWN_EVENT:
6110 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6112 case SCTP_ADAPTATION_INDICATION:
6113 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6115 case SCTP_PARTIAL_DELIVERY_EVENT:
6116 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6118 case SCTP_AUTHENTICATION_EVENT:
6119 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6121 case SCTP_STREAM_RESET_EVENT:
6122 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6124 case SCTP_SENDER_DRY_EVENT:
6125 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6127 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6129 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6132 case SCTP_ASSOC_RESET_EVENT:
6133 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6135 case SCTP_STREAM_CHANGE_EVENT:
6136 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6138 case SCTP_SEND_FAILED_EVENT:
6139 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6143 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6147 if (event_type > 0) {
6150 sctp_stcb_feature_on(inp, stcb, event_type);
6151 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6152 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6153 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6154 (stcb->asoc.stream_queue_cnt == 0)) {
6155 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6159 sctp_stcb_feature_off(inp, stcb, event_type);
6161 SCTP_TCB_UNLOCK(stcb);
6164 * We don't want to send up a storm
6165 * of events, so return an error for
6168 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6169 (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6170 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6171 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6172 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6176 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6177 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6178 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6179 ((event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6180 (event->se_assoc_id == SCTP_ALL_ASSOC)))) {
6181 SCTP_INP_WLOCK(inp);
6183 sctp_feature_on(inp, event_type);
6185 sctp_feature_off(inp, event_type);
6187 SCTP_INP_WUNLOCK(inp);
6189 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6190 ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6191 (event->se_assoc_id == SCTP_ALL_ASSOC))) {
6192 SCTP_INP_RLOCK(inp);
6193 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6194 SCTP_TCB_LOCK(stcb);
6196 sctp_stcb_feature_on(inp, stcb, event_type);
6198 sctp_stcb_feature_off(inp, stcb, event_type);
6200 SCTP_TCB_UNLOCK(stcb);
6202 SCTP_INP_RUNLOCK(inp);
6207 SCTP_TCB_UNLOCK(stcb);
6212 case SCTP_RECVRCVINFO:
6216 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6217 SCTP_INP_WLOCK(inp);
6219 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6221 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6223 SCTP_INP_WUNLOCK(inp);
6226 case SCTP_RECVNXTINFO:
6230 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6231 SCTP_INP_WLOCK(inp);
6233 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6235 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6237 SCTP_INP_WUNLOCK(inp);
6240 case SCTP_DEFAULT_SNDINFO:
6242 struct sctp_sndinfo *info;
6245 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6246 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6249 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6250 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6251 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6252 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6253 stcb->asoc.def_send.sinfo_flags |= policy;
6254 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6255 stcb->asoc.def_send.sinfo_context = info->snd_context;
6257 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6260 SCTP_TCB_UNLOCK(stcb);
6262 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6263 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6264 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6265 ((info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6266 (info->snd_assoc_id == SCTP_ALL_ASSOC)))) {
6267 SCTP_INP_WLOCK(inp);
6268 inp->def_send.sinfo_stream = info->snd_sid;
6269 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6270 inp->def_send.sinfo_flags = info->snd_flags;
6271 inp->def_send.sinfo_flags |= policy;
6272 inp->def_send.sinfo_ppid = info->snd_ppid;
6273 inp->def_send.sinfo_context = info->snd_context;
6274 SCTP_INP_WUNLOCK(inp);
6276 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6277 ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6278 (info->snd_assoc_id == SCTP_ALL_ASSOC))) {
6279 SCTP_INP_RLOCK(inp);
6280 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6281 SCTP_TCB_LOCK(stcb);
6282 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6283 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6284 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6285 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6286 stcb->asoc.def_send.sinfo_flags |= policy;
6287 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6288 stcb->asoc.def_send.sinfo_context = info->snd_context;
6290 SCTP_TCB_UNLOCK(stcb);
6292 SCTP_INP_RUNLOCK(inp);
6297 case SCTP_DEFAULT_PRINFO:
6299 struct sctp_default_prinfo *info;
6301 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6302 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6304 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6306 SCTP_TCB_UNLOCK(stcb);
6308 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6313 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6314 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6315 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6316 SCTP_TCB_UNLOCK(stcb);
6318 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6319 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6320 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6321 ((info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6322 (info->pr_assoc_id == SCTP_ALL_ASSOC)))) {
6323 SCTP_INP_WLOCK(inp);
6324 inp->def_send.sinfo_flags &= 0xfff0;
6325 inp->def_send.sinfo_flags |= info->pr_policy;
6326 inp->def_send.sinfo_timetolive = info->pr_value;
6327 SCTP_INP_WUNLOCK(inp);
6329 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6330 ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6331 (info->pr_assoc_id == SCTP_ALL_ASSOC))) {
6332 SCTP_INP_RLOCK(inp);
6333 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6334 SCTP_TCB_LOCK(stcb);
6335 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6336 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6337 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6338 SCTP_TCB_UNLOCK(stcb);
6340 SCTP_INP_RUNLOCK(inp);
6345 case SCTP_PEER_ADDR_THLDS:
6346 /* Applies to the specific association */
6348 struct sctp_paddrthlds *thlds;
6349 struct sctp_nets *net;
6350 struct sockaddr *addr;
6351 #if defined(INET) && defined(INET6)
6352 struct sockaddr_in sin_store;
6355 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6356 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6358 #if defined(INET) && defined(INET6)
6359 if (thlds->spt_address.ss_family == AF_INET6) {
6360 struct sockaddr_in6 *sin6;
6362 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6363 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6364 in6_sin6_2_sin(&sin_store, sin6);
6365 addr = (struct sockaddr *)&sin_store;
6367 addr = (struct sockaddr *)&thlds->spt_address;
6370 addr = (struct sockaddr *)&thlds->spt_address;
6373 addr = (struct sockaddr *)&thlds->spt_address;
6376 net = sctp_findnet(stcb, addr);
6379 * We increment here since
6380 * sctp_findassociation_ep_addr() wil do a
6381 * decrement if it finds the stcb as long as
6382 * the locked tcb (last argument) is NOT a
6386 SCTP_INP_INCR_REF(inp);
6387 stcb = sctp_findassociation_ep_addr(&inp, addr,
6390 SCTP_INP_DECR_REF(inp);
6393 if ((stcb != NULL) && (net == NULL)) {
6395 if (addr->sa_family == AF_INET) {
6397 struct sockaddr_in *sin;
6399 sin = (struct sockaddr_in *)addr;
6400 if (sin->sin_addr.s_addr != INADDR_ANY) {
6401 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6402 SCTP_TCB_UNLOCK(stcb);
6409 if (addr->sa_family == AF_INET6) {
6410 struct sockaddr_in6 *sin6;
6412 sin6 = (struct sockaddr_in6 *)addr;
6413 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6414 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6415 SCTP_TCB_UNLOCK(stcb);
6422 error = EAFNOSUPPORT;
6423 SCTP_TCB_UNLOCK(stcb);
6424 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6428 if (thlds->spt_pathcpthld != 0xffff) {
6430 SCTP_TCB_UNLOCK(stcb);
6433 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6438 net->failure_threshold = thlds->spt_pathmaxrxt;
6439 net->pf_threshold = thlds->spt_pathpfthld;
6440 if (net->dest_state & SCTP_ADDR_PF) {
6441 if ((net->error_count > net->failure_threshold) ||
6442 (net->error_count <= net->pf_threshold)) {
6443 net->dest_state &= ~SCTP_ADDR_PF;
6446 if ((net->error_count > net->pf_threshold) &&
6447 (net->error_count <= net->failure_threshold)) {
6448 net->dest_state |= SCTP_ADDR_PF;
6449 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6450 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6451 stcb->sctp_ep, stcb, net,
6452 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6453 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6456 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6457 if (net->error_count > net->failure_threshold) {
6458 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6459 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6462 if (net->error_count <= net->failure_threshold) {
6463 net->dest_state |= SCTP_ADDR_REACHABLE;
6464 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6468 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6469 net->failure_threshold = thlds->spt_pathmaxrxt;
6470 net->pf_threshold = thlds->spt_pathpfthld;
6471 if (net->dest_state & SCTP_ADDR_PF) {
6472 if ((net->error_count > net->failure_threshold) ||
6473 (net->error_count <= net->pf_threshold)) {
6474 net->dest_state &= ~SCTP_ADDR_PF;
6477 if ((net->error_count > net->pf_threshold) &&
6478 (net->error_count <= net->failure_threshold)) {
6479 net->dest_state |= SCTP_ADDR_PF;
6480 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6481 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6482 stcb->sctp_ep, stcb, net,
6483 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6484 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6487 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6488 if (net->error_count > net->failure_threshold) {
6489 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6490 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6493 if (net->error_count <= net->failure_threshold) {
6494 net->dest_state |= SCTP_ADDR_REACHABLE;
6495 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6499 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6500 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6502 SCTP_TCB_UNLOCK(stcb);
6504 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6505 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6506 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6507 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
6508 SCTP_INP_WLOCK(inp);
6509 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6510 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6511 SCTP_INP_WUNLOCK(inp);
6513 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6519 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6521 struct sctp_udpencaps *encaps;
6522 struct sctp_nets *net;
6523 struct sockaddr *addr;
6524 #if defined(INET) && defined(INET6)
6525 struct sockaddr_in sin_store;
6528 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6529 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6531 #if defined(INET) && defined(INET6)
6532 if (encaps->sue_address.ss_family == AF_INET6) {
6533 struct sockaddr_in6 *sin6;
6535 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6536 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6537 in6_sin6_2_sin(&sin_store, sin6);
6538 addr = (struct sockaddr *)&sin_store;
6540 addr = (struct sockaddr *)&encaps->sue_address;
6543 addr = (struct sockaddr *)&encaps->sue_address;
6546 addr = (struct sockaddr *)&encaps->sue_address;
6549 net = sctp_findnet(stcb, addr);
6552 * We increment here since
6553 * sctp_findassociation_ep_addr() wil do a
6554 * decrement if it finds the stcb as long as
6555 * the locked tcb (last argument) is NOT a
6559 SCTP_INP_INCR_REF(inp);
6560 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6562 SCTP_INP_DECR_REF(inp);
6565 if ((stcb != NULL) && (net == NULL)) {
6567 if (addr->sa_family == AF_INET) {
6569 struct sockaddr_in *sin;
6571 sin = (struct sockaddr_in *)addr;
6572 if (sin->sin_addr.s_addr != INADDR_ANY) {
6573 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6574 SCTP_TCB_UNLOCK(stcb);
6581 if (addr->sa_family == AF_INET6) {
6582 struct sockaddr_in6 *sin6;
6584 sin6 = (struct sockaddr_in6 *)addr;
6585 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6586 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6587 SCTP_TCB_UNLOCK(stcb);
6594 error = EAFNOSUPPORT;
6595 SCTP_TCB_UNLOCK(stcb);
6596 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6603 net->port = encaps->sue_port;
6605 stcb->asoc.port = encaps->sue_port;
6607 SCTP_TCB_UNLOCK(stcb);
6609 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6610 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6611 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6612 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
6613 SCTP_INP_WLOCK(inp);
6614 inp->sctp_ep.port = encaps->sue_port;
6615 SCTP_INP_WUNLOCK(inp);
6617 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6623 case SCTP_ECN_SUPPORTED:
6625 struct sctp_assoc_value *av;
6627 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6628 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6631 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6633 SCTP_TCB_UNLOCK(stcb);
6635 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6636 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6637 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6638 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6639 SCTP_INP_WLOCK(inp);
6640 if (av->assoc_value == 0) {
6641 inp->ecn_supported = 0;
6643 inp->ecn_supported = 1;
6645 SCTP_INP_WUNLOCK(inp);
6647 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6653 case SCTP_PR_SUPPORTED:
6655 struct sctp_assoc_value *av;
6657 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6658 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6661 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6663 SCTP_TCB_UNLOCK(stcb);
6665 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6666 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6667 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6668 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6669 SCTP_INP_WLOCK(inp);
6670 if (av->assoc_value == 0) {
6671 inp->prsctp_supported = 0;
6673 inp->prsctp_supported = 1;
6675 SCTP_INP_WUNLOCK(inp);
6677 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6683 case SCTP_AUTH_SUPPORTED:
6685 struct sctp_assoc_value *av;
6687 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6688 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6693 SCTP_TCB_UNLOCK(stcb);
6695 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6696 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6697 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6698 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6699 if ((av->assoc_value == 0) &&
6700 (inp->asconf_supported == 1)) {
6702 * AUTH is required for
6705 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6708 SCTP_INP_WLOCK(inp);
6709 if (av->assoc_value == 0) {
6710 inp->auth_supported = 0;
6712 inp->auth_supported = 1;
6714 SCTP_INP_WUNLOCK(inp);
6717 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6723 case SCTP_ASCONF_SUPPORTED:
6725 struct sctp_assoc_value *av;
6727 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6728 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6731 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6733 SCTP_TCB_UNLOCK(stcb);
6735 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6736 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6737 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6738 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6739 if ((av->assoc_value != 0) &&
6740 (inp->auth_supported == 0)) {
6742 * AUTH is required for
6745 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6748 SCTP_INP_WLOCK(inp);
6749 if (av->assoc_value == 0) {
6750 inp->asconf_supported = 0;
6751 sctp_auth_delete_chunk(SCTP_ASCONF,
6752 inp->sctp_ep.local_auth_chunks);
6753 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6754 inp->sctp_ep.local_auth_chunks);
6756 inp->asconf_supported = 1;
6757 sctp_auth_add_chunk(SCTP_ASCONF,
6758 inp->sctp_ep.local_auth_chunks);
6759 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6760 inp->sctp_ep.local_auth_chunks);
6762 SCTP_INP_WUNLOCK(inp);
6765 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6771 case SCTP_RECONFIG_SUPPORTED:
6773 struct sctp_assoc_value *av;
6775 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6776 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6779 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6781 SCTP_TCB_UNLOCK(stcb);
6783 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6784 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6785 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6786 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6787 SCTP_INP_WLOCK(inp);
6788 if (av->assoc_value == 0) {
6789 inp->reconfig_supported = 0;
6791 inp->reconfig_supported = 1;
6793 SCTP_INP_WUNLOCK(inp);
6795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6801 case SCTP_NRSACK_SUPPORTED:
6803 struct sctp_assoc_value *av;
6805 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6806 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6809 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6811 SCTP_TCB_UNLOCK(stcb);
6813 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6814 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6815 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6816 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6817 SCTP_INP_WLOCK(inp);
6818 if (av->assoc_value == 0) {
6819 inp->nrsack_supported = 0;
6821 inp->nrsack_supported = 1;
6823 SCTP_INP_WUNLOCK(inp);
6825 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6831 case SCTP_PKTDROP_SUPPORTED:
6833 struct sctp_assoc_value *av;
6835 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6836 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6839 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6841 SCTP_TCB_UNLOCK(stcb);
6843 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6844 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6845 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6846 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6847 SCTP_INP_WLOCK(inp);
6848 if (av->assoc_value == 0) {
6849 inp->pktdrop_supported = 0;
6851 inp->pktdrop_supported = 1;
6853 SCTP_INP_WUNLOCK(inp);
6855 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6863 struct sctp_assoc_value *av;
6864 struct sctp_nets *net;
6866 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6867 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6870 stcb->asoc.max_cwnd = av->assoc_value;
6871 if (stcb->asoc.max_cwnd > 0) {
6872 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6873 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6874 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6875 net->cwnd = stcb->asoc.max_cwnd;
6876 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6877 net->cwnd = net->mtu - sizeof(struct sctphdr);
6882 SCTP_TCB_UNLOCK(stcb);
6884 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6885 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6886 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6887 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6888 SCTP_INP_WLOCK(inp);
6889 inp->max_cwnd = av->assoc_value;
6890 SCTP_INP_WUNLOCK(inp);
6892 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6899 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6900 error = ENOPROTOOPT;
6902 } /* end switch (opt) */
6907 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6909 void *optval = NULL;
6913 struct sctp_inpcb *inp;
6915 if ((sopt->sopt_level == SOL_SOCKET) &&
6916 (sopt->sopt_name == SO_SETFIB)) {
6917 inp = (struct sctp_inpcb *)so->so_pcb;
6919 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6922 SCTP_INP_WLOCK(inp);
6923 inp->fibnum = so->so_fibnum;
6924 SCTP_INP_WUNLOCK(inp);
6927 if (sopt->sopt_level != IPPROTO_SCTP) {
6928 /* wrong proto level... send back up to IP */
6930 if (INP_CHECK_SOCKAF(so, AF_INET6))
6931 error = ip6_ctloutput(so, sopt);
6933 #if defined(INET) && defined(INET6)
6937 error = ip_ctloutput(so, sopt);
6941 optsize = sopt->sopt_valsize;
6942 if (optsize > SCTP_SOCKET_OPTION_LIMIT) {
6943 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6947 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6948 if (optval == NULL) {
6949 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6952 error = sooptcopyin(sopt, optval, optsize, optsize);
6954 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6958 p = (void *)sopt->sopt_td;
6959 if (sopt->sopt_dir == SOPT_SET) {
6960 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6961 } else if (sopt->sopt_dir == SOPT_GET) {
6962 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6964 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6967 if ((error == 0) && (optval != NULL)) {
6968 error = sooptcopyout(sopt, optval, optsize);
6969 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6970 } else if (optval != NULL) {
6971 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6979 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6982 int create_lock_on = 0;
6984 struct sctp_inpcb *inp;
6985 struct sctp_tcb *stcb = NULL;
6987 inp = (struct sctp_inpcb *)so->so_pcb;
6989 /* I made the same as TCP since we are not setup? */
6990 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6991 return (ECONNRESET);
6994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6998 switch (addr->sa_family) {
7002 struct sockaddr_in6 *sin6;
7004 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
7005 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7008 sin6 = (struct sockaddr_in6 *)addr;
7009 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6->sin6_addr)) != 0) {
7010 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7019 struct sockaddr_in *sin;
7021 if (addr->sa_len != sizeof(struct sockaddr_in)) {
7022 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7025 sin = (struct sockaddr_in *)addr;
7026 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sin->sin_addr)) != 0) {
7027 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7034 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
7035 return (EAFNOSUPPORT);
7037 SCTP_INP_INCR_REF(inp);
7038 SCTP_ASOC_CREATE_LOCK(inp);
7042 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
7043 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
7044 /* Should I really unlock ? */
7045 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
7050 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
7051 (addr->sa_family == AF_INET6)) {
7052 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7057 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
7058 SCTP_PCB_FLAGS_UNBOUND) {
7059 /* Bind a ephemeral port */
7060 error = sctp_inpcb_bind(so, NULL, NULL, p);
7065 /* Now do we connect? */
7066 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
7067 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
7068 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7072 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7073 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7074 /* We are already connected AND the TCP model */
7075 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7079 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7080 SCTP_INP_RLOCK(inp);
7081 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7082 SCTP_INP_RUNLOCK(inp);
7085 * We increment here since sctp_findassociation_ep_addr()
7086 * will do a decrement if it finds the stcb as long as the
7087 * locked tcb (last argument) is NOT a TCB.. aka NULL.
7089 SCTP_INP_INCR_REF(inp);
7090 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7092 SCTP_INP_DECR_REF(inp);
7094 SCTP_TCB_UNLOCK(stcb);
7098 /* Already have or am bring up an association */
7099 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7104 vrf_id = inp->def_vrf_id;
7105 /* We are GOOD to go */
7106 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
7107 inp->sctp_ep.pre_open_stream_count,
7108 inp->sctp_ep.port, p,
7109 SCTP_INITIALIZE_AUTH_PARAMS);
7111 /* Gak! no memory */
7114 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7115 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7116 /* Set the connected flag so we can queue data */
7119 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7120 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7122 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7123 SCTP_TCB_UNLOCK(stcb);
7125 if (create_lock_on) {
7126 SCTP_ASOC_CREATE_UNLOCK(inp);
7129 SCTP_INP_DECR_REF(inp);
7135 sctp_listen(struct socket *so, int backlog, struct thread *p)
7138 * Note this module depends on the protocol processing being called
7139 * AFTER any socket level flags and backlog are applied to the
7140 * socket. The traditional way that the socket flags are applied is
7141 * AFTER protocol processing. We have made a change to the
7142 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7143 * place if the socket API for SCTP is to work properly.
7147 struct sctp_inpcb *inp;
7149 inp = (struct sctp_inpcb *)so->so_pcb;
7151 /* I made the same as TCP since we are not setup? */
7152 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7153 return (ECONNRESET);
7155 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7156 /* See if we have a listener */
7157 struct sctp_inpcb *tinp;
7158 union sctp_sockstore store;
7160 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7162 struct sctp_laddr *laddr;
7164 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7165 memcpy(&store, &laddr->ifa->address, sizeof(store));
7166 switch (store.sa.sa_family) {
7169 store.sin.sin_port = inp->sctp_lport;
7174 store.sin6.sin6_port = inp->sctp_lport;
7180 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7181 if (tinp && (tinp != inp) &&
7182 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7183 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7184 (SCTP_IS_LISTENING(tinp))) {
7186 * we have a listener already and
7189 SCTP_INP_DECR_REF(tinp);
7190 return (EADDRINUSE);
7192 SCTP_INP_DECR_REF(tinp);
7196 /* Setup a local addr bound all */
7197 memset(&store, 0, sizeof(store));
7199 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7200 store.sa.sa_family = AF_INET6;
7201 store.sa.sa_len = sizeof(struct sockaddr_in6);
7205 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7206 store.sa.sa_family = AF_INET;
7207 store.sa.sa_len = sizeof(struct sockaddr_in);
7210 switch (store.sa.sa_family) {
7213 store.sin.sin_port = inp->sctp_lport;
7218 store.sin6.sin6_port = inp->sctp_lport;
7224 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7225 if (tinp && (tinp != inp) &&
7226 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7227 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7228 (SCTP_IS_LISTENING(tinp))) {
7230 * we have a listener already and its not
7233 SCTP_INP_DECR_REF(tinp);
7234 return (EADDRINUSE);
7236 SCTP_INP_DECR_REF(tinp);
7240 SCTP_INP_RLOCK(inp);
7241 #ifdef SCTP_LOCK_LOGGING
7242 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7243 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7247 error = solisten_proto_check(so);
7250 SCTP_INP_RUNLOCK(inp);
7253 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7254 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7256 * The unlucky case - We are in the tcp pool with this guy.
7257 * - Someone else is in the main inp slot. - We must move
7258 * this guy (the listener) to the main slot - We must then
7259 * move the guy that was listener to the TCP Pool.
7261 if (sctp_swap_inpcb_for_listen(inp)) {
7262 SCTP_INP_RUNLOCK(inp);
7263 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7264 return (EADDRINUSE);
7268 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7269 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7270 /* We are already connected AND the TCP model */
7271 SCTP_INP_RUNLOCK(inp);
7272 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7273 return (EADDRINUSE);
7275 SCTP_INP_RUNLOCK(inp);
7276 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7277 /* We must do a bind. */
7278 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7279 /* bind error, probably perm */
7283 SCTP_INP_WLOCK(inp);
7284 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7286 solisten_proto(so, backlog);
7290 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7292 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7294 SCTP_INP_WUNLOCK(inp);
7298 static int sctp_defered_wakeup_cnt = 0;
7301 sctp_accept(struct socket *so, struct sockaddr **addr)
7303 struct sctp_tcb *stcb;
7304 struct sctp_inpcb *inp;
7305 union sctp_sockstore store;
7309 inp = (struct sctp_inpcb *)so->so_pcb;
7312 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7313 return (ECONNRESET);
7315 SCTP_INP_WLOCK(inp);
7316 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7317 SCTP_INP_WUNLOCK(inp);
7318 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7319 return (EOPNOTSUPP);
7321 if (so->so_state & SS_ISDISCONNECTED) {
7322 SCTP_INP_WUNLOCK(inp);
7323 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7324 return (ECONNABORTED);
7326 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7328 SCTP_INP_WUNLOCK(inp);
7329 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7330 return (ECONNRESET);
7332 SCTP_TCB_LOCK(stcb);
7333 store = stcb->asoc.primary_destination->ro._l_addr;
7334 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7335 /* Wake any delayed sleep action */
7336 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7337 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7338 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7339 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7340 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7341 if (sowriteable(inp->sctp_socket)) {
7342 sowwakeup_locked(inp->sctp_socket);
7344 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7347 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7348 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7349 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7350 if (soreadable(inp->sctp_socket)) {
7351 sctp_defered_wakeup_cnt++;
7352 sorwakeup_locked(inp->sctp_socket);
7354 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7358 SCTP_INP_WUNLOCK(inp);
7359 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7360 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7361 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7363 SCTP_TCB_UNLOCK(stcb);
7365 switch (store.sa.sa_family) {
7369 struct sockaddr_in *sin;
7371 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7374 sin->sin_family = AF_INET;
7375 sin->sin_len = sizeof(*sin);
7376 sin->sin_port = store.sin.sin_port;
7377 sin->sin_addr = store.sin.sin_addr;
7378 *addr = (struct sockaddr *)sin;
7385 struct sockaddr_in6 *sin6;
7387 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7390 sin6->sin6_family = AF_INET6;
7391 sin6->sin6_len = sizeof(*sin6);
7392 sin6->sin6_port = store.sin6.sin6_port;
7393 sin6->sin6_addr = store.sin6.sin6_addr;
7394 if ((error = sa6_recoverscope(sin6)) != 0) {
7395 SCTP_FREE_SONAME(sin6);
7398 *addr = (struct sockaddr *)sin6;
7411 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7413 struct sockaddr_in *sin;
7415 struct sctp_inpcb *inp;
7416 struct sctp_ifa *sctp_ifa;
7419 * Do the malloc first in case it blocks.
7421 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7424 sin->sin_family = AF_INET;
7425 sin->sin_len = sizeof(*sin);
7426 inp = (struct sctp_inpcb *)so->so_pcb;
7428 SCTP_FREE_SONAME(sin);
7429 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7430 return (ECONNRESET);
7432 SCTP_INP_RLOCK(inp);
7433 sin->sin_port = inp->sctp_lport;
7434 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7435 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7436 struct sctp_tcb *stcb;
7437 struct sockaddr_in *sin_a;
7438 struct sctp_nets *net;
7441 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7447 SCTP_TCB_LOCK(stcb);
7448 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7449 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7451 /* this will make coverity happy */
7454 if (sin_a->sin_family == AF_INET) {
7459 if ((!fnd) || (sin_a == NULL)) {
7461 SCTP_TCB_UNLOCK(stcb);
7465 vrf_id = inp->def_vrf_id;
7466 sctp_ifa = sctp_source_address_selection(inp,
7468 (sctp_route_t *)&net->ro,
7471 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7472 sctp_free_ifa(sctp_ifa);
7474 SCTP_TCB_UNLOCK(stcb);
7476 /* For the bound all case you get back 0 */
7478 sin->sin_addr.s_addr = 0;
7482 /* Take the first IPv4 address in the list */
7483 struct sctp_laddr *laddr;
7486 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7487 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7488 struct sockaddr_in *sin_a;
7490 sin_a = &laddr->ifa->address.sin;
7491 sin->sin_addr = sin_a->sin_addr;
7497 SCTP_FREE_SONAME(sin);
7498 SCTP_INP_RUNLOCK(inp);
7499 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7503 SCTP_INP_RUNLOCK(inp);
7504 (*addr) = (struct sockaddr *)sin;
7509 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7511 struct sockaddr_in *sin;
7513 struct sockaddr_in *sin_a;
7514 struct sctp_inpcb *inp;
7515 struct sctp_tcb *stcb;
7516 struct sctp_nets *net;
7518 /* Do the malloc first in case it blocks. */
7519 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7522 sin->sin_family = AF_INET;
7523 sin->sin_len = sizeof(*sin);
7525 inp = (struct sctp_inpcb *)so->so_pcb;
7526 if ((inp == NULL) ||
7527 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7528 /* UDP type and listeners will drop out here */
7529 SCTP_FREE_SONAME(sin);
7530 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7533 SCTP_INP_RLOCK(inp);
7534 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7536 SCTP_TCB_LOCK(stcb);
7538 SCTP_INP_RUNLOCK(inp);
7540 SCTP_FREE_SONAME(sin);
7541 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7542 return (ECONNRESET);
7545 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7546 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7547 if (sin_a->sin_family == AF_INET) {
7549 sin->sin_port = stcb->rport;
7550 sin->sin_addr = sin_a->sin_addr;
7554 SCTP_TCB_UNLOCK(stcb);
7556 /* No IPv4 address */
7557 SCTP_FREE_SONAME(sin);
7558 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7561 (*addr) = (struct sockaddr *)sin;
7565 struct pr_usrreqs sctp_usrreqs = {
7566 .pru_abort = sctp_abort,
7567 .pru_accept = sctp_accept,
7568 .pru_attach = sctp_attach,
7569 .pru_bind = sctp_bind,
7570 .pru_connect = sctp_connect,
7571 .pru_control = in_control,
7572 .pru_close = sctp_close,
7573 .pru_detach = sctp_close,
7574 .pru_sopoll = sopoll_generic,
7575 .pru_flush = sctp_flush,
7576 .pru_disconnect = sctp_disconnect,
7577 .pru_listen = sctp_listen,
7578 .pru_peeraddr = sctp_peeraddr,
7579 .pru_send = sctp_sendm,
7580 .pru_shutdown = sctp_shutdown,
7581 .pru_sockaddr = sctp_ingetaddr,
7582 .pru_sosend = sctp_sosend,
7583 .pru_soreceive = sctp_soreceive