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, uint32_t mtu, bool resend)
109 struct sctp_association *asoc;
110 struct sctp_tmit_chunk *chk;
114 KASSERT(mtu < asoc->smallest_mtu,
115 ("Currently only reducing association MTU %u supported (MTU %u)",
116 asoc->smallest_mtu, mtu));
117 asoc->smallest_mtu = mtu;
118 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
119 overhead = SCTP_MIN_OVERHEAD;
121 overhead = SCTP_MIN_V4_OVERHEAD;
123 if (asoc->idata_supported) {
124 if (sctp_auth_is_required_chunk(SCTP_IDATA, asoc->peer_auth_chunks)) {
125 overhead += sctp_get_auth_chunk_len(asoc->peer_hmac_id);
128 if (sctp_auth_is_required_chunk(SCTP_DATA, asoc->peer_auth_chunks)) {
129 overhead += sctp_get_auth_chunk_len(asoc->peer_hmac_id);
132 KASSERT(overhead % 4 == 0,
133 ("overhead (%u) not a multiple of 4", overhead));
134 TAILQ_FOREACH(chk, &asoc->send_queue, sctp_next) {
135 if (((uint32_t)chk->send_size + overhead) > mtu) {
136 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
139 TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) {
140 if (((uint32_t)chk->send_size + overhead) > mtu) {
141 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
142 if (resend && chk->sent < SCTP_DATAGRAM_RESEND) {
144 * If requested, mark the chunk for
145 * immediate resend, since we sent it being
148 sctp_flight_size_decrease(chk);
149 sctp_total_flight_decrease(stcb, chk);
150 chk->sent = SCTP_DATAGRAM_RESEND;
151 sctp_ucount_incr(asoc->sent_queue_retran_cnt);
152 chk->rec.data.doing_fast_retransmit = 0;
153 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
154 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
155 chk->whoTo->flight_size,
157 (uint32_t)(uintptr_t)chk->whoTo,
160 /* Clear any time, so NO RTT is being done. */
161 if (chk->do_rtt == 1) {
163 chk->whoTo->rto_needed = 1;
172 sctp_notify(struct sctp_inpcb *inp,
173 struct sctp_tcb *stcb,
174 struct sctp_nets *net,
182 if (icmp_type != ICMP_UNREACH) {
183 /* We only care about unreachable */
184 SCTP_TCB_UNLOCK(stcb);
187 if ((icmp_code == ICMP_UNREACH_NET) ||
188 (icmp_code == ICMP_UNREACH_HOST) ||
189 (icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
190 (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
191 (icmp_code == ICMP_UNREACH_ISOLATED) ||
192 (icmp_code == ICMP_UNREACH_NET_PROHIB) ||
193 (icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
194 (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
195 /* Mark the net unreachable. */
196 if (net->dest_state & SCTP_ADDR_REACHABLE) {
197 /* OK, that destination is NOT reachable. */
198 net->dest_state &= ~SCTP_ADDR_REACHABLE;
199 net->dest_state &= ~SCTP_ADDR_PF;
200 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
202 (void *)net, SCTP_SO_NOT_LOCKED);
204 SCTP_TCB_UNLOCK(stcb);
205 } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) ||
206 (icmp_code == ICMP_UNREACH_PORT)) {
207 /* Treat it like an ABORT. */
208 sctp_abort_notification(stcb, true, false, 0, NULL, SCTP_SO_NOT_LOCKED);
209 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
210 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
211 /* no need to unlock here, since the TCB is gone */
212 } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) {
213 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
214 SCTP_TCB_UNLOCK(stcb);
217 /* Find the next (smaller) MTU */
220 * Old type router that does not tell us what the
221 * next MTU is. Rats we will have to guess (in a
222 * educated fashion of course).
224 next_mtu = sctp_get_prev_mtu(ip_len);
226 /* Stop the PMTU timer. */
227 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
229 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
230 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
234 /* Update the path MTU. */
236 next_mtu -= sizeof(struct udphdr);
238 if (net->mtu > next_mtu) {
241 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu + sizeof(struct udphdr));
243 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu);
246 /* Update the association MTU */
247 if (stcb->asoc.smallest_mtu > next_mtu) {
248 sctp_pathmtu_adjustment(stcb, next_mtu, true);
250 /* Finally, start the PMTU timer if it was running before. */
252 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
254 SCTP_TCB_UNLOCK(stcb);
256 SCTP_TCB_UNLOCK(stcb);
261 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
267 struct sctp_inpcb *inp;
268 struct sctp_tcb *stcb;
269 struct sctp_nets *net;
270 struct sctp_init_chunk *ch;
271 struct sockaddr_in src, dst;
273 if (sa->sa_family != AF_INET ||
274 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
277 if (PRC_IS_REDIRECT(cmd)) {
279 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
283 inner_ip = (struct ip *)vip;
284 icmp = (struct icmp *)((caddr_t)inner_ip -
285 (sizeof(struct icmp) - sizeof(struct ip)));
286 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
287 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
288 memset(&src, 0, sizeof(struct sockaddr_in));
289 src.sin_family = AF_INET;
290 src.sin_len = sizeof(struct sockaddr_in);
291 src.sin_port = sh->src_port;
292 src.sin_addr = inner_ip->ip_src;
293 memset(&dst, 0, sizeof(struct sockaddr_in));
294 dst.sin_family = AF_INET;
295 dst.sin_len = sizeof(struct sockaddr_in);
296 dst.sin_port = sh->dest_port;
297 dst.sin_addr = inner_ip->ip_dst;
299 * 'dst' holds the dest of the packet that failed to be
300 * sent. 'src' holds our local endpoint address. Thus we
301 * reverse the dst and the src in the lookup.
305 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
306 (struct sockaddr *)&src,
309 if ((stcb != NULL) &&
312 /* Check the verification tag */
313 if (ntohl(sh->v_tag) != 0) {
315 * This must be the verification tag used
316 * for sending out packets. We don't
317 * consider packets reflecting the
320 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
321 SCTP_TCB_UNLOCK(stcb);
325 if (ntohs(outer_ip->ip_len) >=
327 8 + (inner_ip->ip_hl << 2) + 20) {
329 * In this case we can check if we
330 * got an INIT chunk and if the
331 * initiate tag matches.
333 ch = (struct sctp_init_chunk *)(sh + 1);
334 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
335 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
336 SCTP_TCB_UNLOCK(stcb);
340 SCTP_TCB_UNLOCK(stcb);
344 sctp_notify(inp, stcb, net,
347 ntohs(inner_ip->ip_len),
348 (uint32_t)ntohs(icmp->icmp_nextmtu));
350 if ((stcb == NULL) && (inp != NULL)) {
351 /* reduce ref-count */
353 SCTP_INP_DECR_REF(inp);
354 SCTP_INP_WUNLOCK(inp);
357 SCTP_TCB_UNLOCK(stcb);
366 sctp_getcred(SYSCTL_HANDLER_ARGS)
369 struct sockaddr_in addrs[2];
370 struct sctp_inpcb *inp;
371 struct sctp_nets *net;
372 struct sctp_tcb *stcb;
376 /* FIX, for non-bsd is this right? */
377 vrf_id = SCTP_DEFAULT_VRFID;
379 error = priv_check(req->td, PRIV_NETINET_GETCRED);
384 error = SYSCTL_IN(req, addrs, sizeof(addrs));
388 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
390 &inp, &net, 1, vrf_id);
391 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
392 if ((inp != NULL) && (stcb == NULL)) {
393 /* reduce ref-count */
395 SCTP_INP_DECR_REF(inp);
399 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
403 SCTP_TCB_UNLOCK(stcb);
405 * We use the write lock here, only since in the error leg we need
406 * it. If we used RLOCK, then we would have to
407 * wlock/decr/unlock/rlock. Which in theory could create a hole.
408 * Better to use higher wlock.
412 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
414 SCTP_INP_WUNLOCK(inp);
417 cru2x(inp->sctp_socket->so_cred, &xuc);
418 SCTP_INP_WUNLOCK(inp);
419 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
424 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred,
425 CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
426 0, 0, sctp_getcred, "S,ucred",
427 "Get the ucred of a SCTP connection");
431 sctp_abort(struct socket *so)
433 struct epoch_tracker et;
434 struct sctp_inpcb *inp;
436 inp = (struct sctp_inpcb *)so->so_pcb;
443 #ifdef SCTP_LOG_CLOSING
444 sctp_log_closing(inp, NULL, 17);
446 if (((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0)) {
447 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP;
448 #ifdef SCTP_LOG_CLOSING
449 sctp_log_closing(inp, NULL, 16);
451 SCTP_INP_WUNLOCK(inp);
452 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
453 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
455 SCTP_SB_CLEAR(so->so_snd);
457 * same for the rcv ones, they are only here for the
460 SCTP_SB_CLEAR(so->so_rcv);
462 /* Now null out the reference, we are completely detached. */
466 SCTP_INP_WUNLOCK(inp);
472 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
474 struct sctp_inpcb *inp;
475 struct inpcb *ip_inp;
477 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
479 inp = (struct sctp_inpcb *)so->so_pcb;
481 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
484 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
485 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
490 error = sctp_inpcb_alloc(so, vrf_id);
494 inp = (struct sctp_inpcb *)so->so_pcb;
496 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
497 ip_inp = &inp->ip_inp.inp;
498 ip_inp->inp_vflag |= INP_IPV4;
499 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
500 SCTP_INP_WUNLOCK(inp);
505 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
507 struct sctp_inpcb *inp;
509 inp = (struct sctp_inpcb *)so->so_pcb;
511 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
515 if ((addr->sa_family != AF_INET) ||
516 (addr->sa_len != sizeof(struct sockaddr_in))) {
517 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
521 return (sctp_inpcb_bind(so, addr, NULL, p));
526 sctp_close(struct socket *so)
528 struct epoch_tracker et;
529 struct sctp_inpcb *inp;
531 inp = (struct sctp_inpcb *)so->so_pcb;
536 * Inform all the lower layer assoc that we are done.
540 #ifdef SCTP_LOG_CLOSING
541 sctp_log_closing(inp, NULL, 17);
543 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
544 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP;
545 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
546 (so->so_rcv.sb_cc > 0)) {
547 #ifdef SCTP_LOG_CLOSING
548 sctp_log_closing(inp, NULL, 13);
550 SCTP_INP_WUNLOCK(inp);
551 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
552 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
554 #ifdef SCTP_LOG_CLOSING
555 sctp_log_closing(inp, NULL, 14);
557 SCTP_INP_WUNLOCK(inp);
558 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
559 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
562 * The socket is now detached, no matter what the state of
563 * the SCTP association.
566 SCTP_SB_CLEAR(so->so_snd);
568 * same for the rcv ones, they are only here for the
571 SCTP_SB_CLEAR(so->so_rcv);
573 /* Now null out the reference, we are completely detached. */
577 SCTP_INP_WUNLOCK(inp);
583 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
584 struct mbuf *control, struct thread *p);
587 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
588 struct mbuf *control, struct thread *p)
590 struct sctp_inpcb *inp;
593 inp = (struct sctp_inpcb *)so->so_pcb;
596 sctp_m_freem(control);
599 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
603 /* Got to have an to address if we are NOT a connected socket */
604 if ((addr == NULL) &&
605 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
606 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
612 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
613 error = EDESTADDRREQ;
614 } else if (addr->sa_family != AF_INET) {
615 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
616 error = EAFNOSUPPORT;
617 } else if (addr->sa_len != sizeof(struct sockaddr_in)) {
618 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
624 sctp_m_freem(control);
630 /* now what about control */
633 sctp_m_freem(inp->control);
636 inp->control = control;
640 SCTP_BUF_NEXT(inp->pkt_last) = m;
643 inp->pkt_last = inp->pkt = m;
646 /* FreeBSD uses a flag passed */
647 ((flags & PRUS_MORETOCOME) == 0)
650 * note with the current version this code will only be used
651 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
652 * re-defining sosend to use the sctp_sosend. One can
653 * optionally switch back to this code (by changing back the
654 * definitions) but this is not advisable. This code is used
655 * by FreeBSD when sending a file with sendfile() though.
657 struct epoch_tracker et;
661 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
672 sctp_disconnect(struct socket *so)
674 struct sctp_inpcb *inp;
676 inp = (struct sctp_inpcb *)so->so_pcb;
678 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
682 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
683 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
684 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
686 SCTP_INP_RUNLOCK(inp);
689 struct epoch_tracker et;
690 struct sctp_association *asoc;
691 struct sctp_tcb *stcb;
693 stcb = LIST_FIRST(&inp->sctp_asoc_list);
695 SCTP_INP_RUNLOCK(inp);
696 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
701 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
702 /* We are about to be freed, out of here */
703 SCTP_TCB_UNLOCK(stcb);
704 SCTP_INP_RUNLOCK(inp);
708 if (((so->so_options & SO_LINGER) &&
709 (so->so_linger == 0)) ||
710 (so->so_rcv.sb_cc > 0)) {
711 if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) {
712 /* Left with Data unread */
715 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
716 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
717 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
719 SCTP_INP_RUNLOCK(inp);
720 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
721 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
722 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
724 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
725 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
726 /* No unlock tcb assoc is gone */
730 if (TAILQ_EMPTY(&asoc->send_queue) &&
731 TAILQ_EMPTY(&asoc->sent_queue) &&
732 (asoc->stream_queue_cnt == 0)) {
733 /* there is nothing queued to send, so done */
734 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
737 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) &&
738 (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
739 /* only send SHUTDOWN 1st time thru */
740 struct sctp_nets *netp;
742 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
743 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
744 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
746 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
747 sctp_stop_timers_for_shutdown(stcb);
748 if (stcb->asoc.alternate) {
749 netp = stcb->asoc.alternate;
751 netp = stcb->asoc.primary_destination;
753 sctp_send_shutdown(stcb, netp);
754 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
755 stcb->sctp_ep, stcb, netp);
756 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
757 stcb->sctp_ep, stcb, NULL);
758 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
762 * we still got (or just got) data to send,
763 * so set SHUTDOWN_PENDING
766 * XXX sockets draft says that SCTP_EOF
767 * should be sent with no data. currently,
768 * we will allow user data to be sent first
769 * and move to SHUTDOWN-PENDING
771 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
772 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
773 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
774 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
776 if (TAILQ_EMPTY(&asoc->send_queue) &&
777 TAILQ_EMPTY(&asoc->sent_queue) &&
778 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
782 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
783 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
784 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
785 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
786 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
787 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
788 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
790 SCTP_INP_RUNLOCK(inp);
791 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
792 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
796 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
799 soisdisconnecting(so);
801 SCTP_TCB_UNLOCK(stcb);
802 SCTP_INP_RUNLOCK(inp);
807 /* UDP model does not support this */
808 SCTP_INP_RUNLOCK(inp);
809 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
815 sctp_flush(struct socket *so, int how)
818 * We will just clear out the values and let subsequent close clear
819 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
820 * they will not be able to read the data, the socket will block
821 * that from happening.
823 struct sctp_inpcb *inp;
825 inp = (struct sctp_inpcb *)so->so_pcb;
827 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
831 /* For the 1 to many model this does nothing */
832 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
833 SCTP_INP_RUNLOCK(inp);
836 SCTP_INP_RUNLOCK(inp);
837 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
839 * First make sure the sb will be happy, we don't use these
840 * except maybe the count
843 SCTP_INP_READ_LOCK(inp);
844 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
845 SCTP_INP_READ_UNLOCK(inp);
846 SCTP_INP_WUNLOCK(inp);
847 so->so_rcv.sb_cc = 0;
848 so->so_rcv.sb_mbcnt = 0;
849 so->so_rcv.sb_mb = NULL;
851 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
853 * First make sure the sb will be happy, we don't use these
854 * except maybe the count
856 so->so_snd.sb_cc = 0;
857 so->so_snd.sb_mbcnt = 0;
858 so->so_snd.sb_mb = NULL;
864 sctp_shutdown(struct socket *so)
866 struct sctp_inpcb *inp;
868 inp = (struct sctp_inpcb *)so->so_pcb;
870 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
874 /* For UDP model this is a invalid call */
875 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
876 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
877 /* Restore the flags that the soshutdown took away. */
878 SOCKBUF_LOCK(&so->so_rcv);
879 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
880 SOCKBUF_UNLOCK(&so->so_rcv);
881 /* This proc will wakeup for read and do nothing (I hope) */
882 SCTP_INP_RUNLOCK(inp);
883 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
887 * Ok, if we reach here its the TCP model and it is either a
888 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
891 struct epoch_tracker et;
892 struct sctp_tcb *stcb;
893 struct sctp_association *asoc;
894 struct sctp_nets *netp;
897 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
898 SCTP_INP_RUNLOCK(inp);
903 stcb = LIST_FIRST(&inp->sctp_asoc_list);
906 * Ok, we hit the case that the shutdown call was
907 * made after an abort or something. Nothing to do
910 SCTP_INP_RUNLOCK(inp);
915 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
916 SCTP_TCB_UNLOCK(stcb);
917 SCTP_INP_RUNLOCK(inp);
920 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) &&
921 (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) &&
922 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) {
924 * If we are not in or before ESTABLISHED, there is
925 * no protocol action required.
927 SCTP_TCB_UNLOCK(stcb);
928 SCTP_INP_RUNLOCK(inp);
932 if (stcb->asoc.alternate) {
933 netp = stcb->asoc.alternate;
935 netp = stcb->asoc.primary_destination;
937 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) &&
938 TAILQ_EMPTY(&asoc->send_queue) &&
939 TAILQ_EMPTY(&asoc->sent_queue) &&
940 (asoc->stream_queue_cnt == 0)) {
941 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
944 /* there is nothing queued to send, so I'm done... */
945 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
946 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
947 sctp_stop_timers_for_shutdown(stcb);
948 sctp_send_shutdown(stcb, netp);
949 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
950 stcb->sctp_ep, stcb, netp);
953 * We still got (or just got) data to send, so set
956 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
957 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
958 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
960 if (TAILQ_EMPTY(&asoc->send_queue) &&
961 TAILQ_EMPTY(&asoc->sent_queue) &&
962 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
966 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
967 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
968 SCTP_INP_RUNLOCK(inp);
969 sctp_abort_an_association(stcb->sctp_ep, stcb,
970 op_err, false, SCTP_SO_LOCKED);
975 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
977 * XXX: Why do this in the case where we have still data
980 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
981 SCTP_TCB_UNLOCK(stcb);
982 SCTP_INP_RUNLOCK(inp);
989 * copies a "user" presentable address and removes embedded scope, etc.
990 * returns 0 on success, 1 on error
993 sctp_fill_user_address(struct sockaddr *dst, struct sockaddr *src)
996 struct sockaddr_in6 lsa6;
998 src = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)src,
1001 memcpy(dst, src, src->sa_len);
1006 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1007 struct sctp_tcb *stcb,
1009 struct sockaddr *addr,
1012 struct sctp_ifn *sctp_ifn;
1013 struct sctp_ifa *sctp_ifa;
1017 int ipv4_local_scope, ipv4_addr_legal;
1020 int local_scope, site_scope, ipv6_addr_legal;
1022 struct sctp_vrf *vrf;
1024 SCTP_IPI_ADDR_LOCK_ASSERT();
1030 /* Turn on all the appropriate scope */
1031 loopback_scope = stcb->asoc.scope.loopback_scope;
1033 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1034 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1037 local_scope = stcb->asoc.scope.local_scope;
1038 site_scope = stcb->asoc.scope.site_scope;
1039 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1042 /* Use generic values for endpoints. */
1045 ipv4_local_scope = 1;
1051 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1053 ipv6_addr_legal = 1;
1056 if (SCTP_IPV6_V6ONLY(inp)) {
1057 ipv4_addr_legal = 0;
1059 ipv4_addr_legal = 1;
1064 ipv6_addr_legal = 0;
1067 ipv4_addr_legal = 1;
1071 vrf = sctp_find_vrf(vrf_id);
1075 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1076 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1077 if ((loopback_scope == 0) &&
1078 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1079 /* Skip loopback if loopback_scope not set */
1082 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1085 * For the BOUND-ALL case, the list
1086 * associated with a TCB is Always
1087 * considered a reverse list.. i.e.
1088 * it lists addresses that are NOT
1089 * part of the association. If this
1090 * is one of those we must skip it.
1092 if (sctp_is_addr_restricted(stcb,
1097 switch (sctp_ifa->address.sa.sa_family) {
1100 if (ipv4_addr_legal) {
1101 struct sockaddr_in *sin;
1103 sin = &sctp_ifa->address.sin;
1104 if (sin->sin_addr.s_addr == 0) {
1112 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1113 &sin->sin_addr) != 0) {
1116 if ((ipv4_local_scope == 0) &&
1117 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1121 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1122 if (actual + sizeof(struct sockaddr_in6) > limit) {
1125 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)addr);
1126 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1127 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1128 actual += sizeof(struct sockaddr_in6);
1131 if (actual + sizeof(struct sockaddr_in) > limit) {
1134 memcpy(addr, sin, sizeof(struct sockaddr_in));
1135 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1136 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in));
1137 actual += sizeof(struct sockaddr_in);
1148 if (ipv6_addr_legal) {
1149 struct sockaddr_in6 *sin6;
1151 sin6 = &sctp_ifa->address.sin6;
1152 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1160 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1161 &sin6->sin6_addr) != 0) {
1164 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1165 if (local_scope == 0)
1167 if (sin6->sin6_scope_id == 0) {
1168 if (sa6_recoverscope(sin6) != 0)
1181 if ((site_scope == 0) &&
1182 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1185 if (actual + sizeof(struct sockaddr_in6) > limit) {
1188 memcpy(addr, sin6, sizeof(struct sockaddr_in6));
1189 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1190 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1191 actual += sizeof(struct sockaddr_in6);
1204 struct sctp_laddr *laddr;
1207 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1209 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1213 sa_len = laddr->ifa->address.sa.sa_len;
1214 if (actual + sa_len > limit) {
1217 if (sctp_fill_user_address(addr, &laddr->ifa->address.sa))
1219 switch (laddr->ifa->address.sa.sa_family) {
1222 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1227 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1234 addr = (struct sockaddr *)((caddr_t)addr + sa_len);
1242 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1243 struct sctp_tcb *stcb,
1245 struct sockaddr *addr)
1249 SCTP_IPI_ADDR_RLOCK();
1250 /* fill up addresses for the endpoint's default vrf */
1251 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, addr,
1253 SCTP_IPI_ADDR_RUNLOCK();
1258 sctp_max_size_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1260 struct sctp_vrf *vrf;
1264 * In both sub-set bound an bound_all cases we return the size of
1265 * the maximum number of addresses that you could get. In reality
1266 * the sub-set bound may have an exclusion list for a given TCB or
1267 * in the bound-all case a TCB may NOT include the loopback or other
1268 * addresses as well.
1270 SCTP_IPI_ADDR_LOCK_ASSERT();
1271 vrf = sctp_find_vrf(vrf_id);
1276 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1277 struct sctp_ifn *sctp_ifn;
1278 struct sctp_ifa *sctp_ifa;
1280 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1281 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1282 /* Count them if they are the right type */
1283 switch (sctp_ifa->address.sa.sa_family) {
1287 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1288 size += sizeof(struct sockaddr_in6);
1290 size += sizeof(struct sockaddr_in);
1292 size += sizeof(struct sockaddr_in);
1298 size += sizeof(struct sockaddr_in6);
1307 struct sctp_laddr *laddr;
1309 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1310 switch (laddr->ifa->address.sa.sa_family) {
1314 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1315 size += sizeof(struct sockaddr_in6);
1317 size += sizeof(struct sockaddr_in);
1319 size += sizeof(struct sockaddr_in);
1325 size += sizeof(struct sockaddr_in6);
1337 sctp_max_size_addresses(struct sctp_inpcb *inp)
1341 SCTP_IPI_ADDR_RLOCK();
1342 /* Maximum size of all addresses for the endpoint's default VRF */
1343 size = sctp_max_size_addresses_vrf(inp, inp->def_vrf_id);
1344 SCTP_IPI_ADDR_RUNLOCK();
1349 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1350 size_t optsize, void *p, int delay)
1353 int creat_lock_on = 0;
1354 struct sctp_tcb *stcb = NULL;
1355 struct sockaddr *sa;
1356 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1360 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1362 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1363 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1364 /* We are already connected AND the TCP model */
1365 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1366 return (EADDRINUSE);
1369 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1370 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1371 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1375 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1376 SCTP_INP_RLOCK(inp);
1377 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1378 SCTP_INP_RUNLOCK(inp);
1381 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1384 SCTP_INP_INCR_REF(inp);
1385 SCTP_ASOC_CREATE_LOCK(inp);
1387 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1388 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1389 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1393 totaddrp = (unsigned int *)optval;
1394 totaddr = *totaddrp;
1395 sa = (struct sockaddr *)(totaddrp + 1);
1396 error = sctp_connectx_helper_find(inp, sa, totaddr, &num_v4, &num_v6, (unsigned int)(optsize - sizeof(int)));
1398 /* Already have or am bring up an association */
1399 SCTP_ASOC_CREATE_UNLOCK(inp);
1401 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1405 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1410 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1412 if (SCTP_IPV6_V6ONLY(inp)) {
1414 * if IPV6_V6ONLY flag, ignore connections destined
1415 * to a v4 addr or v4-mapped addr
1417 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1423 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1424 SCTP_PCB_FLAGS_UNBOUND) {
1425 /* Bind a ephemeral port */
1426 error = sctp_inpcb_bind(so, NULL, NULL, p);
1432 /* FIX ME: do we want to pass in a vrf on the connect call? */
1433 vrf_id = inp->def_vrf_id;
1435 /* We are GOOD to go */
1436 stcb = sctp_aloc_assoc_connected(inp, sa, &error, 0, 0, vrf_id,
1437 inp->sctp_ep.pre_open_stream_count,
1440 SCTP_INITIALIZE_AUTH_PARAMS);
1442 /* Gak! no memory */
1445 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1446 /* move to second address */
1447 switch (sa->sa_family) {
1450 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1455 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1463 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1464 /* Fill in the return id */
1468 a_id = (sctp_assoc_t *)optval;
1469 *a_id = sctp_get_associd(stcb);
1472 /* doing delayed connection */
1473 stcb->asoc.delayed_connection = 1;
1474 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1476 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1477 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1479 SCTP_TCB_UNLOCK(stcb);
1481 if (creat_lock_on) {
1482 SCTP_ASOC_CREATE_UNLOCK(inp);
1484 SCTP_INP_DECR_REF(inp);
1488 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1489 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1490 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1491 SCTP_INP_RLOCK(inp); \
1492 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1494 SCTP_TCB_LOCK(stcb); \
1496 SCTP_INP_RUNLOCK(inp); \
1497 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1498 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1499 if (stcb == NULL) { \
1500 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1509 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1510 if (size < sizeof(type)) { \
1511 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1515 destp = (type *)srcp; \
1520 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1523 struct sctp_inpcb *inp = NULL;
1525 struct sctp_tcb *stcb = NULL;
1527 if (optval == NULL) {
1528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1532 inp = (struct sctp_inpcb *)so->so_pcb;
1534 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1541 case SCTP_AUTOCLOSE:
1542 case SCTP_EXPLICIT_EOR:
1543 case SCTP_AUTO_ASCONF:
1544 case SCTP_DISABLE_FRAGMENTS:
1545 case SCTP_I_WANT_MAPPED_V4_ADDR:
1546 case SCTP_USE_EXT_RCVINFO:
1547 SCTP_INP_RLOCK(inp);
1549 case SCTP_DISABLE_FRAGMENTS:
1550 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1552 case SCTP_I_WANT_MAPPED_V4_ADDR:
1553 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1555 case SCTP_AUTO_ASCONF:
1556 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1557 /* only valid for bound all sockets */
1558 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1560 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1565 case SCTP_EXPLICIT_EOR:
1566 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1569 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1571 case SCTP_USE_EXT_RCVINFO:
1572 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1574 case SCTP_AUTOCLOSE:
1575 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1576 val = sctp_ticks_to_secs(inp->sctp_ep.auto_close_time);
1582 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1583 error = ENOPROTOOPT;
1584 } /* end switch (sopt->sopt_name) */
1585 if (*optsize < sizeof(val)) {
1586 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1590 SCTP_INP_RUNLOCK(inp);
1592 /* return the option value */
1593 *(int *)optval = val;
1594 *optsize = sizeof(val);
1597 case SCTP_GET_PACKET_LOG:
1599 #ifdef SCTP_PACKET_LOGGING
1603 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1604 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1607 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1612 case SCTP_REUSE_PORT:
1616 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1617 /* Can't do this for a 1-m socket */
1621 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1622 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1623 *optsize = sizeof(uint32_t);
1626 case SCTP_PARTIAL_DELIVERY_POINT:
1630 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1631 *value = inp->partial_delivery_point;
1632 *optsize = sizeof(uint32_t);
1635 case SCTP_FRAGMENT_INTERLEAVE:
1639 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1640 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1641 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1642 *value = SCTP_FRAG_LEVEL_2;
1644 *value = SCTP_FRAG_LEVEL_1;
1647 *value = SCTP_FRAG_LEVEL_0;
1649 *optsize = sizeof(uint32_t);
1652 case SCTP_INTERLEAVING_SUPPORTED:
1654 struct sctp_assoc_value *av;
1656 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1657 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1660 av->assoc_value = stcb->asoc.idata_supported;
1661 SCTP_TCB_UNLOCK(stcb);
1663 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1664 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1665 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1666 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1667 SCTP_INP_RLOCK(inp);
1668 if (inp->idata_supported) {
1669 av->assoc_value = 1;
1671 av->assoc_value = 0;
1673 SCTP_INP_RUNLOCK(inp);
1675 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1680 *optsize = sizeof(struct sctp_assoc_value);
1684 case SCTP_CMT_ON_OFF:
1686 struct sctp_assoc_value *av;
1688 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1689 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1691 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1692 SCTP_TCB_UNLOCK(stcb);
1694 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1695 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1696 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1697 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1698 SCTP_INP_RLOCK(inp);
1699 av->assoc_value = inp->sctp_cmt_on_off;
1700 SCTP_INP_RUNLOCK(inp);
1702 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1707 *optsize = sizeof(struct sctp_assoc_value);
1711 case SCTP_PLUGGABLE_CC:
1713 struct sctp_assoc_value *av;
1715 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1716 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1718 av->assoc_value = stcb->asoc.congestion_control_module;
1719 SCTP_TCB_UNLOCK(stcb);
1721 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1722 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1723 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1724 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1725 SCTP_INP_RLOCK(inp);
1726 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1727 SCTP_INP_RUNLOCK(inp);
1729 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1734 *optsize = sizeof(struct sctp_assoc_value);
1738 case SCTP_CC_OPTION:
1740 struct sctp_cc_option *cc_opt;
1742 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1743 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1747 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1750 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1751 *optsize = sizeof(struct sctp_cc_option);
1753 SCTP_TCB_UNLOCK(stcb);
1757 case SCTP_PLUGGABLE_SS:
1759 struct sctp_assoc_value *av;
1761 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1762 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1764 av->assoc_value = stcb->asoc.stream_scheduling_module;
1765 SCTP_TCB_UNLOCK(stcb);
1767 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1768 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1769 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1770 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1771 SCTP_INP_RLOCK(inp);
1772 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1773 SCTP_INP_RUNLOCK(inp);
1775 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1780 *optsize = sizeof(struct sctp_assoc_value);
1786 struct sctp_stream_value *av;
1788 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1789 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1791 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1792 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1793 &av->stream_value) < 0)) {
1794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1797 *optsize = sizeof(struct sctp_stream_value);
1799 SCTP_TCB_UNLOCK(stcb);
1802 * Can't get stream value without
1805 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1810 case SCTP_GET_ADDR_LEN:
1812 struct sctp_assoc_value *av;
1814 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1817 if (av->assoc_value == AF_INET) {
1818 av->assoc_value = sizeof(struct sockaddr_in);
1823 if (av->assoc_value == AF_INET6) {
1824 av->assoc_value = sizeof(struct sockaddr_in6);
1829 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1831 *optsize = sizeof(struct sctp_assoc_value);
1835 case SCTP_GET_ASSOC_NUMBER:
1837 uint32_t *value, cnt;
1839 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1840 SCTP_INP_RLOCK(inp);
1841 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1842 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1843 /* Can't do this for a 1-1 socket */
1845 SCTP_INP_RUNLOCK(inp);
1849 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1852 SCTP_INP_RUNLOCK(inp);
1854 *optsize = sizeof(uint32_t);
1857 case SCTP_GET_ASSOC_ID_LIST:
1859 struct sctp_assoc_ids *ids;
1863 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1864 SCTP_INP_RLOCK(inp);
1865 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1866 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1867 /* Can't do this for a 1-1 socket */
1869 SCTP_INP_RUNLOCK(inp);
1873 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1874 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1876 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1879 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1884 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1888 SCTP_INP_RUNLOCK(inp);
1890 ids->gaids_number_of_ids = at;
1891 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1897 struct sctp_assoc_value *av;
1899 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1900 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1903 av->assoc_value = stcb->asoc.context;
1904 SCTP_TCB_UNLOCK(stcb);
1906 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1907 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1908 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1909 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1910 SCTP_INP_RLOCK(inp);
1911 av->assoc_value = inp->sctp_context;
1912 SCTP_INP_RUNLOCK(inp);
1914 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1919 *optsize = sizeof(struct sctp_assoc_value);
1925 uint32_t *default_vrfid;
1927 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1928 *default_vrfid = inp->def_vrf_id;
1929 *optsize = sizeof(uint32_t);
1932 case SCTP_GET_ASOC_VRF:
1934 struct sctp_assoc_value *id;
1936 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1937 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1940 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1942 id->assoc_value = stcb->asoc.vrf_id;
1943 SCTP_TCB_UNLOCK(stcb);
1944 *optsize = sizeof(struct sctp_assoc_value);
1948 case SCTP_GET_VRF_IDS:
1950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1954 case SCTP_GET_NONCE_VALUES:
1956 struct sctp_get_nonce_values *gnv;
1958 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1959 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1962 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1963 gnv->gn_local_tag = stcb->asoc.my_vtag;
1964 SCTP_TCB_UNLOCK(stcb);
1965 *optsize = sizeof(struct sctp_get_nonce_values);
1967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1972 case SCTP_DELAYED_SACK:
1974 struct sctp_sack_info *sack;
1976 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1977 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1979 sack->sack_delay = stcb->asoc.delayed_ack;
1980 sack->sack_freq = stcb->asoc.sack_freq;
1981 SCTP_TCB_UNLOCK(stcb);
1983 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1984 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1985 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1986 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC))) {
1987 SCTP_INP_RLOCK(inp);
1988 sack->sack_delay = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1989 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
1990 SCTP_INP_RUNLOCK(inp);
1992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1997 *optsize = sizeof(struct sctp_sack_info);
2001 case SCTP_GET_SNDBUF_USE:
2003 struct sctp_sockstat *ss;
2005 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2006 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2009 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2010 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2011 stcb->asoc.size_on_all_streams);
2012 SCTP_TCB_UNLOCK(stcb);
2013 *optsize = sizeof(struct sctp_sockstat);
2015 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2020 case SCTP_MAX_BURST:
2022 struct sctp_assoc_value *av;
2024 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2025 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2028 av->assoc_value = stcb->asoc.max_burst;
2029 SCTP_TCB_UNLOCK(stcb);
2031 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2032 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2033 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2034 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2035 SCTP_INP_RLOCK(inp);
2036 av->assoc_value = inp->sctp_ep.max_burst;
2037 SCTP_INP_RUNLOCK(inp);
2039 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2044 *optsize = sizeof(struct sctp_assoc_value);
2050 struct sctp_assoc_value *av;
2052 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2053 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2056 av->assoc_value = stcb->asoc.sctp_frag_point;
2057 SCTP_TCB_UNLOCK(stcb);
2059 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2060 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2061 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2062 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2063 SCTP_INP_RLOCK(inp);
2064 av->assoc_value = inp->sctp_frag_point;
2065 SCTP_INP_RUNLOCK(inp);
2067 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2072 *optsize = sizeof(struct sctp_assoc_value);
2076 case SCTP_GET_STAT_LOG:
2077 error = sctp_fill_stat_log(optval, optsize);
2081 struct sctp_event_subscribe *events;
2083 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2084 memset(events, 0, sizeof(struct sctp_event_subscribe));
2085 SCTP_INP_RLOCK(inp);
2086 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2087 events->sctp_data_io_event = 1;
2089 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2090 events->sctp_association_event = 1;
2092 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2093 events->sctp_address_event = 1;
2095 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2096 events->sctp_send_failure_event = 1;
2098 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2099 events->sctp_peer_error_event = 1;
2101 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2102 events->sctp_shutdown_event = 1;
2104 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2105 events->sctp_partial_delivery_event = 1;
2107 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2108 events->sctp_adaptation_layer_event = 1;
2110 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2111 events->sctp_authentication_event = 1;
2113 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2114 events->sctp_sender_dry_event = 1;
2116 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2117 events->sctp_stream_reset_event = 1;
2118 SCTP_INP_RUNLOCK(inp);
2119 *optsize = sizeof(struct sctp_event_subscribe);
2122 case SCTP_ADAPTATION_LAYER:
2126 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2128 SCTP_INP_RLOCK(inp);
2129 *value = inp->sctp_ep.adaptation_layer_indicator;
2130 SCTP_INP_RUNLOCK(inp);
2131 *optsize = sizeof(uint32_t);
2134 case SCTP_SET_INITIAL_DBG_SEQ:
2138 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2139 SCTP_INP_RLOCK(inp);
2140 *value = inp->sctp_ep.initial_sequence_debug;
2141 SCTP_INP_RUNLOCK(inp);
2142 *optsize = sizeof(uint32_t);
2145 case SCTP_GET_LOCAL_ADDR_SIZE:
2149 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2150 SCTP_INP_RLOCK(inp);
2151 *value = (uint32_t)sctp_max_size_addresses(inp);
2152 SCTP_INP_RUNLOCK(inp);
2153 *optsize = sizeof(uint32_t);
2156 case SCTP_GET_REMOTE_ADDR_SIZE:
2159 struct sctp_nets *net;
2162 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2163 /* FIXME MT: change to sctp_assoc_value? */
2164 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2168 /* Count the sizes */
2169 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2170 switch (net->ro._l_addr.sa.sa_family) {
2174 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2175 size += sizeof(struct sockaddr_in6);
2177 size += sizeof(struct sockaddr_in);
2180 size += sizeof(struct sockaddr_in);
2186 size += sizeof(struct sockaddr_in6);
2193 SCTP_TCB_UNLOCK(stcb);
2194 *value = (uint32_t)size;
2195 *optsize = sizeof(uint32_t);
2197 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2198 ((sctp_assoc_t)*value <= SCTP_ALL_ASSOC)) {
2203 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2207 case SCTP_GET_PEER_ADDRESSES:
2209 * Get the address information, an array is passed in to
2210 * fill up we pack it.
2214 struct sockaddr *addr;
2215 struct sctp_nets *net;
2216 struct sctp_getaddresses *saddr;
2218 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2219 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2222 left = *optsize - offsetof(struct sctp_getaddresses, addr);
2223 *optsize = offsetof(struct sctp_getaddresses, addr);
2224 addr = &saddr->addr[0].sa;
2226 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2227 switch (net->ro._l_addr.sa.sa_family) {
2231 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2232 cpsz = sizeof(struct sockaddr_in6);
2234 cpsz = sizeof(struct sockaddr_in);
2237 cpsz = sizeof(struct sockaddr_in);
2243 cpsz = sizeof(struct sockaddr_in6);
2254 /* not enough room. */
2257 #if defined(INET) && defined(INET6)
2258 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2259 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2260 /* Must map the address */
2261 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2262 (struct sockaddr_in6 *)addr);
2264 memcpy(addr, &net->ro._l_addr, cpsz);
2267 memcpy(addr, &net->ro._l_addr, cpsz);
2269 ((struct sockaddr_in *)addr)->sin_port = stcb->rport;
2271 addr = (struct sockaddr *)((caddr_t)addr + cpsz);
2275 SCTP_TCB_UNLOCK(stcb);
2277 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2278 (saddr->sget_assoc_id <= SCTP_ALL_ASSOC)) {
2283 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2287 case SCTP_GET_LOCAL_ADDRESSES:
2289 size_t limit, actual;
2290 struct sctp_getaddresses *saddr;
2292 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2293 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2295 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2296 ((saddr->sget_assoc_id == SCTP_CURRENT_ASSOC) ||
2297 (saddr->sget_assoc_id == SCTP_ALL_ASSOC))) {
2300 limit = *optsize - offsetof(struct sctp_getaddresses, addr);
2301 actual = sctp_fill_up_addresses(inp, stcb, limit, &saddr->addr[0].sa);
2302 *optsize = offsetof(struct sctp_getaddresses, addr) + actual;
2305 SCTP_TCB_UNLOCK(stcb);
2309 case SCTP_PEER_ADDR_PARAMS:
2311 struct sctp_paddrparams *paddrp;
2312 struct sctp_nets *net;
2313 struct sockaddr *addr;
2314 #if defined(INET) && defined(INET6)
2315 struct sockaddr_in sin_store;
2318 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2319 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2321 #if defined(INET) && defined(INET6)
2322 if (paddrp->spp_address.ss_family == AF_INET6) {
2323 struct sockaddr_in6 *sin6;
2325 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2326 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2327 in6_sin6_2_sin(&sin_store, sin6);
2328 addr = (struct sockaddr *)&sin_store;
2330 addr = (struct sockaddr *)&paddrp->spp_address;
2333 addr = (struct sockaddr *)&paddrp->spp_address;
2336 addr = (struct sockaddr *)&paddrp->spp_address;
2339 net = sctp_findnet(stcb, addr);
2342 * We increment here since
2343 * sctp_findassociation_ep_addr() wil do a
2344 * decrement if it finds the stcb as long as
2345 * the locked tcb (last argument) is NOT a
2349 SCTP_INP_INCR_REF(inp);
2350 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2352 SCTP_INP_DECR_REF(inp);
2355 if ((stcb != NULL) && (net == NULL)) {
2357 if (addr->sa_family == AF_INET) {
2358 struct sockaddr_in *sin;
2360 sin = (struct sockaddr_in *)addr;
2361 if (sin->sin_addr.s_addr != INADDR_ANY) {
2363 SCTP_TCB_UNLOCK(stcb);
2364 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2370 if (addr->sa_family == AF_INET6) {
2371 struct sockaddr_in6 *sin6;
2373 sin6 = (struct sockaddr_in6 *)addr;
2374 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2376 SCTP_TCB_UNLOCK(stcb);
2377 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2383 error = EAFNOSUPPORT;
2384 SCTP_TCB_UNLOCK(stcb);
2385 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2391 /* Applies to the specific association */
2392 paddrp->spp_flags = 0;
2394 paddrp->spp_hbinterval = net->heart_beat_delay;
2395 paddrp->spp_pathmaxrxt = net->failure_threshold;
2396 paddrp->spp_pathmtu = net->mtu;
2397 switch (net->ro._l_addr.sa.sa_family) {
2400 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2405 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2411 /* get flags for HB */
2412 if (net->dest_state & SCTP_ADDR_NOHB) {
2413 paddrp->spp_flags |= SPP_HB_DISABLE;
2415 paddrp->spp_flags |= SPP_HB_ENABLE;
2417 /* get flags for PMTU */
2418 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2419 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2421 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2423 if (net->dscp & 0x01) {
2424 paddrp->spp_dscp = net->dscp & 0xfc;
2425 paddrp->spp_flags |= SPP_DSCP;
2428 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2429 (net->flowlabel & 0x80000000)) {
2430 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2431 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2436 * No destination so return default
2439 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2440 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2441 if (stcb->asoc.default_dscp & 0x01) {
2442 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2443 paddrp->spp_flags |= SPP_DSCP;
2446 if (stcb->asoc.default_flowlabel & 0x80000000) {
2447 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2448 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2451 /* default settings should be these */
2452 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2453 paddrp->spp_flags |= SPP_HB_DISABLE;
2455 paddrp->spp_flags |= SPP_HB_ENABLE;
2457 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2458 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2460 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2462 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2464 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2465 SCTP_TCB_UNLOCK(stcb);
2467 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2468 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2469 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2470 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
2471 /* Use endpoint defaults */
2472 SCTP_INP_RLOCK(inp);
2473 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2474 paddrp->spp_hbinterval = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2475 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2476 /* get inp's default */
2477 if (inp->sctp_ep.default_dscp & 0x01) {
2478 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2479 paddrp->spp_flags |= SPP_DSCP;
2482 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2483 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2484 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2485 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2488 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2490 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2491 paddrp->spp_flags |= SPP_HB_ENABLE;
2493 paddrp->spp_flags |= SPP_HB_DISABLE;
2495 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2496 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2498 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2500 SCTP_INP_RUNLOCK(inp);
2502 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2507 *optsize = sizeof(struct sctp_paddrparams);
2511 case SCTP_GET_PEER_ADDR_INFO:
2513 struct sctp_paddrinfo *paddri;
2514 struct sctp_nets *net;
2515 struct sockaddr *addr;
2516 #if defined(INET) && defined(INET6)
2517 struct sockaddr_in sin_store;
2520 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2521 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2523 #if defined(INET) && defined(INET6)
2524 if (paddri->spinfo_address.ss_family == AF_INET6) {
2525 struct sockaddr_in6 *sin6;
2527 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2528 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2529 in6_sin6_2_sin(&sin_store, sin6);
2530 addr = (struct sockaddr *)&sin_store;
2532 addr = (struct sockaddr *)&paddri->spinfo_address;
2535 addr = (struct sockaddr *)&paddri->spinfo_address;
2538 addr = (struct sockaddr *)&paddri->spinfo_address;
2541 net = sctp_findnet(stcb, addr);
2544 * We increment here since
2545 * sctp_findassociation_ep_addr() wil do a
2546 * decrement if it finds the stcb as long as
2547 * the locked tcb (last argument) is NOT a
2551 SCTP_INP_INCR_REF(inp);
2552 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2554 SCTP_INP_DECR_REF(inp);
2558 if ((stcb != NULL) && (net != NULL)) {
2559 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2560 /* It's unconfirmed */
2561 paddri->spinfo_state = SCTP_UNCONFIRMED;
2562 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2564 paddri->spinfo_state = SCTP_ACTIVE;
2567 paddri->spinfo_state = SCTP_INACTIVE;
2569 paddri->spinfo_cwnd = net->cwnd;
2570 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2571 paddri->spinfo_rto = net->RTO;
2572 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2573 paddri->spinfo_mtu = net->mtu;
2574 switch (addr->sa_family) {
2577 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2582 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2588 SCTP_TCB_UNLOCK(stcb);
2589 *optsize = sizeof(struct sctp_paddrinfo);
2592 SCTP_TCB_UNLOCK(stcb);
2594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2599 case SCTP_PCB_STATUS:
2601 struct sctp_pcbinfo *spcb;
2603 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2604 sctp_fill_pcbinfo(spcb);
2605 *optsize = sizeof(struct sctp_pcbinfo);
2610 struct sctp_nets *net;
2611 struct sctp_status *sstat;
2613 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2614 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2617 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2621 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2622 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2623 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2624 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2626 * We can't include chunks that have been passed to
2627 * the socket layer. Only things in queue.
2629 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2630 stcb->asoc.cnt_on_all_streams);
2631 sstat->sstat_instrms = stcb->asoc.streamincnt;
2632 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2633 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb);
2634 net = stcb->asoc.primary_destination;
2636 memcpy(&sstat->sstat_primary.spinfo_address,
2638 ((struct sockaddr *)(&net->ro._l_addr))->sa_len);
2639 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2641 * Again the user can get info from
2642 * sctp_constants.h for what the state of
2645 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2646 /* It's unconfirmed */
2647 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2648 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2650 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2653 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2655 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2656 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2657 sstat->sstat_primary.spinfo_rto = net->RTO;
2658 sstat->sstat_primary.spinfo_mtu = net->mtu;
2659 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2662 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2667 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2674 memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo));
2676 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2677 SCTP_TCB_UNLOCK(stcb);
2678 *optsize = sizeof(struct sctp_status);
2683 struct sctp_rtoinfo *srto;
2685 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2686 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2689 srto->srto_initial = stcb->asoc.initial_rto;
2690 srto->srto_max = stcb->asoc.maxrto;
2691 srto->srto_min = stcb->asoc.minrto;
2692 SCTP_TCB_UNLOCK(stcb);
2694 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2695 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2696 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2697 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
2698 SCTP_INP_RLOCK(inp);
2699 srto->srto_initial = inp->sctp_ep.initial_rto;
2700 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2701 srto->srto_min = inp->sctp_ep.sctp_minrto;
2702 SCTP_INP_RUNLOCK(inp);
2704 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2709 *optsize = sizeof(struct sctp_rtoinfo);
2715 struct sctp_timeouts *stimo;
2717 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2718 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2721 stimo->stimo_init = stcb->asoc.timoinit;
2722 stimo->stimo_data = stcb->asoc.timodata;
2723 stimo->stimo_sack = stcb->asoc.timosack;
2724 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2725 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2726 stimo->stimo_cookie = stcb->asoc.timocookie;
2727 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2728 SCTP_TCB_UNLOCK(stcb);
2729 *optsize = sizeof(struct sctp_timeouts);
2731 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2736 case SCTP_ASSOCINFO:
2738 struct sctp_assocparams *sasoc;
2740 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2741 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2744 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(stcb->asoc.cookie_life);
2745 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2746 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2747 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2748 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2749 SCTP_TCB_UNLOCK(stcb);
2751 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2752 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2753 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2754 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
2755 SCTP_INP_RLOCK(inp);
2756 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(inp->sctp_ep.def_cookie_life);
2757 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2758 sasoc->sasoc_number_peer_destinations = 0;
2759 sasoc->sasoc_peer_rwnd = 0;
2760 sasoc->sasoc_local_rwnd = (uint32_t)sbspace(&inp->sctp_socket->so_rcv);
2761 SCTP_INP_RUNLOCK(inp);
2763 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2768 *optsize = sizeof(struct sctp_assocparams);
2772 case SCTP_DEFAULT_SEND_PARAM:
2774 struct sctp_sndrcvinfo *s_info;
2776 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2777 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2780 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2781 SCTP_TCB_UNLOCK(stcb);
2783 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2784 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2785 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2786 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC))) {
2787 SCTP_INP_RLOCK(inp);
2788 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2789 SCTP_INP_RUNLOCK(inp);
2791 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2796 *optsize = sizeof(struct sctp_sndrcvinfo);
2802 struct sctp_initmsg *sinit;
2804 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2805 SCTP_INP_RLOCK(inp);
2806 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2807 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2808 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2809 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2810 SCTP_INP_RUNLOCK(inp);
2811 *optsize = sizeof(struct sctp_initmsg);
2814 case SCTP_PRIMARY_ADDR:
2815 /* we allow a "get" operation on this */
2817 struct sctp_setprim *ssp;
2819 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2820 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2823 union sctp_sockstore *addr;
2825 addr = &stcb->asoc.primary_destination->ro._l_addr;
2826 switch (addr->sa.sa_family) {
2830 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2831 in6_sin_2_v4mapsin6(&addr->sin,
2832 (struct sockaddr_in6 *)&ssp->ssp_addr);
2834 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2837 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2843 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2849 SCTP_TCB_UNLOCK(stcb);
2850 *optsize = sizeof(struct sctp_setprim);
2852 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2857 case SCTP_HMAC_IDENT:
2859 struct sctp_hmacalgo *shmac;
2860 sctp_hmaclist_t *hmaclist;
2864 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2866 SCTP_INP_RLOCK(inp);
2867 hmaclist = inp->sctp_ep.local_hmacs;
2868 if (hmaclist == NULL) {
2869 /* no HMACs to return */
2870 *optsize = sizeof(*shmac);
2871 SCTP_INP_RUNLOCK(inp);
2874 /* is there room for all of the hmac ids? */
2875 size = sizeof(*shmac) + (hmaclist->num_algo *
2876 sizeof(shmac->shmac_idents[0]));
2877 if (*optsize < size) {
2878 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2880 SCTP_INP_RUNLOCK(inp);
2883 /* copy in the list */
2884 shmac->shmac_number_of_idents = hmaclist->num_algo;
2885 for (i = 0; i < hmaclist->num_algo; i++) {
2886 shmac->shmac_idents[i] = hmaclist->hmac[i];
2888 SCTP_INP_RUNLOCK(inp);
2892 case SCTP_AUTH_ACTIVE_KEY:
2894 struct sctp_authkeyid *scact;
2896 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2897 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2900 /* get the active key on the assoc */
2901 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2902 SCTP_TCB_UNLOCK(stcb);
2904 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2905 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2906 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2907 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC))) {
2908 /* get the endpoint active key */
2909 SCTP_INP_RLOCK(inp);
2910 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2911 SCTP_INP_RUNLOCK(inp);
2913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2918 *optsize = sizeof(struct sctp_authkeyid);
2922 case SCTP_LOCAL_AUTH_CHUNKS:
2924 struct sctp_authchunks *sac;
2925 sctp_auth_chklist_t *chklist = NULL;
2928 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2929 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2932 /* get off the assoc */
2933 chklist = stcb->asoc.local_auth_chunks;
2934 /* is there enough space? */
2935 size = sctp_auth_get_chklist_size(chklist);
2936 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2940 /* copy in the chunks */
2941 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2942 sac->gauth_number_of_chunks = (uint32_t)size;
2943 *optsize = sizeof(struct sctp_authchunks) + size;
2945 SCTP_TCB_UNLOCK(stcb);
2947 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2948 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2949 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2950 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC))) {
2951 /* get off the endpoint */
2952 SCTP_INP_RLOCK(inp);
2953 chklist = inp->sctp_ep.local_auth_chunks;
2954 /* is there enough space? */
2955 size = sctp_auth_get_chklist_size(chklist);
2956 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2958 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2960 /* copy in the chunks */
2961 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2962 sac->gauth_number_of_chunks = (uint32_t)size;
2963 *optsize = sizeof(struct sctp_authchunks) + size;
2965 SCTP_INP_RUNLOCK(inp);
2967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2973 case SCTP_PEER_AUTH_CHUNKS:
2975 struct sctp_authchunks *sac;
2976 sctp_auth_chklist_t *chklist = NULL;
2979 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2980 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2983 /* get off the assoc */
2984 chklist = stcb->asoc.peer_auth_chunks;
2985 /* is there enough space? */
2986 size = sctp_auth_get_chklist_size(chklist);
2987 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2991 /* copy in the chunks */
2992 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2993 sac->gauth_number_of_chunks = (uint32_t)size;
2994 *optsize = sizeof(struct sctp_authchunks) + size;
2996 SCTP_TCB_UNLOCK(stcb);
2998 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3005 struct sctp_event *event;
3006 uint32_t event_type;
3008 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3009 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3011 switch (event->se_type) {
3012 case SCTP_ASSOC_CHANGE:
3013 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3015 case SCTP_PEER_ADDR_CHANGE:
3016 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3018 case SCTP_REMOTE_ERROR:
3019 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3021 case SCTP_SEND_FAILED:
3022 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3024 case SCTP_SHUTDOWN_EVENT:
3025 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3027 case SCTP_ADAPTATION_INDICATION:
3028 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3030 case SCTP_PARTIAL_DELIVERY_EVENT:
3031 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3033 case SCTP_AUTHENTICATION_EVENT:
3034 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3036 case SCTP_STREAM_RESET_EVENT:
3037 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3039 case SCTP_SENDER_DRY_EVENT:
3040 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3042 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3044 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3047 case SCTP_ASSOC_RESET_EVENT:
3048 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3050 case SCTP_STREAM_CHANGE_EVENT:
3051 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3053 case SCTP_SEND_FAILED_EVENT:
3054 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3058 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3062 if (event_type > 0) {
3064 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3066 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3067 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3068 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3069 (event->se_assoc_id == SCTP_FUTURE_ASSOC))) {
3070 SCTP_INP_RLOCK(inp);
3071 event->se_on = sctp_is_feature_on(inp, event_type);
3072 SCTP_INP_RUNLOCK(inp);
3074 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3080 SCTP_TCB_UNLOCK(stcb);
3083 *optsize = sizeof(struct sctp_event);
3087 case SCTP_RECVRCVINFO:
3088 if (*optsize < sizeof(int)) {
3089 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3092 SCTP_INP_RLOCK(inp);
3093 *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3094 SCTP_INP_RUNLOCK(inp);
3095 *optsize = sizeof(int);
3098 case SCTP_RECVNXTINFO:
3099 if (*optsize < sizeof(int)) {
3100 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3103 SCTP_INP_RLOCK(inp);
3104 *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3105 SCTP_INP_RUNLOCK(inp);
3106 *optsize = sizeof(int);
3109 case SCTP_DEFAULT_SNDINFO:
3111 struct sctp_sndinfo *info;
3113 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3114 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3117 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3118 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3119 info->snd_flags &= 0xfff0;
3120 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3121 info->snd_context = stcb->asoc.def_send.sinfo_context;
3122 SCTP_TCB_UNLOCK(stcb);
3124 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3125 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3126 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3127 (info->snd_assoc_id == SCTP_FUTURE_ASSOC))) {
3128 SCTP_INP_RLOCK(inp);
3129 info->snd_sid = inp->def_send.sinfo_stream;
3130 info->snd_flags = inp->def_send.sinfo_flags;
3131 info->snd_flags &= 0xfff0;
3132 info->snd_ppid = inp->def_send.sinfo_ppid;
3133 info->snd_context = inp->def_send.sinfo_context;
3134 SCTP_INP_RUNLOCK(inp);
3136 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3141 *optsize = sizeof(struct sctp_sndinfo);
3145 case SCTP_DEFAULT_PRINFO:
3147 struct sctp_default_prinfo *info;
3149 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3150 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3153 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3154 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3155 SCTP_TCB_UNLOCK(stcb);
3157 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3158 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3159 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3160 (info->pr_assoc_id == SCTP_FUTURE_ASSOC))) {
3161 SCTP_INP_RLOCK(inp);
3162 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3163 info->pr_value = inp->def_send.sinfo_timetolive;
3164 SCTP_INP_RUNLOCK(inp);
3166 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3171 *optsize = sizeof(struct sctp_default_prinfo);
3175 case SCTP_PEER_ADDR_THLDS:
3177 struct sctp_paddrthlds *thlds;
3178 struct sctp_nets *net;
3179 struct sockaddr *addr;
3180 #if defined(INET) && defined(INET6)
3181 struct sockaddr_in sin_store;
3184 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3185 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3187 #if defined(INET) && defined(INET6)
3188 if (thlds->spt_address.ss_family == AF_INET6) {
3189 struct sockaddr_in6 *sin6;
3191 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3192 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3193 in6_sin6_2_sin(&sin_store, sin6);
3194 addr = (struct sockaddr *)&sin_store;
3196 addr = (struct sockaddr *)&thlds->spt_address;
3199 addr = (struct sockaddr *)&thlds->spt_address;
3202 addr = (struct sockaddr *)&thlds->spt_address;
3205 net = sctp_findnet(stcb, addr);
3208 * We increment here since
3209 * sctp_findassociation_ep_addr() wil do a
3210 * decrement if it finds the stcb as long as
3211 * the locked tcb (last argument) is NOT a
3215 SCTP_INP_INCR_REF(inp);
3216 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3218 SCTP_INP_DECR_REF(inp);
3221 if ((stcb != NULL) && (net == NULL)) {
3223 if (addr->sa_family == AF_INET) {
3224 struct sockaddr_in *sin;
3226 sin = (struct sockaddr_in *)addr;
3227 if (sin->sin_addr.s_addr != INADDR_ANY) {
3229 SCTP_TCB_UNLOCK(stcb);
3230 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3236 if (addr->sa_family == AF_INET6) {
3237 struct sockaddr_in6 *sin6;
3239 sin6 = (struct sockaddr_in6 *)addr;
3240 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3242 SCTP_TCB_UNLOCK(stcb);
3243 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3249 error = EAFNOSUPPORT;
3250 SCTP_TCB_UNLOCK(stcb);
3251 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3258 thlds->spt_pathmaxrxt = net->failure_threshold;
3259 thlds->spt_pathpfthld = net->pf_threshold;
3260 thlds->spt_pathcpthld = 0xffff;
3262 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3263 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3264 thlds->spt_pathcpthld = 0xffff;
3266 thlds->spt_assoc_id = sctp_get_associd(stcb);
3267 SCTP_TCB_UNLOCK(stcb);
3269 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3270 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3271 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3272 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
3273 /* Use endpoint defaults */
3274 SCTP_INP_RLOCK(inp);
3275 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3276 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3277 thlds->spt_pathcpthld = 0xffff;
3278 SCTP_INP_RUNLOCK(inp);
3280 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3285 *optsize = sizeof(struct sctp_paddrthlds);
3289 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3291 struct sctp_udpencaps *encaps;
3292 struct sctp_nets *net;
3293 struct sockaddr *addr;
3294 #if defined(INET) && defined(INET6)
3295 struct sockaddr_in sin_store;
3298 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3299 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3301 #if defined(INET) && defined(INET6)
3302 if (encaps->sue_address.ss_family == AF_INET6) {
3303 struct sockaddr_in6 *sin6;
3305 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3306 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3307 in6_sin6_2_sin(&sin_store, sin6);
3308 addr = (struct sockaddr *)&sin_store;
3310 addr = (struct sockaddr *)&encaps->sue_address;
3313 addr = (struct sockaddr *)&encaps->sue_address;
3316 addr = (struct sockaddr *)&encaps->sue_address;
3319 net = sctp_findnet(stcb, addr);
3322 * We increment here since
3323 * sctp_findassociation_ep_addr() wil do a
3324 * decrement if it finds the stcb as long as
3325 * the locked tcb (last argument) is NOT a
3329 SCTP_INP_INCR_REF(inp);
3330 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3332 SCTP_INP_DECR_REF(inp);
3335 if ((stcb != NULL) && (net == NULL)) {
3337 if (addr->sa_family == AF_INET) {
3338 struct sockaddr_in *sin;
3340 sin = (struct sockaddr_in *)addr;
3341 if (sin->sin_addr.s_addr != INADDR_ANY) {
3343 SCTP_TCB_UNLOCK(stcb);
3344 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3350 if (addr->sa_family == AF_INET6) {
3351 struct sockaddr_in6 *sin6;
3353 sin6 = (struct sockaddr_in6 *)addr;
3354 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3356 SCTP_TCB_UNLOCK(stcb);
3357 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3363 error = EAFNOSUPPORT;
3364 SCTP_TCB_UNLOCK(stcb);
3365 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3372 encaps->sue_port = net->port;
3374 encaps->sue_port = stcb->asoc.port;
3376 SCTP_TCB_UNLOCK(stcb);
3378 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3379 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3380 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3381 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
3382 SCTP_INP_RLOCK(inp);
3383 encaps->sue_port = inp->sctp_ep.port;
3384 SCTP_INP_RUNLOCK(inp);
3386 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3391 *optsize = sizeof(struct sctp_udpencaps);
3395 case SCTP_ECN_SUPPORTED:
3397 struct sctp_assoc_value *av;
3399 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3400 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3403 av->assoc_value = stcb->asoc.ecn_supported;
3404 SCTP_TCB_UNLOCK(stcb);
3406 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3407 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3408 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3409 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3410 SCTP_INP_RLOCK(inp);
3411 av->assoc_value = inp->ecn_supported;
3412 SCTP_INP_RUNLOCK(inp);
3414 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3419 *optsize = sizeof(struct sctp_assoc_value);
3423 case SCTP_PR_SUPPORTED:
3425 struct sctp_assoc_value *av;
3427 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3428 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3431 av->assoc_value = stcb->asoc.prsctp_supported;
3432 SCTP_TCB_UNLOCK(stcb);
3434 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3435 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3436 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3437 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3438 SCTP_INP_RLOCK(inp);
3439 av->assoc_value = inp->prsctp_supported;
3440 SCTP_INP_RUNLOCK(inp);
3442 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3447 *optsize = sizeof(struct sctp_assoc_value);
3451 case SCTP_AUTH_SUPPORTED:
3453 struct sctp_assoc_value *av;
3455 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3456 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3459 av->assoc_value = stcb->asoc.auth_supported;
3460 SCTP_TCB_UNLOCK(stcb);
3462 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3463 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3464 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3465 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3466 SCTP_INP_RLOCK(inp);
3467 av->assoc_value = inp->auth_supported;
3468 SCTP_INP_RUNLOCK(inp);
3470 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3475 *optsize = sizeof(struct sctp_assoc_value);
3479 case SCTP_ASCONF_SUPPORTED:
3481 struct sctp_assoc_value *av;
3483 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3484 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3487 av->assoc_value = stcb->asoc.asconf_supported;
3488 SCTP_TCB_UNLOCK(stcb);
3490 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3491 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3492 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3493 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3494 SCTP_INP_RLOCK(inp);
3495 av->assoc_value = inp->asconf_supported;
3496 SCTP_INP_RUNLOCK(inp);
3498 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3503 *optsize = sizeof(struct sctp_assoc_value);
3507 case SCTP_RECONFIG_SUPPORTED:
3509 struct sctp_assoc_value *av;
3511 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3512 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3515 av->assoc_value = stcb->asoc.reconfig_supported;
3516 SCTP_TCB_UNLOCK(stcb);
3518 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3519 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3520 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3521 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3522 SCTP_INP_RLOCK(inp);
3523 av->assoc_value = inp->reconfig_supported;
3524 SCTP_INP_RUNLOCK(inp);
3526 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3531 *optsize = sizeof(struct sctp_assoc_value);
3535 case SCTP_NRSACK_SUPPORTED:
3537 struct sctp_assoc_value *av;
3539 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3540 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3543 av->assoc_value = stcb->asoc.nrsack_supported;
3544 SCTP_TCB_UNLOCK(stcb);
3546 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3547 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3548 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3549 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3550 SCTP_INP_RLOCK(inp);
3551 av->assoc_value = inp->nrsack_supported;
3552 SCTP_INP_RUNLOCK(inp);
3554 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3559 *optsize = sizeof(struct sctp_assoc_value);
3563 case SCTP_PKTDROP_SUPPORTED:
3565 struct sctp_assoc_value *av;
3567 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3568 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3571 av->assoc_value = stcb->asoc.pktdrop_supported;
3572 SCTP_TCB_UNLOCK(stcb);
3574 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3575 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3576 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3577 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3578 SCTP_INP_RLOCK(inp);
3579 av->assoc_value = inp->pktdrop_supported;
3580 SCTP_INP_RUNLOCK(inp);
3582 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3587 *optsize = sizeof(struct sctp_assoc_value);
3591 case SCTP_ENABLE_STREAM_RESET:
3593 struct sctp_assoc_value *av;
3595 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3596 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3599 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3600 SCTP_TCB_UNLOCK(stcb);
3602 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3603 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3604 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3605 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3606 SCTP_INP_RLOCK(inp);
3607 av->assoc_value = (uint32_t)inp->local_strreset_support;
3608 SCTP_INP_RUNLOCK(inp);
3610 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3615 *optsize = sizeof(struct sctp_assoc_value);
3619 case SCTP_PR_STREAM_STATUS:
3621 struct sctp_prstatus *sprstat;
3625 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3626 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3628 sid = sprstat->sprstat_sid;
3629 policy = sprstat->sprstat_policy;
3630 #if defined(SCTP_DETAILED_STR_STATS)
3631 if ((stcb != NULL) &&
3632 (sid < stcb->asoc.streamoutcnt) &&
3633 (policy != SCTP_PR_SCTP_NONE) &&
3634 ((policy <= SCTP_PR_SCTP_MAX) ||
3635 (policy == SCTP_PR_SCTP_ALL))) {
3636 if (policy == SCTP_PR_SCTP_ALL) {
3637 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3638 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3640 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3641 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3644 if ((stcb != NULL) &&
3645 (sid < stcb->asoc.streamoutcnt) &&
3646 (policy == SCTP_PR_SCTP_ALL)) {
3647 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3648 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3651 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3655 SCTP_TCB_UNLOCK(stcb);
3658 *optsize = sizeof(struct sctp_prstatus);
3662 case SCTP_PR_ASSOC_STATUS:
3664 struct sctp_prstatus *sprstat;
3667 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3668 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3670 policy = sprstat->sprstat_policy;
3671 if ((stcb != NULL) &&
3672 (policy != SCTP_PR_SCTP_NONE) &&
3673 ((policy <= SCTP_PR_SCTP_MAX) ||
3674 (policy == SCTP_PR_SCTP_ALL))) {
3675 if (policy == SCTP_PR_SCTP_ALL) {
3676 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3677 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3679 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3680 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3683 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3687 SCTP_TCB_UNLOCK(stcb);
3690 *optsize = sizeof(struct sctp_prstatus);
3696 struct sctp_assoc_value *av;
3698 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3699 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3702 av->assoc_value = stcb->asoc.max_cwnd;
3703 SCTP_TCB_UNLOCK(stcb);
3705 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3706 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3707 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3708 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3709 SCTP_INP_RLOCK(inp);
3710 av->assoc_value = inp->max_cwnd;
3711 SCTP_INP_RUNLOCK(inp);
3713 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3718 *optsize = sizeof(struct sctp_assoc_value);
3723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3724 error = ENOPROTOOPT;
3726 } /* end switch (sopt->sopt_name) */
3734 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3739 struct sctp_tcb *stcb = NULL;
3740 struct sctp_inpcb *inp = NULL;
3743 if (optval == NULL) {
3744 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3747 inp = (struct sctp_inpcb *)so->so_pcb;
3749 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3752 vrf_id = inp->def_vrf_id;
3757 case SCTP_AUTOCLOSE:
3758 case SCTP_AUTO_ASCONF:
3759 case SCTP_EXPLICIT_EOR:
3760 case SCTP_DISABLE_FRAGMENTS:
3761 case SCTP_USE_EXT_RCVINFO:
3762 case SCTP_I_WANT_MAPPED_V4_ADDR:
3763 /* copy in the option value */
3764 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3769 case SCTP_DISABLE_FRAGMENTS:
3770 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3772 case SCTP_AUTO_ASCONF:
3774 * NOTE: we don't really support this flag
3776 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3777 /* only valid for bound all sockets */
3778 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3780 /* forbidden by admin */
3781 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3784 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3786 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3790 case SCTP_EXPLICIT_EOR:
3791 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3793 case SCTP_USE_EXT_RCVINFO:
3794 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3796 case SCTP_I_WANT_MAPPED_V4_ADDR:
3797 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3798 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3805 set_opt = SCTP_PCB_FLAGS_NODELAY;
3807 case SCTP_AUTOCLOSE:
3808 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3809 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3810 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3813 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3815 * The value is in ticks. Note this does not effect
3816 * old associations, only new ones.
3818 inp->sctp_ep.auto_close_time = sctp_secs_to_ticks(*mopt);
3821 SCTP_INP_WLOCK(inp);
3823 sctp_feature_on(inp, set_opt);
3825 sctp_feature_off(inp, set_opt);
3827 SCTP_INP_WUNLOCK(inp);
3829 case SCTP_REUSE_PORT:
3831 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3832 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3833 /* Can't set it after we are bound */
3837 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3838 /* Can't do this for a 1-m socket */
3843 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3845 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3848 case SCTP_PARTIAL_DELIVERY_POINT:
3852 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3853 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3858 inp->partial_delivery_point = *value;
3861 case SCTP_FRAGMENT_INTERLEAVE:
3862 /* not yet until we re-write sctp_recvmsg() */
3866 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3867 if (*level == SCTP_FRAG_LEVEL_2) {
3868 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3869 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3870 } else if (*level == SCTP_FRAG_LEVEL_1) {
3871 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3872 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3873 } else if (*level == SCTP_FRAG_LEVEL_0) {
3874 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3875 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3878 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3883 case SCTP_INTERLEAVING_SUPPORTED:
3885 struct sctp_assoc_value *av;
3887 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3888 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3893 SCTP_TCB_UNLOCK(stcb);
3895 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3896 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3897 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3898 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3899 SCTP_INP_WLOCK(inp);
3900 if (av->assoc_value == 0) {
3901 inp->idata_supported = 0;
3903 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3904 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3905 inp->idata_supported = 1;
3913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3917 SCTP_INP_WUNLOCK(inp);
3919 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3925 case SCTP_CMT_ON_OFF:
3926 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3927 struct sctp_assoc_value *av;
3929 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3930 if (av->assoc_value > SCTP_CMT_MAX) {
3931 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3935 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3937 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3938 SCTP_TCB_UNLOCK(stcb);
3940 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3941 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3942 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3943 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3944 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3945 SCTP_INP_WLOCK(inp);
3946 inp->sctp_cmt_on_off = av->assoc_value;
3947 SCTP_INP_WUNLOCK(inp);
3949 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3950 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3951 (av->assoc_id == SCTP_ALL_ASSOC))) {
3952 SCTP_INP_RLOCK(inp);
3953 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3954 SCTP_TCB_LOCK(stcb);
3955 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3956 SCTP_TCB_UNLOCK(stcb);
3958 SCTP_INP_RUNLOCK(inp);
3962 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3963 error = ENOPROTOOPT;
3966 case SCTP_PLUGGABLE_CC:
3968 struct sctp_assoc_value *av;
3969 struct sctp_nets *net;
3971 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3972 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3973 (av->assoc_value != SCTP_CC_HSTCP) &&
3974 (av->assoc_value != SCTP_CC_HTCP) &&
3975 (av->assoc_value != SCTP_CC_RTCC)) {
3976 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3980 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3982 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3983 stcb->asoc.congestion_control_module = av->assoc_value;
3984 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3985 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3986 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3989 SCTP_TCB_UNLOCK(stcb);
3991 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3992 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3993 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3994 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3995 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3996 SCTP_INP_WLOCK(inp);
3997 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3998 SCTP_INP_WUNLOCK(inp);
4000 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4001 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4002 (av->assoc_id == SCTP_ALL_ASSOC))) {
4003 SCTP_INP_RLOCK(inp);
4004 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4005 SCTP_TCB_LOCK(stcb);
4006 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4007 stcb->asoc.congestion_control_module = av->assoc_value;
4008 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4009 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4010 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4013 SCTP_TCB_UNLOCK(stcb);
4015 SCTP_INP_RUNLOCK(inp);
4020 case SCTP_CC_OPTION:
4022 struct sctp_cc_option *cc_opt;
4024 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4025 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4027 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4028 (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC)) {
4029 SCTP_INP_RLOCK(inp);
4030 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4031 SCTP_TCB_LOCK(stcb);
4032 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4033 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4035 SCTP_TCB_UNLOCK(stcb);
4037 SCTP_INP_RUNLOCK(inp);
4042 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4045 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4048 SCTP_TCB_UNLOCK(stcb);
4052 case SCTP_PLUGGABLE_SS:
4054 struct sctp_assoc_value *av;
4056 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4057 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4058 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4059 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4060 (av->assoc_value != SCTP_SS_PRIORITY) &&
4061 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4062 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4063 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4067 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4069 SCTP_TCB_SEND_LOCK(stcb);
4070 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, true);
4071 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4072 stcb->asoc.stream_scheduling_module = av->assoc_value;
4073 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc);
4074 SCTP_TCB_SEND_UNLOCK(stcb);
4075 SCTP_TCB_UNLOCK(stcb);
4077 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4078 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4079 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4080 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4081 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4082 SCTP_INP_WLOCK(inp);
4083 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4084 SCTP_INP_WUNLOCK(inp);
4086 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4087 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4088 (av->assoc_id == SCTP_ALL_ASSOC))) {
4089 SCTP_INP_RLOCK(inp);
4090 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4091 SCTP_TCB_LOCK(stcb);
4092 SCTP_TCB_SEND_LOCK(stcb);
4093 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, true);
4094 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4095 stcb->asoc.stream_scheduling_module = av->assoc_value;
4096 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc);
4097 SCTP_TCB_SEND_UNLOCK(stcb);
4098 SCTP_TCB_UNLOCK(stcb);
4100 SCTP_INP_RUNLOCK(inp);
4107 struct sctp_stream_value *av;
4109 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4110 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4112 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4113 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4114 av->stream_value) < 0)) {
4115 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4118 SCTP_TCB_UNLOCK(stcb);
4120 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4121 (av->assoc_id == SCTP_CURRENT_ASSOC)) {
4122 SCTP_INP_RLOCK(inp);
4123 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4124 SCTP_TCB_LOCK(stcb);
4125 if (av->stream_id < stcb->asoc.streamoutcnt) {
4126 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4128 &stcb->asoc.strmout[av->stream_id],
4131 SCTP_TCB_UNLOCK(stcb);
4133 SCTP_INP_RUNLOCK(inp);
4136 * Can't set stream value without
4139 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4145 case SCTP_CLR_STAT_LOG:
4146 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4151 struct sctp_assoc_value *av;
4153 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4154 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4157 stcb->asoc.context = av->assoc_value;
4158 SCTP_TCB_UNLOCK(stcb);
4160 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4161 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4162 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4163 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4164 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4165 SCTP_INP_WLOCK(inp);
4166 inp->sctp_context = av->assoc_value;
4167 SCTP_INP_WUNLOCK(inp);
4169 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4170 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4171 (av->assoc_id == SCTP_ALL_ASSOC))) {
4172 SCTP_INP_RLOCK(inp);
4173 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4174 SCTP_TCB_LOCK(stcb);
4175 stcb->asoc.context = av->assoc_value;
4176 SCTP_TCB_UNLOCK(stcb);
4178 SCTP_INP_RUNLOCK(inp);
4185 uint32_t *default_vrfid;
4187 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4188 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4189 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4193 inp->def_vrf_id = *default_vrfid;
4196 case SCTP_DEL_VRF_ID:
4198 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4202 case SCTP_ADD_VRF_ID:
4204 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4208 case SCTP_DELAYED_SACK:
4210 struct sctp_sack_info *sack;
4212 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4213 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4214 if (sack->sack_delay) {
4215 if (sack->sack_delay > SCTP_MAX_SACK_DELAY) {
4218 SCTP_TCB_UNLOCK(stcb);
4224 if (sack->sack_delay) {
4225 stcb->asoc.delayed_ack = sack->sack_delay;
4227 if (sack->sack_freq) {
4228 stcb->asoc.sack_freq = sack->sack_freq;
4230 SCTP_TCB_UNLOCK(stcb);
4232 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4233 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4234 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4235 ((sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4236 (sack->sack_assoc_id == SCTP_ALL_ASSOC)))) {
4237 SCTP_INP_WLOCK(inp);
4238 if (sack->sack_delay) {
4239 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = sctp_msecs_to_ticks(sack->sack_delay);
4241 if (sack->sack_freq) {
4242 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4244 SCTP_INP_WUNLOCK(inp);
4246 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4247 ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4248 (sack->sack_assoc_id == SCTP_ALL_ASSOC))) {
4249 SCTP_INP_RLOCK(inp);
4250 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4251 SCTP_TCB_LOCK(stcb);
4252 if (sack->sack_delay) {
4253 stcb->asoc.delayed_ack = sack->sack_delay;
4255 if (sack->sack_freq) {
4256 stcb->asoc.sack_freq = sack->sack_freq;
4258 SCTP_TCB_UNLOCK(stcb);
4260 SCTP_INP_RUNLOCK(inp);
4265 case SCTP_AUTH_CHUNK:
4267 struct sctp_authchunk *sauth;
4269 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4271 SCTP_INP_WLOCK(inp);
4272 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4273 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4276 inp->auth_supported = 1;
4278 SCTP_INP_WUNLOCK(inp);
4283 struct sctp_authkey *sca;
4284 struct sctp_keyhead *shared_keys;
4285 sctp_sharedkey_t *shared_key;
4286 sctp_key_t *key = NULL;
4289 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4290 if (sca->sca_keylength == 0) {
4291 size = optsize - sizeof(struct sctp_authkey);
4293 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4294 size = sca->sca_keylength;
4296 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4301 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4304 shared_keys = &stcb->asoc.shared_keys;
4305 /* clear the cached keys for this key id */
4306 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4308 * create the new shared key and
4312 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4314 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4316 SCTP_TCB_UNLOCK(stcb);
4320 shared_key = sctp_alloc_sharedkey();
4321 if (shared_key == NULL) {
4323 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4325 SCTP_TCB_UNLOCK(stcb);
4328 shared_key->key = key;
4329 shared_key->keyid = sca->sca_keynumber;
4330 error = sctp_insert_sharedkey(shared_keys, shared_key);
4331 SCTP_TCB_UNLOCK(stcb);
4333 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4334 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4335 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4336 ((sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4337 (sca->sca_assoc_id == SCTP_ALL_ASSOC)))) {
4338 SCTP_INP_WLOCK(inp);
4339 shared_keys = &inp->sctp_ep.shared_keys;
4341 * clear the cached keys on all
4342 * assocs for this key id
4344 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4346 * create the new shared key and
4350 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4352 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4354 SCTP_INP_WUNLOCK(inp);
4358 shared_key = sctp_alloc_sharedkey();
4359 if (shared_key == NULL) {
4361 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4363 SCTP_INP_WUNLOCK(inp);
4366 shared_key->key = key;
4367 shared_key->keyid = sca->sca_keynumber;
4368 error = sctp_insert_sharedkey(shared_keys, shared_key);
4369 SCTP_INP_WUNLOCK(inp);
4371 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4372 ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4373 (sca->sca_assoc_id == SCTP_ALL_ASSOC))) {
4374 SCTP_INP_RLOCK(inp);
4375 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4376 SCTP_TCB_LOCK(stcb);
4377 shared_keys = &stcb->asoc.shared_keys;
4379 * clear the cached keys for
4382 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4384 * create the new shared key
4385 * and insert/replace it
4388 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4390 SCTP_TCB_UNLOCK(stcb);
4394 shared_key = sctp_alloc_sharedkey();
4395 if (shared_key == NULL) {
4397 SCTP_TCB_UNLOCK(stcb);
4400 shared_key->key = key;
4401 shared_key->keyid = sca->sca_keynumber;
4402 error = sctp_insert_sharedkey(shared_keys, shared_key);
4403 SCTP_TCB_UNLOCK(stcb);
4405 SCTP_INP_RUNLOCK(inp);
4410 case SCTP_HMAC_IDENT:
4412 struct sctp_hmacalgo *shmac;
4413 sctp_hmaclist_t *hmaclist;
4417 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4418 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4419 (shmac->shmac_number_of_idents > 0xffff)) {
4420 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4425 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4426 if (hmaclist == NULL) {
4427 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4431 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4432 hmacid = shmac->shmac_idents[i];
4433 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4434 /* invalid HMACs were found */ ;
4435 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4437 sctp_free_hmaclist(hmaclist);
4438 goto sctp_set_hmac_done;
4441 for (i = 0; i < hmaclist->num_algo; i++) {
4442 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4443 /* already in list */
4447 if (i == hmaclist->num_algo) {
4448 /* not found in list */
4449 sctp_free_hmaclist(hmaclist);
4450 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4454 /* set it on the endpoint */
4455 SCTP_INP_WLOCK(inp);
4456 if (inp->sctp_ep.local_hmacs)
4457 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4458 inp->sctp_ep.local_hmacs = hmaclist;
4459 SCTP_INP_WUNLOCK(inp);
4463 case SCTP_AUTH_ACTIVE_KEY:
4465 struct sctp_authkeyid *scact;
4467 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4468 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4470 /* set the active key on the right place */
4472 /* set the active key on the assoc */
4473 if (sctp_auth_setactivekey(stcb,
4474 scact->scact_keynumber)) {
4475 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4476 SCTP_FROM_SCTP_USRREQ,
4480 SCTP_TCB_UNLOCK(stcb);
4482 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4483 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4484 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4485 ((scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4486 (scact->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4487 SCTP_INP_WLOCK(inp);
4488 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4489 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4492 SCTP_INP_WUNLOCK(inp);
4494 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4495 ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4496 (scact->scact_assoc_id == SCTP_ALL_ASSOC))) {
4497 SCTP_INP_RLOCK(inp);
4498 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4499 SCTP_TCB_LOCK(stcb);
4500 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4501 SCTP_TCB_UNLOCK(stcb);
4503 SCTP_INP_RUNLOCK(inp);
4508 case SCTP_AUTH_DELETE_KEY:
4510 struct sctp_authkeyid *scdel;
4512 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4513 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4515 /* delete the key from the right place */
4517 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4518 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4521 SCTP_TCB_UNLOCK(stcb);
4523 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4524 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4525 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4526 ((scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4527 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4528 SCTP_INP_WLOCK(inp);
4529 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4530 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4533 SCTP_INP_WUNLOCK(inp);
4535 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4536 ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4537 (scdel->scact_assoc_id == SCTP_ALL_ASSOC))) {
4538 SCTP_INP_RLOCK(inp);
4539 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4540 SCTP_TCB_LOCK(stcb);
4541 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4542 SCTP_TCB_UNLOCK(stcb);
4544 SCTP_INP_RUNLOCK(inp);
4549 case SCTP_AUTH_DEACTIVATE_KEY:
4551 struct sctp_authkeyid *keyid;
4553 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4554 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4556 /* deactivate the key from the right place */
4558 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4559 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4562 SCTP_TCB_UNLOCK(stcb);
4564 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4565 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4566 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4567 ((keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4568 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4569 SCTP_INP_WLOCK(inp);
4570 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4571 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4574 SCTP_INP_WUNLOCK(inp);
4576 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4577 ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4578 (keyid->scact_assoc_id == SCTP_ALL_ASSOC))) {
4579 SCTP_INP_RLOCK(inp);
4580 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4581 SCTP_TCB_LOCK(stcb);
4582 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4583 SCTP_TCB_UNLOCK(stcb);
4585 SCTP_INP_RUNLOCK(inp);
4590 case SCTP_ENABLE_STREAM_RESET:
4592 struct sctp_assoc_value *av;
4594 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4595 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4596 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4600 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4602 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4603 SCTP_TCB_UNLOCK(stcb);
4605 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4606 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4607 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4608 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4609 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4610 SCTP_INP_WLOCK(inp);
4611 inp->local_strreset_support = (uint8_t)av->assoc_value;
4612 SCTP_INP_WUNLOCK(inp);
4614 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4615 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4616 (av->assoc_id == SCTP_ALL_ASSOC))) {
4617 SCTP_INP_RLOCK(inp);
4618 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4619 SCTP_TCB_LOCK(stcb);
4620 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4621 SCTP_TCB_UNLOCK(stcb);
4623 SCTP_INP_RUNLOCK(inp);
4628 case SCTP_RESET_STREAMS:
4630 struct sctp_reset_streams *strrst;
4631 int i, send_out = 0;
4634 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4635 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4637 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4641 if (stcb->asoc.reconfig_supported == 0) {
4643 * Peer does not support the chunk type.
4645 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4647 SCTP_TCB_UNLOCK(stcb);
4650 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4651 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4653 SCTP_TCB_UNLOCK(stcb);
4656 if (sizeof(struct sctp_reset_streams) +
4657 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4659 SCTP_TCB_UNLOCK(stcb);
4662 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4664 if (stcb->asoc.stream_reset_outstanding) {
4665 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4667 SCTP_TCB_UNLOCK(stcb);
4671 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4674 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4675 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4677 SCTP_TCB_UNLOCK(stcb);
4680 if ((send_in == 0) && (send_out == 0)) {
4681 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4683 SCTP_TCB_UNLOCK(stcb);
4686 for (i = 0; i < strrst->srs_number_streams; i++) {
4688 (strrst->srs_stream_list[i] >= stcb->asoc.streamincnt)) {
4689 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4694 (strrst->srs_stream_list[i] >= stcb->asoc.streamoutcnt)) {
4695 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4701 SCTP_TCB_UNLOCK(stcb);
4708 if (strrst->srs_number_streams) {
4709 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4710 strm = strrst->srs_stream_list[i];
4711 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4712 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4718 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4719 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4720 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4727 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4728 strrst->srs_stream_list,
4729 send_in, 0, 0, 0, 0, 0);
4731 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4734 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4737 * For outgoing streams don't report any
4738 * problems in sending the request to the
4739 * application. XXX: Double check resetting
4744 SCTP_TCB_UNLOCK(stcb);
4747 case SCTP_ADD_STREAMS:
4749 struct sctp_add_streams *stradd;
4750 uint8_t addstream = 0;
4751 uint16_t add_o_strmcnt = 0;
4752 uint16_t add_i_strmcnt = 0;
4754 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4755 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4757 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4761 if (stcb->asoc.reconfig_supported == 0) {
4763 * Peer does not support the chunk type.
4765 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4767 SCTP_TCB_UNLOCK(stcb);
4770 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4771 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4773 SCTP_TCB_UNLOCK(stcb);
4776 if (stcb->asoc.stream_reset_outstanding) {
4777 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4779 SCTP_TCB_UNLOCK(stcb);
4782 if ((stradd->sas_outstrms == 0) &&
4783 (stradd->sas_instrms == 0)) {
4787 if (stradd->sas_outstrms) {
4789 /* We allocate here */
4790 add_o_strmcnt = stradd->sas_outstrms;
4791 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4792 /* You can't have more than 64k */
4797 if (stradd->sas_instrms) {
4802 * We allocate inside
4803 * sctp_send_str_reset_req()
4805 add_i_strmcnt = stradd->sas_instrms;
4806 cnt = add_i_strmcnt;
4807 cnt += stcb->asoc.streamincnt;
4808 if (cnt > 0x0000ffff) {
4809 /* You can't have more than 64k */
4813 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4814 /* More than you are allowed */
4819 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4820 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4822 SCTP_TCB_UNLOCK(stcb);
4825 case SCTP_RESET_ASSOC:
4830 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4831 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4833 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4837 if (stcb->asoc.reconfig_supported == 0) {
4839 * Peer does not support the chunk type.
4841 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4843 SCTP_TCB_UNLOCK(stcb);
4846 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4847 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4849 SCTP_TCB_UNLOCK(stcb);
4852 if (stcb->asoc.stream_reset_outstanding) {
4853 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4855 SCTP_TCB_UNLOCK(stcb);
4859 * Is there any data pending in the send or sent
4862 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4863 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4866 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4867 SCTP_TCB_UNLOCK(stcb);
4870 /* Do any streams have data queued? */
4871 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4872 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4876 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4877 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4878 SCTP_TCB_UNLOCK(stcb);
4881 case SCTP_CONNECT_X:
4882 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4883 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4887 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4889 case SCTP_CONNECT_X_DELAYED:
4890 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4895 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4897 case SCTP_CONNECT_X_COMPLETE:
4899 struct sockaddr *sa;
4901 /* FIXME MT: check correct? */
4902 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4905 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4906 SCTP_INP_RLOCK(inp);
4907 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4909 SCTP_TCB_LOCK(stcb);
4911 SCTP_INP_RUNLOCK(inp);
4914 * We increment here since
4915 * sctp_findassociation_ep_addr() wil do a
4916 * decrement if it finds the stcb as long as
4917 * the locked tcb (last argument) is NOT a
4920 SCTP_INP_INCR_REF(inp);
4921 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4923 SCTP_INP_DECR_REF(inp);
4928 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4932 if (stcb->asoc.delayed_connection == 1) {
4933 stcb->asoc.delayed_connection = 0;
4934 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4935 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4936 stcb->asoc.primary_destination,
4937 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4938 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4941 * already expired or did not use delayed
4944 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4947 SCTP_TCB_UNLOCK(stcb);
4950 case SCTP_MAX_BURST:
4952 struct sctp_assoc_value *av;
4954 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4955 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4958 stcb->asoc.max_burst = av->assoc_value;
4959 SCTP_TCB_UNLOCK(stcb);
4961 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4962 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4963 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4964 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4965 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4966 SCTP_INP_WLOCK(inp);
4967 inp->sctp_ep.max_burst = av->assoc_value;
4968 SCTP_INP_WUNLOCK(inp);
4970 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4971 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4972 (av->assoc_id == SCTP_ALL_ASSOC))) {
4973 SCTP_INP_RLOCK(inp);
4974 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4975 SCTP_TCB_LOCK(stcb);
4976 stcb->asoc.max_burst = av->assoc_value;
4977 SCTP_TCB_UNLOCK(stcb);
4979 SCTP_INP_RUNLOCK(inp);
4986 struct sctp_assoc_value *av;
4988 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4989 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4992 stcb->asoc.sctp_frag_point = av->assoc_value;
4993 SCTP_TCB_UNLOCK(stcb);
4995 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4996 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4997 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4998 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
4999 SCTP_INP_WLOCK(inp);
5000 inp->sctp_frag_point = av->assoc_value;
5001 SCTP_INP_WUNLOCK(inp);
5003 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5011 struct sctp_event_subscribe *events;
5013 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5015 SCTP_INP_WLOCK(inp);
5016 if (events->sctp_data_io_event) {
5017 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5019 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5022 if (events->sctp_association_event) {
5023 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5025 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5028 if (events->sctp_address_event) {
5029 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5031 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5034 if (events->sctp_send_failure_event) {
5035 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5037 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5040 if (events->sctp_peer_error_event) {
5041 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5043 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5046 if (events->sctp_shutdown_event) {
5047 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5049 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5052 if (events->sctp_partial_delivery_event) {
5053 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5055 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5058 if (events->sctp_adaptation_layer_event) {
5059 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5061 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5064 if (events->sctp_authentication_event) {
5065 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5067 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5070 if (events->sctp_sender_dry_event) {
5071 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5073 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5076 if (events->sctp_stream_reset_event) {
5077 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5079 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5081 SCTP_INP_WUNLOCK(inp);
5083 SCTP_INP_RLOCK(inp);
5084 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5085 SCTP_TCB_LOCK(stcb);
5086 if (events->sctp_association_event) {
5087 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5089 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5091 if (events->sctp_address_event) {
5092 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5094 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5096 if (events->sctp_send_failure_event) {
5097 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5099 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5101 if (events->sctp_peer_error_event) {
5102 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5104 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5106 if (events->sctp_shutdown_event) {
5107 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5109 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5111 if (events->sctp_partial_delivery_event) {
5112 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5114 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5116 if (events->sctp_adaptation_layer_event) {
5117 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5119 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5121 if (events->sctp_authentication_event) {
5122 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5124 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5126 if (events->sctp_sender_dry_event) {
5127 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5129 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5131 if (events->sctp_stream_reset_event) {
5132 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5134 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5136 SCTP_TCB_UNLOCK(stcb);
5139 * Send up the sender dry event only for 1-to-1
5142 if (events->sctp_sender_dry_event) {
5143 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5144 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5145 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5147 SCTP_TCB_LOCK(stcb);
5148 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5149 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5150 (stcb->asoc.stream_queue_cnt == 0)) {
5151 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5153 SCTP_TCB_UNLOCK(stcb);
5157 SCTP_INP_RUNLOCK(inp);
5160 case SCTP_ADAPTATION_LAYER:
5162 struct sctp_setadaptation *adap_bits;
5164 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5165 SCTP_INP_WLOCK(inp);
5166 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5167 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5168 SCTP_INP_WUNLOCK(inp);
5172 case SCTP_SET_INITIAL_DBG_SEQ:
5176 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5177 SCTP_INP_WLOCK(inp);
5178 inp->sctp_ep.initial_sequence_debug = *vvv;
5179 SCTP_INP_WUNLOCK(inp);
5183 case SCTP_DEFAULT_SEND_PARAM:
5185 struct sctp_sndrcvinfo *s_info;
5187 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5188 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5191 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5192 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5194 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5197 SCTP_TCB_UNLOCK(stcb);
5199 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5200 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5201 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5202 ((s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5203 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)))) {
5204 SCTP_INP_WLOCK(inp);
5205 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5206 SCTP_INP_WUNLOCK(inp);
5208 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5209 ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5210 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC))) {
5211 SCTP_INP_RLOCK(inp);
5212 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5213 SCTP_TCB_LOCK(stcb);
5214 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5215 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5217 SCTP_TCB_UNLOCK(stcb);
5219 SCTP_INP_RUNLOCK(inp);
5224 case SCTP_PEER_ADDR_PARAMS:
5226 struct sctp_paddrparams *paddrp;
5227 struct sctp_nets *net;
5228 struct sockaddr *addr;
5229 #if defined(INET) && defined(INET6)
5230 struct sockaddr_in sin_store;
5233 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5234 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5236 #if defined(INET) && defined(INET6)
5237 if (paddrp->spp_address.ss_family == AF_INET6) {
5238 struct sockaddr_in6 *sin6;
5240 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5241 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5242 in6_sin6_2_sin(&sin_store, sin6);
5243 addr = (struct sockaddr *)&sin_store;
5245 addr = (struct sockaddr *)&paddrp->spp_address;
5248 addr = (struct sockaddr *)&paddrp->spp_address;
5251 addr = (struct sockaddr *)&paddrp->spp_address;
5254 net = sctp_findnet(stcb, addr);
5257 * We increment here since
5258 * sctp_findassociation_ep_addr() wil do a
5259 * decrement if it finds the stcb as long as
5260 * the locked tcb (last argument) is NOT a
5264 SCTP_INP_INCR_REF(inp);
5265 stcb = sctp_findassociation_ep_addr(&inp, addr,
5268 SCTP_INP_DECR_REF(inp);
5271 if ((stcb != NULL) && (net == NULL)) {
5273 if (addr->sa_family == AF_INET) {
5274 struct sockaddr_in *sin;
5276 sin = (struct sockaddr_in *)addr;
5277 if (sin->sin_addr.s_addr != INADDR_ANY) {
5278 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5279 SCTP_TCB_UNLOCK(stcb);
5286 if (addr->sa_family == AF_INET6) {
5287 struct sockaddr_in6 *sin6;
5289 sin6 = (struct sockaddr_in6 *)addr;
5290 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5291 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5292 SCTP_TCB_UNLOCK(stcb);
5299 error = EAFNOSUPPORT;
5300 SCTP_TCB_UNLOCK(stcb);
5301 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5306 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5308 SCTP_TCB_UNLOCK(stcb);
5309 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5313 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5315 SCTP_TCB_UNLOCK(stcb);
5316 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5319 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) &&
5320 (paddrp->spp_pathmtu > 0) &&
5321 ((paddrp->spp_pathmtu < SCTP_SMALLEST_PMTU) ||
5322 (paddrp->spp_pathmtu > SCTP_LARGEST_PMTU))) {
5324 SCTP_TCB_UNLOCK(stcb);
5325 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5330 /************************TCB SPECIFIC SET ******************/
5332 /************************NET SPECIFIC SET ******************/
5333 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5334 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5335 !(net->dest_state & SCTP_ADDR_NOHB)) {
5336 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5337 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5339 net->dest_state |= SCTP_ADDR_NOHB;
5341 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5342 if (paddrp->spp_hbinterval) {
5343 net->heart_beat_delay = paddrp->spp_hbinterval;
5344 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5345 net->heart_beat_delay = 0;
5347 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5348 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5349 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5350 net->dest_state &= ~SCTP_ADDR_NOHB;
5352 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5353 if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
5354 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5355 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5356 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5359 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5360 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5361 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5362 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5364 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5365 if (paddrp->spp_pathmtu > 0) {
5366 net->mtu = paddrp->spp_pathmtu;
5367 switch (net->ro._l_addr.sa.sa_family) {
5370 net->mtu += SCTP_MIN_V4_OVERHEAD;
5375 net->mtu += SCTP_MIN_OVERHEAD;
5381 if (net->mtu < stcb->asoc.smallest_mtu) {
5382 sctp_pathmtu_adjustment(stcb, net->mtu, true);
5386 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5387 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5388 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5390 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5392 if (paddrp->spp_pathmaxrxt > 0) {
5393 if (net->dest_state & SCTP_ADDR_PF) {
5394 if (net->error_count > paddrp->spp_pathmaxrxt) {
5395 net->dest_state &= ~SCTP_ADDR_PF;
5398 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5399 (net->error_count > net->pf_threshold)) {
5400 net->dest_state |= SCTP_ADDR_PF;
5401 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5402 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5403 stcb->sctp_ep, stcb, net,
5404 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5405 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5408 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5409 if (net->error_count > paddrp->spp_pathmaxrxt) {
5410 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5411 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5414 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5415 net->dest_state |= SCTP_ADDR_REACHABLE;
5416 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5419 net->failure_threshold = paddrp->spp_pathmaxrxt;
5421 if (paddrp->spp_flags & SPP_DSCP) {
5422 net->dscp = paddrp->spp_dscp & 0xfc;
5426 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5427 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5428 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5429 net->flowlabel |= 0x80000000;
5434 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5435 if (paddrp->spp_pathmaxrxt > 0) {
5436 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5437 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5438 if (net->dest_state & SCTP_ADDR_PF) {
5439 if (net->error_count > paddrp->spp_pathmaxrxt) {
5440 net->dest_state &= ~SCTP_ADDR_PF;
5443 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5444 (net->error_count > net->pf_threshold)) {
5445 net->dest_state |= SCTP_ADDR_PF;
5446 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5447 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5448 stcb->sctp_ep, stcb, net,
5449 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5450 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5453 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5454 if (net->error_count > paddrp->spp_pathmaxrxt) {
5455 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5456 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5459 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5460 net->dest_state |= SCTP_ADDR_REACHABLE;
5461 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5464 net->failure_threshold = paddrp->spp_pathmaxrxt;
5467 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5468 if (paddrp->spp_hbinterval != 0) {
5469 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5470 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5471 stcb->asoc.heart_beat_delay = 0;
5473 /* Turn back on the timer */
5474 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5475 if (paddrp->spp_hbinterval != 0) {
5476 net->heart_beat_delay = paddrp->spp_hbinterval;
5477 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5478 net->heart_beat_delay = 0;
5480 if (net->dest_state & SCTP_ADDR_NOHB) {
5481 net->dest_state &= ~SCTP_ADDR_NOHB;
5483 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5484 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5485 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5487 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5489 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5490 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5491 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5492 net->dest_state |= SCTP_ADDR_NOHB;
5493 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5494 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5496 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5500 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5502 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5503 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5504 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5505 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5506 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5508 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5509 if (paddrp->spp_pathmtu > 0) {
5510 net->mtu = paddrp->spp_pathmtu;
5511 switch (net->ro._l_addr.sa.sa_family) {
5514 net->mtu += SCTP_MIN_V4_OVERHEAD;
5519 net->mtu += SCTP_MIN_OVERHEAD;
5525 if (net->mtu < stcb->asoc.smallest_mtu) {
5526 sctp_pathmtu_adjustment(stcb, net->mtu, true);
5530 if (paddrp->spp_pathmtu > 0) {
5531 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5533 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5535 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5536 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5537 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5538 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5540 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5542 stcb->asoc.default_mtu = 0;
5543 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5545 if (paddrp->spp_flags & SPP_DSCP) {
5546 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5547 net->dscp = paddrp->spp_dscp & 0xfc;
5550 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5551 stcb->asoc.default_dscp |= 0x01;
5554 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5555 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5556 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5557 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5558 net->flowlabel |= 0x80000000;
5561 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5562 stcb->asoc.default_flowlabel |= 0x80000000;
5566 SCTP_TCB_UNLOCK(stcb);
5568 /************************NO TCB, SET TO default stuff ******************/
5569 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5570 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5571 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5572 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
5573 SCTP_INP_WLOCK(inp);
5575 * For the TOS/FLOWLABEL stuff you
5576 * set it with the options on the
5579 if (paddrp->spp_pathmaxrxt > 0) {
5580 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5583 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5584 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5585 else if (paddrp->spp_hbinterval != 0) {
5586 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5587 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5588 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5591 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5592 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5593 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5594 } else if (paddrp->spp_hbinterval) {
5595 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5597 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5598 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5599 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5601 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5602 inp->sctp_ep.default_mtu = 0;
5603 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5604 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5605 if (paddrp->spp_pathmtu > 0) {
5606 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5608 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5610 if (paddrp->spp_flags & SPP_DSCP) {
5611 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5612 inp->sctp_ep.default_dscp |= 0x01;
5615 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5616 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5617 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5618 inp->sctp_ep.default_flowlabel |= 0x80000000;
5622 SCTP_INP_WUNLOCK(inp);
5624 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5632 struct sctp_rtoinfo *srto;
5633 uint32_t new_init, new_min, new_max;
5635 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5636 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5639 if (srto->srto_initial)
5640 new_init = srto->srto_initial;
5642 new_init = stcb->asoc.initial_rto;
5644 new_max = srto->srto_max;
5646 new_max = stcb->asoc.maxrto;
5648 new_min = srto->srto_min;
5650 new_min = stcb->asoc.minrto;
5651 if ((new_min <= new_init) && (new_init <= new_max)) {
5652 stcb->asoc.initial_rto = new_init;
5653 stcb->asoc.maxrto = new_max;
5654 stcb->asoc.minrto = new_min;
5656 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5659 SCTP_TCB_UNLOCK(stcb);
5661 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5662 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5663 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5664 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
5665 SCTP_INP_WLOCK(inp);
5666 if (srto->srto_initial)
5667 new_init = srto->srto_initial;
5669 new_init = inp->sctp_ep.initial_rto;
5671 new_max = srto->srto_max;
5673 new_max = inp->sctp_ep.sctp_maxrto;
5675 new_min = srto->srto_min;
5677 new_min = inp->sctp_ep.sctp_minrto;
5678 if ((new_min <= new_init) && (new_init <= new_max)) {
5679 inp->sctp_ep.initial_rto = new_init;
5680 inp->sctp_ep.sctp_maxrto = new_max;
5681 inp->sctp_ep.sctp_minrto = new_min;
5683 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5686 SCTP_INP_WUNLOCK(inp);
5688 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5694 case SCTP_ASSOCINFO:
5696 struct sctp_assocparams *sasoc;
5698 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5699 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5700 if (sasoc->sasoc_cookie_life > 0) {
5701 /* boundary check the cookie life */
5702 if (sasoc->sasoc_cookie_life < SCTP_MIN_COOKIE_LIFE) {
5703 sasoc->sasoc_cookie_life = SCTP_MIN_COOKIE_LIFE;
5705 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5706 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5710 if (sasoc->sasoc_asocmaxrxt > 0) {
5711 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5713 if (sasoc->sasoc_cookie_life > 0) {
5714 stcb->asoc.cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5716 SCTP_TCB_UNLOCK(stcb);
5718 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5719 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5720 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5721 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
5722 SCTP_INP_WLOCK(inp);
5723 if (sasoc->sasoc_asocmaxrxt > 0) {
5724 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5726 if (sasoc->sasoc_cookie_life > 0) {
5727 inp->sctp_ep.def_cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5729 SCTP_INP_WUNLOCK(inp);
5731 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5739 struct sctp_initmsg *sinit;
5741 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5742 SCTP_INP_WLOCK(inp);
5743 if (sinit->sinit_num_ostreams)
5744 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5746 if (sinit->sinit_max_instreams)
5747 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5749 if (sinit->sinit_max_attempts)
5750 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5752 if (sinit->sinit_max_init_timeo)
5753 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5754 SCTP_INP_WUNLOCK(inp);
5757 case SCTP_PRIMARY_ADDR:
5759 struct sctp_setprim *spa;
5760 struct sctp_nets *net;
5761 struct sockaddr *addr;
5762 #if defined(INET) && defined(INET6)
5763 struct sockaddr_in sin_store;
5766 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5767 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5769 #if defined(INET) && defined(INET6)
5770 if (spa->ssp_addr.ss_family == AF_INET6) {
5771 struct sockaddr_in6 *sin6;
5773 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5774 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5775 in6_sin6_2_sin(&sin_store, sin6);
5776 addr = (struct sockaddr *)&sin_store;
5778 addr = (struct sockaddr *)&spa->ssp_addr;
5781 addr = (struct sockaddr *)&spa->ssp_addr;
5784 addr = (struct sockaddr *)&spa->ssp_addr;
5787 net = sctp_findnet(stcb, addr);
5790 * We increment here since
5791 * sctp_findassociation_ep_addr() wil do a
5792 * decrement if it finds the stcb as long as
5793 * the locked tcb (last argument) is NOT a
5797 SCTP_INP_INCR_REF(inp);
5798 stcb = sctp_findassociation_ep_addr(&inp, addr,
5801 SCTP_INP_DECR_REF(inp);
5805 if ((stcb != NULL) && (net != NULL)) {
5806 if (net != stcb->asoc.primary_destination) {
5807 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5808 /* Ok we need to set it */
5809 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5810 if ((stcb->asoc.alternate) &&
5811 (!(net->dest_state & SCTP_ADDR_PF)) &&
5812 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5813 sctp_free_remote_addr(stcb->asoc.alternate);
5814 stcb->asoc.alternate = NULL;
5817 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5821 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5826 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5830 SCTP_TCB_UNLOCK(stcb);
5834 case SCTP_SET_DYNAMIC_PRIMARY:
5836 union sctp_sockstore *ss;
5838 error = priv_check(curthread,
5839 PRIV_NETINET_RESERVEDPORT);
5843 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5844 /* SUPER USER CHECK? */
5845 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5848 case SCTP_SET_PEER_PRIMARY_ADDR:
5850 struct sctp_setpeerprim *sspp;
5851 struct sockaddr *addr;
5852 #if defined(INET) && defined(INET6)
5853 struct sockaddr_in sin_store;
5856 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5857 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5859 struct sctp_ifa *ifa;
5861 #if defined(INET) && defined(INET6)
5862 if (sspp->sspp_addr.ss_family == AF_INET6) {
5863 struct sockaddr_in6 *sin6;
5865 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5866 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5867 in6_sin6_2_sin(&sin_store, sin6);
5868 addr = (struct sockaddr *)&sin_store;
5870 addr = (struct sockaddr *)&sspp->sspp_addr;
5873 addr = (struct sockaddr *)&sspp->sspp_addr;
5876 addr = (struct sockaddr *)&sspp->sspp_addr;
5878 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5880 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5884 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5886 * Must validate the ifa found is in
5889 struct sctp_laddr *laddr;
5892 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5893 if (laddr->ifa == NULL) {
5894 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5898 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5899 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5902 if (laddr->ifa == ifa) {
5908 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5913 switch (addr->sa_family) {
5917 struct sockaddr_in *sin;
5919 sin = (struct sockaddr_in *)addr;
5920 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5921 &sin->sin_addr) != 0) {
5922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5932 struct sockaddr_in6 *sin6;
5934 sin6 = (struct sockaddr_in6 *)addr;
5935 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5936 &sin6->sin6_addr) != 0) {
5937 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5945 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5950 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5954 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5956 SCTP_TCB_UNLOCK(stcb);
5958 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5963 case SCTP_BINDX_ADD_ADDR:
5965 struct sockaddr *sa;
5968 td = (struct thread *)p;
5969 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
5971 if (sa->sa_family == AF_INET) {
5972 if (optsize < sizeof(struct sockaddr_in)) {
5973 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5978 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
5979 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5985 if (sa->sa_family == AF_INET6) {
5986 if (optsize < sizeof(struct sockaddr_in6)) {
5987 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5992 (error = prison_local_ip6(td->td_ucred,
5993 &(((struct sockaddr_in6 *)sa)->sin6_addr),
5994 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5995 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6001 error = EAFNOSUPPORT;
6004 sctp_bindx_add_address(so, inp, sa, vrf_id, &error, p);
6007 case SCTP_BINDX_REM_ADDR:
6009 struct sockaddr *sa;
6012 td = (struct thread *)p;
6014 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
6016 if (sa->sa_family == AF_INET) {
6017 if (optsize < sizeof(struct sockaddr_in)) {
6018 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6023 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
6024 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6030 if (sa->sa_family == AF_INET6) {
6031 if (optsize < sizeof(struct sockaddr_in6)) {
6032 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6037 (error = prison_local_ip6(td->td_ucred,
6038 &(((struct sockaddr_in6 *)sa)->sin6_addr),
6039 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6040 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6046 error = EAFNOSUPPORT;
6049 sctp_bindx_delete_address(inp, sa, vrf_id, &error);
6054 struct sctp_event *event;
6055 uint32_t event_type;
6057 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6058 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6059 switch (event->se_type) {
6060 case SCTP_ASSOC_CHANGE:
6061 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6063 case SCTP_PEER_ADDR_CHANGE:
6064 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6066 case SCTP_REMOTE_ERROR:
6067 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6069 case SCTP_SEND_FAILED:
6070 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6072 case SCTP_SHUTDOWN_EVENT:
6073 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6075 case SCTP_ADAPTATION_INDICATION:
6076 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6078 case SCTP_PARTIAL_DELIVERY_EVENT:
6079 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6081 case SCTP_AUTHENTICATION_EVENT:
6082 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6084 case SCTP_STREAM_RESET_EVENT:
6085 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6087 case SCTP_SENDER_DRY_EVENT:
6088 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6090 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6092 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6095 case SCTP_ASSOC_RESET_EVENT:
6096 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6098 case SCTP_STREAM_CHANGE_EVENT:
6099 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6101 case SCTP_SEND_FAILED_EVENT:
6102 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6106 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6110 if (event_type > 0) {
6113 sctp_stcb_feature_on(inp, stcb, event_type);
6114 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6115 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6116 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6117 (stcb->asoc.stream_queue_cnt == 0)) {
6118 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6122 sctp_stcb_feature_off(inp, stcb, event_type);
6124 SCTP_TCB_UNLOCK(stcb);
6127 * We don't want to send up a storm
6128 * of events, so return an error for
6131 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6132 (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6133 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6134 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6135 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6139 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6140 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6141 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6142 ((event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6143 (event->se_assoc_id == SCTP_ALL_ASSOC)))) {
6144 SCTP_INP_WLOCK(inp);
6146 sctp_feature_on(inp, event_type);
6148 sctp_feature_off(inp, event_type);
6150 SCTP_INP_WUNLOCK(inp);
6152 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6153 ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6154 (event->se_assoc_id == SCTP_ALL_ASSOC))) {
6155 SCTP_INP_RLOCK(inp);
6156 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6157 SCTP_TCB_LOCK(stcb);
6159 sctp_stcb_feature_on(inp, stcb, event_type);
6161 sctp_stcb_feature_off(inp, stcb, event_type);
6163 SCTP_TCB_UNLOCK(stcb);
6165 SCTP_INP_RUNLOCK(inp);
6170 SCTP_TCB_UNLOCK(stcb);
6175 case SCTP_RECVRCVINFO:
6179 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6180 SCTP_INP_WLOCK(inp);
6182 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6184 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6186 SCTP_INP_WUNLOCK(inp);
6189 case SCTP_RECVNXTINFO:
6193 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6194 SCTP_INP_WLOCK(inp);
6196 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6198 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6200 SCTP_INP_WUNLOCK(inp);
6203 case SCTP_DEFAULT_SNDINFO:
6205 struct sctp_sndinfo *info;
6208 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6209 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6212 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6213 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6214 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6215 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6216 stcb->asoc.def_send.sinfo_flags |= policy;
6217 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6218 stcb->asoc.def_send.sinfo_context = info->snd_context;
6220 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6223 SCTP_TCB_UNLOCK(stcb);
6225 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6226 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6227 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6228 ((info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6229 (info->snd_assoc_id == SCTP_ALL_ASSOC)))) {
6230 SCTP_INP_WLOCK(inp);
6231 inp->def_send.sinfo_stream = info->snd_sid;
6232 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6233 inp->def_send.sinfo_flags = info->snd_flags;
6234 inp->def_send.sinfo_flags |= policy;
6235 inp->def_send.sinfo_ppid = info->snd_ppid;
6236 inp->def_send.sinfo_context = info->snd_context;
6237 SCTP_INP_WUNLOCK(inp);
6239 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6240 ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6241 (info->snd_assoc_id == SCTP_ALL_ASSOC))) {
6242 SCTP_INP_RLOCK(inp);
6243 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6244 SCTP_TCB_LOCK(stcb);
6245 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6246 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6247 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6248 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6249 stcb->asoc.def_send.sinfo_flags |= policy;
6250 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6251 stcb->asoc.def_send.sinfo_context = info->snd_context;
6253 SCTP_TCB_UNLOCK(stcb);
6255 SCTP_INP_RUNLOCK(inp);
6260 case SCTP_DEFAULT_PRINFO:
6262 struct sctp_default_prinfo *info;
6264 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6265 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6267 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6269 SCTP_TCB_UNLOCK(stcb);
6271 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6276 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6277 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6278 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6279 SCTP_TCB_UNLOCK(stcb);
6281 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6282 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6283 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6284 ((info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6285 (info->pr_assoc_id == SCTP_ALL_ASSOC)))) {
6286 SCTP_INP_WLOCK(inp);
6287 inp->def_send.sinfo_flags &= 0xfff0;
6288 inp->def_send.sinfo_flags |= info->pr_policy;
6289 inp->def_send.sinfo_timetolive = info->pr_value;
6290 SCTP_INP_WUNLOCK(inp);
6292 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6293 ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6294 (info->pr_assoc_id == SCTP_ALL_ASSOC))) {
6295 SCTP_INP_RLOCK(inp);
6296 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6297 SCTP_TCB_LOCK(stcb);
6298 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6299 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6300 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6301 SCTP_TCB_UNLOCK(stcb);
6303 SCTP_INP_RUNLOCK(inp);
6308 case SCTP_PEER_ADDR_THLDS:
6309 /* Applies to the specific association */
6311 struct sctp_paddrthlds *thlds;
6312 struct sctp_nets *net;
6313 struct sockaddr *addr;
6314 #if defined(INET) && defined(INET6)
6315 struct sockaddr_in sin_store;
6318 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6319 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6321 #if defined(INET) && defined(INET6)
6322 if (thlds->spt_address.ss_family == AF_INET6) {
6323 struct sockaddr_in6 *sin6;
6325 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6326 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6327 in6_sin6_2_sin(&sin_store, sin6);
6328 addr = (struct sockaddr *)&sin_store;
6330 addr = (struct sockaddr *)&thlds->spt_address;
6333 addr = (struct sockaddr *)&thlds->spt_address;
6336 addr = (struct sockaddr *)&thlds->spt_address;
6339 net = sctp_findnet(stcb, addr);
6342 * We increment here since
6343 * sctp_findassociation_ep_addr() wil do a
6344 * decrement if it finds the stcb as long as
6345 * the locked tcb (last argument) is NOT a
6349 SCTP_INP_INCR_REF(inp);
6350 stcb = sctp_findassociation_ep_addr(&inp, addr,
6353 SCTP_INP_DECR_REF(inp);
6356 if ((stcb != NULL) && (net == NULL)) {
6358 if (addr->sa_family == AF_INET) {
6359 struct sockaddr_in *sin;
6361 sin = (struct sockaddr_in *)addr;
6362 if (sin->sin_addr.s_addr != INADDR_ANY) {
6363 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6364 SCTP_TCB_UNLOCK(stcb);
6371 if (addr->sa_family == AF_INET6) {
6372 struct sockaddr_in6 *sin6;
6374 sin6 = (struct sockaddr_in6 *)addr;
6375 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6376 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6377 SCTP_TCB_UNLOCK(stcb);
6384 error = EAFNOSUPPORT;
6385 SCTP_TCB_UNLOCK(stcb);
6386 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6390 if (thlds->spt_pathcpthld != 0xffff) {
6392 SCTP_TCB_UNLOCK(stcb);
6395 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6400 net->failure_threshold = thlds->spt_pathmaxrxt;
6401 net->pf_threshold = thlds->spt_pathpfthld;
6402 if (net->dest_state & SCTP_ADDR_PF) {
6403 if ((net->error_count > net->failure_threshold) ||
6404 (net->error_count <= net->pf_threshold)) {
6405 net->dest_state &= ~SCTP_ADDR_PF;
6408 if ((net->error_count > net->pf_threshold) &&
6409 (net->error_count <= net->failure_threshold)) {
6410 net->dest_state |= SCTP_ADDR_PF;
6411 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6412 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6413 stcb->sctp_ep, stcb, net,
6414 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6415 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6418 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6419 if (net->error_count > net->failure_threshold) {
6420 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6421 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6424 if (net->error_count <= net->failure_threshold) {
6425 net->dest_state |= SCTP_ADDR_REACHABLE;
6426 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6430 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6431 net->failure_threshold = thlds->spt_pathmaxrxt;
6432 net->pf_threshold = thlds->spt_pathpfthld;
6433 if (net->dest_state & SCTP_ADDR_PF) {
6434 if ((net->error_count > net->failure_threshold) ||
6435 (net->error_count <= net->pf_threshold)) {
6436 net->dest_state &= ~SCTP_ADDR_PF;
6439 if ((net->error_count > net->pf_threshold) &&
6440 (net->error_count <= net->failure_threshold)) {
6441 net->dest_state |= SCTP_ADDR_PF;
6442 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6443 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6444 stcb->sctp_ep, stcb, net,
6445 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6446 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6449 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6450 if (net->error_count > net->failure_threshold) {
6451 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6452 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6455 if (net->error_count <= net->failure_threshold) {
6456 net->dest_state |= SCTP_ADDR_REACHABLE;
6457 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6461 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6462 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6464 SCTP_TCB_UNLOCK(stcb);
6466 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6467 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6468 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6469 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
6470 SCTP_INP_WLOCK(inp);
6471 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6472 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6473 SCTP_INP_WUNLOCK(inp);
6475 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6481 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6483 struct sctp_udpencaps *encaps;
6484 struct sctp_nets *net;
6485 struct sockaddr *addr;
6486 #if defined(INET) && defined(INET6)
6487 struct sockaddr_in sin_store;
6490 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6491 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6493 #if defined(INET) && defined(INET6)
6494 if (encaps->sue_address.ss_family == AF_INET6) {
6495 struct sockaddr_in6 *sin6;
6497 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6498 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6499 in6_sin6_2_sin(&sin_store, sin6);
6500 addr = (struct sockaddr *)&sin_store;
6502 addr = (struct sockaddr *)&encaps->sue_address;
6505 addr = (struct sockaddr *)&encaps->sue_address;
6508 addr = (struct sockaddr *)&encaps->sue_address;
6511 net = sctp_findnet(stcb, addr);
6514 * We increment here since
6515 * sctp_findassociation_ep_addr() wil do a
6516 * decrement if it finds the stcb as long as
6517 * the locked tcb (last argument) is NOT a
6521 SCTP_INP_INCR_REF(inp);
6522 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6524 SCTP_INP_DECR_REF(inp);
6527 if ((stcb != NULL) && (net == NULL)) {
6529 if (addr->sa_family == AF_INET) {
6530 struct sockaddr_in *sin;
6532 sin = (struct sockaddr_in *)addr;
6533 if (sin->sin_addr.s_addr != INADDR_ANY) {
6534 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6535 SCTP_TCB_UNLOCK(stcb);
6542 if (addr->sa_family == AF_INET6) {
6543 struct sockaddr_in6 *sin6;
6545 sin6 = (struct sockaddr_in6 *)addr;
6546 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6547 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6548 SCTP_TCB_UNLOCK(stcb);
6555 error = EAFNOSUPPORT;
6556 SCTP_TCB_UNLOCK(stcb);
6557 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6564 net->port = encaps->sue_port;
6566 stcb->asoc.port = encaps->sue_port;
6568 SCTP_TCB_UNLOCK(stcb);
6570 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6571 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6572 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6573 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
6574 SCTP_INP_WLOCK(inp);
6575 inp->sctp_ep.port = encaps->sue_port;
6576 SCTP_INP_WUNLOCK(inp);
6578 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6584 case SCTP_ECN_SUPPORTED:
6586 struct sctp_assoc_value *av;
6588 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6589 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6592 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6594 SCTP_TCB_UNLOCK(stcb);
6596 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6597 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6598 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6599 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6600 SCTP_INP_WLOCK(inp);
6601 if (av->assoc_value == 0) {
6602 inp->ecn_supported = 0;
6604 inp->ecn_supported = 1;
6606 SCTP_INP_WUNLOCK(inp);
6608 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6614 case SCTP_PR_SUPPORTED:
6616 struct sctp_assoc_value *av;
6618 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6619 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6624 SCTP_TCB_UNLOCK(stcb);
6626 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6627 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6628 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6629 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6630 SCTP_INP_WLOCK(inp);
6631 if (av->assoc_value == 0) {
6632 inp->prsctp_supported = 0;
6634 inp->prsctp_supported = 1;
6636 SCTP_INP_WUNLOCK(inp);
6638 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6644 case SCTP_AUTH_SUPPORTED:
6646 struct sctp_assoc_value *av;
6648 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6649 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6652 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6654 SCTP_TCB_UNLOCK(stcb);
6656 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6657 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6658 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6659 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6660 if ((av->assoc_value == 0) &&
6661 (inp->asconf_supported == 1)) {
6663 * AUTH is required for
6666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6669 SCTP_INP_WLOCK(inp);
6670 if (av->assoc_value == 0) {
6671 inp->auth_supported = 0;
6673 inp->auth_supported = 1;
6675 SCTP_INP_WUNLOCK(inp);
6678 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6684 case SCTP_ASCONF_SUPPORTED:
6686 struct sctp_assoc_value *av;
6688 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6689 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6694 SCTP_TCB_UNLOCK(stcb);
6696 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6697 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6698 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6699 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6700 if ((av->assoc_value != 0) &&
6701 (inp->auth_supported == 0)) {
6703 * AUTH is required for
6706 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6709 SCTP_INP_WLOCK(inp);
6710 if (av->assoc_value == 0) {
6711 inp->asconf_supported = 0;
6712 sctp_auth_delete_chunk(SCTP_ASCONF,
6713 inp->sctp_ep.local_auth_chunks);
6714 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6715 inp->sctp_ep.local_auth_chunks);
6717 inp->asconf_supported = 1;
6718 sctp_auth_add_chunk(SCTP_ASCONF,
6719 inp->sctp_ep.local_auth_chunks);
6720 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6721 inp->sctp_ep.local_auth_chunks);
6723 SCTP_INP_WUNLOCK(inp);
6726 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6732 case SCTP_RECONFIG_SUPPORTED:
6734 struct sctp_assoc_value *av;
6736 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6737 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6740 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6742 SCTP_TCB_UNLOCK(stcb);
6744 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6745 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6746 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6747 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6748 SCTP_INP_WLOCK(inp);
6749 if (av->assoc_value == 0) {
6750 inp->reconfig_supported = 0;
6752 inp->reconfig_supported = 1;
6754 SCTP_INP_WUNLOCK(inp);
6756 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6762 case SCTP_NRSACK_SUPPORTED:
6764 struct sctp_assoc_value *av;
6766 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6767 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6770 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6772 SCTP_TCB_UNLOCK(stcb);
6774 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6775 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6776 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6777 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6778 SCTP_INP_WLOCK(inp);
6779 if (av->assoc_value == 0) {
6780 inp->nrsack_supported = 0;
6782 inp->nrsack_supported = 1;
6784 SCTP_INP_WUNLOCK(inp);
6786 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6792 case SCTP_PKTDROP_SUPPORTED:
6794 struct sctp_assoc_value *av;
6796 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6797 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6802 SCTP_TCB_UNLOCK(stcb);
6804 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6805 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6806 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6807 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6808 SCTP_INP_WLOCK(inp);
6809 if (av->assoc_value == 0) {
6810 inp->pktdrop_supported = 0;
6812 inp->pktdrop_supported = 1;
6814 SCTP_INP_WUNLOCK(inp);
6816 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6824 struct sctp_assoc_value *av;
6825 struct sctp_nets *net;
6827 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6828 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6831 stcb->asoc.max_cwnd = av->assoc_value;
6832 if (stcb->asoc.max_cwnd > 0) {
6833 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6834 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6835 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6836 net->cwnd = stcb->asoc.max_cwnd;
6837 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6838 net->cwnd = net->mtu - sizeof(struct sctphdr);
6843 SCTP_TCB_UNLOCK(stcb);
6845 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6846 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6847 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6848 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6849 SCTP_INP_WLOCK(inp);
6850 inp->max_cwnd = av->assoc_value;
6851 SCTP_INP_WUNLOCK(inp);
6853 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6860 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6861 error = ENOPROTOOPT;
6863 } /* end switch (opt) */
6868 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6870 struct epoch_tracker et;
6871 struct sctp_inpcb *inp;
6872 void *optval = NULL;
6877 if ((sopt->sopt_level == SOL_SOCKET) &&
6878 (sopt->sopt_name == SO_SETFIB)) {
6879 inp = (struct sctp_inpcb *)so->so_pcb;
6881 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6884 SCTP_INP_WLOCK(inp);
6885 inp->fibnum = so->so_fibnum;
6886 SCTP_INP_WUNLOCK(inp);
6889 if (sopt->sopt_level != IPPROTO_SCTP) {
6890 /* wrong proto level... send back up to IP */
6892 if (INP_CHECK_SOCKAF(so, AF_INET6))
6893 error = ip6_ctloutput(so, sopt);
6895 #if defined(INET) && defined(INET6)
6899 error = ip_ctloutput(so, sopt);
6903 optsize = sopt->sopt_valsize;
6904 if (optsize > SCTP_SOCKET_OPTION_LIMIT) {
6905 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6909 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6910 if (optval == NULL) {
6911 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6914 error = sooptcopyin(sopt, optval, optsize, optsize);
6916 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6920 p = (void *)sopt->sopt_td;
6921 if (sopt->sopt_dir == SOPT_SET) {
6922 NET_EPOCH_ENTER(et);
6923 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6925 } else if (sopt->sopt_dir == SOPT_GET) {
6926 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6928 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6931 if ((error == 0) && (optval != NULL)) {
6932 error = sooptcopyout(sopt, optval, optsize);
6933 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6934 } else if (optval != NULL) {
6935 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6943 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6945 struct epoch_tracker et;
6947 int create_lock_on = 0;
6949 struct sctp_inpcb *inp;
6950 struct sctp_tcb *stcb = NULL;
6952 inp = (struct sctp_inpcb *)so->so_pcb;
6954 /* I made the same as TCP since we are not setup? */
6955 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6956 return (ECONNRESET);
6959 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6963 switch (addr->sa_family) {
6967 struct sockaddr_in6 *sin6;
6969 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6970 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6973 sin6 = (struct sockaddr_in6 *)addr;
6974 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6->sin6_addr)) != 0) {
6975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6984 struct sockaddr_in *sin;
6986 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6987 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6990 sin = (struct sockaddr_in *)addr;
6991 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sin->sin_addr)) != 0) {
6992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
7000 return (EAFNOSUPPORT);
7002 SCTP_INP_INCR_REF(inp);
7003 SCTP_ASOC_CREATE_LOCK(inp);
7005 NET_EPOCH_ENTER(et);
7007 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
7008 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
7009 /* Should I really unlock ? */
7010 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
7015 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
7016 (addr->sa_family == AF_INET6)) {
7017 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7022 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
7023 SCTP_PCB_FLAGS_UNBOUND) {
7024 /* Bind a ephemeral port */
7025 error = sctp_inpcb_bind(so, NULL, NULL, p);
7030 /* Now do we connect? */
7031 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
7032 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
7033 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7037 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7038 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7039 /* We are already connected AND the TCP model */
7040 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7044 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7045 SCTP_INP_RLOCK(inp);
7046 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7047 SCTP_INP_RUNLOCK(inp);
7050 * We increment here since sctp_findassociation_ep_addr()
7051 * will do a decrement if it finds the stcb as long as the
7052 * locked tcb (last argument) is NOT a TCB.. aka NULL.
7054 SCTP_INP_INCR_REF(inp);
7055 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7057 SCTP_INP_DECR_REF(inp);
7059 SCTP_TCB_UNLOCK(stcb);
7063 /* Already have or am bring up an association */
7064 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7069 vrf_id = inp->def_vrf_id;
7070 /* We are GOOD to go */
7071 stcb = sctp_aloc_assoc_connected(inp, addr, &error, 0, 0, vrf_id,
7072 inp->sctp_ep.pre_open_stream_count,
7073 inp->sctp_ep.port, p,
7074 SCTP_INITIALIZE_AUTH_PARAMS);
7076 /* Gak! no memory */
7079 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7080 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7082 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7083 SCTP_TCB_UNLOCK(stcb);
7086 if (create_lock_on) {
7087 SCTP_ASOC_CREATE_UNLOCK(inp);
7089 SCTP_INP_DECR_REF(inp);
7095 sctp_listen(struct socket *so, int backlog, struct thread *p)
7098 * Note this module depends on the protocol processing being called
7099 * AFTER any socket level flags and backlog are applied to the
7100 * socket. The traditional way that the socket flags are applied is
7101 * AFTER protocol processing. We have made a change to the
7102 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7103 * place if the socket API for SCTP is to work properly.
7107 struct sctp_inpcb *inp;
7109 inp = (struct sctp_inpcb *)so->so_pcb;
7111 /* I made the same as TCP since we are not setup? */
7112 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7113 return (ECONNRESET);
7115 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7116 /* See if we have a listener */
7117 struct sctp_inpcb *tinp;
7118 union sctp_sockstore store;
7120 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7122 struct sctp_laddr *laddr;
7124 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7125 memcpy(&store, &laddr->ifa->address, sizeof(store));
7126 switch (store.sa.sa_family) {
7129 store.sin.sin_port = inp->sctp_lport;
7134 store.sin6.sin6_port = inp->sctp_lport;
7140 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7141 if (tinp && (tinp != inp) &&
7142 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7143 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7144 (SCTP_IS_LISTENING(tinp))) {
7146 * we have a listener already and
7149 SCTP_INP_DECR_REF(tinp);
7150 return (EADDRINUSE);
7152 SCTP_INP_DECR_REF(tinp);
7156 /* Setup a local addr bound all */
7157 memset(&store, 0, sizeof(store));
7159 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7160 store.sa.sa_family = AF_INET6;
7161 store.sa.sa_len = sizeof(struct sockaddr_in6);
7165 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7166 store.sa.sa_family = AF_INET;
7167 store.sa.sa_len = sizeof(struct sockaddr_in);
7170 switch (store.sa.sa_family) {
7173 store.sin.sin_port = inp->sctp_lport;
7178 store.sin6.sin6_port = inp->sctp_lport;
7184 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7185 if (tinp && (tinp != inp) &&
7186 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7187 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7188 (SCTP_IS_LISTENING(tinp))) {
7190 * we have a listener already and its not
7193 SCTP_INP_DECR_REF(tinp);
7194 return (EADDRINUSE);
7196 SCTP_INP_DECR_REF(tinp);
7200 SCTP_INP_RLOCK(inp);
7201 #ifdef SCTP_LOCK_LOGGING
7202 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7203 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7207 error = solisten_proto_check(so);
7210 SCTP_INP_RUNLOCK(inp);
7213 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7214 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7216 * The unlucky case - We are in the tcp pool with this guy.
7217 * - Someone else is in the main inp slot. - We must move
7218 * this guy (the listener) to the main slot - We must then
7219 * move the guy that was listener to the TCP Pool.
7221 if (sctp_swap_inpcb_for_listen(inp)) {
7222 SCTP_INP_RUNLOCK(inp);
7223 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7224 return (EADDRINUSE);
7228 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7229 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7230 /* We are already connected AND the TCP model */
7231 SCTP_INP_RUNLOCK(inp);
7232 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7233 return (EADDRINUSE);
7235 SCTP_INP_RUNLOCK(inp);
7236 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7237 /* We must do a bind. */
7238 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7239 /* bind error, probably perm */
7243 SCTP_INP_WLOCK(inp);
7244 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7246 solisten_proto(so, backlog);
7250 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7252 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7254 SCTP_INP_WUNLOCK(inp);
7258 static int sctp_defered_wakeup_cnt = 0;
7261 sctp_accept(struct socket *so, struct sockaddr **addr)
7263 struct sctp_tcb *stcb;
7264 struct sctp_inpcb *inp;
7265 union sctp_sockstore store;
7269 inp = (struct sctp_inpcb *)so->so_pcb;
7272 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7273 return (ECONNRESET);
7275 SCTP_INP_WLOCK(inp);
7276 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7277 SCTP_INP_WUNLOCK(inp);
7278 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7279 return (EOPNOTSUPP);
7281 if (so->so_state & SS_ISDISCONNECTED) {
7282 SCTP_INP_WUNLOCK(inp);
7283 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7284 return (ECONNABORTED);
7286 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7288 SCTP_INP_WUNLOCK(inp);
7289 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7290 return (ECONNRESET);
7292 SCTP_TCB_LOCK(stcb);
7293 store = stcb->asoc.primary_destination->ro._l_addr;
7294 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7295 /* Wake any delayed sleep action */
7296 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7297 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7298 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7299 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7300 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7301 if (sowriteable(inp->sctp_socket)) {
7302 sowwakeup_locked(inp->sctp_socket);
7304 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7307 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7308 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7309 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7310 if (soreadable(inp->sctp_socket)) {
7311 sctp_defered_wakeup_cnt++;
7312 sorwakeup_locked(inp->sctp_socket);
7314 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7318 SCTP_INP_WUNLOCK(inp);
7319 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7320 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7321 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7323 SCTP_TCB_UNLOCK(stcb);
7325 switch (store.sa.sa_family) {
7329 struct sockaddr_in *sin;
7331 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7334 sin->sin_family = AF_INET;
7335 sin->sin_len = sizeof(*sin);
7336 sin->sin_port = store.sin.sin_port;
7337 sin->sin_addr = store.sin.sin_addr;
7338 *addr = (struct sockaddr *)sin;
7345 struct sockaddr_in6 *sin6;
7347 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7350 sin6->sin6_family = AF_INET6;
7351 sin6->sin6_len = sizeof(*sin6);
7352 sin6->sin6_port = store.sin6.sin6_port;
7353 sin6->sin6_addr = store.sin6.sin6_addr;
7354 if ((error = sa6_recoverscope(sin6)) != 0) {
7355 SCTP_FREE_SONAME(sin6);
7358 *addr = (struct sockaddr *)sin6;
7371 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7373 struct sockaddr_in *sin;
7375 struct sctp_inpcb *inp;
7376 struct sctp_ifa *sctp_ifa;
7379 * Do the malloc first in case it blocks.
7381 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7384 sin->sin_family = AF_INET;
7385 sin->sin_len = sizeof(*sin);
7386 inp = (struct sctp_inpcb *)so->so_pcb;
7388 SCTP_FREE_SONAME(sin);
7389 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7390 return (ECONNRESET);
7392 SCTP_INP_RLOCK(inp);
7393 sin->sin_port = inp->sctp_lport;
7394 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7395 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7396 struct sctp_tcb *stcb;
7397 struct sockaddr_in *sin_a;
7398 struct sctp_nets *net;
7401 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7407 SCTP_TCB_LOCK(stcb);
7408 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7409 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7411 /* this will make coverity happy */
7414 if (sin_a->sin_family == AF_INET) {
7419 if ((!fnd) || (sin_a == NULL)) {
7421 SCTP_TCB_UNLOCK(stcb);
7425 vrf_id = inp->def_vrf_id;
7426 sctp_ifa = sctp_source_address_selection(inp,
7428 (sctp_route_t *)&net->ro,
7431 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7432 sctp_free_ifa(sctp_ifa);
7434 SCTP_TCB_UNLOCK(stcb);
7436 /* For the bound all case you get back 0 */
7438 sin->sin_addr.s_addr = 0;
7442 /* Take the first IPv4 address in the list */
7443 struct sctp_laddr *laddr;
7446 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7447 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7448 struct sockaddr_in *sin_a;
7450 sin_a = &laddr->ifa->address.sin;
7451 sin->sin_addr = sin_a->sin_addr;
7457 SCTP_FREE_SONAME(sin);
7458 SCTP_INP_RUNLOCK(inp);
7459 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7463 SCTP_INP_RUNLOCK(inp);
7464 (*addr) = (struct sockaddr *)sin;
7469 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7471 struct sockaddr_in *sin;
7473 struct sockaddr_in *sin_a;
7474 struct sctp_inpcb *inp;
7475 struct sctp_tcb *stcb;
7476 struct sctp_nets *net;
7478 /* Do the malloc first in case it blocks. */
7479 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7482 sin->sin_family = AF_INET;
7483 sin->sin_len = sizeof(*sin);
7485 inp = (struct sctp_inpcb *)so->so_pcb;
7486 if ((inp == NULL) ||
7487 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7488 /* UDP type and listeners will drop out here */
7489 SCTP_FREE_SONAME(sin);
7490 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7493 SCTP_INP_RLOCK(inp);
7494 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7496 SCTP_TCB_LOCK(stcb);
7498 SCTP_INP_RUNLOCK(inp);
7500 SCTP_FREE_SONAME(sin);
7501 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7502 return (ECONNRESET);
7505 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7506 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7507 if (sin_a->sin_family == AF_INET) {
7509 sin->sin_port = stcb->rport;
7510 sin->sin_addr = sin_a->sin_addr;
7514 SCTP_TCB_UNLOCK(stcb);
7516 /* No IPv4 address */
7517 SCTP_FREE_SONAME(sin);
7518 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7521 (*addr) = (struct sockaddr *)sin;
7525 struct pr_usrreqs sctp_usrreqs = {
7526 .pru_abort = sctp_abort,
7527 .pru_accept = sctp_accept,
7528 .pru_attach = sctp_attach,
7529 .pru_bind = sctp_bind,
7530 .pru_connect = sctp_connect,
7531 .pru_control = in_control,
7532 .pru_close = sctp_close,
7533 .pru_detach = sctp_close,
7534 .pru_sopoll = sopoll_generic,
7535 .pru_flush = sctp_flush,
7536 .pru_disconnect = sctp_disconnect,
7537 .pru_listen = sctp_listen,
7538 .pru_peeraddr = sctp_peeraddr,
7539 .pru_send = sctp_sendm,
7540 .pru_shutdown = sctp_shutdown,
7541 .pru_sockaddr = sctp_ingetaddr,
7542 .pru_sosend = sctp_sosend,
7543 .pru_soreceive = sctp_soreceive