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[];
62 sctp_init(void *arg SCTP_UNUSED)
66 /* Initialize and modify the sysctled variables */
68 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
69 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
71 * Allow a user to take no more than 1/2 the number of clusters or
72 * the SB_MAX, whichever is smaller, for the send window.
74 sb_max_adj = (u_long)((u_quad_t)(SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
75 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
76 (((uint32_t)nmbclusters / 2) * MCLBYTES));
78 * Now for the recv window, should we take the same amount? or
79 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
80 * now I will just copy.
82 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
83 SCTP_BASE_VAR(first_time) = 0;
84 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
86 #if defined(SCTP_PACKET_LOGGING)
87 SCTP_BASE_VAR(packet_log_writers) = 0;
88 SCTP_BASE_VAR(packet_log_end) = 0;
89 memset(&SCTP_BASE_VAR(packet_log_buffer), 0, SCTP_PACKET_LOG_SIZE);
91 SCTP_BASE_VAR(eh_tag) = EVENTHANDLER_REGISTER(rt_addrmsg,
92 sctp_addr_change_event_handler, NULL, EVENTHANDLER_PRI_FIRST);
95 VNET_SYSINIT(sctp_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, sctp_init, NULL);
99 sctp_finish(void *unused __unused)
101 EVENTHANDLER_DEREGISTER(rt_addrmsg, SCTP_BASE_VAR(eh_tag));
105 VNET_SYSUNINIT(sctp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, sctp_finish, NULL);
109 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint32_t mtu, bool resend)
111 struct sctp_association *asoc;
112 struct sctp_tmit_chunk *chk;
116 KASSERT(mtu < asoc->smallest_mtu,
117 ("Currently only reducing association MTU %u supported (MTU %u)",
118 asoc->smallest_mtu, mtu));
119 asoc->smallest_mtu = mtu;
120 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
121 overhead = SCTP_MIN_OVERHEAD;
123 overhead = SCTP_MIN_V4_OVERHEAD;
125 if (asoc->idata_supported) {
126 if (sctp_auth_is_required_chunk(SCTP_IDATA, asoc->peer_auth_chunks)) {
127 overhead += sctp_get_auth_chunk_len(asoc->peer_hmac_id);
130 if (sctp_auth_is_required_chunk(SCTP_DATA, asoc->peer_auth_chunks)) {
131 overhead += sctp_get_auth_chunk_len(asoc->peer_hmac_id);
134 KASSERT(overhead % 4 == 0,
135 ("overhead (%u) not a multiple of 4", overhead));
136 TAILQ_FOREACH(chk, &asoc->send_queue, sctp_next) {
137 if (((uint32_t)chk->send_size + overhead) > mtu) {
138 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
141 TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) {
142 if (((uint32_t)chk->send_size + overhead) > mtu) {
143 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
144 if (resend && chk->sent < SCTP_DATAGRAM_RESEND) {
146 * If requested, mark the chunk for
147 * immediate resend, since we sent it being
150 sctp_flight_size_decrease(chk);
151 sctp_total_flight_decrease(stcb, chk);
152 chk->sent = SCTP_DATAGRAM_RESEND;
153 sctp_ucount_incr(asoc->sent_queue_retran_cnt);
154 chk->rec.data.doing_fast_retransmit = 0;
155 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
156 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
157 chk->whoTo->flight_size,
159 (uint32_t)(uintptr_t)chk->whoTo,
162 /* Clear any time, so NO RTT is being done. */
163 if (chk->do_rtt == 1) {
165 chk->whoTo->rto_needed = 1;
174 sctp_notify(struct sctp_inpcb *inp,
175 struct sctp_tcb *stcb,
176 struct sctp_nets *net,
184 if (icmp_type != ICMP_UNREACH) {
185 /* We only care about unreachable */
186 SCTP_TCB_UNLOCK(stcb);
189 if ((icmp_code == ICMP_UNREACH_NET) ||
190 (icmp_code == ICMP_UNREACH_HOST) ||
191 (icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
192 (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
193 (icmp_code == ICMP_UNREACH_ISOLATED) ||
194 (icmp_code == ICMP_UNREACH_NET_PROHIB) ||
195 (icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
196 (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
197 /* Mark the net unreachable. */
198 if (net->dest_state & SCTP_ADDR_REACHABLE) {
199 /* OK, that destination is NOT reachable. */
200 net->dest_state &= ~SCTP_ADDR_REACHABLE;
201 net->dest_state &= ~SCTP_ADDR_PF;
202 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
204 (void *)net, SCTP_SO_NOT_LOCKED);
206 SCTP_TCB_UNLOCK(stcb);
207 } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) ||
208 (icmp_code == ICMP_UNREACH_PORT)) {
209 /* Treat it like an ABORT. */
210 sctp_abort_notification(stcb, true, false, 0, NULL, SCTP_SO_NOT_LOCKED);
211 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
212 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
213 /* no need to unlock here, since the TCB is gone */
214 } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) {
215 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
216 SCTP_TCB_UNLOCK(stcb);
219 /* Find the next (smaller) MTU */
222 * Old type router that does not tell us what the
223 * next MTU is. Rats we will have to guess (in a
224 * educated fashion of course).
226 next_mtu = sctp_get_prev_mtu(ip_len);
228 /* Stop the PMTU timer. */
229 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
231 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
232 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
236 /* Update the path MTU. */
238 next_mtu -= sizeof(struct udphdr);
240 if (net->mtu > next_mtu) {
243 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu + sizeof(struct udphdr));
245 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu);
248 /* Update the association MTU */
249 if (stcb->asoc.smallest_mtu > next_mtu) {
250 sctp_pathmtu_adjustment(stcb, next_mtu, true);
252 /* Finally, start the PMTU timer if it was running before. */
254 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
256 SCTP_TCB_UNLOCK(stcb);
258 SCTP_TCB_UNLOCK(stcb);
263 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
269 struct sctp_inpcb *inp;
270 struct sctp_tcb *stcb;
271 struct sctp_nets *net;
272 struct sctp_init_chunk *ch;
273 struct sockaddr_in src, dst;
275 if (sa->sa_family != AF_INET ||
276 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
279 if (PRC_IS_REDIRECT(cmd)) {
281 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
285 inner_ip = (struct ip *)vip;
286 icmp = (struct icmp *)((caddr_t)inner_ip -
287 (sizeof(struct icmp) - sizeof(struct ip)));
288 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
289 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
290 memset(&src, 0, sizeof(struct sockaddr_in));
291 src.sin_family = AF_INET;
292 src.sin_len = sizeof(struct sockaddr_in);
293 src.sin_port = sh->src_port;
294 src.sin_addr = inner_ip->ip_src;
295 memset(&dst, 0, sizeof(struct sockaddr_in));
296 dst.sin_family = AF_INET;
297 dst.sin_len = sizeof(struct sockaddr_in);
298 dst.sin_port = sh->dest_port;
299 dst.sin_addr = inner_ip->ip_dst;
301 * 'dst' holds the dest of the packet that failed to be
302 * sent. 'src' holds our local endpoint address. Thus we
303 * reverse the dst and the src in the lookup.
307 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
308 (struct sockaddr *)&src,
311 if ((stcb != NULL) &&
314 /* Check the verification tag */
315 if (ntohl(sh->v_tag) != 0) {
317 * This must be the verification tag used
318 * for sending out packets. We don't
319 * consider packets reflecting the
322 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
323 SCTP_TCB_UNLOCK(stcb);
327 if (ntohs(outer_ip->ip_len) >=
329 8 + (inner_ip->ip_hl << 2) + 20) {
331 * In this case we can check if we
332 * got an INIT chunk and if the
333 * initiate tag matches.
335 ch = (struct sctp_init_chunk *)(sh + 1);
336 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
337 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
338 SCTP_TCB_UNLOCK(stcb);
342 SCTP_TCB_UNLOCK(stcb);
346 sctp_notify(inp, stcb, net,
349 ntohs(inner_ip->ip_len),
350 (uint32_t)ntohs(icmp->icmp_nextmtu));
352 if ((stcb == NULL) && (inp != NULL)) {
353 /* reduce ref-count */
355 SCTP_INP_DECR_REF(inp);
356 SCTP_INP_WUNLOCK(inp);
359 SCTP_TCB_UNLOCK(stcb);
368 sctp_getcred(SYSCTL_HANDLER_ARGS)
371 struct sockaddr_in addrs[2];
372 struct sctp_inpcb *inp;
373 struct sctp_nets *net;
374 struct sctp_tcb *stcb;
378 /* FIX, for non-bsd is this right? */
379 vrf_id = SCTP_DEFAULT_VRFID;
381 error = priv_check(req->td, PRIV_NETINET_GETCRED);
386 error = SYSCTL_IN(req, addrs, sizeof(addrs));
390 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
392 &inp, &net, 1, vrf_id);
393 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
394 if ((inp != NULL) && (stcb == NULL)) {
395 /* reduce ref-count */
397 SCTP_INP_DECR_REF(inp);
401 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
405 SCTP_TCB_UNLOCK(stcb);
407 * We use the write lock here, only since in the error leg we need
408 * it. If we used RLOCK, then we would have to
409 * wlock/decr/unlock/rlock. Which in theory could create a hole.
410 * Better to use higher wlock.
414 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
416 SCTP_INP_WUNLOCK(inp);
419 cru2x(inp->sctp_socket->so_cred, &xuc);
420 SCTP_INP_WUNLOCK(inp);
421 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
426 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred,
427 CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
428 0, 0, sctp_getcred, "S,ucred",
429 "Get the ucred of a SCTP connection");
433 sctp_abort(struct socket *so)
435 struct epoch_tracker et;
436 struct sctp_inpcb *inp;
438 inp = (struct sctp_inpcb *)so->so_pcb;
445 #ifdef SCTP_LOG_CLOSING
446 sctp_log_closing(inp, NULL, 17);
448 if (((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0)) {
449 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP;
450 #ifdef SCTP_LOG_CLOSING
451 sctp_log_closing(inp, NULL, 16);
453 SCTP_INP_WUNLOCK(inp);
454 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
455 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
457 KASSERT(!SOLISTENING(so),
458 ("sctp_abort: called on listening socket %p", so));
459 SCTP_SB_CLEAR(so->so_snd);
460 SCTP_SB_CLEAR(so->so_rcv);
461 /* Now null out the reference, we are completely detached. */
465 SCTP_INP_WUNLOCK(inp);
471 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
473 struct sctp_inpcb *inp;
474 struct inpcb *ip_inp;
476 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
478 inp = (struct sctp_inpcb *)so->so_pcb;
480 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
483 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
484 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
489 error = sctp_inpcb_alloc(so, vrf_id);
493 inp = (struct sctp_inpcb *)so->so_pcb;
495 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
496 ip_inp = &inp->ip_inp.inp;
497 ip_inp->inp_vflag |= INP_IPV4;
498 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
499 SCTP_INP_WUNLOCK(inp);
504 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
506 struct sctp_inpcb *inp;
508 inp = (struct sctp_inpcb *)so->so_pcb;
510 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
514 if ((addr->sa_family != AF_INET) ||
515 (addr->sa_len != sizeof(struct sockaddr_in))) {
516 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
520 return (sctp_inpcb_bind(so, addr, NULL, p));
525 sctp_close(struct socket *so)
527 struct epoch_tracker et;
528 struct sctp_inpcb *inp;
530 inp = (struct sctp_inpcb *)so->so_pcb;
535 * Inform all the lower layer assoc that we are done.
539 #ifdef SCTP_LOG_CLOSING
540 sctp_log_closing(inp, NULL, 17);
542 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
543 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP;
544 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
545 (SCTP_SBAVAIL(&so->so_rcv) > 0)) {
546 #ifdef SCTP_LOG_CLOSING
547 sctp_log_closing(inp, NULL, 13);
549 SCTP_INP_WUNLOCK(inp);
550 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
551 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
553 #ifdef SCTP_LOG_CLOSING
554 sctp_log_closing(inp, NULL, 14);
556 SCTP_INP_WUNLOCK(inp);
557 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
558 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
561 * The socket is now detached, no matter what the state of
562 * the SCTP association.
565 if (!SOLISTENING(so)) {
566 SCTP_SB_CLEAR(so->so_snd);
567 SCTP_SB_CLEAR(so->so_rcv);
569 /* Now null out the reference, we are completely detached. */
573 SCTP_INP_WUNLOCK(inp);
579 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
580 struct mbuf *control, struct thread *p);
583 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
584 struct mbuf *control, struct thread *p)
586 struct sctp_inpcb *inp;
589 inp = (struct sctp_inpcb *)so->so_pcb;
592 sctp_m_freem(control);
595 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
599 /* Got to have an to address if we are NOT a connected socket */
600 if ((addr == NULL) &&
601 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
602 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
608 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
609 error = EDESTADDRREQ;
610 } else if (addr->sa_family != AF_INET) {
611 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
612 error = EAFNOSUPPORT;
613 } else if (addr->sa_len != sizeof(struct sockaddr_in)) {
614 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
620 sctp_m_freem(control);
626 /* now what about control */
629 sctp_m_freem(inp->control);
632 inp->control = control;
636 SCTP_BUF_NEXT(inp->pkt_last) = m;
639 inp->pkt_last = inp->pkt = m;
642 /* FreeBSD uses a flag passed */
643 ((flags & PRUS_MORETOCOME) == 0)
646 * note with the current version this code will only be used
647 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
648 * re-defining sosend to use the sctp_sosend. One can
649 * optionally switch back to this code (by changing back the
650 * definitions) but this is not advisable. This code is used
651 * by FreeBSD when sending a file with sendfile() though.
653 struct epoch_tracker et;
657 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
668 sctp_disconnect(struct socket *so)
670 struct sctp_inpcb *inp;
672 inp = (struct sctp_inpcb *)so->so_pcb;
674 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
678 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
679 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
680 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
682 SCTP_INP_RUNLOCK(inp);
685 struct epoch_tracker et;
686 struct sctp_association *asoc;
687 struct sctp_tcb *stcb;
689 stcb = LIST_FIRST(&inp->sctp_asoc_list);
691 SCTP_INP_RUNLOCK(inp);
692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
697 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
698 /* We are about to be freed, out of here */
699 SCTP_TCB_UNLOCK(stcb);
700 SCTP_INP_RUNLOCK(inp);
704 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
705 (SCTP_SBAVAIL(&so->so_rcv) > 0)) {
706 if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) {
707 /* Left with Data unread */
710 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
711 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
712 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
714 SCTP_INP_RUNLOCK(inp);
715 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
716 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
717 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
719 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
720 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
721 /* No unlock tcb assoc is gone */
725 if (TAILQ_EMPTY(&asoc->send_queue) &&
726 TAILQ_EMPTY(&asoc->sent_queue) &&
727 (asoc->stream_queue_cnt == 0)) {
728 /* there is nothing queued to send, so done */
729 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
732 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) &&
733 (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
734 /* only send SHUTDOWN 1st time thru */
735 struct sctp_nets *netp;
737 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
738 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
739 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
741 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
742 sctp_stop_timers_for_shutdown(stcb);
743 if (stcb->asoc.alternate) {
744 netp = stcb->asoc.alternate;
746 netp = stcb->asoc.primary_destination;
748 sctp_send_shutdown(stcb, netp);
749 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
750 stcb->sctp_ep, stcb, netp);
751 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
752 stcb->sctp_ep, stcb, NULL);
753 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
757 * we still got (or just got) data to send,
758 * so set SHUTDOWN_PENDING
761 * XXX sockets draft says that SCTP_EOF
762 * should be sent with no data. currently,
763 * we will allow user data to be sent first
764 * and move to SHUTDOWN-PENDING
766 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
767 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
768 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
769 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
771 if (TAILQ_EMPTY(&asoc->send_queue) &&
772 TAILQ_EMPTY(&asoc->sent_queue) &&
773 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
777 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
778 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
779 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
780 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
781 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
782 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
783 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
785 SCTP_INP_RUNLOCK(inp);
786 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
787 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
791 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
794 soisdisconnecting(so);
796 SCTP_TCB_UNLOCK(stcb);
797 SCTP_INP_RUNLOCK(inp);
802 /* UDP model does not support this */
803 SCTP_INP_RUNLOCK(inp);
804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
810 sctp_flush(struct socket *so, int how)
813 * We will just clear out the values and let subsequent close clear
814 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
815 * they will not be able to read the data, the socket will block
816 * that from happening.
818 struct sctp_inpcb *inp;
820 inp = (struct sctp_inpcb *)so->so_pcb;
822 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
826 /* For the 1 to many model this does nothing */
827 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
828 SCTP_INP_RUNLOCK(inp);
831 SCTP_INP_RUNLOCK(inp);
832 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
834 * First make sure the sb will be happy, we don't use these
835 * except maybe the count
838 SCTP_INP_READ_LOCK(inp);
839 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
840 SCTP_INP_READ_UNLOCK(inp);
841 SCTP_INP_WUNLOCK(inp);
843 KASSERT(!SOLISTENING(so),
844 ("sctp_flush: called on listening socket %p", so));
845 SCTP_SB_CLEAR(so->so_rcv);
848 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
850 * First make sure the sb will be happy, we don't use these
851 * except maybe the count
854 KASSERT(!SOLISTENING(so),
855 ("sctp_flush: called on listening socket %p", so));
856 SCTP_SB_CLEAR(so->so_snd);
863 sctp_shutdown(struct socket *so)
865 struct sctp_inpcb *inp;
867 inp = (struct sctp_inpcb *)so->so_pcb;
869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
873 /* For UDP model this is a invalid call */
874 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
875 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
876 /* Restore the flags that the soshutdown took away. */
877 SOCKBUF_LOCK(&so->so_rcv);
878 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
879 SOCKBUF_UNLOCK(&so->so_rcv);
880 /* This proc will wakeup for read and do nothing (I hope) */
881 SCTP_INP_RUNLOCK(inp);
882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
886 * Ok, if we reach here its the TCP model and it is either a
887 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
890 struct epoch_tracker et;
891 struct sctp_tcb *stcb;
892 struct sctp_association *asoc;
893 struct sctp_nets *netp;
896 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
897 SCTP_INP_RUNLOCK(inp);
902 stcb = LIST_FIRST(&inp->sctp_asoc_list);
905 * Ok, we hit the case that the shutdown call was
906 * made after an abort or something. Nothing to do
909 SCTP_INP_RUNLOCK(inp);
914 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
915 SCTP_TCB_UNLOCK(stcb);
916 SCTP_INP_RUNLOCK(inp);
919 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) &&
920 (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) &&
921 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) {
923 * If we are not in or before ESTABLISHED, there is
924 * no protocol action required.
926 SCTP_TCB_UNLOCK(stcb);
927 SCTP_INP_RUNLOCK(inp);
931 if (stcb->asoc.alternate) {
932 netp = stcb->asoc.alternate;
934 netp = stcb->asoc.primary_destination;
936 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) &&
937 TAILQ_EMPTY(&asoc->send_queue) &&
938 TAILQ_EMPTY(&asoc->sent_queue) &&
939 (asoc->stream_queue_cnt == 0)) {
940 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
943 /* there is nothing queued to send, so I'm done... */
944 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
945 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
946 sctp_stop_timers_for_shutdown(stcb);
947 sctp_send_shutdown(stcb, netp);
948 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
949 stcb->sctp_ep, stcb, netp);
952 * We still got (or just got) data to send, so set
955 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
956 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
957 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
959 if (TAILQ_EMPTY(&asoc->send_queue) &&
960 TAILQ_EMPTY(&asoc->sent_queue) &&
961 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
965 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
966 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
967 SCTP_INP_RUNLOCK(inp);
968 sctp_abort_an_association(stcb->sctp_ep, stcb,
969 op_err, false, SCTP_SO_LOCKED);
974 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
976 * XXX: Why do this in the case where we have still data
979 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
980 SCTP_TCB_UNLOCK(stcb);
981 SCTP_INP_RUNLOCK(inp);
988 * copies a "user" presentable address and removes embedded scope, etc.
989 * returns 0 on success, 1 on error
992 sctp_fill_user_address(struct sockaddr *dst, struct sockaddr *src)
995 struct sockaddr_in6 lsa6;
997 src = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)src,
1000 memcpy(dst, src, src->sa_len);
1005 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1006 struct sctp_tcb *stcb,
1008 struct sockaddr *addr,
1011 struct sctp_ifn *sctp_ifn;
1012 struct sctp_ifa *sctp_ifa;
1016 int ipv4_local_scope, ipv4_addr_legal;
1019 int local_scope, site_scope, ipv6_addr_legal;
1021 struct sctp_vrf *vrf;
1023 SCTP_IPI_ADDR_LOCK_ASSERT();
1029 /* Turn on all the appropriate scope */
1030 loopback_scope = stcb->asoc.scope.loopback_scope;
1032 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1033 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1036 local_scope = stcb->asoc.scope.local_scope;
1037 site_scope = stcb->asoc.scope.site_scope;
1038 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1041 /* Use generic values for endpoints. */
1044 ipv4_local_scope = 1;
1050 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1052 ipv6_addr_legal = 1;
1055 if (SCTP_IPV6_V6ONLY(inp)) {
1056 ipv4_addr_legal = 0;
1058 ipv4_addr_legal = 1;
1063 ipv6_addr_legal = 0;
1066 ipv4_addr_legal = 1;
1070 vrf = sctp_find_vrf(vrf_id);
1074 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1075 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1076 if ((loopback_scope == 0) &&
1077 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1078 /* Skip loopback if loopback_scope not set */
1081 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1084 * For the BOUND-ALL case, the list
1085 * associated with a TCB is Always
1086 * considered a reverse list.. i.e.
1087 * it lists addresses that are NOT
1088 * part of the association. If this
1089 * is one of those we must skip it.
1091 if (sctp_is_addr_restricted(stcb,
1096 switch (sctp_ifa->address.sa.sa_family) {
1099 if (ipv4_addr_legal) {
1100 struct sockaddr_in *sin;
1102 sin = &sctp_ifa->address.sin;
1103 if (sin->sin_addr.s_addr == 0) {
1111 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1112 &sin->sin_addr) != 0) {
1115 if ((ipv4_local_scope == 0) &&
1116 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1120 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1121 if (actual + sizeof(struct sockaddr_in6) > limit) {
1124 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)addr);
1125 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1126 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1127 actual += sizeof(struct sockaddr_in6);
1130 if (actual + sizeof(struct sockaddr_in) > limit) {
1133 memcpy(addr, sin, sizeof(struct sockaddr_in));
1134 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1135 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in));
1136 actual += sizeof(struct sockaddr_in);
1147 if (ipv6_addr_legal) {
1148 struct sockaddr_in6 *sin6;
1150 sin6 = &sctp_ifa->address.sin6;
1151 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1159 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1160 &sin6->sin6_addr) != 0) {
1163 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1164 if (local_scope == 0)
1166 if (sin6->sin6_scope_id == 0) {
1167 if (sa6_recoverscope(sin6) != 0)
1180 if ((site_scope == 0) &&
1181 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1184 if (actual + sizeof(struct sockaddr_in6) > limit) {
1187 memcpy(addr, sin6, sizeof(struct sockaddr_in6));
1188 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1189 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1190 actual += sizeof(struct sockaddr_in6);
1203 struct sctp_laddr *laddr;
1206 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1208 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1212 sa_len = laddr->ifa->address.sa.sa_len;
1213 if (actual + sa_len > limit) {
1216 if (sctp_fill_user_address(addr, &laddr->ifa->address.sa))
1218 switch (laddr->ifa->address.sa.sa_family) {
1221 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1226 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1233 addr = (struct sockaddr *)((caddr_t)addr + sa_len);
1241 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1242 struct sctp_tcb *stcb,
1244 struct sockaddr *addr)
1248 SCTP_IPI_ADDR_RLOCK();
1249 /* fill up addresses for the endpoint's default vrf */
1250 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, addr,
1252 SCTP_IPI_ADDR_RUNLOCK();
1257 sctp_max_size_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1259 struct sctp_vrf *vrf;
1263 * In both sub-set bound an bound_all cases we return the size of
1264 * the maximum number of addresses that you could get. In reality
1265 * the sub-set bound may have an exclusion list for a given TCB or
1266 * in the bound-all case a TCB may NOT include the loopback or other
1267 * addresses as well.
1269 SCTP_IPI_ADDR_LOCK_ASSERT();
1270 vrf = sctp_find_vrf(vrf_id);
1275 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1276 struct sctp_ifn *sctp_ifn;
1277 struct sctp_ifa *sctp_ifa;
1279 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1280 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1281 /* Count them if they are the right type */
1282 switch (sctp_ifa->address.sa.sa_family) {
1286 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1287 size += sizeof(struct sockaddr_in6);
1289 size += sizeof(struct sockaddr_in);
1291 size += sizeof(struct sockaddr_in);
1297 size += sizeof(struct sockaddr_in6);
1306 struct sctp_laddr *laddr;
1308 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1309 switch (laddr->ifa->address.sa.sa_family) {
1313 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1314 size += sizeof(struct sockaddr_in6);
1316 size += sizeof(struct sockaddr_in);
1318 size += sizeof(struct sockaddr_in);
1324 size += sizeof(struct sockaddr_in6);
1336 sctp_max_size_addresses(struct sctp_inpcb *inp)
1340 SCTP_IPI_ADDR_RLOCK();
1341 /* Maximum size of all addresses for the endpoint's default VRF */
1342 size = sctp_max_size_addresses_vrf(inp, inp->def_vrf_id);
1343 SCTP_IPI_ADDR_RUNLOCK();
1348 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1349 size_t optsize, void *p, int delay)
1352 int creat_lock_on = 0;
1353 struct sctp_tcb *stcb = NULL;
1354 struct sockaddr *sa;
1355 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1359 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1361 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1362 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1363 /* We are already connected AND the TCP model */
1364 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1365 return (EADDRINUSE);
1368 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1369 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1370 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1374 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1375 SCTP_INP_RLOCK(inp);
1376 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1377 SCTP_INP_RUNLOCK(inp);
1380 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1383 SCTP_INP_INCR_REF(inp);
1384 SCTP_ASOC_CREATE_LOCK(inp);
1386 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1387 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1388 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1392 totaddrp = (unsigned int *)optval;
1393 totaddr = *totaddrp;
1394 sa = (struct sockaddr *)(totaddrp + 1);
1395 error = sctp_connectx_helper_find(inp, sa, totaddr, &num_v4, &num_v6, (unsigned int)(optsize - sizeof(int)));
1397 /* Already have or am bring up an association */
1398 SCTP_ASOC_CREATE_UNLOCK(inp);
1400 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1404 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1409 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1411 if (SCTP_IPV6_V6ONLY(inp)) {
1413 * if IPV6_V6ONLY flag, ignore connections destined
1414 * to a v4 addr or v4-mapped addr
1416 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1422 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
1423 /* Bind a ephemeral port */
1424 error = sctp_inpcb_bind(so, NULL, NULL, p);
1430 /* FIX ME: do we want to pass in a vrf on the connect call? */
1431 vrf_id = inp->def_vrf_id;
1433 /* We are GOOD to go */
1434 stcb = sctp_aloc_assoc_connected(inp, sa, &error, 0, 0, vrf_id,
1435 inp->sctp_ep.pre_open_stream_count,
1438 SCTP_INITIALIZE_AUTH_PARAMS);
1440 /* Gak! no memory */
1443 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1444 /* move to second address */
1445 switch (sa->sa_family) {
1448 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1453 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1461 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1462 /* Fill in the return id */
1466 a_id = (sctp_assoc_t *)optval;
1467 *a_id = sctp_get_associd(stcb);
1470 /* doing delayed connection */
1471 stcb->asoc.delayed_connection = 1;
1472 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1474 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1475 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1477 SCTP_TCB_UNLOCK(stcb);
1479 if (creat_lock_on) {
1480 SCTP_ASOC_CREATE_UNLOCK(inp);
1482 SCTP_INP_DECR_REF(inp);
1486 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1487 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1488 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1489 SCTP_INP_RLOCK(inp); \
1490 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1492 SCTP_TCB_LOCK(stcb); \
1494 SCTP_INP_RUNLOCK(inp); \
1495 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1496 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1497 if (stcb == NULL) { \
1498 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1507 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1508 if (size < sizeof(type)) { \
1509 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1513 destp = (type *)srcp; \
1518 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1521 struct sctp_inpcb *inp = NULL;
1523 struct sctp_tcb *stcb = NULL;
1525 if (optval == NULL) {
1526 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1530 inp = (struct sctp_inpcb *)so->so_pcb;
1532 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1539 case SCTP_AUTOCLOSE:
1540 case SCTP_EXPLICIT_EOR:
1541 case SCTP_AUTO_ASCONF:
1542 case SCTP_DISABLE_FRAGMENTS:
1543 case SCTP_I_WANT_MAPPED_V4_ADDR:
1544 case SCTP_USE_EXT_RCVINFO:
1545 SCTP_INP_RLOCK(inp);
1547 case SCTP_DISABLE_FRAGMENTS:
1548 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1550 case SCTP_I_WANT_MAPPED_V4_ADDR:
1551 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1553 case SCTP_AUTO_ASCONF:
1554 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1555 /* only valid for bound all sockets */
1556 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1558 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1563 case SCTP_EXPLICIT_EOR:
1564 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1567 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1569 case SCTP_USE_EXT_RCVINFO:
1570 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1572 case SCTP_AUTOCLOSE:
1573 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1574 val = sctp_ticks_to_secs(inp->sctp_ep.auto_close_time);
1580 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1581 error = ENOPROTOOPT;
1582 } /* end switch (sopt->sopt_name) */
1583 if (*optsize < sizeof(val)) {
1584 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1588 SCTP_INP_RUNLOCK(inp);
1590 /* return the option value */
1591 *(int *)optval = val;
1592 *optsize = sizeof(val);
1595 case SCTP_GET_PACKET_LOG:
1597 #ifdef SCTP_PACKET_LOGGING
1601 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1602 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1605 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1610 case SCTP_REUSE_PORT:
1614 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1615 /* Can't do this for a 1-m socket */
1619 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1620 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1621 *optsize = sizeof(uint32_t);
1624 case SCTP_PARTIAL_DELIVERY_POINT:
1628 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1629 *value = inp->partial_delivery_point;
1630 *optsize = sizeof(uint32_t);
1633 case SCTP_FRAGMENT_INTERLEAVE:
1637 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1638 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1639 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1640 *value = SCTP_FRAG_LEVEL_2;
1642 *value = SCTP_FRAG_LEVEL_1;
1645 *value = SCTP_FRAG_LEVEL_0;
1647 *optsize = sizeof(uint32_t);
1650 case SCTP_INTERLEAVING_SUPPORTED:
1652 struct sctp_assoc_value *av;
1654 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1655 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1658 av->assoc_value = stcb->asoc.idata_supported;
1659 SCTP_TCB_UNLOCK(stcb);
1661 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1662 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1663 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1664 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1665 SCTP_INP_RLOCK(inp);
1666 if (inp->idata_supported) {
1667 av->assoc_value = 1;
1669 av->assoc_value = 0;
1671 SCTP_INP_RUNLOCK(inp);
1673 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1678 *optsize = sizeof(struct sctp_assoc_value);
1682 case SCTP_CMT_ON_OFF:
1684 struct sctp_assoc_value *av;
1686 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1687 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1689 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1690 SCTP_TCB_UNLOCK(stcb);
1692 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1693 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1694 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1695 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1696 SCTP_INP_RLOCK(inp);
1697 av->assoc_value = inp->sctp_cmt_on_off;
1698 SCTP_INP_RUNLOCK(inp);
1700 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1705 *optsize = sizeof(struct sctp_assoc_value);
1709 case SCTP_PLUGGABLE_CC:
1711 struct sctp_assoc_value *av;
1713 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1714 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1716 av->assoc_value = stcb->asoc.congestion_control_module;
1717 SCTP_TCB_UNLOCK(stcb);
1719 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1720 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1721 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1722 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1723 SCTP_INP_RLOCK(inp);
1724 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1725 SCTP_INP_RUNLOCK(inp);
1727 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1732 *optsize = sizeof(struct sctp_assoc_value);
1736 case SCTP_CC_OPTION:
1738 struct sctp_cc_option *cc_opt;
1740 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1741 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1745 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1748 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1749 *optsize = sizeof(struct sctp_cc_option);
1751 SCTP_TCB_UNLOCK(stcb);
1755 case SCTP_PLUGGABLE_SS:
1757 struct sctp_assoc_value *av;
1759 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1760 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1762 av->assoc_value = stcb->asoc.stream_scheduling_module;
1763 SCTP_TCB_UNLOCK(stcb);
1765 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1766 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1767 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1768 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1769 SCTP_INP_RLOCK(inp);
1770 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1771 SCTP_INP_RUNLOCK(inp);
1773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1778 *optsize = sizeof(struct sctp_assoc_value);
1784 struct sctp_stream_value *av;
1786 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1787 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1789 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1790 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1791 &av->stream_value) < 0)) {
1792 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1795 *optsize = sizeof(struct sctp_stream_value);
1797 SCTP_TCB_UNLOCK(stcb);
1800 * Can't get stream value without
1803 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1808 case SCTP_GET_ADDR_LEN:
1810 struct sctp_assoc_value *av;
1812 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1815 if (av->assoc_value == AF_INET) {
1816 av->assoc_value = sizeof(struct sockaddr_in);
1821 if (av->assoc_value == AF_INET6) {
1822 av->assoc_value = sizeof(struct sockaddr_in6);
1827 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1829 *optsize = sizeof(struct sctp_assoc_value);
1833 case SCTP_GET_ASSOC_NUMBER:
1835 uint32_t *value, cnt;
1837 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1838 SCTP_INP_RLOCK(inp);
1839 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1840 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1841 /* Can't do this for a 1-1 socket */
1843 SCTP_INP_RUNLOCK(inp);
1847 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1850 SCTP_INP_RUNLOCK(inp);
1852 *optsize = sizeof(uint32_t);
1855 case SCTP_GET_ASSOC_ID_LIST:
1857 struct sctp_assoc_ids *ids;
1861 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1862 SCTP_INP_RLOCK(inp);
1863 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1864 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1865 /* Can't do this for a 1-1 socket */
1867 SCTP_INP_RUNLOCK(inp);
1871 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1872 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1874 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1877 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1886 SCTP_INP_RUNLOCK(inp);
1888 ids->gaids_number_of_ids = at;
1889 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1895 struct sctp_assoc_value *av;
1897 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1898 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1901 av->assoc_value = stcb->asoc.context;
1902 SCTP_TCB_UNLOCK(stcb);
1904 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1905 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1906 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1907 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1908 SCTP_INP_RLOCK(inp);
1909 av->assoc_value = inp->sctp_context;
1910 SCTP_INP_RUNLOCK(inp);
1912 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1917 *optsize = sizeof(struct sctp_assoc_value);
1923 uint32_t *default_vrfid;
1925 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1926 *default_vrfid = inp->def_vrf_id;
1927 *optsize = sizeof(uint32_t);
1930 case SCTP_GET_ASOC_VRF:
1932 struct sctp_assoc_value *id;
1934 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1935 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1940 id->assoc_value = stcb->asoc.vrf_id;
1941 SCTP_TCB_UNLOCK(stcb);
1942 *optsize = sizeof(struct sctp_assoc_value);
1946 case SCTP_GET_VRF_IDS:
1948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1952 case SCTP_GET_NONCE_VALUES:
1954 struct sctp_get_nonce_values *gnv;
1956 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1957 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1960 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1961 gnv->gn_local_tag = stcb->asoc.my_vtag;
1962 SCTP_TCB_UNLOCK(stcb);
1963 *optsize = sizeof(struct sctp_get_nonce_values);
1965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1970 case SCTP_DELAYED_SACK:
1972 struct sctp_sack_info *sack;
1974 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1975 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1977 sack->sack_delay = stcb->asoc.delayed_ack;
1978 sack->sack_freq = stcb->asoc.sack_freq;
1979 SCTP_TCB_UNLOCK(stcb);
1981 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1982 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1983 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1984 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC))) {
1985 SCTP_INP_RLOCK(inp);
1986 sack->sack_delay = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1987 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
1988 SCTP_INP_RUNLOCK(inp);
1990 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1995 *optsize = sizeof(struct sctp_sack_info);
1999 case SCTP_GET_SNDBUF_USE:
2001 struct sctp_sockstat *ss;
2003 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2004 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2007 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2008 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2009 stcb->asoc.size_on_all_streams);
2010 SCTP_TCB_UNLOCK(stcb);
2011 *optsize = sizeof(struct sctp_sockstat);
2013 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2018 case SCTP_MAX_BURST:
2020 struct sctp_assoc_value *av;
2022 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2023 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2026 av->assoc_value = stcb->asoc.max_burst;
2027 SCTP_TCB_UNLOCK(stcb);
2029 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2030 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2031 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2032 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2033 SCTP_INP_RLOCK(inp);
2034 av->assoc_value = inp->sctp_ep.max_burst;
2035 SCTP_INP_RUNLOCK(inp);
2037 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2042 *optsize = sizeof(struct sctp_assoc_value);
2048 struct sctp_assoc_value *av;
2050 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2051 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2054 av->assoc_value = stcb->asoc.sctp_frag_point;
2055 SCTP_TCB_UNLOCK(stcb);
2057 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2058 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2059 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2060 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2061 SCTP_INP_RLOCK(inp);
2062 av->assoc_value = inp->sctp_frag_point;
2063 SCTP_INP_RUNLOCK(inp);
2065 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2070 *optsize = sizeof(struct sctp_assoc_value);
2074 case SCTP_GET_STAT_LOG:
2075 error = sctp_fill_stat_log(optval, optsize);
2079 struct sctp_event_subscribe *events;
2081 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2082 memset(events, 0, sizeof(struct sctp_event_subscribe));
2083 SCTP_INP_RLOCK(inp);
2084 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2085 events->sctp_data_io_event = 1;
2087 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2088 events->sctp_association_event = 1;
2090 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2091 events->sctp_address_event = 1;
2093 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2094 events->sctp_send_failure_event = 1;
2096 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2097 events->sctp_peer_error_event = 1;
2099 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2100 events->sctp_shutdown_event = 1;
2102 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2103 events->sctp_partial_delivery_event = 1;
2105 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2106 events->sctp_adaptation_layer_event = 1;
2108 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2109 events->sctp_authentication_event = 1;
2111 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2112 events->sctp_sender_dry_event = 1;
2114 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2115 events->sctp_stream_reset_event = 1;
2116 SCTP_INP_RUNLOCK(inp);
2117 *optsize = sizeof(struct sctp_event_subscribe);
2120 case SCTP_ADAPTATION_LAYER:
2124 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2126 SCTP_INP_RLOCK(inp);
2127 *value = inp->sctp_ep.adaptation_layer_indicator;
2128 SCTP_INP_RUNLOCK(inp);
2129 *optsize = sizeof(uint32_t);
2132 case SCTP_SET_INITIAL_DBG_SEQ:
2136 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2137 SCTP_INP_RLOCK(inp);
2138 *value = inp->sctp_ep.initial_sequence_debug;
2139 SCTP_INP_RUNLOCK(inp);
2140 *optsize = sizeof(uint32_t);
2143 case SCTP_GET_LOCAL_ADDR_SIZE:
2147 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2148 SCTP_INP_RLOCK(inp);
2149 *value = (uint32_t)sctp_max_size_addresses(inp);
2150 SCTP_INP_RUNLOCK(inp);
2151 *optsize = sizeof(uint32_t);
2154 case SCTP_GET_REMOTE_ADDR_SIZE:
2157 struct sctp_nets *net;
2160 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2161 /* FIXME MT: change to sctp_assoc_value? */
2162 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2166 /* Count the sizes */
2167 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2168 switch (net->ro._l_addr.sa.sa_family) {
2172 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2173 size += sizeof(struct sockaddr_in6);
2175 size += sizeof(struct sockaddr_in);
2178 size += sizeof(struct sockaddr_in);
2184 size += sizeof(struct sockaddr_in6);
2191 SCTP_TCB_UNLOCK(stcb);
2192 *value = (uint32_t)size;
2193 *optsize = sizeof(uint32_t);
2195 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2196 ((sctp_assoc_t)*value <= SCTP_ALL_ASSOC)) {
2201 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2205 case SCTP_GET_PEER_ADDRESSES:
2207 * Get the address information, an array is passed in to
2208 * fill up we pack it.
2212 struct sockaddr *addr;
2213 struct sctp_nets *net;
2214 struct sctp_getaddresses *saddr;
2216 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2217 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2220 left = *optsize - offsetof(struct sctp_getaddresses, addr);
2221 *optsize = offsetof(struct sctp_getaddresses, addr);
2222 addr = &saddr->addr[0].sa;
2224 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2225 switch (net->ro._l_addr.sa.sa_family) {
2229 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2230 cpsz = sizeof(struct sockaddr_in6);
2232 cpsz = sizeof(struct sockaddr_in);
2235 cpsz = sizeof(struct sockaddr_in);
2241 cpsz = sizeof(struct sockaddr_in6);
2252 /* not enough room. */
2255 #if defined(INET) && defined(INET6)
2256 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2257 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2258 /* Must map the address */
2259 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2260 (struct sockaddr_in6 *)addr);
2262 memcpy(addr, &net->ro._l_addr, cpsz);
2265 memcpy(addr, &net->ro._l_addr, cpsz);
2267 ((struct sockaddr_in *)addr)->sin_port = stcb->rport;
2269 addr = (struct sockaddr *)((caddr_t)addr + cpsz);
2273 SCTP_TCB_UNLOCK(stcb);
2275 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2276 (saddr->sget_assoc_id <= SCTP_ALL_ASSOC)) {
2281 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2285 case SCTP_GET_LOCAL_ADDRESSES:
2287 size_t limit, actual;
2288 struct sctp_getaddresses *saddr;
2290 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2291 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2293 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2294 ((saddr->sget_assoc_id == SCTP_CURRENT_ASSOC) ||
2295 (saddr->sget_assoc_id == SCTP_ALL_ASSOC))) {
2298 limit = *optsize - offsetof(struct sctp_getaddresses, addr);
2299 actual = sctp_fill_up_addresses(inp, stcb, limit, &saddr->addr[0].sa);
2300 *optsize = offsetof(struct sctp_getaddresses, addr) + actual;
2303 SCTP_TCB_UNLOCK(stcb);
2307 case SCTP_PEER_ADDR_PARAMS:
2309 struct sctp_paddrparams *paddrp;
2310 struct sctp_nets *net;
2311 struct sockaddr *addr;
2312 #if defined(INET) && defined(INET6)
2313 struct sockaddr_in sin_store;
2316 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2317 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2319 #if defined(INET) && defined(INET6)
2320 if (paddrp->spp_address.ss_family == AF_INET6) {
2321 struct sockaddr_in6 *sin6;
2323 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2324 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2325 in6_sin6_2_sin(&sin_store, sin6);
2326 addr = (struct sockaddr *)&sin_store;
2328 addr = (struct sockaddr *)&paddrp->spp_address;
2331 addr = (struct sockaddr *)&paddrp->spp_address;
2334 addr = (struct sockaddr *)&paddrp->spp_address;
2337 net = sctp_findnet(stcb, addr);
2340 * We increment here since
2341 * sctp_findassociation_ep_addr() wil do a
2342 * decrement if it finds the stcb as long as
2343 * the locked tcb (last argument) is NOT a
2347 SCTP_INP_INCR_REF(inp);
2348 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2350 SCTP_INP_DECR_REF(inp);
2353 if ((stcb != NULL) && (net == NULL)) {
2355 if (addr->sa_family == AF_INET) {
2356 struct sockaddr_in *sin;
2358 sin = (struct sockaddr_in *)addr;
2359 if (sin->sin_addr.s_addr != INADDR_ANY) {
2361 SCTP_TCB_UNLOCK(stcb);
2362 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2368 if (addr->sa_family == AF_INET6) {
2369 struct sockaddr_in6 *sin6;
2371 sin6 = (struct sockaddr_in6 *)addr;
2372 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2374 SCTP_TCB_UNLOCK(stcb);
2375 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2381 error = EAFNOSUPPORT;
2382 SCTP_TCB_UNLOCK(stcb);
2383 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2389 /* Applies to the specific association */
2390 paddrp->spp_flags = 0;
2392 paddrp->spp_hbinterval = net->heart_beat_delay;
2393 paddrp->spp_pathmaxrxt = net->failure_threshold;
2394 paddrp->spp_pathmtu = net->mtu;
2395 switch (net->ro._l_addr.sa.sa_family) {
2398 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2403 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2409 /* get flags for HB */
2410 if (net->dest_state & SCTP_ADDR_NOHB) {
2411 paddrp->spp_flags |= SPP_HB_DISABLE;
2413 paddrp->spp_flags |= SPP_HB_ENABLE;
2415 /* get flags for PMTU */
2416 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2417 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2419 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2421 if (net->dscp & 0x01) {
2422 paddrp->spp_dscp = net->dscp & 0xfc;
2423 paddrp->spp_flags |= SPP_DSCP;
2426 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2427 (net->flowlabel & 0x80000000)) {
2428 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2429 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2434 * No destination so return default
2437 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2438 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2439 if (stcb->asoc.default_dscp & 0x01) {
2440 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2441 paddrp->spp_flags |= SPP_DSCP;
2444 if (stcb->asoc.default_flowlabel & 0x80000000) {
2445 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2446 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2449 /* default settings should be these */
2450 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2451 paddrp->spp_flags |= SPP_HB_DISABLE;
2453 paddrp->spp_flags |= SPP_HB_ENABLE;
2455 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2456 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2458 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2460 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2462 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2463 SCTP_TCB_UNLOCK(stcb);
2465 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2466 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2467 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2468 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
2469 /* Use endpoint defaults */
2470 SCTP_INP_RLOCK(inp);
2471 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2472 paddrp->spp_hbinterval = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2473 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2474 /* get inp's default */
2475 if (inp->sctp_ep.default_dscp & 0x01) {
2476 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2477 paddrp->spp_flags |= SPP_DSCP;
2480 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2481 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2482 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2483 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2486 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2488 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2489 paddrp->spp_flags |= SPP_HB_ENABLE;
2491 paddrp->spp_flags |= SPP_HB_DISABLE;
2493 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2494 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2496 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2498 SCTP_INP_RUNLOCK(inp);
2500 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2505 *optsize = sizeof(struct sctp_paddrparams);
2509 case SCTP_GET_PEER_ADDR_INFO:
2511 struct sctp_paddrinfo *paddri;
2512 struct sctp_nets *net;
2513 struct sockaddr *addr;
2514 #if defined(INET) && defined(INET6)
2515 struct sockaddr_in sin_store;
2518 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2519 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2521 #if defined(INET) && defined(INET6)
2522 if (paddri->spinfo_address.ss_family == AF_INET6) {
2523 struct sockaddr_in6 *sin6;
2525 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2526 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2527 in6_sin6_2_sin(&sin_store, sin6);
2528 addr = (struct sockaddr *)&sin_store;
2530 addr = (struct sockaddr *)&paddri->spinfo_address;
2533 addr = (struct sockaddr *)&paddri->spinfo_address;
2536 addr = (struct sockaddr *)&paddri->spinfo_address;
2539 net = sctp_findnet(stcb, addr);
2542 * We increment here since
2543 * sctp_findassociation_ep_addr() wil do a
2544 * decrement if it finds the stcb as long as
2545 * the locked tcb (last argument) is NOT a
2549 SCTP_INP_INCR_REF(inp);
2550 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2552 SCTP_INP_DECR_REF(inp);
2556 if ((stcb != NULL) && (net != NULL)) {
2557 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2558 /* It's unconfirmed */
2559 paddri->spinfo_state = SCTP_UNCONFIRMED;
2560 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2562 paddri->spinfo_state = SCTP_ACTIVE;
2565 paddri->spinfo_state = SCTP_INACTIVE;
2567 paddri->spinfo_cwnd = net->cwnd;
2568 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2569 paddri->spinfo_rto = net->RTO;
2570 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2571 paddri->spinfo_mtu = net->mtu;
2572 switch (addr->sa_family) {
2575 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2580 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2586 SCTP_TCB_UNLOCK(stcb);
2587 *optsize = sizeof(struct sctp_paddrinfo);
2590 SCTP_TCB_UNLOCK(stcb);
2592 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2597 case SCTP_PCB_STATUS:
2599 struct sctp_pcbinfo *spcb;
2601 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2602 sctp_fill_pcbinfo(spcb);
2603 *optsize = sizeof(struct sctp_pcbinfo);
2608 struct sctp_nets *net;
2609 struct sctp_status *sstat;
2611 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2612 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2615 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2619 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2620 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2621 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2622 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2624 * We can't include chunks that have been passed to
2625 * the socket layer. Only things in queue.
2627 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2628 stcb->asoc.cnt_on_all_streams);
2629 sstat->sstat_instrms = stcb->asoc.streamincnt;
2630 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2631 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb);
2632 net = stcb->asoc.primary_destination;
2634 memcpy(&sstat->sstat_primary.spinfo_address,
2636 ((struct sockaddr *)(&net->ro._l_addr))->sa_len);
2637 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2639 * Again the user can get info from
2640 * sctp_constants.h for what the state of
2643 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2644 /* It's unconfirmed */
2645 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2646 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2648 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2651 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2653 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2654 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2655 sstat->sstat_primary.spinfo_rto = net->RTO;
2656 sstat->sstat_primary.spinfo_mtu = net->mtu;
2657 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2660 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2665 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2672 memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo));
2674 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2675 SCTP_TCB_UNLOCK(stcb);
2676 *optsize = sizeof(struct sctp_status);
2681 struct sctp_rtoinfo *srto;
2683 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2684 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2687 srto->srto_initial = stcb->asoc.initial_rto;
2688 srto->srto_max = stcb->asoc.maxrto;
2689 srto->srto_min = stcb->asoc.minrto;
2690 SCTP_TCB_UNLOCK(stcb);
2692 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2693 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2694 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2695 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
2696 SCTP_INP_RLOCK(inp);
2697 srto->srto_initial = inp->sctp_ep.initial_rto;
2698 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2699 srto->srto_min = inp->sctp_ep.sctp_minrto;
2700 SCTP_INP_RUNLOCK(inp);
2702 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2707 *optsize = sizeof(struct sctp_rtoinfo);
2713 struct sctp_timeouts *stimo;
2715 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2716 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2719 stimo->stimo_init = stcb->asoc.timoinit;
2720 stimo->stimo_data = stcb->asoc.timodata;
2721 stimo->stimo_sack = stcb->asoc.timosack;
2722 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2723 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2724 stimo->stimo_cookie = stcb->asoc.timocookie;
2725 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2726 SCTP_TCB_UNLOCK(stcb);
2727 *optsize = sizeof(struct sctp_timeouts);
2729 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2734 case SCTP_ASSOCINFO:
2736 struct sctp_assocparams *sasoc;
2738 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2739 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2742 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(stcb->asoc.cookie_life);
2743 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2744 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2745 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2746 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2747 SCTP_TCB_UNLOCK(stcb);
2749 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2750 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2751 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2752 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
2753 SCTP_INP_RLOCK(inp);
2754 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(inp->sctp_ep.def_cookie_life);
2755 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2756 sasoc->sasoc_number_peer_destinations = 0;
2757 sasoc->sasoc_peer_rwnd = 0;
2758 sasoc->sasoc_local_rwnd = (uint32_t)sbspace(&inp->sctp_socket->so_rcv);
2759 SCTP_INP_RUNLOCK(inp);
2761 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2766 *optsize = sizeof(struct sctp_assocparams);
2770 case SCTP_DEFAULT_SEND_PARAM:
2772 struct sctp_sndrcvinfo *s_info;
2774 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2775 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2778 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2779 SCTP_TCB_UNLOCK(stcb);
2781 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2782 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2783 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2784 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC))) {
2785 SCTP_INP_RLOCK(inp);
2786 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2787 SCTP_INP_RUNLOCK(inp);
2789 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2794 *optsize = sizeof(struct sctp_sndrcvinfo);
2800 struct sctp_initmsg *sinit;
2802 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2803 SCTP_INP_RLOCK(inp);
2804 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2805 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2806 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2807 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2808 SCTP_INP_RUNLOCK(inp);
2809 *optsize = sizeof(struct sctp_initmsg);
2812 case SCTP_PRIMARY_ADDR:
2813 /* we allow a "get" operation on this */
2815 struct sctp_setprim *ssp;
2817 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2818 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2821 union sctp_sockstore *addr;
2823 addr = &stcb->asoc.primary_destination->ro._l_addr;
2824 switch (addr->sa.sa_family) {
2828 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2829 in6_sin_2_v4mapsin6(&addr->sin,
2830 (struct sockaddr_in6 *)&ssp->ssp_addr);
2832 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2835 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2841 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2847 SCTP_TCB_UNLOCK(stcb);
2848 *optsize = sizeof(struct sctp_setprim);
2850 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2855 case SCTP_HMAC_IDENT:
2857 struct sctp_hmacalgo *shmac;
2858 sctp_hmaclist_t *hmaclist;
2862 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2864 SCTP_INP_RLOCK(inp);
2865 hmaclist = inp->sctp_ep.local_hmacs;
2866 if (hmaclist == NULL) {
2867 /* no HMACs to return */
2868 *optsize = sizeof(*shmac);
2869 SCTP_INP_RUNLOCK(inp);
2872 /* is there room for all of the hmac ids? */
2873 size = sizeof(*shmac) + (hmaclist->num_algo *
2874 sizeof(shmac->shmac_idents[0]));
2875 if (*optsize < size) {
2876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2878 SCTP_INP_RUNLOCK(inp);
2881 /* copy in the list */
2882 shmac->shmac_number_of_idents = hmaclist->num_algo;
2883 for (i = 0; i < hmaclist->num_algo; i++) {
2884 shmac->shmac_idents[i] = hmaclist->hmac[i];
2886 SCTP_INP_RUNLOCK(inp);
2890 case SCTP_AUTH_ACTIVE_KEY:
2892 struct sctp_authkeyid *scact;
2894 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2895 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2898 /* get the active key on the assoc */
2899 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2900 SCTP_TCB_UNLOCK(stcb);
2902 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2903 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2904 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2905 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC))) {
2906 /* get the endpoint active key */
2907 SCTP_INP_RLOCK(inp);
2908 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2909 SCTP_INP_RUNLOCK(inp);
2911 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2916 *optsize = sizeof(struct sctp_authkeyid);
2920 case SCTP_LOCAL_AUTH_CHUNKS:
2922 struct sctp_authchunks *sac;
2923 sctp_auth_chklist_t *chklist = NULL;
2926 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2927 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2930 /* get off the assoc */
2931 chklist = stcb->asoc.local_auth_chunks;
2932 /* is there enough space? */
2933 size = sctp_auth_get_chklist_size(chklist);
2934 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2936 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2938 /* copy in the chunks */
2939 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2940 sac->gauth_number_of_chunks = (uint32_t)size;
2941 *optsize = sizeof(struct sctp_authchunks) + size;
2943 SCTP_TCB_UNLOCK(stcb);
2945 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2946 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2947 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2948 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC))) {
2949 /* get off the endpoint */
2950 SCTP_INP_RLOCK(inp);
2951 chklist = inp->sctp_ep.local_auth_chunks;
2952 /* is there enough space? */
2953 size = sctp_auth_get_chklist_size(chklist);
2954 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2958 /* copy in the chunks */
2959 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2960 sac->gauth_number_of_chunks = (uint32_t)size;
2961 *optsize = sizeof(struct sctp_authchunks) + size;
2963 SCTP_INP_RUNLOCK(inp);
2965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2971 case SCTP_PEER_AUTH_CHUNKS:
2973 struct sctp_authchunks *sac;
2974 sctp_auth_chklist_t *chklist = NULL;
2977 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2978 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2981 /* get off the assoc */
2982 chklist = stcb->asoc.peer_auth_chunks;
2983 /* is there enough space? */
2984 size = sctp_auth_get_chklist_size(chklist);
2985 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2987 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2989 /* copy in the chunks */
2990 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2991 sac->gauth_number_of_chunks = (uint32_t)size;
2992 *optsize = sizeof(struct sctp_authchunks) + size;
2994 SCTP_TCB_UNLOCK(stcb);
2996 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3003 struct sctp_event *event;
3004 uint32_t event_type;
3006 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3007 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3009 switch (event->se_type) {
3010 case SCTP_ASSOC_CHANGE:
3011 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3013 case SCTP_PEER_ADDR_CHANGE:
3014 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3016 case SCTP_REMOTE_ERROR:
3017 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3019 case SCTP_SEND_FAILED:
3020 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3022 case SCTP_SHUTDOWN_EVENT:
3023 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3025 case SCTP_ADAPTATION_INDICATION:
3026 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3028 case SCTP_PARTIAL_DELIVERY_EVENT:
3029 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3031 case SCTP_AUTHENTICATION_EVENT:
3032 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3034 case SCTP_STREAM_RESET_EVENT:
3035 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3037 case SCTP_SENDER_DRY_EVENT:
3038 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3040 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3042 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3045 case SCTP_ASSOC_RESET_EVENT:
3046 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3048 case SCTP_STREAM_CHANGE_EVENT:
3049 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3051 case SCTP_SEND_FAILED_EVENT:
3052 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3056 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3060 if (event_type > 0) {
3062 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3064 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3065 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3066 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3067 (event->se_assoc_id == SCTP_FUTURE_ASSOC))) {
3068 SCTP_INP_RLOCK(inp);
3069 event->se_on = sctp_is_feature_on(inp, event_type);
3070 SCTP_INP_RUNLOCK(inp);
3072 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3078 SCTP_TCB_UNLOCK(stcb);
3081 *optsize = sizeof(struct sctp_event);
3085 case SCTP_RECVRCVINFO:
3086 if (*optsize < sizeof(int)) {
3087 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3090 SCTP_INP_RLOCK(inp);
3091 *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3092 SCTP_INP_RUNLOCK(inp);
3093 *optsize = sizeof(int);
3096 case SCTP_RECVNXTINFO:
3097 if (*optsize < sizeof(int)) {
3098 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3101 SCTP_INP_RLOCK(inp);
3102 *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3103 SCTP_INP_RUNLOCK(inp);
3104 *optsize = sizeof(int);
3107 case SCTP_DEFAULT_SNDINFO:
3109 struct sctp_sndinfo *info;
3111 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3112 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3115 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3116 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3117 info->snd_flags &= 0xfff0;
3118 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3119 info->snd_context = stcb->asoc.def_send.sinfo_context;
3120 SCTP_TCB_UNLOCK(stcb);
3122 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3123 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3124 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3125 (info->snd_assoc_id == SCTP_FUTURE_ASSOC))) {
3126 SCTP_INP_RLOCK(inp);
3127 info->snd_sid = inp->def_send.sinfo_stream;
3128 info->snd_flags = inp->def_send.sinfo_flags;
3129 info->snd_flags &= 0xfff0;
3130 info->snd_ppid = inp->def_send.sinfo_ppid;
3131 info->snd_context = inp->def_send.sinfo_context;
3132 SCTP_INP_RUNLOCK(inp);
3134 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3139 *optsize = sizeof(struct sctp_sndinfo);
3143 case SCTP_DEFAULT_PRINFO:
3145 struct sctp_default_prinfo *info;
3147 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3148 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3151 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3152 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3153 SCTP_TCB_UNLOCK(stcb);
3155 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3156 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3157 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3158 (info->pr_assoc_id == SCTP_FUTURE_ASSOC))) {
3159 SCTP_INP_RLOCK(inp);
3160 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3161 info->pr_value = inp->def_send.sinfo_timetolive;
3162 SCTP_INP_RUNLOCK(inp);
3164 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3169 *optsize = sizeof(struct sctp_default_prinfo);
3173 case SCTP_PEER_ADDR_THLDS:
3175 struct sctp_paddrthlds *thlds;
3176 struct sctp_nets *net;
3177 struct sockaddr *addr;
3178 #if defined(INET) && defined(INET6)
3179 struct sockaddr_in sin_store;
3182 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3183 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3185 #if defined(INET) && defined(INET6)
3186 if (thlds->spt_address.ss_family == AF_INET6) {
3187 struct sockaddr_in6 *sin6;
3189 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3190 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3191 in6_sin6_2_sin(&sin_store, sin6);
3192 addr = (struct sockaddr *)&sin_store;
3194 addr = (struct sockaddr *)&thlds->spt_address;
3197 addr = (struct sockaddr *)&thlds->spt_address;
3200 addr = (struct sockaddr *)&thlds->spt_address;
3203 net = sctp_findnet(stcb, addr);
3206 * We increment here since
3207 * sctp_findassociation_ep_addr() wil do a
3208 * decrement if it finds the stcb as long as
3209 * the locked tcb (last argument) is NOT a
3213 SCTP_INP_INCR_REF(inp);
3214 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3216 SCTP_INP_DECR_REF(inp);
3219 if ((stcb != NULL) && (net == NULL)) {
3221 if (addr->sa_family == AF_INET) {
3222 struct sockaddr_in *sin;
3224 sin = (struct sockaddr_in *)addr;
3225 if (sin->sin_addr.s_addr != INADDR_ANY) {
3227 SCTP_TCB_UNLOCK(stcb);
3228 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3234 if (addr->sa_family == AF_INET6) {
3235 struct sockaddr_in6 *sin6;
3237 sin6 = (struct sockaddr_in6 *)addr;
3238 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3240 SCTP_TCB_UNLOCK(stcb);
3241 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3247 error = EAFNOSUPPORT;
3248 SCTP_TCB_UNLOCK(stcb);
3249 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3256 thlds->spt_pathmaxrxt = net->failure_threshold;
3257 thlds->spt_pathpfthld = net->pf_threshold;
3258 thlds->spt_pathcpthld = 0xffff;
3260 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3261 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3262 thlds->spt_pathcpthld = 0xffff;
3264 thlds->spt_assoc_id = sctp_get_associd(stcb);
3265 SCTP_TCB_UNLOCK(stcb);
3267 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3268 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3269 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3270 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
3271 /* Use endpoint defaults */
3272 SCTP_INP_RLOCK(inp);
3273 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3274 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3275 thlds->spt_pathcpthld = 0xffff;
3276 SCTP_INP_RUNLOCK(inp);
3278 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3283 *optsize = sizeof(struct sctp_paddrthlds);
3287 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3289 struct sctp_udpencaps *encaps;
3290 struct sctp_nets *net;
3291 struct sockaddr *addr;
3292 #if defined(INET) && defined(INET6)
3293 struct sockaddr_in sin_store;
3296 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3297 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3299 #if defined(INET) && defined(INET6)
3300 if (encaps->sue_address.ss_family == AF_INET6) {
3301 struct sockaddr_in6 *sin6;
3303 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3304 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3305 in6_sin6_2_sin(&sin_store, sin6);
3306 addr = (struct sockaddr *)&sin_store;
3308 addr = (struct sockaddr *)&encaps->sue_address;
3311 addr = (struct sockaddr *)&encaps->sue_address;
3314 addr = (struct sockaddr *)&encaps->sue_address;
3317 net = sctp_findnet(stcb, addr);
3320 * We increment here since
3321 * sctp_findassociation_ep_addr() wil do a
3322 * decrement if it finds the stcb as long as
3323 * the locked tcb (last argument) is NOT a
3327 SCTP_INP_INCR_REF(inp);
3328 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3330 SCTP_INP_DECR_REF(inp);
3333 if ((stcb != NULL) && (net == NULL)) {
3335 if (addr->sa_family == AF_INET) {
3336 struct sockaddr_in *sin;
3338 sin = (struct sockaddr_in *)addr;
3339 if (sin->sin_addr.s_addr != INADDR_ANY) {
3341 SCTP_TCB_UNLOCK(stcb);
3342 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3348 if (addr->sa_family == AF_INET6) {
3349 struct sockaddr_in6 *sin6;
3351 sin6 = (struct sockaddr_in6 *)addr;
3352 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3354 SCTP_TCB_UNLOCK(stcb);
3355 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3361 error = EAFNOSUPPORT;
3362 SCTP_TCB_UNLOCK(stcb);
3363 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3370 encaps->sue_port = net->port;
3372 encaps->sue_port = stcb->asoc.port;
3374 SCTP_TCB_UNLOCK(stcb);
3376 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3377 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3378 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3379 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
3380 SCTP_INP_RLOCK(inp);
3381 encaps->sue_port = inp->sctp_ep.port;
3382 SCTP_INP_RUNLOCK(inp);
3384 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3389 *optsize = sizeof(struct sctp_udpencaps);
3393 case SCTP_ECN_SUPPORTED:
3395 struct sctp_assoc_value *av;
3397 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3398 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3401 av->assoc_value = stcb->asoc.ecn_supported;
3402 SCTP_TCB_UNLOCK(stcb);
3404 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3405 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3406 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3407 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3408 SCTP_INP_RLOCK(inp);
3409 av->assoc_value = inp->ecn_supported;
3410 SCTP_INP_RUNLOCK(inp);
3412 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3417 *optsize = sizeof(struct sctp_assoc_value);
3421 case SCTP_PR_SUPPORTED:
3423 struct sctp_assoc_value *av;
3425 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3426 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3429 av->assoc_value = stcb->asoc.prsctp_supported;
3430 SCTP_TCB_UNLOCK(stcb);
3432 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3433 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3434 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3435 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3436 SCTP_INP_RLOCK(inp);
3437 av->assoc_value = inp->prsctp_supported;
3438 SCTP_INP_RUNLOCK(inp);
3440 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3445 *optsize = sizeof(struct sctp_assoc_value);
3449 case SCTP_AUTH_SUPPORTED:
3451 struct sctp_assoc_value *av;
3453 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3454 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3457 av->assoc_value = stcb->asoc.auth_supported;
3458 SCTP_TCB_UNLOCK(stcb);
3460 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3461 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3462 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3463 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3464 SCTP_INP_RLOCK(inp);
3465 av->assoc_value = inp->auth_supported;
3466 SCTP_INP_RUNLOCK(inp);
3468 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3473 *optsize = sizeof(struct sctp_assoc_value);
3477 case SCTP_ASCONF_SUPPORTED:
3479 struct sctp_assoc_value *av;
3481 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3482 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3485 av->assoc_value = stcb->asoc.asconf_supported;
3486 SCTP_TCB_UNLOCK(stcb);
3488 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3489 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3490 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3491 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3492 SCTP_INP_RLOCK(inp);
3493 av->assoc_value = inp->asconf_supported;
3494 SCTP_INP_RUNLOCK(inp);
3496 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3501 *optsize = sizeof(struct sctp_assoc_value);
3505 case SCTP_RECONFIG_SUPPORTED:
3507 struct sctp_assoc_value *av;
3509 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3510 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3513 av->assoc_value = stcb->asoc.reconfig_supported;
3514 SCTP_TCB_UNLOCK(stcb);
3516 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3517 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3518 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3519 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3520 SCTP_INP_RLOCK(inp);
3521 av->assoc_value = inp->reconfig_supported;
3522 SCTP_INP_RUNLOCK(inp);
3524 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3529 *optsize = sizeof(struct sctp_assoc_value);
3533 case SCTP_NRSACK_SUPPORTED:
3535 struct sctp_assoc_value *av;
3537 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3538 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3541 av->assoc_value = stcb->asoc.nrsack_supported;
3542 SCTP_TCB_UNLOCK(stcb);
3544 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3545 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3546 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3547 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3548 SCTP_INP_RLOCK(inp);
3549 av->assoc_value = inp->nrsack_supported;
3550 SCTP_INP_RUNLOCK(inp);
3552 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3557 *optsize = sizeof(struct sctp_assoc_value);
3561 case SCTP_PKTDROP_SUPPORTED:
3563 struct sctp_assoc_value *av;
3565 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3566 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3569 av->assoc_value = stcb->asoc.pktdrop_supported;
3570 SCTP_TCB_UNLOCK(stcb);
3572 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3573 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3574 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3575 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3576 SCTP_INP_RLOCK(inp);
3577 av->assoc_value = inp->pktdrop_supported;
3578 SCTP_INP_RUNLOCK(inp);
3580 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3585 *optsize = sizeof(struct sctp_assoc_value);
3589 case SCTP_ENABLE_STREAM_RESET:
3591 struct sctp_assoc_value *av;
3593 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3594 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3597 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3598 SCTP_TCB_UNLOCK(stcb);
3600 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3601 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3602 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3603 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3604 SCTP_INP_RLOCK(inp);
3605 av->assoc_value = (uint32_t)inp->local_strreset_support;
3606 SCTP_INP_RUNLOCK(inp);
3608 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3613 *optsize = sizeof(struct sctp_assoc_value);
3617 case SCTP_PR_STREAM_STATUS:
3619 struct sctp_prstatus *sprstat;
3623 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3624 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3626 sid = sprstat->sprstat_sid;
3627 policy = sprstat->sprstat_policy;
3628 #if defined(SCTP_DETAILED_STR_STATS)
3629 if ((stcb != NULL) &&
3630 (sid < stcb->asoc.streamoutcnt) &&
3631 (policy != SCTP_PR_SCTP_NONE) &&
3632 ((policy <= SCTP_PR_SCTP_MAX) ||
3633 (policy == SCTP_PR_SCTP_ALL))) {
3634 if (policy == SCTP_PR_SCTP_ALL) {
3635 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3636 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3638 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3639 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3642 if ((stcb != NULL) &&
3643 (sid < stcb->asoc.streamoutcnt) &&
3644 (policy == SCTP_PR_SCTP_ALL)) {
3645 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3646 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3649 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3653 SCTP_TCB_UNLOCK(stcb);
3656 *optsize = sizeof(struct sctp_prstatus);
3660 case SCTP_PR_ASSOC_STATUS:
3662 struct sctp_prstatus *sprstat;
3665 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3666 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3668 policy = sprstat->sprstat_policy;
3669 if ((stcb != NULL) &&
3670 (policy != SCTP_PR_SCTP_NONE) &&
3671 ((policy <= SCTP_PR_SCTP_MAX) ||
3672 (policy == SCTP_PR_SCTP_ALL))) {
3673 if (policy == SCTP_PR_SCTP_ALL) {
3674 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3675 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3677 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3678 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3681 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3685 SCTP_TCB_UNLOCK(stcb);
3688 *optsize = sizeof(struct sctp_prstatus);
3694 struct sctp_assoc_value *av;
3696 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3697 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3700 av->assoc_value = stcb->asoc.max_cwnd;
3701 SCTP_TCB_UNLOCK(stcb);
3703 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3704 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3705 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3706 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3707 SCTP_INP_RLOCK(inp);
3708 av->assoc_value = inp->max_cwnd;
3709 SCTP_INP_RUNLOCK(inp);
3711 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3716 *optsize = sizeof(struct sctp_assoc_value);
3721 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3722 error = ENOPROTOOPT;
3724 } /* end switch (sopt->sopt_name) */
3732 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3737 struct sctp_tcb *stcb = NULL;
3738 struct sctp_inpcb *inp = NULL;
3741 if (optval == NULL) {
3742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3745 inp = (struct sctp_inpcb *)so->so_pcb;
3747 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3750 vrf_id = inp->def_vrf_id;
3755 case SCTP_AUTOCLOSE:
3756 case SCTP_AUTO_ASCONF:
3757 case SCTP_EXPLICIT_EOR:
3758 case SCTP_DISABLE_FRAGMENTS:
3759 case SCTP_USE_EXT_RCVINFO:
3760 case SCTP_I_WANT_MAPPED_V4_ADDR:
3761 /* copy in the option value */
3762 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3767 case SCTP_DISABLE_FRAGMENTS:
3768 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3770 case SCTP_AUTO_ASCONF:
3772 * NOTE: we don't really support this flag
3774 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3775 /* only valid for bound all sockets */
3776 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3778 /* forbidden by admin */
3779 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3782 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3784 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3788 case SCTP_EXPLICIT_EOR:
3789 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3791 case SCTP_USE_EXT_RCVINFO:
3792 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3794 case SCTP_I_WANT_MAPPED_V4_ADDR:
3795 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3796 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3798 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3803 set_opt = SCTP_PCB_FLAGS_NODELAY;
3805 case SCTP_AUTOCLOSE:
3806 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3807 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3808 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3811 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3813 * The value is in ticks. Note this does not effect
3814 * old associations, only new ones.
3816 inp->sctp_ep.auto_close_time = sctp_secs_to_ticks(*mopt);
3819 SCTP_INP_WLOCK(inp);
3821 sctp_feature_on(inp, set_opt);
3823 sctp_feature_off(inp, set_opt);
3825 SCTP_INP_WUNLOCK(inp);
3827 case SCTP_REUSE_PORT:
3829 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3830 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3831 /* Can't set it after we are bound */
3835 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3836 /* Can't do this for a 1-m socket */
3841 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3843 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3846 case SCTP_PARTIAL_DELIVERY_POINT:
3850 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3851 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3852 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3856 inp->partial_delivery_point = *value;
3859 case SCTP_FRAGMENT_INTERLEAVE:
3860 /* not yet until we re-write sctp_recvmsg() */
3864 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3865 if (*level == SCTP_FRAG_LEVEL_2) {
3866 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3867 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3868 } else if (*level == SCTP_FRAG_LEVEL_1) {
3869 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3870 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3871 } else if (*level == SCTP_FRAG_LEVEL_0) {
3872 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3873 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3881 case SCTP_INTERLEAVING_SUPPORTED:
3883 struct sctp_assoc_value *av;
3885 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3886 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3889 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3891 SCTP_TCB_UNLOCK(stcb);
3893 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3894 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3895 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3896 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3897 SCTP_INP_WLOCK(inp);
3898 if (av->assoc_value == 0) {
3899 inp->idata_supported = 0;
3901 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3902 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3903 inp->idata_supported = 1;
3911 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3915 SCTP_INP_WUNLOCK(inp);
3917 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3923 case SCTP_CMT_ON_OFF:
3924 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3925 struct sctp_assoc_value *av;
3927 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3928 if (av->assoc_value > SCTP_CMT_MAX) {
3929 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3933 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3935 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3936 SCTP_TCB_UNLOCK(stcb);
3938 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3939 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3940 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3941 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3942 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3943 SCTP_INP_WLOCK(inp);
3944 inp->sctp_cmt_on_off = av->assoc_value;
3945 SCTP_INP_WUNLOCK(inp);
3947 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3948 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3949 (av->assoc_id == SCTP_ALL_ASSOC))) {
3950 SCTP_INP_RLOCK(inp);
3951 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3952 SCTP_TCB_LOCK(stcb);
3953 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3954 SCTP_TCB_UNLOCK(stcb);
3956 SCTP_INP_RUNLOCK(inp);
3960 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3961 error = ENOPROTOOPT;
3964 case SCTP_PLUGGABLE_CC:
3966 struct sctp_assoc_value *av;
3967 struct sctp_nets *net;
3969 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3970 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3971 (av->assoc_value != SCTP_CC_HSTCP) &&
3972 (av->assoc_value != SCTP_CC_HTCP) &&
3973 (av->assoc_value != SCTP_CC_RTCC)) {
3974 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3978 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3980 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3981 stcb->asoc.congestion_control_module = av->assoc_value;
3982 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3983 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3984 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3987 SCTP_TCB_UNLOCK(stcb);
3989 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3990 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3991 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3992 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3993 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3994 SCTP_INP_WLOCK(inp);
3995 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3996 SCTP_INP_WUNLOCK(inp);
3998 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3999 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4000 (av->assoc_id == SCTP_ALL_ASSOC))) {
4001 SCTP_INP_RLOCK(inp);
4002 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4003 SCTP_TCB_LOCK(stcb);
4004 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4005 stcb->asoc.congestion_control_module = av->assoc_value;
4006 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4007 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4008 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4011 SCTP_TCB_UNLOCK(stcb);
4013 SCTP_INP_RUNLOCK(inp);
4018 case SCTP_CC_OPTION:
4020 struct sctp_cc_option *cc_opt;
4022 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4023 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4025 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4026 (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC)) {
4027 SCTP_INP_RLOCK(inp);
4028 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4029 SCTP_TCB_LOCK(stcb);
4030 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4031 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4033 SCTP_TCB_UNLOCK(stcb);
4035 SCTP_INP_RUNLOCK(inp);
4040 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4043 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4046 SCTP_TCB_UNLOCK(stcb);
4050 case SCTP_PLUGGABLE_SS:
4052 struct sctp_assoc_value *av;
4054 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4055 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4056 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4057 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4058 (av->assoc_value != SCTP_SS_PRIORITY) &&
4059 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4060 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4061 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4065 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4067 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, true);
4068 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4069 stcb->asoc.stream_scheduling_module = av->assoc_value;
4070 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc);
4071 SCTP_TCB_UNLOCK(stcb);
4073 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4074 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4075 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4076 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4077 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4078 SCTP_INP_WLOCK(inp);
4079 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4080 SCTP_INP_WUNLOCK(inp);
4082 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4083 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4084 (av->assoc_id == SCTP_ALL_ASSOC))) {
4085 SCTP_INP_RLOCK(inp);
4086 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4087 SCTP_TCB_LOCK(stcb);
4088 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, true);
4089 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4090 stcb->asoc.stream_scheduling_module = av->assoc_value;
4091 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc);
4092 SCTP_TCB_UNLOCK(stcb);
4094 SCTP_INP_RUNLOCK(inp);
4101 struct sctp_stream_value *av;
4103 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4104 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4106 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4107 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4108 av->stream_value) < 0)) {
4109 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4112 SCTP_TCB_UNLOCK(stcb);
4114 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4115 (av->assoc_id == SCTP_CURRENT_ASSOC)) {
4116 SCTP_INP_RLOCK(inp);
4117 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4118 SCTP_TCB_LOCK(stcb);
4119 if (av->stream_id < stcb->asoc.streamoutcnt) {
4120 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4122 &stcb->asoc.strmout[av->stream_id],
4125 SCTP_TCB_UNLOCK(stcb);
4127 SCTP_INP_RUNLOCK(inp);
4130 * Can't set stream value without
4133 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4139 case SCTP_CLR_STAT_LOG:
4140 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4145 struct sctp_assoc_value *av;
4147 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4148 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4151 stcb->asoc.context = av->assoc_value;
4152 SCTP_TCB_UNLOCK(stcb);
4154 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4155 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4156 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4157 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4158 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4159 SCTP_INP_WLOCK(inp);
4160 inp->sctp_context = av->assoc_value;
4161 SCTP_INP_WUNLOCK(inp);
4163 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4164 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4165 (av->assoc_id == SCTP_ALL_ASSOC))) {
4166 SCTP_INP_RLOCK(inp);
4167 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4168 SCTP_TCB_LOCK(stcb);
4169 stcb->asoc.context = av->assoc_value;
4170 SCTP_TCB_UNLOCK(stcb);
4172 SCTP_INP_RUNLOCK(inp);
4179 uint32_t *default_vrfid;
4181 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4182 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4183 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4187 inp->def_vrf_id = *default_vrfid;
4190 case SCTP_DEL_VRF_ID:
4192 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4196 case SCTP_ADD_VRF_ID:
4198 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4202 case SCTP_DELAYED_SACK:
4204 struct sctp_sack_info *sack;
4206 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4207 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4208 if (sack->sack_delay) {
4209 if (sack->sack_delay > SCTP_MAX_SACK_DELAY) {
4212 SCTP_TCB_UNLOCK(stcb);
4218 if (sack->sack_delay) {
4219 stcb->asoc.delayed_ack = sack->sack_delay;
4221 if (sack->sack_freq) {
4222 stcb->asoc.sack_freq = sack->sack_freq;
4224 SCTP_TCB_UNLOCK(stcb);
4226 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4227 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4228 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4229 ((sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4230 (sack->sack_assoc_id == SCTP_ALL_ASSOC)))) {
4231 SCTP_INP_WLOCK(inp);
4232 if (sack->sack_delay) {
4233 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = sctp_msecs_to_ticks(sack->sack_delay);
4235 if (sack->sack_freq) {
4236 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4238 SCTP_INP_WUNLOCK(inp);
4240 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4241 ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4242 (sack->sack_assoc_id == SCTP_ALL_ASSOC))) {
4243 SCTP_INP_RLOCK(inp);
4244 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4245 SCTP_TCB_LOCK(stcb);
4246 if (sack->sack_delay) {
4247 stcb->asoc.delayed_ack = sack->sack_delay;
4249 if (sack->sack_freq) {
4250 stcb->asoc.sack_freq = sack->sack_freq;
4252 SCTP_TCB_UNLOCK(stcb);
4254 SCTP_INP_RUNLOCK(inp);
4259 case SCTP_AUTH_CHUNK:
4261 struct sctp_authchunk *sauth;
4263 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4265 SCTP_INP_WLOCK(inp);
4266 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4267 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4270 inp->auth_supported = 1;
4272 SCTP_INP_WUNLOCK(inp);
4277 struct sctp_authkey *sca;
4278 struct sctp_keyhead *shared_keys;
4279 sctp_sharedkey_t *shared_key;
4280 sctp_key_t *key = NULL;
4283 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4284 if (sca->sca_keylength == 0) {
4285 size = optsize - sizeof(struct sctp_authkey);
4287 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4288 size = sca->sca_keylength;
4290 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4295 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4298 shared_keys = &stcb->asoc.shared_keys;
4299 /* clear the cached keys for this key id */
4300 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4302 * create the new shared key and
4306 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4308 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4310 SCTP_TCB_UNLOCK(stcb);
4314 shared_key = sctp_alloc_sharedkey();
4315 if (shared_key == NULL) {
4317 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4319 SCTP_TCB_UNLOCK(stcb);
4322 shared_key->key = key;
4323 shared_key->keyid = sca->sca_keynumber;
4324 error = sctp_insert_sharedkey(shared_keys, shared_key);
4325 SCTP_TCB_UNLOCK(stcb);
4327 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4328 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4329 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4330 ((sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4331 (sca->sca_assoc_id == SCTP_ALL_ASSOC)))) {
4332 SCTP_INP_WLOCK(inp);
4333 shared_keys = &inp->sctp_ep.shared_keys;
4335 * clear the cached keys on all
4336 * assocs for this key id
4338 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4340 * create the new shared key and
4344 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4346 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4348 SCTP_INP_WUNLOCK(inp);
4352 shared_key = sctp_alloc_sharedkey();
4353 if (shared_key == NULL) {
4355 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4357 SCTP_INP_WUNLOCK(inp);
4360 shared_key->key = key;
4361 shared_key->keyid = sca->sca_keynumber;
4362 error = sctp_insert_sharedkey(shared_keys, shared_key);
4363 SCTP_INP_WUNLOCK(inp);
4365 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4366 ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4367 (sca->sca_assoc_id == SCTP_ALL_ASSOC))) {
4368 SCTP_INP_RLOCK(inp);
4369 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4370 SCTP_TCB_LOCK(stcb);
4371 shared_keys = &stcb->asoc.shared_keys;
4373 * clear the cached keys for
4376 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4378 * create the new shared key
4379 * and insert/replace it
4382 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4384 SCTP_TCB_UNLOCK(stcb);
4388 shared_key = sctp_alloc_sharedkey();
4389 if (shared_key == NULL) {
4391 SCTP_TCB_UNLOCK(stcb);
4394 shared_key->key = key;
4395 shared_key->keyid = sca->sca_keynumber;
4396 error = sctp_insert_sharedkey(shared_keys, shared_key);
4397 SCTP_TCB_UNLOCK(stcb);
4399 SCTP_INP_RUNLOCK(inp);
4404 case SCTP_HMAC_IDENT:
4406 struct sctp_hmacalgo *shmac;
4407 sctp_hmaclist_t *hmaclist;
4411 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4412 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4413 (shmac->shmac_number_of_idents > 0xffff)) {
4414 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4419 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4420 if (hmaclist == NULL) {
4421 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4425 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4426 hmacid = shmac->shmac_idents[i];
4427 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4428 /* invalid HMACs were found */ ;
4429 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4431 sctp_free_hmaclist(hmaclist);
4432 goto sctp_set_hmac_done;
4435 for (i = 0; i < hmaclist->num_algo; i++) {
4436 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4437 /* already in list */
4441 if (i == hmaclist->num_algo) {
4442 /* not found in list */
4443 sctp_free_hmaclist(hmaclist);
4444 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4448 /* set it on the endpoint */
4449 SCTP_INP_WLOCK(inp);
4450 if (inp->sctp_ep.local_hmacs)
4451 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4452 inp->sctp_ep.local_hmacs = hmaclist;
4453 SCTP_INP_WUNLOCK(inp);
4457 case SCTP_AUTH_ACTIVE_KEY:
4459 struct sctp_authkeyid *scact;
4461 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4462 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4464 /* set the active key on the right place */
4466 /* set the active key on the assoc */
4467 if (sctp_auth_setactivekey(stcb,
4468 scact->scact_keynumber)) {
4469 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4470 SCTP_FROM_SCTP_USRREQ,
4474 SCTP_TCB_UNLOCK(stcb);
4476 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4477 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4478 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4479 ((scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4480 (scact->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4481 SCTP_INP_WLOCK(inp);
4482 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4483 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4486 SCTP_INP_WUNLOCK(inp);
4488 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4489 ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4490 (scact->scact_assoc_id == SCTP_ALL_ASSOC))) {
4491 SCTP_INP_RLOCK(inp);
4492 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4493 SCTP_TCB_LOCK(stcb);
4494 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4495 SCTP_TCB_UNLOCK(stcb);
4497 SCTP_INP_RUNLOCK(inp);
4502 case SCTP_AUTH_DELETE_KEY:
4504 struct sctp_authkeyid *scdel;
4506 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4507 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4509 /* delete the key from the right place */
4511 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4515 SCTP_TCB_UNLOCK(stcb);
4517 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4518 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4519 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4520 ((scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4521 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4522 SCTP_INP_WLOCK(inp);
4523 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4524 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4527 SCTP_INP_WUNLOCK(inp);
4529 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4530 ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4531 (scdel->scact_assoc_id == SCTP_ALL_ASSOC))) {
4532 SCTP_INP_RLOCK(inp);
4533 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4534 SCTP_TCB_LOCK(stcb);
4535 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4536 SCTP_TCB_UNLOCK(stcb);
4538 SCTP_INP_RUNLOCK(inp);
4543 case SCTP_AUTH_DEACTIVATE_KEY:
4545 struct sctp_authkeyid *keyid;
4547 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4548 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4550 /* deactivate the key from the right place */
4552 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4553 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4556 SCTP_TCB_UNLOCK(stcb);
4558 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4559 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4560 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4561 ((keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4562 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4563 SCTP_INP_WLOCK(inp);
4564 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4565 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4568 SCTP_INP_WUNLOCK(inp);
4570 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4571 ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4572 (keyid->scact_assoc_id == SCTP_ALL_ASSOC))) {
4573 SCTP_INP_RLOCK(inp);
4574 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4575 SCTP_TCB_LOCK(stcb);
4576 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4577 SCTP_TCB_UNLOCK(stcb);
4579 SCTP_INP_RUNLOCK(inp);
4584 case SCTP_ENABLE_STREAM_RESET:
4586 struct sctp_assoc_value *av;
4588 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4589 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4590 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4594 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4596 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4597 SCTP_TCB_UNLOCK(stcb);
4599 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4600 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4601 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4602 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4603 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4604 SCTP_INP_WLOCK(inp);
4605 inp->local_strreset_support = (uint8_t)av->assoc_value;
4606 SCTP_INP_WUNLOCK(inp);
4608 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4609 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4610 (av->assoc_id == SCTP_ALL_ASSOC))) {
4611 SCTP_INP_RLOCK(inp);
4612 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4613 SCTP_TCB_LOCK(stcb);
4614 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4615 SCTP_TCB_UNLOCK(stcb);
4617 SCTP_INP_RUNLOCK(inp);
4622 case SCTP_RESET_STREAMS:
4624 struct sctp_reset_streams *strrst;
4625 int i, send_out = 0;
4628 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4629 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4631 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4635 if (stcb->asoc.reconfig_supported == 0) {
4637 * Peer does not support the chunk type.
4639 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4641 SCTP_TCB_UNLOCK(stcb);
4644 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4645 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4647 SCTP_TCB_UNLOCK(stcb);
4650 if (sizeof(struct sctp_reset_streams) +
4651 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4653 SCTP_TCB_UNLOCK(stcb);
4656 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4658 if (stcb->asoc.stream_reset_outstanding) {
4659 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4661 SCTP_TCB_UNLOCK(stcb);
4665 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4668 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4669 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4671 SCTP_TCB_UNLOCK(stcb);
4674 if ((send_in == 0) && (send_out == 0)) {
4675 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4677 SCTP_TCB_UNLOCK(stcb);
4680 for (i = 0; i < strrst->srs_number_streams; i++) {
4682 (strrst->srs_stream_list[i] >= stcb->asoc.streamincnt)) {
4683 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4688 (strrst->srs_stream_list[i] >= stcb->asoc.streamoutcnt)) {
4689 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4695 SCTP_TCB_UNLOCK(stcb);
4702 if (strrst->srs_number_streams) {
4703 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4704 strm = strrst->srs_stream_list[i];
4705 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4706 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4712 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4713 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4714 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4721 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4722 strrst->srs_stream_list,
4723 send_in, 0, 0, 0, 0, 0);
4725 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4728 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4731 * For outgoing streams don't report any
4732 * problems in sending the request to the
4733 * application. XXX: Double check resetting
4738 SCTP_TCB_UNLOCK(stcb);
4741 case SCTP_ADD_STREAMS:
4743 struct sctp_add_streams *stradd;
4744 uint8_t addstream = 0;
4745 uint16_t add_o_strmcnt = 0;
4746 uint16_t add_i_strmcnt = 0;
4748 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4749 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4751 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4755 if (stcb->asoc.reconfig_supported == 0) {
4757 * Peer does not support the chunk type.
4759 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4761 SCTP_TCB_UNLOCK(stcb);
4764 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4765 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4767 SCTP_TCB_UNLOCK(stcb);
4770 if (stcb->asoc.stream_reset_outstanding) {
4771 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4773 SCTP_TCB_UNLOCK(stcb);
4776 if ((stradd->sas_outstrms == 0) &&
4777 (stradd->sas_instrms == 0)) {
4781 if (stradd->sas_outstrms) {
4783 /* We allocate here */
4784 add_o_strmcnt = stradd->sas_outstrms;
4785 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4786 /* You can't have more than 64k */
4791 if (stradd->sas_instrms) {
4796 * We allocate inside
4797 * sctp_send_str_reset_req()
4799 add_i_strmcnt = stradd->sas_instrms;
4800 cnt = add_i_strmcnt;
4801 cnt += stcb->asoc.streamincnt;
4802 if (cnt > 0x0000ffff) {
4803 /* You can't have more than 64k */
4807 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4808 /* More than you are allowed */
4813 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4814 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4816 SCTP_TCB_UNLOCK(stcb);
4819 case SCTP_RESET_ASSOC:
4824 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4825 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4827 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4831 if (stcb->asoc.reconfig_supported == 0) {
4833 * Peer does not support the chunk type.
4835 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4837 SCTP_TCB_UNLOCK(stcb);
4840 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4841 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4843 SCTP_TCB_UNLOCK(stcb);
4846 if (stcb->asoc.stream_reset_outstanding) {
4847 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4849 SCTP_TCB_UNLOCK(stcb);
4853 * Is there any data pending in the send or sent
4856 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4857 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4860 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4861 SCTP_TCB_UNLOCK(stcb);
4864 /* Do any streams have data queued? */
4865 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4866 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4870 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4871 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4872 SCTP_TCB_UNLOCK(stcb);
4875 case SCTP_CONNECT_X:
4876 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4877 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4881 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4883 case SCTP_CONNECT_X_DELAYED:
4884 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4885 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4889 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4891 case SCTP_CONNECT_X_COMPLETE:
4893 struct sockaddr *sa;
4895 /* FIXME MT: check correct? */
4896 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4899 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4900 SCTP_INP_RLOCK(inp);
4901 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4903 SCTP_TCB_LOCK(stcb);
4905 SCTP_INP_RUNLOCK(inp);
4908 * We increment here since
4909 * sctp_findassociation_ep_addr() wil do a
4910 * decrement if it finds the stcb as long as
4911 * the locked tcb (last argument) is NOT a
4914 SCTP_INP_INCR_REF(inp);
4915 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4917 SCTP_INP_DECR_REF(inp);
4922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4926 if (stcb->asoc.delayed_connection == 1) {
4927 stcb->asoc.delayed_connection = 0;
4928 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4929 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4930 stcb->asoc.primary_destination,
4931 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4932 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4935 * already expired or did not use delayed
4938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4941 SCTP_TCB_UNLOCK(stcb);
4944 case SCTP_MAX_BURST:
4946 struct sctp_assoc_value *av;
4948 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4949 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4952 stcb->asoc.max_burst = av->assoc_value;
4953 SCTP_TCB_UNLOCK(stcb);
4955 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4956 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4957 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4958 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4959 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4960 SCTP_INP_WLOCK(inp);
4961 inp->sctp_ep.max_burst = av->assoc_value;
4962 SCTP_INP_WUNLOCK(inp);
4964 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4965 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4966 (av->assoc_id == SCTP_ALL_ASSOC))) {
4967 SCTP_INP_RLOCK(inp);
4968 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4969 SCTP_TCB_LOCK(stcb);
4970 stcb->asoc.max_burst = av->assoc_value;
4971 SCTP_TCB_UNLOCK(stcb);
4973 SCTP_INP_RUNLOCK(inp);
4980 struct sctp_assoc_value *av;
4982 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4983 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4986 stcb->asoc.sctp_frag_point = av->assoc_value;
4987 SCTP_TCB_UNLOCK(stcb);
4989 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4990 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4991 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4992 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
4993 SCTP_INP_WLOCK(inp);
4994 inp->sctp_frag_point = av->assoc_value;
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);
5076 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5077 SCTP_TCB_LOCK(stcb);
5078 if (events->sctp_association_event) {
5079 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5081 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5083 if (events->sctp_address_event) {
5084 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5086 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5088 if (events->sctp_send_failure_event) {
5089 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5091 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5093 if (events->sctp_peer_error_event) {
5094 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5096 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5098 if (events->sctp_shutdown_event) {
5099 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5101 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5103 if (events->sctp_partial_delivery_event) {
5104 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5106 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5108 if (events->sctp_adaptation_layer_event) {
5109 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5111 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5113 if (events->sctp_authentication_event) {
5114 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5116 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5118 if (events->sctp_sender_dry_event) {
5119 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5121 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5123 if (events->sctp_stream_reset_event) {
5124 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5126 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5128 SCTP_TCB_UNLOCK(stcb);
5131 * Send up the sender dry event only for 1-to-1
5134 if (events->sctp_sender_dry_event) {
5135 if (((inp->sctp_flags & (SCTP_PCB_FLAGS_TCPTYPE | SCTP_PCB_FLAGS_IN_TCPPOOL)) != 0) &&
5136 !SCTP_IS_LISTENING(inp)) {
5137 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5139 SCTP_TCB_LOCK(stcb);
5140 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5141 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5142 (stcb->asoc.stream_queue_cnt == 0)) {
5143 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5145 SCTP_TCB_UNLOCK(stcb);
5149 SCTP_INP_WUNLOCK(inp);
5152 case SCTP_ADAPTATION_LAYER:
5154 struct sctp_setadaptation *adap_bits;
5156 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5157 SCTP_INP_WLOCK(inp);
5158 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5159 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5160 SCTP_INP_WUNLOCK(inp);
5164 case SCTP_SET_INITIAL_DBG_SEQ:
5168 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5169 SCTP_INP_WLOCK(inp);
5170 inp->sctp_ep.initial_sequence_debug = *vvv;
5171 SCTP_INP_WUNLOCK(inp);
5175 case SCTP_DEFAULT_SEND_PARAM:
5177 struct sctp_sndrcvinfo *s_info;
5179 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5180 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5183 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5184 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5189 SCTP_TCB_UNLOCK(stcb);
5191 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5192 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5193 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5194 ((s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5195 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)))) {
5196 SCTP_INP_WLOCK(inp);
5197 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5198 SCTP_INP_WUNLOCK(inp);
5200 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5201 ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5202 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC))) {
5203 SCTP_INP_RLOCK(inp);
5204 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5205 SCTP_TCB_LOCK(stcb);
5206 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5207 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5209 SCTP_TCB_UNLOCK(stcb);
5211 SCTP_INP_RUNLOCK(inp);
5216 case SCTP_PEER_ADDR_PARAMS:
5218 struct sctp_paddrparams *paddrp;
5219 struct sctp_nets *net;
5220 struct sockaddr *addr;
5221 #if defined(INET) && defined(INET6)
5222 struct sockaddr_in sin_store;
5225 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5226 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5228 #if defined(INET) && defined(INET6)
5229 if (paddrp->spp_address.ss_family == AF_INET6) {
5230 struct sockaddr_in6 *sin6;
5232 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5233 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5234 in6_sin6_2_sin(&sin_store, sin6);
5235 addr = (struct sockaddr *)&sin_store;
5237 addr = (struct sockaddr *)&paddrp->spp_address;
5240 addr = (struct sockaddr *)&paddrp->spp_address;
5243 addr = (struct sockaddr *)&paddrp->spp_address;
5246 net = sctp_findnet(stcb, addr);
5249 * We increment here since
5250 * sctp_findassociation_ep_addr() wil do a
5251 * decrement if it finds the stcb as long as
5252 * the locked tcb (last argument) is NOT a
5256 SCTP_INP_INCR_REF(inp);
5257 stcb = sctp_findassociation_ep_addr(&inp, addr,
5260 SCTP_INP_DECR_REF(inp);
5263 if ((stcb != NULL) && (net == NULL)) {
5265 if (addr->sa_family == AF_INET) {
5266 struct sockaddr_in *sin;
5268 sin = (struct sockaddr_in *)addr;
5269 if (sin->sin_addr.s_addr != INADDR_ANY) {
5270 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5271 SCTP_TCB_UNLOCK(stcb);
5278 if (addr->sa_family == AF_INET6) {
5279 struct sockaddr_in6 *sin6;
5281 sin6 = (struct sockaddr_in6 *)addr;
5282 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5283 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5284 SCTP_TCB_UNLOCK(stcb);
5291 error = EAFNOSUPPORT;
5292 SCTP_TCB_UNLOCK(stcb);
5293 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5298 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5300 SCTP_TCB_UNLOCK(stcb);
5301 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5305 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5307 SCTP_TCB_UNLOCK(stcb);
5308 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5311 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) &&
5312 (paddrp->spp_pathmtu > 0) &&
5313 ((paddrp->spp_pathmtu < SCTP_SMALLEST_PMTU) ||
5314 (paddrp->spp_pathmtu > SCTP_LARGEST_PMTU))) {
5316 SCTP_TCB_UNLOCK(stcb);
5317 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5322 /************************TCB SPECIFIC SET ******************/
5324 /************************NET SPECIFIC SET ******************/
5325 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5326 if (((net->dest_state & SCTP_ADDR_UNCONFIRMED) == 0) &&
5327 ((net->dest_state & SCTP_ADDR_NOHB) == 0)) {
5328 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5329 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5331 net->dest_state |= SCTP_ADDR_NOHB;
5333 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5334 if (paddrp->spp_hbinterval) {
5335 net->heart_beat_delay = paddrp->spp_hbinterval;
5336 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5337 net->heart_beat_delay = 0;
5339 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5340 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5341 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5342 net->dest_state &= ~SCTP_ADDR_NOHB;
5344 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5345 if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
5346 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5347 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5348 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5351 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5352 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5353 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5354 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5356 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5357 if (paddrp->spp_pathmtu > 0) {
5358 net->mtu = paddrp->spp_pathmtu;
5359 switch (net->ro._l_addr.sa.sa_family) {
5362 net->mtu += SCTP_MIN_V4_OVERHEAD;
5367 net->mtu += SCTP_MIN_OVERHEAD;
5373 if (net->mtu < stcb->asoc.smallest_mtu) {
5374 sctp_pathmtu_adjustment(stcb, net->mtu, true);
5378 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5379 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5380 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5382 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5384 if (paddrp->spp_pathmaxrxt > 0) {
5385 if (net->dest_state & SCTP_ADDR_PF) {
5386 if (net->error_count > paddrp->spp_pathmaxrxt) {
5387 net->dest_state &= ~SCTP_ADDR_PF;
5390 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5391 (net->error_count > net->pf_threshold)) {
5392 net->dest_state |= SCTP_ADDR_PF;
5393 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5394 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5395 stcb->sctp_ep, stcb, net,
5396 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5397 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5400 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5401 if (net->error_count > paddrp->spp_pathmaxrxt) {
5402 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5403 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5406 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5407 net->dest_state |= SCTP_ADDR_REACHABLE;
5408 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5411 net->failure_threshold = paddrp->spp_pathmaxrxt;
5413 if (paddrp->spp_flags & SPP_DSCP) {
5414 net->dscp = paddrp->spp_dscp & 0xfc;
5418 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5419 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5420 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5421 net->flowlabel |= 0x80000000;
5426 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5427 if (paddrp->spp_pathmaxrxt > 0) {
5428 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5429 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5430 if (net->dest_state & SCTP_ADDR_PF) {
5431 if (net->error_count > paddrp->spp_pathmaxrxt) {
5432 net->dest_state &= ~SCTP_ADDR_PF;
5435 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5436 (net->error_count > net->pf_threshold)) {
5437 net->dest_state |= SCTP_ADDR_PF;
5438 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5439 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5440 stcb->sctp_ep, stcb, net,
5441 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5442 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5445 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5446 if (net->error_count > paddrp->spp_pathmaxrxt) {
5447 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5448 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5451 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5452 net->dest_state |= SCTP_ADDR_REACHABLE;
5453 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5456 net->failure_threshold = paddrp->spp_pathmaxrxt;
5459 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5460 if (paddrp->spp_hbinterval != 0) {
5461 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5462 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5463 stcb->asoc.heart_beat_delay = 0;
5465 /* Turn back on the timer */
5466 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5467 if (paddrp->spp_hbinterval != 0) {
5468 net->heart_beat_delay = paddrp->spp_hbinterval;
5469 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5470 net->heart_beat_delay = 0;
5472 if (net->dest_state & SCTP_ADDR_NOHB) {
5473 net->dest_state &= ~SCTP_ADDR_NOHB;
5475 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5476 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5477 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5479 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5481 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5482 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5483 if ((net->dest_state & SCTP_ADDR_NOHB) == 0) {
5484 net->dest_state |= SCTP_ADDR_NOHB;
5485 if ((net->dest_state & SCTP_ADDR_UNCONFIRMED) == 0) {
5486 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5488 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5492 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5494 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5495 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5496 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5497 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5498 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5500 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5501 if (paddrp->spp_pathmtu > 0) {
5502 net->mtu = paddrp->spp_pathmtu;
5503 switch (net->ro._l_addr.sa.sa_family) {
5506 net->mtu += SCTP_MIN_V4_OVERHEAD;
5511 net->mtu += SCTP_MIN_OVERHEAD;
5517 if (net->mtu < stcb->asoc.smallest_mtu) {
5518 sctp_pathmtu_adjustment(stcb, net->mtu, true);
5522 if (paddrp->spp_pathmtu > 0) {
5523 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5525 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5527 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5528 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5529 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5530 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5532 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5534 stcb->asoc.default_mtu = 0;
5535 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5537 if (paddrp->spp_flags & SPP_DSCP) {
5538 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5539 net->dscp = paddrp->spp_dscp & 0xfc;
5542 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5543 stcb->asoc.default_dscp |= 0x01;
5546 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5547 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5548 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5549 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5550 net->flowlabel |= 0x80000000;
5553 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5554 stcb->asoc.default_flowlabel |= 0x80000000;
5558 SCTP_TCB_UNLOCK(stcb);
5560 /************************NO TCB, SET TO default stuff ******************/
5561 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5562 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5563 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5564 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
5565 SCTP_INP_WLOCK(inp);
5567 * For the TOS/FLOWLABEL stuff you
5568 * set it with the options on the
5571 if (paddrp->spp_pathmaxrxt > 0) {
5572 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5575 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5576 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5577 else if (paddrp->spp_hbinterval != 0) {
5578 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5579 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5580 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5583 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5584 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5585 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5586 } else if (paddrp->spp_hbinterval) {
5587 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5589 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5590 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5591 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5593 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5594 inp->sctp_ep.default_mtu = 0;
5595 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5596 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5597 if (paddrp->spp_pathmtu > 0) {
5598 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5600 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5602 if (paddrp->spp_flags & SPP_DSCP) {
5603 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5604 inp->sctp_ep.default_dscp |= 0x01;
5607 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5608 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5609 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5610 inp->sctp_ep.default_flowlabel |= 0x80000000;
5614 SCTP_INP_WUNLOCK(inp);
5616 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5624 struct sctp_rtoinfo *srto;
5625 uint32_t new_init, new_min, new_max;
5627 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5628 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5631 if (srto->srto_initial)
5632 new_init = srto->srto_initial;
5634 new_init = stcb->asoc.initial_rto;
5636 new_max = srto->srto_max;
5638 new_max = stcb->asoc.maxrto;
5640 new_min = srto->srto_min;
5642 new_min = stcb->asoc.minrto;
5643 if ((new_min <= new_init) && (new_init <= new_max)) {
5644 stcb->asoc.initial_rto = new_init;
5645 stcb->asoc.maxrto = new_max;
5646 stcb->asoc.minrto = new_min;
5648 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5651 SCTP_TCB_UNLOCK(stcb);
5653 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5654 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5655 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5656 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
5657 SCTP_INP_WLOCK(inp);
5658 if (srto->srto_initial)
5659 new_init = srto->srto_initial;
5661 new_init = inp->sctp_ep.initial_rto;
5663 new_max = srto->srto_max;
5665 new_max = inp->sctp_ep.sctp_maxrto;
5667 new_min = srto->srto_min;
5669 new_min = inp->sctp_ep.sctp_minrto;
5670 if ((new_min <= new_init) && (new_init <= new_max)) {
5671 inp->sctp_ep.initial_rto = new_init;
5672 inp->sctp_ep.sctp_maxrto = new_max;
5673 inp->sctp_ep.sctp_minrto = new_min;
5675 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5678 SCTP_INP_WUNLOCK(inp);
5680 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5686 case SCTP_ASSOCINFO:
5688 struct sctp_assocparams *sasoc;
5690 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5691 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5692 if (sasoc->sasoc_cookie_life > 0) {
5693 /* boundary check the cookie life */
5694 if (sasoc->sasoc_cookie_life < SCTP_MIN_COOKIE_LIFE) {
5695 sasoc->sasoc_cookie_life = SCTP_MIN_COOKIE_LIFE;
5697 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5698 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5702 if (sasoc->sasoc_asocmaxrxt > 0) {
5703 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5705 if (sasoc->sasoc_cookie_life > 0) {
5706 stcb->asoc.cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5708 SCTP_TCB_UNLOCK(stcb);
5710 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5711 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5712 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5713 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
5714 SCTP_INP_WLOCK(inp);
5715 if (sasoc->sasoc_asocmaxrxt > 0) {
5716 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5718 if (sasoc->sasoc_cookie_life > 0) {
5719 inp->sctp_ep.def_cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5721 SCTP_INP_WUNLOCK(inp);
5723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5731 struct sctp_initmsg *sinit;
5733 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5734 SCTP_INP_WLOCK(inp);
5735 if (sinit->sinit_num_ostreams)
5736 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5738 if (sinit->sinit_max_instreams)
5739 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5741 if (sinit->sinit_max_attempts)
5742 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5744 if (sinit->sinit_max_init_timeo)
5745 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5746 SCTP_INP_WUNLOCK(inp);
5749 case SCTP_PRIMARY_ADDR:
5751 struct sctp_setprim *spa;
5752 struct sctp_nets *net;
5753 struct sockaddr *addr;
5754 #if defined(INET) && defined(INET6)
5755 struct sockaddr_in sin_store;
5758 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5759 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5761 #if defined(INET) && defined(INET6)
5762 if (spa->ssp_addr.ss_family == AF_INET6) {
5763 struct sockaddr_in6 *sin6;
5765 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5766 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5767 in6_sin6_2_sin(&sin_store, sin6);
5768 addr = (struct sockaddr *)&sin_store;
5770 addr = (struct sockaddr *)&spa->ssp_addr;
5773 addr = (struct sockaddr *)&spa->ssp_addr;
5776 addr = (struct sockaddr *)&spa->ssp_addr;
5779 net = sctp_findnet(stcb, addr);
5782 * We increment here since
5783 * sctp_findassociation_ep_addr() wil do a
5784 * decrement if it finds the stcb as long as
5785 * the locked tcb (last argument) is NOT a
5789 SCTP_INP_INCR_REF(inp);
5790 stcb = sctp_findassociation_ep_addr(&inp, addr,
5793 SCTP_INP_DECR_REF(inp);
5797 if ((stcb != NULL) && (net != NULL)) {
5798 if (net != stcb->asoc.primary_destination) {
5799 if ((net->dest_state & SCTP_ADDR_UNCONFIRMED) == 0) {
5800 /* Ok we need to set it */
5801 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5802 if ((stcb->asoc.alternate) &&
5803 ((net->dest_state & SCTP_ADDR_PF) == 0) &&
5804 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5805 sctp_free_remote_addr(stcb->asoc.alternate);
5806 stcb->asoc.alternate = NULL;
5809 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5813 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5818 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5822 SCTP_TCB_UNLOCK(stcb);
5826 case SCTP_SET_DYNAMIC_PRIMARY:
5828 union sctp_sockstore *ss;
5830 error = priv_check(curthread,
5831 PRIV_NETINET_RESERVEDPORT);
5835 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5836 /* SUPER USER CHECK? */
5837 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5840 case SCTP_SET_PEER_PRIMARY_ADDR:
5842 struct sctp_setpeerprim *sspp;
5843 struct sockaddr *addr;
5844 #if defined(INET) && defined(INET6)
5845 struct sockaddr_in sin_store;
5848 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5849 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5851 struct sctp_ifa *ifa;
5853 #if defined(INET) && defined(INET6)
5854 if (sspp->sspp_addr.ss_family == AF_INET6) {
5855 struct sockaddr_in6 *sin6;
5857 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5858 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5859 in6_sin6_2_sin(&sin_store, sin6);
5860 addr = (struct sockaddr *)&sin_store;
5862 addr = (struct sockaddr *)&sspp->sspp_addr;
5865 addr = (struct sockaddr *)&sspp->sspp_addr;
5868 addr = (struct sockaddr *)&sspp->sspp_addr;
5870 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5876 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5878 * Must validate the ifa found is in
5881 struct sctp_laddr *laddr;
5884 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5885 if (laddr->ifa == NULL) {
5886 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5890 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5891 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5894 if (laddr->ifa == ifa) {
5900 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5905 switch (addr->sa_family) {
5909 struct sockaddr_in *sin;
5911 sin = (struct sockaddr_in *)addr;
5912 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5913 &sin->sin_addr) != 0) {
5914 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5924 struct sockaddr_in6 *sin6;
5926 sin6 = (struct sockaddr_in6 *)addr;
5927 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5928 &sin6->sin6_addr) != 0) {
5929 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5937 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5942 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5943 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5946 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5948 SCTP_TCB_UNLOCK(stcb);
5950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5955 case SCTP_BINDX_ADD_ADDR:
5957 struct sockaddr *sa;
5960 td = (struct thread *)p;
5961 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
5963 if (sa->sa_family == AF_INET) {
5964 if (optsize < sizeof(struct sockaddr_in)) {
5965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5970 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
5971 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5977 if (sa->sa_family == AF_INET6) {
5978 if (optsize < sizeof(struct sockaddr_in6)) {
5979 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5984 (error = prison_local_ip6(td->td_ucred,
5985 &(((struct sockaddr_in6 *)sa)->sin6_addr),
5986 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5987 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5993 error = EAFNOSUPPORT;
5996 sctp_bindx_add_address(so, inp, sa, vrf_id, &error, p);
5999 case SCTP_BINDX_REM_ADDR:
6001 struct sockaddr *sa;
6004 td = (struct thread *)p;
6006 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
6008 if (sa->sa_family == AF_INET) {
6009 if (optsize < sizeof(struct sockaddr_in)) {
6010 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6015 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
6016 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6022 if (sa->sa_family == AF_INET6) {
6023 if (optsize < sizeof(struct sockaddr_in6)) {
6024 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6029 (error = prison_local_ip6(td->td_ucred,
6030 &(((struct sockaddr_in6 *)sa)->sin6_addr),
6031 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6032 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6038 error = EAFNOSUPPORT;
6041 sctp_bindx_delete_address(inp, sa, vrf_id, &error);
6046 struct sctp_event *event;
6047 uint32_t event_type;
6049 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6050 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6051 switch (event->se_type) {
6052 case SCTP_ASSOC_CHANGE:
6053 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6055 case SCTP_PEER_ADDR_CHANGE:
6056 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6058 case SCTP_REMOTE_ERROR:
6059 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6061 case SCTP_SEND_FAILED:
6062 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6064 case SCTP_SHUTDOWN_EVENT:
6065 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6067 case SCTP_ADAPTATION_INDICATION:
6068 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6070 case SCTP_PARTIAL_DELIVERY_EVENT:
6071 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6073 case SCTP_AUTHENTICATION_EVENT:
6074 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6076 case SCTP_STREAM_RESET_EVENT:
6077 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6079 case SCTP_SENDER_DRY_EVENT:
6080 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6082 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6084 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6087 case SCTP_ASSOC_RESET_EVENT:
6088 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6090 case SCTP_STREAM_CHANGE_EVENT:
6091 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6093 case SCTP_SEND_FAILED_EVENT:
6094 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6098 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6102 if (event_type > 0) {
6105 sctp_stcb_feature_on(inp, stcb, event_type);
6106 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6107 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6108 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6109 (stcb->asoc.stream_queue_cnt == 0)) {
6110 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6114 sctp_stcb_feature_off(inp, stcb, event_type);
6116 SCTP_TCB_UNLOCK(stcb);
6119 * We don't want to send up a storm
6120 * of events, so return an error for
6123 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6124 (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6125 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6126 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6127 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6131 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6132 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6133 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6134 ((event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6135 (event->se_assoc_id == SCTP_ALL_ASSOC)))) {
6136 SCTP_INP_WLOCK(inp);
6138 sctp_feature_on(inp, event_type);
6140 sctp_feature_off(inp, event_type);
6142 SCTP_INP_WUNLOCK(inp);
6144 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6145 ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6146 (event->se_assoc_id == SCTP_ALL_ASSOC))) {
6147 SCTP_INP_RLOCK(inp);
6148 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6149 SCTP_TCB_LOCK(stcb);
6151 sctp_stcb_feature_on(inp, stcb, event_type);
6153 sctp_stcb_feature_off(inp, stcb, event_type);
6155 SCTP_TCB_UNLOCK(stcb);
6157 SCTP_INP_RUNLOCK(inp);
6162 SCTP_TCB_UNLOCK(stcb);
6167 case SCTP_RECVRCVINFO:
6171 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6172 SCTP_INP_WLOCK(inp);
6174 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6176 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6178 SCTP_INP_WUNLOCK(inp);
6181 case SCTP_RECVNXTINFO:
6185 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6186 SCTP_INP_WLOCK(inp);
6188 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6190 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6192 SCTP_INP_WUNLOCK(inp);
6195 case SCTP_DEFAULT_SNDINFO:
6197 struct sctp_sndinfo *info;
6200 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6201 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6204 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6205 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6206 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6207 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6208 stcb->asoc.def_send.sinfo_flags |= policy;
6209 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6210 stcb->asoc.def_send.sinfo_context = info->snd_context;
6212 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6215 SCTP_TCB_UNLOCK(stcb);
6217 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6218 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6219 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6220 ((info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6221 (info->snd_assoc_id == SCTP_ALL_ASSOC)))) {
6222 SCTP_INP_WLOCK(inp);
6223 inp->def_send.sinfo_stream = info->snd_sid;
6224 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6225 inp->def_send.sinfo_flags = info->snd_flags;
6226 inp->def_send.sinfo_flags |= policy;
6227 inp->def_send.sinfo_ppid = info->snd_ppid;
6228 inp->def_send.sinfo_context = info->snd_context;
6229 SCTP_INP_WUNLOCK(inp);
6231 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6232 ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6233 (info->snd_assoc_id == SCTP_ALL_ASSOC))) {
6234 SCTP_INP_RLOCK(inp);
6235 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6236 SCTP_TCB_LOCK(stcb);
6237 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6238 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6239 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6240 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6241 stcb->asoc.def_send.sinfo_flags |= policy;
6242 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6243 stcb->asoc.def_send.sinfo_context = info->snd_context;
6245 SCTP_TCB_UNLOCK(stcb);
6247 SCTP_INP_RUNLOCK(inp);
6252 case SCTP_DEFAULT_PRINFO:
6254 struct sctp_default_prinfo *info;
6256 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6257 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6259 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6261 SCTP_TCB_UNLOCK(stcb);
6263 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6268 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6269 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6270 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6271 SCTP_TCB_UNLOCK(stcb);
6273 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6274 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6275 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6276 ((info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6277 (info->pr_assoc_id == SCTP_ALL_ASSOC)))) {
6278 SCTP_INP_WLOCK(inp);
6279 inp->def_send.sinfo_flags &= 0xfff0;
6280 inp->def_send.sinfo_flags |= info->pr_policy;
6281 inp->def_send.sinfo_timetolive = info->pr_value;
6282 SCTP_INP_WUNLOCK(inp);
6284 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6285 ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6286 (info->pr_assoc_id == SCTP_ALL_ASSOC))) {
6287 SCTP_INP_RLOCK(inp);
6288 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6289 SCTP_TCB_LOCK(stcb);
6290 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6291 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6292 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6293 SCTP_TCB_UNLOCK(stcb);
6295 SCTP_INP_RUNLOCK(inp);
6300 case SCTP_PEER_ADDR_THLDS:
6301 /* Applies to the specific association */
6303 struct sctp_paddrthlds *thlds;
6304 struct sctp_nets *net;
6305 struct sockaddr *addr;
6306 #if defined(INET) && defined(INET6)
6307 struct sockaddr_in sin_store;
6310 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6311 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6313 #if defined(INET) && defined(INET6)
6314 if (thlds->spt_address.ss_family == AF_INET6) {
6315 struct sockaddr_in6 *sin6;
6317 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6318 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6319 in6_sin6_2_sin(&sin_store, sin6);
6320 addr = (struct sockaddr *)&sin_store;
6322 addr = (struct sockaddr *)&thlds->spt_address;
6325 addr = (struct sockaddr *)&thlds->spt_address;
6328 addr = (struct sockaddr *)&thlds->spt_address;
6331 net = sctp_findnet(stcb, addr);
6334 * We increment here since
6335 * sctp_findassociation_ep_addr() wil do a
6336 * decrement if it finds the stcb as long as
6337 * the locked tcb (last argument) is NOT a
6341 SCTP_INP_INCR_REF(inp);
6342 stcb = sctp_findassociation_ep_addr(&inp, addr,
6345 SCTP_INP_DECR_REF(inp);
6348 if ((stcb != NULL) && (net == NULL)) {
6350 if (addr->sa_family == AF_INET) {
6351 struct sockaddr_in *sin;
6353 sin = (struct sockaddr_in *)addr;
6354 if (sin->sin_addr.s_addr != INADDR_ANY) {
6355 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6356 SCTP_TCB_UNLOCK(stcb);
6363 if (addr->sa_family == AF_INET6) {
6364 struct sockaddr_in6 *sin6;
6366 sin6 = (struct sockaddr_in6 *)addr;
6367 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6368 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6369 SCTP_TCB_UNLOCK(stcb);
6376 error = EAFNOSUPPORT;
6377 SCTP_TCB_UNLOCK(stcb);
6378 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6382 if (thlds->spt_pathcpthld != 0xffff) {
6384 SCTP_TCB_UNLOCK(stcb);
6387 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6392 net->failure_threshold = thlds->spt_pathmaxrxt;
6393 net->pf_threshold = thlds->spt_pathpfthld;
6394 if (net->dest_state & SCTP_ADDR_PF) {
6395 if ((net->error_count > net->failure_threshold) ||
6396 (net->error_count <= net->pf_threshold)) {
6397 net->dest_state &= ~SCTP_ADDR_PF;
6400 if ((net->error_count > net->pf_threshold) &&
6401 (net->error_count <= net->failure_threshold)) {
6402 net->dest_state |= SCTP_ADDR_PF;
6403 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6404 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6405 stcb->sctp_ep, stcb, net,
6406 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6407 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6410 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6411 if (net->error_count > net->failure_threshold) {
6412 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6413 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6416 if (net->error_count <= net->failure_threshold) {
6417 net->dest_state |= SCTP_ADDR_REACHABLE;
6418 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6422 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6423 net->failure_threshold = thlds->spt_pathmaxrxt;
6424 net->pf_threshold = thlds->spt_pathpfthld;
6425 if (net->dest_state & SCTP_ADDR_PF) {
6426 if ((net->error_count > net->failure_threshold) ||
6427 (net->error_count <= net->pf_threshold)) {
6428 net->dest_state &= ~SCTP_ADDR_PF;
6431 if ((net->error_count > net->pf_threshold) &&
6432 (net->error_count <= net->failure_threshold)) {
6433 net->dest_state |= SCTP_ADDR_PF;
6434 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6435 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6436 stcb->sctp_ep, stcb, net,
6437 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6438 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6441 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6442 if (net->error_count > net->failure_threshold) {
6443 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6444 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6447 if (net->error_count <= net->failure_threshold) {
6448 net->dest_state |= SCTP_ADDR_REACHABLE;
6449 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6453 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6454 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6456 SCTP_TCB_UNLOCK(stcb);
6458 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6459 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6460 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6461 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
6462 SCTP_INP_WLOCK(inp);
6463 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6464 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6465 SCTP_INP_WUNLOCK(inp);
6467 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6473 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6475 struct sctp_udpencaps *encaps;
6476 struct sctp_nets *net;
6477 struct sockaddr *addr;
6478 #if defined(INET) && defined(INET6)
6479 struct sockaddr_in sin_store;
6482 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6483 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6485 #if defined(INET) && defined(INET6)
6486 if (encaps->sue_address.ss_family == AF_INET6) {
6487 struct sockaddr_in6 *sin6;
6489 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6490 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6491 in6_sin6_2_sin(&sin_store, sin6);
6492 addr = (struct sockaddr *)&sin_store;
6494 addr = (struct sockaddr *)&encaps->sue_address;
6497 addr = (struct sockaddr *)&encaps->sue_address;
6500 addr = (struct sockaddr *)&encaps->sue_address;
6503 net = sctp_findnet(stcb, addr);
6506 * We increment here since
6507 * sctp_findassociation_ep_addr() wil do a
6508 * decrement if it finds the stcb as long as
6509 * the locked tcb (last argument) is NOT a
6513 SCTP_INP_INCR_REF(inp);
6514 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6516 SCTP_INP_DECR_REF(inp);
6519 if ((stcb != NULL) && (net == NULL)) {
6521 if (addr->sa_family == AF_INET) {
6522 struct sockaddr_in *sin;
6524 sin = (struct sockaddr_in *)addr;
6525 if (sin->sin_addr.s_addr != INADDR_ANY) {
6526 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6527 SCTP_TCB_UNLOCK(stcb);
6534 if (addr->sa_family == AF_INET6) {
6535 struct sockaddr_in6 *sin6;
6537 sin6 = (struct sockaddr_in6 *)addr;
6538 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6539 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6540 SCTP_TCB_UNLOCK(stcb);
6547 error = EAFNOSUPPORT;
6548 SCTP_TCB_UNLOCK(stcb);
6549 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6556 net->port = encaps->sue_port;
6558 stcb->asoc.port = encaps->sue_port;
6560 SCTP_TCB_UNLOCK(stcb);
6562 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6563 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6564 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6565 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
6566 SCTP_INP_WLOCK(inp);
6567 inp->sctp_ep.port = encaps->sue_port;
6568 SCTP_INP_WUNLOCK(inp);
6570 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6576 case SCTP_ECN_SUPPORTED:
6578 struct sctp_assoc_value *av;
6580 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6581 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6584 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6586 SCTP_TCB_UNLOCK(stcb);
6588 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6589 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6590 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6591 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6592 SCTP_INP_WLOCK(inp);
6593 if (av->assoc_value == 0) {
6594 inp->ecn_supported = 0;
6596 inp->ecn_supported = 1;
6598 SCTP_INP_WUNLOCK(inp);
6600 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6606 case SCTP_PR_SUPPORTED:
6608 struct sctp_assoc_value *av;
6610 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6611 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6614 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6616 SCTP_TCB_UNLOCK(stcb);
6618 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6619 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6620 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6621 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6622 SCTP_INP_WLOCK(inp);
6623 if (av->assoc_value == 0) {
6624 inp->prsctp_supported = 0;
6626 inp->prsctp_supported = 1;
6628 SCTP_INP_WUNLOCK(inp);
6630 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6636 case SCTP_AUTH_SUPPORTED:
6638 struct sctp_assoc_value *av;
6640 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6641 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6644 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6646 SCTP_TCB_UNLOCK(stcb);
6648 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6649 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6650 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6651 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6652 if ((av->assoc_value == 0) &&
6653 (inp->asconf_supported == 1)) {
6655 * AUTH is required for
6658 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6661 SCTP_INP_WLOCK(inp);
6662 if (av->assoc_value == 0) {
6663 inp->auth_supported = 0;
6665 inp->auth_supported = 1;
6667 SCTP_INP_WUNLOCK(inp);
6670 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6676 case SCTP_ASCONF_SUPPORTED:
6678 struct sctp_assoc_value *av;
6680 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6681 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6684 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6686 SCTP_TCB_UNLOCK(stcb);
6688 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6689 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6690 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6691 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6692 if ((av->assoc_value != 0) &&
6693 (inp->auth_supported == 0)) {
6695 * AUTH is required for
6698 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6701 SCTP_INP_WLOCK(inp);
6702 if (av->assoc_value == 0) {
6703 inp->asconf_supported = 0;
6704 sctp_auth_delete_chunk(SCTP_ASCONF,
6705 inp->sctp_ep.local_auth_chunks);
6706 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6707 inp->sctp_ep.local_auth_chunks);
6709 inp->asconf_supported = 1;
6710 sctp_auth_add_chunk(SCTP_ASCONF,
6711 inp->sctp_ep.local_auth_chunks);
6712 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6713 inp->sctp_ep.local_auth_chunks);
6715 SCTP_INP_WUNLOCK(inp);
6718 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6724 case SCTP_RECONFIG_SUPPORTED:
6726 struct sctp_assoc_value *av;
6728 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6729 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6732 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6734 SCTP_TCB_UNLOCK(stcb);
6736 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6737 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6738 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6739 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6740 SCTP_INP_WLOCK(inp);
6741 if (av->assoc_value == 0) {
6742 inp->reconfig_supported = 0;
6744 inp->reconfig_supported = 1;
6746 SCTP_INP_WUNLOCK(inp);
6748 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6754 case SCTP_NRSACK_SUPPORTED:
6756 struct sctp_assoc_value *av;
6758 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6759 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6762 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6764 SCTP_TCB_UNLOCK(stcb);
6766 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6767 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6768 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6769 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6770 SCTP_INP_WLOCK(inp);
6771 if (av->assoc_value == 0) {
6772 inp->nrsack_supported = 0;
6774 inp->nrsack_supported = 1;
6776 SCTP_INP_WUNLOCK(inp);
6778 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6784 case SCTP_PKTDROP_SUPPORTED:
6786 struct sctp_assoc_value *av;
6788 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6789 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6792 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6794 SCTP_TCB_UNLOCK(stcb);
6796 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6797 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6798 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6799 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6800 SCTP_INP_WLOCK(inp);
6801 if (av->assoc_value == 0) {
6802 inp->pktdrop_supported = 0;
6804 inp->pktdrop_supported = 1;
6806 SCTP_INP_WUNLOCK(inp);
6808 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6816 struct sctp_assoc_value *av;
6817 struct sctp_nets *net;
6819 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6820 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6823 stcb->asoc.max_cwnd = av->assoc_value;
6824 if (stcb->asoc.max_cwnd > 0) {
6825 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6826 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6827 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6828 net->cwnd = stcb->asoc.max_cwnd;
6829 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6830 net->cwnd = net->mtu - sizeof(struct sctphdr);
6835 SCTP_TCB_UNLOCK(stcb);
6837 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6838 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6839 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6840 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6841 SCTP_INP_WLOCK(inp);
6842 inp->max_cwnd = av->assoc_value;
6843 SCTP_INP_WUNLOCK(inp);
6845 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6852 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6853 error = ENOPROTOOPT;
6855 } /* end switch (opt) */
6860 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6862 struct epoch_tracker et;
6863 struct sctp_inpcb *inp;
6864 void *optval = NULL;
6869 if ((sopt->sopt_level == SOL_SOCKET) &&
6870 (sopt->sopt_name == SO_SETFIB)) {
6871 inp = (struct sctp_inpcb *)so->so_pcb;
6873 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6876 SCTP_INP_WLOCK(inp);
6877 inp->fibnum = so->so_fibnum;
6878 SCTP_INP_WUNLOCK(inp);
6881 if (sopt->sopt_level != IPPROTO_SCTP) {
6882 /* wrong proto level... send back up to IP */
6884 if (INP_CHECK_SOCKAF(so, AF_INET6))
6885 error = ip6_ctloutput(so, sopt);
6887 #if defined(INET) && defined(INET6)
6891 error = ip_ctloutput(so, sopt);
6895 optsize = sopt->sopt_valsize;
6896 if (optsize > SCTP_SOCKET_OPTION_LIMIT) {
6897 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6901 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6902 if (optval == NULL) {
6903 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6906 error = sooptcopyin(sopt, optval, optsize, optsize);
6908 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6912 p = (void *)sopt->sopt_td;
6913 if (sopt->sopt_dir == SOPT_SET) {
6914 NET_EPOCH_ENTER(et);
6915 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6917 } else if (sopt->sopt_dir == SOPT_GET) {
6918 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6920 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6923 if ((error == 0) && (optval != NULL)) {
6924 error = sooptcopyout(sopt, optval, optsize);
6925 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6926 } else if (optval != NULL) {
6927 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6935 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6937 struct epoch_tracker et;
6939 int create_lock_on = 0;
6941 struct sctp_inpcb *inp;
6942 struct sctp_tcb *stcb = NULL;
6944 inp = (struct sctp_inpcb *)so->so_pcb;
6946 /* I made the same as TCP since we are not setup? */
6947 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6948 return (ECONNRESET);
6951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6955 switch (addr->sa_family) {
6959 struct sockaddr_in6 *sin6;
6961 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6962 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6965 sin6 = (struct sockaddr_in6 *)addr;
6966 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6->sin6_addr)) != 0) {
6967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6976 struct sockaddr_in *sin;
6978 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6979 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6982 sin = (struct sockaddr_in *)addr;
6983 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sin->sin_addr)) != 0) {
6984 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6991 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6992 return (EAFNOSUPPORT);
6994 SCTP_INP_INCR_REF(inp);
6995 SCTP_ASOC_CREATE_LOCK(inp);
6997 NET_EPOCH_ENTER(et);
6999 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
7000 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
7001 /* Should I really unlock ? */
7002 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
7007 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
7008 (addr->sa_family == AF_INET6)) {
7009 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7014 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7015 /* Bind a ephemeral port */
7016 error = sctp_inpcb_bind(so, NULL, NULL, p);
7021 /* Now do we connect? */
7022 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
7023 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
7024 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7028 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7029 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7030 /* We are already connected AND the TCP model */
7031 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7035 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7036 SCTP_INP_RLOCK(inp);
7037 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7038 SCTP_INP_RUNLOCK(inp);
7041 * We increment here since sctp_findassociation_ep_addr()
7042 * will do a decrement if it finds the stcb as long as the
7043 * locked tcb (last argument) is NOT a TCB.. aka NULL.
7045 SCTP_INP_INCR_REF(inp);
7046 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7048 SCTP_INP_DECR_REF(inp);
7050 SCTP_TCB_UNLOCK(stcb);
7054 /* Already have or am bring up an association */
7055 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7060 vrf_id = inp->def_vrf_id;
7061 /* We are GOOD to go */
7062 stcb = sctp_aloc_assoc_connected(inp, addr, &error, 0, 0, vrf_id,
7063 inp->sctp_ep.pre_open_stream_count,
7064 inp->sctp_ep.port, p,
7065 SCTP_INITIALIZE_AUTH_PARAMS);
7067 /* Gak! no memory */
7070 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7071 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7073 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7074 SCTP_TCB_UNLOCK(stcb);
7077 if (create_lock_on) {
7078 SCTP_ASOC_CREATE_UNLOCK(inp);
7080 SCTP_INP_DECR_REF(inp);
7086 sctp_listen(struct socket *so, int backlog, struct thread *p)
7089 * Note this module depends on the protocol processing being called
7090 * AFTER any socket level flags and backlog are applied to the
7091 * socket. The traditional way that the socket flags are applied is
7092 * AFTER protocol processing. We have made a change to the
7093 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7094 * place if the socket API for SCTP is to work properly.
7098 struct sctp_inpcb *inp;
7100 inp = (struct sctp_inpcb *)so->so_pcb;
7102 /* I made the same as TCP since we are not setup? */
7103 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7104 return (ECONNRESET);
7106 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7107 /* See if we have a listener */
7108 struct sctp_inpcb *tinp;
7109 union sctp_sockstore store;
7111 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7113 struct sctp_laddr *laddr;
7115 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7116 memcpy(&store, &laddr->ifa->address, sizeof(store));
7117 switch (store.sa.sa_family) {
7120 store.sin.sin_port = inp->sctp_lport;
7125 store.sin6.sin6_port = inp->sctp_lport;
7131 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7132 if (tinp && (tinp != inp) &&
7133 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7134 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7135 (SCTP_IS_LISTENING(tinp))) {
7137 * we have a listener already and
7140 SCTP_INP_DECR_REF(tinp);
7141 return (EADDRINUSE);
7143 SCTP_INP_DECR_REF(tinp);
7147 /* Setup a local addr bound all */
7148 memset(&store, 0, sizeof(store));
7150 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7151 store.sa.sa_family = AF_INET6;
7152 store.sa.sa_len = sizeof(struct sockaddr_in6);
7156 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7157 store.sa.sa_family = AF_INET;
7158 store.sa.sa_len = sizeof(struct sockaddr_in);
7161 switch (store.sa.sa_family) {
7164 store.sin.sin_port = inp->sctp_lport;
7169 store.sin6.sin6_port = inp->sctp_lport;
7175 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7176 if (tinp && (tinp != inp) &&
7177 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7178 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7179 (SCTP_IS_LISTENING(tinp))) {
7181 * we have a listener already and its not
7184 SCTP_INP_DECR_REF(tinp);
7185 return (EADDRINUSE);
7187 SCTP_INP_DECR_REF(tinp);
7191 SCTP_INP_INFO_WLOCK();
7192 SCTP_INP_WLOCK(inp);
7193 #ifdef SCTP_LOCK_LOGGING
7194 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7195 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7198 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7199 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7201 * The unlucky case - We are in the tcp pool with this guy.
7202 * - Someone else is in the main inp slot. - We must move
7203 * this guy (the listener) to the main slot - We must then
7204 * move the guy that was listener to the TCP Pool.
7206 if (sctp_swap_inpcb_for_listen(inp)) {
7208 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7213 error = solisten_proto_check(so);
7218 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7219 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7221 solisten_proto_abort(so);
7223 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7226 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7227 ((inp->sctp_flags & SCTP_PCB_FLAGS_WAS_CONNECTED) ||
7228 (inp->sctp_flags & SCTP_PCB_FLAGS_WAS_ABORTED))) {
7230 solisten_proto_abort(so);
7232 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7235 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7236 if ((error = sctp_inpcb_bind_locked(inp, NULL, NULL, p))) {
7238 solisten_proto_abort(so);
7239 /* bind error, probably perm */
7243 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7244 solisten_proto(so, backlog);
7246 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7248 solisten_proto_abort(so);
7251 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7253 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7257 SCTP_INP_WUNLOCK(inp);
7258 SCTP_INP_INFO_WUNLOCK();
7262 static int sctp_defered_wakeup_cnt = 0;
7265 sctp_accept(struct socket *so, struct sockaddr **addr)
7267 struct sctp_tcb *stcb;
7268 struct sctp_inpcb *inp;
7269 union sctp_sockstore store;
7273 inp = (struct sctp_inpcb *)so->so_pcb;
7276 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7277 return (ECONNRESET);
7279 SCTP_INP_WLOCK(inp);
7280 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7281 SCTP_INP_WUNLOCK(inp);
7282 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7283 return (EOPNOTSUPP);
7285 if (so->so_state & SS_ISDISCONNECTED) {
7286 SCTP_INP_WUNLOCK(inp);
7287 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7288 return (ECONNABORTED);
7290 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7292 SCTP_INP_WUNLOCK(inp);
7293 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7294 return (ECONNRESET);
7296 SCTP_TCB_LOCK(stcb);
7297 store = stcb->asoc.primary_destination->ro._l_addr;
7298 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7299 /* Wake any delayed sleep action */
7300 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7301 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7302 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7303 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7304 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7305 if (sowriteable(inp->sctp_socket)) {
7306 sowwakeup_locked(inp->sctp_socket);
7308 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7311 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7312 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7313 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7314 if (soreadable(inp->sctp_socket)) {
7315 sctp_defered_wakeup_cnt++;
7316 sorwakeup_locked(inp->sctp_socket);
7318 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7322 SCTP_INP_WUNLOCK(inp);
7323 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7324 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7325 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7327 SCTP_TCB_UNLOCK(stcb);
7329 switch (store.sa.sa_family) {
7333 struct sockaddr_in *sin;
7335 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7338 sin->sin_family = AF_INET;
7339 sin->sin_len = sizeof(*sin);
7340 sin->sin_port = store.sin.sin_port;
7341 sin->sin_addr = store.sin.sin_addr;
7342 *addr = (struct sockaddr *)sin;
7349 struct sockaddr_in6 *sin6;
7351 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7354 sin6->sin6_family = AF_INET6;
7355 sin6->sin6_len = sizeof(*sin6);
7356 sin6->sin6_port = store.sin6.sin6_port;
7357 sin6->sin6_addr = store.sin6.sin6_addr;
7358 if ((error = sa6_recoverscope(sin6)) != 0) {
7359 SCTP_FREE_SONAME(sin6);
7362 *addr = (struct sockaddr *)sin6;
7375 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7377 struct sockaddr_in *sin;
7379 struct sctp_inpcb *inp;
7380 struct sctp_ifa *sctp_ifa;
7383 * Do the malloc first in case it blocks.
7385 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7388 sin->sin_family = AF_INET;
7389 sin->sin_len = sizeof(*sin);
7390 inp = (struct sctp_inpcb *)so->so_pcb;
7392 SCTP_FREE_SONAME(sin);
7393 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7394 return (ECONNRESET);
7396 SCTP_INP_RLOCK(inp);
7397 sin->sin_port = inp->sctp_lport;
7398 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7399 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7400 struct sctp_tcb *stcb;
7401 struct sockaddr_in *sin_a;
7402 struct sctp_nets *net;
7405 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7411 SCTP_TCB_LOCK(stcb);
7412 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7413 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7415 /* this will make coverity happy */
7418 if (sin_a->sin_family == AF_INET) {
7423 if ((!fnd) || (sin_a == NULL)) {
7425 SCTP_TCB_UNLOCK(stcb);
7429 vrf_id = inp->def_vrf_id;
7430 sctp_ifa = sctp_source_address_selection(inp,
7432 (sctp_route_t *)&net->ro,
7435 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7436 sctp_free_ifa(sctp_ifa);
7438 SCTP_TCB_UNLOCK(stcb);
7440 /* For the bound all case you get back 0 */
7442 sin->sin_addr.s_addr = 0;
7446 /* Take the first IPv4 address in the list */
7447 struct sctp_laddr *laddr;
7450 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7451 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7452 struct sockaddr_in *sin_a;
7454 sin_a = &laddr->ifa->address.sin;
7455 sin->sin_addr = sin_a->sin_addr;
7461 SCTP_FREE_SONAME(sin);
7462 SCTP_INP_RUNLOCK(inp);
7463 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7467 SCTP_INP_RUNLOCK(inp);
7468 (*addr) = (struct sockaddr *)sin;
7473 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7475 struct sockaddr_in *sin;
7477 struct sockaddr_in *sin_a;
7478 struct sctp_inpcb *inp;
7479 struct sctp_tcb *stcb;
7480 struct sctp_nets *net;
7482 /* Do the malloc first in case it blocks. */
7483 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7486 sin->sin_family = AF_INET;
7487 sin->sin_len = sizeof(*sin);
7489 inp = (struct sctp_inpcb *)so->so_pcb;
7490 if ((inp == NULL) ||
7491 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7492 /* UDP type and listeners will drop out here */
7493 SCTP_FREE_SONAME(sin);
7494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7497 SCTP_INP_RLOCK(inp);
7498 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7500 SCTP_TCB_LOCK(stcb);
7502 SCTP_INP_RUNLOCK(inp);
7504 SCTP_FREE_SONAME(sin);
7505 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7506 return (ECONNRESET);
7509 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7510 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7511 if (sin_a->sin_family == AF_INET) {
7513 sin->sin_port = stcb->rport;
7514 sin->sin_addr = sin_a->sin_addr;
7518 SCTP_TCB_UNLOCK(stcb);
7520 /* No IPv4 address */
7521 SCTP_FREE_SONAME(sin);
7522 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7525 (*addr) = (struct sockaddr *)sin;
7529 #define SCTP_PROTOSW \
7530 .pr_protocol = IPPROTO_SCTP, \
7531 .pr_ctloutput = sctp_ctloutput, \
7532 .pr_abort = sctp_abort, \
7533 .pr_accept = sctp_accept, \
7534 .pr_attach = sctp_attach, \
7535 .pr_bind = sctp_bind, \
7536 .pr_connect = sctp_connect, \
7537 .pr_control = in_control, \
7538 .pr_close = sctp_close, \
7539 .pr_detach = sctp_close, \
7540 .pr_sopoll = sopoll_generic, \
7541 .pr_flush = sctp_flush, \
7542 .pr_disconnect = sctp_disconnect, \
7543 .pr_listen = sctp_listen, \
7544 .pr_peeraddr = sctp_peeraddr, \
7545 .pr_send = sctp_sendm, \
7546 .pr_shutdown = sctp_shutdown, \
7547 .pr_sockaddr = sctp_ingetaddr, \
7548 .pr_sosend = sctp_sosend, \
7549 .pr_soreceive = sctp_soreceive \
7551 struct protosw sctp_seqpacket_protosw = {
7552 .pr_type = SOCK_SEQPACKET,
7553 .pr_flags = PR_WANTRCVD,
7557 struct protosw sctp_stream_protosw = {
7558 .pr_type = SOCK_STREAM,
7559 .pr_flags = PR_CONNREQUIRED | PR_WANTRCVD,