2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
5 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
6 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * a) Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
14 * b) Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the distribution.
18 * c) Neither the name of Cisco Systems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <netinet/sctp_os.h>
40 #include <netinet/sctp_pcb.h>
41 #include <netinet/sctp_header.h>
42 #include <netinet/sctp_var.h>
44 #include <netinet6/sctp6_var.h>
46 #include <netinet/sctp_sysctl.h>
47 #include <netinet/sctp_output.h>
48 #include <netinet/sctp_uio.h>
49 #include <netinet/sctp_asconf.h>
50 #include <netinet/sctputil.h>
51 #include <netinet/sctp_indata.h>
52 #include <netinet/sctp_timer.h>
53 #include <netinet/sctp_auth.h>
54 #include <netinet/sctp_bsd_addr.h>
55 #include <netinet/udp.h>
56 #include <sys/eventhandler.h>
58 extern const struct sctp_cc_functions sctp_cc_functions[];
59 extern const struct sctp_ss_functions sctp_ss_functions[];
66 /* Initialize and modify the sysctled variables */
68 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
69 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
71 * Allow a user to take no more than 1/2 the number of clusters or
72 * the SB_MAX, whichever is smaller, for the send window.
74 sb_max_adj = (u_long)((u_quad_t)(SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
75 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
76 (((uint32_t)nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
78 * Now for the recv window, should we take the same amount? or
79 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
80 * now I will just copy.
82 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
83 SCTP_BASE_VAR(first_time) = 0;
84 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
86 #if defined(SCTP_PACKET_LOGGING)
87 SCTP_BASE_VAR(packet_log_writers) = 0;
88 SCTP_BASE_VAR(packet_log_end) = 0;
89 memset(&SCTP_BASE_VAR(packet_log_buffer), 0, SCTP_PACKET_LOG_SIZE);
91 SCTP_BASE_VAR(eh_tag) = EVENTHANDLER_REGISTER(rt_addrmsg,
92 sctp_addr_change_event_handler, NULL, EVENTHANDLER_PRI_FIRST);
97 sctp_finish(void *unused __unused)
99 EVENTHANDLER_DEREGISTER(rt_addrmsg, SCTP_BASE_VAR(eh_tag));
103 VNET_SYSUNINIT(sctp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, sctp_finish, NULL);
107 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
109 struct sctp_tmit_chunk *chk;
112 /* Adjust that too */
113 stcb->asoc.smallest_mtu = nxtsz;
114 /* now off to subtract IP_DF flag if needed */
115 overhead = IP_HDR_SIZE + sizeof(struct sctphdr);
116 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
117 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
119 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
120 if ((chk->send_size + overhead) > nxtsz) {
121 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
124 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
125 if ((chk->send_size + overhead) > nxtsz) {
127 * For this guy we also mark for immediate resend
128 * since we sent to big of chunk
130 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
131 if (chk->sent < SCTP_DATAGRAM_RESEND) {
132 sctp_flight_size_decrease(chk);
133 sctp_total_flight_decrease(stcb, chk);
134 chk->sent = SCTP_DATAGRAM_RESEND;
135 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
136 chk->rec.data.doing_fast_retransmit = 0;
137 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
138 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
139 chk->whoTo->flight_size,
141 (uint32_t)(uintptr_t)chk->whoTo,
144 /* Clear any time so NO RTT is being done */
145 if (chk->do_rtt == 1) {
147 chk->whoTo->rto_needed = 1;
156 sctp_notify(struct sctp_inpcb *inp,
157 struct sctp_tcb *stcb,
158 struct sctp_nets *net,
166 if (icmp_type != ICMP_UNREACH) {
167 /* We only care about unreachable */
168 SCTP_TCB_UNLOCK(stcb);
171 if ((icmp_code == ICMP_UNREACH_NET) ||
172 (icmp_code == ICMP_UNREACH_HOST) ||
173 (icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
174 (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
175 (icmp_code == ICMP_UNREACH_ISOLATED) ||
176 (icmp_code == ICMP_UNREACH_NET_PROHIB) ||
177 (icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
178 (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
179 /* Mark the net unreachable. */
180 if (net->dest_state & SCTP_ADDR_REACHABLE) {
181 /* OK, that destination is NOT reachable. */
182 net->dest_state &= ~SCTP_ADDR_REACHABLE;
183 net->dest_state &= ~SCTP_ADDR_PF;
184 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
186 (void *)net, SCTP_SO_NOT_LOCKED);
188 SCTP_TCB_UNLOCK(stcb);
189 } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) ||
190 (icmp_code == ICMP_UNREACH_PORT)) {
191 /* Treat it like an ABORT. */
192 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
193 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
194 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
195 /* no need to unlock here, since the TCB is gone */
196 } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) {
197 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
198 SCTP_TCB_UNLOCK(stcb);
201 /* Find the next (smaller) MTU */
204 * Old type router that does not tell us what the
205 * next MTU is. Rats we will have to guess (in a
206 * educated fashion of course).
208 next_mtu = sctp_get_prev_mtu(ip_len);
210 /* Stop the PMTU timer. */
211 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
213 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
214 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
218 /* Update the path MTU. */
220 next_mtu -= sizeof(struct udphdr);
222 if (net->mtu > next_mtu) {
225 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu + sizeof(struct udphdr));
227 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu);
230 /* Update the association MTU */
231 if (stcb->asoc.smallest_mtu > next_mtu) {
232 sctp_pathmtu_adjustment(stcb, next_mtu);
234 /* Finally, start the PMTU timer if it was running before. */
236 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
238 SCTP_TCB_UNLOCK(stcb);
240 SCTP_TCB_UNLOCK(stcb);
245 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
251 struct sctp_inpcb *inp;
252 struct sctp_tcb *stcb;
253 struct sctp_nets *net;
254 struct sctp_init_chunk *ch;
255 struct sockaddr_in src, dst;
257 if (sa->sa_family != AF_INET ||
258 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
261 if (PRC_IS_REDIRECT(cmd)) {
263 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
267 inner_ip = (struct ip *)vip;
268 icmp = (struct icmp *)((caddr_t)inner_ip -
269 (sizeof(struct icmp) - sizeof(struct ip)));
270 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
271 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
272 memset(&src, 0, sizeof(struct sockaddr_in));
273 src.sin_family = AF_INET;
274 src.sin_len = sizeof(struct sockaddr_in);
275 src.sin_port = sh->src_port;
276 src.sin_addr = inner_ip->ip_src;
277 memset(&dst, 0, sizeof(struct sockaddr_in));
278 dst.sin_family = AF_INET;
279 dst.sin_len = sizeof(struct sockaddr_in);
280 dst.sin_port = sh->dest_port;
281 dst.sin_addr = inner_ip->ip_dst;
283 * 'dst' holds the dest of the packet that failed to be
284 * sent. 'src' holds our local endpoint address. Thus we
285 * reverse the dst and the src in the lookup.
289 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
290 (struct sockaddr *)&src,
293 if ((stcb != NULL) &&
296 /* Check the verification tag */
297 if (ntohl(sh->v_tag) != 0) {
299 * This must be the verification tag used
300 * for sending out packets. We don't
301 * consider packets reflecting the
304 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
305 SCTP_TCB_UNLOCK(stcb);
309 if (ntohs(outer_ip->ip_len) >=
311 8 + (inner_ip->ip_hl << 2) + 20) {
313 * In this case we can check if we
314 * got an INIT chunk and if the
315 * initiate tag matches.
317 ch = (struct sctp_init_chunk *)(sh + 1);
318 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
319 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
320 SCTP_TCB_UNLOCK(stcb);
324 SCTP_TCB_UNLOCK(stcb);
328 sctp_notify(inp, stcb, net,
331 ntohs(inner_ip->ip_len),
332 (uint32_t)ntohs(icmp->icmp_nextmtu));
334 if ((stcb == NULL) && (inp != NULL)) {
335 /* reduce ref-count */
337 SCTP_INP_DECR_REF(inp);
338 SCTP_INP_WUNLOCK(inp);
341 SCTP_TCB_UNLOCK(stcb);
350 sctp_getcred(SYSCTL_HANDLER_ARGS)
353 struct sockaddr_in addrs[2];
354 struct sctp_inpcb *inp;
355 struct sctp_nets *net;
356 struct sctp_tcb *stcb;
360 /* FIX, for non-bsd is this right? */
361 vrf_id = SCTP_DEFAULT_VRFID;
363 error = priv_check(req->td, PRIV_NETINET_GETCRED);
368 error = SYSCTL_IN(req, addrs, sizeof(addrs));
372 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
374 &inp, &net, 1, vrf_id);
375 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
376 if ((inp != NULL) && (stcb == NULL)) {
377 /* reduce ref-count */
379 SCTP_INP_DECR_REF(inp);
383 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
387 SCTP_TCB_UNLOCK(stcb);
389 * We use the write lock here, only since in the error leg we need
390 * it. If we used RLOCK, then we would have to
391 * wlock/decr/unlock/rlock. Which in theory could create a hole.
392 * Better to use higher wlock.
396 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
398 SCTP_INP_WUNLOCK(inp);
401 cru2x(inp->sctp_socket->so_cred, &xuc);
402 SCTP_INP_WUNLOCK(inp);
403 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
408 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred,
409 CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
410 0, 0, sctp_getcred, "S,ucred",
411 "Get the ucred of a SCTP connection");
415 sctp_abort(struct socket *so)
417 struct epoch_tracker et;
418 struct sctp_inpcb *inp;
421 inp = (struct sctp_inpcb *)so->so_pcb;
428 flags = inp->sctp_flags;
429 #ifdef SCTP_LOG_CLOSING
430 sctp_log_closing(inp, NULL, 17);
432 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
433 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
434 #ifdef SCTP_LOG_CLOSING
435 sctp_log_closing(inp, NULL, 16);
437 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
438 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
440 SCTP_SB_CLEAR(so->so_snd);
442 * same for the rcv ones, they are only here for the
445 SCTP_SB_CLEAR(so->so_rcv);
447 /* Now null out the reference, we are completely detached. */
451 flags = inp->sctp_flags;
452 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
453 goto sctp_must_try_again;
461 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
463 struct sctp_inpcb *inp;
464 struct inpcb *ip_inp;
466 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
468 inp = (struct sctp_inpcb *)so->so_pcb;
470 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
473 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
474 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
479 error = sctp_inpcb_alloc(so, vrf_id);
483 inp = (struct sctp_inpcb *)so->so_pcb;
485 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
486 ip_inp = &inp->ip_inp.inp;
487 ip_inp->inp_vflag |= INP_IPV4;
488 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
489 SCTP_INP_WUNLOCK(inp);
494 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
496 struct sctp_inpcb *inp;
498 inp = (struct sctp_inpcb *)so->so_pcb;
500 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
504 if ((addr->sa_family != AF_INET) ||
505 (addr->sa_len != sizeof(struct sockaddr_in))) {
506 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
510 return (sctp_inpcb_bind(so, addr, NULL, p));
515 sctp_close(struct socket *so)
517 struct epoch_tracker et;
518 struct sctp_inpcb *inp;
521 inp = (struct sctp_inpcb *)so->so_pcb;
526 * Inform all the lower layer assoc that we are done.
530 flags = inp->sctp_flags;
531 #ifdef SCTP_LOG_CLOSING
532 sctp_log_closing(inp, NULL, 17);
534 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
535 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
536 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
537 (so->so_rcv.sb_cc > 0)) {
538 #ifdef SCTP_LOG_CLOSING
539 sctp_log_closing(inp, NULL, 13);
541 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
542 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
544 #ifdef SCTP_LOG_CLOSING
545 sctp_log_closing(inp, NULL, 14);
547 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
548 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
551 * The socket is now detached, no matter what the state of
552 * the SCTP association.
555 SCTP_SB_CLEAR(so->so_snd);
557 * same for the rcv ones, they are only here for the
560 SCTP_SB_CLEAR(so->so_rcv);
562 /* Now null out the reference, we are completely detached. */
566 flags = inp->sctp_flags;
567 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
568 goto sctp_must_try_again;
576 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
577 struct mbuf *control, struct thread *p);
580 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
581 struct mbuf *control, struct thread *p)
583 struct sctp_inpcb *inp;
586 inp = (struct sctp_inpcb *)so->so_pcb;
589 sctp_m_freem(control);
592 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
596 /* Got to have an to address if we are NOT a connected socket */
597 if ((addr == NULL) &&
598 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
599 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
605 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
606 error = EDESTADDRREQ;
607 } else if (addr->sa_family != AF_INET) {
608 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
609 error = EAFNOSUPPORT;
610 } else if (addr->sa_len != sizeof(struct sockaddr_in)) {
611 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
617 sctp_m_freem(control);
623 /* now what about control */
626 sctp_m_freem(inp->control);
629 inp->control = control;
633 SCTP_BUF_NEXT(inp->pkt_last) = m;
636 inp->pkt_last = inp->pkt = m;
639 /* FreeBSD uses a flag passed */
640 ((flags & PRUS_MORETOCOME) == 0)
643 * note with the current version this code will only be used
644 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
645 * re-defining sosend to use the sctp_sosend. One can
646 * optionally switch back to this code (by changing back the
647 * definitions) but this is not advisable. This code is used
648 * by FreeBSD when sending a file with sendfile() though.
650 struct epoch_tracker et;
654 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
665 sctp_disconnect(struct socket *so)
667 struct sctp_inpcb *inp;
669 inp = (struct sctp_inpcb *)so->so_pcb;
671 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
675 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
676 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
677 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
679 SCTP_INP_RUNLOCK(inp);
682 struct epoch_tracker et;
683 struct sctp_association *asoc;
684 struct sctp_tcb *stcb;
686 stcb = LIST_FIRST(&inp->sctp_asoc_list);
688 SCTP_INP_RUNLOCK(inp);
689 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
694 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
695 /* We are about to be freed, out of here */
696 SCTP_TCB_UNLOCK(stcb);
697 SCTP_INP_RUNLOCK(inp);
701 if (((so->so_options & SO_LINGER) &&
702 (so->so_linger == 0)) ||
703 (so->so_rcv.sb_cc > 0)) {
704 if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) {
705 /* Left with Data unread */
708 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
709 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
710 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
712 SCTP_INP_RUNLOCK(inp);
713 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
714 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
715 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
717 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
718 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
719 /* No unlock tcb assoc is gone */
723 if (TAILQ_EMPTY(&asoc->send_queue) &&
724 TAILQ_EMPTY(&asoc->sent_queue) &&
725 (asoc->stream_queue_cnt == 0)) {
726 /* there is nothing queued to send, so done */
727 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
730 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) &&
731 (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
732 /* only send SHUTDOWN 1st time thru */
733 struct sctp_nets *netp;
735 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
736 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
737 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
739 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
740 sctp_stop_timers_for_shutdown(stcb);
741 if (stcb->asoc.alternate) {
742 netp = stcb->asoc.alternate;
744 netp = stcb->asoc.primary_destination;
746 sctp_send_shutdown(stcb, netp);
747 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
748 stcb->sctp_ep, stcb, netp);
749 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
750 stcb->sctp_ep, stcb, NULL);
751 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
755 * we still got (or just got) data to send,
756 * so set SHUTDOWN_PENDING
759 * XXX sockets draft says that SCTP_EOF
760 * should be sent with no data. currently,
761 * we will allow user data to be sent first
762 * and move to SHUTDOWN-PENDING
764 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
765 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
766 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
767 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
769 if (TAILQ_EMPTY(&asoc->send_queue) &&
770 TAILQ_EMPTY(&asoc->sent_queue) &&
771 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
775 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
776 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
777 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
778 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
779 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
780 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
781 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
783 SCTP_INP_RUNLOCK(inp);
784 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
785 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
789 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
792 soisdisconnecting(so);
794 SCTP_TCB_UNLOCK(stcb);
795 SCTP_INP_RUNLOCK(inp);
800 /* UDP model does not support this */
801 SCTP_INP_RUNLOCK(inp);
802 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
808 sctp_flush(struct socket *so, int how)
811 * We will just clear out the values and let subsequent close clear
812 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
813 * they will not be able to read the data, the socket will block
814 * that from happening.
816 struct sctp_inpcb *inp;
818 inp = (struct sctp_inpcb *)so->so_pcb;
820 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
824 /* For the 1 to many model this does nothing */
825 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
826 SCTP_INP_RUNLOCK(inp);
829 SCTP_INP_RUNLOCK(inp);
830 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
832 * First make sure the sb will be happy, we don't use these
833 * except maybe the count
836 SCTP_INP_READ_LOCK(inp);
837 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
838 SCTP_INP_READ_UNLOCK(inp);
839 SCTP_INP_WUNLOCK(inp);
840 so->so_rcv.sb_cc = 0;
841 so->so_rcv.sb_mbcnt = 0;
842 so->so_rcv.sb_mb = NULL;
844 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
846 * First make sure the sb will be happy, we don't use these
847 * except maybe the count
849 so->so_snd.sb_cc = 0;
850 so->so_snd.sb_mbcnt = 0;
851 so->so_snd.sb_mb = NULL;
857 sctp_shutdown(struct socket *so)
859 struct sctp_inpcb *inp;
861 inp = (struct sctp_inpcb *)so->so_pcb;
863 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
867 /* For UDP model this is a invalid call */
868 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
869 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
870 /* Restore the flags that the soshutdown took away. */
871 SOCKBUF_LOCK(&so->so_rcv);
872 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
873 SOCKBUF_UNLOCK(&so->so_rcv);
874 /* This proc will wakeup for read and do nothing (I hope) */
875 SCTP_INP_RUNLOCK(inp);
876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
880 * Ok, if we reach here its the TCP model and it is either a
881 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
884 struct epoch_tracker et;
885 struct sctp_tcb *stcb;
886 struct sctp_association *asoc;
887 struct sctp_nets *netp;
890 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
891 SCTP_INP_RUNLOCK(inp);
896 stcb = LIST_FIRST(&inp->sctp_asoc_list);
899 * Ok, we hit the case that the shutdown call was
900 * made after an abort or something. Nothing to do
903 SCTP_INP_RUNLOCK(inp);
908 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
909 SCTP_TCB_UNLOCK(stcb);
910 SCTP_INP_RUNLOCK(inp);
913 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) &&
914 (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) &&
915 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) {
917 * If we are not in or before ESTABLISHED, there is
918 * no protocol action required.
920 SCTP_TCB_UNLOCK(stcb);
921 SCTP_INP_RUNLOCK(inp);
925 if (stcb->asoc.alternate) {
926 netp = stcb->asoc.alternate;
928 netp = stcb->asoc.primary_destination;
930 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) &&
931 TAILQ_EMPTY(&asoc->send_queue) &&
932 TAILQ_EMPTY(&asoc->sent_queue) &&
933 (asoc->stream_queue_cnt == 0)) {
934 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
937 /* there is nothing queued to send, so I'm done... */
938 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
939 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
940 sctp_stop_timers_for_shutdown(stcb);
941 sctp_send_shutdown(stcb, netp);
942 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
943 stcb->sctp_ep, stcb, netp);
946 * We still got (or just got) data to send, so set
949 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
950 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
951 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
953 if (TAILQ_EMPTY(&asoc->send_queue) &&
954 TAILQ_EMPTY(&asoc->sent_queue) &&
955 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
959 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
960 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
961 SCTP_INP_RUNLOCK(inp);
962 sctp_abort_an_association(stcb->sctp_ep, stcb,
963 op_err, SCTP_SO_LOCKED);
968 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
970 * XXX: Why do this in the case where we have still data
973 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
974 SCTP_TCB_UNLOCK(stcb);
975 SCTP_INP_RUNLOCK(inp);
982 * copies a "user" presentable address and removes embedded scope, etc.
983 * returns 0 on success, 1 on error
986 sctp_fill_user_address(struct sockaddr *dst, struct sockaddr *src)
989 struct sockaddr_in6 lsa6;
991 src = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)src,
994 memcpy(dst, src, src->sa_len);
999 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1000 struct sctp_tcb *stcb,
1002 struct sockaddr *addr,
1005 struct sctp_ifn *sctp_ifn;
1006 struct sctp_ifa *sctp_ifa;
1010 int ipv4_local_scope, ipv4_addr_legal;
1013 int local_scope, site_scope, ipv6_addr_legal;
1015 struct sctp_vrf *vrf;
1017 SCTP_IPI_ADDR_LOCK_ASSERT();
1023 /* Turn on all the appropriate scope */
1024 loopback_scope = stcb->asoc.scope.loopback_scope;
1026 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1027 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1030 local_scope = stcb->asoc.scope.local_scope;
1031 site_scope = stcb->asoc.scope.site_scope;
1032 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1035 /* Use generic values for endpoints. */
1038 ipv4_local_scope = 1;
1044 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1046 ipv6_addr_legal = 1;
1049 if (SCTP_IPV6_V6ONLY(inp)) {
1050 ipv4_addr_legal = 0;
1052 ipv4_addr_legal = 1;
1057 ipv6_addr_legal = 0;
1060 ipv4_addr_legal = 1;
1064 vrf = sctp_find_vrf(vrf_id);
1068 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1069 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1070 if ((loopback_scope == 0) &&
1071 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1072 /* Skip loopback if loopback_scope not set */
1075 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1078 * For the BOUND-ALL case, the list
1079 * associated with a TCB is Always
1080 * considered a reverse list.. i.e.
1081 * it lists addresses that are NOT
1082 * part of the association. If this
1083 * is one of those we must skip it.
1085 if (sctp_is_addr_restricted(stcb,
1090 switch (sctp_ifa->address.sa.sa_family) {
1093 if (ipv4_addr_legal) {
1094 struct sockaddr_in *sin;
1096 sin = &sctp_ifa->address.sin;
1097 if (sin->sin_addr.s_addr == 0) {
1105 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1106 &sin->sin_addr) != 0) {
1109 if ((ipv4_local_scope == 0) &&
1110 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1114 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1115 if (actual + sizeof(struct sockaddr_in6) > limit) {
1118 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)addr);
1119 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1120 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1121 actual += sizeof(struct sockaddr_in6);
1124 if (actual + sizeof(struct sockaddr_in) > limit) {
1127 memcpy(addr, sin, sizeof(struct sockaddr_in));
1128 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1129 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in));
1130 actual += sizeof(struct sockaddr_in);
1141 if (ipv6_addr_legal) {
1142 struct sockaddr_in6 *sin6;
1144 sin6 = &sctp_ifa->address.sin6;
1145 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1153 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1154 &sin6->sin6_addr) != 0) {
1157 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1158 if (local_scope == 0)
1160 if (sin6->sin6_scope_id == 0) {
1161 if (sa6_recoverscope(sin6) != 0)
1174 if ((site_scope == 0) &&
1175 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1178 if (actual + sizeof(struct sockaddr_in6) > limit) {
1181 memcpy(addr, sin6, sizeof(struct sockaddr_in6));
1182 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1183 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1184 actual += sizeof(struct sockaddr_in6);
1197 struct sctp_laddr *laddr;
1200 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1202 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1206 sa_len = laddr->ifa->address.sa.sa_len;
1207 if (actual + sa_len > limit) {
1210 if (sctp_fill_user_address(addr, &laddr->ifa->address.sa))
1212 switch (laddr->ifa->address.sa.sa_family) {
1215 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1220 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1227 addr = (struct sockaddr *)((caddr_t)addr + sa_len);
1235 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1236 struct sctp_tcb *stcb,
1238 struct sockaddr *addr)
1242 SCTP_IPI_ADDR_RLOCK();
1243 /* fill up addresses for the endpoint's default vrf */
1244 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, addr,
1246 SCTP_IPI_ADDR_RUNLOCK();
1251 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1254 struct sctp_vrf *vrf = NULL;
1257 * In both sub-set bound an bound_all cases we return the MAXIMUM
1258 * number of addresses that you COULD get. In reality the sub-set
1259 * bound may have an exclusion list for a given TCB OR in the
1260 * bound-all case a TCB may NOT include the loopback or other
1261 * addresses as well.
1263 SCTP_IPI_ADDR_LOCK_ASSERT();
1264 vrf = sctp_find_vrf(vrf_id);
1268 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1269 struct sctp_ifn *sctp_ifn;
1270 struct sctp_ifa *sctp_ifa;
1272 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1273 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1274 /* Count them if they are the right type */
1275 switch (sctp_ifa->address.sa.sa_family) {
1279 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1280 cnt += sizeof(struct sockaddr_in6);
1282 cnt += sizeof(struct sockaddr_in);
1284 cnt += sizeof(struct sockaddr_in);
1290 cnt += sizeof(struct sockaddr_in6);
1299 struct sctp_laddr *laddr;
1301 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1302 switch (laddr->ifa->address.sa.sa_family) {
1306 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1307 cnt += sizeof(struct sockaddr_in6);
1309 cnt += sizeof(struct sockaddr_in);
1311 cnt += sizeof(struct sockaddr_in);
1317 cnt += sizeof(struct sockaddr_in6);
1329 sctp_count_max_addresses(struct sctp_inpcb *inp)
1333 SCTP_IPI_ADDR_RLOCK();
1334 /* count addresses for the endpoint's default VRF */
1335 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1336 SCTP_IPI_ADDR_RUNLOCK();
1341 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1342 size_t optsize, void *p, int delay)
1345 int creat_lock_on = 0;
1346 struct sctp_tcb *stcb = NULL;
1347 struct sockaddr *sa;
1348 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1352 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1354 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1355 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1356 /* We are already connected AND the TCP model */
1357 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1358 return (EADDRINUSE);
1361 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1362 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1363 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1367 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1368 SCTP_INP_RLOCK(inp);
1369 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1370 SCTP_INP_RUNLOCK(inp);
1373 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1376 SCTP_INP_INCR_REF(inp);
1377 SCTP_ASOC_CREATE_LOCK(inp);
1379 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1380 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1381 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1385 totaddrp = (unsigned int *)optval;
1386 totaddr = *totaddrp;
1387 sa = (struct sockaddr *)(totaddrp + 1);
1388 error = sctp_connectx_helper_find(inp, sa, totaddr, &num_v4, &num_v6, (unsigned int)(optsize - sizeof(int)));
1390 /* Already have or am bring up an association */
1391 SCTP_ASOC_CREATE_UNLOCK(inp);
1393 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1397 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1402 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1404 if (SCTP_IPV6_V6ONLY(inp)) {
1406 * if IPV6_V6ONLY flag, ignore connections destined
1407 * to a v4 addr or v4-mapped addr
1409 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1415 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1416 SCTP_PCB_FLAGS_UNBOUND) {
1417 /* Bind a ephemeral port */
1418 error = sctp_inpcb_bind(so, NULL, NULL, p);
1424 /* FIX ME: do we want to pass in a vrf on the connect call? */
1425 vrf_id = inp->def_vrf_id;
1427 /* We are GOOD to go */
1428 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1429 inp->sctp_ep.pre_open_stream_count,
1432 SCTP_INITIALIZE_AUTH_PARAMS);
1434 /* Gak! no memory */
1437 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1438 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1439 /* Set the connected flag so we can queue data */
1442 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1443 /* move to second address */
1444 switch (sa->sa_family) {
1447 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1452 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1460 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1461 /* Fill in the return id */
1465 a_id = (sctp_assoc_t *)optval;
1466 *a_id = sctp_get_associd(stcb);
1469 /* doing delayed connection */
1470 stcb->asoc.delayed_connection = 1;
1471 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1473 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1474 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1476 SCTP_TCB_UNLOCK(stcb);
1478 if (creat_lock_on) {
1479 SCTP_ASOC_CREATE_UNLOCK(inp);
1481 SCTP_INP_DECR_REF(inp);
1485 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1486 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1487 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1488 SCTP_INP_RLOCK(inp); \
1489 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1491 SCTP_TCB_LOCK(stcb); \
1493 SCTP_INP_RUNLOCK(inp); \
1494 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1495 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1496 if (stcb == NULL) { \
1497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1506 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1507 if (size < sizeof(type)) { \
1508 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1512 destp = (type *)srcp; \
1517 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1520 struct sctp_inpcb *inp = NULL;
1522 struct sctp_tcb *stcb = NULL;
1524 if (optval == NULL) {
1525 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1529 inp = (struct sctp_inpcb *)so->so_pcb;
1531 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1538 case SCTP_AUTOCLOSE:
1539 case SCTP_EXPLICIT_EOR:
1540 case SCTP_AUTO_ASCONF:
1541 case SCTP_DISABLE_FRAGMENTS:
1542 case SCTP_I_WANT_MAPPED_V4_ADDR:
1543 case SCTP_USE_EXT_RCVINFO:
1544 SCTP_INP_RLOCK(inp);
1546 case SCTP_DISABLE_FRAGMENTS:
1547 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1549 case SCTP_I_WANT_MAPPED_V4_ADDR:
1550 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1552 case SCTP_AUTO_ASCONF:
1553 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1554 /* only valid for bound all sockets */
1555 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1557 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1562 case SCTP_EXPLICIT_EOR:
1563 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1566 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1568 case SCTP_USE_EXT_RCVINFO:
1569 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1571 case SCTP_AUTOCLOSE:
1572 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1573 val = sctp_ticks_to_secs(inp->sctp_ep.auto_close_time);
1579 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1580 error = ENOPROTOOPT;
1581 } /* end switch (sopt->sopt_name) */
1582 if (*optsize < sizeof(val)) {
1583 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1587 SCTP_INP_RUNLOCK(inp);
1589 /* return the option value */
1590 *(int *)optval = val;
1591 *optsize = sizeof(val);
1594 case SCTP_GET_PACKET_LOG:
1596 #ifdef SCTP_PACKET_LOGGING
1600 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1601 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1604 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1609 case SCTP_REUSE_PORT:
1613 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1614 /* Can't do this for a 1-m socket */
1618 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1619 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1620 *optsize = sizeof(uint32_t);
1623 case SCTP_PARTIAL_DELIVERY_POINT:
1627 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1628 *value = inp->partial_delivery_point;
1629 *optsize = sizeof(uint32_t);
1632 case SCTP_FRAGMENT_INTERLEAVE:
1636 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1637 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1638 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1639 *value = SCTP_FRAG_LEVEL_2;
1641 *value = SCTP_FRAG_LEVEL_1;
1644 *value = SCTP_FRAG_LEVEL_0;
1646 *optsize = sizeof(uint32_t);
1649 case SCTP_INTERLEAVING_SUPPORTED:
1651 struct sctp_assoc_value *av;
1653 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1654 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1657 av->assoc_value = stcb->asoc.idata_supported;
1658 SCTP_TCB_UNLOCK(stcb);
1660 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1661 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1662 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1663 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1664 SCTP_INP_RLOCK(inp);
1665 if (inp->idata_supported) {
1666 av->assoc_value = 1;
1668 av->assoc_value = 0;
1670 SCTP_INP_RUNLOCK(inp);
1672 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1677 *optsize = sizeof(struct sctp_assoc_value);
1681 case SCTP_CMT_ON_OFF:
1683 struct sctp_assoc_value *av;
1685 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1686 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1688 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1689 SCTP_TCB_UNLOCK(stcb);
1691 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1692 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1693 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1694 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1695 SCTP_INP_RLOCK(inp);
1696 av->assoc_value = inp->sctp_cmt_on_off;
1697 SCTP_INP_RUNLOCK(inp);
1699 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1704 *optsize = sizeof(struct sctp_assoc_value);
1708 case SCTP_PLUGGABLE_CC:
1710 struct sctp_assoc_value *av;
1712 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1713 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1715 av->assoc_value = stcb->asoc.congestion_control_module;
1716 SCTP_TCB_UNLOCK(stcb);
1718 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1719 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1720 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1721 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1722 SCTP_INP_RLOCK(inp);
1723 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1724 SCTP_INP_RUNLOCK(inp);
1726 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1731 *optsize = sizeof(struct sctp_assoc_value);
1735 case SCTP_CC_OPTION:
1737 struct sctp_cc_option *cc_opt;
1739 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1740 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1744 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1747 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1748 *optsize = sizeof(struct sctp_cc_option);
1750 SCTP_TCB_UNLOCK(stcb);
1754 case SCTP_PLUGGABLE_SS:
1756 struct sctp_assoc_value *av;
1758 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1759 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1761 av->assoc_value = stcb->asoc.stream_scheduling_module;
1762 SCTP_TCB_UNLOCK(stcb);
1764 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1765 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1766 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1767 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1768 SCTP_INP_RLOCK(inp);
1769 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1770 SCTP_INP_RUNLOCK(inp);
1772 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1777 *optsize = sizeof(struct sctp_assoc_value);
1783 struct sctp_stream_value *av;
1785 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1786 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1788 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1789 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1790 &av->stream_value) < 0)) {
1791 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1794 *optsize = sizeof(struct sctp_stream_value);
1796 SCTP_TCB_UNLOCK(stcb);
1799 * Can't get stream value without
1802 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1807 case SCTP_GET_ADDR_LEN:
1809 struct sctp_assoc_value *av;
1811 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1814 if (av->assoc_value == AF_INET) {
1815 av->assoc_value = sizeof(struct sockaddr_in);
1820 if (av->assoc_value == AF_INET6) {
1821 av->assoc_value = sizeof(struct sockaddr_in6);
1826 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1828 *optsize = sizeof(struct sctp_assoc_value);
1832 case SCTP_GET_ASSOC_NUMBER:
1834 uint32_t *value, cnt;
1836 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1837 SCTP_INP_RLOCK(inp);
1838 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1839 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1840 /* Can't do this for a 1-1 socket */
1842 SCTP_INP_RUNLOCK(inp);
1846 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1849 SCTP_INP_RUNLOCK(inp);
1851 *optsize = sizeof(uint32_t);
1854 case SCTP_GET_ASSOC_ID_LIST:
1856 struct sctp_assoc_ids *ids;
1860 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1861 SCTP_INP_RLOCK(inp);
1862 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1863 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1864 /* Can't do this for a 1-1 socket */
1866 SCTP_INP_RUNLOCK(inp);
1870 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1871 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1873 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1885 SCTP_INP_RUNLOCK(inp);
1887 ids->gaids_number_of_ids = at;
1888 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1894 struct sctp_assoc_value *av;
1896 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1897 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1900 av->assoc_value = stcb->asoc.context;
1901 SCTP_TCB_UNLOCK(stcb);
1903 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1904 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1905 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1906 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1907 SCTP_INP_RLOCK(inp);
1908 av->assoc_value = inp->sctp_context;
1909 SCTP_INP_RUNLOCK(inp);
1911 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1916 *optsize = sizeof(struct sctp_assoc_value);
1922 uint32_t *default_vrfid;
1924 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1925 *default_vrfid = inp->def_vrf_id;
1926 *optsize = sizeof(uint32_t);
1929 case SCTP_GET_ASOC_VRF:
1931 struct sctp_assoc_value *id;
1933 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1934 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1937 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1939 id->assoc_value = stcb->asoc.vrf_id;
1940 SCTP_TCB_UNLOCK(stcb);
1941 *optsize = sizeof(struct sctp_assoc_value);
1945 case SCTP_GET_VRF_IDS:
1947 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1951 case SCTP_GET_NONCE_VALUES:
1953 struct sctp_get_nonce_values *gnv;
1955 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1956 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1959 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1960 gnv->gn_local_tag = stcb->asoc.my_vtag;
1961 SCTP_TCB_UNLOCK(stcb);
1962 *optsize = sizeof(struct sctp_get_nonce_values);
1964 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1969 case SCTP_DELAYED_SACK:
1971 struct sctp_sack_info *sack;
1973 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1974 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1976 sack->sack_delay = stcb->asoc.delayed_ack;
1977 sack->sack_freq = stcb->asoc.sack_freq;
1978 SCTP_TCB_UNLOCK(stcb);
1980 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1981 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1982 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1983 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC))) {
1984 SCTP_INP_RLOCK(inp);
1985 sack->sack_delay = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1986 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
1987 SCTP_INP_RUNLOCK(inp);
1989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1994 *optsize = sizeof(struct sctp_sack_info);
1998 case SCTP_GET_SNDBUF_USE:
2000 struct sctp_sockstat *ss;
2002 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2003 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2006 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2007 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2008 stcb->asoc.size_on_all_streams);
2009 SCTP_TCB_UNLOCK(stcb);
2010 *optsize = sizeof(struct sctp_sockstat);
2012 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2017 case SCTP_MAX_BURST:
2019 struct sctp_assoc_value *av;
2021 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2022 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2025 av->assoc_value = stcb->asoc.max_burst;
2026 SCTP_TCB_UNLOCK(stcb);
2028 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2029 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2030 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2031 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2032 SCTP_INP_RLOCK(inp);
2033 av->assoc_value = inp->sctp_ep.max_burst;
2034 SCTP_INP_RUNLOCK(inp);
2036 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2041 *optsize = sizeof(struct sctp_assoc_value);
2047 struct sctp_assoc_value *av;
2050 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2051 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2054 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2055 SCTP_TCB_UNLOCK(stcb);
2057 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2058 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2059 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2060 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2061 SCTP_INP_RLOCK(inp);
2062 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2063 ovh = SCTP_MED_OVERHEAD;
2065 ovh = SCTP_MED_V4_OVERHEAD;
2067 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2068 av->assoc_value = 0;
2070 av->assoc_value = inp->sctp_frag_point - ovh;
2071 SCTP_INP_RUNLOCK(inp);
2073 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2078 *optsize = sizeof(struct sctp_assoc_value);
2082 case SCTP_GET_STAT_LOG:
2083 error = sctp_fill_stat_log(optval, optsize);
2087 struct sctp_event_subscribe *events;
2089 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2090 memset(events, 0, sizeof(struct sctp_event_subscribe));
2091 SCTP_INP_RLOCK(inp);
2092 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2093 events->sctp_data_io_event = 1;
2095 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2096 events->sctp_association_event = 1;
2098 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2099 events->sctp_address_event = 1;
2101 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2102 events->sctp_send_failure_event = 1;
2104 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2105 events->sctp_peer_error_event = 1;
2107 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2108 events->sctp_shutdown_event = 1;
2110 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2111 events->sctp_partial_delivery_event = 1;
2113 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2114 events->sctp_adaptation_layer_event = 1;
2116 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2117 events->sctp_authentication_event = 1;
2119 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2120 events->sctp_sender_dry_event = 1;
2122 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2123 events->sctp_stream_reset_event = 1;
2124 SCTP_INP_RUNLOCK(inp);
2125 *optsize = sizeof(struct sctp_event_subscribe);
2128 case SCTP_ADAPTATION_LAYER:
2132 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2134 SCTP_INP_RLOCK(inp);
2135 *value = inp->sctp_ep.adaptation_layer_indicator;
2136 SCTP_INP_RUNLOCK(inp);
2137 *optsize = sizeof(uint32_t);
2140 case SCTP_SET_INITIAL_DBG_SEQ:
2144 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2145 SCTP_INP_RLOCK(inp);
2146 *value = inp->sctp_ep.initial_sequence_debug;
2147 SCTP_INP_RUNLOCK(inp);
2148 *optsize = sizeof(uint32_t);
2151 case SCTP_GET_LOCAL_ADDR_SIZE:
2155 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2156 SCTP_INP_RLOCK(inp);
2157 *value = sctp_count_max_addresses(inp);
2158 SCTP_INP_RUNLOCK(inp);
2159 *optsize = sizeof(uint32_t);
2162 case SCTP_GET_REMOTE_ADDR_SIZE:
2166 struct sctp_nets *net;
2168 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2169 /* FIXME MT: change to sctp_assoc_value? */
2170 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2174 /* Count the sizes */
2175 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2176 switch (net->ro._l_addr.sa.sa_family) {
2180 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2181 size += sizeof(struct sockaddr_in6);
2183 size += sizeof(struct sockaddr_in);
2186 size += sizeof(struct sockaddr_in);
2192 size += sizeof(struct sockaddr_in6);
2199 SCTP_TCB_UNLOCK(stcb);
2200 *value = (uint32_t)size;
2201 *optsize = sizeof(uint32_t);
2203 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2208 case SCTP_GET_PEER_ADDRESSES:
2210 * Get the address information, an array is passed in to
2211 * fill up we pack it.
2215 struct sockaddr *addr;
2216 struct sctp_nets *net;
2217 struct sctp_getaddresses *saddr;
2219 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2220 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2223 left = *optsize - offsetof(struct sctp_getaddresses, addr);
2224 *optsize = offsetof(struct sctp_getaddresses, addr);
2225 addr = &saddr->addr[0].sa;
2227 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2228 switch (net->ro._l_addr.sa.sa_family) {
2232 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2233 cpsz = sizeof(struct sockaddr_in6);
2235 cpsz = sizeof(struct sockaddr_in);
2238 cpsz = sizeof(struct sockaddr_in);
2244 cpsz = sizeof(struct sockaddr_in6);
2255 /* not enough room. */
2258 #if defined(INET) && defined(INET6)
2259 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2260 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2261 /* Must map the address */
2262 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2263 (struct sockaddr_in6 *)addr);
2265 memcpy(addr, &net->ro._l_addr, cpsz);
2268 memcpy(addr, &net->ro._l_addr, cpsz);
2270 ((struct sockaddr_in *)addr)->sin_port = stcb->rport;
2272 addr = (struct sockaddr *)((caddr_t)addr + cpsz);
2276 SCTP_TCB_UNLOCK(stcb);
2278 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2283 case SCTP_GET_LOCAL_ADDRESSES:
2285 size_t limit, actual;
2286 struct sctp_getaddresses *saddr;
2288 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2289 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2291 limit = *optsize - offsetof(struct sctp_getaddresses, addr);
2292 actual = sctp_fill_up_addresses(inp, stcb, limit, &saddr->addr[0].sa);
2294 SCTP_TCB_UNLOCK(stcb);
2296 *optsize = offsetof(struct sctp_getaddresses, addr) + actual;
2299 case SCTP_PEER_ADDR_PARAMS:
2301 struct sctp_paddrparams *paddrp;
2302 struct sctp_nets *net;
2303 struct sockaddr *addr;
2304 #if defined(INET) && defined(INET6)
2305 struct sockaddr_in sin_store;
2308 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2309 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2311 #if defined(INET) && defined(INET6)
2312 if (paddrp->spp_address.ss_family == AF_INET6) {
2313 struct sockaddr_in6 *sin6;
2315 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2316 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2317 in6_sin6_2_sin(&sin_store, sin6);
2318 addr = (struct sockaddr *)&sin_store;
2320 addr = (struct sockaddr *)&paddrp->spp_address;
2323 addr = (struct sockaddr *)&paddrp->spp_address;
2326 addr = (struct sockaddr *)&paddrp->spp_address;
2329 net = sctp_findnet(stcb, addr);
2332 * We increment here since
2333 * sctp_findassociation_ep_addr() wil do a
2334 * decrement if it finds the stcb as long as
2335 * the locked tcb (last argument) is NOT a
2339 SCTP_INP_INCR_REF(inp);
2340 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2342 SCTP_INP_DECR_REF(inp);
2345 if ((stcb != NULL) && (net == NULL)) {
2347 if (addr->sa_family == AF_INET) {
2348 struct sockaddr_in *sin;
2350 sin = (struct sockaddr_in *)addr;
2351 if (sin->sin_addr.s_addr != INADDR_ANY) {
2353 SCTP_TCB_UNLOCK(stcb);
2354 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2360 if (addr->sa_family == AF_INET6) {
2361 struct sockaddr_in6 *sin6;
2363 sin6 = (struct sockaddr_in6 *)addr;
2364 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2366 SCTP_TCB_UNLOCK(stcb);
2367 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2373 error = EAFNOSUPPORT;
2374 SCTP_TCB_UNLOCK(stcb);
2375 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2381 /* Applies to the specific association */
2382 paddrp->spp_flags = 0;
2384 paddrp->spp_hbinterval = net->heart_beat_delay;
2385 paddrp->spp_pathmaxrxt = net->failure_threshold;
2386 paddrp->spp_pathmtu = net->mtu;
2387 switch (net->ro._l_addr.sa.sa_family) {
2390 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2395 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2401 /* get flags for HB */
2402 if (net->dest_state & SCTP_ADDR_NOHB) {
2403 paddrp->spp_flags |= SPP_HB_DISABLE;
2405 paddrp->spp_flags |= SPP_HB_ENABLE;
2407 /* get flags for PMTU */
2408 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2409 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2411 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2413 if (net->dscp & 0x01) {
2414 paddrp->spp_dscp = net->dscp & 0xfc;
2415 paddrp->spp_flags |= SPP_DSCP;
2418 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2419 (net->flowlabel & 0x80000000)) {
2420 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2421 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2426 * No destination so return default
2429 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2430 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2431 if (stcb->asoc.default_dscp & 0x01) {
2432 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2433 paddrp->spp_flags |= SPP_DSCP;
2436 if (stcb->asoc.default_flowlabel & 0x80000000) {
2437 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2438 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2441 /* default settings should be these */
2442 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2443 paddrp->spp_flags |= SPP_HB_DISABLE;
2445 paddrp->spp_flags |= SPP_HB_ENABLE;
2447 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2448 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2450 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2452 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2454 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2455 SCTP_TCB_UNLOCK(stcb);
2457 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2458 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2459 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2460 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
2461 /* Use endpoint defaults */
2462 SCTP_INP_RLOCK(inp);
2463 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2464 paddrp->spp_hbinterval = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2465 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2466 /* get inp's default */
2467 if (inp->sctp_ep.default_dscp & 0x01) {
2468 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2469 paddrp->spp_flags |= SPP_DSCP;
2472 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2473 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2474 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2475 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2478 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2480 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2481 paddrp->spp_flags |= SPP_HB_ENABLE;
2483 paddrp->spp_flags |= SPP_HB_DISABLE;
2485 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2486 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2488 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2490 SCTP_INP_RUNLOCK(inp);
2492 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2497 *optsize = sizeof(struct sctp_paddrparams);
2501 case SCTP_GET_PEER_ADDR_INFO:
2503 struct sctp_paddrinfo *paddri;
2504 struct sctp_nets *net;
2505 struct sockaddr *addr;
2506 #if defined(INET) && defined(INET6)
2507 struct sockaddr_in sin_store;
2510 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2511 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2513 #if defined(INET) && defined(INET6)
2514 if (paddri->spinfo_address.ss_family == AF_INET6) {
2515 struct sockaddr_in6 *sin6;
2517 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2518 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2519 in6_sin6_2_sin(&sin_store, sin6);
2520 addr = (struct sockaddr *)&sin_store;
2522 addr = (struct sockaddr *)&paddri->spinfo_address;
2525 addr = (struct sockaddr *)&paddri->spinfo_address;
2528 addr = (struct sockaddr *)&paddri->spinfo_address;
2531 net = sctp_findnet(stcb, addr);
2534 * We increment here since
2535 * sctp_findassociation_ep_addr() wil do a
2536 * decrement if it finds the stcb as long as
2537 * the locked tcb (last argument) is NOT a
2541 SCTP_INP_INCR_REF(inp);
2542 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2544 SCTP_INP_DECR_REF(inp);
2548 if ((stcb != NULL) && (net != NULL)) {
2549 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2550 /* It's unconfirmed */
2551 paddri->spinfo_state = SCTP_UNCONFIRMED;
2552 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2554 paddri->spinfo_state = SCTP_ACTIVE;
2557 paddri->spinfo_state = SCTP_INACTIVE;
2559 paddri->spinfo_cwnd = net->cwnd;
2560 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2561 paddri->spinfo_rto = net->RTO;
2562 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2563 paddri->spinfo_mtu = net->mtu;
2564 switch (addr->sa_family) {
2567 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2572 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2578 SCTP_TCB_UNLOCK(stcb);
2579 *optsize = sizeof(struct sctp_paddrinfo);
2582 SCTP_TCB_UNLOCK(stcb);
2584 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2589 case SCTP_PCB_STATUS:
2591 struct sctp_pcbinfo *spcb;
2593 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2594 sctp_fill_pcbinfo(spcb);
2595 *optsize = sizeof(struct sctp_pcbinfo);
2600 struct sctp_nets *net;
2601 struct sctp_status *sstat;
2603 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2604 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2607 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2611 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2612 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2613 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2614 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2616 * We can't include chunks that have been passed to
2617 * the socket layer. Only things in queue.
2619 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2620 stcb->asoc.cnt_on_all_streams);
2621 sstat->sstat_instrms = stcb->asoc.streamincnt;
2622 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2623 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2624 net = stcb->asoc.primary_destination;
2626 memcpy(&sstat->sstat_primary.spinfo_address,
2628 ((struct sockaddr *)(&net->ro._l_addr))->sa_len);
2629 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2631 * Again the user can get info from
2632 * sctp_constants.h for what the state of
2635 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2636 /* It's unconfirmed */
2637 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2638 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2640 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2643 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2645 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2646 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2647 sstat->sstat_primary.spinfo_rto = net->RTO;
2648 sstat->sstat_primary.spinfo_mtu = net->mtu;
2649 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2652 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2657 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2664 memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo));
2666 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2667 SCTP_TCB_UNLOCK(stcb);
2668 *optsize = sizeof(struct sctp_status);
2673 struct sctp_rtoinfo *srto;
2675 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2676 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2679 srto->srto_initial = stcb->asoc.initial_rto;
2680 srto->srto_max = stcb->asoc.maxrto;
2681 srto->srto_min = stcb->asoc.minrto;
2682 SCTP_TCB_UNLOCK(stcb);
2684 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2685 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2686 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2687 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
2688 SCTP_INP_RLOCK(inp);
2689 srto->srto_initial = inp->sctp_ep.initial_rto;
2690 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2691 srto->srto_min = inp->sctp_ep.sctp_minrto;
2692 SCTP_INP_RUNLOCK(inp);
2694 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2699 *optsize = sizeof(struct sctp_rtoinfo);
2705 struct sctp_timeouts *stimo;
2707 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2708 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2711 stimo->stimo_init = stcb->asoc.timoinit;
2712 stimo->stimo_data = stcb->asoc.timodata;
2713 stimo->stimo_sack = stcb->asoc.timosack;
2714 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2715 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2716 stimo->stimo_cookie = stcb->asoc.timocookie;
2717 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2718 SCTP_TCB_UNLOCK(stcb);
2719 *optsize = sizeof(struct sctp_timeouts);
2721 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2726 case SCTP_ASSOCINFO:
2728 struct sctp_assocparams *sasoc;
2730 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2731 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2734 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(stcb->asoc.cookie_life);
2735 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2736 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2737 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2738 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2739 SCTP_TCB_UNLOCK(stcb);
2741 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2742 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2743 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2744 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
2745 SCTP_INP_RLOCK(inp);
2746 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(inp->sctp_ep.def_cookie_life);
2747 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2748 sasoc->sasoc_number_peer_destinations = 0;
2749 sasoc->sasoc_peer_rwnd = 0;
2750 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2751 SCTP_INP_RUNLOCK(inp);
2753 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2758 *optsize = sizeof(struct sctp_assocparams);
2762 case SCTP_DEFAULT_SEND_PARAM:
2764 struct sctp_sndrcvinfo *s_info;
2766 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2767 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2770 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2771 SCTP_TCB_UNLOCK(stcb);
2773 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2774 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2775 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2776 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC))) {
2777 SCTP_INP_RLOCK(inp);
2778 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2779 SCTP_INP_RUNLOCK(inp);
2781 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2786 *optsize = sizeof(struct sctp_sndrcvinfo);
2792 struct sctp_initmsg *sinit;
2794 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2795 SCTP_INP_RLOCK(inp);
2796 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2797 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2798 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2799 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2800 SCTP_INP_RUNLOCK(inp);
2801 *optsize = sizeof(struct sctp_initmsg);
2804 case SCTP_PRIMARY_ADDR:
2805 /* we allow a "get" operation on this */
2807 struct sctp_setprim *ssp;
2809 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2810 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2813 union sctp_sockstore *addr;
2815 addr = &stcb->asoc.primary_destination->ro._l_addr;
2816 switch (addr->sa.sa_family) {
2820 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2821 in6_sin_2_v4mapsin6(&addr->sin,
2822 (struct sockaddr_in6 *)&ssp->ssp_addr);
2824 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2827 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2833 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2839 SCTP_TCB_UNLOCK(stcb);
2840 *optsize = sizeof(struct sctp_setprim);
2842 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2847 case SCTP_HMAC_IDENT:
2849 struct sctp_hmacalgo *shmac;
2850 sctp_hmaclist_t *hmaclist;
2854 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2856 SCTP_INP_RLOCK(inp);
2857 hmaclist = inp->sctp_ep.local_hmacs;
2858 if (hmaclist == NULL) {
2859 /* no HMACs to return */
2860 *optsize = sizeof(*shmac);
2861 SCTP_INP_RUNLOCK(inp);
2864 /* is there room for all of the hmac ids? */
2865 size = sizeof(*shmac) + (hmaclist->num_algo *
2866 sizeof(shmac->shmac_idents[0]));
2867 if ((size_t)(*optsize) < size) {
2868 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2870 SCTP_INP_RUNLOCK(inp);
2873 /* copy in the list */
2874 shmac->shmac_number_of_idents = hmaclist->num_algo;
2875 for (i = 0; i < hmaclist->num_algo; i++) {
2876 shmac->shmac_idents[i] = hmaclist->hmac[i];
2878 SCTP_INP_RUNLOCK(inp);
2882 case SCTP_AUTH_ACTIVE_KEY:
2884 struct sctp_authkeyid *scact;
2886 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2887 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2890 /* get the active key on the assoc */
2891 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2892 SCTP_TCB_UNLOCK(stcb);
2894 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2895 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2896 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2897 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC))) {
2898 /* get the endpoint active key */
2899 SCTP_INP_RLOCK(inp);
2900 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2901 SCTP_INP_RUNLOCK(inp);
2903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2908 *optsize = sizeof(struct sctp_authkeyid);
2912 case SCTP_LOCAL_AUTH_CHUNKS:
2914 struct sctp_authchunks *sac;
2915 sctp_auth_chklist_t *chklist = NULL;
2918 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2919 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2922 /* get off the assoc */
2923 chklist = stcb->asoc.local_auth_chunks;
2924 /* is there enough space? */
2925 size = sctp_auth_get_chklist_size(chklist);
2926 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2928 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2930 /* copy in the chunks */
2931 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2932 sac->gauth_number_of_chunks = (uint32_t)size;
2933 *optsize = sizeof(struct sctp_authchunks) + size;
2935 SCTP_TCB_UNLOCK(stcb);
2937 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2938 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2939 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2940 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC))) {
2941 /* get off the endpoint */
2942 SCTP_INP_RLOCK(inp);
2943 chklist = inp->sctp_ep.local_auth_chunks;
2944 /* is there enough space? */
2945 size = sctp_auth_get_chklist_size(chklist);
2946 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2950 /* copy in the chunks */
2951 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2952 sac->gauth_number_of_chunks = (uint32_t)size;
2953 *optsize = sizeof(struct sctp_authchunks) + size;
2955 SCTP_INP_RUNLOCK(inp);
2957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2963 case SCTP_PEER_AUTH_CHUNKS:
2965 struct sctp_authchunks *sac;
2966 sctp_auth_chklist_t *chklist = NULL;
2969 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2970 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2973 /* get off the assoc */
2974 chklist = stcb->asoc.peer_auth_chunks;
2975 /* is there enough space? */
2976 size = sctp_auth_get_chklist_size(chklist);
2977 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2979 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2981 /* copy in the chunks */
2982 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2983 sac->gauth_number_of_chunks = (uint32_t)size;
2984 *optsize = sizeof(struct sctp_authchunks) + size;
2986 SCTP_TCB_UNLOCK(stcb);
2988 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2995 struct sctp_event *event;
2996 uint32_t event_type;
2998 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2999 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3001 switch (event->se_type) {
3002 case SCTP_ASSOC_CHANGE:
3003 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3005 case SCTP_PEER_ADDR_CHANGE:
3006 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3008 case SCTP_REMOTE_ERROR:
3009 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3011 case SCTP_SEND_FAILED:
3012 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3014 case SCTP_SHUTDOWN_EVENT:
3015 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3017 case SCTP_ADAPTATION_INDICATION:
3018 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3020 case SCTP_PARTIAL_DELIVERY_EVENT:
3021 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3023 case SCTP_AUTHENTICATION_EVENT:
3024 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3026 case SCTP_STREAM_RESET_EVENT:
3027 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3029 case SCTP_SENDER_DRY_EVENT:
3030 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3032 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3034 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3037 case SCTP_ASSOC_RESET_EVENT:
3038 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3040 case SCTP_STREAM_CHANGE_EVENT:
3041 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3043 case SCTP_SEND_FAILED_EVENT:
3044 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3048 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3052 if (event_type > 0) {
3054 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3056 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3057 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3058 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3059 (event->se_assoc_id == SCTP_FUTURE_ASSOC))) {
3060 SCTP_INP_RLOCK(inp);
3061 event->se_on = sctp_is_feature_on(inp, event_type);
3062 SCTP_INP_RUNLOCK(inp);
3064 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3070 SCTP_TCB_UNLOCK(stcb);
3073 *optsize = sizeof(struct sctp_event);
3077 case SCTP_RECVRCVINFO:
3078 if (*optsize < sizeof(int)) {
3079 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3082 SCTP_INP_RLOCK(inp);
3083 *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3084 SCTP_INP_RUNLOCK(inp);
3085 *optsize = sizeof(int);
3088 case SCTP_RECVNXTINFO:
3089 if (*optsize < sizeof(int)) {
3090 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3093 SCTP_INP_RLOCK(inp);
3094 *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3095 SCTP_INP_RUNLOCK(inp);
3096 *optsize = sizeof(int);
3099 case SCTP_DEFAULT_SNDINFO:
3101 struct sctp_sndinfo *info;
3103 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3104 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3107 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3108 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3109 info->snd_flags &= 0xfff0;
3110 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3111 info->snd_context = stcb->asoc.def_send.sinfo_context;
3112 SCTP_TCB_UNLOCK(stcb);
3114 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3115 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3116 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3117 (info->snd_assoc_id == SCTP_FUTURE_ASSOC))) {
3118 SCTP_INP_RLOCK(inp);
3119 info->snd_sid = inp->def_send.sinfo_stream;
3120 info->snd_flags = inp->def_send.sinfo_flags;
3121 info->snd_flags &= 0xfff0;
3122 info->snd_ppid = inp->def_send.sinfo_ppid;
3123 info->snd_context = inp->def_send.sinfo_context;
3124 SCTP_INP_RUNLOCK(inp);
3126 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3131 *optsize = sizeof(struct sctp_sndinfo);
3135 case SCTP_DEFAULT_PRINFO:
3137 struct sctp_default_prinfo *info;
3139 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3140 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3143 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3144 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3145 SCTP_TCB_UNLOCK(stcb);
3147 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3148 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3149 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3150 (info->pr_assoc_id == SCTP_FUTURE_ASSOC))) {
3151 SCTP_INP_RLOCK(inp);
3152 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3153 info->pr_value = inp->def_send.sinfo_timetolive;
3154 SCTP_INP_RUNLOCK(inp);
3156 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3161 *optsize = sizeof(struct sctp_default_prinfo);
3165 case SCTP_PEER_ADDR_THLDS:
3167 struct sctp_paddrthlds *thlds;
3168 struct sctp_nets *net;
3169 struct sockaddr *addr;
3170 #if defined(INET) && defined(INET6)
3171 struct sockaddr_in sin_store;
3174 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3175 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3177 #if defined(INET) && defined(INET6)
3178 if (thlds->spt_address.ss_family == AF_INET6) {
3179 struct sockaddr_in6 *sin6;
3181 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3182 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3183 in6_sin6_2_sin(&sin_store, sin6);
3184 addr = (struct sockaddr *)&sin_store;
3186 addr = (struct sockaddr *)&thlds->spt_address;
3189 addr = (struct sockaddr *)&thlds->spt_address;
3192 addr = (struct sockaddr *)&thlds->spt_address;
3195 net = sctp_findnet(stcb, addr);
3198 * We increment here since
3199 * sctp_findassociation_ep_addr() wil do a
3200 * decrement if it finds the stcb as long as
3201 * the locked tcb (last argument) is NOT a
3205 SCTP_INP_INCR_REF(inp);
3206 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3208 SCTP_INP_DECR_REF(inp);
3211 if ((stcb != NULL) && (net == NULL)) {
3213 if (addr->sa_family == AF_INET) {
3214 struct sockaddr_in *sin;
3216 sin = (struct sockaddr_in *)addr;
3217 if (sin->sin_addr.s_addr != INADDR_ANY) {
3219 SCTP_TCB_UNLOCK(stcb);
3220 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3226 if (addr->sa_family == AF_INET6) {
3227 struct sockaddr_in6 *sin6;
3229 sin6 = (struct sockaddr_in6 *)addr;
3230 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3232 SCTP_TCB_UNLOCK(stcb);
3233 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3239 error = EAFNOSUPPORT;
3240 SCTP_TCB_UNLOCK(stcb);
3241 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3248 thlds->spt_pathmaxrxt = net->failure_threshold;
3249 thlds->spt_pathpfthld = net->pf_threshold;
3250 thlds->spt_pathcpthld = 0xffff;
3252 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3253 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3254 thlds->spt_pathcpthld = 0xffff;
3256 thlds->spt_assoc_id = sctp_get_associd(stcb);
3257 SCTP_TCB_UNLOCK(stcb);
3259 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3260 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3261 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3262 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
3263 /* Use endpoint defaults */
3264 SCTP_INP_RLOCK(inp);
3265 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3266 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3267 thlds->spt_pathcpthld = 0xffff;
3268 SCTP_INP_RUNLOCK(inp);
3270 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3275 *optsize = sizeof(struct sctp_paddrthlds);
3279 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3281 struct sctp_udpencaps *encaps;
3282 struct sctp_nets *net;
3283 struct sockaddr *addr;
3284 #if defined(INET) && defined(INET6)
3285 struct sockaddr_in sin_store;
3288 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3289 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3291 #if defined(INET) && defined(INET6)
3292 if (encaps->sue_address.ss_family == AF_INET6) {
3293 struct sockaddr_in6 *sin6;
3295 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3296 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3297 in6_sin6_2_sin(&sin_store, sin6);
3298 addr = (struct sockaddr *)&sin_store;
3300 addr = (struct sockaddr *)&encaps->sue_address;
3303 addr = (struct sockaddr *)&encaps->sue_address;
3306 addr = (struct sockaddr *)&encaps->sue_address;
3309 net = sctp_findnet(stcb, addr);
3312 * We increment here since
3313 * sctp_findassociation_ep_addr() wil do a
3314 * decrement if it finds the stcb as long as
3315 * the locked tcb (last argument) is NOT a
3319 SCTP_INP_INCR_REF(inp);
3320 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3322 SCTP_INP_DECR_REF(inp);
3325 if ((stcb != NULL) && (net == NULL)) {
3327 if (addr->sa_family == AF_INET) {
3328 struct sockaddr_in *sin;
3330 sin = (struct sockaddr_in *)addr;
3331 if (sin->sin_addr.s_addr != INADDR_ANY) {
3333 SCTP_TCB_UNLOCK(stcb);
3334 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3340 if (addr->sa_family == AF_INET6) {
3341 struct sockaddr_in6 *sin6;
3343 sin6 = (struct sockaddr_in6 *)addr;
3344 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3346 SCTP_TCB_UNLOCK(stcb);
3347 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3353 error = EAFNOSUPPORT;
3354 SCTP_TCB_UNLOCK(stcb);
3355 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3362 encaps->sue_port = net->port;
3364 encaps->sue_port = stcb->asoc.port;
3366 SCTP_TCB_UNLOCK(stcb);
3368 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3369 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3370 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3371 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
3372 SCTP_INP_RLOCK(inp);
3373 encaps->sue_port = inp->sctp_ep.port;
3374 SCTP_INP_RUNLOCK(inp);
3376 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3381 *optsize = sizeof(struct sctp_udpencaps);
3385 case SCTP_ECN_SUPPORTED:
3387 struct sctp_assoc_value *av;
3389 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3390 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3393 av->assoc_value = stcb->asoc.ecn_supported;
3394 SCTP_TCB_UNLOCK(stcb);
3396 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3397 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3398 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3399 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3400 SCTP_INP_RLOCK(inp);
3401 av->assoc_value = inp->ecn_supported;
3402 SCTP_INP_RUNLOCK(inp);
3404 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3409 *optsize = sizeof(struct sctp_assoc_value);
3413 case SCTP_PR_SUPPORTED:
3415 struct sctp_assoc_value *av;
3417 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3418 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3421 av->assoc_value = stcb->asoc.prsctp_supported;
3422 SCTP_TCB_UNLOCK(stcb);
3424 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3425 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3426 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3427 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3428 SCTP_INP_RLOCK(inp);
3429 av->assoc_value = inp->prsctp_supported;
3430 SCTP_INP_RUNLOCK(inp);
3432 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3437 *optsize = sizeof(struct sctp_assoc_value);
3441 case SCTP_AUTH_SUPPORTED:
3443 struct sctp_assoc_value *av;
3445 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3446 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3449 av->assoc_value = stcb->asoc.auth_supported;
3450 SCTP_TCB_UNLOCK(stcb);
3452 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3453 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3454 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3455 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3456 SCTP_INP_RLOCK(inp);
3457 av->assoc_value = inp->auth_supported;
3458 SCTP_INP_RUNLOCK(inp);
3460 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3465 *optsize = sizeof(struct sctp_assoc_value);
3469 case SCTP_ASCONF_SUPPORTED:
3471 struct sctp_assoc_value *av;
3473 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3474 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3477 av->assoc_value = stcb->asoc.asconf_supported;
3478 SCTP_TCB_UNLOCK(stcb);
3480 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3481 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3482 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3483 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3484 SCTP_INP_RLOCK(inp);
3485 av->assoc_value = inp->asconf_supported;
3486 SCTP_INP_RUNLOCK(inp);
3488 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3493 *optsize = sizeof(struct sctp_assoc_value);
3497 case SCTP_RECONFIG_SUPPORTED:
3499 struct sctp_assoc_value *av;
3501 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3502 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3505 av->assoc_value = stcb->asoc.reconfig_supported;
3506 SCTP_TCB_UNLOCK(stcb);
3508 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3509 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3510 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3511 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3512 SCTP_INP_RLOCK(inp);
3513 av->assoc_value = inp->reconfig_supported;
3514 SCTP_INP_RUNLOCK(inp);
3516 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3521 *optsize = sizeof(struct sctp_assoc_value);
3525 case SCTP_NRSACK_SUPPORTED:
3527 struct sctp_assoc_value *av;
3529 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3530 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3533 av->assoc_value = stcb->asoc.nrsack_supported;
3534 SCTP_TCB_UNLOCK(stcb);
3536 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3537 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3538 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3539 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3540 SCTP_INP_RLOCK(inp);
3541 av->assoc_value = inp->nrsack_supported;
3542 SCTP_INP_RUNLOCK(inp);
3544 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3549 *optsize = sizeof(struct sctp_assoc_value);
3553 case SCTP_PKTDROP_SUPPORTED:
3555 struct sctp_assoc_value *av;
3557 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3558 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3561 av->assoc_value = stcb->asoc.pktdrop_supported;
3562 SCTP_TCB_UNLOCK(stcb);
3564 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3565 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3566 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3567 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3568 SCTP_INP_RLOCK(inp);
3569 av->assoc_value = inp->pktdrop_supported;
3570 SCTP_INP_RUNLOCK(inp);
3572 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3577 *optsize = sizeof(struct sctp_assoc_value);
3581 case SCTP_ENABLE_STREAM_RESET:
3583 struct sctp_assoc_value *av;
3585 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3586 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3589 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3590 SCTP_TCB_UNLOCK(stcb);
3592 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3593 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3594 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3595 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3596 SCTP_INP_RLOCK(inp);
3597 av->assoc_value = (uint32_t)inp->local_strreset_support;
3598 SCTP_INP_RUNLOCK(inp);
3600 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3605 *optsize = sizeof(struct sctp_assoc_value);
3609 case SCTP_PR_STREAM_STATUS:
3611 struct sctp_prstatus *sprstat;
3615 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3616 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3618 sid = sprstat->sprstat_sid;
3619 policy = sprstat->sprstat_policy;
3620 #if defined(SCTP_DETAILED_STR_STATS)
3621 if ((stcb != NULL) &&
3622 (sid < stcb->asoc.streamoutcnt) &&
3623 (policy != SCTP_PR_SCTP_NONE) &&
3624 ((policy <= SCTP_PR_SCTP_MAX) ||
3625 (policy == SCTP_PR_SCTP_ALL))) {
3626 if (policy == SCTP_PR_SCTP_ALL) {
3627 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3628 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3630 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3631 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3634 if ((stcb != NULL) &&
3635 (sid < stcb->asoc.streamoutcnt) &&
3636 (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];
3641 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3645 SCTP_TCB_UNLOCK(stcb);
3648 *optsize = sizeof(struct sctp_prstatus);
3652 case SCTP_PR_ASSOC_STATUS:
3654 struct sctp_prstatus *sprstat;
3657 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3658 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3660 policy = sprstat->sprstat_policy;
3661 if ((stcb != NULL) &&
3662 (policy != SCTP_PR_SCTP_NONE) &&
3663 ((policy <= SCTP_PR_SCTP_MAX) ||
3664 (policy == SCTP_PR_SCTP_ALL))) {
3665 if (policy == SCTP_PR_SCTP_ALL) {
3666 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3667 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3669 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3670 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3673 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3677 SCTP_TCB_UNLOCK(stcb);
3680 *optsize = sizeof(struct sctp_prstatus);
3686 struct sctp_assoc_value *av;
3688 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3689 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3692 av->assoc_value = stcb->asoc.max_cwnd;
3693 SCTP_TCB_UNLOCK(stcb);
3695 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3696 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3697 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3698 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3699 SCTP_INP_RLOCK(inp);
3700 av->assoc_value = inp->max_cwnd;
3701 SCTP_INP_RUNLOCK(inp);
3703 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3708 *optsize = sizeof(struct sctp_assoc_value);
3713 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3714 error = ENOPROTOOPT;
3716 } /* end switch (sopt->sopt_name) */
3724 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3729 struct sctp_tcb *stcb = NULL;
3730 struct sctp_inpcb *inp = NULL;
3733 if (optval == NULL) {
3734 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3737 inp = (struct sctp_inpcb *)so->so_pcb;
3739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3742 vrf_id = inp->def_vrf_id;
3747 case SCTP_AUTOCLOSE:
3748 case SCTP_AUTO_ASCONF:
3749 case SCTP_EXPLICIT_EOR:
3750 case SCTP_DISABLE_FRAGMENTS:
3751 case SCTP_USE_EXT_RCVINFO:
3752 case SCTP_I_WANT_MAPPED_V4_ADDR:
3753 /* copy in the option value */
3754 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3759 case SCTP_DISABLE_FRAGMENTS:
3760 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3762 case SCTP_AUTO_ASCONF:
3764 * NOTE: we don't really support this flag
3766 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3767 /* only valid for bound all sockets */
3768 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3770 /* forbidden by admin */
3771 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3774 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3780 case SCTP_EXPLICIT_EOR:
3781 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3783 case SCTP_USE_EXT_RCVINFO:
3784 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3786 case SCTP_I_WANT_MAPPED_V4_ADDR:
3787 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3788 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3790 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3795 set_opt = SCTP_PCB_FLAGS_NODELAY;
3797 case SCTP_AUTOCLOSE:
3798 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3799 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3803 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3805 * The value is in ticks. Note this does not effect
3806 * old associations, only new ones.
3808 inp->sctp_ep.auto_close_time = sctp_secs_to_ticks(*mopt);
3811 SCTP_INP_WLOCK(inp);
3813 sctp_feature_on(inp, set_opt);
3815 sctp_feature_off(inp, set_opt);
3817 SCTP_INP_WUNLOCK(inp);
3819 case SCTP_REUSE_PORT:
3821 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3822 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3823 /* Can't set it after we are bound */
3827 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3828 /* Can't do this for a 1-m socket */
3833 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3835 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3838 case SCTP_PARTIAL_DELIVERY_POINT:
3842 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3843 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3844 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3848 inp->partial_delivery_point = *value;
3851 case SCTP_FRAGMENT_INTERLEAVE:
3852 /* not yet until we re-write sctp_recvmsg() */
3856 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3857 if (*level == SCTP_FRAG_LEVEL_2) {
3858 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3859 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3860 } else if (*level == SCTP_FRAG_LEVEL_1) {
3861 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3862 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3863 } else if (*level == SCTP_FRAG_LEVEL_0) {
3864 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3865 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3868 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3873 case SCTP_INTERLEAVING_SUPPORTED:
3875 struct sctp_assoc_value *av;
3877 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3878 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3883 SCTP_TCB_UNLOCK(stcb);
3885 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3886 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3887 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3888 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3889 SCTP_INP_WLOCK(inp);
3890 if (av->assoc_value == 0) {
3891 inp->idata_supported = 0;
3893 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3894 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3895 inp->idata_supported = 1;
3903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3907 SCTP_INP_WUNLOCK(inp);
3909 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3915 case SCTP_CMT_ON_OFF:
3916 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3917 struct sctp_assoc_value *av;
3919 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3920 if (av->assoc_value > SCTP_CMT_MAX) {
3921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3925 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3927 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3928 SCTP_TCB_UNLOCK(stcb);
3930 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3931 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3932 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3933 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3934 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3935 SCTP_INP_WLOCK(inp);
3936 inp->sctp_cmt_on_off = av->assoc_value;
3937 SCTP_INP_WUNLOCK(inp);
3939 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3940 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3941 (av->assoc_id == SCTP_ALL_ASSOC))) {
3942 SCTP_INP_RLOCK(inp);
3943 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3944 SCTP_TCB_LOCK(stcb);
3945 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3946 SCTP_TCB_UNLOCK(stcb);
3948 SCTP_INP_RUNLOCK(inp);
3952 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3953 error = ENOPROTOOPT;
3956 case SCTP_PLUGGABLE_CC:
3958 struct sctp_assoc_value *av;
3959 struct sctp_nets *net;
3961 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3962 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3963 (av->assoc_value != SCTP_CC_HSTCP) &&
3964 (av->assoc_value != SCTP_CC_HTCP) &&
3965 (av->assoc_value != SCTP_CC_RTCC)) {
3966 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3970 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3972 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3973 stcb->asoc.congestion_control_module = av->assoc_value;
3974 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3975 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3976 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3979 SCTP_TCB_UNLOCK(stcb);
3981 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3982 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3983 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3984 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3985 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3986 SCTP_INP_WLOCK(inp);
3987 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3988 SCTP_INP_WUNLOCK(inp);
3990 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3991 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3992 (av->assoc_id == SCTP_ALL_ASSOC))) {
3993 SCTP_INP_RLOCK(inp);
3994 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3995 SCTP_TCB_LOCK(stcb);
3996 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3997 stcb->asoc.congestion_control_module = av->assoc_value;
3998 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3999 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4000 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4003 SCTP_TCB_UNLOCK(stcb);
4005 SCTP_INP_RUNLOCK(inp);
4010 case SCTP_CC_OPTION:
4012 struct sctp_cc_option *cc_opt;
4014 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4015 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4017 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4018 (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC)) {
4019 SCTP_INP_RLOCK(inp);
4020 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4021 SCTP_TCB_LOCK(stcb);
4022 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4023 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4025 SCTP_TCB_UNLOCK(stcb);
4027 SCTP_INP_RUNLOCK(inp);
4032 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4035 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4038 SCTP_TCB_UNLOCK(stcb);
4042 case SCTP_PLUGGABLE_SS:
4044 struct sctp_assoc_value *av;
4046 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4047 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4048 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4049 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4050 (av->assoc_value != SCTP_SS_PRIORITY) &&
4051 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4052 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4053 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4057 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4059 SCTP_TCB_SEND_LOCK(stcb);
4060 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4061 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4062 stcb->asoc.stream_scheduling_module = av->assoc_value;
4063 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4064 SCTP_TCB_SEND_UNLOCK(stcb);
4065 SCTP_TCB_UNLOCK(stcb);
4067 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4068 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4069 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4070 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4071 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4072 SCTP_INP_WLOCK(inp);
4073 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4074 SCTP_INP_WUNLOCK(inp);
4076 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4077 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4078 (av->assoc_id == SCTP_ALL_ASSOC))) {
4079 SCTP_INP_RLOCK(inp);
4080 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4081 SCTP_TCB_LOCK(stcb);
4082 SCTP_TCB_SEND_LOCK(stcb);
4083 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4084 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4085 stcb->asoc.stream_scheduling_module = av->assoc_value;
4086 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4087 SCTP_TCB_SEND_UNLOCK(stcb);
4088 SCTP_TCB_UNLOCK(stcb);
4090 SCTP_INP_RUNLOCK(inp);
4097 struct sctp_stream_value *av;
4099 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4100 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4102 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4103 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4104 av->stream_value) < 0)) {
4105 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4108 SCTP_TCB_UNLOCK(stcb);
4110 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4111 (av->assoc_id == SCTP_CURRENT_ASSOC)) {
4112 SCTP_INP_RLOCK(inp);
4113 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4114 SCTP_TCB_LOCK(stcb);
4115 if (av->stream_id < stcb->asoc.streamoutcnt) {
4116 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4118 &stcb->asoc.strmout[av->stream_id],
4121 SCTP_TCB_UNLOCK(stcb);
4123 SCTP_INP_RUNLOCK(inp);
4126 * Can't set stream value without
4129 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4135 case SCTP_CLR_STAT_LOG:
4136 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4141 struct sctp_assoc_value *av;
4143 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4144 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4147 stcb->asoc.context = av->assoc_value;
4148 SCTP_TCB_UNLOCK(stcb);
4150 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4151 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4152 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4153 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4154 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4155 SCTP_INP_WLOCK(inp);
4156 inp->sctp_context = av->assoc_value;
4157 SCTP_INP_WUNLOCK(inp);
4159 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4160 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4161 (av->assoc_id == SCTP_ALL_ASSOC))) {
4162 SCTP_INP_RLOCK(inp);
4163 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4164 SCTP_TCB_LOCK(stcb);
4165 stcb->asoc.context = av->assoc_value;
4166 SCTP_TCB_UNLOCK(stcb);
4168 SCTP_INP_RUNLOCK(inp);
4175 uint32_t *default_vrfid;
4177 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4178 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4179 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4183 inp->def_vrf_id = *default_vrfid;
4186 case SCTP_DEL_VRF_ID:
4188 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4192 case SCTP_ADD_VRF_ID:
4194 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4198 case SCTP_DELAYED_SACK:
4200 struct sctp_sack_info *sack;
4202 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4203 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4204 if (sack->sack_delay) {
4205 if (sack->sack_delay > SCTP_MAX_SACK_DELAY) {
4208 SCTP_TCB_UNLOCK(stcb);
4214 if (sack->sack_delay) {
4215 stcb->asoc.delayed_ack = sack->sack_delay;
4217 if (sack->sack_freq) {
4218 stcb->asoc.sack_freq = sack->sack_freq;
4220 SCTP_TCB_UNLOCK(stcb);
4222 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4223 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4224 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4225 ((sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4226 (sack->sack_assoc_id == SCTP_ALL_ASSOC)))) {
4227 SCTP_INP_WLOCK(inp);
4228 if (sack->sack_delay) {
4229 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = sctp_msecs_to_ticks(sack->sack_delay);
4231 if (sack->sack_freq) {
4232 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4234 SCTP_INP_WUNLOCK(inp);
4236 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4237 ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4238 (sack->sack_assoc_id == SCTP_ALL_ASSOC))) {
4239 SCTP_INP_RLOCK(inp);
4240 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4241 SCTP_TCB_LOCK(stcb);
4242 if (sack->sack_delay) {
4243 stcb->asoc.delayed_ack = sack->sack_delay;
4245 if (sack->sack_freq) {
4246 stcb->asoc.sack_freq = sack->sack_freq;
4248 SCTP_TCB_UNLOCK(stcb);
4250 SCTP_INP_RUNLOCK(inp);
4255 case SCTP_AUTH_CHUNK:
4257 struct sctp_authchunk *sauth;
4259 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4261 SCTP_INP_WLOCK(inp);
4262 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4263 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4266 inp->auth_supported = 1;
4268 SCTP_INP_WUNLOCK(inp);
4273 struct sctp_authkey *sca;
4274 struct sctp_keyhead *shared_keys;
4275 sctp_sharedkey_t *shared_key;
4276 sctp_key_t *key = NULL;
4279 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4280 if (sca->sca_keylength == 0) {
4281 size = optsize - sizeof(struct sctp_authkey);
4283 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4284 size = sca->sca_keylength;
4286 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4291 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4294 shared_keys = &stcb->asoc.shared_keys;
4295 /* clear the cached keys for this key id */
4296 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4298 * create the new shared key and
4302 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4304 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4306 SCTP_TCB_UNLOCK(stcb);
4310 shared_key = sctp_alloc_sharedkey();
4311 if (shared_key == NULL) {
4313 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4315 SCTP_TCB_UNLOCK(stcb);
4318 shared_key->key = key;
4319 shared_key->keyid = sca->sca_keynumber;
4320 error = sctp_insert_sharedkey(shared_keys, shared_key);
4321 SCTP_TCB_UNLOCK(stcb);
4323 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4324 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4325 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4326 ((sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4327 (sca->sca_assoc_id == SCTP_ALL_ASSOC)))) {
4328 SCTP_INP_WLOCK(inp);
4329 shared_keys = &inp->sctp_ep.shared_keys;
4331 * clear the cached keys on all
4332 * assocs for this key id
4334 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4336 * create the new shared key and
4340 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4342 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4344 SCTP_INP_WUNLOCK(inp);
4348 shared_key = sctp_alloc_sharedkey();
4349 if (shared_key == NULL) {
4351 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4353 SCTP_INP_WUNLOCK(inp);
4356 shared_key->key = key;
4357 shared_key->keyid = sca->sca_keynumber;
4358 error = sctp_insert_sharedkey(shared_keys, shared_key);
4359 SCTP_INP_WUNLOCK(inp);
4361 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4362 ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4363 (sca->sca_assoc_id == SCTP_ALL_ASSOC))) {
4364 SCTP_INP_RLOCK(inp);
4365 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4366 SCTP_TCB_LOCK(stcb);
4367 shared_keys = &stcb->asoc.shared_keys;
4369 * clear the cached keys for
4372 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4374 * create the new shared key
4375 * and insert/replace it
4378 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4380 SCTP_TCB_UNLOCK(stcb);
4384 shared_key = sctp_alloc_sharedkey();
4385 if (shared_key == NULL) {
4387 SCTP_TCB_UNLOCK(stcb);
4390 shared_key->key = key;
4391 shared_key->keyid = sca->sca_keynumber;
4392 error = sctp_insert_sharedkey(shared_keys, shared_key);
4393 SCTP_TCB_UNLOCK(stcb);
4395 SCTP_INP_RUNLOCK(inp);
4400 case SCTP_HMAC_IDENT:
4402 struct sctp_hmacalgo *shmac;
4403 sctp_hmaclist_t *hmaclist;
4407 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4408 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4409 (shmac->shmac_number_of_idents > 0xffff)) {
4410 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4415 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4416 if (hmaclist == NULL) {
4417 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4421 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4422 hmacid = shmac->shmac_idents[i];
4423 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4424 /* invalid HMACs were found */ ;
4425 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4427 sctp_free_hmaclist(hmaclist);
4428 goto sctp_set_hmac_done;
4431 for (i = 0; i < hmaclist->num_algo; i++) {
4432 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4433 /* already in list */
4437 if (i == hmaclist->num_algo) {
4438 /* not found in list */
4439 sctp_free_hmaclist(hmaclist);
4440 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4444 /* set it on the endpoint */
4445 SCTP_INP_WLOCK(inp);
4446 if (inp->sctp_ep.local_hmacs)
4447 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4448 inp->sctp_ep.local_hmacs = hmaclist;
4449 SCTP_INP_WUNLOCK(inp);
4453 case SCTP_AUTH_ACTIVE_KEY:
4455 struct sctp_authkeyid *scact;
4457 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4458 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4460 /* set the active key on the right place */
4462 /* set the active key on the assoc */
4463 if (sctp_auth_setactivekey(stcb,
4464 scact->scact_keynumber)) {
4465 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4466 SCTP_FROM_SCTP_USRREQ,
4470 SCTP_TCB_UNLOCK(stcb);
4472 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4473 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4474 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4475 ((scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4476 (scact->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4477 SCTP_INP_WLOCK(inp);
4478 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4479 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4482 SCTP_INP_WUNLOCK(inp);
4484 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4485 ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4486 (scact->scact_assoc_id == SCTP_ALL_ASSOC))) {
4487 SCTP_INP_RLOCK(inp);
4488 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4489 SCTP_TCB_LOCK(stcb);
4490 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4491 SCTP_TCB_UNLOCK(stcb);
4493 SCTP_INP_RUNLOCK(inp);
4498 case SCTP_AUTH_DELETE_KEY:
4500 struct sctp_authkeyid *scdel;
4502 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4503 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4505 /* delete the key from the right place */
4507 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4508 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4511 SCTP_TCB_UNLOCK(stcb);
4513 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4514 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4515 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4516 ((scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4517 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4518 SCTP_INP_WLOCK(inp);
4519 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4520 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4523 SCTP_INP_WUNLOCK(inp);
4525 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4526 ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4527 (scdel->scact_assoc_id == SCTP_ALL_ASSOC))) {
4528 SCTP_INP_RLOCK(inp);
4529 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4530 SCTP_TCB_LOCK(stcb);
4531 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4532 SCTP_TCB_UNLOCK(stcb);
4534 SCTP_INP_RUNLOCK(inp);
4539 case SCTP_AUTH_DEACTIVATE_KEY:
4541 struct sctp_authkeyid *keyid;
4543 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4544 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4546 /* deactivate the key from the right place */
4548 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4549 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4552 SCTP_TCB_UNLOCK(stcb);
4554 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4555 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4556 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4557 ((keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4558 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4559 SCTP_INP_WLOCK(inp);
4560 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4561 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4564 SCTP_INP_WUNLOCK(inp);
4566 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4567 ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4568 (keyid->scact_assoc_id == SCTP_ALL_ASSOC))) {
4569 SCTP_INP_RLOCK(inp);
4570 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4571 SCTP_TCB_LOCK(stcb);
4572 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4573 SCTP_TCB_UNLOCK(stcb);
4575 SCTP_INP_RUNLOCK(inp);
4580 case SCTP_ENABLE_STREAM_RESET:
4582 struct sctp_assoc_value *av;
4584 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4585 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4586 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4590 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4592 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4593 SCTP_TCB_UNLOCK(stcb);
4595 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4596 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4597 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4598 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4599 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4600 SCTP_INP_WLOCK(inp);
4601 inp->local_strreset_support = (uint8_t)av->assoc_value;
4602 SCTP_INP_WUNLOCK(inp);
4604 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4605 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4606 (av->assoc_id == SCTP_ALL_ASSOC))) {
4607 SCTP_INP_RLOCK(inp);
4608 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4609 SCTP_TCB_LOCK(stcb);
4610 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4611 SCTP_TCB_UNLOCK(stcb);
4613 SCTP_INP_RUNLOCK(inp);
4618 case SCTP_RESET_STREAMS:
4620 struct sctp_reset_streams *strrst;
4621 int i, send_out = 0;
4624 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4625 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4627 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4631 if (stcb->asoc.reconfig_supported == 0) {
4633 * Peer does not support the chunk type.
4635 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4637 SCTP_TCB_UNLOCK(stcb);
4640 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4641 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4643 SCTP_TCB_UNLOCK(stcb);
4646 if (sizeof(struct sctp_reset_streams) +
4647 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4649 SCTP_TCB_UNLOCK(stcb);
4652 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4654 if (stcb->asoc.stream_reset_outstanding) {
4655 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4657 SCTP_TCB_UNLOCK(stcb);
4661 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4664 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4665 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4667 SCTP_TCB_UNLOCK(stcb);
4670 if ((send_in == 0) && (send_out == 0)) {
4671 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4673 SCTP_TCB_UNLOCK(stcb);
4676 for (i = 0; i < strrst->srs_number_streams; i++) {
4678 (strrst->srs_stream_list[i] >= stcb->asoc.streamincnt)) {
4679 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4684 (strrst->srs_stream_list[i] >= stcb->asoc.streamoutcnt)) {
4685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4691 SCTP_TCB_UNLOCK(stcb);
4698 if (strrst->srs_number_streams) {
4699 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4700 strm = strrst->srs_stream_list[i];
4701 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4702 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4708 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4709 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4710 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4717 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4718 strrst->srs_stream_list,
4719 send_in, 0, 0, 0, 0, 0);
4721 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4724 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4727 * For outgoing streams don't report any
4728 * problems in sending the request to the
4729 * application. XXX: Double check resetting
4734 SCTP_TCB_UNLOCK(stcb);
4737 case SCTP_ADD_STREAMS:
4739 struct sctp_add_streams *stradd;
4740 uint8_t addstream = 0;
4741 uint16_t add_o_strmcnt = 0;
4742 uint16_t add_i_strmcnt = 0;
4744 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4745 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4747 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4751 if (stcb->asoc.reconfig_supported == 0) {
4753 * Peer does not support the chunk type.
4755 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4757 SCTP_TCB_UNLOCK(stcb);
4760 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4761 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4763 SCTP_TCB_UNLOCK(stcb);
4766 if (stcb->asoc.stream_reset_outstanding) {
4767 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4769 SCTP_TCB_UNLOCK(stcb);
4772 if ((stradd->sas_outstrms == 0) &&
4773 (stradd->sas_instrms == 0)) {
4777 if (stradd->sas_outstrms) {
4779 /* We allocate here */
4780 add_o_strmcnt = stradd->sas_outstrms;
4781 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4782 /* You can't have more than 64k */
4787 if (stradd->sas_instrms) {
4792 * We allocate inside
4793 * sctp_send_str_reset_req()
4795 add_i_strmcnt = stradd->sas_instrms;
4796 cnt = add_i_strmcnt;
4797 cnt += stcb->asoc.streamincnt;
4798 if (cnt > 0x0000ffff) {
4799 /* You can't have more than 64k */
4803 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4804 /* More than you are allowed */
4809 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4810 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4812 SCTP_TCB_UNLOCK(stcb);
4815 case SCTP_RESET_ASSOC:
4820 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4821 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4823 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4827 if (stcb->asoc.reconfig_supported == 0) {
4829 * Peer does not support the chunk type.
4831 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4833 SCTP_TCB_UNLOCK(stcb);
4836 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4837 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4839 SCTP_TCB_UNLOCK(stcb);
4842 if (stcb->asoc.stream_reset_outstanding) {
4843 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4845 SCTP_TCB_UNLOCK(stcb);
4849 * Is there any data pending in the send or sent
4852 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4853 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4856 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4857 SCTP_TCB_UNLOCK(stcb);
4860 /* Do any streams have data queued? */
4861 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4862 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4866 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4867 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4868 SCTP_TCB_UNLOCK(stcb);
4871 case SCTP_CONNECT_X:
4872 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4877 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4879 case SCTP_CONNECT_X_DELAYED:
4880 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4885 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4887 case SCTP_CONNECT_X_COMPLETE:
4889 struct sockaddr *sa;
4891 /* FIXME MT: check correct? */
4892 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4895 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4896 SCTP_INP_RLOCK(inp);
4897 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4899 SCTP_TCB_LOCK(stcb);
4901 SCTP_INP_RUNLOCK(inp);
4904 * We increment here since
4905 * sctp_findassociation_ep_addr() wil do a
4906 * decrement if it finds the stcb as long as
4907 * the locked tcb (last argument) is NOT a
4910 SCTP_INP_INCR_REF(inp);
4911 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4913 SCTP_INP_DECR_REF(inp);
4918 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4922 if (stcb->asoc.delayed_connection == 1) {
4923 stcb->asoc.delayed_connection = 0;
4924 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4925 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4926 stcb->asoc.primary_destination,
4927 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4928 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4931 * already expired or did not use delayed
4934 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4937 SCTP_TCB_UNLOCK(stcb);
4940 case SCTP_MAX_BURST:
4942 struct sctp_assoc_value *av;
4944 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4945 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4948 stcb->asoc.max_burst = av->assoc_value;
4949 SCTP_TCB_UNLOCK(stcb);
4951 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4952 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4953 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4954 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4955 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4956 SCTP_INP_WLOCK(inp);
4957 inp->sctp_ep.max_burst = av->assoc_value;
4958 SCTP_INP_WUNLOCK(inp);
4960 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4961 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4962 (av->assoc_id == SCTP_ALL_ASSOC))) {
4963 SCTP_INP_RLOCK(inp);
4964 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4965 SCTP_TCB_LOCK(stcb);
4966 stcb->asoc.max_burst = av->assoc_value;
4967 SCTP_TCB_UNLOCK(stcb);
4969 SCTP_INP_RUNLOCK(inp);
4976 struct sctp_assoc_value *av;
4979 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4980 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4982 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4983 ovh = SCTP_MED_OVERHEAD;
4985 ovh = SCTP_MED_V4_OVERHEAD;
4988 if (av->assoc_value) {
4989 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4991 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
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);
5001 * FIXME MT: I think this is not in
5002 * tune with the API ID
5004 if (av->assoc_value) {
5005 inp->sctp_frag_point = (av->assoc_value + ovh);
5007 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
5009 SCTP_INP_WUNLOCK(inp);
5011 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5019 struct sctp_event_subscribe *events;
5021 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5023 SCTP_INP_WLOCK(inp);
5024 if (events->sctp_data_io_event) {
5025 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5027 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5030 if (events->sctp_association_event) {
5031 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5033 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5036 if (events->sctp_address_event) {
5037 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5039 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5042 if (events->sctp_send_failure_event) {
5043 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5045 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5048 if (events->sctp_peer_error_event) {
5049 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5051 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5054 if (events->sctp_shutdown_event) {
5055 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5057 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5060 if (events->sctp_partial_delivery_event) {
5061 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5063 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5066 if (events->sctp_adaptation_layer_event) {
5067 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5069 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5072 if (events->sctp_authentication_event) {
5073 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5075 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5078 if (events->sctp_sender_dry_event) {
5079 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5081 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5084 if (events->sctp_stream_reset_event) {
5085 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5087 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5089 SCTP_INP_WUNLOCK(inp);
5091 SCTP_INP_RLOCK(inp);
5092 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5093 SCTP_TCB_LOCK(stcb);
5094 if (events->sctp_association_event) {
5095 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5097 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5099 if (events->sctp_address_event) {
5100 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5102 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5104 if (events->sctp_send_failure_event) {
5105 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5107 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5109 if (events->sctp_peer_error_event) {
5110 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5112 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5114 if (events->sctp_shutdown_event) {
5115 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5117 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5119 if (events->sctp_partial_delivery_event) {
5120 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5122 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5124 if (events->sctp_adaptation_layer_event) {
5125 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5127 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5129 if (events->sctp_authentication_event) {
5130 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5132 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5134 if (events->sctp_sender_dry_event) {
5135 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5137 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5139 if (events->sctp_stream_reset_event) {
5140 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5142 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5144 SCTP_TCB_UNLOCK(stcb);
5147 * Send up the sender dry event only for 1-to-1
5150 if (events->sctp_sender_dry_event) {
5151 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5152 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5153 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5155 SCTP_TCB_LOCK(stcb);
5156 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5157 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5158 (stcb->asoc.stream_queue_cnt == 0)) {
5159 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5161 SCTP_TCB_UNLOCK(stcb);
5165 SCTP_INP_RUNLOCK(inp);
5168 case SCTP_ADAPTATION_LAYER:
5170 struct sctp_setadaptation *adap_bits;
5172 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5173 SCTP_INP_WLOCK(inp);
5174 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5175 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5176 SCTP_INP_WUNLOCK(inp);
5180 case SCTP_SET_INITIAL_DBG_SEQ:
5184 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5185 SCTP_INP_WLOCK(inp);
5186 inp->sctp_ep.initial_sequence_debug = *vvv;
5187 SCTP_INP_WUNLOCK(inp);
5191 case SCTP_DEFAULT_SEND_PARAM:
5193 struct sctp_sndrcvinfo *s_info;
5195 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5196 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5199 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5200 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5202 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5205 SCTP_TCB_UNLOCK(stcb);
5207 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5208 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5209 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5210 ((s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5211 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)))) {
5212 SCTP_INP_WLOCK(inp);
5213 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5214 SCTP_INP_WUNLOCK(inp);
5216 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5217 ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5218 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC))) {
5219 SCTP_INP_RLOCK(inp);
5220 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5221 SCTP_TCB_LOCK(stcb);
5222 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5223 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5225 SCTP_TCB_UNLOCK(stcb);
5227 SCTP_INP_RUNLOCK(inp);
5232 case SCTP_PEER_ADDR_PARAMS:
5234 struct sctp_paddrparams *paddrp;
5235 struct sctp_nets *net;
5236 struct sockaddr *addr;
5237 #if defined(INET) && defined(INET6)
5238 struct sockaddr_in sin_store;
5241 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5242 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5244 #if defined(INET) && defined(INET6)
5245 if (paddrp->spp_address.ss_family == AF_INET6) {
5246 struct sockaddr_in6 *sin6;
5248 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5249 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5250 in6_sin6_2_sin(&sin_store, sin6);
5251 addr = (struct sockaddr *)&sin_store;
5253 addr = (struct sockaddr *)&paddrp->spp_address;
5256 addr = (struct sockaddr *)&paddrp->spp_address;
5259 addr = (struct sockaddr *)&paddrp->spp_address;
5262 net = sctp_findnet(stcb, addr);
5265 * We increment here since
5266 * sctp_findassociation_ep_addr() wil do a
5267 * decrement if it finds the stcb as long as
5268 * the locked tcb (last argument) is NOT a
5272 SCTP_INP_INCR_REF(inp);
5273 stcb = sctp_findassociation_ep_addr(&inp, addr,
5276 SCTP_INP_DECR_REF(inp);
5279 if ((stcb != NULL) && (net == NULL)) {
5281 if (addr->sa_family == AF_INET) {
5282 struct sockaddr_in *sin;
5284 sin = (struct sockaddr_in *)addr;
5285 if (sin->sin_addr.s_addr != INADDR_ANY) {
5286 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5287 SCTP_TCB_UNLOCK(stcb);
5294 if (addr->sa_family == AF_INET6) {
5295 struct sockaddr_in6 *sin6;
5297 sin6 = (struct sockaddr_in6 *)addr;
5298 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5299 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5300 SCTP_TCB_UNLOCK(stcb);
5307 error = EAFNOSUPPORT;
5308 SCTP_TCB_UNLOCK(stcb);
5309 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5314 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5316 SCTP_TCB_UNLOCK(stcb);
5317 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5321 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5323 SCTP_TCB_UNLOCK(stcb);
5324 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5327 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) &&
5328 (paddrp->spp_pathmtu > 0) &&
5329 ((paddrp->spp_pathmtu < SCTP_SMALLEST_PMTU) ||
5330 (paddrp->spp_pathmtu > SCTP_LARGEST_PMTU))) {
5332 SCTP_TCB_UNLOCK(stcb);
5333 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5338 /************************TCB SPECIFIC SET ******************/
5340 /************************NET SPECIFIC SET ******************/
5341 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5342 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5343 !(net->dest_state & SCTP_ADDR_NOHB)) {
5344 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5345 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5347 net->dest_state |= SCTP_ADDR_NOHB;
5349 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5350 if (paddrp->spp_hbinterval) {
5351 net->heart_beat_delay = paddrp->spp_hbinterval;
5352 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5353 net->heart_beat_delay = 0;
5355 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5356 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5357 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5358 net->dest_state &= ~SCTP_ADDR_NOHB;
5360 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5361 if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
5362 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5363 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5364 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5367 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5368 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5369 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5370 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5372 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5373 if (paddrp->spp_pathmtu > 0) {
5374 net->mtu = paddrp->spp_pathmtu;
5375 switch (net->ro._l_addr.sa.sa_family) {
5378 net->mtu += SCTP_MIN_V4_OVERHEAD;
5383 net->mtu += SCTP_MIN_OVERHEAD;
5389 if (net->mtu < stcb->asoc.smallest_mtu) {
5390 sctp_pathmtu_adjustment(stcb, net->mtu);
5394 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5395 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5396 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5398 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5400 if (paddrp->spp_pathmaxrxt > 0) {
5401 if (net->dest_state & SCTP_ADDR_PF) {
5402 if (net->error_count > paddrp->spp_pathmaxrxt) {
5403 net->dest_state &= ~SCTP_ADDR_PF;
5406 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5407 (net->error_count > net->pf_threshold)) {
5408 net->dest_state |= SCTP_ADDR_PF;
5409 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5410 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5411 stcb->sctp_ep, stcb, net,
5412 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5413 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5416 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5417 if (net->error_count > paddrp->spp_pathmaxrxt) {
5418 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5419 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5422 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5423 net->dest_state |= SCTP_ADDR_REACHABLE;
5424 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5427 net->failure_threshold = paddrp->spp_pathmaxrxt;
5429 if (paddrp->spp_flags & SPP_DSCP) {
5430 net->dscp = paddrp->spp_dscp & 0xfc;
5434 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5435 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5436 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5437 net->flowlabel |= 0x80000000;
5442 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5443 if (paddrp->spp_pathmaxrxt > 0) {
5444 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5445 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5446 if (net->dest_state & SCTP_ADDR_PF) {
5447 if (net->error_count > paddrp->spp_pathmaxrxt) {
5448 net->dest_state &= ~SCTP_ADDR_PF;
5451 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5452 (net->error_count > net->pf_threshold)) {
5453 net->dest_state |= SCTP_ADDR_PF;
5454 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5455 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5456 stcb->sctp_ep, stcb, net,
5457 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5458 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5461 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5462 if (net->error_count > paddrp->spp_pathmaxrxt) {
5463 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5464 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5467 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5468 net->dest_state |= SCTP_ADDR_REACHABLE;
5469 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5472 net->failure_threshold = paddrp->spp_pathmaxrxt;
5475 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5476 if (paddrp->spp_hbinterval != 0) {
5477 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5478 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5479 stcb->asoc.heart_beat_delay = 0;
5481 /* Turn back on the timer */
5482 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5483 if (paddrp->spp_hbinterval != 0) {
5484 net->heart_beat_delay = paddrp->spp_hbinterval;
5485 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5486 net->heart_beat_delay = 0;
5488 if (net->dest_state & SCTP_ADDR_NOHB) {
5489 net->dest_state &= ~SCTP_ADDR_NOHB;
5491 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5492 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5493 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5495 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5497 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5498 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5499 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5500 net->dest_state |= SCTP_ADDR_NOHB;
5501 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5502 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5504 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5508 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5510 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5511 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5512 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5513 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5514 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5516 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5517 if (paddrp->spp_pathmtu > 0) {
5518 net->mtu = paddrp->spp_pathmtu;
5519 switch (net->ro._l_addr.sa.sa_family) {
5522 net->mtu += SCTP_MIN_V4_OVERHEAD;
5527 net->mtu += SCTP_MIN_OVERHEAD;
5533 if (net->mtu < stcb->asoc.smallest_mtu) {
5534 sctp_pathmtu_adjustment(stcb, net->mtu);
5538 if (paddrp->spp_pathmtu > 0) {
5539 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5541 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5543 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5544 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5545 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5546 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5548 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5550 stcb->asoc.default_mtu = 0;
5551 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5553 if (paddrp->spp_flags & SPP_DSCP) {
5554 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5555 net->dscp = paddrp->spp_dscp & 0xfc;
5558 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5559 stcb->asoc.default_dscp |= 0x01;
5562 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5563 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5564 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5565 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5566 net->flowlabel |= 0x80000000;
5569 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5570 stcb->asoc.default_flowlabel |= 0x80000000;
5574 SCTP_TCB_UNLOCK(stcb);
5576 /************************NO TCB, SET TO default stuff ******************/
5577 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5578 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5579 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5580 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
5581 SCTP_INP_WLOCK(inp);
5583 * For the TOS/FLOWLABEL stuff you
5584 * set it with the options on the
5587 if (paddrp->spp_pathmaxrxt > 0) {
5588 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5591 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5592 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5593 else if (paddrp->spp_hbinterval != 0) {
5594 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5595 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5596 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5599 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5600 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5601 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5602 } else if (paddrp->spp_hbinterval) {
5603 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5605 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5606 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5607 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5609 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5610 inp->sctp_ep.default_mtu = 0;
5611 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5612 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5613 if (paddrp->spp_pathmtu > 0) {
5614 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5616 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5618 if (paddrp->spp_flags & SPP_DSCP) {
5619 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5620 inp->sctp_ep.default_dscp |= 0x01;
5623 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5624 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5625 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5626 inp->sctp_ep.default_flowlabel |= 0x80000000;
5630 SCTP_INP_WUNLOCK(inp);
5632 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5640 struct sctp_rtoinfo *srto;
5641 uint32_t new_init, new_min, new_max;
5643 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5644 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5647 if (srto->srto_initial)
5648 new_init = srto->srto_initial;
5650 new_init = stcb->asoc.initial_rto;
5652 new_max = srto->srto_max;
5654 new_max = stcb->asoc.maxrto;
5656 new_min = srto->srto_min;
5658 new_min = stcb->asoc.minrto;
5659 if ((new_min <= new_init) && (new_init <= new_max)) {
5660 stcb->asoc.initial_rto = new_init;
5661 stcb->asoc.maxrto = new_max;
5662 stcb->asoc.minrto = new_min;
5664 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5667 SCTP_TCB_UNLOCK(stcb);
5669 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5670 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5671 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5672 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
5673 SCTP_INP_WLOCK(inp);
5674 if (srto->srto_initial)
5675 new_init = srto->srto_initial;
5677 new_init = inp->sctp_ep.initial_rto;
5679 new_max = srto->srto_max;
5681 new_max = inp->sctp_ep.sctp_maxrto;
5683 new_min = srto->srto_min;
5685 new_min = inp->sctp_ep.sctp_minrto;
5686 if ((new_min <= new_init) && (new_init <= new_max)) {
5687 inp->sctp_ep.initial_rto = new_init;
5688 inp->sctp_ep.sctp_maxrto = new_max;
5689 inp->sctp_ep.sctp_minrto = new_min;
5691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5694 SCTP_INP_WUNLOCK(inp);
5696 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5702 case SCTP_ASSOCINFO:
5704 struct sctp_assocparams *sasoc;
5706 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5707 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5708 if (sasoc->sasoc_cookie_life > 0) {
5709 /* boundary check the cookie life */
5710 if (sasoc->sasoc_cookie_life < SCTP_MIN_COOKIE_LIFE) {
5711 sasoc->sasoc_cookie_life = SCTP_MIN_COOKIE_LIFE;
5713 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5714 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5718 if (sasoc->sasoc_asocmaxrxt > 0) {
5719 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5721 if (sasoc->sasoc_cookie_life > 0) {
5722 stcb->asoc.cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5724 SCTP_TCB_UNLOCK(stcb);
5726 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5727 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5728 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5729 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
5730 SCTP_INP_WLOCK(inp);
5731 if (sasoc->sasoc_asocmaxrxt > 0) {
5732 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5734 if (sasoc->sasoc_cookie_life > 0) {
5735 inp->sctp_ep.def_cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5737 SCTP_INP_WUNLOCK(inp);
5739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5747 struct sctp_initmsg *sinit;
5749 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5750 SCTP_INP_WLOCK(inp);
5751 if (sinit->sinit_num_ostreams)
5752 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5754 if (sinit->sinit_max_instreams)
5755 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5757 if (sinit->sinit_max_attempts)
5758 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5760 if (sinit->sinit_max_init_timeo)
5761 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5762 SCTP_INP_WUNLOCK(inp);
5765 case SCTP_PRIMARY_ADDR:
5767 struct sctp_setprim *spa;
5768 struct sctp_nets *net;
5769 struct sockaddr *addr;
5770 #if defined(INET) && defined(INET6)
5771 struct sockaddr_in sin_store;
5774 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5775 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5777 #if defined(INET) && defined(INET6)
5778 if (spa->ssp_addr.ss_family == AF_INET6) {
5779 struct sockaddr_in6 *sin6;
5781 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5782 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5783 in6_sin6_2_sin(&sin_store, sin6);
5784 addr = (struct sockaddr *)&sin_store;
5786 addr = (struct sockaddr *)&spa->ssp_addr;
5789 addr = (struct sockaddr *)&spa->ssp_addr;
5792 addr = (struct sockaddr *)&spa->ssp_addr;
5795 net = sctp_findnet(stcb, addr);
5798 * We increment here since
5799 * sctp_findassociation_ep_addr() wil do a
5800 * decrement if it finds the stcb as long as
5801 * the locked tcb (last argument) is NOT a
5805 SCTP_INP_INCR_REF(inp);
5806 stcb = sctp_findassociation_ep_addr(&inp, addr,
5809 SCTP_INP_DECR_REF(inp);
5813 if ((stcb != NULL) && (net != NULL)) {
5814 if (net != stcb->asoc.primary_destination) {
5815 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5816 /* Ok we need to set it */
5817 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5818 if ((stcb->asoc.alternate) &&
5819 (!(net->dest_state & SCTP_ADDR_PF)) &&
5820 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5821 sctp_free_remote_addr(stcb->asoc.alternate);
5822 stcb->asoc.alternate = NULL;
5825 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5829 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5834 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5838 SCTP_TCB_UNLOCK(stcb);
5842 case SCTP_SET_DYNAMIC_PRIMARY:
5844 union sctp_sockstore *ss;
5846 error = priv_check(curthread,
5847 PRIV_NETINET_RESERVEDPORT);
5851 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5852 /* SUPER USER CHECK? */
5853 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5856 case SCTP_SET_PEER_PRIMARY_ADDR:
5858 struct sctp_setpeerprim *sspp;
5859 struct sockaddr *addr;
5860 #if defined(INET) && defined(INET6)
5861 struct sockaddr_in sin_store;
5864 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5865 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5867 struct sctp_ifa *ifa;
5869 #if defined(INET) && defined(INET6)
5870 if (sspp->sspp_addr.ss_family == AF_INET6) {
5871 struct sockaddr_in6 *sin6;
5873 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5874 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5875 in6_sin6_2_sin(&sin_store, sin6);
5876 addr = (struct sockaddr *)&sin_store;
5878 addr = (struct sockaddr *)&sspp->sspp_addr;
5881 addr = (struct sockaddr *)&sspp->sspp_addr;
5884 addr = (struct sockaddr *)&sspp->sspp_addr;
5886 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5888 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5892 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5894 * Must validate the ifa found is in
5897 struct sctp_laddr *laddr;
5900 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5901 if (laddr->ifa == NULL) {
5902 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5906 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5907 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5910 if (laddr->ifa == ifa) {
5916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5921 switch (addr->sa_family) {
5925 struct sockaddr_in *sin;
5927 sin = (struct sockaddr_in *)addr;
5928 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5929 &sin->sin_addr) != 0) {
5930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5940 struct sockaddr_in6 *sin6;
5942 sin6 = (struct sockaddr_in6 *)addr;
5943 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5944 &sin6->sin6_addr) != 0) {
5945 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5953 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5958 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5959 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5962 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5964 SCTP_TCB_UNLOCK(stcb);
5966 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5971 case SCTP_BINDX_ADD_ADDR:
5973 struct sockaddr *sa;
5976 td = (struct thread *)p;
5977 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
5979 if (sa->sa_family == AF_INET) {
5980 if (optsize < sizeof(struct sockaddr_in)) {
5981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5986 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
5987 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5993 if (sa->sa_family == AF_INET6) {
5994 if (optsize < sizeof(struct sockaddr_in6)) {
5995 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6000 (error = prison_local_ip6(td->td_ucred,
6001 &(((struct sockaddr_in6 *)sa)->sin6_addr),
6002 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6003 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6009 error = EAFNOSUPPORT;
6012 sctp_bindx_add_address(so, inp, sa, vrf_id, &error, p);
6015 case SCTP_BINDX_REM_ADDR:
6017 struct sockaddr *sa;
6020 td = (struct thread *)p;
6022 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
6024 if (sa->sa_family == AF_INET) {
6025 if (optsize < sizeof(struct sockaddr_in)) {
6026 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6031 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
6032 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6038 if (sa->sa_family == AF_INET6) {
6039 if (optsize < sizeof(struct sockaddr_in6)) {
6040 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6045 (error = prison_local_ip6(td->td_ucred,
6046 &(((struct sockaddr_in6 *)sa)->sin6_addr),
6047 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6048 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6054 error = EAFNOSUPPORT;
6057 sctp_bindx_delete_address(inp, sa, vrf_id, &error);
6062 struct sctp_event *event;
6063 uint32_t event_type;
6065 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6066 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6067 switch (event->se_type) {
6068 case SCTP_ASSOC_CHANGE:
6069 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6071 case SCTP_PEER_ADDR_CHANGE:
6072 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6074 case SCTP_REMOTE_ERROR:
6075 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6077 case SCTP_SEND_FAILED:
6078 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6080 case SCTP_SHUTDOWN_EVENT:
6081 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6083 case SCTP_ADAPTATION_INDICATION:
6084 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6086 case SCTP_PARTIAL_DELIVERY_EVENT:
6087 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6089 case SCTP_AUTHENTICATION_EVENT:
6090 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6092 case SCTP_STREAM_RESET_EVENT:
6093 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6095 case SCTP_SENDER_DRY_EVENT:
6096 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6098 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6100 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6103 case SCTP_ASSOC_RESET_EVENT:
6104 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6106 case SCTP_STREAM_CHANGE_EVENT:
6107 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6109 case SCTP_SEND_FAILED_EVENT:
6110 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6114 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6118 if (event_type > 0) {
6121 sctp_stcb_feature_on(inp, stcb, event_type);
6122 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6123 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6124 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6125 (stcb->asoc.stream_queue_cnt == 0)) {
6126 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6130 sctp_stcb_feature_off(inp, stcb, event_type);
6132 SCTP_TCB_UNLOCK(stcb);
6135 * We don't want to send up a storm
6136 * of events, so return an error for
6139 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6140 (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6141 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6142 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6143 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6147 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6148 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6149 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6150 ((event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6151 (event->se_assoc_id == SCTP_ALL_ASSOC)))) {
6152 SCTP_INP_WLOCK(inp);
6154 sctp_feature_on(inp, event_type);
6156 sctp_feature_off(inp, event_type);
6158 SCTP_INP_WUNLOCK(inp);
6160 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6161 ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6162 (event->se_assoc_id == SCTP_ALL_ASSOC))) {
6163 SCTP_INP_RLOCK(inp);
6164 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6165 SCTP_TCB_LOCK(stcb);
6167 sctp_stcb_feature_on(inp, stcb, event_type);
6169 sctp_stcb_feature_off(inp, stcb, event_type);
6171 SCTP_TCB_UNLOCK(stcb);
6173 SCTP_INP_RUNLOCK(inp);
6178 SCTP_TCB_UNLOCK(stcb);
6183 case SCTP_RECVRCVINFO:
6187 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6188 SCTP_INP_WLOCK(inp);
6190 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6192 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6194 SCTP_INP_WUNLOCK(inp);
6197 case SCTP_RECVNXTINFO:
6201 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6202 SCTP_INP_WLOCK(inp);
6204 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6206 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6208 SCTP_INP_WUNLOCK(inp);
6211 case SCTP_DEFAULT_SNDINFO:
6213 struct sctp_sndinfo *info;
6216 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6217 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6220 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6221 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6222 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6223 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6224 stcb->asoc.def_send.sinfo_flags |= policy;
6225 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6226 stcb->asoc.def_send.sinfo_context = info->snd_context;
6228 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6231 SCTP_TCB_UNLOCK(stcb);
6233 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6234 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6235 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6236 ((info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6237 (info->snd_assoc_id == SCTP_ALL_ASSOC)))) {
6238 SCTP_INP_WLOCK(inp);
6239 inp->def_send.sinfo_stream = info->snd_sid;
6240 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6241 inp->def_send.sinfo_flags = info->snd_flags;
6242 inp->def_send.sinfo_flags |= policy;
6243 inp->def_send.sinfo_ppid = info->snd_ppid;
6244 inp->def_send.sinfo_context = info->snd_context;
6245 SCTP_INP_WUNLOCK(inp);
6247 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6248 ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6249 (info->snd_assoc_id == SCTP_ALL_ASSOC))) {
6250 SCTP_INP_RLOCK(inp);
6251 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6252 SCTP_TCB_LOCK(stcb);
6253 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6254 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6255 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6256 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6257 stcb->asoc.def_send.sinfo_flags |= policy;
6258 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6259 stcb->asoc.def_send.sinfo_context = info->snd_context;
6261 SCTP_TCB_UNLOCK(stcb);
6263 SCTP_INP_RUNLOCK(inp);
6268 case SCTP_DEFAULT_PRINFO:
6270 struct sctp_default_prinfo *info;
6272 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6273 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6275 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6277 SCTP_TCB_UNLOCK(stcb);
6279 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6284 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6285 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6286 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6287 SCTP_TCB_UNLOCK(stcb);
6289 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6290 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6291 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6292 ((info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6293 (info->pr_assoc_id == SCTP_ALL_ASSOC)))) {
6294 SCTP_INP_WLOCK(inp);
6295 inp->def_send.sinfo_flags &= 0xfff0;
6296 inp->def_send.sinfo_flags |= info->pr_policy;
6297 inp->def_send.sinfo_timetolive = info->pr_value;
6298 SCTP_INP_WUNLOCK(inp);
6300 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6301 ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6302 (info->pr_assoc_id == SCTP_ALL_ASSOC))) {
6303 SCTP_INP_RLOCK(inp);
6304 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6305 SCTP_TCB_LOCK(stcb);
6306 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6307 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6308 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6309 SCTP_TCB_UNLOCK(stcb);
6311 SCTP_INP_RUNLOCK(inp);
6316 case SCTP_PEER_ADDR_THLDS:
6317 /* Applies to the specific association */
6319 struct sctp_paddrthlds *thlds;
6320 struct sctp_nets *net;
6321 struct sockaddr *addr;
6322 #if defined(INET) && defined(INET6)
6323 struct sockaddr_in sin_store;
6326 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6327 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6329 #if defined(INET) && defined(INET6)
6330 if (thlds->spt_address.ss_family == AF_INET6) {
6331 struct sockaddr_in6 *sin6;
6333 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6334 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6335 in6_sin6_2_sin(&sin_store, sin6);
6336 addr = (struct sockaddr *)&sin_store;
6338 addr = (struct sockaddr *)&thlds->spt_address;
6341 addr = (struct sockaddr *)&thlds->spt_address;
6344 addr = (struct sockaddr *)&thlds->spt_address;
6347 net = sctp_findnet(stcb, addr);
6350 * We increment here since
6351 * sctp_findassociation_ep_addr() wil do a
6352 * decrement if it finds the stcb as long as
6353 * the locked tcb (last argument) is NOT a
6357 SCTP_INP_INCR_REF(inp);
6358 stcb = sctp_findassociation_ep_addr(&inp, addr,
6361 SCTP_INP_DECR_REF(inp);
6364 if ((stcb != NULL) && (net == NULL)) {
6366 if (addr->sa_family == AF_INET) {
6367 struct sockaddr_in *sin;
6369 sin = (struct sockaddr_in *)addr;
6370 if (sin->sin_addr.s_addr != INADDR_ANY) {
6371 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6372 SCTP_TCB_UNLOCK(stcb);
6379 if (addr->sa_family == AF_INET6) {
6380 struct sockaddr_in6 *sin6;
6382 sin6 = (struct sockaddr_in6 *)addr;
6383 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6384 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6385 SCTP_TCB_UNLOCK(stcb);
6392 error = EAFNOSUPPORT;
6393 SCTP_TCB_UNLOCK(stcb);
6394 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6398 if (thlds->spt_pathcpthld != 0xffff) {
6400 SCTP_TCB_UNLOCK(stcb);
6403 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6408 net->failure_threshold = thlds->spt_pathmaxrxt;
6409 net->pf_threshold = thlds->spt_pathpfthld;
6410 if (net->dest_state & SCTP_ADDR_PF) {
6411 if ((net->error_count > net->failure_threshold) ||
6412 (net->error_count <= net->pf_threshold)) {
6413 net->dest_state &= ~SCTP_ADDR_PF;
6416 if ((net->error_count > net->pf_threshold) &&
6417 (net->error_count <= net->failure_threshold)) {
6418 net->dest_state |= SCTP_ADDR_PF;
6419 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6420 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6421 stcb->sctp_ep, stcb, net,
6422 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6423 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6426 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6427 if (net->error_count > net->failure_threshold) {
6428 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6429 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6432 if (net->error_count <= net->failure_threshold) {
6433 net->dest_state |= SCTP_ADDR_REACHABLE;
6434 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6438 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6439 net->failure_threshold = thlds->spt_pathmaxrxt;
6440 net->pf_threshold = thlds->spt_pathpfthld;
6441 if (net->dest_state & SCTP_ADDR_PF) {
6442 if ((net->error_count > net->failure_threshold) ||
6443 (net->error_count <= net->pf_threshold)) {
6444 net->dest_state &= ~SCTP_ADDR_PF;
6447 if ((net->error_count > net->pf_threshold) &&
6448 (net->error_count <= net->failure_threshold)) {
6449 net->dest_state |= SCTP_ADDR_PF;
6450 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6451 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6452 stcb->sctp_ep, stcb, net,
6453 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6454 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6457 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6458 if (net->error_count > net->failure_threshold) {
6459 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6460 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6463 if (net->error_count <= net->failure_threshold) {
6464 net->dest_state |= SCTP_ADDR_REACHABLE;
6465 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6469 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6470 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6472 SCTP_TCB_UNLOCK(stcb);
6474 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6475 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6476 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6477 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
6478 SCTP_INP_WLOCK(inp);
6479 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6480 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6481 SCTP_INP_WUNLOCK(inp);
6483 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6489 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6491 struct sctp_udpencaps *encaps;
6492 struct sctp_nets *net;
6493 struct sockaddr *addr;
6494 #if defined(INET) && defined(INET6)
6495 struct sockaddr_in sin_store;
6498 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6499 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6501 #if defined(INET) && defined(INET6)
6502 if (encaps->sue_address.ss_family == AF_INET6) {
6503 struct sockaddr_in6 *sin6;
6505 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6506 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6507 in6_sin6_2_sin(&sin_store, sin6);
6508 addr = (struct sockaddr *)&sin_store;
6510 addr = (struct sockaddr *)&encaps->sue_address;
6513 addr = (struct sockaddr *)&encaps->sue_address;
6516 addr = (struct sockaddr *)&encaps->sue_address;
6519 net = sctp_findnet(stcb, addr);
6522 * We increment here since
6523 * sctp_findassociation_ep_addr() wil do a
6524 * decrement if it finds the stcb as long as
6525 * the locked tcb (last argument) is NOT a
6529 SCTP_INP_INCR_REF(inp);
6530 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6532 SCTP_INP_DECR_REF(inp);
6535 if ((stcb != NULL) && (net == NULL)) {
6537 if (addr->sa_family == AF_INET) {
6538 struct sockaddr_in *sin;
6540 sin = (struct sockaddr_in *)addr;
6541 if (sin->sin_addr.s_addr != INADDR_ANY) {
6542 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6543 SCTP_TCB_UNLOCK(stcb);
6550 if (addr->sa_family == AF_INET6) {
6551 struct sockaddr_in6 *sin6;
6553 sin6 = (struct sockaddr_in6 *)addr;
6554 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6555 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6556 SCTP_TCB_UNLOCK(stcb);
6563 error = EAFNOSUPPORT;
6564 SCTP_TCB_UNLOCK(stcb);
6565 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6572 net->port = encaps->sue_port;
6574 stcb->asoc.port = encaps->sue_port;
6576 SCTP_TCB_UNLOCK(stcb);
6578 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6579 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6580 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6581 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
6582 SCTP_INP_WLOCK(inp);
6583 inp->sctp_ep.port = encaps->sue_port;
6584 SCTP_INP_WUNLOCK(inp);
6586 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6592 case SCTP_ECN_SUPPORTED:
6594 struct sctp_assoc_value *av;
6596 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6597 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6600 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6602 SCTP_TCB_UNLOCK(stcb);
6604 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6605 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6606 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6607 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6608 SCTP_INP_WLOCK(inp);
6609 if (av->assoc_value == 0) {
6610 inp->ecn_supported = 0;
6612 inp->ecn_supported = 1;
6614 SCTP_INP_WUNLOCK(inp);
6616 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6622 case SCTP_PR_SUPPORTED:
6624 struct sctp_assoc_value *av;
6626 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6627 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6630 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6632 SCTP_TCB_UNLOCK(stcb);
6634 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6635 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6636 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6637 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6638 SCTP_INP_WLOCK(inp);
6639 if (av->assoc_value == 0) {
6640 inp->prsctp_supported = 0;
6642 inp->prsctp_supported = 1;
6644 SCTP_INP_WUNLOCK(inp);
6646 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6652 case SCTP_AUTH_SUPPORTED:
6654 struct sctp_assoc_value *av;
6656 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6657 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6662 SCTP_TCB_UNLOCK(stcb);
6664 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6665 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6666 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6667 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6668 if ((av->assoc_value == 0) &&
6669 (inp->asconf_supported == 1)) {
6671 * AUTH is required for
6674 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6677 SCTP_INP_WLOCK(inp);
6678 if (av->assoc_value == 0) {
6679 inp->auth_supported = 0;
6681 inp->auth_supported = 1;
6683 SCTP_INP_WUNLOCK(inp);
6686 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6692 case SCTP_ASCONF_SUPPORTED:
6694 struct sctp_assoc_value *av;
6696 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6697 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6700 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6702 SCTP_TCB_UNLOCK(stcb);
6704 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6705 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6706 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6707 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6708 if ((av->assoc_value != 0) &&
6709 (inp->auth_supported == 0)) {
6711 * AUTH is required for
6714 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6717 SCTP_INP_WLOCK(inp);
6718 if (av->assoc_value == 0) {
6719 inp->asconf_supported = 0;
6720 sctp_auth_delete_chunk(SCTP_ASCONF,
6721 inp->sctp_ep.local_auth_chunks);
6722 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6723 inp->sctp_ep.local_auth_chunks);
6725 inp->asconf_supported = 1;
6726 sctp_auth_add_chunk(SCTP_ASCONF,
6727 inp->sctp_ep.local_auth_chunks);
6728 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6729 inp->sctp_ep.local_auth_chunks);
6731 SCTP_INP_WUNLOCK(inp);
6734 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6740 case SCTP_RECONFIG_SUPPORTED:
6742 struct sctp_assoc_value *av;
6744 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6745 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6748 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6750 SCTP_TCB_UNLOCK(stcb);
6752 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6753 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6754 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6755 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6756 SCTP_INP_WLOCK(inp);
6757 if (av->assoc_value == 0) {
6758 inp->reconfig_supported = 0;
6760 inp->reconfig_supported = 1;
6762 SCTP_INP_WUNLOCK(inp);
6764 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6770 case SCTP_NRSACK_SUPPORTED:
6772 struct sctp_assoc_value *av;
6774 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6775 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6778 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6780 SCTP_TCB_UNLOCK(stcb);
6782 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6783 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6784 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6785 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6786 SCTP_INP_WLOCK(inp);
6787 if (av->assoc_value == 0) {
6788 inp->nrsack_supported = 0;
6790 inp->nrsack_supported = 1;
6792 SCTP_INP_WUNLOCK(inp);
6794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6800 case SCTP_PKTDROP_SUPPORTED:
6802 struct sctp_assoc_value *av;
6804 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6805 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6808 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6810 SCTP_TCB_UNLOCK(stcb);
6812 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6813 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6814 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6815 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6816 SCTP_INP_WLOCK(inp);
6817 if (av->assoc_value == 0) {
6818 inp->pktdrop_supported = 0;
6820 inp->pktdrop_supported = 1;
6822 SCTP_INP_WUNLOCK(inp);
6824 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6832 struct sctp_assoc_value *av;
6833 struct sctp_nets *net;
6835 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6836 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6839 stcb->asoc.max_cwnd = av->assoc_value;
6840 if (stcb->asoc.max_cwnd > 0) {
6841 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6842 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6843 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6844 net->cwnd = stcb->asoc.max_cwnd;
6845 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6846 net->cwnd = net->mtu - sizeof(struct sctphdr);
6851 SCTP_TCB_UNLOCK(stcb);
6853 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6854 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6855 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6856 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6857 SCTP_INP_WLOCK(inp);
6858 inp->max_cwnd = av->assoc_value;
6859 SCTP_INP_WUNLOCK(inp);
6861 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6868 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6869 error = ENOPROTOOPT;
6871 } /* end switch (opt) */
6876 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6878 struct epoch_tracker et;
6879 struct sctp_inpcb *inp;
6880 void *optval = NULL;
6885 if ((sopt->sopt_level == SOL_SOCKET) &&
6886 (sopt->sopt_name == SO_SETFIB)) {
6887 inp = (struct sctp_inpcb *)so->so_pcb;
6889 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6892 SCTP_INP_WLOCK(inp);
6893 inp->fibnum = so->so_fibnum;
6894 SCTP_INP_WUNLOCK(inp);
6897 if (sopt->sopt_level != IPPROTO_SCTP) {
6898 /* wrong proto level... send back up to IP */
6900 if (INP_CHECK_SOCKAF(so, AF_INET6))
6901 error = ip6_ctloutput(so, sopt);
6903 #if defined(INET) && defined(INET6)
6907 error = ip_ctloutput(so, sopt);
6911 optsize = sopt->sopt_valsize;
6912 if (optsize > SCTP_SOCKET_OPTION_LIMIT) {
6913 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6917 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6918 if (optval == NULL) {
6919 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6922 error = sooptcopyin(sopt, optval, optsize, optsize);
6924 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6928 p = (void *)sopt->sopt_td;
6929 if (sopt->sopt_dir == SOPT_SET) {
6930 NET_EPOCH_ENTER(et);
6931 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6933 } else if (sopt->sopt_dir == SOPT_GET) {
6934 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6936 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6939 if ((error == 0) && (optval != NULL)) {
6940 error = sooptcopyout(sopt, optval, optsize);
6941 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6942 } else if (optval != NULL) {
6943 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6951 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6953 struct epoch_tracker et;
6955 int create_lock_on = 0;
6957 struct sctp_inpcb *inp;
6958 struct sctp_tcb *stcb = NULL;
6960 inp = (struct sctp_inpcb *)so->so_pcb;
6962 /* I made the same as TCP since we are not setup? */
6963 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6964 return (ECONNRESET);
6967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6971 switch (addr->sa_family) {
6975 struct sockaddr_in6 *sin6;
6977 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6978 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6981 sin6 = (struct sockaddr_in6 *)addr;
6982 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6->sin6_addr)) != 0) {
6983 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6992 struct sockaddr_in *sin;
6994 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6995 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6998 sin = (struct sockaddr_in *)addr;
6999 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sin->sin_addr)) != 0) {
7000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7007 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
7008 return (EAFNOSUPPORT);
7010 SCTP_INP_INCR_REF(inp);
7011 SCTP_ASOC_CREATE_LOCK(inp);
7013 NET_EPOCH_ENTER(et);
7015 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
7016 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
7017 /* Should I really unlock ? */
7018 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
7023 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
7024 (addr->sa_family == AF_INET6)) {
7025 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7030 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
7031 SCTP_PCB_FLAGS_UNBOUND) {
7032 /* Bind a ephemeral port */
7033 error = sctp_inpcb_bind(so, NULL, NULL, p);
7038 /* Now do we connect? */
7039 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
7040 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
7041 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7045 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7046 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7047 /* We are already connected AND the TCP model */
7048 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7052 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7053 SCTP_INP_RLOCK(inp);
7054 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7055 SCTP_INP_RUNLOCK(inp);
7058 * We increment here since sctp_findassociation_ep_addr()
7059 * will do a decrement if it finds the stcb as long as the
7060 * locked tcb (last argument) is NOT a TCB.. aka NULL.
7062 SCTP_INP_INCR_REF(inp);
7063 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7065 SCTP_INP_DECR_REF(inp);
7067 SCTP_TCB_UNLOCK(stcb);
7071 /* Already have or am bring up an association */
7072 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7077 vrf_id = inp->def_vrf_id;
7078 /* We are GOOD to go */
7079 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
7080 inp->sctp_ep.pre_open_stream_count,
7081 inp->sctp_ep.port, p,
7082 SCTP_INITIALIZE_AUTH_PARAMS);
7084 /* Gak! no memory */
7087 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7088 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7089 /* Set the connected flag so we can queue data */
7092 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7093 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7095 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7096 SCTP_TCB_UNLOCK(stcb);
7099 if (create_lock_on) {
7100 SCTP_ASOC_CREATE_UNLOCK(inp);
7102 SCTP_INP_DECR_REF(inp);
7108 sctp_listen(struct socket *so, int backlog, struct thread *p)
7111 * Note this module depends on the protocol processing being called
7112 * AFTER any socket level flags and backlog are applied to the
7113 * socket. The traditional way that the socket flags are applied is
7114 * AFTER protocol processing. We have made a change to the
7115 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7116 * place if the socket API for SCTP is to work properly.
7120 struct sctp_inpcb *inp;
7122 inp = (struct sctp_inpcb *)so->so_pcb;
7124 /* I made the same as TCP since we are not setup? */
7125 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7126 return (ECONNRESET);
7128 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7129 /* See if we have a listener */
7130 struct sctp_inpcb *tinp;
7131 union sctp_sockstore store;
7133 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7135 struct sctp_laddr *laddr;
7137 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7138 memcpy(&store, &laddr->ifa->address, sizeof(store));
7139 switch (store.sa.sa_family) {
7142 store.sin.sin_port = inp->sctp_lport;
7147 store.sin6.sin6_port = inp->sctp_lport;
7153 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7154 if (tinp && (tinp != inp) &&
7155 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7156 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7157 (SCTP_IS_LISTENING(tinp))) {
7159 * we have a listener already and
7162 SCTP_INP_DECR_REF(tinp);
7163 return (EADDRINUSE);
7165 SCTP_INP_DECR_REF(tinp);
7169 /* Setup a local addr bound all */
7170 memset(&store, 0, sizeof(store));
7172 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7173 store.sa.sa_family = AF_INET6;
7174 store.sa.sa_len = sizeof(struct sockaddr_in6);
7178 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7179 store.sa.sa_family = AF_INET;
7180 store.sa.sa_len = sizeof(struct sockaddr_in);
7183 switch (store.sa.sa_family) {
7186 store.sin.sin_port = inp->sctp_lport;
7191 store.sin6.sin6_port = inp->sctp_lport;
7197 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7198 if (tinp && (tinp != inp) &&
7199 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7200 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7201 (SCTP_IS_LISTENING(tinp))) {
7203 * we have a listener already and its not
7206 SCTP_INP_DECR_REF(tinp);
7207 return (EADDRINUSE);
7209 SCTP_INP_DECR_REF(tinp);
7213 SCTP_INP_RLOCK(inp);
7214 #ifdef SCTP_LOCK_LOGGING
7215 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7216 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7220 error = solisten_proto_check(so);
7223 SCTP_INP_RUNLOCK(inp);
7226 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7227 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7229 * The unlucky case - We are in the tcp pool with this guy.
7230 * - Someone else is in the main inp slot. - We must move
7231 * this guy (the listener) to the main slot - We must then
7232 * move the guy that was listener to the TCP Pool.
7234 if (sctp_swap_inpcb_for_listen(inp)) {
7235 SCTP_INP_RUNLOCK(inp);
7236 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7237 return (EADDRINUSE);
7241 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7242 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7243 /* We are already connected AND the TCP model */
7244 SCTP_INP_RUNLOCK(inp);
7245 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7246 return (EADDRINUSE);
7248 SCTP_INP_RUNLOCK(inp);
7249 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7250 /* We must do a bind. */
7251 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7252 /* bind error, probably perm */
7256 SCTP_INP_WLOCK(inp);
7257 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7259 solisten_proto(so, backlog);
7263 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7265 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7267 SCTP_INP_WUNLOCK(inp);
7271 static int sctp_defered_wakeup_cnt = 0;
7274 sctp_accept(struct socket *so, struct sockaddr **addr)
7276 struct sctp_tcb *stcb;
7277 struct sctp_inpcb *inp;
7278 union sctp_sockstore store;
7282 inp = (struct sctp_inpcb *)so->so_pcb;
7285 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7286 return (ECONNRESET);
7288 SCTP_INP_WLOCK(inp);
7289 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7290 SCTP_INP_WUNLOCK(inp);
7291 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7292 return (EOPNOTSUPP);
7294 if (so->so_state & SS_ISDISCONNECTED) {
7295 SCTP_INP_WUNLOCK(inp);
7296 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7297 return (ECONNABORTED);
7299 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7301 SCTP_INP_WUNLOCK(inp);
7302 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7303 return (ECONNRESET);
7305 SCTP_TCB_LOCK(stcb);
7306 store = stcb->asoc.primary_destination->ro._l_addr;
7307 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7308 /* Wake any delayed sleep action */
7309 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7310 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7311 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7312 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7313 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7314 if (sowriteable(inp->sctp_socket)) {
7315 sowwakeup_locked(inp->sctp_socket);
7317 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7320 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7321 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7322 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7323 if (soreadable(inp->sctp_socket)) {
7324 sctp_defered_wakeup_cnt++;
7325 sorwakeup_locked(inp->sctp_socket);
7327 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7331 SCTP_INP_WUNLOCK(inp);
7332 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7333 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7334 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7336 SCTP_TCB_UNLOCK(stcb);
7338 switch (store.sa.sa_family) {
7342 struct sockaddr_in *sin;
7344 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7347 sin->sin_family = AF_INET;
7348 sin->sin_len = sizeof(*sin);
7349 sin->sin_port = store.sin.sin_port;
7350 sin->sin_addr = store.sin.sin_addr;
7351 *addr = (struct sockaddr *)sin;
7358 struct sockaddr_in6 *sin6;
7360 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7363 sin6->sin6_family = AF_INET6;
7364 sin6->sin6_len = sizeof(*sin6);
7365 sin6->sin6_port = store.sin6.sin6_port;
7366 sin6->sin6_addr = store.sin6.sin6_addr;
7367 if ((error = sa6_recoverscope(sin6)) != 0) {
7368 SCTP_FREE_SONAME(sin6);
7371 *addr = (struct sockaddr *)sin6;
7384 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7386 struct sockaddr_in *sin;
7388 struct sctp_inpcb *inp;
7389 struct sctp_ifa *sctp_ifa;
7392 * Do the malloc first in case it blocks.
7394 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7397 sin->sin_family = AF_INET;
7398 sin->sin_len = sizeof(*sin);
7399 inp = (struct sctp_inpcb *)so->so_pcb;
7401 SCTP_FREE_SONAME(sin);
7402 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7403 return (ECONNRESET);
7405 SCTP_INP_RLOCK(inp);
7406 sin->sin_port = inp->sctp_lport;
7407 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7408 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7409 struct sctp_tcb *stcb;
7410 struct sockaddr_in *sin_a;
7411 struct sctp_nets *net;
7414 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7420 SCTP_TCB_LOCK(stcb);
7421 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7422 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7424 /* this will make coverity happy */
7427 if (sin_a->sin_family == AF_INET) {
7432 if ((!fnd) || (sin_a == NULL)) {
7434 SCTP_TCB_UNLOCK(stcb);
7438 vrf_id = inp->def_vrf_id;
7439 sctp_ifa = sctp_source_address_selection(inp,
7441 (sctp_route_t *)&net->ro,
7444 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7445 sctp_free_ifa(sctp_ifa);
7447 SCTP_TCB_UNLOCK(stcb);
7449 /* For the bound all case you get back 0 */
7451 sin->sin_addr.s_addr = 0;
7455 /* Take the first IPv4 address in the list */
7456 struct sctp_laddr *laddr;
7459 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7460 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7461 struct sockaddr_in *sin_a;
7463 sin_a = &laddr->ifa->address.sin;
7464 sin->sin_addr = sin_a->sin_addr;
7470 SCTP_FREE_SONAME(sin);
7471 SCTP_INP_RUNLOCK(inp);
7472 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7476 SCTP_INP_RUNLOCK(inp);
7477 (*addr) = (struct sockaddr *)sin;
7482 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7484 struct sockaddr_in *sin;
7486 struct sockaddr_in *sin_a;
7487 struct sctp_inpcb *inp;
7488 struct sctp_tcb *stcb;
7489 struct sctp_nets *net;
7491 /* Do the malloc first in case it blocks. */
7492 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7495 sin->sin_family = AF_INET;
7496 sin->sin_len = sizeof(*sin);
7498 inp = (struct sctp_inpcb *)so->so_pcb;
7499 if ((inp == NULL) ||
7500 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7501 /* UDP type and listeners will drop out here */
7502 SCTP_FREE_SONAME(sin);
7503 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7506 SCTP_INP_RLOCK(inp);
7507 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7509 SCTP_TCB_LOCK(stcb);
7511 SCTP_INP_RUNLOCK(inp);
7513 SCTP_FREE_SONAME(sin);
7514 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7515 return (ECONNRESET);
7518 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7519 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7520 if (sin_a->sin_family == AF_INET) {
7522 sin->sin_port = stcb->rport;
7523 sin->sin_addr = sin_a->sin_addr;
7527 SCTP_TCB_UNLOCK(stcb);
7529 /* No IPv4 address */
7530 SCTP_FREE_SONAME(sin);
7531 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7534 (*addr) = (struct sockaddr *)sin;
7538 struct pr_usrreqs sctp_usrreqs = {
7539 .pru_abort = sctp_abort,
7540 .pru_accept = sctp_accept,
7541 .pru_attach = sctp_attach,
7542 .pru_bind = sctp_bind,
7543 .pru_connect = sctp_connect,
7544 .pru_control = in_control,
7545 .pru_close = sctp_close,
7546 .pru_detach = sctp_close,
7547 .pru_sopoll = sopoll_generic,
7548 .pru_flush = sctp_flush,
7549 .pru_disconnect = sctp_disconnect,
7550 .pru_listen = sctp_listen,
7551 .pru_peeraddr = sctp_peeraddr,
7552 .pru_send = sctp_sendm,
7553 .pru_shutdown = sctp_shutdown,
7554 .pru_sockaddr = sctp_ingetaddr,
7555 .pru_sosend = sctp_sosend,
7556 .pru_soreceive = sctp_soreceive