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>
59 extern const struct sctp_cc_functions sctp_cc_functions[];
60 extern const struct sctp_ss_functions sctp_ss_functions[];
67 /* Initialize and modify the sysctled variables */
69 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
70 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
72 * Allow a user to take no more than 1/2 the number of clusters or
73 * the SB_MAX, whichever is smaller, for the send window.
75 sb_max_adj = (u_long)((u_quad_t)(SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
76 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
77 (((uint32_t)nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
79 * Now for the recv window, should we take the same amount? or
80 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
81 * now I will just copy.
83 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
84 SCTP_BASE_VAR(first_time) = 0;
85 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
87 #if defined(SCTP_PACKET_LOGGING)
88 SCTP_BASE_VAR(packet_log_writers) = 0;
89 SCTP_BASE_VAR(packet_log_end) = 0;
90 memset(&SCTP_BASE_VAR(packet_log_buffer), 0, SCTP_PACKET_LOG_SIZE);
92 SCTP_BASE_VAR(eh_tag) = EVENTHANDLER_REGISTER(rt_addrmsg,
93 sctp_addr_change_event_handler, NULL, EVENTHANDLER_PRI_FIRST);
98 sctp_finish(void *unused __unused)
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");
416 sctp_abort(struct socket *so)
418 struct epoch_tracker et;
419 struct sctp_inpcb *inp;
422 inp = (struct sctp_inpcb *)so->so_pcb;
429 flags = inp->sctp_flags;
430 #ifdef SCTP_LOG_CLOSING
431 sctp_log_closing(inp, NULL, 17);
433 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
434 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
435 #ifdef SCTP_LOG_CLOSING
436 sctp_log_closing(inp, NULL, 16);
438 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
439 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
441 SCTP_SB_CLEAR(so->so_snd);
443 * same for the rcv ones, they are only here for the
446 SCTP_SB_CLEAR(so->so_rcv);
448 /* Now null out the reference, we are completely detached. */
452 flags = inp->sctp_flags;
453 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
454 goto sctp_must_try_again;
462 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
464 struct sctp_inpcb *inp;
465 struct inpcb *ip_inp;
467 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
469 inp = (struct sctp_inpcb *)so->so_pcb;
471 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
474 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
475 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
480 error = sctp_inpcb_alloc(so, vrf_id);
484 inp = (struct sctp_inpcb *)so->so_pcb;
486 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
487 ip_inp = &inp->ip_inp.inp;
488 ip_inp->inp_vflag |= INP_IPV4;
489 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
490 SCTP_INP_WUNLOCK(inp);
495 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
497 struct sctp_inpcb *inp;
499 inp = (struct sctp_inpcb *)so->so_pcb;
501 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
505 if ((addr->sa_family != AF_INET) ||
506 (addr->sa_len != sizeof(struct sockaddr_in))) {
507 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
511 return (sctp_inpcb_bind(so, addr, NULL, p));
516 sctp_close(struct socket *so)
518 struct epoch_tracker et;
519 struct sctp_inpcb *inp;
522 inp = (struct sctp_inpcb *)so->so_pcb;
527 * Inform all the lower layer assoc that we are done.
531 flags = inp->sctp_flags;
532 #ifdef SCTP_LOG_CLOSING
533 sctp_log_closing(inp, NULL, 17);
535 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
536 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
537 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
538 (so->so_rcv.sb_cc > 0)) {
539 #ifdef SCTP_LOG_CLOSING
540 sctp_log_closing(inp, NULL, 13);
542 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
543 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
545 #ifdef SCTP_LOG_CLOSING
546 sctp_log_closing(inp, NULL, 14);
548 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
549 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
552 * The socket is now detached, no matter what the state of
553 * the SCTP association.
556 SCTP_SB_CLEAR(so->so_snd);
558 * same for the rcv ones, they are only here for the
561 SCTP_SB_CLEAR(so->so_rcv);
563 /* Now null out the reference, we are completely detached. */
567 flags = inp->sctp_flags;
568 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
569 goto sctp_must_try_again;
578 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
579 struct mbuf *control, struct thread *p);
583 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
584 struct mbuf *control, struct thread *p)
586 struct sctp_inpcb *inp;
589 inp = (struct sctp_inpcb *)so->so_pcb;
592 sctp_m_freem(control);
595 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
599 /* Got to have an to address if we are NOT a connected socket */
600 if ((addr == NULL) &&
601 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
602 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
604 } else if (addr == NULL) {
605 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
606 error = EDESTADDRREQ;
609 sctp_m_freem(control);
615 if (addr->sa_family != AF_INET) {
616 /* must be a v4 address! */
617 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
620 sctp_m_freem(control);
623 error = EDESTADDRREQ;
628 /* now what about control */
631 sctp_m_freem(inp->control);
634 inp->control = control;
638 SCTP_BUF_NEXT(inp->pkt_last) = m;
641 inp->pkt_last = inp->pkt = m;
644 /* FreeBSD uses a flag passed */
645 ((flags & PRUS_MORETOCOME) == 0)
648 * note with the current version this code will only be used
649 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
650 * re-defining sosend to use the sctp_sosend. One can
651 * optionally switch back to this code (by changing back the
652 * definitions) but this is not advisable. This code is used
653 * by FreeBSD when sending a file with sendfile() though.
655 struct epoch_tracker et;
659 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
670 sctp_disconnect(struct socket *so)
672 struct sctp_inpcb *inp;
674 inp = (struct sctp_inpcb *)so->so_pcb;
676 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
680 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
681 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
682 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
684 SCTP_INP_RUNLOCK(inp);
687 struct epoch_tracker et;
688 struct sctp_association *asoc;
689 struct sctp_tcb *stcb;
691 stcb = LIST_FIRST(&inp->sctp_asoc_list);
693 SCTP_INP_RUNLOCK(inp);
694 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
699 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
700 /* We are about to be freed, out of here */
701 SCTP_TCB_UNLOCK(stcb);
702 SCTP_INP_RUNLOCK(inp);
706 if (((so->so_options & SO_LINGER) &&
707 (so->so_linger == 0)) ||
708 (so->so_rcv.sb_cc > 0)) {
709 if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) {
710 /* Left with Data unread */
713 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
714 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
715 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
717 SCTP_INP_RUNLOCK(inp);
718 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
719 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
720 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
722 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
723 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
724 /* No unlock tcb assoc is gone */
728 if (TAILQ_EMPTY(&asoc->send_queue) &&
729 TAILQ_EMPTY(&asoc->sent_queue) &&
730 (asoc->stream_queue_cnt == 0)) {
731 /* there is nothing queued to send, so done */
732 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
735 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) &&
736 (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
737 /* only send SHUTDOWN 1st time thru */
738 struct sctp_nets *netp;
740 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
741 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
742 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
744 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
745 sctp_stop_timers_for_shutdown(stcb);
746 if (stcb->asoc.alternate) {
747 netp = stcb->asoc.alternate;
749 netp = stcb->asoc.primary_destination;
751 sctp_send_shutdown(stcb, netp);
752 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
753 stcb->sctp_ep, stcb, netp);
754 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
755 stcb->sctp_ep, stcb, NULL);
756 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
760 * we still got (or just got) data to send,
761 * so set SHUTDOWN_PENDING
764 * XXX sockets draft says that SCTP_EOF
765 * should be sent with no data. currently,
766 * we will allow user data to be sent first
767 * and move to SHUTDOWN-PENDING
769 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
770 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
771 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
772 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
774 if (TAILQ_EMPTY(&asoc->send_queue) &&
775 TAILQ_EMPTY(&asoc->sent_queue) &&
776 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
780 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
781 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
782 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
783 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
784 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
785 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
786 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
788 SCTP_INP_RUNLOCK(inp);
789 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
790 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
794 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
797 soisdisconnecting(so);
799 SCTP_TCB_UNLOCK(stcb);
800 SCTP_INP_RUNLOCK(inp);
805 /* UDP model does not support this */
806 SCTP_INP_RUNLOCK(inp);
807 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
813 sctp_flush(struct socket *so, int how)
816 * We will just clear out the values and let subsequent close clear
817 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
818 * they will not be able to read the data, the socket will block
819 * that from happening.
821 struct sctp_inpcb *inp;
823 inp = (struct sctp_inpcb *)so->so_pcb;
825 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
829 /* For the 1 to many model this does nothing */
830 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
831 SCTP_INP_RUNLOCK(inp);
834 SCTP_INP_RUNLOCK(inp);
835 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
837 * First make sure the sb will be happy, we don't use these
838 * except maybe the count
841 SCTP_INP_READ_LOCK(inp);
842 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
843 SCTP_INP_READ_UNLOCK(inp);
844 SCTP_INP_WUNLOCK(inp);
845 so->so_rcv.sb_cc = 0;
846 so->so_rcv.sb_mbcnt = 0;
847 so->so_rcv.sb_mb = NULL;
849 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
851 * First make sure the sb will be happy, we don't use these
852 * except maybe the count
854 so->so_snd.sb_cc = 0;
855 so->so_snd.sb_mbcnt = 0;
856 so->so_snd.sb_mb = NULL;
863 sctp_shutdown(struct socket *so)
865 struct sctp_inpcb *inp;
867 inp = (struct sctp_inpcb *)so->so_pcb;
869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
873 /* For UDP model this is a invalid call */
874 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
875 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
876 /* Restore the flags that the soshutdown took away. */
877 SOCKBUF_LOCK(&so->so_rcv);
878 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
879 SOCKBUF_UNLOCK(&so->so_rcv);
880 /* This proc will wakeup for read and do nothing (I hope) */
881 SCTP_INP_RUNLOCK(inp);
882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
886 * Ok, if we reach here its the TCP model and it is either a
887 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
890 struct epoch_tracker et;
891 struct sctp_tcb *stcb;
892 struct sctp_association *asoc;
893 struct sctp_nets *netp;
896 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
897 SCTP_INP_RUNLOCK(inp);
902 stcb = LIST_FIRST(&inp->sctp_asoc_list);
905 * Ok, we hit the case that the shutdown call was
906 * made after an abort or something. Nothing to do
909 SCTP_INP_RUNLOCK(inp);
914 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
915 SCTP_TCB_UNLOCK(stcb);
916 SCTP_INP_RUNLOCK(inp);
919 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) &&
920 (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) &&
921 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) {
923 * If we are not in or before ESTABLISHED, there is
924 * no protocol action required.
926 SCTP_TCB_UNLOCK(stcb);
927 SCTP_INP_RUNLOCK(inp);
931 if (stcb->asoc.alternate) {
932 netp = stcb->asoc.alternate;
934 netp = stcb->asoc.primary_destination;
936 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) &&
937 TAILQ_EMPTY(&asoc->send_queue) &&
938 TAILQ_EMPTY(&asoc->sent_queue) &&
939 (asoc->stream_queue_cnt == 0)) {
940 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
943 /* there is nothing queued to send, so I'm done... */
944 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
945 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
946 sctp_stop_timers_for_shutdown(stcb);
947 sctp_send_shutdown(stcb, netp);
948 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
949 stcb->sctp_ep, stcb, netp);
952 * We still got (or just got) data to send, so set
955 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
956 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
957 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
959 if (TAILQ_EMPTY(&asoc->send_queue) &&
960 TAILQ_EMPTY(&asoc->sent_queue) &&
961 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
965 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
966 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
967 SCTP_INP_RUNLOCK(inp);
968 sctp_abort_an_association(stcb->sctp_ep, stcb,
969 op_err, SCTP_SO_LOCKED);
974 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
976 * XXX: Why do this in the case where we have still data
979 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
980 SCTP_TCB_UNLOCK(stcb);
981 SCTP_INP_RUNLOCK(inp);
988 * copies a "user" presentable address and removes embedded scope, etc.
989 * returns 0 on success, 1 on error
992 sctp_fill_user_address(struct sockaddr *dst, struct sockaddr *src)
995 struct sockaddr_in6 lsa6;
997 src = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)src,
1000 memcpy(dst, src, src->sa_len);
1007 * NOTE: assumes addr lock is held
1010 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1011 struct sctp_tcb *stcb,
1013 struct sockaddr *addr,
1016 struct sctp_ifn *sctp_ifn;
1017 struct sctp_ifa *sctp_ifa;
1021 int ipv4_local_scope, ipv4_addr_legal;
1024 int local_scope, site_scope, ipv6_addr_legal;
1026 struct sctp_vrf *vrf;
1033 /* Turn on all the appropriate scope */
1034 loopback_scope = stcb->asoc.scope.loopback_scope;
1036 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1037 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1040 local_scope = stcb->asoc.scope.local_scope;
1041 site_scope = stcb->asoc.scope.site_scope;
1042 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1045 /* Use generic values for endpoints. */
1048 ipv4_local_scope = 1;
1054 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1056 ipv6_addr_legal = 1;
1059 if (SCTP_IPV6_V6ONLY(inp)) {
1060 ipv4_addr_legal = 0;
1062 ipv4_addr_legal = 1;
1067 ipv6_addr_legal = 0;
1070 ipv4_addr_legal = 1;
1074 vrf = sctp_find_vrf(vrf_id);
1078 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1079 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1080 if ((loopback_scope == 0) &&
1081 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1082 /* Skip loopback if loopback_scope not set */
1085 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1088 * For the BOUND-ALL case, the list
1089 * associated with a TCB is Always
1090 * considered a reverse list.. i.e.
1091 * it lists addresses that are NOT
1092 * part of the association. If this
1093 * is one of those we must skip it.
1095 if (sctp_is_addr_restricted(stcb,
1100 switch (sctp_ifa->address.sa.sa_family) {
1103 if (ipv4_addr_legal) {
1104 struct sockaddr_in *sin;
1106 sin = &sctp_ifa->address.sin;
1107 if (sin->sin_addr.s_addr == 0) {
1115 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1116 &sin->sin_addr) != 0) {
1119 if ((ipv4_local_scope == 0) &&
1120 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1124 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1125 if (actual + sizeof(struct sockaddr_in6) > limit) {
1128 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)&addr);
1129 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1130 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1131 actual += sizeof(struct sockaddr_in6);
1134 if (actual + sizeof(struct sockaddr_in) > limit) {
1137 memcpy(addr, sin, sizeof(struct sockaddr_in));
1138 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1139 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in));
1140 actual += sizeof(struct sockaddr_in);
1151 if (ipv6_addr_legal) {
1152 struct sockaddr_in6 *sin6;
1154 sin6 = &sctp_ifa->address.sin6;
1155 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1163 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1164 &sin6->sin6_addr) != 0) {
1167 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1168 if (local_scope == 0)
1170 if (sin6->sin6_scope_id == 0) {
1171 if (sa6_recoverscope(sin6) != 0)
1184 if ((site_scope == 0) &&
1185 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1188 if (actual + sizeof(struct sockaddr_in6) > limit) {
1191 memcpy(addr, sin6, sizeof(struct sockaddr_in6));
1192 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1193 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1194 actual += sizeof(struct sockaddr_in6);
1207 struct sctp_laddr *laddr;
1210 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1212 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1216 sa_len = laddr->ifa->address.sa.sa_len;
1217 if (actual + sa_len > limit) {
1220 if (sctp_fill_user_address(addr, &laddr->ifa->address.sa))
1222 switch (laddr->ifa->address.sa.sa_family) {
1225 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1230 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1237 addr = (struct sockaddr *)((caddr_t)addr + sa_len);
1245 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1246 struct sctp_tcb *stcb,
1248 struct sockaddr *addr)
1252 SCTP_IPI_ADDR_RLOCK();
1253 /* fill up addresses for the endpoint's default vrf */
1254 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, addr,
1256 SCTP_IPI_ADDR_RUNLOCK();
1261 * NOTE: assumes addr lock is held
1264 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1267 struct sctp_vrf *vrf = NULL;
1270 * In both sub-set bound an bound_all cases we return the MAXIMUM
1271 * number of addresses that you COULD get. In reality the sub-set
1272 * bound may have an exclusion list for a given TCB OR in the
1273 * bound-all case a TCB may NOT include the loopback or other
1274 * addresses as well.
1276 vrf = sctp_find_vrf(vrf_id);
1280 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1281 struct sctp_ifn *sctp_ifn;
1282 struct sctp_ifa *sctp_ifa;
1284 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1285 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1286 /* Count them if they are the right type */
1287 switch (sctp_ifa->address.sa.sa_family) {
1291 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1292 cnt += sizeof(struct sockaddr_in6);
1294 cnt += sizeof(struct sockaddr_in);
1296 cnt += sizeof(struct sockaddr_in);
1302 cnt += sizeof(struct sockaddr_in6);
1311 struct sctp_laddr *laddr;
1313 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1314 switch (laddr->ifa->address.sa.sa_family) {
1318 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1319 cnt += sizeof(struct sockaddr_in6);
1321 cnt += sizeof(struct sockaddr_in);
1323 cnt += sizeof(struct sockaddr_in);
1329 cnt += sizeof(struct sockaddr_in6);
1341 sctp_count_max_addresses(struct sctp_inpcb *inp)
1345 SCTP_IPI_ADDR_RLOCK();
1346 /* count addresses for the endpoint's default VRF */
1347 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1348 SCTP_IPI_ADDR_RUNLOCK();
1353 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1354 size_t optsize, void *p, int delay)
1357 int creat_lock_on = 0;
1358 struct sctp_tcb *stcb = NULL;
1359 struct sockaddr *sa;
1360 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1364 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1366 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1367 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1368 /* We are already connected AND the TCP model */
1369 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1370 return (EADDRINUSE);
1373 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1374 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1375 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1379 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1380 SCTP_INP_RLOCK(inp);
1381 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1382 SCTP_INP_RUNLOCK(inp);
1385 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1388 SCTP_INP_INCR_REF(inp);
1389 SCTP_ASOC_CREATE_LOCK(inp);
1391 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1392 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1393 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1397 totaddrp = (unsigned int *)optval;
1398 totaddr = *totaddrp;
1399 sa = (struct sockaddr *)(totaddrp + 1);
1400 error = sctp_connectx_helper_find(inp, sa, totaddr, &num_v4, &num_v6, (unsigned int)(optsize - sizeof(int)));
1402 /* Already have or am bring up an association */
1403 SCTP_ASOC_CREATE_UNLOCK(inp);
1405 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1409 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1414 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1416 if (SCTP_IPV6_V6ONLY(inp)) {
1418 * if IPV6_V6ONLY flag, ignore connections destined
1419 * to a v4 addr or v4-mapped addr
1421 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1427 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1428 SCTP_PCB_FLAGS_UNBOUND) {
1429 /* Bind a ephemeral port */
1430 error = sctp_inpcb_bind(so, NULL, NULL, p);
1436 /* FIX ME: do we want to pass in a vrf on the connect call? */
1437 vrf_id = inp->def_vrf_id;
1440 /* We are GOOD to go */
1441 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1442 inp->sctp_ep.pre_open_stream_count,
1445 SCTP_INITIALIZE_AUTH_PARAMS);
1447 /* Gak! no memory */
1450 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1451 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1452 /* Set the connected flag so we can queue data */
1455 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1456 /* move to second address */
1457 switch (sa->sa_family) {
1460 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1465 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1473 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1474 /* Fill in the return id */
1478 a_id = (sctp_assoc_t *)optval;
1479 *a_id = sctp_get_associd(stcb);
1482 /* doing delayed connection */
1483 stcb->asoc.delayed_connection = 1;
1484 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1486 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1487 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1489 SCTP_TCB_UNLOCK(stcb);
1491 if (creat_lock_on) {
1492 SCTP_ASOC_CREATE_UNLOCK(inp);
1494 SCTP_INP_DECR_REF(inp);
1498 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1499 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1500 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1501 SCTP_INP_RLOCK(inp); \
1502 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1504 SCTP_TCB_LOCK(stcb); \
1506 SCTP_INP_RUNLOCK(inp); \
1507 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1508 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1509 if (stcb == NULL) { \
1510 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1520 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1521 if (size < sizeof(type)) { \
1522 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1526 destp = (type *)srcp; \
1531 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1534 struct sctp_inpcb *inp = NULL;
1536 struct sctp_tcb *stcb = NULL;
1538 if (optval == NULL) {
1539 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1543 inp = (struct sctp_inpcb *)so->so_pcb;
1545 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1552 case SCTP_AUTOCLOSE:
1553 case SCTP_EXPLICIT_EOR:
1554 case SCTP_AUTO_ASCONF:
1555 case SCTP_DISABLE_FRAGMENTS:
1556 case SCTP_I_WANT_MAPPED_V4_ADDR:
1557 case SCTP_USE_EXT_RCVINFO:
1558 SCTP_INP_RLOCK(inp);
1560 case SCTP_DISABLE_FRAGMENTS:
1561 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1563 case SCTP_I_WANT_MAPPED_V4_ADDR:
1564 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1566 case SCTP_AUTO_ASCONF:
1567 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1568 /* only valid for bound all sockets */
1569 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1571 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1576 case SCTP_EXPLICIT_EOR:
1577 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1580 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1582 case SCTP_USE_EXT_RCVINFO:
1583 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1585 case SCTP_AUTOCLOSE:
1586 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1587 val = sctp_ticks_to_secs(inp->sctp_ep.auto_close_time);
1593 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1594 error = ENOPROTOOPT;
1595 } /* end switch (sopt->sopt_name) */
1596 if (*optsize < sizeof(val)) {
1597 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1601 SCTP_INP_RUNLOCK(inp);
1603 /* return the option value */
1604 *(int *)optval = val;
1605 *optsize = sizeof(val);
1608 case SCTP_GET_PACKET_LOG:
1610 #ifdef SCTP_PACKET_LOGGING
1614 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1615 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1618 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1623 case SCTP_REUSE_PORT:
1627 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1628 /* Can't do this for a 1-m socket */
1632 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1633 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1634 *optsize = sizeof(uint32_t);
1637 case SCTP_PARTIAL_DELIVERY_POINT:
1641 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1642 *value = inp->partial_delivery_point;
1643 *optsize = sizeof(uint32_t);
1646 case SCTP_FRAGMENT_INTERLEAVE:
1650 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1651 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1652 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1653 *value = SCTP_FRAG_LEVEL_2;
1655 *value = SCTP_FRAG_LEVEL_1;
1658 *value = SCTP_FRAG_LEVEL_0;
1660 *optsize = sizeof(uint32_t);
1663 case SCTP_INTERLEAVING_SUPPORTED:
1665 struct sctp_assoc_value *av;
1667 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1668 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1671 av->assoc_value = stcb->asoc.idata_supported;
1672 SCTP_TCB_UNLOCK(stcb);
1674 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1675 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1676 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1677 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1678 SCTP_INP_RLOCK(inp);
1679 if (inp->idata_supported) {
1680 av->assoc_value = 1;
1682 av->assoc_value = 0;
1684 SCTP_INP_RUNLOCK(inp);
1686 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1691 *optsize = sizeof(struct sctp_assoc_value);
1695 case SCTP_CMT_ON_OFF:
1697 struct sctp_assoc_value *av;
1699 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1700 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1702 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1703 SCTP_TCB_UNLOCK(stcb);
1705 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1706 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1707 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1708 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1709 SCTP_INP_RLOCK(inp);
1710 av->assoc_value = inp->sctp_cmt_on_off;
1711 SCTP_INP_RUNLOCK(inp);
1713 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1718 *optsize = sizeof(struct sctp_assoc_value);
1722 case SCTP_PLUGGABLE_CC:
1724 struct sctp_assoc_value *av;
1726 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1727 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1729 av->assoc_value = stcb->asoc.congestion_control_module;
1730 SCTP_TCB_UNLOCK(stcb);
1732 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1733 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1734 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1735 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1736 SCTP_INP_RLOCK(inp);
1737 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1738 SCTP_INP_RUNLOCK(inp);
1740 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1745 *optsize = sizeof(struct sctp_assoc_value);
1749 case SCTP_CC_OPTION:
1751 struct sctp_cc_option *cc_opt;
1753 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1754 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1758 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1761 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1762 *optsize = sizeof(struct sctp_cc_option);
1764 SCTP_TCB_UNLOCK(stcb);
1768 case SCTP_PLUGGABLE_SS:
1770 struct sctp_assoc_value *av;
1772 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1773 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1775 av->assoc_value = stcb->asoc.stream_scheduling_module;
1776 SCTP_TCB_UNLOCK(stcb);
1778 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1779 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1780 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1781 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1782 SCTP_INP_RLOCK(inp);
1783 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1784 SCTP_INP_RUNLOCK(inp);
1786 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1791 *optsize = sizeof(struct sctp_assoc_value);
1797 struct sctp_stream_value *av;
1799 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1800 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1802 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1803 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1804 &av->stream_value) < 0)) {
1805 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1808 *optsize = sizeof(struct sctp_stream_value);
1810 SCTP_TCB_UNLOCK(stcb);
1813 * Can't get stream value without
1816 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1821 case SCTP_GET_ADDR_LEN:
1823 struct sctp_assoc_value *av;
1825 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1828 if (av->assoc_value == AF_INET) {
1829 av->assoc_value = sizeof(struct sockaddr_in);
1834 if (av->assoc_value == AF_INET6) {
1835 av->assoc_value = sizeof(struct sockaddr_in6);
1840 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1842 *optsize = sizeof(struct sctp_assoc_value);
1846 case SCTP_GET_ASSOC_NUMBER:
1848 uint32_t *value, cnt;
1850 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1851 SCTP_INP_RLOCK(inp);
1852 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1853 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1854 /* Can't do this for a 1-1 socket */
1856 SCTP_INP_RUNLOCK(inp);
1860 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1863 SCTP_INP_RUNLOCK(inp);
1865 *optsize = sizeof(uint32_t);
1868 case SCTP_GET_ASSOC_ID_LIST:
1870 struct sctp_assoc_ids *ids;
1874 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1875 SCTP_INP_RLOCK(inp);
1876 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1877 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1878 /* Can't do this for a 1-1 socket */
1880 SCTP_INP_RUNLOCK(inp);
1884 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1885 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1887 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1890 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1895 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1899 SCTP_INP_RUNLOCK(inp);
1901 ids->gaids_number_of_ids = at;
1902 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1908 struct sctp_assoc_value *av;
1910 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1911 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1914 av->assoc_value = stcb->asoc.context;
1915 SCTP_TCB_UNLOCK(stcb);
1917 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1918 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1919 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1920 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1921 SCTP_INP_RLOCK(inp);
1922 av->assoc_value = inp->sctp_context;
1923 SCTP_INP_RUNLOCK(inp);
1925 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1930 *optsize = sizeof(struct sctp_assoc_value);
1936 uint32_t *default_vrfid;
1938 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1939 *default_vrfid = inp->def_vrf_id;
1940 *optsize = sizeof(uint32_t);
1943 case SCTP_GET_ASOC_VRF:
1945 struct sctp_assoc_value *id;
1947 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1948 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1953 id->assoc_value = stcb->asoc.vrf_id;
1954 SCTP_TCB_UNLOCK(stcb);
1955 *optsize = sizeof(struct sctp_assoc_value);
1959 case SCTP_GET_VRF_IDS:
1961 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1965 case SCTP_GET_NONCE_VALUES:
1967 struct sctp_get_nonce_values *gnv;
1969 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1970 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1973 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1974 gnv->gn_local_tag = stcb->asoc.my_vtag;
1975 SCTP_TCB_UNLOCK(stcb);
1976 *optsize = sizeof(struct sctp_get_nonce_values);
1978 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1983 case SCTP_DELAYED_SACK:
1985 struct sctp_sack_info *sack;
1987 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1988 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1990 sack->sack_delay = stcb->asoc.delayed_ack;
1991 sack->sack_freq = stcb->asoc.sack_freq;
1992 SCTP_TCB_UNLOCK(stcb);
1994 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1995 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1996 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1997 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC))) {
1998 SCTP_INP_RLOCK(inp);
1999 sack->sack_delay = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2000 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2001 SCTP_INP_RUNLOCK(inp);
2003 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2008 *optsize = sizeof(struct sctp_sack_info);
2012 case SCTP_GET_SNDBUF_USE:
2014 struct sctp_sockstat *ss;
2016 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2017 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2020 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2021 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2022 stcb->asoc.size_on_all_streams);
2023 SCTP_TCB_UNLOCK(stcb);
2024 *optsize = sizeof(struct sctp_sockstat);
2026 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2031 case SCTP_MAX_BURST:
2033 struct sctp_assoc_value *av;
2035 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2036 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2039 av->assoc_value = stcb->asoc.max_burst;
2040 SCTP_TCB_UNLOCK(stcb);
2042 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2043 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2044 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2045 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2046 SCTP_INP_RLOCK(inp);
2047 av->assoc_value = inp->sctp_ep.max_burst;
2048 SCTP_INP_RUNLOCK(inp);
2050 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2055 *optsize = sizeof(struct sctp_assoc_value);
2061 struct sctp_assoc_value *av;
2064 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2065 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2068 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2069 SCTP_TCB_UNLOCK(stcb);
2071 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2072 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2073 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2074 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2075 SCTP_INP_RLOCK(inp);
2076 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2077 ovh = SCTP_MED_OVERHEAD;
2079 ovh = SCTP_MED_V4_OVERHEAD;
2081 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2082 av->assoc_value = 0;
2084 av->assoc_value = inp->sctp_frag_point - ovh;
2085 SCTP_INP_RUNLOCK(inp);
2087 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2092 *optsize = sizeof(struct sctp_assoc_value);
2096 case SCTP_GET_STAT_LOG:
2097 error = sctp_fill_stat_log(optval, optsize);
2101 struct sctp_event_subscribe *events;
2103 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2104 memset(events, 0, sizeof(struct sctp_event_subscribe));
2105 SCTP_INP_RLOCK(inp);
2106 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2107 events->sctp_data_io_event = 1;
2109 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2110 events->sctp_association_event = 1;
2112 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2113 events->sctp_address_event = 1;
2115 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2116 events->sctp_send_failure_event = 1;
2118 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2119 events->sctp_peer_error_event = 1;
2121 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2122 events->sctp_shutdown_event = 1;
2124 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2125 events->sctp_partial_delivery_event = 1;
2127 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2128 events->sctp_adaptation_layer_event = 1;
2130 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2131 events->sctp_authentication_event = 1;
2133 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2134 events->sctp_sender_dry_event = 1;
2136 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2137 events->sctp_stream_reset_event = 1;
2138 SCTP_INP_RUNLOCK(inp);
2139 *optsize = sizeof(struct sctp_event_subscribe);
2142 case SCTP_ADAPTATION_LAYER:
2146 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2148 SCTP_INP_RLOCK(inp);
2149 *value = inp->sctp_ep.adaptation_layer_indicator;
2150 SCTP_INP_RUNLOCK(inp);
2151 *optsize = sizeof(uint32_t);
2154 case SCTP_SET_INITIAL_DBG_SEQ:
2158 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2159 SCTP_INP_RLOCK(inp);
2160 *value = inp->sctp_ep.initial_sequence_debug;
2161 SCTP_INP_RUNLOCK(inp);
2162 *optsize = sizeof(uint32_t);
2165 case SCTP_GET_LOCAL_ADDR_SIZE:
2169 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2170 SCTP_INP_RLOCK(inp);
2171 *value = sctp_count_max_addresses(inp);
2172 SCTP_INP_RUNLOCK(inp);
2173 *optsize = sizeof(uint32_t);
2176 case SCTP_GET_REMOTE_ADDR_SIZE:
2180 struct sctp_nets *net;
2182 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2183 /* FIXME MT: change to sctp_assoc_value? */
2184 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2188 /* Count the sizes */
2189 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2190 switch (net->ro._l_addr.sa.sa_family) {
2194 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2195 size += sizeof(struct sockaddr_in6);
2197 size += sizeof(struct sockaddr_in);
2200 size += sizeof(struct sockaddr_in);
2206 size += sizeof(struct sockaddr_in6);
2213 SCTP_TCB_UNLOCK(stcb);
2214 *value = (uint32_t)size;
2215 *optsize = sizeof(uint32_t);
2217 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2222 case SCTP_GET_PEER_ADDRESSES:
2224 * Get the address information, an array is passed in to
2225 * fill up we pack it.
2229 struct sockaddr *addr;
2230 struct sctp_nets *net;
2231 struct sctp_getaddresses *saddr;
2233 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2234 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2237 left = *optsize - offsetof(struct sctp_getaddresses, addr);
2238 *optsize = offsetof(struct sctp_getaddresses, addr);
2239 addr = &saddr->addr[0].sa;
2241 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2242 switch (net->ro._l_addr.sa.sa_family) {
2246 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2247 cpsz = sizeof(struct sockaddr_in6);
2249 cpsz = sizeof(struct sockaddr_in);
2252 cpsz = sizeof(struct sockaddr_in);
2258 cpsz = sizeof(struct sockaddr_in6);
2269 /* not enough room. */
2272 #if defined(INET) && defined(INET6)
2273 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2274 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2275 /* Must map the address */
2276 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2277 (struct sockaddr_in6 *)&addr);
2279 memcpy(addr, &net->ro._l_addr, cpsz);
2282 memcpy(addr, &net->ro._l_addr, cpsz);
2284 ((struct sockaddr_in *)addr)->sin_port = stcb->rport;
2286 addr = (struct sockaddr *)((caddr_t)addr + cpsz);
2290 SCTP_TCB_UNLOCK(stcb);
2292 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2297 case SCTP_GET_LOCAL_ADDRESSES:
2299 size_t limit, actual;
2300 struct sctp_getaddresses *saddr;
2302 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2303 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2305 limit = *optsize - offsetof(struct sctp_getaddresses, addr);
2306 actual = sctp_fill_up_addresses(inp, stcb, limit, &saddr->addr[0].sa);
2308 SCTP_TCB_UNLOCK(stcb);
2310 *optsize = offsetof(struct sctp_getaddresses, addr) + actual;
2313 case SCTP_PEER_ADDR_PARAMS:
2315 struct sctp_paddrparams *paddrp;
2316 struct sctp_nets *net;
2317 struct sockaddr *addr;
2318 #if defined(INET) && defined(INET6)
2319 struct sockaddr_in sin_store;
2322 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2323 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2325 #if defined(INET) && defined(INET6)
2326 if (paddrp->spp_address.ss_family == AF_INET6) {
2327 struct sockaddr_in6 *sin6;
2329 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2330 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2331 in6_sin6_2_sin(&sin_store, sin6);
2332 addr = (struct sockaddr *)&sin_store;
2334 addr = (struct sockaddr *)&paddrp->spp_address;
2337 addr = (struct sockaddr *)&paddrp->spp_address;
2340 addr = (struct sockaddr *)&paddrp->spp_address;
2343 net = sctp_findnet(stcb, addr);
2346 * We increment here since
2347 * sctp_findassociation_ep_addr() wil do a
2348 * decrement if it finds the stcb as long as
2349 * the locked tcb (last argument) is NOT a
2353 SCTP_INP_INCR_REF(inp);
2354 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2356 SCTP_INP_DECR_REF(inp);
2359 if ((stcb != NULL) && (net == NULL)) {
2361 if (addr->sa_family == AF_INET) {
2362 struct sockaddr_in *sin;
2364 sin = (struct sockaddr_in *)addr;
2365 if (sin->sin_addr.s_addr != INADDR_ANY) {
2367 SCTP_TCB_UNLOCK(stcb);
2368 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2374 if (addr->sa_family == AF_INET6) {
2375 struct sockaddr_in6 *sin6;
2377 sin6 = (struct sockaddr_in6 *)addr;
2378 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2380 SCTP_TCB_UNLOCK(stcb);
2381 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2387 error = EAFNOSUPPORT;
2388 SCTP_TCB_UNLOCK(stcb);
2389 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2395 /* Applies to the specific association */
2396 paddrp->spp_flags = 0;
2398 paddrp->spp_hbinterval = net->heart_beat_delay;
2399 paddrp->spp_pathmaxrxt = net->failure_threshold;
2400 paddrp->spp_pathmtu = net->mtu;
2401 switch (net->ro._l_addr.sa.sa_family) {
2404 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2409 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2415 /* get flags for HB */
2416 if (net->dest_state & SCTP_ADDR_NOHB) {
2417 paddrp->spp_flags |= SPP_HB_DISABLE;
2419 paddrp->spp_flags |= SPP_HB_ENABLE;
2421 /* get flags for PMTU */
2422 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2423 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2425 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2427 if (net->dscp & 0x01) {
2428 paddrp->spp_dscp = net->dscp & 0xfc;
2429 paddrp->spp_flags |= SPP_DSCP;
2432 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2433 (net->flowlabel & 0x80000000)) {
2434 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2435 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2440 * No destination so return default
2443 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2444 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2445 if (stcb->asoc.default_dscp & 0x01) {
2446 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2447 paddrp->spp_flags |= SPP_DSCP;
2450 if (stcb->asoc.default_flowlabel & 0x80000000) {
2451 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2452 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2455 /* default settings should be these */
2456 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2457 paddrp->spp_flags |= SPP_HB_DISABLE;
2459 paddrp->spp_flags |= SPP_HB_ENABLE;
2461 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2462 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2464 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2466 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2468 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2469 SCTP_TCB_UNLOCK(stcb);
2471 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2472 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2473 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2474 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
2475 /* Use endpoint defaults */
2476 SCTP_INP_RLOCK(inp);
2477 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2478 paddrp->spp_hbinterval = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2479 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2480 /* get inp's default */
2481 if (inp->sctp_ep.default_dscp & 0x01) {
2482 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2483 paddrp->spp_flags |= SPP_DSCP;
2486 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2487 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2488 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2489 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2492 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2494 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2495 paddrp->spp_flags |= SPP_HB_ENABLE;
2497 paddrp->spp_flags |= SPP_HB_DISABLE;
2499 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2500 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2502 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2504 SCTP_INP_RUNLOCK(inp);
2506 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2511 *optsize = sizeof(struct sctp_paddrparams);
2515 case SCTP_GET_PEER_ADDR_INFO:
2517 struct sctp_paddrinfo *paddri;
2518 struct sctp_nets *net;
2519 struct sockaddr *addr;
2520 #if defined(INET) && defined(INET6)
2521 struct sockaddr_in sin_store;
2524 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2525 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2527 #if defined(INET) && defined(INET6)
2528 if (paddri->spinfo_address.ss_family == AF_INET6) {
2529 struct sockaddr_in6 *sin6;
2531 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2532 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2533 in6_sin6_2_sin(&sin_store, sin6);
2534 addr = (struct sockaddr *)&sin_store;
2536 addr = (struct sockaddr *)&paddri->spinfo_address;
2539 addr = (struct sockaddr *)&paddri->spinfo_address;
2542 addr = (struct sockaddr *)&paddri->spinfo_address;
2545 net = sctp_findnet(stcb, addr);
2548 * We increment here since
2549 * sctp_findassociation_ep_addr() wil do a
2550 * decrement if it finds the stcb as long as
2551 * the locked tcb (last argument) is NOT a
2555 SCTP_INP_INCR_REF(inp);
2556 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2558 SCTP_INP_DECR_REF(inp);
2562 if ((stcb != NULL) && (net != NULL)) {
2563 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2564 /* It's unconfirmed */
2565 paddri->spinfo_state = SCTP_UNCONFIRMED;
2566 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2568 paddri->spinfo_state = SCTP_ACTIVE;
2571 paddri->spinfo_state = SCTP_INACTIVE;
2573 paddri->spinfo_cwnd = net->cwnd;
2574 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2575 paddri->spinfo_rto = net->RTO;
2576 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2577 paddri->spinfo_mtu = net->mtu;
2578 switch (addr->sa_family) {
2581 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2586 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2592 SCTP_TCB_UNLOCK(stcb);
2593 *optsize = sizeof(struct sctp_paddrinfo);
2596 SCTP_TCB_UNLOCK(stcb);
2598 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2603 case SCTP_PCB_STATUS:
2605 struct sctp_pcbinfo *spcb;
2607 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2608 sctp_fill_pcbinfo(spcb);
2609 *optsize = sizeof(struct sctp_pcbinfo);
2614 struct sctp_nets *net;
2615 struct sctp_status *sstat;
2617 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2618 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2625 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2626 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2627 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2628 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2630 * We can't include chunks that have been passed to
2631 * the socket layer. Only things in queue.
2633 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2634 stcb->asoc.cnt_on_all_streams);
2637 sstat->sstat_instrms = stcb->asoc.streamincnt;
2638 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2639 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2640 net = stcb->asoc.primary_destination;
2642 memcpy(&sstat->sstat_primary.spinfo_address,
2644 ((struct sockaddr *)(&net->ro._l_addr))->sa_len);
2645 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2647 * Again the user can get info from
2648 * sctp_constants.h for what the state of
2651 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2652 /* It's unconfirmed */
2653 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2654 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2656 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2659 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2661 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2662 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2663 sstat->sstat_primary.spinfo_rto = net->RTO;
2664 sstat->sstat_primary.spinfo_mtu = net->mtu;
2665 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2668 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2673 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2680 memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo));
2682 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2683 SCTP_TCB_UNLOCK(stcb);
2684 *optsize = sizeof(struct sctp_status);
2689 struct sctp_rtoinfo *srto;
2691 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2692 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2695 srto->srto_initial = stcb->asoc.initial_rto;
2696 srto->srto_max = stcb->asoc.maxrto;
2697 srto->srto_min = stcb->asoc.minrto;
2698 SCTP_TCB_UNLOCK(stcb);
2700 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2701 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2702 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2703 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
2704 SCTP_INP_RLOCK(inp);
2705 srto->srto_initial = inp->sctp_ep.initial_rto;
2706 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2707 srto->srto_min = inp->sctp_ep.sctp_minrto;
2708 SCTP_INP_RUNLOCK(inp);
2710 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2715 *optsize = sizeof(struct sctp_rtoinfo);
2721 struct sctp_timeouts *stimo;
2723 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2724 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2727 stimo->stimo_init = stcb->asoc.timoinit;
2728 stimo->stimo_data = stcb->asoc.timodata;
2729 stimo->stimo_sack = stcb->asoc.timosack;
2730 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2731 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2732 stimo->stimo_cookie = stcb->asoc.timocookie;
2733 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2734 SCTP_TCB_UNLOCK(stcb);
2735 *optsize = sizeof(struct sctp_timeouts);
2737 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2742 case SCTP_ASSOCINFO:
2744 struct sctp_assocparams *sasoc;
2746 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2747 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2750 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(stcb->asoc.cookie_life);
2751 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2752 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2753 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2754 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2755 SCTP_TCB_UNLOCK(stcb);
2757 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2758 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2759 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2760 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
2761 SCTP_INP_RLOCK(inp);
2762 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(inp->sctp_ep.def_cookie_life);
2763 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2764 sasoc->sasoc_number_peer_destinations = 0;
2765 sasoc->sasoc_peer_rwnd = 0;
2766 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2767 SCTP_INP_RUNLOCK(inp);
2769 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2774 *optsize = sizeof(struct sctp_assocparams);
2778 case SCTP_DEFAULT_SEND_PARAM:
2780 struct sctp_sndrcvinfo *s_info;
2782 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2783 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2786 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2787 SCTP_TCB_UNLOCK(stcb);
2789 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2790 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2791 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2792 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC))) {
2793 SCTP_INP_RLOCK(inp);
2794 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2795 SCTP_INP_RUNLOCK(inp);
2797 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2802 *optsize = sizeof(struct sctp_sndrcvinfo);
2808 struct sctp_initmsg *sinit;
2810 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2811 SCTP_INP_RLOCK(inp);
2812 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2813 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2814 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2815 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2816 SCTP_INP_RUNLOCK(inp);
2817 *optsize = sizeof(struct sctp_initmsg);
2820 case SCTP_PRIMARY_ADDR:
2821 /* we allow a "get" operation on this */
2823 struct sctp_setprim *ssp;
2825 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2826 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2829 union sctp_sockstore *addr;
2831 addr = &stcb->asoc.primary_destination->ro._l_addr;
2832 switch (addr->sa.sa_family) {
2836 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2837 in6_sin_2_v4mapsin6(&addr->sin,
2838 (struct sockaddr_in6 *)&ssp->ssp_addr);
2840 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2843 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2849 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2855 SCTP_TCB_UNLOCK(stcb);
2856 *optsize = sizeof(struct sctp_setprim);
2858 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2863 case SCTP_HMAC_IDENT:
2865 struct sctp_hmacalgo *shmac;
2866 sctp_hmaclist_t *hmaclist;
2870 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2872 SCTP_INP_RLOCK(inp);
2873 hmaclist = inp->sctp_ep.local_hmacs;
2874 if (hmaclist == NULL) {
2875 /* no HMACs to return */
2876 *optsize = sizeof(*shmac);
2877 SCTP_INP_RUNLOCK(inp);
2880 /* is there room for all of the hmac ids? */
2881 size = sizeof(*shmac) + (hmaclist->num_algo *
2882 sizeof(shmac->shmac_idents[0]));
2883 if ((size_t)(*optsize) < size) {
2884 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2886 SCTP_INP_RUNLOCK(inp);
2889 /* copy in the list */
2890 shmac->shmac_number_of_idents = hmaclist->num_algo;
2891 for (i = 0; i < hmaclist->num_algo; i++) {
2892 shmac->shmac_idents[i] = hmaclist->hmac[i];
2894 SCTP_INP_RUNLOCK(inp);
2898 case SCTP_AUTH_ACTIVE_KEY:
2900 struct sctp_authkeyid *scact;
2902 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2903 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2906 /* get the active key on the assoc */
2907 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2908 SCTP_TCB_UNLOCK(stcb);
2910 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2911 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2912 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2913 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC))) {
2914 /* get the endpoint active key */
2915 SCTP_INP_RLOCK(inp);
2916 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2917 SCTP_INP_RUNLOCK(inp);
2919 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2924 *optsize = sizeof(struct sctp_authkeyid);
2928 case SCTP_LOCAL_AUTH_CHUNKS:
2930 struct sctp_authchunks *sac;
2931 sctp_auth_chklist_t *chklist = NULL;
2934 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2935 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2938 /* get off the assoc */
2939 chklist = stcb->asoc.local_auth_chunks;
2940 /* is there enough space? */
2941 size = sctp_auth_get_chklist_size(chklist);
2942 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2944 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2946 /* copy in the chunks */
2947 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2948 sac->gauth_number_of_chunks = (uint32_t)size;
2949 *optsize = sizeof(struct sctp_authchunks) + size;
2951 SCTP_TCB_UNLOCK(stcb);
2953 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2954 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2955 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2956 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC))) {
2957 /* get off the endpoint */
2958 SCTP_INP_RLOCK(inp);
2959 chklist = inp->sctp_ep.local_auth_chunks;
2960 /* is there enough space? */
2961 size = sctp_auth_get_chklist_size(chklist);
2962 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2964 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2966 /* copy in the chunks */
2967 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2968 sac->gauth_number_of_chunks = (uint32_t)size;
2969 *optsize = sizeof(struct sctp_authchunks) + size;
2971 SCTP_INP_RUNLOCK(inp);
2973 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2979 case SCTP_PEER_AUTH_CHUNKS:
2981 struct sctp_authchunks *sac;
2982 sctp_auth_chklist_t *chklist = NULL;
2985 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2986 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2989 /* get off the assoc */
2990 chklist = stcb->asoc.peer_auth_chunks;
2991 /* is there enough space? */
2992 size = sctp_auth_get_chklist_size(chklist);
2993 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2995 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2997 /* copy in the chunks */
2998 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2999 sac->gauth_number_of_chunks = (uint32_t)size;
3000 *optsize = sizeof(struct sctp_authchunks) + size;
3002 SCTP_TCB_UNLOCK(stcb);
3004 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3011 struct sctp_event *event;
3012 uint32_t event_type;
3014 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3015 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3017 switch (event->se_type) {
3018 case SCTP_ASSOC_CHANGE:
3019 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3021 case SCTP_PEER_ADDR_CHANGE:
3022 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3024 case SCTP_REMOTE_ERROR:
3025 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3027 case SCTP_SEND_FAILED:
3028 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3030 case SCTP_SHUTDOWN_EVENT:
3031 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3033 case SCTP_ADAPTATION_INDICATION:
3034 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3036 case SCTP_PARTIAL_DELIVERY_EVENT:
3037 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3039 case SCTP_AUTHENTICATION_EVENT:
3040 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3042 case SCTP_STREAM_RESET_EVENT:
3043 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3045 case SCTP_SENDER_DRY_EVENT:
3046 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3048 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3050 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3053 case SCTP_ASSOC_RESET_EVENT:
3054 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3056 case SCTP_STREAM_CHANGE_EVENT:
3057 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3059 case SCTP_SEND_FAILED_EVENT:
3060 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3064 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3068 if (event_type > 0) {
3070 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3072 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3073 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3074 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3075 (event->se_assoc_id == SCTP_FUTURE_ASSOC))) {
3076 SCTP_INP_RLOCK(inp);
3077 event->se_on = sctp_is_feature_on(inp, event_type);
3078 SCTP_INP_RUNLOCK(inp);
3080 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3086 SCTP_TCB_UNLOCK(stcb);
3089 *optsize = sizeof(struct sctp_event);
3093 case SCTP_RECVRCVINFO:
3097 if (*optsize < sizeof(int)) {
3098 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3101 SCTP_INP_RLOCK(inp);
3102 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3103 SCTP_INP_RUNLOCK(inp);
3106 /* return the option value */
3107 *(int *)optval = onoff;
3108 *optsize = sizeof(int);
3112 case SCTP_RECVNXTINFO:
3116 if (*optsize < sizeof(int)) {
3117 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3120 SCTP_INP_RLOCK(inp);
3121 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3122 SCTP_INP_RUNLOCK(inp);
3125 /* return the option value */
3126 *(int *)optval = onoff;
3127 *optsize = sizeof(int);
3131 case SCTP_DEFAULT_SNDINFO:
3133 struct sctp_sndinfo *info;
3135 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3136 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3139 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3140 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3141 info->snd_flags &= 0xfff0;
3142 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3143 info->snd_context = stcb->asoc.def_send.sinfo_context;
3144 SCTP_TCB_UNLOCK(stcb);
3146 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3147 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3148 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3149 (info->snd_assoc_id == SCTP_FUTURE_ASSOC))) {
3150 SCTP_INP_RLOCK(inp);
3151 info->snd_sid = inp->def_send.sinfo_stream;
3152 info->snd_flags = inp->def_send.sinfo_flags;
3153 info->snd_flags &= 0xfff0;
3154 info->snd_ppid = inp->def_send.sinfo_ppid;
3155 info->snd_context = inp->def_send.sinfo_context;
3156 SCTP_INP_RUNLOCK(inp);
3158 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3163 *optsize = sizeof(struct sctp_sndinfo);
3167 case SCTP_DEFAULT_PRINFO:
3169 struct sctp_default_prinfo *info;
3171 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3172 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3175 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3176 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3177 SCTP_TCB_UNLOCK(stcb);
3179 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3180 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3181 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3182 (info->pr_assoc_id == SCTP_FUTURE_ASSOC))) {
3183 SCTP_INP_RLOCK(inp);
3184 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3185 info->pr_value = inp->def_send.sinfo_timetolive;
3186 SCTP_INP_RUNLOCK(inp);
3188 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3193 *optsize = sizeof(struct sctp_default_prinfo);
3197 case SCTP_PEER_ADDR_THLDS:
3199 struct sctp_paddrthlds *thlds;
3200 struct sctp_nets *net;
3201 struct sockaddr *addr;
3202 #if defined(INET) && defined(INET6)
3203 struct sockaddr_in sin_store;
3206 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3207 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3209 #if defined(INET) && defined(INET6)
3210 if (thlds->spt_address.ss_family == AF_INET6) {
3211 struct sockaddr_in6 *sin6;
3213 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3214 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3215 in6_sin6_2_sin(&sin_store, sin6);
3216 addr = (struct sockaddr *)&sin_store;
3218 addr = (struct sockaddr *)&thlds->spt_address;
3221 addr = (struct sockaddr *)&thlds->spt_address;
3224 addr = (struct sockaddr *)&thlds->spt_address;
3227 net = sctp_findnet(stcb, addr);
3230 * We increment here since
3231 * sctp_findassociation_ep_addr() wil do a
3232 * decrement if it finds the stcb as long as
3233 * the locked tcb (last argument) is NOT a
3237 SCTP_INP_INCR_REF(inp);
3238 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3240 SCTP_INP_DECR_REF(inp);
3243 if ((stcb != NULL) && (net == NULL)) {
3245 if (addr->sa_family == AF_INET) {
3246 struct sockaddr_in *sin;
3248 sin = (struct sockaddr_in *)addr;
3249 if (sin->sin_addr.s_addr != INADDR_ANY) {
3251 SCTP_TCB_UNLOCK(stcb);
3252 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3258 if (addr->sa_family == AF_INET6) {
3259 struct sockaddr_in6 *sin6;
3261 sin6 = (struct sockaddr_in6 *)addr;
3262 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3264 SCTP_TCB_UNLOCK(stcb);
3265 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3271 error = EAFNOSUPPORT;
3272 SCTP_TCB_UNLOCK(stcb);
3273 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3280 thlds->spt_pathmaxrxt = net->failure_threshold;
3281 thlds->spt_pathpfthld = net->pf_threshold;
3282 thlds->spt_pathcpthld = 0xffff;
3284 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3285 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3286 thlds->spt_pathcpthld = 0xffff;
3288 thlds->spt_assoc_id = sctp_get_associd(stcb);
3289 SCTP_TCB_UNLOCK(stcb);
3291 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3292 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3293 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3294 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
3295 /* Use endpoint defaults */
3296 SCTP_INP_RLOCK(inp);
3297 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3298 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3299 thlds->spt_pathcpthld = 0xffff;
3300 SCTP_INP_RUNLOCK(inp);
3302 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3307 *optsize = sizeof(struct sctp_paddrthlds);
3311 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3313 struct sctp_udpencaps *encaps;
3314 struct sctp_nets *net;
3315 struct sockaddr *addr;
3316 #if defined(INET) && defined(INET6)
3317 struct sockaddr_in sin_store;
3320 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3321 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3323 #if defined(INET) && defined(INET6)
3324 if (encaps->sue_address.ss_family == AF_INET6) {
3325 struct sockaddr_in6 *sin6;
3327 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3328 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3329 in6_sin6_2_sin(&sin_store, sin6);
3330 addr = (struct sockaddr *)&sin_store;
3332 addr = (struct sockaddr *)&encaps->sue_address;
3335 addr = (struct sockaddr *)&encaps->sue_address;
3338 addr = (struct sockaddr *)&encaps->sue_address;
3341 net = sctp_findnet(stcb, addr);
3344 * We increment here since
3345 * sctp_findassociation_ep_addr() wil do a
3346 * decrement if it finds the stcb as long as
3347 * the locked tcb (last argument) is NOT a
3351 SCTP_INP_INCR_REF(inp);
3352 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3354 SCTP_INP_DECR_REF(inp);
3357 if ((stcb != NULL) && (net == NULL)) {
3359 if (addr->sa_family == AF_INET) {
3360 struct sockaddr_in *sin;
3362 sin = (struct sockaddr_in *)addr;
3363 if (sin->sin_addr.s_addr != INADDR_ANY) {
3365 SCTP_TCB_UNLOCK(stcb);
3366 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3372 if (addr->sa_family == AF_INET6) {
3373 struct sockaddr_in6 *sin6;
3375 sin6 = (struct sockaddr_in6 *)addr;
3376 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3378 SCTP_TCB_UNLOCK(stcb);
3379 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3385 error = EAFNOSUPPORT;
3386 SCTP_TCB_UNLOCK(stcb);
3387 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3394 encaps->sue_port = net->port;
3396 encaps->sue_port = stcb->asoc.port;
3398 SCTP_TCB_UNLOCK(stcb);
3400 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3401 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3402 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3403 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
3404 SCTP_INP_RLOCK(inp);
3405 encaps->sue_port = inp->sctp_ep.port;
3406 SCTP_INP_RUNLOCK(inp);
3408 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3413 *optsize = sizeof(struct sctp_udpencaps);
3417 case SCTP_ECN_SUPPORTED:
3419 struct sctp_assoc_value *av;
3421 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3422 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3425 av->assoc_value = stcb->asoc.ecn_supported;
3426 SCTP_TCB_UNLOCK(stcb);
3428 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3429 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3430 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3431 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3432 SCTP_INP_RLOCK(inp);
3433 av->assoc_value = inp->ecn_supported;
3434 SCTP_INP_RUNLOCK(inp);
3436 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3441 *optsize = sizeof(struct sctp_assoc_value);
3445 case SCTP_PR_SUPPORTED:
3447 struct sctp_assoc_value *av;
3449 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3450 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3453 av->assoc_value = stcb->asoc.prsctp_supported;
3454 SCTP_TCB_UNLOCK(stcb);
3456 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3457 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3458 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3459 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3460 SCTP_INP_RLOCK(inp);
3461 av->assoc_value = inp->prsctp_supported;
3462 SCTP_INP_RUNLOCK(inp);
3464 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3469 *optsize = sizeof(struct sctp_assoc_value);
3473 case SCTP_AUTH_SUPPORTED:
3475 struct sctp_assoc_value *av;
3477 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3478 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3481 av->assoc_value = stcb->asoc.auth_supported;
3482 SCTP_TCB_UNLOCK(stcb);
3484 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3485 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3486 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3487 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3488 SCTP_INP_RLOCK(inp);
3489 av->assoc_value = inp->auth_supported;
3490 SCTP_INP_RUNLOCK(inp);
3492 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3497 *optsize = sizeof(struct sctp_assoc_value);
3501 case SCTP_ASCONF_SUPPORTED:
3503 struct sctp_assoc_value *av;
3505 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3506 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3509 av->assoc_value = stcb->asoc.asconf_supported;
3510 SCTP_TCB_UNLOCK(stcb);
3512 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3513 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3514 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3515 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3516 SCTP_INP_RLOCK(inp);
3517 av->assoc_value = inp->asconf_supported;
3518 SCTP_INP_RUNLOCK(inp);
3520 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3525 *optsize = sizeof(struct sctp_assoc_value);
3529 case SCTP_RECONFIG_SUPPORTED:
3531 struct sctp_assoc_value *av;
3533 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3534 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3537 av->assoc_value = stcb->asoc.reconfig_supported;
3538 SCTP_TCB_UNLOCK(stcb);
3540 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3541 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3542 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3543 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3544 SCTP_INP_RLOCK(inp);
3545 av->assoc_value = inp->reconfig_supported;
3546 SCTP_INP_RUNLOCK(inp);
3548 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3553 *optsize = sizeof(struct sctp_assoc_value);
3557 case SCTP_NRSACK_SUPPORTED:
3559 struct sctp_assoc_value *av;
3561 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3562 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3565 av->assoc_value = stcb->asoc.nrsack_supported;
3566 SCTP_TCB_UNLOCK(stcb);
3568 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3569 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3570 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3571 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3572 SCTP_INP_RLOCK(inp);
3573 av->assoc_value = inp->nrsack_supported;
3574 SCTP_INP_RUNLOCK(inp);
3576 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3581 *optsize = sizeof(struct sctp_assoc_value);
3585 case SCTP_PKTDROP_SUPPORTED:
3587 struct sctp_assoc_value *av;
3589 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3590 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3593 av->assoc_value = stcb->asoc.pktdrop_supported;
3594 SCTP_TCB_UNLOCK(stcb);
3596 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3597 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3598 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3599 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3600 SCTP_INP_RLOCK(inp);
3601 av->assoc_value = inp->pktdrop_supported;
3602 SCTP_INP_RUNLOCK(inp);
3604 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3609 *optsize = sizeof(struct sctp_assoc_value);
3613 case SCTP_ENABLE_STREAM_RESET:
3615 struct sctp_assoc_value *av;
3617 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3618 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3621 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3622 SCTP_TCB_UNLOCK(stcb);
3624 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3625 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3626 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3627 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3628 SCTP_INP_RLOCK(inp);
3629 av->assoc_value = (uint32_t)inp->local_strreset_support;
3630 SCTP_INP_RUNLOCK(inp);
3632 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3637 *optsize = sizeof(struct sctp_assoc_value);
3641 case SCTP_PR_STREAM_STATUS:
3643 struct sctp_prstatus *sprstat;
3647 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3648 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3650 sid = sprstat->sprstat_sid;
3651 policy = sprstat->sprstat_policy;
3652 #if defined(SCTP_DETAILED_STR_STATS)
3653 if ((stcb != NULL) &&
3654 (sid < stcb->asoc.streamoutcnt) &&
3655 (policy != SCTP_PR_SCTP_NONE) &&
3656 ((policy <= SCTP_PR_SCTP_MAX) ||
3657 (policy == SCTP_PR_SCTP_ALL))) {
3658 if (policy == SCTP_PR_SCTP_ALL) {
3659 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3660 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3662 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3663 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3666 if ((stcb != NULL) &&
3667 (sid < stcb->asoc.streamoutcnt) &&
3668 (policy == SCTP_PR_SCTP_ALL)) {
3669 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3670 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3673 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3677 SCTP_TCB_UNLOCK(stcb);
3680 *optsize = sizeof(struct sctp_prstatus);
3684 case SCTP_PR_ASSOC_STATUS:
3686 struct sctp_prstatus *sprstat;
3689 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3690 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3692 policy = sprstat->sprstat_policy;
3693 if ((stcb != NULL) &&
3694 (policy != SCTP_PR_SCTP_NONE) &&
3695 ((policy <= SCTP_PR_SCTP_MAX) ||
3696 (policy == SCTP_PR_SCTP_ALL))) {
3697 if (policy == SCTP_PR_SCTP_ALL) {
3698 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3699 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3701 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3702 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3705 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3709 SCTP_TCB_UNLOCK(stcb);
3712 *optsize = sizeof(struct sctp_prstatus);
3718 struct sctp_assoc_value *av;
3720 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3721 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3724 av->assoc_value = stcb->asoc.max_cwnd;
3725 SCTP_TCB_UNLOCK(stcb);
3727 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3728 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3729 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3730 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3731 SCTP_INP_RLOCK(inp);
3732 av->assoc_value = inp->max_cwnd;
3733 SCTP_INP_RUNLOCK(inp);
3735 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3740 *optsize = sizeof(struct sctp_assoc_value);
3745 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3746 error = ENOPROTOOPT;
3748 } /* end switch (sopt->sopt_name) */
3756 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3761 struct sctp_tcb *stcb = NULL;
3762 struct sctp_inpcb *inp = NULL;
3765 if (optval == NULL) {
3766 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3769 inp = (struct sctp_inpcb *)so->so_pcb;
3771 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3774 vrf_id = inp->def_vrf_id;
3779 case SCTP_AUTOCLOSE:
3780 case SCTP_AUTO_ASCONF:
3781 case SCTP_EXPLICIT_EOR:
3782 case SCTP_DISABLE_FRAGMENTS:
3783 case SCTP_USE_EXT_RCVINFO:
3784 case SCTP_I_WANT_MAPPED_V4_ADDR:
3785 /* copy in the option value */
3786 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3791 case SCTP_DISABLE_FRAGMENTS:
3792 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3794 case SCTP_AUTO_ASCONF:
3796 * NOTE: we don't really support this flag
3798 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3799 /* only valid for bound all sockets */
3800 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3802 /* forbidden by admin */
3803 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3806 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3808 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3812 case SCTP_EXPLICIT_EOR:
3813 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3815 case SCTP_USE_EXT_RCVINFO:
3816 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3818 case SCTP_I_WANT_MAPPED_V4_ADDR:
3819 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3820 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3822 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3827 set_opt = SCTP_PCB_FLAGS_NODELAY;
3829 case SCTP_AUTOCLOSE:
3830 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3831 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3832 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3835 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3837 * The value is in ticks. Note this does not effect
3838 * old associations, only new ones.
3840 inp->sctp_ep.auto_close_time = sctp_secs_to_ticks(*mopt);
3843 SCTP_INP_WLOCK(inp);
3845 sctp_feature_on(inp, set_opt);
3847 sctp_feature_off(inp, set_opt);
3849 SCTP_INP_WUNLOCK(inp);
3851 case SCTP_REUSE_PORT:
3853 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3854 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3855 /* Can't set it after we are bound */
3859 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3860 /* Can't do this for a 1-m socket */
3865 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3867 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3870 case SCTP_PARTIAL_DELIVERY_POINT:
3874 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3875 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3880 inp->partial_delivery_point = *value;
3883 case SCTP_FRAGMENT_INTERLEAVE:
3884 /* not yet until we re-write sctp_recvmsg() */
3888 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3889 if (*level == SCTP_FRAG_LEVEL_2) {
3890 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3891 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3892 } else if (*level == SCTP_FRAG_LEVEL_1) {
3893 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3894 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3895 } else if (*level == SCTP_FRAG_LEVEL_0) {
3896 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3897 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3900 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3905 case SCTP_INTERLEAVING_SUPPORTED:
3907 struct sctp_assoc_value *av;
3909 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3910 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3915 SCTP_TCB_UNLOCK(stcb);
3917 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3918 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3919 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3920 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3921 SCTP_INP_WLOCK(inp);
3922 if (av->assoc_value == 0) {
3923 inp->idata_supported = 0;
3925 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3926 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3927 inp->idata_supported = 1;
3935 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3939 SCTP_INP_WUNLOCK(inp);
3941 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3947 case SCTP_CMT_ON_OFF:
3948 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3949 struct sctp_assoc_value *av;
3951 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3952 if (av->assoc_value > SCTP_CMT_MAX) {
3953 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3957 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3959 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3960 SCTP_TCB_UNLOCK(stcb);
3962 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3963 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3964 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3965 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3966 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3967 SCTP_INP_WLOCK(inp);
3968 inp->sctp_cmt_on_off = av->assoc_value;
3969 SCTP_INP_WUNLOCK(inp);
3971 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3972 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3973 (av->assoc_id == SCTP_ALL_ASSOC))) {
3974 SCTP_INP_RLOCK(inp);
3975 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3976 SCTP_TCB_LOCK(stcb);
3977 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3978 SCTP_TCB_UNLOCK(stcb);
3980 SCTP_INP_RUNLOCK(inp);
3984 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3985 error = ENOPROTOOPT;
3988 case SCTP_PLUGGABLE_CC:
3990 struct sctp_assoc_value *av;
3991 struct sctp_nets *net;
3993 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3994 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3995 (av->assoc_value != SCTP_CC_HSTCP) &&
3996 (av->assoc_value != SCTP_CC_HTCP) &&
3997 (av->assoc_value != SCTP_CC_RTCC)) {
3998 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4002 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4004 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4005 stcb->asoc.congestion_control_module = av->assoc_value;
4006 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4007 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4008 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4011 SCTP_TCB_UNLOCK(stcb);
4013 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4014 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4015 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4016 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4017 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4018 SCTP_INP_WLOCK(inp);
4019 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
4020 SCTP_INP_WUNLOCK(inp);
4022 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4023 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4024 (av->assoc_id == SCTP_ALL_ASSOC))) {
4025 SCTP_INP_RLOCK(inp);
4026 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4027 SCTP_TCB_LOCK(stcb);
4028 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4029 stcb->asoc.congestion_control_module = av->assoc_value;
4030 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4031 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4032 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4035 SCTP_TCB_UNLOCK(stcb);
4037 SCTP_INP_RUNLOCK(inp);
4042 case SCTP_CC_OPTION:
4044 struct sctp_cc_option *cc_opt;
4046 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4047 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4049 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4050 (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC)) {
4051 SCTP_INP_RLOCK(inp);
4052 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4053 SCTP_TCB_LOCK(stcb);
4054 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4055 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4057 SCTP_TCB_UNLOCK(stcb);
4059 SCTP_INP_RUNLOCK(inp);
4064 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4067 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4070 SCTP_TCB_UNLOCK(stcb);
4074 case SCTP_PLUGGABLE_SS:
4076 struct sctp_assoc_value *av;
4078 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4079 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4080 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4081 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4082 (av->assoc_value != SCTP_SS_PRIORITY) &&
4083 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4084 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4085 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4089 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4091 SCTP_TCB_SEND_LOCK(stcb);
4092 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4093 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4094 stcb->asoc.stream_scheduling_module = av->assoc_value;
4095 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4096 SCTP_TCB_SEND_UNLOCK(stcb);
4097 SCTP_TCB_UNLOCK(stcb);
4099 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4100 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4101 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4102 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4103 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4104 SCTP_INP_WLOCK(inp);
4105 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4106 SCTP_INP_WUNLOCK(inp);
4108 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4109 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4110 (av->assoc_id == SCTP_ALL_ASSOC))) {
4111 SCTP_INP_RLOCK(inp);
4112 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4113 SCTP_TCB_LOCK(stcb);
4114 SCTP_TCB_SEND_LOCK(stcb);
4115 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4116 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4117 stcb->asoc.stream_scheduling_module = av->assoc_value;
4118 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4119 SCTP_TCB_SEND_UNLOCK(stcb);
4120 SCTP_TCB_UNLOCK(stcb);
4122 SCTP_INP_RUNLOCK(inp);
4129 struct sctp_stream_value *av;
4131 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4132 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4134 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4135 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4136 av->stream_value) < 0)) {
4137 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4140 SCTP_TCB_UNLOCK(stcb);
4142 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4143 (av->assoc_id == SCTP_CURRENT_ASSOC)) {
4144 SCTP_INP_RLOCK(inp);
4145 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4146 SCTP_TCB_LOCK(stcb);
4147 if (av->stream_id < stcb->asoc.streamoutcnt) {
4148 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4150 &stcb->asoc.strmout[av->stream_id],
4153 SCTP_TCB_UNLOCK(stcb);
4155 SCTP_INP_RUNLOCK(inp);
4158 * Can't set stream value without
4161 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4167 case SCTP_CLR_STAT_LOG:
4168 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4173 struct sctp_assoc_value *av;
4175 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4176 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4179 stcb->asoc.context = av->assoc_value;
4180 SCTP_TCB_UNLOCK(stcb);
4182 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4183 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4184 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4185 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4186 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4187 SCTP_INP_WLOCK(inp);
4188 inp->sctp_context = av->assoc_value;
4189 SCTP_INP_WUNLOCK(inp);
4191 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4192 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4193 (av->assoc_id == SCTP_ALL_ASSOC))) {
4194 SCTP_INP_RLOCK(inp);
4195 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4196 SCTP_TCB_LOCK(stcb);
4197 stcb->asoc.context = av->assoc_value;
4198 SCTP_TCB_UNLOCK(stcb);
4200 SCTP_INP_RUNLOCK(inp);
4207 uint32_t *default_vrfid;
4209 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4210 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4211 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4215 inp->def_vrf_id = *default_vrfid;
4218 case SCTP_DEL_VRF_ID:
4220 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4224 case SCTP_ADD_VRF_ID:
4226 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4230 case SCTP_DELAYED_SACK:
4232 struct sctp_sack_info *sack;
4234 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4235 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4236 if (sack->sack_delay) {
4237 if (sack->sack_delay > SCTP_MAX_SACK_DELAY) {
4240 SCTP_TCB_UNLOCK(stcb);
4246 if (sack->sack_delay) {
4247 stcb->asoc.delayed_ack = sack->sack_delay;
4249 if (sack->sack_freq) {
4250 stcb->asoc.sack_freq = sack->sack_freq;
4252 SCTP_TCB_UNLOCK(stcb);
4254 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4255 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4256 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4257 ((sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4258 (sack->sack_assoc_id == SCTP_ALL_ASSOC)))) {
4259 SCTP_INP_WLOCK(inp);
4260 if (sack->sack_delay) {
4261 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = sctp_msecs_to_ticks(sack->sack_delay);
4263 if (sack->sack_freq) {
4264 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4266 SCTP_INP_WUNLOCK(inp);
4268 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4269 ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4270 (sack->sack_assoc_id == SCTP_ALL_ASSOC))) {
4271 SCTP_INP_RLOCK(inp);
4272 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4273 SCTP_TCB_LOCK(stcb);
4274 if (sack->sack_delay) {
4275 stcb->asoc.delayed_ack = sack->sack_delay;
4277 if (sack->sack_freq) {
4278 stcb->asoc.sack_freq = sack->sack_freq;
4280 SCTP_TCB_UNLOCK(stcb);
4282 SCTP_INP_RUNLOCK(inp);
4287 case SCTP_AUTH_CHUNK:
4289 struct sctp_authchunk *sauth;
4291 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4293 SCTP_INP_WLOCK(inp);
4294 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4295 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4298 inp->auth_supported = 1;
4300 SCTP_INP_WUNLOCK(inp);
4305 struct sctp_authkey *sca;
4306 struct sctp_keyhead *shared_keys;
4307 sctp_sharedkey_t *shared_key;
4308 sctp_key_t *key = NULL;
4311 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4312 if (sca->sca_keylength == 0) {
4313 size = optsize - sizeof(struct sctp_authkey);
4315 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4316 size = sca->sca_keylength;
4318 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4323 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4326 shared_keys = &stcb->asoc.shared_keys;
4327 /* clear the cached keys for this key id */
4328 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4330 * create the new shared key and
4334 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4336 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4338 SCTP_TCB_UNLOCK(stcb);
4342 shared_key = sctp_alloc_sharedkey();
4343 if (shared_key == NULL) {
4345 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4347 SCTP_TCB_UNLOCK(stcb);
4350 shared_key->key = key;
4351 shared_key->keyid = sca->sca_keynumber;
4352 error = sctp_insert_sharedkey(shared_keys, shared_key);
4353 SCTP_TCB_UNLOCK(stcb);
4355 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4356 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4357 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4358 ((sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4359 (sca->sca_assoc_id == SCTP_ALL_ASSOC)))) {
4360 SCTP_INP_WLOCK(inp);
4361 shared_keys = &inp->sctp_ep.shared_keys;
4363 * clear the cached keys on all
4364 * assocs for this key id
4366 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4368 * create the new shared key and
4372 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4374 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4376 SCTP_INP_WUNLOCK(inp);
4380 shared_key = sctp_alloc_sharedkey();
4381 if (shared_key == NULL) {
4383 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4385 SCTP_INP_WUNLOCK(inp);
4388 shared_key->key = key;
4389 shared_key->keyid = sca->sca_keynumber;
4390 error = sctp_insert_sharedkey(shared_keys, shared_key);
4391 SCTP_INP_WUNLOCK(inp);
4393 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4394 ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4395 (sca->sca_assoc_id == SCTP_ALL_ASSOC))) {
4396 SCTP_INP_RLOCK(inp);
4397 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4398 SCTP_TCB_LOCK(stcb);
4399 shared_keys = &stcb->asoc.shared_keys;
4401 * clear the cached keys for
4404 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4406 * create the new shared key
4407 * and insert/replace it
4410 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4412 SCTP_TCB_UNLOCK(stcb);
4416 shared_key = sctp_alloc_sharedkey();
4417 if (shared_key == NULL) {
4419 SCTP_TCB_UNLOCK(stcb);
4422 shared_key->key = key;
4423 shared_key->keyid = sca->sca_keynumber;
4424 error = sctp_insert_sharedkey(shared_keys, shared_key);
4425 SCTP_TCB_UNLOCK(stcb);
4427 SCTP_INP_RUNLOCK(inp);
4432 case SCTP_HMAC_IDENT:
4434 struct sctp_hmacalgo *shmac;
4435 sctp_hmaclist_t *hmaclist;
4439 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4440 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4441 (shmac->shmac_number_of_idents > 0xffff)) {
4442 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4447 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4448 if (hmaclist == NULL) {
4449 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4453 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4454 hmacid = shmac->shmac_idents[i];
4455 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4456 /* invalid HMACs were found */ ;
4457 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4459 sctp_free_hmaclist(hmaclist);
4460 goto sctp_set_hmac_done;
4463 for (i = 0; i < hmaclist->num_algo; i++) {
4464 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4465 /* already in list */
4469 if (i == hmaclist->num_algo) {
4470 /* not found in list */
4471 sctp_free_hmaclist(hmaclist);
4472 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4476 /* set it on the endpoint */
4477 SCTP_INP_WLOCK(inp);
4478 if (inp->sctp_ep.local_hmacs)
4479 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4480 inp->sctp_ep.local_hmacs = hmaclist;
4481 SCTP_INP_WUNLOCK(inp);
4485 case SCTP_AUTH_ACTIVE_KEY:
4487 struct sctp_authkeyid *scact;
4489 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4490 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4492 /* set the active key on the right place */
4494 /* set the active key on the assoc */
4495 if (sctp_auth_setactivekey(stcb,
4496 scact->scact_keynumber)) {
4497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4498 SCTP_FROM_SCTP_USRREQ,
4502 SCTP_TCB_UNLOCK(stcb);
4504 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4505 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4506 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4507 ((scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4508 (scact->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4509 SCTP_INP_WLOCK(inp);
4510 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4511 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4514 SCTP_INP_WUNLOCK(inp);
4516 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4517 ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4518 (scact->scact_assoc_id == SCTP_ALL_ASSOC))) {
4519 SCTP_INP_RLOCK(inp);
4520 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4521 SCTP_TCB_LOCK(stcb);
4522 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4523 SCTP_TCB_UNLOCK(stcb);
4525 SCTP_INP_RUNLOCK(inp);
4530 case SCTP_AUTH_DELETE_KEY:
4532 struct sctp_authkeyid *scdel;
4534 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4535 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4537 /* delete the key from the right place */
4539 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4540 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4543 SCTP_TCB_UNLOCK(stcb);
4545 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4546 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4547 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4548 ((scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4549 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4550 SCTP_INP_WLOCK(inp);
4551 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4552 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4555 SCTP_INP_WUNLOCK(inp);
4557 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4558 ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4559 (scdel->scact_assoc_id == SCTP_ALL_ASSOC))) {
4560 SCTP_INP_RLOCK(inp);
4561 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4562 SCTP_TCB_LOCK(stcb);
4563 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4564 SCTP_TCB_UNLOCK(stcb);
4566 SCTP_INP_RUNLOCK(inp);
4571 case SCTP_AUTH_DEACTIVATE_KEY:
4573 struct sctp_authkeyid *keyid;
4575 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4576 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4578 /* deactivate the key from the right place */
4580 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4581 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4584 SCTP_TCB_UNLOCK(stcb);
4586 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4587 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4588 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4589 ((keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4590 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4591 SCTP_INP_WLOCK(inp);
4592 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4593 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4596 SCTP_INP_WUNLOCK(inp);
4598 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4599 ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4600 (keyid->scact_assoc_id == SCTP_ALL_ASSOC))) {
4601 SCTP_INP_RLOCK(inp);
4602 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4603 SCTP_TCB_LOCK(stcb);
4604 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4605 SCTP_TCB_UNLOCK(stcb);
4607 SCTP_INP_RUNLOCK(inp);
4612 case SCTP_ENABLE_STREAM_RESET:
4614 struct sctp_assoc_value *av;
4616 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4617 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4618 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4622 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4624 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4625 SCTP_TCB_UNLOCK(stcb);
4627 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4628 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4629 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4630 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4631 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4632 SCTP_INP_WLOCK(inp);
4633 inp->local_strreset_support = (uint8_t)av->assoc_value;
4634 SCTP_INP_WUNLOCK(inp);
4636 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4637 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4638 (av->assoc_id == SCTP_ALL_ASSOC))) {
4639 SCTP_INP_RLOCK(inp);
4640 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4641 SCTP_TCB_LOCK(stcb);
4642 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4643 SCTP_TCB_UNLOCK(stcb);
4645 SCTP_INP_RUNLOCK(inp);
4651 case SCTP_RESET_STREAMS:
4653 struct sctp_reset_streams *strrst;
4654 int i, send_out = 0;
4657 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4658 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4664 if (stcb->asoc.reconfig_supported == 0) {
4666 * Peer does not support the chunk type.
4668 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4670 SCTP_TCB_UNLOCK(stcb);
4673 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4674 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4676 SCTP_TCB_UNLOCK(stcb);
4679 if (sizeof(struct sctp_reset_streams) +
4680 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4682 SCTP_TCB_UNLOCK(stcb);
4685 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4687 if (stcb->asoc.stream_reset_outstanding) {
4688 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4690 SCTP_TCB_UNLOCK(stcb);
4694 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4697 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4698 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4700 SCTP_TCB_UNLOCK(stcb);
4703 if ((send_in == 0) && (send_out == 0)) {
4704 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4706 SCTP_TCB_UNLOCK(stcb);
4709 for (i = 0; i < strrst->srs_number_streams; i++) {
4711 (strrst->srs_stream_list[i] >= stcb->asoc.streamincnt)) {
4712 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4717 (strrst->srs_stream_list[i] >= stcb->asoc.streamoutcnt)) {
4718 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4724 SCTP_TCB_UNLOCK(stcb);
4731 if (strrst->srs_number_streams) {
4732 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4733 strm = strrst->srs_stream_list[i];
4734 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4735 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4741 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4742 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4743 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4750 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4751 strrst->srs_stream_list,
4752 send_in, 0, 0, 0, 0, 0);
4754 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4757 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4760 * For outgoing streams don't report any
4761 * problems in sending the request to the
4762 * application. XXX: Double check resetting
4767 SCTP_TCB_UNLOCK(stcb);
4770 case SCTP_ADD_STREAMS:
4772 struct sctp_add_streams *stradd;
4773 uint8_t addstream = 0;
4774 uint16_t add_o_strmcnt = 0;
4775 uint16_t add_i_strmcnt = 0;
4777 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4778 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4780 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4784 if (stcb->asoc.reconfig_supported == 0) {
4786 * Peer does not support the chunk type.
4788 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4790 SCTP_TCB_UNLOCK(stcb);
4793 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4796 SCTP_TCB_UNLOCK(stcb);
4799 if (stcb->asoc.stream_reset_outstanding) {
4800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4802 SCTP_TCB_UNLOCK(stcb);
4805 if ((stradd->sas_outstrms == 0) &&
4806 (stradd->sas_instrms == 0)) {
4810 if (stradd->sas_outstrms) {
4812 /* We allocate here */
4813 add_o_strmcnt = stradd->sas_outstrms;
4814 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4815 /* You can't have more than 64k */
4820 if (stradd->sas_instrms) {
4825 * We allocate inside
4826 * sctp_send_str_reset_req()
4828 add_i_strmcnt = stradd->sas_instrms;
4829 cnt = add_i_strmcnt;
4830 cnt += stcb->asoc.streamincnt;
4831 if (cnt > 0x0000ffff) {
4832 /* You can't have more than 64k */
4836 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4837 /* More than you are allowed */
4842 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4843 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4845 SCTP_TCB_UNLOCK(stcb);
4848 case SCTP_RESET_ASSOC:
4853 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4854 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4856 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4860 if (stcb->asoc.reconfig_supported == 0) {
4862 * Peer does not support the chunk type.
4864 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4866 SCTP_TCB_UNLOCK(stcb);
4869 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4870 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4872 SCTP_TCB_UNLOCK(stcb);
4875 if (stcb->asoc.stream_reset_outstanding) {
4876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4878 SCTP_TCB_UNLOCK(stcb);
4882 * Is there any data pending in the send or sent
4885 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4886 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4889 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4890 SCTP_TCB_UNLOCK(stcb);
4893 /* Do any streams have data queued? */
4894 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4895 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4899 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4900 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4901 SCTP_TCB_UNLOCK(stcb);
4904 case SCTP_CONNECT_X:
4905 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4906 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4910 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4912 case SCTP_CONNECT_X_DELAYED:
4913 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4914 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4918 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4920 case SCTP_CONNECT_X_COMPLETE:
4922 struct sockaddr *sa;
4924 /* FIXME MT: check correct? */
4925 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4928 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4929 SCTP_INP_RLOCK(inp);
4930 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4932 SCTP_TCB_LOCK(stcb);
4934 SCTP_INP_RUNLOCK(inp);
4937 * We increment here since
4938 * sctp_findassociation_ep_addr() wil do a
4939 * decrement if it finds the stcb as long as
4940 * the locked tcb (last argument) is NOT a
4943 SCTP_INP_INCR_REF(inp);
4944 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4946 SCTP_INP_DECR_REF(inp);
4951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4955 if (stcb->asoc.delayed_connection == 1) {
4956 stcb->asoc.delayed_connection = 0;
4957 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4958 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4959 stcb->asoc.primary_destination,
4960 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4961 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4964 * already expired or did not use delayed
4967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4970 SCTP_TCB_UNLOCK(stcb);
4973 case SCTP_MAX_BURST:
4975 struct sctp_assoc_value *av;
4977 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4978 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4981 stcb->asoc.max_burst = av->assoc_value;
4982 SCTP_TCB_UNLOCK(stcb);
4984 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4985 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4986 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4987 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4988 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4989 SCTP_INP_WLOCK(inp);
4990 inp->sctp_ep.max_burst = av->assoc_value;
4991 SCTP_INP_WUNLOCK(inp);
4993 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4994 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4995 (av->assoc_id == SCTP_ALL_ASSOC))) {
4996 SCTP_INP_RLOCK(inp);
4997 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4998 SCTP_TCB_LOCK(stcb);
4999 stcb->asoc.max_burst = av->assoc_value;
5000 SCTP_TCB_UNLOCK(stcb);
5002 SCTP_INP_RUNLOCK(inp);
5009 struct sctp_assoc_value *av;
5012 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
5013 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
5015 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5016 ovh = SCTP_MED_OVERHEAD;
5018 ovh = SCTP_MED_V4_OVERHEAD;
5021 if (av->assoc_value) {
5022 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
5024 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
5026 SCTP_TCB_UNLOCK(stcb);
5028 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5029 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5030 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5031 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
5032 SCTP_INP_WLOCK(inp);
5034 * FIXME MT: I think this is not in
5035 * tune with the API ID
5037 if (av->assoc_value) {
5038 inp->sctp_frag_point = (av->assoc_value + ovh);
5040 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
5042 SCTP_INP_WUNLOCK(inp);
5044 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5052 struct sctp_event_subscribe *events;
5054 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5056 SCTP_INP_WLOCK(inp);
5057 if (events->sctp_data_io_event) {
5058 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5060 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5063 if (events->sctp_association_event) {
5064 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5066 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5069 if (events->sctp_address_event) {
5070 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5072 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5075 if (events->sctp_send_failure_event) {
5076 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5078 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5081 if (events->sctp_peer_error_event) {
5082 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5084 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5087 if (events->sctp_shutdown_event) {
5088 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5090 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5093 if (events->sctp_partial_delivery_event) {
5094 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5096 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5099 if (events->sctp_adaptation_layer_event) {
5100 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5102 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5105 if (events->sctp_authentication_event) {
5106 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5108 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5111 if (events->sctp_sender_dry_event) {
5112 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5114 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5117 if (events->sctp_stream_reset_event) {
5118 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5120 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5122 SCTP_INP_WUNLOCK(inp);
5124 SCTP_INP_RLOCK(inp);
5125 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5126 SCTP_TCB_LOCK(stcb);
5127 if (events->sctp_association_event) {
5128 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5130 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5132 if (events->sctp_address_event) {
5133 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5135 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5137 if (events->sctp_send_failure_event) {
5138 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5140 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5142 if (events->sctp_peer_error_event) {
5143 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5145 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5147 if (events->sctp_shutdown_event) {
5148 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5150 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5152 if (events->sctp_partial_delivery_event) {
5153 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5155 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5157 if (events->sctp_adaptation_layer_event) {
5158 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5160 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5162 if (events->sctp_authentication_event) {
5163 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5165 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5167 if (events->sctp_sender_dry_event) {
5168 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5170 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5172 if (events->sctp_stream_reset_event) {
5173 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5175 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5177 SCTP_TCB_UNLOCK(stcb);
5180 * Send up the sender dry event only for 1-to-1
5183 if (events->sctp_sender_dry_event) {
5184 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5185 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5186 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5188 SCTP_TCB_LOCK(stcb);
5189 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5190 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5191 (stcb->asoc.stream_queue_cnt == 0)) {
5192 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5194 SCTP_TCB_UNLOCK(stcb);
5198 SCTP_INP_RUNLOCK(inp);
5201 case SCTP_ADAPTATION_LAYER:
5203 struct sctp_setadaptation *adap_bits;
5205 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5206 SCTP_INP_WLOCK(inp);
5207 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5208 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5209 SCTP_INP_WUNLOCK(inp);
5213 case SCTP_SET_INITIAL_DBG_SEQ:
5217 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5218 SCTP_INP_WLOCK(inp);
5219 inp->sctp_ep.initial_sequence_debug = *vvv;
5220 SCTP_INP_WUNLOCK(inp);
5224 case SCTP_DEFAULT_SEND_PARAM:
5226 struct sctp_sndrcvinfo *s_info;
5228 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5229 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5232 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5233 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5235 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5238 SCTP_TCB_UNLOCK(stcb);
5240 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5241 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5242 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5243 ((s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5244 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)))) {
5245 SCTP_INP_WLOCK(inp);
5246 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5247 SCTP_INP_WUNLOCK(inp);
5249 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5250 ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5251 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC))) {
5252 SCTP_INP_RLOCK(inp);
5253 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5254 SCTP_TCB_LOCK(stcb);
5255 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5256 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5258 SCTP_TCB_UNLOCK(stcb);
5260 SCTP_INP_RUNLOCK(inp);
5265 case SCTP_PEER_ADDR_PARAMS:
5267 struct sctp_paddrparams *paddrp;
5268 struct sctp_nets *net;
5269 struct sockaddr *addr;
5270 #if defined(INET) && defined(INET6)
5271 struct sockaddr_in sin_store;
5274 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5275 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5277 #if defined(INET) && defined(INET6)
5278 if (paddrp->spp_address.ss_family == AF_INET6) {
5279 struct sockaddr_in6 *sin6;
5281 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5282 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5283 in6_sin6_2_sin(&sin_store, sin6);
5284 addr = (struct sockaddr *)&sin_store;
5286 addr = (struct sockaddr *)&paddrp->spp_address;
5289 addr = (struct sockaddr *)&paddrp->spp_address;
5292 addr = (struct sockaddr *)&paddrp->spp_address;
5295 net = sctp_findnet(stcb, addr);
5298 * We increment here since
5299 * sctp_findassociation_ep_addr() wil do a
5300 * decrement if it finds the stcb as long as
5301 * the locked tcb (last argument) is NOT a
5305 SCTP_INP_INCR_REF(inp);
5306 stcb = sctp_findassociation_ep_addr(&inp, addr,
5309 SCTP_INP_DECR_REF(inp);
5312 if ((stcb != NULL) && (net == NULL)) {
5314 if (addr->sa_family == AF_INET) {
5316 struct sockaddr_in *sin;
5318 sin = (struct sockaddr_in *)addr;
5319 if (sin->sin_addr.s_addr != INADDR_ANY) {
5320 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5321 SCTP_TCB_UNLOCK(stcb);
5328 if (addr->sa_family == AF_INET6) {
5329 struct sockaddr_in6 *sin6;
5331 sin6 = (struct sockaddr_in6 *)addr;
5332 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5333 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5334 SCTP_TCB_UNLOCK(stcb);
5341 error = EAFNOSUPPORT;
5342 SCTP_TCB_UNLOCK(stcb);
5343 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5348 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5350 SCTP_TCB_UNLOCK(stcb);
5351 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5355 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5357 SCTP_TCB_UNLOCK(stcb);
5358 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5361 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) &&
5362 ((paddrp->spp_pathmtu < SCTP_SMALLEST_PMTU) ||
5363 (paddrp->spp_pathmtu > SCTP_LARGEST_PMTU))) {
5365 SCTP_TCB_UNLOCK(stcb);
5366 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5371 /************************TCB SPECIFIC SET ******************/
5373 /************************NET SPECIFIC SET ******************/
5374 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5375 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5376 !(net->dest_state & SCTP_ADDR_NOHB)) {
5377 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5378 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5380 net->dest_state |= SCTP_ADDR_NOHB;
5382 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5383 if (paddrp->spp_hbinterval) {
5384 net->heart_beat_delay = paddrp->spp_hbinterval;
5385 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5386 net->heart_beat_delay = 0;
5388 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5389 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5390 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5391 net->dest_state &= ~SCTP_ADDR_NOHB;
5393 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5394 if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
5395 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5396 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5397 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5400 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5401 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5402 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5403 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5405 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5406 net->mtu = paddrp->spp_pathmtu;
5407 switch (net->ro._l_addr.sa.sa_family) {
5410 net->mtu += SCTP_MIN_V4_OVERHEAD;
5415 net->mtu += SCTP_MIN_OVERHEAD;
5421 if (net->mtu < stcb->asoc.smallest_mtu) {
5422 sctp_pathmtu_adjustment(stcb, net->mtu);
5425 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5426 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5427 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5429 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5431 if (paddrp->spp_pathmaxrxt) {
5432 if (net->dest_state & SCTP_ADDR_PF) {
5433 if (net->error_count > paddrp->spp_pathmaxrxt) {
5434 net->dest_state &= ~SCTP_ADDR_PF;
5437 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5438 (net->error_count > net->pf_threshold)) {
5439 net->dest_state |= SCTP_ADDR_PF;
5440 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5441 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5442 stcb->sctp_ep, stcb, net,
5443 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5444 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5447 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5448 if (net->error_count > paddrp->spp_pathmaxrxt) {
5449 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5450 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5453 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5454 net->dest_state |= SCTP_ADDR_REACHABLE;
5455 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5458 net->failure_threshold = paddrp->spp_pathmaxrxt;
5460 if (paddrp->spp_flags & SPP_DSCP) {
5461 net->dscp = paddrp->spp_dscp & 0xfc;
5465 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5466 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5467 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5468 net->flowlabel |= 0x80000000;
5473 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5474 if (paddrp->spp_pathmaxrxt != 0) {
5475 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5476 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5477 if (net->dest_state & SCTP_ADDR_PF) {
5478 if (net->error_count > paddrp->spp_pathmaxrxt) {
5479 net->dest_state &= ~SCTP_ADDR_PF;
5482 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5483 (net->error_count > net->pf_threshold)) {
5484 net->dest_state |= SCTP_ADDR_PF;
5485 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5486 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5487 stcb->sctp_ep, stcb, net,
5488 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5489 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5492 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5493 if (net->error_count > paddrp->spp_pathmaxrxt) {
5494 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5495 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5498 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5499 net->dest_state |= SCTP_ADDR_REACHABLE;
5500 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5503 net->failure_threshold = paddrp->spp_pathmaxrxt;
5507 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5508 if (paddrp->spp_hbinterval != 0) {
5509 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5510 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5511 stcb->asoc.heart_beat_delay = 0;
5513 /* Turn back on the timer */
5514 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5515 if (paddrp->spp_hbinterval != 0) {
5516 net->heart_beat_delay = paddrp->spp_hbinterval;
5517 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5518 net->heart_beat_delay = 0;
5520 if (net->dest_state & SCTP_ADDR_NOHB) {
5521 net->dest_state &= ~SCTP_ADDR_NOHB;
5523 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5524 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5525 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5527 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5529 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5530 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5531 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5532 net->dest_state |= SCTP_ADDR_NOHB;
5533 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5534 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5536 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5540 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5542 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5543 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5544 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5545 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5546 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5548 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5549 net->mtu = paddrp->spp_pathmtu;
5550 switch (net->ro._l_addr.sa.sa_family) {
5553 net->mtu += SCTP_MIN_V4_OVERHEAD;
5558 net->mtu += SCTP_MIN_OVERHEAD;
5564 if (net->mtu < stcb->asoc.smallest_mtu) {
5565 sctp_pathmtu_adjustment(stcb, net->mtu);
5568 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5569 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5571 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5572 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5573 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5574 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5576 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5578 stcb->asoc.default_mtu = 0;
5579 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5581 if (paddrp->spp_flags & SPP_DSCP) {
5582 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5583 net->dscp = paddrp->spp_dscp & 0xfc;
5586 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5587 stcb->asoc.default_dscp |= 0x01;
5590 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5591 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5592 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5593 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5594 net->flowlabel |= 0x80000000;
5597 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5598 stcb->asoc.default_flowlabel |= 0x80000000;
5602 SCTP_TCB_UNLOCK(stcb);
5604 /************************NO TCB, SET TO default stuff ******************/
5605 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5606 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5607 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5608 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
5609 SCTP_INP_WLOCK(inp);
5611 * For the TOS/FLOWLABEL stuff you
5612 * set it with the options on the
5615 if (paddrp->spp_pathmaxrxt != 0) {
5616 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5619 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5620 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5621 else if (paddrp->spp_hbinterval != 0) {
5622 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5623 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5624 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5627 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5628 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5629 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5630 } else if (paddrp->spp_hbinterval) {
5631 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5633 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5634 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5635 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5637 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5638 inp->sctp_ep.default_mtu = 0;
5639 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5640 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5641 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5642 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5644 if (paddrp->spp_flags & SPP_DSCP) {
5645 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5646 inp->sctp_ep.default_dscp |= 0x01;
5649 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5650 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5651 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5652 inp->sctp_ep.default_flowlabel |= 0x80000000;
5656 SCTP_INP_WUNLOCK(inp);
5658 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5666 struct sctp_rtoinfo *srto;
5667 uint32_t new_init, new_min, new_max;
5669 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5670 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5673 if (srto->srto_initial)
5674 new_init = srto->srto_initial;
5676 new_init = stcb->asoc.initial_rto;
5678 new_max = srto->srto_max;
5680 new_max = stcb->asoc.maxrto;
5682 new_min = srto->srto_min;
5684 new_min = stcb->asoc.minrto;
5685 if ((new_min <= new_init) && (new_init <= new_max)) {
5686 stcb->asoc.initial_rto = new_init;
5687 stcb->asoc.maxrto = new_max;
5688 stcb->asoc.minrto = new_min;
5690 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5693 SCTP_TCB_UNLOCK(stcb);
5695 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5696 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5697 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5698 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
5699 SCTP_INP_WLOCK(inp);
5700 if (srto->srto_initial)
5701 new_init = srto->srto_initial;
5703 new_init = inp->sctp_ep.initial_rto;
5705 new_max = srto->srto_max;
5707 new_max = inp->sctp_ep.sctp_maxrto;
5709 new_min = srto->srto_min;
5711 new_min = inp->sctp_ep.sctp_minrto;
5712 if ((new_min <= new_init) && (new_init <= new_max)) {
5713 inp->sctp_ep.initial_rto = new_init;
5714 inp->sctp_ep.sctp_maxrto = new_max;
5715 inp->sctp_ep.sctp_minrto = new_min;
5717 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5720 SCTP_INP_WUNLOCK(inp);
5722 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5728 case SCTP_ASSOCINFO:
5730 struct sctp_assocparams *sasoc;
5732 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5733 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5734 if (sasoc->sasoc_cookie_life) {
5735 /* boundary check the cookie life */
5736 if (sasoc->sasoc_cookie_life < 1000)
5737 sasoc->sasoc_cookie_life = 1000;
5738 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5739 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5743 if (sasoc->sasoc_asocmaxrxt)
5744 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5745 if (sasoc->sasoc_cookie_life) {
5746 stcb->asoc.cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5748 SCTP_TCB_UNLOCK(stcb);
5750 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5751 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5752 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5753 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
5754 SCTP_INP_WLOCK(inp);
5755 if (sasoc->sasoc_asocmaxrxt)
5756 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5757 if (sasoc->sasoc_cookie_life) {
5758 inp->sctp_ep.def_cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5760 SCTP_INP_WUNLOCK(inp);
5762 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5770 struct sctp_initmsg *sinit;
5772 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5773 SCTP_INP_WLOCK(inp);
5774 if (sinit->sinit_num_ostreams)
5775 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5777 if (sinit->sinit_max_instreams)
5778 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5780 if (sinit->sinit_max_attempts)
5781 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5783 if (sinit->sinit_max_init_timeo)
5784 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5785 SCTP_INP_WUNLOCK(inp);
5788 case SCTP_PRIMARY_ADDR:
5790 struct sctp_setprim *spa;
5791 struct sctp_nets *net;
5792 struct sockaddr *addr;
5793 #if defined(INET) && defined(INET6)
5794 struct sockaddr_in sin_store;
5797 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5798 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5800 #if defined(INET) && defined(INET6)
5801 if (spa->ssp_addr.ss_family == AF_INET6) {
5802 struct sockaddr_in6 *sin6;
5804 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5805 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5806 in6_sin6_2_sin(&sin_store, sin6);
5807 addr = (struct sockaddr *)&sin_store;
5809 addr = (struct sockaddr *)&spa->ssp_addr;
5812 addr = (struct sockaddr *)&spa->ssp_addr;
5815 addr = (struct sockaddr *)&spa->ssp_addr;
5818 net = sctp_findnet(stcb, addr);
5821 * We increment here since
5822 * sctp_findassociation_ep_addr() wil do a
5823 * decrement if it finds the stcb as long as
5824 * the locked tcb (last argument) is NOT a
5828 SCTP_INP_INCR_REF(inp);
5829 stcb = sctp_findassociation_ep_addr(&inp, addr,
5832 SCTP_INP_DECR_REF(inp);
5836 if ((stcb != NULL) && (net != NULL)) {
5837 if (net != stcb->asoc.primary_destination) {
5838 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5839 /* Ok we need to set it */
5840 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5841 if ((stcb->asoc.alternate) &&
5842 (!(net->dest_state & SCTP_ADDR_PF)) &&
5843 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5844 sctp_free_remote_addr(stcb->asoc.alternate);
5845 stcb->asoc.alternate = NULL;
5848 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5852 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5857 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5861 SCTP_TCB_UNLOCK(stcb);
5865 case SCTP_SET_DYNAMIC_PRIMARY:
5867 union sctp_sockstore *ss;
5869 error = priv_check(curthread,
5870 PRIV_NETINET_RESERVEDPORT);
5874 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5875 /* SUPER USER CHECK? */
5876 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5879 case SCTP_SET_PEER_PRIMARY_ADDR:
5881 struct sctp_setpeerprim *sspp;
5882 struct sockaddr *addr;
5883 #if defined(INET) && defined(INET6)
5884 struct sockaddr_in sin_store;
5887 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5888 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5890 struct sctp_ifa *ifa;
5892 #if defined(INET) && defined(INET6)
5893 if (sspp->sspp_addr.ss_family == AF_INET6) {
5894 struct sockaddr_in6 *sin6;
5896 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5897 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5898 in6_sin6_2_sin(&sin_store, sin6);
5899 addr = (struct sockaddr *)&sin_store;
5901 addr = (struct sockaddr *)&sspp->sspp_addr;
5904 addr = (struct sockaddr *)&sspp->sspp_addr;
5907 addr = (struct sockaddr *)&sspp->sspp_addr;
5909 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5911 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5915 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5917 * Must validate the ifa found is in
5920 struct sctp_laddr *laddr;
5923 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5924 if (laddr->ifa == NULL) {
5925 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5929 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5930 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5933 if (laddr->ifa == ifa) {
5939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5944 switch (addr->sa_family) {
5948 struct sockaddr_in *sin;
5950 sin = (struct sockaddr_in *)addr;
5951 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5952 &sin->sin_addr) != 0) {
5953 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5963 struct sockaddr_in6 *sin6;
5965 sin6 = (struct sockaddr_in6 *)addr;
5966 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5967 &sin6->sin6_addr) != 0) {
5968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5976 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5981 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5985 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5987 SCTP_TCB_UNLOCK(stcb);
5989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5994 case SCTP_BINDX_ADD_ADDR:
5996 struct sockaddr *sa;
5999 td = (struct thread *)p;
6000 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
6002 if (sa->sa_family == AF_INET) {
6003 if (optsize < sizeof(struct sockaddr_in)) {
6004 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6009 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
6010 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6016 if (sa->sa_family == AF_INET6) {
6017 if (optsize < sizeof(struct sockaddr_in6)) {
6018 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6023 (error = prison_local_ip6(td->td_ucred,
6024 &(((struct sockaddr_in6 *)sa)->sin6_addr),
6025 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6026 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6032 error = EAFNOSUPPORT;
6035 sctp_bindx_add_address(so, inp, sa, vrf_id, &error, p);
6038 case SCTP_BINDX_REM_ADDR:
6040 struct sockaddr *sa;
6043 td = (struct thread *)p;
6045 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
6047 if (sa->sa_family == AF_INET) {
6048 if (optsize < sizeof(struct sockaddr_in)) {
6049 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6054 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
6055 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6061 if (sa->sa_family == AF_INET6) {
6062 if (optsize < sizeof(struct sockaddr_in6)) {
6063 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6068 (error = prison_local_ip6(td->td_ucred,
6069 &(((struct sockaddr_in6 *)sa)->sin6_addr),
6070 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6071 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6077 error = EAFNOSUPPORT;
6080 sctp_bindx_delete_address(inp, sa, vrf_id, &error);
6085 struct sctp_event *event;
6086 uint32_t event_type;
6088 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6089 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6090 switch (event->se_type) {
6091 case SCTP_ASSOC_CHANGE:
6092 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6094 case SCTP_PEER_ADDR_CHANGE:
6095 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6097 case SCTP_REMOTE_ERROR:
6098 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6100 case SCTP_SEND_FAILED:
6101 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6103 case SCTP_SHUTDOWN_EVENT:
6104 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6106 case SCTP_ADAPTATION_INDICATION:
6107 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6109 case SCTP_PARTIAL_DELIVERY_EVENT:
6110 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6112 case SCTP_AUTHENTICATION_EVENT:
6113 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6115 case SCTP_STREAM_RESET_EVENT:
6116 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6118 case SCTP_SENDER_DRY_EVENT:
6119 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6121 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6123 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6126 case SCTP_ASSOC_RESET_EVENT:
6127 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6129 case SCTP_STREAM_CHANGE_EVENT:
6130 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6132 case SCTP_SEND_FAILED_EVENT:
6133 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6137 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6141 if (event_type > 0) {
6144 sctp_stcb_feature_on(inp, stcb, event_type);
6145 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6146 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6147 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6148 (stcb->asoc.stream_queue_cnt == 0)) {
6149 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6153 sctp_stcb_feature_off(inp, stcb, event_type);
6155 SCTP_TCB_UNLOCK(stcb);
6158 * We don't want to send up a storm
6159 * of events, so return an error for
6162 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6163 (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6164 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6165 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6166 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6170 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6171 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6172 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6173 ((event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6174 (event->se_assoc_id == SCTP_ALL_ASSOC)))) {
6175 SCTP_INP_WLOCK(inp);
6177 sctp_feature_on(inp, event_type);
6179 sctp_feature_off(inp, event_type);
6181 SCTP_INP_WUNLOCK(inp);
6183 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6184 ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6185 (event->se_assoc_id == SCTP_ALL_ASSOC))) {
6186 SCTP_INP_RLOCK(inp);
6187 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6188 SCTP_TCB_LOCK(stcb);
6190 sctp_stcb_feature_on(inp, stcb, event_type);
6192 sctp_stcb_feature_off(inp, stcb, event_type);
6194 SCTP_TCB_UNLOCK(stcb);
6196 SCTP_INP_RUNLOCK(inp);
6201 SCTP_TCB_UNLOCK(stcb);
6206 case SCTP_RECVRCVINFO:
6210 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6211 SCTP_INP_WLOCK(inp);
6213 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6215 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6217 SCTP_INP_WUNLOCK(inp);
6220 case SCTP_RECVNXTINFO:
6224 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6225 SCTP_INP_WLOCK(inp);
6227 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6229 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6231 SCTP_INP_WUNLOCK(inp);
6234 case SCTP_DEFAULT_SNDINFO:
6236 struct sctp_sndinfo *info;
6239 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6240 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6243 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6244 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6245 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6246 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6247 stcb->asoc.def_send.sinfo_flags |= policy;
6248 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6249 stcb->asoc.def_send.sinfo_context = info->snd_context;
6251 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6254 SCTP_TCB_UNLOCK(stcb);
6256 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6257 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6258 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6259 ((info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6260 (info->snd_assoc_id == SCTP_ALL_ASSOC)))) {
6261 SCTP_INP_WLOCK(inp);
6262 inp->def_send.sinfo_stream = info->snd_sid;
6263 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6264 inp->def_send.sinfo_flags = info->snd_flags;
6265 inp->def_send.sinfo_flags |= policy;
6266 inp->def_send.sinfo_ppid = info->snd_ppid;
6267 inp->def_send.sinfo_context = info->snd_context;
6268 SCTP_INP_WUNLOCK(inp);
6270 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6271 ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6272 (info->snd_assoc_id == SCTP_ALL_ASSOC))) {
6273 SCTP_INP_RLOCK(inp);
6274 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6275 SCTP_TCB_LOCK(stcb);
6276 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6277 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6278 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6279 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6280 stcb->asoc.def_send.sinfo_flags |= policy;
6281 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6282 stcb->asoc.def_send.sinfo_context = info->snd_context;
6284 SCTP_TCB_UNLOCK(stcb);
6286 SCTP_INP_RUNLOCK(inp);
6291 case SCTP_DEFAULT_PRINFO:
6293 struct sctp_default_prinfo *info;
6295 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6296 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6298 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6300 SCTP_TCB_UNLOCK(stcb);
6302 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6307 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6308 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6309 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6310 SCTP_TCB_UNLOCK(stcb);
6312 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6313 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6314 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6315 ((info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6316 (info->pr_assoc_id == SCTP_ALL_ASSOC)))) {
6317 SCTP_INP_WLOCK(inp);
6318 inp->def_send.sinfo_flags &= 0xfff0;
6319 inp->def_send.sinfo_flags |= info->pr_policy;
6320 inp->def_send.sinfo_timetolive = info->pr_value;
6321 SCTP_INP_WUNLOCK(inp);
6323 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6324 ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6325 (info->pr_assoc_id == SCTP_ALL_ASSOC))) {
6326 SCTP_INP_RLOCK(inp);
6327 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6328 SCTP_TCB_LOCK(stcb);
6329 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6330 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6331 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6332 SCTP_TCB_UNLOCK(stcb);
6334 SCTP_INP_RUNLOCK(inp);
6339 case SCTP_PEER_ADDR_THLDS:
6340 /* Applies to the specific association */
6342 struct sctp_paddrthlds *thlds;
6343 struct sctp_nets *net;
6344 struct sockaddr *addr;
6345 #if defined(INET) && defined(INET6)
6346 struct sockaddr_in sin_store;
6349 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6350 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6352 #if defined(INET) && defined(INET6)
6353 if (thlds->spt_address.ss_family == AF_INET6) {
6354 struct sockaddr_in6 *sin6;
6356 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6357 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6358 in6_sin6_2_sin(&sin_store, sin6);
6359 addr = (struct sockaddr *)&sin_store;
6361 addr = (struct sockaddr *)&thlds->spt_address;
6364 addr = (struct sockaddr *)&thlds->spt_address;
6367 addr = (struct sockaddr *)&thlds->spt_address;
6370 net = sctp_findnet(stcb, addr);
6373 * We increment here since
6374 * sctp_findassociation_ep_addr() wil do a
6375 * decrement if it finds the stcb as long as
6376 * the locked tcb (last argument) is NOT a
6380 SCTP_INP_INCR_REF(inp);
6381 stcb = sctp_findassociation_ep_addr(&inp, addr,
6384 SCTP_INP_DECR_REF(inp);
6387 if ((stcb != NULL) && (net == NULL)) {
6389 if (addr->sa_family == AF_INET) {
6391 struct sockaddr_in *sin;
6393 sin = (struct sockaddr_in *)addr;
6394 if (sin->sin_addr.s_addr != INADDR_ANY) {
6395 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6396 SCTP_TCB_UNLOCK(stcb);
6403 if (addr->sa_family == AF_INET6) {
6404 struct sockaddr_in6 *sin6;
6406 sin6 = (struct sockaddr_in6 *)addr;
6407 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6408 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6409 SCTP_TCB_UNLOCK(stcb);
6416 error = EAFNOSUPPORT;
6417 SCTP_TCB_UNLOCK(stcb);
6418 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6422 if (thlds->spt_pathcpthld != 0xffff) {
6424 SCTP_TCB_UNLOCK(stcb);
6427 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6432 net->failure_threshold = thlds->spt_pathmaxrxt;
6433 net->pf_threshold = thlds->spt_pathpfthld;
6434 if (net->dest_state & SCTP_ADDR_PF) {
6435 if ((net->error_count > net->failure_threshold) ||
6436 (net->error_count <= net->pf_threshold)) {
6437 net->dest_state &= ~SCTP_ADDR_PF;
6440 if ((net->error_count > net->pf_threshold) &&
6441 (net->error_count <= net->failure_threshold)) {
6442 net->dest_state |= SCTP_ADDR_PF;
6443 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6444 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6445 stcb->sctp_ep, stcb, net,
6446 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6447 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6450 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6451 if (net->error_count > net->failure_threshold) {
6452 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6453 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6456 if (net->error_count <= net->failure_threshold) {
6457 net->dest_state |= SCTP_ADDR_REACHABLE;
6458 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6462 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6463 net->failure_threshold = thlds->spt_pathmaxrxt;
6464 net->pf_threshold = thlds->spt_pathpfthld;
6465 if (net->dest_state & SCTP_ADDR_PF) {
6466 if ((net->error_count > net->failure_threshold) ||
6467 (net->error_count <= net->pf_threshold)) {
6468 net->dest_state &= ~SCTP_ADDR_PF;
6471 if ((net->error_count > net->pf_threshold) &&
6472 (net->error_count <= net->failure_threshold)) {
6473 net->dest_state |= SCTP_ADDR_PF;
6474 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6475 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6476 stcb->sctp_ep, stcb, net,
6477 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6478 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6481 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6482 if (net->error_count > net->failure_threshold) {
6483 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6484 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6487 if (net->error_count <= net->failure_threshold) {
6488 net->dest_state |= SCTP_ADDR_REACHABLE;
6489 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6493 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6494 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6496 SCTP_TCB_UNLOCK(stcb);
6498 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6499 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6500 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6501 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
6502 SCTP_INP_WLOCK(inp);
6503 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6504 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6505 SCTP_INP_WUNLOCK(inp);
6507 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6513 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6515 struct sctp_udpencaps *encaps;
6516 struct sctp_nets *net;
6517 struct sockaddr *addr;
6518 #if defined(INET) && defined(INET6)
6519 struct sockaddr_in sin_store;
6522 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6523 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6525 #if defined(INET) && defined(INET6)
6526 if (encaps->sue_address.ss_family == AF_INET6) {
6527 struct sockaddr_in6 *sin6;
6529 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6530 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6531 in6_sin6_2_sin(&sin_store, sin6);
6532 addr = (struct sockaddr *)&sin_store;
6534 addr = (struct sockaddr *)&encaps->sue_address;
6537 addr = (struct sockaddr *)&encaps->sue_address;
6540 addr = (struct sockaddr *)&encaps->sue_address;
6543 net = sctp_findnet(stcb, addr);
6546 * We increment here since
6547 * sctp_findassociation_ep_addr() wil do a
6548 * decrement if it finds the stcb as long as
6549 * the locked tcb (last argument) is NOT a
6553 SCTP_INP_INCR_REF(inp);
6554 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6556 SCTP_INP_DECR_REF(inp);
6559 if ((stcb != NULL) && (net == NULL)) {
6561 if (addr->sa_family == AF_INET) {
6563 struct sockaddr_in *sin;
6565 sin = (struct sockaddr_in *)addr;
6566 if (sin->sin_addr.s_addr != INADDR_ANY) {
6567 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6568 SCTP_TCB_UNLOCK(stcb);
6575 if (addr->sa_family == AF_INET6) {
6576 struct sockaddr_in6 *sin6;
6578 sin6 = (struct sockaddr_in6 *)addr;
6579 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6580 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6581 SCTP_TCB_UNLOCK(stcb);
6588 error = EAFNOSUPPORT;
6589 SCTP_TCB_UNLOCK(stcb);
6590 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6597 net->port = encaps->sue_port;
6599 stcb->asoc.port = encaps->sue_port;
6601 SCTP_TCB_UNLOCK(stcb);
6603 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6604 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6605 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6606 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
6607 SCTP_INP_WLOCK(inp);
6608 inp->sctp_ep.port = encaps->sue_port;
6609 SCTP_INP_WUNLOCK(inp);
6611 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6617 case SCTP_ECN_SUPPORTED:
6619 struct sctp_assoc_value *av;
6621 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6622 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6625 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6627 SCTP_TCB_UNLOCK(stcb);
6629 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6630 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6631 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6632 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6633 SCTP_INP_WLOCK(inp);
6634 if (av->assoc_value == 0) {
6635 inp->ecn_supported = 0;
6637 inp->ecn_supported = 1;
6639 SCTP_INP_WUNLOCK(inp);
6641 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6647 case SCTP_PR_SUPPORTED:
6649 struct sctp_assoc_value *av;
6651 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6652 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6655 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6657 SCTP_TCB_UNLOCK(stcb);
6659 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6660 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6661 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6662 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6663 SCTP_INP_WLOCK(inp);
6664 if (av->assoc_value == 0) {
6665 inp->prsctp_supported = 0;
6667 inp->prsctp_supported = 1;
6669 SCTP_INP_WUNLOCK(inp);
6671 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6677 case SCTP_AUTH_SUPPORTED:
6679 struct sctp_assoc_value *av;
6681 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6682 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6687 SCTP_TCB_UNLOCK(stcb);
6689 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6690 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6691 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6692 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6693 if ((av->assoc_value == 0) &&
6694 (inp->asconf_supported == 1)) {
6696 * AUTH is required for
6699 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6702 SCTP_INP_WLOCK(inp);
6703 if (av->assoc_value == 0) {
6704 inp->auth_supported = 0;
6706 inp->auth_supported = 1;
6708 SCTP_INP_WUNLOCK(inp);
6711 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6717 case SCTP_ASCONF_SUPPORTED:
6719 struct sctp_assoc_value *av;
6721 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6722 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6725 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6727 SCTP_TCB_UNLOCK(stcb);
6729 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6730 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6731 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6732 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6733 if ((av->assoc_value != 0) &&
6734 (inp->auth_supported == 0)) {
6736 * AUTH is required for
6739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6742 SCTP_INP_WLOCK(inp);
6743 if (av->assoc_value == 0) {
6744 inp->asconf_supported = 0;
6745 sctp_auth_delete_chunk(SCTP_ASCONF,
6746 inp->sctp_ep.local_auth_chunks);
6747 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6748 inp->sctp_ep.local_auth_chunks);
6750 inp->asconf_supported = 1;
6751 sctp_auth_add_chunk(SCTP_ASCONF,
6752 inp->sctp_ep.local_auth_chunks);
6753 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6754 inp->sctp_ep.local_auth_chunks);
6756 SCTP_INP_WUNLOCK(inp);
6759 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6765 case SCTP_RECONFIG_SUPPORTED:
6767 struct sctp_assoc_value *av;
6769 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6770 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6775 SCTP_TCB_UNLOCK(stcb);
6777 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6778 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6779 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6780 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6781 SCTP_INP_WLOCK(inp);
6782 if (av->assoc_value == 0) {
6783 inp->reconfig_supported = 0;
6785 inp->reconfig_supported = 1;
6787 SCTP_INP_WUNLOCK(inp);
6789 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6795 case SCTP_NRSACK_SUPPORTED:
6797 struct sctp_assoc_value *av;
6799 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6800 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6803 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6805 SCTP_TCB_UNLOCK(stcb);
6807 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6808 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6809 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6810 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6811 SCTP_INP_WLOCK(inp);
6812 if (av->assoc_value == 0) {
6813 inp->nrsack_supported = 0;
6815 inp->nrsack_supported = 1;
6817 SCTP_INP_WUNLOCK(inp);
6819 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6825 case SCTP_PKTDROP_SUPPORTED:
6827 struct sctp_assoc_value *av;
6829 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6830 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6833 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6835 SCTP_TCB_UNLOCK(stcb);
6837 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6838 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6839 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6840 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6841 SCTP_INP_WLOCK(inp);
6842 if (av->assoc_value == 0) {
6843 inp->pktdrop_supported = 0;
6845 inp->pktdrop_supported = 1;
6847 SCTP_INP_WUNLOCK(inp);
6849 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6857 struct sctp_assoc_value *av;
6858 struct sctp_nets *net;
6860 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6861 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6864 stcb->asoc.max_cwnd = av->assoc_value;
6865 if (stcb->asoc.max_cwnd > 0) {
6866 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6867 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6868 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6869 net->cwnd = stcb->asoc.max_cwnd;
6870 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6871 net->cwnd = net->mtu - sizeof(struct sctphdr);
6876 SCTP_TCB_UNLOCK(stcb);
6878 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6879 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6880 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6881 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6882 SCTP_INP_WLOCK(inp);
6883 inp->max_cwnd = av->assoc_value;
6884 SCTP_INP_WUNLOCK(inp);
6886 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6893 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6894 error = ENOPROTOOPT;
6896 } /* end switch (opt) */
6901 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6903 struct epoch_tracker et;
6904 struct sctp_inpcb *inp;
6905 void *optval = NULL;
6910 if ((sopt->sopt_level == SOL_SOCKET) &&
6911 (sopt->sopt_name == SO_SETFIB)) {
6912 inp = (struct sctp_inpcb *)so->so_pcb;
6914 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6917 SCTP_INP_WLOCK(inp);
6918 inp->fibnum = so->so_fibnum;
6919 SCTP_INP_WUNLOCK(inp);
6922 if (sopt->sopt_level != IPPROTO_SCTP) {
6923 /* wrong proto level... send back up to IP */
6925 if (INP_CHECK_SOCKAF(so, AF_INET6))
6926 error = ip6_ctloutput(so, sopt);
6928 #if defined(INET) && defined(INET6)
6932 error = ip_ctloutput(so, sopt);
6936 optsize = sopt->sopt_valsize;
6937 if (optsize > SCTP_SOCKET_OPTION_LIMIT) {
6938 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6942 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6943 if (optval == NULL) {
6944 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6947 error = sooptcopyin(sopt, optval, optsize, optsize);
6949 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6953 p = (void *)sopt->sopt_td;
6954 if (sopt->sopt_dir == SOPT_SET) {
6955 NET_EPOCH_ENTER(et);
6956 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6958 } else if (sopt->sopt_dir == SOPT_GET) {
6959 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6961 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6964 if ((error == 0) && (optval != NULL)) {
6965 error = sooptcopyout(sopt, optval, optsize);
6966 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6967 } else if (optval != NULL) {
6968 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6976 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6978 struct epoch_tracker et;
6980 int create_lock_on = 0;
6982 struct sctp_inpcb *inp;
6983 struct sctp_tcb *stcb = NULL;
6985 inp = (struct sctp_inpcb *)so->so_pcb;
6987 /* I made the same as TCP since we are not setup? */
6988 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6989 return (ECONNRESET);
6992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6996 switch (addr->sa_family) {
7000 struct sockaddr_in6 *sin6;
7002 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
7003 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7006 sin6 = (struct sockaddr_in6 *)addr;
7007 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6->sin6_addr)) != 0) {
7008 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7017 struct sockaddr_in *sin;
7019 if (addr->sa_len != sizeof(struct sockaddr_in)) {
7020 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7023 sin = (struct sockaddr_in *)addr;
7024 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sin->sin_addr)) != 0) {
7025 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7032 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
7033 return (EAFNOSUPPORT);
7035 SCTP_INP_INCR_REF(inp);
7036 SCTP_ASOC_CREATE_LOCK(inp);
7038 NET_EPOCH_ENTER(et);
7040 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
7041 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
7042 /* Should I really unlock ? */
7043 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
7048 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
7049 (addr->sa_family == AF_INET6)) {
7050 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7055 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
7056 SCTP_PCB_FLAGS_UNBOUND) {
7057 /* Bind a ephemeral port */
7058 error = sctp_inpcb_bind(so, NULL, NULL, p);
7063 /* Now do we connect? */
7064 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
7065 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
7066 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7070 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7071 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7072 /* We are already connected AND the TCP model */
7073 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7077 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7078 SCTP_INP_RLOCK(inp);
7079 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7080 SCTP_INP_RUNLOCK(inp);
7083 * We increment here since sctp_findassociation_ep_addr()
7084 * will do a decrement if it finds the stcb as long as the
7085 * locked tcb (last argument) is NOT a TCB.. aka NULL.
7087 SCTP_INP_INCR_REF(inp);
7088 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7090 SCTP_INP_DECR_REF(inp);
7092 SCTP_TCB_UNLOCK(stcb);
7096 /* Already have or am bring up an association */
7097 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7102 vrf_id = inp->def_vrf_id;
7103 /* We are GOOD to go */
7104 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
7105 inp->sctp_ep.pre_open_stream_count,
7106 inp->sctp_ep.port, p,
7107 SCTP_INITIALIZE_AUTH_PARAMS);
7109 /* Gak! no memory */
7112 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7113 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7114 /* Set the connected flag so we can queue data */
7117 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7118 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7120 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7121 SCTP_TCB_UNLOCK(stcb);
7124 if (create_lock_on) {
7125 SCTP_ASOC_CREATE_UNLOCK(inp);
7127 SCTP_INP_DECR_REF(inp);
7133 sctp_listen(struct socket *so, int backlog, struct thread *p)
7136 * Note this module depends on the protocol processing being called
7137 * AFTER any socket level flags and backlog are applied to the
7138 * socket. The traditional way that the socket flags are applied is
7139 * AFTER protocol processing. We have made a change to the
7140 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7141 * place if the socket API for SCTP is to work properly.
7145 struct sctp_inpcb *inp;
7147 inp = (struct sctp_inpcb *)so->so_pcb;
7149 /* I made the same as TCP since we are not setup? */
7150 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7151 return (ECONNRESET);
7153 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7154 /* See if we have a listener */
7155 struct sctp_inpcb *tinp;
7156 union sctp_sockstore store;
7158 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7160 struct sctp_laddr *laddr;
7162 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7163 memcpy(&store, &laddr->ifa->address, sizeof(store));
7164 switch (store.sa.sa_family) {
7167 store.sin.sin_port = inp->sctp_lport;
7172 store.sin6.sin6_port = inp->sctp_lport;
7178 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7179 if (tinp && (tinp != inp) &&
7180 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7181 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7182 (SCTP_IS_LISTENING(tinp))) {
7184 * we have a listener already and
7187 SCTP_INP_DECR_REF(tinp);
7188 return (EADDRINUSE);
7190 SCTP_INP_DECR_REF(tinp);
7194 /* Setup a local addr bound all */
7195 memset(&store, 0, sizeof(store));
7197 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7198 store.sa.sa_family = AF_INET6;
7199 store.sa.sa_len = sizeof(struct sockaddr_in6);
7203 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7204 store.sa.sa_family = AF_INET;
7205 store.sa.sa_len = sizeof(struct sockaddr_in);
7208 switch (store.sa.sa_family) {
7211 store.sin.sin_port = inp->sctp_lport;
7216 store.sin6.sin6_port = inp->sctp_lport;
7222 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7223 if (tinp && (tinp != inp) &&
7224 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7225 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7226 (SCTP_IS_LISTENING(tinp))) {
7228 * we have a listener already and its not
7231 SCTP_INP_DECR_REF(tinp);
7232 return (EADDRINUSE);
7234 SCTP_INP_DECR_REF(tinp);
7238 SCTP_INP_RLOCK(inp);
7239 #ifdef SCTP_LOCK_LOGGING
7240 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7241 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7245 error = solisten_proto_check(so);
7248 SCTP_INP_RUNLOCK(inp);
7251 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7252 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7254 * The unlucky case - We are in the tcp pool with this guy.
7255 * - Someone else is in the main inp slot. - We must move
7256 * this guy (the listener) to the main slot - We must then
7257 * move the guy that was listener to the TCP Pool.
7259 if (sctp_swap_inpcb_for_listen(inp)) {
7260 SCTP_INP_RUNLOCK(inp);
7261 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7262 return (EADDRINUSE);
7266 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7267 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7268 /* We are already connected AND the TCP model */
7269 SCTP_INP_RUNLOCK(inp);
7270 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7271 return (EADDRINUSE);
7273 SCTP_INP_RUNLOCK(inp);
7274 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7275 /* We must do a bind. */
7276 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7277 /* bind error, probably perm */
7281 SCTP_INP_WLOCK(inp);
7282 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7284 solisten_proto(so, backlog);
7288 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7290 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7292 SCTP_INP_WUNLOCK(inp);
7296 static int sctp_defered_wakeup_cnt = 0;
7299 sctp_accept(struct socket *so, struct sockaddr **addr)
7301 struct sctp_tcb *stcb;
7302 struct sctp_inpcb *inp;
7303 union sctp_sockstore store;
7307 inp = (struct sctp_inpcb *)so->so_pcb;
7310 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7311 return (ECONNRESET);
7313 SCTP_INP_WLOCK(inp);
7314 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7315 SCTP_INP_WUNLOCK(inp);
7316 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7317 return (EOPNOTSUPP);
7319 if (so->so_state & SS_ISDISCONNECTED) {
7320 SCTP_INP_WUNLOCK(inp);
7321 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7322 return (ECONNABORTED);
7324 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7326 SCTP_INP_WUNLOCK(inp);
7327 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7328 return (ECONNRESET);
7330 SCTP_TCB_LOCK(stcb);
7331 store = stcb->asoc.primary_destination->ro._l_addr;
7332 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7333 /* Wake any delayed sleep action */
7334 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7335 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7336 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7337 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7338 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7339 if (sowriteable(inp->sctp_socket)) {
7340 sowwakeup_locked(inp->sctp_socket);
7342 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7345 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7346 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7347 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7348 if (soreadable(inp->sctp_socket)) {
7349 sctp_defered_wakeup_cnt++;
7350 sorwakeup_locked(inp->sctp_socket);
7352 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7356 SCTP_INP_WUNLOCK(inp);
7357 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7358 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7359 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7361 SCTP_TCB_UNLOCK(stcb);
7363 switch (store.sa.sa_family) {
7367 struct sockaddr_in *sin;
7369 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7372 sin->sin_family = AF_INET;
7373 sin->sin_len = sizeof(*sin);
7374 sin->sin_port = store.sin.sin_port;
7375 sin->sin_addr = store.sin.sin_addr;
7376 *addr = (struct sockaddr *)sin;
7383 struct sockaddr_in6 *sin6;
7385 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7388 sin6->sin6_family = AF_INET6;
7389 sin6->sin6_len = sizeof(*sin6);
7390 sin6->sin6_port = store.sin6.sin6_port;
7391 sin6->sin6_addr = store.sin6.sin6_addr;
7392 if ((error = sa6_recoverscope(sin6)) != 0) {
7393 SCTP_FREE_SONAME(sin6);
7396 *addr = (struct sockaddr *)sin6;
7409 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7411 struct sockaddr_in *sin;
7413 struct sctp_inpcb *inp;
7414 struct sctp_ifa *sctp_ifa;
7417 * Do the malloc first in case it blocks.
7419 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7422 sin->sin_family = AF_INET;
7423 sin->sin_len = sizeof(*sin);
7424 inp = (struct sctp_inpcb *)so->so_pcb;
7426 SCTP_FREE_SONAME(sin);
7427 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7428 return (ECONNRESET);
7430 SCTP_INP_RLOCK(inp);
7431 sin->sin_port = inp->sctp_lport;
7432 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7433 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7434 struct sctp_tcb *stcb;
7435 struct sockaddr_in *sin_a;
7436 struct sctp_nets *net;
7439 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7445 SCTP_TCB_LOCK(stcb);
7446 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7447 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7449 /* this will make coverity happy */
7452 if (sin_a->sin_family == AF_INET) {
7457 if ((!fnd) || (sin_a == NULL)) {
7459 SCTP_TCB_UNLOCK(stcb);
7463 vrf_id = inp->def_vrf_id;
7464 sctp_ifa = sctp_source_address_selection(inp,
7466 (sctp_route_t *)&net->ro,
7469 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7470 sctp_free_ifa(sctp_ifa);
7472 SCTP_TCB_UNLOCK(stcb);
7474 /* For the bound all case you get back 0 */
7476 sin->sin_addr.s_addr = 0;
7480 /* Take the first IPv4 address in the list */
7481 struct sctp_laddr *laddr;
7484 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7485 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7486 struct sockaddr_in *sin_a;
7488 sin_a = &laddr->ifa->address.sin;
7489 sin->sin_addr = sin_a->sin_addr;
7495 SCTP_FREE_SONAME(sin);
7496 SCTP_INP_RUNLOCK(inp);
7497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7501 SCTP_INP_RUNLOCK(inp);
7502 (*addr) = (struct sockaddr *)sin;
7507 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7509 struct sockaddr_in *sin;
7511 struct sockaddr_in *sin_a;
7512 struct sctp_inpcb *inp;
7513 struct sctp_tcb *stcb;
7514 struct sctp_nets *net;
7516 /* Do the malloc first in case it blocks. */
7517 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7520 sin->sin_family = AF_INET;
7521 sin->sin_len = sizeof(*sin);
7523 inp = (struct sctp_inpcb *)so->so_pcb;
7524 if ((inp == NULL) ||
7525 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7526 /* UDP type and listeners will drop out here */
7527 SCTP_FREE_SONAME(sin);
7528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7531 SCTP_INP_RLOCK(inp);
7532 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7534 SCTP_TCB_LOCK(stcb);
7536 SCTP_INP_RUNLOCK(inp);
7538 SCTP_FREE_SONAME(sin);
7539 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7540 return (ECONNRESET);
7543 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7544 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7545 if (sin_a->sin_family == AF_INET) {
7547 sin->sin_port = stcb->rport;
7548 sin->sin_addr = sin_a->sin_addr;
7552 SCTP_TCB_UNLOCK(stcb);
7554 /* No IPv4 address */
7555 SCTP_FREE_SONAME(sin);
7556 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7559 (*addr) = (struct sockaddr *)sin;
7563 struct pr_usrreqs sctp_usrreqs = {
7564 .pru_abort = sctp_abort,
7565 .pru_accept = sctp_accept,
7566 .pru_attach = sctp_attach,
7567 .pru_bind = sctp_bind,
7568 .pru_connect = sctp_connect,
7569 .pru_control = in_control,
7570 .pru_close = sctp_close,
7571 .pru_detach = sctp_close,
7572 .pru_sopoll = sopoll_generic,
7573 .pru_flush = sctp_flush,
7574 .pru_disconnect = sctp_disconnect,
7575 .pru_listen = sctp_listen,
7576 .pru_peeraddr = sctp_peeraddr,
7577 .pru_send = sctp_sendm,
7578 .pru_shutdown = sctp_shutdown,
7579 .pru_sockaddr = sctp_ingetaddr,
7580 .pru_sosend = sctp_sosend,
7581 .pru_soreceive = sctp_soreceive