2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
5 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
6 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * a) Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
14 * b) Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the distribution.
18 * c) Neither the name of Cisco Systems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <netinet/sctp_os.h>
40 #include <netinet/sctp_pcb.h>
41 #include <netinet/sctp_header.h>
42 #include <netinet/sctp_var.h>
44 #include <netinet6/sctp6_var.h>
46 #include <netinet/sctp_sysctl.h>
47 #include <netinet/sctp_output.h>
48 #include <netinet/sctp_uio.h>
49 #include <netinet/sctp_asconf.h>
50 #include <netinet/sctputil.h>
51 #include <netinet/sctp_indata.h>
52 #include <netinet/sctp_timer.h>
53 #include <netinet/sctp_auth.h>
54 #include <netinet/sctp_bsd_addr.h>
55 #include <netinet/udp.h>
56 #include <sys/eventhandler.h>
58 extern const struct sctp_cc_functions sctp_cc_functions[];
59 extern const struct sctp_ss_functions sctp_ss_functions[];
66 /* Initialize and modify the sysctled variables */
68 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
69 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
71 * Allow a user to take no more than 1/2 the number of clusters or
72 * the SB_MAX, whichever is smaller, for the send window.
74 sb_max_adj = (u_long)((u_quad_t)(SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
75 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
76 (((uint32_t)nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
78 * Now for the recv window, should we take the same amount? or
79 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
80 * now I will just copy.
82 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
83 SCTP_BASE_VAR(first_time) = 0;
84 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
86 #if defined(SCTP_PACKET_LOGGING)
87 SCTP_BASE_VAR(packet_log_writers) = 0;
88 SCTP_BASE_VAR(packet_log_end) = 0;
89 memset(&SCTP_BASE_VAR(packet_log_buffer), 0, SCTP_PACKET_LOG_SIZE);
91 SCTP_BASE_VAR(eh_tag) = EVENTHANDLER_REGISTER(rt_addrmsg,
92 sctp_addr_change_event_handler, NULL, EVENTHANDLER_PRI_FIRST);
97 sctp_finish(void *unused __unused)
99 EVENTHANDLER_DEREGISTER(rt_addrmsg, SCTP_BASE_VAR(eh_tag));
103 VNET_SYSUNINIT(sctp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, sctp_finish, NULL);
107 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
109 struct sctp_tmit_chunk *chk;
112 /* Adjust that too */
113 stcb->asoc.smallest_mtu = nxtsz;
114 /* now off to subtract IP_DF flag if needed */
115 overhead = IP_HDR_SIZE + sizeof(struct sctphdr);
116 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
117 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
119 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
120 if ((chk->send_size + overhead) > nxtsz) {
121 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
124 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
125 if ((chk->send_size + overhead) > nxtsz) {
127 * For this guy we also mark for immediate resend
128 * since we sent to big of chunk
130 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
131 if (chk->sent < SCTP_DATAGRAM_RESEND) {
132 sctp_flight_size_decrease(chk);
133 sctp_total_flight_decrease(stcb, chk);
134 chk->sent = SCTP_DATAGRAM_RESEND;
135 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
136 chk->rec.data.doing_fast_retransmit = 0;
137 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
138 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
139 chk->whoTo->flight_size,
141 (uint32_t)(uintptr_t)chk->whoTo,
144 /* Clear any time so NO RTT is being done */
145 if (chk->do_rtt == 1) {
147 chk->whoTo->rto_needed = 1;
156 sctp_notify(struct sctp_inpcb *inp,
157 struct sctp_tcb *stcb,
158 struct sctp_nets *net,
166 if (icmp_type != ICMP_UNREACH) {
167 /* We only care about unreachable */
168 SCTP_TCB_UNLOCK(stcb);
171 if ((icmp_code == ICMP_UNREACH_NET) ||
172 (icmp_code == ICMP_UNREACH_HOST) ||
173 (icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
174 (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
175 (icmp_code == ICMP_UNREACH_ISOLATED) ||
176 (icmp_code == ICMP_UNREACH_NET_PROHIB) ||
177 (icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
178 (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
179 /* Mark the net unreachable. */
180 if (net->dest_state & SCTP_ADDR_REACHABLE) {
181 /* OK, that destination is NOT reachable. */
182 net->dest_state &= ~SCTP_ADDR_REACHABLE;
183 net->dest_state &= ~SCTP_ADDR_PF;
184 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
186 (void *)net, SCTP_SO_NOT_LOCKED);
188 SCTP_TCB_UNLOCK(stcb);
189 } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) ||
190 (icmp_code == ICMP_UNREACH_PORT)) {
191 /* Treat it like an ABORT. */
192 sctp_abort_notification(stcb, true, false, 0, NULL, SCTP_SO_NOT_LOCKED);
193 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
194 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
195 /* no need to unlock here, since the TCB is gone */
196 } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) {
197 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
198 SCTP_TCB_UNLOCK(stcb);
201 /* Find the next (smaller) MTU */
204 * Old type router that does not tell us what the
205 * next MTU is. Rats we will have to guess (in a
206 * educated fashion of course).
208 next_mtu = sctp_get_prev_mtu(ip_len);
210 /* Stop the PMTU timer. */
211 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
213 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
214 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
218 /* Update the path MTU. */
220 next_mtu -= sizeof(struct udphdr);
222 if (net->mtu > next_mtu) {
225 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu + sizeof(struct udphdr));
227 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu);
230 /* Update the association MTU */
231 if (stcb->asoc.smallest_mtu > next_mtu) {
232 sctp_pathmtu_adjustment(stcb, next_mtu);
234 /* Finally, start the PMTU timer if it was running before. */
236 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
238 SCTP_TCB_UNLOCK(stcb);
240 SCTP_TCB_UNLOCK(stcb);
245 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
251 struct sctp_inpcb *inp;
252 struct sctp_tcb *stcb;
253 struct sctp_nets *net;
254 struct sctp_init_chunk *ch;
255 struct sockaddr_in src, dst;
257 if (sa->sa_family != AF_INET ||
258 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
261 if (PRC_IS_REDIRECT(cmd)) {
263 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
267 inner_ip = (struct ip *)vip;
268 icmp = (struct icmp *)((caddr_t)inner_ip -
269 (sizeof(struct icmp) - sizeof(struct ip)));
270 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
271 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
272 memset(&src, 0, sizeof(struct sockaddr_in));
273 src.sin_family = AF_INET;
274 src.sin_len = sizeof(struct sockaddr_in);
275 src.sin_port = sh->src_port;
276 src.sin_addr = inner_ip->ip_src;
277 memset(&dst, 0, sizeof(struct sockaddr_in));
278 dst.sin_family = AF_INET;
279 dst.sin_len = sizeof(struct sockaddr_in);
280 dst.sin_port = sh->dest_port;
281 dst.sin_addr = inner_ip->ip_dst;
283 * 'dst' holds the dest of the packet that failed to be
284 * sent. 'src' holds our local endpoint address. Thus we
285 * reverse the dst and the src in the lookup.
289 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
290 (struct sockaddr *)&src,
293 if ((stcb != NULL) &&
296 /* Check the verification tag */
297 if (ntohl(sh->v_tag) != 0) {
299 * This must be the verification tag used
300 * for sending out packets. We don't
301 * consider packets reflecting the
304 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
305 SCTP_TCB_UNLOCK(stcb);
309 if (ntohs(outer_ip->ip_len) >=
311 8 + (inner_ip->ip_hl << 2) + 20) {
313 * In this case we can check if we
314 * got an INIT chunk and if the
315 * initiate tag matches.
317 ch = (struct sctp_init_chunk *)(sh + 1);
318 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
319 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
320 SCTP_TCB_UNLOCK(stcb);
324 SCTP_TCB_UNLOCK(stcb);
328 sctp_notify(inp, stcb, net,
331 ntohs(inner_ip->ip_len),
332 (uint32_t)ntohs(icmp->icmp_nextmtu));
334 if ((stcb == NULL) && (inp != NULL)) {
335 /* reduce ref-count */
337 SCTP_INP_DECR_REF(inp);
338 SCTP_INP_WUNLOCK(inp);
341 SCTP_TCB_UNLOCK(stcb);
350 sctp_getcred(SYSCTL_HANDLER_ARGS)
353 struct sockaddr_in addrs[2];
354 struct sctp_inpcb *inp;
355 struct sctp_nets *net;
356 struct sctp_tcb *stcb;
360 /* FIX, for non-bsd is this right? */
361 vrf_id = SCTP_DEFAULT_VRFID;
363 error = priv_check(req->td, PRIV_NETINET_GETCRED);
368 error = SYSCTL_IN(req, addrs, sizeof(addrs));
372 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
374 &inp, &net, 1, vrf_id);
375 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
376 if ((inp != NULL) && (stcb == NULL)) {
377 /* reduce ref-count */
379 SCTP_INP_DECR_REF(inp);
383 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
387 SCTP_TCB_UNLOCK(stcb);
389 * We use the write lock here, only since in the error leg we need
390 * it. If we used RLOCK, then we would have to
391 * wlock/decr/unlock/rlock. Which in theory could create a hole.
392 * Better to use higher wlock.
396 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
398 SCTP_INP_WUNLOCK(inp);
401 cru2x(inp->sctp_socket->so_cred, &xuc);
402 SCTP_INP_WUNLOCK(inp);
403 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
408 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred,
409 CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
410 0, 0, sctp_getcred, "S,ucred",
411 "Get the ucred of a SCTP connection");
415 sctp_abort(struct socket *so)
417 struct epoch_tracker et;
418 struct sctp_inpcb *inp;
420 inp = (struct sctp_inpcb *)so->so_pcb;
427 #ifdef SCTP_LOG_CLOSING
428 sctp_log_closing(inp, NULL, 17);
430 if (((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0)) {
431 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP;
432 #ifdef SCTP_LOG_CLOSING
433 sctp_log_closing(inp, NULL, 16);
435 SCTP_INP_WUNLOCK(inp);
436 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
437 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
439 SCTP_SB_CLEAR(so->so_snd);
441 * same for the rcv ones, they are only here for the
444 SCTP_SB_CLEAR(so->so_rcv);
446 /* Now null out the reference, we are completely detached. */
450 SCTP_INP_WUNLOCK(inp);
456 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
458 struct sctp_inpcb *inp;
459 struct inpcb *ip_inp;
461 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
463 inp = (struct sctp_inpcb *)so->so_pcb;
465 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
468 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
469 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
474 error = sctp_inpcb_alloc(so, vrf_id);
478 inp = (struct sctp_inpcb *)so->so_pcb;
480 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
481 ip_inp = &inp->ip_inp.inp;
482 ip_inp->inp_vflag |= INP_IPV4;
483 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
484 SCTP_INP_WUNLOCK(inp);
489 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
491 struct sctp_inpcb *inp;
493 inp = (struct sctp_inpcb *)so->so_pcb;
495 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
499 if ((addr->sa_family != AF_INET) ||
500 (addr->sa_len != sizeof(struct sockaddr_in))) {
501 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
505 return (sctp_inpcb_bind(so, addr, NULL, p));
510 sctp_close(struct socket *so)
512 struct epoch_tracker et;
513 struct sctp_inpcb *inp;
515 inp = (struct sctp_inpcb *)so->so_pcb;
520 * Inform all the lower layer assoc that we are done.
524 #ifdef SCTP_LOG_CLOSING
525 sctp_log_closing(inp, NULL, 17);
527 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
528 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP;
529 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
530 (so->so_rcv.sb_cc > 0)) {
531 #ifdef SCTP_LOG_CLOSING
532 sctp_log_closing(inp, NULL, 13);
534 SCTP_INP_WUNLOCK(inp);
535 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
536 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
538 #ifdef SCTP_LOG_CLOSING
539 sctp_log_closing(inp, NULL, 14);
541 SCTP_INP_WUNLOCK(inp);
542 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
543 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
546 * The socket is now detached, no matter what the state of
547 * the SCTP association.
550 SCTP_SB_CLEAR(so->so_snd);
552 * same for the rcv ones, they are only here for the
555 SCTP_SB_CLEAR(so->so_rcv);
557 /* Now null out the reference, we are completely detached. */
561 SCTP_INP_WUNLOCK(inp);
567 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
568 struct mbuf *control, struct thread *p);
571 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
572 struct mbuf *control, struct thread *p)
574 struct sctp_inpcb *inp;
577 inp = (struct sctp_inpcb *)so->so_pcb;
580 sctp_m_freem(control);
583 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
587 /* Got to have an to address if we are NOT a connected socket */
588 if ((addr == NULL) &&
589 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
590 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
596 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
597 error = EDESTADDRREQ;
598 } else if (addr->sa_family != AF_INET) {
599 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
600 error = EAFNOSUPPORT;
601 } else if (addr->sa_len != sizeof(struct sockaddr_in)) {
602 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
608 sctp_m_freem(control);
614 /* now what about control */
617 sctp_m_freem(inp->control);
620 inp->control = control;
624 SCTP_BUF_NEXT(inp->pkt_last) = m;
627 inp->pkt_last = inp->pkt = m;
630 /* FreeBSD uses a flag passed */
631 ((flags & PRUS_MORETOCOME) == 0)
634 * note with the current version this code will only be used
635 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
636 * re-defining sosend to use the sctp_sosend. One can
637 * optionally switch back to this code (by changing back the
638 * definitions) but this is not advisable. This code is used
639 * by FreeBSD when sending a file with sendfile() though.
641 struct epoch_tracker et;
645 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
656 sctp_disconnect(struct socket *so)
658 struct sctp_inpcb *inp;
660 inp = (struct sctp_inpcb *)so->so_pcb;
662 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
666 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
667 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
668 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
670 SCTP_INP_RUNLOCK(inp);
673 struct epoch_tracker et;
674 struct sctp_association *asoc;
675 struct sctp_tcb *stcb;
677 stcb = LIST_FIRST(&inp->sctp_asoc_list);
679 SCTP_INP_RUNLOCK(inp);
680 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
685 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
686 /* We are about to be freed, out of here */
687 SCTP_TCB_UNLOCK(stcb);
688 SCTP_INP_RUNLOCK(inp);
692 if (((so->so_options & SO_LINGER) &&
693 (so->so_linger == 0)) ||
694 (so->so_rcv.sb_cc > 0)) {
695 if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) {
696 /* Left with Data unread */
699 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
700 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
701 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
703 SCTP_INP_RUNLOCK(inp);
704 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
705 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
706 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
708 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
709 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
710 /* No unlock tcb assoc is gone */
714 if (TAILQ_EMPTY(&asoc->send_queue) &&
715 TAILQ_EMPTY(&asoc->sent_queue) &&
716 (asoc->stream_queue_cnt == 0)) {
717 /* there is nothing queued to send, so done */
718 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
721 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) &&
722 (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
723 /* only send SHUTDOWN 1st time thru */
724 struct sctp_nets *netp;
726 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
727 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
728 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
730 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
731 sctp_stop_timers_for_shutdown(stcb);
732 if (stcb->asoc.alternate) {
733 netp = stcb->asoc.alternate;
735 netp = stcb->asoc.primary_destination;
737 sctp_send_shutdown(stcb, netp);
738 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
739 stcb->sctp_ep, stcb, netp);
740 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
741 stcb->sctp_ep, stcb, NULL);
742 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
746 * we still got (or just got) data to send,
747 * so set SHUTDOWN_PENDING
750 * XXX sockets draft says that SCTP_EOF
751 * should be sent with no data. currently,
752 * we will allow user data to be sent first
753 * and move to SHUTDOWN-PENDING
755 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
756 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
757 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
758 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
760 if (TAILQ_EMPTY(&asoc->send_queue) &&
761 TAILQ_EMPTY(&asoc->sent_queue) &&
762 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
766 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
767 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
768 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
769 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
770 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
771 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
772 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
774 SCTP_INP_RUNLOCK(inp);
775 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
776 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
780 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
783 soisdisconnecting(so);
785 SCTP_TCB_UNLOCK(stcb);
786 SCTP_INP_RUNLOCK(inp);
791 /* UDP model does not support this */
792 SCTP_INP_RUNLOCK(inp);
793 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
799 sctp_flush(struct socket *so, int how)
802 * We will just clear out the values and let subsequent close clear
803 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
804 * they will not be able to read the data, the socket will block
805 * that from happening.
807 struct sctp_inpcb *inp;
809 inp = (struct sctp_inpcb *)so->so_pcb;
811 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
815 /* For the 1 to many model this does nothing */
816 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
817 SCTP_INP_RUNLOCK(inp);
820 SCTP_INP_RUNLOCK(inp);
821 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
823 * First make sure the sb will be happy, we don't use these
824 * except maybe the count
827 SCTP_INP_READ_LOCK(inp);
828 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
829 SCTP_INP_READ_UNLOCK(inp);
830 SCTP_INP_WUNLOCK(inp);
831 so->so_rcv.sb_cc = 0;
832 so->so_rcv.sb_mbcnt = 0;
833 so->so_rcv.sb_mb = NULL;
835 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
837 * First make sure the sb will be happy, we don't use these
838 * except maybe the count
840 so->so_snd.sb_cc = 0;
841 so->so_snd.sb_mbcnt = 0;
842 so->so_snd.sb_mb = NULL;
848 sctp_shutdown(struct socket *so)
850 struct sctp_inpcb *inp;
852 inp = (struct sctp_inpcb *)so->so_pcb;
854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
858 /* For UDP model this is a invalid call */
859 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
860 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
861 /* Restore the flags that the soshutdown took away. */
862 SOCKBUF_LOCK(&so->so_rcv);
863 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
864 SOCKBUF_UNLOCK(&so->so_rcv);
865 /* This proc will wakeup for read and do nothing (I hope) */
866 SCTP_INP_RUNLOCK(inp);
867 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
871 * Ok, if we reach here its the TCP model and it is either a
872 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
875 struct epoch_tracker et;
876 struct sctp_tcb *stcb;
877 struct sctp_association *asoc;
878 struct sctp_nets *netp;
881 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
882 SCTP_INP_RUNLOCK(inp);
887 stcb = LIST_FIRST(&inp->sctp_asoc_list);
890 * Ok, we hit the case that the shutdown call was
891 * made after an abort or something. Nothing to do
894 SCTP_INP_RUNLOCK(inp);
899 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
900 SCTP_TCB_UNLOCK(stcb);
901 SCTP_INP_RUNLOCK(inp);
904 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) &&
905 (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) &&
906 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) {
908 * If we are not in or before ESTABLISHED, there is
909 * no protocol action required.
911 SCTP_TCB_UNLOCK(stcb);
912 SCTP_INP_RUNLOCK(inp);
916 if (stcb->asoc.alternate) {
917 netp = stcb->asoc.alternate;
919 netp = stcb->asoc.primary_destination;
921 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) &&
922 TAILQ_EMPTY(&asoc->send_queue) &&
923 TAILQ_EMPTY(&asoc->sent_queue) &&
924 (asoc->stream_queue_cnt == 0)) {
925 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
928 /* there is nothing queued to send, so I'm done... */
929 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
930 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
931 sctp_stop_timers_for_shutdown(stcb);
932 sctp_send_shutdown(stcb, netp);
933 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
934 stcb->sctp_ep, stcb, netp);
937 * We still got (or just got) data to send, so set
940 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
941 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
942 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
944 if (TAILQ_EMPTY(&asoc->send_queue) &&
945 TAILQ_EMPTY(&asoc->sent_queue) &&
946 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
950 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
951 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
952 SCTP_INP_RUNLOCK(inp);
953 sctp_abort_an_association(stcb->sctp_ep, stcb,
954 op_err, false, SCTP_SO_LOCKED);
959 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
961 * XXX: Why do this in the case where we have still data
964 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
965 SCTP_TCB_UNLOCK(stcb);
966 SCTP_INP_RUNLOCK(inp);
973 * copies a "user" presentable address and removes embedded scope, etc.
974 * returns 0 on success, 1 on error
977 sctp_fill_user_address(struct sockaddr *dst, struct sockaddr *src)
980 struct sockaddr_in6 lsa6;
982 src = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)src,
985 memcpy(dst, src, src->sa_len);
990 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
991 struct sctp_tcb *stcb,
993 struct sockaddr *addr,
996 struct sctp_ifn *sctp_ifn;
997 struct sctp_ifa *sctp_ifa;
1001 int ipv4_local_scope, ipv4_addr_legal;
1004 int local_scope, site_scope, ipv6_addr_legal;
1006 struct sctp_vrf *vrf;
1008 SCTP_IPI_ADDR_LOCK_ASSERT();
1014 /* Turn on all the appropriate scope */
1015 loopback_scope = stcb->asoc.scope.loopback_scope;
1017 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1018 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1021 local_scope = stcb->asoc.scope.local_scope;
1022 site_scope = stcb->asoc.scope.site_scope;
1023 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1026 /* Use generic values for endpoints. */
1029 ipv4_local_scope = 1;
1035 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1037 ipv6_addr_legal = 1;
1040 if (SCTP_IPV6_V6ONLY(inp)) {
1041 ipv4_addr_legal = 0;
1043 ipv4_addr_legal = 1;
1048 ipv6_addr_legal = 0;
1051 ipv4_addr_legal = 1;
1055 vrf = sctp_find_vrf(vrf_id);
1059 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1060 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1061 if ((loopback_scope == 0) &&
1062 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1063 /* Skip loopback if loopback_scope not set */
1066 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1069 * For the BOUND-ALL case, the list
1070 * associated with a TCB is Always
1071 * considered a reverse list.. i.e.
1072 * it lists addresses that are NOT
1073 * part of the association. If this
1074 * is one of those we must skip it.
1076 if (sctp_is_addr_restricted(stcb,
1081 switch (sctp_ifa->address.sa.sa_family) {
1084 if (ipv4_addr_legal) {
1085 struct sockaddr_in *sin;
1087 sin = &sctp_ifa->address.sin;
1088 if (sin->sin_addr.s_addr == 0) {
1096 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1097 &sin->sin_addr) != 0) {
1100 if ((ipv4_local_scope == 0) &&
1101 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1105 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1106 if (actual + sizeof(struct sockaddr_in6) > limit) {
1109 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)addr);
1110 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1111 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1112 actual += sizeof(struct sockaddr_in6);
1115 if (actual + sizeof(struct sockaddr_in) > limit) {
1118 memcpy(addr, sin, sizeof(struct sockaddr_in));
1119 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1120 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in));
1121 actual += sizeof(struct sockaddr_in);
1132 if (ipv6_addr_legal) {
1133 struct sockaddr_in6 *sin6;
1135 sin6 = &sctp_ifa->address.sin6;
1136 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1144 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1145 &sin6->sin6_addr) != 0) {
1148 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1149 if (local_scope == 0)
1151 if (sin6->sin6_scope_id == 0) {
1152 if (sa6_recoverscope(sin6) != 0)
1165 if ((site_scope == 0) &&
1166 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1169 if (actual + sizeof(struct sockaddr_in6) > limit) {
1172 memcpy(addr, sin6, sizeof(struct sockaddr_in6));
1173 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1174 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1175 actual += sizeof(struct sockaddr_in6);
1188 struct sctp_laddr *laddr;
1191 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1193 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1197 sa_len = laddr->ifa->address.sa.sa_len;
1198 if (actual + sa_len > limit) {
1201 if (sctp_fill_user_address(addr, &laddr->ifa->address.sa))
1203 switch (laddr->ifa->address.sa.sa_family) {
1206 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1211 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1218 addr = (struct sockaddr *)((caddr_t)addr + sa_len);
1226 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1227 struct sctp_tcb *stcb,
1229 struct sockaddr *addr)
1233 SCTP_IPI_ADDR_RLOCK();
1234 /* fill up addresses for the endpoint's default vrf */
1235 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, addr,
1237 SCTP_IPI_ADDR_RUNLOCK();
1242 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1245 struct sctp_vrf *vrf = NULL;
1248 * In both sub-set bound an bound_all cases we return the MAXIMUM
1249 * number of addresses that you COULD get. In reality the sub-set
1250 * bound may have an exclusion list for a given TCB OR in the
1251 * bound-all case a TCB may NOT include the loopback or other
1252 * addresses as well.
1254 SCTP_IPI_ADDR_LOCK_ASSERT();
1255 vrf = sctp_find_vrf(vrf_id);
1259 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1260 struct sctp_ifn *sctp_ifn;
1261 struct sctp_ifa *sctp_ifa;
1263 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1264 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1265 /* Count them if they are the right type */
1266 switch (sctp_ifa->address.sa.sa_family) {
1270 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1271 cnt += sizeof(struct sockaddr_in6);
1273 cnt += sizeof(struct sockaddr_in);
1275 cnt += sizeof(struct sockaddr_in);
1281 cnt += sizeof(struct sockaddr_in6);
1290 struct sctp_laddr *laddr;
1292 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1293 switch (laddr->ifa->address.sa.sa_family) {
1297 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1298 cnt += sizeof(struct sockaddr_in6);
1300 cnt += sizeof(struct sockaddr_in);
1302 cnt += sizeof(struct sockaddr_in);
1308 cnt += sizeof(struct sockaddr_in6);
1320 sctp_count_max_addresses(struct sctp_inpcb *inp)
1324 SCTP_IPI_ADDR_RLOCK();
1325 /* count addresses for the endpoint's default VRF */
1326 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1327 SCTP_IPI_ADDR_RUNLOCK();
1332 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1333 size_t optsize, void *p, int delay)
1336 int creat_lock_on = 0;
1337 struct sctp_tcb *stcb = NULL;
1338 struct sockaddr *sa;
1339 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1343 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1345 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1346 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1347 /* We are already connected AND the TCP model */
1348 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1349 return (EADDRINUSE);
1352 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1353 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1354 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1358 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1359 SCTP_INP_RLOCK(inp);
1360 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1361 SCTP_INP_RUNLOCK(inp);
1364 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1367 SCTP_INP_INCR_REF(inp);
1368 SCTP_ASOC_CREATE_LOCK(inp);
1370 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1371 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1372 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1376 totaddrp = (unsigned int *)optval;
1377 totaddr = *totaddrp;
1378 sa = (struct sockaddr *)(totaddrp + 1);
1379 error = sctp_connectx_helper_find(inp, sa, totaddr, &num_v4, &num_v6, (unsigned int)(optsize - sizeof(int)));
1381 /* Already have or am bring up an association */
1382 SCTP_ASOC_CREATE_UNLOCK(inp);
1384 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1388 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1393 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1395 if (SCTP_IPV6_V6ONLY(inp)) {
1397 * if IPV6_V6ONLY flag, ignore connections destined
1398 * to a v4 addr or v4-mapped addr
1400 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1406 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1407 SCTP_PCB_FLAGS_UNBOUND) {
1408 /* Bind a ephemeral port */
1409 error = sctp_inpcb_bind(so, NULL, NULL, p);
1415 /* FIX ME: do we want to pass in a vrf on the connect call? */
1416 vrf_id = inp->def_vrf_id;
1418 /* We are GOOD to go */
1419 stcb = sctp_aloc_assoc_connected(inp, sa, &error, 0, 0, vrf_id,
1420 inp->sctp_ep.pre_open_stream_count,
1423 SCTP_INITIALIZE_AUTH_PARAMS);
1425 /* Gak! no memory */
1428 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1429 /* move to second address */
1430 switch (sa->sa_family) {
1433 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1438 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1446 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1447 /* Fill in the return id */
1451 a_id = (sctp_assoc_t *)optval;
1452 *a_id = sctp_get_associd(stcb);
1455 /* doing delayed connection */
1456 stcb->asoc.delayed_connection = 1;
1457 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1459 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1460 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1462 SCTP_TCB_UNLOCK(stcb);
1464 if (creat_lock_on) {
1465 SCTP_ASOC_CREATE_UNLOCK(inp);
1467 SCTP_INP_DECR_REF(inp);
1471 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1472 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1473 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1474 SCTP_INP_RLOCK(inp); \
1475 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1477 SCTP_TCB_LOCK(stcb); \
1479 SCTP_INP_RUNLOCK(inp); \
1480 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1481 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1482 if (stcb == NULL) { \
1483 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1492 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1493 if (size < sizeof(type)) { \
1494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1498 destp = (type *)srcp; \
1503 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1506 struct sctp_inpcb *inp = NULL;
1508 struct sctp_tcb *stcb = NULL;
1510 if (optval == NULL) {
1511 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1515 inp = (struct sctp_inpcb *)so->so_pcb;
1517 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1524 case SCTP_AUTOCLOSE:
1525 case SCTP_EXPLICIT_EOR:
1526 case SCTP_AUTO_ASCONF:
1527 case SCTP_DISABLE_FRAGMENTS:
1528 case SCTP_I_WANT_MAPPED_V4_ADDR:
1529 case SCTP_USE_EXT_RCVINFO:
1530 SCTP_INP_RLOCK(inp);
1532 case SCTP_DISABLE_FRAGMENTS:
1533 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1535 case SCTP_I_WANT_MAPPED_V4_ADDR:
1536 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1538 case SCTP_AUTO_ASCONF:
1539 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1540 /* only valid for bound all sockets */
1541 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1543 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1548 case SCTP_EXPLICIT_EOR:
1549 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1552 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1554 case SCTP_USE_EXT_RCVINFO:
1555 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1557 case SCTP_AUTOCLOSE:
1558 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1559 val = sctp_ticks_to_secs(inp->sctp_ep.auto_close_time);
1565 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1566 error = ENOPROTOOPT;
1567 } /* end switch (sopt->sopt_name) */
1568 if (*optsize < sizeof(val)) {
1569 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1573 SCTP_INP_RUNLOCK(inp);
1575 /* return the option value */
1576 *(int *)optval = val;
1577 *optsize = sizeof(val);
1580 case SCTP_GET_PACKET_LOG:
1582 #ifdef SCTP_PACKET_LOGGING
1586 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1587 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1590 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1595 case SCTP_REUSE_PORT:
1599 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1600 /* Can't do this for a 1-m socket */
1604 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1605 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1606 *optsize = sizeof(uint32_t);
1609 case SCTP_PARTIAL_DELIVERY_POINT:
1613 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1614 *value = inp->partial_delivery_point;
1615 *optsize = sizeof(uint32_t);
1618 case SCTP_FRAGMENT_INTERLEAVE:
1622 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1623 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1624 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1625 *value = SCTP_FRAG_LEVEL_2;
1627 *value = SCTP_FRAG_LEVEL_1;
1630 *value = SCTP_FRAG_LEVEL_0;
1632 *optsize = sizeof(uint32_t);
1635 case SCTP_INTERLEAVING_SUPPORTED:
1637 struct sctp_assoc_value *av;
1639 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1640 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1643 av->assoc_value = stcb->asoc.idata_supported;
1644 SCTP_TCB_UNLOCK(stcb);
1646 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1647 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1648 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1649 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1650 SCTP_INP_RLOCK(inp);
1651 if (inp->idata_supported) {
1652 av->assoc_value = 1;
1654 av->assoc_value = 0;
1656 SCTP_INP_RUNLOCK(inp);
1658 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1663 *optsize = sizeof(struct sctp_assoc_value);
1667 case SCTP_CMT_ON_OFF:
1669 struct sctp_assoc_value *av;
1671 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1672 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1674 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1675 SCTP_TCB_UNLOCK(stcb);
1677 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1678 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1679 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1680 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1681 SCTP_INP_RLOCK(inp);
1682 av->assoc_value = inp->sctp_cmt_on_off;
1683 SCTP_INP_RUNLOCK(inp);
1685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1690 *optsize = sizeof(struct sctp_assoc_value);
1694 case SCTP_PLUGGABLE_CC:
1696 struct sctp_assoc_value *av;
1698 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1699 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1701 av->assoc_value = stcb->asoc.congestion_control_module;
1702 SCTP_TCB_UNLOCK(stcb);
1704 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1705 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1706 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1707 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1708 SCTP_INP_RLOCK(inp);
1709 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1710 SCTP_INP_RUNLOCK(inp);
1712 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1717 *optsize = sizeof(struct sctp_assoc_value);
1721 case SCTP_CC_OPTION:
1723 struct sctp_cc_option *cc_opt;
1725 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1726 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1730 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1733 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1734 *optsize = sizeof(struct sctp_cc_option);
1736 SCTP_TCB_UNLOCK(stcb);
1740 case SCTP_PLUGGABLE_SS:
1742 struct sctp_assoc_value *av;
1744 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1745 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1747 av->assoc_value = stcb->asoc.stream_scheduling_module;
1748 SCTP_TCB_UNLOCK(stcb);
1750 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1751 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1752 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1753 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1754 SCTP_INP_RLOCK(inp);
1755 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1756 SCTP_INP_RUNLOCK(inp);
1758 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1763 *optsize = sizeof(struct sctp_assoc_value);
1769 struct sctp_stream_value *av;
1771 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1772 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1774 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1775 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1776 &av->stream_value) < 0)) {
1777 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1780 *optsize = sizeof(struct sctp_stream_value);
1782 SCTP_TCB_UNLOCK(stcb);
1785 * Can't get stream value without
1788 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1793 case SCTP_GET_ADDR_LEN:
1795 struct sctp_assoc_value *av;
1797 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1800 if (av->assoc_value == AF_INET) {
1801 av->assoc_value = sizeof(struct sockaddr_in);
1806 if (av->assoc_value == AF_INET6) {
1807 av->assoc_value = sizeof(struct sockaddr_in6);
1812 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1814 *optsize = sizeof(struct sctp_assoc_value);
1818 case SCTP_GET_ASSOC_NUMBER:
1820 uint32_t *value, cnt;
1822 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1823 SCTP_INP_RLOCK(inp);
1824 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1825 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1826 /* Can't do this for a 1-1 socket */
1828 SCTP_INP_RUNLOCK(inp);
1832 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1835 SCTP_INP_RUNLOCK(inp);
1837 *optsize = sizeof(uint32_t);
1840 case SCTP_GET_ASSOC_ID_LIST:
1842 struct sctp_assoc_ids *ids;
1846 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1847 SCTP_INP_RLOCK(inp);
1848 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1849 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1850 /* Can't do this for a 1-1 socket */
1852 SCTP_INP_RUNLOCK(inp);
1856 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1857 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1859 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1862 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1867 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1871 SCTP_INP_RUNLOCK(inp);
1873 ids->gaids_number_of_ids = at;
1874 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1880 struct sctp_assoc_value *av;
1882 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1883 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1886 av->assoc_value = stcb->asoc.context;
1887 SCTP_TCB_UNLOCK(stcb);
1889 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1890 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1891 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1892 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1893 SCTP_INP_RLOCK(inp);
1894 av->assoc_value = inp->sctp_context;
1895 SCTP_INP_RUNLOCK(inp);
1897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1902 *optsize = sizeof(struct sctp_assoc_value);
1908 uint32_t *default_vrfid;
1910 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1911 *default_vrfid = inp->def_vrf_id;
1912 *optsize = sizeof(uint32_t);
1915 case SCTP_GET_ASOC_VRF:
1917 struct sctp_assoc_value *id;
1919 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1920 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1923 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1925 id->assoc_value = stcb->asoc.vrf_id;
1926 SCTP_TCB_UNLOCK(stcb);
1927 *optsize = sizeof(struct sctp_assoc_value);
1931 case SCTP_GET_VRF_IDS:
1933 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1937 case SCTP_GET_NONCE_VALUES:
1939 struct sctp_get_nonce_values *gnv;
1941 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1942 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1945 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1946 gnv->gn_local_tag = stcb->asoc.my_vtag;
1947 SCTP_TCB_UNLOCK(stcb);
1948 *optsize = sizeof(struct sctp_get_nonce_values);
1950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1955 case SCTP_DELAYED_SACK:
1957 struct sctp_sack_info *sack;
1959 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1960 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1962 sack->sack_delay = stcb->asoc.delayed_ack;
1963 sack->sack_freq = stcb->asoc.sack_freq;
1964 SCTP_TCB_UNLOCK(stcb);
1966 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1967 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1968 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1969 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC))) {
1970 SCTP_INP_RLOCK(inp);
1971 sack->sack_delay = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1972 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
1973 SCTP_INP_RUNLOCK(inp);
1975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1980 *optsize = sizeof(struct sctp_sack_info);
1984 case SCTP_GET_SNDBUF_USE:
1986 struct sctp_sockstat *ss;
1988 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
1989 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
1992 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
1993 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
1994 stcb->asoc.size_on_all_streams);
1995 SCTP_TCB_UNLOCK(stcb);
1996 *optsize = sizeof(struct sctp_sockstat);
1998 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2003 case SCTP_MAX_BURST:
2005 struct sctp_assoc_value *av;
2007 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2008 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2011 av->assoc_value = stcb->asoc.max_burst;
2012 SCTP_TCB_UNLOCK(stcb);
2014 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2015 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2016 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2017 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2018 SCTP_INP_RLOCK(inp);
2019 av->assoc_value = inp->sctp_ep.max_burst;
2020 SCTP_INP_RUNLOCK(inp);
2022 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2027 *optsize = sizeof(struct sctp_assoc_value);
2033 struct sctp_assoc_value *av;
2036 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2037 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2040 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2041 SCTP_TCB_UNLOCK(stcb);
2043 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2044 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2045 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2046 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2047 SCTP_INP_RLOCK(inp);
2048 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2049 ovh = SCTP_MED_OVERHEAD;
2051 ovh = SCTP_MED_V4_OVERHEAD;
2053 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2054 av->assoc_value = 0;
2056 av->assoc_value = inp->sctp_frag_point - ovh;
2057 SCTP_INP_RUNLOCK(inp);
2059 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2064 *optsize = sizeof(struct sctp_assoc_value);
2068 case SCTP_GET_STAT_LOG:
2069 error = sctp_fill_stat_log(optval, optsize);
2073 struct sctp_event_subscribe *events;
2075 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2076 memset(events, 0, sizeof(struct sctp_event_subscribe));
2077 SCTP_INP_RLOCK(inp);
2078 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2079 events->sctp_data_io_event = 1;
2081 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2082 events->sctp_association_event = 1;
2084 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2085 events->sctp_address_event = 1;
2087 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2088 events->sctp_send_failure_event = 1;
2090 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2091 events->sctp_peer_error_event = 1;
2093 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2094 events->sctp_shutdown_event = 1;
2096 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2097 events->sctp_partial_delivery_event = 1;
2099 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2100 events->sctp_adaptation_layer_event = 1;
2102 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2103 events->sctp_authentication_event = 1;
2105 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2106 events->sctp_sender_dry_event = 1;
2108 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2109 events->sctp_stream_reset_event = 1;
2110 SCTP_INP_RUNLOCK(inp);
2111 *optsize = sizeof(struct sctp_event_subscribe);
2114 case SCTP_ADAPTATION_LAYER:
2118 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2120 SCTP_INP_RLOCK(inp);
2121 *value = inp->sctp_ep.adaptation_layer_indicator;
2122 SCTP_INP_RUNLOCK(inp);
2123 *optsize = sizeof(uint32_t);
2126 case SCTP_SET_INITIAL_DBG_SEQ:
2130 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2131 SCTP_INP_RLOCK(inp);
2132 *value = inp->sctp_ep.initial_sequence_debug;
2133 SCTP_INP_RUNLOCK(inp);
2134 *optsize = sizeof(uint32_t);
2137 case SCTP_GET_LOCAL_ADDR_SIZE:
2141 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2142 SCTP_INP_RLOCK(inp);
2143 *value = sctp_count_max_addresses(inp);
2144 SCTP_INP_RUNLOCK(inp);
2145 *optsize = sizeof(uint32_t);
2148 case SCTP_GET_REMOTE_ADDR_SIZE:
2152 struct sctp_nets *net;
2154 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2155 /* FIXME MT: change to sctp_assoc_value? */
2156 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2160 /* Count the sizes */
2161 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2162 switch (net->ro._l_addr.sa.sa_family) {
2166 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2167 size += sizeof(struct sockaddr_in6);
2169 size += sizeof(struct sockaddr_in);
2172 size += sizeof(struct sockaddr_in);
2178 size += sizeof(struct sockaddr_in6);
2185 SCTP_TCB_UNLOCK(stcb);
2186 *value = (uint32_t)size;
2187 *optsize = sizeof(uint32_t);
2189 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2194 case SCTP_GET_PEER_ADDRESSES:
2196 * Get the address information, an array is passed in to
2197 * fill up we pack it.
2201 struct sockaddr *addr;
2202 struct sctp_nets *net;
2203 struct sctp_getaddresses *saddr;
2205 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2206 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2209 left = *optsize - offsetof(struct sctp_getaddresses, addr);
2210 *optsize = offsetof(struct sctp_getaddresses, addr);
2211 addr = &saddr->addr[0].sa;
2213 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2214 switch (net->ro._l_addr.sa.sa_family) {
2218 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2219 cpsz = sizeof(struct sockaddr_in6);
2221 cpsz = sizeof(struct sockaddr_in);
2224 cpsz = sizeof(struct sockaddr_in);
2230 cpsz = sizeof(struct sockaddr_in6);
2241 /* not enough room. */
2244 #if defined(INET) && defined(INET6)
2245 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2246 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2247 /* Must map the address */
2248 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2249 (struct sockaddr_in6 *)addr);
2251 memcpy(addr, &net->ro._l_addr, cpsz);
2254 memcpy(addr, &net->ro._l_addr, cpsz);
2256 ((struct sockaddr_in *)addr)->sin_port = stcb->rport;
2258 addr = (struct sockaddr *)((caddr_t)addr + cpsz);
2262 SCTP_TCB_UNLOCK(stcb);
2264 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2269 case SCTP_GET_LOCAL_ADDRESSES:
2271 size_t limit, actual;
2272 struct sctp_getaddresses *saddr;
2274 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2275 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2277 limit = *optsize - offsetof(struct sctp_getaddresses, addr);
2278 actual = sctp_fill_up_addresses(inp, stcb, limit, &saddr->addr[0].sa);
2280 SCTP_TCB_UNLOCK(stcb);
2282 *optsize = offsetof(struct sctp_getaddresses, addr) + actual;
2285 case SCTP_PEER_ADDR_PARAMS:
2287 struct sctp_paddrparams *paddrp;
2288 struct sctp_nets *net;
2289 struct sockaddr *addr;
2290 #if defined(INET) && defined(INET6)
2291 struct sockaddr_in sin_store;
2294 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2295 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2297 #if defined(INET) && defined(INET6)
2298 if (paddrp->spp_address.ss_family == AF_INET6) {
2299 struct sockaddr_in6 *sin6;
2301 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2302 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2303 in6_sin6_2_sin(&sin_store, sin6);
2304 addr = (struct sockaddr *)&sin_store;
2306 addr = (struct sockaddr *)&paddrp->spp_address;
2309 addr = (struct sockaddr *)&paddrp->spp_address;
2312 addr = (struct sockaddr *)&paddrp->spp_address;
2315 net = sctp_findnet(stcb, addr);
2318 * We increment here since
2319 * sctp_findassociation_ep_addr() wil do a
2320 * decrement if it finds the stcb as long as
2321 * the locked tcb (last argument) is NOT a
2325 SCTP_INP_INCR_REF(inp);
2326 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2328 SCTP_INP_DECR_REF(inp);
2331 if ((stcb != NULL) && (net == NULL)) {
2333 if (addr->sa_family == AF_INET) {
2334 struct sockaddr_in *sin;
2336 sin = (struct sockaddr_in *)addr;
2337 if (sin->sin_addr.s_addr != INADDR_ANY) {
2339 SCTP_TCB_UNLOCK(stcb);
2340 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2346 if (addr->sa_family == AF_INET6) {
2347 struct sockaddr_in6 *sin6;
2349 sin6 = (struct sockaddr_in6 *)addr;
2350 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2352 SCTP_TCB_UNLOCK(stcb);
2353 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2359 error = EAFNOSUPPORT;
2360 SCTP_TCB_UNLOCK(stcb);
2361 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2367 /* Applies to the specific association */
2368 paddrp->spp_flags = 0;
2370 paddrp->spp_hbinterval = net->heart_beat_delay;
2371 paddrp->spp_pathmaxrxt = net->failure_threshold;
2372 paddrp->spp_pathmtu = net->mtu;
2373 switch (net->ro._l_addr.sa.sa_family) {
2376 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2381 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2387 /* get flags for HB */
2388 if (net->dest_state & SCTP_ADDR_NOHB) {
2389 paddrp->spp_flags |= SPP_HB_DISABLE;
2391 paddrp->spp_flags |= SPP_HB_ENABLE;
2393 /* get flags for PMTU */
2394 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2395 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2397 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2399 if (net->dscp & 0x01) {
2400 paddrp->spp_dscp = net->dscp & 0xfc;
2401 paddrp->spp_flags |= SPP_DSCP;
2404 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2405 (net->flowlabel & 0x80000000)) {
2406 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2407 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2412 * No destination so return default
2415 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2416 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2417 if (stcb->asoc.default_dscp & 0x01) {
2418 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2419 paddrp->spp_flags |= SPP_DSCP;
2422 if (stcb->asoc.default_flowlabel & 0x80000000) {
2423 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2424 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2427 /* default settings should be these */
2428 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2429 paddrp->spp_flags |= SPP_HB_DISABLE;
2431 paddrp->spp_flags |= SPP_HB_ENABLE;
2433 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2434 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2436 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2438 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2440 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2441 SCTP_TCB_UNLOCK(stcb);
2443 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2444 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2445 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2446 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
2447 /* Use endpoint defaults */
2448 SCTP_INP_RLOCK(inp);
2449 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2450 paddrp->spp_hbinterval = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2451 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2452 /* get inp's default */
2453 if (inp->sctp_ep.default_dscp & 0x01) {
2454 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2455 paddrp->spp_flags |= SPP_DSCP;
2458 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2459 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2460 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2461 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2464 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2466 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2467 paddrp->spp_flags |= SPP_HB_ENABLE;
2469 paddrp->spp_flags |= SPP_HB_DISABLE;
2471 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2472 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2474 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2476 SCTP_INP_RUNLOCK(inp);
2478 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2483 *optsize = sizeof(struct sctp_paddrparams);
2487 case SCTP_GET_PEER_ADDR_INFO:
2489 struct sctp_paddrinfo *paddri;
2490 struct sctp_nets *net;
2491 struct sockaddr *addr;
2492 #if defined(INET) && defined(INET6)
2493 struct sockaddr_in sin_store;
2496 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2497 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2499 #if defined(INET) && defined(INET6)
2500 if (paddri->spinfo_address.ss_family == AF_INET6) {
2501 struct sockaddr_in6 *sin6;
2503 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2504 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2505 in6_sin6_2_sin(&sin_store, sin6);
2506 addr = (struct sockaddr *)&sin_store;
2508 addr = (struct sockaddr *)&paddri->spinfo_address;
2511 addr = (struct sockaddr *)&paddri->spinfo_address;
2514 addr = (struct sockaddr *)&paddri->spinfo_address;
2517 net = sctp_findnet(stcb, addr);
2520 * We increment here since
2521 * sctp_findassociation_ep_addr() wil do a
2522 * decrement if it finds the stcb as long as
2523 * the locked tcb (last argument) is NOT a
2527 SCTP_INP_INCR_REF(inp);
2528 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2530 SCTP_INP_DECR_REF(inp);
2534 if ((stcb != NULL) && (net != NULL)) {
2535 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2536 /* It's unconfirmed */
2537 paddri->spinfo_state = SCTP_UNCONFIRMED;
2538 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2540 paddri->spinfo_state = SCTP_ACTIVE;
2543 paddri->spinfo_state = SCTP_INACTIVE;
2545 paddri->spinfo_cwnd = net->cwnd;
2546 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2547 paddri->spinfo_rto = net->RTO;
2548 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2549 paddri->spinfo_mtu = net->mtu;
2550 switch (addr->sa_family) {
2553 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2558 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2564 SCTP_TCB_UNLOCK(stcb);
2565 *optsize = sizeof(struct sctp_paddrinfo);
2568 SCTP_TCB_UNLOCK(stcb);
2570 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2575 case SCTP_PCB_STATUS:
2577 struct sctp_pcbinfo *spcb;
2579 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2580 sctp_fill_pcbinfo(spcb);
2581 *optsize = sizeof(struct sctp_pcbinfo);
2586 struct sctp_nets *net;
2587 struct sctp_status *sstat;
2589 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2590 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2593 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2597 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2598 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2599 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2600 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2602 * We can't include chunks that have been passed to
2603 * the socket layer. Only things in queue.
2605 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2606 stcb->asoc.cnt_on_all_streams);
2607 sstat->sstat_instrms = stcb->asoc.streamincnt;
2608 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2609 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2610 net = stcb->asoc.primary_destination;
2612 memcpy(&sstat->sstat_primary.spinfo_address,
2614 ((struct sockaddr *)(&net->ro._l_addr))->sa_len);
2615 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2617 * Again the user can get info from
2618 * sctp_constants.h for what the state of
2621 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2622 /* It's unconfirmed */
2623 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2624 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2626 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2629 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2631 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2632 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2633 sstat->sstat_primary.spinfo_rto = net->RTO;
2634 sstat->sstat_primary.spinfo_mtu = net->mtu;
2635 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2638 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2643 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2650 memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo));
2652 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2653 SCTP_TCB_UNLOCK(stcb);
2654 *optsize = sizeof(struct sctp_status);
2659 struct sctp_rtoinfo *srto;
2661 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2662 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2665 srto->srto_initial = stcb->asoc.initial_rto;
2666 srto->srto_max = stcb->asoc.maxrto;
2667 srto->srto_min = stcb->asoc.minrto;
2668 SCTP_TCB_UNLOCK(stcb);
2670 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2671 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2672 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2673 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
2674 SCTP_INP_RLOCK(inp);
2675 srto->srto_initial = inp->sctp_ep.initial_rto;
2676 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2677 srto->srto_min = inp->sctp_ep.sctp_minrto;
2678 SCTP_INP_RUNLOCK(inp);
2680 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2685 *optsize = sizeof(struct sctp_rtoinfo);
2691 struct sctp_timeouts *stimo;
2693 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2694 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2697 stimo->stimo_init = stcb->asoc.timoinit;
2698 stimo->stimo_data = stcb->asoc.timodata;
2699 stimo->stimo_sack = stcb->asoc.timosack;
2700 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2701 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2702 stimo->stimo_cookie = stcb->asoc.timocookie;
2703 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2704 SCTP_TCB_UNLOCK(stcb);
2705 *optsize = sizeof(struct sctp_timeouts);
2707 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2712 case SCTP_ASSOCINFO:
2714 struct sctp_assocparams *sasoc;
2716 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2717 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2720 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(stcb->asoc.cookie_life);
2721 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2722 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2723 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2724 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2725 SCTP_TCB_UNLOCK(stcb);
2727 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2728 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2729 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2730 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
2731 SCTP_INP_RLOCK(inp);
2732 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(inp->sctp_ep.def_cookie_life);
2733 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2734 sasoc->sasoc_number_peer_destinations = 0;
2735 sasoc->sasoc_peer_rwnd = 0;
2736 sasoc->sasoc_local_rwnd = (uint32_t)sbspace(&inp->sctp_socket->so_rcv);
2737 SCTP_INP_RUNLOCK(inp);
2739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2744 *optsize = sizeof(struct sctp_assocparams);
2748 case SCTP_DEFAULT_SEND_PARAM:
2750 struct sctp_sndrcvinfo *s_info;
2752 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2753 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2756 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2757 SCTP_TCB_UNLOCK(stcb);
2759 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2760 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2761 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2762 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC))) {
2763 SCTP_INP_RLOCK(inp);
2764 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2765 SCTP_INP_RUNLOCK(inp);
2767 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2772 *optsize = sizeof(struct sctp_sndrcvinfo);
2778 struct sctp_initmsg *sinit;
2780 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2781 SCTP_INP_RLOCK(inp);
2782 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2783 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2784 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2785 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2786 SCTP_INP_RUNLOCK(inp);
2787 *optsize = sizeof(struct sctp_initmsg);
2790 case SCTP_PRIMARY_ADDR:
2791 /* we allow a "get" operation on this */
2793 struct sctp_setprim *ssp;
2795 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2796 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2799 union sctp_sockstore *addr;
2801 addr = &stcb->asoc.primary_destination->ro._l_addr;
2802 switch (addr->sa.sa_family) {
2806 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2807 in6_sin_2_v4mapsin6(&addr->sin,
2808 (struct sockaddr_in6 *)&ssp->ssp_addr);
2810 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2813 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2819 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2825 SCTP_TCB_UNLOCK(stcb);
2826 *optsize = sizeof(struct sctp_setprim);
2828 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2833 case SCTP_HMAC_IDENT:
2835 struct sctp_hmacalgo *shmac;
2836 sctp_hmaclist_t *hmaclist;
2840 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2842 SCTP_INP_RLOCK(inp);
2843 hmaclist = inp->sctp_ep.local_hmacs;
2844 if (hmaclist == NULL) {
2845 /* no HMACs to return */
2846 *optsize = sizeof(*shmac);
2847 SCTP_INP_RUNLOCK(inp);
2850 /* is there room for all of the hmac ids? */
2851 size = sizeof(*shmac) + (hmaclist->num_algo *
2852 sizeof(shmac->shmac_idents[0]));
2853 if (*optsize < size) {
2854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2856 SCTP_INP_RUNLOCK(inp);
2859 /* copy in the list */
2860 shmac->shmac_number_of_idents = hmaclist->num_algo;
2861 for (i = 0; i < hmaclist->num_algo; i++) {
2862 shmac->shmac_idents[i] = hmaclist->hmac[i];
2864 SCTP_INP_RUNLOCK(inp);
2868 case SCTP_AUTH_ACTIVE_KEY:
2870 struct sctp_authkeyid *scact;
2872 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2873 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2876 /* get the active key on the assoc */
2877 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2878 SCTP_TCB_UNLOCK(stcb);
2880 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2881 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2882 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2883 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC))) {
2884 /* get the endpoint active key */
2885 SCTP_INP_RLOCK(inp);
2886 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2887 SCTP_INP_RUNLOCK(inp);
2889 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2894 *optsize = sizeof(struct sctp_authkeyid);
2898 case SCTP_LOCAL_AUTH_CHUNKS:
2900 struct sctp_authchunks *sac;
2901 sctp_auth_chklist_t *chklist = NULL;
2904 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2905 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2908 /* get off the assoc */
2909 chklist = stcb->asoc.local_auth_chunks;
2910 /* is there enough space? */
2911 size = sctp_auth_get_chklist_size(chklist);
2912 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2914 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2916 /* copy in the chunks */
2917 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2918 sac->gauth_number_of_chunks = (uint32_t)size;
2919 *optsize = sizeof(struct sctp_authchunks) + size;
2921 SCTP_TCB_UNLOCK(stcb);
2923 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2924 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2925 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2926 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC))) {
2927 /* get off the endpoint */
2928 SCTP_INP_RLOCK(inp);
2929 chklist = inp->sctp_ep.local_auth_chunks;
2930 /* is there enough space? */
2931 size = sctp_auth_get_chklist_size(chklist);
2932 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2934 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2936 /* copy in the chunks */
2937 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2938 sac->gauth_number_of_chunks = (uint32_t)size;
2939 *optsize = sizeof(struct sctp_authchunks) + size;
2941 SCTP_INP_RUNLOCK(inp);
2943 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2949 case SCTP_PEER_AUTH_CHUNKS:
2951 struct sctp_authchunks *sac;
2952 sctp_auth_chklist_t *chklist = NULL;
2955 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2956 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2959 /* get off the assoc */
2960 chklist = stcb->asoc.peer_auth_chunks;
2961 /* is there enough space? */
2962 size = sctp_auth_get_chklist_size(chklist);
2963 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2967 /* copy in the chunks */
2968 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2969 sac->gauth_number_of_chunks = (uint32_t)size;
2970 *optsize = sizeof(struct sctp_authchunks) + size;
2972 SCTP_TCB_UNLOCK(stcb);
2974 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2981 struct sctp_event *event;
2982 uint32_t event_type;
2984 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2985 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2987 switch (event->se_type) {
2988 case SCTP_ASSOC_CHANGE:
2989 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2991 case SCTP_PEER_ADDR_CHANGE:
2992 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
2994 case SCTP_REMOTE_ERROR:
2995 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
2997 case SCTP_SEND_FAILED:
2998 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3000 case SCTP_SHUTDOWN_EVENT:
3001 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3003 case SCTP_ADAPTATION_INDICATION:
3004 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3006 case SCTP_PARTIAL_DELIVERY_EVENT:
3007 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3009 case SCTP_AUTHENTICATION_EVENT:
3010 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3012 case SCTP_STREAM_RESET_EVENT:
3013 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3015 case SCTP_SENDER_DRY_EVENT:
3016 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3018 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3020 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3023 case SCTP_ASSOC_RESET_EVENT:
3024 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3026 case SCTP_STREAM_CHANGE_EVENT:
3027 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3029 case SCTP_SEND_FAILED_EVENT:
3030 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3034 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3038 if (event_type > 0) {
3040 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3042 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3043 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3044 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3045 (event->se_assoc_id == SCTP_FUTURE_ASSOC))) {
3046 SCTP_INP_RLOCK(inp);
3047 event->se_on = sctp_is_feature_on(inp, event_type);
3048 SCTP_INP_RUNLOCK(inp);
3050 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3056 SCTP_TCB_UNLOCK(stcb);
3059 *optsize = sizeof(struct sctp_event);
3063 case SCTP_RECVRCVINFO:
3064 if (*optsize < sizeof(int)) {
3065 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3068 SCTP_INP_RLOCK(inp);
3069 *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3070 SCTP_INP_RUNLOCK(inp);
3071 *optsize = sizeof(int);
3074 case SCTP_RECVNXTINFO:
3075 if (*optsize < sizeof(int)) {
3076 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3079 SCTP_INP_RLOCK(inp);
3080 *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3081 SCTP_INP_RUNLOCK(inp);
3082 *optsize = sizeof(int);
3085 case SCTP_DEFAULT_SNDINFO:
3087 struct sctp_sndinfo *info;
3089 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3090 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3093 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3094 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3095 info->snd_flags &= 0xfff0;
3096 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3097 info->snd_context = stcb->asoc.def_send.sinfo_context;
3098 SCTP_TCB_UNLOCK(stcb);
3100 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3101 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3102 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3103 (info->snd_assoc_id == SCTP_FUTURE_ASSOC))) {
3104 SCTP_INP_RLOCK(inp);
3105 info->snd_sid = inp->def_send.sinfo_stream;
3106 info->snd_flags = inp->def_send.sinfo_flags;
3107 info->snd_flags &= 0xfff0;
3108 info->snd_ppid = inp->def_send.sinfo_ppid;
3109 info->snd_context = inp->def_send.sinfo_context;
3110 SCTP_INP_RUNLOCK(inp);
3112 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3117 *optsize = sizeof(struct sctp_sndinfo);
3121 case SCTP_DEFAULT_PRINFO:
3123 struct sctp_default_prinfo *info;
3125 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3126 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3129 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3130 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3131 SCTP_TCB_UNLOCK(stcb);
3133 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3134 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3135 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3136 (info->pr_assoc_id == SCTP_FUTURE_ASSOC))) {
3137 SCTP_INP_RLOCK(inp);
3138 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3139 info->pr_value = inp->def_send.sinfo_timetolive;
3140 SCTP_INP_RUNLOCK(inp);
3142 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3147 *optsize = sizeof(struct sctp_default_prinfo);
3151 case SCTP_PEER_ADDR_THLDS:
3153 struct sctp_paddrthlds *thlds;
3154 struct sctp_nets *net;
3155 struct sockaddr *addr;
3156 #if defined(INET) && defined(INET6)
3157 struct sockaddr_in sin_store;
3160 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3161 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3163 #if defined(INET) && defined(INET6)
3164 if (thlds->spt_address.ss_family == AF_INET6) {
3165 struct sockaddr_in6 *sin6;
3167 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3168 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3169 in6_sin6_2_sin(&sin_store, sin6);
3170 addr = (struct sockaddr *)&sin_store;
3172 addr = (struct sockaddr *)&thlds->spt_address;
3175 addr = (struct sockaddr *)&thlds->spt_address;
3178 addr = (struct sockaddr *)&thlds->spt_address;
3181 net = sctp_findnet(stcb, addr);
3184 * We increment here since
3185 * sctp_findassociation_ep_addr() wil do a
3186 * decrement if it finds the stcb as long as
3187 * the locked tcb (last argument) is NOT a
3191 SCTP_INP_INCR_REF(inp);
3192 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3194 SCTP_INP_DECR_REF(inp);
3197 if ((stcb != NULL) && (net == NULL)) {
3199 if (addr->sa_family == AF_INET) {
3200 struct sockaddr_in *sin;
3202 sin = (struct sockaddr_in *)addr;
3203 if (sin->sin_addr.s_addr != INADDR_ANY) {
3205 SCTP_TCB_UNLOCK(stcb);
3206 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3212 if (addr->sa_family == AF_INET6) {
3213 struct sockaddr_in6 *sin6;
3215 sin6 = (struct sockaddr_in6 *)addr;
3216 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3218 SCTP_TCB_UNLOCK(stcb);
3219 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3225 error = EAFNOSUPPORT;
3226 SCTP_TCB_UNLOCK(stcb);
3227 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3234 thlds->spt_pathmaxrxt = net->failure_threshold;
3235 thlds->spt_pathpfthld = net->pf_threshold;
3236 thlds->spt_pathcpthld = 0xffff;
3238 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3239 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3240 thlds->spt_pathcpthld = 0xffff;
3242 thlds->spt_assoc_id = sctp_get_associd(stcb);
3243 SCTP_TCB_UNLOCK(stcb);
3245 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3246 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3247 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3248 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
3249 /* Use endpoint defaults */
3250 SCTP_INP_RLOCK(inp);
3251 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3252 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3253 thlds->spt_pathcpthld = 0xffff;
3254 SCTP_INP_RUNLOCK(inp);
3256 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3261 *optsize = sizeof(struct sctp_paddrthlds);
3265 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3267 struct sctp_udpencaps *encaps;
3268 struct sctp_nets *net;
3269 struct sockaddr *addr;
3270 #if defined(INET) && defined(INET6)
3271 struct sockaddr_in sin_store;
3274 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3275 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3277 #if defined(INET) && defined(INET6)
3278 if (encaps->sue_address.ss_family == AF_INET6) {
3279 struct sockaddr_in6 *sin6;
3281 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3282 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3283 in6_sin6_2_sin(&sin_store, sin6);
3284 addr = (struct sockaddr *)&sin_store;
3286 addr = (struct sockaddr *)&encaps->sue_address;
3289 addr = (struct sockaddr *)&encaps->sue_address;
3292 addr = (struct sockaddr *)&encaps->sue_address;
3295 net = sctp_findnet(stcb, addr);
3298 * We increment here since
3299 * sctp_findassociation_ep_addr() wil do a
3300 * decrement if it finds the stcb as long as
3301 * the locked tcb (last argument) is NOT a
3305 SCTP_INP_INCR_REF(inp);
3306 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3308 SCTP_INP_DECR_REF(inp);
3311 if ((stcb != NULL) && (net == NULL)) {
3313 if (addr->sa_family == AF_INET) {
3314 struct sockaddr_in *sin;
3316 sin = (struct sockaddr_in *)addr;
3317 if (sin->sin_addr.s_addr != INADDR_ANY) {
3319 SCTP_TCB_UNLOCK(stcb);
3320 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3326 if (addr->sa_family == AF_INET6) {
3327 struct sockaddr_in6 *sin6;
3329 sin6 = (struct sockaddr_in6 *)addr;
3330 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3332 SCTP_TCB_UNLOCK(stcb);
3333 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3339 error = EAFNOSUPPORT;
3340 SCTP_TCB_UNLOCK(stcb);
3341 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3348 encaps->sue_port = net->port;
3350 encaps->sue_port = stcb->asoc.port;
3352 SCTP_TCB_UNLOCK(stcb);
3354 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3355 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3356 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3357 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
3358 SCTP_INP_RLOCK(inp);
3359 encaps->sue_port = inp->sctp_ep.port;
3360 SCTP_INP_RUNLOCK(inp);
3362 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3367 *optsize = sizeof(struct sctp_udpencaps);
3371 case SCTP_ECN_SUPPORTED:
3373 struct sctp_assoc_value *av;
3375 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3376 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3379 av->assoc_value = stcb->asoc.ecn_supported;
3380 SCTP_TCB_UNLOCK(stcb);
3382 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3383 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3384 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3385 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3386 SCTP_INP_RLOCK(inp);
3387 av->assoc_value = inp->ecn_supported;
3388 SCTP_INP_RUNLOCK(inp);
3390 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3395 *optsize = sizeof(struct sctp_assoc_value);
3399 case SCTP_PR_SUPPORTED:
3401 struct sctp_assoc_value *av;
3403 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3404 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3407 av->assoc_value = stcb->asoc.prsctp_supported;
3408 SCTP_TCB_UNLOCK(stcb);
3410 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3411 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3412 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3413 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3414 SCTP_INP_RLOCK(inp);
3415 av->assoc_value = inp->prsctp_supported;
3416 SCTP_INP_RUNLOCK(inp);
3418 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3423 *optsize = sizeof(struct sctp_assoc_value);
3427 case SCTP_AUTH_SUPPORTED:
3429 struct sctp_assoc_value *av;
3431 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3432 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3435 av->assoc_value = stcb->asoc.auth_supported;
3436 SCTP_TCB_UNLOCK(stcb);
3438 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3439 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3440 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3441 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3442 SCTP_INP_RLOCK(inp);
3443 av->assoc_value = inp->auth_supported;
3444 SCTP_INP_RUNLOCK(inp);
3446 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3451 *optsize = sizeof(struct sctp_assoc_value);
3455 case SCTP_ASCONF_SUPPORTED:
3457 struct sctp_assoc_value *av;
3459 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3460 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3463 av->assoc_value = stcb->asoc.asconf_supported;
3464 SCTP_TCB_UNLOCK(stcb);
3466 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3467 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3468 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3469 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3470 SCTP_INP_RLOCK(inp);
3471 av->assoc_value = inp->asconf_supported;
3472 SCTP_INP_RUNLOCK(inp);
3474 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3479 *optsize = sizeof(struct sctp_assoc_value);
3483 case SCTP_RECONFIG_SUPPORTED:
3485 struct sctp_assoc_value *av;
3487 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3488 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3491 av->assoc_value = stcb->asoc.reconfig_supported;
3492 SCTP_TCB_UNLOCK(stcb);
3494 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3495 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3496 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3497 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3498 SCTP_INP_RLOCK(inp);
3499 av->assoc_value = inp->reconfig_supported;
3500 SCTP_INP_RUNLOCK(inp);
3502 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3507 *optsize = sizeof(struct sctp_assoc_value);
3511 case SCTP_NRSACK_SUPPORTED:
3513 struct sctp_assoc_value *av;
3515 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3516 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3519 av->assoc_value = stcb->asoc.nrsack_supported;
3520 SCTP_TCB_UNLOCK(stcb);
3522 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3523 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3524 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3525 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3526 SCTP_INP_RLOCK(inp);
3527 av->assoc_value = inp->nrsack_supported;
3528 SCTP_INP_RUNLOCK(inp);
3530 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3535 *optsize = sizeof(struct sctp_assoc_value);
3539 case SCTP_PKTDROP_SUPPORTED:
3541 struct sctp_assoc_value *av;
3543 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3544 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3547 av->assoc_value = stcb->asoc.pktdrop_supported;
3548 SCTP_TCB_UNLOCK(stcb);
3550 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3551 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3552 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3553 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3554 SCTP_INP_RLOCK(inp);
3555 av->assoc_value = inp->pktdrop_supported;
3556 SCTP_INP_RUNLOCK(inp);
3558 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3563 *optsize = sizeof(struct sctp_assoc_value);
3567 case SCTP_ENABLE_STREAM_RESET:
3569 struct sctp_assoc_value *av;
3571 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3572 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3575 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3576 SCTP_TCB_UNLOCK(stcb);
3578 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3579 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3580 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3581 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3582 SCTP_INP_RLOCK(inp);
3583 av->assoc_value = (uint32_t)inp->local_strreset_support;
3584 SCTP_INP_RUNLOCK(inp);
3586 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3591 *optsize = sizeof(struct sctp_assoc_value);
3595 case SCTP_PR_STREAM_STATUS:
3597 struct sctp_prstatus *sprstat;
3601 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3602 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3604 sid = sprstat->sprstat_sid;
3605 policy = sprstat->sprstat_policy;
3606 #if defined(SCTP_DETAILED_STR_STATS)
3607 if ((stcb != NULL) &&
3608 (sid < stcb->asoc.streamoutcnt) &&
3609 (policy != SCTP_PR_SCTP_NONE) &&
3610 ((policy <= SCTP_PR_SCTP_MAX) ||
3611 (policy == SCTP_PR_SCTP_ALL))) {
3612 if (policy == SCTP_PR_SCTP_ALL) {
3613 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3614 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3616 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3617 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3620 if ((stcb != NULL) &&
3621 (sid < stcb->asoc.streamoutcnt) &&
3622 (policy == SCTP_PR_SCTP_ALL)) {
3623 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3624 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3627 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3631 SCTP_TCB_UNLOCK(stcb);
3634 *optsize = sizeof(struct sctp_prstatus);
3638 case SCTP_PR_ASSOC_STATUS:
3640 struct sctp_prstatus *sprstat;
3643 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3644 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3646 policy = sprstat->sprstat_policy;
3647 if ((stcb != NULL) &&
3648 (policy != SCTP_PR_SCTP_NONE) &&
3649 ((policy <= SCTP_PR_SCTP_MAX) ||
3650 (policy == SCTP_PR_SCTP_ALL))) {
3651 if (policy == SCTP_PR_SCTP_ALL) {
3652 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3653 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3655 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3656 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3659 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3663 SCTP_TCB_UNLOCK(stcb);
3666 *optsize = sizeof(struct sctp_prstatus);
3672 struct sctp_assoc_value *av;
3674 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3675 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3678 av->assoc_value = stcb->asoc.max_cwnd;
3679 SCTP_TCB_UNLOCK(stcb);
3681 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3682 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3683 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3684 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3685 SCTP_INP_RLOCK(inp);
3686 av->assoc_value = inp->max_cwnd;
3687 SCTP_INP_RUNLOCK(inp);
3689 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3694 *optsize = sizeof(struct sctp_assoc_value);
3699 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3700 error = ENOPROTOOPT;
3702 } /* end switch (sopt->sopt_name) */
3710 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3715 struct sctp_tcb *stcb = NULL;
3716 struct sctp_inpcb *inp = NULL;
3719 if (optval == NULL) {
3720 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3723 inp = (struct sctp_inpcb *)so->so_pcb;
3725 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3728 vrf_id = inp->def_vrf_id;
3733 case SCTP_AUTOCLOSE:
3734 case SCTP_AUTO_ASCONF:
3735 case SCTP_EXPLICIT_EOR:
3736 case SCTP_DISABLE_FRAGMENTS:
3737 case SCTP_USE_EXT_RCVINFO:
3738 case SCTP_I_WANT_MAPPED_V4_ADDR:
3739 /* copy in the option value */
3740 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3745 case SCTP_DISABLE_FRAGMENTS:
3746 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3748 case SCTP_AUTO_ASCONF:
3750 * NOTE: we don't really support this flag
3752 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3753 /* only valid for bound all sockets */
3754 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3756 /* forbidden by admin */
3757 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3760 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3762 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3766 case SCTP_EXPLICIT_EOR:
3767 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3769 case SCTP_USE_EXT_RCVINFO:
3770 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3772 case SCTP_I_WANT_MAPPED_V4_ADDR:
3773 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3774 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3781 set_opt = SCTP_PCB_FLAGS_NODELAY;
3783 case SCTP_AUTOCLOSE:
3784 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3785 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3786 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3789 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3791 * The value is in ticks. Note this does not effect
3792 * old associations, only new ones.
3794 inp->sctp_ep.auto_close_time = sctp_secs_to_ticks(*mopt);
3797 SCTP_INP_WLOCK(inp);
3799 sctp_feature_on(inp, set_opt);
3801 sctp_feature_off(inp, set_opt);
3803 SCTP_INP_WUNLOCK(inp);
3805 case SCTP_REUSE_PORT:
3807 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3808 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3809 /* Can't set it after we are bound */
3813 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3814 /* Can't do this for a 1-m socket */
3819 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3821 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3824 case SCTP_PARTIAL_DELIVERY_POINT:
3828 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3829 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3830 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3834 inp->partial_delivery_point = *value;
3837 case SCTP_FRAGMENT_INTERLEAVE:
3838 /* not yet until we re-write sctp_recvmsg() */
3842 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3843 if (*level == SCTP_FRAG_LEVEL_2) {
3844 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3845 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3846 } else if (*level == SCTP_FRAG_LEVEL_1) {
3847 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3848 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3849 } else if (*level == SCTP_FRAG_LEVEL_0) {
3850 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3851 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3859 case SCTP_INTERLEAVING_SUPPORTED:
3861 struct sctp_assoc_value *av;
3863 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3864 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3867 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3869 SCTP_TCB_UNLOCK(stcb);
3871 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3872 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3873 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3874 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3875 SCTP_INP_WLOCK(inp);
3876 if (av->assoc_value == 0) {
3877 inp->idata_supported = 0;
3879 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3880 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3881 inp->idata_supported = 1;
3889 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3893 SCTP_INP_WUNLOCK(inp);
3895 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3901 case SCTP_CMT_ON_OFF:
3902 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3903 struct sctp_assoc_value *av;
3905 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3906 if (av->assoc_value > SCTP_CMT_MAX) {
3907 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3911 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3913 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3914 SCTP_TCB_UNLOCK(stcb);
3916 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3917 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3918 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3919 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3920 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3921 SCTP_INP_WLOCK(inp);
3922 inp->sctp_cmt_on_off = av->assoc_value;
3923 SCTP_INP_WUNLOCK(inp);
3925 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3926 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3927 (av->assoc_id == SCTP_ALL_ASSOC))) {
3928 SCTP_INP_RLOCK(inp);
3929 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3930 SCTP_TCB_LOCK(stcb);
3931 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3932 SCTP_TCB_UNLOCK(stcb);
3934 SCTP_INP_RUNLOCK(inp);
3938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3939 error = ENOPROTOOPT;
3942 case SCTP_PLUGGABLE_CC:
3944 struct sctp_assoc_value *av;
3945 struct sctp_nets *net;
3947 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3948 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3949 (av->assoc_value != SCTP_CC_HSTCP) &&
3950 (av->assoc_value != SCTP_CC_HTCP) &&
3951 (av->assoc_value != SCTP_CC_RTCC)) {
3952 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3956 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3958 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3959 stcb->asoc.congestion_control_module = av->assoc_value;
3960 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3961 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3962 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3965 SCTP_TCB_UNLOCK(stcb);
3967 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3968 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3969 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3970 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3971 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3972 SCTP_INP_WLOCK(inp);
3973 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3974 SCTP_INP_WUNLOCK(inp);
3976 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3977 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3978 (av->assoc_id == SCTP_ALL_ASSOC))) {
3979 SCTP_INP_RLOCK(inp);
3980 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3981 SCTP_TCB_LOCK(stcb);
3982 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3983 stcb->asoc.congestion_control_module = av->assoc_value;
3984 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3985 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3986 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3989 SCTP_TCB_UNLOCK(stcb);
3991 SCTP_INP_RUNLOCK(inp);
3996 case SCTP_CC_OPTION:
3998 struct sctp_cc_option *cc_opt;
4000 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4001 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4003 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4004 (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC)) {
4005 SCTP_INP_RLOCK(inp);
4006 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4007 SCTP_TCB_LOCK(stcb);
4008 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4009 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4011 SCTP_TCB_UNLOCK(stcb);
4013 SCTP_INP_RUNLOCK(inp);
4018 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4021 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4024 SCTP_TCB_UNLOCK(stcb);
4028 case SCTP_PLUGGABLE_SS:
4030 struct sctp_assoc_value *av;
4032 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4033 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4034 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4035 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4036 (av->assoc_value != SCTP_SS_PRIORITY) &&
4037 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4038 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4039 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4043 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4045 SCTP_TCB_SEND_LOCK(stcb);
4046 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, true);
4047 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4048 stcb->asoc.stream_scheduling_module = av->assoc_value;
4049 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc);
4050 SCTP_TCB_SEND_UNLOCK(stcb);
4051 SCTP_TCB_UNLOCK(stcb);
4053 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4054 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4055 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4056 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4057 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4058 SCTP_INP_WLOCK(inp);
4059 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4060 SCTP_INP_WUNLOCK(inp);
4062 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4063 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4064 (av->assoc_id == SCTP_ALL_ASSOC))) {
4065 SCTP_INP_RLOCK(inp);
4066 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4067 SCTP_TCB_LOCK(stcb);
4068 SCTP_TCB_SEND_LOCK(stcb);
4069 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, true);
4070 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4071 stcb->asoc.stream_scheduling_module = av->assoc_value;
4072 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc);
4073 SCTP_TCB_SEND_UNLOCK(stcb);
4074 SCTP_TCB_UNLOCK(stcb);
4076 SCTP_INP_RUNLOCK(inp);
4083 struct sctp_stream_value *av;
4085 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4086 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4088 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4089 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4090 av->stream_value) < 0)) {
4091 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4094 SCTP_TCB_UNLOCK(stcb);
4096 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4097 (av->assoc_id == SCTP_CURRENT_ASSOC)) {
4098 SCTP_INP_RLOCK(inp);
4099 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4100 SCTP_TCB_LOCK(stcb);
4101 if (av->stream_id < stcb->asoc.streamoutcnt) {
4102 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4104 &stcb->asoc.strmout[av->stream_id],
4107 SCTP_TCB_UNLOCK(stcb);
4109 SCTP_INP_RUNLOCK(inp);
4112 * Can't set stream value without
4115 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4121 case SCTP_CLR_STAT_LOG:
4122 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4127 struct sctp_assoc_value *av;
4129 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4130 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4133 stcb->asoc.context = av->assoc_value;
4134 SCTP_TCB_UNLOCK(stcb);
4136 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4137 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4138 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4139 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4140 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4141 SCTP_INP_WLOCK(inp);
4142 inp->sctp_context = av->assoc_value;
4143 SCTP_INP_WUNLOCK(inp);
4145 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4146 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4147 (av->assoc_id == SCTP_ALL_ASSOC))) {
4148 SCTP_INP_RLOCK(inp);
4149 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4150 SCTP_TCB_LOCK(stcb);
4151 stcb->asoc.context = av->assoc_value;
4152 SCTP_TCB_UNLOCK(stcb);
4154 SCTP_INP_RUNLOCK(inp);
4161 uint32_t *default_vrfid;
4163 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4164 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4165 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4169 inp->def_vrf_id = *default_vrfid;
4172 case SCTP_DEL_VRF_ID:
4174 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4178 case SCTP_ADD_VRF_ID:
4180 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4184 case SCTP_DELAYED_SACK:
4186 struct sctp_sack_info *sack;
4188 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4189 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4190 if (sack->sack_delay) {
4191 if (sack->sack_delay > SCTP_MAX_SACK_DELAY) {
4194 SCTP_TCB_UNLOCK(stcb);
4200 if (sack->sack_delay) {
4201 stcb->asoc.delayed_ack = sack->sack_delay;
4203 if (sack->sack_freq) {
4204 stcb->asoc.sack_freq = sack->sack_freq;
4206 SCTP_TCB_UNLOCK(stcb);
4208 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4209 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4210 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4211 ((sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4212 (sack->sack_assoc_id == SCTP_ALL_ASSOC)))) {
4213 SCTP_INP_WLOCK(inp);
4214 if (sack->sack_delay) {
4215 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = sctp_msecs_to_ticks(sack->sack_delay);
4217 if (sack->sack_freq) {
4218 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4220 SCTP_INP_WUNLOCK(inp);
4222 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4223 ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4224 (sack->sack_assoc_id == SCTP_ALL_ASSOC))) {
4225 SCTP_INP_RLOCK(inp);
4226 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4227 SCTP_TCB_LOCK(stcb);
4228 if (sack->sack_delay) {
4229 stcb->asoc.delayed_ack = sack->sack_delay;
4231 if (sack->sack_freq) {
4232 stcb->asoc.sack_freq = sack->sack_freq;
4234 SCTP_TCB_UNLOCK(stcb);
4236 SCTP_INP_RUNLOCK(inp);
4241 case SCTP_AUTH_CHUNK:
4243 struct sctp_authchunk *sauth;
4245 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4247 SCTP_INP_WLOCK(inp);
4248 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4249 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4252 inp->auth_supported = 1;
4254 SCTP_INP_WUNLOCK(inp);
4259 struct sctp_authkey *sca;
4260 struct sctp_keyhead *shared_keys;
4261 sctp_sharedkey_t *shared_key;
4262 sctp_key_t *key = NULL;
4265 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4266 if (sca->sca_keylength == 0) {
4267 size = optsize - sizeof(struct sctp_authkey);
4269 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4270 size = sca->sca_keylength;
4272 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4277 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4280 shared_keys = &stcb->asoc.shared_keys;
4281 /* clear the cached keys for this key id */
4282 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4284 * create the new shared key and
4288 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4290 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4292 SCTP_TCB_UNLOCK(stcb);
4296 shared_key = sctp_alloc_sharedkey();
4297 if (shared_key == NULL) {
4299 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4301 SCTP_TCB_UNLOCK(stcb);
4304 shared_key->key = key;
4305 shared_key->keyid = sca->sca_keynumber;
4306 error = sctp_insert_sharedkey(shared_keys, shared_key);
4307 SCTP_TCB_UNLOCK(stcb);
4309 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4310 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4311 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4312 ((sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4313 (sca->sca_assoc_id == SCTP_ALL_ASSOC)))) {
4314 SCTP_INP_WLOCK(inp);
4315 shared_keys = &inp->sctp_ep.shared_keys;
4317 * clear the cached keys on all
4318 * assocs for this key id
4320 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4322 * create the new shared key and
4326 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4328 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4330 SCTP_INP_WUNLOCK(inp);
4334 shared_key = sctp_alloc_sharedkey();
4335 if (shared_key == NULL) {
4337 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4339 SCTP_INP_WUNLOCK(inp);
4342 shared_key->key = key;
4343 shared_key->keyid = sca->sca_keynumber;
4344 error = sctp_insert_sharedkey(shared_keys, shared_key);
4345 SCTP_INP_WUNLOCK(inp);
4347 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4348 ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4349 (sca->sca_assoc_id == SCTP_ALL_ASSOC))) {
4350 SCTP_INP_RLOCK(inp);
4351 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4352 SCTP_TCB_LOCK(stcb);
4353 shared_keys = &stcb->asoc.shared_keys;
4355 * clear the cached keys for
4358 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4360 * create the new shared key
4361 * and insert/replace it
4364 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4366 SCTP_TCB_UNLOCK(stcb);
4370 shared_key = sctp_alloc_sharedkey();
4371 if (shared_key == NULL) {
4373 SCTP_TCB_UNLOCK(stcb);
4376 shared_key->key = key;
4377 shared_key->keyid = sca->sca_keynumber;
4378 error = sctp_insert_sharedkey(shared_keys, shared_key);
4379 SCTP_TCB_UNLOCK(stcb);
4381 SCTP_INP_RUNLOCK(inp);
4386 case SCTP_HMAC_IDENT:
4388 struct sctp_hmacalgo *shmac;
4389 sctp_hmaclist_t *hmaclist;
4393 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4394 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4395 (shmac->shmac_number_of_idents > 0xffff)) {
4396 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4401 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4402 if (hmaclist == NULL) {
4403 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4407 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4408 hmacid = shmac->shmac_idents[i];
4409 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4410 /* invalid HMACs were found */ ;
4411 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4413 sctp_free_hmaclist(hmaclist);
4414 goto sctp_set_hmac_done;
4417 for (i = 0; i < hmaclist->num_algo; i++) {
4418 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4419 /* already in list */
4423 if (i == hmaclist->num_algo) {
4424 /* not found in list */
4425 sctp_free_hmaclist(hmaclist);
4426 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4430 /* set it on the endpoint */
4431 SCTP_INP_WLOCK(inp);
4432 if (inp->sctp_ep.local_hmacs)
4433 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4434 inp->sctp_ep.local_hmacs = hmaclist;
4435 SCTP_INP_WUNLOCK(inp);
4439 case SCTP_AUTH_ACTIVE_KEY:
4441 struct sctp_authkeyid *scact;
4443 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4444 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4446 /* set the active key on the right place */
4448 /* set the active key on the assoc */
4449 if (sctp_auth_setactivekey(stcb,
4450 scact->scact_keynumber)) {
4451 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4452 SCTP_FROM_SCTP_USRREQ,
4456 SCTP_TCB_UNLOCK(stcb);
4458 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4459 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4460 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4461 ((scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4462 (scact->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4463 SCTP_INP_WLOCK(inp);
4464 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4465 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4468 SCTP_INP_WUNLOCK(inp);
4470 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4471 ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4472 (scact->scact_assoc_id == SCTP_ALL_ASSOC))) {
4473 SCTP_INP_RLOCK(inp);
4474 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4475 SCTP_TCB_LOCK(stcb);
4476 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4477 SCTP_TCB_UNLOCK(stcb);
4479 SCTP_INP_RUNLOCK(inp);
4484 case SCTP_AUTH_DELETE_KEY:
4486 struct sctp_authkeyid *scdel;
4488 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4489 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4491 /* delete the key from the right place */
4493 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4497 SCTP_TCB_UNLOCK(stcb);
4499 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4500 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4501 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4502 ((scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4503 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4504 SCTP_INP_WLOCK(inp);
4505 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4506 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4509 SCTP_INP_WUNLOCK(inp);
4511 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4512 ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4513 (scdel->scact_assoc_id == SCTP_ALL_ASSOC))) {
4514 SCTP_INP_RLOCK(inp);
4515 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4516 SCTP_TCB_LOCK(stcb);
4517 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4518 SCTP_TCB_UNLOCK(stcb);
4520 SCTP_INP_RUNLOCK(inp);
4525 case SCTP_AUTH_DEACTIVATE_KEY:
4527 struct sctp_authkeyid *keyid;
4529 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4530 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4532 /* deactivate the key from the right place */
4534 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4535 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4538 SCTP_TCB_UNLOCK(stcb);
4540 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4541 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4542 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4543 ((keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4544 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4545 SCTP_INP_WLOCK(inp);
4546 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4547 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4550 SCTP_INP_WUNLOCK(inp);
4552 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4553 ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4554 (keyid->scact_assoc_id == SCTP_ALL_ASSOC))) {
4555 SCTP_INP_RLOCK(inp);
4556 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4557 SCTP_TCB_LOCK(stcb);
4558 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4559 SCTP_TCB_UNLOCK(stcb);
4561 SCTP_INP_RUNLOCK(inp);
4566 case SCTP_ENABLE_STREAM_RESET:
4568 struct sctp_assoc_value *av;
4570 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4571 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4572 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4576 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4578 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4579 SCTP_TCB_UNLOCK(stcb);
4581 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4582 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4583 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4584 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4585 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4586 SCTP_INP_WLOCK(inp);
4587 inp->local_strreset_support = (uint8_t)av->assoc_value;
4588 SCTP_INP_WUNLOCK(inp);
4590 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4591 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4592 (av->assoc_id == SCTP_ALL_ASSOC))) {
4593 SCTP_INP_RLOCK(inp);
4594 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4595 SCTP_TCB_LOCK(stcb);
4596 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4597 SCTP_TCB_UNLOCK(stcb);
4599 SCTP_INP_RUNLOCK(inp);
4604 case SCTP_RESET_STREAMS:
4606 struct sctp_reset_streams *strrst;
4607 int i, send_out = 0;
4610 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4611 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4613 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4617 if (stcb->asoc.reconfig_supported == 0) {
4619 * Peer does not support the chunk type.
4621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4623 SCTP_TCB_UNLOCK(stcb);
4626 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4627 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4629 SCTP_TCB_UNLOCK(stcb);
4632 if (sizeof(struct sctp_reset_streams) +
4633 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4635 SCTP_TCB_UNLOCK(stcb);
4638 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4640 if (stcb->asoc.stream_reset_outstanding) {
4641 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4643 SCTP_TCB_UNLOCK(stcb);
4647 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4650 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4651 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4653 SCTP_TCB_UNLOCK(stcb);
4656 if ((send_in == 0) && (send_out == 0)) {
4657 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4659 SCTP_TCB_UNLOCK(stcb);
4662 for (i = 0; i < strrst->srs_number_streams; i++) {
4664 (strrst->srs_stream_list[i] >= stcb->asoc.streamincnt)) {
4665 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4670 (strrst->srs_stream_list[i] >= stcb->asoc.streamoutcnt)) {
4671 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4677 SCTP_TCB_UNLOCK(stcb);
4684 if (strrst->srs_number_streams) {
4685 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4686 strm = strrst->srs_stream_list[i];
4687 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4688 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4694 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4695 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4696 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4703 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4704 strrst->srs_stream_list,
4705 send_in, 0, 0, 0, 0, 0);
4707 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4710 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4713 * For outgoing streams don't report any
4714 * problems in sending the request to the
4715 * application. XXX: Double check resetting
4720 SCTP_TCB_UNLOCK(stcb);
4723 case SCTP_ADD_STREAMS:
4725 struct sctp_add_streams *stradd;
4726 uint8_t addstream = 0;
4727 uint16_t add_o_strmcnt = 0;
4728 uint16_t add_i_strmcnt = 0;
4730 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4731 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4733 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4737 if (stcb->asoc.reconfig_supported == 0) {
4739 * Peer does not support the chunk type.
4741 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4743 SCTP_TCB_UNLOCK(stcb);
4746 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4747 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4749 SCTP_TCB_UNLOCK(stcb);
4752 if (stcb->asoc.stream_reset_outstanding) {
4753 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4755 SCTP_TCB_UNLOCK(stcb);
4758 if ((stradd->sas_outstrms == 0) &&
4759 (stradd->sas_instrms == 0)) {
4763 if (stradd->sas_outstrms) {
4765 /* We allocate here */
4766 add_o_strmcnt = stradd->sas_outstrms;
4767 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4768 /* You can't have more than 64k */
4773 if (stradd->sas_instrms) {
4778 * We allocate inside
4779 * sctp_send_str_reset_req()
4781 add_i_strmcnt = stradd->sas_instrms;
4782 cnt = add_i_strmcnt;
4783 cnt += stcb->asoc.streamincnt;
4784 if (cnt > 0x0000ffff) {
4785 /* You can't have more than 64k */
4789 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4790 /* More than you are allowed */
4795 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4796 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4798 SCTP_TCB_UNLOCK(stcb);
4801 case SCTP_RESET_ASSOC:
4806 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4807 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4809 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4813 if (stcb->asoc.reconfig_supported == 0) {
4815 * Peer does not support the chunk type.
4817 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4819 SCTP_TCB_UNLOCK(stcb);
4822 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4823 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4825 SCTP_TCB_UNLOCK(stcb);
4828 if (stcb->asoc.stream_reset_outstanding) {
4829 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4831 SCTP_TCB_UNLOCK(stcb);
4835 * Is there any data pending in the send or sent
4838 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4839 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4842 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4843 SCTP_TCB_UNLOCK(stcb);
4846 /* Do any streams have data queued? */
4847 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4848 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4852 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4853 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4854 SCTP_TCB_UNLOCK(stcb);
4857 case SCTP_CONNECT_X:
4858 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4859 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4863 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4865 case SCTP_CONNECT_X_DELAYED:
4866 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4867 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4871 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4873 case SCTP_CONNECT_X_COMPLETE:
4875 struct sockaddr *sa;
4877 /* FIXME MT: check correct? */
4878 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4881 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4882 SCTP_INP_RLOCK(inp);
4883 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4885 SCTP_TCB_LOCK(stcb);
4887 SCTP_INP_RUNLOCK(inp);
4890 * We increment here since
4891 * sctp_findassociation_ep_addr() wil do a
4892 * decrement if it finds the stcb as long as
4893 * the locked tcb (last argument) is NOT a
4896 SCTP_INP_INCR_REF(inp);
4897 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4899 SCTP_INP_DECR_REF(inp);
4904 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4908 if (stcb->asoc.delayed_connection == 1) {
4909 stcb->asoc.delayed_connection = 0;
4910 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4911 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4912 stcb->asoc.primary_destination,
4913 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4914 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4917 * already expired or did not use delayed
4920 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4923 SCTP_TCB_UNLOCK(stcb);
4926 case SCTP_MAX_BURST:
4928 struct sctp_assoc_value *av;
4930 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4931 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4934 stcb->asoc.max_burst = av->assoc_value;
4935 SCTP_TCB_UNLOCK(stcb);
4937 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4938 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4939 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4940 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4941 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4942 SCTP_INP_WLOCK(inp);
4943 inp->sctp_ep.max_burst = av->assoc_value;
4944 SCTP_INP_WUNLOCK(inp);
4946 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4947 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4948 (av->assoc_id == SCTP_ALL_ASSOC))) {
4949 SCTP_INP_RLOCK(inp);
4950 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4951 SCTP_TCB_LOCK(stcb);
4952 stcb->asoc.max_burst = av->assoc_value;
4953 SCTP_TCB_UNLOCK(stcb);
4955 SCTP_INP_RUNLOCK(inp);
4962 struct sctp_assoc_value *av;
4965 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4966 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4968 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4969 ovh = SCTP_MED_OVERHEAD;
4971 ovh = SCTP_MED_V4_OVERHEAD;
4974 if (av->assoc_value) {
4975 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4977 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4979 SCTP_TCB_UNLOCK(stcb);
4981 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4982 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4983 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4984 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
4985 SCTP_INP_WLOCK(inp);
4987 * FIXME MT: I think this is not in
4988 * tune with the API ID
4990 if (av->assoc_value) {
4991 inp->sctp_frag_point = (av->assoc_value + ovh);
4993 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4995 SCTP_INP_WUNLOCK(inp);
4997 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5005 struct sctp_event_subscribe *events;
5007 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5009 SCTP_INP_WLOCK(inp);
5010 if (events->sctp_data_io_event) {
5011 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5013 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5016 if (events->sctp_association_event) {
5017 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5019 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5022 if (events->sctp_address_event) {
5023 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5025 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5028 if (events->sctp_send_failure_event) {
5029 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5031 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5034 if (events->sctp_peer_error_event) {
5035 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5037 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5040 if (events->sctp_shutdown_event) {
5041 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5043 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5046 if (events->sctp_partial_delivery_event) {
5047 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5049 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5052 if (events->sctp_adaptation_layer_event) {
5053 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5055 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5058 if (events->sctp_authentication_event) {
5059 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5061 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5064 if (events->sctp_sender_dry_event) {
5065 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5067 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5070 if (events->sctp_stream_reset_event) {
5071 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5073 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5075 SCTP_INP_WUNLOCK(inp);
5077 SCTP_INP_RLOCK(inp);
5078 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5079 SCTP_TCB_LOCK(stcb);
5080 if (events->sctp_association_event) {
5081 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5083 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5085 if (events->sctp_address_event) {
5086 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5088 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5090 if (events->sctp_send_failure_event) {
5091 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5093 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5095 if (events->sctp_peer_error_event) {
5096 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5098 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5100 if (events->sctp_shutdown_event) {
5101 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5103 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5105 if (events->sctp_partial_delivery_event) {
5106 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5108 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5110 if (events->sctp_adaptation_layer_event) {
5111 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5113 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5115 if (events->sctp_authentication_event) {
5116 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5118 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5120 if (events->sctp_sender_dry_event) {
5121 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5123 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5125 if (events->sctp_stream_reset_event) {
5126 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5128 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5130 SCTP_TCB_UNLOCK(stcb);
5133 * Send up the sender dry event only for 1-to-1
5136 if (events->sctp_sender_dry_event) {
5137 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5138 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5139 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5141 SCTP_TCB_LOCK(stcb);
5142 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5143 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5144 (stcb->asoc.stream_queue_cnt == 0)) {
5145 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5147 SCTP_TCB_UNLOCK(stcb);
5151 SCTP_INP_RUNLOCK(inp);
5154 case SCTP_ADAPTATION_LAYER:
5156 struct sctp_setadaptation *adap_bits;
5158 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5159 SCTP_INP_WLOCK(inp);
5160 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5161 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5162 SCTP_INP_WUNLOCK(inp);
5166 case SCTP_SET_INITIAL_DBG_SEQ:
5170 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5171 SCTP_INP_WLOCK(inp);
5172 inp->sctp_ep.initial_sequence_debug = *vvv;
5173 SCTP_INP_WUNLOCK(inp);
5177 case SCTP_DEFAULT_SEND_PARAM:
5179 struct sctp_sndrcvinfo *s_info;
5181 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5182 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5185 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5186 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5188 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5191 SCTP_TCB_UNLOCK(stcb);
5193 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5194 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5195 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5196 ((s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5197 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)))) {
5198 SCTP_INP_WLOCK(inp);
5199 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5200 SCTP_INP_WUNLOCK(inp);
5202 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5203 ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5204 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC))) {
5205 SCTP_INP_RLOCK(inp);
5206 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5207 SCTP_TCB_LOCK(stcb);
5208 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5209 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5211 SCTP_TCB_UNLOCK(stcb);
5213 SCTP_INP_RUNLOCK(inp);
5218 case SCTP_PEER_ADDR_PARAMS:
5220 struct sctp_paddrparams *paddrp;
5221 struct sctp_nets *net;
5222 struct sockaddr *addr;
5223 #if defined(INET) && defined(INET6)
5224 struct sockaddr_in sin_store;
5227 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5228 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5230 #if defined(INET) && defined(INET6)
5231 if (paddrp->spp_address.ss_family == AF_INET6) {
5232 struct sockaddr_in6 *sin6;
5234 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5235 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5236 in6_sin6_2_sin(&sin_store, sin6);
5237 addr = (struct sockaddr *)&sin_store;
5239 addr = (struct sockaddr *)&paddrp->spp_address;
5242 addr = (struct sockaddr *)&paddrp->spp_address;
5245 addr = (struct sockaddr *)&paddrp->spp_address;
5248 net = sctp_findnet(stcb, addr);
5251 * We increment here since
5252 * sctp_findassociation_ep_addr() wil do a
5253 * decrement if it finds the stcb as long as
5254 * the locked tcb (last argument) is NOT a
5258 SCTP_INP_INCR_REF(inp);
5259 stcb = sctp_findassociation_ep_addr(&inp, addr,
5262 SCTP_INP_DECR_REF(inp);
5265 if ((stcb != NULL) && (net == NULL)) {
5267 if (addr->sa_family == AF_INET) {
5268 struct sockaddr_in *sin;
5270 sin = (struct sockaddr_in *)addr;
5271 if (sin->sin_addr.s_addr != INADDR_ANY) {
5272 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5273 SCTP_TCB_UNLOCK(stcb);
5280 if (addr->sa_family == AF_INET6) {
5281 struct sockaddr_in6 *sin6;
5283 sin6 = (struct sockaddr_in6 *)addr;
5284 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5285 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5286 SCTP_TCB_UNLOCK(stcb);
5293 error = EAFNOSUPPORT;
5294 SCTP_TCB_UNLOCK(stcb);
5295 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5300 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5302 SCTP_TCB_UNLOCK(stcb);
5303 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5307 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5309 SCTP_TCB_UNLOCK(stcb);
5310 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5313 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) &&
5314 (paddrp->spp_pathmtu > 0) &&
5315 ((paddrp->spp_pathmtu < SCTP_SMALLEST_PMTU) ||
5316 (paddrp->spp_pathmtu > SCTP_LARGEST_PMTU))) {
5318 SCTP_TCB_UNLOCK(stcb);
5319 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5324 /************************TCB SPECIFIC SET ******************/
5326 /************************NET SPECIFIC SET ******************/
5327 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5328 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5329 !(net->dest_state & SCTP_ADDR_NOHB)) {
5330 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5331 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5333 net->dest_state |= SCTP_ADDR_NOHB;
5335 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5336 if (paddrp->spp_hbinterval) {
5337 net->heart_beat_delay = paddrp->spp_hbinterval;
5338 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5339 net->heart_beat_delay = 0;
5341 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5342 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5343 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5344 net->dest_state &= ~SCTP_ADDR_NOHB;
5346 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5347 if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
5348 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5349 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5350 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5353 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5354 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5355 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5356 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5358 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5359 if (paddrp->spp_pathmtu > 0) {
5360 net->mtu = paddrp->spp_pathmtu;
5361 switch (net->ro._l_addr.sa.sa_family) {
5364 net->mtu += SCTP_MIN_V4_OVERHEAD;
5369 net->mtu += SCTP_MIN_OVERHEAD;
5375 if (net->mtu < stcb->asoc.smallest_mtu) {
5376 sctp_pathmtu_adjustment(stcb, net->mtu);
5380 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5381 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5382 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5384 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5386 if (paddrp->spp_pathmaxrxt > 0) {
5387 if (net->dest_state & SCTP_ADDR_PF) {
5388 if (net->error_count > paddrp->spp_pathmaxrxt) {
5389 net->dest_state &= ~SCTP_ADDR_PF;
5392 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5393 (net->error_count > net->pf_threshold)) {
5394 net->dest_state |= SCTP_ADDR_PF;
5395 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5396 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5397 stcb->sctp_ep, stcb, net,
5398 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5399 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5402 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5403 if (net->error_count > paddrp->spp_pathmaxrxt) {
5404 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5405 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5408 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5409 net->dest_state |= SCTP_ADDR_REACHABLE;
5410 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5413 net->failure_threshold = paddrp->spp_pathmaxrxt;
5415 if (paddrp->spp_flags & SPP_DSCP) {
5416 net->dscp = paddrp->spp_dscp & 0xfc;
5420 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5421 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5422 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5423 net->flowlabel |= 0x80000000;
5428 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5429 if (paddrp->spp_pathmaxrxt > 0) {
5430 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5431 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5432 if (net->dest_state & SCTP_ADDR_PF) {
5433 if (net->error_count > paddrp->spp_pathmaxrxt) {
5434 net->dest_state &= ~SCTP_ADDR_PF;
5437 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5438 (net->error_count > net->pf_threshold)) {
5439 net->dest_state |= SCTP_ADDR_PF;
5440 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5441 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5442 stcb->sctp_ep, stcb, net,
5443 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5444 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5447 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5448 if (net->error_count > paddrp->spp_pathmaxrxt) {
5449 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5450 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5453 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5454 net->dest_state |= SCTP_ADDR_REACHABLE;
5455 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5458 net->failure_threshold = paddrp->spp_pathmaxrxt;
5461 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5462 if (paddrp->spp_hbinterval != 0) {
5463 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5464 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5465 stcb->asoc.heart_beat_delay = 0;
5467 /* Turn back on the timer */
5468 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5469 if (paddrp->spp_hbinterval != 0) {
5470 net->heart_beat_delay = paddrp->spp_hbinterval;
5471 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5472 net->heart_beat_delay = 0;
5474 if (net->dest_state & SCTP_ADDR_NOHB) {
5475 net->dest_state &= ~SCTP_ADDR_NOHB;
5477 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5478 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5479 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5481 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5483 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5484 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5485 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5486 net->dest_state |= SCTP_ADDR_NOHB;
5487 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5488 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5490 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5494 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5496 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5497 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5498 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5499 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5500 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5502 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5503 if (paddrp->spp_pathmtu > 0) {
5504 net->mtu = paddrp->spp_pathmtu;
5505 switch (net->ro._l_addr.sa.sa_family) {
5508 net->mtu += SCTP_MIN_V4_OVERHEAD;
5513 net->mtu += SCTP_MIN_OVERHEAD;
5519 if (net->mtu < stcb->asoc.smallest_mtu) {
5520 sctp_pathmtu_adjustment(stcb, net->mtu);
5524 if (paddrp->spp_pathmtu > 0) {
5525 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5527 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5529 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5530 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5531 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5532 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5534 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5536 stcb->asoc.default_mtu = 0;
5537 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5539 if (paddrp->spp_flags & SPP_DSCP) {
5540 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5541 net->dscp = paddrp->spp_dscp & 0xfc;
5544 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5545 stcb->asoc.default_dscp |= 0x01;
5548 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5549 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5550 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5551 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5552 net->flowlabel |= 0x80000000;
5555 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5556 stcb->asoc.default_flowlabel |= 0x80000000;
5560 SCTP_TCB_UNLOCK(stcb);
5562 /************************NO TCB, SET TO default stuff ******************/
5563 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5564 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5565 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5566 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
5567 SCTP_INP_WLOCK(inp);
5569 * For the TOS/FLOWLABEL stuff you
5570 * set it with the options on the
5573 if (paddrp->spp_pathmaxrxt > 0) {
5574 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5577 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5578 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5579 else if (paddrp->spp_hbinterval != 0) {
5580 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5581 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5582 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5585 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5586 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5587 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5588 } else if (paddrp->spp_hbinterval) {
5589 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5591 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5592 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5593 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5595 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5596 inp->sctp_ep.default_mtu = 0;
5597 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5598 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5599 if (paddrp->spp_pathmtu > 0) {
5600 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5602 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5604 if (paddrp->spp_flags & SPP_DSCP) {
5605 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5606 inp->sctp_ep.default_dscp |= 0x01;
5609 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5610 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5611 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5612 inp->sctp_ep.default_flowlabel |= 0x80000000;
5616 SCTP_INP_WUNLOCK(inp);
5618 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5626 struct sctp_rtoinfo *srto;
5627 uint32_t new_init, new_min, new_max;
5629 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5630 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5633 if (srto->srto_initial)
5634 new_init = srto->srto_initial;
5636 new_init = stcb->asoc.initial_rto;
5638 new_max = srto->srto_max;
5640 new_max = stcb->asoc.maxrto;
5642 new_min = srto->srto_min;
5644 new_min = stcb->asoc.minrto;
5645 if ((new_min <= new_init) && (new_init <= new_max)) {
5646 stcb->asoc.initial_rto = new_init;
5647 stcb->asoc.maxrto = new_max;
5648 stcb->asoc.minrto = new_min;
5650 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5653 SCTP_TCB_UNLOCK(stcb);
5655 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5656 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5657 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5658 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
5659 SCTP_INP_WLOCK(inp);
5660 if (srto->srto_initial)
5661 new_init = srto->srto_initial;
5663 new_init = inp->sctp_ep.initial_rto;
5665 new_max = srto->srto_max;
5667 new_max = inp->sctp_ep.sctp_maxrto;
5669 new_min = srto->srto_min;
5671 new_min = inp->sctp_ep.sctp_minrto;
5672 if ((new_min <= new_init) && (new_init <= new_max)) {
5673 inp->sctp_ep.initial_rto = new_init;
5674 inp->sctp_ep.sctp_maxrto = new_max;
5675 inp->sctp_ep.sctp_minrto = new_min;
5677 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5680 SCTP_INP_WUNLOCK(inp);
5682 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5688 case SCTP_ASSOCINFO:
5690 struct sctp_assocparams *sasoc;
5692 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5693 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5694 if (sasoc->sasoc_cookie_life > 0) {
5695 /* boundary check the cookie life */
5696 if (sasoc->sasoc_cookie_life < SCTP_MIN_COOKIE_LIFE) {
5697 sasoc->sasoc_cookie_life = SCTP_MIN_COOKIE_LIFE;
5699 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5700 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5704 if (sasoc->sasoc_asocmaxrxt > 0) {
5705 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5707 if (sasoc->sasoc_cookie_life > 0) {
5708 stcb->asoc.cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5710 SCTP_TCB_UNLOCK(stcb);
5712 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5713 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5714 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5715 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
5716 SCTP_INP_WLOCK(inp);
5717 if (sasoc->sasoc_asocmaxrxt > 0) {
5718 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5720 if (sasoc->sasoc_cookie_life > 0) {
5721 inp->sctp_ep.def_cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5723 SCTP_INP_WUNLOCK(inp);
5725 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5733 struct sctp_initmsg *sinit;
5735 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5736 SCTP_INP_WLOCK(inp);
5737 if (sinit->sinit_num_ostreams)
5738 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5740 if (sinit->sinit_max_instreams)
5741 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5743 if (sinit->sinit_max_attempts)
5744 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5746 if (sinit->sinit_max_init_timeo)
5747 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5748 SCTP_INP_WUNLOCK(inp);
5751 case SCTP_PRIMARY_ADDR:
5753 struct sctp_setprim *spa;
5754 struct sctp_nets *net;
5755 struct sockaddr *addr;
5756 #if defined(INET) && defined(INET6)
5757 struct sockaddr_in sin_store;
5760 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5761 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5763 #if defined(INET) && defined(INET6)
5764 if (spa->ssp_addr.ss_family == AF_INET6) {
5765 struct sockaddr_in6 *sin6;
5767 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5768 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5769 in6_sin6_2_sin(&sin_store, sin6);
5770 addr = (struct sockaddr *)&sin_store;
5772 addr = (struct sockaddr *)&spa->ssp_addr;
5775 addr = (struct sockaddr *)&spa->ssp_addr;
5778 addr = (struct sockaddr *)&spa->ssp_addr;
5781 net = sctp_findnet(stcb, addr);
5784 * We increment here since
5785 * sctp_findassociation_ep_addr() wil do a
5786 * decrement if it finds the stcb as long as
5787 * the locked tcb (last argument) is NOT a
5791 SCTP_INP_INCR_REF(inp);
5792 stcb = sctp_findassociation_ep_addr(&inp, addr,
5795 SCTP_INP_DECR_REF(inp);
5799 if ((stcb != NULL) && (net != NULL)) {
5800 if (net != stcb->asoc.primary_destination) {
5801 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5802 /* Ok we need to set it */
5803 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5804 if ((stcb->asoc.alternate) &&
5805 (!(net->dest_state & SCTP_ADDR_PF)) &&
5806 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5807 sctp_free_remote_addr(stcb->asoc.alternate);
5808 stcb->asoc.alternate = NULL;
5811 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5815 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5820 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5824 SCTP_TCB_UNLOCK(stcb);
5828 case SCTP_SET_DYNAMIC_PRIMARY:
5830 union sctp_sockstore *ss;
5832 error = priv_check(curthread,
5833 PRIV_NETINET_RESERVEDPORT);
5837 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5838 /* SUPER USER CHECK? */
5839 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5842 case SCTP_SET_PEER_PRIMARY_ADDR:
5844 struct sctp_setpeerprim *sspp;
5845 struct sockaddr *addr;
5846 #if defined(INET) && defined(INET6)
5847 struct sockaddr_in sin_store;
5850 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5851 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5853 struct sctp_ifa *ifa;
5855 #if defined(INET) && defined(INET6)
5856 if (sspp->sspp_addr.ss_family == AF_INET6) {
5857 struct sockaddr_in6 *sin6;
5859 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5860 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5861 in6_sin6_2_sin(&sin_store, sin6);
5862 addr = (struct sockaddr *)&sin_store;
5864 addr = (struct sockaddr *)&sspp->sspp_addr;
5867 addr = (struct sockaddr *)&sspp->sspp_addr;
5870 addr = (struct sockaddr *)&sspp->sspp_addr;
5872 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5874 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5878 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5880 * Must validate the ifa found is in
5883 struct sctp_laddr *laddr;
5886 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5887 if (laddr->ifa == NULL) {
5888 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5892 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5893 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5896 if (laddr->ifa == ifa) {
5902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5907 switch (addr->sa_family) {
5911 struct sockaddr_in *sin;
5913 sin = (struct sockaddr_in *)addr;
5914 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5915 &sin->sin_addr) != 0) {
5916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5926 struct sockaddr_in6 *sin6;
5928 sin6 = (struct sockaddr_in6 *)addr;
5929 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5930 &sin6->sin6_addr) != 0) {
5931 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5944 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5945 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5948 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5950 SCTP_TCB_UNLOCK(stcb);
5952 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5957 case SCTP_BINDX_ADD_ADDR:
5959 struct sockaddr *sa;
5962 td = (struct thread *)p;
5963 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
5965 if (sa->sa_family == AF_INET) {
5966 if (optsize < sizeof(struct sockaddr_in)) {
5967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5972 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
5973 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5979 if (sa->sa_family == AF_INET6) {
5980 if (optsize < sizeof(struct sockaddr_in6)) {
5981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5986 (error = prison_local_ip6(td->td_ucred,
5987 &(((struct sockaddr_in6 *)sa)->sin6_addr),
5988 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5989 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5995 error = EAFNOSUPPORT;
5998 sctp_bindx_add_address(so, inp, sa, vrf_id, &error, p);
6001 case SCTP_BINDX_REM_ADDR:
6003 struct sockaddr *sa;
6006 td = (struct thread *)p;
6008 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
6010 if (sa->sa_family == AF_INET) {
6011 if (optsize < sizeof(struct sockaddr_in)) {
6012 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6017 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
6018 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6024 if (sa->sa_family == AF_INET6) {
6025 if (optsize < sizeof(struct sockaddr_in6)) {
6026 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6031 (error = prison_local_ip6(td->td_ucred,
6032 &(((struct sockaddr_in6 *)sa)->sin6_addr),
6033 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6034 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6040 error = EAFNOSUPPORT;
6043 sctp_bindx_delete_address(inp, sa, vrf_id, &error);
6048 struct sctp_event *event;
6049 uint32_t event_type;
6051 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6052 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6053 switch (event->se_type) {
6054 case SCTP_ASSOC_CHANGE:
6055 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6057 case SCTP_PEER_ADDR_CHANGE:
6058 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6060 case SCTP_REMOTE_ERROR:
6061 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6063 case SCTP_SEND_FAILED:
6064 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6066 case SCTP_SHUTDOWN_EVENT:
6067 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6069 case SCTP_ADAPTATION_INDICATION:
6070 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6072 case SCTP_PARTIAL_DELIVERY_EVENT:
6073 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6075 case SCTP_AUTHENTICATION_EVENT:
6076 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6078 case SCTP_STREAM_RESET_EVENT:
6079 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6081 case SCTP_SENDER_DRY_EVENT:
6082 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6084 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6086 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6089 case SCTP_ASSOC_RESET_EVENT:
6090 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6092 case SCTP_STREAM_CHANGE_EVENT:
6093 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6095 case SCTP_SEND_FAILED_EVENT:
6096 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6100 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6104 if (event_type > 0) {
6107 sctp_stcb_feature_on(inp, stcb, event_type);
6108 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6109 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6110 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6111 (stcb->asoc.stream_queue_cnt == 0)) {
6112 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6116 sctp_stcb_feature_off(inp, stcb, event_type);
6118 SCTP_TCB_UNLOCK(stcb);
6121 * We don't want to send up a storm
6122 * of events, so return an error for
6125 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6126 (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6127 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6128 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6129 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6133 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6134 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6135 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6136 ((event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6137 (event->se_assoc_id == SCTP_ALL_ASSOC)))) {
6138 SCTP_INP_WLOCK(inp);
6140 sctp_feature_on(inp, event_type);
6142 sctp_feature_off(inp, event_type);
6144 SCTP_INP_WUNLOCK(inp);
6146 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6147 ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6148 (event->se_assoc_id == SCTP_ALL_ASSOC))) {
6149 SCTP_INP_RLOCK(inp);
6150 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6151 SCTP_TCB_LOCK(stcb);
6153 sctp_stcb_feature_on(inp, stcb, event_type);
6155 sctp_stcb_feature_off(inp, stcb, event_type);
6157 SCTP_TCB_UNLOCK(stcb);
6159 SCTP_INP_RUNLOCK(inp);
6164 SCTP_TCB_UNLOCK(stcb);
6169 case SCTP_RECVRCVINFO:
6173 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6174 SCTP_INP_WLOCK(inp);
6176 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6178 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6180 SCTP_INP_WUNLOCK(inp);
6183 case SCTP_RECVNXTINFO:
6187 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6188 SCTP_INP_WLOCK(inp);
6190 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6192 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6194 SCTP_INP_WUNLOCK(inp);
6197 case SCTP_DEFAULT_SNDINFO:
6199 struct sctp_sndinfo *info;
6202 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6203 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6206 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6207 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6208 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6209 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6210 stcb->asoc.def_send.sinfo_flags |= policy;
6211 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6212 stcb->asoc.def_send.sinfo_context = info->snd_context;
6214 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6217 SCTP_TCB_UNLOCK(stcb);
6219 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6220 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6221 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6222 ((info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6223 (info->snd_assoc_id == SCTP_ALL_ASSOC)))) {
6224 SCTP_INP_WLOCK(inp);
6225 inp->def_send.sinfo_stream = info->snd_sid;
6226 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6227 inp->def_send.sinfo_flags = info->snd_flags;
6228 inp->def_send.sinfo_flags |= policy;
6229 inp->def_send.sinfo_ppid = info->snd_ppid;
6230 inp->def_send.sinfo_context = info->snd_context;
6231 SCTP_INP_WUNLOCK(inp);
6233 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6234 ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6235 (info->snd_assoc_id == SCTP_ALL_ASSOC))) {
6236 SCTP_INP_RLOCK(inp);
6237 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6238 SCTP_TCB_LOCK(stcb);
6239 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6240 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6241 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6242 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6243 stcb->asoc.def_send.sinfo_flags |= policy;
6244 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6245 stcb->asoc.def_send.sinfo_context = info->snd_context;
6247 SCTP_TCB_UNLOCK(stcb);
6249 SCTP_INP_RUNLOCK(inp);
6254 case SCTP_DEFAULT_PRINFO:
6256 struct sctp_default_prinfo *info;
6258 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6259 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6261 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6263 SCTP_TCB_UNLOCK(stcb);
6265 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6270 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6271 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6272 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6273 SCTP_TCB_UNLOCK(stcb);
6275 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6276 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6277 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6278 ((info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6279 (info->pr_assoc_id == SCTP_ALL_ASSOC)))) {
6280 SCTP_INP_WLOCK(inp);
6281 inp->def_send.sinfo_flags &= 0xfff0;
6282 inp->def_send.sinfo_flags |= info->pr_policy;
6283 inp->def_send.sinfo_timetolive = info->pr_value;
6284 SCTP_INP_WUNLOCK(inp);
6286 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6287 ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6288 (info->pr_assoc_id == SCTP_ALL_ASSOC))) {
6289 SCTP_INP_RLOCK(inp);
6290 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6291 SCTP_TCB_LOCK(stcb);
6292 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6293 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6294 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6295 SCTP_TCB_UNLOCK(stcb);
6297 SCTP_INP_RUNLOCK(inp);
6302 case SCTP_PEER_ADDR_THLDS:
6303 /* Applies to the specific association */
6305 struct sctp_paddrthlds *thlds;
6306 struct sctp_nets *net;
6307 struct sockaddr *addr;
6308 #if defined(INET) && defined(INET6)
6309 struct sockaddr_in sin_store;
6312 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6313 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6315 #if defined(INET) && defined(INET6)
6316 if (thlds->spt_address.ss_family == AF_INET6) {
6317 struct sockaddr_in6 *sin6;
6319 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6320 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6321 in6_sin6_2_sin(&sin_store, sin6);
6322 addr = (struct sockaddr *)&sin_store;
6324 addr = (struct sockaddr *)&thlds->spt_address;
6327 addr = (struct sockaddr *)&thlds->spt_address;
6330 addr = (struct sockaddr *)&thlds->spt_address;
6333 net = sctp_findnet(stcb, addr);
6336 * We increment here since
6337 * sctp_findassociation_ep_addr() wil do a
6338 * decrement if it finds the stcb as long as
6339 * the locked tcb (last argument) is NOT a
6343 SCTP_INP_INCR_REF(inp);
6344 stcb = sctp_findassociation_ep_addr(&inp, addr,
6347 SCTP_INP_DECR_REF(inp);
6350 if ((stcb != NULL) && (net == NULL)) {
6352 if (addr->sa_family == AF_INET) {
6353 struct sockaddr_in *sin;
6355 sin = (struct sockaddr_in *)addr;
6356 if (sin->sin_addr.s_addr != INADDR_ANY) {
6357 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6358 SCTP_TCB_UNLOCK(stcb);
6365 if (addr->sa_family == AF_INET6) {
6366 struct sockaddr_in6 *sin6;
6368 sin6 = (struct sockaddr_in6 *)addr;
6369 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6371 SCTP_TCB_UNLOCK(stcb);
6378 error = EAFNOSUPPORT;
6379 SCTP_TCB_UNLOCK(stcb);
6380 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6384 if (thlds->spt_pathcpthld != 0xffff) {
6386 SCTP_TCB_UNLOCK(stcb);
6389 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6394 net->failure_threshold = thlds->spt_pathmaxrxt;
6395 net->pf_threshold = thlds->spt_pathpfthld;
6396 if (net->dest_state & SCTP_ADDR_PF) {
6397 if ((net->error_count > net->failure_threshold) ||
6398 (net->error_count <= net->pf_threshold)) {
6399 net->dest_state &= ~SCTP_ADDR_PF;
6402 if ((net->error_count > net->pf_threshold) &&
6403 (net->error_count <= net->failure_threshold)) {
6404 net->dest_state |= SCTP_ADDR_PF;
6405 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6406 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6407 stcb->sctp_ep, stcb, net,
6408 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6409 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6412 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6413 if (net->error_count > net->failure_threshold) {
6414 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6415 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6418 if (net->error_count <= net->failure_threshold) {
6419 net->dest_state |= SCTP_ADDR_REACHABLE;
6420 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6424 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6425 net->failure_threshold = thlds->spt_pathmaxrxt;
6426 net->pf_threshold = thlds->spt_pathpfthld;
6427 if (net->dest_state & SCTP_ADDR_PF) {
6428 if ((net->error_count > net->failure_threshold) ||
6429 (net->error_count <= net->pf_threshold)) {
6430 net->dest_state &= ~SCTP_ADDR_PF;
6433 if ((net->error_count > net->pf_threshold) &&
6434 (net->error_count <= net->failure_threshold)) {
6435 net->dest_state |= SCTP_ADDR_PF;
6436 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6437 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6438 stcb->sctp_ep, stcb, net,
6439 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6440 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6443 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6444 if (net->error_count > net->failure_threshold) {
6445 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6446 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6449 if (net->error_count <= net->failure_threshold) {
6450 net->dest_state |= SCTP_ADDR_REACHABLE;
6451 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6455 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6456 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6458 SCTP_TCB_UNLOCK(stcb);
6460 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6461 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6462 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6463 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
6464 SCTP_INP_WLOCK(inp);
6465 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6466 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6467 SCTP_INP_WUNLOCK(inp);
6469 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6475 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6477 struct sctp_udpencaps *encaps;
6478 struct sctp_nets *net;
6479 struct sockaddr *addr;
6480 #if defined(INET) && defined(INET6)
6481 struct sockaddr_in sin_store;
6484 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6485 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6487 #if defined(INET) && defined(INET6)
6488 if (encaps->sue_address.ss_family == AF_INET6) {
6489 struct sockaddr_in6 *sin6;
6491 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6492 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6493 in6_sin6_2_sin(&sin_store, sin6);
6494 addr = (struct sockaddr *)&sin_store;
6496 addr = (struct sockaddr *)&encaps->sue_address;
6499 addr = (struct sockaddr *)&encaps->sue_address;
6502 addr = (struct sockaddr *)&encaps->sue_address;
6505 net = sctp_findnet(stcb, addr);
6508 * We increment here since
6509 * sctp_findassociation_ep_addr() wil do a
6510 * decrement if it finds the stcb as long as
6511 * the locked tcb (last argument) is NOT a
6515 SCTP_INP_INCR_REF(inp);
6516 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6518 SCTP_INP_DECR_REF(inp);
6521 if ((stcb != NULL) && (net == NULL)) {
6523 if (addr->sa_family == AF_INET) {
6524 struct sockaddr_in *sin;
6526 sin = (struct sockaddr_in *)addr;
6527 if (sin->sin_addr.s_addr != INADDR_ANY) {
6528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6529 SCTP_TCB_UNLOCK(stcb);
6536 if (addr->sa_family == AF_INET6) {
6537 struct sockaddr_in6 *sin6;
6539 sin6 = (struct sockaddr_in6 *)addr;
6540 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6541 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6542 SCTP_TCB_UNLOCK(stcb);
6549 error = EAFNOSUPPORT;
6550 SCTP_TCB_UNLOCK(stcb);
6551 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6558 net->port = encaps->sue_port;
6560 stcb->asoc.port = encaps->sue_port;
6562 SCTP_TCB_UNLOCK(stcb);
6564 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6565 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6566 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6567 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
6568 SCTP_INP_WLOCK(inp);
6569 inp->sctp_ep.port = encaps->sue_port;
6570 SCTP_INP_WUNLOCK(inp);
6572 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6578 case SCTP_ECN_SUPPORTED:
6580 struct sctp_assoc_value *av;
6582 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6583 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6586 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6588 SCTP_TCB_UNLOCK(stcb);
6590 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6591 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6592 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6593 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6594 SCTP_INP_WLOCK(inp);
6595 if (av->assoc_value == 0) {
6596 inp->ecn_supported = 0;
6598 inp->ecn_supported = 1;
6600 SCTP_INP_WUNLOCK(inp);
6602 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6608 case SCTP_PR_SUPPORTED:
6610 struct sctp_assoc_value *av;
6612 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6613 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6616 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6618 SCTP_TCB_UNLOCK(stcb);
6620 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6621 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6622 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6623 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6624 SCTP_INP_WLOCK(inp);
6625 if (av->assoc_value == 0) {
6626 inp->prsctp_supported = 0;
6628 inp->prsctp_supported = 1;
6630 SCTP_INP_WUNLOCK(inp);
6632 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6638 case SCTP_AUTH_SUPPORTED:
6640 struct sctp_assoc_value *av;
6642 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6643 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6646 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6648 SCTP_TCB_UNLOCK(stcb);
6650 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6651 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6652 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6653 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6654 if ((av->assoc_value == 0) &&
6655 (inp->asconf_supported == 1)) {
6657 * AUTH is required for
6660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6663 SCTP_INP_WLOCK(inp);
6664 if (av->assoc_value == 0) {
6665 inp->auth_supported = 0;
6667 inp->auth_supported = 1;
6669 SCTP_INP_WUNLOCK(inp);
6672 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6678 case SCTP_ASCONF_SUPPORTED:
6680 struct sctp_assoc_value *av;
6682 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6683 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6686 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6688 SCTP_TCB_UNLOCK(stcb);
6690 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6691 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6692 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6693 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6694 if ((av->assoc_value != 0) &&
6695 (inp->auth_supported == 0)) {
6697 * AUTH is required for
6700 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6703 SCTP_INP_WLOCK(inp);
6704 if (av->assoc_value == 0) {
6705 inp->asconf_supported = 0;
6706 sctp_auth_delete_chunk(SCTP_ASCONF,
6707 inp->sctp_ep.local_auth_chunks);
6708 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6709 inp->sctp_ep.local_auth_chunks);
6711 inp->asconf_supported = 1;
6712 sctp_auth_add_chunk(SCTP_ASCONF,
6713 inp->sctp_ep.local_auth_chunks);
6714 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6715 inp->sctp_ep.local_auth_chunks);
6717 SCTP_INP_WUNLOCK(inp);
6720 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6726 case SCTP_RECONFIG_SUPPORTED:
6728 struct sctp_assoc_value *av;
6730 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6731 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6734 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6736 SCTP_TCB_UNLOCK(stcb);
6738 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6739 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6740 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6741 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6742 SCTP_INP_WLOCK(inp);
6743 if (av->assoc_value == 0) {
6744 inp->reconfig_supported = 0;
6746 inp->reconfig_supported = 1;
6748 SCTP_INP_WUNLOCK(inp);
6750 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6756 case SCTP_NRSACK_SUPPORTED:
6758 struct sctp_assoc_value *av;
6760 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6761 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6764 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6766 SCTP_TCB_UNLOCK(stcb);
6768 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6769 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6770 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6771 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6772 SCTP_INP_WLOCK(inp);
6773 if (av->assoc_value == 0) {
6774 inp->nrsack_supported = 0;
6776 inp->nrsack_supported = 1;
6778 SCTP_INP_WUNLOCK(inp);
6780 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6786 case SCTP_PKTDROP_SUPPORTED:
6788 struct sctp_assoc_value *av;
6790 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6791 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6796 SCTP_TCB_UNLOCK(stcb);
6798 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6799 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6800 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6801 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6802 SCTP_INP_WLOCK(inp);
6803 if (av->assoc_value == 0) {
6804 inp->pktdrop_supported = 0;
6806 inp->pktdrop_supported = 1;
6808 SCTP_INP_WUNLOCK(inp);
6810 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6818 struct sctp_assoc_value *av;
6819 struct sctp_nets *net;
6821 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6822 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6825 stcb->asoc.max_cwnd = av->assoc_value;
6826 if (stcb->asoc.max_cwnd > 0) {
6827 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6828 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6829 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6830 net->cwnd = stcb->asoc.max_cwnd;
6831 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6832 net->cwnd = net->mtu - sizeof(struct sctphdr);
6837 SCTP_TCB_UNLOCK(stcb);
6839 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6840 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6841 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6842 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6843 SCTP_INP_WLOCK(inp);
6844 inp->max_cwnd = av->assoc_value;
6845 SCTP_INP_WUNLOCK(inp);
6847 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6855 error = ENOPROTOOPT;
6857 } /* end switch (opt) */
6862 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6864 struct epoch_tracker et;
6865 struct sctp_inpcb *inp;
6866 void *optval = NULL;
6871 if ((sopt->sopt_level == SOL_SOCKET) &&
6872 (sopt->sopt_name == SO_SETFIB)) {
6873 inp = (struct sctp_inpcb *)so->so_pcb;
6875 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6878 SCTP_INP_WLOCK(inp);
6879 inp->fibnum = so->so_fibnum;
6880 SCTP_INP_WUNLOCK(inp);
6883 if (sopt->sopt_level != IPPROTO_SCTP) {
6884 /* wrong proto level... send back up to IP */
6886 if (INP_CHECK_SOCKAF(so, AF_INET6))
6887 error = ip6_ctloutput(so, sopt);
6889 #if defined(INET) && defined(INET6)
6893 error = ip_ctloutput(so, sopt);
6897 optsize = sopt->sopt_valsize;
6898 if (optsize > SCTP_SOCKET_OPTION_LIMIT) {
6899 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6903 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6904 if (optval == NULL) {
6905 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6908 error = sooptcopyin(sopt, optval, optsize, optsize);
6910 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6914 p = (void *)sopt->sopt_td;
6915 if (sopt->sopt_dir == SOPT_SET) {
6916 NET_EPOCH_ENTER(et);
6917 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6919 } else if (sopt->sopt_dir == SOPT_GET) {
6920 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6922 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6925 if ((error == 0) && (optval != NULL)) {
6926 error = sooptcopyout(sopt, optval, optsize);
6927 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6928 } else if (optval != NULL) {
6929 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6937 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6939 struct epoch_tracker et;
6941 int create_lock_on = 0;
6943 struct sctp_inpcb *inp;
6944 struct sctp_tcb *stcb = NULL;
6946 inp = (struct sctp_inpcb *)so->so_pcb;
6948 /* I made the same as TCP since we are not setup? */
6949 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6950 return (ECONNRESET);
6953 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6957 switch (addr->sa_family) {
6961 struct sockaddr_in6 *sin6;
6963 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6964 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6967 sin6 = (struct sockaddr_in6 *)addr;
6968 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6->sin6_addr)) != 0) {
6969 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6978 struct sockaddr_in *sin;
6980 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6984 sin = (struct sockaddr_in *)addr;
6985 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sin->sin_addr)) != 0) {
6986 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6993 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6994 return (EAFNOSUPPORT);
6996 SCTP_INP_INCR_REF(inp);
6997 SCTP_ASOC_CREATE_LOCK(inp);
6999 NET_EPOCH_ENTER(et);
7001 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
7002 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
7003 /* Should I really unlock ? */
7004 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
7009 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
7010 (addr->sa_family == AF_INET6)) {
7011 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7016 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
7017 SCTP_PCB_FLAGS_UNBOUND) {
7018 /* Bind a ephemeral port */
7019 error = sctp_inpcb_bind(so, NULL, NULL, p);
7024 /* Now do we connect? */
7025 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
7026 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
7027 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7031 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7032 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7033 /* We are already connected AND the TCP model */
7034 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7038 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7039 SCTP_INP_RLOCK(inp);
7040 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7041 SCTP_INP_RUNLOCK(inp);
7044 * We increment here since sctp_findassociation_ep_addr()
7045 * will do a decrement if it finds the stcb as long as the
7046 * locked tcb (last argument) is NOT a TCB.. aka NULL.
7048 SCTP_INP_INCR_REF(inp);
7049 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7051 SCTP_INP_DECR_REF(inp);
7053 SCTP_TCB_UNLOCK(stcb);
7057 /* Already have or am bring up an association */
7058 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7063 vrf_id = inp->def_vrf_id;
7064 /* We are GOOD to go */
7065 stcb = sctp_aloc_assoc_connected(inp, addr, &error, 0, 0, vrf_id,
7066 inp->sctp_ep.pre_open_stream_count,
7067 inp->sctp_ep.port, p,
7068 SCTP_INITIALIZE_AUTH_PARAMS);
7070 /* Gak! no memory */
7073 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7074 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7076 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7077 SCTP_TCB_UNLOCK(stcb);
7080 if (create_lock_on) {
7081 SCTP_ASOC_CREATE_UNLOCK(inp);
7083 SCTP_INP_DECR_REF(inp);
7089 sctp_listen(struct socket *so, int backlog, struct thread *p)
7092 * Note this module depends on the protocol processing being called
7093 * AFTER any socket level flags and backlog are applied to the
7094 * socket. The traditional way that the socket flags are applied is
7095 * AFTER protocol processing. We have made a change to the
7096 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7097 * place if the socket API for SCTP is to work properly.
7101 struct sctp_inpcb *inp;
7103 inp = (struct sctp_inpcb *)so->so_pcb;
7105 /* I made the same as TCP since we are not setup? */
7106 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7107 return (ECONNRESET);
7109 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7110 /* See if we have a listener */
7111 struct sctp_inpcb *tinp;
7112 union sctp_sockstore store;
7114 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7116 struct sctp_laddr *laddr;
7118 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7119 memcpy(&store, &laddr->ifa->address, sizeof(store));
7120 switch (store.sa.sa_family) {
7123 store.sin.sin_port = inp->sctp_lport;
7128 store.sin6.sin6_port = inp->sctp_lport;
7134 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7135 if (tinp && (tinp != inp) &&
7136 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7137 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7138 (SCTP_IS_LISTENING(tinp))) {
7140 * we have a listener already and
7143 SCTP_INP_DECR_REF(tinp);
7144 return (EADDRINUSE);
7146 SCTP_INP_DECR_REF(tinp);
7150 /* Setup a local addr bound all */
7151 memset(&store, 0, sizeof(store));
7153 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7154 store.sa.sa_family = AF_INET6;
7155 store.sa.sa_len = sizeof(struct sockaddr_in6);
7159 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7160 store.sa.sa_family = AF_INET;
7161 store.sa.sa_len = sizeof(struct sockaddr_in);
7164 switch (store.sa.sa_family) {
7167 store.sin.sin_port = inp->sctp_lport;
7172 store.sin6.sin6_port = inp->sctp_lport;
7178 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7179 if (tinp && (tinp != inp) &&
7180 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7181 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7182 (SCTP_IS_LISTENING(tinp))) {
7184 * we have a listener already and its not
7187 SCTP_INP_DECR_REF(tinp);
7188 return (EADDRINUSE);
7190 SCTP_INP_DECR_REF(tinp);
7194 SCTP_INP_INFO_WLOCK();
7195 SCTP_INP_WLOCK(inp);
7196 #ifdef SCTP_LOCK_LOGGING
7197 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7198 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7201 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7202 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7204 * The unlucky case - We are in the tcp pool with this guy.
7205 * - Someone else is in the main inp slot. - We must move
7206 * this guy (the listener) to the main slot - We must then
7207 * move the guy that was listener to the TCP Pool.
7209 if (sctp_swap_inpcb_for_listen(inp)) {
7211 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7216 error = solisten_proto_check(so);
7221 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7222 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7224 solisten_proto_abort(so);
7226 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7229 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7230 if ((error = sctp_inpcb_bind_locked(inp, NULL, NULL, p))) {
7232 solisten_proto_abort(so);
7233 /* bind error, probably perm */
7237 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7238 solisten_proto(so, backlog);
7240 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7242 solisten_proto_abort(so);
7245 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7247 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7251 SCTP_INP_WUNLOCK(inp);
7252 SCTP_INP_INFO_WUNLOCK();
7256 static int sctp_defered_wakeup_cnt = 0;
7259 sctp_accept(struct socket *so, struct sockaddr **addr)
7261 struct sctp_tcb *stcb;
7262 struct sctp_inpcb *inp;
7263 union sctp_sockstore store;
7267 inp = (struct sctp_inpcb *)so->so_pcb;
7270 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7271 return (ECONNRESET);
7273 SCTP_INP_WLOCK(inp);
7274 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7275 SCTP_INP_WUNLOCK(inp);
7276 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7277 return (EOPNOTSUPP);
7279 if (so->so_state & SS_ISDISCONNECTED) {
7280 SCTP_INP_WUNLOCK(inp);
7281 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7282 return (ECONNABORTED);
7284 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7286 SCTP_INP_WUNLOCK(inp);
7287 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7288 return (ECONNRESET);
7290 SCTP_TCB_LOCK(stcb);
7291 store = stcb->asoc.primary_destination->ro._l_addr;
7292 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7293 /* Wake any delayed sleep action */
7294 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7295 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7296 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7297 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7298 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7299 if (sowriteable(inp->sctp_socket)) {
7300 sowwakeup_locked(inp->sctp_socket);
7302 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7305 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7306 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7307 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7308 if (soreadable(inp->sctp_socket)) {
7309 sctp_defered_wakeup_cnt++;
7310 sorwakeup_locked(inp->sctp_socket);
7312 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7316 SCTP_INP_WUNLOCK(inp);
7317 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7318 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7319 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7321 SCTP_TCB_UNLOCK(stcb);
7323 switch (store.sa.sa_family) {
7327 struct sockaddr_in *sin;
7329 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7332 sin->sin_family = AF_INET;
7333 sin->sin_len = sizeof(*sin);
7334 sin->sin_port = store.sin.sin_port;
7335 sin->sin_addr = store.sin.sin_addr;
7336 *addr = (struct sockaddr *)sin;
7343 struct sockaddr_in6 *sin6;
7345 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7348 sin6->sin6_family = AF_INET6;
7349 sin6->sin6_len = sizeof(*sin6);
7350 sin6->sin6_port = store.sin6.sin6_port;
7351 sin6->sin6_addr = store.sin6.sin6_addr;
7352 if ((error = sa6_recoverscope(sin6)) != 0) {
7353 SCTP_FREE_SONAME(sin6);
7356 *addr = (struct sockaddr *)sin6;
7369 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7371 struct sockaddr_in *sin;
7373 struct sctp_inpcb *inp;
7374 struct sctp_ifa *sctp_ifa;
7377 * Do the malloc first in case it blocks.
7379 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7382 sin->sin_family = AF_INET;
7383 sin->sin_len = sizeof(*sin);
7384 inp = (struct sctp_inpcb *)so->so_pcb;
7386 SCTP_FREE_SONAME(sin);
7387 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7388 return (ECONNRESET);
7390 SCTP_INP_RLOCK(inp);
7391 sin->sin_port = inp->sctp_lport;
7392 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7393 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7394 struct sctp_tcb *stcb;
7395 struct sockaddr_in *sin_a;
7396 struct sctp_nets *net;
7399 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7405 SCTP_TCB_LOCK(stcb);
7406 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7407 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7409 /* this will make coverity happy */
7412 if (sin_a->sin_family == AF_INET) {
7417 if ((!fnd) || (sin_a == NULL)) {
7419 SCTP_TCB_UNLOCK(stcb);
7423 vrf_id = inp->def_vrf_id;
7424 sctp_ifa = sctp_source_address_selection(inp,
7426 (sctp_route_t *)&net->ro,
7429 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7430 sctp_free_ifa(sctp_ifa);
7432 SCTP_TCB_UNLOCK(stcb);
7434 /* For the bound all case you get back 0 */
7436 sin->sin_addr.s_addr = 0;
7440 /* Take the first IPv4 address in the list */
7441 struct sctp_laddr *laddr;
7444 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7445 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7446 struct sockaddr_in *sin_a;
7448 sin_a = &laddr->ifa->address.sin;
7449 sin->sin_addr = sin_a->sin_addr;
7455 SCTP_FREE_SONAME(sin);
7456 SCTP_INP_RUNLOCK(inp);
7457 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7461 SCTP_INP_RUNLOCK(inp);
7462 (*addr) = (struct sockaddr *)sin;
7467 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7469 struct sockaddr_in *sin;
7471 struct sockaddr_in *sin_a;
7472 struct sctp_inpcb *inp;
7473 struct sctp_tcb *stcb;
7474 struct sctp_nets *net;
7476 /* Do the malloc first in case it blocks. */
7477 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7480 sin->sin_family = AF_INET;
7481 sin->sin_len = sizeof(*sin);
7483 inp = (struct sctp_inpcb *)so->so_pcb;
7484 if ((inp == NULL) ||
7485 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7486 /* UDP type and listeners will drop out here */
7487 SCTP_FREE_SONAME(sin);
7488 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7491 SCTP_INP_RLOCK(inp);
7492 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7494 SCTP_TCB_LOCK(stcb);
7496 SCTP_INP_RUNLOCK(inp);
7498 SCTP_FREE_SONAME(sin);
7499 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7500 return (ECONNRESET);
7503 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7504 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7505 if (sin_a->sin_family == AF_INET) {
7507 sin->sin_port = stcb->rport;
7508 sin->sin_addr = sin_a->sin_addr;
7512 SCTP_TCB_UNLOCK(stcb);
7514 /* No IPv4 address */
7515 SCTP_FREE_SONAME(sin);
7516 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7519 (*addr) = (struct sockaddr *)sin;
7523 struct pr_usrreqs sctp_usrreqs = {
7524 .pru_abort = sctp_abort,
7525 .pru_accept = sctp_accept,
7526 .pru_attach = sctp_attach,
7527 .pru_bind = sctp_bind,
7528 .pru_connect = sctp_connect,
7529 .pru_control = in_control,
7530 .pru_close = sctp_close,
7531 .pru_detach = sctp_close,
7532 .pru_sopoll = sopoll_generic,
7533 .pru_flush = sctp_flush,
7534 .pru_disconnect = sctp_disconnect,
7535 .pru_listen = sctp_listen,
7536 .pru_peeraddr = sctp_peeraddr,
7537 .pru_send = sctp_sendm,
7538 .pru_shutdown = sctp_shutdown,
7539 .pru_sockaddr = sctp_ingetaddr,
7540 .pru_sosend = sctp_sosend,
7541 .pru_soreceive = sctp_soreceive