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) * MCLBYTES));
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, true, false, 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;
420 inp = (struct sctp_inpcb *)so->so_pcb;
427 #ifdef SCTP_LOG_CLOSING
428 sctp_log_closing(inp, NULL, 17);
430 if (((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0)) {
431 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP;
432 #ifdef SCTP_LOG_CLOSING
433 sctp_log_closing(inp, NULL, 16);
435 SCTP_INP_WUNLOCK(inp);
436 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
437 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
439 SCTP_SB_CLEAR(so->so_snd);
441 * same for the rcv ones, they are only here for the
444 SCTP_SB_CLEAR(so->so_rcv);
446 /* Now null out the reference, we are completely detached. */
450 SCTP_INP_WUNLOCK(inp);
456 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
458 struct sctp_inpcb *inp;
459 struct inpcb *ip_inp;
461 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
463 inp = (struct sctp_inpcb *)so->so_pcb;
465 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
468 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
469 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
474 error = sctp_inpcb_alloc(so, vrf_id);
478 inp = (struct sctp_inpcb *)so->so_pcb;
480 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
481 ip_inp = &inp->ip_inp.inp;
482 ip_inp->inp_vflag |= INP_IPV4;
483 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
484 SCTP_INP_WUNLOCK(inp);
489 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
491 struct sctp_inpcb *inp;
493 inp = (struct sctp_inpcb *)so->so_pcb;
495 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
499 if ((addr->sa_family != AF_INET) ||
500 (addr->sa_len != sizeof(struct sockaddr_in))) {
501 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
505 return (sctp_inpcb_bind(so, addr, NULL, p));
510 sctp_close(struct socket *so)
512 struct epoch_tracker et;
513 struct sctp_inpcb *inp;
515 inp = (struct sctp_inpcb *)so->so_pcb;
520 * Inform all the lower layer assoc that we are done.
524 #ifdef SCTP_LOG_CLOSING
525 sctp_log_closing(inp, NULL, 17);
527 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
528 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP;
529 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
530 (so->so_rcv.sb_cc > 0)) {
531 #ifdef SCTP_LOG_CLOSING
532 sctp_log_closing(inp, NULL, 13);
534 SCTP_INP_WUNLOCK(inp);
535 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
536 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
538 #ifdef SCTP_LOG_CLOSING
539 sctp_log_closing(inp, NULL, 14);
541 SCTP_INP_WUNLOCK(inp);
542 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
543 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
546 * The socket is now detached, no matter what the state of
547 * the SCTP association.
550 SCTP_SB_CLEAR(so->so_snd);
552 * same for the rcv ones, they are only here for the
555 SCTP_SB_CLEAR(so->so_rcv);
557 /* Now null out the reference, we are completely detached. */
561 SCTP_INP_WUNLOCK(inp);
567 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
568 struct mbuf *control, struct thread *p);
571 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
572 struct mbuf *control, struct thread *p)
574 struct sctp_inpcb *inp;
577 inp = (struct sctp_inpcb *)so->so_pcb;
580 sctp_m_freem(control);
583 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
587 /* Got to have an to address if we are NOT a connected socket */
588 if ((addr == NULL) &&
589 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
590 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
596 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
597 error = EDESTADDRREQ;
598 } else if (addr->sa_family != AF_INET) {
599 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
600 error = EAFNOSUPPORT;
601 } else if (addr->sa_len != sizeof(struct sockaddr_in)) {
602 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
608 sctp_m_freem(control);
614 /* now what about control */
617 sctp_m_freem(inp->control);
620 inp->control = control;
624 SCTP_BUF_NEXT(inp->pkt_last) = m;
627 inp->pkt_last = inp->pkt = m;
630 /* FreeBSD uses a flag passed */
631 ((flags & PRUS_MORETOCOME) == 0)
634 * note with the current version this code will only be used
635 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
636 * re-defining sosend to use the sctp_sosend. One can
637 * optionally switch back to this code (by changing back the
638 * definitions) but this is not advisable. This code is used
639 * by FreeBSD when sending a file with sendfile() though.
641 struct epoch_tracker et;
645 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
656 sctp_disconnect(struct socket *so)
658 struct sctp_inpcb *inp;
660 inp = (struct sctp_inpcb *)so->so_pcb;
662 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
666 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
667 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
668 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
670 SCTP_INP_RUNLOCK(inp);
673 struct epoch_tracker et;
674 struct sctp_association *asoc;
675 struct sctp_tcb *stcb;
677 stcb = LIST_FIRST(&inp->sctp_asoc_list);
679 SCTP_INP_RUNLOCK(inp);
680 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
685 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
686 /* We are about to be freed, out of here */
687 SCTP_TCB_UNLOCK(stcb);
688 SCTP_INP_RUNLOCK(inp);
692 if (((so->so_options & SO_LINGER) &&
693 (so->so_linger == 0)) ||
694 (so->so_rcv.sb_cc > 0)) {
695 if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) {
696 /* Left with Data unread */
699 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
700 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
701 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
703 SCTP_INP_RUNLOCK(inp);
704 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
705 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
706 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
708 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
709 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
710 /* No unlock tcb assoc is gone */
714 if (TAILQ_EMPTY(&asoc->send_queue) &&
715 TAILQ_EMPTY(&asoc->sent_queue) &&
716 (asoc->stream_queue_cnt == 0)) {
717 /* there is nothing queued to send, so done */
718 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
721 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) &&
722 (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
723 /* only send SHUTDOWN 1st time thru */
724 struct sctp_nets *netp;
726 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
727 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
728 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
730 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
731 sctp_stop_timers_for_shutdown(stcb);
732 if (stcb->asoc.alternate) {
733 netp = stcb->asoc.alternate;
735 netp = stcb->asoc.primary_destination;
737 sctp_send_shutdown(stcb, netp);
738 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
739 stcb->sctp_ep, stcb, netp);
740 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
741 stcb->sctp_ep, stcb, NULL);
742 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
746 * we still got (or just got) data to send,
747 * so set SHUTDOWN_PENDING
750 * XXX sockets draft says that SCTP_EOF
751 * should be sent with no data. currently,
752 * we will allow user data to be sent first
753 * and move to SHUTDOWN-PENDING
755 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
756 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
757 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
758 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
760 if (TAILQ_EMPTY(&asoc->send_queue) &&
761 TAILQ_EMPTY(&asoc->sent_queue) &&
762 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
766 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
767 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
768 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
769 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
770 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
771 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
772 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
774 SCTP_INP_RUNLOCK(inp);
775 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
776 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
780 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
783 soisdisconnecting(so);
785 SCTP_TCB_UNLOCK(stcb);
786 SCTP_INP_RUNLOCK(inp);
791 /* UDP model does not support this */
792 SCTP_INP_RUNLOCK(inp);
793 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
799 sctp_flush(struct socket *so, int how)
802 * We will just clear out the values and let subsequent close clear
803 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
804 * they will not be able to read the data, the socket will block
805 * that from happening.
807 struct sctp_inpcb *inp;
809 inp = (struct sctp_inpcb *)so->so_pcb;
811 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
815 /* For the 1 to many model this does nothing */
816 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
817 SCTP_INP_RUNLOCK(inp);
820 SCTP_INP_RUNLOCK(inp);
821 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
823 * First make sure the sb will be happy, we don't use these
824 * except maybe the count
827 SCTP_INP_READ_LOCK(inp);
828 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
829 SCTP_INP_READ_UNLOCK(inp);
830 SCTP_INP_WUNLOCK(inp);
831 so->so_rcv.sb_cc = 0;
832 so->so_rcv.sb_mbcnt = 0;
833 so->so_rcv.sb_mb = NULL;
835 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
837 * First make sure the sb will be happy, we don't use these
838 * except maybe the count
840 so->so_snd.sb_cc = 0;
841 so->so_snd.sb_mbcnt = 0;
842 so->so_snd.sb_mb = NULL;
848 sctp_shutdown(struct socket *so)
850 struct sctp_inpcb *inp;
852 inp = (struct sctp_inpcb *)so->so_pcb;
854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
858 /* For UDP model this is a invalid call */
859 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
860 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
861 /* Restore the flags that the soshutdown took away. */
862 SOCKBUF_LOCK(&so->so_rcv);
863 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
864 SOCKBUF_UNLOCK(&so->so_rcv);
865 /* This proc will wakeup for read and do nothing (I hope) */
866 SCTP_INP_RUNLOCK(inp);
867 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
871 * Ok, if we reach here its the TCP model and it is either a
872 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
875 struct epoch_tracker et;
876 struct sctp_tcb *stcb;
877 struct sctp_association *asoc;
878 struct sctp_nets *netp;
881 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
882 SCTP_INP_RUNLOCK(inp);
887 stcb = LIST_FIRST(&inp->sctp_asoc_list);
890 * Ok, we hit the case that the shutdown call was
891 * made after an abort or something. Nothing to do
894 SCTP_INP_RUNLOCK(inp);
899 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
900 SCTP_TCB_UNLOCK(stcb);
901 SCTP_INP_RUNLOCK(inp);
904 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) &&
905 (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) &&
906 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) {
908 * If we are not in or before ESTABLISHED, there is
909 * no protocol action required.
911 SCTP_TCB_UNLOCK(stcb);
912 SCTP_INP_RUNLOCK(inp);
916 if (stcb->asoc.alternate) {
917 netp = stcb->asoc.alternate;
919 netp = stcb->asoc.primary_destination;
921 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) &&
922 TAILQ_EMPTY(&asoc->send_queue) &&
923 TAILQ_EMPTY(&asoc->sent_queue) &&
924 (asoc->stream_queue_cnt == 0)) {
925 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
928 /* there is nothing queued to send, so I'm done... */
929 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
930 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
931 sctp_stop_timers_for_shutdown(stcb);
932 sctp_send_shutdown(stcb, netp);
933 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
934 stcb->sctp_ep, stcb, netp);
937 * We still got (or just got) data to send, so set
940 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
941 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
942 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
944 if (TAILQ_EMPTY(&asoc->send_queue) &&
945 TAILQ_EMPTY(&asoc->sent_queue) &&
946 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
950 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
951 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
952 SCTP_INP_RUNLOCK(inp);
953 sctp_abort_an_association(stcb->sctp_ep, stcb,
954 op_err, false, SCTP_SO_LOCKED);
959 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
961 * XXX: Why do this in the case where we have still data
964 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
965 SCTP_TCB_UNLOCK(stcb);
966 SCTP_INP_RUNLOCK(inp);
973 * copies a "user" presentable address and removes embedded scope, etc.
974 * returns 0 on success, 1 on error
977 sctp_fill_user_address(struct sockaddr *dst, struct sockaddr *src)
980 struct sockaddr_in6 lsa6;
982 src = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)src,
985 memcpy(dst, src, src->sa_len);
990 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
991 struct sctp_tcb *stcb,
993 struct sockaddr *addr,
996 struct sctp_ifn *sctp_ifn;
997 struct sctp_ifa *sctp_ifa;
1001 int ipv4_local_scope, ipv4_addr_legal;
1004 int local_scope, site_scope, ipv6_addr_legal;
1006 struct sctp_vrf *vrf;
1008 SCTP_IPI_ADDR_LOCK_ASSERT();
1014 /* Turn on all the appropriate scope */
1015 loopback_scope = stcb->asoc.scope.loopback_scope;
1017 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1018 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1021 local_scope = stcb->asoc.scope.local_scope;
1022 site_scope = stcb->asoc.scope.site_scope;
1023 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1026 /* Use generic values for endpoints. */
1029 ipv4_local_scope = 1;
1035 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1037 ipv6_addr_legal = 1;
1040 if (SCTP_IPV6_V6ONLY(inp)) {
1041 ipv4_addr_legal = 0;
1043 ipv4_addr_legal = 1;
1048 ipv6_addr_legal = 0;
1051 ipv4_addr_legal = 1;
1055 vrf = sctp_find_vrf(vrf_id);
1059 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1060 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1061 if ((loopback_scope == 0) &&
1062 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1063 /* Skip loopback if loopback_scope not set */
1066 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1069 * For the BOUND-ALL case, the list
1070 * associated with a TCB is Always
1071 * considered a reverse list.. i.e.
1072 * it lists addresses that are NOT
1073 * part of the association. If this
1074 * is one of those we must skip it.
1076 if (sctp_is_addr_restricted(stcb,
1081 switch (sctp_ifa->address.sa.sa_family) {
1084 if (ipv4_addr_legal) {
1085 struct sockaddr_in *sin;
1087 sin = &sctp_ifa->address.sin;
1088 if (sin->sin_addr.s_addr == 0) {
1096 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1097 &sin->sin_addr) != 0) {
1100 if ((ipv4_local_scope == 0) &&
1101 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1105 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1106 if (actual + sizeof(struct sockaddr_in6) > limit) {
1109 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)addr);
1110 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1111 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1112 actual += sizeof(struct sockaddr_in6);
1115 if (actual + sizeof(struct sockaddr_in) > limit) {
1118 memcpy(addr, sin, sizeof(struct sockaddr_in));
1119 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1120 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in));
1121 actual += sizeof(struct sockaddr_in);
1132 if (ipv6_addr_legal) {
1133 struct sockaddr_in6 *sin6;
1135 sin6 = &sctp_ifa->address.sin6;
1136 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1144 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1145 &sin6->sin6_addr) != 0) {
1148 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1149 if (local_scope == 0)
1151 if (sin6->sin6_scope_id == 0) {
1152 if (sa6_recoverscope(sin6) != 0)
1165 if ((site_scope == 0) &&
1166 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1169 if (actual + sizeof(struct sockaddr_in6) > limit) {
1172 memcpy(addr, sin6, sizeof(struct sockaddr_in6));
1173 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1174 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1175 actual += sizeof(struct sockaddr_in6);
1188 struct sctp_laddr *laddr;
1191 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1193 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1197 sa_len = laddr->ifa->address.sa.sa_len;
1198 if (actual + sa_len > limit) {
1201 if (sctp_fill_user_address(addr, &laddr->ifa->address.sa))
1203 switch (laddr->ifa->address.sa.sa_family) {
1206 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1211 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1218 addr = (struct sockaddr *)((caddr_t)addr + sa_len);
1226 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1227 struct sctp_tcb *stcb,
1229 struct sockaddr *addr)
1233 SCTP_IPI_ADDR_RLOCK();
1234 /* fill up addresses for the endpoint's default vrf */
1235 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, addr,
1237 SCTP_IPI_ADDR_RUNLOCK();
1242 sctp_max_size_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1244 struct sctp_vrf *vrf;
1248 * In both sub-set bound an bound_all cases we return the size of
1249 * the maximum number of addresses that you could get. In reality
1250 * the sub-set bound may have an exclusion list for a given TCB or
1251 * in the bound-all case a TCB may NOT include the loopback or other
1252 * addresses as well.
1254 SCTP_IPI_ADDR_LOCK_ASSERT();
1255 vrf = sctp_find_vrf(vrf_id);
1260 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1261 struct sctp_ifn *sctp_ifn;
1262 struct sctp_ifa *sctp_ifa;
1264 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1265 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1266 /* Count them if they are the right type */
1267 switch (sctp_ifa->address.sa.sa_family) {
1271 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1272 size += sizeof(struct sockaddr_in6);
1274 size += sizeof(struct sockaddr_in);
1276 size += sizeof(struct sockaddr_in);
1282 size += sizeof(struct sockaddr_in6);
1291 struct sctp_laddr *laddr;
1293 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1294 switch (laddr->ifa->address.sa.sa_family) {
1298 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1299 size += sizeof(struct sockaddr_in6);
1301 size += sizeof(struct sockaddr_in);
1303 size += sizeof(struct sockaddr_in);
1309 size += sizeof(struct sockaddr_in6);
1321 sctp_max_size_addresses(struct sctp_inpcb *inp)
1325 SCTP_IPI_ADDR_RLOCK();
1326 /* Maximum size of all addresses for the endpoint's default VRF */
1327 size = sctp_max_size_addresses_vrf(inp, inp->def_vrf_id);
1328 SCTP_IPI_ADDR_RUNLOCK();
1333 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1334 size_t optsize, void *p, int delay)
1337 int creat_lock_on = 0;
1338 struct sctp_tcb *stcb = NULL;
1339 struct sockaddr *sa;
1340 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1344 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1346 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1347 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1348 /* We are already connected AND the TCP model */
1349 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1350 return (EADDRINUSE);
1353 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1354 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1355 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1359 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1360 SCTP_INP_RLOCK(inp);
1361 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1362 SCTP_INP_RUNLOCK(inp);
1365 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1368 SCTP_INP_INCR_REF(inp);
1369 SCTP_ASOC_CREATE_LOCK(inp);
1371 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1372 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1373 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1377 totaddrp = (unsigned int *)optval;
1378 totaddr = *totaddrp;
1379 sa = (struct sockaddr *)(totaddrp + 1);
1380 error = sctp_connectx_helper_find(inp, sa, totaddr, &num_v4, &num_v6, (unsigned int)(optsize - sizeof(int)));
1382 /* Already have or am bring up an association */
1383 SCTP_ASOC_CREATE_UNLOCK(inp);
1385 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1389 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1394 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1396 if (SCTP_IPV6_V6ONLY(inp)) {
1398 * if IPV6_V6ONLY flag, ignore connections destined
1399 * to a v4 addr or v4-mapped addr
1401 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1407 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1408 SCTP_PCB_FLAGS_UNBOUND) {
1409 /* Bind a ephemeral port */
1410 error = sctp_inpcb_bind(so, NULL, NULL, p);
1416 /* FIX ME: do we want to pass in a vrf on the connect call? */
1417 vrf_id = inp->def_vrf_id;
1419 /* We are GOOD to go */
1420 stcb = sctp_aloc_assoc_connected(inp, sa, &error, 0, 0, vrf_id,
1421 inp->sctp_ep.pre_open_stream_count,
1424 SCTP_INITIALIZE_AUTH_PARAMS);
1426 /* Gak! no memory */
1429 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1430 /* move to second address */
1431 switch (sa->sa_family) {
1434 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1439 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1447 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1448 /* Fill in the return id */
1452 a_id = (sctp_assoc_t *)optval;
1453 *a_id = sctp_get_associd(stcb);
1456 /* doing delayed connection */
1457 stcb->asoc.delayed_connection = 1;
1458 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1460 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1461 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1463 SCTP_TCB_UNLOCK(stcb);
1465 if (creat_lock_on) {
1466 SCTP_ASOC_CREATE_UNLOCK(inp);
1468 SCTP_INP_DECR_REF(inp);
1472 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1473 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1474 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1475 SCTP_INP_RLOCK(inp); \
1476 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1478 SCTP_TCB_LOCK(stcb); \
1480 SCTP_INP_RUNLOCK(inp); \
1481 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1482 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1483 if (stcb == NULL) { \
1484 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1493 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1494 if (size < sizeof(type)) { \
1495 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1499 destp = (type *)srcp; \
1504 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1507 struct sctp_inpcb *inp = NULL;
1509 struct sctp_tcb *stcb = NULL;
1511 if (optval == NULL) {
1512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1516 inp = (struct sctp_inpcb *)so->so_pcb;
1518 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1525 case SCTP_AUTOCLOSE:
1526 case SCTP_EXPLICIT_EOR:
1527 case SCTP_AUTO_ASCONF:
1528 case SCTP_DISABLE_FRAGMENTS:
1529 case SCTP_I_WANT_MAPPED_V4_ADDR:
1530 case SCTP_USE_EXT_RCVINFO:
1531 SCTP_INP_RLOCK(inp);
1533 case SCTP_DISABLE_FRAGMENTS:
1534 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1536 case SCTP_I_WANT_MAPPED_V4_ADDR:
1537 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1539 case SCTP_AUTO_ASCONF:
1540 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1541 /* only valid for bound all sockets */
1542 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1544 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1549 case SCTP_EXPLICIT_EOR:
1550 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1553 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1555 case SCTP_USE_EXT_RCVINFO:
1556 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1558 case SCTP_AUTOCLOSE:
1559 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1560 val = sctp_ticks_to_secs(inp->sctp_ep.auto_close_time);
1566 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1567 error = ENOPROTOOPT;
1568 } /* end switch (sopt->sopt_name) */
1569 if (*optsize < sizeof(val)) {
1570 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1574 SCTP_INP_RUNLOCK(inp);
1576 /* return the option value */
1577 *(int *)optval = val;
1578 *optsize = sizeof(val);
1581 case SCTP_GET_PACKET_LOG:
1583 #ifdef SCTP_PACKET_LOGGING
1587 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1588 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1591 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1596 case SCTP_REUSE_PORT:
1600 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1601 /* Can't do this for a 1-m socket */
1605 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1606 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1607 *optsize = sizeof(uint32_t);
1610 case SCTP_PARTIAL_DELIVERY_POINT:
1614 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1615 *value = inp->partial_delivery_point;
1616 *optsize = sizeof(uint32_t);
1619 case SCTP_FRAGMENT_INTERLEAVE:
1623 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1624 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1625 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1626 *value = SCTP_FRAG_LEVEL_2;
1628 *value = SCTP_FRAG_LEVEL_1;
1631 *value = SCTP_FRAG_LEVEL_0;
1633 *optsize = sizeof(uint32_t);
1636 case SCTP_INTERLEAVING_SUPPORTED:
1638 struct sctp_assoc_value *av;
1640 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1641 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1644 av->assoc_value = stcb->asoc.idata_supported;
1645 SCTP_TCB_UNLOCK(stcb);
1647 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1648 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1649 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1650 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1651 SCTP_INP_RLOCK(inp);
1652 if (inp->idata_supported) {
1653 av->assoc_value = 1;
1655 av->assoc_value = 0;
1657 SCTP_INP_RUNLOCK(inp);
1659 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1664 *optsize = sizeof(struct sctp_assoc_value);
1668 case SCTP_CMT_ON_OFF:
1670 struct sctp_assoc_value *av;
1672 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1673 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1675 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1676 SCTP_TCB_UNLOCK(stcb);
1678 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1679 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1680 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1681 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1682 SCTP_INP_RLOCK(inp);
1683 av->assoc_value = inp->sctp_cmt_on_off;
1684 SCTP_INP_RUNLOCK(inp);
1686 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1691 *optsize = sizeof(struct sctp_assoc_value);
1695 case SCTP_PLUGGABLE_CC:
1697 struct sctp_assoc_value *av;
1699 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1700 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1702 av->assoc_value = stcb->asoc.congestion_control_module;
1703 SCTP_TCB_UNLOCK(stcb);
1705 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1706 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1707 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1708 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1709 SCTP_INP_RLOCK(inp);
1710 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1711 SCTP_INP_RUNLOCK(inp);
1713 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1718 *optsize = sizeof(struct sctp_assoc_value);
1722 case SCTP_CC_OPTION:
1724 struct sctp_cc_option *cc_opt;
1726 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1727 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1731 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1734 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1735 *optsize = sizeof(struct sctp_cc_option);
1737 SCTP_TCB_UNLOCK(stcb);
1741 case SCTP_PLUGGABLE_SS:
1743 struct sctp_assoc_value *av;
1745 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1746 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1748 av->assoc_value = stcb->asoc.stream_scheduling_module;
1749 SCTP_TCB_UNLOCK(stcb);
1751 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1752 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1753 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1754 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1755 SCTP_INP_RLOCK(inp);
1756 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1757 SCTP_INP_RUNLOCK(inp);
1759 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1764 *optsize = sizeof(struct sctp_assoc_value);
1770 struct sctp_stream_value *av;
1772 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1773 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1775 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1776 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1777 &av->stream_value) < 0)) {
1778 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1781 *optsize = sizeof(struct sctp_stream_value);
1783 SCTP_TCB_UNLOCK(stcb);
1786 * Can't get stream value without
1789 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1794 case SCTP_GET_ADDR_LEN:
1796 struct sctp_assoc_value *av;
1798 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1801 if (av->assoc_value == AF_INET) {
1802 av->assoc_value = sizeof(struct sockaddr_in);
1807 if (av->assoc_value == AF_INET6) {
1808 av->assoc_value = sizeof(struct sockaddr_in6);
1813 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1815 *optsize = sizeof(struct sctp_assoc_value);
1819 case SCTP_GET_ASSOC_NUMBER:
1821 uint32_t *value, cnt;
1823 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1824 SCTP_INP_RLOCK(inp);
1825 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1826 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1827 /* Can't do this for a 1-1 socket */
1829 SCTP_INP_RUNLOCK(inp);
1833 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1836 SCTP_INP_RUNLOCK(inp);
1838 *optsize = sizeof(uint32_t);
1841 case SCTP_GET_ASSOC_ID_LIST:
1843 struct sctp_assoc_ids *ids;
1847 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1848 SCTP_INP_RLOCK(inp);
1849 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1850 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1851 /* Can't do this for a 1-1 socket */
1853 SCTP_INP_RUNLOCK(inp);
1857 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1858 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1860 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1863 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1868 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1872 SCTP_INP_RUNLOCK(inp);
1874 ids->gaids_number_of_ids = at;
1875 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1881 struct sctp_assoc_value *av;
1883 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1884 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1887 av->assoc_value = stcb->asoc.context;
1888 SCTP_TCB_UNLOCK(stcb);
1890 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1891 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1892 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1893 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1894 SCTP_INP_RLOCK(inp);
1895 av->assoc_value = inp->sctp_context;
1896 SCTP_INP_RUNLOCK(inp);
1898 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1903 *optsize = sizeof(struct sctp_assoc_value);
1909 uint32_t *default_vrfid;
1911 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1912 *default_vrfid = inp->def_vrf_id;
1913 *optsize = sizeof(uint32_t);
1916 case SCTP_GET_ASOC_VRF:
1918 struct sctp_assoc_value *id;
1920 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1921 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1926 id->assoc_value = stcb->asoc.vrf_id;
1927 SCTP_TCB_UNLOCK(stcb);
1928 *optsize = sizeof(struct sctp_assoc_value);
1932 case SCTP_GET_VRF_IDS:
1934 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1938 case SCTP_GET_NONCE_VALUES:
1940 struct sctp_get_nonce_values *gnv;
1942 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1943 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1946 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1947 gnv->gn_local_tag = stcb->asoc.my_vtag;
1948 SCTP_TCB_UNLOCK(stcb);
1949 *optsize = sizeof(struct sctp_get_nonce_values);
1951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1956 case SCTP_DELAYED_SACK:
1958 struct sctp_sack_info *sack;
1960 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1961 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1963 sack->sack_delay = stcb->asoc.delayed_ack;
1964 sack->sack_freq = stcb->asoc.sack_freq;
1965 SCTP_TCB_UNLOCK(stcb);
1967 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1968 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1969 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1970 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC))) {
1971 SCTP_INP_RLOCK(inp);
1972 sack->sack_delay = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1973 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
1974 SCTP_INP_RUNLOCK(inp);
1976 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1981 *optsize = sizeof(struct sctp_sack_info);
1985 case SCTP_GET_SNDBUF_USE:
1987 struct sctp_sockstat *ss;
1989 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
1990 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
1993 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
1994 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
1995 stcb->asoc.size_on_all_streams);
1996 SCTP_TCB_UNLOCK(stcb);
1997 *optsize = sizeof(struct sctp_sockstat);
1999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2004 case SCTP_MAX_BURST:
2006 struct sctp_assoc_value *av;
2008 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2009 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2012 av->assoc_value = stcb->asoc.max_burst;
2013 SCTP_TCB_UNLOCK(stcb);
2015 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2016 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2017 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2018 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2019 SCTP_INP_RLOCK(inp);
2020 av->assoc_value = inp->sctp_ep.max_burst;
2021 SCTP_INP_RUNLOCK(inp);
2023 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2028 *optsize = sizeof(struct sctp_assoc_value);
2034 struct sctp_assoc_value *av;
2036 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2037 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2040 av->assoc_value = stcb->asoc.sctp_frag_point;
2041 SCTP_TCB_UNLOCK(stcb);
2043 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2044 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2045 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2046 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2047 SCTP_INP_RLOCK(inp);
2048 av->assoc_value = inp->sctp_frag_point;
2049 SCTP_INP_RUNLOCK(inp);
2051 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2056 *optsize = sizeof(struct sctp_assoc_value);
2060 case SCTP_GET_STAT_LOG:
2061 error = sctp_fill_stat_log(optval, optsize);
2065 struct sctp_event_subscribe *events;
2067 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2068 memset(events, 0, sizeof(struct sctp_event_subscribe));
2069 SCTP_INP_RLOCK(inp);
2070 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2071 events->sctp_data_io_event = 1;
2073 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2074 events->sctp_association_event = 1;
2076 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2077 events->sctp_address_event = 1;
2079 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2080 events->sctp_send_failure_event = 1;
2082 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2083 events->sctp_peer_error_event = 1;
2085 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2086 events->sctp_shutdown_event = 1;
2088 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2089 events->sctp_partial_delivery_event = 1;
2091 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2092 events->sctp_adaptation_layer_event = 1;
2094 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2095 events->sctp_authentication_event = 1;
2097 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2098 events->sctp_sender_dry_event = 1;
2100 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2101 events->sctp_stream_reset_event = 1;
2102 SCTP_INP_RUNLOCK(inp);
2103 *optsize = sizeof(struct sctp_event_subscribe);
2106 case SCTP_ADAPTATION_LAYER:
2110 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2112 SCTP_INP_RLOCK(inp);
2113 *value = inp->sctp_ep.adaptation_layer_indicator;
2114 SCTP_INP_RUNLOCK(inp);
2115 *optsize = sizeof(uint32_t);
2118 case SCTP_SET_INITIAL_DBG_SEQ:
2122 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2123 SCTP_INP_RLOCK(inp);
2124 *value = inp->sctp_ep.initial_sequence_debug;
2125 SCTP_INP_RUNLOCK(inp);
2126 *optsize = sizeof(uint32_t);
2129 case SCTP_GET_LOCAL_ADDR_SIZE:
2133 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2134 SCTP_INP_RLOCK(inp);
2135 *value = (uint32_t)sctp_max_size_addresses(inp);
2136 SCTP_INP_RUNLOCK(inp);
2137 *optsize = sizeof(uint32_t);
2140 case SCTP_GET_REMOTE_ADDR_SIZE:
2143 struct sctp_nets *net;
2146 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2147 /* FIXME MT: change to sctp_assoc_value? */
2148 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2152 /* Count the sizes */
2153 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2154 switch (net->ro._l_addr.sa.sa_family) {
2158 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2159 size += sizeof(struct sockaddr_in6);
2161 size += sizeof(struct sockaddr_in);
2164 size += sizeof(struct sockaddr_in);
2170 size += sizeof(struct sockaddr_in6);
2177 SCTP_TCB_UNLOCK(stcb);
2178 *value = (uint32_t)size;
2179 *optsize = sizeof(uint32_t);
2181 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2182 ((sctp_assoc_t)*value <= SCTP_ALL_ASSOC)) {
2187 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2191 case SCTP_GET_PEER_ADDRESSES:
2193 * Get the address information, an array is passed in to
2194 * fill up we pack it.
2198 struct sockaddr *addr;
2199 struct sctp_nets *net;
2200 struct sctp_getaddresses *saddr;
2202 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2203 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2206 left = *optsize - offsetof(struct sctp_getaddresses, addr);
2207 *optsize = offsetof(struct sctp_getaddresses, addr);
2208 addr = &saddr->addr[0].sa;
2210 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2211 switch (net->ro._l_addr.sa.sa_family) {
2215 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2216 cpsz = sizeof(struct sockaddr_in6);
2218 cpsz = sizeof(struct sockaddr_in);
2221 cpsz = sizeof(struct sockaddr_in);
2227 cpsz = sizeof(struct sockaddr_in6);
2238 /* not enough room. */
2241 #if defined(INET) && defined(INET6)
2242 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2243 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2244 /* Must map the address */
2245 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2246 (struct sockaddr_in6 *)addr);
2248 memcpy(addr, &net->ro._l_addr, cpsz);
2251 memcpy(addr, &net->ro._l_addr, cpsz);
2253 ((struct sockaddr_in *)addr)->sin_port = stcb->rport;
2255 addr = (struct sockaddr *)((caddr_t)addr + cpsz);
2259 SCTP_TCB_UNLOCK(stcb);
2261 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2262 (saddr->sget_assoc_id <= SCTP_ALL_ASSOC)) {
2267 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2271 case SCTP_GET_LOCAL_ADDRESSES:
2273 size_t limit, actual;
2274 struct sctp_getaddresses *saddr;
2276 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2277 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2279 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2280 ((saddr->sget_assoc_id == SCTP_CURRENT_ASSOC) ||
2281 (saddr->sget_assoc_id == SCTP_ALL_ASSOC))) {
2284 limit = *optsize - offsetof(struct sctp_getaddresses, addr);
2285 actual = sctp_fill_up_addresses(inp, stcb, limit, &saddr->addr[0].sa);
2286 *optsize = offsetof(struct sctp_getaddresses, addr) + actual;
2289 SCTP_TCB_UNLOCK(stcb);
2293 case SCTP_PEER_ADDR_PARAMS:
2295 struct sctp_paddrparams *paddrp;
2296 struct sctp_nets *net;
2297 struct sockaddr *addr;
2298 #if defined(INET) && defined(INET6)
2299 struct sockaddr_in sin_store;
2302 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2303 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2305 #if defined(INET) && defined(INET6)
2306 if (paddrp->spp_address.ss_family == AF_INET6) {
2307 struct sockaddr_in6 *sin6;
2309 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2310 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2311 in6_sin6_2_sin(&sin_store, sin6);
2312 addr = (struct sockaddr *)&sin_store;
2314 addr = (struct sockaddr *)&paddrp->spp_address;
2317 addr = (struct sockaddr *)&paddrp->spp_address;
2320 addr = (struct sockaddr *)&paddrp->spp_address;
2323 net = sctp_findnet(stcb, addr);
2326 * We increment here since
2327 * sctp_findassociation_ep_addr() wil do a
2328 * decrement if it finds the stcb as long as
2329 * the locked tcb (last argument) is NOT a
2333 SCTP_INP_INCR_REF(inp);
2334 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2336 SCTP_INP_DECR_REF(inp);
2339 if ((stcb != NULL) && (net == NULL)) {
2341 if (addr->sa_family == AF_INET) {
2342 struct sockaddr_in *sin;
2344 sin = (struct sockaddr_in *)addr;
2345 if (sin->sin_addr.s_addr != INADDR_ANY) {
2347 SCTP_TCB_UNLOCK(stcb);
2348 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2354 if (addr->sa_family == AF_INET6) {
2355 struct sockaddr_in6 *sin6;
2357 sin6 = (struct sockaddr_in6 *)addr;
2358 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2360 SCTP_TCB_UNLOCK(stcb);
2361 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2367 error = EAFNOSUPPORT;
2368 SCTP_TCB_UNLOCK(stcb);
2369 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2375 /* Applies to the specific association */
2376 paddrp->spp_flags = 0;
2378 paddrp->spp_hbinterval = net->heart_beat_delay;
2379 paddrp->spp_pathmaxrxt = net->failure_threshold;
2380 paddrp->spp_pathmtu = net->mtu;
2381 switch (net->ro._l_addr.sa.sa_family) {
2384 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2389 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2395 /* get flags for HB */
2396 if (net->dest_state & SCTP_ADDR_NOHB) {
2397 paddrp->spp_flags |= SPP_HB_DISABLE;
2399 paddrp->spp_flags |= SPP_HB_ENABLE;
2401 /* get flags for PMTU */
2402 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2403 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2405 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2407 if (net->dscp & 0x01) {
2408 paddrp->spp_dscp = net->dscp & 0xfc;
2409 paddrp->spp_flags |= SPP_DSCP;
2412 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2413 (net->flowlabel & 0x80000000)) {
2414 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2415 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2420 * No destination so return default
2423 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2424 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2425 if (stcb->asoc.default_dscp & 0x01) {
2426 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2427 paddrp->spp_flags |= SPP_DSCP;
2430 if (stcb->asoc.default_flowlabel & 0x80000000) {
2431 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2432 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2435 /* default settings should be these */
2436 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2437 paddrp->spp_flags |= SPP_HB_DISABLE;
2439 paddrp->spp_flags |= SPP_HB_ENABLE;
2441 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2442 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2444 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2446 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2448 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2449 SCTP_TCB_UNLOCK(stcb);
2451 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2452 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2453 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2454 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
2455 /* Use endpoint defaults */
2456 SCTP_INP_RLOCK(inp);
2457 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2458 paddrp->spp_hbinterval = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2459 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2460 /* get inp's default */
2461 if (inp->sctp_ep.default_dscp & 0x01) {
2462 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2463 paddrp->spp_flags |= SPP_DSCP;
2466 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2467 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2468 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2469 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2472 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2474 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2475 paddrp->spp_flags |= SPP_HB_ENABLE;
2477 paddrp->spp_flags |= SPP_HB_DISABLE;
2479 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2480 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2482 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2484 SCTP_INP_RUNLOCK(inp);
2486 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2491 *optsize = sizeof(struct sctp_paddrparams);
2495 case SCTP_GET_PEER_ADDR_INFO:
2497 struct sctp_paddrinfo *paddri;
2498 struct sctp_nets *net;
2499 struct sockaddr *addr;
2500 #if defined(INET) && defined(INET6)
2501 struct sockaddr_in sin_store;
2504 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2505 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2507 #if defined(INET) && defined(INET6)
2508 if (paddri->spinfo_address.ss_family == AF_INET6) {
2509 struct sockaddr_in6 *sin6;
2511 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2512 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2513 in6_sin6_2_sin(&sin_store, sin6);
2514 addr = (struct sockaddr *)&sin_store;
2516 addr = (struct sockaddr *)&paddri->spinfo_address;
2519 addr = (struct sockaddr *)&paddri->spinfo_address;
2522 addr = (struct sockaddr *)&paddri->spinfo_address;
2525 net = sctp_findnet(stcb, addr);
2528 * We increment here since
2529 * sctp_findassociation_ep_addr() wil do a
2530 * decrement if it finds the stcb as long as
2531 * the locked tcb (last argument) is NOT a
2535 SCTP_INP_INCR_REF(inp);
2536 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2538 SCTP_INP_DECR_REF(inp);
2542 if ((stcb != NULL) && (net != NULL)) {
2543 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2544 /* It's unconfirmed */
2545 paddri->spinfo_state = SCTP_UNCONFIRMED;
2546 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2548 paddri->spinfo_state = SCTP_ACTIVE;
2551 paddri->spinfo_state = SCTP_INACTIVE;
2553 paddri->spinfo_cwnd = net->cwnd;
2554 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2555 paddri->spinfo_rto = net->RTO;
2556 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2557 paddri->spinfo_mtu = net->mtu;
2558 switch (addr->sa_family) {
2561 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2566 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2572 SCTP_TCB_UNLOCK(stcb);
2573 *optsize = sizeof(struct sctp_paddrinfo);
2576 SCTP_TCB_UNLOCK(stcb);
2578 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2583 case SCTP_PCB_STATUS:
2585 struct sctp_pcbinfo *spcb;
2587 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2588 sctp_fill_pcbinfo(spcb);
2589 *optsize = sizeof(struct sctp_pcbinfo);
2594 struct sctp_nets *net;
2595 struct sctp_status *sstat;
2597 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2598 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2601 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2605 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2606 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2607 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2608 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2610 * We can't include chunks that have been passed to
2611 * the socket layer. Only things in queue.
2613 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2614 stcb->asoc.cnt_on_all_streams);
2615 sstat->sstat_instrms = stcb->asoc.streamincnt;
2616 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2617 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb);
2618 net = stcb->asoc.primary_destination;
2620 memcpy(&sstat->sstat_primary.spinfo_address,
2622 ((struct sockaddr *)(&net->ro._l_addr))->sa_len);
2623 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2625 * Again the user can get info from
2626 * sctp_constants.h for what the state of
2629 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2630 /* It's unconfirmed */
2631 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2632 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2634 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2637 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2639 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2640 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2641 sstat->sstat_primary.spinfo_rto = net->RTO;
2642 sstat->sstat_primary.spinfo_mtu = net->mtu;
2643 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2646 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2651 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2658 memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo));
2660 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2661 SCTP_TCB_UNLOCK(stcb);
2662 *optsize = sizeof(struct sctp_status);
2667 struct sctp_rtoinfo *srto;
2669 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2670 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2673 srto->srto_initial = stcb->asoc.initial_rto;
2674 srto->srto_max = stcb->asoc.maxrto;
2675 srto->srto_min = stcb->asoc.minrto;
2676 SCTP_TCB_UNLOCK(stcb);
2678 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2679 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2680 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2681 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
2682 SCTP_INP_RLOCK(inp);
2683 srto->srto_initial = inp->sctp_ep.initial_rto;
2684 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2685 srto->srto_min = inp->sctp_ep.sctp_minrto;
2686 SCTP_INP_RUNLOCK(inp);
2688 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2693 *optsize = sizeof(struct sctp_rtoinfo);
2699 struct sctp_timeouts *stimo;
2701 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2702 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2705 stimo->stimo_init = stcb->asoc.timoinit;
2706 stimo->stimo_data = stcb->asoc.timodata;
2707 stimo->stimo_sack = stcb->asoc.timosack;
2708 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2709 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2710 stimo->stimo_cookie = stcb->asoc.timocookie;
2711 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2712 SCTP_TCB_UNLOCK(stcb);
2713 *optsize = sizeof(struct sctp_timeouts);
2715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2720 case SCTP_ASSOCINFO:
2722 struct sctp_assocparams *sasoc;
2724 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2725 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2728 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(stcb->asoc.cookie_life);
2729 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2730 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2731 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2732 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2733 SCTP_TCB_UNLOCK(stcb);
2735 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2736 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2737 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2738 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
2739 SCTP_INP_RLOCK(inp);
2740 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(inp->sctp_ep.def_cookie_life);
2741 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2742 sasoc->sasoc_number_peer_destinations = 0;
2743 sasoc->sasoc_peer_rwnd = 0;
2744 sasoc->sasoc_local_rwnd = (uint32_t)sbspace(&inp->sctp_socket->so_rcv);
2745 SCTP_INP_RUNLOCK(inp);
2747 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2752 *optsize = sizeof(struct sctp_assocparams);
2756 case SCTP_DEFAULT_SEND_PARAM:
2758 struct sctp_sndrcvinfo *s_info;
2760 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2761 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2764 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2765 SCTP_TCB_UNLOCK(stcb);
2767 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2768 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2769 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2770 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC))) {
2771 SCTP_INP_RLOCK(inp);
2772 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2773 SCTP_INP_RUNLOCK(inp);
2775 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2780 *optsize = sizeof(struct sctp_sndrcvinfo);
2786 struct sctp_initmsg *sinit;
2788 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2789 SCTP_INP_RLOCK(inp);
2790 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2791 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2792 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2793 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2794 SCTP_INP_RUNLOCK(inp);
2795 *optsize = sizeof(struct sctp_initmsg);
2798 case SCTP_PRIMARY_ADDR:
2799 /* we allow a "get" operation on this */
2801 struct sctp_setprim *ssp;
2803 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2804 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2807 union sctp_sockstore *addr;
2809 addr = &stcb->asoc.primary_destination->ro._l_addr;
2810 switch (addr->sa.sa_family) {
2814 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2815 in6_sin_2_v4mapsin6(&addr->sin,
2816 (struct sockaddr_in6 *)&ssp->ssp_addr);
2818 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2821 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2827 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2833 SCTP_TCB_UNLOCK(stcb);
2834 *optsize = sizeof(struct sctp_setprim);
2836 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2841 case SCTP_HMAC_IDENT:
2843 struct sctp_hmacalgo *shmac;
2844 sctp_hmaclist_t *hmaclist;
2848 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2850 SCTP_INP_RLOCK(inp);
2851 hmaclist = inp->sctp_ep.local_hmacs;
2852 if (hmaclist == NULL) {
2853 /* no HMACs to return */
2854 *optsize = sizeof(*shmac);
2855 SCTP_INP_RUNLOCK(inp);
2858 /* is there room for all of the hmac ids? */
2859 size = sizeof(*shmac) + (hmaclist->num_algo *
2860 sizeof(shmac->shmac_idents[0]));
2861 if (*optsize < size) {
2862 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2864 SCTP_INP_RUNLOCK(inp);
2867 /* copy in the list */
2868 shmac->shmac_number_of_idents = hmaclist->num_algo;
2869 for (i = 0; i < hmaclist->num_algo; i++) {
2870 shmac->shmac_idents[i] = hmaclist->hmac[i];
2872 SCTP_INP_RUNLOCK(inp);
2876 case SCTP_AUTH_ACTIVE_KEY:
2878 struct sctp_authkeyid *scact;
2880 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2881 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2884 /* get the active key on the assoc */
2885 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2886 SCTP_TCB_UNLOCK(stcb);
2888 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2889 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2890 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2891 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC))) {
2892 /* get the endpoint active key */
2893 SCTP_INP_RLOCK(inp);
2894 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2895 SCTP_INP_RUNLOCK(inp);
2897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2902 *optsize = sizeof(struct sctp_authkeyid);
2906 case SCTP_LOCAL_AUTH_CHUNKS:
2908 struct sctp_authchunks *sac;
2909 sctp_auth_chklist_t *chklist = NULL;
2912 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2913 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2916 /* get off the assoc */
2917 chklist = stcb->asoc.local_auth_chunks;
2918 /* is there enough space? */
2919 size = sctp_auth_get_chklist_size(chklist);
2920 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2924 /* copy in the chunks */
2925 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2926 sac->gauth_number_of_chunks = (uint32_t)size;
2927 *optsize = sizeof(struct sctp_authchunks) + size;
2929 SCTP_TCB_UNLOCK(stcb);
2931 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2932 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2933 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2934 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC))) {
2935 /* get off the endpoint */
2936 SCTP_INP_RLOCK(inp);
2937 chklist = inp->sctp_ep.local_auth_chunks;
2938 /* is there enough space? */
2939 size = sctp_auth_get_chklist_size(chklist);
2940 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2942 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2944 /* copy in the chunks */
2945 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2946 sac->gauth_number_of_chunks = (uint32_t)size;
2947 *optsize = sizeof(struct sctp_authchunks) + size;
2949 SCTP_INP_RUNLOCK(inp);
2951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2957 case SCTP_PEER_AUTH_CHUNKS:
2959 struct sctp_authchunks *sac;
2960 sctp_auth_chklist_t *chklist = NULL;
2963 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2964 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2967 /* get off the assoc */
2968 chklist = stcb->asoc.peer_auth_chunks;
2969 /* is there enough space? */
2970 size = sctp_auth_get_chklist_size(chklist);
2971 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2973 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2975 /* copy in the chunks */
2976 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2977 sac->gauth_number_of_chunks = (uint32_t)size;
2978 *optsize = sizeof(struct sctp_authchunks) + size;
2980 SCTP_TCB_UNLOCK(stcb);
2982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2989 struct sctp_event *event;
2990 uint32_t event_type;
2992 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2993 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2995 switch (event->se_type) {
2996 case SCTP_ASSOC_CHANGE:
2997 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2999 case SCTP_PEER_ADDR_CHANGE:
3000 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3002 case SCTP_REMOTE_ERROR:
3003 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3005 case SCTP_SEND_FAILED:
3006 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3008 case SCTP_SHUTDOWN_EVENT:
3009 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3011 case SCTP_ADAPTATION_INDICATION:
3012 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3014 case SCTP_PARTIAL_DELIVERY_EVENT:
3015 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3017 case SCTP_AUTHENTICATION_EVENT:
3018 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3020 case SCTP_STREAM_RESET_EVENT:
3021 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3023 case SCTP_SENDER_DRY_EVENT:
3024 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3026 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3028 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3031 case SCTP_ASSOC_RESET_EVENT:
3032 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3034 case SCTP_STREAM_CHANGE_EVENT:
3035 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3037 case SCTP_SEND_FAILED_EVENT:
3038 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3042 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3046 if (event_type > 0) {
3048 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3050 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3051 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3052 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3053 (event->se_assoc_id == SCTP_FUTURE_ASSOC))) {
3054 SCTP_INP_RLOCK(inp);
3055 event->se_on = sctp_is_feature_on(inp, event_type);
3056 SCTP_INP_RUNLOCK(inp);
3058 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3064 SCTP_TCB_UNLOCK(stcb);
3067 *optsize = sizeof(struct sctp_event);
3071 case SCTP_RECVRCVINFO:
3072 if (*optsize < sizeof(int)) {
3073 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3076 SCTP_INP_RLOCK(inp);
3077 *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3078 SCTP_INP_RUNLOCK(inp);
3079 *optsize = sizeof(int);
3082 case SCTP_RECVNXTINFO:
3083 if (*optsize < sizeof(int)) {
3084 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3087 SCTP_INP_RLOCK(inp);
3088 *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3089 SCTP_INP_RUNLOCK(inp);
3090 *optsize = sizeof(int);
3093 case SCTP_DEFAULT_SNDINFO:
3095 struct sctp_sndinfo *info;
3097 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3098 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3101 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3102 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3103 info->snd_flags &= 0xfff0;
3104 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3105 info->snd_context = stcb->asoc.def_send.sinfo_context;
3106 SCTP_TCB_UNLOCK(stcb);
3108 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3109 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3110 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3111 (info->snd_assoc_id == SCTP_FUTURE_ASSOC))) {
3112 SCTP_INP_RLOCK(inp);
3113 info->snd_sid = inp->def_send.sinfo_stream;
3114 info->snd_flags = inp->def_send.sinfo_flags;
3115 info->snd_flags &= 0xfff0;
3116 info->snd_ppid = inp->def_send.sinfo_ppid;
3117 info->snd_context = inp->def_send.sinfo_context;
3118 SCTP_INP_RUNLOCK(inp);
3120 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3125 *optsize = sizeof(struct sctp_sndinfo);
3129 case SCTP_DEFAULT_PRINFO:
3131 struct sctp_default_prinfo *info;
3133 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3134 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3137 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3138 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3139 SCTP_TCB_UNLOCK(stcb);
3141 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3142 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3143 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3144 (info->pr_assoc_id == SCTP_FUTURE_ASSOC))) {
3145 SCTP_INP_RLOCK(inp);
3146 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3147 info->pr_value = inp->def_send.sinfo_timetolive;
3148 SCTP_INP_RUNLOCK(inp);
3150 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3155 *optsize = sizeof(struct sctp_default_prinfo);
3159 case SCTP_PEER_ADDR_THLDS:
3161 struct sctp_paddrthlds *thlds;
3162 struct sctp_nets *net;
3163 struct sockaddr *addr;
3164 #if defined(INET) && defined(INET6)
3165 struct sockaddr_in sin_store;
3168 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3169 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3171 #if defined(INET) && defined(INET6)
3172 if (thlds->spt_address.ss_family == AF_INET6) {
3173 struct sockaddr_in6 *sin6;
3175 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3176 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3177 in6_sin6_2_sin(&sin_store, sin6);
3178 addr = (struct sockaddr *)&sin_store;
3180 addr = (struct sockaddr *)&thlds->spt_address;
3183 addr = (struct sockaddr *)&thlds->spt_address;
3186 addr = (struct sockaddr *)&thlds->spt_address;
3189 net = sctp_findnet(stcb, addr);
3192 * We increment here since
3193 * sctp_findassociation_ep_addr() wil do a
3194 * decrement if it finds the stcb as long as
3195 * the locked tcb (last argument) is NOT a
3199 SCTP_INP_INCR_REF(inp);
3200 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3202 SCTP_INP_DECR_REF(inp);
3205 if ((stcb != NULL) && (net == NULL)) {
3207 if (addr->sa_family == AF_INET) {
3208 struct sockaddr_in *sin;
3210 sin = (struct sockaddr_in *)addr;
3211 if (sin->sin_addr.s_addr != INADDR_ANY) {
3213 SCTP_TCB_UNLOCK(stcb);
3214 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3220 if (addr->sa_family == AF_INET6) {
3221 struct sockaddr_in6 *sin6;
3223 sin6 = (struct sockaddr_in6 *)addr;
3224 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3226 SCTP_TCB_UNLOCK(stcb);
3227 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3233 error = EAFNOSUPPORT;
3234 SCTP_TCB_UNLOCK(stcb);
3235 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3242 thlds->spt_pathmaxrxt = net->failure_threshold;
3243 thlds->spt_pathpfthld = net->pf_threshold;
3244 thlds->spt_pathcpthld = 0xffff;
3246 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3247 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3248 thlds->spt_pathcpthld = 0xffff;
3250 thlds->spt_assoc_id = sctp_get_associd(stcb);
3251 SCTP_TCB_UNLOCK(stcb);
3253 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3254 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3255 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3256 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
3257 /* Use endpoint defaults */
3258 SCTP_INP_RLOCK(inp);
3259 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3260 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3261 thlds->spt_pathcpthld = 0xffff;
3262 SCTP_INP_RUNLOCK(inp);
3264 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3269 *optsize = sizeof(struct sctp_paddrthlds);
3273 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3275 struct sctp_udpencaps *encaps;
3276 struct sctp_nets *net;
3277 struct sockaddr *addr;
3278 #if defined(INET) && defined(INET6)
3279 struct sockaddr_in sin_store;
3282 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3283 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3285 #if defined(INET) && defined(INET6)
3286 if (encaps->sue_address.ss_family == AF_INET6) {
3287 struct sockaddr_in6 *sin6;
3289 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3290 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3291 in6_sin6_2_sin(&sin_store, sin6);
3292 addr = (struct sockaddr *)&sin_store;
3294 addr = (struct sockaddr *)&encaps->sue_address;
3297 addr = (struct sockaddr *)&encaps->sue_address;
3300 addr = (struct sockaddr *)&encaps->sue_address;
3303 net = sctp_findnet(stcb, addr);
3306 * We increment here since
3307 * sctp_findassociation_ep_addr() wil do a
3308 * decrement if it finds the stcb as long as
3309 * the locked tcb (last argument) is NOT a
3313 SCTP_INP_INCR_REF(inp);
3314 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3316 SCTP_INP_DECR_REF(inp);
3319 if ((stcb != NULL) && (net == NULL)) {
3321 if (addr->sa_family == AF_INET) {
3322 struct sockaddr_in *sin;
3324 sin = (struct sockaddr_in *)addr;
3325 if (sin->sin_addr.s_addr != INADDR_ANY) {
3327 SCTP_TCB_UNLOCK(stcb);
3328 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3334 if (addr->sa_family == AF_INET6) {
3335 struct sockaddr_in6 *sin6;
3337 sin6 = (struct sockaddr_in6 *)addr;
3338 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3340 SCTP_TCB_UNLOCK(stcb);
3341 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3347 error = EAFNOSUPPORT;
3348 SCTP_TCB_UNLOCK(stcb);
3349 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3356 encaps->sue_port = net->port;
3358 encaps->sue_port = stcb->asoc.port;
3360 SCTP_TCB_UNLOCK(stcb);
3362 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3363 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3364 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3365 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
3366 SCTP_INP_RLOCK(inp);
3367 encaps->sue_port = inp->sctp_ep.port;
3368 SCTP_INP_RUNLOCK(inp);
3370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3375 *optsize = sizeof(struct sctp_udpencaps);
3379 case SCTP_ECN_SUPPORTED:
3381 struct sctp_assoc_value *av;
3383 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3384 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3387 av->assoc_value = stcb->asoc.ecn_supported;
3388 SCTP_TCB_UNLOCK(stcb);
3390 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3391 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3392 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3393 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3394 SCTP_INP_RLOCK(inp);
3395 av->assoc_value = inp->ecn_supported;
3396 SCTP_INP_RUNLOCK(inp);
3398 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3403 *optsize = sizeof(struct sctp_assoc_value);
3407 case SCTP_PR_SUPPORTED:
3409 struct sctp_assoc_value *av;
3411 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3412 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3415 av->assoc_value = stcb->asoc.prsctp_supported;
3416 SCTP_TCB_UNLOCK(stcb);
3418 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3419 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3420 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3421 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3422 SCTP_INP_RLOCK(inp);
3423 av->assoc_value = inp->prsctp_supported;
3424 SCTP_INP_RUNLOCK(inp);
3426 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3431 *optsize = sizeof(struct sctp_assoc_value);
3435 case SCTP_AUTH_SUPPORTED:
3437 struct sctp_assoc_value *av;
3439 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3440 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3443 av->assoc_value = stcb->asoc.auth_supported;
3444 SCTP_TCB_UNLOCK(stcb);
3446 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3447 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3448 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3449 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3450 SCTP_INP_RLOCK(inp);
3451 av->assoc_value = inp->auth_supported;
3452 SCTP_INP_RUNLOCK(inp);
3454 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3459 *optsize = sizeof(struct sctp_assoc_value);
3463 case SCTP_ASCONF_SUPPORTED:
3465 struct sctp_assoc_value *av;
3467 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3468 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3471 av->assoc_value = stcb->asoc.asconf_supported;
3472 SCTP_TCB_UNLOCK(stcb);
3474 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3475 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3476 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3477 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3478 SCTP_INP_RLOCK(inp);
3479 av->assoc_value = inp->asconf_supported;
3480 SCTP_INP_RUNLOCK(inp);
3482 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3487 *optsize = sizeof(struct sctp_assoc_value);
3491 case SCTP_RECONFIG_SUPPORTED:
3493 struct sctp_assoc_value *av;
3495 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3496 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3499 av->assoc_value = stcb->asoc.reconfig_supported;
3500 SCTP_TCB_UNLOCK(stcb);
3502 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3503 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3504 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3505 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3506 SCTP_INP_RLOCK(inp);
3507 av->assoc_value = inp->reconfig_supported;
3508 SCTP_INP_RUNLOCK(inp);
3510 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3515 *optsize = sizeof(struct sctp_assoc_value);
3519 case SCTP_NRSACK_SUPPORTED:
3521 struct sctp_assoc_value *av;
3523 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3524 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3527 av->assoc_value = stcb->asoc.nrsack_supported;
3528 SCTP_TCB_UNLOCK(stcb);
3530 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3531 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3532 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3533 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3534 SCTP_INP_RLOCK(inp);
3535 av->assoc_value = inp->nrsack_supported;
3536 SCTP_INP_RUNLOCK(inp);
3538 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3543 *optsize = sizeof(struct sctp_assoc_value);
3547 case SCTP_PKTDROP_SUPPORTED:
3549 struct sctp_assoc_value *av;
3551 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3552 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3555 av->assoc_value = stcb->asoc.pktdrop_supported;
3556 SCTP_TCB_UNLOCK(stcb);
3558 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3559 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3560 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3561 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3562 SCTP_INP_RLOCK(inp);
3563 av->assoc_value = inp->pktdrop_supported;
3564 SCTP_INP_RUNLOCK(inp);
3566 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3571 *optsize = sizeof(struct sctp_assoc_value);
3575 case SCTP_ENABLE_STREAM_RESET:
3577 struct sctp_assoc_value *av;
3579 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3580 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3583 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3584 SCTP_TCB_UNLOCK(stcb);
3586 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3587 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3588 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3589 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3590 SCTP_INP_RLOCK(inp);
3591 av->assoc_value = (uint32_t)inp->local_strreset_support;
3592 SCTP_INP_RUNLOCK(inp);
3594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3599 *optsize = sizeof(struct sctp_assoc_value);
3603 case SCTP_PR_STREAM_STATUS:
3605 struct sctp_prstatus *sprstat;
3609 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3610 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3612 sid = sprstat->sprstat_sid;
3613 policy = sprstat->sprstat_policy;
3614 #if defined(SCTP_DETAILED_STR_STATS)
3615 if ((stcb != NULL) &&
3616 (sid < stcb->asoc.streamoutcnt) &&
3617 (policy != SCTP_PR_SCTP_NONE) &&
3618 ((policy <= SCTP_PR_SCTP_MAX) ||
3619 (policy == SCTP_PR_SCTP_ALL))) {
3620 if (policy == SCTP_PR_SCTP_ALL) {
3621 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3622 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3624 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3625 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3628 if ((stcb != NULL) &&
3629 (sid < stcb->asoc.streamoutcnt) &&
3630 (policy == SCTP_PR_SCTP_ALL)) {
3631 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3632 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3635 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3639 SCTP_TCB_UNLOCK(stcb);
3642 *optsize = sizeof(struct sctp_prstatus);
3646 case SCTP_PR_ASSOC_STATUS:
3648 struct sctp_prstatus *sprstat;
3651 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3652 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3654 policy = sprstat->sprstat_policy;
3655 if ((stcb != NULL) &&
3656 (policy != SCTP_PR_SCTP_NONE) &&
3657 ((policy <= SCTP_PR_SCTP_MAX) ||
3658 (policy == SCTP_PR_SCTP_ALL))) {
3659 if (policy == SCTP_PR_SCTP_ALL) {
3660 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3661 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3663 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3664 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3671 SCTP_TCB_UNLOCK(stcb);
3674 *optsize = sizeof(struct sctp_prstatus);
3680 struct sctp_assoc_value *av;
3682 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3683 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3686 av->assoc_value = stcb->asoc.max_cwnd;
3687 SCTP_TCB_UNLOCK(stcb);
3689 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3690 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3691 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3692 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3693 SCTP_INP_RLOCK(inp);
3694 av->assoc_value = inp->max_cwnd;
3695 SCTP_INP_RUNLOCK(inp);
3697 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3702 *optsize = sizeof(struct sctp_assoc_value);
3707 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3708 error = ENOPROTOOPT;
3710 } /* end switch (sopt->sopt_name) */
3718 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3723 struct sctp_tcb *stcb = NULL;
3724 struct sctp_inpcb *inp = NULL;
3727 if (optval == NULL) {
3728 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3731 inp = (struct sctp_inpcb *)so->so_pcb;
3733 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3736 vrf_id = inp->def_vrf_id;
3741 case SCTP_AUTOCLOSE:
3742 case SCTP_AUTO_ASCONF:
3743 case SCTP_EXPLICIT_EOR:
3744 case SCTP_DISABLE_FRAGMENTS:
3745 case SCTP_USE_EXT_RCVINFO:
3746 case SCTP_I_WANT_MAPPED_V4_ADDR:
3747 /* copy in the option value */
3748 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3753 case SCTP_DISABLE_FRAGMENTS:
3754 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3756 case SCTP_AUTO_ASCONF:
3758 * NOTE: we don't really support this flag
3760 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3761 /* only valid for bound all sockets */
3762 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3764 /* forbidden by admin */
3765 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3768 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3770 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3774 case SCTP_EXPLICIT_EOR:
3775 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3777 case SCTP_USE_EXT_RCVINFO:
3778 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3780 case SCTP_I_WANT_MAPPED_V4_ADDR:
3781 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3782 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3784 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3789 set_opt = SCTP_PCB_FLAGS_NODELAY;
3791 case SCTP_AUTOCLOSE:
3792 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3793 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3797 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3799 * The value is in ticks. Note this does not effect
3800 * old associations, only new ones.
3802 inp->sctp_ep.auto_close_time = sctp_secs_to_ticks(*mopt);
3805 SCTP_INP_WLOCK(inp);
3807 sctp_feature_on(inp, set_opt);
3809 sctp_feature_off(inp, set_opt);
3811 SCTP_INP_WUNLOCK(inp);
3813 case SCTP_REUSE_PORT:
3815 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3816 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3817 /* Can't set it after we are bound */
3821 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3822 /* Can't do this for a 1-m socket */
3827 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3829 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3832 case SCTP_PARTIAL_DELIVERY_POINT:
3836 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3837 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3838 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3842 inp->partial_delivery_point = *value;
3845 case SCTP_FRAGMENT_INTERLEAVE:
3846 /* not yet until we re-write sctp_recvmsg() */
3850 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3851 if (*level == SCTP_FRAG_LEVEL_2) {
3852 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3853 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3854 } else if (*level == SCTP_FRAG_LEVEL_1) {
3855 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3856 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3857 } else if (*level == SCTP_FRAG_LEVEL_0) {
3858 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3859 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3862 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3867 case SCTP_INTERLEAVING_SUPPORTED:
3869 struct sctp_assoc_value *av;
3871 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3872 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3875 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3877 SCTP_TCB_UNLOCK(stcb);
3879 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3880 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3881 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3882 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3883 SCTP_INP_WLOCK(inp);
3884 if (av->assoc_value == 0) {
3885 inp->idata_supported = 0;
3887 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3888 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3889 inp->idata_supported = 1;
3897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3901 SCTP_INP_WUNLOCK(inp);
3903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3909 case SCTP_CMT_ON_OFF:
3910 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3911 struct sctp_assoc_value *av;
3913 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3914 if (av->assoc_value > SCTP_CMT_MAX) {
3915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3919 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3921 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3922 SCTP_TCB_UNLOCK(stcb);
3924 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3925 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3926 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3927 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3928 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3929 SCTP_INP_WLOCK(inp);
3930 inp->sctp_cmt_on_off = av->assoc_value;
3931 SCTP_INP_WUNLOCK(inp);
3933 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3934 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3935 (av->assoc_id == SCTP_ALL_ASSOC))) {
3936 SCTP_INP_RLOCK(inp);
3937 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3938 SCTP_TCB_LOCK(stcb);
3939 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3940 SCTP_TCB_UNLOCK(stcb);
3942 SCTP_INP_RUNLOCK(inp);
3946 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3947 error = ENOPROTOOPT;
3950 case SCTP_PLUGGABLE_CC:
3952 struct sctp_assoc_value *av;
3953 struct sctp_nets *net;
3955 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3956 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3957 (av->assoc_value != SCTP_CC_HSTCP) &&
3958 (av->assoc_value != SCTP_CC_HTCP) &&
3959 (av->assoc_value != SCTP_CC_RTCC)) {
3960 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3964 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3966 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3967 stcb->asoc.congestion_control_module = av->assoc_value;
3968 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3969 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3970 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3973 SCTP_TCB_UNLOCK(stcb);
3975 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3976 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3977 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3978 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3979 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3980 SCTP_INP_WLOCK(inp);
3981 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3982 SCTP_INP_WUNLOCK(inp);
3984 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3985 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3986 (av->assoc_id == SCTP_ALL_ASSOC))) {
3987 SCTP_INP_RLOCK(inp);
3988 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3989 SCTP_TCB_LOCK(stcb);
3990 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3991 stcb->asoc.congestion_control_module = av->assoc_value;
3992 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3993 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3994 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3997 SCTP_TCB_UNLOCK(stcb);
3999 SCTP_INP_RUNLOCK(inp);
4004 case SCTP_CC_OPTION:
4006 struct sctp_cc_option *cc_opt;
4008 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4009 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4011 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4012 (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC)) {
4013 SCTP_INP_RLOCK(inp);
4014 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4015 SCTP_TCB_LOCK(stcb);
4016 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4017 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4019 SCTP_TCB_UNLOCK(stcb);
4021 SCTP_INP_RUNLOCK(inp);
4026 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4029 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4032 SCTP_TCB_UNLOCK(stcb);
4036 case SCTP_PLUGGABLE_SS:
4038 struct sctp_assoc_value *av;
4040 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4041 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4042 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4043 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4044 (av->assoc_value != SCTP_SS_PRIORITY) &&
4045 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4046 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4047 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4051 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4053 SCTP_TCB_SEND_LOCK(stcb);
4054 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, true);
4055 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4056 stcb->asoc.stream_scheduling_module = av->assoc_value;
4057 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc);
4058 SCTP_TCB_SEND_UNLOCK(stcb);
4059 SCTP_TCB_UNLOCK(stcb);
4061 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4062 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4063 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4064 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4065 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4066 SCTP_INP_WLOCK(inp);
4067 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4068 SCTP_INP_WUNLOCK(inp);
4070 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4071 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4072 (av->assoc_id == SCTP_ALL_ASSOC))) {
4073 SCTP_INP_RLOCK(inp);
4074 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4075 SCTP_TCB_LOCK(stcb);
4076 SCTP_TCB_SEND_LOCK(stcb);
4077 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, true);
4078 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4079 stcb->asoc.stream_scheduling_module = av->assoc_value;
4080 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc);
4081 SCTP_TCB_SEND_UNLOCK(stcb);
4082 SCTP_TCB_UNLOCK(stcb);
4084 SCTP_INP_RUNLOCK(inp);
4091 struct sctp_stream_value *av;
4093 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4094 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4096 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4097 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4098 av->stream_value) < 0)) {
4099 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4102 SCTP_TCB_UNLOCK(stcb);
4104 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4105 (av->assoc_id == SCTP_CURRENT_ASSOC)) {
4106 SCTP_INP_RLOCK(inp);
4107 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4108 SCTP_TCB_LOCK(stcb);
4109 if (av->stream_id < stcb->asoc.streamoutcnt) {
4110 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4112 &stcb->asoc.strmout[av->stream_id],
4115 SCTP_TCB_UNLOCK(stcb);
4117 SCTP_INP_RUNLOCK(inp);
4120 * Can't set stream value without
4123 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4129 case SCTP_CLR_STAT_LOG:
4130 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4135 struct sctp_assoc_value *av;
4137 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4138 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4141 stcb->asoc.context = av->assoc_value;
4142 SCTP_TCB_UNLOCK(stcb);
4144 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4145 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4146 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4147 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4148 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4149 SCTP_INP_WLOCK(inp);
4150 inp->sctp_context = av->assoc_value;
4151 SCTP_INP_WUNLOCK(inp);
4153 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4154 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4155 (av->assoc_id == SCTP_ALL_ASSOC))) {
4156 SCTP_INP_RLOCK(inp);
4157 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4158 SCTP_TCB_LOCK(stcb);
4159 stcb->asoc.context = av->assoc_value;
4160 SCTP_TCB_UNLOCK(stcb);
4162 SCTP_INP_RUNLOCK(inp);
4169 uint32_t *default_vrfid;
4171 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4172 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4173 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4177 inp->def_vrf_id = *default_vrfid;
4180 case SCTP_DEL_VRF_ID:
4182 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4186 case SCTP_ADD_VRF_ID:
4188 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4192 case SCTP_DELAYED_SACK:
4194 struct sctp_sack_info *sack;
4196 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4197 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4198 if (sack->sack_delay) {
4199 if (sack->sack_delay > SCTP_MAX_SACK_DELAY) {
4202 SCTP_TCB_UNLOCK(stcb);
4208 if (sack->sack_delay) {
4209 stcb->asoc.delayed_ack = sack->sack_delay;
4211 if (sack->sack_freq) {
4212 stcb->asoc.sack_freq = sack->sack_freq;
4214 SCTP_TCB_UNLOCK(stcb);
4216 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4217 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4218 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4219 ((sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4220 (sack->sack_assoc_id == SCTP_ALL_ASSOC)))) {
4221 SCTP_INP_WLOCK(inp);
4222 if (sack->sack_delay) {
4223 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = sctp_msecs_to_ticks(sack->sack_delay);
4225 if (sack->sack_freq) {
4226 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4228 SCTP_INP_WUNLOCK(inp);
4230 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4231 ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4232 (sack->sack_assoc_id == SCTP_ALL_ASSOC))) {
4233 SCTP_INP_RLOCK(inp);
4234 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4235 SCTP_TCB_LOCK(stcb);
4236 if (sack->sack_delay) {
4237 stcb->asoc.delayed_ack = sack->sack_delay;
4239 if (sack->sack_freq) {
4240 stcb->asoc.sack_freq = sack->sack_freq;
4242 SCTP_TCB_UNLOCK(stcb);
4244 SCTP_INP_RUNLOCK(inp);
4249 case SCTP_AUTH_CHUNK:
4251 struct sctp_authchunk *sauth;
4253 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4255 SCTP_INP_WLOCK(inp);
4256 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4257 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4260 inp->auth_supported = 1;
4262 SCTP_INP_WUNLOCK(inp);
4267 struct sctp_authkey *sca;
4268 struct sctp_keyhead *shared_keys;
4269 sctp_sharedkey_t *shared_key;
4270 sctp_key_t *key = NULL;
4273 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4274 if (sca->sca_keylength == 0) {
4275 size = optsize - sizeof(struct sctp_authkey);
4277 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4278 size = sca->sca_keylength;
4280 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4285 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4288 shared_keys = &stcb->asoc.shared_keys;
4289 /* clear the cached keys for this key id */
4290 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4292 * create the new shared key and
4296 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4298 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4300 SCTP_TCB_UNLOCK(stcb);
4304 shared_key = sctp_alloc_sharedkey();
4305 if (shared_key == NULL) {
4307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4309 SCTP_TCB_UNLOCK(stcb);
4312 shared_key->key = key;
4313 shared_key->keyid = sca->sca_keynumber;
4314 error = sctp_insert_sharedkey(shared_keys, shared_key);
4315 SCTP_TCB_UNLOCK(stcb);
4317 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4318 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4319 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4320 ((sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4321 (sca->sca_assoc_id == SCTP_ALL_ASSOC)))) {
4322 SCTP_INP_WLOCK(inp);
4323 shared_keys = &inp->sctp_ep.shared_keys;
4325 * clear the cached keys on all
4326 * assocs for this key id
4328 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4330 * create the new shared key and
4334 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4336 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4338 SCTP_INP_WUNLOCK(inp);
4342 shared_key = sctp_alloc_sharedkey();
4343 if (shared_key == NULL) {
4345 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4347 SCTP_INP_WUNLOCK(inp);
4350 shared_key->key = key;
4351 shared_key->keyid = sca->sca_keynumber;
4352 error = sctp_insert_sharedkey(shared_keys, shared_key);
4353 SCTP_INP_WUNLOCK(inp);
4355 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4356 ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4357 (sca->sca_assoc_id == SCTP_ALL_ASSOC))) {
4358 SCTP_INP_RLOCK(inp);
4359 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4360 SCTP_TCB_LOCK(stcb);
4361 shared_keys = &stcb->asoc.shared_keys;
4363 * clear the cached keys for
4366 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4368 * create the new shared key
4369 * and insert/replace it
4372 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4374 SCTP_TCB_UNLOCK(stcb);
4378 shared_key = sctp_alloc_sharedkey();
4379 if (shared_key == NULL) {
4381 SCTP_TCB_UNLOCK(stcb);
4384 shared_key->key = key;
4385 shared_key->keyid = sca->sca_keynumber;
4386 error = sctp_insert_sharedkey(shared_keys, shared_key);
4387 SCTP_TCB_UNLOCK(stcb);
4389 SCTP_INP_RUNLOCK(inp);
4394 case SCTP_HMAC_IDENT:
4396 struct sctp_hmacalgo *shmac;
4397 sctp_hmaclist_t *hmaclist;
4401 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4402 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4403 (shmac->shmac_number_of_idents > 0xffff)) {
4404 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4409 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4410 if (hmaclist == NULL) {
4411 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4415 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4416 hmacid = shmac->shmac_idents[i];
4417 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4418 /* invalid HMACs were found */ ;
4419 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4421 sctp_free_hmaclist(hmaclist);
4422 goto sctp_set_hmac_done;
4425 for (i = 0; i < hmaclist->num_algo; i++) {
4426 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4427 /* already in list */
4431 if (i == hmaclist->num_algo) {
4432 /* not found in list */
4433 sctp_free_hmaclist(hmaclist);
4434 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4438 /* set it on the endpoint */
4439 SCTP_INP_WLOCK(inp);
4440 if (inp->sctp_ep.local_hmacs)
4441 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4442 inp->sctp_ep.local_hmacs = hmaclist;
4443 SCTP_INP_WUNLOCK(inp);
4447 case SCTP_AUTH_ACTIVE_KEY:
4449 struct sctp_authkeyid *scact;
4451 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4452 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4454 /* set the active key on the right place */
4456 /* set the active key on the assoc */
4457 if (sctp_auth_setactivekey(stcb,
4458 scact->scact_keynumber)) {
4459 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4460 SCTP_FROM_SCTP_USRREQ,
4464 SCTP_TCB_UNLOCK(stcb);
4466 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4467 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4468 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4469 ((scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4470 (scact->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4471 SCTP_INP_WLOCK(inp);
4472 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4473 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4476 SCTP_INP_WUNLOCK(inp);
4478 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4479 ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4480 (scact->scact_assoc_id == SCTP_ALL_ASSOC))) {
4481 SCTP_INP_RLOCK(inp);
4482 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4483 SCTP_TCB_LOCK(stcb);
4484 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4485 SCTP_TCB_UNLOCK(stcb);
4487 SCTP_INP_RUNLOCK(inp);
4492 case SCTP_AUTH_DELETE_KEY:
4494 struct sctp_authkeyid *scdel;
4496 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4497 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4499 /* delete the key from the right place */
4501 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4502 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4505 SCTP_TCB_UNLOCK(stcb);
4507 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4508 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4509 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4510 ((scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4511 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4512 SCTP_INP_WLOCK(inp);
4513 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4514 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4517 SCTP_INP_WUNLOCK(inp);
4519 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4520 ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4521 (scdel->scact_assoc_id == SCTP_ALL_ASSOC))) {
4522 SCTP_INP_RLOCK(inp);
4523 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4524 SCTP_TCB_LOCK(stcb);
4525 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4526 SCTP_TCB_UNLOCK(stcb);
4528 SCTP_INP_RUNLOCK(inp);
4533 case SCTP_AUTH_DEACTIVATE_KEY:
4535 struct sctp_authkeyid *keyid;
4537 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4538 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4540 /* deactivate the key from the right place */
4542 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4543 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4546 SCTP_TCB_UNLOCK(stcb);
4548 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4549 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4550 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4551 ((keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4552 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4553 SCTP_INP_WLOCK(inp);
4554 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4555 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4558 SCTP_INP_WUNLOCK(inp);
4560 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4561 ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4562 (keyid->scact_assoc_id == SCTP_ALL_ASSOC))) {
4563 SCTP_INP_RLOCK(inp);
4564 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4565 SCTP_TCB_LOCK(stcb);
4566 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4567 SCTP_TCB_UNLOCK(stcb);
4569 SCTP_INP_RUNLOCK(inp);
4574 case SCTP_ENABLE_STREAM_RESET:
4576 struct sctp_assoc_value *av;
4578 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4579 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4580 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4584 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4586 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4587 SCTP_TCB_UNLOCK(stcb);
4589 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4590 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4591 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4592 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4593 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4594 SCTP_INP_WLOCK(inp);
4595 inp->local_strreset_support = (uint8_t)av->assoc_value;
4596 SCTP_INP_WUNLOCK(inp);
4598 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4599 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4600 (av->assoc_id == SCTP_ALL_ASSOC))) {
4601 SCTP_INP_RLOCK(inp);
4602 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4603 SCTP_TCB_LOCK(stcb);
4604 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4605 SCTP_TCB_UNLOCK(stcb);
4607 SCTP_INP_RUNLOCK(inp);
4612 case SCTP_RESET_STREAMS:
4614 struct sctp_reset_streams *strrst;
4615 int i, send_out = 0;
4618 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4619 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4625 if (stcb->asoc.reconfig_supported == 0) {
4627 * Peer does not support the chunk type.
4629 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4631 SCTP_TCB_UNLOCK(stcb);
4634 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4635 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4637 SCTP_TCB_UNLOCK(stcb);
4640 if (sizeof(struct sctp_reset_streams) +
4641 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4643 SCTP_TCB_UNLOCK(stcb);
4646 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4648 if (stcb->asoc.stream_reset_outstanding) {
4649 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4651 SCTP_TCB_UNLOCK(stcb);
4655 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4658 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4659 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4661 SCTP_TCB_UNLOCK(stcb);
4664 if ((send_in == 0) && (send_out == 0)) {
4665 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4667 SCTP_TCB_UNLOCK(stcb);
4670 for (i = 0; i < strrst->srs_number_streams; i++) {
4672 (strrst->srs_stream_list[i] >= stcb->asoc.streamincnt)) {
4673 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4678 (strrst->srs_stream_list[i] >= stcb->asoc.streamoutcnt)) {
4679 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4685 SCTP_TCB_UNLOCK(stcb);
4692 if (strrst->srs_number_streams) {
4693 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4694 strm = strrst->srs_stream_list[i];
4695 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4696 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4702 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4703 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4704 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4711 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4712 strrst->srs_stream_list,
4713 send_in, 0, 0, 0, 0, 0);
4715 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4718 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4721 * For outgoing streams don't report any
4722 * problems in sending the request to the
4723 * application. XXX: Double check resetting
4728 SCTP_TCB_UNLOCK(stcb);
4731 case SCTP_ADD_STREAMS:
4733 struct sctp_add_streams *stradd;
4734 uint8_t addstream = 0;
4735 uint16_t add_o_strmcnt = 0;
4736 uint16_t add_i_strmcnt = 0;
4738 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4739 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4741 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4745 if (stcb->asoc.reconfig_supported == 0) {
4747 * Peer does not support the chunk type.
4749 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4751 SCTP_TCB_UNLOCK(stcb);
4754 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4755 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4757 SCTP_TCB_UNLOCK(stcb);
4760 if (stcb->asoc.stream_reset_outstanding) {
4761 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4763 SCTP_TCB_UNLOCK(stcb);
4766 if ((stradd->sas_outstrms == 0) &&
4767 (stradd->sas_instrms == 0)) {
4771 if (stradd->sas_outstrms) {
4773 /* We allocate here */
4774 add_o_strmcnt = stradd->sas_outstrms;
4775 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4776 /* You can't have more than 64k */
4781 if (stradd->sas_instrms) {
4786 * We allocate inside
4787 * sctp_send_str_reset_req()
4789 add_i_strmcnt = stradd->sas_instrms;
4790 cnt = add_i_strmcnt;
4791 cnt += stcb->asoc.streamincnt;
4792 if (cnt > 0x0000ffff) {
4793 /* You can't have more than 64k */
4797 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4798 /* More than you are allowed */
4803 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4804 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4806 SCTP_TCB_UNLOCK(stcb);
4809 case SCTP_RESET_ASSOC:
4814 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4815 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4817 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4821 if (stcb->asoc.reconfig_supported == 0) {
4823 * Peer does not support the chunk type.
4825 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4827 SCTP_TCB_UNLOCK(stcb);
4830 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4831 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4833 SCTP_TCB_UNLOCK(stcb);
4836 if (stcb->asoc.stream_reset_outstanding) {
4837 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4839 SCTP_TCB_UNLOCK(stcb);
4843 * Is there any data pending in the send or sent
4846 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4847 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4850 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4851 SCTP_TCB_UNLOCK(stcb);
4854 /* Do any streams have data queued? */
4855 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4856 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4860 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4861 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4862 SCTP_TCB_UNLOCK(stcb);
4865 case SCTP_CONNECT_X:
4866 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4867 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4871 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4873 case SCTP_CONNECT_X_DELAYED:
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, 1);
4881 case SCTP_CONNECT_X_COMPLETE:
4883 struct sockaddr *sa;
4885 /* FIXME MT: check correct? */
4886 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4889 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4890 SCTP_INP_RLOCK(inp);
4891 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4893 SCTP_TCB_LOCK(stcb);
4895 SCTP_INP_RUNLOCK(inp);
4898 * We increment here since
4899 * sctp_findassociation_ep_addr() wil do a
4900 * decrement if it finds the stcb as long as
4901 * the locked tcb (last argument) is NOT a
4904 SCTP_INP_INCR_REF(inp);
4905 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4907 SCTP_INP_DECR_REF(inp);
4912 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4916 if (stcb->asoc.delayed_connection == 1) {
4917 stcb->asoc.delayed_connection = 0;
4918 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4919 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4920 stcb->asoc.primary_destination,
4921 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4922 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4925 * already expired or did not use delayed
4928 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4931 SCTP_TCB_UNLOCK(stcb);
4934 case SCTP_MAX_BURST:
4936 struct sctp_assoc_value *av;
4938 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4939 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4942 stcb->asoc.max_burst = av->assoc_value;
4943 SCTP_TCB_UNLOCK(stcb);
4945 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4946 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4947 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4948 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4949 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4950 SCTP_INP_WLOCK(inp);
4951 inp->sctp_ep.max_burst = av->assoc_value;
4952 SCTP_INP_WUNLOCK(inp);
4954 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4955 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4956 (av->assoc_id == SCTP_ALL_ASSOC))) {
4957 SCTP_INP_RLOCK(inp);
4958 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4959 SCTP_TCB_LOCK(stcb);
4960 stcb->asoc.max_burst = av->assoc_value;
4961 SCTP_TCB_UNLOCK(stcb);
4963 SCTP_INP_RUNLOCK(inp);
4970 struct sctp_assoc_value *av;
4972 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4973 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4976 stcb->asoc.sctp_frag_point = av->assoc_value;
4977 SCTP_TCB_UNLOCK(stcb);
4979 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4980 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4981 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4982 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
4983 SCTP_INP_WLOCK(inp);
4984 inp->sctp_frag_point = av->assoc_value;
4985 SCTP_INP_WUNLOCK(inp);
4987 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4995 struct sctp_event_subscribe *events;
4997 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4999 SCTP_INP_WLOCK(inp);
5000 if (events->sctp_data_io_event) {
5001 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5003 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5006 if (events->sctp_association_event) {
5007 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5009 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5012 if (events->sctp_address_event) {
5013 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5015 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5018 if (events->sctp_send_failure_event) {
5019 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5021 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5024 if (events->sctp_peer_error_event) {
5025 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5027 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5030 if (events->sctp_shutdown_event) {
5031 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5033 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5036 if (events->sctp_partial_delivery_event) {
5037 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5039 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5042 if (events->sctp_adaptation_layer_event) {
5043 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5045 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5048 if (events->sctp_authentication_event) {
5049 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5051 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5054 if (events->sctp_sender_dry_event) {
5055 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5057 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5060 if (events->sctp_stream_reset_event) {
5061 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5063 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5065 SCTP_INP_WUNLOCK(inp);
5067 SCTP_INP_RLOCK(inp);
5068 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5069 SCTP_TCB_LOCK(stcb);
5070 if (events->sctp_association_event) {
5071 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5073 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5075 if (events->sctp_address_event) {
5076 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5078 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5080 if (events->sctp_send_failure_event) {
5081 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5083 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5085 if (events->sctp_peer_error_event) {
5086 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5088 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5090 if (events->sctp_shutdown_event) {
5091 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5093 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5095 if (events->sctp_partial_delivery_event) {
5096 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5098 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5100 if (events->sctp_adaptation_layer_event) {
5101 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5103 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5105 if (events->sctp_authentication_event) {
5106 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5108 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5110 if (events->sctp_sender_dry_event) {
5111 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5113 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5115 if (events->sctp_stream_reset_event) {
5116 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5118 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5120 SCTP_TCB_UNLOCK(stcb);
5123 * Send up the sender dry event only for 1-to-1
5126 if (events->sctp_sender_dry_event) {
5127 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5128 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5129 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5131 SCTP_TCB_LOCK(stcb);
5132 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5133 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5134 (stcb->asoc.stream_queue_cnt == 0)) {
5135 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5137 SCTP_TCB_UNLOCK(stcb);
5141 SCTP_INP_RUNLOCK(inp);
5144 case SCTP_ADAPTATION_LAYER:
5146 struct sctp_setadaptation *adap_bits;
5148 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5149 SCTP_INP_WLOCK(inp);
5150 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5151 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5152 SCTP_INP_WUNLOCK(inp);
5156 case SCTP_SET_INITIAL_DBG_SEQ:
5160 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5161 SCTP_INP_WLOCK(inp);
5162 inp->sctp_ep.initial_sequence_debug = *vvv;
5163 SCTP_INP_WUNLOCK(inp);
5167 case SCTP_DEFAULT_SEND_PARAM:
5169 struct sctp_sndrcvinfo *s_info;
5171 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5172 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5175 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5176 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5178 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5181 SCTP_TCB_UNLOCK(stcb);
5183 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5184 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5185 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5186 ((s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5187 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)))) {
5188 SCTP_INP_WLOCK(inp);
5189 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5190 SCTP_INP_WUNLOCK(inp);
5192 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5193 ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5194 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC))) {
5195 SCTP_INP_RLOCK(inp);
5196 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5197 SCTP_TCB_LOCK(stcb);
5198 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5199 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5201 SCTP_TCB_UNLOCK(stcb);
5203 SCTP_INP_RUNLOCK(inp);
5208 case SCTP_PEER_ADDR_PARAMS:
5210 struct sctp_paddrparams *paddrp;
5211 struct sctp_nets *net;
5212 struct sockaddr *addr;
5213 #if defined(INET) && defined(INET6)
5214 struct sockaddr_in sin_store;
5217 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5218 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5220 #if defined(INET) && defined(INET6)
5221 if (paddrp->spp_address.ss_family == AF_INET6) {
5222 struct sockaddr_in6 *sin6;
5224 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5225 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5226 in6_sin6_2_sin(&sin_store, sin6);
5227 addr = (struct sockaddr *)&sin_store;
5229 addr = (struct sockaddr *)&paddrp->spp_address;
5232 addr = (struct sockaddr *)&paddrp->spp_address;
5235 addr = (struct sockaddr *)&paddrp->spp_address;
5238 net = sctp_findnet(stcb, addr);
5241 * We increment here since
5242 * sctp_findassociation_ep_addr() wil do a
5243 * decrement if it finds the stcb as long as
5244 * the locked tcb (last argument) is NOT a
5248 SCTP_INP_INCR_REF(inp);
5249 stcb = sctp_findassociation_ep_addr(&inp, addr,
5252 SCTP_INP_DECR_REF(inp);
5255 if ((stcb != NULL) && (net == NULL)) {
5257 if (addr->sa_family == AF_INET) {
5258 struct sockaddr_in *sin;
5260 sin = (struct sockaddr_in *)addr;
5261 if (sin->sin_addr.s_addr != INADDR_ANY) {
5262 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5263 SCTP_TCB_UNLOCK(stcb);
5270 if (addr->sa_family == AF_INET6) {
5271 struct sockaddr_in6 *sin6;
5273 sin6 = (struct sockaddr_in6 *)addr;
5274 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5275 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5276 SCTP_TCB_UNLOCK(stcb);
5283 error = EAFNOSUPPORT;
5284 SCTP_TCB_UNLOCK(stcb);
5285 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5290 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5292 SCTP_TCB_UNLOCK(stcb);
5293 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5297 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5299 SCTP_TCB_UNLOCK(stcb);
5300 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5303 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) &&
5304 (paddrp->spp_pathmtu > 0) &&
5305 ((paddrp->spp_pathmtu < SCTP_SMALLEST_PMTU) ||
5306 (paddrp->spp_pathmtu > SCTP_LARGEST_PMTU))) {
5308 SCTP_TCB_UNLOCK(stcb);
5309 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5314 /************************TCB SPECIFIC SET ******************/
5316 /************************NET SPECIFIC SET ******************/
5317 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5318 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5319 !(net->dest_state & SCTP_ADDR_NOHB)) {
5320 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5321 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5323 net->dest_state |= SCTP_ADDR_NOHB;
5325 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5326 if (paddrp->spp_hbinterval) {
5327 net->heart_beat_delay = paddrp->spp_hbinterval;
5328 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5329 net->heart_beat_delay = 0;
5331 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5332 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5333 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5334 net->dest_state &= ~SCTP_ADDR_NOHB;
5336 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5337 if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
5338 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5339 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5340 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5343 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5344 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5345 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5346 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5348 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5349 if (paddrp->spp_pathmtu > 0) {
5350 net->mtu = paddrp->spp_pathmtu;
5351 switch (net->ro._l_addr.sa.sa_family) {
5354 net->mtu += SCTP_MIN_V4_OVERHEAD;
5359 net->mtu += SCTP_MIN_OVERHEAD;
5365 if (net->mtu < stcb->asoc.smallest_mtu) {
5366 sctp_pathmtu_adjustment(stcb, net->mtu);
5370 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5371 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5372 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5374 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5376 if (paddrp->spp_pathmaxrxt > 0) {
5377 if (net->dest_state & SCTP_ADDR_PF) {
5378 if (net->error_count > paddrp->spp_pathmaxrxt) {
5379 net->dest_state &= ~SCTP_ADDR_PF;
5382 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5383 (net->error_count > net->pf_threshold)) {
5384 net->dest_state |= SCTP_ADDR_PF;
5385 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5386 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5387 stcb->sctp_ep, stcb, net,
5388 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5389 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5392 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5393 if (net->error_count > paddrp->spp_pathmaxrxt) {
5394 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5395 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5398 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5399 net->dest_state |= SCTP_ADDR_REACHABLE;
5400 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5403 net->failure_threshold = paddrp->spp_pathmaxrxt;
5405 if (paddrp->spp_flags & SPP_DSCP) {
5406 net->dscp = paddrp->spp_dscp & 0xfc;
5410 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5411 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5412 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5413 net->flowlabel |= 0x80000000;
5418 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5419 if (paddrp->spp_pathmaxrxt > 0) {
5420 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5421 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5422 if (net->dest_state & SCTP_ADDR_PF) {
5423 if (net->error_count > paddrp->spp_pathmaxrxt) {
5424 net->dest_state &= ~SCTP_ADDR_PF;
5427 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5428 (net->error_count > net->pf_threshold)) {
5429 net->dest_state |= SCTP_ADDR_PF;
5430 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5431 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5432 stcb->sctp_ep, stcb, net,
5433 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5434 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5437 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5438 if (net->error_count > paddrp->spp_pathmaxrxt) {
5439 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5440 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5443 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5444 net->dest_state |= SCTP_ADDR_REACHABLE;
5445 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5448 net->failure_threshold = paddrp->spp_pathmaxrxt;
5451 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5452 if (paddrp->spp_hbinterval != 0) {
5453 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5454 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5455 stcb->asoc.heart_beat_delay = 0;
5457 /* Turn back on the timer */
5458 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5459 if (paddrp->spp_hbinterval != 0) {
5460 net->heart_beat_delay = paddrp->spp_hbinterval;
5461 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5462 net->heart_beat_delay = 0;
5464 if (net->dest_state & SCTP_ADDR_NOHB) {
5465 net->dest_state &= ~SCTP_ADDR_NOHB;
5467 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5468 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5469 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5471 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5473 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5474 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5475 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5476 net->dest_state |= SCTP_ADDR_NOHB;
5477 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5478 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5480 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5484 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5486 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5487 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5488 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5489 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5490 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5492 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5493 if (paddrp->spp_pathmtu > 0) {
5494 net->mtu = paddrp->spp_pathmtu;
5495 switch (net->ro._l_addr.sa.sa_family) {
5498 net->mtu += SCTP_MIN_V4_OVERHEAD;
5503 net->mtu += SCTP_MIN_OVERHEAD;
5509 if (net->mtu < stcb->asoc.smallest_mtu) {
5510 sctp_pathmtu_adjustment(stcb, net->mtu);
5514 if (paddrp->spp_pathmtu > 0) {
5515 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5517 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5519 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5520 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5521 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5522 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5524 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5526 stcb->asoc.default_mtu = 0;
5527 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5529 if (paddrp->spp_flags & SPP_DSCP) {
5530 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5531 net->dscp = paddrp->spp_dscp & 0xfc;
5534 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5535 stcb->asoc.default_dscp |= 0x01;
5538 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5539 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5540 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5541 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5542 net->flowlabel |= 0x80000000;
5545 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5546 stcb->asoc.default_flowlabel |= 0x80000000;
5550 SCTP_TCB_UNLOCK(stcb);
5552 /************************NO TCB, SET TO default stuff ******************/
5553 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5554 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5555 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5556 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
5557 SCTP_INP_WLOCK(inp);
5559 * For the TOS/FLOWLABEL stuff you
5560 * set it with the options on the
5563 if (paddrp->spp_pathmaxrxt > 0) {
5564 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5567 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5568 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5569 else if (paddrp->spp_hbinterval != 0) {
5570 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5571 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5572 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5575 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5576 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5577 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5578 } else if (paddrp->spp_hbinterval) {
5579 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5581 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5582 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5583 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5585 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5586 inp->sctp_ep.default_mtu = 0;
5587 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5588 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5589 if (paddrp->spp_pathmtu > 0) {
5590 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5592 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5594 if (paddrp->spp_flags & SPP_DSCP) {
5595 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5596 inp->sctp_ep.default_dscp |= 0x01;
5599 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5600 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5601 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5602 inp->sctp_ep.default_flowlabel |= 0x80000000;
5606 SCTP_INP_WUNLOCK(inp);
5608 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5616 struct sctp_rtoinfo *srto;
5617 uint32_t new_init, new_min, new_max;
5619 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5620 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5623 if (srto->srto_initial)
5624 new_init = srto->srto_initial;
5626 new_init = stcb->asoc.initial_rto;
5628 new_max = srto->srto_max;
5630 new_max = stcb->asoc.maxrto;
5632 new_min = srto->srto_min;
5634 new_min = stcb->asoc.minrto;
5635 if ((new_min <= new_init) && (new_init <= new_max)) {
5636 stcb->asoc.initial_rto = new_init;
5637 stcb->asoc.maxrto = new_max;
5638 stcb->asoc.minrto = new_min;
5640 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5643 SCTP_TCB_UNLOCK(stcb);
5645 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5646 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5647 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5648 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
5649 SCTP_INP_WLOCK(inp);
5650 if (srto->srto_initial)
5651 new_init = srto->srto_initial;
5653 new_init = inp->sctp_ep.initial_rto;
5655 new_max = srto->srto_max;
5657 new_max = inp->sctp_ep.sctp_maxrto;
5659 new_min = srto->srto_min;
5661 new_min = inp->sctp_ep.sctp_minrto;
5662 if ((new_min <= new_init) && (new_init <= new_max)) {
5663 inp->sctp_ep.initial_rto = new_init;
5664 inp->sctp_ep.sctp_maxrto = new_max;
5665 inp->sctp_ep.sctp_minrto = new_min;
5667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5670 SCTP_INP_WUNLOCK(inp);
5672 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5678 case SCTP_ASSOCINFO:
5680 struct sctp_assocparams *sasoc;
5682 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5683 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5684 if (sasoc->sasoc_cookie_life > 0) {
5685 /* boundary check the cookie life */
5686 if (sasoc->sasoc_cookie_life < SCTP_MIN_COOKIE_LIFE) {
5687 sasoc->sasoc_cookie_life = SCTP_MIN_COOKIE_LIFE;
5689 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5690 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5694 if (sasoc->sasoc_asocmaxrxt > 0) {
5695 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5697 if (sasoc->sasoc_cookie_life > 0) {
5698 stcb->asoc.cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5700 SCTP_TCB_UNLOCK(stcb);
5702 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5703 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5704 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5705 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
5706 SCTP_INP_WLOCK(inp);
5707 if (sasoc->sasoc_asocmaxrxt > 0) {
5708 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5710 if (sasoc->sasoc_cookie_life > 0) {
5711 inp->sctp_ep.def_cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5713 SCTP_INP_WUNLOCK(inp);
5715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5723 struct sctp_initmsg *sinit;
5725 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5726 SCTP_INP_WLOCK(inp);
5727 if (sinit->sinit_num_ostreams)
5728 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5730 if (sinit->sinit_max_instreams)
5731 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5733 if (sinit->sinit_max_attempts)
5734 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5736 if (sinit->sinit_max_init_timeo)
5737 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5738 SCTP_INP_WUNLOCK(inp);
5741 case SCTP_PRIMARY_ADDR:
5743 struct sctp_setprim *spa;
5744 struct sctp_nets *net;
5745 struct sockaddr *addr;
5746 #if defined(INET) && defined(INET6)
5747 struct sockaddr_in sin_store;
5750 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5751 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5753 #if defined(INET) && defined(INET6)
5754 if (spa->ssp_addr.ss_family == AF_INET6) {
5755 struct sockaddr_in6 *sin6;
5757 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5758 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5759 in6_sin6_2_sin(&sin_store, sin6);
5760 addr = (struct sockaddr *)&sin_store;
5762 addr = (struct sockaddr *)&spa->ssp_addr;
5765 addr = (struct sockaddr *)&spa->ssp_addr;
5768 addr = (struct sockaddr *)&spa->ssp_addr;
5771 net = sctp_findnet(stcb, addr);
5774 * We increment here since
5775 * sctp_findassociation_ep_addr() wil do a
5776 * decrement if it finds the stcb as long as
5777 * the locked tcb (last argument) is NOT a
5781 SCTP_INP_INCR_REF(inp);
5782 stcb = sctp_findassociation_ep_addr(&inp, addr,
5785 SCTP_INP_DECR_REF(inp);
5789 if ((stcb != NULL) && (net != NULL)) {
5790 if (net != stcb->asoc.primary_destination) {
5791 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5792 /* Ok we need to set it */
5793 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5794 if ((stcb->asoc.alternate) &&
5795 (!(net->dest_state & SCTP_ADDR_PF)) &&
5796 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5797 sctp_free_remote_addr(stcb->asoc.alternate);
5798 stcb->asoc.alternate = NULL;
5801 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5805 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5810 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5814 SCTP_TCB_UNLOCK(stcb);
5818 case SCTP_SET_DYNAMIC_PRIMARY:
5820 union sctp_sockstore *ss;
5822 error = priv_check(curthread,
5823 PRIV_NETINET_RESERVEDPORT);
5827 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5828 /* SUPER USER CHECK? */
5829 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5832 case SCTP_SET_PEER_PRIMARY_ADDR:
5834 struct sctp_setpeerprim *sspp;
5835 struct sockaddr *addr;
5836 #if defined(INET) && defined(INET6)
5837 struct sockaddr_in sin_store;
5840 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5841 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5843 struct sctp_ifa *ifa;
5845 #if defined(INET) && defined(INET6)
5846 if (sspp->sspp_addr.ss_family == AF_INET6) {
5847 struct sockaddr_in6 *sin6;
5849 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5850 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5851 in6_sin6_2_sin(&sin_store, sin6);
5852 addr = (struct sockaddr *)&sin_store;
5854 addr = (struct sockaddr *)&sspp->sspp_addr;
5857 addr = (struct sockaddr *)&sspp->sspp_addr;
5860 addr = (struct sockaddr *)&sspp->sspp_addr;
5862 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5864 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5868 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5870 * Must validate the ifa found is in
5873 struct sctp_laddr *laddr;
5876 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5877 if (laddr->ifa == NULL) {
5878 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5882 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5883 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5886 if (laddr->ifa == ifa) {
5892 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5897 switch (addr->sa_family) {
5901 struct sockaddr_in *sin;
5903 sin = (struct sockaddr_in *)addr;
5904 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5905 &sin->sin_addr) != 0) {
5906 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5916 struct sockaddr_in6 *sin6;
5918 sin6 = (struct sockaddr_in6 *)addr;
5919 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5920 &sin6->sin6_addr) != 0) {
5921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5929 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5934 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5935 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5938 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5940 SCTP_TCB_UNLOCK(stcb);
5942 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5947 case SCTP_BINDX_ADD_ADDR:
5949 struct sockaddr *sa;
5952 td = (struct thread *)p;
5953 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
5955 if (sa->sa_family == AF_INET) {
5956 if (optsize < sizeof(struct sockaddr_in)) {
5957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5962 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
5963 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5969 if (sa->sa_family == AF_INET6) {
5970 if (optsize < sizeof(struct sockaddr_in6)) {
5971 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5976 (error = prison_local_ip6(td->td_ucred,
5977 &(((struct sockaddr_in6 *)sa)->sin6_addr),
5978 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5979 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5985 error = EAFNOSUPPORT;
5988 sctp_bindx_add_address(so, inp, sa, vrf_id, &error, p);
5991 case SCTP_BINDX_REM_ADDR:
5993 struct sockaddr *sa;
5996 td = (struct thread *)p;
5998 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
6000 if (sa->sa_family == AF_INET) {
6001 if (optsize < sizeof(struct sockaddr_in)) {
6002 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6007 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
6008 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6014 if (sa->sa_family == AF_INET6) {
6015 if (optsize < sizeof(struct sockaddr_in6)) {
6016 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6021 (error = prison_local_ip6(td->td_ucred,
6022 &(((struct sockaddr_in6 *)sa)->sin6_addr),
6023 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6024 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6030 error = EAFNOSUPPORT;
6033 sctp_bindx_delete_address(inp, sa, vrf_id, &error);
6038 struct sctp_event *event;
6039 uint32_t event_type;
6041 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6042 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6043 switch (event->se_type) {
6044 case SCTP_ASSOC_CHANGE:
6045 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6047 case SCTP_PEER_ADDR_CHANGE:
6048 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6050 case SCTP_REMOTE_ERROR:
6051 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6053 case SCTP_SEND_FAILED:
6054 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6056 case SCTP_SHUTDOWN_EVENT:
6057 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6059 case SCTP_ADAPTATION_INDICATION:
6060 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6062 case SCTP_PARTIAL_DELIVERY_EVENT:
6063 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6065 case SCTP_AUTHENTICATION_EVENT:
6066 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6068 case SCTP_STREAM_RESET_EVENT:
6069 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6071 case SCTP_SENDER_DRY_EVENT:
6072 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6074 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6076 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6079 case SCTP_ASSOC_RESET_EVENT:
6080 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6082 case SCTP_STREAM_CHANGE_EVENT:
6083 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6085 case SCTP_SEND_FAILED_EVENT:
6086 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6090 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6094 if (event_type > 0) {
6097 sctp_stcb_feature_on(inp, stcb, event_type);
6098 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6099 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6100 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6101 (stcb->asoc.stream_queue_cnt == 0)) {
6102 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6106 sctp_stcb_feature_off(inp, stcb, event_type);
6108 SCTP_TCB_UNLOCK(stcb);
6111 * We don't want to send up a storm
6112 * of events, so return an error for
6115 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6116 (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6117 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6118 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6119 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6123 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6124 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6125 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6126 ((event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6127 (event->se_assoc_id == SCTP_ALL_ASSOC)))) {
6128 SCTP_INP_WLOCK(inp);
6130 sctp_feature_on(inp, event_type);
6132 sctp_feature_off(inp, event_type);
6134 SCTP_INP_WUNLOCK(inp);
6136 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6137 ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6138 (event->se_assoc_id == SCTP_ALL_ASSOC))) {
6139 SCTP_INP_RLOCK(inp);
6140 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6141 SCTP_TCB_LOCK(stcb);
6143 sctp_stcb_feature_on(inp, stcb, event_type);
6145 sctp_stcb_feature_off(inp, stcb, event_type);
6147 SCTP_TCB_UNLOCK(stcb);
6149 SCTP_INP_RUNLOCK(inp);
6154 SCTP_TCB_UNLOCK(stcb);
6159 case SCTP_RECVRCVINFO:
6163 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6164 SCTP_INP_WLOCK(inp);
6166 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6168 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6170 SCTP_INP_WUNLOCK(inp);
6173 case SCTP_RECVNXTINFO:
6177 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6178 SCTP_INP_WLOCK(inp);
6180 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6182 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6184 SCTP_INP_WUNLOCK(inp);
6187 case SCTP_DEFAULT_SNDINFO:
6189 struct sctp_sndinfo *info;
6192 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6193 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6196 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6197 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6198 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6199 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6200 stcb->asoc.def_send.sinfo_flags |= policy;
6201 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6202 stcb->asoc.def_send.sinfo_context = info->snd_context;
6204 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6207 SCTP_TCB_UNLOCK(stcb);
6209 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6210 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6211 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6212 ((info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6213 (info->snd_assoc_id == SCTP_ALL_ASSOC)))) {
6214 SCTP_INP_WLOCK(inp);
6215 inp->def_send.sinfo_stream = info->snd_sid;
6216 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6217 inp->def_send.sinfo_flags = info->snd_flags;
6218 inp->def_send.sinfo_flags |= policy;
6219 inp->def_send.sinfo_ppid = info->snd_ppid;
6220 inp->def_send.sinfo_context = info->snd_context;
6221 SCTP_INP_WUNLOCK(inp);
6223 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6224 ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6225 (info->snd_assoc_id == SCTP_ALL_ASSOC))) {
6226 SCTP_INP_RLOCK(inp);
6227 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6228 SCTP_TCB_LOCK(stcb);
6229 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6230 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6231 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6232 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6233 stcb->asoc.def_send.sinfo_flags |= policy;
6234 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6235 stcb->asoc.def_send.sinfo_context = info->snd_context;
6237 SCTP_TCB_UNLOCK(stcb);
6239 SCTP_INP_RUNLOCK(inp);
6244 case SCTP_DEFAULT_PRINFO:
6246 struct sctp_default_prinfo *info;
6248 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6249 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6251 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6253 SCTP_TCB_UNLOCK(stcb);
6255 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6260 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6261 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6262 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6263 SCTP_TCB_UNLOCK(stcb);
6265 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6266 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6267 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6268 ((info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6269 (info->pr_assoc_id == SCTP_ALL_ASSOC)))) {
6270 SCTP_INP_WLOCK(inp);
6271 inp->def_send.sinfo_flags &= 0xfff0;
6272 inp->def_send.sinfo_flags |= info->pr_policy;
6273 inp->def_send.sinfo_timetolive = info->pr_value;
6274 SCTP_INP_WUNLOCK(inp);
6276 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6277 ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6278 (info->pr_assoc_id == SCTP_ALL_ASSOC))) {
6279 SCTP_INP_RLOCK(inp);
6280 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6281 SCTP_TCB_LOCK(stcb);
6282 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6283 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6284 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6285 SCTP_TCB_UNLOCK(stcb);
6287 SCTP_INP_RUNLOCK(inp);
6292 case SCTP_PEER_ADDR_THLDS:
6293 /* Applies to the specific association */
6295 struct sctp_paddrthlds *thlds;
6296 struct sctp_nets *net;
6297 struct sockaddr *addr;
6298 #if defined(INET) && defined(INET6)
6299 struct sockaddr_in sin_store;
6302 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6303 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6305 #if defined(INET) && defined(INET6)
6306 if (thlds->spt_address.ss_family == AF_INET6) {
6307 struct sockaddr_in6 *sin6;
6309 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6310 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6311 in6_sin6_2_sin(&sin_store, sin6);
6312 addr = (struct sockaddr *)&sin_store;
6314 addr = (struct sockaddr *)&thlds->spt_address;
6317 addr = (struct sockaddr *)&thlds->spt_address;
6320 addr = (struct sockaddr *)&thlds->spt_address;
6323 net = sctp_findnet(stcb, addr);
6326 * We increment here since
6327 * sctp_findassociation_ep_addr() wil do a
6328 * decrement if it finds the stcb as long as
6329 * the locked tcb (last argument) is NOT a
6333 SCTP_INP_INCR_REF(inp);
6334 stcb = sctp_findassociation_ep_addr(&inp, addr,
6337 SCTP_INP_DECR_REF(inp);
6340 if ((stcb != NULL) && (net == NULL)) {
6342 if (addr->sa_family == AF_INET) {
6343 struct sockaddr_in *sin;
6345 sin = (struct sockaddr_in *)addr;
6346 if (sin->sin_addr.s_addr != INADDR_ANY) {
6347 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6348 SCTP_TCB_UNLOCK(stcb);
6355 if (addr->sa_family == AF_INET6) {
6356 struct sockaddr_in6 *sin6;
6358 sin6 = (struct sockaddr_in6 *)addr;
6359 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6360 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6361 SCTP_TCB_UNLOCK(stcb);
6368 error = EAFNOSUPPORT;
6369 SCTP_TCB_UNLOCK(stcb);
6370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6374 if (thlds->spt_pathcpthld != 0xffff) {
6376 SCTP_TCB_UNLOCK(stcb);
6379 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6384 net->failure_threshold = thlds->spt_pathmaxrxt;
6385 net->pf_threshold = thlds->spt_pathpfthld;
6386 if (net->dest_state & SCTP_ADDR_PF) {
6387 if ((net->error_count > net->failure_threshold) ||
6388 (net->error_count <= net->pf_threshold)) {
6389 net->dest_state &= ~SCTP_ADDR_PF;
6392 if ((net->error_count > net->pf_threshold) &&
6393 (net->error_count <= net->failure_threshold)) {
6394 net->dest_state |= SCTP_ADDR_PF;
6395 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6396 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6397 stcb->sctp_ep, stcb, net,
6398 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6399 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6402 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6403 if (net->error_count > net->failure_threshold) {
6404 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6405 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6408 if (net->error_count <= net->failure_threshold) {
6409 net->dest_state |= SCTP_ADDR_REACHABLE;
6410 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6414 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6415 net->failure_threshold = thlds->spt_pathmaxrxt;
6416 net->pf_threshold = thlds->spt_pathpfthld;
6417 if (net->dest_state & SCTP_ADDR_PF) {
6418 if ((net->error_count > net->failure_threshold) ||
6419 (net->error_count <= net->pf_threshold)) {
6420 net->dest_state &= ~SCTP_ADDR_PF;
6423 if ((net->error_count > net->pf_threshold) &&
6424 (net->error_count <= net->failure_threshold)) {
6425 net->dest_state |= SCTP_ADDR_PF;
6426 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6427 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6428 stcb->sctp_ep, stcb, net,
6429 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6430 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6433 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6434 if (net->error_count > net->failure_threshold) {
6435 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6436 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6439 if (net->error_count <= net->failure_threshold) {
6440 net->dest_state |= SCTP_ADDR_REACHABLE;
6441 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6445 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6446 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6448 SCTP_TCB_UNLOCK(stcb);
6450 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6451 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6452 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6453 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
6454 SCTP_INP_WLOCK(inp);
6455 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6456 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6457 SCTP_INP_WUNLOCK(inp);
6459 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6465 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6467 struct sctp_udpencaps *encaps;
6468 struct sctp_nets *net;
6469 struct sockaddr *addr;
6470 #if defined(INET) && defined(INET6)
6471 struct sockaddr_in sin_store;
6474 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6475 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6477 #if defined(INET) && defined(INET6)
6478 if (encaps->sue_address.ss_family == AF_INET6) {
6479 struct sockaddr_in6 *sin6;
6481 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6482 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6483 in6_sin6_2_sin(&sin_store, sin6);
6484 addr = (struct sockaddr *)&sin_store;
6486 addr = (struct sockaddr *)&encaps->sue_address;
6489 addr = (struct sockaddr *)&encaps->sue_address;
6492 addr = (struct sockaddr *)&encaps->sue_address;
6495 net = sctp_findnet(stcb, addr);
6498 * We increment here since
6499 * sctp_findassociation_ep_addr() wil do a
6500 * decrement if it finds the stcb as long as
6501 * the locked tcb (last argument) is NOT a
6505 SCTP_INP_INCR_REF(inp);
6506 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6508 SCTP_INP_DECR_REF(inp);
6511 if ((stcb != NULL) && (net == NULL)) {
6513 if (addr->sa_family == AF_INET) {
6514 struct sockaddr_in *sin;
6516 sin = (struct sockaddr_in *)addr;
6517 if (sin->sin_addr.s_addr != INADDR_ANY) {
6518 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6519 SCTP_TCB_UNLOCK(stcb);
6526 if (addr->sa_family == AF_INET6) {
6527 struct sockaddr_in6 *sin6;
6529 sin6 = (struct sockaddr_in6 *)addr;
6530 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6531 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6532 SCTP_TCB_UNLOCK(stcb);
6539 error = EAFNOSUPPORT;
6540 SCTP_TCB_UNLOCK(stcb);
6541 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6548 net->port = encaps->sue_port;
6550 stcb->asoc.port = encaps->sue_port;
6552 SCTP_TCB_UNLOCK(stcb);
6554 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6555 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6556 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6557 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
6558 SCTP_INP_WLOCK(inp);
6559 inp->sctp_ep.port = encaps->sue_port;
6560 SCTP_INP_WUNLOCK(inp);
6562 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6568 case SCTP_ECN_SUPPORTED:
6570 struct sctp_assoc_value *av;
6572 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6573 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6576 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6578 SCTP_TCB_UNLOCK(stcb);
6580 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6581 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6582 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6583 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6584 SCTP_INP_WLOCK(inp);
6585 if (av->assoc_value == 0) {
6586 inp->ecn_supported = 0;
6588 inp->ecn_supported = 1;
6590 SCTP_INP_WUNLOCK(inp);
6592 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6598 case SCTP_PR_SUPPORTED:
6600 struct sctp_assoc_value *av;
6602 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6603 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6606 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6608 SCTP_TCB_UNLOCK(stcb);
6610 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6611 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6612 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6613 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6614 SCTP_INP_WLOCK(inp);
6615 if (av->assoc_value == 0) {
6616 inp->prsctp_supported = 0;
6618 inp->prsctp_supported = 1;
6620 SCTP_INP_WUNLOCK(inp);
6622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6628 case SCTP_AUTH_SUPPORTED:
6630 struct sctp_assoc_value *av;
6632 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6633 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6636 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6638 SCTP_TCB_UNLOCK(stcb);
6640 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6641 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6642 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6643 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6644 if ((av->assoc_value == 0) &&
6645 (inp->asconf_supported == 1)) {
6647 * AUTH is required for
6650 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6653 SCTP_INP_WLOCK(inp);
6654 if (av->assoc_value == 0) {
6655 inp->auth_supported = 0;
6657 inp->auth_supported = 1;
6659 SCTP_INP_WUNLOCK(inp);
6662 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6668 case SCTP_ASCONF_SUPPORTED:
6670 struct sctp_assoc_value *av;
6672 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6673 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6676 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6678 SCTP_TCB_UNLOCK(stcb);
6680 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6681 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6682 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6683 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6684 if ((av->assoc_value != 0) &&
6685 (inp->auth_supported == 0)) {
6687 * AUTH is required for
6690 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6693 SCTP_INP_WLOCK(inp);
6694 if (av->assoc_value == 0) {
6695 inp->asconf_supported = 0;
6696 sctp_auth_delete_chunk(SCTP_ASCONF,
6697 inp->sctp_ep.local_auth_chunks);
6698 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6699 inp->sctp_ep.local_auth_chunks);
6701 inp->asconf_supported = 1;
6702 sctp_auth_add_chunk(SCTP_ASCONF,
6703 inp->sctp_ep.local_auth_chunks);
6704 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6705 inp->sctp_ep.local_auth_chunks);
6707 SCTP_INP_WUNLOCK(inp);
6710 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6716 case SCTP_RECONFIG_SUPPORTED:
6718 struct sctp_assoc_value *av;
6720 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6721 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6726 SCTP_TCB_UNLOCK(stcb);
6728 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6729 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6730 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6731 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6732 SCTP_INP_WLOCK(inp);
6733 if (av->assoc_value == 0) {
6734 inp->reconfig_supported = 0;
6736 inp->reconfig_supported = 1;
6738 SCTP_INP_WUNLOCK(inp);
6740 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6746 case SCTP_NRSACK_SUPPORTED:
6748 struct sctp_assoc_value *av;
6750 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6751 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6754 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6756 SCTP_TCB_UNLOCK(stcb);
6758 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6759 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6760 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6761 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6762 SCTP_INP_WLOCK(inp);
6763 if (av->assoc_value == 0) {
6764 inp->nrsack_supported = 0;
6766 inp->nrsack_supported = 1;
6768 SCTP_INP_WUNLOCK(inp);
6770 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6776 case SCTP_PKTDROP_SUPPORTED:
6778 struct sctp_assoc_value *av;
6780 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6781 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6784 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6786 SCTP_TCB_UNLOCK(stcb);
6788 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6789 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6790 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6791 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6792 SCTP_INP_WLOCK(inp);
6793 if (av->assoc_value == 0) {
6794 inp->pktdrop_supported = 0;
6796 inp->pktdrop_supported = 1;
6798 SCTP_INP_WUNLOCK(inp);
6800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6808 struct sctp_assoc_value *av;
6809 struct sctp_nets *net;
6811 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6812 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6815 stcb->asoc.max_cwnd = av->assoc_value;
6816 if (stcb->asoc.max_cwnd > 0) {
6817 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6818 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6819 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6820 net->cwnd = stcb->asoc.max_cwnd;
6821 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6822 net->cwnd = net->mtu - sizeof(struct sctphdr);
6827 SCTP_TCB_UNLOCK(stcb);
6829 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6830 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6831 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6832 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6833 SCTP_INP_WLOCK(inp);
6834 inp->max_cwnd = av->assoc_value;
6835 SCTP_INP_WUNLOCK(inp);
6837 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6844 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6845 error = ENOPROTOOPT;
6847 } /* end switch (opt) */
6852 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6854 struct epoch_tracker et;
6855 struct sctp_inpcb *inp;
6856 void *optval = NULL;
6861 if ((sopt->sopt_level == SOL_SOCKET) &&
6862 (sopt->sopt_name == SO_SETFIB)) {
6863 inp = (struct sctp_inpcb *)so->so_pcb;
6865 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6868 SCTP_INP_WLOCK(inp);
6869 inp->fibnum = so->so_fibnum;
6870 SCTP_INP_WUNLOCK(inp);
6873 if (sopt->sopt_level != IPPROTO_SCTP) {
6874 /* wrong proto level... send back up to IP */
6876 if (INP_CHECK_SOCKAF(so, AF_INET6))
6877 error = ip6_ctloutput(so, sopt);
6879 #if defined(INET) && defined(INET6)
6883 error = ip_ctloutput(so, sopt);
6887 optsize = sopt->sopt_valsize;
6888 if (optsize > SCTP_SOCKET_OPTION_LIMIT) {
6889 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6893 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6894 if (optval == NULL) {
6895 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6898 error = sooptcopyin(sopt, optval, optsize, optsize);
6900 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6904 p = (void *)sopt->sopt_td;
6905 if (sopt->sopt_dir == SOPT_SET) {
6906 NET_EPOCH_ENTER(et);
6907 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6909 } else if (sopt->sopt_dir == SOPT_GET) {
6910 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6912 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6915 if ((error == 0) && (optval != NULL)) {
6916 error = sooptcopyout(sopt, optval, optsize);
6917 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6918 } else if (optval != NULL) {
6919 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6927 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6929 struct epoch_tracker et;
6931 int create_lock_on = 0;
6933 struct sctp_inpcb *inp;
6934 struct sctp_tcb *stcb = NULL;
6936 inp = (struct sctp_inpcb *)so->so_pcb;
6938 /* I made the same as TCP since we are not setup? */
6939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6940 return (ECONNRESET);
6943 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6947 switch (addr->sa_family) {
6951 struct sockaddr_in6 *sin6;
6953 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6954 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6957 sin6 = (struct sockaddr_in6 *)addr;
6958 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6->sin6_addr)) != 0) {
6959 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6968 struct sockaddr_in *sin;
6970 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6971 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6974 sin = (struct sockaddr_in *)addr;
6975 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sin->sin_addr)) != 0) {
6976 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6983 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6984 return (EAFNOSUPPORT);
6986 SCTP_INP_INCR_REF(inp);
6987 SCTP_ASOC_CREATE_LOCK(inp);
6989 NET_EPOCH_ENTER(et);
6991 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6992 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6993 /* Should I really unlock ? */
6994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6999 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
7000 (addr->sa_family == AF_INET6)) {
7001 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7006 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
7007 SCTP_PCB_FLAGS_UNBOUND) {
7008 /* Bind a ephemeral port */
7009 error = sctp_inpcb_bind(so, NULL, NULL, p);
7014 /* Now do we connect? */
7015 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
7016 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
7017 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7021 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7022 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7023 /* We are already connected AND the TCP model */
7024 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7028 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7029 SCTP_INP_RLOCK(inp);
7030 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7031 SCTP_INP_RUNLOCK(inp);
7034 * We increment here since sctp_findassociation_ep_addr()
7035 * will do a decrement if it finds the stcb as long as the
7036 * locked tcb (last argument) is NOT a TCB.. aka NULL.
7038 SCTP_INP_INCR_REF(inp);
7039 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7041 SCTP_INP_DECR_REF(inp);
7043 SCTP_TCB_UNLOCK(stcb);
7047 /* Already have or am bring up an association */
7048 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7053 vrf_id = inp->def_vrf_id;
7054 /* We are GOOD to go */
7055 stcb = sctp_aloc_assoc_connected(inp, addr, &error, 0, 0, vrf_id,
7056 inp->sctp_ep.pre_open_stream_count,
7057 inp->sctp_ep.port, p,
7058 SCTP_INITIALIZE_AUTH_PARAMS);
7060 /* Gak! no memory */
7063 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7064 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7066 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7067 SCTP_TCB_UNLOCK(stcb);
7070 if (create_lock_on) {
7071 SCTP_ASOC_CREATE_UNLOCK(inp);
7073 SCTP_INP_DECR_REF(inp);
7079 sctp_listen(struct socket *so, int backlog, struct thread *p)
7082 * Note this module depends on the protocol processing being called
7083 * AFTER any socket level flags and backlog are applied to the
7084 * socket. The traditional way that the socket flags are applied is
7085 * AFTER protocol processing. We have made a change to the
7086 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7087 * place if the socket API for SCTP is to work properly.
7091 struct sctp_inpcb *inp;
7093 inp = (struct sctp_inpcb *)so->so_pcb;
7095 /* I made the same as TCP since we are not setup? */
7096 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7097 return (ECONNRESET);
7099 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7100 /* See if we have a listener */
7101 struct sctp_inpcb *tinp;
7102 union sctp_sockstore store;
7104 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7106 struct sctp_laddr *laddr;
7108 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7109 memcpy(&store, &laddr->ifa->address, sizeof(store));
7110 switch (store.sa.sa_family) {
7113 store.sin.sin_port = inp->sctp_lport;
7118 store.sin6.sin6_port = inp->sctp_lport;
7124 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7125 if (tinp && (tinp != inp) &&
7126 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7127 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7128 (SCTP_IS_LISTENING(tinp))) {
7130 * we have a listener already and
7133 SCTP_INP_DECR_REF(tinp);
7134 return (EADDRINUSE);
7136 SCTP_INP_DECR_REF(tinp);
7140 /* Setup a local addr bound all */
7141 memset(&store, 0, sizeof(store));
7143 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7144 store.sa.sa_family = AF_INET6;
7145 store.sa.sa_len = sizeof(struct sockaddr_in6);
7149 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7150 store.sa.sa_family = AF_INET;
7151 store.sa.sa_len = sizeof(struct sockaddr_in);
7154 switch (store.sa.sa_family) {
7157 store.sin.sin_port = inp->sctp_lport;
7162 store.sin6.sin6_port = inp->sctp_lport;
7168 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7169 if (tinp && (tinp != inp) &&
7170 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7171 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7172 (SCTP_IS_LISTENING(tinp))) {
7174 * we have a listener already and its not
7177 SCTP_INP_DECR_REF(tinp);
7178 return (EADDRINUSE);
7180 SCTP_INP_DECR_REF(tinp);
7184 SCTP_INP_RLOCK(inp);
7185 #ifdef SCTP_LOCK_LOGGING
7186 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7187 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7191 error = solisten_proto_check(so);
7194 SCTP_INP_RUNLOCK(inp);
7197 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7198 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7200 * The unlucky case - We are in the tcp pool with this guy.
7201 * - Someone else is in the main inp slot. - We must move
7202 * this guy (the listener) to the main slot - We must then
7203 * move the guy that was listener to the TCP Pool.
7205 if (sctp_swap_inpcb_for_listen(inp)) {
7206 SCTP_INP_RUNLOCK(inp);
7207 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7208 return (EADDRINUSE);
7212 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7213 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7214 /* We are already connected AND the TCP model */
7215 SCTP_INP_RUNLOCK(inp);
7216 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7217 return (EADDRINUSE);
7219 SCTP_INP_RUNLOCK(inp);
7220 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7221 /* We must do a bind. */
7222 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7223 /* bind error, probably perm */
7227 SCTP_INP_WLOCK(inp);
7228 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7230 solisten_proto(so, backlog);
7234 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7236 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7238 SCTP_INP_WUNLOCK(inp);
7242 static int sctp_defered_wakeup_cnt = 0;
7245 sctp_accept(struct socket *so, struct sockaddr **addr)
7247 struct sctp_tcb *stcb;
7248 struct sctp_inpcb *inp;
7249 union sctp_sockstore store;
7253 inp = (struct sctp_inpcb *)so->so_pcb;
7256 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7257 return (ECONNRESET);
7259 SCTP_INP_WLOCK(inp);
7260 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7261 SCTP_INP_WUNLOCK(inp);
7262 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7263 return (EOPNOTSUPP);
7265 if (so->so_state & SS_ISDISCONNECTED) {
7266 SCTP_INP_WUNLOCK(inp);
7267 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7268 return (ECONNABORTED);
7270 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7272 SCTP_INP_WUNLOCK(inp);
7273 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7274 return (ECONNRESET);
7276 SCTP_TCB_LOCK(stcb);
7277 store = stcb->asoc.primary_destination->ro._l_addr;
7278 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7279 /* Wake any delayed sleep action */
7280 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7281 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7282 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7283 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7284 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7285 if (sowriteable(inp->sctp_socket)) {
7286 sowwakeup_locked(inp->sctp_socket);
7288 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7291 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7292 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7293 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7294 if (soreadable(inp->sctp_socket)) {
7295 sctp_defered_wakeup_cnt++;
7296 sorwakeup_locked(inp->sctp_socket);
7298 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7302 SCTP_INP_WUNLOCK(inp);
7303 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7304 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7305 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7307 SCTP_TCB_UNLOCK(stcb);
7309 switch (store.sa.sa_family) {
7313 struct sockaddr_in *sin;
7315 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7318 sin->sin_family = AF_INET;
7319 sin->sin_len = sizeof(*sin);
7320 sin->sin_port = store.sin.sin_port;
7321 sin->sin_addr = store.sin.sin_addr;
7322 *addr = (struct sockaddr *)sin;
7329 struct sockaddr_in6 *sin6;
7331 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7334 sin6->sin6_family = AF_INET6;
7335 sin6->sin6_len = sizeof(*sin6);
7336 sin6->sin6_port = store.sin6.sin6_port;
7337 sin6->sin6_addr = store.sin6.sin6_addr;
7338 if ((error = sa6_recoverscope(sin6)) != 0) {
7339 SCTP_FREE_SONAME(sin6);
7342 *addr = (struct sockaddr *)sin6;
7355 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7357 struct sockaddr_in *sin;
7359 struct sctp_inpcb *inp;
7360 struct sctp_ifa *sctp_ifa;
7363 * Do the malloc first in case it blocks.
7365 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7368 sin->sin_family = AF_INET;
7369 sin->sin_len = sizeof(*sin);
7370 inp = (struct sctp_inpcb *)so->so_pcb;
7372 SCTP_FREE_SONAME(sin);
7373 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7374 return (ECONNRESET);
7376 SCTP_INP_RLOCK(inp);
7377 sin->sin_port = inp->sctp_lport;
7378 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7379 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7380 struct sctp_tcb *stcb;
7381 struct sockaddr_in *sin_a;
7382 struct sctp_nets *net;
7385 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7391 SCTP_TCB_LOCK(stcb);
7392 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7393 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7395 /* this will make coverity happy */
7398 if (sin_a->sin_family == AF_INET) {
7403 if ((!fnd) || (sin_a == NULL)) {
7405 SCTP_TCB_UNLOCK(stcb);
7409 vrf_id = inp->def_vrf_id;
7410 sctp_ifa = sctp_source_address_selection(inp,
7412 (sctp_route_t *)&net->ro,
7415 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7416 sctp_free_ifa(sctp_ifa);
7418 SCTP_TCB_UNLOCK(stcb);
7420 /* For the bound all case you get back 0 */
7422 sin->sin_addr.s_addr = 0;
7426 /* Take the first IPv4 address in the list */
7427 struct sctp_laddr *laddr;
7430 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7431 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7432 struct sockaddr_in *sin_a;
7434 sin_a = &laddr->ifa->address.sin;
7435 sin->sin_addr = sin_a->sin_addr;
7441 SCTP_FREE_SONAME(sin);
7442 SCTP_INP_RUNLOCK(inp);
7443 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7447 SCTP_INP_RUNLOCK(inp);
7448 (*addr) = (struct sockaddr *)sin;
7453 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7455 struct sockaddr_in *sin;
7457 struct sockaddr_in *sin_a;
7458 struct sctp_inpcb *inp;
7459 struct sctp_tcb *stcb;
7460 struct sctp_nets *net;
7462 /* Do the malloc first in case it blocks. */
7463 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7466 sin->sin_family = AF_INET;
7467 sin->sin_len = sizeof(*sin);
7469 inp = (struct sctp_inpcb *)so->so_pcb;
7470 if ((inp == NULL) ||
7471 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7472 /* UDP type and listeners will drop out here */
7473 SCTP_FREE_SONAME(sin);
7474 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7477 SCTP_INP_RLOCK(inp);
7478 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7480 SCTP_TCB_LOCK(stcb);
7482 SCTP_INP_RUNLOCK(inp);
7484 SCTP_FREE_SONAME(sin);
7485 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7486 return (ECONNRESET);
7489 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7490 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7491 if (sin_a->sin_family == AF_INET) {
7493 sin->sin_port = stcb->rport;
7494 sin->sin_addr = sin_a->sin_addr;
7498 SCTP_TCB_UNLOCK(stcb);
7500 /* No IPv4 address */
7501 SCTP_FREE_SONAME(sin);
7502 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7505 (*addr) = (struct sockaddr *)sin;
7509 struct pr_usrreqs sctp_usrreqs = {
7510 .pru_abort = sctp_abort,
7511 .pru_accept = sctp_accept,
7512 .pru_attach = sctp_attach,
7513 .pru_bind = sctp_bind,
7514 .pru_connect = sctp_connect,
7515 .pru_control = in_control,
7516 .pru_close = sctp_close,
7517 .pru_detach = sctp_close,
7518 .pru_sopoll = sopoll_generic,
7519 .pru_flush = sctp_flush,
7520 .pru_disconnect = sctp_disconnect,
7521 .pru_listen = sctp_listen,
7522 .pru_peeraddr = sctp_peeraddr,
7523 .pru_send = sctp_sendm,
7524 .pru_shutdown = sctp_shutdown,
7525 .pru_sockaddr = sctp_ingetaddr,
7526 .pru_sosend = sctp_sosend,
7527 .pru_soreceive = sctp_soreceive