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 SCTP_SB_CLEAR(so->so_snd);
459 * same for the rcv ones, they are only here for the
462 SCTP_SB_CLEAR(so->so_rcv);
464 /* Now null out the reference, we are completely detached. */
468 SCTP_INP_WUNLOCK(inp);
474 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
476 struct sctp_inpcb *inp;
477 struct inpcb *ip_inp;
479 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
481 inp = (struct sctp_inpcb *)so->so_pcb;
483 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
486 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
487 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
492 error = sctp_inpcb_alloc(so, vrf_id);
496 inp = (struct sctp_inpcb *)so->so_pcb;
498 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
499 ip_inp = &inp->ip_inp.inp;
500 ip_inp->inp_vflag |= INP_IPV4;
501 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
502 SCTP_INP_WUNLOCK(inp);
507 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
509 struct sctp_inpcb *inp;
511 inp = (struct sctp_inpcb *)so->so_pcb;
513 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
517 if ((addr->sa_family != AF_INET) ||
518 (addr->sa_len != sizeof(struct sockaddr_in))) {
519 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
523 return (sctp_inpcb_bind(so, addr, NULL, p));
528 sctp_close(struct socket *so)
530 struct epoch_tracker et;
531 struct sctp_inpcb *inp;
533 inp = (struct sctp_inpcb *)so->so_pcb;
538 * Inform all the lower layer assoc that we are done.
542 #ifdef SCTP_LOG_CLOSING
543 sctp_log_closing(inp, NULL, 17);
545 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
546 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP;
547 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
548 (so->so_rcv.sb_cc > 0)) {
549 #ifdef SCTP_LOG_CLOSING
550 sctp_log_closing(inp, NULL, 13);
552 SCTP_INP_WUNLOCK(inp);
553 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
554 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
556 #ifdef SCTP_LOG_CLOSING
557 sctp_log_closing(inp, NULL, 14);
559 SCTP_INP_WUNLOCK(inp);
560 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
561 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
564 * The socket is now detached, no matter what the state of
565 * the SCTP association.
568 SCTP_SB_CLEAR(so->so_snd);
570 * same for the rcv ones, they are only here for the
573 SCTP_SB_CLEAR(so->so_rcv);
575 /* Now null out the reference, we are completely detached. */
579 SCTP_INP_WUNLOCK(inp);
585 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
586 struct mbuf *control, struct thread *p);
589 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
590 struct mbuf *control, struct thread *p)
592 struct sctp_inpcb *inp;
595 inp = (struct sctp_inpcb *)so->so_pcb;
598 sctp_m_freem(control);
601 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
605 /* Got to have an to address if we are NOT a connected socket */
606 if ((addr == NULL) &&
607 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
608 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
614 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
615 error = EDESTADDRREQ;
616 } else if (addr->sa_family != AF_INET) {
617 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
618 error = EAFNOSUPPORT;
619 } else if (addr->sa_len != sizeof(struct sockaddr_in)) {
620 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
626 sctp_m_freem(control);
632 /* now what about control */
635 sctp_m_freem(inp->control);
638 inp->control = control;
642 SCTP_BUF_NEXT(inp->pkt_last) = m;
645 inp->pkt_last = inp->pkt = m;
648 /* FreeBSD uses a flag passed */
649 ((flags & PRUS_MORETOCOME) == 0)
652 * note with the current version this code will only be used
653 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
654 * re-defining sosend to use the sctp_sosend. One can
655 * optionally switch back to this code (by changing back the
656 * definitions) but this is not advisable. This code is used
657 * by FreeBSD when sending a file with sendfile() though.
659 struct epoch_tracker et;
663 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
674 sctp_disconnect(struct socket *so)
676 struct sctp_inpcb *inp;
678 inp = (struct sctp_inpcb *)so->so_pcb;
680 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
684 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
685 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
686 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
688 SCTP_INP_RUNLOCK(inp);
691 struct epoch_tracker et;
692 struct sctp_association *asoc;
693 struct sctp_tcb *stcb;
695 stcb = LIST_FIRST(&inp->sctp_asoc_list);
697 SCTP_INP_RUNLOCK(inp);
698 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
703 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
704 /* We are about to be freed, out of here */
705 SCTP_TCB_UNLOCK(stcb);
706 SCTP_INP_RUNLOCK(inp);
710 if (((so->so_options & SO_LINGER) &&
711 (so->so_linger == 0)) ||
712 (so->so_rcv.sb_cc > 0)) {
713 if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) {
714 /* Left with Data unread */
717 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
718 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
719 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
721 SCTP_INP_RUNLOCK(inp);
722 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
723 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
724 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
726 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
727 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
728 /* No unlock tcb assoc is gone */
732 if (TAILQ_EMPTY(&asoc->send_queue) &&
733 TAILQ_EMPTY(&asoc->sent_queue) &&
734 (asoc->stream_queue_cnt == 0)) {
735 /* there is nothing queued to send, so done */
736 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
739 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) &&
740 (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
741 /* only send SHUTDOWN 1st time thru */
742 struct sctp_nets *netp;
744 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
745 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
746 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
748 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
749 sctp_stop_timers_for_shutdown(stcb);
750 if (stcb->asoc.alternate) {
751 netp = stcb->asoc.alternate;
753 netp = stcb->asoc.primary_destination;
755 sctp_send_shutdown(stcb, netp);
756 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
757 stcb->sctp_ep, stcb, netp);
758 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
759 stcb->sctp_ep, stcb, NULL);
760 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
764 * we still got (or just got) data to send,
765 * so set SHUTDOWN_PENDING
768 * XXX sockets draft says that SCTP_EOF
769 * should be sent with no data. currently,
770 * we will allow user data to be sent first
771 * and move to SHUTDOWN-PENDING
773 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
774 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
775 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
776 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
778 if (TAILQ_EMPTY(&asoc->send_queue) &&
779 TAILQ_EMPTY(&asoc->sent_queue) &&
780 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
784 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
785 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
786 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
787 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
788 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
789 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
790 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
792 SCTP_INP_RUNLOCK(inp);
793 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
794 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
798 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
801 soisdisconnecting(so);
803 SCTP_TCB_UNLOCK(stcb);
804 SCTP_INP_RUNLOCK(inp);
809 /* UDP model does not support this */
810 SCTP_INP_RUNLOCK(inp);
811 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
817 sctp_flush(struct socket *so, int how)
820 * We will just clear out the values and let subsequent close clear
821 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
822 * they will not be able to read the data, the socket will block
823 * that from happening.
825 struct sctp_inpcb *inp;
827 inp = (struct sctp_inpcb *)so->so_pcb;
829 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
833 /* For the 1 to many model this does nothing */
834 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
835 SCTP_INP_RUNLOCK(inp);
838 SCTP_INP_RUNLOCK(inp);
839 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
841 * First make sure the sb will be happy, we don't use these
842 * except maybe the count
845 SCTP_INP_READ_LOCK(inp);
846 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
847 SCTP_INP_READ_UNLOCK(inp);
848 SCTP_INP_WUNLOCK(inp);
849 so->so_rcv.sb_cc = 0;
850 so->so_rcv.sb_mbcnt = 0;
851 so->so_rcv.sb_mb = NULL;
853 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
855 * First make sure the sb will be happy, we don't use these
856 * except maybe the count
858 so->so_snd.sb_cc = 0;
859 so->so_snd.sb_mbcnt = 0;
860 so->so_snd.sb_mb = NULL;
866 sctp_shutdown(struct socket *so)
868 struct sctp_inpcb *inp;
870 inp = (struct sctp_inpcb *)so->so_pcb;
872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
876 /* For UDP model this is a invalid call */
877 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
878 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
879 /* Restore the flags that the soshutdown took away. */
880 SOCKBUF_LOCK(&so->so_rcv);
881 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
882 SOCKBUF_UNLOCK(&so->so_rcv);
883 /* This proc will wakeup for read and do nothing (I hope) */
884 SCTP_INP_RUNLOCK(inp);
885 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
889 * Ok, if we reach here its the TCP model and it is either a
890 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
893 struct epoch_tracker et;
894 struct sctp_tcb *stcb;
895 struct sctp_association *asoc;
896 struct sctp_nets *netp;
899 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
900 SCTP_INP_RUNLOCK(inp);
905 stcb = LIST_FIRST(&inp->sctp_asoc_list);
908 * Ok, we hit the case that the shutdown call was
909 * made after an abort or something. Nothing to do
912 SCTP_INP_RUNLOCK(inp);
917 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
918 SCTP_TCB_UNLOCK(stcb);
919 SCTP_INP_RUNLOCK(inp);
922 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) &&
923 (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) &&
924 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) {
926 * If we are not in or before ESTABLISHED, there is
927 * no protocol action required.
929 SCTP_TCB_UNLOCK(stcb);
930 SCTP_INP_RUNLOCK(inp);
934 if (stcb->asoc.alternate) {
935 netp = stcb->asoc.alternate;
937 netp = stcb->asoc.primary_destination;
939 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) &&
940 TAILQ_EMPTY(&asoc->send_queue) &&
941 TAILQ_EMPTY(&asoc->sent_queue) &&
942 (asoc->stream_queue_cnt == 0)) {
943 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
946 /* there is nothing queued to send, so I'm done... */
947 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
948 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
949 sctp_stop_timers_for_shutdown(stcb);
950 sctp_send_shutdown(stcb, netp);
951 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
952 stcb->sctp_ep, stcb, netp);
955 * We still got (or just got) data to send, so set
958 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
959 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
960 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
962 if (TAILQ_EMPTY(&asoc->send_queue) &&
963 TAILQ_EMPTY(&asoc->sent_queue) &&
964 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
968 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
969 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
970 SCTP_INP_RUNLOCK(inp);
971 sctp_abort_an_association(stcb->sctp_ep, stcb,
972 op_err, false, SCTP_SO_LOCKED);
977 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
979 * XXX: Why do this in the case where we have still data
982 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
983 SCTP_TCB_UNLOCK(stcb);
984 SCTP_INP_RUNLOCK(inp);
991 * copies a "user" presentable address and removes embedded scope, etc.
992 * returns 0 on success, 1 on error
995 sctp_fill_user_address(struct sockaddr *dst, struct sockaddr *src)
998 struct sockaddr_in6 lsa6;
1000 src = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)src,
1003 memcpy(dst, src, src->sa_len);
1008 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1009 struct sctp_tcb *stcb,
1011 struct sockaddr *addr,
1014 struct sctp_ifn *sctp_ifn;
1015 struct sctp_ifa *sctp_ifa;
1019 int ipv4_local_scope, ipv4_addr_legal;
1022 int local_scope, site_scope, ipv6_addr_legal;
1024 struct sctp_vrf *vrf;
1026 SCTP_IPI_ADDR_LOCK_ASSERT();
1032 /* Turn on all the appropriate scope */
1033 loopback_scope = stcb->asoc.scope.loopback_scope;
1035 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1036 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1039 local_scope = stcb->asoc.scope.local_scope;
1040 site_scope = stcb->asoc.scope.site_scope;
1041 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1044 /* Use generic values for endpoints. */
1047 ipv4_local_scope = 1;
1053 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1055 ipv6_addr_legal = 1;
1058 if (SCTP_IPV6_V6ONLY(inp)) {
1059 ipv4_addr_legal = 0;
1061 ipv4_addr_legal = 1;
1066 ipv6_addr_legal = 0;
1069 ipv4_addr_legal = 1;
1073 vrf = sctp_find_vrf(vrf_id);
1077 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1078 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1079 if ((loopback_scope == 0) &&
1080 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1081 /* Skip loopback if loopback_scope not set */
1084 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1087 * For the BOUND-ALL case, the list
1088 * associated with a TCB is Always
1089 * considered a reverse list.. i.e.
1090 * it lists addresses that are NOT
1091 * part of the association. If this
1092 * is one of those we must skip it.
1094 if (sctp_is_addr_restricted(stcb,
1099 switch (sctp_ifa->address.sa.sa_family) {
1102 if (ipv4_addr_legal) {
1103 struct sockaddr_in *sin;
1105 sin = &sctp_ifa->address.sin;
1106 if (sin->sin_addr.s_addr == 0) {
1114 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1115 &sin->sin_addr) != 0) {
1118 if ((ipv4_local_scope == 0) &&
1119 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1123 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1124 if (actual + sizeof(struct sockaddr_in6) > limit) {
1127 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)addr);
1128 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1129 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1130 actual += sizeof(struct sockaddr_in6);
1133 if (actual + sizeof(struct sockaddr_in) > limit) {
1136 memcpy(addr, sin, sizeof(struct sockaddr_in));
1137 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1138 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in));
1139 actual += sizeof(struct sockaddr_in);
1150 if (ipv6_addr_legal) {
1151 struct sockaddr_in6 *sin6;
1153 sin6 = &sctp_ifa->address.sin6;
1154 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1162 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1163 &sin6->sin6_addr) != 0) {
1166 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1167 if (local_scope == 0)
1169 if (sin6->sin6_scope_id == 0) {
1170 if (sa6_recoverscope(sin6) != 0)
1183 if ((site_scope == 0) &&
1184 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1187 if (actual + sizeof(struct sockaddr_in6) > limit) {
1190 memcpy(addr, sin6, sizeof(struct sockaddr_in6));
1191 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1192 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1193 actual += sizeof(struct sockaddr_in6);
1206 struct sctp_laddr *laddr;
1209 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1211 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1215 sa_len = laddr->ifa->address.sa.sa_len;
1216 if (actual + sa_len > limit) {
1219 if (sctp_fill_user_address(addr, &laddr->ifa->address.sa))
1221 switch (laddr->ifa->address.sa.sa_family) {
1224 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1229 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1236 addr = (struct sockaddr *)((caddr_t)addr + sa_len);
1244 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1245 struct sctp_tcb *stcb,
1247 struct sockaddr *addr)
1251 SCTP_IPI_ADDR_RLOCK();
1252 /* fill up addresses for the endpoint's default vrf */
1253 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, addr,
1255 SCTP_IPI_ADDR_RUNLOCK();
1260 sctp_max_size_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1262 struct sctp_vrf *vrf;
1266 * In both sub-set bound an bound_all cases we return the size of
1267 * the maximum number of addresses that you could get. In reality
1268 * the sub-set bound may have an exclusion list for a given TCB or
1269 * in the bound-all case a TCB may NOT include the loopback or other
1270 * addresses as well.
1272 SCTP_IPI_ADDR_LOCK_ASSERT();
1273 vrf = sctp_find_vrf(vrf_id);
1278 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1279 struct sctp_ifn *sctp_ifn;
1280 struct sctp_ifa *sctp_ifa;
1282 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1283 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1284 /* Count them if they are the right type */
1285 switch (sctp_ifa->address.sa.sa_family) {
1289 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1290 size += sizeof(struct sockaddr_in6);
1292 size += sizeof(struct sockaddr_in);
1294 size += sizeof(struct sockaddr_in);
1300 size += sizeof(struct sockaddr_in6);
1309 struct sctp_laddr *laddr;
1311 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1312 switch (laddr->ifa->address.sa.sa_family) {
1316 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1317 size += sizeof(struct sockaddr_in6);
1319 size += sizeof(struct sockaddr_in);
1321 size += sizeof(struct sockaddr_in);
1327 size += sizeof(struct sockaddr_in6);
1339 sctp_max_size_addresses(struct sctp_inpcb *inp)
1343 SCTP_IPI_ADDR_RLOCK();
1344 /* Maximum size of all addresses for the endpoint's default VRF */
1345 size = sctp_max_size_addresses_vrf(inp, inp->def_vrf_id);
1346 SCTP_IPI_ADDR_RUNLOCK();
1351 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1352 size_t optsize, void *p, int delay)
1355 int creat_lock_on = 0;
1356 struct sctp_tcb *stcb = NULL;
1357 struct sockaddr *sa;
1358 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1362 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1364 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1365 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1366 /* We are already connected AND the TCP model */
1367 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1368 return (EADDRINUSE);
1371 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1372 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1373 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1377 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1378 SCTP_INP_RLOCK(inp);
1379 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1380 SCTP_INP_RUNLOCK(inp);
1383 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1386 SCTP_INP_INCR_REF(inp);
1387 SCTP_ASOC_CREATE_LOCK(inp);
1389 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1390 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1391 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1395 totaddrp = (unsigned int *)optval;
1396 totaddr = *totaddrp;
1397 sa = (struct sockaddr *)(totaddrp + 1);
1398 error = sctp_connectx_helper_find(inp, sa, totaddr, &num_v4, &num_v6, (unsigned int)(optsize - sizeof(int)));
1400 /* Already have or am bring up an association */
1401 SCTP_ASOC_CREATE_UNLOCK(inp);
1403 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1407 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1412 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1414 if (SCTP_IPV6_V6ONLY(inp)) {
1416 * if IPV6_V6ONLY flag, ignore connections destined
1417 * to a v4 addr or v4-mapped addr
1419 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1425 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1426 SCTP_PCB_FLAGS_UNBOUND) {
1427 /* Bind a ephemeral port */
1428 error = sctp_inpcb_bind(so, NULL, NULL, p);
1434 /* FIX ME: do we want to pass in a vrf on the connect call? */
1435 vrf_id = inp->def_vrf_id;
1437 /* We are GOOD to go */
1438 stcb = sctp_aloc_assoc_connected(inp, sa, &error, 0, 0, vrf_id,
1439 inp->sctp_ep.pre_open_stream_count,
1442 SCTP_INITIALIZE_AUTH_PARAMS);
1444 /* Gak! no memory */
1447 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1448 /* move to second address */
1449 switch (sa->sa_family) {
1452 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1457 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1465 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1466 /* Fill in the return id */
1470 a_id = (sctp_assoc_t *)optval;
1471 *a_id = sctp_get_associd(stcb);
1474 /* doing delayed connection */
1475 stcb->asoc.delayed_connection = 1;
1476 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1478 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1479 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1481 SCTP_TCB_UNLOCK(stcb);
1483 if (creat_lock_on) {
1484 SCTP_ASOC_CREATE_UNLOCK(inp);
1486 SCTP_INP_DECR_REF(inp);
1490 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1491 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1492 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1493 SCTP_INP_RLOCK(inp); \
1494 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1496 SCTP_TCB_LOCK(stcb); \
1498 SCTP_INP_RUNLOCK(inp); \
1499 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1500 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1501 if (stcb == NULL) { \
1502 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1511 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1512 if (size < sizeof(type)) { \
1513 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1517 destp = (type *)srcp; \
1522 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1525 struct sctp_inpcb *inp = NULL;
1527 struct sctp_tcb *stcb = NULL;
1529 if (optval == NULL) {
1530 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1534 inp = (struct sctp_inpcb *)so->so_pcb;
1536 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1543 case SCTP_AUTOCLOSE:
1544 case SCTP_EXPLICIT_EOR:
1545 case SCTP_AUTO_ASCONF:
1546 case SCTP_DISABLE_FRAGMENTS:
1547 case SCTP_I_WANT_MAPPED_V4_ADDR:
1548 case SCTP_USE_EXT_RCVINFO:
1549 SCTP_INP_RLOCK(inp);
1551 case SCTP_DISABLE_FRAGMENTS:
1552 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1554 case SCTP_I_WANT_MAPPED_V4_ADDR:
1555 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1557 case SCTP_AUTO_ASCONF:
1558 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1559 /* only valid for bound all sockets */
1560 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1562 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1567 case SCTP_EXPLICIT_EOR:
1568 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1571 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1573 case SCTP_USE_EXT_RCVINFO:
1574 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1576 case SCTP_AUTOCLOSE:
1577 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1578 val = sctp_ticks_to_secs(inp->sctp_ep.auto_close_time);
1584 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1585 error = ENOPROTOOPT;
1586 } /* end switch (sopt->sopt_name) */
1587 if (*optsize < sizeof(val)) {
1588 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1592 SCTP_INP_RUNLOCK(inp);
1594 /* return the option value */
1595 *(int *)optval = val;
1596 *optsize = sizeof(val);
1599 case SCTP_GET_PACKET_LOG:
1601 #ifdef SCTP_PACKET_LOGGING
1605 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1606 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1609 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1614 case SCTP_REUSE_PORT:
1618 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1619 /* Can't do this for a 1-m socket */
1623 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1624 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1625 *optsize = sizeof(uint32_t);
1628 case SCTP_PARTIAL_DELIVERY_POINT:
1632 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1633 *value = inp->partial_delivery_point;
1634 *optsize = sizeof(uint32_t);
1637 case SCTP_FRAGMENT_INTERLEAVE:
1641 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1642 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1643 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1644 *value = SCTP_FRAG_LEVEL_2;
1646 *value = SCTP_FRAG_LEVEL_1;
1649 *value = SCTP_FRAG_LEVEL_0;
1651 *optsize = sizeof(uint32_t);
1654 case SCTP_INTERLEAVING_SUPPORTED:
1656 struct sctp_assoc_value *av;
1658 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1659 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1662 av->assoc_value = stcb->asoc.idata_supported;
1663 SCTP_TCB_UNLOCK(stcb);
1665 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1666 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1667 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1668 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1669 SCTP_INP_RLOCK(inp);
1670 if (inp->idata_supported) {
1671 av->assoc_value = 1;
1673 av->assoc_value = 0;
1675 SCTP_INP_RUNLOCK(inp);
1677 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1682 *optsize = sizeof(struct sctp_assoc_value);
1686 case SCTP_CMT_ON_OFF:
1688 struct sctp_assoc_value *av;
1690 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1691 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1693 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1694 SCTP_TCB_UNLOCK(stcb);
1696 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1697 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1698 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1699 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1700 SCTP_INP_RLOCK(inp);
1701 av->assoc_value = inp->sctp_cmt_on_off;
1702 SCTP_INP_RUNLOCK(inp);
1704 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1709 *optsize = sizeof(struct sctp_assoc_value);
1713 case SCTP_PLUGGABLE_CC:
1715 struct sctp_assoc_value *av;
1717 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1718 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1720 av->assoc_value = stcb->asoc.congestion_control_module;
1721 SCTP_TCB_UNLOCK(stcb);
1723 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1724 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1725 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1726 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1727 SCTP_INP_RLOCK(inp);
1728 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1729 SCTP_INP_RUNLOCK(inp);
1731 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1736 *optsize = sizeof(struct sctp_assoc_value);
1740 case SCTP_CC_OPTION:
1742 struct sctp_cc_option *cc_opt;
1744 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1745 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1749 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1752 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1753 *optsize = sizeof(struct sctp_cc_option);
1755 SCTP_TCB_UNLOCK(stcb);
1759 case SCTP_PLUGGABLE_SS:
1761 struct sctp_assoc_value *av;
1763 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1764 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1766 av->assoc_value = stcb->asoc.stream_scheduling_module;
1767 SCTP_TCB_UNLOCK(stcb);
1769 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1770 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1771 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1772 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1773 SCTP_INP_RLOCK(inp);
1774 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1775 SCTP_INP_RUNLOCK(inp);
1777 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1782 *optsize = sizeof(struct sctp_assoc_value);
1788 struct sctp_stream_value *av;
1790 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1791 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1793 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1794 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1795 &av->stream_value) < 0)) {
1796 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1799 *optsize = sizeof(struct sctp_stream_value);
1801 SCTP_TCB_UNLOCK(stcb);
1804 * Can't get stream value without
1807 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1812 case SCTP_GET_ADDR_LEN:
1814 struct sctp_assoc_value *av;
1816 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1819 if (av->assoc_value == AF_INET) {
1820 av->assoc_value = sizeof(struct sockaddr_in);
1825 if (av->assoc_value == AF_INET6) {
1826 av->assoc_value = sizeof(struct sockaddr_in6);
1831 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1833 *optsize = sizeof(struct sctp_assoc_value);
1837 case SCTP_GET_ASSOC_NUMBER:
1839 uint32_t *value, cnt;
1841 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1842 SCTP_INP_RLOCK(inp);
1843 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1844 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1845 /* Can't do this for a 1-1 socket */
1847 SCTP_INP_RUNLOCK(inp);
1851 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1854 SCTP_INP_RUNLOCK(inp);
1856 *optsize = sizeof(uint32_t);
1859 case SCTP_GET_ASSOC_ID_LIST:
1861 struct sctp_assoc_ids *ids;
1865 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1866 SCTP_INP_RLOCK(inp);
1867 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1868 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1869 /* Can't do this for a 1-1 socket */
1871 SCTP_INP_RUNLOCK(inp);
1875 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1876 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1878 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1886 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1890 SCTP_INP_RUNLOCK(inp);
1892 ids->gaids_number_of_ids = at;
1893 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1899 struct sctp_assoc_value *av;
1901 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1902 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1905 av->assoc_value = stcb->asoc.context;
1906 SCTP_TCB_UNLOCK(stcb);
1908 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1909 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1910 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1911 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1912 SCTP_INP_RLOCK(inp);
1913 av->assoc_value = inp->sctp_context;
1914 SCTP_INP_RUNLOCK(inp);
1916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1921 *optsize = sizeof(struct sctp_assoc_value);
1927 uint32_t *default_vrfid;
1929 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1930 *default_vrfid = inp->def_vrf_id;
1931 *optsize = sizeof(uint32_t);
1934 case SCTP_GET_ASOC_VRF:
1936 struct sctp_assoc_value *id;
1938 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1939 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1942 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1944 id->assoc_value = stcb->asoc.vrf_id;
1945 SCTP_TCB_UNLOCK(stcb);
1946 *optsize = sizeof(struct sctp_assoc_value);
1950 case SCTP_GET_VRF_IDS:
1952 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1956 case SCTP_GET_NONCE_VALUES:
1958 struct sctp_get_nonce_values *gnv;
1960 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1961 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1964 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1965 gnv->gn_local_tag = stcb->asoc.my_vtag;
1966 SCTP_TCB_UNLOCK(stcb);
1967 *optsize = sizeof(struct sctp_get_nonce_values);
1969 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1974 case SCTP_DELAYED_SACK:
1976 struct sctp_sack_info *sack;
1978 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1979 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1981 sack->sack_delay = stcb->asoc.delayed_ack;
1982 sack->sack_freq = stcb->asoc.sack_freq;
1983 SCTP_TCB_UNLOCK(stcb);
1985 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1986 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1987 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1988 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC))) {
1989 SCTP_INP_RLOCK(inp);
1990 sack->sack_delay = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1991 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
1992 SCTP_INP_RUNLOCK(inp);
1994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1999 *optsize = sizeof(struct sctp_sack_info);
2003 case SCTP_GET_SNDBUF_USE:
2005 struct sctp_sockstat *ss;
2007 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2008 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2011 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2012 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2013 stcb->asoc.size_on_all_streams);
2014 SCTP_TCB_UNLOCK(stcb);
2015 *optsize = sizeof(struct sctp_sockstat);
2017 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2022 case SCTP_MAX_BURST:
2024 struct sctp_assoc_value *av;
2026 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2027 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2030 av->assoc_value = stcb->asoc.max_burst;
2031 SCTP_TCB_UNLOCK(stcb);
2033 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2034 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2035 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2036 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2037 SCTP_INP_RLOCK(inp);
2038 av->assoc_value = inp->sctp_ep.max_burst;
2039 SCTP_INP_RUNLOCK(inp);
2041 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2046 *optsize = sizeof(struct sctp_assoc_value);
2052 struct sctp_assoc_value *av;
2054 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2055 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2058 av->assoc_value = stcb->asoc.sctp_frag_point;
2059 SCTP_TCB_UNLOCK(stcb);
2061 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2062 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2063 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2064 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2065 SCTP_INP_RLOCK(inp);
2066 av->assoc_value = inp->sctp_frag_point;
2067 SCTP_INP_RUNLOCK(inp);
2069 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2074 *optsize = sizeof(struct sctp_assoc_value);
2078 case SCTP_GET_STAT_LOG:
2079 error = sctp_fill_stat_log(optval, optsize);
2083 struct sctp_event_subscribe *events;
2085 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2086 memset(events, 0, sizeof(struct sctp_event_subscribe));
2087 SCTP_INP_RLOCK(inp);
2088 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2089 events->sctp_data_io_event = 1;
2091 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2092 events->sctp_association_event = 1;
2094 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2095 events->sctp_address_event = 1;
2097 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2098 events->sctp_send_failure_event = 1;
2100 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2101 events->sctp_peer_error_event = 1;
2103 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2104 events->sctp_shutdown_event = 1;
2106 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2107 events->sctp_partial_delivery_event = 1;
2109 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2110 events->sctp_adaptation_layer_event = 1;
2112 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2113 events->sctp_authentication_event = 1;
2115 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2116 events->sctp_sender_dry_event = 1;
2118 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2119 events->sctp_stream_reset_event = 1;
2120 SCTP_INP_RUNLOCK(inp);
2121 *optsize = sizeof(struct sctp_event_subscribe);
2124 case SCTP_ADAPTATION_LAYER:
2128 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2130 SCTP_INP_RLOCK(inp);
2131 *value = inp->sctp_ep.adaptation_layer_indicator;
2132 SCTP_INP_RUNLOCK(inp);
2133 *optsize = sizeof(uint32_t);
2136 case SCTP_SET_INITIAL_DBG_SEQ:
2140 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2141 SCTP_INP_RLOCK(inp);
2142 *value = inp->sctp_ep.initial_sequence_debug;
2143 SCTP_INP_RUNLOCK(inp);
2144 *optsize = sizeof(uint32_t);
2147 case SCTP_GET_LOCAL_ADDR_SIZE:
2151 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2152 SCTP_INP_RLOCK(inp);
2153 *value = (uint32_t)sctp_max_size_addresses(inp);
2154 SCTP_INP_RUNLOCK(inp);
2155 *optsize = sizeof(uint32_t);
2158 case SCTP_GET_REMOTE_ADDR_SIZE:
2161 struct sctp_nets *net;
2164 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2165 /* FIXME MT: change to sctp_assoc_value? */
2166 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2170 /* Count the sizes */
2171 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2172 switch (net->ro._l_addr.sa.sa_family) {
2176 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2177 size += sizeof(struct sockaddr_in6);
2179 size += sizeof(struct sockaddr_in);
2182 size += sizeof(struct sockaddr_in);
2188 size += sizeof(struct sockaddr_in6);
2195 SCTP_TCB_UNLOCK(stcb);
2196 *value = (uint32_t)size;
2197 *optsize = sizeof(uint32_t);
2199 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2200 ((sctp_assoc_t)*value <= SCTP_ALL_ASSOC)) {
2205 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2209 case SCTP_GET_PEER_ADDRESSES:
2211 * Get the address information, an array is passed in to
2212 * fill up we pack it.
2216 struct sockaddr *addr;
2217 struct sctp_nets *net;
2218 struct sctp_getaddresses *saddr;
2220 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2221 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2224 left = *optsize - offsetof(struct sctp_getaddresses, addr);
2225 *optsize = offsetof(struct sctp_getaddresses, addr);
2226 addr = &saddr->addr[0].sa;
2228 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2229 switch (net->ro._l_addr.sa.sa_family) {
2233 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2234 cpsz = sizeof(struct sockaddr_in6);
2236 cpsz = sizeof(struct sockaddr_in);
2239 cpsz = sizeof(struct sockaddr_in);
2245 cpsz = sizeof(struct sockaddr_in6);
2256 /* not enough room. */
2259 #if defined(INET) && defined(INET6)
2260 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2261 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2262 /* Must map the address */
2263 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2264 (struct sockaddr_in6 *)addr);
2266 memcpy(addr, &net->ro._l_addr, cpsz);
2269 memcpy(addr, &net->ro._l_addr, cpsz);
2271 ((struct sockaddr_in *)addr)->sin_port = stcb->rport;
2273 addr = (struct sockaddr *)((caddr_t)addr + cpsz);
2277 SCTP_TCB_UNLOCK(stcb);
2279 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2280 (saddr->sget_assoc_id <= SCTP_ALL_ASSOC)) {
2285 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2289 case SCTP_GET_LOCAL_ADDRESSES:
2291 size_t limit, actual;
2292 struct sctp_getaddresses *saddr;
2294 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2295 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2297 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2298 ((saddr->sget_assoc_id == SCTP_CURRENT_ASSOC) ||
2299 (saddr->sget_assoc_id == SCTP_ALL_ASSOC))) {
2302 limit = *optsize - offsetof(struct sctp_getaddresses, addr);
2303 actual = sctp_fill_up_addresses(inp, stcb, limit, &saddr->addr[0].sa);
2304 *optsize = offsetof(struct sctp_getaddresses, addr) + actual;
2307 SCTP_TCB_UNLOCK(stcb);
2311 case SCTP_PEER_ADDR_PARAMS:
2313 struct sctp_paddrparams *paddrp;
2314 struct sctp_nets *net;
2315 struct sockaddr *addr;
2316 #if defined(INET) && defined(INET6)
2317 struct sockaddr_in sin_store;
2320 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2321 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2323 #if defined(INET) && defined(INET6)
2324 if (paddrp->spp_address.ss_family == AF_INET6) {
2325 struct sockaddr_in6 *sin6;
2327 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2328 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2329 in6_sin6_2_sin(&sin_store, sin6);
2330 addr = (struct sockaddr *)&sin_store;
2332 addr = (struct sockaddr *)&paddrp->spp_address;
2335 addr = (struct sockaddr *)&paddrp->spp_address;
2338 addr = (struct sockaddr *)&paddrp->spp_address;
2341 net = sctp_findnet(stcb, addr);
2344 * We increment here since
2345 * sctp_findassociation_ep_addr() wil do a
2346 * decrement if it finds the stcb as long as
2347 * the locked tcb (last argument) is NOT a
2351 SCTP_INP_INCR_REF(inp);
2352 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2354 SCTP_INP_DECR_REF(inp);
2357 if ((stcb != NULL) && (net == NULL)) {
2359 if (addr->sa_family == AF_INET) {
2360 struct sockaddr_in *sin;
2362 sin = (struct sockaddr_in *)addr;
2363 if (sin->sin_addr.s_addr != INADDR_ANY) {
2365 SCTP_TCB_UNLOCK(stcb);
2366 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2372 if (addr->sa_family == AF_INET6) {
2373 struct sockaddr_in6 *sin6;
2375 sin6 = (struct sockaddr_in6 *)addr;
2376 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2378 SCTP_TCB_UNLOCK(stcb);
2379 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2385 error = EAFNOSUPPORT;
2386 SCTP_TCB_UNLOCK(stcb);
2387 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2393 /* Applies to the specific association */
2394 paddrp->spp_flags = 0;
2396 paddrp->spp_hbinterval = net->heart_beat_delay;
2397 paddrp->spp_pathmaxrxt = net->failure_threshold;
2398 paddrp->spp_pathmtu = net->mtu;
2399 switch (net->ro._l_addr.sa.sa_family) {
2402 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2407 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2413 /* get flags for HB */
2414 if (net->dest_state & SCTP_ADDR_NOHB) {
2415 paddrp->spp_flags |= SPP_HB_DISABLE;
2417 paddrp->spp_flags |= SPP_HB_ENABLE;
2419 /* get flags for PMTU */
2420 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2421 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2423 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2425 if (net->dscp & 0x01) {
2426 paddrp->spp_dscp = net->dscp & 0xfc;
2427 paddrp->spp_flags |= SPP_DSCP;
2430 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2431 (net->flowlabel & 0x80000000)) {
2432 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2433 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2438 * No destination so return default
2441 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2442 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2443 if (stcb->asoc.default_dscp & 0x01) {
2444 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2445 paddrp->spp_flags |= SPP_DSCP;
2448 if (stcb->asoc.default_flowlabel & 0x80000000) {
2449 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2450 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2453 /* default settings should be these */
2454 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2455 paddrp->spp_flags |= SPP_HB_DISABLE;
2457 paddrp->spp_flags |= SPP_HB_ENABLE;
2459 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2460 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2462 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2464 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2466 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2467 SCTP_TCB_UNLOCK(stcb);
2469 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2470 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2471 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2472 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
2473 /* Use endpoint defaults */
2474 SCTP_INP_RLOCK(inp);
2475 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2476 paddrp->spp_hbinterval = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2477 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2478 /* get inp's default */
2479 if (inp->sctp_ep.default_dscp & 0x01) {
2480 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2481 paddrp->spp_flags |= SPP_DSCP;
2484 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2485 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2486 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2487 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2490 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2492 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2493 paddrp->spp_flags |= SPP_HB_ENABLE;
2495 paddrp->spp_flags |= SPP_HB_DISABLE;
2497 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2498 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2500 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2502 SCTP_INP_RUNLOCK(inp);
2504 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2509 *optsize = sizeof(struct sctp_paddrparams);
2513 case SCTP_GET_PEER_ADDR_INFO:
2515 struct sctp_paddrinfo *paddri;
2516 struct sctp_nets *net;
2517 struct sockaddr *addr;
2518 #if defined(INET) && defined(INET6)
2519 struct sockaddr_in sin_store;
2522 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2523 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2525 #if defined(INET) && defined(INET6)
2526 if (paddri->spinfo_address.ss_family == AF_INET6) {
2527 struct sockaddr_in6 *sin6;
2529 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2530 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2531 in6_sin6_2_sin(&sin_store, sin6);
2532 addr = (struct sockaddr *)&sin_store;
2534 addr = (struct sockaddr *)&paddri->spinfo_address;
2537 addr = (struct sockaddr *)&paddri->spinfo_address;
2540 addr = (struct sockaddr *)&paddri->spinfo_address;
2543 net = sctp_findnet(stcb, addr);
2546 * We increment here since
2547 * sctp_findassociation_ep_addr() wil do a
2548 * decrement if it finds the stcb as long as
2549 * the locked tcb (last argument) is NOT a
2553 SCTP_INP_INCR_REF(inp);
2554 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2556 SCTP_INP_DECR_REF(inp);
2560 if ((stcb != NULL) && (net != NULL)) {
2561 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2562 /* It's unconfirmed */
2563 paddri->spinfo_state = SCTP_UNCONFIRMED;
2564 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2566 paddri->spinfo_state = SCTP_ACTIVE;
2569 paddri->spinfo_state = SCTP_INACTIVE;
2571 paddri->spinfo_cwnd = net->cwnd;
2572 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2573 paddri->spinfo_rto = net->RTO;
2574 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2575 paddri->spinfo_mtu = net->mtu;
2576 switch (addr->sa_family) {
2579 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2584 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2590 SCTP_TCB_UNLOCK(stcb);
2591 *optsize = sizeof(struct sctp_paddrinfo);
2594 SCTP_TCB_UNLOCK(stcb);
2596 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2601 case SCTP_PCB_STATUS:
2603 struct sctp_pcbinfo *spcb;
2605 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2606 sctp_fill_pcbinfo(spcb);
2607 *optsize = sizeof(struct sctp_pcbinfo);
2612 struct sctp_nets *net;
2613 struct sctp_status *sstat;
2615 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2616 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2619 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2623 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2624 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2625 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2626 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2628 * We can't include chunks that have been passed to
2629 * the socket layer. Only things in queue.
2631 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2632 stcb->asoc.cnt_on_all_streams);
2633 sstat->sstat_instrms = stcb->asoc.streamincnt;
2634 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2635 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb);
2636 net = stcb->asoc.primary_destination;
2638 memcpy(&sstat->sstat_primary.spinfo_address,
2640 ((struct sockaddr *)(&net->ro._l_addr))->sa_len);
2641 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2643 * Again the user can get info from
2644 * sctp_constants.h for what the state of
2647 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2648 /* It's unconfirmed */
2649 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2650 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2652 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2655 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2657 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2658 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2659 sstat->sstat_primary.spinfo_rto = net->RTO;
2660 sstat->sstat_primary.spinfo_mtu = net->mtu;
2661 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2664 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2669 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2676 memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo));
2678 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2679 SCTP_TCB_UNLOCK(stcb);
2680 *optsize = sizeof(struct sctp_status);
2685 struct sctp_rtoinfo *srto;
2687 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2688 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2691 srto->srto_initial = stcb->asoc.initial_rto;
2692 srto->srto_max = stcb->asoc.maxrto;
2693 srto->srto_min = stcb->asoc.minrto;
2694 SCTP_TCB_UNLOCK(stcb);
2696 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2697 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2698 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2699 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
2700 SCTP_INP_RLOCK(inp);
2701 srto->srto_initial = inp->sctp_ep.initial_rto;
2702 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2703 srto->srto_min = inp->sctp_ep.sctp_minrto;
2704 SCTP_INP_RUNLOCK(inp);
2706 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2711 *optsize = sizeof(struct sctp_rtoinfo);
2717 struct sctp_timeouts *stimo;
2719 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2720 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2723 stimo->stimo_init = stcb->asoc.timoinit;
2724 stimo->stimo_data = stcb->asoc.timodata;
2725 stimo->stimo_sack = stcb->asoc.timosack;
2726 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2727 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2728 stimo->stimo_cookie = stcb->asoc.timocookie;
2729 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2730 SCTP_TCB_UNLOCK(stcb);
2731 *optsize = sizeof(struct sctp_timeouts);
2733 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2738 case SCTP_ASSOCINFO:
2740 struct sctp_assocparams *sasoc;
2742 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2743 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2746 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(stcb->asoc.cookie_life);
2747 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2748 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2749 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2750 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2751 SCTP_TCB_UNLOCK(stcb);
2753 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2754 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2755 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2756 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
2757 SCTP_INP_RLOCK(inp);
2758 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(inp->sctp_ep.def_cookie_life);
2759 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2760 sasoc->sasoc_number_peer_destinations = 0;
2761 sasoc->sasoc_peer_rwnd = 0;
2762 sasoc->sasoc_local_rwnd = (uint32_t)sbspace(&inp->sctp_socket->so_rcv);
2763 SCTP_INP_RUNLOCK(inp);
2765 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2770 *optsize = sizeof(struct sctp_assocparams);
2774 case SCTP_DEFAULT_SEND_PARAM:
2776 struct sctp_sndrcvinfo *s_info;
2778 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2779 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2782 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2783 SCTP_TCB_UNLOCK(stcb);
2785 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2786 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2787 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2788 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC))) {
2789 SCTP_INP_RLOCK(inp);
2790 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2791 SCTP_INP_RUNLOCK(inp);
2793 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2798 *optsize = sizeof(struct sctp_sndrcvinfo);
2804 struct sctp_initmsg *sinit;
2806 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2807 SCTP_INP_RLOCK(inp);
2808 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2809 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2810 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2811 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2812 SCTP_INP_RUNLOCK(inp);
2813 *optsize = sizeof(struct sctp_initmsg);
2816 case SCTP_PRIMARY_ADDR:
2817 /* we allow a "get" operation on this */
2819 struct sctp_setprim *ssp;
2821 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2822 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2825 union sctp_sockstore *addr;
2827 addr = &stcb->asoc.primary_destination->ro._l_addr;
2828 switch (addr->sa.sa_family) {
2832 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2833 in6_sin_2_v4mapsin6(&addr->sin,
2834 (struct sockaddr_in6 *)&ssp->ssp_addr);
2836 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2839 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2845 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2851 SCTP_TCB_UNLOCK(stcb);
2852 *optsize = sizeof(struct sctp_setprim);
2854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2859 case SCTP_HMAC_IDENT:
2861 struct sctp_hmacalgo *shmac;
2862 sctp_hmaclist_t *hmaclist;
2866 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2868 SCTP_INP_RLOCK(inp);
2869 hmaclist = inp->sctp_ep.local_hmacs;
2870 if (hmaclist == NULL) {
2871 /* no HMACs to return */
2872 *optsize = sizeof(*shmac);
2873 SCTP_INP_RUNLOCK(inp);
2876 /* is there room for all of the hmac ids? */
2877 size = sizeof(*shmac) + (hmaclist->num_algo *
2878 sizeof(shmac->shmac_idents[0]));
2879 if (*optsize < size) {
2880 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2882 SCTP_INP_RUNLOCK(inp);
2885 /* copy in the list */
2886 shmac->shmac_number_of_idents = hmaclist->num_algo;
2887 for (i = 0; i < hmaclist->num_algo; i++) {
2888 shmac->shmac_idents[i] = hmaclist->hmac[i];
2890 SCTP_INP_RUNLOCK(inp);
2894 case SCTP_AUTH_ACTIVE_KEY:
2896 struct sctp_authkeyid *scact;
2898 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2899 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2902 /* get the active key on the assoc */
2903 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2904 SCTP_TCB_UNLOCK(stcb);
2906 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2907 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2908 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2909 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC))) {
2910 /* get the endpoint active key */
2911 SCTP_INP_RLOCK(inp);
2912 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2913 SCTP_INP_RUNLOCK(inp);
2915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2920 *optsize = sizeof(struct sctp_authkeyid);
2924 case SCTP_LOCAL_AUTH_CHUNKS:
2926 struct sctp_authchunks *sac;
2927 sctp_auth_chklist_t *chklist = NULL;
2930 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2931 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2934 /* get off the assoc */
2935 chklist = stcb->asoc.local_auth_chunks;
2936 /* is there enough space? */
2937 size = sctp_auth_get_chklist_size(chklist);
2938 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2940 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2942 /* copy in the chunks */
2943 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2944 sac->gauth_number_of_chunks = (uint32_t)size;
2945 *optsize = sizeof(struct sctp_authchunks) + size;
2947 SCTP_TCB_UNLOCK(stcb);
2949 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2950 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2951 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2952 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC))) {
2953 /* get off the endpoint */
2954 SCTP_INP_RLOCK(inp);
2955 chklist = inp->sctp_ep.local_auth_chunks;
2956 /* is there enough space? */
2957 size = sctp_auth_get_chklist_size(chklist);
2958 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2960 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2962 /* copy in the chunks */
2963 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2964 sac->gauth_number_of_chunks = (uint32_t)size;
2965 *optsize = sizeof(struct sctp_authchunks) + size;
2967 SCTP_INP_RUNLOCK(inp);
2969 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2975 case SCTP_PEER_AUTH_CHUNKS:
2977 struct sctp_authchunks *sac;
2978 sctp_auth_chklist_t *chklist = NULL;
2981 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2982 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2985 /* get off the assoc */
2986 chklist = stcb->asoc.peer_auth_chunks;
2987 /* is there enough space? */
2988 size = sctp_auth_get_chklist_size(chklist);
2989 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2991 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2993 /* copy in the chunks */
2994 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2995 sac->gauth_number_of_chunks = (uint32_t)size;
2996 *optsize = sizeof(struct sctp_authchunks) + size;
2998 SCTP_TCB_UNLOCK(stcb);
3000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3007 struct sctp_event *event;
3008 uint32_t event_type;
3010 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3011 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3013 switch (event->se_type) {
3014 case SCTP_ASSOC_CHANGE:
3015 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3017 case SCTP_PEER_ADDR_CHANGE:
3018 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3020 case SCTP_REMOTE_ERROR:
3021 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3023 case SCTP_SEND_FAILED:
3024 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3026 case SCTP_SHUTDOWN_EVENT:
3027 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3029 case SCTP_ADAPTATION_INDICATION:
3030 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3032 case SCTP_PARTIAL_DELIVERY_EVENT:
3033 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3035 case SCTP_AUTHENTICATION_EVENT:
3036 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3038 case SCTP_STREAM_RESET_EVENT:
3039 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3041 case SCTP_SENDER_DRY_EVENT:
3042 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3044 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3046 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3049 case SCTP_ASSOC_RESET_EVENT:
3050 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3052 case SCTP_STREAM_CHANGE_EVENT:
3053 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3055 case SCTP_SEND_FAILED_EVENT:
3056 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3060 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3064 if (event_type > 0) {
3066 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3068 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3069 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3070 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3071 (event->se_assoc_id == SCTP_FUTURE_ASSOC))) {
3072 SCTP_INP_RLOCK(inp);
3073 event->se_on = sctp_is_feature_on(inp, event_type);
3074 SCTP_INP_RUNLOCK(inp);
3076 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3082 SCTP_TCB_UNLOCK(stcb);
3085 *optsize = sizeof(struct sctp_event);
3089 case SCTP_RECVRCVINFO:
3090 if (*optsize < sizeof(int)) {
3091 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3094 SCTP_INP_RLOCK(inp);
3095 *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3096 SCTP_INP_RUNLOCK(inp);
3097 *optsize = sizeof(int);
3100 case SCTP_RECVNXTINFO:
3101 if (*optsize < sizeof(int)) {
3102 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3105 SCTP_INP_RLOCK(inp);
3106 *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3107 SCTP_INP_RUNLOCK(inp);
3108 *optsize = sizeof(int);
3111 case SCTP_DEFAULT_SNDINFO:
3113 struct sctp_sndinfo *info;
3115 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3116 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3119 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3120 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3121 info->snd_flags &= 0xfff0;
3122 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3123 info->snd_context = stcb->asoc.def_send.sinfo_context;
3124 SCTP_TCB_UNLOCK(stcb);
3126 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3127 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3128 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3129 (info->snd_assoc_id == SCTP_FUTURE_ASSOC))) {
3130 SCTP_INP_RLOCK(inp);
3131 info->snd_sid = inp->def_send.sinfo_stream;
3132 info->snd_flags = inp->def_send.sinfo_flags;
3133 info->snd_flags &= 0xfff0;
3134 info->snd_ppid = inp->def_send.sinfo_ppid;
3135 info->snd_context = inp->def_send.sinfo_context;
3136 SCTP_INP_RUNLOCK(inp);
3138 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3143 *optsize = sizeof(struct sctp_sndinfo);
3147 case SCTP_DEFAULT_PRINFO:
3149 struct sctp_default_prinfo *info;
3151 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3152 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3155 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3156 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3157 SCTP_TCB_UNLOCK(stcb);
3159 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3160 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3161 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3162 (info->pr_assoc_id == SCTP_FUTURE_ASSOC))) {
3163 SCTP_INP_RLOCK(inp);
3164 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3165 info->pr_value = inp->def_send.sinfo_timetolive;
3166 SCTP_INP_RUNLOCK(inp);
3168 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3173 *optsize = sizeof(struct sctp_default_prinfo);
3177 case SCTP_PEER_ADDR_THLDS:
3179 struct sctp_paddrthlds *thlds;
3180 struct sctp_nets *net;
3181 struct sockaddr *addr;
3182 #if defined(INET) && defined(INET6)
3183 struct sockaddr_in sin_store;
3186 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3187 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3189 #if defined(INET) && defined(INET6)
3190 if (thlds->spt_address.ss_family == AF_INET6) {
3191 struct sockaddr_in6 *sin6;
3193 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3194 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3195 in6_sin6_2_sin(&sin_store, sin6);
3196 addr = (struct sockaddr *)&sin_store;
3198 addr = (struct sockaddr *)&thlds->spt_address;
3201 addr = (struct sockaddr *)&thlds->spt_address;
3204 addr = (struct sockaddr *)&thlds->spt_address;
3207 net = sctp_findnet(stcb, addr);
3210 * We increment here since
3211 * sctp_findassociation_ep_addr() wil do a
3212 * decrement if it finds the stcb as long as
3213 * the locked tcb (last argument) is NOT a
3217 SCTP_INP_INCR_REF(inp);
3218 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3220 SCTP_INP_DECR_REF(inp);
3223 if ((stcb != NULL) && (net == NULL)) {
3225 if (addr->sa_family == AF_INET) {
3226 struct sockaddr_in *sin;
3228 sin = (struct sockaddr_in *)addr;
3229 if (sin->sin_addr.s_addr != INADDR_ANY) {
3231 SCTP_TCB_UNLOCK(stcb);
3232 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3238 if (addr->sa_family == AF_INET6) {
3239 struct sockaddr_in6 *sin6;
3241 sin6 = (struct sockaddr_in6 *)addr;
3242 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3244 SCTP_TCB_UNLOCK(stcb);
3245 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3251 error = EAFNOSUPPORT;
3252 SCTP_TCB_UNLOCK(stcb);
3253 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3260 thlds->spt_pathmaxrxt = net->failure_threshold;
3261 thlds->spt_pathpfthld = net->pf_threshold;
3262 thlds->spt_pathcpthld = 0xffff;
3264 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3265 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3266 thlds->spt_pathcpthld = 0xffff;
3268 thlds->spt_assoc_id = sctp_get_associd(stcb);
3269 SCTP_TCB_UNLOCK(stcb);
3271 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3272 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3273 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3274 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
3275 /* Use endpoint defaults */
3276 SCTP_INP_RLOCK(inp);
3277 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3278 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3279 thlds->spt_pathcpthld = 0xffff;
3280 SCTP_INP_RUNLOCK(inp);
3282 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3287 *optsize = sizeof(struct sctp_paddrthlds);
3291 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3293 struct sctp_udpencaps *encaps;
3294 struct sctp_nets *net;
3295 struct sockaddr *addr;
3296 #if defined(INET) && defined(INET6)
3297 struct sockaddr_in sin_store;
3300 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3301 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3303 #if defined(INET) && defined(INET6)
3304 if (encaps->sue_address.ss_family == AF_INET6) {
3305 struct sockaddr_in6 *sin6;
3307 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3308 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3309 in6_sin6_2_sin(&sin_store, sin6);
3310 addr = (struct sockaddr *)&sin_store;
3312 addr = (struct sockaddr *)&encaps->sue_address;
3315 addr = (struct sockaddr *)&encaps->sue_address;
3318 addr = (struct sockaddr *)&encaps->sue_address;
3321 net = sctp_findnet(stcb, addr);
3324 * We increment here since
3325 * sctp_findassociation_ep_addr() wil do a
3326 * decrement if it finds the stcb as long as
3327 * the locked tcb (last argument) is NOT a
3331 SCTP_INP_INCR_REF(inp);
3332 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3334 SCTP_INP_DECR_REF(inp);
3337 if ((stcb != NULL) && (net == NULL)) {
3339 if (addr->sa_family == AF_INET) {
3340 struct sockaddr_in *sin;
3342 sin = (struct sockaddr_in *)addr;
3343 if (sin->sin_addr.s_addr != INADDR_ANY) {
3345 SCTP_TCB_UNLOCK(stcb);
3346 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3352 if (addr->sa_family == AF_INET6) {
3353 struct sockaddr_in6 *sin6;
3355 sin6 = (struct sockaddr_in6 *)addr;
3356 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3358 SCTP_TCB_UNLOCK(stcb);
3359 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3365 error = EAFNOSUPPORT;
3366 SCTP_TCB_UNLOCK(stcb);
3367 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3374 encaps->sue_port = net->port;
3376 encaps->sue_port = stcb->asoc.port;
3378 SCTP_TCB_UNLOCK(stcb);
3380 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3381 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3382 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3383 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
3384 SCTP_INP_RLOCK(inp);
3385 encaps->sue_port = inp->sctp_ep.port;
3386 SCTP_INP_RUNLOCK(inp);
3388 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3393 *optsize = sizeof(struct sctp_udpencaps);
3397 case SCTP_ECN_SUPPORTED:
3399 struct sctp_assoc_value *av;
3401 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3402 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3405 av->assoc_value = stcb->asoc.ecn_supported;
3406 SCTP_TCB_UNLOCK(stcb);
3408 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3409 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3410 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3411 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3412 SCTP_INP_RLOCK(inp);
3413 av->assoc_value = inp->ecn_supported;
3414 SCTP_INP_RUNLOCK(inp);
3416 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3421 *optsize = sizeof(struct sctp_assoc_value);
3425 case SCTP_PR_SUPPORTED:
3427 struct sctp_assoc_value *av;
3429 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3430 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3433 av->assoc_value = stcb->asoc.prsctp_supported;
3434 SCTP_TCB_UNLOCK(stcb);
3436 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3437 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3438 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3439 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3440 SCTP_INP_RLOCK(inp);
3441 av->assoc_value = inp->prsctp_supported;
3442 SCTP_INP_RUNLOCK(inp);
3444 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3449 *optsize = sizeof(struct sctp_assoc_value);
3453 case SCTP_AUTH_SUPPORTED:
3455 struct sctp_assoc_value *av;
3457 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3458 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3461 av->assoc_value = stcb->asoc.auth_supported;
3462 SCTP_TCB_UNLOCK(stcb);
3464 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3465 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3466 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3467 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3468 SCTP_INP_RLOCK(inp);
3469 av->assoc_value = inp->auth_supported;
3470 SCTP_INP_RUNLOCK(inp);
3472 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3477 *optsize = sizeof(struct sctp_assoc_value);
3481 case SCTP_ASCONF_SUPPORTED:
3483 struct sctp_assoc_value *av;
3485 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3486 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3489 av->assoc_value = stcb->asoc.asconf_supported;
3490 SCTP_TCB_UNLOCK(stcb);
3492 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3493 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3494 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3495 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3496 SCTP_INP_RLOCK(inp);
3497 av->assoc_value = inp->asconf_supported;
3498 SCTP_INP_RUNLOCK(inp);
3500 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3505 *optsize = sizeof(struct sctp_assoc_value);
3509 case SCTP_RECONFIG_SUPPORTED:
3511 struct sctp_assoc_value *av;
3513 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3514 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3517 av->assoc_value = stcb->asoc.reconfig_supported;
3518 SCTP_TCB_UNLOCK(stcb);
3520 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3521 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3522 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3523 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3524 SCTP_INP_RLOCK(inp);
3525 av->assoc_value = inp->reconfig_supported;
3526 SCTP_INP_RUNLOCK(inp);
3528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3533 *optsize = sizeof(struct sctp_assoc_value);
3537 case SCTP_NRSACK_SUPPORTED:
3539 struct sctp_assoc_value *av;
3541 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3542 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3545 av->assoc_value = stcb->asoc.nrsack_supported;
3546 SCTP_TCB_UNLOCK(stcb);
3548 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3549 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3550 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3551 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3552 SCTP_INP_RLOCK(inp);
3553 av->assoc_value = inp->nrsack_supported;
3554 SCTP_INP_RUNLOCK(inp);
3556 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3561 *optsize = sizeof(struct sctp_assoc_value);
3565 case SCTP_PKTDROP_SUPPORTED:
3567 struct sctp_assoc_value *av;
3569 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3570 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3573 av->assoc_value = stcb->asoc.pktdrop_supported;
3574 SCTP_TCB_UNLOCK(stcb);
3576 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3577 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3578 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3579 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3580 SCTP_INP_RLOCK(inp);
3581 av->assoc_value = inp->pktdrop_supported;
3582 SCTP_INP_RUNLOCK(inp);
3584 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3589 *optsize = sizeof(struct sctp_assoc_value);
3593 case SCTP_ENABLE_STREAM_RESET:
3595 struct sctp_assoc_value *av;
3597 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3598 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3601 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3602 SCTP_TCB_UNLOCK(stcb);
3604 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3605 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3606 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3607 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3608 SCTP_INP_RLOCK(inp);
3609 av->assoc_value = (uint32_t)inp->local_strreset_support;
3610 SCTP_INP_RUNLOCK(inp);
3612 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3617 *optsize = sizeof(struct sctp_assoc_value);
3621 case SCTP_PR_STREAM_STATUS:
3623 struct sctp_prstatus *sprstat;
3627 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3628 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3630 sid = sprstat->sprstat_sid;
3631 policy = sprstat->sprstat_policy;
3632 #if defined(SCTP_DETAILED_STR_STATS)
3633 if ((stcb != NULL) &&
3634 (sid < stcb->asoc.streamoutcnt) &&
3635 (policy != SCTP_PR_SCTP_NONE) &&
3636 ((policy <= SCTP_PR_SCTP_MAX) ||
3637 (policy == SCTP_PR_SCTP_ALL))) {
3638 if (policy == SCTP_PR_SCTP_ALL) {
3639 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3640 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3642 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3643 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3646 if ((stcb != NULL) &&
3647 (sid < stcb->asoc.streamoutcnt) &&
3648 (policy == SCTP_PR_SCTP_ALL)) {
3649 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3650 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3653 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3657 SCTP_TCB_UNLOCK(stcb);
3660 *optsize = sizeof(struct sctp_prstatus);
3664 case SCTP_PR_ASSOC_STATUS:
3666 struct sctp_prstatus *sprstat;
3669 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3670 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3672 policy = sprstat->sprstat_policy;
3673 if ((stcb != NULL) &&
3674 (policy != SCTP_PR_SCTP_NONE) &&
3675 ((policy <= SCTP_PR_SCTP_MAX) ||
3676 (policy == SCTP_PR_SCTP_ALL))) {
3677 if (policy == SCTP_PR_SCTP_ALL) {
3678 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3679 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3681 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3682 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3689 SCTP_TCB_UNLOCK(stcb);
3692 *optsize = sizeof(struct sctp_prstatus);
3698 struct sctp_assoc_value *av;
3700 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3701 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3704 av->assoc_value = stcb->asoc.max_cwnd;
3705 SCTP_TCB_UNLOCK(stcb);
3707 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3708 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3709 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3710 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3711 SCTP_INP_RLOCK(inp);
3712 av->assoc_value = inp->max_cwnd;
3713 SCTP_INP_RUNLOCK(inp);
3715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3720 *optsize = sizeof(struct sctp_assoc_value);
3725 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3726 error = ENOPROTOOPT;
3728 } /* end switch (sopt->sopt_name) */
3736 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3741 struct sctp_tcb *stcb = NULL;
3742 struct sctp_inpcb *inp = NULL;
3745 if (optval == NULL) {
3746 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3749 inp = (struct sctp_inpcb *)so->so_pcb;
3751 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3754 vrf_id = inp->def_vrf_id;
3759 case SCTP_AUTOCLOSE:
3760 case SCTP_AUTO_ASCONF:
3761 case SCTP_EXPLICIT_EOR:
3762 case SCTP_DISABLE_FRAGMENTS:
3763 case SCTP_USE_EXT_RCVINFO:
3764 case SCTP_I_WANT_MAPPED_V4_ADDR:
3765 /* copy in the option value */
3766 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3771 case SCTP_DISABLE_FRAGMENTS:
3772 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3774 case SCTP_AUTO_ASCONF:
3776 * NOTE: we don't really support this flag
3778 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3779 /* only valid for bound all sockets */
3780 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3782 /* forbidden by admin */
3783 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3786 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3788 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3792 case SCTP_EXPLICIT_EOR:
3793 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3795 case SCTP_USE_EXT_RCVINFO:
3796 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3798 case SCTP_I_WANT_MAPPED_V4_ADDR:
3799 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3800 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3802 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3807 set_opt = SCTP_PCB_FLAGS_NODELAY;
3809 case SCTP_AUTOCLOSE:
3810 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3811 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3812 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3815 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3817 * The value is in ticks. Note this does not effect
3818 * old associations, only new ones.
3820 inp->sctp_ep.auto_close_time = sctp_secs_to_ticks(*mopt);
3823 SCTP_INP_WLOCK(inp);
3825 sctp_feature_on(inp, set_opt);
3827 sctp_feature_off(inp, set_opt);
3829 SCTP_INP_WUNLOCK(inp);
3831 case SCTP_REUSE_PORT:
3833 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3834 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3835 /* Can't set it after we are bound */
3839 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3840 /* Can't do this for a 1-m socket */
3845 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3847 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3850 case SCTP_PARTIAL_DELIVERY_POINT:
3854 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3855 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3856 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3860 inp->partial_delivery_point = *value;
3863 case SCTP_FRAGMENT_INTERLEAVE:
3864 /* not yet until we re-write sctp_recvmsg() */
3868 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3869 if (*level == SCTP_FRAG_LEVEL_2) {
3870 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3871 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3872 } else if (*level == SCTP_FRAG_LEVEL_1) {
3873 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3874 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3875 } else if (*level == SCTP_FRAG_LEVEL_0) {
3876 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3877 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3880 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3885 case SCTP_INTERLEAVING_SUPPORTED:
3887 struct sctp_assoc_value *av;
3889 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3890 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3893 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3895 SCTP_TCB_UNLOCK(stcb);
3897 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3898 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3899 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3900 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3901 SCTP_INP_WLOCK(inp);
3902 if (av->assoc_value == 0) {
3903 inp->idata_supported = 0;
3905 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3906 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3907 inp->idata_supported = 1;
3915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3919 SCTP_INP_WUNLOCK(inp);
3921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3927 case SCTP_CMT_ON_OFF:
3928 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3929 struct sctp_assoc_value *av;
3931 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3932 if (av->assoc_value > SCTP_CMT_MAX) {
3933 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3937 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3939 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3940 SCTP_TCB_UNLOCK(stcb);
3942 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3943 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3944 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3945 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3946 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3947 SCTP_INP_WLOCK(inp);
3948 inp->sctp_cmt_on_off = av->assoc_value;
3949 SCTP_INP_WUNLOCK(inp);
3951 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3952 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3953 (av->assoc_id == SCTP_ALL_ASSOC))) {
3954 SCTP_INP_RLOCK(inp);
3955 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3956 SCTP_TCB_LOCK(stcb);
3957 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3958 SCTP_TCB_UNLOCK(stcb);
3960 SCTP_INP_RUNLOCK(inp);
3964 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3965 error = ENOPROTOOPT;
3968 case SCTP_PLUGGABLE_CC:
3970 struct sctp_assoc_value *av;
3971 struct sctp_nets *net;
3973 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3974 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3975 (av->assoc_value != SCTP_CC_HSTCP) &&
3976 (av->assoc_value != SCTP_CC_HTCP) &&
3977 (av->assoc_value != SCTP_CC_RTCC)) {
3978 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3982 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3984 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3985 stcb->asoc.congestion_control_module = av->assoc_value;
3986 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3987 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3988 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3991 SCTP_TCB_UNLOCK(stcb);
3993 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3994 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3995 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3996 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3997 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3998 SCTP_INP_WLOCK(inp);
3999 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
4000 SCTP_INP_WUNLOCK(inp);
4002 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4003 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4004 (av->assoc_id == SCTP_ALL_ASSOC))) {
4005 SCTP_INP_RLOCK(inp);
4006 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4007 SCTP_TCB_LOCK(stcb);
4008 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4009 stcb->asoc.congestion_control_module = av->assoc_value;
4010 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4011 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4012 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4015 SCTP_TCB_UNLOCK(stcb);
4017 SCTP_INP_RUNLOCK(inp);
4022 case SCTP_CC_OPTION:
4024 struct sctp_cc_option *cc_opt;
4026 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4027 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4029 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4030 (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC)) {
4031 SCTP_INP_RLOCK(inp);
4032 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4033 SCTP_TCB_LOCK(stcb);
4034 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4035 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4037 SCTP_TCB_UNLOCK(stcb);
4039 SCTP_INP_RUNLOCK(inp);
4044 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4047 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4050 SCTP_TCB_UNLOCK(stcb);
4054 case SCTP_PLUGGABLE_SS:
4056 struct sctp_assoc_value *av;
4058 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4059 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4060 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4061 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4062 (av->assoc_value != SCTP_SS_PRIORITY) &&
4063 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4064 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4065 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4069 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4071 SCTP_TCB_SEND_LOCK(stcb);
4072 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, true);
4073 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4074 stcb->asoc.stream_scheduling_module = av->assoc_value;
4075 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc);
4076 SCTP_TCB_SEND_UNLOCK(stcb);
4077 SCTP_TCB_UNLOCK(stcb);
4079 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4080 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4081 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4082 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4083 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4084 SCTP_INP_WLOCK(inp);
4085 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4086 SCTP_INP_WUNLOCK(inp);
4088 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4089 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4090 (av->assoc_id == SCTP_ALL_ASSOC))) {
4091 SCTP_INP_RLOCK(inp);
4092 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4093 SCTP_TCB_LOCK(stcb);
4094 SCTP_TCB_SEND_LOCK(stcb);
4095 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, true);
4096 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4097 stcb->asoc.stream_scheduling_module = av->assoc_value;
4098 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc);
4099 SCTP_TCB_SEND_UNLOCK(stcb);
4100 SCTP_TCB_UNLOCK(stcb);
4102 SCTP_INP_RUNLOCK(inp);
4109 struct sctp_stream_value *av;
4111 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4112 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4114 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4115 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4116 av->stream_value) < 0)) {
4117 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4120 SCTP_TCB_UNLOCK(stcb);
4122 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4123 (av->assoc_id == SCTP_CURRENT_ASSOC)) {
4124 SCTP_INP_RLOCK(inp);
4125 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4126 SCTP_TCB_LOCK(stcb);
4127 if (av->stream_id < stcb->asoc.streamoutcnt) {
4128 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4130 &stcb->asoc.strmout[av->stream_id],
4133 SCTP_TCB_UNLOCK(stcb);
4135 SCTP_INP_RUNLOCK(inp);
4138 * Can't set stream value without
4141 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4147 case SCTP_CLR_STAT_LOG:
4148 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4153 struct sctp_assoc_value *av;
4155 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4156 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4159 stcb->asoc.context = av->assoc_value;
4160 SCTP_TCB_UNLOCK(stcb);
4162 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4163 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4164 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4165 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4166 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4167 SCTP_INP_WLOCK(inp);
4168 inp->sctp_context = av->assoc_value;
4169 SCTP_INP_WUNLOCK(inp);
4171 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4172 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4173 (av->assoc_id == SCTP_ALL_ASSOC))) {
4174 SCTP_INP_RLOCK(inp);
4175 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4176 SCTP_TCB_LOCK(stcb);
4177 stcb->asoc.context = av->assoc_value;
4178 SCTP_TCB_UNLOCK(stcb);
4180 SCTP_INP_RUNLOCK(inp);
4187 uint32_t *default_vrfid;
4189 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4190 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4191 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4195 inp->def_vrf_id = *default_vrfid;
4198 case SCTP_DEL_VRF_ID:
4200 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4204 case SCTP_ADD_VRF_ID:
4206 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4210 case SCTP_DELAYED_SACK:
4212 struct sctp_sack_info *sack;
4214 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4215 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4216 if (sack->sack_delay) {
4217 if (sack->sack_delay > SCTP_MAX_SACK_DELAY) {
4220 SCTP_TCB_UNLOCK(stcb);
4226 if (sack->sack_delay) {
4227 stcb->asoc.delayed_ack = sack->sack_delay;
4229 if (sack->sack_freq) {
4230 stcb->asoc.sack_freq = sack->sack_freq;
4232 SCTP_TCB_UNLOCK(stcb);
4234 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4235 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4236 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4237 ((sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4238 (sack->sack_assoc_id == SCTP_ALL_ASSOC)))) {
4239 SCTP_INP_WLOCK(inp);
4240 if (sack->sack_delay) {
4241 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = sctp_msecs_to_ticks(sack->sack_delay);
4243 if (sack->sack_freq) {
4244 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4246 SCTP_INP_WUNLOCK(inp);
4248 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4249 ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4250 (sack->sack_assoc_id == SCTP_ALL_ASSOC))) {
4251 SCTP_INP_RLOCK(inp);
4252 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4253 SCTP_TCB_LOCK(stcb);
4254 if (sack->sack_delay) {
4255 stcb->asoc.delayed_ack = sack->sack_delay;
4257 if (sack->sack_freq) {
4258 stcb->asoc.sack_freq = sack->sack_freq;
4260 SCTP_TCB_UNLOCK(stcb);
4262 SCTP_INP_RUNLOCK(inp);
4267 case SCTP_AUTH_CHUNK:
4269 struct sctp_authchunk *sauth;
4271 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4273 SCTP_INP_WLOCK(inp);
4274 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4275 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4278 inp->auth_supported = 1;
4280 SCTP_INP_WUNLOCK(inp);
4285 struct sctp_authkey *sca;
4286 struct sctp_keyhead *shared_keys;
4287 sctp_sharedkey_t *shared_key;
4288 sctp_key_t *key = NULL;
4291 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4292 if (sca->sca_keylength == 0) {
4293 size = optsize - sizeof(struct sctp_authkey);
4295 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4296 size = sca->sca_keylength;
4298 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4303 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4306 shared_keys = &stcb->asoc.shared_keys;
4307 /* clear the cached keys for this key id */
4308 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4310 * create the new shared key and
4314 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4316 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4318 SCTP_TCB_UNLOCK(stcb);
4322 shared_key = sctp_alloc_sharedkey();
4323 if (shared_key == NULL) {
4325 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4327 SCTP_TCB_UNLOCK(stcb);
4330 shared_key->key = key;
4331 shared_key->keyid = sca->sca_keynumber;
4332 error = sctp_insert_sharedkey(shared_keys, shared_key);
4333 SCTP_TCB_UNLOCK(stcb);
4335 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4336 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4337 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4338 ((sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4339 (sca->sca_assoc_id == SCTP_ALL_ASSOC)))) {
4340 SCTP_INP_WLOCK(inp);
4341 shared_keys = &inp->sctp_ep.shared_keys;
4343 * clear the cached keys on all
4344 * assocs for this key id
4346 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4348 * create the new shared key and
4352 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4354 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4356 SCTP_INP_WUNLOCK(inp);
4360 shared_key = sctp_alloc_sharedkey();
4361 if (shared_key == NULL) {
4363 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4365 SCTP_INP_WUNLOCK(inp);
4368 shared_key->key = key;
4369 shared_key->keyid = sca->sca_keynumber;
4370 error = sctp_insert_sharedkey(shared_keys, shared_key);
4371 SCTP_INP_WUNLOCK(inp);
4373 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4374 ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4375 (sca->sca_assoc_id == SCTP_ALL_ASSOC))) {
4376 SCTP_INP_RLOCK(inp);
4377 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4378 SCTP_TCB_LOCK(stcb);
4379 shared_keys = &stcb->asoc.shared_keys;
4381 * clear the cached keys for
4384 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4386 * create the new shared key
4387 * and insert/replace it
4390 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4392 SCTP_TCB_UNLOCK(stcb);
4396 shared_key = sctp_alloc_sharedkey();
4397 if (shared_key == NULL) {
4399 SCTP_TCB_UNLOCK(stcb);
4402 shared_key->key = key;
4403 shared_key->keyid = sca->sca_keynumber;
4404 error = sctp_insert_sharedkey(shared_keys, shared_key);
4405 SCTP_TCB_UNLOCK(stcb);
4407 SCTP_INP_RUNLOCK(inp);
4412 case SCTP_HMAC_IDENT:
4414 struct sctp_hmacalgo *shmac;
4415 sctp_hmaclist_t *hmaclist;
4419 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4420 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4421 (shmac->shmac_number_of_idents > 0xffff)) {
4422 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4427 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4428 if (hmaclist == NULL) {
4429 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4433 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4434 hmacid = shmac->shmac_idents[i];
4435 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4436 /* invalid HMACs were found */ ;
4437 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4439 sctp_free_hmaclist(hmaclist);
4440 goto sctp_set_hmac_done;
4443 for (i = 0; i < hmaclist->num_algo; i++) {
4444 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4445 /* already in list */
4449 if (i == hmaclist->num_algo) {
4450 /* not found in list */
4451 sctp_free_hmaclist(hmaclist);
4452 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4456 /* set it on the endpoint */
4457 SCTP_INP_WLOCK(inp);
4458 if (inp->sctp_ep.local_hmacs)
4459 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4460 inp->sctp_ep.local_hmacs = hmaclist;
4461 SCTP_INP_WUNLOCK(inp);
4465 case SCTP_AUTH_ACTIVE_KEY:
4467 struct sctp_authkeyid *scact;
4469 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4470 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4472 /* set the active key on the right place */
4474 /* set the active key on the assoc */
4475 if (sctp_auth_setactivekey(stcb,
4476 scact->scact_keynumber)) {
4477 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4478 SCTP_FROM_SCTP_USRREQ,
4482 SCTP_TCB_UNLOCK(stcb);
4484 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4485 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4486 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4487 ((scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4488 (scact->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4489 SCTP_INP_WLOCK(inp);
4490 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4491 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4494 SCTP_INP_WUNLOCK(inp);
4496 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4497 ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4498 (scact->scact_assoc_id == SCTP_ALL_ASSOC))) {
4499 SCTP_INP_RLOCK(inp);
4500 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4501 SCTP_TCB_LOCK(stcb);
4502 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4503 SCTP_TCB_UNLOCK(stcb);
4505 SCTP_INP_RUNLOCK(inp);
4510 case SCTP_AUTH_DELETE_KEY:
4512 struct sctp_authkeyid *scdel;
4514 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4515 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4517 /* delete the key from the right place */
4519 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4520 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4523 SCTP_TCB_UNLOCK(stcb);
4525 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4526 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4527 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4528 ((scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4529 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4530 SCTP_INP_WLOCK(inp);
4531 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4532 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4535 SCTP_INP_WUNLOCK(inp);
4537 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4538 ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4539 (scdel->scact_assoc_id == SCTP_ALL_ASSOC))) {
4540 SCTP_INP_RLOCK(inp);
4541 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4542 SCTP_TCB_LOCK(stcb);
4543 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4544 SCTP_TCB_UNLOCK(stcb);
4546 SCTP_INP_RUNLOCK(inp);
4551 case SCTP_AUTH_DEACTIVATE_KEY:
4553 struct sctp_authkeyid *keyid;
4555 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4556 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4558 /* deactivate the key from the right place */
4560 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4561 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4564 SCTP_TCB_UNLOCK(stcb);
4566 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4567 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4568 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4569 ((keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4570 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4571 SCTP_INP_WLOCK(inp);
4572 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4573 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4576 SCTP_INP_WUNLOCK(inp);
4578 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4579 ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4580 (keyid->scact_assoc_id == SCTP_ALL_ASSOC))) {
4581 SCTP_INP_RLOCK(inp);
4582 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4583 SCTP_TCB_LOCK(stcb);
4584 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4585 SCTP_TCB_UNLOCK(stcb);
4587 SCTP_INP_RUNLOCK(inp);
4592 case SCTP_ENABLE_STREAM_RESET:
4594 struct sctp_assoc_value *av;
4596 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4597 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4598 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4602 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4604 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4605 SCTP_TCB_UNLOCK(stcb);
4607 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4608 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4609 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4610 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4611 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4612 SCTP_INP_WLOCK(inp);
4613 inp->local_strreset_support = (uint8_t)av->assoc_value;
4614 SCTP_INP_WUNLOCK(inp);
4616 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4617 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4618 (av->assoc_id == SCTP_ALL_ASSOC))) {
4619 SCTP_INP_RLOCK(inp);
4620 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4621 SCTP_TCB_LOCK(stcb);
4622 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4623 SCTP_TCB_UNLOCK(stcb);
4625 SCTP_INP_RUNLOCK(inp);
4630 case SCTP_RESET_STREAMS:
4632 struct sctp_reset_streams *strrst;
4633 int i, send_out = 0;
4636 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4637 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4639 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4643 if (stcb->asoc.reconfig_supported == 0) {
4645 * Peer does not support the chunk type.
4647 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4649 SCTP_TCB_UNLOCK(stcb);
4652 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4653 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4655 SCTP_TCB_UNLOCK(stcb);
4658 if (sizeof(struct sctp_reset_streams) +
4659 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4661 SCTP_TCB_UNLOCK(stcb);
4664 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4666 if (stcb->asoc.stream_reset_outstanding) {
4667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4669 SCTP_TCB_UNLOCK(stcb);
4673 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4676 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4677 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4679 SCTP_TCB_UNLOCK(stcb);
4682 if ((send_in == 0) && (send_out == 0)) {
4683 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4685 SCTP_TCB_UNLOCK(stcb);
4688 for (i = 0; i < strrst->srs_number_streams; i++) {
4690 (strrst->srs_stream_list[i] >= stcb->asoc.streamincnt)) {
4691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4696 (strrst->srs_stream_list[i] >= stcb->asoc.streamoutcnt)) {
4697 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4703 SCTP_TCB_UNLOCK(stcb);
4710 if (strrst->srs_number_streams) {
4711 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4712 strm = strrst->srs_stream_list[i];
4713 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4714 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4720 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4721 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4722 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4729 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4730 strrst->srs_stream_list,
4731 send_in, 0, 0, 0, 0, 0);
4733 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4736 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4739 * For outgoing streams don't report any
4740 * problems in sending the request to the
4741 * application. XXX: Double check resetting
4746 SCTP_TCB_UNLOCK(stcb);
4749 case SCTP_ADD_STREAMS:
4751 struct sctp_add_streams *stradd;
4752 uint8_t addstream = 0;
4753 uint16_t add_o_strmcnt = 0;
4754 uint16_t add_i_strmcnt = 0;
4756 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4757 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4759 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4763 if (stcb->asoc.reconfig_supported == 0) {
4765 * Peer does not support the chunk type.
4767 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4769 SCTP_TCB_UNLOCK(stcb);
4772 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4775 SCTP_TCB_UNLOCK(stcb);
4778 if (stcb->asoc.stream_reset_outstanding) {
4779 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4781 SCTP_TCB_UNLOCK(stcb);
4784 if ((stradd->sas_outstrms == 0) &&
4785 (stradd->sas_instrms == 0)) {
4789 if (stradd->sas_outstrms) {
4791 /* We allocate here */
4792 add_o_strmcnt = stradd->sas_outstrms;
4793 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4794 /* You can't have more than 64k */
4799 if (stradd->sas_instrms) {
4804 * We allocate inside
4805 * sctp_send_str_reset_req()
4807 add_i_strmcnt = stradd->sas_instrms;
4808 cnt = add_i_strmcnt;
4809 cnt += stcb->asoc.streamincnt;
4810 if (cnt > 0x0000ffff) {
4811 /* You can't have more than 64k */
4815 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4816 /* More than you are allowed */
4821 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4822 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4824 SCTP_TCB_UNLOCK(stcb);
4827 case SCTP_RESET_ASSOC:
4832 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4833 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4835 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4839 if (stcb->asoc.reconfig_supported == 0) {
4841 * Peer does not support the chunk type.
4843 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4845 SCTP_TCB_UNLOCK(stcb);
4848 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4849 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4851 SCTP_TCB_UNLOCK(stcb);
4854 if (stcb->asoc.stream_reset_outstanding) {
4855 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4857 SCTP_TCB_UNLOCK(stcb);
4861 * Is there any data pending in the send or sent
4864 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4865 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4868 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4869 SCTP_TCB_UNLOCK(stcb);
4872 /* Do any streams have data queued? */
4873 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4874 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4878 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4879 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4880 SCTP_TCB_UNLOCK(stcb);
4883 case SCTP_CONNECT_X:
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, 0);
4891 case SCTP_CONNECT_X_DELAYED:
4892 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4893 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4897 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4899 case SCTP_CONNECT_X_COMPLETE:
4901 struct sockaddr *sa;
4903 /* FIXME MT: check correct? */
4904 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4907 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4908 SCTP_INP_RLOCK(inp);
4909 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4911 SCTP_TCB_LOCK(stcb);
4913 SCTP_INP_RUNLOCK(inp);
4916 * We increment here since
4917 * sctp_findassociation_ep_addr() wil do a
4918 * decrement if it finds the stcb as long as
4919 * the locked tcb (last argument) is NOT a
4922 SCTP_INP_INCR_REF(inp);
4923 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4925 SCTP_INP_DECR_REF(inp);
4930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4934 if (stcb->asoc.delayed_connection == 1) {
4935 stcb->asoc.delayed_connection = 0;
4936 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4937 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4938 stcb->asoc.primary_destination,
4939 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4940 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4943 * already expired or did not use delayed
4946 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4949 SCTP_TCB_UNLOCK(stcb);
4952 case SCTP_MAX_BURST:
4954 struct sctp_assoc_value *av;
4956 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4957 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4960 stcb->asoc.max_burst = av->assoc_value;
4961 SCTP_TCB_UNLOCK(stcb);
4963 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4964 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4965 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4966 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4967 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4968 SCTP_INP_WLOCK(inp);
4969 inp->sctp_ep.max_burst = av->assoc_value;
4970 SCTP_INP_WUNLOCK(inp);
4972 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4973 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4974 (av->assoc_id == SCTP_ALL_ASSOC))) {
4975 SCTP_INP_RLOCK(inp);
4976 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4977 SCTP_TCB_LOCK(stcb);
4978 stcb->asoc.max_burst = av->assoc_value;
4979 SCTP_TCB_UNLOCK(stcb);
4981 SCTP_INP_RUNLOCK(inp);
4988 struct sctp_assoc_value *av;
4990 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4991 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4994 stcb->asoc.sctp_frag_point = av->assoc_value;
4995 SCTP_TCB_UNLOCK(stcb);
4997 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4998 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4999 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5000 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
5001 SCTP_INP_WLOCK(inp);
5002 inp->sctp_frag_point = av->assoc_value;
5003 SCTP_INP_WUNLOCK(inp);
5005 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5013 struct sctp_event_subscribe *events;
5015 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5017 SCTP_INP_WLOCK(inp);
5018 if (events->sctp_data_io_event) {
5019 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5021 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5024 if (events->sctp_association_event) {
5025 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5027 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5030 if (events->sctp_address_event) {
5031 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5033 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5036 if (events->sctp_send_failure_event) {
5037 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5039 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5042 if (events->sctp_peer_error_event) {
5043 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5045 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5048 if (events->sctp_shutdown_event) {
5049 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5051 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5054 if (events->sctp_partial_delivery_event) {
5055 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5057 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5060 if (events->sctp_adaptation_layer_event) {
5061 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5063 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5066 if (events->sctp_authentication_event) {
5067 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5069 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5072 if (events->sctp_sender_dry_event) {
5073 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5075 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5078 if (events->sctp_stream_reset_event) {
5079 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5081 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5083 SCTP_INP_WUNLOCK(inp);
5085 SCTP_INP_RLOCK(inp);
5086 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5087 SCTP_TCB_LOCK(stcb);
5088 if (events->sctp_association_event) {
5089 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5091 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5093 if (events->sctp_address_event) {
5094 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5096 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5098 if (events->sctp_send_failure_event) {
5099 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5101 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5103 if (events->sctp_peer_error_event) {
5104 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5106 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5108 if (events->sctp_shutdown_event) {
5109 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5111 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5113 if (events->sctp_partial_delivery_event) {
5114 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5116 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5118 if (events->sctp_adaptation_layer_event) {
5119 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5121 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5123 if (events->sctp_authentication_event) {
5124 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5126 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5128 if (events->sctp_sender_dry_event) {
5129 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5131 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5133 if (events->sctp_stream_reset_event) {
5134 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5136 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5138 SCTP_TCB_UNLOCK(stcb);
5141 * Send up the sender dry event only for 1-to-1
5144 if (events->sctp_sender_dry_event) {
5145 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5146 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5147 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5149 SCTP_TCB_LOCK(stcb);
5150 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5151 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5152 (stcb->asoc.stream_queue_cnt == 0)) {
5153 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5155 SCTP_TCB_UNLOCK(stcb);
5159 SCTP_INP_RUNLOCK(inp);
5162 case SCTP_ADAPTATION_LAYER:
5164 struct sctp_setadaptation *adap_bits;
5166 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5167 SCTP_INP_WLOCK(inp);
5168 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5169 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5170 SCTP_INP_WUNLOCK(inp);
5174 case SCTP_SET_INITIAL_DBG_SEQ:
5178 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5179 SCTP_INP_WLOCK(inp);
5180 inp->sctp_ep.initial_sequence_debug = *vvv;
5181 SCTP_INP_WUNLOCK(inp);
5185 case SCTP_DEFAULT_SEND_PARAM:
5187 struct sctp_sndrcvinfo *s_info;
5189 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5190 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5193 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5194 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5196 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5199 SCTP_TCB_UNLOCK(stcb);
5201 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5202 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5203 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5204 ((s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5205 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)))) {
5206 SCTP_INP_WLOCK(inp);
5207 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5208 SCTP_INP_WUNLOCK(inp);
5210 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5211 ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5212 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC))) {
5213 SCTP_INP_RLOCK(inp);
5214 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5215 SCTP_TCB_LOCK(stcb);
5216 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5217 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5219 SCTP_TCB_UNLOCK(stcb);
5221 SCTP_INP_RUNLOCK(inp);
5226 case SCTP_PEER_ADDR_PARAMS:
5228 struct sctp_paddrparams *paddrp;
5229 struct sctp_nets *net;
5230 struct sockaddr *addr;
5231 #if defined(INET) && defined(INET6)
5232 struct sockaddr_in sin_store;
5235 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5236 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5238 #if defined(INET) && defined(INET6)
5239 if (paddrp->spp_address.ss_family == AF_INET6) {
5240 struct sockaddr_in6 *sin6;
5242 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5243 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5244 in6_sin6_2_sin(&sin_store, sin6);
5245 addr = (struct sockaddr *)&sin_store;
5247 addr = (struct sockaddr *)&paddrp->spp_address;
5250 addr = (struct sockaddr *)&paddrp->spp_address;
5253 addr = (struct sockaddr *)&paddrp->spp_address;
5256 net = sctp_findnet(stcb, addr);
5259 * We increment here since
5260 * sctp_findassociation_ep_addr() wil do a
5261 * decrement if it finds the stcb as long as
5262 * the locked tcb (last argument) is NOT a
5266 SCTP_INP_INCR_REF(inp);
5267 stcb = sctp_findassociation_ep_addr(&inp, addr,
5270 SCTP_INP_DECR_REF(inp);
5273 if ((stcb != NULL) && (net == NULL)) {
5275 if (addr->sa_family == AF_INET) {
5276 struct sockaddr_in *sin;
5278 sin = (struct sockaddr_in *)addr;
5279 if (sin->sin_addr.s_addr != INADDR_ANY) {
5280 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5281 SCTP_TCB_UNLOCK(stcb);
5288 if (addr->sa_family == AF_INET6) {
5289 struct sockaddr_in6 *sin6;
5291 sin6 = (struct sockaddr_in6 *)addr;
5292 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5293 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5294 SCTP_TCB_UNLOCK(stcb);
5301 error = EAFNOSUPPORT;
5302 SCTP_TCB_UNLOCK(stcb);
5303 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5308 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5310 SCTP_TCB_UNLOCK(stcb);
5311 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5315 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5317 SCTP_TCB_UNLOCK(stcb);
5318 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5321 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) &&
5322 (paddrp->spp_pathmtu > 0) &&
5323 ((paddrp->spp_pathmtu < SCTP_SMALLEST_PMTU) ||
5324 (paddrp->spp_pathmtu > SCTP_LARGEST_PMTU))) {
5326 SCTP_TCB_UNLOCK(stcb);
5327 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5332 /************************TCB SPECIFIC SET ******************/
5334 /************************NET SPECIFIC SET ******************/
5335 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5336 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5337 !(net->dest_state & SCTP_ADDR_NOHB)) {
5338 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5339 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5341 net->dest_state |= SCTP_ADDR_NOHB;
5343 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5344 if (paddrp->spp_hbinterval) {
5345 net->heart_beat_delay = paddrp->spp_hbinterval;
5346 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5347 net->heart_beat_delay = 0;
5349 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5350 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5351 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5352 net->dest_state &= ~SCTP_ADDR_NOHB;
5354 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5355 if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
5356 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5357 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5358 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5361 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5362 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5363 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5364 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5366 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5367 if (paddrp->spp_pathmtu > 0) {
5368 net->mtu = paddrp->spp_pathmtu;
5369 switch (net->ro._l_addr.sa.sa_family) {
5372 net->mtu += SCTP_MIN_V4_OVERHEAD;
5377 net->mtu += SCTP_MIN_OVERHEAD;
5383 if (net->mtu < stcb->asoc.smallest_mtu) {
5384 sctp_pathmtu_adjustment(stcb, net->mtu, true);
5388 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5389 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5390 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5392 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5394 if (paddrp->spp_pathmaxrxt > 0) {
5395 if (net->dest_state & SCTP_ADDR_PF) {
5396 if (net->error_count > paddrp->spp_pathmaxrxt) {
5397 net->dest_state &= ~SCTP_ADDR_PF;
5400 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5401 (net->error_count > net->pf_threshold)) {
5402 net->dest_state |= SCTP_ADDR_PF;
5403 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5404 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5405 stcb->sctp_ep, stcb, net,
5406 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5407 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5410 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5411 if (net->error_count > paddrp->spp_pathmaxrxt) {
5412 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5413 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5416 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5417 net->dest_state |= SCTP_ADDR_REACHABLE;
5418 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5421 net->failure_threshold = paddrp->spp_pathmaxrxt;
5423 if (paddrp->spp_flags & SPP_DSCP) {
5424 net->dscp = paddrp->spp_dscp & 0xfc;
5428 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5429 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5430 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5431 net->flowlabel |= 0x80000000;
5436 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5437 if (paddrp->spp_pathmaxrxt > 0) {
5438 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5439 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5440 if (net->dest_state & SCTP_ADDR_PF) {
5441 if (net->error_count > paddrp->spp_pathmaxrxt) {
5442 net->dest_state &= ~SCTP_ADDR_PF;
5445 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5446 (net->error_count > net->pf_threshold)) {
5447 net->dest_state |= SCTP_ADDR_PF;
5448 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5449 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5450 stcb->sctp_ep, stcb, net,
5451 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5452 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5455 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5456 if (net->error_count > paddrp->spp_pathmaxrxt) {
5457 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5458 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5461 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5462 net->dest_state |= SCTP_ADDR_REACHABLE;
5463 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5466 net->failure_threshold = paddrp->spp_pathmaxrxt;
5469 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5470 if (paddrp->spp_hbinterval != 0) {
5471 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5472 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5473 stcb->asoc.heart_beat_delay = 0;
5475 /* Turn back on the timer */
5476 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5477 if (paddrp->spp_hbinterval != 0) {
5478 net->heart_beat_delay = paddrp->spp_hbinterval;
5479 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5480 net->heart_beat_delay = 0;
5482 if (net->dest_state & SCTP_ADDR_NOHB) {
5483 net->dest_state &= ~SCTP_ADDR_NOHB;
5485 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5486 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5487 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5489 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5491 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5492 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5493 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5494 net->dest_state |= SCTP_ADDR_NOHB;
5495 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5496 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5498 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5502 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5504 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5505 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5506 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5507 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5508 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5510 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5511 if (paddrp->spp_pathmtu > 0) {
5512 net->mtu = paddrp->spp_pathmtu;
5513 switch (net->ro._l_addr.sa.sa_family) {
5516 net->mtu += SCTP_MIN_V4_OVERHEAD;
5521 net->mtu += SCTP_MIN_OVERHEAD;
5527 if (net->mtu < stcb->asoc.smallest_mtu) {
5528 sctp_pathmtu_adjustment(stcb, net->mtu, true);
5532 if (paddrp->spp_pathmtu > 0) {
5533 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5535 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5537 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5538 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5539 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5540 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5542 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5544 stcb->asoc.default_mtu = 0;
5545 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5547 if (paddrp->spp_flags & SPP_DSCP) {
5548 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5549 net->dscp = paddrp->spp_dscp & 0xfc;
5552 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5553 stcb->asoc.default_dscp |= 0x01;
5556 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5557 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5558 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5559 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5560 net->flowlabel |= 0x80000000;
5563 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5564 stcb->asoc.default_flowlabel |= 0x80000000;
5568 SCTP_TCB_UNLOCK(stcb);
5570 /************************NO TCB, SET TO default stuff ******************/
5571 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5572 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5573 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5574 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
5575 SCTP_INP_WLOCK(inp);
5577 * For the TOS/FLOWLABEL stuff you
5578 * set it with the options on the
5581 if (paddrp->spp_pathmaxrxt > 0) {
5582 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5585 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5586 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5587 else if (paddrp->spp_hbinterval != 0) {
5588 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5589 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5590 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5593 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5594 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5595 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5596 } else if (paddrp->spp_hbinterval) {
5597 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5599 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5600 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5601 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5603 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5604 inp->sctp_ep.default_mtu = 0;
5605 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5606 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5607 if (paddrp->spp_pathmtu > 0) {
5608 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5610 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5612 if (paddrp->spp_flags & SPP_DSCP) {
5613 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5614 inp->sctp_ep.default_dscp |= 0x01;
5617 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5618 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5619 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5620 inp->sctp_ep.default_flowlabel |= 0x80000000;
5624 SCTP_INP_WUNLOCK(inp);
5626 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5634 struct sctp_rtoinfo *srto;
5635 uint32_t new_init, new_min, new_max;
5637 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5638 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5641 if (srto->srto_initial)
5642 new_init = srto->srto_initial;
5644 new_init = stcb->asoc.initial_rto;
5646 new_max = srto->srto_max;
5648 new_max = stcb->asoc.maxrto;
5650 new_min = srto->srto_min;
5652 new_min = stcb->asoc.minrto;
5653 if ((new_min <= new_init) && (new_init <= new_max)) {
5654 stcb->asoc.initial_rto = new_init;
5655 stcb->asoc.maxrto = new_max;
5656 stcb->asoc.minrto = new_min;
5658 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5661 SCTP_TCB_UNLOCK(stcb);
5663 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5664 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5665 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5666 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
5667 SCTP_INP_WLOCK(inp);
5668 if (srto->srto_initial)
5669 new_init = srto->srto_initial;
5671 new_init = inp->sctp_ep.initial_rto;
5673 new_max = srto->srto_max;
5675 new_max = inp->sctp_ep.sctp_maxrto;
5677 new_min = srto->srto_min;
5679 new_min = inp->sctp_ep.sctp_minrto;
5680 if ((new_min <= new_init) && (new_init <= new_max)) {
5681 inp->sctp_ep.initial_rto = new_init;
5682 inp->sctp_ep.sctp_maxrto = new_max;
5683 inp->sctp_ep.sctp_minrto = new_min;
5685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5688 SCTP_INP_WUNLOCK(inp);
5690 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5696 case SCTP_ASSOCINFO:
5698 struct sctp_assocparams *sasoc;
5700 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5701 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5702 if (sasoc->sasoc_cookie_life > 0) {
5703 /* boundary check the cookie life */
5704 if (sasoc->sasoc_cookie_life < SCTP_MIN_COOKIE_LIFE) {
5705 sasoc->sasoc_cookie_life = SCTP_MIN_COOKIE_LIFE;
5707 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5708 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5712 if (sasoc->sasoc_asocmaxrxt > 0) {
5713 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5715 if (sasoc->sasoc_cookie_life > 0) {
5716 stcb->asoc.cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5718 SCTP_TCB_UNLOCK(stcb);
5720 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5721 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5722 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5723 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
5724 SCTP_INP_WLOCK(inp);
5725 if (sasoc->sasoc_asocmaxrxt > 0) {
5726 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5728 if (sasoc->sasoc_cookie_life > 0) {
5729 inp->sctp_ep.def_cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5731 SCTP_INP_WUNLOCK(inp);
5733 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5741 struct sctp_initmsg *sinit;
5743 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5744 SCTP_INP_WLOCK(inp);
5745 if (sinit->sinit_num_ostreams)
5746 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5748 if (sinit->sinit_max_instreams)
5749 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5751 if (sinit->sinit_max_attempts)
5752 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5754 if (sinit->sinit_max_init_timeo)
5755 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5756 SCTP_INP_WUNLOCK(inp);
5759 case SCTP_PRIMARY_ADDR:
5761 struct sctp_setprim *spa;
5762 struct sctp_nets *net;
5763 struct sockaddr *addr;
5764 #if defined(INET) && defined(INET6)
5765 struct sockaddr_in sin_store;
5768 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5769 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5771 #if defined(INET) && defined(INET6)
5772 if (spa->ssp_addr.ss_family == AF_INET6) {
5773 struct sockaddr_in6 *sin6;
5775 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5776 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5777 in6_sin6_2_sin(&sin_store, sin6);
5778 addr = (struct sockaddr *)&sin_store;
5780 addr = (struct sockaddr *)&spa->ssp_addr;
5783 addr = (struct sockaddr *)&spa->ssp_addr;
5786 addr = (struct sockaddr *)&spa->ssp_addr;
5789 net = sctp_findnet(stcb, addr);
5792 * We increment here since
5793 * sctp_findassociation_ep_addr() wil do a
5794 * decrement if it finds the stcb as long as
5795 * the locked tcb (last argument) is NOT a
5799 SCTP_INP_INCR_REF(inp);
5800 stcb = sctp_findassociation_ep_addr(&inp, addr,
5803 SCTP_INP_DECR_REF(inp);
5807 if ((stcb != NULL) && (net != NULL)) {
5808 if (net != stcb->asoc.primary_destination) {
5809 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5810 /* Ok we need to set it */
5811 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5812 if ((stcb->asoc.alternate) &&
5813 (!(net->dest_state & SCTP_ADDR_PF)) &&
5814 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5815 sctp_free_remote_addr(stcb->asoc.alternate);
5816 stcb->asoc.alternate = NULL;
5819 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5823 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5828 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5832 SCTP_TCB_UNLOCK(stcb);
5836 case SCTP_SET_DYNAMIC_PRIMARY:
5838 union sctp_sockstore *ss;
5840 error = priv_check(curthread,
5841 PRIV_NETINET_RESERVEDPORT);
5845 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5846 /* SUPER USER CHECK? */
5847 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5850 case SCTP_SET_PEER_PRIMARY_ADDR:
5852 struct sctp_setpeerprim *sspp;
5853 struct sockaddr *addr;
5854 #if defined(INET) && defined(INET6)
5855 struct sockaddr_in sin_store;
5858 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5859 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5861 struct sctp_ifa *ifa;
5863 #if defined(INET) && defined(INET6)
5864 if (sspp->sspp_addr.ss_family == AF_INET6) {
5865 struct sockaddr_in6 *sin6;
5867 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5868 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5869 in6_sin6_2_sin(&sin_store, sin6);
5870 addr = (struct sockaddr *)&sin_store;
5872 addr = (struct sockaddr *)&sspp->sspp_addr;
5875 addr = (struct sockaddr *)&sspp->sspp_addr;
5878 addr = (struct sockaddr *)&sspp->sspp_addr;
5880 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5886 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5888 * Must validate the ifa found is in
5891 struct sctp_laddr *laddr;
5894 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5895 if (laddr->ifa == NULL) {
5896 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5900 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5901 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5904 if (laddr->ifa == ifa) {
5910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5915 switch (addr->sa_family) {
5919 struct sockaddr_in *sin;
5921 sin = (struct sockaddr_in *)addr;
5922 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5923 &sin->sin_addr) != 0) {
5924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5934 struct sockaddr_in6 *sin6;
5936 sin6 = (struct sockaddr_in6 *)addr;
5937 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5938 &sin6->sin6_addr) != 0) {
5939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5947 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5952 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5953 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5956 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5958 SCTP_TCB_UNLOCK(stcb);
5960 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5965 case SCTP_BINDX_ADD_ADDR:
5967 struct sockaddr *sa;
5970 td = (struct thread *)p;
5971 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
5973 if (sa->sa_family == AF_INET) {
5974 if (optsize < sizeof(struct sockaddr_in)) {
5975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5980 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
5981 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5987 if (sa->sa_family == AF_INET6) {
5988 if (optsize < sizeof(struct sockaddr_in6)) {
5989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5994 (error = prison_local_ip6(td->td_ucred,
5995 &(((struct sockaddr_in6 *)sa)->sin6_addr),
5996 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5997 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6003 error = EAFNOSUPPORT;
6006 sctp_bindx_add_address(so, inp, sa, vrf_id, &error, p);
6009 case SCTP_BINDX_REM_ADDR:
6011 struct sockaddr *sa;
6014 td = (struct thread *)p;
6016 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
6018 if (sa->sa_family == AF_INET) {
6019 if (optsize < sizeof(struct sockaddr_in)) {
6020 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6025 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
6026 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6032 if (sa->sa_family == AF_INET6) {
6033 if (optsize < sizeof(struct sockaddr_in6)) {
6034 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6039 (error = prison_local_ip6(td->td_ucred,
6040 &(((struct sockaddr_in6 *)sa)->sin6_addr),
6041 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6042 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6048 error = EAFNOSUPPORT;
6051 sctp_bindx_delete_address(inp, sa, vrf_id, &error);
6056 struct sctp_event *event;
6057 uint32_t event_type;
6059 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6060 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6061 switch (event->se_type) {
6062 case SCTP_ASSOC_CHANGE:
6063 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6065 case SCTP_PEER_ADDR_CHANGE:
6066 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6068 case SCTP_REMOTE_ERROR:
6069 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6071 case SCTP_SEND_FAILED:
6072 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6074 case SCTP_SHUTDOWN_EVENT:
6075 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6077 case SCTP_ADAPTATION_INDICATION:
6078 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6080 case SCTP_PARTIAL_DELIVERY_EVENT:
6081 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6083 case SCTP_AUTHENTICATION_EVENT:
6084 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6086 case SCTP_STREAM_RESET_EVENT:
6087 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6089 case SCTP_SENDER_DRY_EVENT:
6090 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6092 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6094 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6097 case SCTP_ASSOC_RESET_EVENT:
6098 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6100 case SCTP_STREAM_CHANGE_EVENT:
6101 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6103 case SCTP_SEND_FAILED_EVENT:
6104 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6108 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6112 if (event_type > 0) {
6115 sctp_stcb_feature_on(inp, stcb, event_type);
6116 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6117 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6118 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6119 (stcb->asoc.stream_queue_cnt == 0)) {
6120 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6124 sctp_stcb_feature_off(inp, stcb, event_type);
6126 SCTP_TCB_UNLOCK(stcb);
6129 * We don't want to send up a storm
6130 * of events, so return an error for
6133 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6134 (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6135 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6136 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6137 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6141 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6142 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6143 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6144 ((event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6145 (event->se_assoc_id == SCTP_ALL_ASSOC)))) {
6146 SCTP_INP_WLOCK(inp);
6148 sctp_feature_on(inp, event_type);
6150 sctp_feature_off(inp, event_type);
6152 SCTP_INP_WUNLOCK(inp);
6154 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6155 ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6156 (event->se_assoc_id == SCTP_ALL_ASSOC))) {
6157 SCTP_INP_RLOCK(inp);
6158 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6159 SCTP_TCB_LOCK(stcb);
6161 sctp_stcb_feature_on(inp, stcb, event_type);
6163 sctp_stcb_feature_off(inp, stcb, event_type);
6165 SCTP_TCB_UNLOCK(stcb);
6167 SCTP_INP_RUNLOCK(inp);
6172 SCTP_TCB_UNLOCK(stcb);
6177 case SCTP_RECVRCVINFO:
6181 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6182 SCTP_INP_WLOCK(inp);
6184 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6186 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6188 SCTP_INP_WUNLOCK(inp);
6191 case SCTP_RECVNXTINFO:
6195 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6196 SCTP_INP_WLOCK(inp);
6198 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6200 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6202 SCTP_INP_WUNLOCK(inp);
6205 case SCTP_DEFAULT_SNDINFO:
6207 struct sctp_sndinfo *info;
6210 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6211 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6214 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6215 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6216 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6217 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6218 stcb->asoc.def_send.sinfo_flags |= policy;
6219 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6220 stcb->asoc.def_send.sinfo_context = info->snd_context;
6222 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6225 SCTP_TCB_UNLOCK(stcb);
6227 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6228 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6229 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6230 ((info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6231 (info->snd_assoc_id == SCTP_ALL_ASSOC)))) {
6232 SCTP_INP_WLOCK(inp);
6233 inp->def_send.sinfo_stream = info->snd_sid;
6234 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6235 inp->def_send.sinfo_flags = info->snd_flags;
6236 inp->def_send.sinfo_flags |= policy;
6237 inp->def_send.sinfo_ppid = info->snd_ppid;
6238 inp->def_send.sinfo_context = info->snd_context;
6239 SCTP_INP_WUNLOCK(inp);
6241 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6242 ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6243 (info->snd_assoc_id == SCTP_ALL_ASSOC))) {
6244 SCTP_INP_RLOCK(inp);
6245 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6246 SCTP_TCB_LOCK(stcb);
6247 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6248 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6249 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6250 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6251 stcb->asoc.def_send.sinfo_flags |= policy;
6252 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6253 stcb->asoc.def_send.sinfo_context = info->snd_context;
6255 SCTP_TCB_UNLOCK(stcb);
6257 SCTP_INP_RUNLOCK(inp);
6262 case SCTP_DEFAULT_PRINFO:
6264 struct sctp_default_prinfo *info;
6266 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6267 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6269 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6271 SCTP_TCB_UNLOCK(stcb);
6273 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6278 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6279 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6280 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6281 SCTP_TCB_UNLOCK(stcb);
6283 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6284 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6285 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6286 ((info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6287 (info->pr_assoc_id == SCTP_ALL_ASSOC)))) {
6288 SCTP_INP_WLOCK(inp);
6289 inp->def_send.sinfo_flags &= 0xfff0;
6290 inp->def_send.sinfo_flags |= info->pr_policy;
6291 inp->def_send.sinfo_timetolive = info->pr_value;
6292 SCTP_INP_WUNLOCK(inp);
6294 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6295 ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6296 (info->pr_assoc_id == SCTP_ALL_ASSOC))) {
6297 SCTP_INP_RLOCK(inp);
6298 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6299 SCTP_TCB_LOCK(stcb);
6300 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6301 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6302 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6303 SCTP_TCB_UNLOCK(stcb);
6305 SCTP_INP_RUNLOCK(inp);
6310 case SCTP_PEER_ADDR_THLDS:
6311 /* Applies to the specific association */
6313 struct sctp_paddrthlds *thlds;
6314 struct sctp_nets *net;
6315 struct sockaddr *addr;
6316 #if defined(INET) && defined(INET6)
6317 struct sockaddr_in sin_store;
6320 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6321 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6323 #if defined(INET) && defined(INET6)
6324 if (thlds->spt_address.ss_family == AF_INET6) {
6325 struct sockaddr_in6 *sin6;
6327 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6328 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6329 in6_sin6_2_sin(&sin_store, sin6);
6330 addr = (struct sockaddr *)&sin_store;
6332 addr = (struct sockaddr *)&thlds->spt_address;
6335 addr = (struct sockaddr *)&thlds->spt_address;
6338 addr = (struct sockaddr *)&thlds->spt_address;
6341 net = sctp_findnet(stcb, addr);
6344 * We increment here since
6345 * sctp_findassociation_ep_addr() wil do a
6346 * decrement if it finds the stcb as long as
6347 * the locked tcb (last argument) is NOT a
6351 SCTP_INP_INCR_REF(inp);
6352 stcb = sctp_findassociation_ep_addr(&inp, addr,
6355 SCTP_INP_DECR_REF(inp);
6358 if ((stcb != NULL) && (net == NULL)) {
6360 if (addr->sa_family == AF_INET) {
6361 struct sockaddr_in *sin;
6363 sin = (struct sockaddr_in *)addr;
6364 if (sin->sin_addr.s_addr != INADDR_ANY) {
6365 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6366 SCTP_TCB_UNLOCK(stcb);
6373 if (addr->sa_family == AF_INET6) {
6374 struct sockaddr_in6 *sin6;
6376 sin6 = (struct sockaddr_in6 *)addr;
6377 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6378 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6379 SCTP_TCB_UNLOCK(stcb);
6386 error = EAFNOSUPPORT;
6387 SCTP_TCB_UNLOCK(stcb);
6388 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6392 if (thlds->spt_pathcpthld != 0xffff) {
6394 SCTP_TCB_UNLOCK(stcb);
6397 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6402 net->failure_threshold = thlds->spt_pathmaxrxt;
6403 net->pf_threshold = thlds->spt_pathpfthld;
6404 if (net->dest_state & SCTP_ADDR_PF) {
6405 if ((net->error_count > net->failure_threshold) ||
6406 (net->error_count <= net->pf_threshold)) {
6407 net->dest_state &= ~SCTP_ADDR_PF;
6410 if ((net->error_count > net->pf_threshold) &&
6411 (net->error_count <= net->failure_threshold)) {
6412 net->dest_state |= SCTP_ADDR_PF;
6413 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6414 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6415 stcb->sctp_ep, stcb, net,
6416 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6417 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6420 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6421 if (net->error_count > net->failure_threshold) {
6422 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6423 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6426 if (net->error_count <= net->failure_threshold) {
6427 net->dest_state |= SCTP_ADDR_REACHABLE;
6428 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6432 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6433 net->failure_threshold = thlds->spt_pathmaxrxt;
6434 net->pf_threshold = thlds->spt_pathpfthld;
6435 if (net->dest_state & SCTP_ADDR_PF) {
6436 if ((net->error_count > net->failure_threshold) ||
6437 (net->error_count <= net->pf_threshold)) {
6438 net->dest_state &= ~SCTP_ADDR_PF;
6441 if ((net->error_count > net->pf_threshold) &&
6442 (net->error_count <= net->failure_threshold)) {
6443 net->dest_state |= SCTP_ADDR_PF;
6444 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6445 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6446 stcb->sctp_ep, stcb, net,
6447 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6448 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6451 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6452 if (net->error_count > net->failure_threshold) {
6453 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6454 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6457 if (net->error_count <= net->failure_threshold) {
6458 net->dest_state |= SCTP_ADDR_REACHABLE;
6459 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6463 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6464 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6466 SCTP_TCB_UNLOCK(stcb);
6468 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6469 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6470 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6471 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
6472 SCTP_INP_WLOCK(inp);
6473 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6474 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6475 SCTP_INP_WUNLOCK(inp);
6477 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6483 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6485 struct sctp_udpencaps *encaps;
6486 struct sctp_nets *net;
6487 struct sockaddr *addr;
6488 #if defined(INET) && defined(INET6)
6489 struct sockaddr_in sin_store;
6492 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6493 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6495 #if defined(INET) && defined(INET6)
6496 if (encaps->sue_address.ss_family == AF_INET6) {
6497 struct sockaddr_in6 *sin6;
6499 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6500 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6501 in6_sin6_2_sin(&sin_store, sin6);
6502 addr = (struct sockaddr *)&sin_store;
6504 addr = (struct sockaddr *)&encaps->sue_address;
6507 addr = (struct sockaddr *)&encaps->sue_address;
6510 addr = (struct sockaddr *)&encaps->sue_address;
6513 net = sctp_findnet(stcb, addr);
6516 * We increment here since
6517 * sctp_findassociation_ep_addr() wil do a
6518 * decrement if it finds the stcb as long as
6519 * the locked tcb (last argument) is NOT a
6523 SCTP_INP_INCR_REF(inp);
6524 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6526 SCTP_INP_DECR_REF(inp);
6529 if ((stcb != NULL) && (net == NULL)) {
6531 if (addr->sa_family == AF_INET) {
6532 struct sockaddr_in *sin;
6534 sin = (struct sockaddr_in *)addr;
6535 if (sin->sin_addr.s_addr != INADDR_ANY) {
6536 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6537 SCTP_TCB_UNLOCK(stcb);
6544 if (addr->sa_family == AF_INET6) {
6545 struct sockaddr_in6 *sin6;
6547 sin6 = (struct sockaddr_in6 *)addr;
6548 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6549 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6550 SCTP_TCB_UNLOCK(stcb);
6557 error = EAFNOSUPPORT;
6558 SCTP_TCB_UNLOCK(stcb);
6559 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6566 net->port = encaps->sue_port;
6568 stcb->asoc.port = encaps->sue_port;
6570 SCTP_TCB_UNLOCK(stcb);
6572 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6573 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6574 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6575 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
6576 SCTP_INP_WLOCK(inp);
6577 inp->sctp_ep.port = encaps->sue_port;
6578 SCTP_INP_WUNLOCK(inp);
6580 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6586 case SCTP_ECN_SUPPORTED:
6588 struct sctp_assoc_value *av;
6590 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6591 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6596 SCTP_TCB_UNLOCK(stcb);
6598 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6599 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6600 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6601 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6602 SCTP_INP_WLOCK(inp);
6603 if (av->assoc_value == 0) {
6604 inp->ecn_supported = 0;
6606 inp->ecn_supported = 1;
6608 SCTP_INP_WUNLOCK(inp);
6610 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6616 case SCTP_PR_SUPPORTED:
6618 struct sctp_assoc_value *av;
6620 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6621 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6624 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6626 SCTP_TCB_UNLOCK(stcb);
6628 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6629 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6630 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6631 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6632 SCTP_INP_WLOCK(inp);
6633 if (av->assoc_value == 0) {
6634 inp->prsctp_supported = 0;
6636 inp->prsctp_supported = 1;
6638 SCTP_INP_WUNLOCK(inp);
6640 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6646 case SCTP_AUTH_SUPPORTED:
6648 struct sctp_assoc_value *av;
6650 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6651 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6654 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6656 SCTP_TCB_UNLOCK(stcb);
6658 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6659 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6660 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6661 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6662 if ((av->assoc_value == 0) &&
6663 (inp->asconf_supported == 1)) {
6665 * AUTH is required for
6668 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6671 SCTP_INP_WLOCK(inp);
6672 if (av->assoc_value == 0) {
6673 inp->auth_supported = 0;
6675 inp->auth_supported = 1;
6677 SCTP_INP_WUNLOCK(inp);
6680 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6686 case SCTP_ASCONF_SUPPORTED:
6688 struct sctp_assoc_value *av;
6690 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6691 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6694 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6696 SCTP_TCB_UNLOCK(stcb);
6698 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6699 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6700 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6701 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6702 if ((av->assoc_value != 0) &&
6703 (inp->auth_supported == 0)) {
6705 * AUTH is required for
6708 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6711 SCTP_INP_WLOCK(inp);
6712 if (av->assoc_value == 0) {
6713 inp->asconf_supported = 0;
6714 sctp_auth_delete_chunk(SCTP_ASCONF,
6715 inp->sctp_ep.local_auth_chunks);
6716 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6717 inp->sctp_ep.local_auth_chunks);
6719 inp->asconf_supported = 1;
6720 sctp_auth_add_chunk(SCTP_ASCONF,
6721 inp->sctp_ep.local_auth_chunks);
6722 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6723 inp->sctp_ep.local_auth_chunks);
6725 SCTP_INP_WUNLOCK(inp);
6728 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6734 case SCTP_RECONFIG_SUPPORTED:
6736 struct sctp_assoc_value *av;
6738 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6739 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6744 SCTP_TCB_UNLOCK(stcb);
6746 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6747 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6748 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6749 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6750 SCTP_INP_WLOCK(inp);
6751 if (av->assoc_value == 0) {
6752 inp->reconfig_supported = 0;
6754 inp->reconfig_supported = 1;
6756 SCTP_INP_WUNLOCK(inp);
6758 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6764 case SCTP_NRSACK_SUPPORTED:
6766 struct sctp_assoc_value *av;
6768 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6769 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6772 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6774 SCTP_TCB_UNLOCK(stcb);
6776 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6777 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6778 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6779 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6780 SCTP_INP_WLOCK(inp);
6781 if (av->assoc_value == 0) {
6782 inp->nrsack_supported = 0;
6784 inp->nrsack_supported = 1;
6786 SCTP_INP_WUNLOCK(inp);
6788 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6794 case SCTP_PKTDROP_SUPPORTED:
6796 struct sctp_assoc_value *av;
6798 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6799 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6802 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6804 SCTP_TCB_UNLOCK(stcb);
6806 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6807 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6808 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6809 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6810 SCTP_INP_WLOCK(inp);
6811 if (av->assoc_value == 0) {
6812 inp->pktdrop_supported = 0;
6814 inp->pktdrop_supported = 1;
6816 SCTP_INP_WUNLOCK(inp);
6818 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6826 struct sctp_assoc_value *av;
6827 struct sctp_nets *net;
6829 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6830 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6833 stcb->asoc.max_cwnd = av->assoc_value;
6834 if (stcb->asoc.max_cwnd > 0) {
6835 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6836 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6837 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6838 net->cwnd = stcb->asoc.max_cwnd;
6839 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6840 net->cwnd = net->mtu - sizeof(struct sctphdr);
6845 SCTP_TCB_UNLOCK(stcb);
6847 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6848 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6849 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6850 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6851 SCTP_INP_WLOCK(inp);
6852 inp->max_cwnd = av->assoc_value;
6853 SCTP_INP_WUNLOCK(inp);
6855 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6862 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6863 error = ENOPROTOOPT;
6865 } /* end switch (opt) */
6870 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6872 struct epoch_tracker et;
6873 struct sctp_inpcb *inp;
6874 void *optval = NULL;
6879 if ((sopt->sopt_level == SOL_SOCKET) &&
6880 (sopt->sopt_name == SO_SETFIB)) {
6881 inp = (struct sctp_inpcb *)so->so_pcb;
6883 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6886 SCTP_INP_WLOCK(inp);
6887 inp->fibnum = so->so_fibnum;
6888 SCTP_INP_WUNLOCK(inp);
6891 if (sopt->sopt_level != IPPROTO_SCTP) {
6892 /* wrong proto level... send back up to IP */
6894 if (INP_CHECK_SOCKAF(so, AF_INET6))
6895 error = ip6_ctloutput(so, sopt);
6897 #if defined(INET) && defined(INET6)
6901 error = ip_ctloutput(so, sopt);
6905 optsize = sopt->sopt_valsize;
6906 if (optsize > SCTP_SOCKET_OPTION_LIMIT) {
6907 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6911 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6912 if (optval == NULL) {
6913 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6916 error = sooptcopyin(sopt, optval, optsize, optsize);
6918 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6922 p = (void *)sopt->sopt_td;
6923 if (sopt->sopt_dir == SOPT_SET) {
6924 NET_EPOCH_ENTER(et);
6925 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6927 } else if (sopt->sopt_dir == SOPT_GET) {
6928 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6930 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6933 if ((error == 0) && (optval != NULL)) {
6934 error = sooptcopyout(sopt, optval, optsize);
6935 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6936 } else if (optval != NULL) {
6937 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6945 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6947 struct epoch_tracker et;
6949 int create_lock_on = 0;
6951 struct sctp_inpcb *inp;
6952 struct sctp_tcb *stcb = NULL;
6954 inp = (struct sctp_inpcb *)so->so_pcb;
6956 /* I made the same as TCP since we are not setup? */
6957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6958 return (ECONNRESET);
6961 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6965 switch (addr->sa_family) {
6969 struct sockaddr_in6 *sin6;
6971 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6972 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6975 sin6 = (struct sockaddr_in6 *)addr;
6976 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6->sin6_addr)) != 0) {
6977 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6986 struct sockaddr_in *sin;
6988 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6992 sin = (struct sockaddr_in *)addr;
6993 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sin->sin_addr)) != 0) {
6994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7001 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
7002 return (EAFNOSUPPORT);
7004 SCTP_INP_INCR_REF(inp);
7005 SCTP_ASOC_CREATE_LOCK(inp);
7007 NET_EPOCH_ENTER(et);
7009 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
7010 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
7011 /* Should I really unlock ? */
7012 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
7017 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
7018 (addr->sa_family == AF_INET6)) {
7019 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7024 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
7025 SCTP_PCB_FLAGS_UNBOUND) {
7026 /* Bind a ephemeral port */
7027 error = sctp_inpcb_bind(so, NULL, NULL, p);
7032 /* Now do we connect? */
7033 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
7034 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
7035 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7039 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7040 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7041 /* We are already connected AND the TCP model */
7042 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7046 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7047 SCTP_INP_RLOCK(inp);
7048 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7049 SCTP_INP_RUNLOCK(inp);
7052 * We increment here since sctp_findassociation_ep_addr()
7053 * will do a decrement if it finds the stcb as long as the
7054 * locked tcb (last argument) is NOT a TCB.. aka NULL.
7056 SCTP_INP_INCR_REF(inp);
7057 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7059 SCTP_INP_DECR_REF(inp);
7061 SCTP_TCB_UNLOCK(stcb);
7065 /* Already have or am bring up an association */
7066 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7071 vrf_id = inp->def_vrf_id;
7072 /* We are GOOD to go */
7073 stcb = sctp_aloc_assoc_connected(inp, addr, &error, 0, 0, vrf_id,
7074 inp->sctp_ep.pre_open_stream_count,
7075 inp->sctp_ep.port, p,
7076 SCTP_INITIALIZE_AUTH_PARAMS);
7078 /* Gak! no memory */
7081 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7082 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7084 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7085 SCTP_TCB_UNLOCK(stcb);
7088 if (create_lock_on) {
7089 SCTP_ASOC_CREATE_UNLOCK(inp);
7091 SCTP_INP_DECR_REF(inp);
7097 sctp_listen(struct socket *so, int backlog, struct thread *p)
7100 * Note this module depends on the protocol processing being called
7101 * AFTER any socket level flags and backlog are applied to the
7102 * socket. The traditional way that the socket flags are applied is
7103 * AFTER protocol processing. We have made a change to the
7104 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7105 * place if the socket API for SCTP is to work properly.
7109 struct sctp_inpcb *inp;
7111 inp = (struct sctp_inpcb *)so->so_pcb;
7113 /* I made the same as TCP since we are not setup? */
7114 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7115 return (ECONNRESET);
7117 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7118 /* See if we have a listener */
7119 struct sctp_inpcb *tinp;
7120 union sctp_sockstore store;
7122 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7124 struct sctp_laddr *laddr;
7126 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7127 memcpy(&store, &laddr->ifa->address, sizeof(store));
7128 switch (store.sa.sa_family) {
7131 store.sin.sin_port = inp->sctp_lport;
7136 store.sin6.sin6_port = inp->sctp_lport;
7142 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7143 if (tinp && (tinp != inp) &&
7144 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7145 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7146 (SCTP_IS_LISTENING(tinp))) {
7148 * we have a listener already and
7151 SCTP_INP_DECR_REF(tinp);
7152 return (EADDRINUSE);
7154 SCTP_INP_DECR_REF(tinp);
7158 /* Setup a local addr bound all */
7159 memset(&store, 0, sizeof(store));
7161 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7162 store.sa.sa_family = AF_INET6;
7163 store.sa.sa_len = sizeof(struct sockaddr_in6);
7167 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7168 store.sa.sa_family = AF_INET;
7169 store.sa.sa_len = sizeof(struct sockaddr_in);
7172 switch (store.sa.sa_family) {
7175 store.sin.sin_port = inp->sctp_lport;
7180 store.sin6.sin6_port = inp->sctp_lport;
7186 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7187 if (tinp && (tinp != inp) &&
7188 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7189 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7190 (SCTP_IS_LISTENING(tinp))) {
7192 * we have a listener already and its not
7195 SCTP_INP_DECR_REF(tinp);
7196 return (EADDRINUSE);
7198 SCTP_INP_DECR_REF(tinp);
7202 SCTP_INP_INFO_WLOCK();
7203 SCTP_INP_WLOCK(inp);
7204 #ifdef SCTP_LOCK_LOGGING
7205 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7206 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7209 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7210 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7212 * The unlucky case - We are in the tcp pool with this guy.
7213 * - Someone else is in the main inp slot. - We must move
7214 * this guy (the listener) to the main slot - We must then
7215 * move the guy that was listener to the TCP Pool.
7217 if (sctp_swap_inpcb_for_listen(inp)) {
7219 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7224 error = solisten_proto_check(so);
7229 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7230 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7232 solisten_proto_abort(so);
7234 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7237 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7238 if ((error = sctp_inpcb_bind_locked(inp, NULL, NULL, p))) {
7240 solisten_proto_abort(so);
7241 /* bind error, probably perm */
7245 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7246 solisten_proto(so, backlog);
7248 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7250 solisten_proto_abort(so);
7253 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7255 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7259 SCTP_INP_WUNLOCK(inp);
7260 SCTP_INP_INFO_WUNLOCK();
7264 static int sctp_defered_wakeup_cnt = 0;
7267 sctp_accept(struct socket *so, struct sockaddr **addr)
7269 struct sctp_tcb *stcb;
7270 struct sctp_inpcb *inp;
7271 union sctp_sockstore store;
7275 inp = (struct sctp_inpcb *)so->so_pcb;
7278 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7279 return (ECONNRESET);
7281 SCTP_INP_WLOCK(inp);
7282 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7283 SCTP_INP_WUNLOCK(inp);
7284 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7285 return (EOPNOTSUPP);
7287 if (so->so_state & SS_ISDISCONNECTED) {
7288 SCTP_INP_WUNLOCK(inp);
7289 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7290 return (ECONNABORTED);
7292 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7294 SCTP_INP_WUNLOCK(inp);
7295 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7296 return (ECONNRESET);
7298 SCTP_TCB_LOCK(stcb);
7299 store = stcb->asoc.primary_destination->ro._l_addr;
7300 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7301 /* Wake any delayed sleep action */
7302 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7303 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7304 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7305 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7306 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7307 if (sowriteable(inp->sctp_socket)) {
7308 sowwakeup_locked(inp->sctp_socket);
7310 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7313 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7314 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7315 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7316 if (soreadable(inp->sctp_socket)) {
7317 sctp_defered_wakeup_cnt++;
7318 sorwakeup_locked(inp->sctp_socket);
7320 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7324 SCTP_INP_WUNLOCK(inp);
7325 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7326 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7327 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7329 SCTP_TCB_UNLOCK(stcb);
7331 switch (store.sa.sa_family) {
7335 struct sockaddr_in *sin;
7337 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7340 sin->sin_family = AF_INET;
7341 sin->sin_len = sizeof(*sin);
7342 sin->sin_port = store.sin.sin_port;
7343 sin->sin_addr = store.sin.sin_addr;
7344 *addr = (struct sockaddr *)sin;
7351 struct sockaddr_in6 *sin6;
7353 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7356 sin6->sin6_family = AF_INET6;
7357 sin6->sin6_len = sizeof(*sin6);
7358 sin6->sin6_port = store.sin6.sin6_port;
7359 sin6->sin6_addr = store.sin6.sin6_addr;
7360 if ((error = sa6_recoverscope(sin6)) != 0) {
7361 SCTP_FREE_SONAME(sin6);
7364 *addr = (struct sockaddr *)sin6;
7377 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7379 struct sockaddr_in *sin;
7381 struct sctp_inpcb *inp;
7382 struct sctp_ifa *sctp_ifa;
7385 * Do the malloc first in case it blocks.
7387 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7390 sin->sin_family = AF_INET;
7391 sin->sin_len = sizeof(*sin);
7392 inp = (struct sctp_inpcb *)so->so_pcb;
7394 SCTP_FREE_SONAME(sin);
7395 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7396 return (ECONNRESET);
7398 SCTP_INP_RLOCK(inp);
7399 sin->sin_port = inp->sctp_lport;
7400 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7401 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7402 struct sctp_tcb *stcb;
7403 struct sockaddr_in *sin_a;
7404 struct sctp_nets *net;
7407 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7413 SCTP_TCB_LOCK(stcb);
7414 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7415 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7417 /* this will make coverity happy */
7420 if (sin_a->sin_family == AF_INET) {
7425 if ((!fnd) || (sin_a == NULL)) {
7427 SCTP_TCB_UNLOCK(stcb);
7431 vrf_id = inp->def_vrf_id;
7432 sctp_ifa = sctp_source_address_selection(inp,
7434 (sctp_route_t *)&net->ro,
7437 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7438 sctp_free_ifa(sctp_ifa);
7440 SCTP_TCB_UNLOCK(stcb);
7442 /* For the bound all case you get back 0 */
7444 sin->sin_addr.s_addr = 0;
7448 /* Take the first IPv4 address in the list */
7449 struct sctp_laddr *laddr;
7452 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7453 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7454 struct sockaddr_in *sin_a;
7456 sin_a = &laddr->ifa->address.sin;
7457 sin->sin_addr = sin_a->sin_addr;
7463 SCTP_FREE_SONAME(sin);
7464 SCTP_INP_RUNLOCK(inp);
7465 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7469 SCTP_INP_RUNLOCK(inp);
7470 (*addr) = (struct sockaddr *)sin;
7475 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7477 struct sockaddr_in *sin;
7479 struct sockaddr_in *sin_a;
7480 struct sctp_inpcb *inp;
7481 struct sctp_tcb *stcb;
7482 struct sctp_nets *net;
7484 /* Do the malloc first in case it blocks. */
7485 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7488 sin->sin_family = AF_INET;
7489 sin->sin_len = sizeof(*sin);
7491 inp = (struct sctp_inpcb *)so->so_pcb;
7492 if ((inp == NULL) ||
7493 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7494 /* UDP type and listeners will drop out here */
7495 SCTP_FREE_SONAME(sin);
7496 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7499 SCTP_INP_RLOCK(inp);
7500 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7502 SCTP_TCB_LOCK(stcb);
7504 SCTP_INP_RUNLOCK(inp);
7506 SCTP_FREE_SONAME(sin);
7507 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7508 return (ECONNRESET);
7511 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7512 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7513 if (sin_a->sin_family == AF_INET) {
7515 sin->sin_port = stcb->rport;
7516 sin->sin_addr = sin_a->sin_addr;
7520 SCTP_TCB_UNLOCK(stcb);
7522 /* No IPv4 address */
7523 SCTP_FREE_SONAME(sin);
7524 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7527 (*addr) = (struct sockaddr *)sin;
7531 struct pr_usrreqs sctp_usrreqs = {
7532 .pru_abort = sctp_abort,
7533 .pru_accept = sctp_accept,
7534 .pru_attach = sctp_attach,
7535 .pru_bind = sctp_bind,
7536 .pru_connect = sctp_connect,
7537 .pru_control = in_control,
7538 .pru_close = sctp_close,
7539 .pru_detach = sctp_close,
7540 .pru_sopoll = sopoll_generic,
7541 .pru_flush = sctp_flush,
7542 .pru_disconnect = sctp_disconnect,
7543 .pru_listen = sctp_listen,
7544 .pru_peeraddr = sctp_peeraddr,
7545 .pru_send = sctp_sendm,
7546 .pru_shutdown = sctp_shutdown,
7547 .pru_sockaddr = sctp_ingetaddr,
7548 .pru_sosend = sctp_sosend,
7549 .pru_soreceive = sctp_soreceive