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)
100 EVENTHANDLER_DEREGISTER(rt_addrmsg, SCTP_BASE_VAR(eh_tag));
104 VNET_SYSUNINIT(sctp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, sctp_finish, NULL);
108 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
110 struct sctp_tmit_chunk *chk;
113 /* Adjust that too */
114 stcb->asoc.smallest_mtu = nxtsz;
115 /* now off to subtract IP_DF flag if needed */
116 overhead = IP_HDR_SIZE + sizeof(struct sctphdr);
117 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
118 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
120 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
121 if ((chk->send_size + overhead) > nxtsz) {
122 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
125 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
126 if ((chk->send_size + overhead) > nxtsz) {
128 * For this guy we also mark for immediate resend
129 * since we sent to big of chunk
131 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
132 if (chk->sent < SCTP_DATAGRAM_RESEND) {
133 sctp_flight_size_decrease(chk);
134 sctp_total_flight_decrease(stcb, chk);
135 chk->sent = SCTP_DATAGRAM_RESEND;
136 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
137 chk->rec.data.doing_fast_retransmit = 0;
138 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
139 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
140 chk->whoTo->flight_size,
142 (uint32_t)(uintptr_t)chk->whoTo,
145 /* Clear any time so NO RTT is being done */
146 if (chk->do_rtt == 1) {
148 chk->whoTo->rto_needed = 1;
157 sctp_notify(struct sctp_inpcb *inp,
158 struct sctp_tcb *stcb,
159 struct sctp_nets *net,
167 if (icmp_type != ICMP_UNREACH) {
168 /* We only care about unreachable */
169 SCTP_TCB_UNLOCK(stcb);
172 if ((icmp_code == ICMP_UNREACH_NET) ||
173 (icmp_code == ICMP_UNREACH_HOST) ||
174 (icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
175 (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
176 (icmp_code == ICMP_UNREACH_ISOLATED) ||
177 (icmp_code == ICMP_UNREACH_NET_PROHIB) ||
178 (icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
179 (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
180 /* Mark the net unreachable. */
181 if (net->dest_state & SCTP_ADDR_REACHABLE) {
182 /* OK, that destination is NOT reachable. */
183 net->dest_state &= ~SCTP_ADDR_REACHABLE;
184 net->dest_state &= ~SCTP_ADDR_PF;
185 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
187 (void *)net, SCTP_SO_NOT_LOCKED);
189 SCTP_TCB_UNLOCK(stcb);
190 } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) ||
191 (icmp_code == ICMP_UNREACH_PORT)) {
192 /* Treat it like an ABORT. */
193 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
194 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
195 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
196 /* no need to unlock here, since the TCB is gone */
197 } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) {
198 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
199 SCTP_TCB_UNLOCK(stcb);
202 /* Find the next (smaller) MTU */
205 * Old type router that does not tell us what the
206 * next MTU is. Rats we will have to guess (in a
207 * educated fashion of course).
209 next_mtu = sctp_get_prev_mtu(ip_len);
211 /* Stop the PMTU timer. */
212 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
214 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
215 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
219 /* Update the path MTU. */
221 next_mtu -= sizeof(struct udphdr);
223 if (net->mtu > next_mtu) {
226 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu + sizeof(struct udphdr));
228 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu);
231 /* Update the association MTU */
232 if (stcb->asoc.smallest_mtu > next_mtu) {
233 sctp_pathmtu_adjustment(stcb, next_mtu);
235 /* Finally, start the PMTU timer if it was running before. */
237 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
239 SCTP_TCB_UNLOCK(stcb);
241 SCTP_TCB_UNLOCK(stcb);
246 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
252 struct sctp_inpcb *inp;
253 struct sctp_tcb *stcb;
254 struct sctp_nets *net;
255 struct sctp_init_chunk *ch;
256 struct sockaddr_in src, dst;
258 if (sa->sa_family != AF_INET ||
259 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
262 if (PRC_IS_REDIRECT(cmd)) {
264 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
268 inner_ip = (struct ip *)vip;
269 icmp = (struct icmp *)((caddr_t)inner_ip -
270 (sizeof(struct icmp) - sizeof(struct ip)));
271 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
272 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
273 memset(&src, 0, sizeof(struct sockaddr_in));
274 src.sin_family = AF_INET;
275 src.sin_len = sizeof(struct sockaddr_in);
276 src.sin_port = sh->src_port;
277 src.sin_addr = inner_ip->ip_src;
278 memset(&dst, 0, sizeof(struct sockaddr_in));
279 dst.sin_family = AF_INET;
280 dst.sin_len = sizeof(struct sockaddr_in);
281 dst.sin_port = sh->dest_port;
282 dst.sin_addr = inner_ip->ip_dst;
284 * 'dst' holds the dest of the packet that failed to be
285 * sent. 'src' holds our local endpoint address. Thus we
286 * reverse the dst and the src in the lookup.
290 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
291 (struct sockaddr *)&src,
294 if ((stcb != NULL) &&
297 /* Check the verification tag */
298 if (ntohl(sh->v_tag) != 0) {
300 * This must be the verification tag used
301 * for sending out packets. We don't
302 * consider packets reflecting the
305 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
306 SCTP_TCB_UNLOCK(stcb);
310 if (ntohs(outer_ip->ip_len) >=
312 8 + (inner_ip->ip_hl << 2) + 20) {
314 * In this case we can check if we
315 * got an INIT chunk and if the
316 * initiate tag matches.
318 ch = (struct sctp_init_chunk *)(sh + 1);
319 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
320 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
321 SCTP_TCB_UNLOCK(stcb);
325 SCTP_TCB_UNLOCK(stcb);
329 sctp_notify(inp, stcb, net,
332 ntohs(inner_ip->ip_len),
333 (uint32_t)ntohs(icmp->icmp_nextmtu));
335 if ((stcb == NULL) && (inp != NULL)) {
336 /* reduce ref-count */
338 SCTP_INP_DECR_REF(inp);
339 SCTP_INP_WUNLOCK(inp);
342 SCTP_TCB_UNLOCK(stcb);
351 sctp_getcred(SYSCTL_HANDLER_ARGS)
354 struct sockaddr_in addrs[2];
355 struct sctp_inpcb *inp;
356 struct sctp_nets *net;
357 struct sctp_tcb *stcb;
361 /* FIX, for non-bsd is this right? */
362 vrf_id = SCTP_DEFAULT_VRFID;
364 error = priv_check(req->td, PRIV_NETINET_GETCRED);
369 error = SYSCTL_IN(req, addrs, sizeof(addrs));
373 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
375 &inp, &net, 1, vrf_id);
376 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
377 if ((inp != NULL) && (stcb == NULL)) {
378 /* reduce ref-count */
380 SCTP_INP_DECR_REF(inp);
384 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
388 SCTP_TCB_UNLOCK(stcb);
390 * We use the write lock here, only since in the error leg we need
391 * it. If we used RLOCK, then we would have to
392 * wlock/decr/unlock/rlock. Which in theory could create a hole.
393 * Better to use higher wlock.
397 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
399 SCTP_INP_WUNLOCK(inp);
402 cru2x(inp->sctp_socket->so_cred, &xuc);
403 SCTP_INP_WUNLOCK(inp);
404 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
409 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
410 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
415 sctp_abort(struct socket *so)
417 struct sctp_inpcb *inp;
420 inp = (struct sctp_inpcb *)so->so_pcb;
426 flags = inp->sctp_flags;
427 #ifdef SCTP_LOG_CLOSING
428 sctp_log_closing(inp, NULL, 17);
430 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
431 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
432 #ifdef SCTP_LOG_CLOSING
433 sctp_log_closing(inp, NULL, 16);
435 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
436 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
438 SCTP_SB_CLEAR(so->so_snd);
440 * same for the rcv ones, they are only here for the
443 SCTP_SB_CLEAR(so->so_rcv);
445 /* Now null out the reference, we are completely detached. */
449 flags = inp->sctp_flags;
450 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
451 goto sctp_must_try_again;
458 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
460 struct sctp_inpcb *inp;
461 struct inpcb *ip_inp;
463 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
465 inp = (struct sctp_inpcb *)so->so_pcb;
467 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
470 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
471 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
476 error = sctp_inpcb_alloc(so, vrf_id);
480 inp = (struct sctp_inpcb *)so->so_pcb;
482 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
483 ip_inp = &inp->ip_inp.inp;
484 ip_inp->inp_vflag |= INP_IPV4;
485 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
486 SCTP_INP_WUNLOCK(inp);
491 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
493 struct sctp_inpcb *inp;
495 inp = (struct sctp_inpcb *)so->so_pcb;
497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
501 if ((addr->sa_family != AF_INET) ||
502 (addr->sa_len != sizeof(struct sockaddr_in))) {
503 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
507 return (sctp_inpcb_bind(so, addr, NULL, p));
512 sctp_close(struct socket *so)
514 struct sctp_inpcb *inp;
517 inp = (struct sctp_inpcb *)so->so_pcb;
522 * Inform all the lower layer assoc that we are done.
525 flags = inp->sctp_flags;
526 #ifdef SCTP_LOG_CLOSING
527 sctp_log_closing(inp, NULL, 17);
529 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
530 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
531 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
532 (so->so_rcv.sb_cc > 0)) {
533 #ifdef SCTP_LOG_CLOSING
534 sctp_log_closing(inp, NULL, 13);
536 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
537 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
539 #ifdef SCTP_LOG_CLOSING
540 sctp_log_closing(inp, NULL, 14);
542 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
543 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
546 * The socket is now detached, no matter what the state of
547 * the SCTP association.
550 SCTP_SB_CLEAR(so->so_snd);
552 * same for the rcv ones, they are only here for the
555 SCTP_SB_CLEAR(so->so_rcv);
557 /* Now null out the reference, we are completely detached. */
561 flags = inp->sctp_flags;
562 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
563 goto sctp_must_try_again;
571 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
572 struct mbuf *control, struct thread *p);
576 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
577 struct mbuf *control, struct thread *p)
579 struct sctp_inpcb *inp;
582 inp = (struct sctp_inpcb *)so->so_pcb;
585 sctp_m_freem(control);
588 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
592 /* Got to have an to address if we are NOT a connected socket */
593 if ((addr == NULL) &&
594 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
595 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
597 } else if (addr == NULL) {
598 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
599 error = EDESTADDRREQ;
602 sctp_m_freem(control);
608 if (addr->sa_family != AF_INET) {
609 /* must be a v4 address! */
610 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
613 sctp_m_freem(control);
616 error = EDESTADDRREQ;
621 /* now what about control */
624 sctp_m_freem(inp->control);
627 inp->control = control;
631 SCTP_BUF_NEXT(inp->pkt_last) = m;
634 inp->pkt_last = inp->pkt = m;
637 /* FreeBSD uses a flag passed */
638 ((flags & PRUS_MORETOCOME) == 0)
641 * note with the current version this code will only be used
642 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
643 * re-defining sosend to use the sctp_sosend. One can
644 * optionally switch back to this code (by changing back the
645 * definitions) but this is not advisable. This code is used
646 * by FreeBSD when sending a file with sendfile() though.
650 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
660 sctp_disconnect(struct socket *so)
662 struct sctp_inpcb *inp;
664 inp = (struct sctp_inpcb *)so->so_pcb;
666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
670 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
671 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
672 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
674 SCTP_INP_RUNLOCK(inp);
677 struct sctp_association *asoc;
678 struct sctp_tcb *stcb;
680 stcb = LIST_FIRST(&inp->sctp_asoc_list);
682 SCTP_INP_RUNLOCK(inp);
683 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
688 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
689 /* We are about to be freed, out of here */
690 SCTP_TCB_UNLOCK(stcb);
691 SCTP_INP_RUNLOCK(inp);
694 if (((so->so_options & SO_LINGER) &&
695 (so->so_linger == 0)) ||
696 (so->so_rcv.sb_cc > 0)) {
697 if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) {
698 /* Left with Data unread */
701 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
702 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
703 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
705 SCTP_INP_RUNLOCK(inp);
706 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
707 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
708 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
710 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
711 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
712 /* No unlock tcb assoc is gone */
715 if (TAILQ_EMPTY(&asoc->send_queue) &&
716 TAILQ_EMPTY(&asoc->sent_queue) &&
717 (asoc->stream_queue_cnt == 0)) {
718 /* there is nothing queued to send, so done */
719 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
722 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) &&
723 (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
724 /* only send SHUTDOWN 1st time thru */
725 struct sctp_nets *netp;
727 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
728 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
729 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
731 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
732 sctp_stop_timers_for_shutdown(stcb);
733 if (stcb->asoc.alternate) {
734 netp = stcb->asoc.alternate;
736 netp = stcb->asoc.primary_destination;
738 sctp_send_shutdown(stcb, netp);
739 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
740 stcb->sctp_ep, stcb, netp);
741 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
742 stcb->sctp_ep, stcb, NULL);
743 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
747 * we still got (or just got) data to send,
748 * so set SHUTDOWN_PENDING
751 * XXX sockets draft says that SCTP_EOF
752 * should be sent with no data. currently,
753 * we will allow user data to be sent first
754 * and move to SHUTDOWN-PENDING
756 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
757 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
758 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
759 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
761 if (TAILQ_EMPTY(&asoc->send_queue) &&
762 TAILQ_EMPTY(&asoc->sent_queue) &&
763 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
767 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
768 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
769 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
770 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
771 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
772 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
773 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
775 SCTP_INP_RUNLOCK(inp);
776 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
777 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
780 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
783 soisdisconnecting(so);
784 SCTP_TCB_UNLOCK(stcb);
785 SCTP_INP_RUNLOCK(inp);
790 /* UDP model does not support this */
791 SCTP_INP_RUNLOCK(inp);
792 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
798 sctp_flush(struct socket *so, int how)
801 * We will just clear out the values and let subsequent close clear
802 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
803 * they will not be able to read the data, the socket will block
804 * that from happening.
806 struct sctp_inpcb *inp;
808 inp = (struct sctp_inpcb *)so->so_pcb;
810 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
814 /* For the 1 to many model this does nothing */
815 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
816 SCTP_INP_RUNLOCK(inp);
819 SCTP_INP_RUNLOCK(inp);
820 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
822 * First make sure the sb will be happy, we don't use these
823 * except maybe the count
826 SCTP_INP_READ_LOCK(inp);
827 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
828 SCTP_INP_READ_UNLOCK(inp);
829 SCTP_INP_WUNLOCK(inp);
830 so->so_rcv.sb_cc = 0;
831 so->so_rcv.sb_mbcnt = 0;
832 so->so_rcv.sb_mb = NULL;
834 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
836 * First make sure the sb will be happy, we don't use these
837 * except maybe the count
839 so->so_snd.sb_cc = 0;
840 so->so_snd.sb_mbcnt = 0;
841 so->so_snd.sb_mb = NULL;
848 sctp_shutdown(struct socket *so)
850 struct sctp_inpcb *inp;
852 inp = (struct sctp_inpcb *)so->so_pcb;
854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
858 /* For UDP model this is a invalid call */
859 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
860 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
861 /* Restore the flags that the soshutdown took away. */
862 SOCKBUF_LOCK(&so->so_rcv);
863 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
864 SOCKBUF_UNLOCK(&so->so_rcv);
865 /* This proc will wakeup for read and do nothing (I hope) */
866 SCTP_INP_RUNLOCK(inp);
867 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
871 * Ok, if we reach here its the TCP model and it is either a
872 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
875 struct sctp_tcb *stcb;
876 struct sctp_association *asoc;
877 struct sctp_nets *netp;
880 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
881 SCTP_INP_RUNLOCK(inp);
886 stcb = LIST_FIRST(&inp->sctp_asoc_list);
889 * Ok, we hit the case that the shutdown call was
890 * made after an abort or something. Nothing to do
893 SCTP_INP_RUNLOCK(inp);
898 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
899 SCTP_TCB_UNLOCK(stcb);
900 SCTP_INP_RUNLOCK(inp);
903 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) &&
904 (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) &&
905 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) {
907 * If we are not in or before ESTABLISHED, there is
908 * no protocol action required.
910 SCTP_TCB_UNLOCK(stcb);
911 SCTP_INP_RUNLOCK(inp);
914 if (stcb->asoc.alternate) {
915 netp = stcb->asoc.alternate;
917 netp = stcb->asoc.primary_destination;
919 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) &&
920 TAILQ_EMPTY(&asoc->send_queue) &&
921 TAILQ_EMPTY(&asoc->sent_queue) &&
922 (asoc->stream_queue_cnt == 0)) {
923 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
926 /* there is nothing queued to send, so I'm done... */
927 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
928 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
929 sctp_stop_timers_for_shutdown(stcb);
930 sctp_send_shutdown(stcb, netp);
931 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
932 stcb->sctp_ep, stcb, netp);
935 * We still got (or just got) data to send, so set
938 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
939 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
940 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
942 if (TAILQ_EMPTY(&asoc->send_queue) &&
943 TAILQ_EMPTY(&asoc->sent_queue) &&
944 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
948 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
949 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
950 SCTP_INP_RUNLOCK(inp);
951 sctp_abort_an_association(stcb->sctp_ep, stcb,
952 op_err, SCTP_SO_LOCKED);
956 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
958 * XXX: Why do this in the case where we have still data
961 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
962 SCTP_TCB_UNLOCK(stcb);
963 SCTP_INP_RUNLOCK(inp);
969 * copies a "user" presentable address and removes embedded scope, etc.
970 * returns 0 on success, 1 on error
973 sctp_fill_user_address(union sctp_sockstore *ss, struct sockaddr *sa)
976 struct sockaddr_in6 lsa6;
978 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
981 memcpy(ss, sa, sa->sa_len);
988 * NOTE: assumes addr lock is held
991 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
992 struct sctp_tcb *stcb,
994 union sctp_sockstore *addr,
997 struct sctp_ifn *sctp_ifn;
998 struct sctp_ifa *sctp_ifa;
1002 int ipv4_local_scope, ipv4_addr_legal;
1005 int local_scope, site_scope, ipv6_addr_legal;
1007 struct sctp_vrf *vrf;
1014 /* Turn on all the appropriate scope */
1015 loopback_scope = stcb->asoc.scope.loopback_scope;
1017 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1018 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1021 local_scope = stcb->asoc.scope.local_scope;
1022 site_scope = stcb->asoc.scope.site_scope;
1023 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1026 /* Use generic values for endpoints. */
1029 ipv4_local_scope = 1;
1035 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1037 ipv6_addr_legal = 1;
1040 if (SCTP_IPV6_V6ONLY(inp)) {
1041 ipv4_addr_legal = 0;
1043 ipv4_addr_legal = 1;
1048 ipv6_addr_legal = 0;
1051 ipv4_addr_legal = 1;
1055 vrf = sctp_find_vrf(vrf_id);
1059 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1060 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1061 if ((loopback_scope == 0) &&
1062 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1063 /* Skip loopback if loopback_scope not set */
1066 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1069 * For the BOUND-ALL case, the list
1070 * associated with a TCB is Always
1071 * considered a reverse list.. i.e.
1072 * it lists addresses that are NOT
1073 * part of the association. If this
1074 * is one of those we must skip it.
1076 if (sctp_is_addr_restricted(stcb,
1081 switch (sctp_ifa->address.sa.sa_family) {
1084 if (ipv4_addr_legal) {
1085 struct sockaddr_in *sin;
1087 sin = &sctp_ifa->address.sin;
1088 if (sin->sin_addr.s_addr == 0) {
1096 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1097 &sin->sin_addr) != 0) {
1100 if ((ipv4_local_scope == 0) &&
1101 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1105 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1106 if (actual + sizeof(struct sockaddr_in6) > limit) {
1109 in6_sin_2_v4mapsin6(sin, &addr->sin6);
1110 addr->sin6.sin6_port = inp->sctp_lport;
1111 addr = (union sctp_sockstore *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1112 actual += sizeof(struct sockaddr_in6);
1115 if (actual + sizeof(struct sockaddr_in) > limit) {
1118 memcpy(addr, sin, sizeof(struct sockaddr_in));
1119 addr->sin.sin_port = inp->sctp_lport;
1120 addr = (union sctp_sockstore *)((caddr_t)addr + sizeof(struct sockaddr_in));
1121 actual += sizeof(struct sockaddr_in);
1132 if (ipv6_addr_legal) {
1133 struct sockaddr_in6 *sin6;
1135 sin6 = &sctp_ifa->address.sin6;
1136 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1144 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1145 &sin6->sin6_addr) != 0) {
1148 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1149 if (local_scope == 0)
1151 if (sin6->sin6_scope_id == 0) {
1152 if (sa6_recoverscope(sin6) != 0)
1165 if ((site_scope == 0) &&
1166 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1169 if (actual + sizeof(struct sockaddr_in6) > limit) {
1172 memcpy(addr, sin6, sizeof(struct sockaddr_in6));
1173 addr->sin6.sin6_port = inp->sctp_lport;
1174 addr = (union sctp_sockstore *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1175 actual += sizeof(struct sockaddr_in6);
1188 struct sctp_laddr *laddr;
1191 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1193 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1197 sa_len = laddr->ifa->address.sa.sa_len;
1198 if (actual + sa_len > limit) {
1201 if (sctp_fill_user_address(addr, &laddr->ifa->address.sa))
1203 switch (laddr->ifa->address.sa.sa_family) {
1206 addr->sin.sin_port = inp->sctp_lport;
1211 addr->sin6.sin6_port = inp->sctp_lport;
1218 addr = (union sctp_sockstore *)((caddr_t)addr + sa_len);
1226 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1227 struct sctp_tcb *stcb,
1229 union sctp_sockstore *addr)
1233 SCTP_IPI_ADDR_RLOCK();
1234 /* fill up addresses for the endpoint's default vrf */
1235 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, addr,
1237 SCTP_IPI_ADDR_RUNLOCK();
1242 * NOTE: assumes addr lock is held
1245 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1248 struct sctp_vrf *vrf = NULL;
1251 * In both sub-set bound an bound_all cases we return the MAXIMUM
1252 * number of addresses that you COULD get. In reality the sub-set
1253 * bound may have an exclusion list for a given TCB OR in the
1254 * bound-all case a TCB may NOT include the loopback or other
1255 * addresses as well.
1257 vrf = sctp_find_vrf(vrf_id);
1261 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1262 struct sctp_ifn *sctp_ifn;
1263 struct sctp_ifa *sctp_ifa;
1265 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1266 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1267 /* Count them if they are the right type */
1268 switch (sctp_ifa->address.sa.sa_family) {
1272 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1273 cnt += sizeof(struct sockaddr_in6);
1275 cnt += sizeof(struct sockaddr_in);
1277 cnt += sizeof(struct sockaddr_in);
1283 cnt += sizeof(struct sockaddr_in6);
1292 struct sctp_laddr *laddr;
1294 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1295 switch (laddr->ifa->address.sa.sa_family) {
1299 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1300 cnt += sizeof(struct sockaddr_in6);
1302 cnt += sizeof(struct sockaddr_in);
1304 cnt += sizeof(struct sockaddr_in);
1310 cnt += sizeof(struct sockaddr_in6);
1322 sctp_count_max_addresses(struct sctp_inpcb *inp)
1326 SCTP_IPI_ADDR_RLOCK();
1327 /* count addresses for the endpoint's default VRF */
1328 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1329 SCTP_IPI_ADDR_RUNLOCK();
1334 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1335 size_t optsize, void *p, int delay)
1338 int creat_lock_on = 0;
1339 struct sctp_tcb *stcb = NULL;
1340 struct sockaddr *sa;
1341 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1345 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1347 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1348 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1349 /* We are already connected AND the TCP model */
1350 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1351 return (EADDRINUSE);
1354 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1355 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1356 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1360 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1361 SCTP_INP_RLOCK(inp);
1362 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1363 SCTP_INP_RUNLOCK(inp);
1366 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1369 SCTP_INP_INCR_REF(inp);
1370 SCTP_ASOC_CREATE_LOCK(inp);
1372 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1373 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1374 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1378 totaddrp = (unsigned int *)optval;
1379 totaddr = *totaddrp;
1380 sa = (struct sockaddr *)(totaddrp + 1);
1381 error = sctp_connectx_helper_find(inp, sa, totaddr, &num_v4, &num_v6, (unsigned int)(optsize - sizeof(int)));
1383 /* Already have or am bring up an association */
1384 SCTP_ASOC_CREATE_UNLOCK(inp);
1386 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1390 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1395 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1397 if (SCTP_IPV6_V6ONLY(inp)) {
1399 * if IPV6_V6ONLY flag, ignore connections destined
1400 * to a v4 addr or v4-mapped addr
1402 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1408 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1409 SCTP_PCB_FLAGS_UNBOUND) {
1410 /* Bind a ephemeral port */
1411 error = sctp_inpcb_bind(so, NULL, NULL, p);
1417 /* FIX ME: do we want to pass in a vrf on the connect call? */
1418 vrf_id = inp->def_vrf_id;
1421 /* We are GOOD to go */
1422 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1423 inp->sctp_ep.pre_open_stream_count,
1426 SCTP_INITIALIZE_AUTH_PARAMS);
1428 /* Gak! no memory */
1431 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1432 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1433 /* Set the connected flag so we can queue data */
1436 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1437 /* move to second address */
1438 switch (sa->sa_family) {
1441 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1446 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1454 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1455 /* Fill in the return id */
1459 a_id = (sctp_assoc_t *)optval;
1460 *a_id = sctp_get_associd(stcb);
1463 /* doing delayed connection */
1464 stcb->asoc.delayed_connection = 1;
1465 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1467 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1468 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1470 SCTP_TCB_UNLOCK(stcb);
1472 if (creat_lock_on) {
1473 SCTP_ASOC_CREATE_UNLOCK(inp);
1475 SCTP_INP_DECR_REF(inp);
1479 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1480 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1481 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1482 SCTP_INP_RLOCK(inp); \
1483 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1485 SCTP_TCB_LOCK(stcb); \
1487 SCTP_INP_RUNLOCK(inp); \
1488 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1489 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1490 if (stcb == NULL) { \
1491 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1501 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1502 if (size < sizeof(type)) { \
1503 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1507 destp = (type *)srcp; \
1512 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1515 struct sctp_inpcb *inp = NULL;
1517 struct sctp_tcb *stcb = NULL;
1519 if (optval == NULL) {
1520 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1524 inp = (struct sctp_inpcb *)so->so_pcb;
1526 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1533 case SCTP_AUTOCLOSE:
1534 case SCTP_EXPLICIT_EOR:
1535 case SCTP_AUTO_ASCONF:
1536 case SCTP_DISABLE_FRAGMENTS:
1537 case SCTP_I_WANT_MAPPED_V4_ADDR:
1538 case SCTP_USE_EXT_RCVINFO:
1539 SCTP_INP_RLOCK(inp);
1541 case SCTP_DISABLE_FRAGMENTS:
1542 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1544 case SCTP_I_WANT_MAPPED_V4_ADDR:
1545 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1547 case SCTP_AUTO_ASCONF:
1548 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1549 /* only valid for bound all sockets */
1550 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1552 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1557 case SCTP_EXPLICIT_EOR:
1558 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1561 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1563 case SCTP_USE_EXT_RCVINFO:
1564 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1566 case SCTP_AUTOCLOSE:
1567 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1568 val = sctp_ticks_to_secs(inp->sctp_ep.auto_close_time);
1574 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1575 error = ENOPROTOOPT;
1576 } /* end switch (sopt->sopt_name) */
1577 if (*optsize < sizeof(val)) {
1578 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1582 SCTP_INP_RUNLOCK(inp);
1584 /* return the option value */
1585 *(int *)optval = val;
1586 *optsize = sizeof(val);
1589 case SCTP_GET_PACKET_LOG:
1591 #ifdef SCTP_PACKET_LOGGING
1595 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1596 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1599 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1604 case SCTP_REUSE_PORT:
1608 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1609 /* Can't do this for a 1-m socket */
1613 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1614 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1615 *optsize = sizeof(uint32_t);
1618 case SCTP_PARTIAL_DELIVERY_POINT:
1622 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1623 *value = inp->partial_delivery_point;
1624 *optsize = sizeof(uint32_t);
1627 case SCTP_FRAGMENT_INTERLEAVE:
1631 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1632 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1633 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1634 *value = SCTP_FRAG_LEVEL_2;
1636 *value = SCTP_FRAG_LEVEL_1;
1639 *value = SCTP_FRAG_LEVEL_0;
1641 *optsize = sizeof(uint32_t);
1644 case SCTP_INTERLEAVING_SUPPORTED:
1646 struct sctp_assoc_value *av;
1648 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1649 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1652 av->assoc_value = stcb->asoc.idata_supported;
1653 SCTP_TCB_UNLOCK(stcb);
1655 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1656 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1657 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1658 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1659 SCTP_INP_RLOCK(inp);
1660 if (inp->idata_supported) {
1661 av->assoc_value = 1;
1663 av->assoc_value = 0;
1665 SCTP_INP_RUNLOCK(inp);
1667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1672 *optsize = sizeof(struct sctp_assoc_value);
1676 case SCTP_CMT_ON_OFF:
1678 struct sctp_assoc_value *av;
1680 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1681 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1683 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1684 SCTP_TCB_UNLOCK(stcb);
1686 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1687 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1688 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1689 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1690 SCTP_INP_RLOCK(inp);
1691 av->assoc_value = inp->sctp_cmt_on_off;
1692 SCTP_INP_RUNLOCK(inp);
1694 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1699 *optsize = sizeof(struct sctp_assoc_value);
1703 case SCTP_PLUGGABLE_CC:
1705 struct sctp_assoc_value *av;
1707 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1708 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1710 av->assoc_value = stcb->asoc.congestion_control_module;
1711 SCTP_TCB_UNLOCK(stcb);
1713 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1714 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1715 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1716 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1717 SCTP_INP_RLOCK(inp);
1718 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1719 SCTP_INP_RUNLOCK(inp);
1721 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1726 *optsize = sizeof(struct sctp_assoc_value);
1730 case SCTP_CC_OPTION:
1732 struct sctp_cc_option *cc_opt;
1734 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1735 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1739 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1742 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1743 *optsize = sizeof(struct sctp_cc_option);
1745 SCTP_TCB_UNLOCK(stcb);
1749 case SCTP_PLUGGABLE_SS:
1751 struct sctp_assoc_value *av;
1753 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1754 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1756 av->assoc_value = stcb->asoc.stream_scheduling_module;
1757 SCTP_TCB_UNLOCK(stcb);
1759 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1760 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1761 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1762 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1763 SCTP_INP_RLOCK(inp);
1764 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1765 SCTP_INP_RUNLOCK(inp);
1767 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1772 *optsize = sizeof(struct sctp_assoc_value);
1778 struct sctp_stream_value *av;
1780 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1781 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1783 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1784 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1785 &av->stream_value) < 0)) {
1786 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1789 *optsize = sizeof(struct sctp_stream_value);
1791 SCTP_TCB_UNLOCK(stcb);
1794 * Can't get stream value without
1797 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1802 case SCTP_GET_ADDR_LEN:
1804 struct sctp_assoc_value *av;
1806 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1809 if (av->assoc_value == AF_INET) {
1810 av->assoc_value = sizeof(struct sockaddr_in);
1815 if (av->assoc_value == AF_INET6) {
1816 av->assoc_value = sizeof(struct sockaddr_in6);
1821 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1823 *optsize = sizeof(struct sctp_assoc_value);
1827 case SCTP_GET_ASSOC_NUMBER:
1829 uint32_t *value, cnt;
1831 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1832 SCTP_INP_RLOCK(inp);
1833 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1834 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1835 /* Can't do this for a 1-1 socket */
1837 SCTP_INP_RUNLOCK(inp);
1841 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1844 SCTP_INP_RUNLOCK(inp);
1846 *optsize = sizeof(uint32_t);
1849 case SCTP_GET_ASSOC_ID_LIST:
1851 struct sctp_assoc_ids *ids;
1855 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1856 SCTP_INP_RLOCK(inp);
1857 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1858 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1859 /* Can't do this for a 1-1 socket */
1861 SCTP_INP_RUNLOCK(inp);
1865 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1866 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1868 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1871 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1880 SCTP_INP_RUNLOCK(inp);
1882 ids->gaids_number_of_ids = at;
1883 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1889 struct sctp_assoc_value *av;
1891 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1892 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1895 av->assoc_value = stcb->asoc.context;
1896 SCTP_TCB_UNLOCK(stcb);
1898 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1899 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1900 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1901 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1902 SCTP_INP_RLOCK(inp);
1903 av->assoc_value = inp->sctp_context;
1904 SCTP_INP_RUNLOCK(inp);
1906 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1911 *optsize = sizeof(struct sctp_assoc_value);
1917 uint32_t *default_vrfid;
1919 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1920 *default_vrfid = inp->def_vrf_id;
1921 *optsize = sizeof(uint32_t);
1924 case SCTP_GET_ASOC_VRF:
1926 struct sctp_assoc_value *id;
1928 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1929 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1932 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1934 id->assoc_value = stcb->asoc.vrf_id;
1935 SCTP_TCB_UNLOCK(stcb);
1936 *optsize = sizeof(struct sctp_assoc_value);
1940 case SCTP_GET_VRF_IDS:
1942 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1946 case SCTP_GET_NONCE_VALUES:
1948 struct sctp_get_nonce_values *gnv;
1950 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1951 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1954 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1955 gnv->gn_local_tag = stcb->asoc.my_vtag;
1956 SCTP_TCB_UNLOCK(stcb);
1957 *optsize = sizeof(struct sctp_get_nonce_values);
1959 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1964 case SCTP_DELAYED_SACK:
1966 struct sctp_sack_info *sack;
1968 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1969 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1971 sack->sack_delay = stcb->asoc.delayed_ack;
1972 sack->sack_freq = stcb->asoc.sack_freq;
1973 SCTP_TCB_UNLOCK(stcb);
1975 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1976 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1977 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1978 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC))) {
1979 SCTP_INP_RLOCK(inp);
1980 sack->sack_delay = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1981 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
1982 SCTP_INP_RUNLOCK(inp);
1984 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1989 *optsize = sizeof(struct sctp_sack_info);
1993 case SCTP_GET_SNDBUF_USE:
1995 struct sctp_sockstat *ss;
1997 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
1998 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2001 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2002 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2003 stcb->asoc.size_on_all_streams);
2004 SCTP_TCB_UNLOCK(stcb);
2005 *optsize = sizeof(struct sctp_sockstat);
2007 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2012 case SCTP_MAX_BURST:
2014 struct sctp_assoc_value *av;
2016 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2017 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2020 av->assoc_value = stcb->asoc.max_burst;
2021 SCTP_TCB_UNLOCK(stcb);
2023 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2024 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2025 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2026 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2027 SCTP_INP_RLOCK(inp);
2028 av->assoc_value = inp->sctp_ep.max_burst;
2029 SCTP_INP_RUNLOCK(inp);
2031 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2036 *optsize = sizeof(struct sctp_assoc_value);
2042 struct sctp_assoc_value *av;
2045 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2046 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2049 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2050 SCTP_TCB_UNLOCK(stcb);
2052 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2053 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2054 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2055 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2056 SCTP_INP_RLOCK(inp);
2057 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2058 ovh = SCTP_MED_OVERHEAD;
2060 ovh = SCTP_MED_V4_OVERHEAD;
2062 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2063 av->assoc_value = 0;
2065 av->assoc_value = inp->sctp_frag_point - ovh;
2066 SCTP_INP_RUNLOCK(inp);
2068 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2073 *optsize = sizeof(struct sctp_assoc_value);
2077 case SCTP_GET_STAT_LOG:
2078 error = sctp_fill_stat_log(optval, optsize);
2082 struct sctp_event_subscribe *events;
2084 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2085 memset(events, 0, sizeof(struct sctp_event_subscribe));
2086 SCTP_INP_RLOCK(inp);
2087 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2088 events->sctp_data_io_event = 1;
2090 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2091 events->sctp_association_event = 1;
2093 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2094 events->sctp_address_event = 1;
2096 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2097 events->sctp_send_failure_event = 1;
2099 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2100 events->sctp_peer_error_event = 1;
2102 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2103 events->sctp_shutdown_event = 1;
2105 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2106 events->sctp_partial_delivery_event = 1;
2108 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2109 events->sctp_adaptation_layer_event = 1;
2111 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2112 events->sctp_authentication_event = 1;
2114 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2115 events->sctp_sender_dry_event = 1;
2117 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2118 events->sctp_stream_reset_event = 1;
2119 SCTP_INP_RUNLOCK(inp);
2120 *optsize = sizeof(struct sctp_event_subscribe);
2123 case SCTP_ADAPTATION_LAYER:
2127 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2129 SCTP_INP_RLOCK(inp);
2130 *value = inp->sctp_ep.adaptation_layer_indicator;
2131 SCTP_INP_RUNLOCK(inp);
2132 *optsize = sizeof(uint32_t);
2135 case SCTP_SET_INITIAL_DBG_SEQ:
2139 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2140 SCTP_INP_RLOCK(inp);
2141 *value = inp->sctp_ep.initial_sequence_debug;
2142 SCTP_INP_RUNLOCK(inp);
2143 *optsize = sizeof(uint32_t);
2146 case SCTP_GET_LOCAL_ADDR_SIZE:
2150 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2151 SCTP_INP_RLOCK(inp);
2152 *value = sctp_count_max_addresses(inp);
2153 SCTP_INP_RUNLOCK(inp);
2154 *optsize = sizeof(uint32_t);
2157 case SCTP_GET_REMOTE_ADDR_SIZE:
2161 struct sctp_nets *net;
2163 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2164 /* FIXME MT: change to sctp_assoc_value? */
2165 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2169 /* Count the sizes */
2170 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2171 switch (net->ro._l_addr.sa.sa_family) {
2175 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2176 size += sizeof(struct sockaddr_in6);
2178 size += sizeof(struct sockaddr_in);
2181 size += sizeof(struct sockaddr_in);
2187 size += sizeof(struct sockaddr_in6);
2194 SCTP_TCB_UNLOCK(stcb);
2195 *value = (uint32_t)size;
2196 *optsize = sizeof(uint32_t);
2198 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2203 case SCTP_GET_PEER_ADDRESSES:
2205 * Get the address information, an array is passed in to
2206 * fill up we pack it.
2210 union sctp_sockstore *addr;
2211 struct sctp_nets *net;
2212 struct sctp_getaddresses *saddr;
2214 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2215 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2218 left = *optsize - offsetof(struct sctp_getaddresses, addr);
2219 *optsize = offsetof(struct sctp_getaddresses, addr);
2220 addr = &saddr->addr[0];
2222 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2223 switch (net->ro._l_addr.sa.sa_family) {
2227 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2228 cpsz = sizeof(struct sockaddr_in6);
2230 cpsz = sizeof(struct sockaddr_in);
2233 cpsz = sizeof(struct sockaddr_in);
2239 cpsz = sizeof(struct sockaddr_in6);
2250 /* not enough room. */
2253 #if defined(INET) && defined(INET6)
2254 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2255 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2256 /* Must map the address */
2257 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2260 memcpy(addr, &net->ro._l_addr, cpsz);
2263 memcpy(addr, &net->ro._l_addr, cpsz);
2265 addr->sin.sin_port = stcb->rport;
2267 addr = (union sctp_sockstore *)((caddr_t)addr + cpsz);
2271 SCTP_TCB_UNLOCK(stcb);
2273 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2278 case SCTP_GET_LOCAL_ADDRESSES:
2280 size_t limit, actual;
2281 struct sctp_getaddresses *saddr;
2283 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2284 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2286 limit = *optsize - offsetof(struct sctp_getaddresses, addr);
2287 actual = sctp_fill_up_addresses(inp, stcb, limit, saddr->addr);
2289 SCTP_TCB_UNLOCK(stcb);
2291 *optsize = offsetof(struct sctp_getaddresses, addr) + actual;
2294 case SCTP_PEER_ADDR_PARAMS:
2296 struct sctp_paddrparams *paddrp;
2297 struct sctp_nets *net;
2298 struct sockaddr *addr;
2299 #if defined(INET) && defined(INET6)
2300 struct sockaddr_in sin_store;
2303 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2304 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2306 #if defined(INET) && defined(INET6)
2307 if (paddrp->spp_address.ss_family == AF_INET6) {
2308 struct sockaddr_in6 *sin6;
2310 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2311 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2312 in6_sin6_2_sin(&sin_store, sin6);
2313 addr = (struct sockaddr *)&sin_store;
2315 addr = (struct sockaddr *)&paddrp->spp_address;
2318 addr = (struct sockaddr *)&paddrp->spp_address;
2321 addr = (struct sockaddr *)&paddrp->spp_address;
2324 net = sctp_findnet(stcb, addr);
2327 * We increment here since
2328 * sctp_findassociation_ep_addr() wil do a
2329 * decrement if it finds the stcb as long as
2330 * the locked tcb (last argument) is NOT a
2334 SCTP_INP_INCR_REF(inp);
2335 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2337 SCTP_INP_DECR_REF(inp);
2340 if ((stcb != NULL) && (net == NULL)) {
2342 if (addr->sa_family == AF_INET) {
2343 struct sockaddr_in *sin;
2345 sin = (struct sockaddr_in *)addr;
2346 if (sin->sin_addr.s_addr != INADDR_ANY) {
2348 SCTP_TCB_UNLOCK(stcb);
2349 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2355 if (addr->sa_family == AF_INET6) {
2356 struct sockaddr_in6 *sin6;
2358 sin6 = (struct sockaddr_in6 *)addr;
2359 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2361 SCTP_TCB_UNLOCK(stcb);
2362 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2368 error = EAFNOSUPPORT;
2369 SCTP_TCB_UNLOCK(stcb);
2370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2376 /* Applies to the specific association */
2377 paddrp->spp_flags = 0;
2379 paddrp->spp_hbinterval = net->heart_beat_delay;
2380 paddrp->spp_pathmaxrxt = net->failure_threshold;
2381 paddrp->spp_pathmtu = net->mtu;
2382 switch (net->ro._l_addr.sa.sa_family) {
2385 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2390 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2396 /* get flags for HB */
2397 if (net->dest_state & SCTP_ADDR_NOHB) {
2398 paddrp->spp_flags |= SPP_HB_DISABLE;
2400 paddrp->spp_flags |= SPP_HB_ENABLE;
2402 /* get flags for PMTU */
2403 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2404 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2406 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2408 if (net->dscp & 0x01) {
2409 paddrp->spp_dscp = net->dscp & 0xfc;
2410 paddrp->spp_flags |= SPP_DSCP;
2413 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2414 (net->flowlabel & 0x80000000)) {
2415 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2416 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2421 * No destination so return default
2424 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2425 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2426 if (stcb->asoc.default_dscp & 0x01) {
2427 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2428 paddrp->spp_flags |= SPP_DSCP;
2431 if (stcb->asoc.default_flowlabel & 0x80000000) {
2432 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2433 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2436 /* default settings should be these */
2437 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2438 paddrp->spp_flags |= SPP_HB_DISABLE;
2440 paddrp->spp_flags |= SPP_HB_ENABLE;
2442 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2443 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2445 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2447 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2449 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2450 SCTP_TCB_UNLOCK(stcb);
2452 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2453 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2454 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2455 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
2456 /* Use endpoint defaults */
2457 SCTP_INP_RLOCK(inp);
2458 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2459 paddrp->spp_hbinterval = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2460 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2461 /* get inp's default */
2462 if (inp->sctp_ep.default_dscp & 0x01) {
2463 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2464 paddrp->spp_flags |= SPP_DSCP;
2467 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2468 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2469 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2470 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2473 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2475 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2476 paddrp->spp_flags |= SPP_HB_ENABLE;
2478 paddrp->spp_flags |= SPP_HB_DISABLE;
2480 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2481 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2483 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2485 SCTP_INP_RUNLOCK(inp);
2487 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2492 *optsize = sizeof(struct sctp_paddrparams);
2496 case SCTP_GET_PEER_ADDR_INFO:
2498 struct sctp_paddrinfo *paddri;
2499 struct sctp_nets *net;
2500 struct sockaddr *addr;
2501 #if defined(INET) && defined(INET6)
2502 struct sockaddr_in sin_store;
2505 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2506 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2508 #if defined(INET) && defined(INET6)
2509 if (paddri->spinfo_address.ss_family == AF_INET6) {
2510 struct sockaddr_in6 *sin6;
2512 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2513 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2514 in6_sin6_2_sin(&sin_store, sin6);
2515 addr = (struct sockaddr *)&sin_store;
2517 addr = (struct sockaddr *)&paddri->spinfo_address;
2520 addr = (struct sockaddr *)&paddri->spinfo_address;
2523 addr = (struct sockaddr *)&paddri->spinfo_address;
2526 net = sctp_findnet(stcb, addr);
2529 * We increment here since
2530 * sctp_findassociation_ep_addr() wil do a
2531 * decrement if it finds the stcb as long as
2532 * the locked tcb (last argument) is NOT a
2536 SCTP_INP_INCR_REF(inp);
2537 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2539 SCTP_INP_DECR_REF(inp);
2543 if ((stcb != NULL) && (net != NULL)) {
2544 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2545 /* It's unconfirmed */
2546 paddri->spinfo_state = SCTP_UNCONFIRMED;
2547 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2549 paddri->spinfo_state = SCTP_ACTIVE;
2552 paddri->spinfo_state = SCTP_INACTIVE;
2554 paddri->spinfo_cwnd = net->cwnd;
2555 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2556 paddri->spinfo_rto = net->RTO;
2557 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2558 paddri->spinfo_mtu = net->mtu;
2559 switch (addr->sa_family) {
2562 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2567 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2573 SCTP_TCB_UNLOCK(stcb);
2574 *optsize = sizeof(struct sctp_paddrinfo);
2577 SCTP_TCB_UNLOCK(stcb);
2579 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2584 case SCTP_PCB_STATUS:
2586 struct sctp_pcbinfo *spcb;
2588 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2589 sctp_fill_pcbinfo(spcb);
2590 *optsize = sizeof(struct sctp_pcbinfo);
2595 struct sctp_nets *net;
2596 struct sctp_status *sstat;
2598 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2599 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2602 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2606 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2607 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2608 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2609 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2611 * We can't include chunks that have been passed to
2612 * the socket layer. Only things in queue.
2614 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2615 stcb->asoc.cnt_on_all_streams);
2618 sstat->sstat_instrms = stcb->asoc.streamincnt;
2619 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2620 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2621 net = stcb->asoc.primary_destination;
2623 memcpy(&sstat->sstat_primary.spinfo_address,
2625 ((struct sockaddr *)(&net->ro._l_addr))->sa_len);
2626 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2628 * Again the user can get info from
2629 * sctp_constants.h for what the state of
2632 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2633 /* It's unconfirmed */
2634 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2635 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2637 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2640 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2642 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2643 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2644 sstat->sstat_primary.spinfo_rto = net->RTO;
2645 sstat->sstat_primary.spinfo_mtu = net->mtu;
2646 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2649 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2654 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2661 memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo));
2663 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2664 SCTP_TCB_UNLOCK(stcb);
2665 *optsize = sizeof(struct sctp_status);
2670 struct sctp_rtoinfo *srto;
2672 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2673 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2676 srto->srto_initial = stcb->asoc.initial_rto;
2677 srto->srto_max = stcb->asoc.maxrto;
2678 srto->srto_min = stcb->asoc.minrto;
2679 SCTP_TCB_UNLOCK(stcb);
2681 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2682 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2683 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2684 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
2685 SCTP_INP_RLOCK(inp);
2686 srto->srto_initial = inp->sctp_ep.initial_rto;
2687 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2688 srto->srto_min = inp->sctp_ep.sctp_minrto;
2689 SCTP_INP_RUNLOCK(inp);
2691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2696 *optsize = sizeof(struct sctp_rtoinfo);
2702 struct sctp_timeouts *stimo;
2704 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2705 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2708 stimo->stimo_init = stcb->asoc.timoinit;
2709 stimo->stimo_data = stcb->asoc.timodata;
2710 stimo->stimo_sack = stcb->asoc.timosack;
2711 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2712 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2713 stimo->stimo_cookie = stcb->asoc.timocookie;
2714 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2715 SCTP_TCB_UNLOCK(stcb);
2716 *optsize = sizeof(struct sctp_timeouts);
2718 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2723 case SCTP_ASSOCINFO:
2725 struct sctp_assocparams *sasoc;
2727 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2728 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2731 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(stcb->asoc.cookie_life);
2732 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2733 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2734 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2735 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2736 SCTP_TCB_UNLOCK(stcb);
2738 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2739 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2740 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2741 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
2742 SCTP_INP_RLOCK(inp);
2743 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(inp->sctp_ep.def_cookie_life);
2744 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2745 sasoc->sasoc_number_peer_destinations = 0;
2746 sasoc->sasoc_peer_rwnd = 0;
2747 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2748 SCTP_INP_RUNLOCK(inp);
2750 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2755 *optsize = sizeof(struct sctp_assocparams);
2759 case SCTP_DEFAULT_SEND_PARAM:
2761 struct sctp_sndrcvinfo *s_info;
2763 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2764 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2767 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2768 SCTP_TCB_UNLOCK(stcb);
2770 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2771 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2772 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2773 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC))) {
2774 SCTP_INP_RLOCK(inp);
2775 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2776 SCTP_INP_RUNLOCK(inp);
2778 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2783 *optsize = sizeof(struct sctp_sndrcvinfo);
2789 struct sctp_initmsg *sinit;
2791 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2792 SCTP_INP_RLOCK(inp);
2793 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2794 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2795 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2796 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2797 SCTP_INP_RUNLOCK(inp);
2798 *optsize = sizeof(struct sctp_initmsg);
2801 case SCTP_PRIMARY_ADDR:
2802 /* we allow a "get" operation on this */
2804 struct sctp_setprim *ssp;
2806 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2807 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2810 union sctp_sockstore *addr;
2812 addr = &stcb->asoc.primary_destination->ro._l_addr;
2813 switch (addr->sa.sa_family) {
2817 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2818 in6_sin_2_v4mapsin6(&addr->sin,
2819 (struct sockaddr_in6 *)&ssp->ssp_addr);
2821 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2824 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2830 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2836 SCTP_TCB_UNLOCK(stcb);
2837 *optsize = sizeof(struct sctp_setprim);
2839 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2844 case SCTP_HMAC_IDENT:
2846 struct sctp_hmacalgo *shmac;
2847 sctp_hmaclist_t *hmaclist;
2851 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2853 SCTP_INP_RLOCK(inp);
2854 hmaclist = inp->sctp_ep.local_hmacs;
2855 if (hmaclist == NULL) {
2856 /* no HMACs to return */
2857 *optsize = sizeof(*shmac);
2858 SCTP_INP_RUNLOCK(inp);
2861 /* is there room for all of the hmac ids? */
2862 size = sizeof(*shmac) + (hmaclist->num_algo *
2863 sizeof(shmac->shmac_idents[0]));
2864 if ((size_t)(*optsize) < size) {
2865 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2867 SCTP_INP_RUNLOCK(inp);
2870 /* copy in the list */
2871 shmac->shmac_number_of_idents = hmaclist->num_algo;
2872 for (i = 0; i < hmaclist->num_algo; i++) {
2873 shmac->shmac_idents[i] = hmaclist->hmac[i];
2875 SCTP_INP_RUNLOCK(inp);
2879 case SCTP_AUTH_ACTIVE_KEY:
2881 struct sctp_authkeyid *scact;
2883 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2884 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2887 /* get the active key on the assoc */
2888 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2889 SCTP_TCB_UNLOCK(stcb);
2891 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2892 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2893 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2894 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC))) {
2895 /* get the endpoint active key */
2896 SCTP_INP_RLOCK(inp);
2897 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2898 SCTP_INP_RUNLOCK(inp);
2900 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2905 *optsize = sizeof(struct sctp_authkeyid);
2909 case SCTP_LOCAL_AUTH_CHUNKS:
2911 struct sctp_authchunks *sac;
2912 sctp_auth_chklist_t *chklist = NULL;
2915 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2916 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2919 /* get off the assoc */
2920 chklist = stcb->asoc.local_auth_chunks;
2921 /* is there enough space? */
2922 size = sctp_auth_get_chklist_size(chklist);
2923 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2925 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2927 /* copy in the chunks */
2928 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2929 sac->gauth_number_of_chunks = (uint32_t)size;
2930 *optsize = sizeof(struct sctp_authchunks) + size;
2932 SCTP_TCB_UNLOCK(stcb);
2934 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2935 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2936 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2937 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC))) {
2938 /* get off the endpoint */
2939 SCTP_INP_RLOCK(inp);
2940 chklist = inp->sctp_ep.local_auth_chunks;
2941 /* is there enough space? */
2942 size = sctp_auth_get_chklist_size(chklist);
2943 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2945 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2947 /* copy in the chunks */
2948 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2949 sac->gauth_number_of_chunks = (uint32_t)size;
2950 *optsize = sizeof(struct sctp_authchunks) + size;
2952 SCTP_INP_RUNLOCK(inp);
2954 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2960 case SCTP_PEER_AUTH_CHUNKS:
2962 struct sctp_authchunks *sac;
2963 sctp_auth_chklist_t *chklist = NULL;
2966 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2967 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2970 /* get off the assoc */
2971 chklist = stcb->asoc.peer_auth_chunks;
2972 /* is there enough space? */
2973 size = sctp_auth_get_chklist_size(chklist);
2974 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2976 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2978 /* copy in the chunks */
2979 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2980 sac->gauth_number_of_chunks = (uint32_t)size;
2981 *optsize = sizeof(struct sctp_authchunks) + size;
2983 SCTP_TCB_UNLOCK(stcb);
2985 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2992 struct sctp_event *event;
2993 uint32_t event_type;
2995 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2996 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2998 switch (event->se_type) {
2999 case SCTP_ASSOC_CHANGE:
3000 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3002 case SCTP_PEER_ADDR_CHANGE:
3003 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3005 case SCTP_REMOTE_ERROR:
3006 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3008 case SCTP_SEND_FAILED:
3009 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3011 case SCTP_SHUTDOWN_EVENT:
3012 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3014 case SCTP_ADAPTATION_INDICATION:
3015 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3017 case SCTP_PARTIAL_DELIVERY_EVENT:
3018 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3020 case SCTP_AUTHENTICATION_EVENT:
3021 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3023 case SCTP_STREAM_RESET_EVENT:
3024 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3026 case SCTP_SENDER_DRY_EVENT:
3027 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3029 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3031 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3034 case SCTP_ASSOC_RESET_EVENT:
3035 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3037 case SCTP_STREAM_CHANGE_EVENT:
3038 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3040 case SCTP_SEND_FAILED_EVENT:
3041 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3045 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3049 if (event_type > 0) {
3051 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3053 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3054 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3055 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3056 (event->se_assoc_id == SCTP_FUTURE_ASSOC))) {
3057 SCTP_INP_RLOCK(inp);
3058 event->se_on = sctp_is_feature_on(inp, event_type);
3059 SCTP_INP_RUNLOCK(inp);
3061 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3067 SCTP_TCB_UNLOCK(stcb);
3070 *optsize = sizeof(struct sctp_event);
3074 case SCTP_RECVRCVINFO:
3078 if (*optsize < sizeof(int)) {
3079 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3082 SCTP_INP_RLOCK(inp);
3083 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3084 SCTP_INP_RUNLOCK(inp);
3087 /* return the option value */
3088 *(int *)optval = onoff;
3089 *optsize = sizeof(int);
3093 case SCTP_RECVNXTINFO:
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_RECVNXTINFO);
3103 SCTP_INP_RUNLOCK(inp);
3106 /* return the option value */
3107 *(int *)optval = onoff;
3108 *optsize = sizeof(int);
3112 case SCTP_DEFAULT_SNDINFO:
3114 struct sctp_sndinfo *info;
3116 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3117 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3120 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3121 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3122 info->snd_flags &= 0xfff0;
3123 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3124 info->snd_context = stcb->asoc.def_send.sinfo_context;
3125 SCTP_TCB_UNLOCK(stcb);
3127 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3128 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3129 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3130 (info->snd_assoc_id == SCTP_FUTURE_ASSOC))) {
3131 SCTP_INP_RLOCK(inp);
3132 info->snd_sid = inp->def_send.sinfo_stream;
3133 info->snd_flags = inp->def_send.sinfo_flags;
3134 info->snd_flags &= 0xfff0;
3135 info->snd_ppid = inp->def_send.sinfo_ppid;
3136 info->snd_context = inp->def_send.sinfo_context;
3137 SCTP_INP_RUNLOCK(inp);
3139 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3144 *optsize = sizeof(struct sctp_sndinfo);
3148 case SCTP_DEFAULT_PRINFO:
3150 struct sctp_default_prinfo *info;
3152 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3153 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3156 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3157 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3158 SCTP_TCB_UNLOCK(stcb);
3160 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3161 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3162 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3163 (info->pr_assoc_id == SCTP_FUTURE_ASSOC))) {
3164 SCTP_INP_RLOCK(inp);
3165 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3166 info->pr_value = inp->def_send.sinfo_timetolive;
3167 SCTP_INP_RUNLOCK(inp);
3169 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3174 *optsize = sizeof(struct sctp_default_prinfo);
3178 case SCTP_PEER_ADDR_THLDS:
3180 struct sctp_paddrthlds *thlds;
3181 struct sctp_nets *net;
3182 struct sockaddr *addr;
3183 #if defined(INET) && defined(INET6)
3184 struct sockaddr_in sin_store;
3187 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3188 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3190 #if defined(INET) && defined(INET6)
3191 if (thlds->spt_address.ss_family == AF_INET6) {
3192 struct sockaddr_in6 *sin6;
3194 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3195 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3196 in6_sin6_2_sin(&sin_store, sin6);
3197 addr = (struct sockaddr *)&sin_store;
3199 addr = (struct sockaddr *)&thlds->spt_address;
3202 addr = (struct sockaddr *)&thlds->spt_address;
3205 addr = (struct sockaddr *)&thlds->spt_address;
3208 net = sctp_findnet(stcb, addr);
3211 * We increment here since
3212 * sctp_findassociation_ep_addr() wil do a
3213 * decrement if it finds the stcb as long as
3214 * the locked tcb (last argument) is NOT a
3218 SCTP_INP_INCR_REF(inp);
3219 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3221 SCTP_INP_DECR_REF(inp);
3224 if ((stcb != NULL) && (net == NULL)) {
3226 if (addr->sa_family == AF_INET) {
3227 struct sockaddr_in *sin;
3229 sin = (struct sockaddr_in *)addr;
3230 if (sin->sin_addr.s_addr != INADDR_ANY) {
3232 SCTP_TCB_UNLOCK(stcb);
3233 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3239 if (addr->sa_family == AF_INET6) {
3240 struct sockaddr_in6 *sin6;
3242 sin6 = (struct sockaddr_in6 *)addr;
3243 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3245 SCTP_TCB_UNLOCK(stcb);
3246 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3252 error = EAFNOSUPPORT;
3253 SCTP_TCB_UNLOCK(stcb);
3254 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3261 thlds->spt_pathmaxrxt = net->failure_threshold;
3262 thlds->spt_pathpfthld = net->pf_threshold;
3263 thlds->spt_pathcpthld = 0xffff;
3265 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3266 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3267 thlds->spt_pathcpthld = 0xffff;
3269 thlds->spt_assoc_id = sctp_get_associd(stcb);
3270 SCTP_TCB_UNLOCK(stcb);
3272 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3273 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3274 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3275 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
3276 /* Use endpoint defaults */
3277 SCTP_INP_RLOCK(inp);
3278 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3279 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3280 thlds->spt_pathcpthld = 0xffff;
3281 SCTP_INP_RUNLOCK(inp);
3283 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3288 *optsize = sizeof(struct sctp_paddrthlds);
3292 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3294 struct sctp_udpencaps *encaps;
3295 struct sctp_nets *net;
3296 struct sockaddr *addr;
3297 #if defined(INET) && defined(INET6)
3298 struct sockaddr_in sin_store;
3301 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3302 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3304 #if defined(INET) && defined(INET6)
3305 if (encaps->sue_address.ss_family == AF_INET6) {
3306 struct sockaddr_in6 *sin6;
3308 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3309 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3310 in6_sin6_2_sin(&sin_store, sin6);
3311 addr = (struct sockaddr *)&sin_store;
3313 addr = (struct sockaddr *)&encaps->sue_address;
3316 addr = (struct sockaddr *)&encaps->sue_address;
3319 addr = (struct sockaddr *)&encaps->sue_address;
3322 net = sctp_findnet(stcb, addr);
3325 * We increment here since
3326 * sctp_findassociation_ep_addr() wil do a
3327 * decrement if it finds the stcb as long as
3328 * the locked tcb (last argument) is NOT a
3332 SCTP_INP_INCR_REF(inp);
3333 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3335 SCTP_INP_DECR_REF(inp);
3338 if ((stcb != NULL) && (net == NULL)) {
3340 if (addr->sa_family == AF_INET) {
3341 struct sockaddr_in *sin;
3343 sin = (struct sockaddr_in *)addr;
3344 if (sin->sin_addr.s_addr != INADDR_ANY) {
3346 SCTP_TCB_UNLOCK(stcb);
3347 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3353 if (addr->sa_family == AF_INET6) {
3354 struct sockaddr_in6 *sin6;
3356 sin6 = (struct sockaddr_in6 *)addr;
3357 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3359 SCTP_TCB_UNLOCK(stcb);
3360 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3366 error = EAFNOSUPPORT;
3367 SCTP_TCB_UNLOCK(stcb);
3368 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3375 encaps->sue_port = net->port;
3377 encaps->sue_port = stcb->asoc.port;
3379 SCTP_TCB_UNLOCK(stcb);
3381 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3382 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3383 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3384 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
3385 SCTP_INP_RLOCK(inp);
3386 encaps->sue_port = inp->sctp_ep.port;
3387 SCTP_INP_RUNLOCK(inp);
3389 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3394 *optsize = sizeof(struct sctp_udpencaps);
3398 case SCTP_ECN_SUPPORTED:
3400 struct sctp_assoc_value *av;
3402 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3403 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3406 av->assoc_value = stcb->asoc.ecn_supported;
3407 SCTP_TCB_UNLOCK(stcb);
3409 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3410 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3411 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3412 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3413 SCTP_INP_RLOCK(inp);
3414 av->assoc_value = inp->ecn_supported;
3415 SCTP_INP_RUNLOCK(inp);
3417 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3422 *optsize = sizeof(struct sctp_assoc_value);
3426 case SCTP_PR_SUPPORTED:
3428 struct sctp_assoc_value *av;
3430 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3431 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3434 av->assoc_value = stcb->asoc.prsctp_supported;
3435 SCTP_TCB_UNLOCK(stcb);
3437 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3438 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3439 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3440 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3441 SCTP_INP_RLOCK(inp);
3442 av->assoc_value = inp->prsctp_supported;
3443 SCTP_INP_RUNLOCK(inp);
3445 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3450 *optsize = sizeof(struct sctp_assoc_value);
3454 case SCTP_AUTH_SUPPORTED:
3456 struct sctp_assoc_value *av;
3458 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3459 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3462 av->assoc_value = stcb->asoc.auth_supported;
3463 SCTP_TCB_UNLOCK(stcb);
3465 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3466 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3467 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3468 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3469 SCTP_INP_RLOCK(inp);
3470 av->assoc_value = inp->auth_supported;
3471 SCTP_INP_RUNLOCK(inp);
3473 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3478 *optsize = sizeof(struct sctp_assoc_value);
3482 case SCTP_ASCONF_SUPPORTED:
3484 struct sctp_assoc_value *av;
3486 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3487 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3490 av->assoc_value = stcb->asoc.asconf_supported;
3491 SCTP_TCB_UNLOCK(stcb);
3493 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3494 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3495 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3496 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3497 SCTP_INP_RLOCK(inp);
3498 av->assoc_value = inp->asconf_supported;
3499 SCTP_INP_RUNLOCK(inp);
3501 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3506 *optsize = sizeof(struct sctp_assoc_value);
3510 case SCTP_RECONFIG_SUPPORTED:
3512 struct sctp_assoc_value *av;
3514 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3515 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3518 av->assoc_value = stcb->asoc.reconfig_supported;
3519 SCTP_TCB_UNLOCK(stcb);
3521 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3522 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3523 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3524 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3525 SCTP_INP_RLOCK(inp);
3526 av->assoc_value = inp->reconfig_supported;
3527 SCTP_INP_RUNLOCK(inp);
3529 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3534 *optsize = sizeof(struct sctp_assoc_value);
3538 case SCTP_NRSACK_SUPPORTED:
3540 struct sctp_assoc_value *av;
3542 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3543 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3546 av->assoc_value = stcb->asoc.nrsack_supported;
3547 SCTP_TCB_UNLOCK(stcb);
3549 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3550 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3551 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3552 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3553 SCTP_INP_RLOCK(inp);
3554 av->assoc_value = inp->nrsack_supported;
3555 SCTP_INP_RUNLOCK(inp);
3557 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3562 *optsize = sizeof(struct sctp_assoc_value);
3566 case SCTP_PKTDROP_SUPPORTED:
3568 struct sctp_assoc_value *av;
3570 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3571 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3574 av->assoc_value = stcb->asoc.pktdrop_supported;
3575 SCTP_TCB_UNLOCK(stcb);
3577 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3578 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3579 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3580 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3581 SCTP_INP_RLOCK(inp);
3582 av->assoc_value = inp->pktdrop_supported;
3583 SCTP_INP_RUNLOCK(inp);
3585 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3590 *optsize = sizeof(struct sctp_assoc_value);
3594 case SCTP_ENABLE_STREAM_RESET:
3596 struct sctp_assoc_value *av;
3598 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3599 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3602 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3603 SCTP_TCB_UNLOCK(stcb);
3605 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3606 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3607 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3608 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3609 SCTP_INP_RLOCK(inp);
3610 av->assoc_value = (uint32_t)inp->local_strreset_support;
3611 SCTP_INP_RUNLOCK(inp);
3613 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3618 *optsize = sizeof(struct sctp_assoc_value);
3622 case SCTP_PR_STREAM_STATUS:
3624 struct sctp_prstatus *sprstat;
3628 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3629 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3631 sid = sprstat->sprstat_sid;
3632 policy = sprstat->sprstat_policy;
3633 #if defined(SCTP_DETAILED_STR_STATS)
3634 if ((stcb != NULL) &&
3635 (sid < stcb->asoc.streamoutcnt) &&
3636 (policy != SCTP_PR_SCTP_NONE) &&
3637 ((policy <= SCTP_PR_SCTP_MAX) ||
3638 (policy == SCTP_PR_SCTP_ALL))) {
3639 if (policy == SCTP_PR_SCTP_ALL) {
3640 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3641 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3643 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3644 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3647 if ((stcb != NULL) &&
3648 (sid < stcb->asoc.streamoutcnt) &&
3649 (policy == SCTP_PR_SCTP_ALL)) {
3650 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3651 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3654 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3658 SCTP_TCB_UNLOCK(stcb);
3661 *optsize = sizeof(struct sctp_prstatus);
3665 case SCTP_PR_ASSOC_STATUS:
3667 struct sctp_prstatus *sprstat;
3670 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3671 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3673 policy = sprstat->sprstat_policy;
3674 if ((stcb != NULL) &&
3675 (policy != SCTP_PR_SCTP_NONE) &&
3676 ((policy <= SCTP_PR_SCTP_MAX) ||
3677 (policy == SCTP_PR_SCTP_ALL))) {
3678 if (policy == SCTP_PR_SCTP_ALL) {
3679 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3680 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3682 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3683 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3686 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3690 SCTP_TCB_UNLOCK(stcb);
3693 *optsize = sizeof(struct sctp_prstatus);
3699 struct sctp_assoc_value *av;
3701 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3702 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3705 av->assoc_value = stcb->asoc.max_cwnd;
3706 SCTP_TCB_UNLOCK(stcb);
3708 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3709 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3710 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3711 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3712 SCTP_INP_RLOCK(inp);
3713 av->assoc_value = inp->max_cwnd;
3714 SCTP_INP_RUNLOCK(inp);
3716 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3721 *optsize = sizeof(struct sctp_assoc_value);
3726 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3727 error = ENOPROTOOPT;
3729 } /* end switch (sopt->sopt_name) */
3737 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3742 struct sctp_tcb *stcb = NULL;
3743 struct sctp_inpcb *inp = NULL;
3746 if (optval == NULL) {
3747 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3750 inp = (struct sctp_inpcb *)so->so_pcb;
3752 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3755 vrf_id = inp->def_vrf_id;
3760 case SCTP_AUTOCLOSE:
3761 case SCTP_AUTO_ASCONF:
3762 case SCTP_EXPLICIT_EOR:
3763 case SCTP_DISABLE_FRAGMENTS:
3764 case SCTP_USE_EXT_RCVINFO:
3765 case SCTP_I_WANT_MAPPED_V4_ADDR:
3766 /* copy in the option value */
3767 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3772 case SCTP_DISABLE_FRAGMENTS:
3773 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3775 case SCTP_AUTO_ASCONF:
3777 * NOTE: we don't really support this flag
3779 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3780 /* only valid for bound all sockets */
3781 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3783 /* forbidden by admin */
3784 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3787 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3789 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3793 case SCTP_EXPLICIT_EOR:
3794 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3796 case SCTP_USE_EXT_RCVINFO:
3797 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3799 case SCTP_I_WANT_MAPPED_V4_ADDR:
3800 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3801 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3803 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3808 set_opt = SCTP_PCB_FLAGS_NODELAY;
3810 case SCTP_AUTOCLOSE:
3811 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3812 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3813 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3816 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3818 * The value is in ticks. Note this does not effect
3819 * old associations, only new ones.
3821 inp->sctp_ep.auto_close_time = sctp_secs_to_ticks(*mopt);
3824 SCTP_INP_WLOCK(inp);
3826 sctp_feature_on(inp, set_opt);
3828 sctp_feature_off(inp, set_opt);
3830 SCTP_INP_WUNLOCK(inp);
3832 case SCTP_REUSE_PORT:
3834 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3835 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3836 /* Can't set it after we are bound */
3840 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3841 /* Can't do this for a 1-m socket */
3846 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3848 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3851 case SCTP_PARTIAL_DELIVERY_POINT:
3855 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3856 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3857 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3861 inp->partial_delivery_point = *value;
3864 case SCTP_FRAGMENT_INTERLEAVE:
3865 /* not yet until we re-write sctp_recvmsg() */
3869 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3870 if (*level == SCTP_FRAG_LEVEL_2) {
3871 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3872 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3873 } else if (*level == SCTP_FRAG_LEVEL_1) {
3874 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3875 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3876 } else if (*level == SCTP_FRAG_LEVEL_0) {
3877 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3878 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3886 case SCTP_INTERLEAVING_SUPPORTED:
3888 struct sctp_assoc_value *av;
3890 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3891 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3894 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3896 SCTP_TCB_UNLOCK(stcb);
3898 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3899 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3900 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3901 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3902 SCTP_INP_WLOCK(inp);
3903 if (av->assoc_value == 0) {
3904 inp->idata_supported = 0;
3906 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3907 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3908 inp->idata_supported = 1;
3916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3920 SCTP_INP_WUNLOCK(inp);
3922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3928 case SCTP_CMT_ON_OFF:
3929 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3930 struct sctp_assoc_value *av;
3932 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3933 if (av->assoc_value > SCTP_CMT_MAX) {
3934 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3938 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3940 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3941 SCTP_TCB_UNLOCK(stcb);
3943 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3944 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3945 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3946 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3947 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3948 SCTP_INP_WLOCK(inp);
3949 inp->sctp_cmt_on_off = av->assoc_value;
3950 SCTP_INP_WUNLOCK(inp);
3952 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3953 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3954 (av->assoc_id == SCTP_ALL_ASSOC))) {
3955 SCTP_INP_RLOCK(inp);
3956 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3957 SCTP_TCB_LOCK(stcb);
3958 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3959 SCTP_TCB_UNLOCK(stcb);
3961 SCTP_INP_RUNLOCK(inp);
3965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3966 error = ENOPROTOOPT;
3969 case SCTP_PLUGGABLE_CC:
3971 struct sctp_assoc_value *av;
3972 struct sctp_nets *net;
3974 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3975 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3976 (av->assoc_value != SCTP_CC_HSTCP) &&
3977 (av->assoc_value != SCTP_CC_HTCP) &&
3978 (av->assoc_value != SCTP_CC_RTCC)) {
3979 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3983 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3985 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3986 stcb->asoc.congestion_control_module = av->assoc_value;
3987 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3988 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3989 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3992 SCTP_TCB_UNLOCK(stcb);
3994 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3995 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3996 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3997 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3998 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3999 SCTP_INP_WLOCK(inp);
4000 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
4001 SCTP_INP_WUNLOCK(inp);
4003 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4004 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4005 (av->assoc_id == SCTP_ALL_ASSOC))) {
4006 SCTP_INP_RLOCK(inp);
4007 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4008 SCTP_TCB_LOCK(stcb);
4009 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4010 stcb->asoc.congestion_control_module = av->assoc_value;
4011 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4012 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4013 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4016 SCTP_TCB_UNLOCK(stcb);
4018 SCTP_INP_RUNLOCK(inp);
4023 case SCTP_CC_OPTION:
4025 struct sctp_cc_option *cc_opt;
4027 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4028 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4030 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4031 (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC)) {
4032 SCTP_INP_RLOCK(inp);
4033 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4034 SCTP_TCB_LOCK(stcb);
4035 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4036 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4038 SCTP_TCB_UNLOCK(stcb);
4040 SCTP_INP_RUNLOCK(inp);
4045 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4048 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4051 SCTP_TCB_UNLOCK(stcb);
4055 case SCTP_PLUGGABLE_SS:
4057 struct sctp_assoc_value *av;
4059 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4060 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4061 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4062 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4063 (av->assoc_value != SCTP_SS_PRIORITY) &&
4064 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4065 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4066 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4070 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4072 SCTP_TCB_SEND_LOCK(stcb);
4073 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4074 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4075 stcb->asoc.stream_scheduling_module = av->assoc_value;
4076 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4077 SCTP_TCB_SEND_UNLOCK(stcb);
4078 SCTP_TCB_UNLOCK(stcb);
4080 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4081 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4082 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4083 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4084 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4085 SCTP_INP_WLOCK(inp);
4086 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4087 SCTP_INP_WUNLOCK(inp);
4089 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4090 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4091 (av->assoc_id == SCTP_ALL_ASSOC))) {
4092 SCTP_INP_RLOCK(inp);
4093 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4094 SCTP_TCB_LOCK(stcb);
4095 SCTP_TCB_SEND_LOCK(stcb);
4096 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4097 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4098 stcb->asoc.stream_scheduling_module = av->assoc_value;
4099 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4100 SCTP_TCB_SEND_UNLOCK(stcb);
4101 SCTP_TCB_UNLOCK(stcb);
4103 SCTP_INP_RUNLOCK(inp);
4110 struct sctp_stream_value *av;
4112 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4113 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4115 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4116 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4117 av->stream_value) < 0)) {
4118 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4121 SCTP_TCB_UNLOCK(stcb);
4123 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4124 (av->assoc_id == SCTP_CURRENT_ASSOC)) {
4125 SCTP_INP_RLOCK(inp);
4126 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4127 SCTP_TCB_LOCK(stcb);
4128 if (av->stream_id < stcb->asoc.streamoutcnt) {
4129 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4131 &stcb->asoc.strmout[av->stream_id],
4134 SCTP_TCB_UNLOCK(stcb);
4136 SCTP_INP_RUNLOCK(inp);
4139 * Can't set stream value without
4142 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4148 case SCTP_CLR_STAT_LOG:
4149 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4154 struct sctp_assoc_value *av;
4156 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4157 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4160 stcb->asoc.context = av->assoc_value;
4161 SCTP_TCB_UNLOCK(stcb);
4163 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4164 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4165 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4166 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4167 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4168 SCTP_INP_WLOCK(inp);
4169 inp->sctp_context = av->assoc_value;
4170 SCTP_INP_WUNLOCK(inp);
4172 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4173 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4174 (av->assoc_id == SCTP_ALL_ASSOC))) {
4175 SCTP_INP_RLOCK(inp);
4176 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4177 SCTP_TCB_LOCK(stcb);
4178 stcb->asoc.context = av->assoc_value;
4179 SCTP_TCB_UNLOCK(stcb);
4181 SCTP_INP_RUNLOCK(inp);
4188 uint32_t *default_vrfid;
4190 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4191 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4192 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4196 inp->def_vrf_id = *default_vrfid;
4199 case SCTP_DEL_VRF_ID:
4201 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4205 case SCTP_ADD_VRF_ID:
4207 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4211 case SCTP_DELAYED_SACK:
4213 struct sctp_sack_info *sack;
4215 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4216 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4217 if (sack->sack_delay) {
4218 if (sack->sack_delay > SCTP_MAX_SACK_DELAY) {
4221 SCTP_TCB_UNLOCK(stcb);
4227 if (sack->sack_delay) {
4228 stcb->asoc.delayed_ack = sack->sack_delay;
4230 if (sack->sack_freq) {
4231 stcb->asoc.sack_freq = sack->sack_freq;
4233 SCTP_TCB_UNLOCK(stcb);
4235 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4236 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4237 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4238 ((sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4239 (sack->sack_assoc_id == SCTP_ALL_ASSOC)))) {
4240 SCTP_INP_WLOCK(inp);
4241 if (sack->sack_delay) {
4242 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = sctp_msecs_to_ticks(sack->sack_delay);
4244 if (sack->sack_freq) {
4245 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4247 SCTP_INP_WUNLOCK(inp);
4249 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4250 ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4251 (sack->sack_assoc_id == SCTP_ALL_ASSOC))) {
4252 SCTP_INP_RLOCK(inp);
4253 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4254 SCTP_TCB_LOCK(stcb);
4255 if (sack->sack_delay) {
4256 stcb->asoc.delayed_ack = sack->sack_delay;
4258 if (sack->sack_freq) {
4259 stcb->asoc.sack_freq = sack->sack_freq;
4261 SCTP_TCB_UNLOCK(stcb);
4263 SCTP_INP_RUNLOCK(inp);
4268 case SCTP_AUTH_CHUNK:
4270 struct sctp_authchunk *sauth;
4272 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4274 SCTP_INP_WLOCK(inp);
4275 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4276 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4279 inp->auth_supported = 1;
4281 SCTP_INP_WUNLOCK(inp);
4286 struct sctp_authkey *sca;
4287 struct sctp_keyhead *shared_keys;
4288 sctp_sharedkey_t *shared_key;
4289 sctp_key_t *key = NULL;
4292 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4293 if (sca->sca_keylength == 0) {
4294 size = optsize - sizeof(struct sctp_authkey);
4296 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4297 size = sca->sca_keylength;
4299 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4304 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4307 shared_keys = &stcb->asoc.shared_keys;
4308 /* clear the cached keys for this key id */
4309 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4311 * create the new shared key and
4315 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4317 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4319 SCTP_TCB_UNLOCK(stcb);
4323 shared_key = sctp_alloc_sharedkey();
4324 if (shared_key == NULL) {
4326 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4328 SCTP_TCB_UNLOCK(stcb);
4331 shared_key->key = key;
4332 shared_key->keyid = sca->sca_keynumber;
4333 error = sctp_insert_sharedkey(shared_keys, shared_key);
4334 SCTP_TCB_UNLOCK(stcb);
4336 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4337 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4338 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4339 ((sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4340 (sca->sca_assoc_id == SCTP_ALL_ASSOC)))) {
4341 SCTP_INP_WLOCK(inp);
4342 shared_keys = &inp->sctp_ep.shared_keys;
4344 * clear the cached keys on all
4345 * assocs for this key id
4347 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4349 * create the new shared key and
4353 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4355 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4357 SCTP_INP_WUNLOCK(inp);
4361 shared_key = sctp_alloc_sharedkey();
4362 if (shared_key == NULL) {
4364 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4366 SCTP_INP_WUNLOCK(inp);
4369 shared_key->key = key;
4370 shared_key->keyid = sca->sca_keynumber;
4371 error = sctp_insert_sharedkey(shared_keys, shared_key);
4372 SCTP_INP_WUNLOCK(inp);
4374 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4375 ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4376 (sca->sca_assoc_id == SCTP_ALL_ASSOC))) {
4377 SCTP_INP_RLOCK(inp);
4378 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4379 SCTP_TCB_LOCK(stcb);
4380 shared_keys = &stcb->asoc.shared_keys;
4382 * clear the cached keys for
4385 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4387 * create the new shared key
4388 * and insert/replace it
4391 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4393 SCTP_TCB_UNLOCK(stcb);
4397 shared_key = sctp_alloc_sharedkey();
4398 if (shared_key == NULL) {
4400 SCTP_TCB_UNLOCK(stcb);
4403 shared_key->key = key;
4404 shared_key->keyid = sca->sca_keynumber;
4405 error = sctp_insert_sharedkey(shared_keys, shared_key);
4406 SCTP_TCB_UNLOCK(stcb);
4408 SCTP_INP_RUNLOCK(inp);
4413 case SCTP_HMAC_IDENT:
4415 struct sctp_hmacalgo *shmac;
4416 sctp_hmaclist_t *hmaclist;
4420 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4421 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4422 (shmac->shmac_number_of_idents > 0xffff)) {
4423 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4428 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4429 if (hmaclist == NULL) {
4430 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4434 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4435 hmacid = shmac->shmac_idents[i];
4436 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4437 /* invalid HMACs were found */ ;
4438 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4440 sctp_free_hmaclist(hmaclist);
4441 goto sctp_set_hmac_done;
4444 for (i = 0; i < hmaclist->num_algo; i++) {
4445 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4446 /* already in list */
4450 if (i == hmaclist->num_algo) {
4451 /* not found in list */
4452 sctp_free_hmaclist(hmaclist);
4453 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4457 /* set it on the endpoint */
4458 SCTP_INP_WLOCK(inp);
4459 if (inp->sctp_ep.local_hmacs)
4460 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4461 inp->sctp_ep.local_hmacs = hmaclist;
4462 SCTP_INP_WUNLOCK(inp);
4466 case SCTP_AUTH_ACTIVE_KEY:
4468 struct sctp_authkeyid *scact;
4470 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4471 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4473 /* set the active key on the right place */
4475 /* set the active key on the assoc */
4476 if (sctp_auth_setactivekey(stcb,
4477 scact->scact_keynumber)) {
4478 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4479 SCTP_FROM_SCTP_USRREQ,
4483 SCTP_TCB_UNLOCK(stcb);
4485 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4486 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4487 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4488 ((scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4489 (scact->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4490 SCTP_INP_WLOCK(inp);
4491 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4492 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4495 SCTP_INP_WUNLOCK(inp);
4497 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4498 ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4499 (scact->scact_assoc_id == SCTP_ALL_ASSOC))) {
4500 SCTP_INP_RLOCK(inp);
4501 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4502 SCTP_TCB_LOCK(stcb);
4503 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4504 SCTP_TCB_UNLOCK(stcb);
4506 SCTP_INP_RUNLOCK(inp);
4511 case SCTP_AUTH_DELETE_KEY:
4513 struct sctp_authkeyid *scdel;
4515 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4516 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4518 /* delete the key from the right place */
4520 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4521 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4524 SCTP_TCB_UNLOCK(stcb);
4526 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4527 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4528 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4529 ((scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4530 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4531 SCTP_INP_WLOCK(inp);
4532 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4533 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4536 SCTP_INP_WUNLOCK(inp);
4538 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4539 ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4540 (scdel->scact_assoc_id == SCTP_ALL_ASSOC))) {
4541 SCTP_INP_RLOCK(inp);
4542 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4543 SCTP_TCB_LOCK(stcb);
4544 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4545 SCTP_TCB_UNLOCK(stcb);
4547 SCTP_INP_RUNLOCK(inp);
4552 case SCTP_AUTH_DEACTIVATE_KEY:
4554 struct sctp_authkeyid *keyid;
4556 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4557 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4559 /* deactivate the key from the right place */
4561 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4562 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4565 SCTP_TCB_UNLOCK(stcb);
4567 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4568 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4569 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4570 ((keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4571 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4572 SCTP_INP_WLOCK(inp);
4573 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4574 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4577 SCTP_INP_WUNLOCK(inp);
4579 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4580 ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4581 (keyid->scact_assoc_id == SCTP_ALL_ASSOC))) {
4582 SCTP_INP_RLOCK(inp);
4583 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4584 SCTP_TCB_LOCK(stcb);
4585 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4586 SCTP_TCB_UNLOCK(stcb);
4588 SCTP_INP_RUNLOCK(inp);
4593 case SCTP_ENABLE_STREAM_RESET:
4595 struct sctp_assoc_value *av;
4597 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4598 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4599 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4603 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4605 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4606 SCTP_TCB_UNLOCK(stcb);
4608 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4609 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4610 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4611 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4612 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4613 SCTP_INP_WLOCK(inp);
4614 inp->local_strreset_support = (uint8_t)av->assoc_value;
4615 SCTP_INP_WUNLOCK(inp);
4617 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4618 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4619 (av->assoc_id == SCTP_ALL_ASSOC))) {
4620 SCTP_INP_RLOCK(inp);
4621 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4622 SCTP_TCB_LOCK(stcb);
4623 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4624 SCTP_TCB_UNLOCK(stcb);
4626 SCTP_INP_RUNLOCK(inp);
4632 case SCTP_RESET_STREAMS:
4634 struct sctp_reset_streams *strrst;
4635 int i, send_out = 0;
4638 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4639 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4641 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4645 if (stcb->asoc.reconfig_supported == 0) {
4647 * Peer does not support the chunk type.
4649 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4651 SCTP_TCB_UNLOCK(stcb);
4654 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4655 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4657 SCTP_TCB_UNLOCK(stcb);
4660 if (sizeof(struct sctp_reset_streams) +
4661 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4663 SCTP_TCB_UNLOCK(stcb);
4666 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4668 if (stcb->asoc.stream_reset_outstanding) {
4669 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4671 SCTP_TCB_UNLOCK(stcb);
4675 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4678 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4679 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4681 SCTP_TCB_UNLOCK(stcb);
4684 if ((send_in == 0) && (send_out == 0)) {
4685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4687 SCTP_TCB_UNLOCK(stcb);
4690 for (i = 0; i < strrst->srs_number_streams; i++) {
4692 (strrst->srs_stream_list[i] >= stcb->asoc.streamincnt)) {
4693 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4698 (strrst->srs_stream_list[i] >= stcb->asoc.streamoutcnt)) {
4699 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4705 SCTP_TCB_UNLOCK(stcb);
4712 if (strrst->srs_number_streams) {
4713 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4714 strm = strrst->srs_stream_list[i];
4715 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4716 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4722 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4723 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4724 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4731 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4732 strrst->srs_stream_list,
4733 send_in, 0, 0, 0, 0, 0);
4735 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4738 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4741 * For outgoing streams don't report any
4742 * problems in sending the request to the
4743 * application. XXX: Double check resetting
4748 SCTP_TCB_UNLOCK(stcb);
4751 case SCTP_ADD_STREAMS:
4753 struct sctp_add_streams *stradd;
4754 uint8_t addstream = 0;
4755 uint16_t add_o_strmcnt = 0;
4756 uint16_t add_i_strmcnt = 0;
4758 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4759 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4761 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4765 if (stcb->asoc.reconfig_supported == 0) {
4767 * Peer does not support the chunk type.
4769 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4771 SCTP_TCB_UNLOCK(stcb);
4774 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4775 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4777 SCTP_TCB_UNLOCK(stcb);
4780 if (stcb->asoc.stream_reset_outstanding) {
4781 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4783 SCTP_TCB_UNLOCK(stcb);
4786 if ((stradd->sas_outstrms == 0) &&
4787 (stradd->sas_instrms == 0)) {
4791 if (stradd->sas_outstrms) {
4793 /* We allocate here */
4794 add_o_strmcnt = stradd->sas_outstrms;
4795 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4796 /* You can't have more than 64k */
4801 if (stradd->sas_instrms) {
4806 * We allocate inside
4807 * sctp_send_str_reset_req()
4809 add_i_strmcnt = stradd->sas_instrms;
4810 cnt = add_i_strmcnt;
4811 cnt += stcb->asoc.streamincnt;
4812 if (cnt > 0x0000ffff) {
4813 /* You can't have more than 64k */
4817 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4818 /* More than you are allowed */
4823 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4824 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4826 SCTP_TCB_UNLOCK(stcb);
4829 case SCTP_RESET_ASSOC:
4834 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4835 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4837 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4841 if (stcb->asoc.reconfig_supported == 0) {
4843 * Peer does not support the chunk type.
4845 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4847 SCTP_TCB_UNLOCK(stcb);
4850 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4851 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4853 SCTP_TCB_UNLOCK(stcb);
4856 if (stcb->asoc.stream_reset_outstanding) {
4857 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4859 SCTP_TCB_UNLOCK(stcb);
4863 * Is there any data pending in the send or sent
4866 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4867 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4870 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4871 SCTP_TCB_UNLOCK(stcb);
4874 /* Do any streams have data queued? */
4875 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4876 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4880 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4881 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4882 SCTP_TCB_UNLOCK(stcb);
4885 case SCTP_CONNECT_X:
4886 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4891 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4893 case SCTP_CONNECT_X_DELAYED:
4894 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4895 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4899 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4901 case SCTP_CONNECT_X_COMPLETE:
4903 struct sockaddr *sa;
4905 /* FIXME MT: check correct? */
4906 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4909 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4910 SCTP_INP_RLOCK(inp);
4911 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4913 SCTP_TCB_LOCK(stcb);
4915 SCTP_INP_RUNLOCK(inp);
4918 * We increment here since
4919 * sctp_findassociation_ep_addr() wil do a
4920 * decrement if it finds the stcb as long as
4921 * the locked tcb (last argument) is NOT a
4924 SCTP_INP_INCR_REF(inp);
4925 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4927 SCTP_INP_DECR_REF(inp);
4932 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4936 if (stcb->asoc.delayed_connection == 1) {
4937 stcb->asoc.delayed_connection = 0;
4938 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4939 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4940 stcb->asoc.primary_destination,
4941 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4942 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4945 * already expired or did not use delayed
4948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4951 SCTP_TCB_UNLOCK(stcb);
4954 case SCTP_MAX_BURST:
4956 struct sctp_assoc_value *av;
4958 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4959 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4962 stcb->asoc.max_burst = av->assoc_value;
4963 SCTP_TCB_UNLOCK(stcb);
4965 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4966 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4967 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4968 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4969 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4970 SCTP_INP_WLOCK(inp);
4971 inp->sctp_ep.max_burst = av->assoc_value;
4972 SCTP_INP_WUNLOCK(inp);
4974 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4975 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4976 (av->assoc_id == SCTP_ALL_ASSOC))) {
4977 SCTP_INP_RLOCK(inp);
4978 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4979 SCTP_TCB_LOCK(stcb);
4980 stcb->asoc.max_burst = av->assoc_value;
4981 SCTP_TCB_UNLOCK(stcb);
4983 SCTP_INP_RUNLOCK(inp);
4990 struct sctp_assoc_value *av;
4993 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4994 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4996 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4997 ovh = SCTP_MED_OVERHEAD;
4999 ovh = SCTP_MED_V4_OVERHEAD;
5002 if (av->assoc_value) {
5003 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
5005 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
5007 SCTP_TCB_UNLOCK(stcb);
5009 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5010 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5011 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5012 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
5013 SCTP_INP_WLOCK(inp);
5015 * FIXME MT: I think this is not in
5016 * tune with the API ID
5018 if (av->assoc_value) {
5019 inp->sctp_frag_point = (av->assoc_value + ovh);
5021 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
5023 SCTP_INP_WUNLOCK(inp);
5025 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5033 struct sctp_event_subscribe *events;
5035 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5037 SCTP_INP_WLOCK(inp);
5038 if (events->sctp_data_io_event) {
5039 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5041 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5044 if (events->sctp_association_event) {
5045 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5047 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5050 if (events->sctp_address_event) {
5051 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5053 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5056 if (events->sctp_send_failure_event) {
5057 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5059 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5062 if (events->sctp_peer_error_event) {
5063 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5065 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5068 if (events->sctp_shutdown_event) {
5069 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5071 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5074 if (events->sctp_partial_delivery_event) {
5075 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5077 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5080 if (events->sctp_adaptation_layer_event) {
5081 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5083 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5086 if (events->sctp_authentication_event) {
5087 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5089 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5092 if (events->sctp_sender_dry_event) {
5093 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5095 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5098 if (events->sctp_stream_reset_event) {
5099 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5101 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5103 SCTP_INP_WUNLOCK(inp);
5105 SCTP_INP_RLOCK(inp);
5106 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5107 SCTP_TCB_LOCK(stcb);
5108 if (events->sctp_association_event) {
5109 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5111 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5113 if (events->sctp_address_event) {
5114 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5116 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5118 if (events->sctp_send_failure_event) {
5119 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5121 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5123 if (events->sctp_peer_error_event) {
5124 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5126 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5128 if (events->sctp_shutdown_event) {
5129 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5131 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5133 if (events->sctp_partial_delivery_event) {
5134 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5136 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5138 if (events->sctp_adaptation_layer_event) {
5139 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5141 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5143 if (events->sctp_authentication_event) {
5144 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5146 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5148 if (events->sctp_sender_dry_event) {
5149 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5151 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5153 if (events->sctp_stream_reset_event) {
5154 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5156 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5158 SCTP_TCB_UNLOCK(stcb);
5161 * Send up the sender dry event only for 1-to-1
5164 if (events->sctp_sender_dry_event) {
5165 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5166 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5167 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5169 SCTP_TCB_LOCK(stcb);
5170 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5171 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5172 (stcb->asoc.stream_queue_cnt == 0)) {
5173 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5175 SCTP_TCB_UNLOCK(stcb);
5179 SCTP_INP_RUNLOCK(inp);
5182 case SCTP_ADAPTATION_LAYER:
5184 struct sctp_setadaptation *adap_bits;
5186 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5187 SCTP_INP_WLOCK(inp);
5188 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5189 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5190 SCTP_INP_WUNLOCK(inp);
5194 case SCTP_SET_INITIAL_DBG_SEQ:
5198 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5199 SCTP_INP_WLOCK(inp);
5200 inp->sctp_ep.initial_sequence_debug = *vvv;
5201 SCTP_INP_WUNLOCK(inp);
5205 case SCTP_DEFAULT_SEND_PARAM:
5207 struct sctp_sndrcvinfo *s_info;
5209 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5210 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5213 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5214 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5216 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5219 SCTP_TCB_UNLOCK(stcb);
5221 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5222 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5223 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5224 ((s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5225 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)))) {
5226 SCTP_INP_WLOCK(inp);
5227 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5228 SCTP_INP_WUNLOCK(inp);
5230 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5231 ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5232 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC))) {
5233 SCTP_INP_RLOCK(inp);
5234 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5235 SCTP_TCB_LOCK(stcb);
5236 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5237 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5239 SCTP_TCB_UNLOCK(stcb);
5241 SCTP_INP_RUNLOCK(inp);
5246 case SCTP_PEER_ADDR_PARAMS:
5248 struct sctp_paddrparams *paddrp;
5249 struct sctp_nets *net;
5250 struct sockaddr *addr;
5251 #if defined(INET) && defined(INET6)
5252 struct sockaddr_in sin_store;
5255 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5256 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5258 #if defined(INET) && defined(INET6)
5259 if (paddrp->spp_address.ss_family == AF_INET6) {
5260 struct sockaddr_in6 *sin6;
5262 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5263 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5264 in6_sin6_2_sin(&sin_store, sin6);
5265 addr = (struct sockaddr *)&sin_store;
5267 addr = (struct sockaddr *)&paddrp->spp_address;
5270 addr = (struct sockaddr *)&paddrp->spp_address;
5273 addr = (struct sockaddr *)&paddrp->spp_address;
5276 net = sctp_findnet(stcb, addr);
5279 * We increment here since
5280 * sctp_findassociation_ep_addr() wil do a
5281 * decrement if it finds the stcb as long as
5282 * the locked tcb (last argument) is NOT a
5286 SCTP_INP_INCR_REF(inp);
5287 stcb = sctp_findassociation_ep_addr(&inp, addr,
5290 SCTP_INP_DECR_REF(inp);
5293 if ((stcb != NULL) && (net == NULL)) {
5295 if (addr->sa_family == AF_INET) {
5297 struct sockaddr_in *sin;
5299 sin = (struct sockaddr_in *)addr;
5300 if (sin->sin_addr.s_addr != INADDR_ANY) {
5301 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5302 SCTP_TCB_UNLOCK(stcb);
5309 if (addr->sa_family == AF_INET6) {
5310 struct sockaddr_in6 *sin6;
5312 sin6 = (struct sockaddr_in6 *)addr;
5313 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5314 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5315 SCTP_TCB_UNLOCK(stcb);
5322 error = EAFNOSUPPORT;
5323 SCTP_TCB_UNLOCK(stcb);
5324 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5329 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5331 SCTP_TCB_UNLOCK(stcb);
5332 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5336 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5338 SCTP_TCB_UNLOCK(stcb);
5339 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5342 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) &&
5343 ((paddrp->spp_pathmtu < SCTP_SMALLEST_PMTU) ||
5344 (paddrp->spp_pathmtu > SCTP_LARGEST_PMTU))) {
5346 SCTP_TCB_UNLOCK(stcb);
5347 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5352 /************************TCB SPECIFIC SET ******************/
5354 /************************NET SPECIFIC SET ******************/
5355 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5356 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5357 !(net->dest_state & SCTP_ADDR_NOHB)) {
5358 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5359 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5361 net->dest_state |= SCTP_ADDR_NOHB;
5363 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5364 if (paddrp->spp_hbinterval) {
5365 net->heart_beat_delay = paddrp->spp_hbinterval;
5366 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5367 net->heart_beat_delay = 0;
5369 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5370 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5371 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5372 net->dest_state &= ~SCTP_ADDR_NOHB;
5374 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5375 if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
5376 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5377 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5378 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5381 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5382 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5383 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5384 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5386 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5387 net->mtu = paddrp->spp_pathmtu;
5388 switch (net->ro._l_addr.sa.sa_family) {
5391 net->mtu += SCTP_MIN_V4_OVERHEAD;
5396 net->mtu += SCTP_MIN_OVERHEAD;
5402 if (net->mtu < stcb->asoc.smallest_mtu) {
5403 sctp_pathmtu_adjustment(stcb, net->mtu);
5406 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5407 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5408 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5410 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5412 if (paddrp->spp_pathmaxrxt) {
5413 if (net->dest_state & SCTP_ADDR_PF) {
5414 if (net->error_count > paddrp->spp_pathmaxrxt) {
5415 net->dest_state &= ~SCTP_ADDR_PF;
5418 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5419 (net->error_count > net->pf_threshold)) {
5420 net->dest_state |= SCTP_ADDR_PF;
5421 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5422 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5423 stcb->sctp_ep, stcb, net,
5424 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5425 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5428 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5429 if (net->error_count > paddrp->spp_pathmaxrxt) {
5430 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5431 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5434 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5435 net->dest_state |= SCTP_ADDR_REACHABLE;
5436 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5439 net->failure_threshold = paddrp->spp_pathmaxrxt;
5441 if (paddrp->spp_flags & SPP_DSCP) {
5442 net->dscp = paddrp->spp_dscp & 0xfc;
5446 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5447 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5448 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5449 net->flowlabel |= 0x80000000;
5454 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5455 if (paddrp->spp_pathmaxrxt != 0) {
5456 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5457 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5458 if (net->dest_state & SCTP_ADDR_PF) {
5459 if (net->error_count > paddrp->spp_pathmaxrxt) {
5460 net->dest_state &= ~SCTP_ADDR_PF;
5463 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5464 (net->error_count > net->pf_threshold)) {
5465 net->dest_state |= SCTP_ADDR_PF;
5466 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5467 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5468 stcb->sctp_ep, stcb, net,
5469 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5470 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5473 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5474 if (net->error_count > paddrp->spp_pathmaxrxt) {
5475 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5476 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5479 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5480 net->dest_state |= SCTP_ADDR_REACHABLE;
5481 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5484 net->failure_threshold = paddrp->spp_pathmaxrxt;
5488 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5489 if (paddrp->spp_hbinterval != 0) {
5490 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5491 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5492 stcb->asoc.heart_beat_delay = 0;
5494 /* Turn back on the timer */
5495 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5496 if (paddrp->spp_hbinterval != 0) {
5497 net->heart_beat_delay = paddrp->spp_hbinterval;
5498 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5499 net->heart_beat_delay = 0;
5501 if (net->dest_state & SCTP_ADDR_NOHB) {
5502 net->dest_state &= ~SCTP_ADDR_NOHB;
5504 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5505 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5506 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5508 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5510 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5511 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5512 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5513 net->dest_state |= SCTP_ADDR_NOHB;
5514 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5515 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5517 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5521 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5523 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5524 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5525 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5526 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5527 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5529 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5530 net->mtu = paddrp->spp_pathmtu;
5531 switch (net->ro._l_addr.sa.sa_family) {
5534 net->mtu += SCTP_MIN_V4_OVERHEAD;
5539 net->mtu += SCTP_MIN_OVERHEAD;
5545 if (net->mtu < stcb->asoc.smallest_mtu) {
5546 sctp_pathmtu_adjustment(stcb, net->mtu);
5549 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5550 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5552 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5553 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5554 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5555 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5557 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5559 stcb->asoc.default_mtu = 0;
5560 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5562 if (paddrp->spp_flags & SPP_DSCP) {
5563 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5564 net->dscp = paddrp->spp_dscp & 0xfc;
5567 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5568 stcb->asoc.default_dscp |= 0x01;
5571 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5572 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5573 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5574 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5575 net->flowlabel |= 0x80000000;
5578 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5579 stcb->asoc.default_flowlabel |= 0x80000000;
5583 SCTP_TCB_UNLOCK(stcb);
5585 /************************NO TCB, SET TO default stuff ******************/
5586 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5587 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5588 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5589 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
5590 SCTP_INP_WLOCK(inp);
5592 * For the TOS/FLOWLABEL stuff you
5593 * set it with the options on the
5596 if (paddrp->spp_pathmaxrxt != 0) {
5597 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5600 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5601 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5602 else if (paddrp->spp_hbinterval != 0) {
5603 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5604 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5605 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5608 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5609 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5610 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5611 } else if (paddrp->spp_hbinterval) {
5612 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5614 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5615 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5616 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5618 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5619 inp->sctp_ep.default_mtu = 0;
5620 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5621 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5622 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5623 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5625 if (paddrp->spp_flags & SPP_DSCP) {
5626 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5627 inp->sctp_ep.default_dscp |= 0x01;
5630 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5631 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5632 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5633 inp->sctp_ep.default_flowlabel |= 0x80000000;
5637 SCTP_INP_WUNLOCK(inp);
5639 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5647 struct sctp_rtoinfo *srto;
5648 uint32_t new_init, new_min, new_max;
5650 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5651 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5654 if (srto->srto_initial)
5655 new_init = srto->srto_initial;
5657 new_init = stcb->asoc.initial_rto;
5659 new_max = srto->srto_max;
5661 new_max = stcb->asoc.maxrto;
5663 new_min = srto->srto_min;
5665 new_min = stcb->asoc.minrto;
5666 if ((new_min <= new_init) && (new_init <= new_max)) {
5667 stcb->asoc.initial_rto = new_init;
5668 stcb->asoc.maxrto = new_max;
5669 stcb->asoc.minrto = new_min;
5671 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5674 SCTP_TCB_UNLOCK(stcb);
5676 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5677 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5678 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5679 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
5680 SCTP_INP_WLOCK(inp);
5681 if (srto->srto_initial)
5682 new_init = srto->srto_initial;
5684 new_init = inp->sctp_ep.initial_rto;
5686 new_max = srto->srto_max;
5688 new_max = inp->sctp_ep.sctp_maxrto;
5690 new_min = srto->srto_min;
5692 new_min = inp->sctp_ep.sctp_minrto;
5693 if ((new_min <= new_init) && (new_init <= new_max)) {
5694 inp->sctp_ep.initial_rto = new_init;
5695 inp->sctp_ep.sctp_maxrto = new_max;
5696 inp->sctp_ep.sctp_minrto = new_min;
5698 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5701 SCTP_INP_WUNLOCK(inp);
5703 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5709 case SCTP_ASSOCINFO:
5711 struct sctp_assocparams *sasoc;
5713 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5714 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5715 if (sasoc->sasoc_cookie_life) {
5716 /* boundary check the cookie life */
5717 if (sasoc->sasoc_cookie_life < 1000)
5718 sasoc->sasoc_cookie_life = 1000;
5719 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5720 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5724 if (sasoc->sasoc_asocmaxrxt)
5725 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5726 if (sasoc->sasoc_cookie_life) {
5727 stcb->asoc.cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5729 SCTP_TCB_UNLOCK(stcb);
5731 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5732 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5733 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5734 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
5735 SCTP_INP_WLOCK(inp);
5736 if (sasoc->sasoc_asocmaxrxt)
5737 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5738 if (sasoc->sasoc_cookie_life) {
5739 inp->sctp_ep.def_cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5741 SCTP_INP_WUNLOCK(inp);
5743 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5751 struct sctp_initmsg *sinit;
5753 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5754 SCTP_INP_WLOCK(inp);
5755 if (sinit->sinit_num_ostreams)
5756 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5758 if (sinit->sinit_max_instreams)
5759 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5761 if (sinit->sinit_max_attempts)
5762 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5764 if (sinit->sinit_max_init_timeo)
5765 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5766 SCTP_INP_WUNLOCK(inp);
5769 case SCTP_PRIMARY_ADDR:
5771 struct sctp_setprim *spa;
5772 struct sctp_nets *net;
5773 struct sockaddr *addr;
5774 #if defined(INET) && defined(INET6)
5775 struct sockaddr_in sin_store;
5778 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5779 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5781 #if defined(INET) && defined(INET6)
5782 if (spa->ssp_addr.ss_family == AF_INET6) {
5783 struct sockaddr_in6 *sin6;
5785 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5786 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5787 in6_sin6_2_sin(&sin_store, sin6);
5788 addr = (struct sockaddr *)&sin_store;
5790 addr = (struct sockaddr *)&spa->ssp_addr;
5793 addr = (struct sockaddr *)&spa->ssp_addr;
5796 addr = (struct sockaddr *)&spa->ssp_addr;
5799 net = sctp_findnet(stcb, addr);
5802 * We increment here since
5803 * sctp_findassociation_ep_addr() wil do a
5804 * decrement if it finds the stcb as long as
5805 * the locked tcb (last argument) is NOT a
5809 SCTP_INP_INCR_REF(inp);
5810 stcb = sctp_findassociation_ep_addr(&inp, addr,
5813 SCTP_INP_DECR_REF(inp);
5817 if ((stcb != NULL) && (net != NULL)) {
5818 if (net != stcb->asoc.primary_destination) {
5819 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5820 /* Ok we need to set it */
5821 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5822 if ((stcb->asoc.alternate) &&
5823 (!(net->dest_state & SCTP_ADDR_PF)) &&
5824 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5825 sctp_free_remote_addr(stcb->asoc.alternate);
5826 stcb->asoc.alternate = NULL;
5829 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5833 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5838 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5842 SCTP_TCB_UNLOCK(stcb);
5846 case SCTP_SET_DYNAMIC_PRIMARY:
5848 union sctp_sockstore *ss;
5850 error = priv_check(curthread,
5851 PRIV_NETINET_RESERVEDPORT);
5855 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5856 /* SUPER USER CHECK? */
5857 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5860 case SCTP_SET_PEER_PRIMARY_ADDR:
5862 struct sctp_setpeerprim *sspp;
5863 struct sockaddr *addr;
5864 #if defined(INET) && defined(INET6)
5865 struct sockaddr_in sin_store;
5868 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5869 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5871 struct sctp_ifa *ifa;
5873 #if defined(INET) && defined(INET6)
5874 if (sspp->sspp_addr.ss_family == AF_INET6) {
5875 struct sockaddr_in6 *sin6;
5877 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5878 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5879 in6_sin6_2_sin(&sin_store, sin6);
5880 addr = (struct sockaddr *)&sin_store;
5882 addr = (struct sockaddr *)&sspp->sspp_addr;
5885 addr = (struct sockaddr *)&sspp->sspp_addr;
5888 addr = (struct sockaddr *)&sspp->sspp_addr;
5890 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5892 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5896 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5898 * Must validate the ifa found is in
5901 struct sctp_laddr *laddr;
5904 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5905 if (laddr->ifa == NULL) {
5906 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5910 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5911 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5914 if (laddr->ifa == ifa) {
5920 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5925 switch (addr->sa_family) {
5929 struct sockaddr_in *sin;
5931 sin = (struct sockaddr_in *)addr;
5932 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5933 &sin->sin_addr) != 0) {
5934 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5944 struct sockaddr_in6 *sin6;
5946 sin6 = (struct sockaddr_in6 *)addr;
5947 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5948 &sin6->sin6_addr) != 0) {
5949 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5962 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5963 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5966 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5968 SCTP_TCB_UNLOCK(stcb);
5970 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5975 case SCTP_BINDX_ADD_ADDR:
5977 struct sockaddr *sa;
5980 td = (struct thread *)p;
5981 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
5983 if (sa->sa_family == AF_INET) {
5984 if (optsize < sizeof(struct sockaddr_in)) {
5985 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5990 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
5991 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5997 if (sa->sa_family == AF_INET6) {
5998 if (optsize < sizeof(struct sockaddr_in6)) {
5999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6004 (error = prison_local_ip6(td->td_ucred,
6005 &(((struct sockaddr_in6 *)sa)->sin6_addr),
6006 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6007 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6013 error = EAFNOSUPPORT;
6016 sctp_bindx_add_address(so, inp, sa, vrf_id, &error, p);
6019 case SCTP_BINDX_REM_ADDR:
6021 struct sockaddr *sa;
6024 td = (struct thread *)p;
6026 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
6028 if (sa->sa_family == AF_INET) {
6029 if (optsize < sizeof(struct sockaddr_in)) {
6030 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6035 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
6036 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6042 if (sa->sa_family == AF_INET6) {
6043 if (optsize < sizeof(struct sockaddr_in6)) {
6044 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6049 (error = prison_local_ip6(td->td_ucred,
6050 &(((struct sockaddr_in6 *)sa)->sin6_addr),
6051 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6052 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6058 error = EAFNOSUPPORT;
6061 sctp_bindx_delete_address(inp, sa, vrf_id, &error);
6066 struct sctp_event *event;
6067 uint32_t event_type;
6069 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6070 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6071 switch (event->se_type) {
6072 case SCTP_ASSOC_CHANGE:
6073 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6075 case SCTP_PEER_ADDR_CHANGE:
6076 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6078 case SCTP_REMOTE_ERROR:
6079 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6081 case SCTP_SEND_FAILED:
6082 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6084 case SCTP_SHUTDOWN_EVENT:
6085 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6087 case SCTP_ADAPTATION_INDICATION:
6088 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6090 case SCTP_PARTIAL_DELIVERY_EVENT:
6091 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6093 case SCTP_AUTHENTICATION_EVENT:
6094 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6096 case SCTP_STREAM_RESET_EVENT:
6097 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6099 case SCTP_SENDER_DRY_EVENT:
6100 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6102 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6104 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6107 case SCTP_ASSOC_RESET_EVENT:
6108 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6110 case SCTP_STREAM_CHANGE_EVENT:
6111 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6113 case SCTP_SEND_FAILED_EVENT:
6114 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6118 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6122 if (event_type > 0) {
6125 sctp_stcb_feature_on(inp, stcb, event_type);
6126 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6127 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6128 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6129 (stcb->asoc.stream_queue_cnt == 0)) {
6130 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6134 sctp_stcb_feature_off(inp, stcb, event_type);
6136 SCTP_TCB_UNLOCK(stcb);
6139 * We don't want to send up a storm
6140 * of events, so return an error for
6143 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6144 (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6145 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6146 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6147 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6151 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6152 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6153 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6154 ((event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6155 (event->se_assoc_id == SCTP_ALL_ASSOC)))) {
6156 SCTP_INP_WLOCK(inp);
6158 sctp_feature_on(inp, event_type);
6160 sctp_feature_off(inp, event_type);
6162 SCTP_INP_WUNLOCK(inp);
6164 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6165 ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6166 (event->se_assoc_id == SCTP_ALL_ASSOC))) {
6167 SCTP_INP_RLOCK(inp);
6168 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6169 SCTP_TCB_LOCK(stcb);
6171 sctp_stcb_feature_on(inp, stcb, event_type);
6173 sctp_stcb_feature_off(inp, stcb, event_type);
6175 SCTP_TCB_UNLOCK(stcb);
6177 SCTP_INP_RUNLOCK(inp);
6182 SCTP_TCB_UNLOCK(stcb);
6187 case SCTP_RECVRCVINFO:
6191 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6192 SCTP_INP_WLOCK(inp);
6194 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6196 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6198 SCTP_INP_WUNLOCK(inp);
6201 case SCTP_RECVNXTINFO:
6205 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6206 SCTP_INP_WLOCK(inp);
6208 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6210 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6212 SCTP_INP_WUNLOCK(inp);
6215 case SCTP_DEFAULT_SNDINFO:
6217 struct sctp_sndinfo *info;
6220 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6221 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6224 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6225 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6226 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6227 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6228 stcb->asoc.def_send.sinfo_flags |= policy;
6229 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6230 stcb->asoc.def_send.sinfo_context = info->snd_context;
6232 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6235 SCTP_TCB_UNLOCK(stcb);
6237 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6238 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6239 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6240 ((info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6241 (info->snd_assoc_id == SCTP_ALL_ASSOC)))) {
6242 SCTP_INP_WLOCK(inp);
6243 inp->def_send.sinfo_stream = info->snd_sid;
6244 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6245 inp->def_send.sinfo_flags = info->snd_flags;
6246 inp->def_send.sinfo_flags |= policy;
6247 inp->def_send.sinfo_ppid = info->snd_ppid;
6248 inp->def_send.sinfo_context = info->snd_context;
6249 SCTP_INP_WUNLOCK(inp);
6251 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6252 ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6253 (info->snd_assoc_id == SCTP_ALL_ASSOC))) {
6254 SCTP_INP_RLOCK(inp);
6255 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6256 SCTP_TCB_LOCK(stcb);
6257 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6258 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6259 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6260 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6261 stcb->asoc.def_send.sinfo_flags |= policy;
6262 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6263 stcb->asoc.def_send.sinfo_context = info->snd_context;
6265 SCTP_TCB_UNLOCK(stcb);
6267 SCTP_INP_RUNLOCK(inp);
6272 case SCTP_DEFAULT_PRINFO:
6274 struct sctp_default_prinfo *info;
6276 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6277 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6279 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6281 SCTP_TCB_UNLOCK(stcb);
6283 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6288 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6289 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6290 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6291 SCTP_TCB_UNLOCK(stcb);
6293 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6294 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6295 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6296 ((info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6297 (info->pr_assoc_id == SCTP_ALL_ASSOC)))) {
6298 SCTP_INP_WLOCK(inp);
6299 inp->def_send.sinfo_flags &= 0xfff0;
6300 inp->def_send.sinfo_flags |= info->pr_policy;
6301 inp->def_send.sinfo_timetolive = info->pr_value;
6302 SCTP_INP_WUNLOCK(inp);
6304 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6305 ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6306 (info->pr_assoc_id == SCTP_ALL_ASSOC))) {
6307 SCTP_INP_RLOCK(inp);
6308 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6309 SCTP_TCB_LOCK(stcb);
6310 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6311 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6312 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6313 SCTP_TCB_UNLOCK(stcb);
6315 SCTP_INP_RUNLOCK(inp);
6320 case SCTP_PEER_ADDR_THLDS:
6321 /* Applies to the specific association */
6323 struct sctp_paddrthlds *thlds;
6324 struct sctp_nets *net;
6325 struct sockaddr *addr;
6326 #if defined(INET) && defined(INET6)
6327 struct sockaddr_in sin_store;
6330 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6331 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6333 #if defined(INET) && defined(INET6)
6334 if (thlds->spt_address.ss_family == AF_INET6) {
6335 struct sockaddr_in6 *sin6;
6337 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6338 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6339 in6_sin6_2_sin(&sin_store, sin6);
6340 addr = (struct sockaddr *)&sin_store;
6342 addr = (struct sockaddr *)&thlds->spt_address;
6345 addr = (struct sockaddr *)&thlds->spt_address;
6348 addr = (struct sockaddr *)&thlds->spt_address;
6351 net = sctp_findnet(stcb, addr);
6354 * We increment here since
6355 * sctp_findassociation_ep_addr() wil do a
6356 * decrement if it finds the stcb as long as
6357 * the locked tcb (last argument) is NOT a
6361 SCTP_INP_INCR_REF(inp);
6362 stcb = sctp_findassociation_ep_addr(&inp, addr,
6365 SCTP_INP_DECR_REF(inp);
6368 if ((stcb != NULL) && (net == NULL)) {
6370 if (addr->sa_family == AF_INET) {
6372 struct sockaddr_in *sin;
6374 sin = (struct sockaddr_in *)addr;
6375 if (sin->sin_addr.s_addr != INADDR_ANY) {
6376 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6377 SCTP_TCB_UNLOCK(stcb);
6384 if (addr->sa_family == AF_INET6) {
6385 struct sockaddr_in6 *sin6;
6387 sin6 = (struct sockaddr_in6 *)addr;
6388 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6389 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6390 SCTP_TCB_UNLOCK(stcb);
6397 error = EAFNOSUPPORT;
6398 SCTP_TCB_UNLOCK(stcb);
6399 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6403 if (thlds->spt_pathcpthld != 0xffff) {
6405 SCTP_TCB_UNLOCK(stcb);
6408 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6413 net->failure_threshold = thlds->spt_pathmaxrxt;
6414 net->pf_threshold = thlds->spt_pathpfthld;
6415 if (net->dest_state & SCTP_ADDR_PF) {
6416 if ((net->error_count > net->failure_threshold) ||
6417 (net->error_count <= net->pf_threshold)) {
6418 net->dest_state &= ~SCTP_ADDR_PF;
6421 if ((net->error_count > net->pf_threshold) &&
6422 (net->error_count <= net->failure_threshold)) {
6423 net->dest_state |= SCTP_ADDR_PF;
6424 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6425 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6426 stcb->sctp_ep, stcb, net,
6427 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6428 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6431 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6432 if (net->error_count > net->failure_threshold) {
6433 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6434 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6437 if (net->error_count <= net->failure_threshold) {
6438 net->dest_state |= SCTP_ADDR_REACHABLE;
6439 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6443 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6444 net->failure_threshold = thlds->spt_pathmaxrxt;
6445 net->pf_threshold = thlds->spt_pathpfthld;
6446 if (net->dest_state & SCTP_ADDR_PF) {
6447 if ((net->error_count > net->failure_threshold) ||
6448 (net->error_count <= net->pf_threshold)) {
6449 net->dest_state &= ~SCTP_ADDR_PF;
6452 if ((net->error_count > net->pf_threshold) &&
6453 (net->error_count <= net->failure_threshold)) {
6454 net->dest_state |= SCTP_ADDR_PF;
6455 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6456 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6457 stcb->sctp_ep, stcb, net,
6458 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6459 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6462 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6463 if (net->error_count > net->failure_threshold) {
6464 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6465 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6468 if (net->error_count <= net->failure_threshold) {
6469 net->dest_state |= SCTP_ADDR_REACHABLE;
6470 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6474 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6475 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6477 SCTP_TCB_UNLOCK(stcb);
6479 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6480 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6481 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6482 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
6483 SCTP_INP_WLOCK(inp);
6484 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6485 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6486 SCTP_INP_WUNLOCK(inp);
6488 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6494 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6496 struct sctp_udpencaps *encaps;
6497 struct sctp_nets *net;
6498 struct sockaddr *addr;
6499 #if defined(INET) && defined(INET6)
6500 struct sockaddr_in sin_store;
6503 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6504 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6506 #if defined(INET) && defined(INET6)
6507 if (encaps->sue_address.ss_family == AF_INET6) {
6508 struct sockaddr_in6 *sin6;
6510 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6511 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6512 in6_sin6_2_sin(&sin_store, sin6);
6513 addr = (struct sockaddr *)&sin_store;
6515 addr = (struct sockaddr *)&encaps->sue_address;
6518 addr = (struct sockaddr *)&encaps->sue_address;
6521 addr = (struct sockaddr *)&encaps->sue_address;
6524 net = sctp_findnet(stcb, addr);
6527 * We increment here since
6528 * sctp_findassociation_ep_addr() wil do a
6529 * decrement if it finds the stcb as long as
6530 * the locked tcb (last argument) is NOT a
6534 SCTP_INP_INCR_REF(inp);
6535 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6537 SCTP_INP_DECR_REF(inp);
6540 if ((stcb != NULL) && (net == NULL)) {
6542 if (addr->sa_family == AF_INET) {
6544 struct sockaddr_in *sin;
6546 sin = (struct sockaddr_in *)addr;
6547 if (sin->sin_addr.s_addr != INADDR_ANY) {
6548 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6549 SCTP_TCB_UNLOCK(stcb);
6556 if (addr->sa_family == AF_INET6) {
6557 struct sockaddr_in6 *sin6;
6559 sin6 = (struct sockaddr_in6 *)addr;
6560 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6561 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6562 SCTP_TCB_UNLOCK(stcb);
6569 error = EAFNOSUPPORT;
6570 SCTP_TCB_UNLOCK(stcb);
6571 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6578 net->port = encaps->sue_port;
6580 stcb->asoc.port = encaps->sue_port;
6582 SCTP_TCB_UNLOCK(stcb);
6584 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6585 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6586 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6587 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
6588 SCTP_INP_WLOCK(inp);
6589 inp->sctp_ep.port = encaps->sue_port;
6590 SCTP_INP_WUNLOCK(inp);
6592 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6598 case SCTP_ECN_SUPPORTED:
6600 struct sctp_assoc_value *av;
6602 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6603 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6606 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6608 SCTP_TCB_UNLOCK(stcb);
6610 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6611 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6612 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6613 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6614 SCTP_INP_WLOCK(inp);
6615 if (av->assoc_value == 0) {
6616 inp->ecn_supported = 0;
6618 inp->ecn_supported = 1;
6620 SCTP_INP_WUNLOCK(inp);
6622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6628 case SCTP_PR_SUPPORTED:
6630 struct sctp_assoc_value *av;
6632 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6633 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6636 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6638 SCTP_TCB_UNLOCK(stcb);
6640 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6641 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6642 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6643 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6644 SCTP_INP_WLOCK(inp);
6645 if (av->assoc_value == 0) {
6646 inp->prsctp_supported = 0;
6648 inp->prsctp_supported = 1;
6650 SCTP_INP_WUNLOCK(inp);
6652 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6658 case SCTP_AUTH_SUPPORTED:
6660 struct sctp_assoc_value *av;
6662 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6663 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6668 SCTP_TCB_UNLOCK(stcb);
6670 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6671 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6672 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6673 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6674 if ((av->assoc_value == 0) &&
6675 (inp->asconf_supported == 1)) {
6677 * AUTH is required for
6680 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6683 SCTP_INP_WLOCK(inp);
6684 if (av->assoc_value == 0) {
6685 inp->auth_supported = 0;
6687 inp->auth_supported = 1;
6689 SCTP_INP_WUNLOCK(inp);
6692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6698 case SCTP_ASCONF_SUPPORTED:
6700 struct sctp_assoc_value *av;
6702 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6703 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6706 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6708 SCTP_TCB_UNLOCK(stcb);
6710 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6711 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6712 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6713 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6714 if ((av->assoc_value != 0) &&
6715 (inp->auth_supported == 0)) {
6717 * AUTH is required for
6720 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6723 SCTP_INP_WLOCK(inp);
6724 if (av->assoc_value == 0) {
6725 inp->asconf_supported = 0;
6726 sctp_auth_delete_chunk(SCTP_ASCONF,
6727 inp->sctp_ep.local_auth_chunks);
6728 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6729 inp->sctp_ep.local_auth_chunks);
6731 inp->asconf_supported = 1;
6732 sctp_auth_add_chunk(SCTP_ASCONF,
6733 inp->sctp_ep.local_auth_chunks);
6734 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6735 inp->sctp_ep.local_auth_chunks);
6737 SCTP_INP_WUNLOCK(inp);
6740 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6746 case SCTP_RECONFIG_SUPPORTED:
6748 struct sctp_assoc_value *av;
6750 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6751 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6754 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6756 SCTP_TCB_UNLOCK(stcb);
6758 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6759 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6760 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6761 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6762 SCTP_INP_WLOCK(inp);
6763 if (av->assoc_value == 0) {
6764 inp->reconfig_supported = 0;
6766 inp->reconfig_supported = 1;
6768 SCTP_INP_WUNLOCK(inp);
6770 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6776 case SCTP_NRSACK_SUPPORTED:
6778 struct sctp_assoc_value *av;
6780 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6781 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6784 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6786 SCTP_TCB_UNLOCK(stcb);
6788 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6789 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6790 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6791 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6792 SCTP_INP_WLOCK(inp);
6793 if (av->assoc_value == 0) {
6794 inp->nrsack_supported = 0;
6796 inp->nrsack_supported = 1;
6798 SCTP_INP_WUNLOCK(inp);
6800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6806 case SCTP_PKTDROP_SUPPORTED:
6808 struct sctp_assoc_value *av;
6810 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6811 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6814 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6816 SCTP_TCB_UNLOCK(stcb);
6818 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6819 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6820 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6821 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6822 SCTP_INP_WLOCK(inp);
6823 if (av->assoc_value == 0) {
6824 inp->pktdrop_supported = 0;
6826 inp->pktdrop_supported = 1;
6828 SCTP_INP_WUNLOCK(inp);
6830 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6838 struct sctp_assoc_value *av;
6839 struct sctp_nets *net;
6841 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6842 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6845 stcb->asoc.max_cwnd = av->assoc_value;
6846 if (stcb->asoc.max_cwnd > 0) {
6847 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6848 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6849 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6850 net->cwnd = stcb->asoc.max_cwnd;
6851 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6852 net->cwnd = net->mtu - sizeof(struct sctphdr);
6857 SCTP_TCB_UNLOCK(stcb);
6859 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6860 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6861 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6862 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6863 SCTP_INP_WLOCK(inp);
6864 inp->max_cwnd = av->assoc_value;
6865 SCTP_INP_WUNLOCK(inp);
6867 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6874 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6875 error = ENOPROTOOPT;
6877 } /* end switch (opt) */
6882 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6884 void *optval = NULL;
6888 struct sctp_inpcb *inp;
6890 if ((sopt->sopt_level == SOL_SOCKET) &&
6891 (sopt->sopt_name == SO_SETFIB)) {
6892 inp = (struct sctp_inpcb *)so->so_pcb;
6894 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6897 SCTP_INP_WLOCK(inp);
6898 inp->fibnum = so->so_fibnum;
6899 SCTP_INP_WUNLOCK(inp);
6902 if (sopt->sopt_level != IPPROTO_SCTP) {
6903 /* wrong proto level... send back up to IP */
6905 if (INP_CHECK_SOCKAF(so, AF_INET6))
6906 error = ip6_ctloutput(so, sopt);
6908 #if defined(INET) && defined(INET6)
6912 error = ip_ctloutput(so, sopt);
6916 optsize = sopt->sopt_valsize;
6917 if (optsize > SCTP_SOCKET_OPTION_LIMIT) {
6918 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6922 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6923 if (optval == NULL) {
6924 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6927 error = sooptcopyin(sopt, optval, optsize, optsize);
6929 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6933 p = (void *)sopt->sopt_td;
6934 if (sopt->sopt_dir == SOPT_SET) {
6935 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6936 } else if (sopt->sopt_dir == SOPT_GET) {
6937 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6939 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6942 if ((error == 0) && (optval != NULL)) {
6943 error = sooptcopyout(sopt, optval, optsize);
6944 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6945 } else if (optval != NULL) {
6946 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6954 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6957 int create_lock_on = 0;
6959 struct sctp_inpcb *inp;
6960 struct sctp_tcb *stcb = NULL;
6962 inp = (struct sctp_inpcb *)so->so_pcb;
6964 /* I made the same as TCP since we are not setup? */
6965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6966 return (ECONNRESET);
6969 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6973 switch (addr->sa_family) {
6977 struct sockaddr_in6 *sin6;
6979 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6980 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6983 sin6 = (struct sockaddr_in6 *)addr;
6984 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6->sin6_addr)) != 0) {
6985 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6994 struct sockaddr_in *sin;
6996 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6997 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7000 sin = (struct sockaddr_in *)addr;
7001 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sin->sin_addr)) != 0) {
7002 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7009 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
7010 return (EAFNOSUPPORT);
7012 SCTP_INP_INCR_REF(inp);
7013 SCTP_ASOC_CREATE_LOCK(inp);
7017 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
7018 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
7019 /* Should I really unlock ? */
7020 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
7025 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
7026 (addr->sa_family == AF_INET6)) {
7027 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7032 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
7033 SCTP_PCB_FLAGS_UNBOUND) {
7034 /* Bind a ephemeral port */
7035 error = sctp_inpcb_bind(so, NULL, NULL, p);
7040 /* Now do we connect? */
7041 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
7042 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
7043 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7047 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7048 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7049 /* We are already connected AND the TCP model */
7050 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7054 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7055 SCTP_INP_RLOCK(inp);
7056 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7057 SCTP_INP_RUNLOCK(inp);
7060 * We increment here since sctp_findassociation_ep_addr()
7061 * will do a decrement if it finds the stcb as long as the
7062 * locked tcb (last argument) is NOT a TCB.. aka NULL.
7064 SCTP_INP_INCR_REF(inp);
7065 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7067 SCTP_INP_DECR_REF(inp);
7069 SCTP_TCB_UNLOCK(stcb);
7073 /* Already have or am bring up an association */
7074 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7079 vrf_id = inp->def_vrf_id;
7080 /* We are GOOD to go */
7081 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
7082 inp->sctp_ep.pre_open_stream_count,
7083 inp->sctp_ep.port, p,
7084 SCTP_INITIALIZE_AUTH_PARAMS);
7086 /* Gak! no memory */
7089 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7090 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7091 /* Set the connected flag so we can queue data */
7094 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7095 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7097 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7098 SCTP_TCB_UNLOCK(stcb);
7100 if (create_lock_on) {
7101 SCTP_ASOC_CREATE_UNLOCK(inp);
7104 SCTP_INP_DECR_REF(inp);
7110 sctp_listen(struct socket *so, int backlog, struct thread *p)
7113 * Note this module depends on the protocol processing being called
7114 * AFTER any socket level flags and backlog are applied to the
7115 * socket. The traditional way that the socket flags are applied is
7116 * AFTER protocol processing. We have made a change to the
7117 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7118 * place if the socket API for SCTP is to work properly.
7122 struct sctp_inpcb *inp;
7124 inp = (struct sctp_inpcb *)so->so_pcb;
7126 /* I made the same as TCP since we are not setup? */
7127 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7128 return (ECONNRESET);
7130 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7131 /* See if we have a listener */
7132 struct sctp_inpcb *tinp;
7133 union sctp_sockstore store;
7135 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7137 struct sctp_laddr *laddr;
7139 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7140 memcpy(&store, &laddr->ifa->address, sizeof(store));
7141 switch (store.sa.sa_family) {
7144 store.sin.sin_port = inp->sctp_lport;
7149 store.sin6.sin6_port = inp->sctp_lport;
7155 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7156 if (tinp && (tinp != inp) &&
7157 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7158 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7159 (SCTP_IS_LISTENING(tinp))) {
7161 * we have a listener already and
7164 SCTP_INP_DECR_REF(tinp);
7165 return (EADDRINUSE);
7167 SCTP_INP_DECR_REF(tinp);
7171 /* Setup a local addr bound all */
7172 memset(&store, 0, sizeof(store));
7174 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7175 store.sa.sa_family = AF_INET6;
7176 store.sa.sa_len = sizeof(struct sockaddr_in6);
7180 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7181 store.sa.sa_family = AF_INET;
7182 store.sa.sa_len = sizeof(struct sockaddr_in);
7185 switch (store.sa.sa_family) {
7188 store.sin.sin_port = inp->sctp_lport;
7193 store.sin6.sin6_port = inp->sctp_lport;
7199 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7200 if (tinp && (tinp != inp) &&
7201 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7202 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7203 (SCTP_IS_LISTENING(tinp))) {
7205 * we have a listener already and its not
7208 SCTP_INP_DECR_REF(tinp);
7209 return (EADDRINUSE);
7211 SCTP_INP_DECR_REF(tinp);
7215 SCTP_INP_RLOCK(inp);
7216 #ifdef SCTP_LOCK_LOGGING
7217 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7218 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7222 error = solisten_proto_check(so);
7225 SCTP_INP_RUNLOCK(inp);
7228 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7229 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7231 * The unlucky case - We are in the tcp pool with this guy.
7232 * - Someone else is in the main inp slot. - We must move
7233 * this guy (the listener) to the main slot - We must then
7234 * move the guy that was listener to the TCP Pool.
7236 if (sctp_swap_inpcb_for_listen(inp)) {
7237 SCTP_INP_RUNLOCK(inp);
7238 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7239 return (EADDRINUSE);
7243 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7244 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7245 /* We are already connected AND the TCP model */
7246 SCTP_INP_RUNLOCK(inp);
7247 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7248 return (EADDRINUSE);
7250 SCTP_INP_RUNLOCK(inp);
7251 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7252 /* We must do a bind. */
7253 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7254 /* bind error, probably perm */
7258 SCTP_INP_WLOCK(inp);
7259 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7261 solisten_proto(so, backlog);
7265 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7267 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7269 SCTP_INP_WUNLOCK(inp);
7273 static int sctp_defered_wakeup_cnt = 0;
7276 sctp_accept(struct socket *so, struct sockaddr **addr)
7278 struct sctp_tcb *stcb;
7279 struct sctp_inpcb *inp;
7280 union sctp_sockstore store;
7284 inp = (struct sctp_inpcb *)so->so_pcb;
7287 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7288 return (ECONNRESET);
7290 SCTP_INP_WLOCK(inp);
7291 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7292 SCTP_INP_WUNLOCK(inp);
7293 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7294 return (EOPNOTSUPP);
7296 if (so->so_state & SS_ISDISCONNECTED) {
7297 SCTP_INP_WUNLOCK(inp);
7298 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7299 return (ECONNABORTED);
7301 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7303 SCTP_INP_WUNLOCK(inp);
7304 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7305 return (ECONNRESET);
7307 SCTP_TCB_LOCK(stcb);
7308 store = stcb->asoc.primary_destination->ro._l_addr;
7309 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7310 /* Wake any delayed sleep action */
7311 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7312 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7313 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7314 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7315 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7316 if (sowriteable(inp->sctp_socket)) {
7317 sowwakeup_locked(inp->sctp_socket);
7319 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7322 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7323 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7324 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7325 if (soreadable(inp->sctp_socket)) {
7326 sctp_defered_wakeup_cnt++;
7327 sorwakeup_locked(inp->sctp_socket);
7329 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7333 SCTP_INP_WUNLOCK(inp);
7334 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7335 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7336 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7338 SCTP_TCB_UNLOCK(stcb);
7340 switch (store.sa.sa_family) {
7344 struct sockaddr_in *sin;
7346 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7349 sin->sin_family = AF_INET;
7350 sin->sin_len = sizeof(*sin);
7351 sin->sin_port = store.sin.sin_port;
7352 sin->sin_addr = store.sin.sin_addr;
7353 *addr = (struct sockaddr *)sin;
7360 struct sockaddr_in6 *sin6;
7362 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7365 sin6->sin6_family = AF_INET6;
7366 sin6->sin6_len = sizeof(*sin6);
7367 sin6->sin6_port = store.sin6.sin6_port;
7368 sin6->sin6_addr = store.sin6.sin6_addr;
7369 if ((error = sa6_recoverscope(sin6)) != 0) {
7370 SCTP_FREE_SONAME(sin6);
7373 *addr = (struct sockaddr *)sin6;
7386 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7388 struct sockaddr_in *sin;
7390 struct sctp_inpcb *inp;
7391 struct sctp_ifa *sctp_ifa;
7394 * Do the malloc first in case it blocks.
7396 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7399 sin->sin_family = AF_INET;
7400 sin->sin_len = sizeof(*sin);
7401 inp = (struct sctp_inpcb *)so->so_pcb;
7403 SCTP_FREE_SONAME(sin);
7404 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7405 return (ECONNRESET);
7407 SCTP_INP_RLOCK(inp);
7408 sin->sin_port = inp->sctp_lport;
7409 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7410 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7411 struct sctp_tcb *stcb;
7412 struct sockaddr_in *sin_a;
7413 struct sctp_nets *net;
7416 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7422 SCTP_TCB_LOCK(stcb);
7423 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7424 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7426 /* this will make coverity happy */
7429 if (sin_a->sin_family == AF_INET) {
7434 if ((!fnd) || (sin_a == NULL)) {
7436 SCTP_TCB_UNLOCK(stcb);
7440 vrf_id = inp->def_vrf_id;
7441 sctp_ifa = sctp_source_address_selection(inp,
7443 (sctp_route_t *)&net->ro,
7446 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7447 sctp_free_ifa(sctp_ifa);
7449 SCTP_TCB_UNLOCK(stcb);
7451 /* For the bound all case you get back 0 */
7453 sin->sin_addr.s_addr = 0;
7457 /* Take the first IPv4 address in the list */
7458 struct sctp_laddr *laddr;
7461 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7462 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7463 struct sockaddr_in *sin_a;
7465 sin_a = &laddr->ifa->address.sin;
7466 sin->sin_addr = sin_a->sin_addr;
7472 SCTP_FREE_SONAME(sin);
7473 SCTP_INP_RUNLOCK(inp);
7474 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7478 SCTP_INP_RUNLOCK(inp);
7479 (*addr) = (struct sockaddr *)sin;
7484 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7486 struct sockaddr_in *sin;
7488 struct sockaddr_in *sin_a;
7489 struct sctp_inpcb *inp;
7490 struct sctp_tcb *stcb;
7491 struct sctp_nets *net;
7493 /* Do the malloc first in case it blocks. */
7494 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7497 sin->sin_family = AF_INET;
7498 sin->sin_len = sizeof(*sin);
7500 inp = (struct sctp_inpcb *)so->so_pcb;
7501 if ((inp == NULL) ||
7502 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7503 /* UDP type and listeners will drop out here */
7504 SCTP_FREE_SONAME(sin);
7505 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7508 SCTP_INP_RLOCK(inp);
7509 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7511 SCTP_TCB_LOCK(stcb);
7513 SCTP_INP_RUNLOCK(inp);
7515 SCTP_FREE_SONAME(sin);
7516 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7517 return (ECONNRESET);
7520 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7521 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7522 if (sin_a->sin_family == AF_INET) {
7524 sin->sin_port = stcb->rport;
7525 sin->sin_addr = sin_a->sin_addr;
7529 SCTP_TCB_UNLOCK(stcb);
7531 /* No IPv4 address */
7532 SCTP_FREE_SONAME(sin);
7533 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7536 (*addr) = (struct sockaddr *)sin;
7540 struct pr_usrreqs sctp_usrreqs = {
7541 .pru_abort = sctp_abort,
7542 .pru_accept = sctp_accept,
7543 .pru_attach = sctp_attach,
7544 .pru_bind = sctp_bind,
7545 .pru_connect = sctp_connect,
7546 .pru_control = in_control,
7547 .pru_close = sctp_close,
7548 .pru_detach = sctp_close,
7549 .pru_sopoll = sopoll_generic,
7550 .pru_flush = sctp_flush,
7551 .pru_disconnect = sctp_disconnect,
7552 .pru_listen = sctp_listen,
7553 .pru_peeraddr = sctp_peeraddr,
7554 .pru_send = sctp_sendm,
7555 .pru_shutdown = sctp_shutdown,
7556 .pru_sockaddr = sctp_ingetaddr,
7557 .pru_sosend = sctp_sosend,
7558 .pru_soreceive = sctp_soreceive