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,
425 CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
426 0, 0, sctp_getcred, "S,ucred",
427 "Get the ucred of a SCTP connection");
432 sctp_abort(struct socket *so)
434 struct epoch_tracker et;
435 struct sctp_inpcb *inp;
438 inp = (struct sctp_inpcb *)so->so_pcb;
445 flags = inp->sctp_flags;
446 #ifdef SCTP_LOG_CLOSING
447 sctp_log_closing(inp, NULL, 17);
449 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
450 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
451 #ifdef SCTP_LOG_CLOSING
452 sctp_log_closing(inp, NULL, 16);
454 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
455 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
457 SCTP_SB_CLEAR(so->so_snd);
459 * same for the rcv ones, they are only here for the
462 SCTP_SB_CLEAR(so->so_rcv);
464 /* Now null out the reference, we are completely detached. */
468 flags = inp->sctp_flags;
469 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
470 goto sctp_must_try_again;
478 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
480 struct sctp_inpcb *inp;
481 struct inpcb *ip_inp;
483 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
485 inp = (struct sctp_inpcb *)so->so_pcb;
487 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
490 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
491 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
496 error = sctp_inpcb_alloc(so, vrf_id);
500 inp = (struct sctp_inpcb *)so->so_pcb;
502 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
503 ip_inp = &inp->ip_inp.inp;
504 ip_inp->inp_vflag |= INP_IPV4;
505 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
506 SCTP_INP_WUNLOCK(inp);
511 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
513 struct sctp_inpcb *inp;
515 inp = (struct sctp_inpcb *)so->so_pcb;
517 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
521 if ((addr->sa_family != AF_INET) ||
522 (addr->sa_len != sizeof(struct sockaddr_in))) {
523 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
527 return (sctp_inpcb_bind(so, addr, NULL, p));
532 sctp_close(struct socket *so)
534 struct epoch_tracker et;
535 struct sctp_inpcb *inp;
538 inp = (struct sctp_inpcb *)so->so_pcb;
543 * Inform all the lower layer assoc that we are done.
547 flags = inp->sctp_flags;
548 #ifdef SCTP_LOG_CLOSING
549 sctp_log_closing(inp, NULL, 17);
551 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
552 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
553 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
554 (so->so_rcv.sb_cc > 0)) {
555 #ifdef SCTP_LOG_CLOSING
556 sctp_log_closing(inp, NULL, 13);
558 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
559 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
561 #ifdef SCTP_LOG_CLOSING
562 sctp_log_closing(inp, NULL, 14);
564 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
565 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
568 * The socket is now detached, no matter what the state of
569 * the SCTP association.
572 SCTP_SB_CLEAR(so->so_snd);
574 * same for the rcv ones, they are only here for the
577 SCTP_SB_CLEAR(so->so_rcv);
579 /* Now null out the reference, we are completely detached. */
583 flags = inp->sctp_flags;
584 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
585 goto sctp_must_try_again;
594 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
595 struct mbuf *control, struct thread *p);
599 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
600 struct mbuf *control, struct thread *p)
602 struct sctp_inpcb *inp;
605 inp = (struct sctp_inpcb *)so->so_pcb;
608 sctp_m_freem(control);
611 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
615 /* Got to have an to address if we are NOT a connected socket */
616 if ((addr == NULL) &&
617 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
618 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
620 } else if (addr == NULL) {
621 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
622 error = EDESTADDRREQ;
625 sctp_m_freem(control);
631 if (addr->sa_family != AF_INET) {
632 /* must be a v4 address! */
633 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
636 sctp_m_freem(control);
639 error = EDESTADDRREQ;
644 /* now what about control */
647 sctp_m_freem(inp->control);
650 inp->control = control;
654 SCTP_BUF_NEXT(inp->pkt_last) = m;
657 inp->pkt_last = inp->pkt = m;
660 /* FreeBSD uses a flag passed */
661 ((flags & PRUS_MORETOCOME) == 0)
664 * note with the current version this code will only be used
665 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
666 * re-defining sosend to use the sctp_sosend. One can
667 * optionally switch back to this code (by changing back the
668 * definitions) but this is not advisable. This code is used
669 * by FreeBSD when sending a file with sendfile() though.
671 struct epoch_tracker et;
675 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
686 sctp_disconnect(struct socket *so)
688 struct sctp_inpcb *inp;
690 inp = (struct sctp_inpcb *)so->so_pcb;
692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
696 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
697 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
698 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
700 SCTP_INP_RUNLOCK(inp);
703 struct epoch_tracker et;
704 struct sctp_association *asoc;
705 struct sctp_tcb *stcb;
707 stcb = LIST_FIRST(&inp->sctp_asoc_list);
709 SCTP_INP_RUNLOCK(inp);
710 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
715 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
716 /* We are about to be freed, out of here */
717 SCTP_TCB_UNLOCK(stcb);
718 SCTP_INP_RUNLOCK(inp);
722 if (((so->so_options & SO_LINGER) &&
723 (so->so_linger == 0)) ||
724 (so->so_rcv.sb_cc > 0)) {
725 if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) {
726 /* Left with Data unread */
729 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
730 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
731 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
733 SCTP_INP_RUNLOCK(inp);
734 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
735 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
736 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
738 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
739 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
740 /* No unlock tcb assoc is gone */
744 if (TAILQ_EMPTY(&asoc->send_queue) &&
745 TAILQ_EMPTY(&asoc->sent_queue) &&
746 (asoc->stream_queue_cnt == 0)) {
747 /* there is nothing queued to send, so done */
748 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
751 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) &&
752 (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
753 /* only send SHUTDOWN 1st time thru */
754 struct sctp_nets *netp;
756 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
757 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
758 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
760 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
761 sctp_stop_timers_for_shutdown(stcb);
762 if (stcb->asoc.alternate) {
763 netp = stcb->asoc.alternate;
765 netp = stcb->asoc.primary_destination;
767 sctp_send_shutdown(stcb, netp);
768 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
769 stcb->sctp_ep, stcb, netp);
770 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
771 stcb->sctp_ep, stcb, NULL);
772 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
776 * we still got (or just got) data to send,
777 * so set SHUTDOWN_PENDING
780 * XXX sockets draft says that SCTP_EOF
781 * should be sent with no data. currently,
782 * we will allow user data to be sent first
783 * and move to SHUTDOWN-PENDING
785 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
786 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
787 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
788 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
790 if (TAILQ_EMPTY(&asoc->send_queue) &&
791 TAILQ_EMPTY(&asoc->sent_queue) &&
792 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
796 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
797 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
798 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
799 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
800 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
801 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
802 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
804 SCTP_INP_RUNLOCK(inp);
805 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
806 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
810 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
813 soisdisconnecting(so);
815 SCTP_TCB_UNLOCK(stcb);
816 SCTP_INP_RUNLOCK(inp);
821 /* UDP model does not support this */
822 SCTP_INP_RUNLOCK(inp);
823 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
829 sctp_flush(struct socket *so, int how)
832 * We will just clear out the values and let subsequent close clear
833 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
834 * they will not be able to read the data, the socket will block
835 * that from happening.
837 struct sctp_inpcb *inp;
839 inp = (struct sctp_inpcb *)so->so_pcb;
841 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
845 /* For the 1 to many model this does nothing */
846 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
847 SCTP_INP_RUNLOCK(inp);
850 SCTP_INP_RUNLOCK(inp);
851 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
853 * First make sure the sb will be happy, we don't use these
854 * except maybe the count
857 SCTP_INP_READ_LOCK(inp);
858 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
859 SCTP_INP_READ_UNLOCK(inp);
860 SCTP_INP_WUNLOCK(inp);
861 so->so_rcv.sb_cc = 0;
862 so->so_rcv.sb_mbcnt = 0;
863 so->so_rcv.sb_mb = NULL;
865 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
867 * First make sure the sb will be happy, we don't use these
868 * except maybe the count
870 so->so_snd.sb_cc = 0;
871 so->so_snd.sb_mbcnt = 0;
872 so->so_snd.sb_mb = NULL;
879 sctp_shutdown(struct socket *so)
881 struct sctp_inpcb *inp;
883 inp = (struct sctp_inpcb *)so->so_pcb;
885 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
889 /* For UDP model this is a invalid call */
890 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
891 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
892 /* Restore the flags that the soshutdown took away. */
893 SOCKBUF_LOCK(&so->so_rcv);
894 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
895 SOCKBUF_UNLOCK(&so->so_rcv);
896 /* This proc will wakeup for read and do nothing (I hope) */
897 SCTP_INP_RUNLOCK(inp);
898 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
902 * Ok, if we reach here its the TCP model and it is either a
903 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
906 struct epoch_tracker et;
907 struct sctp_tcb *stcb;
908 struct sctp_association *asoc;
909 struct sctp_nets *netp;
912 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
913 SCTP_INP_RUNLOCK(inp);
918 stcb = LIST_FIRST(&inp->sctp_asoc_list);
921 * Ok, we hit the case that the shutdown call was
922 * made after an abort or something. Nothing to do
925 SCTP_INP_RUNLOCK(inp);
930 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
931 SCTP_TCB_UNLOCK(stcb);
932 SCTP_INP_RUNLOCK(inp);
935 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) &&
936 (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) &&
937 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) {
939 * If we are not in or before ESTABLISHED, there is
940 * no protocol action required.
942 SCTP_TCB_UNLOCK(stcb);
943 SCTP_INP_RUNLOCK(inp);
947 if (stcb->asoc.alternate) {
948 netp = stcb->asoc.alternate;
950 netp = stcb->asoc.primary_destination;
952 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) &&
953 TAILQ_EMPTY(&asoc->send_queue) &&
954 TAILQ_EMPTY(&asoc->sent_queue) &&
955 (asoc->stream_queue_cnt == 0)) {
956 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
959 /* there is nothing queued to send, so I'm done... */
960 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
961 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
962 sctp_stop_timers_for_shutdown(stcb);
963 sctp_send_shutdown(stcb, netp);
964 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
965 stcb->sctp_ep, stcb, netp);
968 * We still got (or just got) data to send, so set
971 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
972 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
973 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
975 if (TAILQ_EMPTY(&asoc->send_queue) &&
976 TAILQ_EMPTY(&asoc->sent_queue) &&
977 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
981 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
982 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
983 SCTP_INP_RUNLOCK(inp);
984 sctp_abort_an_association(stcb->sctp_ep, stcb,
985 op_err, SCTP_SO_LOCKED);
990 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
992 * XXX: Why do this in the case where we have still data
995 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
996 SCTP_TCB_UNLOCK(stcb);
997 SCTP_INP_RUNLOCK(inp);
1004 * copies a "user" presentable address and removes embedded scope, etc.
1005 * returns 0 on success, 1 on error
1008 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1011 struct sockaddr_in6 lsa6;
1013 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1016 memcpy(ss, sa, sa->sa_len);
1023 * NOTE: assumes addr lock is held
1026 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1027 struct sctp_tcb *stcb,
1029 struct sockaddr_storage *sas,
1032 struct sctp_ifn *sctp_ifn;
1033 struct sctp_ifa *sctp_ifa;
1037 int ipv4_local_scope, ipv4_addr_legal;
1040 int local_scope, site_scope, ipv6_addr_legal;
1042 struct sctp_vrf *vrf;
1049 /* Turn on all the appropriate scope */
1050 loopback_scope = stcb->asoc.scope.loopback_scope;
1052 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1053 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1056 local_scope = stcb->asoc.scope.local_scope;
1057 site_scope = stcb->asoc.scope.site_scope;
1058 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1061 /* Use generic values for endpoints. */
1064 ipv4_local_scope = 1;
1070 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1072 ipv6_addr_legal = 1;
1075 if (SCTP_IPV6_V6ONLY(inp)) {
1076 ipv4_addr_legal = 0;
1078 ipv4_addr_legal = 1;
1083 ipv6_addr_legal = 0;
1086 ipv4_addr_legal = 1;
1090 vrf = sctp_find_vrf(vrf_id);
1094 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1095 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1096 if ((loopback_scope == 0) &&
1097 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1098 /* Skip loopback if loopback_scope not set */
1101 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1104 * For the BOUND-ALL case, the list
1105 * associated with a TCB is Always
1106 * considered a reverse list.. i.e.
1107 * it lists addresses that are NOT
1108 * part of the association. If this
1109 * is one of those we must skip it.
1111 if (sctp_is_addr_restricted(stcb,
1116 switch (sctp_ifa->address.sa.sa_family) {
1119 if (ipv4_addr_legal) {
1120 struct sockaddr_in *sin;
1122 sin = &sctp_ifa->address.sin;
1123 if (sin->sin_addr.s_addr == 0) {
1131 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1132 &sin->sin_addr) != 0) {
1135 if ((ipv4_local_scope == 0) &&
1136 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1140 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1141 if (actual + sizeof(struct sockaddr_in6) > limit) {
1144 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1145 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1146 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1147 actual += sizeof(struct sockaddr_in6);
1150 if (actual + sizeof(struct sockaddr_in) > limit) {
1153 memcpy(sas, sin, sizeof(struct sockaddr_in));
1154 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1155 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in));
1156 actual += sizeof(struct sockaddr_in);
1167 if (ipv6_addr_legal) {
1168 struct sockaddr_in6 *sin6;
1170 sin6 = &sctp_ifa->address.sin6;
1171 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1179 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1180 &sin6->sin6_addr) != 0) {
1183 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1184 if (local_scope == 0)
1186 if (sin6->sin6_scope_id == 0) {
1187 if (sa6_recoverscope(sin6) != 0)
1200 if ((site_scope == 0) &&
1201 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1204 if (actual + sizeof(struct sockaddr_in6) > limit) {
1207 memcpy(sas, sin6, sizeof(struct sockaddr_in6));
1208 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1209 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1210 actual += sizeof(struct sockaddr_in6);
1223 struct sctp_laddr *laddr;
1226 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1228 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1232 sa_len = laddr->ifa->address.sa.sa_len;
1233 if (actual + sa_len > limit) {
1236 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1238 switch (laddr->ifa->address.sa.sa_family) {
1241 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1246 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1253 sas = (struct sockaddr_storage *)((caddr_t)sas + sa_len);
1261 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1262 struct sctp_tcb *stcb,
1264 struct sockaddr_storage *sas)
1268 SCTP_IPI_ADDR_RLOCK();
1269 /* fill up addresses for the endpoint's default vrf */
1270 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1272 SCTP_IPI_ADDR_RUNLOCK();
1277 * NOTE: assumes addr lock is held
1280 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1283 struct sctp_vrf *vrf = NULL;
1286 * In both sub-set bound an bound_all cases we return the MAXIMUM
1287 * number of addresses that you COULD get. In reality the sub-set
1288 * bound may have an exclusion list for a given TCB OR in the
1289 * bound-all case a TCB may NOT include the loopback or other
1290 * addresses as well.
1292 vrf = sctp_find_vrf(vrf_id);
1296 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1297 struct sctp_ifn *sctp_ifn;
1298 struct sctp_ifa *sctp_ifa;
1300 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1301 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1302 /* Count them if they are the right type */
1303 switch (sctp_ifa->address.sa.sa_family) {
1307 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1308 cnt += sizeof(struct sockaddr_in6);
1310 cnt += sizeof(struct sockaddr_in);
1312 cnt += sizeof(struct sockaddr_in);
1318 cnt += sizeof(struct sockaddr_in6);
1327 struct sctp_laddr *laddr;
1329 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1330 switch (laddr->ifa->address.sa.sa_family) {
1334 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1335 cnt += sizeof(struct sockaddr_in6);
1337 cnt += sizeof(struct sockaddr_in);
1339 cnt += sizeof(struct sockaddr_in);
1345 cnt += sizeof(struct sockaddr_in6);
1357 sctp_count_max_addresses(struct sctp_inpcb *inp)
1361 SCTP_IPI_ADDR_RLOCK();
1362 /* count addresses for the endpoint's default VRF */
1363 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1364 SCTP_IPI_ADDR_RUNLOCK();
1369 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1370 size_t optsize, void *p, int delay)
1373 int creat_lock_on = 0;
1374 struct sctp_tcb *stcb = NULL;
1375 struct sockaddr *sa;
1376 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1380 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1382 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1383 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1384 /* We are already connected AND the TCP model */
1385 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1386 return (EADDRINUSE);
1389 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1390 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1391 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1395 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1396 SCTP_INP_RLOCK(inp);
1397 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1398 SCTP_INP_RUNLOCK(inp);
1401 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1404 SCTP_INP_INCR_REF(inp);
1405 SCTP_ASOC_CREATE_LOCK(inp);
1407 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1408 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1409 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1413 totaddrp = (unsigned int *)optval;
1414 totaddr = *totaddrp;
1415 sa = (struct sockaddr *)(totaddrp + 1);
1416 error = sctp_connectx_helper_find(inp, sa, totaddr, &num_v4, &num_v6, (unsigned int)(optsize - sizeof(int)));
1418 /* Already have or am bring up an association */
1419 SCTP_ASOC_CREATE_UNLOCK(inp);
1421 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1425 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1430 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1432 if (SCTP_IPV6_V6ONLY(inp)) {
1434 * if IPV6_V6ONLY flag, ignore connections destined
1435 * to a v4 addr or v4-mapped addr
1437 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1443 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1444 SCTP_PCB_FLAGS_UNBOUND) {
1445 /* Bind a ephemeral port */
1446 error = sctp_inpcb_bind(so, NULL, NULL, p);
1452 /* FIX ME: do we want to pass in a vrf on the connect call? */
1453 vrf_id = inp->def_vrf_id;
1456 /* We are GOOD to go */
1457 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1458 inp->sctp_ep.pre_open_stream_count,
1461 SCTP_INITIALIZE_AUTH_PARAMS);
1463 /* Gak! no memory */
1466 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1467 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1468 /* Set the connected flag so we can queue data */
1471 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1472 /* move to second address */
1473 switch (sa->sa_family) {
1476 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1481 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1489 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1490 /* Fill in the return id */
1494 a_id = (sctp_assoc_t *)optval;
1495 *a_id = sctp_get_associd(stcb);
1498 /* doing delayed connection */
1499 stcb->asoc.delayed_connection = 1;
1500 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1502 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1503 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1505 SCTP_TCB_UNLOCK(stcb);
1507 if (creat_lock_on) {
1508 SCTP_ASOC_CREATE_UNLOCK(inp);
1510 SCTP_INP_DECR_REF(inp);
1514 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1515 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1516 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1517 SCTP_INP_RLOCK(inp); \
1518 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1520 SCTP_TCB_LOCK(stcb); \
1522 SCTP_INP_RUNLOCK(inp); \
1523 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1524 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1525 if (stcb == NULL) { \
1526 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1536 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1537 if (size < sizeof(type)) { \
1538 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1542 destp = (type *)srcp; \
1547 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1550 struct sctp_inpcb *inp = NULL;
1552 struct sctp_tcb *stcb = NULL;
1554 if (optval == NULL) {
1555 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1559 inp = (struct sctp_inpcb *)so->so_pcb;
1561 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1568 case SCTP_AUTOCLOSE:
1569 case SCTP_EXPLICIT_EOR:
1570 case SCTP_AUTO_ASCONF:
1571 case SCTP_DISABLE_FRAGMENTS:
1572 case SCTP_I_WANT_MAPPED_V4_ADDR:
1573 case SCTP_USE_EXT_RCVINFO:
1574 SCTP_INP_RLOCK(inp);
1576 case SCTP_DISABLE_FRAGMENTS:
1577 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1579 case SCTP_I_WANT_MAPPED_V4_ADDR:
1580 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1582 case SCTP_AUTO_ASCONF:
1583 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1584 /* only valid for bound all sockets */
1585 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1587 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1592 case SCTP_EXPLICIT_EOR:
1593 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1596 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1598 case SCTP_USE_EXT_RCVINFO:
1599 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1601 case SCTP_AUTOCLOSE:
1602 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1603 val = sctp_ticks_to_secs(inp->sctp_ep.auto_close_time);
1609 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1610 error = ENOPROTOOPT;
1611 } /* end switch (sopt->sopt_name) */
1612 if (*optsize < sizeof(val)) {
1613 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1617 SCTP_INP_RUNLOCK(inp);
1619 /* return the option value */
1620 *(int *)optval = val;
1621 *optsize = sizeof(val);
1624 case SCTP_GET_PACKET_LOG:
1626 #ifdef SCTP_PACKET_LOGGING
1630 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1631 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1634 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1639 case SCTP_REUSE_PORT:
1643 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1644 /* Can't do this for a 1-m socket */
1648 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1649 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1650 *optsize = sizeof(uint32_t);
1653 case SCTP_PARTIAL_DELIVERY_POINT:
1657 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1658 *value = inp->partial_delivery_point;
1659 *optsize = sizeof(uint32_t);
1662 case SCTP_FRAGMENT_INTERLEAVE:
1666 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1667 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1668 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1669 *value = SCTP_FRAG_LEVEL_2;
1671 *value = SCTP_FRAG_LEVEL_1;
1674 *value = SCTP_FRAG_LEVEL_0;
1676 *optsize = sizeof(uint32_t);
1679 case SCTP_INTERLEAVING_SUPPORTED:
1681 struct sctp_assoc_value *av;
1683 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1684 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1687 av->assoc_value = stcb->asoc.idata_supported;
1688 SCTP_TCB_UNLOCK(stcb);
1690 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1691 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1692 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1693 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1694 SCTP_INP_RLOCK(inp);
1695 if (inp->idata_supported) {
1696 av->assoc_value = 1;
1698 av->assoc_value = 0;
1700 SCTP_INP_RUNLOCK(inp);
1702 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1707 *optsize = sizeof(struct sctp_assoc_value);
1711 case SCTP_CMT_ON_OFF:
1713 struct sctp_assoc_value *av;
1715 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1716 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1718 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1719 SCTP_TCB_UNLOCK(stcb);
1721 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1722 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1723 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1724 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1725 SCTP_INP_RLOCK(inp);
1726 av->assoc_value = inp->sctp_cmt_on_off;
1727 SCTP_INP_RUNLOCK(inp);
1729 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1734 *optsize = sizeof(struct sctp_assoc_value);
1738 case SCTP_PLUGGABLE_CC:
1740 struct sctp_assoc_value *av;
1742 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1743 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1745 av->assoc_value = stcb->asoc.congestion_control_module;
1746 SCTP_TCB_UNLOCK(stcb);
1748 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1749 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1750 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1751 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1752 SCTP_INP_RLOCK(inp);
1753 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1754 SCTP_INP_RUNLOCK(inp);
1756 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1761 *optsize = sizeof(struct sctp_assoc_value);
1765 case SCTP_CC_OPTION:
1767 struct sctp_cc_option *cc_opt;
1769 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1770 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1774 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1777 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1778 *optsize = sizeof(struct sctp_cc_option);
1780 SCTP_TCB_UNLOCK(stcb);
1784 case SCTP_PLUGGABLE_SS:
1786 struct sctp_assoc_value *av;
1788 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1789 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1791 av->assoc_value = stcb->asoc.stream_scheduling_module;
1792 SCTP_TCB_UNLOCK(stcb);
1794 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1795 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1796 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1797 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1798 SCTP_INP_RLOCK(inp);
1799 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1800 SCTP_INP_RUNLOCK(inp);
1802 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1807 *optsize = sizeof(struct sctp_assoc_value);
1813 struct sctp_stream_value *av;
1815 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1816 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1818 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1819 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1820 &av->stream_value) < 0)) {
1821 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1824 *optsize = sizeof(struct sctp_stream_value);
1826 SCTP_TCB_UNLOCK(stcb);
1829 * Can't get stream value without
1832 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1837 case SCTP_GET_ADDR_LEN:
1839 struct sctp_assoc_value *av;
1841 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1844 if (av->assoc_value == AF_INET) {
1845 av->assoc_value = sizeof(struct sockaddr_in);
1850 if (av->assoc_value == AF_INET6) {
1851 av->assoc_value = sizeof(struct sockaddr_in6);
1856 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1858 *optsize = sizeof(struct sctp_assoc_value);
1862 case SCTP_GET_ASSOC_NUMBER:
1864 uint32_t *value, cnt;
1866 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1867 SCTP_INP_RLOCK(inp);
1868 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1869 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1870 /* Can't do this for a 1-1 socket */
1872 SCTP_INP_RUNLOCK(inp);
1876 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1879 SCTP_INP_RUNLOCK(inp);
1881 *optsize = sizeof(uint32_t);
1884 case SCTP_GET_ASSOC_ID_LIST:
1886 struct sctp_assoc_ids *ids;
1890 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1891 SCTP_INP_RLOCK(inp);
1892 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1893 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1894 /* Can't do this for a 1-1 socket */
1896 SCTP_INP_RUNLOCK(inp);
1900 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1901 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1903 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1906 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1911 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1915 SCTP_INP_RUNLOCK(inp);
1917 ids->gaids_number_of_ids = at;
1918 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1924 struct sctp_assoc_value *av;
1926 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1927 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1930 av->assoc_value = stcb->asoc.context;
1931 SCTP_TCB_UNLOCK(stcb);
1933 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1934 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1935 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1936 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1937 SCTP_INP_RLOCK(inp);
1938 av->assoc_value = inp->sctp_context;
1939 SCTP_INP_RUNLOCK(inp);
1941 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1946 *optsize = sizeof(struct sctp_assoc_value);
1952 uint32_t *default_vrfid;
1954 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1955 *default_vrfid = inp->def_vrf_id;
1956 *optsize = sizeof(uint32_t);
1959 case SCTP_GET_ASOC_VRF:
1961 struct sctp_assoc_value *id;
1963 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1964 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1969 id->assoc_value = stcb->asoc.vrf_id;
1970 SCTP_TCB_UNLOCK(stcb);
1971 *optsize = sizeof(struct sctp_assoc_value);
1975 case SCTP_GET_VRF_IDS:
1977 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1981 case SCTP_GET_NONCE_VALUES:
1983 struct sctp_get_nonce_values *gnv;
1985 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1986 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1989 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1990 gnv->gn_local_tag = stcb->asoc.my_vtag;
1991 SCTP_TCB_UNLOCK(stcb);
1992 *optsize = sizeof(struct sctp_get_nonce_values);
1994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1999 case SCTP_DELAYED_SACK:
2001 struct sctp_sack_info *sack;
2003 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2004 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2006 sack->sack_delay = stcb->asoc.delayed_ack;
2007 sack->sack_freq = stcb->asoc.sack_freq;
2008 SCTP_TCB_UNLOCK(stcb);
2010 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2011 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2012 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2013 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC))) {
2014 SCTP_INP_RLOCK(inp);
2015 sack->sack_delay = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2016 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2017 SCTP_INP_RUNLOCK(inp);
2019 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2024 *optsize = sizeof(struct sctp_sack_info);
2028 case SCTP_GET_SNDBUF_USE:
2030 struct sctp_sockstat *ss;
2032 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2033 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2036 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2037 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2038 stcb->asoc.size_on_all_streams);
2039 SCTP_TCB_UNLOCK(stcb);
2040 *optsize = sizeof(struct sctp_sockstat);
2042 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2047 case SCTP_MAX_BURST:
2049 struct sctp_assoc_value *av;
2051 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2052 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2055 av->assoc_value = stcb->asoc.max_burst;
2056 SCTP_TCB_UNLOCK(stcb);
2058 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2059 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2060 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2061 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2062 SCTP_INP_RLOCK(inp);
2063 av->assoc_value = inp->sctp_ep.max_burst;
2064 SCTP_INP_RUNLOCK(inp);
2066 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2071 *optsize = sizeof(struct sctp_assoc_value);
2077 struct sctp_assoc_value *av;
2080 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2081 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2084 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2085 SCTP_TCB_UNLOCK(stcb);
2087 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2088 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2089 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2090 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2091 SCTP_INP_RLOCK(inp);
2092 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2093 ovh = SCTP_MED_OVERHEAD;
2095 ovh = SCTP_MED_V4_OVERHEAD;
2097 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2098 av->assoc_value = 0;
2100 av->assoc_value = inp->sctp_frag_point - ovh;
2101 SCTP_INP_RUNLOCK(inp);
2103 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2108 *optsize = sizeof(struct sctp_assoc_value);
2112 case SCTP_GET_STAT_LOG:
2113 error = sctp_fill_stat_log(optval, optsize);
2117 struct sctp_event_subscribe *events;
2119 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2120 memset(events, 0, sizeof(struct sctp_event_subscribe));
2121 SCTP_INP_RLOCK(inp);
2122 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2123 events->sctp_data_io_event = 1;
2125 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2126 events->sctp_association_event = 1;
2128 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2129 events->sctp_address_event = 1;
2131 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2132 events->sctp_send_failure_event = 1;
2134 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2135 events->sctp_peer_error_event = 1;
2137 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2138 events->sctp_shutdown_event = 1;
2140 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2141 events->sctp_partial_delivery_event = 1;
2143 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2144 events->sctp_adaptation_layer_event = 1;
2146 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2147 events->sctp_authentication_event = 1;
2149 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2150 events->sctp_sender_dry_event = 1;
2152 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2153 events->sctp_stream_reset_event = 1;
2154 SCTP_INP_RUNLOCK(inp);
2155 *optsize = sizeof(struct sctp_event_subscribe);
2158 case SCTP_ADAPTATION_LAYER:
2162 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2164 SCTP_INP_RLOCK(inp);
2165 *value = inp->sctp_ep.adaptation_layer_indicator;
2166 SCTP_INP_RUNLOCK(inp);
2167 *optsize = sizeof(uint32_t);
2170 case SCTP_SET_INITIAL_DBG_SEQ:
2174 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2175 SCTP_INP_RLOCK(inp);
2176 *value = inp->sctp_ep.initial_sequence_debug;
2177 SCTP_INP_RUNLOCK(inp);
2178 *optsize = sizeof(uint32_t);
2181 case SCTP_GET_LOCAL_ADDR_SIZE:
2185 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2186 SCTP_INP_RLOCK(inp);
2187 *value = sctp_count_max_addresses(inp);
2188 SCTP_INP_RUNLOCK(inp);
2189 *optsize = sizeof(uint32_t);
2192 case SCTP_GET_REMOTE_ADDR_SIZE:
2196 struct sctp_nets *net;
2198 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2199 /* FIXME MT: change to sctp_assoc_value? */
2200 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2204 /* Count the sizes */
2205 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2206 switch (net->ro._l_addr.sa.sa_family) {
2210 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2211 size += sizeof(struct sockaddr_in6);
2213 size += sizeof(struct sockaddr_in);
2216 size += sizeof(struct sockaddr_in);
2222 size += sizeof(struct sockaddr_in6);
2229 SCTP_TCB_UNLOCK(stcb);
2230 *value = (uint32_t)size;
2231 *optsize = sizeof(uint32_t);
2233 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2238 case SCTP_GET_PEER_ADDRESSES:
2240 * Get the address information, an array is passed in to
2241 * fill up we pack it.
2245 struct sockaddr_storage *sas;
2246 struct sctp_nets *net;
2247 struct sctp_getaddresses *saddr;
2249 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2250 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2253 left = (*optsize) - sizeof(sctp_assoc_t);
2254 *optsize = sizeof(sctp_assoc_t);
2255 sas = (struct sockaddr_storage *)&saddr->addr[0];
2257 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2258 switch (net->ro._l_addr.sa.sa_family) {
2262 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2263 cpsz = sizeof(struct sockaddr_in6);
2265 cpsz = sizeof(struct sockaddr_in);
2268 cpsz = sizeof(struct sockaddr_in);
2274 cpsz = sizeof(struct sockaddr_in6);
2285 /* not enough room. */
2288 #if defined(INET) && defined(INET6)
2289 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2290 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2291 /* Must map the address */
2292 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2293 (struct sockaddr_in6 *)sas);
2295 memcpy(sas, &net->ro._l_addr, cpsz);
2298 memcpy(sas, &net->ro._l_addr, cpsz);
2300 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2302 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2306 SCTP_TCB_UNLOCK(stcb);
2308 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2313 case SCTP_GET_LOCAL_ADDRESSES:
2315 size_t limit, actual;
2316 struct sockaddr_storage *sas;
2317 struct sctp_getaddresses *saddr;
2319 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2320 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2322 sas = (struct sockaddr_storage *)&saddr->addr[0];
2323 limit = *optsize - sizeof(sctp_assoc_t);
2324 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2326 SCTP_TCB_UNLOCK(stcb);
2328 *optsize = sizeof(sctp_assoc_t) + actual;
2331 case SCTP_PEER_ADDR_PARAMS:
2333 struct sctp_paddrparams *paddrp;
2334 struct sctp_nets *net;
2335 struct sockaddr *addr;
2336 #if defined(INET) && defined(INET6)
2337 struct sockaddr_in sin_store;
2340 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2341 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2343 #if defined(INET) && defined(INET6)
2344 if (paddrp->spp_address.ss_family == AF_INET6) {
2345 struct sockaddr_in6 *sin6;
2347 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2348 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2349 in6_sin6_2_sin(&sin_store, sin6);
2350 addr = (struct sockaddr *)&sin_store;
2352 addr = (struct sockaddr *)&paddrp->spp_address;
2355 addr = (struct sockaddr *)&paddrp->spp_address;
2358 addr = (struct sockaddr *)&paddrp->spp_address;
2361 net = sctp_findnet(stcb, addr);
2364 * We increment here since
2365 * sctp_findassociation_ep_addr() wil do a
2366 * decrement if it finds the stcb as long as
2367 * the locked tcb (last argument) is NOT a
2371 SCTP_INP_INCR_REF(inp);
2372 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2374 SCTP_INP_DECR_REF(inp);
2377 if ((stcb != NULL) && (net == NULL)) {
2379 if (addr->sa_family == AF_INET) {
2380 struct sockaddr_in *sin;
2382 sin = (struct sockaddr_in *)addr;
2383 if (sin->sin_addr.s_addr != INADDR_ANY) {
2385 SCTP_TCB_UNLOCK(stcb);
2386 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2392 if (addr->sa_family == AF_INET6) {
2393 struct sockaddr_in6 *sin6;
2395 sin6 = (struct sockaddr_in6 *)addr;
2396 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2398 SCTP_TCB_UNLOCK(stcb);
2399 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2405 error = EAFNOSUPPORT;
2406 SCTP_TCB_UNLOCK(stcb);
2407 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2413 /* Applies to the specific association */
2414 paddrp->spp_flags = 0;
2416 paddrp->spp_hbinterval = net->heart_beat_delay;
2417 paddrp->spp_pathmaxrxt = net->failure_threshold;
2418 paddrp->spp_pathmtu = net->mtu;
2419 switch (net->ro._l_addr.sa.sa_family) {
2422 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2427 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2433 /* get flags for HB */
2434 if (net->dest_state & SCTP_ADDR_NOHB) {
2435 paddrp->spp_flags |= SPP_HB_DISABLE;
2437 paddrp->spp_flags |= SPP_HB_ENABLE;
2439 /* get flags for PMTU */
2440 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2441 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2443 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2445 if (net->dscp & 0x01) {
2446 paddrp->spp_dscp = net->dscp & 0xfc;
2447 paddrp->spp_flags |= SPP_DSCP;
2450 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2451 (net->flowlabel & 0x80000000)) {
2452 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2453 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2458 * No destination so return default
2461 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2462 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2463 if (stcb->asoc.default_dscp & 0x01) {
2464 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2465 paddrp->spp_flags |= SPP_DSCP;
2468 if (stcb->asoc.default_flowlabel & 0x80000000) {
2469 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2470 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2473 /* default settings should be these */
2474 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2475 paddrp->spp_flags |= SPP_HB_DISABLE;
2477 paddrp->spp_flags |= SPP_HB_ENABLE;
2479 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2480 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2482 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2484 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2486 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2487 SCTP_TCB_UNLOCK(stcb);
2489 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2490 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2491 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2492 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
2493 /* Use endpoint defaults */
2494 SCTP_INP_RLOCK(inp);
2495 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2496 paddrp->spp_hbinterval = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2497 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2498 /* get inp's default */
2499 if (inp->sctp_ep.default_dscp & 0x01) {
2500 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2501 paddrp->spp_flags |= SPP_DSCP;
2504 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2505 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2506 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2507 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2510 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2512 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2513 paddrp->spp_flags |= SPP_HB_ENABLE;
2515 paddrp->spp_flags |= SPP_HB_DISABLE;
2517 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2518 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2520 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2522 SCTP_INP_RUNLOCK(inp);
2524 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2529 *optsize = sizeof(struct sctp_paddrparams);
2533 case SCTP_GET_PEER_ADDR_INFO:
2535 struct sctp_paddrinfo *paddri;
2536 struct sctp_nets *net;
2537 struct sockaddr *addr;
2538 #if defined(INET) && defined(INET6)
2539 struct sockaddr_in sin_store;
2542 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2543 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2545 #if defined(INET) && defined(INET6)
2546 if (paddri->spinfo_address.ss_family == AF_INET6) {
2547 struct sockaddr_in6 *sin6;
2549 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2550 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2551 in6_sin6_2_sin(&sin_store, sin6);
2552 addr = (struct sockaddr *)&sin_store;
2554 addr = (struct sockaddr *)&paddri->spinfo_address;
2557 addr = (struct sockaddr *)&paddri->spinfo_address;
2560 addr = (struct sockaddr *)&paddri->spinfo_address;
2563 net = sctp_findnet(stcb, addr);
2566 * We increment here since
2567 * sctp_findassociation_ep_addr() wil do a
2568 * decrement if it finds the stcb as long as
2569 * the locked tcb (last argument) is NOT a
2573 SCTP_INP_INCR_REF(inp);
2574 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2576 SCTP_INP_DECR_REF(inp);
2580 if ((stcb != NULL) && (net != NULL)) {
2581 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2582 /* It's unconfirmed */
2583 paddri->spinfo_state = SCTP_UNCONFIRMED;
2584 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2586 paddri->spinfo_state = SCTP_ACTIVE;
2589 paddri->spinfo_state = SCTP_INACTIVE;
2591 paddri->spinfo_cwnd = net->cwnd;
2592 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2593 paddri->spinfo_rto = net->RTO;
2594 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2595 paddri->spinfo_mtu = net->mtu;
2596 switch (addr->sa_family) {
2599 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2604 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2610 SCTP_TCB_UNLOCK(stcb);
2611 *optsize = sizeof(struct sctp_paddrinfo);
2614 SCTP_TCB_UNLOCK(stcb);
2616 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2621 case SCTP_PCB_STATUS:
2623 struct sctp_pcbinfo *spcb;
2625 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2626 sctp_fill_pcbinfo(spcb);
2627 *optsize = sizeof(struct sctp_pcbinfo);
2632 struct sctp_nets *net;
2633 struct sctp_status *sstat;
2635 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2636 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2639 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2643 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2644 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2645 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2646 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2648 * We can't include chunks that have been passed to
2649 * the socket layer. Only things in queue.
2651 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2652 stcb->asoc.cnt_on_all_streams);
2655 sstat->sstat_instrms = stcb->asoc.streamincnt;
2656 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2657 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2658 net = stcb->asoc.primary_destination;
2660 memcpy(&sstat->sstat_primary.spinfo_address,
2662 ((struct sockaddr *)(&net->ro._l_addr))->sa_len);
2663 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2665 * Again the user can get info from
2666 * sctp_constants.h for what the state of
2669 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2670 /* It's unconfirmed */
2671 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2672 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2674 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2677 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2679 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2680 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2681 sstat->sstat_primary.spinfo_rto = net->RTO;
2682 sstat->sstat_primary.spinfo_mtu = net->mtu;
2683 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2686 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2691 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2698 memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo));
2700 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2701 SCTP_TCB_UNLOCK(stcb);
2702 *optsize = sizeof(struct sctp_status);
2707 struct sctp_rtoinfo *srto;
2709 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2710 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2713 srto->srto_initial = stcb->asoc.initial_rto;
2714 srto->srto_max = stcb->asoc.maxrto;
2715 srto->srto_min = stcb->asoc.minrto;
2716 SCTP_TCB_UNLOCK(stcb);
2718 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2719 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2720 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2721 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
2722 SCTP_INP_RLOCK(inp);
2723 srto->srto_initial = inp->sctp_ep.initial_rto;
2724 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2725 srto->srto_min = inp->sctp_ep.sctp_minrto;
2726 SCTP_INP_RUNLOCK(inp);
2728 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2733 *optsize = sizeof(struct sctp_rtoinfo);
2739 struct sctp_timeouts *stimo;
2741 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2742 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2745 stimo->stimo_init = stcb->asoc.timoinit;
2746 stimo->stimo_data = stcb->asoc.timodata;
2747 stimo->stimo_sack = stcb->asoc.timosack;
2748 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2749 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2750 stimo->stimo_cookie = stcb->asoc.timocookie;
2751 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2752 SCTP_TCB_UNLOCK(stcb);
2753 *optsize = sizeof(struct sctp_timeouts);
2755 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2760 case SCTP_ASSOCINFO:
2762 struct sctp_assocparams *sasoc;
2764 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2765 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2768 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(stcb->asoc.cookie_life);
2769 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2770 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2771 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2772 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2773 SCTP_TCB_UNLOCK(stcb);
2775 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2776 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2777 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2778 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
2779 SCTP_INP_RLOCK(inp);
2780 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(inp->sctp_ep.def_cookie_life);
2781 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2782 sasoc->sasoc_number_peer_destinations = 0;
2783 sasoc->sasoc_peer_rwnd = 0;
2784 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2785 SCTP_INP_RUNLOCK(inp);
2787 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2792 *optsize = sizeof(struct sctp_assocparams);
2796 case SCTP_DEFAULT_SEND_PARAM:
2798 struct sctp_sndrcvinfo *s_info;
2800 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2801 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2804 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2805 SCTP_TCB_UNLOCK(stcb);
2807 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2808 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2809 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2810 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC))) {
2811 SCTP_INP_RLOCK(inp);
2812 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2813 SCTP_INP_RUNLOCK(inp);
2815 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2820 *optsize = sizeof(struct sctp_sndrcvinfo);
2826 struct sctp_initmsg *sinit;
2828 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2829 SCTP_INP_RLOCK(inp);
2830 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2831 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2832 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2833 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2834 SCTP_INP_RUNLOCK(inp);
2835 *optsize = sizeof(struct sctp_initmsg);
2838 case SCTP_PRIMARY_ADDR:
2839 /* we allow a "get" operation on this */
2841 struct sctp_setprim *ssp;
2843 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2844 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2847 union sctp_sockstore *addr;
2849 addr = &stcb->asoc.primary_destination->ro._l_addr;
2850 switch (addr->sa.sa_family) {
2854 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2855 in6_sin_2_v4mapsin6(&addr->sin,
2856 (struct sockaddr_in6 *)&ssp->ssp_addr);
2858 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2861 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2867 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2873 SCTP_TCB_UNLOCK(stcb);
2874 *optsize = sizeof(struct sctp_setprim);
2876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2881 case SCTP_HMAC_IDENT:
2883 struct sctp_hmacalgo *shmac;
2884 sctp_hmaclist_t *hmaclist;
2888 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2890 SCTP_INP_RLOCK(inp);
2891 hmaclist = inp->sctp_ep.local_hmacs;
2892 if (hmaclist == NULL) {
2893 /* no HMACs to return */
2894 *optsize = sizeof(*shmac);
2895 SCTP_INP_RUNLOCK(inp);
2898 /* is there room for all of the hmac ids? */
2899 size = sizeof(*shmac) + (hmaclist->num_algo *
2900 sizeof(shmac->shmac_idents[0]));
2901 if ((size_t)(*optsize) < size) {
2902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2904 SCTP_INP_RUNLOCK(inp);
2907 /* copy in the list */
2908 shmac->shmac_number_of_idents = hmaclist->num_algo;
2909 for (i = 0; i < hmaclist->num_algo; i++) {
2910 shmac->shmac_idents[i] = hmaclist->hmac[i];
2912 SCTP_INP_RUNLOCK(inp);
2916 case SCTP_AUTH_ACTIVE_KEY:
2918 struct sctp_authkeyid *scact;
2920 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2921 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2924 /* get the active key on the assoc */
2925 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2926 SCTP_TCB_UNLOCK(stcb);
2928 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2929 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2930 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2931 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC))) {
2932 /* get the endpoint active key */
2933 SCTP_INP_RLOCK(inp);
2934 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2935 SCTP_INP_RUNLOCK(inp);
2937 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2942 *optsize = sizeof(struct sctp_authkeyid);
2946 case SCTP_LOCAL_AUTH_CHUNKS:
2948 struct sctp_authchunks *sac;
2949 sctp_auth_chklist_t *chklist = NULL;
2952 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2953 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2956 /* get off the assoc */
2957 chklist = stcb->asoc.local_auth_chunks;
2958 /* is there enough space? */
2959 size = sctp_auth_get_chklist_size(chklist);
2960 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2962 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2964 /* copy in the chunks */
2965 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2966 sac->gauth_number_of_chunks = (uint32_t)size;
2967 *optsize = sizeof(struct sctp_authchunks) + size;
2969 SCTP_TCB_UNLOCK(stcb);
2971 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2972 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2973 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2974 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC))) {
2975 /* get off the endpoint */
2976 SCTP_INP_RLOCK(inp);
2977 chklist = inp->sctp_ep.local_auth_chunks;
2978 /* is there enough space? */
2979 size = sctp_auth_get_chklist_size(chklist);
2980 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2984 /* copy in the chunks */
2985 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2986 sac->gauth_number_of_chunks = (uint32_t)size;
2987 *optsize = sizeof(struct sctp_authchunks) + size;
2989 SCTP_INP_RUNLOCK(inp);
2991 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2997 case SCTP_PEER_AUTH_CHUNKS:
2999 struct sctp_authchunks *sac;
3000 sctp_auth_chklist_t *chklist = NULL;
3003 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
3004 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
3007 /* get off the assoc */
3008 chklist = stcb->asoc.peer_auth_chunks;
3009 /* is there enough space? */
3010 size = sctp_auth_get_chklist_size(chklist);
3011 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
3013 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3015 /* copy in the chunks */
3016 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3017 sac->gauth_number_of_chunks = (uint32_t)size;
3018 *optsize = sizeof(struct sctp_authchunks) + size;
3020 SCTP_TCB_UNLOCK(stcb);
3022 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3029 struct sctp_event *event;
3030 uint32_t event_type;
3032 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3033 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3035 switch (event->se_type) {
3036 case SCTP_ASSOC_CHANGE:
3037 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3039 case SCTP_PEER_ADDR_CHANGE:
3040 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3042 case SCTP_REMOTE_ERROR:
3043 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3045 case SCTP_SEND_FAILED:
3046 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3048 case SCTP_SHUTDOWN_EVENT:
3049 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3051 case SCTP_ADAPTATION_INDICATION:
3052 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3054 case SCTP_PARTIAL_DELIVERY_EVENT:
3055 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3057 case SCTP_AUTHENTICATION_EVENT:
3058 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3060 case SCTP_STREAM_RESET_EVENT:
3061 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3063 case SCTP_SENDER_DRY_EVENT:
3064 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3066 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3068 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3071 case SCTP_ASSOC_RESET_EVENT:
3072 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3074 case SCTP_STREAM_CHANGE_EVENT:
3075 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3077 case SCTP_SEND_FAILED_EVENT:
3078 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3082 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3086 if (event_type > 0) {
3088 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3090 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3091 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3092 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3093 (event->se_assoc_id == SCTP_FUTURE_ASSOC))) {
3094 SCTP_INP_RLOCK(inp);
3095 event->se_on = sctp_is_feature_on(inp, event_type);
3096 SCTP_INP_RUNLOCK(inp);
3098 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3104 SCTP_TCB_UNLOCK(stcb);
3107 *optsize = sizeof(struct sctp_event);
3111 case SCTP_RECVRCVINFO:
3115 if (*optsize < sizeof(int)) {
3116 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3119 SCTP_INP_RLOCK(inp);
3120 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3121 SCTP_INP_RUNLOCK(inp);
3124 /* return the option value */
3125 *(int *)optval = onoff;
3126 *optsize = sizeof(int);
3130 case SCTP_RECVNXTINFO:
3134 if (*optsize < sizeof(int)) {
3135 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3138 SCTP_INP_RLOCK(inp);
3139 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3140 SCTP_INP_RUNLOCK(inp);
3143 /* return the option value */
3144 *(int *)optval = onoff;
3145 *optsize = sizeof(int);
3149 case SCTP_DEFAULT_SNDINFO:
3151 struct sctp_sndinfo *info;
3153 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3154 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3157 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3158 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3159 info->snd_flags &= 0xfff0;
3160 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3161 info->snd_context = stcb->asoc.def_send.sinfo_context;
3162 SCTP_TCB_UNLOCK(stcb);
3164 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3165 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3166 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3167 (info->snd_assoc_id == SCTP_FUTURE_ASSOC))) {
3168 SCTP_INP_RLOCK(inp);
3169 info->snd_sid = inp->def_send.sinfo_stream;
3170 info->snd_flags = inp->def_send.sinfo_flags;
3171 info->snd_flags &= 0xfff0;
3172 info->snd_ppid = inp->def_send.sinfo_ppid;
3173 info->snd_context = inp->def_send.sinfo_context;
3174 SCTP_INP_RUNLOCK(inp);
3176 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3181 *optsize = sizeof(struct sctp_sndinfo);
3185 case SCTP_DEFAULT_PRINFO:
3187 struct sctp_default_prinfo *info;
3189 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3190 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3193 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3194 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3195 SCTP_TCB_UNLOCK(stcb);
3197 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3198 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3199 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3200 (info->pr_assoc_id == SCTP_FUTURE_ASSOC))) {
3201 SCTP_INP_RLOCK(inp);
3202 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3203 info->pr_value = inp->def_send.sinfo_timetolive;
3204 SCTP_INP_RUNLOCK(inp);
3206 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3211 *optsize = sizeof(struct sctp_default_prinfo);
3215 case SCTP_PEER_ADDR_THLDS:
3217 struct sctp_paddrthlds *thlds;
3218 struct sctp_nets *net;
3219 struct sockaddr *addr;
3220 #if defined(INET) && defined(INET6)
3221 struct sockaddr_in sin_store;
3224 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3225 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3227 #if defined(INET) && defined(INET6)
3228 if (thlds->spt_address.ss_family == AF_INET6) {
3229 struct sockaddr_in6 *sin6;
3231 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3232 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3233 in6_sin6_2_sin(&sin_store, sin6);
3234 addr = (struct sockaddr *)&sin_store;
3236 addr = (struct sockaddr *)&thlds->spt_address;
3239 addr = (struct sockaddr *)&thlds->spt_address;
3242 addr = (struct sockaddr *)&thlds->spt_address;
3245 net = sctp_findnet(stcb, addr);
3248 * We increment here since
3249 * sctp_findassociation_ep_addr() wil do a
3250 * decrement if it finds the stcb as long as
3251 * the locked tcb (last argument) is NOT a
3255 SCTP_INP_INCR_REF(inp);
3256 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3258 SCTP_INP_DECR_REF(inp);
3261 if ((stcb != NULL) && (net == NULL)) {
3263 if (addr->sa_family == AF_INET) {
3264 struct sockaddr_in *sin;
3266 sin = (struct sockaddr_in *)addr;
3267 if (sin->sin_addr.s_addr != INADDR_ANY) {
3269 SCTP_TCB_UNLOCK(stcb);
3270 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3276 if (addr->sa_family == AF_INET6) {
3277 struct sockaddr_in6 *sin6;
3279 sin6 = (struct sockaddr_in6 *)addr;
3280 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3282 SCTP_TCB_UNLOCK(stcb);
3283 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3289 error = EAFNOSUPPORT;
3290 SCTP_TCB_UNLOCK(stcb);
3291 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3298 thlds->spt_pathmaxrxt = net->failure_threshold;
3299 thlds->spt_pathpfthld = net->pf_threshold;
3300 thlds->spt_pathcpthld = 0xffff;
3302 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3303 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3304 thlds->spt_pathcpthld = 0xffff;
3306 thlds->spt_assoc_id = sctp_get_associd(stcb);
3307 SCTP_TCB_UNLOCK(stcb);
3309 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3310 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3311 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3312 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
3313 /* Use endpoint defaults */
3314 SCTP_INP_RLOCK(inp);
3315 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3316 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3317 thlds->spt_pathcpthld = 0xffff;
3318 SCTP_INP_RUNLOCK(inp);
3320 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3325 *optsize = sizeof(struct sctp_paddrthlds);
3329 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3331 struct sctp_udpencaps *encaps;
3332 struct sctp_nets *net;
3333 struct sockaddr *addr;
3334 #if defined(INET) && defined(INET6)
3335 struct sockaddr_in sin_store;
3338 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3339 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3341 #if defined(INET) && defined(INET6)
3342 if (encaps->sue_address.ss_family == AF_INET6) {
3343 struct sockaddr_in6 *sin6;
3345 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3346 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3347 in6_sin6_2_sin(&sin_store, sin6);
3348 addr = (struct sockaddr *)&sin_store;
3350 addr = (struct sockaddr *)&encaps->sue_address;
3353 addr = (struct sockaddr *)&encaps->sue_address;
3356 addr = (struct sockaddr *)&encaps->sue_address;
3359 net = sctp_findnet(stcb, addr);
3362 * We increment here since
3363 * sctp_findassociation_ep_addr() wil do a
3364 * decrement if it finds the stcb as long as
3365 * the locked tcb (last argument) is NOT a
3369 SCTP_INP_INCR_REF(inp);
3370 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3372 SCTP_INP_DECR_REF(inp);
3375 if ((stcb != NULL) && (net == NULL)) {
3377 if (addr->sa_family == AF_INET) {
3378 struct sockaddr_in *sin;
3380 sin = (struct sockaddr_in *)addr;
3381 if (sin->sin_addr.s_addr != INADDR_ANY) {
3383 SCTP_TCB_UNLOCK(stcb);
3384 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3390 if (addr->sa_family == AF_INET6) {
3391 struct sockaddr_in6 *sin6;
3393 sin6 = (struct sockaddr_in6 *)addr;
3394 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3396 SCTP_TCB_UNLOCK(stcb);
3397 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3403 error = EAFNOSUPPORT;
3404 SCTP_TCB_UNLOCK(stcb);
3405 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3412 encaps->sue_port = net->port;
3414 encaps->sue_port = stcb->asoc.port;
3416 SCTP_TCB_UNLOCK(stcb);
3418 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3419 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3420 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3421 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
3422 SCTP_INP_RLOCK(inp);
3423 encaps->sue_port = inp->sctp_ep.port;
3424 SCTP_INP_RUNLOCK(inp);
3426 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3431 *optsize = sizeof(struct sctp_udpencaps);
3435 case SCTP_ECN_SUPPORTED:
3437 struct sctp_assoc_value *av;
3439 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3440 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3443 av->assoc_value = stcb->asoc.ecn_supported;
3444 SCTP_TCB_UNLOCK(stcb);
3446 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3447 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3448 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3449 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3450 SCTP_INP_RLOCK(inp);
3451 av->assoc_value = inp->ecn_supported;
3452 SCTP_INP_RUNLOCK(inp);
3454 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3459 *optsize = sizeof(struct sctp_assoc_value);
3463 case SCTP_PR_SUPPORTED:
3465 struct sctp_assoc_value *av;
3467 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3468 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3471 av->assoc_value = stcb->asoc.prsctp_supported;
3472 SCTP_TCB_UNLOCK(stcb);
3474 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3475 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3476 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3477 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3478 SCTP_INP_RLOCK(inp);
3479 av->assoc_value = inp->prsctp_supported;
3480 SCTP_INP_RUNLOCK(inp);
3482 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3487 *optsize = sizeof(struct sctp_assoc_value);
3491 case SCTP_AUTH_SUPPORTED:
3493 struct sctp_assoc_value *av;
3495 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3496 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3499 av->assoc_value = stcb->asoc.auth_supported;
3500 SCTP_TCB_UNLOCK(stcb);
3502 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3503 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3504 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3505 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3506 SCTP_INP_RLOCK(inp);
3507 av->assoc_value = inp->auth_supported;
3508 SCTP_INP_RUNLOCK(inp);
3510 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3515 *optsize = sizeof(struct sctp_assoc_value);
3519 case SCTP_ASCONF_SUPPORTED:
3521 struct sctp_assoc_value *av;
3523 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3524 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3527 av->assoc_value = stcb->asoc.asconf_supported;
3528 SCTP_TCB_UNLOCK(stcb);
3530 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3531 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3532 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3533 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3534 SCTP_INP_RLOCK(inp);
3535 av->assoc_value = inp->asconf_supported;
3536 SCTP_INP_RUNLOCK(inp);
3538 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3543 *optsize = sizeof(struct sctp_assoc_value);
3547 case SCTP_RECONFIG_SUPPORTED:
3549 struct sctp_assoc_value *av;
3551 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3552 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3555 av->assoc_value = stcb->asoc.reconfig_supported;
3556 SCTP_TCB_UNLOCK(stcb);
3558 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3559 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3560 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3561 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3562 SCTP_INP_RLOCK(inp);
3563 av->assoc_value = inp->reconfig_supported;
3564 SCTP_INP_RUNLOCK(inp);
3566 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3571 *optsize = sizeof(struct sctp_assoc_value);
3575 case SCTP_NRSACK_SUPPORTED:
3577 struct sctp_assoc_value *av;
3579 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3580 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3583 av->assoc_value = stcb->asoc.nrsack_supported;
3584 SCTP_TCB_UNLOCK(stcb);
3586 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3587 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3588 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3589 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3590 SCTP_INP_RLOCK(inp);
3591 av->assoc_value = inp->nrsack_supported;
3592 SCTP_INP_RUNLOCK(inp);
3594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3599 *optsize = sizeof(struct sctp_assoc_value);
3603 case SCTP_PKTDROP_SUPPORTED:
3605 struct sctp_assoc_value *av;
3607 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3608 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3611 av->assoc_value = stcb->asoc.pktdrop_supported;
3612 SCTP_TCB_UNLOCK(stcb);
3614 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3615 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3616 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3617 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3618 SCTP_INP_RLOCK(inp);
3619 av->assoc_value = inp->pktdrop_supported;
3620 SCTP_INP_RUNLOCK(inp);
3622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3627 *optsize = sizeof(struct sctp_assoc_value);
3631 case SCTP_ENABLE_STREAM_RESET:
3633 struct sctp_assoc_value *av;
3635 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3636 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3639 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3640 SCTP_TCB_UNLOCK(stcb);
3642 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3643 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3644 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3645 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3646 SCTP_INP_RLOCK(inp);
3647 av->assoc_value = (uint32_t)inp->local_strreset_support;
3648 SCTP_INP_RUNLOCK(inp);
3650 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3655 *optsize = sizeof(struct sctp_assoc_value);
3659 case SCTP_PR_STREAM_STATUS:
3661 struct sctp_prstatus *sprstat;
3665 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3666 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3668 sid = sprstat->sprstat_sid;
3669 policy = sprstat->sprstat_policy;
3670 #if defined(SCTP_DETAILED_STR_STATS)
3671 if ((stcb != NULL) &&
3672 (sid < stcb->asoc.streamoutcnt) &&
3673 (policy != SCTP_PR_SCTP_NONE) &&
3674 ((policy <= SCTP_PR_SCTP_MAX) ||
3675 (policy == SCTP_PR_SCTP_ALL))) {
3676 if (policy == SCTP_PR_SCTP_ALL) {
3677 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3678 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3680 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3681 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3684 if ((stcb != NULL) &&
3685 (sid < stcb->asoc.streamoutcnt) &&
3686 (policy == SCTP_PR_SCTP_ALL)) {
3687 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3688 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3695 SCTP_TCB_UNLOCK(stcb);
3698 *optsize = sizeof(struct sctp_prstatus);
3702 case SCTP_PR_ASSOC_STATUS:
3704 struct sctp_prstatus *sprstat;
3707 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3708 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3710 policy = sprstat->sprstat_policy;
3711 if ((stcb != NULL) &&
3712 (policy != SCTP_PR_SCTP_NONE) &&
3713 ((policy <= SCTP_PR_SCTP_MAX) ||
3714 (policy == SCTP_PR_SCTP_ALL))) {
3715 if (policy == SCTP_PR_SCTP_ALL) {
3716 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3717 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3719 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3720 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3727 SCTP_TCB_UNLOCK(stcb);
3730 *optsize = sizeof(struct sctp_prstatus);
3736 struct sctp_assoc_value *av;
3738 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3739 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3742 av->assoc_value = stcb->asoc.max_cwnd;
3743 SCTP_TCB_UNLOCK(stcb);
3745 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3746 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3747 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3748 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3749 SCTP_INP_RLOCK(inp);
3750 av->assoc_value = inp->max_cwnd;
3751 SCTP_INP_RUNLOCK(inp);
3753 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3758 *optsize = sizeof(struct sctp_assoc_value);
3763 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3764 error = ENOPROTOOPT;
3766 } /* end switch (sopt->sopt_name) */
3774 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3779 struct sctp_tcb *stcb = NULL;
3780 struct sctp_inpcb *inp = NULL;
3783 if (optval == NULL) {
3784 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3787 inp = (struct sctp_inpcb *)so->so_pcb;
3789 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3792 vrf_id = inp->def_vrf_id;
3797 case SCTP_AUTOCLOSE:
3798 case SCTP_AUTO_ASCONF:
3799 case SCTP_EXPLICIT_EOR:
3800 case SCTP_DISABLE_FRAGMENTS:
3801 case SCTP_USE_EXT_RCVINFO:
3802 case SCTP_I_WANT_MAPPED_V4_ADDR:
3803 /* copy in the option value */
3804 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3809 case SCTP_DISABLE_FRAGMENTS:
3810 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3812 case SCTP_AUTO_ASCONF:
3814 * NOTE: we don't really support this flag
3816 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3817 /* only valid for bound all sockets */
3818 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3820 /* forbidden by admin */
3821 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3824 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3826 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3830 case SCTP_EXPLICIT_EOR:
3831 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3833 case SCTP_USE_EXT_RCVINFO:
3834 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3836 case SCTP_I_WANT_MAPPED_V4_ADDR:
3837 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3838 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3840 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3845 set_opt = SCTP_PCB_FLAGS_NODELAY;
3847 case SCTP_AUTOCLOSE:
3848 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3849 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3850 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3853 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3855 * The value is in ticks. Note this does not effect
3856 * old associations, only new ones.
3858 inp->sctp_ep.auto_close_time = sctp_secs_to_ticks(*mopt);
3861 SCTP_INP_WLOCK(inp);
3863 sctp_feature_on(inp, set_opt);
3865 sctp_feature_off(inp, set_opt);
3867 SCTP_INP_WUNLOCK(inp);
3869 case SCTP_REUSE_PORT:
3871 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3872 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3873 /* Can't set it after we are bound */
3877 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3878 /* Can't do this for a 1-m socket */
3883 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3885 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3888 case SCTP_PARTIAL_DELIVERY_POINT:
3892 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3893 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3894 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3898 inp->partial_delivery_point = *value;
3901 case SCTP_FRAGMENT_INTERLEAVE:
3902 /* not yet until we re-write sctp_recvmsg() */
3906 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3907 if (*level == SCTP_FRAG_LEVEL_2) {
3908 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3909 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3910 } else if (*level == SCTP_FRAG_LEVEL_1) {
3911 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3912 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3913 } else if (*level == SCTP_FRAG_LEVEL_0) {
3914 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3915 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3918 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3923 case SCTP_INTERLEAVING_SUPPORTED:
3925 struct sctp_assoc_value *av;
3927 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3928 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3931 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3933 SCTP_TCB_UNLOCK(stcb);
3935 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3936 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3937 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3938 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3939 SCTP_INP_WLOCK(inp);
3940 if (av->assoc_value == 0) {
3941 inp->idata_supported = 0;
3943 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3944 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3945 inp->idata_supported = 1;
3953 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3957 SCTP_INP_WUNLOCK(inp);
3959 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3965 case SCTP_CMT_ON_OFF:
3966 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3967 struct sctp_assoc_value *av;
3969 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3970 if (av->assoc_value > SCTP_CMT_MAX) {
3971 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3975 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3977 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3978 SCTP_TCB_UNLOCK(stcb);
3980 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3981 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3982 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3983 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3984 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3985 SCTP_INP_WLOCK(inp);
3986 inp->sctp_cmt_on_off = av->assoc_value;
3987 SCTP_INP_WUNLOCK(inp);
3989 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3990 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3991 (av->assoc_id == SCTP_ALL_ASSOC))) {
3992 SCTP_INP_RLOCK(inp);
3993 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3994 SCTP_TCB_LOCK(stcb);
3995 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3996 SCTP_TCB_UNLOCK(stcb);
3998 SCTP_INP_RUNLOCK(inp);
4002 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
4003 error = ENOPROTOOPT;
4006 case SCTP_PLUGGABLE_CC:
4008 struct sctp_assoc_value *av;
4009 struct sctp_nets *net;
4011 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4012 if ((av->assoc_value != SCTP_CC_RFC2581) &&
4013 (av->assoc_value != SCTP_CC_HSTCP) &&
4014 (av->assoc_value != SCTP_CC_HTCP) &&
4015 (av->assoc_value != SCTP_CC_RTCC)) {
4016 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4020 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4022 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4023 stcb->asoc.congestion_control_module = av->assoc_value;
4024 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4025 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4026 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4029 SCTP_TCB_UNLOCK(stcb);
4031 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4032 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4033 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4034 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4035 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4036 SCTP_INP_WLOCK(inp);
4037 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
4038 SCTP_INP_WUNLOCK(inp);
4040 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4041 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4042 (av->assoc_id == SCTP_ALL_ASSOC))) {
4043 SCTP_INP_RLOCK(inp);
4044 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4045 SCTP_TCB_LOCK(stcb);
4046 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4047 stcb->asoc.congestion_control_module = av->assoc_value;
4048 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4049 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4050 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4053 SCTP_TCB_UNLOCK(stcb);
4055 SCTP_INP_RUNLOCK(inp);
4060 case SCTP_CC_OPTION:
4062 struct sctp_cc_option *cc_opt;
4064 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4065 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4067 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4068 (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC)) {
4069 SCTP_INP_RLOCK(inp);
4070 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4071 SCTP_TCB_LOCK(stcb);
4072 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4073 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4075 SCTP_TCB_UNLOCK(stcb);
4077 SCTP_INP_RUNLOCK(inp);
4082 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4085 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4088 SCTP_TCB_UNLOCK(stcb);
4092 case SCTP_PLUGGABLE_SS:
4094 struct sctp_assoc_value *av;
4096 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4097 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4098 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4099 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4100 (av->assoc_value != SCTP_SS_PRIORITY) &&
4101 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4102 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4103 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4107 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4109 SCTP_TCB_SEND_LOCK(stcb);
4110 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4111 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4112 stcb->asoc.stream_scheduling_module = av->assoc_value;
4113 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4114 SCTP_TCB_SEND_UNLOCK(stcb);
4115 SCTP_TCB_UNLOCK(stcb);
4117 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4118 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4119 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4120 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4121 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4122 SCTP_INP_WLOCK(inp);
4123 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4124 SCTP_INP_WUNLOCK(inp);
4126 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4127 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4128 (av->assoc_id == SCTP_ALL_ASSOC))) {
4129 SCTP_INP_RLOCK(inp);
4130 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4131 SCTP_TCB_LOCK(stcb);
4132 SCTP_TCB_SEND_LOCK(stcb);
4133 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4134 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4135 stcb->asoc.stream_scheduling_module = av->assoc_value;
4136 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4137 SCTP_TCB_SEND_UNLOCK(stcb);
4138 SCTP_TCB_UNLOCK(stcb);
4140 SCTP_INP_RUNLOCK(inp);
4147 struct sctp_stream_value *av;
4149 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4150 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4152 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4153 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4154 av->stream_value) < 0)) {
4155 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4158 SCTP_TCB_UNLOCK(stcb);
4160 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4161 (av->assoc_id == SCTP_CURRENT_ASSOC)) {
4162 SCTP_INP_RLOCK(inp);
4163 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4164 SCTP_TCB_LOCK(stcb);
4165 if (av->stream_id < stcb->asoc.streamoutcnt) {
4166 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4168 &stcb->asoc.strmout[av->stream_id],
4171 SCTP_TCB_UNLOCK(stcb);
4173 SCTP_INP_RUNLOCK(inp);
4176 * Can't set stream value without
4179 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4185 case SCTP_CLR_STAT_LOG:
4186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4191 struct sctp_assoc_value *av;
4193 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4194 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4197 stcb->asoc.context = av->assoc_value;
4198 SCTP_TCB_UNLOCK(stcb);
4200 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4201 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4202 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4203 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4204 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4205 SCTP_INP_WLOCK(inp);
4206 inp->sctp_context = av->assoc_value;
4207 SCTP_INP_WUNLOCK(inp);
4209 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4210 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4211 (av->assoc_id == SCTP_ALL_ASSOC))) {
4212 SCTP_INP_RLOCK(inp);
4213 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4214 SCTP_TCB_LOCK(stcb);
4215 stcb->asoc.context = av->assoc_value;
4216 SCTP_TCB_UNLOCK(stcb);
4218 SCTP_INP_RUNLOCK(inp);
4225 uint32_t *default_vrfid;
4227 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4228 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4229 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4233 inp->def_vrf_id = *default_vrfid;
4236 case SCTP_DEL_VRF_ID:
4238 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4242 case SCTP_ADD_VRF_ID:
4244 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4248 case SCTP_DELAYED_SACK:
4250 struct sctp_sack_info *sack;
4252 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4253 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4254 if (sack->sack_delay) {
4255 if (sack->sack_delay > SCTP_MAX_SACK_DELAY) {
4258 SCTP_TCB_UNLOCK(stcb);
4264 if (sack->sack_delay) {
4265 stcb->asoc.delayed_ack = sack->sack_delay;
4267 if (sack->sack_freq) {
4268 stcb->asoc.sack_freq = sack->sack_freq;
4270 SCTP_TCB_UNLOCK(stcb);
4272 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4273 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4274 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4275 ((sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4276 (sack->sack_assoc_id == SCTP_ALL_ASSOC)))) {
4277 SCTP_INP_WLOCK(inp);
4278 if (sack->sack_delay) {
4279 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = sctp_msecs_to_ticks(sack->sack_delay);
4281 if (sack->sack_freq) {
4282 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4284 SCTP_INP_WUNLOCK(inp);
4286 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4287 ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4288 (sack->sack_assoc_id == SCTP_ALL_ASSOC))) {
4289 SCTP_INP_RLOCK(inp);
4290 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4291 SCTP_TCB_LOCK(stcb);
4292 if (sack->sack_delay) {
4293 stcb->asoc.delayed_ack = sack->sack_delay;
4295 if (sack->sack_freq) {
4296 stcb->asoc.sack_freq = sack->sack_freq;
4298 SCTP_TCB_UNLOCK(stcb);
4300 SCTP_INP_RUNLOCK(inp);
4305 case SCTP_AUTH_CHUNK:
4307 struct sctp_authchunk *sauth;
4309 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4311 SCTP_INP_WLOCK(inp);
4312 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4313 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4316 inp->auth_supported = 1;
4318 SCTP_INP_WUNLOCK(inp);
4323 struct sctp_authkey *sca;
4324 struct sctp_keyhead *shared_keys;
4325 sctp_sharedkey_t *shared_key;
4326 sctp_key_t *key = NULL;
4329 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4330 if (sca->sca_keylength == 0) {
4331 size = optsize - sizeof(struct sctp_authkey);
4333 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4334 size = sca->sca_keylength;
4336 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4341 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4344 shared_keys = &stcb->asoc.shared_keys;
4345 /* clear the cached keys for this key id */
4346 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4348 * create the new shared key and
4352 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4354 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4356 SCTP_TCB_UNLOCK(stcb);
4360 shared_key = sctp_alloc_sharedkey();
4361 if (shared_key == NULL) {
4363 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4365 SCTP_TCB_UNLOCK(stcb);
4368 shared_key->key = key;
4369 shared_key->keyid = sca->sca_keynumber;
4370 error = sctp_insert_sharedkey(shared_keys, shared_key);
4371 SCTP_TCB_UNLOCK(stcb);
4373 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4374 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4375 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4376 ((sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4377 (sca->sca_assoc_id == SCTP_ALL_ASSOC)))) {
4378 SCTP_INP_WLOCK(inp);
4379 shared_keys = &inp->sctp_ep.shared_keys;
4381 * clear the cached keys on all
4382 * assocs for this key id
4384 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4386 * create the new shared key and
4390 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4392 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4394 SCTP_INP_WUNLOCK(inp);
4398 shared_key = sctp_alloc_sharedkey();
4399 if (shared_key == NULL) {
4401 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4403 SCTP_INP_WUNLOCK(inp);
4406 shared_key->key = key;
4407 shared_key->keyid = sca->sca_keynumber;
4408 error = sctp_insert_sharedkey(shared_keys, shared_key);
4409 SCTP_INP_WUNLOCK(inp);
4411 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4412 ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4413 (sca->sca_assoc_id == SCTP_ALL_ASSOC))) {
4414 SCTP_INP_RLOCK(inp);
4415 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4416 SCTP_TCB_LOCK(stcb);
4417 shared_keys = &stcb->asoc.shared_keys;
4419 * clear the cached keys for
4422 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4424 * create the new shared key
4425 * and insert/replace it
4428 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4430 SCTP_TCB_UNLOCK(stcb);
4434 shared_key = sctp_alloc_sharedkey();
4435 if (shared_key == NULL) {
4437 SCTP_TCB_UNLOCK(stcb);
4440 shared_key->key = key;
4441 shared_key->keyid = sca->sca_keynumber;
4442 error = sctp_insert_sharedkey(shared_keys, shared_key);
4443 SCTP_TCB_UNLOCK(stcb);
4445 SCTP_INP_RUNLOCK(inp);
4450 case SCTP_HMAC_IDENT:
4452 struct sctp_hmacalgo *shmac;
4453 sctp_hmaclist_t *hmaclist;
4457 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4458 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4459 (shmac->shmac_number_of_idents > 0xffff)) {
4460 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4465 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4466 if (hmaclist == NULL) {
4467 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4471 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4472 hmacid = shmac->shmac_idents[i];
4473 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4474 /* invalid HMACs were found */ ;
4475 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4477 sctp_free_hmaclist(hmaclist);
4478 goto sctp_set_hmac_done;
4481 for (i = 0; i < hmaclist->num_algo; i++) {
4482 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4483 /* already in list */
4487 if (i == hmaclist->num_algo) {
4488 /* not found in list */
4489 sctp_free_hmaclist(hmaclist);
4490 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4494 /* set it on the endpoint */
4495 SCTP_INP_WLOCK(inp);
4496 if (inp->sctp_ep.local_hmacs)
4497 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4498 inp->sctp_ep.local_hmacs = hmaclist;
4499 SCTP_INP_WUNLOCK(inp);
4503 case SCTP_AUTH_ACTIVE_KEY:
4505 struct sctp_authkeyid *scact;
4507 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4508 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4510 /* set the active key on the right place */
4512 /* set the active key on the assoc */
4513 if (sctp_auth_setactivekey(stcb,
4514 scact->scact_keynumber)) {
4515 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4516 SCTP_FROM_SCTP_USRREQ,
4520 SCTP_TCB_UNLOCK(stcb);
4522 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4523 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4524 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4525 ((scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4526 (scact->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4527 SCTP_INP_WLOCK(inp);
4528 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4529 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4532 SCTP_INP_WUNLOCK(inp);
4534 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4535 ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4536 (scact->scact_assoc_id == SCTP_ALL_ASSOC))) {
4537 SCTP_INP_RLOCK(inp);
4538 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4539 SCTP_TCB_LOCK(stcb);
4540 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4541 SCTP_TCB_UNLOCK(stcb);
4543 SCTP_INP_RUNLOCK(inp);
4548 case SCTP_AUTH_DELETE_KEY:
4550 struct sctp_authkeyid *scdel;
4552 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4553 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4555 /* delete the key from the right place */
4557 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4558 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4561 SCTP_TCB_UNLOCK(stcb);
4563 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4564 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4565 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4566 ((scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4567 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4568 SCTP_INP_WLOCK(inp);
4569 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4570 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4573 SCTP_INP_WUNLOCK(inp);
4575 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4576 ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4577 (scdel->scact_assoc_id == SCTP_ALL_ASSOC))) {
4578 SCTP_INP_RLOCK(inp);
4579 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4580 SCTP_TCB_LOCK(stcb);
4581 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4582 SCTP_TCB_UNLOCK(stcb);
4584 SCTP_INP_RUNLOCK(inp);
4589 case SCTP_AUTH_DEACTIVATE_KEY:
4591 struct sctp_authkeyid *keyid;
4593 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4594 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4596 /* deactivate the key from the right place */
4598 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4599 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4602 SCTP_TCB_UNLOCK(stcb);
4604 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4605 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4606 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4607 ((keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4608 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4609 SCTP_INP_WLOCK(inp);
4610 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4611 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4614 SCTP_INP_WUNLOCK(inp);
4616 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4617 ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4618 (keyid->scact_assoc_id == SCTP_ALL_ASSOC))) {
4619 SCTP_INP_RLOCK(inp);
4620 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4621 SCTP_TCB_LOCK(stcb);
4622 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4623 SCTP_TCB_UNLOCK(stcb);
4625 SCTP_INP_RUNLOCK(inp);
4630 case SCTP_ENABLE_STREAM_RESET:
4632 struct sctp_assoc_value *av;
4634 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4635 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4636 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4640 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4642 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4643 SCTP_TCB_UNLOCK(stcb);
4645 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4646 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4647 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4648 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4649 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4650 SCTP_INP_WLOCK(inp);
4651 inp->local_strreset_support = (uint8_t)av->assoc_value;
4652 SCTP_INP_WUNLOCK(inp);
4654 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4655 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4656 (av->assoc_id == SCTP_ALL_ASSOC))) {
4657 SCTP_INP_RLOCK(inp);
4658 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4659 SCTP_TCB_LOCK(stcb);
4660 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4661 SCTP_TCB_UNLOCK(stcb);
4663 SCTP_INP_RUNLOCK(inp);
4669 case SCTP_RESET_STREAMS:
4671 struct sctp_reset_streams *strrst;
4672 int i, send_out = 0;
4675 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4676 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4678 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4682 if (stcb->asoc.reconfig_supported == 0) {
4684 * Peer does not support the chunk type.
4686 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4688 SCTP_TCB_UNLOCK(stcb);
4691 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4694 SCTP_TCB_UNLOCK(stcb);
4697 if (sizeof(struct sctp_reset_streams) +
4698 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4700 SCTP_TCB_UNLOCK(stcb);
4703 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4705 if (stcb->asoc.stream_reset_outstanding) {
4706 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4708 SCTP_TCB_UNLOCK(stcb);
4712 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4715 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4716 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4718 SCTP_TCB_UNLOCK(stcb);
4721 if ((send_in == 0) && (send_out == 0)) {
4722 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4724 SCTP_TCB_UNLOCK(stcb);
4727 for (i = 0; i < strrst->srs_number_streams; i++) {
4729 (strrst->srs_stream_list[i] >= stcb->asoc.streamincnt)) {
4730 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4735 (strrst->srs_stream_list[i] >= stcb->asoc.streamoutcnt)) {
4736 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4742 SCTP_TCB_UNLOCK(stcb);
4749 if (strrst->srs_number_streams) {
4750 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4751 strm = strrst->srs_stream_list[i];
4752 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4753 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4759 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4760 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4761 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4768 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4769 strrst->srs_stream_list,
4770 send_in, 0, 0, 0, 0, 0);
4772 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4775 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4778 * For outgoing streams don't report any
4779 * problems in sending the request to the
4780 * application. XXX: Double check resetting
4785 SCTP_TCB_UNLOCK(stcb);
4788 case SCTP_ADD_STREAMS:
4790 struct sctp_add_streams *stradd;
4791 uint8_t addstream = 0;
4792 uint16_t add_o_strmcnt = 0;
4793 uint16_t add_i_strmcnt = 0;
4795 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4796 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4798 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4802 if (stcb->asoc.reconfig_supported == 0) {
4804 * Peer does not support the chunk type.
4806 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4808 SCTP_TCB_UNLOCK(stcb);
4811 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4812 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4814 SCTP_TCB_UNLOCK(stcb);
4817 if (stcb->asoc.stream_reset_outstanding) {
4818 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4820 SCTP_TCB_UNLOCK(stcb);
4823 if ((stradd->sas_outstrms == 0) &&
4824 (stradd->sas_instrms == 0)) {
4828 if (stradd->sas_outstrms) {
4830 /* We allocate here */
4831 add_o_strmcnt = stradd->sas_outstrms;
4832 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4833 /* You can't have more than 64k */
4838 if (stradd->sas_instrms) {
4843 * We allocate inside
4844 * sctp_send_str_reset_req()
4846 add_i_strmcnt = stradd->sas_instrms;
4847 cnt = add_i_strmcnt;
4848 cnt += stcb->asoc.streamincnt;
4849 if (cnt > 0x0000ffff) {
4850 /* You can't have more than 64k */
4854 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4855 /* More than you are allowed */
4860 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4861 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4863 SCTP_TCB_UNLOCK(stcb);
4866 case SCTP_RESET_ASSOC:
4871 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4872 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4874 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4878 if (stcb->asoc.reconfig_supported == 0) {
4880 * Peer does not support the chunk type.
4882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4884 SCTP_TCB_UNLOCK(stcb);
4887 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4888 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4890 SCTP_TCB_UNLOCK(stcb);
4893 if (stcb->asoc.stream_reset_outstanding) {
4894 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4896 SCTP_TCB_UNLOCK(stcb);
4900 * Is there any data pending in the send or sent
4903 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4904 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4907 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4908 SCTP_TCB_UNLOCK(stcb);
4911 /* Do any streams have data queued? */
4912 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4913 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4917 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4918 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4919 SCTP_TCB_UNLOCK(stcb);
4922 case SCTP_CONNECT_X:
4923 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4928 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4930 case SCTP_CONNECT_X_DELAYED:
4931 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4932 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4936 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4938 case SCTP_CONNECT_X_COMPLETE:
4940 struct sockaddr *sa;
4942 /* FIXME MT: check correct? */
4943 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4946 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4947 SCTP_INP_RLOCK(inp);
4948 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4950 SCTP_TCB_LOCK(stcb);
4952 SCTP_INP_RUNLOCK(inp);
4955 * We increment here since
4956 * sctp_findassociation_ep_addr() wil do a
4957 * decrement if it finds the stcb as long as
4958 * the locked tcb (last argument) is NOT a
4961 SCTP_INP_INCR_REF(inp);
4962 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4964 SCTP_INP_DECR_REF(inp);
4969 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4973 if (stcb->asoc.delayed_connection == 1) {
4974 stcb->asoc.delayed_connection = 0;
4975 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4976 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4977 stcb->asoc.primary_destination,
4978 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4979 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4982 * already expired or did not use delayed
4985 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4988 SCTP_TCB_UNLOCK(stcb);
4991 case SCTP_MAX_BURST:
4993 struct sctp_assoc_value *av;
4995 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4996 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4999 stcb->asoc.max_burst = av->assoc_value;
5000 SCTP_TCB_UNLOCK(stcb);
5002 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5003 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5004 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5005 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
5006 (av->assoc_id == SCTP_ALL_ASSOC)))) {
5007 SCTP_INP_WLOCK(inp);
5008 inp->sctp_ep.max_burst = av->assoc_value;
5009 SCTP_INP_WUNLOCK(inp);
5011 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5012 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
5013 (av->assoc_id == SCTP_ALL_ASSOC))) {
5014 SCTP_INP_RLOCK(inp);
5015 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5016 SCTP_TCB_LOCK(stcb);
5017 stcb->asoc.max_burst = av->assoc_value;
5018 SCTP_TCB_UNLOCK(stcb);
5020 SCTP_INP_RUNLOCK(inp);
5027 struct sctp_assoc_value *av;
5030 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
5031 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
5033 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5034 ovh = SCTP_MED_OVERHEAD;
5036 ovh = SCTP_MED_V4_OVERHEAD;
5039 if (av->assoc_value) {
5040 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
5042 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
5044 SCTP_TCB_UNLOCK(stcb);
5046 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5047 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5048 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5049 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
5050 SCTP_INP_WLOCK(inp);
5052 * FIXME MT: I think this is not in
5053 * tune with the API ID
5055 if (av->assoc_value) {
5056 inp->sctp_frag_point = (av->assoc_value + ovh);
5058 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
5060 SCTP_INP_WUNLOCK(inp);
5062 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5070 struct sctp_event_subscribe *events;
5072 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5074 SCTP_INP_WLOCK(inp);
5075 if (events->sctp_data_io_event) {
5076 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5078 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5081 if (events->sctp_association_event) {
5082 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5084 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5087 if (events->sctp_address_event) {
5088 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5090 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5093 if (events->sctp_send_failure_event) {
5094 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5096 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5099 if (events->sctp_peer_error_event) {
5100 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5102 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5105 if (events->sctp_shutdown_event) {
5106 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5108 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5111 if (events->sctp_partial_delivery_event) {
5112 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5114 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5117 if (events->sctp_adaptation_layer_event) {
5118 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5120 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5123 if (events->sctp_authentication_event) {
5124 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5126 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5129 if (events->sctp_sender_dry_event) {
5130 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5132 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5135 if (events->sctp_stream_reset_event) {
5136 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5138 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5140 SCTP_INP_WUNLOCK(inp);
5142 SCTP_INP_RLOCK(inp);
5143 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5144 SCTP_TCB_LOCK(stcb);
5145 if (events->sctp_association_event) {
5146 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5148 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5150 if (events->sctp_address_event) {
5151 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5153 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5155 if (events->sctp_send_failure_event) {
5156 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5158 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5160 if (events->sctp_peer_error_event) {
5161 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5163 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5165 if (events->sctp_shutdown_event) {
5166 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5168 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5170 if (events->sctp_partial_delivery_event) {
5171 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5173 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5175 if (events->sctp_adaptation_layer_event) {
5176 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5178 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5180 if (events->sctp_authentication_event) {
5181 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5183 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5185 if (events->sctp_sender_dry_event) {
5186 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5188 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5190 if (events->sctp_stream_reset_event) {
5191 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5193 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5195 SCTP_TCB_UNLOCK(stcb);
5198 * Send up the sender dry event only for 1-to-1
5201 if (events->sctp_sender_dry_event) {
5202 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5203 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5204 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5206 SCTP_TCB_LOCK(stcb);
5207 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5208 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5209 (stcb->asoc.stream_queue_cnt == 0)) {
5210 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5212 SCTP_TCB_UNLOCK(stcb);
5216 SCTP_INP_RUNLOCK(inp);
5219 case SCTP_ADAPTATION_LAYER:
5221 struct sctp_setadaptation *adap_bits;
5223 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5224 SCTP_INP_WLOCK(inp);
5225 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5226 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5227 SCTP_INP_WUNLOCK(inp);
5231 case SCTP_SET_INITIAL_DBG_SEQ:
5235 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5236 SCTP_INP_WLOCK(inp);
5237 inp->sctp_ep.initial_sequence_debug = *vvv;
5238 SCTP_INP_WUNLOCK(inp);
5242 case SCTP_DEFAULT_SEND_PARAM:
5244 struct sctp_sndrcvinfo *s_info;
5246 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5247 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5250 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5251 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5253 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5256 SCTP_TCB_UNLOCK(stcb);
5258 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5259 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5260 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5261 ((s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5262 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)))) {
5263 SCTP_INP_WLOCK(inp);
5264 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5265 SCTP_INP_WUNLOCK(inp);
5267 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5268 ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5269 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC))) {
5270 SCTP_INP_RLOCK(inp);
5271 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5272 SCTP_TCB_LOCK(stcb);
5273 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5274 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5276 SCTP_TCB_UNLOCK(stcb);
5278 SCTP_INP_RUNLOCK(inp);
5283 case SCTP_PEER_ADDR_PARAMS:
5285 struct sctp_paddrparams *paddrp;
5286 struct sctp_nets *net;
5287 struct sockaddr *addr;
5288 #if defined(INET) && defined(INET6)
5289 struct sockaddr_in sin_store;
5292 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5293 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5295 #if defined(INET) && defined(INET6)
5296 if (paddrp->spp_address.ss_family == AF_INET6) {
5297 struct sockaddr_in6 *sin6;
5299 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5300 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5301 in6_sin6_2_sin(&sin_store, sin6);
5302 addr = (struct sockaddr *)&sin_store;
5304 addr = (struct sockaddr *)&paddrp->spp_address;
5307 addr = (struct sockaddr *)&paddrp->spp_address;
5310 addr = (struct sockaddr *)&paddrp->spp_address;
5313 net = sctp_findnet(stcb, addr);
5316 * We increment here since
5317 * sctp_findassociation_ep_addr() wil do a
5318 * decrement if it finds the stcb as long as
5319 * the locked tcb (last argument) is NOT a
5323 SCTP_INP_INCR_REF(inp);
5324 stcb = sctp_findassociation_ep_addr(&inp, addr,
5327 SCTP_INP_DECR_REF(inp);
5330 if ((stcb != NULL) && (net == NULL)) {
5332 if (addr->sa_family == AF_INET) {
5334 struct sockaddr_in *sin;
5336 sin = (struct sockaddr_in *)addr;
5337 if (sin->sin_addr.s_addr != INADDR_ANY) {
5338 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5339 SCTP_TCB_UNLOCK(stcb);
5346 if (addr->sa_family == AF_INET6) {
5347 struct sockaddr_in6 *sin6;
5349 sin6 = (struct sockaddr_in6 *)addr;
5350 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5351 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5352 SCTP_TCB_UNLOCK(stcb);
5359 error = EAFNOSUPPORT;
5360 SCTP_TCB_UNLOCK(stcb);
5361 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5366 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5368 SCTP_TCB_UNLOCK(stcb);
5369 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5373 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5375 SCTP_TCB_UNLOCK(stcb);
5376 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5379 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) &&
5380 ((paddrp->spp_pathmtu < SCTP_SMALLEST_PMTU) ||
5381 (paddrp->spp_pathmtu > SCTP_LARGEST_PMTU))) {
5383 SCTP_TCB_UNLOCK(stcb);
5384 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5389 /************************TCB SPECIFIC SET ******************/
5391 /************************NET SPECIFIC SET ******************/
5392 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5393 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5394 !(net->dest_state & SCTP_ADDR_NOHB)) {
5395 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5396 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5398 net->dest_state |= SCTP_ADDR_NOHB;
5400 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5401 if (paddrp->spp_hbinterval) {
5402 net->heart_beat_delay = paddrp->spp_hbinterval;
5403 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5404 net->heart_beat_delay = 0;
5406 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5407 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5408 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5409 net->dest_state &= ~SCTP_ADDR_NOHB;
5411 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5412 if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
5413 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5414 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5415 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5418 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5419 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5420 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5421 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5423 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5424 net->mtu = paddrp->spp_pathmtu;
5425 switch (net->ro._l_addr.sa.sa_family) {
5428 net->mtu += SCTP_MIN_V4_OVERHEAD;
5433 net->mtu += SCTP_MIN_OVERHEAD;
5439 if (net->mtu < stcb->asoc.smallest_mtu) {
5440 sctp_pathmtu_adjustment(stcb, net->mtu);
5443 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5444 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5445 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5447 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5449 if (paddrp->spp_pathmaxrxt) {
5450 if (net->dest_state & SCTP_ADDR_PF) {
5451 if (net->error_count > paddrp->spp_pathmaxrxt) {
5452 net->dest_state &= ~SCTP_ADDR_PF;
5455 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5456 (net->error_count > net->pf_threshold)) {
5457 net->dest_state |= SCTP_ADDR_PF;
5458 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5459 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5460 stcb->sctp_ep, stcb, net,
5461 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5462 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5465 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5466 if (net->error_count > paddrp->spp_pathmaxrxt) {
5467 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5468 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5471 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5472 net->dest_state |= SCTP_ADDR_REACHABLE;
5473 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5476 net->failure_threshold = paddrp->spp_pathmaxrxt;
5478 if (paddrp->spp_flags & SPP_DSCP) {
5479 net->dscp = paddrp->spp_dscp & 0xfc;
5483 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5484 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5485 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5486 net->flowlabel |= 0x80000000;
5491 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5492 if (paddrp->spp_pathmaxrxt != 0) {
5493 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5494 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5495 if (net->dest_state & SCTP_ADDR_PF) {
5496 if (net->error_count > paddrp->spp_pathmaxrxt) {
5497 net->dest_state &= ~SCTP_ADDR_PF;
5500 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5501 (net->error_count > net->pf_threshold)) {
5502 net->dest_state |= SCTP_ADDR_PF;
5503 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5504 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5505 stcb->sctp_ep, stcb, net,
5506 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5507 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5510 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5511 if (net->error_count > paddrp->spp_pathmaxrxt) {
5512 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5513 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5516 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5517 net->dest_state |= SCTP_ADDR_REACHABLE;
5518 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5521 net->failure_threshold = paddrp->spp_pathmaxrxt;
5525 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5526 if (paddrp->spp_hbinterval != 0) {
5527 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5528 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5529 stcb->asoc.heart_beat_delay = 0;
5531 /* Turn back on the timer */
5532 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5533 if (paddrp->spp_hbinterval != 0) {
5534 net->heart_beat_delay = paddrp->spp_hbinterval;
5535 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5536 net->heart_beat_delay = 0;
5538 if (net->dest_state & SCTP_ADDR_NOHB) {
5539 net->dest_state &= ~SCTP_ADDR_NOHB;
5541 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5542 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5543 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5545 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5547 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5548 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5549 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5550 net->dest_state |= SCTP_ADDR_NOHB;
5551 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5552 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5554 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5558 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5560 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5561 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5562 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5563 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5564 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5566 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5567 net->mtu = paddrp->spp_pathmtu;
5568 switch (net->ro._l_addr.sa.sa_family) {
5571 net->mtu += SCTP_MIN_V4_OVERHEAD;
5576 net->mtu += SCTP_MIN_OVERHEAD;
5582 if (net->mtu < stcb->asoc.smallest_mtu) {
5583 sctp_pathmtu_adjustment(stcb, net->mtu);
5586 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5587 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5589 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5590 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5591 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5592 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5594 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5596 stcb->asoc.default_mtu = 0;
5597 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5599 if (paddrp->spp_flags & SPP_DSCP) {
5600 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5601 net->dscp = paddrp->spp_dscp & 0xfc;
5604 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5605 stcb->asoc.default_dscp |= 0x01;
5608 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5609 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5610 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5611 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5612 net->flowlabel |= 0x80000000;
5615 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5616 stcb->asoc.default_flowlabel |= 0x80000000;
5620 SCTP_TCB_UNLOCK(stcb);
5622 /************************NO TCB, SET TO default stuff ******************/
5623 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5624 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5625 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5626 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
5627 SCTP_INP_WLOCK(inp);
5629 * For the TOS/FLOWLABEL stuff you
5630 * set it with the options on the
5633 if (paddrp->spp_pathmaxrxt != 0) {
5634 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5637 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5638 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5639 else if (paddrp->spp_hbinterval != 0) {
5640 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5641 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5642 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5645 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5646 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5647 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5648 } else if (paddrp->spp_hbinterval) {
5649 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5651 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5652 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5653 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5655 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5656 inp->sctp_ep.default_mtu = 0;
5657 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5658 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5659 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5660 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5662 if (paddrp->spp_flags & SPP_DSCP) {
5663 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5664 inp->sctp_ep.default_dscp |= 0x01;
5667 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5668 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5669 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5670 inp->sctp_ep.default_flowlabel |= 0x80000000;
5674 SCTP_INP_WUNLOCK(inp);
5676 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5684 struct sctp_rtoinfo *srto;
5685 uint32_t new_init, new_min, new_max;
5687 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5688 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5691 if (srto->srto_initial)
5692 new_init = srto->srto_initial;
5694 new_init = stcb->asoc.initial_rto;
5696 new_max = srto->srto_max;
5698 new_max = stcb->asoc.maxrto;
5700 new_min = srto->srto_min;
5702 new_min = stcb->asoc.minrto;
5703 if ((new_min <= new_init) && (new_init <= new_max)) {
5704 stcb->asoc.initial_rto = new_init;
5705 stcb->asoc.maxrto = new_max;
5706 stcb->asoc.minrto = new_min;
5708 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5711 SCTP_TCB_UNLOCK(stcb);
5713 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5714 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5715 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5716 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
5717 SCTP_INP_WLOCK(inp);
5718 if (srto->srto_initial)
5719 new_init = srto->srto_initial;
5721 new_init = inp->sctp_ep.initial_rto;
5723 new_max = srto->srto_max;
5725 new_max = inp->sctp_ep.sctp_maxrto;
5727 new_min = srto->srto_min;
5729 new_min = inp->sctp_ep.sctp_minrto;
5730 if ((new_min <= new_init) && (new_init <= new_max)) {
5731 inp->sctp_ep.initial_rto = new_init;
5732 inp->sctp_ep.sctp_maxrto = new_max;
5733 inp->sctp_ep.sctp_minrto = new_min;
5735 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5738 SCTP_INP_WUNLOCK(inp);
5740 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5746 case SCTP_ASSOCINFO:
5748 struct sctp_assocparams *sasoc;
5750 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5751 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5752 if (sasoc->sasoc_cookie_life) {
5753 /* boundary check the cookie life */
5754 if (sasoc->sasoc_cookie_life < 1000)
5755 sasoc->sasoc_cookie_life = 1000;
5756 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5757 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5761 if (sasoc->sasoc_asocmaxrxt)
5762 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5763 if (sasoc->sasoc_cookie_life) {
5764 stcb->asoc.cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5766 SCTP_TCB_UNLOCK(stcb);
5768 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5769 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5770 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5771 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
5772 SCTP_INP_WLOCK(inp);
5773 if (sasoc->sasoc_asocmaxrxt)
5774 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5775 if (sasoc->sasoc_cookie_life) {
5776 inp->sctp_ep.def_cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5778 SCTP_INP_WUNLOCK(inp);
5780 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5788 struct sctp_initmsg *sinit;
5790 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5791 SCTP_INP_WLOCK(inp);
5792 if (sinit->sinit_num_ostreams)
5793 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5795 if (sinit->sinit_max_instreams)
5796 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5798 if (sinit->sinit_max_attempts)
5799 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5801 if (sinit->sinit_max_init_timeo)
5802 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5803 SCTP_INP_WUNLOCK(inp);
5806 case SCTP_PRIMARY_ADDR:
5808 struct sctp_setprim *spa;
5809 struct sctp_nets *net;
5810 struct sockaddr *addr;
5811 #if defined(INET) && defined(INET6)
5812 struct sockaddr_in sin_store;
5815 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5816 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5818 #if defined(INET) && defined(INET6)
5819 if (spa->ssp_addr.ss_family == AF_INET6) {
5820 struct sockaddr_in6 *sin6;
5822 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5823 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5824 in6_sin6_2_sin(&sin_store, sin6);
5825 addr = (struct sockaddr *)&sin_store;
5827 addr = (struct sockaddr *)&spa->ssp_addr;
5830 addr = (struct sockaddr *)&spa->ssp_addr;
5833 addr = (struct sockaddr *)&spa->ssp_addr;
5836 net = sctp_findnet(stcb, addr);
5839 * We increment here since
5840 * sctp_findassociation_ep_addr() wil do a
5841 * decrement if it finds the stcb as long as
5842 * the locked tcb (last argument) is NOT a
5846 SCTP_INP_INCR_REF(inp);
5847 stcb = sctp_findassociation_ep_addr(&inp, addr,
5850 SCTP_INP_DECR_REF(inp);
5854 if ((stcb != NULL) && (net != NULL)) {
5855 if (net != stcb->asoc.primary_destination) {
5856 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5857 /* Ok we need to set it */
5858 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5859 if ((stcb->asoc.alternate) &&
5860 (!(net->dest_state & SCTP_ADDR_PF)) &&
5861 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5862 sctp_free_remote_addr(stcb->asoc.alternate);
5863 stcb->asoc.alternate = NULL;
5866 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5870 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5875 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5879 SCTP_TCB_UNLOCK(stcb);
5883 case SCTP_SET_DYNAMIC_PRIMARY:
5885 union sctp_sockstore *ss;
5887 error = priv_check(curthread,
5888 PRIV_NETINET_RESERVEDPORT);
5892 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5893 /* SUPER USER CHECK? */
5894 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5897 case SCTP_SET_PEER_PRIMARY_ADDR:
5899 struct sctp_setpeerprim *sspp;
5900 struct sockaddr *addr;
5901 #if defined(INET) && defined(INET6)
5902 struct sockaddr_in sin_store;
5905 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5906 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5908 struct sctp_ifa *ifa;
5910 #if defined(INET) && defined(INET6)
5911 if (sspp->sspp_addr.ss_family == AF_INET6) {
5912 struct sockaddr_in6 *sin6;
5914 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5915 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5916 in6_sin6_2_sin(&sin_store, sin6);
5917 addr = (struct sockaddr *)&sin_store;
5919 addr = (struct sockaddr *)&sspp->sspp_addr;
5922 addr = (struct sockaddr *)&sspp->sspp_addr;
5925 addr = (struct sockaddr *)&sspp->sspp_addr;
5927 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5929 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5933 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5935 * Must validate the ifa found is in
5938 struct sctp_laddr *laddr;
5941 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5942 if (laddr->ifa == NULL) {
5943 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5947 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5948 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5951 if (laddr->ifa == ifa) {
5957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5962 switch (addr->sa_family) {
5966 struct sockaddr_in *sin;
5968 sin = (struct sockaddr_in *)addr;
5969 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5970 &sin->sin_addr) != 0) {
5971 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5981 struct sockaddr_in6 *sin6;
5983 sin6 = (struct sockaddr_in6 *)addr;
5984 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5985 &sin6->sin6_addr) != 0) {
5986 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5999 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
6000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6003 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
6005 SCTP_TCB_UNLOCK(stcb);
6007 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6012 case SCTP_BINDX_ADD_ADDR:
6014 struct sctp_getaddresses *addrs;
6017 td = (struct thread *)p;
6018 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
6021 if (addrs->addr->sa_family == AF_INET) {
6022 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
6023 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6027 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
6028 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6034 if (addrs->addr->sa_family == AF_INET6) {
6035 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
6036 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6040 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
6041 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6042 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6048 error = EAFNOSUPPORT;
6051 sctp_bindx_add_address(so, inp, addrs->addr,
6052 addrs->sget_assoc_id, vrf_id,
6056 case SCTP_BINDX_REM_ADDR:
6058 struct sctp_getaddresses *addrs;
6061 td = (struct thread *)p;
6063 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
6065 if (addrs->addr->sa_family == AF_INET) {
6066 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
6067 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6071 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
6072 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6078 if (addrs->addr->sa_family == AF_INET6) {
6079 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
6080 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6085 (error = prison_local_ip6(td->td_ucred,
6086 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
6087 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6088 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6094 error = EAFNOSUPPORT;
6097 sctp_bindx_delete_address(inp, addrs->addr,
6098 addrs->sget_assoc_id, vrf_id,
6104 struct sctp_event *event;
6105 uint32_t event_type;
6107 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6108 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6109 switch (event->se_type) {
6110 case SCTP_ASSOC_CHANGE:
6111 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6113 case SCTP_PEER_ADDR_CHANGE:
6114 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6116 case SCTP_REMOTE_ERROR:
6117 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6119 case SCTP_SEND_FAILED:
6120 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6122 case SCTP_SHUTDOWN_EVENT:
6123 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6125 case SCTP_ADAPTATION_INDICATION:
6126 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6128 case SCTP_PARTIAL_DELIVERY_EVENT:
6129 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6131 case SCTP_AUTHENTICATION_EVENT:
6132 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6134 case SCTP_STREAM_RESET_EVENT:
6135 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6137 case SCTP_SENDER_DRY_EVENT:
6138 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6140 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6142 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6145 case SCTP_ASSOC_RESET_EVENT:
6146 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6148 case SCTP_STREAM_CHANGE_EVENT:
6149 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6151 case SCTP_SEND_FAILED_EVENT:
6152 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6156 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6160 if (event_type > 0) {
6163 sctp_stcb_feature_on(inp, stcb, event_type);
6164 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6165 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6166 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6167 (stcb->asoc.stream_queue_cnt == 0)) {
6168 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6172 sctp_stcb_feature_off(inp, stcb, event_type);
6174 SCTP_TCB_UNLOCK(stcb);
6177 * We don't want to send up a storm
6178 * of events, so return an error for
6181 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6182 (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6183 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6184 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6185 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6189 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6190 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6191 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6192 ((event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6193 (event->se_assoc_id == SCTP_ALL_ASSOC)))) {
6194 SCTP_INP_WLOCK(inp);
6196 sctp_feature_on(inp, event_type);
6198 sctp_feature_off(inp, event_type);
6200 SCTP_INP_WUNLOCK(inp);
6202 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6203 ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6204 (event->se_assoc_id == SCTP_ALL_ASSOC))) {
6205 SCTP_INP_RLOCK(inp);
6206 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6207 SCTP_TCB_LOCK(stcb);
6209 sctp_stcb_feature_on(inp, stcb, event_type);
6211 sctp_stcb_feature_off(inp, stcb, event_type);
6213 SCTP_TCB_UNLOCK(stcb);
6215 SCTP_INP_RUNLOCK(inp);
6220 SCTP_TCB_UNLOCK(stcb);
6225 case SCTP_RECVRCVINFO:
6229 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6230 SCTP_INP_WLOCK(inp);
6232 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6234 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6236 SCTP_INP_WUNLOCK(inp);
6239 case SCTP_RECVNXTINFO:
6243 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6244 SCTP_INP_WLOCK(inp);
6246 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6248 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6250 SCTP_INP_WUNLOCK(inp);
6253 case SCTP_DEFAULT_SNDINFO:
6255 struct sctp_sndinfo *info;
6258 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6259 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6262 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6263 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6264 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6265 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6266 stcb->asoc.def_send.sinfo_flags |= policy;
6267 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6268 stcb->asoc.def_send.sinfo_context = info->snd_context;
6270 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6273 SCTP_TCB_UNLOCK(stcb);
6275 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6276 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6277 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6278 ((info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6279 (info->snd_assoc_id == SCTP_ALL_ASSOC)))) {
6280 SCTP_INP_WLOCK(inp);
6281 inp->def_send.sinfo_stream = info->snd_sid;
6282 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6283 inp->def_send.sinfo_flags = info->snd_flags;
6284 inp->def_send.sinfo_flags |= policy;
6285 inp->def_send.sinfo_ppid = info->snd_ppid;
6286 inp->def_send.sinfo_context = info->snd_context;
6287 SCTP_INP_WUNLOCK(inp);
6289 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6290 ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6291 (info->snd_assoc_id == SCTP_ALL_ASSOC))) {
6292 SCTP_INP_RLOCK(inp);
6293 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6294 SCTP_TCB_LOCK(stcb);
6295 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6296 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6297 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6298 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6299 stcb->asoc.def_send.sinfo_flags |= policy;
6300 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6301 stcb->asoc.def_send.sinfo_context = info->snd_context;
6303 SCTP_TCB_UNLOCK(stcb);
6305 SCTP_INP_RUNLOCK(inp);
6310 case SCTP_DEFAULT_PRINFO:
6312 struct sctp_default_prinfo *info;
6314 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6315 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6317 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6319 SCTP_TCB_UNLOCK(stcb);
6321 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6326 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6327 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6328 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6329 SCTP_TCB_UNLOCK(stcb);
6331 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6332 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6333 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6334 ((info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6335 (info->pr_assoc_id == SCTP_ALL_ASSOC)))) {
6336 SCTP_INP_WLOCK(inp);
6337 inp->def_send.sinfo_flags &= 0xfff0;
6338 inp->def_send.sinfo_flags |= info->pr_policy;
6339 inp->def_send.sinfo_timetolive = info->pr_value;
6340 SCTP_INP_WUNLOCK(inp);
6342 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6343 ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6344 (info->pr_assoc_id == SCTP_ALL_ASSOC))) {
6345 SCTP_INP_RLOCK(inp);
6346 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6347 SCTP_TCB_LOCK(stcb);
6348 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6349 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6350 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6351 SCTP_TCB_UNLOCK(stcb);
6353 SCTP_INP_RUNLOCK(inp);
6358 case SCTP_PEER_ADDR_THLDS:
6359 /* Applies to the specific association */
6361 struct sctp_paddrthlds *thlds;
6362 struct sctp_nets *net;
6363 struct sockaddr *addr;
6364 #if defined(INET) && defined(INET6)
6365 struct sockaddr_in sin_store;
6368 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6369 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6371 #if defined(INET) && defined(INET6)
6372 if (thlds->spt_address.ss_family == AF_INET6) {
6373 struct sockaddr_in6 *sin6;
6375 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6376 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6377 in6_sin6_2_sin(&sin_store, sin6);
6378 addr = (struct sockaddr *)&sin_store;
6380 addr = (struct sockaddr *)&thlds->spt_address;
6383 addr = (struct sockaddr *)&thlds->spt_address;
6386 addr = (struct sockaddr *)&thlds->spt_address;
6389 net = sctp_findnet(stcb, addr);
6392 * We increment here since
6393 * sctp_findassociation_ep_addr() wil do a
6394 * decrement if it finds the stcb as long as
6395 * the locked tcb (last argument) is NOT a
6399 SCTP_INP_INCR_REF(inp);
6400 stcb = sctp_findassociation_ep_addr(&inp, addr,
6403 SCTP_INP_DECR_REF(inp);
6406 if ((stcb != NULL) && (net == NULL)) {
6408 if (addr->sa_family == AF_INET) {
6410 struct sockaddr_in *sin;
6412 sin = (struct sockaddr_in *)addr;
6413 if (sin->sin_addr.s_addr != INADDR_ANY) {
6414 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6415 SCTP_TCB_UNLOCK(stcb);
6422 if (addr->sa_family == AF_INET6) {
6423 struct sockaddr_in6 *sin6;
6425 sin6 = (struct sockaddr_in6 *)addr;
6426 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6427 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6428 SCTP_TCB_UNLOCK(stcb);
6435 error = EAFNOSUPPORT;
6436 SCTP_TCB_UNLOCK(stcb);
6437 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6441 if (thlds->spt_pathcpthld != 0xffff) {
6443 SCTP_TCB_UNLOCK(stcb);
6446 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6451 net->failure_threshold = thlds->spt_pathmaxrxt;
6452 net->pf_threshold = thlds->spt_pathpfthld;
6453 if (net->dest_state & SCTP_ADDR_PF) {
6454 if ((net->error_count > net->failure_threshold) ||
6455 (net->error_count <= net->pf_threshold)) {
6456 net->dest_state &= ~SCTP_ADDR_PF;
6459 if ((net->error_count > net->pf_threshold) &&
6460 (net->error_count <= net->failure_threshold)) {
6461 net->dest_state |= SCTP_ADDR_PF;
6462 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6463 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6464 stcb->sctp_ep, stcb, net,
6465 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6466 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6469 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6470 if (net->error_count > net->failure_threshold) {
6471 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6472 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6475 if (net->error_count <= net->failure_threshold) {
6476 net->dest_state |= SCTP_ADDR_REACHABLE;
6477 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6481 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6482 net->failure_threshold = thlds->spt_pathmaxrxt;
6483 net->pf_threshold = thlds->spt_pathpfthld;
6484 if (net->dest_state & SCTP_ADDR_PF) {
6485 if ((net->error_count > net->failure_threshold) ||
6486 (net->error_count <= net->pf_threshold)) {
6487 net->dest_state &= ~SCTP_ADDR_PF;
6490 if ((net->error_count > net->pf_threshold) &&
6491 (net->error_count <= net->failure_threshold)) {
6492 net->dest_state |= SCTP_ADDR_PF;
6493 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6494 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6495 stcb->sctp_ep, stcb, net,
6496 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6497 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6500 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6501 if (net->error_count > net->failure_threshold) {
6502 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6503 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6506 if (net->error_count <= net->failure_threshold) {
6507 net->dest_state |= SCTP_ADDR_REACHABLE;
6508 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6512 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6513 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6515 SCTP_TCB_UNLOCK(stcb);
6517 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6518 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6519 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6520 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
6521 SCTP_INP_WLOCK(inp);
6522 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6523 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6524 SCTP_INP_WUNLOCK(inp);
6526 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6532 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6534 struct sctp_udpencaps *encaps;
6535 struct sctp_nets *net;
6536 struct sockaddr *addr;
6537 #if defined(INET) && defined(INET6)
6538 struct sockaddr_in sin_store;
6541 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6542 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6544 #if defined(INET) && defined(INET6)
6545 if (encaps->sue_address.ss_family == AF_INET6) {
6546 struct sockaddr_in6 *sin6;
6548 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6549 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6550 in6_sin6_2_sin(&sin_store, sin6);
6551 addr = (struct sockaddr *)&sin_store;
6553 addr = (struct sockaddr *)&encaps->sue_address;
6556 addr = (struct sockaddr *)&encaps->sue_address;
6559 addr = (struct sockaddr *)&encaps->sue_address;
6562 net = sctp_findnet(stcb, addr);
6565 * We increment here since
6566 * sctp_findassociation_ep_addr() wil do a
6567 * decrement if it finds the stcb as long as
6568 * the locked tcb (last argument) is NOT a
6572 SCTP_INP_INCR_REF(inp);
6573 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6575 SCTP_INP_DECR_REF(inp);
6578 if ((stcb != NULL) && (net == NULL)) {
6580 if (addr->sa_family == AF_INET) {
6582 struct sockaddr_in *sin;
6584 sin = (struct sockaddr_in *)addr;
6585 if (sin->sin_addr.s_addr != INADDR_ANY) {
6586 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6587 SCTP_TCB_UNLOCK(stcb);
6594 if (addr->sa_family == AF_INET6) {
6595 struct sockaddr_in6 *sin6;
6597 sin6 = (struct sockaddr_in6 *)addr;
6598 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6599 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6600 SCTP_TCB_UNLOCK(stcb);
6607 error = EAFNOSUPPORT;
6608 SCTP_TCB_UNLOCK(stcb);
6609 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6616 net->port = encaps->sue_port;
6618 stcb->asoc.port = encaps->sue_port;
6620 SCTP_TCB_UNLOCK(stcb);
6622 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6623 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6624 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6625 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
6626 SCTP_INP_WLOCK(inp);
6627 inp->sctp_ep.port = encaps->sue_port;
6628 SCTP_INP_WUNLOCK(inp);
6630 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6636 case SCTP_ECN_SUPPORTED:
6638 struct sctp_assoc_value *av;
6640 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6641 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6644 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6646 SCTP_TCB_UNLOCK(stcb);
6648 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6649 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6650 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6651 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6652 SCTP_INP_WLOCK(inp);
6653 if (av->assoc_value == 0) {
6654 inp->ecn_supported = 0;
6656 inp->ecn_supported = 1;
6658 SCTP_INP_WUNLOCK(inp);
6660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6666 case SCTP_PR_SUPPORTED:
6668 struct sctp_assoc_value *av;
6670 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6671 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6674 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6676 SCTP_TCB_UNLOCK(stcb);
6678 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6679 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6680 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6681 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6682 SCTP_INP_WLOCK(inp);
6683 if (av->assoc_value == 0) {
6684 inp->prsctp_supported = 0;
6686 inp->prsctp_supported = 1;
6688 SCTP_INP_WUNLOCK(inp);
6690 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6696 case SCTP_AUTH_SUPPORTED:
6698 struct sctp_assoc_value *av;
6700 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6701 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6704 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6706 SCTP_TCB_UNLOCK(stcb);
6708 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6709 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6710 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6711 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6712 if ((av->assoc_value == 0) &&
6713 (inp->asconf_supported == 1)) {
6715 * AUTH is required for
6718 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6721 SCTP_INP_WLOCK(inp);
6722 if (av->assoc_value == 0) {
6723 inp->auth_supported = 0;
6725 inp->auth_supported = 1;
6727 SCTP_INP_WUNLOCK(inp);
6730 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6736 case SCTP_ASCONF_SUPPORTED:
6738 struct sctp_assoc_value *av;
6740 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6741 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6744 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6746 SCTP_TCB_UNLOCK(stcb);
6748 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6749 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6750 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6751 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6752 if ((av->assoc_value != 0) &&
6753 (inp->auth_supported == 0)) {
6755 * AUTH is required for
6758 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6761 SCTP_INP_WLOCK(inp);
6762 if (av->assoc_value == 0) {
6763 inp->asconf_supported = 0;
6764 sctp_auth_delete_chunk(SCTP_ASCONF,
6765 inp->sctp_ep.local_auth_chunks);
6766 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6767 inp->sctp_ep.local_auth_chunks);
6769 inp->asconf_supported = 1;
6770 sctp_auth_add_chunk(SCTP_ASCONF,
6771 inp->sctp_ep.local_auth_chunks);
6772 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6773 inp->sctp_ep.local_auth_chunks);
6775 SCTP_INP_WUNLOCK(inp);
6778 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6784 case SCTP_RECONFIG_SUPPORTED:
6786 struct sctp_assoc_value *av;
6788 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6789 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6792 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6794 SCTP_TCB_UNLOCK(stcb);
6796 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6797 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6798 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6799 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6800 SCTP_INP_WLOCK(inp);
6801 if (av->assoc_value == 0) {
6802 inp->reconfig_supported = 0;
6804 inp->reconfig_supported = 1;
6806 SCTP_INP_WUNLOCK(inp);
6808 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6814 case SCTP_NRSACK_SUPPORTED:
6816 struct sctp_assoc_value *av;
6818 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6819 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6822 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6824 SCTP_TCB_UNLOCK(stcb);
6826 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6827 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6828 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6829 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6830 SCTP_INP_WLOCK(inp);
6831 if (av->assoc_value == 0) {
6832 inp->nrsack_supported = 0;
6834 inp->nrsack_supported = 1;
6836 SCTP_INP_WUNLOCK(inp);
6838 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6844 case SCTP_PKTDROP_SUPPORTED:
6846 struct sctp_assoc_value *av;
6848 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6849 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6852 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6854 SCTP_TCB_UNLOCK(stcb);
6856 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6857 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6858 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6859 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6860 SCTP_INP_WLOCK(inp);
6861 if (av->assoc_value == 0) {
6862 inp->pktdrop_supported = 0;
6864 inp->pktdrop_supported = 1;
6866 SCTP_INP_WUNLOCK(inp);
6868 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6876 struct sctp_assoc_value *av;
6877 struct sctp_nets *net;
6879 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6880 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6883 stcb->asoc.max_cwnd = av->assoc_value;
6884 if (stcb->asoc.max_cwnd > 0) {
6885 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6886 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6887 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6888 net->cwnd = stcb->asoc.max_cwnd;
6889 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6890 net->cwnd = net->mtu - sizeof(struct sctphdr);
6895 SCTP_TCB_UNLOCK(stcb);
6897 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6898 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6899 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6900 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6901 SCTP_INP_WLOCK(inp);
6902 inp->max_cwnd = av->assoc_value;
6903 SCTP_INP_WUNLOCK(inp);
6905 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6912 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6913 error = ENOPROTOOPT;
6915 } /* end switch (opt) */
6920 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6922 struct epoch_tracker et;
6923 struct sctp_inpcb *inp;
6924 void *optval = NULL;
6929 if ((sopt->sopt_level == SOL_SOCKET) &&
6930 (sopt->sopt_name == SO_SETFIB)) {
6931 inp = (struct sctp_inpcb *)so->so_pcb;
6933 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6936 SCTP_INP_WLOCK(inp);
6937 inp->fibnum = so->so_fibnum;
6938 SCTP_INP_WUNLOCK(inp);
6941 if (sopt->sopt_level != IPPROTO_SCTP) {
6942 /* wrong proto level... send back up to IP */
6944 if (INP_CHECK_SOCKAF(so, AF_INET6))
6945 error = ip6_ctloutput(so, sopt);
6947 #if defined(INET) && defined(INET6)
6951 error = ip_ctloutput(so, sopt);
6955 optsize = sopt->sopt_valsize;
6956 if (optsize > SCTP_SOCKET_OPTION_LIMIT) {
6957 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6961 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6962 if (optval == NULL) {
6963 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6966 error = sooptcopyin(sopt, optval, optsize, optsize);
6968 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6972 p = (void *)sopt->sopt_td;
6973 if (sopt->sopt_dir == SOPT_SET) {
6974 NET_EPOCH_ENTER(et);
6975 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6977 } else if (sopt->sopt_dir == SOPT_GET) {
6978 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6980 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6983 if ((error == 0) && (optval != NULL)) {
6984 error = sooptcopyout(sopt, optval, optsize);
6985 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6986 } else if (optval != NULL) {
6987 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6995 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6997 struct epoch_tracker et;
6999 int create_lock_on = 0;
7001 struct sctp_inpcb *inp;
7002 struct sctp_tcb *stcb = NULL;
7004 inp = (struct sctp_inpcb *)so->so_pcb;
7006 /* I made the same as TCP since we are not setup? */
7007 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7008 return (ECONNRESET);
7011 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7015 switch (addr->sa_family) {
7019 struct sockaddr_in6 *sin6;
7021 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
7022 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7025 sin6 = (struct sockaddr_in6 *)addr;
7026 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6->sin6_addr)) != 0) {
7027 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7036 struct sockaddr_in *sin;
7038 if (addr->sa_len != sizeof(struct sockaddr_in)) {
7039 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7042 sin = (struct sockaddr_in *)addr;
7043 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sin->sin_addr)) != 0) {
7044 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7051 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
7052 return (EAFNOSUPPORT);
7054 SCTP_INP_INCR_REF(inp);
7055 SCTP_ASOC_CREATE_LOCK(inp);
7057 NET_EPOCH_ENTER(et);
7059 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
7060 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
7061 /* Should I really unlock ? */
7062 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
7067 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
7068 (addr->sa_family == AF_INET6)) {
7069 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7074 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
7075 SCTP_PCB_FLAGS_UNBOUND) {
7076 /* Bind a ephemeral port */
7077 error = sctp_inpcb_bind(so, NULL, NULL, p);
7082 /* Now do we connect? */
7083 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
7084 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
7085 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7089 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7090 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7091 /* We are already connected AND the TCP model */
7092 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7096 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7097 SCTP_INP_RLOCK(inp);
7098 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7099 SCTP_INP_RUNLOCK(inp);
7102 * We increment here since sctp_findassociation_ep_addr()
7103 * will do a decrement if it finds the stcb as long as the
7104 * locked tcb (last argument) is NOT a TCB.. aka NULL.
7106 SCTP_INP_INCR_REF(inp);
7107 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7109 SCTP_INP_DECR_REF(inp);
7111 SCTP_TCB_UNLOCK(stcb);
7115 /* Already have or am bring up an association */
7116 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7121 vrf_id = inp->def_vrf_id;
7122 /* We are GOOD to go */
7123 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
7124 inp->sctp_ep.pre_open_stream_count,
7125 inp->sctp_ep.port, p,
7126 SCTP_INITIALIZE_AUTH_PARAMS);
7128 /* Gak! no memory */
7131 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7132 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7133 /* Set the connected flag so we can queue data */
7136 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7137 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7139 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7140 SCTP_TCB_UNLOCK(stcb);
7143 if (create_lock_on) {
7144 SCTP_ASOC_CREATE_UNLOCK(inp);
7146 SCTP_INP_DECR_REF(inp);
7152 sctp_listen(struct socket *so, int backlog, struct thread *p)
7155 * Note this module depends on the protocol processing being called
7156 * AFTER any socket level flags and backlog are applied to the
7157 * socket. The traditional way that the socket flags are applied is
7158 * AFTER protocol processing. We have made a change to the
7159 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7160 * place if the socket API for SCTP is to work properly.
7164 struct sctp_inpcb *inp;
7166 inp = (struct sctp_inpcb *)so->so_pcb;
7168 /* I made the same as TCP since we are not setup? */
7169 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7170 return (ECONNRESET);
7172 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7173 /* See if we have a listener */
7174 struct sctp_inpcb *tinp;
7175 union sctp_sockstore store;
7177 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7179 struct sctp_laddr *laddr;
7181 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7182 memcpy(&store, &laddr->ifa->address, sizeof(store));
7183 switch (store.sa.sa_family) {
7186 store.sin.sin_port = inp->sctp_lport;
7191 store.sin6.sin6_port = inp->sctp_lport;
7197 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7198 if (tinp && (tinp != inp) &&
7199 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7200 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7201 (SCTP_IS_LISTENING(tinp))) {
7203 * we have a listener already and
7206 SCTP_INP_DECR_REF(tinp);
7207 return (EADDRINUSE);
7209 SCTP_INP_DECR_REF(tinp);
7213 /* Setup a local addr bound all */
7214 memset(&store, 0, sizeof(store));
7216 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7217 store.sa.sa_family = AF_INET6;
7218 store.sa.sa_len = sizeof(struct sockaddr_in6);
7222 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7223 store.sa.sa_family = AF_INET;
7224 store.sa.sa_len = sizeof(struct sockaddr_in);
7227 switch (store.sa.sa_family) {
7230 store.sin.sin_port = inp->sctp_lport;
7235 store.sin6.sin6_port = inp->sctp_lport;
7241 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7242 if (tinp && (tinp != inp) &&
7243 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7244 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7245 (SCTP_IS_LISTENING(tinp))) {
7247 * we have a listener already and its not
7250 SCTP_INP_DECR_REF(tinp);
7251 return (EADDRINUSE);
7253 SCTP_INP_DECR_REF(tinp);
7257 SCTP_INP_RLOCK(inp);
7258 #ifdef SCTP_LOCK_LOGGING
7259 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7260 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7264 error = solisten_proto_check(so);
7267 SCTP_INP_RUNLOCK(inp);
7270 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7271 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7273 * The unlucky case - We are in the tcp pool with this guy.
7274 * - Someone else is in the main inp slot. - We must move
7275 * this guy (the listener) to the main slot - We must then
7276 * move the guy that was listener to the TCP Pool.
7278 if (sctp_swap_inpcb_for_listen(inp)) {
7279 SCTP_INP_RUNLOCK(inp);
7280 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7281 return (EADDRINUSE);
7285 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7286 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7287 /* We are already connected AND the TCP model */
7288 SCTP_INP_RUNLOCK(inp);
7289 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7290 return (EADDRINUSE);
7292 SCTP_INP_RUNLOCK(inp);
7293 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7294 /* We must do a bind. */
7295 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7296 /* bind error, probably perm */
7300 SCTP_INP_WLOCK(inp);
7301 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7303 solisten_proto(so, backlog);
7307 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7309 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7311 SCTP_INP_WUNLOCK(inp);
7315 static int sctp_defered_wakeup_cnt = 0;
7318 sctp_accept(struct socket *so, struct sockaddr **addr)
7320 struct sctp_tcb *stcb;
7321 struct sctp_inpcb *inp;
7322 union sctp_sockstore store;
7326 inp = (struct sctp_inpcb *)so->so_pcb;
7329 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7330 return (ECONNRESET);
7332 SCTP_INP_WLOCK(inp);
7333 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7334 SCTP_INP_WUNLOCK(inp);
7335 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7336 return (EOPNOTSUPP);
7338 if (so->so_state & SS_ISDISCONNECTED) {
7339 SCTP_INP_WUNLOCK(inp);
7340 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7341 return (ECONNABORTED);
7343 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7345 SCTP_INP_WUNLOCK(inp);
7346 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7347 return (ECONNRESET);
7349 SCTP_TCB_LOCK(stcb);
7350 store = stcb->asoc.primary_destination->ro._l_addr;
7351 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7352 /* Wake any delayed sleep action */
7353 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7354 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7355 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7356 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7357 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7358 if (sowriteable(inp->sctp_socket)) {
7359 sowwakeup_locked(inp->sctp_socket);
7361 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7364 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7365 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7366 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7367 if (soreadable(inp->sctp_socket)) {
7368 sctp_defered_wakeup_cnt++;
7369 sorwakeup_locked(inp->sctp_socket);
7371 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7375 SCTP_INP_WUNLOCK(inp);
7376 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7377 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7378 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7380 SCTP_TCB_UNLOCK(stcb);
7382 switch (store.sa.sa_family) {
7386 struct sockaddr_in *sin;
7388 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7391 sin->sin_family = AF_INET;
7392 sin->sin_len = sizeof(*sin);
7393 sin->sin_port = store.sin.sin_port;
7394 sin->sin_addr = store.sin.sin_addr;
7395 *addr = (struct sockaddr *)sin;
7402 struct sockaddr_in6 *sin6;
7404 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7407 sin6->sin6_family = AF_INET6;
7408 sin6->sin6_len = sizeof(*sin6);
7409 sin6->sin6_port = store.sin6.sin6_port;
7410 sin6->sin6_addr = store.sin6.sin6_addr;
7411 if ((error = sa6_recoverscope(sin6)) != 0) {
7412 SCTP_FREE_SONAME(sin6);
7415 *addr = (struct sockaddr *)sin6;
7428 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7430 struct sockaddr_in *sin;
7432 struct sctp_inpcb *inp;
7433 struct sctp_ifa *sctp_ifa;
7436 * Do the malloc first in case it blocks.
7438 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7441 sin->sin_family = AF_INET;
7442 sin->sin_len = sizeof(*sin);
7443 inp = (struct sctp_inpcb *)so->so_pcb;
7445 SCTP_FREE_SONAME(sin);
7446 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7447 return (ECONNRESET);
7449 SCTP_INP_RLOCK(inp);
7450 sin->sin_port = inp->sctp_lport;
7451 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7452 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7453 struct sctp_tcb *stcb;
7454 struct sockaddr_in *sin_a;
7455 struct sctp_nets *net;
7458 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7464 SCTP_TCB_LOCK(stcb);
7465 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7466 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7468 /* this will make coverity happy */
7471 if (sin_a->sin_family == AF_INET) {
7476 if ((!fnd) || (sin_a == NULL)) {
7478 SCTP_TCB_UNLOCK(stcb);
7482 vrf_id = inp->def_vrf_id;
7483 sctp_ifa = sctp_source_address_selection(inp,
7485 (sctp_route_t *)&net->ro,
7488 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7489 sctp_free_ifa(sctp_ifa);
7491 SCTP_TCB_UNLOCK(stcb);
7493 /* For the bound all case you get back 0 */
7495 sin->sin_addr.s_addr = 0;
7499 /* Take the first IPv4 address in the list */
7500 struct sctp_laddr *laddr;
7503 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7504 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7505 struct sockaddr_in *sin_a;
7507 sin_a = &laddr->ifa->address.sin;
7508 sin->sin_addr = sin_a->sin_addr;
7514 SCTP_FREE_SONAME(sin);
7515 SCTP_INP_RUNLOCK(inp);
7516 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7520 SCTP_INP_RUNLOCK(inp);
7521 (*addr) = (struct sockaddr *)sin;
7526 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7528 struct sockaddr_in *sin;
7530 struct sockaddr_in *sin_a;
7531 struct sctp_inpcb *inp;
7532 struct sctp_tcb *stcb;
7533 struct sctp_nets *net;
7535 /* Do the malloc first in case it blocks. */
7536 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7539 sin->sin_family = AF_INET;
7540 sin->sin_len = sizeof(*sin);
7542 inp = (struct sctp_inpcb *)so->so_pcb;
7543 if ((inp == NULL) ||
7544 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7545 /* UDP type and listeners will drop out here */
7546 SCTP_FREE_SONAME(sin);
7547 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7550 SCTP_INP_RLOCK(inp);
7551 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7553 SCTP_TCB_LOCK(stcb);
7555 SCTP_INP_RUNLOCK(inp);
7557 SCTP_FREE_SONAME(sin);
7558 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7559 return (ECONNRESET);
7562 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7563 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7564 if (sin_a->sin_family == AF_INET) {
7566 sin->sin_port = stcb->rport;
7567 sin->sin_addr = sin_a->sin_addr;
7571 SCTP_TCB_UNLOCK(stcb);
7573 /* No IPv4 address */
7574 SCTP_FREE_SONAME(sin);
7575 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7578 (*addr) = (struct sockaddr *)sin;
7582 struct pr_usrreqs sctp_usrreqs = {
7583 .pru_abort = sctp_abort,
7584 .pru_accept = sctp_accept,
7585 .pru_attach = sctp_attach,
7586 .pru_bind = sctp_bind,
7587 .pru_connect = sctp_connect,
7588 .pru_control = in_control,
7589 .pru_close = sctp_close,
7590 .pru_detach = sctp_close,
7591 .pru_sopoll = sopoll_generic,
7592 .pru_flush = sctp_flush,
7593 .pru_disconnect = sctp_disconnect,
7594 .pru_listen = sctp_listen,
7595 .pru_peeraddr = sctp_peeraddr,
7596 .pru_send = sctp_sendm,
7597 .pru_shutdown = sctp_shutdown,
7598 .pru_sockaddr = sctp_ingetaddr,
7599 .pru_sosend = sctp_sosend,
7600 .pru_soreceive = sctp_soreceive