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(struct icmp *icmp)
265 struct ip *inner_ip, *outer_ip;
267 struct sctp_inpcb *inp;
268 struct sctp_tcb *stcb;
269 struct sctp_nets *net;
270 struct sctp_init_chunk *ch;
271 struct sockaddr_in src, dst;
273 if (icmp_errmap(icmp) == 0)
276 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
277 inner_ip = &icmp->icmp_ip;
278 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
279 memset(&src, 0, sizeof(struct sockaddr_in));
280 src.sin_family = AF_INET;
281 src.sin_len = sizeof(struct sockaddr_in);
282 src.sin_port = sh->src_port;
283 src.sin_addr = inner_ip->ip_src;
284 memset(&dst, 0, sizeof(struct sockaddr_in));
285 dst.sin_family = AF_INET;
286 dst.sin_len = sizeof(struct sockaddr_in);
287 dst.sin_port = sh->dest_port;
288 dst.sin_addr = inner_ip->ip_dst;
290 * 'dst' holds the dest of the packet that failed to be sent. 'src'
291 * holds our local endpoint address. Thus we reverse the dst and the
296 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
297 (struct sockaddr *)&src,
300 if ((stcb != NULL) &&
303 /* Check the verification tag */
304 if (ntohl(sh->v_tag) != 0) {
306 * This must be the verification tag used for
307 * sending out packets. We don't consider packets
308 * reflecting the verification tag.
310 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
311 SCTP_TCB_UNLOCK(stcb);
315 if (ntohs(outer_ip->ip_len) >=
317 8 + (inner_ip->ip_hl << 2) + 20) {
319 * In this case we can check if we got an
320 * INIT chunk and if the initiate tag
323 ch = (struct sctp_init_chunk *)(sh + 1);
324 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
325 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
326 SCTP_TCB_UNLOCK(stcb);
330 SCTP_TCB_UNLOCK(stcb);
334 sctp_notify(inp, stcb, net,
337 ntohs(inner_ip->ip_len),
338 (uint32_t)ntohs(icmp->icmp_nextmtu));
340 if ((stcb == NULL) && (inp != NULL)) {
341 /* reduce ref-count */
343 SCTP_INP_DECR_REF(inp);
344 SCTP_INP_WUNLOCK(inp);
347 SCTP_TCB_UNLOCK(stcb);
354 sctp_getcred(SYSCTL_HANDLER_ARGS)
357 struct sockaddr_in addrs[2];
358 struct sctp_inpcb *inp;
359 struct sctp_nets *net;
360 struct sctp_tcb *stcb;
364 /* FIX, for non-bsd is this right? */
365 vrf_id = SCTP_DEFAULT_VRFID;
367 error = priv_check(req->td, PRIV_NETINET_GETCRED);
372 error = SYSCTL_IN(req, addrs, sizeof(addrs));
376 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
378 &inp, &net, 1, vrf_id);
379 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
380 if ((inp != NULL) && (stcb == NULL)) {
381 /* reduce ref-count */
383 SCTP_INP_DECR_REF(inp);
387 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
391 SCTP_TCB_UNLOCK(stcb);
393 * We use the write lock here, only since in the error leg we need
394 * it. If we used RLOCK, then we would have to
395 * wlock/decr/unlock/rlock. Which in theory could create a hole.
396 * Better to use higher wlock.
400 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
402 SCTP_INP_WUNLOCK(inp);
405 cru2x(inp->sctp_socket->so_cred, &xuc);
406 SCTP_INP_WUNLOCK(inp);
407 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
412 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred,
413 CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
414 0, 0, sctp_getcred, "S,ucred",
415 "Get the ucred of a SCTP connection");
419 sctp_abort(struct socket *so)
421 struct epoch_tracker et;
422 struct sctp_inpcb *inp;
424 inp = (struct sctp_inpcb *)so->so_pcb;
431 #ifdef SCTP_LOG_CLOSING
432 sctp_log_closing(inp, NULL, 17);
434 if (((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0)) {
435 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP;
436 #ifdef SCTP_LOG_CLOSING
437 sctp_log_closing(inp, NULL, 16);
439 SCTP_INP_WUNLOCK(inp);
440 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
441 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
443 KASSERT(!SOLISTENING(so),
444 ("sctp_abort: called on listening socket %p", so));
445 SCTP_SB_CLEAR(so->so_snd);
446 SCTP_SB_CLEAR(so->so_rcv);
447 /* Now null out the reference, we are completely detached. */
451 SCTP_INP_WUNLOCK(inp);
457 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
459 struct sctp_inpcb *inp;
460 struct inpcb *ip_inp;
462 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
464 inp = (struct sctp_inpcb *)so->so_pcb;
466 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
469 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
470 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
475 error = sctp_inpcb_alloc(so, vrf_id);
479 inp = (struct sctp_inpcb *)so->so_pcb;
481 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
482 ip_inp = &inp->ip_inp.inp;
483 ip_inp->inp_vflag |= INP_IPV4;
484 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
485 SCTP_INP_WUNLOCK(inp);
490 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
492 struct sctp_inpcb *inp;
494 inp = (struct sctp_inpcb *)so->so_pcb;
496 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
500 if ((addr->sa_family != AF_INET) ||
501 (addr->sa_len != sizeof(struct sockaddr_in))) {
502 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
506 return (sctp_inpcb_bind(so, addr, NULL, p));
511 sctp_close(struct socket *so)
513 struct epoch_tracker et;
514 struct sctp_inpcb *inp;
516 inp = (struct sctp_inpcb *)so->so_pcb;
521 * Inform all the lower layer assoc that we are done.
525 #ifdef SCTP_LOG_CLOSING
526 sctp_log_closing(inp, NULL, 17);
528 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
529 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP;
530 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
531 (SCTP_SBAVAIL(&so->so_rcv) > 0)) {
532 #ifdef SCTP_LOG_CLOSING
533 sctp_log_closing(inp, NULL, 13);
535 SCTP_INP_WUNLOCK(inp);
536 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
537 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
539 #ifdef SCTP_LOG_CLOSING
540 sctp_log_closing(inp, NULL, 14);
542 SCTP_INP_WUNLOCK(inp);
543 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
544 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
547 * The socket is now detached, no matter what the state of
548 * the SCTP association.
551 if (!SOLISTENING(so)) {
552 SCTP_SB_CLEAR(so->so_snd);
553 SCTP_SB_CLEAR(so->so_rcv);
555 /* Now null out the reference, we are completely detached. */
559 SCTP_INP_WUNLOCK(inp);
565 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
566 struct mbuf *control, struct thread *p);
569 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
570 struct mbuf *control, struct thread *p)
572 struct sctp_inpcb *inp;
575 inp = (struct sctp_inpcb *)so->so_pcb;
578 sctp_m_freem(control);
581 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
585 /* Got to have an to address if we are NOT a connected socket */
586 if ((addr == NULL) &&
587 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
588 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
594 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
595 error = EDESTADDRREQ;
596 } else if (addr->sa_family != AF_INET) {
597 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
598 error = EAFNOSUPPORT;
599 } else if (addr->sa_len != sizeof(struct sockaddr_in)) {
600 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
606 sctp_m_freem(control);
612 /* now what about control */
615 sctp_m_freem(inp->control);
618 inp->control = control;
622 SCTP_BUF_NEXT(inp->pkt_last) = m;
625 inp->pkt_last = inp->pkt = m;
628 /* FreeBSD uses a flag passed */
629 ((flags & PRUS_MORETOCOME) == 0)
632 * note with the current version this code will only be used
633 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
634 * re-defining sosend to use the sctp_sosend. One can
635 * optionally switch back to this code (by changing back the
636 * definitions) but this is not advisable. This code is used
637 * by FreeBSD when sending a file with sendfile() though.
639 struct epoch_tracker et;
643 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
654 sctp_disconnect(struct socket *so)
656 struct sctp_inpcb *inp;
658 inp = (struct sctp_inpcb *)so->so_pcb;
660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
664 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
665 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
666 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
668 SCTP_INP_RUNLOCK(inp);
671 struct epoch_tracker et;
672 struct sctp_association *asoc;
673 struct sctp_tcb *stcb;
675 stcb = LIST_FIRST(&inp->sctp_asoc_list);
677 SCTP_INP_RUNLOCK(inp);
678 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
683 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
684 /* We are about to be freed, out of here */
685 SCTP_TCB_UNLOCK(stcb);
686 SCTP_INP_RUNLOCK(inp);
690 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
691 (SCTP_SBAVAIL(&so->so_rcv) > 0)) {
692 if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) {
693 /* Left with Data unread */
696 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
697 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
698 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
700 SCTP_INP_RUNLOCK(inp);
701 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
702 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
703 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
705 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
706 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
707 /* No unlock tcb assoc is gone */
711 if (TAILQ_EMPTY(&asoc->send_queue) &&
712 TAILQ_EMPTY(&asoc->sent_queue) &&
713 (asoc->stream_queue_cnt == 0)) {
714 /* there is nothing queued to send, so done */
715 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
718 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) &&
719 (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
720 /* only send SHUTDOWN 1st time thru */
721 struct sctp_nets *netp;
723 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
724 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
725 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
727 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
728 sctp_stop_timers_for_shutdown(stcb);
729 if (stcb->asoc.alternate) {
730 netp = stcb->asoc.alternate;
732 netp = stcb->asoc.primary_destination;
734 sctp_send_shutdown(stcb, netp);
735 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
736 stcb->sctp_ep, stcb, netp);
737 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
738 stcb->sctp_ep, stcb, NULL);
739 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
743 * we still got (or just got) data to send,
744 * so set SHUTDOWN_PENDING
747 * XXX sockets draft says that SCTP_EOF
748 * should be sent with no data. currently,
749 * we will allow user data to be sent first
750 * and move to SHUTDOWN-PENDING
752 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
753 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
754 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
756 if (TAILQ_EMPTY(&asoc->send_queue) &&
757 TAILQ_EMPTY(&asoc->sent_queue) &&
758 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
762 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
763 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
764 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
765 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
766 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
767 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
768 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
770 SCTP_INP_RUNLOCK(inp);
771 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
772 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
776 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
779 soisdisconnecting(so);
781 SCTP_TCB_UNLOCK(stcb);
782 SCTP_INP_RUNLOCK(inp);
787 /* UDP model does not support this */
788 SCTP_INP_RUNLOCK(inp);
789 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
795 sctp_flush(struct socket *so, int how)
798 * We will just clear out the values and let subsequent close clear
799 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
800 * they will not be able to read the data, the socket will block
801 * that from happening.
803 struct sctp_inpcb *inp;
805 inp = (struct sctp_inpcb *)so->so_pcb;
807 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
811 /* For the 1 to many model this does nothing */
812 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
813 SCTP_INP_RUNLOCK(inp);
816 SCTP_INP_RUNLOCK(inp);
817 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
819 * First make sure the sb will be happy, we don't use these
820 * except maybe the count
823 SCTP_INP_READ_LOCK(inp);
824 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
825 SCTP_INP_READ_UNLOCK(inp);
826 SCTP_INP_WUNLOCK(inp);
828 KASSERT(!SOLISTENING(so),
829 ("sctp_flush: called on listening socket %p", so));
830 SCTP_SB_CLEAR(so->so_rcv);
833 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
835 * First make sure the sb will be happy, we don't use these
836 * except maybe the count
839 KASSERT(!SOLISTENING(so),
840 ("sctp_flush: called on listening socket %p", so));
841 SCTP_SB_CLEAR(so->so_snd);
848 sctp_shutdown(struct socket *so)
850 struct sctp_inpcb *inp;
852 inp = (struct sctp_inpcb *)so->so_pcb;
854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
858 /* For UDP model this is a invalid call */
859 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
860 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
861 /* Restore the flags that the soshutdown took away. */
862 SOCKBUF_LOCK(&so->so_rcv);
863 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
864 SOCKBUF_UNLOCK(&so->so_rcv);
865 /* This proc will wakeup for read and do nothing (I hope) */
866 SCTP_INP_RUNLOCK(inp);
867 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
871 * Ok, if we reach here its the TCP model and it is either a
872 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
875 struct epoch_tracker et;
876 struct sctp_tcb *stcb;
877 struct sctp_association *asoc;
878 struct sctp_nets *netp;
881 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
882 SCTP_INP_RUNLOCK(inp);
887 stcb = LIST_FIRST(&inp->sctp_asoc_list);
890 * Ok, we hit the case that the shutdown call was
891 * made after an abort or something. Nothing to do
894 SCTP_INP_RUNLOCK(inp);
899 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
900 SCTP_TCB_UNLOCK(stcb);
901 SCTP_INP_RUNLOCK(inp);
904 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) &&
905 (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) &&
906 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) {
908 * If we are not in or before ESTABLISHED, there is
909 * no protocol action required.
911 SCTP_TCB_UNLOCK(stcb);
912 SCTP_INP_RUNLOCK(inp);
916 if (stcb->asoc.alternate) {
917 netp = stcb->asoc.alternate;
919 netp = stcb->asoc.primary_destination;
921 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) &&
922 TAILQ_EMPTY(&asoc->send_queue) &&
923 TAILQ_EMPTY(&asoc->sent_queue) &&
924 (asoc->stream_queue_cnt == 0)) {
925 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
928 /* there is nothing queued to send, so I'm done... */
929 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
930 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
931 sctp_stop_timers_for_shutdown(stcb);
932 sctp_send_shutdown(stcb, netp);
933 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
934 stcb->sctp_ep, stcb, netp);
935 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
936 stcb->sctp_ep, stcb, NULL);
939 * We still got (or just got) data to send, so set
942 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
943 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
944 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
946 if (TAILQ_EMPTY(&asoc->send_queue) &&
947 TAILQ_EMPTY(&asoc->sent_queue) &&
948 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
952 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
953 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
954 SCTP_INP_RUNLOCK(inp);
955 sctp_abort_an_association(stcb->sctp_ep, stcb,
956 op_err, false, SCTP_SO_LOCKED);
962 * XXX: Why do this in the case where we have still data
965 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
966 SCTP_TCB_UNLOCK(stcb);
967 SCTP_INP_RUNLOCK(inp);
974 * copies a "user" presentable address and removes embedded scope, etc.
975 * returns 0 on success, 1 on error
978 sctp_fill_user_address(struct sockaddr *dst, struct sockaddr *src)
981 struct sockaddr_in6 lsa6;
983 src = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)src,
986 memcpy(dst, src, src->sa_len);
991 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
992 struct sctp_tcb *stcb,
994 struct sockaddr *addr,
997 struct sctp_ifn *sctp_ifn;
998 struct sctp_ifa *sctp_ifa;
1002 int ipv4_local_scope, ipv4_addr_legal;
1005 int local_scope, site_scope, ipv6_addr_legal;
1007 struct sctp_vrf *vrf;
1009 SCTP_IPI_ADDR_LOCK_ASSERT();
1015 /* Turn on all the appropriate scope */
1016 loopback_scope = stcb->asoc.scope.loopback_scope;
1018 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1019 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1022 local_scope = stcb->asoc.scope.local_scope;
1023 site_scope = stcb->asoc.scope.site_scope;
1024 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1027 /* Use generic values for endpoints. */
1030 ipv4_local_scope = 1;
1036 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1038 ipv6_addr_legal = 1;
1041 if (SCTP_IPV6_V6ONLY(inp)) {
1042 ipv4_addr_legal = 0;
1044 ipv4_addr_legal = 1;
1049 ipv6_addr_legal = 0;
1052 ipv4_addr_legal = 1;
1056 vrf = sctp_find_vrf(vrf_id);
1060 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1061 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1062 if ((loopback_scope == 0) &&
1063 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1064 /* Skip loopback if loopback_scope not set */
1067 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1070 * For the BOUND-ALL case, the list
1071 * associated with a TCB is Always
1072 * considered a reverse list.. i.e.
1073 * it lists addresses that are NOT
1074 * part of the association. If this
1075 * is one of those we must skip it.
1077 if (sctp_is_addr_restricted(stcb,
1082 switch (sctp_ifa->address.sa.sa_family) {
1085 if (ipv4_addr_legal) {
1086 struct sockaddr_in *sin;
1088 sin = &sctp_ifa->address.sin;
1089 if (sin->sin_addr.s_addr == 0) {
1097 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1098 &sin->sin_addr) != 0) {
1101 if ((ipv4_local_scope == 0) &&
1102 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1106 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1107 if (actual + sizeof(struct sockaddr_in6) > limit) {
1110 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)addr);
1111 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1112 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1113 actual += sizeof(struct sockaddr_in6);
1116 if (actual + sizeof(struct sockaddr_in) > limit) {
1119 memcpy(addr, sin, sizeof(struct sockaddr_in));
1120 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1121 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in));
1122 actual += sizeof(struct sockaddr_in);
1133 if (ipv6_addr_legal) {
1134 struct sockaddr_in6 *sin6;
1136 sin6 = &sctp_ifa->address.sin6;
1137 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1145 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1146 &sin6->sin6_addr) != 0) {
1149 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1150 if (local_scope == 0)
1152 if (sin6->sin6_scope_id == 0) {
1153 if (sa6_recoverscope(sin6) != 0)
1166 if ((site_scope == 0) &&
1167 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1170 if (actual + sizeof(struct sockaddr_in6) > limit) {
1173 memcpy(addr, sin6, sizeof(struct sockaddr_in6));
1174 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1175 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1176 actual += sizeof(struct sockaddr_in6);
1189 struct sctp_laddr *laddr;
1192 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1194 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1198 sa_len = laddr->ifa->address.sa.sa_len;
1199 if (actual + sa_len > limit) {
1202 if (sctp_fill_user_address(addr, &laddr->ifa->address.sa))
1204 switch (laddr->ifa->address.sa.sa_family) {
1207 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1212 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1219 addr = (struct sockaddr *)((caddr_t)addr + sa_len);
1227 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1228 struct sctp_tcb *stcb,
1230 struct sockaddr *addr)
1234 SCTP_IPI_ADDR_RLOCK();
1235 /* fill up addresses for the endpoint's default vrf */
1236 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, addr,
1238 SCTP_IPI_ADDR_RUNLOCK();
1243 sctp_max_size_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1245 struct sctp_vrf *vrf;
1249 * In both sub-set bound an bound_all cases we return the size of
1250 * the maximum number of addresses that you could get. In reality
1251 * the sub-set bound may have an exclusion list for a given TCB or
1252 * in the bound-all case a TCB may NOT include the loopback or other
1253 * addresses as well.
1255 SCTP_IPI_ADDR_LOCK_ASSERT();
1256 vrf = sctp_find_vrf(vrf_id);
1261 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1262 struct sctp_ifn *sctp_ifn;
1263 struct sctp_ifa *sctp_ifa;
1265 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1266 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1267 /* Count them if they are the right type */
1268 switch (sctp_ifa->address.sa.sa_family) {
1272 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1273 size += sizeof(struct sockaddr_in6);
1275 size += sizeof(struct sockaddr_in);
1277 size += sizeof(struct sockaddr_in);
1283 size += sizeof(struct sockaddr_in6);
1292 struct sctp_laddr *laddr;
1294 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1295 switch (laddr->ifa->address.sa.sa_family) {
1299 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1300 size += sizeof(struct sockaddr_in6);
1302 size += sizeof(struct sockaddr_in);
1304 size += sizeof(struct sockaddr_in);
1310 size += sizeof(struct sockaddr_in6);
1322 sctp_max_size_addresses(struct sctp_inpcb *inp)
1326 SCTP_IPI_ADDR_RLOCK();
1327 /* Maximum size of all addresses for the endpoint's default VRF */
1328 size = sctp_max_size_addresses_vrf(inp, inp->def_vrf_id);
1329 SCTP_IPI_ADDR_RUNLOCK();
1334 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1335 size_t optsize, void *p, int delay)
1338 int creat_lock_on = 0;
1339 struct sctp_tcb *stcb = NULL;
1340 struct sockaddr *sa;
1341 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1345 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1347 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1348 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1349 /* We are already connected AND the TCP model */
1350 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1351 return (EADDRINUSE);
1354 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1355 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1356 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1360 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1361 SCTP_INP_RLOCK(inp);
1362 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1363 SCTP_INP_RUNLOCK(inp);
1366 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1369 SCTP_INP_INCR_REF(inp);
1370 SCTP_ASOC_CREATE_LOCK(inp);
1372 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1373 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1374 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1378 totaddrp = (unsigned int *)optval;
1379 totaddr = *totaddrp;
1380 sa = (struct sockaddr *)(totaddrp + 1);
1381 error = sctp_connectx_helper_find(inp, sa, totaddr, &num_v4, &num_v6, (unsigned int)(optsize - sizeof(int)));
1383 /* Already have or am bring up an association */
1384 SCTP_ASOC_CREATE_UNLOCK(inp);
1386 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1390 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1395 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1397 if (SCTP_IPV6_V6ONLY(inp)) {
1399 * if IPV6_V6ONLY flag, ignore connections destined
1400 * to a v4 addr or v4-mapped addr
1402 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1408 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
1409 /* Bind a ephemeral port */
1410 error = sctp_inpcb_bind(so, NULL, NULL, p);
1416 /* FIX ME: do we want to pass in a vrf on the connect call? */
1417 vrf_id = inp->def_vrf_id;
1419 /* We are GOOD to go */
1420 stcb = sctp_aloc_assoc_connected(inp, sa, &error, 0, 0, vrf_id,
1421 inp->sctp_ep.pre_open_stream_count,
1424 SCTP_INITIALIZE_AUTH_PARAMS);
1426 /* Gak! no memory */
1429 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1430 /* move to second address */
1431 switch (sa->sa_family) {
1434 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1439 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1447 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1448 /* Fill in the return id */
1452 a_id = (sctp_assoc_t *)optval;
1453 *a_id = sctp_get_associd(stcb);
1456 /* doing delayed connection */
1457 stcb->asoc.delayed_connection = 1;
1458 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1460 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1461 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1463 SCTP_TCB_UNLOCK(stcb);
1465 if (creat_lock_on) {
1466 SCTP_ASOC_CREATE_UNLOCK(inp);
1468 SCTP_INP_DECR_REF(inp);
1472 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1473 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1474 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1475 SCTP_INP_RLOCK(inp); \
1476 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1478 SCTP_TCB_LOCK(stcb); \
1480 SCTP_INP_RUNLOCK(inp); \
1481 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1482 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1483 if (stcb == NULL) { \
1484 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1493 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1494 if (size < sizeof(type)) { \
1495 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1499 destp = (type *)srcp; \
1504 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1507 struct sctp_inpcb *inp = NULL;
1509 struct sctp_tcb *stcb = NULL;
1511 if (optval == NULL) {
1512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1516 inp = (struct sctp_inpcb *)so->so_pcb;
1518 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1525 case SCTP_AUTOCLOSE:
1526 case SCTP_EXPLICIT_EOR:
1527 case SCTP_AUTO_ASCONF:
1528 case SCTP_DISABLE_FRAGMENTS:
1529 case SCTP_I_WANT_MAPPED_V4_ADDR:
1530 case SCTP_USE_EXT_RCVINFO:
1531 SCTP_INP_RLOCK(inp);
1533 case SCTP_DISABLE_FRAGMENTS:
1534 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1536 case SCTP_I_WANT_MAPPED_V4_ADDR:
1537 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1539 case SCTP_AUTO_ASCONF:
1540 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1541 /* only valid for bound all sockets */
1542 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1544 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1549 case SCTP_EXPLICIT_EOR:
1550 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1553 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1555 case SCTP_USE_EXT_RCVINFO:
1556 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1558 case SCTP_AUTOCLOSE:
1559 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1560 val = sctp_ticks_to_secs(inp->sctp_ep.auto_close_time);
1566 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1567 error = ENOPROTOOPT;
1568 } /* end switch (sopt->sopt_name) */
1569 if (*optsize < sizeof(val)) {
1570 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1574 SCTP_INP_RUNLOCK(inp);
1576 /* return the option value */
1577 *(int *)optval = val;
1578 *optsize = sizeof(val);
1581 case SCTP_GET_PACKET_LOG:
1583 #ifdef SCTP_PACKET_LOGGING
1587 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1588 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1591 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1596 case SCTP_REUSE_PORT:
1600 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1601 /* Can't do this for a 1-m socket */
1605 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1606 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1607 *optsize = sizeof(uint32_t);
1610 case SCTP_PARTIAL_DELIVERY_POINT:
1614 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1615 *value = inp->partial_delivery_point;
1616 *optsize = sizeof(uint32_t);
1619 case SCTP_FRAGMENT_INTERLEAVE:
1623 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1624 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1625 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1626 *value = SCTP_FRAG_LEVEL_2;
1628 *value = SCTP_FRAG_LEVEL_1;
1631 *value = SCTP_FRAG_LEVEL_0;
1633 *optsize = sizeof(uint32_t);
1636 case SCTP_INTERLEAVING_SUPPORTED:
1638 struct sctp_assoc_value *av;
1640 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1641 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1644 av->assoc_value = stcb->asoc.idata_supported;
1645 SCTP_TCB_UNLOCK(stcb);
1647 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1648 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1649 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1650 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1651 SCTP_INP_RLOCK(inp);
1652 if (inp->idata_supported) {
1653 av->assoc_value = 1;
1655 av->assoc_value = 0;
1657 SCTP_INP_RUNLOCK(inp);
1659 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1664 *optsize = sizeof(struct sctp_assoc_value);
1668 case SCTP_CMT_ON_OFF:
1670 struct sctp_assoc_value *av;
1672 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1673 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1675 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1676 SCTP_TCB_UNLOCK(stcb);
1678 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1679 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1680 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1681 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1682 SCTP_INP_RLOCK(inp);
1683 av->assoc_value = inp->sctp_cmt_on_off;
1684 SCTP_INP_RUNLOCK(inp);
1686 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1691 *optsize = sizeof(struct sctp_assoc_value);
1695 case SCTP_PLUGGABLE_CC:
1697 struct sctp_assoc_value *av;
1699 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1700 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1702 av->assoc_value = stcb->asoc.congestion_control_module;
1703 SCTP_TCB_UNLOCK(stcb);
1705 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1706 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1707 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1708 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1709 SCTP_INP_RLOCK(inp);
1710 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1711 SCTP_INP_RUNLOCK(inp);
1713 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1718 *optsize = sizeof(struct sctp_assoc_value);
1722 case SCTP_CC_OPTION:
1724 struct sctp_cc_option *cc_opt;
1726 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1727 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1731 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1734 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1735 *optsize = sizeof(struct sctp_cc_option);
1737 SCTP_TCB_UNLOCK(stcb);
1741 case SCTP_STREAM_SCHEDULER:
1743 struct sctp_assoc_value *av;
1745 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1746 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1748 av->assoc_value = stcb->asoc.stream_scheduling_module;
1749 SCTP_TCB_UNLOCK(stcb);
1751 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1752 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1753 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1754 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1755 SCTP_INP_RLOCK(inp);
1756 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1757 SCTP_INP_RUNLOCK(inp);
1759 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1764 *optsize = sizeof(struct sctp_assoc_value);
1768 case SCTP_STREAM_SCHEDULER_VALUE:
1770 struct sctp_stream_value *av;
1772 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1773 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1775 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1776 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1777 &av->stream_value) < 0)) {
1778 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1781 *optsize = sizeof(struct sctp_stream_value);
1783 SCTP_TCB_UNLOCK(stcb);
1786 * Can't get stream value without
1789 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1794 case SCTP_GET_ADDR_LEN:
1796 struct sctp_assoc_value *av;
1798 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1801 if (av->assoc_value == AF_INET) {
1802 av->assoc_value = sizeof(struct sockaddr_in);
1807 if (av->assoc_value == AF_INET6) {
1808 av->assoc_value = sizeof(struct sockaddr_in6);
1813 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1815 *optsize = sizeof(struct sctp_assoc_value);
1819 case SCTP_GET_ASSOC_NUMBER:
1821 uint32_t *value, cnt;
1823 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1824 SCTP_INP_RLOCK(inp);
1825 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1826 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1827 /* Can't do this for a 1-1 socket */
1829 SCTP_INP_RUNLOCK(inp);
1833 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1836 SCTP_INP_RUNLOCK(inp);
1838 *optsize = sizeof(uint32_t);
1841 case SCTP_GET_ASSOC_ID_LIST:
1843 struct sctp_assoc_ids *ids;
1847 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1848 SCTP_INP_RLOCK(inp);
1849 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1850 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1851 /* Can't do this for a 1-1 socket */
1853 SCTP_INP_RUNLOCK(inp);
1857 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1858 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1860 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1863 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1868 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1872 SCTP_INP_RUNLOCK(inp);
1874 ids->gaids_number_of_ids = at;
1875 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1881 struct sctp_assoc_value *av;
1883 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1884 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1887 av->assoc_value = stcb->asoc.context;
1888 SCTP_TCB_UNLOCK(stcb);
1890 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1891 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1892 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1893 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1894 SCTP_INP_RLOCK(inp);
1895 av->assoc_value = inp->sctp_context;
1896 SCTP_INP_RUNLOCK(inp);
1898 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1903 *optsize = sizeof(struct sctp_assoc_value);
1909 uint32_t *default_vrfid;
1911 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1912 *default_vrfid = inp->def_vrf_id;
1913 *optsize = sizeof(uint32_t);
1916 case SCTP_GET_ASOC_VRF:
1918 struct sctp_assoc_value *id;
1920 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1921 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1926 id->assoc_value = stcb->asoc.vrf_id;
1927 SCTP_TCB_UNLOCK(stcb);
1928 *optsize = sizeof(struct sctp_assoc_value);
1932 case SCTP_GET_VRF_IDS:
1934 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1938 case SCTP_GET_NONCE_VALUES:
1940 struct sctp_get_nonce_values *gnv;
1942 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1943 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1946 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1947 gnv->gn_local_tag = stcb->asoc.my_vtag;
1948 SCTP_TCB_UNLOCK(stcb);
1949 *optsize = sizeof(struct sctp_get_nonce_values);
1951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1956 case SCTP_DELAYED_SACK:
1958 struct sctp_sack_info *sack;
1960 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1961 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1963 sack->sack_delay = stcb->asoc.delayed_ack;
1964 sack->sack_freq = stcb->asoc.sack_freq;
1965 SCTP_TCB_UNLOCK(stcb);
1967 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1968 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1969 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1970 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC))) {
1971 SCTP_INP_RLOCK(inp);
1972 sack->sack_delay = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1973 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
1974 SCTP_INP_RUNLOCK(inp);
1976 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1981 *optsize = sizeof(struct sctp_sack_info);
1985 case SCTP_GET_SNDBUF_USE:
1987 struct sctp_sockstat *ss;
1989 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
1990 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
1993 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
1994 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
1995 stcb->asoc.size_on_all_streams);
1996 SCTP_TCB_UNLOCK(stcb);
1997 *optsize = sizeof(struct sctp_sockstat);
1999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2004 case SCTP_MAX_BURST:
2006 struct sctp_assoc_value *av;
2008 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2009 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2012 av->assoc_value = stcb->asoc.max_burst;
2013 SCTP_TCB_UNLOCK(stcb);
2015 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2016 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2017 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2018 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2019 SCTP_INP_RLOCK(inp);
2020 av->assoc_value = inp->sctp_ep.max_burst;
2021 SCTP_INP_RUNLOCK(inp);
2023 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2028 *optsize = sizeof(struct sctp_assoc_value);
2034 struct sctp_assoc_value *av;
2036 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2037 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2040 av->assoc_value = stcb->asoc.sctp_frag_point;
2041 SCTP_TCB_UNLOCK(stcb);
2043 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2044 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2045 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2046 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2047 SCTP_INP_RLOCK(inp);
2048 av->assoc_value = inp->sctp_frag_point;
2049 SCTP_INP_RUNLOCK(inp);
2051 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2056 *optsize = sizeof(struct sctp_assoc_value);
2060 case SCTP_GET_STAT_LOG:
2061 error = sctp_fill_stat_log(optval, optsize);
2065 struct sctp_event_subscribe *events;
2067 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2068 memset(events, 0, sizeof(struct sctp_event_subscribe));
2069 SCTP_INP_RLOCK(inp);
2070 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2071 events->sctp_data_io_event = 1;
2073 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2074 events->sctp_association_event = 1;
2076 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2077 events->sctp_address_event = 1;
2079 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2080 events->sctp_send_failure_event = 1;
2082 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2083 events->sctp_peer_error_event = 1;
2085 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2086 events->sctp_shutdown_event = 1;
2088 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2089 events->sctp_partial_delivery_event = 1;
2091 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2092 events->sctp_adaptation_layer_event = 1;
2094 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2095 events->sctp_authentication_event = 1;
2097 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2098 events->sctp_sender_dry_event = 1;
2100 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2101 events->sctp_stream_reset_event = 1;
2102 SCTP_INP_RUNLOCK(inp);
2103 *optsize = sizeof(struct sctp_event_subscribe);
2106 case SCTP_ADAPTATION_LAYER:
2110 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2112 SCTP_INP_RLOCK(inp);
2113 *value = inp->sctp_ep.adaptation_layer_indicator;
2114 SCTP_INP_RUNLOCK(inp);
2115 *optsize = sizeof(uint32_t);
2118 case SCTP_SET_INITIAL_DBG_SEQ:
2122 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2123 SCTP_INP_RLOCK(inp);
2124 *value = inp->sctp_ep.initial_sequence_debug;
2125 SCTP_INP_RUNLOCK(inp);
2126 *optsize = sizeof(uint32_t);
2129 case SCTP_GET_LOCAL_ADDR_SIZE:
2133 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2134 SCTP_INP_RLOCK(inp);
2135 *value = (uint32_t)sctp_max_size_addresses(inp);
2136 SCTP_INP_RUNLOCK(inp);
2137 *optsize = sizeof(uint32_t);
2140 case SCTP_GET_REMOTE_ADDR_SIZE:
2143 struct sctp_nets *net;
2146 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2147 /* FIXME MT: change to sctp_assoc_value? */
2148 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2152 /* Count the sizes */
2153 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2154 switch (net->ro._l_addr.sa.sa_family) {
2158 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2159 size += sizeof(struct sockaddr_in6);
2161 size += sizeof(struct sockaddr_in);
2164 size += sizeof(struct sockaddr_in);
2170 size += sizeof(struct sockaddr_in6);
2177 SCTP_TCB_UNLOCK(stcb);
2178 *value = (uint32_t)size;
2179 *optsize = sizeof(uint32_t);
2181 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2182 ((sctp_assoc_t)*value <= SCTP_ALL_ASSOC)) {
2187 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2191 case SCTP_GET_PEER_ADDRESSES:
2193 * Get the address information, an array is passed in to
2194 * fill up we pack it.
2198 struct sockaddr *addr;
2199 struct sctp_nets *net;
2200 struct sctp_getaddresses *saddr;
2202 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2203 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2206 left = *optsize - offsetof(struct sctp_getaddresses, addr);
2207 *optsize = offsetof(struct sctp_getaddresses, addr);
2208 addr = &saddr->addr[0].sa;
2210 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2211 switch (net->ro._l_addr.sa.sa_family) {
2215 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2216 cpsz = sizeof(struct sockaddr_in6);
2218 cpsz = sizeof(struct sockaddr_in);
2221 cpsz = sizeof(struct sockaddr_in);
2227 cpsz = sizeof(struct sockaddr_in6);
2238 /* not enough room. */
2241 #if defined(INET) && defined(INET6)
2242 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2243 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2244 /* Must map the address */
2245 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2246 (struct sockaddr_in6 *)addr);
2248 memcpy(addr, &net->ro._l_addr, cpsz);
2251 memcpy(addr, &net->ro._l_addr, cpsz);
2253 ((struct sockaddr_in *)addr)->sin_port = stcb->rport;
2255 addr = (struct sockaddr *)((caddr_t)addr + cpsz);
2259 SCTP_TCB_UNLOCK(stcb);
2261 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2262 (saddr->sget_assoc_id <= SCTP_ALL_ASSOC)) {
2267 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2271 case SCTP_GET_LOCAL_ADDRESSES:
2273 size_t limit, actual;
2274 struct sctp_getaddresses *saddr;
2276 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2277 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2279 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2280 ((saddr->sget_assoc_id == SCTP_CURRENT_ASSOC) ||
2281 (saddr->sget_assoc_id == SCTP_ALL_ASSOC))) {
2284 limit = *optsize - offsetof(struct sctp_getaddresses, addr);
2285 actual = sctp_fill_up_addresses(inp, stcb, limit, &saddr->addr[0].sa);
2286 *optsize = offsetof(struct sctp_getaddresses, addr) + actual;
2289 SCTP_TCB_UNLOCK(stcb);
2293 case SCTP_PEER_ADDR_PARAMS:
2295 struct sctp_paddrparams *paddrp;
2296 struct sctp_nets *net;
2297 struct sockaddr *addr;
2298 #if defined(INET) && defined(INET6)
2299 struct sockaddr_in sin_store;
2302 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2303 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2305 #if defined(INET) && defined(INET6)
2306 if (paddrp->spp_address.ss_family == AF_INET6) {
2307 struct sockaddr_in6 *sin6;
2309 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2310 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2311 in6_sin6_2_sin(&sin_store, sin6);
2312 addr = (struct sockaddr *)&sin_store;
2314 addr = (struct sockaddr *)&paddrp->spp_address;
2317 addr = (struct sockaddr *)&paddrp->spp_address;
2320 addr = (struct sockaddr *)&paddrp->spp_address;
2323 net = sctp_findnet(stcb, addr);
2326 * We increment here since
2327 * sctp_findassociation_ep_addr() wil do a
2328 * decrement if it finds the stcb as long as
2329 * the locked tcb (last argument) is NOT a
2333 SCTP_INP_INCR_REF(inp);
2334 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2336 SCTP_INP_DECR_REF(inp);
2339 if ((stcb != NULL) && (net == NULL)) {
2341 if (addr->sa_family == AF_INET) {
2342 struct sockaddr_in *sin;
2344 sin = (struct sockaddr_in *)addr;
2345 if (sin->sin_addr.s_addr != INADDR_ANY) {
2347 SCTP_TCB_UNLOCK(stcb);
2348 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2354 if (addr->sa_family == AF_INET6) {
2355 struct sockaddr_in6 *sin6;
2357 sin6 = (struct sockaddr_in6 *)addr;
2358 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2360 SCTP_TCB_UNLOCK(stcb);
2361 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2367 error = EAFNOSUPPORT;
2368 SCTP_TCB_UNLOCK(stcb);
2369 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2375 /* Applies to the specific association */
2376 paddrp->spp_flags = 0;
2378 paddrp->spp_hbinterval = net->heart_beat_delay;
2379 paddrp->spp_pathmaxrxt = net->failure_threshold;
2380 paddrp->spp_pathmtu = net->mtu;
2381 switch (net->ro._l_addr.sa.sa_family) {
2384 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2389 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2395 /* get flags for HB */
2396 if (net->dest_state & SCTP_ADDR_NOHB) {
2397 paddrp->spp_flags |= SPP_HB_DISABLE;
2399 paddrp->spp_flags |= SPP_HB_ENABLE;
2401 /* get flags for PMTU */
2402 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2403 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2405 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2407 if (net->dscp & 0x01) {
2408 paddrp->spp_dscp = net->dscp & 0xfc;
2409 paddrp->spp_flags |= SPP_DSCP;
2412 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2413 (net->flowlabel & 0x80000000)) {
2414 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2415 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2420 * No destination so return default
2423 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2424 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2425 if (stcb->asoc.default_dscp & 0x01) {
2426 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2427 paddrp->spp_flags |= SPP_DSCP;
2430 if (stcb->asoc.default_flowlabel & 0x80000000) {
2431 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2432 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2435 /* default settings should be these */
2436 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2437 paddrp->spp_flags |= SPP_HB_DISABLE;
2439 paddrp->spp_flags |= SPP_HB_ENABLE;
2441 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2442 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2444 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2446 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2448 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2449 SCTP_TCB_UNLOCK(stcb);
2451 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2452 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2453 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2454 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
2455 /* Use endpoint defaults */
2456 SCTP_INP_RLOCK(inp);
2457 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2458 paddrp->spp_hbinterval = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2459 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2460 /* get inp's default */
2461 if (inp->sctp_ep.default_dscp & 0x01) {
2462 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2463 paddrp->spp_flags |= SPP_DSCP;
2466 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2467 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2468 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2469 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2472 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2474 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2475 paddrp->spp_flags |= SPP_HB_ENABLE;
2477 paddrp->spp_flags |= SPP_HB_DISABLE;
2479 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2480 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2482 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2484 SCTP_INP_RUNLOCK(inp);
2486 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2491 *optsize = sizeof(struct sctp_paddrparams);
2495 case SCTP_GET_PEER_ADDR_INFO:
2497 struct sctp_paddrinfo *paddri;
2498 struct sctp_nets *net;
2499 struct sockaddr *addr;
2500 #if defined(INET) && defined(INET6)
2501 struct sockaddr_in sin_store;
2504 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2505 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2507 #if defined(INET) && defined(INET6)
2508 if (paddri->spinfo_address.ss_family == AF_INET6) {
2509 struct sockaddr_in6 *sin6;
2511 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2512 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2513 in6_sin6_2_sin(&sin_store, sin6);
2514 addr = (struct sockaddr *)&sin_store;
2516 addr = (struct sockaddr *)&paddri->spinfo_address;
2519 addr = (struct sockaddr *)&paddri->spinfo_address;
2522 addr = (struct sockaddr *)&paddri->spinfo_address;
2525 net = sctp_findnet(stcb, addr);
2528 * We increment here since
2529 * sctp_findassociation_ep_addr() wil do a
2530 * decrement if it finds the stcb as long as
2531 * the locked tcb (last argument) is NOT a
2535 SCTP_INP_INCR_REF(inp);
2536 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2538 SCTP_INP_DECR_REF(inp);
2542 if ((stcb != NULL) && (net != NULL)) {
2543 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2544 /* It's unconfirmed */
2545 paddri->spinfo_state = SCTP_UNCONFIRMED;
2546 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2548 paddri->spinfo_state = SCTP_ACTIVE;
2551 paddri->spinfo_state = SCTP_INACTIVE;
2553 paddri->spinfo_cwnd = net->cwnd;
2554 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2555 paddri->spinfo_rto = net->RTO;
2556 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2557 paddri->spinfo_mtu = net->mtu;
2558 switch (addr->sa_family) {
2561 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2566 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2572 SCTP_TCB_UNLOCK(stcb);
2573 *optsize = sizeof(struct sctp_paddrinfo);
2576 SCTP_TCB_UNLOCK(stcb);
2578 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2583 case SCTP_PCB_STATUS:
2585 struct sctp_pcbinfo *spcb;
2587 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2588 sctp_fill_pcbinfo(spcb);
2589 *optsize = sizeof(struct sctp_pcbinfo);
2594 struct sctp_nets *net;
2595 struct sctp_status *sstat;
2597 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2598 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2601 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2605 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2606 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2607 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2608 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2610 * We can't include chunks that have been passed to
2611 * the socket layer. Only things in queue.
2613 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2614 stcb->asoc.cnt_on_all_streams);
2615 sstat->sstat_instrms = stcb->asoc.streamincnt;
2616 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2617 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb);
2618 net = stcb->asoc.primary_destination;
2620 memcpy(&sstat->sstat_primary.spinfo_address,
2622 ((struct sockaddr *)(&net->ro._l_addr))->sa_len);
2623 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2625 * Again the user can get info from
2626 * sctp_constants.h for what the state of
2629 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2630 /* It's unconfirmed */
2631 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2632 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2634 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2637 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2639 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2640 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2641 sstat->sstat_primary.spinfo_rto = net->RTO;
2642 sstat->sstat_primary.spinfo_mtu = net->mtu;
2643 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2646 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2651 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2658 memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo));
2660 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2661 SCTP_TCB_UNLOCK(stcb);
2662 *optsize = sizeof(struct sctp_status);
2667 struct sctp_rtoinfo *srto;
2669 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2670 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2673 srto->srto_initial = stcb->asoc.initial_rto;
2674 srto->srto_max = stcb->asoc.maxrto;
2675 srto->srto_min = stcb->asoc.minrto;
2676 SCTP_TCB_UNLOCK(stcb);
2678 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2679 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2680 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2681 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
2682 SCTP_INP_RLOCK(inp);
2683 srto->srto_initial = inp->sctp_ep.initial_rto;
2684 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2685 srto->srto_min = inp->sctp_ep.sctp_minrto;
2686 SCTP_INP_RUNLOCK(inp);
2688 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2693 *optsize = sizeof(struct sctp_rtoinfo);
2699 struct sctp_timeouts *stimo;
2701 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2702 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2705 stimo->stimo_init = stcb->asoc.timoinit;
2706 stimo->stimo_data = stcb->asoc.timodata;
2707 stimo->stimo_sack = stcb->asoc.timosack;
2708 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2709 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2710 stimo->stimo_cookie = stcb->asoc.timocookie;
2711 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2712 SCTP_TCB_UNLOCK(stcb);
2713 *optsize = sizeof(struct sctp_timeouts);
2715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2720 case SCTP_ASSOCINFO:
2722 struct sctp_assocparams *sasoc;
2724 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2725 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2728 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(stcb->asoc.cookie_life);
2729 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2730 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2731 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2732 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2733 SCTP_TCB_UNLOCK(stcb);
2735 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2736 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2737 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2738 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
2739 SCTP_INP_RLOCK(inp);
2740 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(inp->sctp_ep.def_cookie_life);
2741 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2742 sasoc->sasoc_number_peer_destinations = 0;
2743 sasoc->sasoc_peer_rwnd = 0;
2744 sasoc->sasoc_local_rwnd = (uint32_t)sbspace(&inp->sctp_socket->so_rcv);
2745 SCTP_INP_RUNLOCK(inp);
2747 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2752 *optsize = sizeof(struct sctp_assocparams);
2756 case SCTP_DEFAULT_SEND_PARAM:
2758 struct sctp_sndrcvinfo *s_info;
2760 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2761 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2764 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2765 SCTP_TCB_UNLOCK(stcb);
2767 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2768 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2769 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2770 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC))) {
2771 SCTP_INP_RLOCK(inp);
2772 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2773 SCTP_INP_RUNLOCK(inp);
2775 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2780 *optsize = sizeof(struct sctp_sndrcvinfo);
2786 struct sctp_initmsg *sinit;
2788 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2789 SCTP_INP_RLOCK(inp);
2790 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2791 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2792 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2793 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2794 SCTP_INP_RUNLOCK(inp);
2795 *optsize = sizeof(struct sctp_initmsg);
2798 case SCTP_PRIMARY_ADDR:
2799 /* we allow a "get" operation on this */
2801 struct sctp_setprim *ssp;
2803 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2804 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2807 union sctp_sockstore *addr;
2809 addr = &stcb->asoc.primary_destination->ro._l_addr;
2810 switch (addr->sa.sa_family) {
2814 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2815 in6_sin_2_v4mapsin6(&addr->sin,
2816 (struct sockaddr_in6 *)&ssp->ssp_addr);
2818 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2821 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2827 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2833 SCTP_TCB_UNLOCK(stcb);
2834 *optsize = sizeof(struct sctp_setprim);
2836 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2841 case SCTP_HMAC_IDENT:
2843 struct sctp_hmacalgo *shmac;
2844 sctp_hmaclist_t *hmaclist;
2848 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2850 SCTP_INP_RLOCK(inp);
2851 hmaclist = inp->sctp_ep.local_hmacs;
2852 if (hmaclist == NULL) {
2853 /* no HMACs to return */
2854 *optsize = sizeof(*shmac);
2855 SCTP_INP_RUNLOCK(inp);
2858 /* is there room for all of the hmac ids? */
2859 size = sizeof(*shmac) + (hmaclist->num_algo *
2860 sizeof(shmac->shmac_idents[0]));
2861 if (*optsize < size) {
2862 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2864 SCTP_INP_RUNLOCK(inp);
2867 /* copy in the list */
2868 shmac->shmac_number_of_idents = hmaclist->num_algo;
2869 for (i = 0; i < hmaclist->num_algo; i++) {
2870 shmac->shmac_idents[i] = hmaclist->hmac[i];
2872 SCTP_INP_RUNLOCK(inp);
2876 case SCTP_AUTH_ACTIVE_KEY:
2878 struct sctp_authkeyid *scact;
2880 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2881 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2884 /* get the active key on the assoc */
2885 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2886 SCTP_TCB_UNLOCK(stcb);
2888 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2889 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2890 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2891 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC))) {
2892 /* get the endpoint active key */
2893 SCTP_INP_RLOCK(inp);
2894 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2895 SCTP_INP_RUNLOCK(inp);
2897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2902 *optsize = sizeof(struct sctp_authkeyid);
2906 case SCTP_LOCAL_AUTH_CHUNKS:
2908 struct sctp_authchunks *sac;
2909 sctp_auth_chklist_t *chklist = NULL;
2912 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2913 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2916 /* get off the assoc */
2917 chklist = stcb->asoc.local_auth_chunks;
2918 /* is there enough space? */
2919 size = sctp_auth_get_chklist_size(chklist);
2920 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2924 /* copy in the chunks */
2925 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2926 sac->gauth_number_of_chunks = (uint32_t)size;
2927 *optsize = sizeof(struct sctp_authchunks) + size;
2929 SCTP_TCB_UNLOCK(stcb);
2931 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2932 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2933 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2934 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC))) {
2935 /* get off the endpoint */
2936 SCTP_INP_RLOCK(inp);
2937 chklist = inp->sctp_ep.local_auth_chunks;
2938 /* is there enough space? */
2939 size = sctp_auth_get_chklist_size(chklist);
2940 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2942 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2944 /* copy in the chunks */
2945 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2946 sac->gauth_number_of_chunks = (uint32_t)size;
2947 *optsize = sizeof(struct sctp_authchunks) + size;
2949 SCTP_INP_RUNLOCK(inp);
2951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2957 case SCTP_PEER_AUTH_CHUNKS:
2959 struct sctp_authchunks *sac;
2960 sctp_auth_chklist_t *chklist = NULL;
2963 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2964 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2967 /* get off the assoc */
2968 chklist = stcb->asoc.peer_auth_chunks;
2969 /* is there enough space? */
2970 size = sctp_auth_get_chklist_size(chklist);
2971 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2973 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2975 /* copy in the chunks */
2976 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2977 sac->gauth_number_of_chunks = (uint32_t)size;
2978 *optsize = sizeof(struct sctp_authchunks) + size;
2980 SCTP_TCB_UNLOCK(stcb);
2982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2989 struct sctp_event *event;
2990 uint32_t event_type;
2992 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2993 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2995 switch (event->se_type) {
2996 case SCTP_ASSOC_CHANGE:
2997 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2999 case SCTP_PEER_ADDR_CHANGE:
3000 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3002 case SCTP_REMOTE_ERROR:
3003 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3005 case SCTP_SEND_FAILED:
3006 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3008 case SCTP_SHUTDOWN_EVENT:
3009 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3011 case SCTP_ADAPTATION_INDICATION:
3012 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3014 case SCTP_PARTIAL_DELIVERY_EVENT:
3015 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3017 case SCTP_AUTHENTICATION_EVENT:
3018 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3020 case SCTP_STREAM_RESET_EVENT:
3021 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3023 case SCTP_SENDER_DRY_EVENT:
3024 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3026 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3028 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3031 case SCTP_ASSOC_RESET_EVENT:
3032 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3034 case SCTP_STREAM_CHANGE_EVENT:
3035 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3037 case SCTP_SEND_FAILED_EVENT:
3038 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3042 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3046 if (event_type > 0) {
3048 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3050 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3051 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3052 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3053 (event->se_assoc_id == SCTP_FUTURE_ASSOC))) {
3054 SCTP_INP_RLOCK(inp);
3055 event->se_on = sctp_is_feature_on(inp, event_type);
3056 SCTP_INP_RUNLOCK(inp);
3058 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3064 SCTP_TCB_UNLOCK(stcb);
3067 *optsize = sizeof(struct sctp_event);
3071 case SCTP_RECVRCVINFO:
3072 if (*optsize < sizeof(int)) {
3073 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3076 SCTP_INP_RLOCK(inp);
3077 *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3078 SCTP_INP_RUNLOCK(inp);
3079 *optsize = sizeof(int);
3082 case SCTP_RECVNXTINFO:
3083 if (*optsize < sizeof(int)) {
3084 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3087 SCTP_INP_RLOCK(inp);
3088 *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3089 SCTP_INP_RUNLOCK(inp);
3090 *optsize = sizeof(int);
3093 case SCTP_DEFAULT_SNDINFO:
3095 struct sctp_sndinfo *info;
3097 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3098 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3101 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3102 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3103 info->snd_flags &= 0xfff0;
3104 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3105 info->snd_context = stcb->asoc.def_send.sinfo_context;
3106 SCTP_TCB_UNLOCK(stcb);
3108 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3109 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3110 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3111 (info->snd_assoc_id == SCTP_FUTURE_ASSOC))) {
3112 SCTP_INP_RLOCK(inp);
3113 info->snd_sid = inp->def_send.sinfo_stream;
3114 info->snd_flags = inp->def_send.sinfo_flags;
3115 info->snd_flags &= 0xfff0;
3116 info->snd_ppid = inp->def_send.sinfo_ppid;
3117 info->snd_context = inp->def_send.sinfo_context;
3118 SCTP_INP_RUNLOCK(inp);
3120 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3125 *optsize = sizeof(struct sctp_sndinfo);
3129 case SCTP_DEFAULT_PRINFO:
3131 struct sctp_default_prinfo *info;
3133 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3134 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3137 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3138 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3139 SCTP_TCB_UNLOCK(stcb);
3141 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3142 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3143 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3144 (info->pr_assoc_id == SCTP_FUTURE_ASSOC))) {
3145 SCTP_INP_RLOCK(inp);
3146 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3147 info->pr_value = inp->def_send.sinfo_timetolive;
3148 SCTP_INP_RUNLOCK(inp);
3150 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3155 *optsize = sizeof(struct sctp_default_prinfo);
3159 case SCTP_PEER_ADDR_THLDS:
3161 struct sctp_paddrthlds *thlds;
3162 struct sctp_nets *net;
3163 struct sockaddr *addr;
3164 #if defined(INET) && defined(INET6)
3165 struct sockaddr_in sin_store;
3168 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3169 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3171 #if defined(INET) && defined(INET6)
3172 if (thlds->spt_address.ss_family == AF_INET6) {
3173 struct sockaddr_in6 *sin6;
3175 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3176 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3177 in6_sin6_2_sin(&sin_store, sin6);
3178 addr = (struct sockaddr *)&sin_store;
3180 addr = (struct sockaddr *)&thlds->spt_address;
3183 addr = (struct sockaddr *)&thlds->spt_address;
3186 addr = (struct sockaddr *)&thlds->spt_address;
3189 net = sctp_findnet(stcb, addr);
3192 * We increment here since
3193 * sctp_findassociation_ep_addr() wil do a
3194 * decrement if it finds the stcb as long as
3195 * the locked tcb (last argument) is NOT a
3199 SCTP_INP_INCR_REF(inp);
3200 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3202 SCTP_INP_DECR_REF(inp);
3205 if ((stcb != NULL) && (net == NULL)) {
3207 if (addr->sa_family == AF_INET) {
3208 struct sockaddr_in *sin;
3210 sin = (struct sockaddr_in *)addr;
3211 if (sin->sin_addr.s_addr != INADDR_ANY) {
3213 SCTP_TCB_UNLOCK(stcb);
3214 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3220 if (addr->sa_family == AF_INET6) {
3221 struct sockaddr_in6 *sin6;
3223 sin6 = (struct sockaddr_in6 *)addr;
3224 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3226 SCTP_TCB_UNLOCK(stcb);
3227 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3233 error = EAFNOSUPPORT;
3234 SCTP_TCB_UNLOCK(stcb);
3235 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3242 thlds->spt_pathmaxrxt = net->failure_threshold;
3243 thlds->spt_pathpfthld = net->pf_threshold;
3244 thlds->spt_pathcpthld = 0xffff;
3246 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3247 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3248 thlds->spt_pathcpthld = 0xffff;
3250 thlds->spt_assoc_id = sctp_get_associd(stcb);
3251 SCTP_TCB_UNLOCK(stcb);
3253 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3254 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3255 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3256 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
3257 /* Use endpoint defaults */
3258 SCTP_INP_RLOCK(inp);
3259 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3260 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3261 thlds->spt_pathcpthld = 0xffff;
3262 SCTP_INP_RUNLOCK(inp);
3264 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3269 *optsize = sizeof(struct sctp_paddrthlds);
3273 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3275 struct sctp_udpencaps *encaps;
3276 struct sctp_nets *net;
3277 struct sockaddr *addr;
3278 #if defined(INET) && defined(INET6)
3279 struct sockaddr_in sin_store;
3282 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3283 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3285 #if defined(INET) && defined(INET6)
3286 if (encaps->sue_address.ss_family == AF_INET6) {
3287 struct sockaddr_in6 *sin6;
3289 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3290 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3291 in6_sin6_2_sin(&sin_store, sin6);
3292 addr = (struct sockaddr *)&sin_store;
3294 addr = (struct sockaddr *)&encaps->sue_address;
3297 addr = (struct sockaddr *)&encaps->sue_address;
3300 addr = (struct sockaddr *)&encaps->sue_address;
3303 net = sctp_findnet(stcb, addr);
3306 * We increment here since
3307 * sctp_findassociation_ep_addr() wil do a
3308 * decrement if it finds the stcb as long as
3309 * the locked tcb (last argument) is NOT a
3313 SCTP_INP_INCR_REF(inp);
3314 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3316 SCTP_INP_DECR_REF(inp);
3319 if ((stcb != NULL) && (net == NULL)) {
3321 if (addr->sa_family == AF_INET) {
3322 struct sockaddr_in *sin;
3324 sin = (struct sockaddr_in *)addr;
3325 if (sin->sin_addr.s_addr != INADDR_ANY) {
3327 SCTP_TCB_UNLOCK(stcb);
3328 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3334 if (addr->sa_family == AF_INET6) {
3335 struct sockaddr_in6 *sin6;
3337 sin6 = (struct sockaddr_in6 *)addr;
3338 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3340 SCTP_TCB_UNLOCK(stcb);
3341 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3347 error = EAFNOSUPPORT;
3348 SCTP_TCB_UNLOCK(stcb);
3349 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3356 encaps->sue_port = net->port;
3358 encaps->sue_port = stcb->asoc.port;
3360 SCTP_TCB_UNLOCK(stcb);
3362 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3363 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3364 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3365 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
3366 SCTP_INP_RLOCK(inp);
3367 encaps->sue_port = inp->sctp_ep.port;
3368 SCTP_INP_RUNLOCK(inp);
3370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3375 *optsize = sizeof(struct sctp_udpencaps);
3379 case SCTP_ECN_SUPPORTED:
3381 struct sctp_assoc_value *av;
3383 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3384 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3387 av->assoc_value = stcb->asoc.ecn_supported;
3388 SCTP_TCB_UNLOCK(stcb);
3390 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3391 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3392 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3393 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3394 SCTP_INP_RLOCK(inp);
3395 av->assoc_value = inp->ecn_supported;
3396 SCTP_INP_RUNLOCK(inp);
3398 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3403 *optsize = sizeof(struct sctp_assoc_value);
3407 case SCTP_PR_SUPPORTED:
3409 struct sctp_assoc_value *av;
3411 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3412 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3415 av->assoc_value = stcb->asoc.prsctp_supported;
3416 SCTP_TCB_UNLOCK(stcb);
3418 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3419 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3420 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3421 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3422 SCTP_INP_RLOCK(inp);
3423 av->assoc_value = inp->prsctp_supported;
3424 SCTP_INP_RUNLOCK(inp);
3426 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3431 *optsize = sizeof(struct sctp_assoc_value);
3435 case SCTP_AUTH_SUPPORTED:
3437 struct sctp_assoc_value *av;
3439 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3440 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3443 av->assoc_value = stcb->asoc.auth_supported;
3444 SCTP_TCB_UNLOCK(stcb);
3446 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3447 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3448 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3449 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3450 SCTP_INP_RLOCK(inp);
3451 av->assoc_value = inp->auth_supported;
3452 SCTP_INP_RUNLOCK(inp);
3454 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3459 *optsize = sizeof(struct sctp_assoc_value);
3463 case SCTP_ASCONF_SUPPORTED:
3465 struct sctp_assoc_value *av;
3467 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3468 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3471 av->assoc_value = stcb->asoc.asconf_supported;
3472 SCTP_TCB_UNLOCK(stcb);
3474 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3475 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3476 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3477 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3478 SCTP_INP_RLOCK(inp);
3479 av->assoc_value = inp->asconf_supported;
3480 SCTP_INP_RUNLOCK(inp);
3482 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3487 *optsize = sizeof(struct sctp_assoc_value);
3491 case SCTP_RECONFIG_SUPPORTED:
3493 struct sctp_assoc_value *av;
3495 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3496 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3499 av->assoc_value = stcb->asoc.reconfig_supported;
3500 SCTP_TCB_UNLOCK(stcb);
3502 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3503 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3504 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3505 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3506 SCTP_INP_RLOCK(inp);
3507 av->assoc_value = inp->reconfig_supported;
3508 SCTP_INP_RUNLOCK(inp);
3510 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3515 *optsize = sizeof(struct sctp_assoc_value);
3519 case SCTP_NRSACK_SUPPORTED:
3521 struct sctp_assoc_value *av;
3523 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3524 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3527 av->assoc_value = stcb->asoc.nrsack_supported;
3528 SCTP_TCB_UNLOCK(stcb);
3530 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3531 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3532 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3533 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3534 SCTP_INP_RLOCK(inp);
3535 av->assoc_value = inp->nrsack_supported;
3536 SCTP_INP_RUNLOCK(inp);
3538 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3543 *optsize = sizeof(struct sctp_assoc_value);
3547 case SCTP_PKTDROP_SUPPORTED:
3549 struct sctp_assoc_value *av;
3551 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3552 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3555 av->assoc_value = stcb->asoc.pktdrop_supported;
3556 SCTP_TCB_UNLOCK(stcb);
3558 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3559 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3560 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3561 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3562 SCTP_INP_RLOCK(inp);
3563 av->assoc_value = inp->pktdrop_supported;
3564 SCTP_INP_RUNLOCK(inp);
3566 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3571 *optsize = sizeof(struct sctp_assoc_value);
3575 case SCTP_ENABLE_STREAM_RESET:
3577 struct sctp_assoc_value *av;
3579 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3580 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3583 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3584 SCTP_TCB_UNLOCK(stcb);
3586 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3587 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3588 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3589 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3590 SCTP_INP_RLOCK(inp);
3591 av->assoc_value = (uint32_t)inp->local_strreset_support;
3592 SCTP_INP_RUNLOCK(inp);
3594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3599 *optsize = sizeof(struct sctp_assoc_value);
3603 case SCTP_PR_STREAM_STATUS:
3605 struct sctp_prstatus *sprstat;
3609 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3610 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3612 sid = sprstat->sprstat_sid;
3613 policy = sprstat->sprstat_policy;
3614 #if defined(SCTP_DETAILED_STR_STATS)
3615 if ((stcb != NULL) &&
3616 (sid < stcb->asoc.streamoutcnt) &&
3617 (policy != SCTP_PR_SCTP_NONE) &&
3618 ((policy <= SCTP_PR_SCTP_MAX) ||
3619 (policy == SCTP_PR_SCTP_ALL))) {
3620 if (policy == SCTP_PR_SCTP_ALL) {
3621 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3622 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3624 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3625 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3628 if ((stcb != NULL) &&
3629 (sid < stcb->asoc.streamoutcnt) &&
3630 (policy == SCTP_PR_SCTP_ALL)) {
3631 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3632 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3635 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3639 SCTP_TCB_UNLOCK(stcb);
3642 *optsize = sizeof(struct sctp_prstatus);
3646 case SCTP_PR_ASSOC_STATUS:
3648 struct sctp_prstatus *sprstat;
3651 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3652 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3654 policy = sprstat->sprstat_policy;
3655 if ((stcb != NULL) &&
3656 (policy != SCTP_PR_SCTP_NONE) &&
3657 ((policy <= SCTP_PR_SCTP_MAX) ||
3658 (policy == SCTP_PR_SCTP_ALL))) {
3659 if (policy == SCTP_PR_SCTP_ALL) {
3660 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3661 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3663 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3664 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3671 SCTP_TCB_UNLOCK(stcb);
3674 *optsize = sizeof(struct sctp_prstatus);
3680 struct sctp_assoc_value *av;
3682 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3683 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3686 av->assoc_value = stcb->asoc.max_cwnd;
3687 SCTP_TCB_UNLOCK(stcb);
3689 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3690 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3691 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3692 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3693 SCTP_INP_RLOCK(inp);
3694 av->assoc_value = inp->max_cwnd;
3695 SCTP_INP_RUNLOCK(inp);
3697 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3702 *optsize = sizeof(struct sctp_assoc_value);
3707 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3708 error = ENOPROTOOPT;
3710 } /* end switch (sopt->sopt_name) */
3718 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3723 struct sctp_tcb *stcb = NULL;
3724 struct sctp_inpcb *inp = NULL;
3727 if (optval == NULL) {
3728 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3731 inp = (struct sctp_inpcb *)so->so_pcb;
3733 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3736 vrf_id = inp->def_vrf_id;
3741 case SCTP_AUTOCLOSE:
3742 case SCTP_AUTO_ASCONF:
3743 case SCTP_EXPLICIT_EOR:
3744 case SCTP_DISABLE_FRAGMENTS:
3745 case SCTP_USE_EXT_RCVINFO:
3746 case SCTP_I_WANT_MAPPED_V4_ADDR:
3747 /* copy in the option value */
3748 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3753 case SCTP_DISABLE_FRAGMENTS:
3754 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3756 case SCTP_AUTO_ASCONF:
3758 * NOTE: we don't really support this flag
3760 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3761 /* only valid for bound all sockets */
3762 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3764 /* forbidden by admin */
3765 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3768 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3770 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3774 case SCTP_EXPLICIT_EOR:
3775 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3777 case SCTP_USE_EXT_RCVINFO:
3778 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3780 case SCTP_I_WANT_MAPPED_V4_ADDR:
3781 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3782 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3784 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3789 set_opt = SCTP_PCB_FLAGS_NODELAY;
3791 case SCTP_AUTOCLOSE:
3792 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3793 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3797 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3799 * The value is in ticks. Note this does not effect
3800 * old associations, only new ones.
3802 inp->sctp_ep.auto_close_time = sctp_secs_to_ticks(*mopt);
3805 SCTP_INP_WLOCK(inp);
3807 sctp_feature_on(inp, set_opt);
3809 sctp_feature_off(inp, set_opt);
3811 SCTP_INP_WUNLOCK(inp);
3813 case SCTP_REUSE_PORT:
3815 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3816 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3817 /* Can't set it after we are bound */
3821 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3822 /* Can't do this for a 1-m socket */
3827 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3829 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3832 case SCTP_PARTIAL_DELIVERY_POINT:
3836 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3837 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3838 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3842 inp->partial_delivery_point = *value;
3845 case SCTP_FRAGMENT_INTERLEAVE:
3846 /* not yet until we re-write sctp_recvmsg() */
3850 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3851 if (*level == SCTP_FRAG_LEVEL_2) {
3852 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3853 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3854 } else if (*level == SCTP_FRAG_LEVEL_1) {
3855 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3856 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3857 } else if (*level == SCTP_FRAG_LEVEL_0) {
3858 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3859 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3862 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3867 case SCTP_INTERLEAVING_SUPPORTED:
3869 struct sctp_assoc_value *av;
3871 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3872 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3875 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3877 SCTP_TCB_UNLOCK(stcb);
3879 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3880 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3881 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3882 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3883 SCTP_INP_WLOCK(inp);
3884 if (av->assoc_value == 0) {
3885 inp->idata_supported = 0;
3887 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3888 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3889 inp->idata_supported = 1;
3897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3901 SCTP_INP_WUNLOCK(inp);
3903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3909 case SCTP_CMT_ON_OFF:
3910 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3911 struct sctp_assoc_value *av;
3913 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3914 if (av->assoc_value > SCTP_CMT_MAX) {
3915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3919 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3921 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3922 SCTP_TCB_UNLOCK(stcb);
3924 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3925 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3926 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3927 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3928 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3929 SCTP_INP_WLOCK(inp);
3930 inp->sctp_cmt_on_off = av->assoc_value;
3931 SCTP_INP_WUNLOCK(inp);
3933 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3934 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3935 (av->assoc_id == SCTP_ALL_ASSOC))) {
3936 SCTP_INP_RLOCK(inp);
3937 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3938 SCTP_TCB_LOCK(stcb);
3939 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3940 SCTP_TCB_UNLOCK(stcb);
3942 SCTP_INP_RUNLOCK(inp);
3946 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3947 error = ENOPROTOOPT;
3950 case SCTP_PLUGGABLE_CC:
3952 struct sctp_assoc_value *av;
3953 struct sctp_nets *net;
3955 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3956 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3957 (av->assoc_value != SCTP_CC_HSTCP) &&
3958 (av->assoc_value != SCTP_CC_HTCP) &&
3959 (av->assoc_value != SCTP_CC_RTCC)) {
3960 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3964 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3966 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3967 stcb->asoc.congestion_control_module = av->assoc_value;
3968 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3969 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3970 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3973 SCTP_TCB_UNLOCK(stcb);
3975 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3976 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3977 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3978 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3979 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3980 SCTP_INP_WLOCK(inp);
3981 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3982 SCTP_INP_WUNLOCK(inp);
3984 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3985 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3986 (av->assoc_id == SCTP_ALL_ASSOC))) {
3987 SCTP_INP_RLOCK(inp);
3988 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3989 SCTP_TCB_LOCK(stcb);
3990 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3991 stcb->asoc.congestion_control_module = av->assoc_value;
3992 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3993 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3994 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3997 SCTP_TCB_UNLOCK(stcb);
3999 SCTP_INP_RUNLOCK(inp);
4004 case SCTP_CC_OPTION:
4006 struct sctp_cc_option *cc_opt;
4008 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4009 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4011 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4012 (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC)) {
4013 SCTP_INP_RLOCK(inp);
4014 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4015 SCTP_TCB_LOCK(stcb);
4016 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4017 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4019 SCTP_TCB_UNLOCK(stcb);
4021 SCTP_INP_RUNLOCK(inp);
4026 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4029 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4032 SCTP_TCB_UNLOCK(stcb);
4036 case SCTP_STREAM_SCHEDULER:
4038 struct sctp_assoc_value *av;
4040 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4041 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4042 (av->assoc_value != SCTP_SS_RR) &&
4043 (av->assoc_value != SCTP_SS_RR_PKT) &&
4044 (av->assoc_value != SCTP_SS_PRIO) &&
4045 (av->assoc_value != SCTP_SS_FB) &&
4046 (av->assoc_value != SCTP_SS_FCFS)) {
4047 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4051 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4053 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, true);
4054 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4055 stcb->asoc.stream_scheduling_module = av->assoc_value;
4056 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc);
4057 SCTP_TCB_UNLOCK(stcb);
4059 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4060 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4061 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4062 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4063 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4064 SCTP_INP_WLOCK(inp);
4065 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4066 SCTP_INP_WUNLOCK(inp);
4068 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4069 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4070 (av->assoc_id == SCTP_ALL_ASSOC))) {
4071 SCTP_INP_RLOCK(inp);
4072 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4073 SCTP_TCB_LOCK(stcb);
4074 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, true);
4075 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4076 stcb->asoc.stream_scheduling_module = av->assoc_value;
4077 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc);
4078 SCTP_TCB_UNLOCK(stcb);
4080 SCTP_INP_RUNLOCK(inp);
4085 case SCTP_STREAM_SCHEDULER_VALUE:
4087 struct sctp_stream_value *av;
4089 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4090 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4092 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4093 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4094 av->stream_value) < 0)) {
4095 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4098 SCTP_TCB_UNLOCK(stcb);
4100 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4101 (av->assoc_id == SCTP_CURRENT_ASSOC)) {
4102 SCTP_INP_RLOCK(inp);
4103 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4104 SCTP_TCB_LOCK(stcb);
4105 if (av->stream_id < stcb->asoc.streamoutcnt) {
4106 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4108 &stcb->asoc.strmout[av->stream_id],
4111 SCTP_TCB_UNLOCK(stcb);
4113 SCTP_INP_RUNLOCK(inp);
4116 * Can't set stream value without
4119 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4125 case SCTP_CLR_STAT_LOG:
4126 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4131 struct sctp_assoc_value *av;
4133 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4134 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4137 stcb->asoc.context = av->assoc_value;
4138 SCTP_TCB_UNLOCK(stcb);
4140 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4141 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4142 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4143 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4144 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4145 SCTP_INP_WLOCK(inp);
4146 inp->sctp_context = av->assoc_value;
4147 SCTP_INP_WUNLOCK(inp);
4149 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4150 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4151 (av->assoc_id == SCTP_ALL_ASSOC))) {
4152 SCTP_INP_RLOCK(inp);
4153 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4154 SCTP_TCB_LOCK(stcb);
4155 stcb->asoc.context = av->assoc_value;
4156 SCTP_TCB_UNLOCK(stcb);
4158 SCTP_INP_RUNLOCK(inp);
4165 uint32_t *default_vrfid;
4167 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4168 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4169 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4173 inp->def_vrf_id = *default_vrfid;
4176 case SCTP_DEL_VRF_ID:
4178 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4182 case SCTP_ADD_VRF_ID:
4184 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4188 case SCTP_DELAYED_SACK:
4190 struct sctp_sack_info *sack;
4192 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4193 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4194 if (sack->sack_delay) {
4195 if (sack->sack_delay > SCTP_MAX_SACK_DELAY) {
4198 SCTP_TCB_UNLOCK(stcb);
4204 if (sack->sack_delay) {
4205 stcb->asoc.delayed_ack = sack->sack_delay;
4207 if (sack->sack_freq) {
4208 stcb->asoc.sack_freq = sack->sack_freq;
4210 SCTP_TCB_UNLOCK(stcb);
4212 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4213 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4214 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4215 ((sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4216 (sack->sack_assoc_id == SCTP_ALL_ASSOC)))) {
4217 SCTP_INP_WLOCK(inp);
4218 if (sack->sack_delay) {
4219 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = sctp_msecs_to_ticks(sack->sack_delay);
4221 if (sack->sack_freq) {
4222 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4224 SCTP_INP_WUNLOCK(inp);
4226 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4227 ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4228 (sack->sack_assoc_id == SCTP_ALL_ASSOC))) {
4229 SCTP_INP_RLOCK(inp);
4230 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4231 SCTP_TCB_LOCK(stcb);
4232 if (sack->sack_delay) {
4233 stcb->asoc.delayed_ack = sack->sack_delay;
4235 if (sack->sack_freq) {
4236 stcb->asoc.sack_freq = sack->sack_freq;
4238 SCTP_TCB_UNLOCK(stcb);
4240 SCTP_INP_RUNLOCK(inp);
4245 case SCTP_AUTH_CHUNK:
4247 struct sctp_authchunk *sauth;
4249 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4251 SCTP_INP_WLOCK(inp);
4252 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4253 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4256 inp->auth_supported = 1;
4258 SCTP_INP_WUNLOCK(inp);
4263 struct sctp_authkey *sca;
4264 struct sctp_keyhead *shared_keys;
4265 sctp_sharedkey_t *shared_key;
4266 sctp_key_t *key = NULL;
4269 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4270 if (sca->sca_keylength == 0) {
4271 size = optsize - sizeof(struct sctp_authkey);
4273 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4274 size = sca->sca_keylength;
4276 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4281 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4284 shared_keys = &stcb->asoc.shared_keys;
4285 /* clear the cached keys for this key id */
4286 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4288 * create the new shared key and
4292 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4294 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4296 SCTP_TCB_UNLOCK(stcb);
4300 shared_key = sctp_alloc_sharedkey();
4301 if (shared_key == NULL) {
4303 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4305 SCTP_TCB_UNLOCK(stcb);
4308 shared_key->key = key;
4309 shared_key->keyid = sca->sca_keynumber;
4310 error = sctp_insert_sharedkey(shared_keys, shared_key);
4311 SCTP_TCB_UNLOCK(stcb);
4313 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4314 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4315 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4316 ((sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4317 (sca->sca_assoc_id == SCTP_ALL_ASSOC)))) {
4318 SCTP_INP_WLOCK(inp);
4319 shared_keys = &inp->sctp_ep.shared_keys;
4321 * clear the cached keys on all
4322 * assocs for this key id
4324 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4326 * create the new shared key and
4330 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4332 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4334 SCTP_INP_WUNLOCK(inp);
4338 shared_key = sctp_alloc_sharedkey();
4339 if (shared_key == NULL) {
4341 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4343 SCTP_INP_WUNLOCK(inp);
4346 shared_key->key = key;
4347 shared_key->keyid = sca->sca_keynumber;
4348 error = sctp_insert_sharedkey(shared_keys, shared_key);
4349 SCTP_INP_WUNLOCK(inp);
4351 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4352 ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4353 (sca->sca_assoc_id == SCTP_ALL_ASSOC))) {
4354 SCTP_INP_RLOCK(inp);
4355 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4356 SCTP_TCB_LOCK(stcb);
4357 shared_keys = &stcb->asoc.shared_keys;
4359 * clear the cached keys for
4362 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4364 * create the new shared key
4365 * and insert/replace it
4368 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4370 SCTP_TCB_UNLOCK(stcb);
4374 shared_key = sctp_alloc_sharedkey();
4375 if (shared_key == NULL) {
4377 SCTP_TCB_UNLOCK(stcb);
4380 shared_key->key = key;
4381 shared_key->keyid = sca->sca_keynumber;
4382 error = sctp_insert_sharedkey(shared_keys, shared_key);
4383 SCTP_TCB_UNLOCK(stcb);
4385 SCTP_INP_RUNLOCK(inp);
4390 case SCTP_HMAC_IDENT:
4392 struct sctp_hmacalgo *shmac;
4393 sctp_hmaclist_t *hmaclist;
4397 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4398 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4399 (shmac->shmac_number_of_idents > 0xffff)) {
4400 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4405 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4406 if (hmaclist == NULL) {
4407 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4411 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4412 hmacid = shmac->shmac_idents[i];
4413 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4414 /* invalid HMACs were found */ ;
4415 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4417 sctp_free_hmaclist(hmaclist);
4418 goto sctp_set_hmac_done;
4421 for (i = 0; i < hmaclist->num_algo; i++) {
4422 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4423 /* already in list */
4427 if (i == hmaclist->num_algo) {
4428 /* not found in list */
4429 sctp_free_hmaclist(hmaclist);
4430 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4434 /* set it on the endpoint */
4435 SCTP_INP_WLOCK(inp);
4436 if (inp->sctp_ep.local_hmacs)
4437 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4438 inp->sctp_ep.local_hmacs = hmaclist;
4439 SCTP_INP_WUNLOCK(inp);
4443 case SCTP_AUTH_ACTIVE_KEY:
4445 struct sctp_authkeyid *scact;
4447 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4448 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4450 /* set the active key on the right place */
4452 /* set the active key on the assoc */
4453 if (sctp_auth_setactivekey(stcb,
4454 scact->scact_keynumber)) {
4455 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4456 SCTP_FROM_SCTP_USRREQ,
4460 SCTP_TCB_UNLOCK(stcb);
4462 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4463 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4464 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4465 ((scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4466 (scact->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4467 SCTP_INP_WLOCK(inp);
4468 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4469 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4472 SCTP_INP_WUNLOCK(inp);
4474 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4475 ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4476 (scact->scact_assoc_id == SCTP_ALL_ASSOC))) {
4477 SCTP_INP_RLOCK(inp);
4478 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4479 SCTP_TCB_LOCK(stcb);
4480 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4481 SCTP_TCB_UNLOCK(stcb);
4483 SCTP_INP_RUNLOCK(inp);
4488 case SCTP_AUTH_DELETE_KEY:
4490 struct sctp_authkeyid *scdel;
4492 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4493 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4495 /* delete the key from the right place */
4497 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4498 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4501 SCTP_TCB_UNLOCK(stcb);
4503 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4504 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4505 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4506 ((scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4507 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4508 SCTP_INP_WLOCK(inp);
4509 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4510 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4513 SCTP_INP_WUNLOCK(inp);
4515 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4516 ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4517 (scdel->scact_assoc_id == SCTP_ALL_ASSOC))) {
4518 SCTP_INP_RLOCK(inp);
4519 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4520 SCTP_TCB_LOCK(stcb);
4521 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4522 SCTP_TCB_UNLOCK(stcb);
4524 SCTP_INP_RUNLOCK(inp);
4529 case SCTP_AUTH_DEACTIVATE_KEY:
4531 struct sctp_authkeyid *keyid;
4533 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4534 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4536 /* deactivate the key from the right place */
4538 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4539 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4542 SCTP_TCB_UNLOCK(stcb);
4544 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4545 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4546 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4547 ((keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4548 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4549 SCTP_INP_WLOCK(inp);
4550 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4551 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4554 SCTP_INP_WUNLOCK(inp);
4556 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4557 ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4558 (keyid->scact_assoc_id == SCTP_ALL_ASSOC))) {
4559 SCTP_INP_RLOCK(inp);
4560 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4561 SCTP_TCB_LOCK(stcb);
4562 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4563 SCTP_TCB_UNLOCK(stcb);
4565 SCTP_INP_RUNLOCK(inp);
4570 case SCTP_ENABLE_STREAM_RESET:
4572 struct sctp_assoc_value *av;
4574 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4575 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4576 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4580 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4582 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4583 SCTP_TCB_UNLOCK(stcb);
4585 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4586 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4587 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4588 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4589 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4590 SCTP_INP_WLOCK(inp);
4591 inp->local_strreset_support = (uint8_t)av->assoc_value;
4592 SCTP_INP_WUNLOCK(inp);
4594 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4595 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4596 (av->assoc_id == SCTP_ALL_ASSOC))) {
4597 SCTP_INP_RLOCK(inp);
4598 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4599 SCTP_TCB_LOCK(stcb);
4600 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4601 SCTP_TCB_UNLOCK(stcb);
4603 SCTP_INP_RUNLOCK(inp);
4608 case SCTP_RESET_STREAMS:
4610 struct sctp_reset_streams *strrst;
4611 int i, send_out = 0;
4614 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4615 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4617 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4621 if (stcb->asoc.reconfig_supported == 0) {
4623 * Peer does not support the chunk type.
4625 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4627 SCTP_TCB_UNLOCK(stcb);
4630 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4631 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4633 SCTP_TCB_UNLOCK(stcb);
4636 if (sizeof(struct sctp_reset_streams) +
4637 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4639 SCTP_TCB_UNLOCK(stcb);
4642 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4644 if (stcb->asoc.stream_reset_outstanding) {
4645 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4647 SCTP_TCB_UNLOCK(stcb);
4651 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4654 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4655 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4657 SCTP_TCB_UNLOCK(stcb);
4660 if ((send_in == 0) && (send_out == 0)) {
4661 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4663 SCTP_TCB_UNLOCK(stcb);
4666 for (i = 0; i < strrst->srs_number_streams; i++) {
4668 (strrst->srs_stream_list[i] >= stcb->asoc.streamincnt)) {
4669 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4674 (strrst->srs_stream_list[i] >= stcb->asoc.streamoutcnt)) {
4675 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4681 SCTP_TCB_UNLOCK(stcb);
4688 if (strrst->srs_number_streams) {
4689 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4690 strm = strrst->srs_stream_list[i];
4691 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4692 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4698 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4699 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4700 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4707 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4708 strrst->srs_stream_list,
4709 send_in, 0, 0, 0, 0, 0);
4711 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4714 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4717 * For outgoing streams don't report any
4718 * problems in sending the request to the
4719 * application. XXX: Double check resetting
4724 SCTP_TCB_UNLOCK(stcb);
4727 case SCTP_ADD_STREAMS:
4729 struct sctp_add_streams *stradd;
4730 uint8_t addstream = 0;
4731 uint16_t add_o_strmcnt = 0;
4732 uint16_t add_i_strmcnt = 0;
4734 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4735 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4737 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4741 if (stcb->asoc.reconfig_supported == 0) {
4743 * Peer does not support the chunk type.
4745 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4747 SCTP_TCB_UNLOCK(stcb);
4750 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4751 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4753 SCTP_TCB_UNLOCK(stcb);
4756 if (stcb->asoc.stream_reset_outstanding) {
4757 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4759 SCTP_TCB_UNLOCK(stcb);
4762 if ((stradd->sas_outstrms == 0) &&
4763 (stradd->sas_instrms == 0)) {
4767 if (stradd->sas_outstrms) {
4769 /* We allocate here */
4770 add_o_strmcnt = stradd->sas_outstrms;
4771 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4772 /* You can't have more than 64k */
4777 if (stradd->sas_instrms) {
4782 * We allocate inside
4783 * sctp_send_str_reset_req()
4785 add_i_strmcnt = stradd->sas_instrms;
4786 cnt = add_i_strmcnt;
4787 cnt += stcb->asoc.streamincnt;
4788 if (cnt > 0x0000ffff) {
4789 /* You can't have more than 64k */
4793 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4794 /* More than you are allowed */
4799 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4800 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4802 SCTP_TCB_UNLOCK(stcb);
4805 case SCTP_RESET_ASSOC:
4810 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4811 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4813 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4817 if (stcb->asoc.reconfig_supported == 0) {
4819 * Peer does not support the chunk type.
4821 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4823 SCTP_TCB_UNLOCK(stcb);
4826 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4827 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4829 SCTP_TCB_UNLOCK(stcb);
4832 if (stcb->asoc.stream_reset_outstanding) {
4833 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4835 SCTP_TCB_UNLOCK(stcb);
4839 * Is there any data pending in the send or sent
4842 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4843 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4846 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4847 SCTP_TCB_UNLOCK(stcb);
4850 /* Do any streams have data queued? */
4851 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4852 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4856 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4857 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4858 SCTP_TCB_UNLOCK(stcb);
4861 case SCTP_CONNECT_X:
4862 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4863 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4867 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4869 case SCTP_CONNECT_X_DELAYED:
4870 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4871 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4875 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4877 case SCTP_CONNECT_X_COMPLETE:
4879 struct sockaddr *sa;
4881 /* FIXME MT: check correct? */
4882 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4885 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4886 SCTP_INP_RLOCK(inp);
4887 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4889 SCTP_TCB_LOCK(stcb);
4891 SCTP_INP_RUNLOCK(inp);
4894 * We increment here since
4895 * sctp_findassociation_ep_addr() wil do a
4896 * decrement if it finds the stcb as long as
4897 * the locked tcb (last argument) is NOT a
4900 SCTP_INP_INCR_REF(inp);
4901 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4903 SCTP_INP_DECR_REF(inp);
4908 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4912 if (stcb->asoc.delayed_connection == 1) {
4913 stcb->asoc.delayed_connection = 0;
4914 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4915 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4916 stcb->asoc.primary_destination,
4917 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4918 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4921 * already expired or did not use delayed
4924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4927 SCTP_TCB_UNLOCK(stcb);
4930 case SCTP_MAX_BURST:
4932 struct sctp_assoc_value *av;
4934 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4935 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4938 stcb->asoc.max_burst = av->assoc_value;
4939 SCTP_TCB_UNLOCK(stcb);
4941 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4942 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4943 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4944 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4945 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4946 SCTP_INP_WLOCK(inp);
4947 inp->sctp_ep.max_burst = av->assoc_value;
4948 SCTP_INP_WUNLOCK(inp);
4950 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4951 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4952 (av->assoc_id == SCTP_ALL_ASSOC))) {
4953 SCTP_INP_RLOCK(inp);
4954 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4955 SCTP_TCB_LOCK(stcb);
4956 stcb->asoc.max_burst = av->assoc_value;
4957 SCTP_TCB_UNLOCK(stcb);
4959 SCTP_INP_RUNLOCK(inp);
4966 struct sctp_assoc_value *av;
4968 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4969 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4972 stcb->asoc.sctp_frag_point = av->assoc_value;
4973 SCTP_TCB_UNLOCK(stcb);
4975 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4976 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4977 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4978 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
4979 SCTP_INP_WLOCK(inp);
4980 inp->sctp_frag_point = av->assoc_value;
4981 SCTP_INP_WUNLOCK(inp);
4983 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4991 struct sctp_event_subscribe *events;
4993 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4995 SCTP_INP_WLOCK(inp);
4996 if (events->sctp_data_io_event) {
4997 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4999 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5002 if (events->sctp_association_event) {
5003 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5005 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5008 if (events->sctp_address_event) {
5009 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5011 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5014 if (events->sctp_send_failure_event) {
5015 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5017 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5020 if (events->sctp_peer_error_event) {
5021 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5023 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5026 if (events->sctp_shutdown_event) {
5027 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5029 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5032 if (events->sctp_partial_delivery_event) {
5033 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5035 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5038 if (events->sctp_adaptation_layer_event) {
5039 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5041 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5044 if (events->sctp_authentication_event) {
5045 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5047 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5050 if (events->sctp_sender_dry_event) {
5051 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5053 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5056 if (events->sctp_stream_reset_event) {
5057 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5059 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5062 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5063 SCTP_TCB_LOCK(stcb);
5064 if (events->sctp_association_event) {
5065 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5067 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5069 if (events->sctp_address_event) {
5070 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5072 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5074 if (events->sctp_send_failure_event) {
5075 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5077 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5079 if (events->sctp_peer_error_event) {
5080 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5082 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5084 if (events->sctp_shutdown_event) {
5085 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5087 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5089 if (events->sctp_partial_delivery_event) {
5090 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5092 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5094 if (events->sctp_adaptation_layer_event) {
5095 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5097 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5099 if (events->sctp_authentication_event) {
5100 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5102 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5104 if (events->sctp_sender_dry_event) {
5105 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5107 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5109 if (events->sctp_stream_reset_event) {
5110 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5112 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5114 SCTP_TCB_UNLOCK(stcb);
5117 * Send up the sender dry event only for 1-to-1
5120 if (events->sctp_sender_dry_event) {
5121 if (((inp->sctp_flags & (SCTP_PCB_FLAGS_TCPTYPE | SCTP_PCB_FLAGS_IN_TCPPOOL)) != 0) &&
5122 !SCTP_IS_LISTENING(inp)) {
5123 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5125 SCTP_TCB_LOCK(stcb);
5126 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5127 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5128 (stcb->asoc.stream_queue_cnt == 0)) {
5129 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5131 SCTP_TCB_UNLOCK(stcb);
5135 SCTP_INP_WUNLOCK(inp);
5138 case SCTP_ADAPTATION_LAYER:
5140 struct sctp_setadaptation *adap_bits;
5142 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5143 SCTP_INP_WLOCK(inp);
5144 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5145 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5146 SCTP_INP_WUNLOCK(inp);
5150 case SCTP_SET_INITIAL_DBG_SEQ:
5154 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5155 SCTP_INP_WLOCK(inp);
5156 inp->sctp_ep.initial_sequence_debug = *vvv;
5157 SCTP_INP_WUNLOCK(inp);
5161 case SCTP_DEFAULT_SEND_PARAM:
5163 struct sctp_sndrcvinfo *s_info;
5165 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5166 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5169 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5170 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5172 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5175 SCTP_TCB_UNLOCK(stcb);
5177 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5178 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5179 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5180 ((s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5181 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)))) {
5182 SCTP_INP_WLOCK(inp);
5183 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5184 SCTP_INP_WUNLOCK(inp);
5186 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5187 ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5188 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC))) {
5189 SCTP_INP_RLOCK(inp);
5190 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5191 SCTP_TCB_LOCK(stcb);
5192 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5193 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5195 SCTP_TCB_UNLOCK(stcb);
5197 SCTP_INP_RUNLOCK(inp);
5202 case SCTP_PEER_ADDR_PARAMS:
5204 struct sctp_paddrparams *paddrp;
5205 struct sctp_nets *net;
5206 struct sockaddr *addr;
5207 #if defined(INET) && defined(INET6)
5208 struct sockaddr_in sin_store;
5211 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5212 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5214 #if defined(INET) && defined(INET6)
5215 if (paddrp->spp_address.ss_family == AF_INET6) {
5216 struct sockaddr_in6 *sin6;
5218 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5219 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5220 in6_sin6_2_sin(&sin_store, sin6);
5221 addr = (struct sockaddr *)&sin_store;
5223 addr = (struct sockaddr *)&paddrp->spp_address;
5226 addr = (struct sockaddr *)&paddrp->spp_address;
5229 addr = (struct sockaddr *)&paddrp->spp_address;
5232 net = sctp_findnet(stcb, addr);
5235 * We increment here since
5236 * sctp_findassociation_ep_addr() wil do a
5237 * decrement if it finds the stcb as long as
5238 * the locked tcb (last argument) is NOT a
5242 SCTP_INP_INCR_REF(inp);
5243 stcb = sctp_findassociation_ep_addr(&inp, addr,
5246 SCTP_INP_DECR_REF(inp);
5249 if ((stcb != NULL) && (net == NULL)) {
5251 if (addr->sa_family == AF_INET) {
5252 struct sockaddr_in *sin;
5254 sin = (struct sockaddr_in *)addr;
5255 if (sin->sin_addr.s_addr != INADDR_ANY) {
5256 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5257 SCTP_TCB_UNLOCK(stcb);
5264 if (addr->sa_family == AF_INET6) {
5265 struct sockaddr_in6 *sin6;
5267 sin6 = (struct sockaddr_in6 *)addr;
5268 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5269 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5270 SCTP_TCB_UNLOCK(stcb);
5277 error = EAFNOSUPPORT;
5278 SCTP_TCB_UNLOCK(stcb);
5279 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5284 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5286 SCTP_TCB_UNLOCK(stcb);
5287 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5291 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5293 SCTP_TCB_UNLOCK(stcb);
5294 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5297 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) &&
5298 (paddrp->spp_pathmtu > 0) &&
5299 ((paddrp->spp_pathmtu < SCTP_SMALLEST_PMTU) ||
5300 (paddrp->spp_pathmtu > SCTP_LARGEST_PMTU))) {
5302 SCTP_TCB_UNLOCK(stcb);
5303 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5308 /************************TCB SPECIFIC SET ******************/
5310 /************************NET SPECIFIC SET ******************/
5311 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5312 if (((net->dest_state & SCTP_ADDR_UNCONFIRMED) == 0) &&
5313 ((net->dest_state & SCTP_ADDR_NOHB) == 0)) {
5314 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5315 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5317 net->dest_state |= SCTP_ADDR_NOHB;
5319 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5320 if (paddrp->spp_hbinterval) {
5321 net->heart_beat_delay = paddrp->spp_hbinterval;
5322 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5323 net->heart_beat_delay = 0;
5325 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5326 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5327 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5328 net->dest_state &= ~SCTP_ADDR_NOHB;
5330 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5331 if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
5332 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5333 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5334 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5337 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5338 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5339 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5340 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5342 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5343 if (paddrp->spp_pathmtu > 0) {
5344 net->mtu = paddrp->spp_pathmtu;
5345 switch (net->ro._l_addr.sa.sa_family) {
5348 net->mtu += SCTP_MIN_V4_OVERHEAD;
5353 net->mtu += SCTP_MIN_OVERHEAD;
5359 if (net->mtu < stcb->asoc.smallest_mtu) {
5360 sctp_pathmtu_adjustment(stcb, net->mtu, true);
5364 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5365 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5366 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5368 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5370 if (paddrp->spp_pathmaxrxt > 0) {
5371 if (net->dest_state & SCTP_ADDR_PF) {
5372 if (net->error_count > paddrp->spp_pathmaxrxt) {
5373 net->dest_state &= ~SCTP_ADDR_PF;
5376 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5377 (net->error_count > net->pf_threshold)) {
5378 net->dest_state |= SCTP_ADDR_PF;
5379 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5380 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5381 stcb->sctp_ep, stcb, net,
5382 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5383 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5386 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5387 if (net->error_count > paddrp->spp_pathmaxrxt) {
5388 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5389 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5392 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5393 net->dest_state |= SCTP_ADDR_REACHABLE;
5394 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5397 net->failure_threshold = paddrp->spp_pathmaxrxt;
5399 if (paddrp->spp_flags & SPP_DSCP) {
5400 net->dscp = paddrp->spp_dscp & 0xfc;
5404 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5405 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5406 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5407 net->flowlabel |= 0x80000000;
5412 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5413 if (paddrp->spp_pathmaxrxt > 0) {
5414 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5415 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5416 if (net->dest_state & SCTP_ADDR_PF) {
5417 if (net->error_count > paddrp->spp_pathmaxrxt) {
5418 net->dest_state &= ~SCTP_ADDR_PF;
5421 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5422 (net->error_count > net->pf_threshold)) {
5423 net->dest_state |= SCTP_ADDR_PF;
5424 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5425 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5426 stcb->sctp_ep, stcb, net,
5427 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5428 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5431 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5432 if (net->error_count > paddrp->spp_pathmaxrxt) {
5433 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5434 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5437 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5438 net->dest_state |= SCTP_ADDR_REACHABLE;
5439 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5442 net->failure_threshold = paddrp->spp_pathmaxrxt;
5445 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5446 if (paddrp->spp_hbinterval != 0) {
5447 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5448 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5449 stcb->asoc.heart_beat_delay = 0;
5451 /* Turn back on the timer */
5452 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5453 if (paddrp->spp_hbinterval != 0) {
5454 net->heart_beat_delay = paddrp->spp_hbinterval;
5455 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5456 net->heart_beat_delay = 0;
5458 if (net->dest_state & SCTP_ADDR_NOHB) {
5459 net->dest_state &= ~SCTP_ADDR_NOHB;
5461 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5462 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5463 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5465 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5467 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5468 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5469 if ((net->dest_state & SCTP_ADDR_NOHB) == 0) {
5470 net->dest_state |= SCTP_ADDR_NOHB;
5471 if ((net->dest_state & SCTP_ADDR_UNCONFIRMED) == 0) {
5472 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5474 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5478 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5480 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5481 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5482 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5483 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5484 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5486 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5487 if (paddrp->spp_pathmtu > 0) {
5488 net->mtu = paddrp->spp_pathmtu;
5489 switch (net->ro._l_addr.sa.sa_family) {
5492 net->mtu += SCTP_MIN_V4_OVERHEAD;
5497 net->mtu += SCTP_MIN_OVERHEAD;
5503 if (net->mtu < stcb->asoc.smallest_mtu) {
5504 sctp_pathmtu_adjustment(stcb, net->mtu, true);
5508 if (paddrp->spp_pathmtu > 0) {
5509 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5511 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5513 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5514 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5515 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5516 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5518 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5520 stcb->asoc.default_mtu = 0;
5521 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5523 if (paddrp->spp_flags & SPP_DSCP) {
5524 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5525 net->dscp = paddrp->spp_dscp & 0xfc;
5528 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5529 stcb->asoc.default_dscp |= 0x01;
5532 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5533 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5534 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5535 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5536 net->flowlabel |= 0x80000000;
5539 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5540 stcb->asoc.default_flowlabel |= 0x80000000;
5544 SCTP_TCB_UNLOCK(stcb);
5546 /************************NO TCB, SET TO default stuff ******************/
5547 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5548 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5549 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5550 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
5551 SCTP_INP_WLOCK(inp);
5553 * For the TOS/FLOWLABEL stuff you
5554 * set it with the options on the
5557 if (paddrp->spp_pathmaxrxt > 0) {
5558 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5561 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5562 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5563 else if (paddrp->spp_hbinterval != 0) {
5564 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5565 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5566 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5569 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5570 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5571 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5572 } else if (paddrp->spp_hbinterval) {
5573 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5575 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5576 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5577 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5579 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5580 inp->sctp_ep.default_mtu = 0;
5581 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5582 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5583 if (paddrp->spp_pathmtu > 0) {
5584 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5586 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5588 if (paddrp->spp_flags & SPP_DSCP) {
5589 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5590 inp->sctp_ep.default_dscp |= 0x01;
5593 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5594 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5595 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5596 inp->sctp_ep.default_flowlabel |= 0x80000000;
5600 SCTP_INP_WUNLOCK(inp);
5602 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5610 struct sctp_rtoinfo *srto;
5611 uint32_t new_init, new_min, new_max;
5613 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5614 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5617 if (srto->srto_initial)
5618 new_init = srto->srto_initial;
5620 new_init = stcb->asoc.initial_rto;
5622 new_max = srto->srto_max;
5624 new_max = stcb->asoc.maxrto;
5626 new_min = srto->srto_min;
5628 new_min = stcb->asoc.minrto;
5629 if ((new_min <= new_init) && (new_init <= new_max)) {
5630 stcb->asoc.initial_rto = new_init;
5631 stcb->asoc.maxrto = new_max;
5632 stcb->asoc.minrto = new_min;
5634 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5637 SCTP_TCB_UNLOCK(stcb);
5639 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5640 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5641 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5642 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
5643 SCTP_INP_WLOCK(inp);
5644 if (srto->srto_initial)
5645 new_init = srto->srto_initial;
5647 new_init = inp->sctp_ep.initial_rto;
5649 new_max = srto->srto_max;
5651 new_max = inp->sctp_ep.sctp_maxrto;
5653 new_min = srto->srto_min;
5655 new_min = inp->sctp_ep.sctp_minrto;
5656 if ((new_min <= new_init) && (new_init <= new_max)) {
5657 inp->sctp_ep.initial_rto = new_init;
5658 inp->sctp_ep.sctp_maxrto = new_max;
5659 inp->sctp_ep.sctp_minrto = new_min;
5661 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5664 SCTP_INP_WUNLOCK(inp);
5666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5672 case SCTP_ASSOCINFO:
5674 struct sctp_assocparams *sasoc;
5676 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5677 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5678 if (sasoc->sasoc_cookie_life > 0) {
5679 /* boundary check the cookie life */
5680 if (sasoc->sasoc_cookie_life < SCTP_MIN_COOKIE_LIFE) {
5681 sasoc->sasoc_cookie_life = SCTP_MIN_COOKIE_LIFE;
5683 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5684 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5688 if (sasoc->sasoc_asocmaxrxt > 0) {
5689 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5691 if (sasoc->sasoc_cookie_life > 0) {
5692 stcb->asoc.cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5694 SCTP_TCB_UNLOCK(stcb);
5696 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5697 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5698 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5699 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
5700 SCTP_INP_WLOCK(inp);
5701 if (sasoc->sasoc_asocmaxrxt > 0) {
5702 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5704 if (sasoc->sasoc_cookie_life > 0) {
5705 inp->sctp_ep.def_cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5707 SCTP_INP_WUNLOCK(inp);
5709 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5717 struct sctp_initmsg *sinit;
5719 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5720 SCTP_INP_WLOCK(inp);
5721 if (sinit->sinit_num_ostreams)
5722 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5724 if (sinit->sinit_max_instreams)
5725 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5727 if (sinit->sinit_max_attempts)
5728 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5730 if (sinit->sinit_max_init_timeo)
5731 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5732 SCTP_INP_WUNLOCK(inp);
5735 case SCTP_PRIMARY_ADDR:
5737 struct sctp_setprim *spa;
5738 struct sctp_nets *net;
5739 struct sockaddr *addr;
5740 #if defined(INET) && defined(INET6)
5741 struct sockaddr_in sin_store;
5744 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5745 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5747 #if defined(INET) && defined(INET6)
5748 if (spa->ssp_addr.ss_family == AF_INET6) {
5749 struct sockaddr_in6 *sin6;
5751 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5752 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5753 in6_sin6_2_sin(&sin_store, sin6);
5754 addr = (struct sockaddr *)&sin_store;
5756 addr = (struct sockaddr *)&spa->ssp_addr;
5759 addr = (struct sockaddr *)&spa->ssp_addr;
5762 addr = (struct sockaddr *)&spa->ssp_addr;
5765 net = sctp_findnet(stcb, addr);
5768 * We increment here since
5769 * sctp_findassociation_ep_addr() wil do a
5770 * decrement if it finds the stcb as long as
5771 * the locked tcb (last argument) is NOT a
5775 SCTP_INP_INCR_REF(inp);
5776 stcb = sctp_findassociation_ep_addr(&inp, addr,
5779 SCTP_INP_DECR_REF(inp);
5783 if ((stcb != NULL) && (net != NULL)) {
5784 if (net != stcb->asoc.primary_destination) {
5785 if ((net->dest_state & SCTP_ADDR_UNCONFIRMED) == 0) {
5786 /* Ok we need to set it */
5787 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5788 if ((stcb->asoc.alternate) &&
5789 ((net->dest_state & SCTP_ADDR_PF) == 0) &&
5790 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5791 sctp_free_remote_addr(stcb->asoc.alternate);
5792 stcb->asoc.alternate = NULL;
5795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5799 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5808 SCTP_TCB_UNLOCK(stcb);
5812 case SCTP_SET_DYNAMIC_PRIMARY:
5814 union sctp_sockstore *ss;
5816 error = priv_check(curthread,
5817 PRIV_NETINET_RESERVEDPORT);
5821 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5822 /* SUPER USER CHECK? */
5823 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5826 case SCTP_SET_PEER_PRIMARY_ADDR:
5828 struct sctp_setpeerprim *sspp;
5829 struct sockaddr *addr;
5830 #if defined(INET) && defined(INET6)
5831 struct sockaddr_in sin_store;
5834 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5835 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5837 struct sctp_ifa *ifa;
5839 #if defined(INET) && defined(INET6)
5840 if (sspp->sspp_addr.ss_family == AF_INET6) {
5841 struct sockaddr_in6 *sin6;
5843 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5844 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5845 in6_sin6_2_sin(&sin_store, sin6);
5846 addr = (struct sockaddr *)&sin_store;
5848 addr = (struct sockaddr *)&sspp->sspp_addr;
5851 addr = (struct sockaddr *)&sspp->sspp_addr;
5854 addr = (struct sockaddr *)&sspp->sspp_addr;
5856 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5858 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5862 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5864 * Must validate the ifa found is in
5867 struct sctp_laddr *laddr;
5870 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5871 if (laddr->ifa == NULL) {
5872 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5876 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5877 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5880 if (laddr->ifa == ifa) {
5886 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5891 switch (addr->sa_family) {
5895 struct sockaddr_in *sin;
5897 sin = (struct sockaddr_in *)addr;
5898 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5899 &sin->sin_addr) != 0) {
5900 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5910 struct sockaddr_in6 *sin6;
5912 sin6 = (struct sockaddr_in6 *)addr;
5913 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5914 &sin6->sin6_addr) != 0) {
5915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5923 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5928 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5929 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5932 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5934 SCTP_TCB_UNLOCK(stcb);
5936 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5941 case SCTP_BINDX_ADD_ADDR:
5943 struct sockaddr *sa;
5946 td = (struct thread *)p;
5947 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
5949 if (sa->sa_family == AF_INET) {
5950 if (optsize < sizeof(struct sockaddr_in)) {
5951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5956 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
5957 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5963 if (sa->sa_family == AF_INET6) {
5964 if (optsize < sizeof(struct sockaddr_in6)) {
5965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5970 (error = prison_local_ip6(td->td_ucred,
5971 &(((struct sockaddr_in6 *)sa)->sin6_addr),
5972 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5973 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5979 error = EAFNOSUPPORT;
5982 sctp_bindx_add_address(so, inp, sa, vrf_id, &error, p);
5985 case SCTP_BINDX_REM_ADDR:
5987 struct sockaddr *sa;
5990 td = (struct thread *)p;
5992 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
5994 if (sa->sa_family == AF_INET) {
5995 if (optsize < sizeof(struct sockaddr_in)) {
5996 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6001 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
6002 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6008 if (sa->sa_family == AF_INET6) {
6009 if (optsize < sizeof(struct sockaddr_in6)) {
6010 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6015 (error = prison_local_ip6(td->td_ucred,
6016 &(((struct sockaddr_in6 *)sa)->sin6_addr),
6017 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6018 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6024 error = EAFNOSUPPORT;
6027 sctp_bindx_delete_address(inp, sa, vrf_id, &error);
6032 struct sctp_event *event;
6033 uint32_t event_type;
6035 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6036 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6037 switch (event->se_type) {
6038 case SCTP_ASSOC_CHANGE:
6039 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6041 case SCTP_PEER_ADDR_CHANGE:
6042 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6044 case SCTP_REMOTE_ERROR:
6045 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6047 case SCTP_SEND_FAILED:
6048 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6050 case SCTP_SHUTDOWN_EVENT:
6051 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6053 case SCTP_ADAPTATION_INDICATION:
6054 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6056 case SCTP_PARTIAL_DELIVERY_EVENT:
6057 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6059 case SCTP_AUTHENTICATION_EVENT:
6060 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6062 case SCTP_STREAM_RESET_EVENT:
6063 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6065 case SCTP_SENDER_DRY_EVENT:
6066 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6068 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6070 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6073 case SCTP_ASSOC_RESET_EVENT:
6074 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6076 case SCTP_STREAM_CHANGE_EVENT:
6077 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6079 case SCTP_SEND_FAILED_EVENT:
6080 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6084 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6088 if (event_type > 0) {
6091 sctp_stcb_feature_on(inp, stcb, event_type);
6092 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6093 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6094 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6095 (stcb->asoc.stream_queue_cnt == 0)) {
6096 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6100 sctp_stcb_feature_off(inp, stcb, event_type);
6102 SCTP_TCB_UNLOCK(stcb);
6105 * We don't want to send up a storm
6106 * of events, so return an error for
6109 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6110 (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6111 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6112 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6113 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6117 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6118 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6119 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6120 ((event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6121 (event->se_assoc_id == SCTP_ALL_ASSOC)))) {
6122 SCTP_INP_WLOCK(inp);
6124 sctp_feature_on(inp, event_type);
6126 sctp_feature_off(inp, event_type);
6128 SCTP_INP_WUNLOCK(inp);
6130 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6131 ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6132 (event->se_assoc_id == SCTP_ALL_ASSOC))) {
6133 SCTP_INP_RLOCK(inp);
6134 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6135 SCTP_TCB_LOCK(stcb);
6137 sctp_stcb_feature_on(inp, stcb, event_type);
6139 sctp_stcb_feature_off(inp, stcb, event_type);
6141 SCTP_TCB_UNLOCK(stcb);
6143 SCTP_INP_RUNLOCK(inp);
6148 SCTP_TCB_UNLOCK(stcb);
6153 case SCTP_RECVRCVINFO:
6157 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6158 SCTP_INP_WLOCK(inp);
6160 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6162 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6164 SCTP_INP_WUNLOCK(inp);
6167 case SCTP_RECVNXTINFO:
6171 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6172 SCTP_INP_WLOCK(inp);
6174 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6176 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6178 SCTP_INP_WUNLOCK(inp);
6181 case SCTP_DEFAULT_SNDINFO:
6183 struct sctp_sndinfo *info;
6186 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6187 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6190 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6191 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6192 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6193 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6194 stcb->asoc.def_send.sinfo_flags |= policy;
6195 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6196 stcb->asoc.def_send.sinfo_context = info->snd_context;
6198 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6201 SCTP_TCB_UNLOCK(stcb);
6203 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6204 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6205 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6206 ((info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6207 (info->snd_assoc_id == SCTP_ALL_ASSOC)))) {
6208 SCTP_INP_WLOCK(inp);
6209 inp->def_send.sinfo_stream = info->snd_sid;
6210 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6211 inp->def_send.sinfo_flags = info->snd_flags;
6212 inp->def_send.sinfo_flags |= policy;
6213 inp->def_send.sinfo_ppid = info->snd_ppid;
6214 inp->def_send.sinfo_context = info->snd_context;
6215 SCTP_INP_WUNLOCK(inp);
6217 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6218 ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6219 (info->snd_assoc_id == SCTP_ALL_ASSOC))) {
6220 SCTP_INP_RLOCK(inp);
6221 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6222 SCTP_TCB_LOCK(stcb);
6223 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6224 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6225 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6226 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6227 stcb->asoc.def_send.sinfo_flags |= policy;
6228 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6229 stcb->asoc.def_send.sinfo_context = info->snd_context;
6231 SCTP_TCB_UNLOCK(stcb);
6233 SCTP_INP_RUNLOCK(inp);
6238 case SCTP_DEFAULT_PRINFO:
6240 struct sctp_default_prinfo *info;
6242 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6243 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6245 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6247 SCTP_TCB_UNLOCK(stcb);
6249 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6254 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6255 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6256 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6257 SCTP_TCB_UNLOCK(stcb);
6259 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6260 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6261 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6262 ((info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6263 (info->pr_assoc_id == SCTP_ALL_ASSOC)))) {
6264 SCTP_INP_WLOCK(inp);
6265 inp->def_send.sinfo_flags &= 0xfff0;
6266 inp->def_send.sinfo_flags |= info->pr_policy;
6267 inp->def_send.sinfo_timetolive = info->pr_value;
6268 SCTP_INP_WUNLOCK(inp);
6270 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6271 ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6272 (info->pr_assoc_id == SCTP_ALL_ASSOC))) {
6273 SCTP_INP_RLOCK(inp);
6274 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6275 SCTP_TCB_LOCK(stcb);
6276 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6277 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6278 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6279 SCTP_TCB_UNLOCK(stcb);
6281 SCTP_INP_RUNLOCK(inp);
6286 case SCTP_PEER_ADDR_THLDS:
6287 /* Applies to the specific association */
6289 struct sctp_paddrthlds *thlds;
6290 struct sctp_nets *net;
6291 struct sockaddr *addr;
6292 #if defined(INET) && defined(INET6)
6293 struct sockaddr_in sin_store;
6296 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6297 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6299 #if defined(INET) && defined(INET6)
6300 if (thlds->spt_address.ss_family == AF_INET6) {
6301 struct sockaddr_in6 *sin6;
6303 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6304 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6305 in6_sin6_2_sin(&sin_store, sin6);
6306 addr = (struct sockaddr *)&sin_store;
6308 addr = (struct sockaddr *)&thlds->spt_address;
6311 addr = (struct sockaddr *)&thlds->spt_address;
6314 addr = (struct sockaddr *)&thlds->spt_address;
6317 net = sctp_findnet(stcb, addr);
6320 * We increment here since
6321 * sctp_findassociation_ep_addr() wil do a
6322 * decrement if it finds the stcb as long as
6323 * the locked tcb (last argument) is NOT a
6327 SCTP_INP_INCR_REF(inp);
6328 stcb = sctp_findassociation_ep_addr(&inp, addr,
6331 SCTP_INP_DECR_REF(inp);
6334 if ((stcb != NULL) && (net == NULL)) {
6336 if (addr->sa_family == AF_INET) {
6337 struct sockaddr_in *sin;
6339 sin = (struct sockaddr_in *)addr;
6340 if (sin->sin_addr.s_addr != INADDR_ANY) {
6341 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6342 SCTP_TCB_UNLOCK(stcb);
6349 if (addr->sa_family == AF_INET6) {
6350 struct sockaddr_in6 *sin6;
6352 sin6 = (struct sockaddr_in6 *)addr;
6353 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6354 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6355 SCTP_TCB_UNLOCK(stcb);
6362 error = EAFNOSUPPORT;
6363 SCTP_TCB_UNLOCK(stcb);
6364 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6368 if (thlds->spt_pathcpthld != 0xffff) {
6370 SCTP_TCB_UNLOCK(stcb);
6373 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6378 net->failure_threshold = thlds->spt_pathmaxrxt;
6379 net->pf_threshold = thlds->spt_pathpfthld;
6380 if (net->dest_state & SCTP_ADDR_PF) {
6381 if ((net->error_count > net->failure_threshold) ||
6382 (net->error_count <= net->pf_threshold)) {
6383 net->dest_state &= ~SCTP_ADDR_PF;
6386 if ((net->error_count > net->pf_threshold) &&
6387 (net->error_count <= net->failure_threshold)) {
6388 net->dest_state |= SCTP_ADDR_PF;
6389 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6390 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6391 stcb->sctp_ep, stcb, net,
6392 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6393 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6396 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6397 if (net->error_count > net->failure_threshold) {
6398 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6399 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6402 if (net->error_count <= net->failure_threshold) {
6403 net->dest_state |= SCTP_ADDR_REACHABLE;
6404 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6408 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6409 net->failure_threshold = thlds->spt_pathmaxrxt;
6410 net->pf_threshold = thlds->spt_pathpfthld;
6411 if (net->dest_state & SCTP_ADDR_PF) {
6412 if ((net->error_count > net->failure_threshold) ||
6413 (net->error_count <= net->pf_threshold)) {
6414 net->dest_state &= ~SCTP_ADDR_PF;
6417 if ((net->error_count > net->pf_threshold) &&
6418 (net->error_count <= net->failure_threshold)) {
6419 net->dest_state |= SCTP_ADDR_PF;
6420 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6421 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6422 stcb->sctp_ep, stcb, net,
6423 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6424 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6427 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6428 if (net->error_count > net->failure_threshold) {
6429 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6430 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6433 if (net->error_count <= net->failure_threshold) {
6434 net->dest_state |= SCTP_ADDR_REACHABLE;
6435 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6439 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6440 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6442 SCTP_TCB_UNLOCK(stcb);
6444 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6445 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6446 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6447 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
6448 SCTP_INP_WLOCK(inp);
6449 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6450 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6451 SCTP_INP_WUNLOCK(inp);
6453 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6459 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6461 struct sctp_udpencaps *encaps;
6462 struct sctp_nets *net;
6463 struct sockaddr *addr;
6464 #if defined(INET) && defined(INET6)
6465 struct sockaddr_in sin_store;
6468 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6469 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6471 #if defined(INET) && defined(INET6)
6472 if (encaps->sue_address.ss_family == AF_INET6) {
6473 struct sockaddr_in6 *sin6;
6475 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6476 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6477 in6_sin6_2_sin(&sin_store, sin6);
6478 addr = (struct sockaddr *)&sin_store;
6480 addr = (struct sockaddr *)&encaps->sue_address;
6483 addr = (struct sockaddr *)&encaps->sue_address;
6486 addr = (struct sockaddr *)&encaps->sue_address;
6489 net = sctp_findnet(stcb, addr);
6492 * We increment here since
6493 * sctp_findassociation_ep_addr() wil do a
6494 * decrement if it finds the stcb as long as
6495 * the locked tcb (last argument) is NOT a
6499 SCTP_INP_INCR_REF(inp);
6500 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6502 SCTP_INP_DECR_REF(inp);
6505 if ((stcb != NULL) && (net == NULL)) {
6507 if (addr->sa_family == AF_INET) {
6508 struct sockaddr_in *sin;
6510 sin = (struct sockaddr_in *)addr;
6511 if (sin->sin_addr.s_addr != INADDR_ANY) {
6512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6513 SCTP_TCB_UNLOCK(stcb);
6520 if (addr->sa_family == AF_INET6) {
6521 struct sockaddr_in6 *sin6;
6523 sin6 = (struct sockaddr_in6 *)addr;
6524 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6525 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6526 SCTP_TCB_UNLOCK(stcb);
6533 error = EAFNOSUPPORT;
6534 SCTP_TCB_UNLOCK(stcb);
6535 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6542 net->port = encaps->sue_port;
6544 stcb->asoc.port = encaps->sue_port;
6546 SCTP_TCB_UNLOCK(stcb);
6548 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6549 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6550 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6551 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
6552 SCTP_INP_WLOCK(inp);
6553 inp->sctp_ep.port = encaps->sue_port;
6554 SCTP_INP_WUNLOCK(inp);
6556 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6562 case SCTP_ECN_SUPPORTED:
6564 struct sctp_assoc_value *av;
6566 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6567 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6570 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6572 SCTP_TCB_UNLOCK(stcb);
6574 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6575 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6576 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6577 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6578 SCTP_INP_WLOCK(inp);
6579 if (av->assoc_value == 0) {
6580 inp->ecn_supported = 0;
6582 inp->ecn_supported = 1;
6584 SCTP_INP_WUNLOCK(inp);
6586 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6592 case SCTP_PR_SUPPORTED:
6594 struct sctp_assoc_value *av;
6596 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6597 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6600 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6602 SCTP_TCB_UNLOCK(stcb);
6604 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6605 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6606 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6607 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6608 SCTP_INP_WLOCK(inp);
6609 if (av->assoc_value == 0) {
6610 inp->prsctp_supported = 0;
6612 inp->prsctp_supported = 1;
6614 SCTP_INP_WUNLOCK(inp);
6616 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6622 case SCTP_AUTH_SUPPORTED:
6624 struct sctp_assoc_value *av;
6626 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6627 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6630 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6632 SCTP_TCB_UNLOCK(stcb);
6634 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6635 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6636 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6637 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6638 if ((av->assoc_value == 0) &&
6639 (inp->asconf_supported == 1)) {
6641 * AUTH is required for
6644 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6647 SCTP_INP_WLOCK(inp);
6648 if (av->assoc_value == 0) {
6649 inp->auth_supported = 0;
6651 inp->auth_supported = 1;
6653 SCTP_INP_WUNLOCK(inp);
6656 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6662 case SCTP_ASCONF_SUPPORTED:
6664 struct sctp_assoc_value *av;
6666 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6667 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6670 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6672 SCTP_TCB_UNLOCK(stcb);
6674 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6675 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6676 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6677 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6678 if ((av->assoc_value != 0) &&
6679 (inp->auth_supported == 0)) {
6681 * AUTH is required for
6684 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6687 SCTP_INP_WLOCK(inp);
6688 if (av->assoc_value == 0) {
6689 inp->asconf_supported = 0;
6690 sctp_auth_delete_chunk(SCTP_ASCONF,
6691 inp->sctp_ep.local_auth_chunks);
6692 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6693 inp->sctp_ep.local_auth_chunks);
6695 inp->asconf_supported = 1;
6696 sctp_auth_add_chunk(SCTP_ASCONF,
6697 inp->sctp_ep.local_auth_chunks);
6698 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6699 inp->sctp_ep.local_auth_chunks);
6701 SCTP_INP_WUNLOCK(inp);
6704 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6710 case SCTP_RECONFIG_SUPPORTED:
6712 struct sctp_assoc_value *av;
6714 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6715 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6718 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6720 SCTP_TCB_UNLOCK(stcb);
6722 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6723 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6724 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6725 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6726 SCTP_INP_WLOCK(inp);
6727 if (av->assoc_value == 0) {
6728 inp->reconfig_supported = 0;
6730 inp->reconfig_supported = 1;
6732 SCTP_INP_WUNLOCK(inp);
6734 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6740 case SCTP_NRSACK_SUPPORTED:
6742 struct sctp_assoc_value *av;
6744 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6745 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6748 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6750 SCTP_TCB_UNLOCK(stcb);
6752 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6753 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6754 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6755 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6756 SCTP_INP_WLOCK(inp);
6757 if (av->assoc_value == 0) {
6758 inp->nrsack_supported = 0;
6760 inp->nrsack_supported = 1;
6762 SCTP_INP_WUNLOCK(inp);
6764 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6770 case SCTP_PKTDROP_SUPPORTED:
6772 struct sctp_assoc_value *av;
6774 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6775 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6778 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6780 SCTP_TCB_UNLOCK(stcb);
6782 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6783 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6784 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6785 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6786 SCTP_INP_WLOCK(inp);
6787 if (av->assoc_value == 0) {
6788 inp->pktdrop_supported = 0;
6790 inp->pktdrop_supported = 1;
6792 SCTP_INP_WUNLOCK(inp);
6794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6802 struct sctp_assoc_value *av;
6803 struct sctp_nets *net;
6805 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6806 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6809 stcb->asoc.max_cwnd = av->assoc_value;
6810 if (stcb->asoc.max_cwnd > 0) {
6811 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6812 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6813 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6814 net->cwnd = stcb->asoc.max_cwnd;
6815 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6816 net->cwnd = net->mtu - sizeof(struct sctphdr);
6821 SCTP_TCB_UNLOCK(stcb);
6823 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6824 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6825 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6826 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6827 SCTP_INP_WLOCK(inp);
6828 inp->max_cwnd = av->assoc_value;
6829 SCTP_INP_WUNLOCK(inp);
6831 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6837 case SCTP_ACCEPT_ZERO_CHECKSUM:
6841 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
6842 if ((*value == SCTP_EDMID_NONE) ||
6843 (*value == SCTP_EDMID_LOWER_LAYER_DTLS)) {
6844 SCTP_INP_WLOCK(inp);
6845 inp->rcv_edmid = *value;
6846 SCTP_INP_WUNLOCK(inp);
6848 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6855 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6856 error = ENOPROTOOPT;
6858 } /* end switch (opt) */
6863 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6865 struct epoch_tracker et;
6866 struct sctp_inpcb *inp;
6867 void *optval = NULL;
6872 if ((sopt->sopt_level == SOL_SOCKET) &&
6873 (sopt->sopt_name == SO_SETFIB)) {
6874 inp = (struct sctp_inpcb *)so->so_pcb;
6876 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6879 SCTP_INP_WLOCK(inp);
6880 inp->fibnum = so->so_fibnum;
6881 SCTP_INP_WUNLOCK(inp);
6884 if (sopt->sopt_level != IPPROTO_SCTP) {
6885 /* wrong proto level... send back up to IP */
6887 if (INP_CHECK_SOCKAF(so, AF_INET6))
6888 error = ip6_ctloutput(so, sopt);
6890 #if defined(INET) && defined(INET6)
6894 error = ip_ctloutput(so, sopt);
6898 optsize = sopt->sopt_valsize;
6899 if (optsize > SCTP_SOCKET_OPTION_LIMIT) {
6900 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6904 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6905 if (optval == NULL) {
6906 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6909 error = sooptcopyin(sopt, optval, optsize, optsize);
6911 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6915 p = (void *)sopt->sopt_td;
6916 if (sopt->sopt_dir == SOPT_SET) {
6917 NET_EPOCH_ENTER(et);
6918 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6920 } else if (sopt->sopt_dir == SOPT_GET) {
6921 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6923 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6926 if ((error == 0) && (optval != NULL)) {
6927 error = sooptcopyout(sopt, optval, optsize);
6928 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6929 } else if (optval != NULL) {
6930 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6938 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6940 struct epoch_tracker et;
6942 int create_lock_on = 0;
6944 struct sctp_inpcb *inp;
6945 struct sctp_tcb *stcb = NULL;
6947 inp = (struct sctp_inpcb *)so->so_pcb;
6949 /* I made the same as TCP since we are not setup? */
6950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6951 return (ECONNRESET);
6954 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6958 switch (addr->sa_family) {
6962 struct sockaddr_in6 *sin6;
6964 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6968 sin6 = (struct sockaddr_in6 *)addr;
6969 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6->sin6_addr)) != 0) {
6970 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6979 struct sockaddr_in *sin;
6981 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6985 sin = (struct sockaddr_in *)addr;
6986 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sin->sin_addr)) != 0) {
6987 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6995 return (EAFNOSUPPORT);
6997 SCTP_INP_INCR_REF(inp);
6998 SCTP_ASOC_CREATE_LOCK(inp);
7000 NET_EPOCH_ENTER(et);
7002 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
7003 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
7004 /* Should I really unlock ? */
7005 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
7010 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
7011 (addr->sa_family == AF_INET6)) {
7012 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7017 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7018 /* Bind a ephemeral port */
7019 error = sctp_inpcb_bind(so, NULL, NULL, p);
7024 /* Now do we connect? */
7025 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
7026 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
7027 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7031 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7032 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7033 /* We are already connected AND the TCP model */
7034 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7038 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7039 SCTP_INP_RLOCK(inp);
7040 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7041 SCTP_INP_RUNLOCK(inp);
7044 * We increment here since sctp_findassociation_ep_addr()
7045 * will do a decrement if it finds the stcb as long as the
7046 * locked tcb (last argument) is NOT a TCB.. aka NULL.
7048 SCTP_INP_INCR_REF(inp);
7049 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7051 SCTP_INP_DECR_REF(inp);
7053 SCTP_TCB_UNLOCK(stcb);
7057 /* Already have or am bring up an association */
7058 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7063 vrf_id = inp->def_vrf_id;
7064 /* We are GOOD to go */
7065 stcb = sctp_aloc_assoc_connected(inp, addr, &error, 0, 0, vrf_id,
7066 inp->sctp_ep.pre_open_stream_count,
7067 inp->sctp_ep.port, p,
7068 SCTP_INITIALIZE_AUTH_PARAMS);
7070 /* Gak! no memory */
7073 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7074 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7076 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7077 SCTP_TCB_UNLOCK(stcb);
7080 if (create_lock_on) {
7081 SCTP_ASOC_CREATE_UNLOCK(inp);
7083 SCTP_INP_DECR_REF(inp);
7089 sctp_listen(struct socket *so, int backlog, struct thread *p)
7092 * Note this module depends on the protocol processing being called
7093 * AFTER any socket level flags and backlog are applied to the
7094 * socket. The traditional way that the socket flags are applied is
7095 * AFTER protocol processing. We have made a change to the
7096 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7097 * place if the socket API for SCTP is to work properly.
7101 struct sctp_inpcb *inp;
7103 inp = (struct sctp_inpcb *)so->so_pcb;
7105 /* I made the same as TCP since we are not setup? */
7106 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7107 return (ECONNRESET);
7109 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7110 /* See if we have a listener */
7111 struct sctp_inpcb *tinp;
7112 union sctp_sockstore store;
7114 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7116 struct sctp_laddr *laddr;
7118 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7119 memcpy(&store, &laddr->ifa->address, sizeof(store));
7120 switch (store.sa.sa_family) {
7123 store.sin.sin_port = inp->sctp_lport;
7128 store.sin6.sin6_port = inp->sctp_lport;
7134 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7135 if (tinp && (tinp != inp) &&
7136 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7137 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7138 (SCTP_IS_LISTENING(tinp))) {
7140 * we have a listener already and
7143 SCTP_INP_DECR_REF(tinp);
7144 return (EADDRINUSE);
7146 SCTP_INP_DECR_REF(tinp);
7150 /* Setup a local addr bound all */
7151 memset(&store, 0, sizeof(store));
7153 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7154 store.sa.sa_family = AF_INET6;
7155 store.sa.sa_len = sizeof(struct sockaddr_in6);
7159 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7160 store.sa.sa_family = AF_INET;
7161 store.sa.sa_len = sizeof(struct sockaddr_in);
7164 switch (store.sa.sa_family) {
7167 store.sin.sin_port = inp->sctp_lport;
7172 store.sin6.sin6_port = inp->sctp_lport;
7178 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7179 if (tinp && (tinp != inp) &&
7180 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7181 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7182 (SCTP_IS_LISTENING(tinp))) {
7184 * we have a listener already and its not
7187 SCTP_INP_DECR_REF(tinp);
7188 return (EADDRINUSE);
7190 SCTP_INP_DECR_REF(tinp);
7194 SCTP_INP_INFO_WLOCK();
7195 SCTP_INP_WLOCK(inp);
7196 #ifdef SCTP_LOCK_LOGGING
7197 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7198 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7201 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7202 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7204 * The unlucky case - We are in the tcp pool with this guy.
7205 * - Someone else is in the main inp slot. - We must move
7206 * this guy (the listener) to the main slot - We must then
7207 * move the guy that was listener to the TCP Pool.
7209 if (sctp_swap_inpcb_for_listen(inp)) {
7211 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7216 error = solisten_proto_check(so);
7221 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7222 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7224 solisten_proto_abort(so);
7226 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7229 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7230 ((inp->sctp_flags & SCTP_PCB_FLAGS_WAS_CONNECTED) ||
7231 (inp->sctp_flags & SCTP_PCB_FLAGS_WAS_ABORTED))) {
7233 solisten_proto_abort(so);
7235 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7238 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7239 if ((error = sctp_inpcb_bind_locked(inp, NULL, NULL, p))) {
7241 solisten_proto_abort(so);
7242 /* bind error, probably perm */
7246 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7247 solisten_proto(so, backlog);
7249 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7251 solisten_proto_abort(so);
7254 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7256 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7260 SCTP_INP_WUNLOCK(inp);
7261 SCTP_INP_INFO_WUNLOCK();
7265 static int sctp_defered_wakeup_cnt = 0;
7268 sctp_accept(struct socket *so, struct sockaddr **addr)
7270 struct sctp_tcb *stcb;
7271 struct sctp_inpcb *inp;
7272 union sctp_sockstore store;
7276 inp = (struct sctp_inpcb *)so->so_pcb;
7279 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7280 return (ECONNRESET);
7282 SCTP_INP_WLOCK(inp);
7283 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7284 SCTP_INP_WUNLOCK(inp);
7285 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7286 return (EOPNOTSUPP);
7288 if (so->so_state & SS_ISDISCONNECTED) {
7289 SCTP_INP_WUNLOCK(inp);
7290 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7291 return (ECONNABORTED);
7293 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7295 SCTP_INP_WUNLOCK(inp);
7296 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7297 return (ECONNRESET);
7299 SCTP_TCB_LOCK(stcb);
7300 store = stcb->asoc.primary_destination->ro._l_addr;
7301 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7302 /* Wake any delayed sleep action */
7303 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7304 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7305 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7306 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7307 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7308 if (sowriteable(inp->sctp_socket)) {
7309 sowwakeup_locked(inp->sctp_socket);
7311 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7314 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7315 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7316 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7317 if (soreadable(inp->sctp_socket)) {
7318 sctp_defered_wakeup_cnt++;
7319 sorwakeup_locked(inp->sctp_socket);
7321 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7325 SCTP_INP_WUNLOCK(inp);
7326 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7327 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7328 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7330 SCTP_TCB_UNLOCK(stcb);
7332 switch (store.sa.sa_family) {
7336 struct sockaddr_in *sin;
7338 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7341 sin->sin_family = AF_INET;
7342 sin->sin_len = sizeof(*sin);
7343 sin->sin_port = store.sin.sin_port;
7344 sin->sin_addr = store.sin.sin_addr;
7345 *addr = (struct sockaddr *)sin;
7352 struct sockaddr_in6 *sin6;
7354 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7357 sin6->sin6_family = AF_INET6;
7358 sin6->sin6_len = sizeof(*sin6);
7359 sin6->sin6_port = store.sin6.sin6_port;
7360 sin6->sin6_addr = store.sin6.sin6_addr;
7361 if ((error = sa6_recoverscope(sin6)) != 0) {
7362 SCTP_FREE_SONAME(sin6);
7365 *addr = (struct sockaddr *)sin6;
7378 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7380 struct sockaddr_in *sin;
7382 struct sctp_inpcb *inp;
7383 struct sctp_ifa *sctp_ifa;
7386 * Do the malloc first in case it blocks.
7388 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7391 sin->sin_family = AF_INET;
7392 sin->sin_len = sizeof(*sin);
7393 inp = (struct sctp_inpcb *)so->so_pcb;
7395 SCTP_FREE_SONAME(sin);
7396 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7397 return (ECONNRESET);
7399 SCTP_INP_RLOCK(inp);
7400 sin->sin_port = inp->sctp_lport;
7401 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7402 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7403 struct sctp_tcb *stcb;
7404 struct sockaddr_in *sin_a;
7405 struct sctp_nets *net;
7408 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7414 SCTP_TCB_LOCK(stcb);
7415 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7416 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7418 /* this will make coverity happy */
7421 if (sin_a->sin_family == AF_INET) {
7426 if ((!fnd) || (sin_a == NULL)) {
7428 SCTP_TCB_UNLOCK(stcb);
7432 vrf_id = inp->def_vrf_id;
7433 sctp_ifa = sctp_source_address_selection(inp,
7435 (sctp_route_t *)&net->ro,
7438 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7439 sctp_free_ifa(sctp_ifa);
7441 SCTP_TCB_UNLOCK(stcb);
7443 /* For the bound all case you get back 0 */
7445 sin->sin_addr.s_addr = 0;
7449 /* Take the first IPv4 address in the list */
7450 struct sctp_laddr *laddr;
7453 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7454 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7455 struct sockaddr_in *sin_a;
7457 sin_a = &laddr->ifa->address.sin;
7458 sin->sin_addr = sin_a->sin_addr;
7464 SCTP_FREE_SONAME(sin);
7465 SCTP_INP_RUNLOCK(inp);
7466 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7470 SCTP_INP_RUNLOCK(inp);
7471 (*addr) = (struct sockaddr *)sin;
7476 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7478 struct sockaddr_in *sin;
7480 struct sockaddr_in *sin_a;
7481 struct sctp_inpcb *inp;
7482 struct sctp_tcb *stcb;
7483 struct sctp_nets *net;
7485 /* Do the malloc first in case it blocks. */
7486 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7489 sin->sin_family = AF_INET;
7490 sin->sin_len = sizeof(*sin);
7492 inp = (struct sctp_inpcb *)so->so_pcb;
7493 if ((inp == NULL) ||
7494 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7495 /* UDP type and listeners will drop out here */
7496 SCTP_FREE_SONAME(sin);
7497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7500 SCTP_INP_RLOCK(inp);
7501 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7503 SCTP_TCB_LOCK(stcb);
7505 SCTP_INP_RUNLOCK(inp);
7507 SCTP_FREE_SONAME(sin);
7508 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7509 return (ECONNRESET);
7512 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7513 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7514 if (sin_a->sin_family == AF_INET) {
7516 sin->sin_port = stcb->rport;
7517 sin->sin_addr = sin_a->sin_addr;
7521 SCTP_TCB_UNLOCK(stcb);
7523 /* No IPv4 address */
7524 SCTP_FREE_SONAME(sin);
7525 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7528 (*addr) = (struct sockaddr *)sin;
7532 #define SCTP_PROTOSW \
7533 .pr_protocol = IPPROTO_SCTP, \
7534 .pr_ctloutput = sctp_ctloutput, \
7535 .pr_abort = sctp_abort, \
7536 .pr_accept = sctp_accept, \
7537 .pr_attach = sctp_attach, \
7538 .pr_bind = sctp_bind, \
7539 .pr_connect = sctp_connect, \
7540 .pr_control = in_control, \
7541 .pr_close = sctp_close, \
7542 .pr_detach = sctp_close, \
7543 .pr_sopoll = sopoll_generic, \
7544 .pr_flush = sctp_flush, \
7545 .pr_disconnect = sctp_disconnect, \
7546 .pr_listen = sctp_listen, \
7547 .pr_peeraddr = sctp_peeraddr, \
7548 .pr_send = sctp_sendm, \
7549 .pr_shutdown = sctp_shutdown, \
7550 .pr_sockaddr = sctp_ingetaddr, \
7551 .pr_sosend = sctp_sosend, \
7552 .pr_soreceive = sctp_soreceive \
7554 struct protosw sctp_seqpacket_protosw = {
7555 .pr_type = SOCK_SEQPACKET,
7556 .pr_flags = PR_WANTRCVD,
7560 struct protosw sctp_stream_protosw = {
7561 .pr_type = SOCK_STREAM,
7562 .pr_flags = PR_CONNREQUIRED | PR_WANTRCVD,