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>
58 extern const struct sctp_cc_functions sctp_cc_functions[];
59 extern const struct sctp_ss_functions sctp_ss_functions[];
66 /* Initialize and modify the sysctled variables */
68 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
69 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
71 * Allow a user to take no more than 1/2 the number of clusters or
72 * the SB_MAX, whichever is smaller, for the send window.
74 sb_max_adj = (u_long)((u_quad_t)(SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
75 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
76 (((uint32_t)nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
78 * Now for the recv window, should we take the same amount? or
79 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
80 * now I will just copy.
82 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
83 SCTP_BASE_VAR(first_time) = 0;
84 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
86 #if defined(SCTP_PACKET_LOGGING)
87 SCTP_BASE_VAR(packet_log_writers) = 0;
88 SCTP_BASE_VAR(packet_log_end) = 0;
89 memset(&SCTP_BASE_VAR(packet_log_buffer), 0, SCTP_PACKET_LOG_SIZE);
91 SCTP_BASE_VAR(eh_tag) = EVENTHANDLER_REGISTER(rt_addrmsg,
92 sctp_addr_change_event_handler, NULL, EVENTHANDLER_PRI_FIRST);
97 sctp_finish(void *unused __unused)
99 EVENTHANDLER_DEREGISTER(rt_addrmsg, SCTP_BASE_VAR(eh_tag));
103 VNET_SYSUNINIT(sctp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, sctp_finish, NULL);
107 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
109 struct sctp_tmit_chunk *chk;
112 /* Adjust that too */
113 stcb->asoc.smallest_mtu = nxtsz;
114 /* now off to subtract IP_DF flag if needed */
115 overhead = IP_HDR_SIZE + sizeof(struct sctphdr);
116 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
117 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
119 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
120 if ((chk->send_size + overhead) > nxtsz) {
121 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
124 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
125 if ((chk->send_size + overhead) > nxtsz) {
127 * For this guy we also mark for immediate resend
128 * since we sent to big of chunk
130 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
131 if (chk->sent < SCTP_DATAGRAM_RESEND) {
132 sctp_flight_size_decrease(chk);
133 sctp_total_flight_decrease(stcb, chk);
134 chk->sent = SCTP_DATAGRAM_RESEND;
135 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
136 chk->rec.data.doing_fast_retransmit = 0;
137 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
138 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
139 chk->whoTo->flight_size,
141 (uint32_t)(uintptr_t)chk->whoTo,
144 /* Clear any time so NO RTT is being done */
145 if (chk->do_rtt == 1) {
147 chk->whoTo->rto_needed = 1;
156 sctp_notify(struct sctp_inpcb *inp,
157 struct sctp_tcb *stcb,
158 struct sctp_nets *net,
166 if (icmp_type != ICMP_UNREACH) {
167 /* We only care about unreachable */
168 SCTP_TCB_UNLOCK(stcb);
171 if ((icmp_code == ICMP_UNREACH_NET) ||
172 (icmp_code == ICMP_UNREACH_HOST) ||
173 (icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
174 (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
175 (icmp_code == ICMP_UNREACH_ISOLATED) ||
176 (icmp_code == ICMP_UNREACH_NET_PROHIB) ||
177 (icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
178 (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
179 /* Mark the net unreachable. */
180 if (net->dest_state & SCTP_ADDR_REACHABLE) {
181 /* OK, that destination is NOT reachable. */
182 net->dest_state &= ~SCTP_ADDR_REACHABLE;
183 net->dest_state &= ~SCTP_ADDR_PF;
184 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
186 (void *)net, SCTP_SO_NOT_LOCKED);
188 SCTP_TCB_UNLOCK(stcb);
189 } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) ||
190 (icmp_code == ICMP_UNREACH_PORT)) {
191 /* Treat it like an ABORT. */
192 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
193 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
194 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
195 /* no need to unlock here, since the TCB is gone */
196 } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) {
197 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
198 SCTP_TCB_UNLOCK(stcb);
201 /* Find the next (smaller) MTU */
204 * Old type router that does not tell us what the
205 * next MTU is. Rats we will have to guess (in a
206 * educated fashion of course).
208 next_mtu = sctp_get_prev_mtu(ip_len);
210 /* Stop the PMTU timer. */
211 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
213 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
214 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
218 /* Update the path MTU. */
220 next_mtu -= sizeof(struct udphdr);
222 if (net->mtu > next_mtu) {
225 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu + sizeof(struct udphdr));
227 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu);
230 /* Update the association MTU */
231 if (stcb->asoc.smallest_mtu > next_mtu) {
232 sctp_pathmtu_adjustment(stcb, next_mtu);
234 /* Finally, start the PMTU timer if it was running before. */
236 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
238 SCTP_TCB_UNLOCK(stcb);
240 SCTP_TCB_UNLOCK(stcb);
245 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
251 struct sctp_inpcb *inp;
252 struct sctp_tcb *stcb;
253 struct sctp_nets *net;
254 struct sctp_init_chunk *ch;
255 struct sockaddr_in src, dst;
257 if (sa->sa_family != AF_INET ||
258 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
261 if (PRC_IS_REDIRECT(cmd)) {
263 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
267 inner_ip = (struct ip *)vip;
268 icmp = (struct icmp *)((caddr_t)inner_ip -
269 (sizeof(struct icmp) - sizeof(struct ip)));
270 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
271 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
272 memset(&src, 0, sizeof(struct sockaddr_in));
273 src.sin_family = AF_INET;
274 src.sin_len = sizeof(struct sockaddr_in);
275 src.sin_port = sh->src_port;
276 src.sin_addr = inner_ip->ip_src;
277 memset(&dst, 0, sizeof(struct sockaddr_in));
278 dst.sin_family = AF_INET;
279 dst.sin_len = sizeof(struct sockaddr_in);
280 dst.sin_port = sh->dest_port;
281 dst.sin_addr = inner_ip->ip_dst;
283 * 'dst' holds the dest of the packet that failed to be
284 * sent. 'src' holds our local endpoint address. Thus we
285 * reverse the dst and the src in the lookup.
289 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
290 (struct sockaddr *)&src,
293 if ((stcb != NULL) &&
296 /* Check the verification tag */
297 if (ntohl(sh->v_tag) != 0) {
299 * This must be the verification tag used
300 * for sending out packets. We don't
301 * consider packets reflecting the
304 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
305 SCTP_TCB_UNLOCK(stcb);
309 if (ntohs(outer_ip->ip_len) >=
311 8 + (inner_ip->ip_hl << 2) + 20) {
313 * In this case we can check if we
314 * got an INIT chunk and if the
315 * initiate tag matches.
317 ch = (struct sctp_init_chunk *)(sh + 1);
318 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
319 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
320 SCTP_TCB_UNLOCK(stcb);
324 SCTP_TCB_UNLOCK(stcb);
328 sctp_notify(inp, stcb, net,
331 ntohs(inner_ip->ip_len),
332 (uint32_t)ntohs(icmp->icmp_nextmtu));
334 if ((stcb == NULL) && (inp != NULL)) {
335 /* reduce ref-count */
337 SCTP_INP_DECR_REF(inp);
338 SCTP_INP_WUNLOCK(inp);
341 SCTP_TCB_UNLOCK(stcb);
350 sctp_getcred(SYSCTL_HANDLER_ARGS)
353 struct sockaddr_in addrs[2];
354 struct sctp_inpcb *inp;
355 struct sctp_nets *net;
356 struct sctp_tcb *stcb;
360 /* FIX, for non-bsd is this right? */
361 vrf_id = SCTP_DEFAULT_VRFID;
363 error = priv_check(req->td, PRIV_NETINET_GETCRED);
368 error = SYSCTL_IN(req, addrs, sizeof(addrs));
372 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
374 &inp, &net, 1, vrf_id);
375 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
376 if ((inp != NULL) && (stcb == NULL)) {
377 /* reduce ref-count */
379 SCTP_INP_DECR_REF(inp);
383 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
387 SCTP_TCB_UNLOCK(stcb);
389 * We use the write lock here, only since in the error leg we need
390 * it. If we used RLOCK, then we would have to
391 * wlock/decr/unlock/rlock. Which in theory could create a hole.
392 * Better to use higher wlock.
396 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
398 SCTP_INP_WUNLOCK(inp);
401 cru2x(inp->sctp_socket->so_cred, &xuc);
402 SCTP_INP_WUNLOCK(inp);
403 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
408 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred,
409 CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
410 0, 0, sctp_getcred, "S,ucred",
411 "Get the ucred of a SCTP connection");
415 sctp_abort(struct socket *so)
417 struct epoch_tracker et;
418 struct sctp_inpcb *inp;
421 inp = (struct sctp_inpcb *)so->so_pcb;
428 flags = inp->sctp_flags;
429 #ifdef SCTP_LOG_CLOSING
430 sctp_log_closing(inp, NULL, 17);
432 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
433 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
434 #ifdef SCTP_LOG_CLOSING
435 sctp_log_closing(inp, NULL, 16);
437 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
438 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
440 SCTP_SB_CLEAR(so->so_snd);
442 * same for the rcv ones, they are only here for the
445 SCTP_SB_CLEAR(so->so_rcv);
447 /* Now null out the reference, we are completely detached. */
451 flags = inp->sctp_flags;
452 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
453 goto sctp_must_try_again;
461 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
463 struct sctp_inpcb *inp;
464 struct inpcb *ip_inp;
466 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
468 inp = (struct sctp_inpcb *)so->so_pcb;
470 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
473 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
474 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
479 error = sctp_inpcb_alloc(so, vrf_id);
483 inp = (struct sctp_inpcb *)so->so_pcb;
485 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
486 ip_inp = &inp->ip_inp.inp;
487 ip_inp->inp_vflag |= INP_IPV4;
488 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
489 SCTP_INP_WUNLOCK(inp);
494 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
496 struct sctp_inpcb *inp;
498 inp = (struct sctp_inpcb *)so->so_pcb;
500 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
504 if ((addr->sa_family != AF_INET) ||
505 (addr->sa_len != sizeof(struct sockaddr_in))) {
506 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
510 return (sctp_inpcb_bind(so, addr, NULL, p));
515 sctp_close(struct socket *so)
517 struct epoch_tracker et;
518 struct sctp_inpcb *inp;
521 inp = (struct sctp_inpcb *)so->so_pcb;
526 * Inform all the lower layer assoc that we are done.
530 flags = inp->sctp_flags;
531 #ifdef SCTP_LOG_CLOSING
532 sctp_log_closing(inp, NULL, 17);
534 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
535 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
536 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
537 (so->so_rcv.sb_cc > 0)) {
538 #ifdef SCTP_LOG_CLOSING
539 sctp_log_closing(inp, NULL, 13);
541 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
542 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
544 #ifdef SCTP_LOG_CLOSING
545 sctp_log_closing(inp, NULL, 14);
547 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
548 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
551 * The socket is now detached, no matter what the state of
552 * the SCTP association.
555 SCTP_SB_CLEAR(so->so_snd);
557 * same for the rcv ones, they are only here for the
560 SCTP_SB_CLEAR(so->so_rcv);
562 /* Now null out the reference, we are completely detached. */
566 flags = inp->sctp_flags;
567 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
568 goto sctp_must_try_again;
576 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
577 struct mbuf *control, struct thread *p);
580 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
581 struct mbuf *control, struct thread *p)
583 struct sctp_inpcb *inp;
586 inp = (struct sctp_inpcb *)so->so_pcb;
589 sctp_m_freem(control);
592 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
596 /* Got to have an to address if we are NOT a connected socket */
597 if ((addr == NULL) &&
598 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
599 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
601 } else if (addr == NULL) {
602 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
603 error = EDESTADDRREQ;
606 sctp_m_freem(control);
612 if (addr->sa_family != AF_INET) {
613 /* must be a v4 address! */
614 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
617 sctp_m_freem(control);
620 error = EDESTADDRREQ;
625 /* now what about control */
628 sctp_m_freem(inp->control);
631 inp->control = control;
635 SCTP_BUF_NEXT(inp->pkt_last) = m;
638 inp->pkt_last = inp->pkt = m;
641 /* FreeBSD uses a flag passed */
642 ((flags & PRUS_MORETOCOME) == 0)
645 * note with the current version this code will only be used
646 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
647 * re-defining sosend to use the sctp_sosend. One can
648 * optionally switch back to this code (by changing back the
649 * definitions) but this is not advisable. This code is used
650 * by FreeBSD when sending a file with sendfile() though.
652 struct epoch_tracker et;
656 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
667 sctp_disconnect(struct socket *so)
669 struct sctp_inpcb *inp;
671 inp = (struct sctp_inpcb *)so->so_pcb;
673 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
677 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
678 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
679 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
681 SCTP_INP_RUNLOCK(inp);
684 struct epoch_tracker et;
685 struct sctp_association *asoc;
686 struct sctp_tcb *stcb;
688 stcb = LIST_FIRST(&inp->sctp_asoc_list);
690 SCTP_INP_RUNLOCK(inp);
691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
696 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
697 /* We are about to be freed, out of here */
698 SCTP_TCB_UNLOCK(stcb);
699 SCTP_INP_RUNLOCK(inp);
703 if (((so->so_options & SO_LINGER) &&
704 (so->so_linger == 0)) ||
705 (so->so_rcv.sb_cc > 0)) {
706 if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) {
707 /* Left with Data unread */
710 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
711 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
712 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
714 SCTP_INP_RUNLOCK(inp);
715 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
716 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
717 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
719 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
720 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
721 /* No unlock tcb assoc is gone */
725 if (TAILQ_EMPTY(&asoc->send_queue) &&
726 TAILQ_EMPTY(&asoc->sent_queue) &&
727 (asoc->stream_queue_cnt == 0)) {
728 /* there is nothing queued to send, so done */
729 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
732 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) &&
733 (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
734 /* only send SHUTDOWN 1st time thru */
735 struct sctp_nets *netp;
737 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
738 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
739 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
741 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
742 sctp_stop_timers_for_shutdown(stcb);
743 if (stcb->asoc.alternate) {
744 netp = stcb->asoc.alternate;
746 netp = stcb->asoc.primary_destination;
748 sctp_send_shutdown(stcb, netp);
749 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
750 stcb->sctp_ep, stcb, netp);
751 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
752 stcb->sctp_ep, stcb, NULL);
753 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
757 * we still got (or just got) data to send,
758 * so set SHUTDOWN_PENDING
761 * XXX sockets draft says that SCTP_EOF
762 * should be sent with no data. currently,
763 * we will allow user data to be sent first
764 * and move to SHUTDOWN-PENDING
766 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
767 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
768 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
769 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
771 if (TAILQ_EMPTY(&asoc->send_queue) &&
772 TAILQ_EMPTY(&asoc->sent_queue) &&
773 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
777 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
778 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
779 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
780 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
781 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
782 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
783 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
785 SCTP_INP_RUNLOCK(inp);
786 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
787 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
791 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
794 soisdisconnecting(so);
796 SCTP_TCB_UNLOCK(stcb);
797 SCTP_INP_RUNLOCK(inp);
802 /* UDP model does not support this */
803 SCTP_INP_RUNLOCK(inp);
804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
810 sctp_flush(struct socket *so, int how)
813 * We will just clear out the values and let subsequent close clear
814 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
815 * they will not be able to read the data, the socket will block
816 * that from happening.
818 struct sctp_inpcb *inp;
820 inp = (struct sctp_inpcb *)so->so_pcb;
822 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
826 /* For the 1 to many model this does nothing */
827 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
828 SCTP_INP_RUNLOCK(inp);
831 SCTP_INP_RUNLOCK(inp);
832 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
834 * First make sure the sb will be happy, we don't use these
835 * except maybe the count
838 SCTP_INP_READ_LOCK(inp);
839 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
840 SCTP_INP_READ_UNLOCK(inp);
841 SCTP_INP_WUNLOCK(inp);
842 so->so_rcv.sb_cc = 0;
843 so->so_rcv.sb_mbcnt = 0;
844 so->so_rcv.sb_mb = NULL;
846 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
848 * First make sure the sb will be happy, we don't use these
849 * except maybe the count
851 so->so_snd.sb_cc = 0;
852 so->so_snd.sb_mbcnt = 0;
853 so->so_snd.sb_mb = NULL;
859 sctp_shutdown(struct socket *so)
861 struct sctp_inpcb *inp;
863 inp = (struct sctp_inpcb *)so->so_pcb;
865 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
869 /* For UDP model this is a invalid call */
870 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
871 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
872 /* Restore the flags that the soshutdown took away. */
873 SOCKBUF_LOCK(&so->so_rcv);
874 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
875 SOCKBUF_UNLOCK(&so->so_rcv);
876 /* This proc will wakeup for read and do nothing (I hope) */
877 SCTP_INP_RUNLOCK(inp);
878 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
882 * Ok, if we reach here its the TCP model and it is either a
883 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
886 struct epoch_tracker et;
887 struct sctp_tcb *stcb;
888 struct sctp_association *asoc;
889 struct sctp_nets *netp;
892 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
893 SCTP_INP_RUNLOCK(inp);
898 stcb = LIST_FIRST(&inp->sctp_asoc_list);
901 * Ok, we hit the case that the shutdown call was
902 * made after an abort or something. Nothing to do
905 SCTP_INP_RUNLOCK(inp);
910 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
911 SCTP_TCB_UNLOCK(stcb);
912 SCTP_INP_RUNLOCK(inp);
915 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) &&
916 (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) &&
917 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) {
919 * If we are not in or before ESTABLISHED, there is
920 * no protocol action required.
922 SCTP_TCB_UNLOCK(stcb);
923 SCTP_INP_RUNLOCK(inp);
927 if (stcb->asoc.alternate) {
928 netp = stcb->asoc.alternate;
930 netp = stcb->asoc.primary_destination;
932 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) &&
933 TAILQ_EMPTY(&asoc->send_queue) &&
934 TAILQ_EMPTY(&asoc->sent_queue) &&
935 (asoc->stream_queue_cnt == 0)) {
936 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
939 /* there is nothing queued to send, so I'm done... */
940 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
941 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
942 sctp_stop_timers_for_shutdown(stcb);
943 sctp_send_shutdown(stcb, netp);
944 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
945 stcb->sctp_ep, stcb, netp);
948 * We still got (or just got) data to send, so set
951 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
952 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
953 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
955 if (TAILQ_EMPTY(&asoc->send_queue) &&
956 TAILQ_EMPTY(&asoc->sent_queue) &&
957 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
961 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
962 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
963 SCTP_INP_RUNLOCK(inp);
964 sctp_abort_an_association(stcb->sctp_ep, stcb,
965 op_err, SCTP_SO_LOCKED);
970 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
972 * XXX: Why do this in the case where we have still data
975 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
976 SCTP_TCB_UNLOCK(stcb);
977 SCTP_INP_RUNLOCK(inp);
984 * copies a "user" presentable address and removes embedded scope, etc.
985 * returns 0 on success, 1 on error
988 sctp_fill_user_address(struct sockaddr *dst, struct sockaddr *src)
991 struct sockaddr_in6 lsa6;
993 src = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)src,
996 memcpy(dst, src, src->sa_len);
1001 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1002 struct sctp_tcb *stcb,
1004 struct sockaddr *addr,
1007 struct sctp_ifn *sctp_ifn;
1008 struct sctp_ifa *sctp_ifa;
1012 int ipv4_local_scope, ipv4_addr_legal;
1015 int local_scope, site_scope, ipv6_addr_legal;
1017 struct sctp_vrf *vrf;
1019 SCTP_IPI_ADDR_LOCK_ASSERT();
1025 /* Turn on all the appropriate scope */
1026 loopback_scope = stcb->asoc.scope.loopback_scope;
1028 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1029 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1032 local_scope = stcb->asoc.scope.local_scope;
1033 site_scope = stcb->asoc.scope.site_scope;
1034 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1037 /* Use generic values for endpoints. */
1040 ipv4_local_scope = 1;
1046 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1048 ipv6_addr_legal = 1;
1051 if (SCTP_IPV6_V6ONLY(inp)) {
1052 ipv4_addr_legal = 0;
1054 ipv4_addr_legal = 1;
1059 ipv6_addr_legal = 0;
1062 ipv4_addr_legal = 1;
1066 vrf = sctp_find_vrf(vrf_id);
1070 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1071 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1072 if ((loopback_scope == 0) &&
1073 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1074 /* Skip loopback if loopback_scope not set */
1077 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1080 * For the BOUND-ALL case, the list
1081 * associated with a TCB is Always
1082 * considered a reverse list.. i.e.
1083 * it lists addresses that are NOT
1084 * part of the association. If this
1085 * is one of those we must skip it.
1087 if (sctp_is_addr_restricted(stcb,
1092 switch (sctp_ifa->address.sa.sa_family) {
1095 if (ipv4_addr_legal) {
1096 struct sockaddr_in *sin;
1098 sin = &sctp_ifa->address.sin;
1099 if (sin->sin_addr.s_addr == 0) {
1107 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1108 &sin->sin_addr) != 0) {
1111 if ((ipv4_local_scope == 0) &&
1112 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1116 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1117 if (actual + sizeof(struct sockaddr_in6) > limit) {
1120 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)addr);
1121 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1122 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1123 actual += sizeof(struct sockaddr_in6);
1126 if (actual + sizeof(struct sockaddr_in) > limit) {
1129 memcpy(addr, sin, sizeof(struct sockaddr_in));
1130 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1131 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in));
1132 actual += sizeof(struct sockaddr_in);
1143 if (ipv6_addr_legal) {
1144 struct sockaddr_in6 *sin6;
1146 sin6 = &sctp_ifa->address.sin6;
1147 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1155 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1156 &sin6->sin6_addr) != 0) {
1159 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1160 if (local_scope == 0)
1162 if (sin6->sin6_scope_id == 0) {
1163 if (sa6_recoverscope(sin6) != 0)
1176 if ((site_scope == 0) &&
1177 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1180 if (actual + sizeof(struct sockaddr_in6) > limit) {
1183 memcpy(addr, sin6, sizeof(struct sockaddr_in6));
1184 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1185 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1186 actual += sizeof(struct sockaddr_in6);
1199 struct sctp_laddr *laddr;
1202 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1204 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1208 sa_len = laddr->ifa->address.sa.sa_len;
1209 if (actual + sa_len > limit) {
1212 if (sctp_fill_user_address(addr, &laddr->ifa->address.sa))
1214 switch (laddr->ifa->address.sa.sa_family) {
1217 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1222 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1229 addr = (struct sockaddr *)((caddr_t)addr + sa_len);
1237 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1238 struct sctp_tcb *stcb,
1240 struct sockaddr *addr)
1244 SCTP_IPI_ADDR_RLOCK();
1245 /* fill up addresses for the endpoint's default vrf */
1246 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, addr,
1248 SCTP_IPI_ADDR_RUNLOCK();
1253 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1256 struct sctp_vrf *vrf = NULL;
1259 * In both sub-set bound an bound_all cases we return the MAXIMUM
1260 * number of addresses that you COULD get. In reality the sub-set
1261 * bound may have an exclusion list for a given TCB OR in the
1262 * bound-all case a TCB may NOT include the loopback or other
1263 * addresses as well.
1265 SCTP_IPI_ADDR_LOCK_ASSERT();
1266 vrf = sctp_find_vrf(vrf_id);
1270 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1271 struct sctp_ifn *sctp_ifn;
1272 struct sctp_ifa *sctp_ifa;
1274 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1275 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1276 /* Count them if they are the right type */
1277 switch (sctp_ifa->address.sa.sa_family) {
1281 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1282 cnt += sizeof(struct sockaddr_in6);
1284 cnt += sizeof(struct sockaddr_in);
1286 cnt += sizeof(struct sockaddr_in);
1292 cnt += sizeof(struct sockaddr_in6);
1301 struct sctp_laddr *laddr;
1303 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1304 switch (laddr->ifa->address.sa.sa_family) {
1308 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1309 cnt += sizeof(struct sockaddr_in6);
1311 cnt += sizeof(struct sockaddr_in);
1313 cnt += sizeof(struct sockaddr_in);
1319 cnt += sizeof(struct sockaddr_in6);
1331 sctp_count_max_addresses(struct sctp_inpcb *inp)
1335 SCTP_IPI_ADDR_RLOCK();
1336 /* count addresses for the endpoint's default VRF */
1337 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1338 SCTP_IPI_ADDR_RUNLOCK();
1343 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1344 size_t optsize, void *p, int delay)
1347 int creat_lock_on = 0;
1348 struct sctp_tcb *stcb = NULL;
1349 struct sockaddr *sa;
1350 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1354 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1356 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1357 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1358 /* We are already connected AND the TCP model */
1359 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1360 return (EADDRINUSE);
1363 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1364 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1365 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1369 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1370 SCTP_INP_RLOCK(inp);
1371 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1372 SCTP_INP_RUNLOCK(inp);
1375 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1378 SCTP_INP_INCR_REF(inp);
1379 SCTP_ASOC_CREATE_LOCK(inp);
1381 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1382 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1383 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1387 totaddrp = (unsigned int *)optval;
1388 totaddr = *totaddrp;
1389 sa = (struct sockaddr *)(totaddrp + 1);
1390 error = sctp_connectx_helper_find(inp, sa, totaddr, &num_v4, &num_v6, (unsigned int)(optsize - sizeof(int)));
1392 /* Already have or am bring up an association */
1393 SCTP_ASOC_CREATE_UNLOCK(inp);
1395 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1399 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1404 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1406 if (SCTP_IPV6_V6ONLY(inp)) {
1408 * if IPV6_V6ONLY flag, ignore connections destined
1409 * to a v4 addr or v4-mapped addr
1411 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1417 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1418 SCTP_PCB_FLAGS_UNBOUND) {
1419 /* Bind a ephemeral port */
1420 error = sctp_inpcb_bind(so, NULL, NULL, p);
1426 /* FIX ME: do we want to pass in a vrf on the connect call? */
1427 vrf_id = inp->def_vrf_id;
1429 /* We are GOOD to go */
1430 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1431 inp->sctp_ep.pre_open_stream_count,
1434 SCTP_INITIALIZE_AUTH_PARAMS);
1436 /* Gak! no memory */
1439 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1440 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1441 /* Set the connected flag so we can queue data */
1444 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1445 /* move to second address */
1446 switch (sa->sa_family) {
1449 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1454 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1462 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1463 /* Fill in the return id */
1467 a_id = (sctp_assoc_t *)optval;
1468 *a_id = sctp_get_associd(stcb);
1471 /* doing delayed connection */
1472 stcb->asoc.delayed_connection = 1;
1473 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1475 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1476 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1478 SCTP_TCB_UNLOCK(stcb);
1480 if (creat_lock_on) {
1481 SCTP_ASOC_CREATE_UNLOCK(inp);
1483 SCTP_INP_DECR_REF(inp);
1487 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1488 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1489 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1490 SCTP_INP_RLOCK(inp); \
1491 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1493 SCTP_TCB_LOCK(stcb); \
1495 SCTP_INP_RUNLOCK(inp); \
1496 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1497 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1498 if (stcb == NULL) { \
1499 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1508 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1509 if (size < sizeof(type)) { \
1510 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1514 destp = (type *)srcp; \
1519 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1522 struct sctp_inpcb *inp = NULL;
1524 struct sctp_tcb *stcb = NULL;
1526 if (optval == NULL) {
1527 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1531 inp = (struct sctp_inpcb *)so->so_pcb;
1533 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1540 case SCTP_AUTOCLOSE:
1541 case SCTP_EXPLICIT_EOR:
1542 case SCTP_AUTO_ASCONF:
1543 case SCTP_DISABLE_FRAGMENTS:
1544 case SCTP_I_WANT_MAPPED_V4_ADDR:
1545 case SCTP_USE_EXT_RCVINFO:
1546 SCTP_INP_RLOCK(inp);
1548 case SCTP_DISABLE_FRAGMENTS:
1549 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1551 case SCTP_I_WANT_MAPPED_V4_ADDR:
1552 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1554 case SCTP_AUTO_ASCONF:
1555 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1556 /* only valid for bound all sockets */
1557 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1559 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1564 case SCTP_EXPLICIT_EOR:
1565 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1568 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1570 case SCTP_USE_EXT_RCVINFO:
1571 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1573 case SCTP_AUTOCLOSE:
1574 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1575 val = sctp_ticks_to_secs(inp->sctp_ep.auto_close_time);
1581 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1582 error = ENOPROTOOPT;
1583 } /* end switch (sopt->sopt_name) */
1584 if (*optsize < sizeof(val)) {
1585 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1589 SCTP_INP_RUNLOCK(inp);
1591 /* return the option value */
1592 *(int *)optval = val;
1593 *optsize = sizeof(val);
1596 case SCTP_GET_PACKET_LOG:
1598 #ifdef SCTP_PACKET_LOGGING
1602 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1603 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1606 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1611 case SCTP_REUSE_PORT:
1615 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1616 /* Can't do this for a 1-m socket */
1620 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1621 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1622 *optsize = sizeof(uint32_t);
1625 case SCTP_PARTIAL_DELIVERY_POINT:
1629 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1630 *value = inp->partial_delivery_point;
1631 *optsize = sizeof(uint32_t);
1634 case SCTP_FRAGMENT_INTERLEAVE:
1638 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1639 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1640 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1641 *value = SCTP_FRAG_LEVEL_2;
1643 *value = SCTP_FRAG_LEVEL_1;
1646 *value = SCTP_FRAG_LEVEL_0;
1648 *optsize = sizeof(uint32_t);
1651 case SCTP_INTERLEAVING_SUPPORTED:
1653 struct sctp_assoc_value *av;
1655 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1656 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1659 av->assoc_value = stcb->asoc.idata_supported;
1660 SCTP_TCB_UNLOCK(stcb);
1662 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1663 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1664 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1665 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1666 SCTP_INP_RLOCK(inp);
1667 if (inp->idata_supported) {
1668 av->assoc_value = 1;
1670 av->assoc_value = 0;
1672 SCTP_INP_RUNLOCK(inp);
1674 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1679 *optsize = sizeof(struct sctp_assoc_value);
1683 case SCTP_CMT_ON_OFF:
1685 struct sctp_assoc_value *av;
1687 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1688 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1690 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1691 SCTP_TCB_UNLOCK(stcb);
1693 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1694 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1695 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1696 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1697 SCTP_INP_RLOCK(inp);
1698 av->assoc_value = inp->sctp_cmt_on_off;
1699 SCTP_INP_RUNLOCK(inp);
1701 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1706 *optsize = sizeof(struct sctp_assoc_value);
1710 case SCTP_PLUGGABLE_CC:
1712 struct sctp_assoc_value *av;
1714 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1715 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1717 av->assoc_value = stcb->asoc.congestion_control_module;
1718 SCTP_TCB_UNLOCK(stcb);
1720 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1721 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1722 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1723 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1724 SCTP_INP_RLOCK(inp);
1725 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1726 SCTP_INP_RUNLOCK(inp);
1728 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1733 *optsize = sizeof(struct sctp_assoc_value);
1737 case SCTP_CC_OPTION:
1739 struct sctp_cc_option *cc_opt;
1741 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1742 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1746 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1749 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1750 *optsize = sizeof(struct sctp_cc_option);
1752 SCTP_TCB_UNLOCK(stcb);
1756 case SCTP_PLUGGABLE_SS:
1758 struct sctp_assoc_value *av;
1760 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1761 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1763 av->assoc_value = stcb->asoc.stream_scheduling_module;
1764 SCTP_TCB_UNLOCK(stcb);
1766 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1767 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1768 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1769 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1770 SCTP_INP_RLOCK(inp);
1771 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1772 SCTP_INP_RUNLOCK(inp);
1774 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1779 *optsize = sizeof(struct sctp_assoc_value);
1785 struct sctp_stream_value *av;
1787 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1788 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1790 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1791 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1792 &av->stream_value) < 0)) {
1793 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1796 *optsize = sizeof(struct sctp_stream_value);
1798 SCTP_TCB_UNLOCK(stcb);
1801 * Can't get stream value without
1804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1809 case SCTP_GET_ADDR_LEN:
1811 struct sctp_assoc_value *av;
1813 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1816 if (av->assoc_value == AF_INET) {
1817 av->assoc_value = sizeof(struct sockaddr_in);
1822 if (av->assoc_value == AF_INET6) {
1823 av->assoc_value = sizeof(struct sockaddr_in6);
1828 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1830 *optsize = sizeof(struct sctp_assoc_value);
1834 case SCTP_GET_ASSOC_NUMBER:
1836 uint32_t *value, cnt;
1838 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1839 SCTP_INP_RLOCK(inp);
1840 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1841 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1842 /* Can't do this for a 1-1 socket */
1844 SCTP_INP_RUNLOCK(inp);
1848 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1851 SCTP_INP_RUNLOCK(inp);
1853 *optsize = sizeof(uint32_t);
1856 case SCTP_GET_ASSOC_ID_LIST:
1858 struct sctp_assoc_ids *ids;
1862 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1863 SCTP_INP_RLOCK(inp);
1864 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1865 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1866 /* Can't do this for a 1-1 socket */
1868 SCTP_INP_RUNLOCK(inp);
1872 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1873 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1875 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1878 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1883 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1887 SCTP_INP_RUNLOCK(inp);
1889 ids->gaids_number_of_ids = at;
1890 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1896 struct sctp_assoc_value *av;
1898 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1899 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1902 av->assoc_value = stcb->asoc.context;
1903 SCTP_TCB_UNLOCK(stcb);
1905 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1906 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1907 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1908 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1909 SCTP_INP_RLOCK(inp);
1910 av->assoc_value = inp->sctp_context;
1911 SCTP_INP_RUNLOCK(inp);
1913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1918 *optsize = sizeof(struct sctp_assoc_value);
1924 uint32_t *default_vrfid;
1926 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1927 *default_vrfid = inp->def_vrf_id;
1928 *optsize = sizeof(uint32_t);
1931 case SCTP_GET_ASOC_VRF:
1933 struct sctp_assoc_value *id;
1935 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1936 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1941 id->assoc_value = stcb->asoc.vrf_id;
1942 SCTP_TCB_UNLOCK(stcb);
1943 *optsize = sizeof(struct sctp_assoc_value);
1947 case SCTP_GET_VRF_IDS:
1949 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1953 case SCTP_GET_NONCE_VALUES:
1955 struct sctp_get_nonce_values *gnv;
1957 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1958 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1961 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1962 gnv->gn_local_tag = stcb->asoc.my_vtag;
1963 SCTP_TCB_UNLOCK(stcb);
1964 *optsize = sizeof(struct sctp_get_nonce_values);
1966 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1971 case SCTP_DELAYED_SACK:
1973 struct sctp_sack_info *sack;
1975 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1976 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1978 sack->sack_delay = stcb->asoc.delayed_ack;
1979 sack->sack_freq = stcb->asoc.sack_freq;
1980 SCTP_TCB_UNLOCK(stcb);
1982 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1983 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1984 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1985 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC))) {
1986 SCTP_INP_RLOCK(inp);
1987 sack->sack_delay = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1988 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
1989 SCTP_INP_RUNLOCK(inp);
1991 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1996 *optsize = sizeof(struct sctp_sack_info);
2000 case SCTP_GET_SNDBUF_USE:
2002 struct sctp_sockstat *ss;
2004 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2005 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2008 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2009 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2010 stcb->asoc.size_on_all_streams);
2011 SCTP_TCB_UNLOCK(stcb);
2012 *optsize = sizeof(struct sctp_sockstat);
2014 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2019 case SCTP_MAX_BURST:
2021 struct sctp_assoc_value *av;
2023 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2024 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2027 av->assoc_value = stcb->asoc.max_burst;
2028 SCTP_TCB_UNLOCK(stcb);
2030 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2031 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2032 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2033 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2034 SCTP_INP_RLOCK(inp);
2035 av->assoc_value = inp->sctp_ep.max_burst;
2036 SCTP_INP_RUNLOCK(inp);
2038 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2043 *optsize = sizeof(struct sctp_assoc_value);
2049 struct sctp_assoc_value *av;
2052 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2053 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2056 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2057 SCTP_TCB_UNLOCK(stcb);
2059 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2060 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2061 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2062 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2063 SCTP_INP_RLOCK(inp);
2064 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2065 ovh = SCTP_MED_OVERHEAD;
2067 ovh = SCTP_MED_V4_OVERHEAD;
2069 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2070 av->assoc_value = 0;
2072 av->assoc_value = inp->sctp_frag_point - ovh;
2073 SCTP_INP_RUNLOCK(inp);
2075 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2080 *optsize = sizeof(struct sctp_assoc_value);
2084 case SCTP_GET_STAT_LOG:
2085 error = sctp_fill_stat_log(optval, optsize);
2089 struct sctp_event_subscribe *events;
2091 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2092 memset(events, 0, sizeof(struct sctp_event_subscribe));
2093 SCTP_INP_RLOCK(inp);
2094 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2095 events->sctp_data_io_event = 1;
2097 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2098 events->sctp_association_event = 1;
2100 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2101 events->sctp_address_event = 1;
2103 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2104 events->sctp_send_failure_event = 1;
2106 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2107 events->sctp_peer_error_event = 1;
2109 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2110 events->sctp_shutdown_event = 1;
2112 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2113 events->sctp_partial_delivery_event = 1;
2115 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2116 events->sctp_adaptation_layer_event = 1;
2118 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2119 events->sctp_authentication_event = 1;
2121 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2122 events->sctp_sender_dry_event = 1;
2124 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2125 events->sctp_stream_reset_event = 1;
2126 SCTP_INP_RUNLOCK(inp);
2127 *optsize = sizeof(struct sctp_event_subscribe);
2130 case SCTP_ADAPTATION_LAYER:
2134 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2136 SCTP_INP_RLOCK(inp);
2137 *value = inp->sctp_ep.adaptation_layer_indicator;
2138 SCTP_INP_RUNLOCK(inp);
2139 *optsize = sizeof(uint32_t);
2142 case SCTP_SET_INITIAL_DBG_SEQ:
2146 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2147 SCTP_INP_RLOCK(inp);
2148 *value = inp->sctp_ep.initial_sequence_debug;
2149 SCTP_INP_RUNLOCK(inp);
2150 *optsize = sizeof(uint32_t);
2153 case SCTP_GET_LOCAL_ADDR_SIZE:
2157 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2158 SCTP_INP_RLOCK(inp);
2159 *value = sctp_count_max_addresses(inp);
2160 SCTP_INP_RUNLOCK(inp);
2161 *optsize = sizeof(uint32_t);
2164 case SCTP_GET_REMOTE_ADDR_SIZE:
2168 struct sctp_nets *net;
2170 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2171 /* FIXME MT: change to sctp_assoc_value? */
2172 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2176 /* Count the sizes */
2177 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2178 switch (net->ro._l_addr.sa.sa_family) {
2182 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2183 size += sizeof(struct sockaddr_in6);
2185 size += sizeof(struct sockaddr_in);
2188 size += sizeof(struct sockaddr_in);
2194 size += sizeof(struct sockaddr_in6);
2201 SCTP_TCB_UNLOCK(stcb);
2202 *value = (uint32_t)size;
2203 *optsize = sizeof(uint32_t);
2205 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2210 case SCTP_GET_PEER_ADDRESSES:
2212 * Get the address information, an array is passed in to
2213 * fill up we pack it.
2217 struct sockaddr *addr;
2218 struct sctp_nets *net;
2219 struct sctp_getaddresses *saddr;
2221 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2222 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2225 left = *optsize - offsetof(struct sctp_getaddresses, addr);
2226 *optsize = offsetof(struct sctp_getaddresses, addr);
2227 addr = &saddr->addr[0].sa;
2229 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2230 switch (net->ro._l_addr.sa.sa_family) {
2234 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2235 cpsz = sizeof(struct sockaddr_in6);
2237 cpsz = sizeof(struct sockaddr_in);
2240 cpsz = sizeof(struct sockaddr_in);
2246 cpsz = sizeof(struct sockaddr_in6);
2257 /* not enough room. */
2260 #if defined(INET) && defined(INET6)
2261 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2262 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2263 /* Must map the address */
2264 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2265 (struct sockaddr_in6 *)addr);
2267 memcpy(addr, &net->ro._l_addr, cpsz);
2270 memcpy(addr, &net->ro._l_addr, cpsz);
2272 ((struct sockaddr_in *)addr)->sin_port = stcb->rport;
2274 addr = (struct sockaddr *)((caddr_t)addr + cpsz);
2278 SCTP_TCB_UNLOCK(stcb);
2280 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2285 case SCTP_GET_LOCAL_ADDRESSES:
2287 size_t limit, actual;
2288 struct sctp_getaddresses *saddr;
2290 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2291 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2293 limit = *optsize - offsetof(struct sctp_getaddresses, addr);
2294 actual = sctp_fill_up_addresses(inp, stcb, limit, &saddr->addr[0].sa);
2296 SCTP_TCB_UNLOCK(stcb);
2298 *optsize = offsetof(struct sctp_getaddresses, addr) + actual;
2301 case SCTP_PEER_ADDR_PARAMS:
2303 struct sctp_paddrparams *paddrp;
2304 struct sctp_nets *net;
2305 struct sockaddr *addr;
2306 #if defined(INET) && defined(INET6)
2307 struct sockaddr_in sin_store;
2310 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2311 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2313 #if defined(INET) && defined(INET6)
2314 if (paddrp->spp_address.ss_family == AF_INET6) {
2315 struct sockaddr_in6 *sin6;
2317 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2318 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2319 in6_sin6_2_sin(&sin_store, sin6);
2320 addr = (struct sockaddr *)&sin_store;
2322 addr = (struct sockaddr *)&paddrp->spp_address;
2325 addr = (struct sockaddr *)&paddrp->spp_address;
2328 addr = (struct sockaddr *)&paddrp->spp_address;
2331 net = sctp_findnet(stcb, addr);
2334 * We increment here since
2335 * sctp_findassociation_ep_addr() wil do a
2336 * decrement if it finds the stcb as long as
2337 * the locked tcb (last argument) is NOT a
2341 SCTP_INP_INCR_REF(inp);
2342 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2344 SCTP_INP_DECR_REF(inp);
2347 if ((stcb != NULL) && (net == NULL)) {
2349 if (addr->sa_family == AF_INET) {
2350 struct sockaddr_in *sin;
2352 sin = (struct sockaddr_in *)addr;
2353 if (sin->sin_addr.s_addr != INADDR_ANY) {
2355 SCTP_TCB_UNLOCK(stcb);
2356 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2362 if (addr->sa_family == AF_INET6) {
2363 struct sockaddr_in6 *sin6;
2365 sin6 = (struct sockaddr_in6 *)addr;
2366 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2368 SCTP_TCB_UNLOCK(stcb);
2369 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2375 error = EAFNOSUPPORT;
2376 SCTP_TCB_UNLOCK(stcb);
2377 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2383 /* Applies to the specific association */
2384 paddrp->spp_flags = 0;
2386 paddrp->spp_hbinterval = net->heart_beat_delay;
2387 paddrp->spp_pathmaxrxt = net->failure_threshold;
2388 paddrp->spp_pathmtu = net->mtu;
2389 switch (net->ro._l_addr.sa.sa_family) {
2392 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2397 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2403 /* get flags for HB */
2404 if (net->dest_state & SCTP_ADDR_NOHB) {
2405 paddrp->spp_flags |= SPP_HB_DISABLE;
2407 paddrp->spp_flags |= SPP_HB_ENABLE;
2409 /* get flags for PMTU */
2410 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2411 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2413 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2415 if (net->dscp & 0x01) {
2416 paddrp->spp_dscp = net->dscp & 0xfc;
2417 paddrp->spp_flags |= SPP_DSCP;
2420 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2421 (net->flowlabel & 0x80000000)) {
2422 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2423 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2428 * No destination so return default
2431 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2432 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2433 if (stcb->asoc.default_dscp & 0x01) {
2434 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2435 paddrp->spp_flags |= SPP_DSCP;
2438 if (stcb->asoc.default_flowlabel & 0x80000000) {
2439 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2440 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2443 /* default settings should be these */
2444 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2445 paddrp->spp_flags |= SPP_HB_DISABLE;
2447 paddrp->spp_flags |= SPP_HB_ENABLE;
2449 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2450 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2452 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2454 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2456 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2457 SCTP_TCB_UNLOCK(stcb);
2459 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2460 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2461 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2462 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
2463 /* Use endpoint defaults */
2464 SCTP_INP_RLOCK(inp);
2465 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2466 paddrp->spp_hbinterval = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2467 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2468 /* get inp's default */
2469 if (inp->sctp_ep.default_dscp & 0x01) {
2470 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2471 paddrp->spp_flags |= SPP_DSCP;
2474 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2475 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2476 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2477 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2480 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2482 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2483 paddrp->spp_flags |= SPP_HB_ENABLE;
2485 paddrp->spp_flags |= SPP_HB_DISABLE;
2487 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2488 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2490 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2492 SCTP_INP_RUNLOCK(inp);
2494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2499 *optsize = sizeof(struct sctp_paddrparams);
2503 case SCTP_GET_PEER_ADDR_INFO:
2505 struct sctp_paddrinfo *paddri;
2506 struct sctp_nets *net;
2507 struct sockaddr *addr;
2508 #if defined(INET) && defined(INET6)
2509 struct sockaddr_in sin_store;
2512 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2513 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2515 #if defined(INET) && defined(INET6)
2516 if (paddri->spinfo_address.ss_family == AF_INET6) {
2517 struct sockaddr_in6 *sin6;
2519 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2520 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2521 in6_sin6_2_sin(&sin_store, sin6);
2522 addr = (struct sockaddr *)&sin_store;
2524 addr = (struct sockaddr *)&paddri->spinfo_address;
2527 addr = (struct sockaddr *)&paddri->spinfo_address;
2530 addr = (struct sockaddr *)&paddri->spinfo_address;
2533 net = sctp_findnet(stcb, addr);
2536 * We increment here since
2537 * sctp_findassociation_ep_addr() wil do a
2538 * decrement if it finds the stcb as long as
2539 * the locked tcb (last argument) is NOT a
2543 SCTP_INP_INCR_REF(inp);
2544 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2546 SCTP_INP_DECR_REF(inp);
2550 if ((stcb != NULL) && (net != NULL)) {
2551 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2552 /* It's unconfirmed */
2553 paddri->spinfo_state = SCTP_UNCONFIRMED;
2554 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2556 paddri->spinfo_state = SCTP_ACTIVE;
2559 paddri->spinfo_state = SCTP_INACTIVE;
2561 paddri->spinfo_cwnd = net->cwnd;
2562 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2563 paddri->spinfo_rto = net->RTO;
2564 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2565 paddri->spinfo_mtu = net->mtu;
2566 switch (addr->sa_family) {
2569 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2574 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2580 SCTP_TCB_UNLOCK(stcb);
2581 *optsize = sizeof(struct sctp_paddrinfo);
2584 SCTP_TCB_UNLOCK(stcb);
2586 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2591 case SCTP_PCB_STATUS:
2593 struct sctp_pcbinfo *spcb;
2595 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2596 sctp_fill_pcbinfo(spcb);
2597 *optsize = sizeof(struct sctp_pcbinfo);
2602 struct sctp_nets *net;
2603 struct sctp_status *sstat;
2605 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2606 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2609 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2613 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2614 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2615 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2616 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2618 * We can't include chunks that have been passed to
2619 * the socket layer. Only things in queue.
2621 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2622 stcb->asoc.cnt_on_all_streams);
2623 sstat->sstat_instrms = stcb->asoc.streamincnt;
2624 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2625 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2626 net = stcb->asoc.primary_destination;
2628 memcpy(&sstat->sstat_primary.spinfo_address,
2630 ((struct sockaddr *)(&net->ro._l_addr))->sa_len);
2631 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2633 * Again the user can get info from
2634 * sctp_constants.h for what the state of
2637 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2638 /* It's unconfirmed */
2639 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2640 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2642 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2645 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2647 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2648 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2649 sstat->sstat_primary.spinfo_rto = net->RTO;
2650 sstat->sstat_primary.spinfo_mtu = net->mtu;
2651 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2654 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2659 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2666 memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo));
2668 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2669 SCTP_TCB_UNLOCK(stcb);
2670 *optsize = sizeof(struct sctp_status);
2675 struct sctp_rtoinfo *srto;
2677 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2678 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2681 srto->srto_initial = stcb->asoc.initial_rto;
2682 srto->srto_max = stcb->asoc.maxrto;
2683 srto->srto_min = stcb->asoc.minrto;
2684 SCTP_TCB_UNLOCK(stcb);
2686 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2687 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2688 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2689 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
2690 SCTP_INP_RLOCK(inp);
2691 srto->srto_initial = inp->sctp_ep.initial_rto;
2692 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2693 srto->srto_min = inp->sctp_ep.sctp_minrto;
2694 SCTP_INP_RUNLOCK(inp);
2696 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2701 *optsize = sizeof(struct sctp_rtoinfo);
2707 struct sctp_timeouts *stimo;
2709 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2710 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2713 stimo->stimo_init = stcb->asoc.timoinit;
2714 stimo->stimo_data = stcb->asoc.timodata;
2715 stimo->stimo_sack = stcb->asoc.timosack;
2716 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2717 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2718 stimo->stimo_cookie = stcb->asoc.timocookie;
2719 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2720 SCTP_TCB_UNLOCK(stcb);
2721 *optsize = sizeof(struct sctp_timeouts);
2723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2728 case SCTP_ASSOCINFO:
2730 struct sctp_assocparams *sasoc;
2732 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2733 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2736 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(stcb->asoc.cookie_life);
2737 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2738 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2739 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2740 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2741 SCTP_TCB_UNLOCK(stcb);
2743 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2744 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2745 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2746 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
2747 SCTP_INP_RLOCK(inp);
2748 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(inp->sctp_ep.def_cookie_life);
2749 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2750 sasoc->sasoc_number_peer_destinations = 0;
2751 sasoc->sasoc_peer_rwnd = 0;
2752 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2753 SCTP_INP_RUNLOCK(inp);
2755 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2760 *optsize = sizeof(struct sctp_assocparams);
2764 case SCTP_DEFAULT_SEND_PARAM:
2766 struct sctp_sndrcvinfo *s_info;
2768 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2769 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2772 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
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 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC))) {
2779 SCTP_INP_RLOCK(inp);
2780 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2781 SCTP_INP_RUNLOCK(inp);
2783 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2788 *optsize = sizeof(struct sctp_sndrcvinfo);
2794 struct sctp_initmsg *sinit;
2796 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2797 SCTP_INP_RLOCK(inp);
2798 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2799 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2800 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2801 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2802 SCTP_INP_RUNLOCK(inp);
2803 *optsize = sizeof(struct sctp_initmsg);
2806 case SCTP_PRIMARY_ADDR:
2807 /* we allow a "get" operation on this */
2809 struct sctp_setprim *ssp;
2811 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2812 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2815 union sctp_sockstore *addr;
2817 addr = &stcb->asoc.primary_destination->ro._l_addr;
2818 switch (addr->sa.sa_family) {
2822 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2823 in6_sin_2_v4mapsin6(&addr->sin,
2824 (struct sockaddr_in6 *)&ssp->ssp_addr);
2826 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2829 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2835 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2841 SCTP_TCB_UNLOCK(stcb);
2842 *optsize = sizeof(struct sctp_setprim);
2844 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2849 case SCTP_HMAC_IDENT:
2851 struct sctp_hmacalgo *shmac;
2852 sctp_hmaclist_t *hmaclist;
2856 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2858 SCTP_INP_RLOCK(inp);
2859 hmaclist = inp->sctp_ep.local_hmacs;
2860 if (hmaclist == NULL) {
2861 /* no HMACs to return */
2862 *optsize = sizeof(*shmac);
2863 SCTP_INP_RUNLOCK(inp);
2866 /* is there room for all of the hmac ids? */
2867 size = sizeof(*shmac) + (hmaclist->num_algo *
2868 sizeof(shmac->shmac_idents[0]));
2869 if ((size_t)(*optsize) < size) {
2870 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2872 SCTP_INP_RUNLOCK(inp);
2875 /* copy in the list */
2876 shmac->shmac_number_of_idents = hmaclist->num_algo;
2877 for (i = 0; i < hmaclist->num_algo; i++) {
2878 shmac->shmac_idents[i] = hmaclist->hmac[i];
2880 SCTP_INP_RUNLOCK(inp);
2884 case SCTP_AUTH_ACTIVE_KEY:
2886 struct sctp_authkeyid *scact;
2888 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2889 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2892 /* get the active key on the assoc */
2893 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2894 SCTP_TCB_UNLOCK(stcb);
2896 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2897 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2898 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2899 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC))) {
2900 /* get the endpoint active key */
2901 SCTP_INP_RLOCK(inp);
2902 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2903 SCTP_INP_RUNLOCK(inp);
2905 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2910 *optsize = sizeof(struct sctp_authkeyid);
2914 case SCTP_LOCAL_AUTH_CHUNKS:
2916 struct sctp_authchunks *sac;
2917 sctp_auth_chklist_t *chklist = NULL;
2920 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2921 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2924 /* get off the assoc */
2925 chklist = stcb->asoc.local_auth_chunks;
2926 /* is there enough space? */
2927 size = sctp_auth_get_chklist_size(chklist);
2928 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2932 /* copy in the chunks */
2933 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2934 sac->gauth_number_of_chunks = (uint32_t)size;
2935 *optsize = sizeof(struct sctp_authchunks) + size;
2937 SCTP_TCB_UNLOCK(stcb);
2939 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2940 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2941 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2942 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC))) {
2943 /* get off the endpoint */
2944 SCTP_INP_RLOCK(inp);
2945 chklist = inp->sctp_ep.local_auth_chunks;
2946 /* is there enough space? */
2947 size = sctp_auth_get_chklist_size(chklist);
2948 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2952 /* copy in the chunks */
2953 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2954 sac->gauth_number_of_chunks = (uint32_t)size;
2955 *optsize = sizeof(struct sctp_authchunks) + size;
2957 SCTP_INP_RUNLOCK(inp);
2959 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2965 case SCTP_PEER_AUTH_CHUNKS:
2967 struct sctp_authchunks *sac;
2968 sctp_auth_chklist_t *chklist = NULL;
2971 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2972 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2975 /* get off the assoc */
2976 chklist = stcb->asoc.peer_auth_chunks;
2977 /* is there enough space? */
2978 size = sctp_auth_get_chklist_size(chklist);
2979 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2983 /* copy in the chunks */
2984 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2985 sac->gauth_number_of_chunks = (uint32_t)size;
2986 *optsize = sizeof(struct sctp_authchunks) + size;
2988 SCTP_TCB_UNLOCK(stcb);
2990 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2997 struct sctp_event *event;
2998 uint32_t event_type;
3000 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3001 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3003 switch (event->se_type) {
3004 case SCTP_ASSOC_CHANGE:
3005 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3007 case SCTP_PEER_ADDR_CHANGE:
3008 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3010 case SCTP_REMOTE_ERROR:
3011 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3013 case SCTP_SEND_FAILED:
3014 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3016 case SCTP_SHUTDOWN_EVENT:
3017 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3019 case SCTP_ADAPTATION_INDICATION:
3020 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3022 case SCTP_PARTIAL_DELIVERY_EVENT:
3023 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3025 case SCTP_AUTHENTICATION_EVENT:
3026 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3028 case SCTP_STREAM_RESET_EVENT:
3029 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3031 case SCTP_SENDER_DRY_EVENT:
3032 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3034 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3036 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3039 case SCTP_ASSOC_RESET_EVENT:
3040 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3042 case SCTP_STREAM_CHANGE_EVENT:
3043 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3045 case SCTP_SEND_FAILED_EVENT:
3046 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3050 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3054 if (event_type > 0) {
3056 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3058 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3059 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3060 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3061 (event->se_assoc_id == SCTP_FUTURE_ASSOC))) {
3062 SCTP_INP_RLOCK(inp);
3063 event->se_on = sctp_is_feature_on(inp, event_type);
3064 SCTP_INP_RUNLOCK(inp);
3066 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3072 SCTP_TCB_UNLOCK(stcb);
3075 *optsize = sizeof(struct sctp_event);
3079 case SCTP_RECVRCVINFO:
3080 if (*optsize < sizeof(int)) {
3081 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3084 SCTP_INP_RLOCK(inp);
3085 *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3086 SCTP_INP_RUNLOCK(inp);
3087 *optsize = sizeof(int);
3090 case SCTP_RECVNXTINFO:
3091 if (*optsize < sizeof(int)) {
3092 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3095 SCTP_INP_RLOCK(inp);
3096 *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3097 SCTP_INP_RUNLOCK(inp);
3098 *optsize = sizeof(int);
3101 case SCTP_DEFAULT_SNDINFO:
3103 struct sctp_sndinfo *info;
3105 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3106 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3109 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3110 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3111 info->snd_flags &= 0xfff0;
3112 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3113 info->snd_context = stcb->asoc.def_send.sinfo_context;
3114 SCTP_TCB_UNLOCK(stcb);
3116 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3117 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3118 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3119 (info->snd_assoc_id == SCTP_FUTURE_ASSOC))) {
3120 SCTP_INP_RLOCK(inp);
3121 info->snd_sid = inp->def_send.sinfo_stream;
3122 info->snd_flags = inp->def_send.sinfo_flags;
3123 info->snd_flags &= 0xfff0;
3124 info->snd_ppid = inp->def_send.sinfo_ppid;
3125 info->snd_context = inp->def_send.sinfo_context;
3126 SCTP_INP_RUNLOCK(inp);
3128 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3133 *optsize = sizeof(struct sctp_sndinfo);
3137 case SCTP_DEFAULT_PRINFO:
3139 struct sctp_default_prinfo *info;
3141 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3142 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3145 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3146 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3147 SCTP_TCB_UNLOCK(stcb);
3149 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3150 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3151 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3152 (info->pr_assoc_id == SCTP_FUTURE_ASSOC))) {
3153 SCTP_INP_RLOCK(inp);
3154 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3155 info->pr_value = inp->def_send.sinfo_timetolive;
3156 SCTP_INP_RUNLOCK(inp);
3158 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3163 *optsize = sizeof(struct sctp_default_prinfo);
3167 case SCTP_PEER_ADDR_THLDS:
3169 struct sctp_paddrthlds *thlds;
3170 struct sctp_nets *net;
3171 struct sockaddr *addr;
3172 #if defined(INET) && defined(INET6)
3173 struct sockaddr_in sin_store;
3176 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3177 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3179 #if defined(INET) && defined(INET6)
3180 if (thlds->spt_address.ss_family == AF_INET6) {
3181 struct sockaddr_in6 *sin6;
3183 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3184 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3185 in6_sin6_2_sin(&sin_store, sin6);
3186 addr = (struct sockaddr *)&sin_store;
3188 addr = (struct sockaddr *)&thlds->spt_address;
3191 addr = (struct sockaddr *)&thlds->spt_address;
3194 addr = (struct sockaddr *)&thlds->spt_address;
3197 net = sctp_findnet(stcb, addr);
3200 * We increment here since
3201 * sctp_findassociation_ep_addr() wil do a
3202 * decrement if it finds the stcb as long as
3203 * the locked tcb (last argument) is NOT a
3207 SCTP_INP_INCR_REF(inp);
3208 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3210 SCTP_INP_DECR_REF(inp);
3213 if ((stcb != NULL) && (net == NULL)) {
3215 if (addr->sa_family == AF_INET) {
3216 struct sockaddr_in *sin;
3218 sin = (struct sockaddr_in *)addr;
3219 if (sin->sin_addr.s_addr != INADDR_ANY) {
3221 SCTP_TCB_UNLOCK(stcb);
3222 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3228 if (addr->sa_family == AF_INET6) {
3229 struct sockaddr_in6 *sin6;
3231 sin6 = (struct sockaddr_in6 *)addr;
3232 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3234 SCTP_TCB_UNLOCK(stcb);
3235 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3241 error = EAFNOSUPPORT;
3242 SCTP_TCB_UNLOCK(stcb);
3243 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3250 thlds->spt_pathmaxrxt = net->failure_threshold;
3251 thlds->spt_pathpfthld = net->pf_threshold;
3252 thlds->spt_pathcpthld = 0xffff;
3254 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3255 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3256 thlds->spt_pathcpthld = 0xffff;
3258 thlds->spt_assoc_id = sctp_get_associd(stcb);
3259 SCTP_TCB_UNLOCK(stcb);
3261 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3262 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3263 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3264 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
3265 /* Use endpoint defaults */
3266 SCTP_INP_RLOCK(inp);
3267 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3268 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3269 thlds->spt_pathcpthld = 0xffff;
3270 SCTP_INP_RUNLOCK(inp);
3272 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3277 *optsize = sizeof(struct sctp_paddrthlds);
3281 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3283 struct sctp_udpencaps *encaps;
3284 struct sctp_nets *net;
3285 struct sockaddr *addr;
3286 #if defined(INET) && defined(INET6)
3287 struct sockaddr_in sin_store;
3290 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3291 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3293 #if defined(INET) && defined(INET6)
3294 if (encaps->sue_address.ss_family == AF_INET6) {
3295 struct sockaddr_in6 *sin6;
3297 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3298 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3299 in6_sin6_2_sin(&sin_store, sin6);
3300 addr = (struct sockaddr *)&sin_store;
3302 addr = (struct sockaddr *)&encaps->sue_address;
3305 addr = (struct sockaddr *)&encaps->sue_address;
3308 addr = (struct sockaddr *)&encaps->sue_address;
3311 net = sctp_findnet(stcb, addr);
3314 * We increment here since
3315 * sctp_findassociation_ep_addr() wil do a
3316 * decrement if it finds the stcb as long as
3317 * the locked tcb (last argument) is NOT a
3321 SCTP_INP_INCR_REF(inp);
3322 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3324 SCTP_INP_DECR_REF(inp);
3327 if ((stcb != NULL) && (net == NULL)) {
3329 if (addr->sa_family == AF_INET) {
3330 struct sockaddr_in *sin;
3332 sin = (struct sockaddr_in *)addr;
3333 if (sin->sin_addr.s_addr != INADDR_ANY) {
3335 SCTP_TCB_UNLOCK(stcb);
3336 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3342 if (addr->sa_family == AF_INET6) {
3343 struct sockaddr_in6 *sin6;
3345 sin6 = (struct sockaddr_in6 *)addr;
3346 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3348 SCTP_TCB_UNLOCK(stcb);
3349 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3355 error = EAFNOSUPPORT;
3356 SCTP_TCB_UNLOCK(stcb);
3357 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3364 encaps->sue_port = net->port;
3366 encaps->sue_port = stcb->asoc.port;
3368 SCTP_TCB_UNLOCK(stcb);
3370 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3371 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3372 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3373 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
3374 SCTP_INP_RLOCK(inp);
3375 encaps->sue_port = inp->sctp_ep.port;
3376 SCTP_INP_RUNLOCK(inp);
3378 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3383 *optsize = sizeof(struct sctp_udpencaps);
3387 case SCTP_ECN_SUPPORTED:
3389 struct sctp_assoc_value *av;
3391 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3392 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3395 av->assoc_value = stcb->asoc.ecn_supported;
3396 SCTP_TCB_UNLOCK(stcb);
3398 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3399 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3400 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3401 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3402 SCTP_INP_RLOCK(inp);
3403 av->assoc_value = inp->ecn_supported;
3404 SCTP_INP_RUNLOCK(inp);
3406 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3411 *optsize = sizeof(struct sctp_assoc_value);
3415 case SCTP_PR_SUPPORTED:
3417 struct sctp_assoc_value *av;
3419 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3420 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3423 av->assoc_value = stcb->asoc.prsctp_supported;
3424 SCTP_TCB_UNLOCK(stcb);
3426 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3427 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3428 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3429 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3430 SCTP_INP_RLOCK(inp);
3431 av->assoc_value = inp->prsctp_supported;
3432 SCTP_INP_RUNLOCK(inp);
3434 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3439 *optsize = sizeof(struct sctp_assoc_value);
3443 case SCTP_AUTH_SUPPORTED:
3445 struct sctp_assoc_value *av;
3447 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3448 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3451 av->assoc_value = stcb->asoc.auth_supported;
3452 SCTP_TCB_UNLOCK(stcb);
3454 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3455 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3456 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3457 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3458 SCTP_INP_RLOCK(inp);
3459 av->assoc_value = inp->auth_supported;
3460 SCTP_INP_RUNLOCK(inp);
3462 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3467 *optsize = sizeof(struct sctp_assoc_value);
3471 case SCTP_ASCONF_SUPPORTED:
3473 struct sctp_assoc_value *av;
3475 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3476 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3479 av->assoc_value = stcb->asoc.asconf_supported;
3480 SCTP_TCB_UNLOCK(stcb);
3482 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3483 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3484 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3485 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3486 SCTP_INP_RLOCK(inp);
3487 av->assoc_value = inp->asconf_supported;
3488 SCTP_INP_RUNLOCK(inp);
3490 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3495 *optsize = sizeof(struct sctp_assoc_value);
3499 case SCTP_RECONFIG_SUPPORTED:
3501 struct sctp_assoc_value *av;
3503 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3504 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3507 av->assoc_value = stcb->asoc.reconfig_supported;
3508 SCTP_TCB_UNLOCK(stcb);
3510 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3511 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3512 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3513 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3514 SCTP_INP_RLOCK(inp);
3515 av->assoc_value = inp->reconfig_supported;
3516 SCTP_INP_RUNLOCK(inp);
3518 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3523 *optsize = sizeof(struct sctp_assoc_value);
3527 case SCTP_NRSACK_SUPPORTED:
3529 struct sctp_assoc_value *av;
3531 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3532 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3535 av->assoc_value = stcb->asoc.nrsack_supported;
3536 SCTP_TCB_UNLOCK(stcb);
3538 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3539 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3540 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3541 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3542 SCTP_INP_RLOCK(inp);
3543 av->assoc_value = inp->nrsack_supported;
3544 SCTP_INP_RUNLOCK(inp);
3546 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3551 *optsize = sizeof(struct sctp_assoc_value);
3555 case SCTP_PKTDROP_SUPPORTED:
3557 struct sctp_assoc_value *av;
3559 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3560 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3563 av->assoc_value = stcb->asoc.pktdrop_supported;
3564 SCTP_TCB_UNLOCK(stcb);
3566 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3567 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3568 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3569 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3570 SCTP_INP_RLOCK(inp);
3571 av->assoc_value = inp->pktdrop_supported;
3572 SCTP_INP_RUNLOCK(inp);
3574 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3579 *optsize = sizeof(struct sctp_assoc_value);
3583 case SCTP_ENABLE_STREAM_RESET:
3585 struct sctp_assoc_value *av;
3587 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3588 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3591 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3592 SCTP_TCB_UNLOCK(stcb);
3594 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3595 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3596 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3597 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3598 SCTP_INP_RLOCK(inp);
3599 av->assoc_value = (uint32_t)inp->local_strreset_support;
3600 SCTP_INP_RUNLOCK(inp);
3602 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3607 *optsize = sizeof(struct sctp_assoc_value);
3611 case SCTP_PR_STREAM_STATUS:
3613 struct sctp_prstatus *sprstat;
3617 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3618 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3620 sid = sprstat->sprstat_sid;
3621 policy = sprstat->sprstat_policy;
3622 #if defined(SCTP_DETAILED_STR_STATS)
3623 if ((stcb != NULL) &&
3624 (sid < stcb->asoc.streamoutcnt) &&
3625 (policy != SCTP_PR_SCTP_NONE) &&
3626 ((policy <= SCTP_PR_SCTP_MAX) ||
3627 (policy == SCTP_PR_SCTP_ALL))) {
3628 if (policy == SCTP_PR_SCTP_ALL) {
3629 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3630 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3632 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3633 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3636 if ((stcb != NULL) &&
3637 (sid < stcb->asoc.streamoutcnt) &&
3638 (policy == SCTP_PR_SCTP_ALL)) {
3639 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3640 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3643 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3647 SCTP_TCB_UNLOCK(stcb);
3650 *optsize = sizeof(struct sctp_prstatus);
3654 case SCTP_PR_ASSOC_STATUS:
3656 struct sctp_prstatus *sprstat;
3659 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3660 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3662 policy = sprstat->sprstat_policy;
3663 if ((stcb != NULL) &&
3664 (policy != SCTP_PR_SCTP_NONE) &&
3665 ((policy <= SCTP_PR_SCTP_MAX) ||
3666 (policy == SCTP_PR_SCTP_ALL))) {
3667 if (policy == SCTP_PR_SCTP_ALL) {
3668 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3669 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3671 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3672 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3675 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3679 SCTP_TCB_UNLOCK(stcb);
3682 *optsize = sizeof(struct sctp_prstatus);
3688 struct sctp_assoc_value *av;
3690 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3691 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3694 av->assoc_value = stcb->asoc.max_cwnd;
3695 SCTP_TCB_UNLOCK(stcb);
3697 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3698 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3699 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3700 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3701 SCTP_INP_RLOCK(inp);
3702 av->assoc_value = inp->max_cwnd;
3703 SCTP_INP_RUNLOCK(inp);
3705 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3710 *optsize = sizeof(struct sctp_assoc_value);
3715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3716 error = ENOPROTOOPT;
3718 } /* end switch (sopt->sopt_name) */
3726 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3731 struct sctp_tcb *stcb = NULL;
3732 struct sctp_inpcb *inp = NULL;
3735 if (optval == NULL) {
3736 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3739 inp = (struct sctp_inpcb *)so->so_pcb;
3741 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3744 vrf_id = inp->def_vrf_id;
3749 case SCTP_AUTOCLOSE:
3750 case SCTP_AUTO_ASCONF:
3751 case SCTP_EXPLICIT_EOR:
3752 case SCTP_DISABLE_FRAGMENTS:
3753 case SCTP_USE_EXT_RCVINFO:
3754 case SCTP_I_WANT_MAPPED_V4_ADDR:
3755 /* copy in the option value */
3756 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3761 case SCTP_DISABLE_FRAGMENTS:
3762 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3764 case SCTP_AUTO_ASCONF:
3766 * NOTE: we don't really support this flag
3768 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3769 /* only valid for bound all sockets */
3770 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3772 /* forbidden by admin */
3773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3776 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3778 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3782 case SCTP_EXPLICIT_EOR:
3783 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3785 case SCTP_USE_EXT_RCVINFO:
3786 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3788 case SCTP_I_WANT_MAPPED_V4_ADDR:
3789 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3790 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3792 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3797 set_opt = SCTP_PCB_FLAGS_NODELAY;
3799 case SCTP_AUTOCLOSE:
3800 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3801 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3802 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3805 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3807 * The value is in ticks. Note this does not effect
3808 * old associations, only new ones.
3810 inp->sctp_ep.auto_close_time = sctp_secs_to_ticks(*mopt);
3813 SCTP_INP_WLOCK(inp);
3815 sctp_feature_on(inp, set_opt);
3817 sctp_feature_off(inp, set_opt);
3819 SCTP_INP_WUNLOCK(inp);
3821 case SCTP_REUSE_PORT:
3823 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3824 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3825 /* Can't set it after we are bound */
3829 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3830 /* Can't do this for a 1-m socket */
3835 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3837 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3840 case SCTP_PARTIAL_DELIVERY_POINT:
3844 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3845 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3846 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3850 inp->partial_delivery_point = *value;
3853 case SCTP_FRAGMENT_INTERLEAVE:
3854 /* not yet until we re-write sctp_recvmsg() */
3858 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3859 if (*level == SCTP_FRAG_LEVEL_2) {
3860 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3861 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3862 } else if (*level == SCTP_FRAG_LEVEL_1) {
3863 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3864 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3865 } else if (*level == SCTP_FRAG_LEVEL_0) {
3866 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3867 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3870 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3875 case SCTP_INTERLEAVING_SUPPORTED:
3877 struct sctp_assoc_value *av;
3879 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3880 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3883 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3885 SCTP_TCB_UNLOCK(stcb);
3887 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3888 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3889 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3890 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3891 SCTP_INP_WLOCK(inp);
3892 if (av->assoc_value == 0) {
3893 inp->idata_supported = 0;
3895 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3896 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3897 inp->idata_supported = 1;
3905 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3909 SCTP_INP_WUNLOCK(inp);
3911 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3917 case SCTP_CMT_ON_OFF:
3918 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3919 struct sctp_assoc_value *av;
3921 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3922 if (av->assoc_value > SCTP_CMT_MAX) {
3923 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3927 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3929 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3930 SCTP_TCB_UNLOCK(stcb);
3932 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3933 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3934 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3935 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3936 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3937 SCTP_INP_WLOCK(inp);
3938 inp->sctp_cmt_on_off = av->assoc_value;
3939 SCTP_INP_WUNLOCK(inp);
3941 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3942 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3943 (av->assoc_id == SCTP_ALL_ASSOC))) {
3944 SCTP_INP_RLOCK(inp);
3945 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3946 SCTP_TCB_LOCK(stcb);
3947 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3948 SCTP_TCB_UNLOCK(stcb);
3950 SCTP_INP_RUNLOCK(inp);
3954 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3955 error = ENOPROTOOPT;
3958 case SCTP_PLUGGABLE_CC:
3960 struct sctp_assoc_value *av;
3961 struct sctp_nets *net;
3963 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3964 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3965 (av->assoc_value != SCTP_CC_HSTCP) &&
3966 (av->assoc_value != SCTP_CC_HTCP) &&
3967 (av->assoc_value != SCTP_CC_RTCC)) {
3968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3972 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3974 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3975 stcb->asoc.congestion_control_module = av->assoc_value;
3976 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3977 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3978 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3981 SCTP_TCB_UNLOCK(stcb);
3983 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3984 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3985 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3986 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3987 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3988 SCTP_INP_WLOCK(inp);
3989 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3990 SCTP_INP_WUNLOCK(inp);
3992 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3993 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3994 (av->assoc_id == SCTP_ALL_ASSOC))) {
3995 SCTP_INP_RLOCK(inp);
3996 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3997 SCTP_TCB_LOCK(stcb);
3998 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3999 stcb->asoc.congestion_control_module = av->assoc_value;
4000 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4001 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4002 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4005 SCTP_TCB_UNLOCK(stcb);
4007 SCTP_INP_RUNLOCK(inp);
4012 case SCTP_CC_OPTION:
4014 struct sctp_cc_option *cc_opt;
4016 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4017 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4019 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4020 (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC)) {
4021 SCTP_INP_RLOCK(inp);
4022 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4023 SCTP_TCB_LOCK(stcb);
4024 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4025 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4027 SCTP_TCB_UNLOCK(stcb);
4029 SCTP_INP_RUNLOCK(inp);
4034 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4037 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4040 SCTP_TCB_UNLOCK(stcb);
4044 case SCTP_PLUGGABLE_SS:
4046 struct sctp_assoc_value *av;
4048 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4049 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4050 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4051 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4052 (av->assoc_value != SCTP_SS_PRIORITY) &&
4053 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4054 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4055 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4059 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4061 SCTP_TCB_SEND_LOCK(stcb);
4062 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4063 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4064 stcb->asoc.stream_scheduling_module = av->assoc_value;
4065 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4066 SCTP_TCB_SEND_UNLOCK(stcb);
4067 SCTP_TCB_UNLOCK(stcb);
4069 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4070 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4071 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4072 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4073 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4074 SCTP_INP_WLOCK(inp);
4075 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4076 SCTP_INP_WUNLOCK(inp);
4078 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4079 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4080 (av->assoc_id == SCTP_ALL_ASSOC))) {
4081 SCTP_INP_RLOCK(inp);
4082 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4083 SCTP_TCB_LOCK(stcb);
4084 SCTP_TCB_SEND_LOCK(stcb);
4085 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4086 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4087 stcb->asoc.stream_scheduling_module = av->assoc_value;
4088 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4089 SCTP_TCB_SEND_UNLOCK(stcb);
4090 SCTP_TCB_UNLOCK(stcb);
4092 SCTP_INP_RUNLOCK(inp);
4099 struct sctp_stream_value *av;
4101 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4102 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4104 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4105 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4106 av->stream_value) < 0)) {
4107 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4110 SCTP_TCB_UNLOCK(stcb);
4112 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4113 (av->assoc_id == SCTP_CURRENT_ASSOC)) {
4114 SCTP_INP_RLOCK(inp);
4115 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4116 SCTP_TCB_LOCK(stcb);
4117 if (av->stream_id < stcb->asoc.streamoutcnt) {
4118 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4120 &stcb->asoc.strmout[av->stream_id],
4123 SCTP_TCB_UNLOCK(stcb);
4125 SCTP_INP_RUNLOCK(inp);
4128 * Can't set stream value without
4131 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4137 case SCTP_CLR_STAT_LOG:
4138 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4143 struct sctp_assoc_value *av;
4145 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4146 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4149 stcb->asoc.context = av->assoc_value;
4150 SCTP_TCB_UNLOCK(stcb);
4152 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4153 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4154 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4155 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4156 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4157 SCTP_INP_WLOCK(inp);
4158 inp->sctp_context = av->assoc_value;
4159 SCTP_INP_WUNLOCK(inp);
4161 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4162 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4163 (av->assoc_id == SCTP_ALL_ASSOC))) {
4164 SCTP_INP_RLOCK(inp);
4165 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4166 SCTP_TCB_LOCK(stcb);
4167 stcb->asoc.context = av->assoc_value;
4168 SCTP_TCB_UNLOCK(stcb);
4170 SCTP_INP_RUNLOCK(inp);
4177 uint32_t *default_vrfid;
4179 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4180 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4181 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4185 inp->def_vrf_id = *default_vrfid;
4188 case SCTP_DEL_VRF_ID:
4190 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4194 case SCTP_ADD_VRF_ID:
4196 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4200 case SCTP_DELAYED_SACK:
4202 struct sctp_sack_info *sack;
4204 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4205 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4206 if (sack->sack_delay) {
4207 if (sack->sack_delay > SCTP_MAX_SACK_DELAY) {
4210 SCTP_TCB_UNLOCK(stcb);
4216 if (sack->sack_delay) {
4217 stcb->asoc.delayed_ack = sack->sack_delay;
4219 if (sack->sack_freq) {
4220 stcb->asoc.sack_freq = sack->sack_freq;
4222 SCTP_TCB_UNLOCK(stcb);
4224 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4225 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4226 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4227 ((sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4228 (sack->sack_assoc_id == SCTP_ALL_ASSOC)))) {
4229 SCTP_INP_WLOCK(inp);
4230 if (sack->sack_delay) {
4231 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = sctp_msecs_to_ticks(sack->sack_delay);
4233 if (sack->sack_freq) {
4234 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4236 SCTP_INP_WUNLOCK(inp);
4238 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4239 ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4240 (sack->sack_assoc_id == SCTP_ALL_ASSOC))) {
4241 SCTP_INP_RLOCK(inp);
4242 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4243 SCTP_TCB_LOCK(stcb);
4244 if (sack->sack_delay) {
4245 stcb->asoc.delayed_ack = sack->sack_delay;
4247 if (sack->sack_freq) {
4248 stcb->asoc.sack_freq = sack->sack_freq;
4250 SCTP_TCB_UNLOCK(stcb);
4252 SCTP_INP_RUNLOCK(inp);
4257 case SCTP_AUTH_CHUNK:
4259 struct sctp_authchunk *sauth;
4261 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4263 SCTP_INP_WLOCK(inp);
4264 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4265 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4268 inp->auth_supported = 1;
4270 SCTP_INP_WUNLOCK(inp);
4275 struct sctp_authkey *sca;
4276 struct sctp_keyhead *shared_keys;
4277 sctp_sharedkey_t *shared_key;
4278 sctp_key_t *key = NULL;
4281 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4282 if (sca->sca_keylength == 0) {
4283 size = optsize - sizeof(struct sctp_authkey);
4285 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4286 size = sca->sca_keylength;
4288 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4293 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4296 shared_keys = &stcb->asoc.shared_keys;
4297 /* clear the cached keys for this key id */
4298 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4300 * create the new shared key and
4304 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4306 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4308 SCTP_TCB_UNLOCK(stcb);
4312 shared_key = sctp_alloc_sharedkey();
4313 if (shared_key == NULL) {
4315 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4317 SCTP_TCB_UNLOCK(stcb);
4320 shared_key->key = key;
4321 shared_key->keyid = sca->sca_keynumber;
4322 error = sctp_insert_sharedkey(shared_keys, shared_key);
4323 SCTP_TCB_UNLOCK(stcb);
4325 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4326 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4327 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4328 ((sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4329 (sca->sca_assoc_id == SCTP_ALL_ASSOC)))) {
4330 SCTP_INP_WLOCK(inp);
4331 shared_keys = &inp->sctp_ep.shared_keys;
4333 * clear the cached keys on all
4334 * assocs for this key id
4336 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4338 * create the new shared key and
4342 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4344 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4346 SCTP_INP_WUNLOCK(inp);
4350 shared_key = sctp_alloc_sharedkey();
4351 if (shared_key == NULL) {
4353 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4355 SCTP_INP_WUNLOCK(inp);
4358 shared_key->key = key;
4359 shared_key->keyid = sca->sca_keynumber;
4360 error = sctp_insert_sharedkey(shared_keys, shared_key);
4361 SCTP_INP_WUNLOCK(inp);
4363 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4364 ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4365 (sca->sca_assoc_id == SCTP_ALL_ASSOC))) {
4366 SCTP_INP_RLOCK(inp);
4367 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4368 SCTP_TCB_LOCK(stcb);
4369 shared_keys = &stcb->asoc.shared_keys;
4371 * clear the cached keys for
4374 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4376 * create the new shared key
4377 * and insert/replace it
4380 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4382 SCTP_TCB_UNLOCK(stcb);
4386 shared_key = sctp_alloc_sharedkey();
4387 if (shared_key == NULL) {
4389 SCTP_TCB_UNLOCK(stcb);
4392 shared_key->key = key;
4393 shared_key->keyid = sca->sca_keynumber;
4394 error = sctp_insert_sharedkey(shared_keys, shared_key);
4395 SCTP_TCB_UNLOCK(stcb);
4397 SCTP_INP_RUNLOCK(inp);
4402 case SCTP_HMAC_IDENT:
4404 struct sctp_hmacalgo *shmac;
4405 sctp_hmaclist_t *hmaclist;
4409 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4410 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4411 (shmac->shmac_number_of_idents > 0xffff)) {
4412 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4417 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4418 if (hmaclist == NULL) {
4419 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4423 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4424 hmacid = shmac->shmac_idents[i];
4425 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4426 /* invalid HMACs were found */ ;
4427 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4429 sctp_free_hmaclist(hmaclist);
4430 goto sctp_set_hmac_done;
4433 for (i = 0; i < hmaclist->num_algo; i++) {
4434 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4435 /* already in list */
4439 if (i == hmaclist->num_algo) {
4440 /* not found in list */
4441 sctp_free_hmaclist(hmaclist);
4442 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4446 /* set it on the endpoint */
4447 SCTP_INP_WLOCK(inp);
4448 if (inp->sctp_ep.local_hmacs)
4449 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4450 inp->sctp_ep.local_hmacs = hmaclist;
4451 SCTP_INP_WUNLOCK(inp);
4455 case SCTP_AUTH_ACTIVE_KEY:
4457 struct sctp_authkeyid *scact;
4459 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4460 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4462 /* set the active key on the right place */
4464 /* set the active key on the assoc */
4465 if (sctp_auth_setactivekey(stcb,
4466 scact->scact_keynumber)) {
4467 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4468 SCTP_FROM_SCTP_USRREQ,
4472 SCTP_TCB_UNLOCK(stcb);
4474 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4475 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4476 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4477 ((scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4478 (scact->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4479 SCTP_INP_WLOCK(inp);
4480 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4481 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4484 SCTP_INP_WUNLOCK(inp);
4486 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4487 ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4488 (scact->scact_assoc_id == SCTP_ALL_ASSOC))) {
4489 SCTP_INP_RLOCK(inp);
4490 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4491 SCTP_TCB_LOCK(stcb);
4492 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4493 SCTP_TCB_UNLOCK(stcb);
4495 SCTP_INP_RUNLOCK(inp);
4500 case SCTP_AUTH_DELETE_KEY:
4502 struct sctp_authkeyid *scdel;
4504 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4505 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4507 /* delete the key from the right place */
4509 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4510 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4513 SCTP_TCB_UNLOCK(stcb);
4515 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4516 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4517 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4518 ((scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4519 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4520 SCTP_INP_WLOCK(inp);
4521 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4522 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4525 SCTP_INP_WUNLOCK(inp);
4527 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4528 ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4529 (scdel->scact_assoc_id == SCTP_ALL_ASSOC))) {
4530 SCTP_INP_RLOCK(inp);
4531 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4532 SCTP_TCB_LOCK(stcb);
4533 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4534 SCTP_TCB_UNLOCK(stcb);
4536 SCTP_INP_RUNLOCK(inp);
4541 case SCTP_AUTH_DEACTIVATE_KEY:
4543 struct sctp_authkeyid *keyid;
4545 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4546 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4548 /* deactivate the key from the right place */
4550 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4551 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4554 SCTP_TCB_UNLOCK(stcb);
4556 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4557 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4558 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4559 ((keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4560 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4561 SCTP_INP_WLOCK(inp);
4562 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4563 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4566 SCTP_INP_WUNLOCK(inp);
4568 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4569 ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4570 (keyid->scact_assoc_id == SCTP_ALL_ASSOC))) {
4571 SCTP_INP_RLOCK(inp);
4572 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4573 SCTP_TCB_LOCK(stcb);
4574 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4575 SCTP_TCB_UNLOCK(stcb);
4577 SCTP_INP_RUNLOCK(inp);
4582 case SCTP_ENABLE_STREAM_RESET:
4584 struct sctp_assoc_value *av;
4586 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4587 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4588 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4592 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4594 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4595 SCTP_TCB_UNLOCK(stcb);
4597 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4598 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4599 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4600 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4601 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4602 SCTP_INP_WLOCK(inp);
4603 inp->local_strreset_support = (uint8_t)av->assoc_value;
4604 SCTP_INP_WUNLOCK(inp);
4606 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4607 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4608 (av->assoc_id == SCTP_ALL_ASSOC))) {
4609 SCTP_INP_RLOCK(inp);
4610 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4611 SCTP_TCB_LOCK(stcb);
4612 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4613 SCTP_TCB_UNLOCK(stcb);
4615 SCTP_INP_RUNLOCK(inp);
4620 case SCTP_RESET_STREAMS:
4622 struct sctp_reset_streams *strrst;
4623 int i, send_out = 0;
4626 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4627 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4629 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4633 if (stcb->asoc.reconfig_supported == 0) {
4635 * Peer does not support the chunk type.
4637 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4639 SCTP_TCB_UNLOCK(stcb);
4642 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4643 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4645 SCTP_TCB_UNLOCK(stcb);
4648 if (sizeof(struct sctp_reset_streams) +
4649 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4651 SCTP_TCB_UNLOCK(stcb);
4654 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4656 if (stcb->asoc.stream_reset_outstanding) {
4657 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4659 SCTP_TCB_UNLOCK(stcb);
4663 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4666 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4669 SCTP_TCB_UNLOCK(stcb);
4672 if ((send_in == 0) && (send_out == 0)) {
4673 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4675 SCTP_TCB_UNLOCK(stcb);
4678 for (i = 0; i < strrst->srs_number_streams; i++) {
4680 (strrst->srs_stream_list[i] >= stcb->asoc.streamincnt)) {
4681 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4686 (strrst->srs_stream_list[i] >= stcb->asoc.streamoutcnt)) {
4687 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4693 SCTP_TCB_UNLOCK(stcb);
4700 if (strrst->srs_number_streams) {
4701 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4702 strm = strrst->srs_stream_list[i];
4703 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4704 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4710 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4711 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4712 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4719 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4720 strrst->srs_stream_list,
4721 send_in, 0, 0, 0, 0, 0);
4723 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4726 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4729 * For outgoing streams don't report any
4730 * problems in sending the request to the
4731 * application. XXX: Double check resetting
4736 SCTP_TCB_UNLOCK(stcb);
4739 case SCTP_ADD_STREAMS:
4741 struct sctp_add_streams *stradd;
4742 uint8_t addstream = 0;
4743 uint16_t add_o_strmcnt = 0;
4744 uint16_t add_i_strmcnt = 0;
4746 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4747 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4749 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4753 if (stcb->asoc.reconfig_supported == 0) {
4755 * Peer does not support the chunk type.
4757 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4759 SCTP_TCB_UNLOCK(stcb);
4762 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4763 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4765 SCTP_TCB_UNLOCK(stcb);
4768 if (stcb->asoc.stream_reset_outstanding) {
4769 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4771 SCTP_TCB_UNLOCK(stcb);
4774 if ((stradd->sas_outstrms == 0) &&
4775 (stradd->sas_instrms == 0)) {
4779 if (stradd->sas_outstrms) {
4781 /* We allocate here */
4782 add_o_strmcnt = stradd->sas_outstrms;
4783 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4784 /* You can't have more than 64k */
4789 if (stradd->sas_instrms) {
4794 * We allocate inside
4795 * sctp_send_str_reset_req()
4797 add_i_strmcnt = stradd->sas_instrms;
4798 cnt = add_i_strmcnt;
4799 cnt += stcb->asoc.streamincnt;
4800 if (cnt > 0x0000ffff) {
4801 /* You can't have more than 64k */
4805 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4806 /* More than you are allowed */
4811 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4812 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4814 SCTP_TCB_UNLOCK(stcb);
4817 case SCTP_RESET_ASSOC:
4822 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4823 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4825 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4829 if (stcb->asoc.reconfig_supported == 0) {
4831 * Peer does not support the chunk type.
4833 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4835 SCTP_TCB_UNLOCK(stcb);
4838 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4839 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4841 SCTP_TCB_UNLOCK(stcb);
4844 if (stcb->asoc.stream_reset_outstanding) {
4845 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4847 SCTP_TCB_UNLOCK(stcb);
4851 * Is there any data pending in the send or sent
4854 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4855 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4858 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4859 SCTP_TCB_UNLOCK(stcb);
4862 /* Do any streams have data queued? */
4863 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4864 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4868 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4869 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4870 SCTP_TCB_UNLOCK(stcb);
4873 case SCTP_CONNECT_X:
4874 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4875 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4879 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4881 case SCTP_CONNECT_X_DELAYED:
4882 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4883 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4887 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4889 case SCTP_CONNECT_X_COMPLETE:
4891 struct sockaddr *sa;
4893 /* FIXME MT: check correct? */
4894 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4897 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4898 SCTP_INP_RLOCK(inp);
4899 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4901 SCTP_TCB_LOCK(stcb);
4903 SCTP_INP_RUNLOCK(inp);
4906 * We increment here since
4907 * sctp_findassociation_ep_addr() wil do a
4908 * decrement if it finds the stcb as long as
4909 * the locked tcb (last argument) is NOT a
4912 SCTP_INP_INCR_REF(inp);
4913 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4915 SCTP_INP_DECR_REF(inp);
4920 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4924 if (stcb->asoc.delayed_connection == 1) {
4925 stcb->asoc.delayed_connection = 0;
4926 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4927 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4928 stcb->asoc.primary_destination,
4929 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4930 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4933 * already expired or did not use delayed
4936 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4939 SCTP_TCB_UNLOCK(stcb);
4942 case SCTP_MAX_BURST:
4944 struct sctp_assoc_value *av;
4946 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4947 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4950 stcb->asoc.max_burst = av->assoc_value;
4951 SCTP_TCB_UNLOCK(stcb);
4953 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4954 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4955 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4956 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4957 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4958 SCTP_INP_WLOCK(inp);
4959 inp->sctp_ep.max_burst = av->assoc_value;
4960 SCTP_INP_WUNLOCK(inp);
4962 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4963 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4964 (av->assoc_id == SCTP_ALL_ASSOC))) {
4965 SCTP_INP_RLOCK(inp);
4966 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4967 SCTP_TCB_LOCK(stcb);
4968 stcb->asoc.max_burst = av->assoc_value;
4969 SCTP_TCB_UNLOCK(stcb);
4971 SCTP_INP_RUNLOCK(inp);
4978 struct sctp_assoc_value *av;
4981 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4982 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4984 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4985 ovh = SCTP_MED_OVERHEAD;
4987 ovh = SCTP_MED_V4_OVERHEAD;
4990 if (av->assoc_value) {
4991 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4993 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4995 SCTP_TCB_UNLOCK(stcb);
4997 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4998 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4999 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5000 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
5001 SCTP_INP_WLOCK(inp);
5003 * FIXME MT: I think this is not in
5004 * tune with the API ID
5006 if (av->assoc_value) {
5007 inp->sctp_frag_point = (av->assoc_value + ovh);
5009 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
5011 SCTP_INP_WUNLOCK(inp);
5013 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5021 struct sctp_event_subscribe *events;
5023 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5025 SCTP_INP_WLOCK(inp);
5026 if (events->sctp_data_io_event) {
5027 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5029 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5032 if (events->sctp_association_event) {
5033 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5035 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5038 if (events->sctp_address_event) {
5039 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5041 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5044 if (events->sctp_send_failure_event) {
5045 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5047 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5050 if (events->sctp_peer_error_event) {
5051 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5053 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5056 if (events->sctp_shutdown_event) {
5057 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5059 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5062 if (events->sctp_partial_delivery_event) {
5063 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5065 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5068 if (events->sctp_adaptation_layer_event) {
5069 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5071 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5074 if (events->sctp_authentication_event) {
5075 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5077 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5080 if (events->sctp_sender_dry_event) {
5081 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5083 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5086 if (events->sctp_stream_reset_event) {
5087 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5089 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5091 SCTP_INP_WUNLOCK(inp);
5093 SCTP_INP_RLOCK(inp);
5094 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5095 SCTP_TCB_LOCK(stcb);
5096 if (events->sctp_association_event) {
5097 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5099 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5101 if (events->sctp_address_event) {
5102 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5104 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5106 if (events->sctp_send_failure_event) {
5107 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5109 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5111 if (events->sctp_peer_error_event) {
5112 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5114 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5116 if (events->sctp_shutdown_event) {
5117 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5119 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5121 if (events->sctp_partial_delivery_event) {
5122 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5124 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5126 if (events->sctp_adaptation_layer_event) {
5127 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5129 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5131 if (events->sctp_authentication_event) {
5132 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5134 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5136 if (events->sctp_sender_dry_event) {
5137 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5139 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5141 if (events->sctp_stream_reset_event) {
5142 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5144 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5146 SCTP_TCB_UNLOCK(stcb);
5149 * Send up the sender dry event only for 1-to-1
5152 if (events->sctp_sender_dry_event) {
5153 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5154 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5155 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5157 SCTP_TCB_LOCK(stcb);
5158 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5159 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5160 (stcb->asoc.stream_queue_cnt == 0)) {
5161 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5163 SCTP_TCB_UNLOCK(stcb);
5167 SCTP_INP_RUNLOCK(inp);
5170 case SCTP_ADAPTATION_LAYER:
5172 struct sctp_setadaptation *adap_bits;
5174 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5175 SCTP_INP_WLOCK(inp);
5176 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5177 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5178 SCTP_INP_WUNLOCK(inp);
5182 case SCTP_SET_INITIAL_DBG_SEQ:
5186 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5187 SCTP_INP_WLOCK(inp);
5188 inp->sctp_ep.initial_sequence_debug = *vvv;
5189 SCTP_INP_WUNLOCK(inp);
5193 case SCTP_DEFAULT_SEND_PARAM:
5195 struct sctp_sndrcvinfo *s_info;
5197 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5198 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5201 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5202 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5204 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5207 SCTP_TCB_UNLOCK(stcb);
5209 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5210 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5211 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5212 ((s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5213 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)))) {
5214 SCTP_INP_WLOCK(inp);
5215 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5216 SCTP_INP_WUNLOCK(inp);
5218 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5219 ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5220 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC))) {
5221 SCTP_INP_RLOCK(inp);
5222 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5223 SCTP_TCB_LOCK(stcb);
5224 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5225 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5227 SCTP_TCB_UNLOCK(stcb);
5229 SCTP_INP_RUNLOCK(inp);
5234 case SCTP_PEER_ADDR_PARAMS:
5236 struct sctp_paddrparams *paddrp;
5237 struct sctp_nets *net;
5238 struct sockaddr *addr;
5239 #if defined(INET) && defined(INET6)
5240 struct sockaddr_in sin_store;
5243 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5244 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5246 #if defined(INET) && defined(INET6)
5247 if (paddrp->spp_address.ss_family == AF_INET6) {
5248 struct sockaddr_in6 *sin6;
5250 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5251 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5252 in6_sin6_2_sin(&sin_store, sin6);
5253 addr = (struct sockaddr *)&sin_store;
5255 addr = (struct sockaddr *)&paddrp->spp_address;
5258 addr = (struct sockaddr *)&paddrp->spp_address;
5261 addr = (struct sockaddr *)&paddrp->spp_address;
5264 net = sctp_findnet(stcb, addr);
5267 * We increment here since
5268 * sctp_findassociation_ep_addr() wil do a
5269 * decrement if it finds the stcb as long as
5270 * the locked tcb (last argument) is NOT a
5274 SCTP_INP_INCR_REF(inp);
5275 stcb = sctp_findassociation_ep_addr(&inp, addr,
5278 SCTP_INP_DECR_REF(inp);
5281 if ((stcb != NULL) && (net == NULL)) {
5283 if (addr->sa_family == AF_INET) {
5284 struct sockaddr_in *sin;
5286 sin = (struct sockaddr_in *)addr;
5287 if (sin->sin_addr.s_addr != INADDR_ANY) {
5288 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5289 SCTP_TCB_UNLOCK(stcb);
5296 if (addr->sa_family == AF_INET6) {
5297 struct sockaddr_in6 *sin6;
5299 sin6 = (struct sockaddr_in6 *)addr;
5300 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5301 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5302 SCTP_TCB_UNLOCK(stcb);
5309 error = EAFNOSUPPORT;
5310 SCTP_TCB_UNLOCK(stcb);
5311 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5316 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5318 SCTP_TCB_UNLOCK(stcb);
5319 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5323 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5325 SCTP_TCB_UNLOCK(stcb);
5326 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5329 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) &&
5330 ((paddrp->spp_pathmtu < SCTP_SMALLEST_PMTU) ||
5331 (paddrp->spp_pathmtu > SCTP_LARGEST_PMTU))) {
5333 SCTP_TCB_UNLOCK(stcb);
5334 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5339 /************************TCB SPECIFIC SET ******************/
5341 /************************NET SPECIFIC SET ******************/
5342 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5343 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5344 !(net->dest_state & SCTP_ADDR_NOHB)) {
5345 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5346 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5348 net->dest_state |= SCTP_ADDR_NOHB;
5350 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5351 if (paddrp->spp_hbinterval) {
5352 net->heart_beat_delay = paddrp->spp_hbinterval;
5353 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5354 net->heart_beat_delay = 0;
5356 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5357 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5358 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5359 net->dest_state &= ~SCTP_ADDR_NOHB;
5361 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5362 if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
5363 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5364 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5365 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5368 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5369 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5370 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5371 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5373 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5374 net->mtu = paddrp->spp_pathmtu;
5375 switch (net->ro._l_addr.sa.sa_family) {
5378 net->mtu += SCTP_MIN_V4_OVERHEAD;
5383 net->mtu += SCTP_MIN_OVERHEAD;
5389 if (net->mtu < stcb->asoc.smallest_mtu) {
5390 sctp_pathmtu_adjustment(stcb, net->mtu);
5393 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5394 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5395 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5397 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5399 if (paddrp->spp_pathmaxrxt) {
5400 if (net->dest_state & SCTP_ADDR_PF) {
5401 if (net->error_count > paddrp->spp_pathmaxrxt) {
5402 net->dest_state &= ~SCTP_ADDR_PF;
5405 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5406 (net->error_count > net->pf_threshold)) {
5407 net->dest_state |= SCTP_ADDR_PF;
5408 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5409 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5410 stcb->sctp_ep, stcb, net,
5411 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5412 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5415 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5416 if (net->error_count > paddrp->spp_pathmaxrxt) {
5417 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5418 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5421 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5422 net->dest_state |= SCTP_ADDR_REACHABLE;
5423 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5426 net->failure_threshold = paddrp->spp_pathmaxrxt;
5428 if (paddrp->spp_flags & SPP_DSCP) {
5429 net->dscp = paddrp->spp_dscp & 0xfc;
5433 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5434 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5435 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5436 net->flowlabel |= 0x80000000;
5441 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5442 if (paddrp->spp_pathmaxrxt != 0) {
5443 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5444 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5445 if (net->dest_state & SCTP_ADDR_PF) {
5446 if (net->error_count > paddrp->spp_pathmaxrxt) {
5447 net->dest_state &= ~SCTP_ADDR_PF;
5450 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5451 (net->error_count > net->pf_threshold)) {
5452 net->dest_state |= SCTP_ADDR_PF;
5453 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5454 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5455 stcb->sctp_ep, stcb, net,
5456 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5457 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5460 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5461 if (net->error_count > paddrp->spp_pathmaxrxt) {
5462 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5463 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5466 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5467 net->dest_state |= SCTP_ADDR_REACHABLE;
5468 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5471 net->failure_threshold = paddrp->spp_pathmaxrxt;
5475 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5476 if (paddrp->spp_hbinterval != 0) {
5477 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5478 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5479 stcb->asoc.heart_beat_delay = 0;
5481 /* Turn back on the timer */
5482 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5483 if (paddrp->spp_hbinterval != 0) {
5484 net->heart_beat_delay = paddrp->spp_hbinterval;
5485 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5486 net->heart_beat_delay = 0;
5488 if (net->dest_state & SCTP_ADDR_NOHB) {
5489 net->dest_state &= ~SCTP_ADDR_NOHB;
5491 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5492 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5493 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5495 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5497 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5498 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5499 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5500 net->dest_state |= SCTP_ADDR_NOHB;
5501 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5502 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5504 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5508 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5510 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5511 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5512 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5513 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5514 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5516 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5517 net->mtu = paddrp->spp_pathmtu;
5518 switch (net->ro._l_addr.sa.sa_family) {
5521 net->mtu += SCTP_MIN_V4_OVERHEAD;
5526 net->mtu += SCTP_MIN_OVERHEAD;
5532 if (net->mtu < stcb->asoc.smallest_mtu) {
5533 sctp_pathmtu_adjustment(stcb, net->mtu);
5536 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5537 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5539 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5540 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5541 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5542 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5544 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5546 stcb->asoc.default_mtu = 0;
5547 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5549 if (paddrp->spp_flags & SPP_DSCP) {
5550 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5551 net->dscp = paddrp->spp_dscp & 0xfc;
5554 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5555 stcb->asoc.default_dscp |= 0x01;
5558 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5559 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5560 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5561 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5562 net->flowlabel |= 0x80000000;
5565 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5566 stcb->asoc.default_flowlabel |= 0x80000000;
5570 SCTP_TCB_UNLOCK(stcb);
5572 /************************NO TCB, SET TO default stuff ******************/
5573 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5574 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5575 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5576 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
5577 SCTP_INP_WLOCK(inp);
5579 * For the TOS/FLOWLABEL stuff you
5580 * set it with the options on the
5583 if (paddrp->spp_pathmaxrxt != 0) {
5584 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5587 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5588 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5589 else if (paddrp->spp_hbinterval != 0) {
5590 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5591 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5592 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5595 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5596 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5597 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5598 } else if (paddrp->spp_hbinterval) {
5599 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5601 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5602 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5603 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5605 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5606 inp->sctp_ep.default_mtu = 0;
5607 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5608 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5609 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5610 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5612 if (paddrp->spp_flags & SPP_DSCP) {
5613 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5614 inp->sctp_ep.default_dscp |= 0x01;
5617 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5618 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5619 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5620 inp->sctp_ep.default_flowlabel |= 0x80000000;
5624 SCTP_INP_WUNLOCK(inp);
5626 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5634 struct sctp_rtoinfo *srto;
5635 uint32_t new_init, new_min, new_max;
5637 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5638 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5641 if (srto->srto_initial)
5642 new_init = srto->srto_initial;
5644 new_init = stcb->asoc.initial_rto;
5646 new_max = srto->srto_max;
5648 new_max = stcb->asoc.maxrto;
5650 new_min = srto->srto_min;
5652 new_min = stcb->asoc.minrto;
5653 if ((new_min <= new_init) && (new_init <= new_max)) {
5654 stcb->asoc.initial_rto = new_init;
5655 stcb->asoc.maxrto = new_max;
5656 stcb->asoc.minrto = new_min;
5658 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5661 SCTP_TCB_UNLOCK(stcb);
5663 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5664 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5665 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5666 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
5667 SCTP_INP_WLOCK(inp);
5668 if (srto->srto_initial)
5669 new_init = srto->srto_initial;
5671 new_init = inp->sctp_ep.initial_rto;
5673 new_max = srto->srto_max;
5675 new_max = inp->sctp_ep.sctp_maxrto;
5677 new_min = srto->srto_min;
5679 new_min = inp->sctp_ep.sctp_minrto;
5680 if ((new_min <= new_init) && (new_init <= new_max)) {
5681 inp->sctp_ep.initial_rto = new_init;
5682 inp->sctp_ep.sctp_maxrto = new_max;
5683 inp->sctp_ep.sctp_minrto = new_min;
5685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5688 SCTP_INP_WUNLOCK(inp);
5690 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5696 case SCTP_ASSOCINFO:
5698 struct sctp_assocparams *sasoc;
5700 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5701 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5702 if (sasoc->sasoc_cookie_life > 0) {
5703 /* boundary check the cookie life */
5704 if (sasoc->sasoc_cookie_life < SCTP_MIN_COOKIE_LIFE) {
5705 sasoc->sasoc_cookie_life = SCTP_MIN_COOKIE_LIFE;
5707 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5708 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5712 if (sasoc->sasoc_asocmaxrxt > 0) {
5713 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5715 if (sasoc->sasoc_cookie_life > 0) {
5716 stcb->asoc.cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5718 SCTP_TCB_UNLOCK(stcb);
5720 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5721 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5722 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5723 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
5724 SCTP_INP_WLOCK(inp);
5725 if (sasoc->sasoc_asocmaxrxt > 0) {
5726 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5728 if (sasoc->sasoc_cookie_life > 0) {
5729 inp->sctp_ep.def_cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5731 SCTP_INP_WUNLOCK(inp);
5733 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5741 struct sctp_initmsg *sinit;
5743 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5744 SCTP_INP_WLOCK(inp);
5745 if (sinit->sinit_num_ostreams)
5746 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5748 if (sinit->sinit_max_instreams)
5749 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5751 if (sinit->sinit_max_attempts)
5752 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5754 if (sinit->sinit_max_init_timeo)
5755 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5756 SCTP_INP_WUNLOCK(inp);
5759 case SCTP_PRIMARY_ADDR:
5761 struct sctp_setprim *spa;
5762 struct sctp_nets *net;
5763 struct sockaddr *addr;
5764 #if defined(INET) && defined(INET6)
5765 struct sockaddr_in sin_store;
5768 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5769 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5771 #if defined(INET) && defined(INET6)
5772 if (spa->ssp_addr.ss_family == AF_INET6) {
5773 struct sockaddr_in6 *sin6;
5775 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5776 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5777 in6_sin6_2_sin(&sin_store, sin6);
5778 addr = (struct sockaddr *)&sin_store;
5780 addr = (struct sockaddr *)&spa->ssp_addr;
5783 addr = (struct sockaddr *)&spa->ssp_addr;
5786 addr = (struct sockaddr *)&spa->ssp_addr;
5789 net = sctp_findnet(stcb, addr);
5792 * We increment here since
5793 * sctp_findassociation_ep_addr() wil do a
5794 * decrement if it finds the stcb as long as
5795 * the locked tcb (last argument) is NOT a
5799 SCTP_INP_INCR_REF(inp);
5800 stcb = sctp_findassociation_ep_addr(&inp, addr,
5803 SCTP_INP_DECR_REF(inp);
5807 if ((stcb != NULL) && (net != NULL)) {
5808 if (net != stcb->asoc.primary_destination) {
5809 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5810 /* Ok we need to set it */
5811 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5812 if ((stcb->asoc.alternate) &&
5813 (!(net->dest_state & SCTP_ADDR_PF)) &&
5814 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5815 sctp_free_remote_addr(stcb->asoc.alternate);
5816 stcb->asoc.alternate = NULL;
5819 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5823 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5828 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5832 SCTP_TCB_UNLOCK(stcb);
5836 case SCTP_SET_DYNAMIC_PRIMARY:
5838 union sctp_sockstore *ss;
5840 error = priv_check(curthread,
5841 PRIV_NETINET_RESERVEDPORT);
5845 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5846 /* SUPER USER CHECK? */
5847 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5850 case SCTP_SET_PEER_PRIMARY_ADDR:
5852 struct sctp_setpeerprim *sspp;
5853 struct sockaddr *addr;
5854 #if defined(INET) && defined(INET6)
5855 struct sockaddr_in sin_store;
5858 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5859 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5861 struct sctp_ifa *ifa;
5863 #if defined(INET) && defined(INET6)
5864 if (sspp->sspp_addr.ss_family == AF_INET6) {
5865 struct sockaddr_in6 *sin6;
5867 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5868 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5869 in6_sin6_2_sin(&sin_store, sin6);
5870 addr = (struct sockaddr *)&sin_store;
5872 addr = (struct sockaddr *)&sspp->sspp_addr;
5875 addr = (struct sockaddr *)&sspp->sspp_addr;
5878 addr = (struct sockaddr *)&sspp->sspp_addr;
5880 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5886 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5888 * Must validate the ifa found is in
5891 struct sctp_laddr *laddr;
5894 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5895 if (laddr->ifa == NULL) {
5896 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5900 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5901 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5904 if (laddr->ifa == ifa) {
5910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5915 switch (addr->sa_family) {
5919 struct sockaddr_in *sin;
5921 sin = (struct sockaddr_in *)addr;
5922 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5923 &sin->sin_addr) != 0) {
5924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5934 struct sockaddr_in6 *sin6;
5936 sin6 = (struct sockaddr_in6 *)addr;
5937 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5938 &sin6->sin6_addr) != 0) {
5939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5947 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5952 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5953 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5956 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5958 SCTP_TCB_UNLOCK(stcb);
5960 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5965 case SCTP_BINDX_ADD_ADDR:
5967 struct sockaddr *sa;
5970 td = (struct thread *)p;
5971 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
5973 if (sa->sa_family == AF_INET) {
5974 if (optsize < sizeof(struct sockaddr_in)) {
5975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5980 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
5981 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5987 if (sa->sa_family == AF_INET6) {
5988 if (optsize < sizeof(struct sockaddr_in6)) {
5989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5994 (error = prison_local_ip6(td->td_ucred,
5995 &(((struct sockaddr_in6 *)sa)->sin6_addr),
5996 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5997 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6003 error = EAFNOSUPPORT;
6006 sctp_bindx_add_address(so, inp, sa, vrf_id, &error, p);
6009 case SCTP_BINDX_REM_ADDR:
6011 struct sockaddr *sa;
6014 td = (struct thread *)p;
6016 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
6018 if (sa->sa_family == AF_INET) {
6019 if (optsize < sizeof(struct sockaddr_in)) {
6020 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6025 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
6026 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6032 if (sa->sa_family == AF_INET6) {
6033 if (optsize < sizeof(struct sockaddr_in6)) {
6034 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6039 (error = prison_local_ip6(td->td_ucred,
6040 &(((struct sockaddr_in6 *)sa)->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_delete_address(inp, sa, vrf_id, &error);
6056 struct sctp_event *event;
6057 uint32_t event_type;
6059 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6060 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6061 switch (event->se_type) {
6062 case SCTP_ASSOC_CHANGE:
6063 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6065 case SCTP_PEER_ADDR_CHANGE:
6066 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6068 case SCTP_REMOTE_ERROR:
6069 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6071 case SCTP_SEND_FAILED:
6072 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6074 case SCTP_SHUTDOWN_EVENT:
6075 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6077 case SCTP_ADAPTATION_INDICATION:
6078 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6080 case SCTP_PARTIAL_DELIVERY_EVENT:
6081 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6083 case SCTP_AUTHENTICATION_EVENT:
6084 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6086 case SCTP_STREAM_RESET_EVENT:
6087 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6089 case SCTP_SENDER_DRY_EVENT:
6090 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6092 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6094 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6097 case SCTP_ASSOC_RESET_EVENT:
6098 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6100 case SCTP_STREAM_CHANGE_EVENT:
6101 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6103 case SCTP_SEND_FAILED_EVENT:
6104 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6108 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6112 if (event_type > 0) {
6115 sctp_stcb_feature_on(inp, stcb, event_type);
6116 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6117 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6118 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6119 (stcb->asoc.stream_queue_cnt == 0)) {
6120 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6124 sctp_stcb_feature_off(inp, stcb, event_type);
6126 SCTP_TCB_UNLOCK(stcb);
6129 * We don't want to send up a storm
6130 * of events, so return an error for
6133 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6134 (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6135 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6136 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6137 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6141 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6142 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6143 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6144 ((event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6145 (event->se_assoc_id == SCTP_ALL_ASSOC)))) {
6146 SCTP_INP_WLOCK(inp);
6148 sctp_feature_on(inp, event_type);
6150 sctp_feature_off(inp, event_type);
6152 SCTP_INP_WUNLOCK(inp);
6154 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6155 ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6156 (event->se_assoc_id == SCTP_ALL_ASSOC))) {
6157 SCTP_INP_RLOCK(inp);
6158 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6159 SCTP_TCB_LOCK(stcb);
6161 sctp_stcb_feature_on(inp, stcb, event_type);
6163 sctp_stcb_feature_off(inp, stcb, event_type);
6165 SCTP_TCB_UNLOCK(stcb);
6167 SCTP_INP_RUNLOCK(inp);
6172 SCTP_TCB_UNLOCK(stcb);
6177 case SCTP_RECVRCVINFO:
6181 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6182 SCTP_INP_WLOCK(inp);
6184 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6186 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6188 SCTP_INP_WUNLOCK(inp);
6191 case SCTP_RECVNXTINFO:
6195 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6196 SCTP_INP_WLOCK(inp);
6198 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6200 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6202 SCTP_INP_WUNLOCK(inp);
6205 case SCTP_DEFAULT_SNDINFO:
6207 struct sctp_sndinfo *info;
6210 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6211 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6214 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6215 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6216 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6217 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6218 stcb->asoc.def_send.sinfo_flags |= policy;
6219 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6220 stcb->asoc.def_send.sinfo_context = info->snd_context;
6222 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6225 SCTP_TCB_UNLOCK(stcb);
6227 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6228 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6229 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6230 ((info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6231 (info->snd_assoc_id == SCTP_ALL_ASSOC)))) {
6232 SCTP_INP_WLOCK(inp);
6233 inp->def_send.sinfo_stream = info->snd_sid;
6234 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6235 inp->def_send.sinfo_flags = info->snd_flags;
6236 inp->def_send.sinfo_flags |= policy;
6237 inp->def_send.sinfo_ppid = info->snd_ppid;
6238 inp->def_send.sinfo_context = info->snd_context;
6239 SCTP_INP_WUNLOCK(inp);
6241 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6242 ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6243 (info->snd_assoc_id == SCTP_ALL_ASSOC))) {
6244 SCTP_INP_RLOCK(inp);
6245 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6246 SCTP_TCB_LOCK(stcb);
6247 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6248 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6249 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6250 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6251 stcb->asoc.def_send.sinfo_flags |= policy;
6252 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6253 stcb->asoc.def_send.sinfo_context = info->snd_context;
6255 SCTP_TCB_UNLOCK(stcb);
6257 SCTP_INP_RUNLOCK(inp);
6262 case SCTP_DEFAULT_PRINFO:
6264 struct sctp_default_prinfo *info;
6266 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6267 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6269 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6271 SCTP_TCB_UNLOCK(stcb);
6273 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6278 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6279 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6280 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6281 SCTP_TCB_UNLOCK(stcb);
6283 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6284 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6285 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6286 ((info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6287 (info->pr_assoc_id == SCTP_ALL_ASSOC)))) {
6288 SCTP_INP_WLOCK(inp);
6289 inp->def_send.sinfo_flags &= 0xfff0;
6290 inp->def_send.sinfo_flags |= info->pr_policy;
6291 inp->def_send.sinfo_timetolive = info->pr_value;
6292 SCTP_INP_WUNLOCK(inp);
6294 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6295 ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6296 (info->pr_assoc_id == SCTP_ALL_ASSOC))) {
6297 SCTP_INP_RLOCK(inp);
6298 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6299 SCTP_TCB_LOCK(stcb);
6300 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6301 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6302 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6303 SCTP_TCB_UNLOCK(stcb);
6305 SCTP_INP_RUNLOCK(inp);
6310 case SCTP_PEER_ADDR_THLDS:
6311 /* Applies to the specific association */
6313 struct sctp_paddrthlds *thlds;
6314 struct sctp_nets *net;
6315 struct sockaddr *addr;
6316 #if defined(INET) && defined(INET6)
6317 struct sockaddr_in sin_store;
6320 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6321 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6323 #if defined(INET) && defined(INET6)
6324 if (thlds->spt_address.ss_family == AF_INET6) {
6325 struct sockaddr_in6 *sin6;
6327 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6328 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6329 in6_sin6_2_sin(&sin_store, sin6);
6330 addr = (struct sockaddr *)&sin_store;
6332 addr = (struct sockaddr *)&thlds->spt_address;
6335 addr = (struct sockaddr *)&thlds->spt_address;
6338 addr = (struct sockaddr *)&thlds->spt_address;
6341 net = sctp_findnet(stcb, addr);
6344 * We increment here since
6345 * sctp_findassociation_ep_addr() wil do a
6346 * decrement if it finds the stcb as long as
6347 * the locked tcb (last argument) is NOT a
6351 SCTP_INP_INCR_REF(inp);
6352 stcb = sctp_findassociation_ep_addr(&inp, addr,
6355 SCTP_INP_DECR_REF(inp);
6358 if ((stcb != NULL) && (net == NULL)) {
6360 if (addr->sa_family == AF_INET) {
6361 struct sockaddr_in *sin;
6363 sin = (struct sockaddr_in *)addr;
6364 if (sin->sin_addr.s_addr != INADDR_ANY) {
6365 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6366 SCTP_TCB_UNLOCK(stcb);
6373 if (addr->sa_family == AF_INET6) {
6374 struct sockaddr_in6 *sin6;
6376 sin6 = (struct sockaddr_in6 *)addr;
6377 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6378 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6379 SCTP_TCB_UNLOCK(stcb);
6386 error = EAFNOSUPPORT;
6387 SCTP_TCB_UNLOCK(stcb);
6388 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6392 if (thlds->spt_pathcpthld != 0xffff) {
6394 SCTP_TCB_UNLOCK(stcb);
6397 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6402 net->failure_threshold = thlds->spt_pathmaxrxt;
6403 net->pf_threshold = thlds->spt_pathpfthld;
6404 if (net->dest_state & SCTP_ADDR_PF) {
6405 if ((net->error_count > net->failure_threshold) ||
6406 (net->error_count <= net->pf_threshold)) {
6407 net->dest_state &= ~SCTP_ADDR_PF;
6410 if ((net->error_count > net->pf_threshold) &&
6411 (net->error_count <= net->failure_threshold)) {
6412 net->dest_state |= SCTP_ADDR_PF;
6413 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6414 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6415 stcb->sctp_ep, stcb, net,
6416 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6417 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6420 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6421 if (net->error_count > net->failure_threshold) {
6422 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6423 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6426 if (net->error_count <= net->failure_threshold) {
6427 net->dest_state |= SCTP_ADDR_REACHABLE;
6428 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6432 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6433 net->failure_threshold = thlds->spt_pathmaxrxt;
6434 net->pf_threshold = thlds->spt_pathpfthld;
6435 if (net->dest_state & SCTP_ADDR_PF) {
6436 if ((net->error_count > net->failure_threshold) ||
6437 (net->error_count <= net->pf_threshold)) {
6438 net->dest_state &= ~SCTP_ADDR_PF;
6441 if ((net->error_count > net->pf_threshold) &&
6442 (net->error_count <= net->failure_threshold)) {
6443 net->dest_state |= SCTP_ADDR_PF;
6444 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6445 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6446 stcb->sctp_ep, stcb, net,
6447 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6448 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6451 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6452 if (net->error_count > net->failure_threshold) {
6453 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6454 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6457 if (net->error_count <= net->failure_threshold) {
6458 net->dest_state |= SCTP_ADDR_REACHABLE;
6459 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6463 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6464 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6466 SCTP_TCB_UNLOCK(stcb);
6468 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6469 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6470 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6471 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
6472 SCTP_INP_WLOCK(inp);
6473 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6474 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6475 SCTP_INP_WUNLOCK(inp);
6477 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6483 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6485 struct sctp_udpencaps *encaps;
6486 struct sctp_nets *net;
6487 struct sockaddr *addr;
6488 #if defined(INET) && defined(INET6)
6489 struct sockaddr_in sin_store;
6492 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6493 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6495 #if defined(INET) && defined(INET6)
6496 if (encaps->sue_address.ss_family == AF_INET6) {
6497 struct sockaddr_in6 *sin6;
6499 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6500 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6501 in6_sin6_2_sin(&sin_store, sin6);
6502 addr = (struct sockaddr *)&sin_store;
6504 addr = (struct sockaddr *)&encaps->sue_address;
6507 addr = (struct sockaddr *)&encaps->sue_address;
6510 addr = (struct sockaddr *)&encaps->sue_address;
6513 net = sctp_findnet(stcb, addr);
6516 * We increment here since
6517 * sctp_findassociation_ep_addr() wil do a
6518 * decrement if it finds the stcb as long as
6519 * the locked tcb (last argument) is NOT a
6523 SCTP_INP_INCR_REF(inp);
6524 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6526 SCTP_INP_DECR_REF(inp);
6529 if ((stcb != NULL) && (net == NULL)) {
6531 if (addr->sa_family == AF_INET) {
6532 struct sockaddr_in *sin;
6534 sin = (struct sockaddr_in *)addr;
6535 if (sin->sin_addr.s_addr != INADDR_ANY) {
6536 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6537 SCTP_TCB_UNLOCK(stcb);
6544 if (addr->sa_family == AF_INET6) {
6545 struct sockaddr_in6 *sin6;
6547 sin6 = (struct sockaddr_in6 *)addr;
6548 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6549 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6550 SCTP_TCB_UNLOCK(stcb);
6557 error = EAFNOSUPPORT;
6558 SCTP_TCB_UNLOCK(stcb);
6559 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6566 net->port = encaps->sue_port;
6568 stcb->asoc.port = encaps->sue_port;
6570 SCTP_TCB_UNLOCK(stcb);
6572 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6573 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6574 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6575 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
6576 SCTP_INP_WLOCK(inp);
6577 inp->sctp_ep.port = encaps->sue_port;
6578 SCTP_INP_WUNLOCK(inp);
6580 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6586 case SCTP_ECN_SUPPORTED:
6588 struct sctp_assoc_value *av;
6590 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6591 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6596 SCTP_TCB_UNLOCK(stcb);
6598 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6599 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6600 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6601 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6602 SCTP_INP_WLOCK(inp);
6603 if (av->assoc_value == 0) {
6604 inp->ecn_supported = 0;
6606 inp->ecn_supported = 1;
6608 SCTP_INP_WUNLOCK(inp);
6610 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6616 case SCTP_PR_SUPPORTED:
6618 struct sctp_assoc_value *av;
6620 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6621 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6624 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6626 SCTP_TCB_UNLOCK(stcb);
6628 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6629 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6630 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6631 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6632 SCTP_INP_WLOCK(inp);
6633 if (av->assoc_value == 0) {
6634 inp->prsctp_supported = 0;
6636 inp->prsctp_supported = 1;
6638 SCTP_INP_WUNLOCK(inp);
6640 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6646 case SCTP_AUTH_SUPPORTED:
6648 struct sctp_assoc_value *av;
6650 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6651 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6654 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6656 SCTP_TCB_UNLOCK(stcb);
6658 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6659 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6660 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6661 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6662 if ((av->assoc_value == 0) &&
6663 (inp->asconf_supported == 1)) {
6665 * AUTH is required for
6668 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6671 SCTP_INP_WLOCK(inp);
6672 if (av->assoc_value == 0) {
6673 inp->auth_supported = 0;
6675 inp->auth_supported = 1;
6677 SCTP_INP_WUNLOCK(inp);
6680 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6686 case SCTP_ASCONF_SUPPORTED:
6688 struct sctp_assoc_value *av;
6690 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6691 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6694 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6696 SCTP_TCB_UNLOCK(stcb);
6698 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6699 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6700 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6701 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6702 if ((av->assoc_value != 0) &&
6703 (inp->auth_supported == 0)) {
6705 * AUTH is required for
6708 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6711 SCTP_INP_WLOCK(inp);
6712 if (av->assoc_value == 0) {
6713 inp->asconf_supported = 0;
6714 sctp_auth_delete_chunk(SCTP_ASCONF,
6715 inp->sctp_ep.local_auth_chunks);
6716 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6717 inp->sctp_ep.local_auth_chunks);
6719 inp->asconf_supported = 1;
6720 sctp_auth_add_chunk(SCTP_ASCONF,
6721 inp->sctp_ep.local_auth_chunks);
6722 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6723 inp->sctp_ep.local_auth_chunks);
6725 SCTP_INP_WUNLOCK(inp);
6728 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6734 case SCTP_RECONFIG_SUPPORTED:
6736 struct sctp_assoc_value *av;
6738 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6739 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6744 SCTP_TCB_UNLOCK(stcb);
6746 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6747 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6748 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6749 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6750 SCTP_INP_WLOCK(inp);
6751 if (av->assoc_value == 0) {
6752 inp->reconfig_supported = 0;
6754 inp->reconfig_supported = 1;
6756 SCTP_INP_WUNLOCK(inp);
6758 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6764 case SCTP_NRSACK_SUPPORTED:
6766 struct sctp_assoc_value *av;
6768 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6769 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6772 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6774 SCTP_TCB_UNLOCK(stcb);
6776 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6777 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6778 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6779 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6780 SCTP_INP_WLOCK(inp);
6781 if (av->assoc_value == 0) {
6782 inp->nrsack_supported = 0;
6784 inp->nrsack_supported = 1;
6786 SCTP_INP_WUNLOCK(inp);
6788 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6794 case SCTP_PKTDROP_SUPPORTED:
6796 struct sctp_assoc_value *av;
6798 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6799 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6802 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6804 SCTP_TCB_UNLOCK(stcb);
6806 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6807 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6808 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6809 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6810 SCTP_INP_WLOCK(inp);
6811 if (av->assoc_value == 0) {
6812 inp->pktdrop_supported = 0;
6814 inp->pktdrop_supported = 1;
6816 SCTP_INP_WUNLOCK(inp);
6818 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6826 struct sctp_assoc_value *av;
6827 struct sctp_nets *net;
6829 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6830 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6833 stcb->asoc.max_cwnd = av->assoc_value;
6834 if (stcb->asoc.max_cwnd > 0) {
6835 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6836 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6837 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6838 net->cwnd = stcb->asoc.max_cwnd;
6839 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6840 net->cwnd = net->mtu - sizeof(struct sctphdr);
6845 SCTP_TCB_UNLOCK(stcb);
6847 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6848 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6849 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6850 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6851 SCTP_INP_WLOCK(inp);
6852 inp->max_cwnd = av->assoc_value;
6853 SCTP_INP_WUNLOCK(inp);
6855 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6862 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6863 error = ENOPROTOOPT;
6865 } /* end switch (opt) */
6870 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6872 struct epoch_tracker et;
6873 struct sctp_inpcb *inp;
6874 void *optval = NULL;
6879 if ((sopt->sopt_level == SOL_SOCKET) &&
6880 (sopt->sopt_name == SO_SETFIB)) {
6881 inp = (struct sctp_inpcb *)so->so_pcb;
6883 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6886 SCTP_INP_WLOCK(inp);
6887 inp->fibnum = so->so_fibnum;
6888 SCTP_INP_WUNLOCK(inp);
6891 if (sopt->sopt_level != IPPROTO_SCTP) {
6892 /* wrong proto level... send back up to IP */
6894 if (INP_CHECK_SOCKAF(so, AF_INET6))
6895 error = ip6_ctloutput(so, sopt);
6897 #if defined(INET) && defined(INET6)
6901 error = ip_ctloutput(so, sopt);
6905 optsize = sopt->sopt_valsize;
6906 if (optsize > SCTP_SOCKET_OPTION_LIMIT) {
6907 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6911 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6912 if (optval == NULL) {
6913 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6916 error = sooptcopyin(sopt, optval, optsize, optsize);
6918 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6922 p = (void *)sopt->sopt_td;
6923 if (sopt->sopt_dir == SOPT_SET) {
6924 NET_EPOCH_ENTER(et);
6925 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6927 } else if (sopt->sopt_dir == SOPT_GET) {
6928 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6930 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6933 if ((error == 0) && (optval != NULL)) {
6934 error = sooptcopyout(sopt, optval, optsize);
6935 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6936 } else if (optval != NULL) {
6937 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6945 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6947 struct epoch_tracker et;
6949 int create_lock_on = 0;
6951 struct sctp_inpcb *inp;
6952 struct sctp_tcb *stcb = NULL;
6954 inp = (struct sctp_inpcb *)so->so_pcb;
6956 /* I made the same as TCP since we are not setup? */
6957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6958 return (ECONNRESET);
6961 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6965 switch (addr->sa_family) {
6969 struct sockaddr_in6 *sin6;
6971 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6972 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6975 sin6 = (struct sockaddr_in6 *)addr;
6976 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6->sin6_addr)) != 0) {
6977 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6986 struct sockaddr_in *sin;
6988 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6992 sin = (struct sockaddr_in *)addr;
6993 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sin->sin_addr)) != 0) {
6994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7001 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
7002 return (EAFNOSUPPORT);
7004 SCTP_INP_INCR_REF(inp);
7005 SCTP_ASOC_CREATE_LOCK(inp);
7007 NET_EPOCH_ENTER(et);
7009 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
7010 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
7011 /* Should I really unlock ? */
7012 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
7017 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
7018 (addr->sa_family == AF_INET6)) {
7019 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7024 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
7025 SCTP_PCB_FLAGS_UNBOUND) {
7026 /* Bind a ephemeral port */
7027 error = sctp_inpcb_bind(so, NULL, NULL, p);
7032 /* Now do we connect? */
7033 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
7034 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
7035 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7039 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7040 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7041 /* We are already connected AND the TCP model */
7042 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7046 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7047 SCTP_INP_RLOCK(inp);
7048 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7049 SCTP_INP_RUNLOCK(inp);
7052 * We increment here since sctp_findassociation_ep_addr()
7053 * will do a decrement if it finds the stcb as long as the
7054 * locked tcb (last argument) is NOT a TCB.. aka NULL.
7056 SCTP_INP_INCR_REF(inp);
7057 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7059 SCTP_INP_DECR_REF(inp);
7061 SCTP_TCB_UNLOCK(stcb);
7065 /* Already have or am bring up an association */
7066 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7071 vrf_id = inp->def_vrf_id;
7072 /* We are GOOD to go */
7073 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
7074 inp->sctp_ep.pre_open_stream_count,
7075 inp->sctp_ep.port, p,
7076 SCTP_INITIALIZE_AUTH_PARAMS);
7078 /* Gak! no memory */
7081 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7082 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7083 /* Set the connected flag so we can queue data */
7086 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7087 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7089 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7090 SCTP_TCB_UNLOCK(stcb);
7093 if (create_lock_on) {
7094 SCTP_ASOC_CREATE_UNLOCK(inp);
7096 SCTP_INP_DECR_REF(inp);
7102 sctp_listen(struct socket *so, int backlog, struct thread *p)
7105 * Note this module depends on the protocol processing being called
7106 * AFTER any socket level flags and backlog are applied to the
7107 * socket. The traditional way that the socket flags are applied is
7108 * AFTER protocol processing. We have made a change to the
7109 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7110 * place if the socket API for SCTP is to work properly.
7114 struct sctp_inpcb *inp;
7116 inp = (struct sctp_inpcb *)so->so_pcb;
7118 /* I made the same as TCP since we are not setup? */
7119 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7120 return (ECONNRESET);
7122 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7123 /* See if we have a listener */
7124 struct sctp_inpcb *tinp;
7125 union sctp_sockstore store;
7127 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7129 struct sctp_laddr *laddr;
7131 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7132 memcpy(&store, &laddr->ifa->address, sizeof(store));
7133 switch (store.sa.sa_family) {
7136 store.sin.sin_port = inp->sctp_lport;
7141 store.sin6.sin6_port = inp->sctp_lport;
7147 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7148 if (tinp && (tinp != inp) &&
7149 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7150 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7151 (SCTP_IS_LISTENING(tinp))) {
7153 * we have a listener already and
7156 SCTP_INP_DECR_REF(tinp);
7157 return (EADDRINUSE);
7159 SCTP_INP_DECR_REF(tinp);
7163 /* Setup a local addr bound all */
7164 memset(&store, 0, sizeof(store));
7166 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7167 store.sa.sa_family = AF_INET6;
7168 store.sa.sa_len = sizeof(struct sockaddr_in6);
7172 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7173 store.sa.sa_family = AF_INET;
7174 store.sa.sa_len = sizeof(struct sockaddr_in);
7177 switch (store.sa.sa_family) {
7180 store.sin.sin_port = inp->sctp_lport;
7185 store.sin6.sin6_port = inp->sctp_lport;
7191 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7192 if (tinp && (tinp != inp) &&
7193 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7194 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7195 (SCTP_IS_LISTENING(tinp))) {
7197 * we have a listener already and its not
7200 SCTP_INP_DECR_REF(tinp);
7201 return (EADDRINUSE);
7203 SCTP_INP_DECR_REF(tinp);
7207 SCTP_INP_RLOCK(inp);
7208 #ifdef SCTP_LOCK_LOGGING
7209 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7210 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7214 error = solisten_proto_check(so);
7217 SCTP_INP_RUNLOCK(inp);
7220 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7221 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7223 * The unlucky case - We are in the tcp pool with this guy.
7224 * - Someone else is in the main inp slot. - We must move
7225 * this guy (the listener) to the main slot - We must then
7226 * move the guy that was listener to the TCP Pool.
7228 if (sctp_swap_inpcb_for_listen(inp)) {
7229 SCTP_INP_RUNLOCK(inp);
7230 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7231 return (EADDRINUSE);
7235 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7236 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7237 /* We are already connected AND the TCP model */
7238 SCTP_INP_RUNLOCK(inp);
7239 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7240 return (EADDRINUSE);
7242 SCTP_INP_RUNLOCK(inp);
7243 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7244 /* We must do a bind. */
7245 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7246 /* bind error, probably perm */
7250 SCTP_INP_WLOCK(inp);
7251 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7253 solisten_proto(so, backlog);
7257 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7259 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7261 SCTP_INP_WUNLOCK(inp);
7265 static int sctp_defered_wakeup_cnt = 0;
7268 sctp_accept(struct socket *so, struct sockaddr **addr)
7270 struct sctp_tcb *stcb;
7271 struct sctp_inpcb *inp;
7272 union sctp_sockstore store;
7276 inp = (struct sctp_inpcb *)so->so_pcb;
7279 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7280 return (ECONNRESET);
7282 SCTP_INP_WLOCK(inp);
7283 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7284 SCTP_INP_WUNLOCK(inp);
7285 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7286 return (EOPNOTSUPP);
7288 if (so->so_state & SS_ISDISCONNECTED) {
7289 SCTP_INP_WUNLOCK(inp);
7290 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7291 return (ECONNABORTED);
7293 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7295 SCTP_INP_WUNLOCK(inp);
7296 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7297 return (ECONNRESET);
7299 SCTP_TCB_LOCK(stcb);
7300 store = stcb->asoc.primary_destination->ro._l_addr;
7301 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7302 /* Wake any delayed sleep action */
7303 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7304 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7305 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7306 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7307 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7308 if (sowriteable(inp->sctp_socket)) {
7309 sowwakeup_locked(inp->sctp_socket);
7311 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7314 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7315 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7316 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7317 if (soreadable(inp->sctp_socket)) {
7318 sctp_defered_wakeup_cnt++;
7319 sorwakeup_locked(inp->sctp_socket);
7321 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7325 SCTP_INP_WUNLOCK(inp);
7326 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7327 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7328 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7330 SCTP_TCB_UNLOCK(stcb);
7332 switch (store.sa.sa_family) {
7336 struct sockaddr_in *sin;
7338 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7341 sin->sin_family = AF_INET;
7342 sin->sin_len = sizeof(*sin);
7343 sin->sin_port = store.sin.sin_port;
7344 sin->sin_addr = store.sin.sin_addr;
7345 *addr = (struct sockaddr *)sin;
7352 struct sockaddr_in6 *sin6;
7354 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7357 sin6->sin6_family = AF_INET6;
7358 sin6->sin6_len = sizeof(*sin6);
7359 sin6->sin6_port = store.sin6.sin6_port;
7360 sin6->sin6_addr = store.sin6.sin6_addr;
7361 if ((error = sa6_recoverscope(sin6)) != 0) {
7362 SCTP_FREE_SONAME(sin6);
7365 *addr = (struct sockaddr *)sin6;
7378 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7380 struct sockaddr_in *sin;
7382 struct sctp_inpcb *inp;
7383 struct sctp_ifa *sctp_ifa;
7386 * Do the malloc first in case it blocks.
7388 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7391 sin->sin_family = AF_INET;
7392 sin->sin_len = sizeof(*sin);
7393 inp = (struct sctp_inpcb *)so->so_pcb;
7395 SCTP_FREE_SONAME(sin);
7396 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7397 return (ECONNRESET);
7399 SCTP_INP_RLOCK(inp);
7400 sin->sin_port = inp->sctp_lport;
7401 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7402 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7403 struct sctp_tcb *stcb;
7404 struct sockaddr_in *sin_a;
7405 struct sctp_nets *net;
7408 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7414 SCTP_TCB_LOCK(stcb);
7415 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7416 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7418 /* this will make coverity happy */
7421 if (sin_a->sin_family == AF_INET) {
7426 if ((!fnd) || (sin_a == NULL)) {
7428 SCTP_TCB_UNLOCK(stcb);
7432 vrf_id = inp->def_vrf_id;
7433 sctp_ifa = sctp_source_address_selection(inp,
7435 (sctp_route_t *)&net->ro,
7438 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7439 sctp_free_ifa(sctp_ifa);
7441 SCTP_TCB_UNLOCK(stcb);
7443 /* For the bound all case you get back 0 */
7445 sin->sin_addr.s_addr = 0;
7449 /* Take the first IPv4 address in the list */
7450 struct sctp_laddr *laddr;
7453 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7454 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7455 struct sockaddr_in *sin_a;
7457 sin_a = &laddr->ifa->address.sin;
7458 sin->sin_addr = sin_a->sin_addr;
7464 SCTP_FREE_SONAME(sin);
7465 SCTP_INP_RUNLOCK(inp);
7466 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7470 SCTP_INP_RUNLOCK(inp);
7471 (*addr) = (struct sockaddr *)sin;
7476 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7478 struct sockaddr_in *sin;
7480 struct sockaddr_in *sin_a;
7481 struct sctp_inpcb *inp;
7482 struct sctp_tcb *stcb;
7483 struct sctp_nets *net;
7485 /* Do the malloc first in case it blocks. */
7486 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7489 sin->sin_family = AF_INET;
7490 sin->sin_len = sizeof(*sin);
7492 inp = (struct sctp_inpcb *)so->so_pcb;
7493 if ((inp == NULL) ||
7494 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7495 /* UDP type and listeners will drop out here */
7496 SCTP_FREE_SONAME(sin);
7497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7500 SCTP_INP_RLOCK(inp);
7501 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7503 SCTP_TCB_LOCK(stcb);
7505 SCTP_INP_RUNLOCK(inp);
7507 SCTP_FREE_SONAME(sin);
7508 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7509 return (ECONNRESET);
7512 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7513 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7514 if (sin_a->sin_family == AF_INET) {
7516 sin->sin_port = stcb->rport;
7517 sin->sin_addr = sin_a->sin_addr;
7521 SCTP_TCB_UNLOCK(stcb);
7523 /* No IPv4 address */
7524 SCTP_FREE_SONAME(sin);
7525 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7528 (*addr) = (struct sockaddr *)sin;
7532 struct pr_usrreqs sctp_usrreqs = {
7533 .pru_abort = sctp_abort,
7534 .pru_accept = sctp_accept,
7535 .pru_attach = sctp_attach,
7536 .pru_bind = sctp_bind,
7537 .pru_connect = sctp_connect,
7538 .pru_control = in_control,
7539 .pru_close = sctp_close,
7540 .pru_detach = sctp_close,
7541 .pru_sopoll = sopoll_generic,
7542 .pru_flush = sctp_flush,
7543 .pru_disconnect = sctp_disconnect,
7544 .pru_listen = sctp_listen,
7545 .pru_peeraddr = sctp_peeraddr,
7546 .pru_send = sctp_sendm,
7547 .pru_shutdown = sctp_shutdown,
7548 .pru_sockaddr = sctp_ingetaddr,
7549 .pru_sosend = sctp_sosend,
7550 .pru_soreceive = sctp_soreceive