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 <netinet/sctp_os.h>
37 #include <netinet/sctp_pcb.h>
38 #include <netinet/sctp_header.h>
39 #include <netinet/sctp_var.h>
41 #include <netinet6/sctp6_var.h>
43 #include <netinet/sctp_sysctl.h>
44 #include <netinet/sctp_output.h>
45 #include <netinet/sctp_uio.h>
46 #include <netinet/sctp_asconf.h>
47 #include <netinet/sctputil.h>
48 #include <netinet/sctp_indata.h>
49 #include <netinet/sctp_timer.h>
50 #include <netinet/sctp_auth.h>
51 #include <netinet/sctp_bsd_addr.h>
52 #include <netinet/udp.h>
53 #include <sys/eventhandler.h>
55 extern const struct sctp_cc_functions sctp_cc_functions[];
56 extern const struct sctp_ss_functions sctp_ss_functions[];
59 sctp_init(void *arg SCTP_UNUSED)
63 /* Initialize and modify the sysctled variables */
65 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
66 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
68 * Allow a user to take no more than 1/2 the number of clusters or
69 * the SB_MAX, whichever is smaller, for the send window.
71 sb_max_adj = (u_long)((u_quad_t)(SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
72 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
73 (((uint32_t)nmbclusters / 2) * MCLBYTES));
75 * Now for the recv window, should we take the same amount? or
76 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
77 * now I will just copy.
79 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
80 SCTP_BASE_VAR(first_time) = 0;
81 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
83 #if defined(SCTP_PACKET_LOGGING)
84 SCTP_BASE_VAR(packet_log_writers) = 0;
85 SCTP_BASE_VAR(packet_log_end) = 0;
86 memset(&SCTP_BASE_VAR(packet_log_buffer), 0, SCTP_PACKET_LOG_SIZE);
88 SCTP_BASE_VAR(eh_tag) = EVENTHANDLER_REGISTER(rt_addrmsg,
89 sctp_addr_change_event_handler, NULL, EVENTHANDLER_PRI_FIRST);
92 VNET_SYSINIT(sctp_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, sctp_init, NULL);
96 sctp_finish(void *unused __unused)
98 EVENTHANDLER_DEREGISTER(rt_addrmsg, SCTP_BASE_VAR(eh_tag));
102 VNET_SYSUNINIT(sctp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, sctp_finish, NULL);
106 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint32_t mtu, bool resend)
108 struct sctp_association *asoc;
109 struct sctp_tmit_chunk *chk;
113 KASSERT(mtu < asoc->smallest_mtu,
114 ("Currently only reducing association MTU %u supported (MTU %u)",
115 asoc->smallest_mtu, mtu));
116 asoc->smallest_mtu = mtu;
117 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
118 overhead = SCTP_MIN_OVERHEAD;
120 overhead = SCTP_MIN_V4_OVERHEAD;
122 if (asoc->idata_supported) {
123 if (sctp_auth_is_required_chunk(SCTP_IDATA, asoc->peer_auth_chunks)) {
124 overhead += sctp_get_auth_chunk_len(asoc->peer_hmac_id);
127 if (sctp_auth_is_required_chunk(SCTP_DATA, asoc->peer_auth_chunks)) {
128 overhead += sctp_get_auth_chunk_len(asoc->peer_hmac_id);
131 KASSERT(overhead % 4 == 0,
132 ("overhead (%u) not a multiple of 4", overhead));
133 TAILQ_FOREACH(chk, &asoc->send_queue, sctp_next) {
134 if (((uint32_t)chk->send_size + overhead) > mtu) {
135 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
138 TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) {
139 if (((uint32_t)chk->send_size + overhead) > mtu) {
140 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
141 if (resend && chk->sent < SCTP_DATAGRAM_RESEND) {
143 * If requested, mark the chunk for
144 * immediate resend, since we sent it being
147 sctp_flight_size_decrease(chk);
148 sctp_total_flight_decrease(stcb, chk);
149 chk->sent = SCTP_DATAGRAM_RESEND;
150 sctp_ucount_incr(asoc->sent_queue_retran_cnt);
151 chk->rec.data.doing_fast_retransmit = 0;
152 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
153 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
154 chk->whoTo->flight_size,
156 (uint32_t)(uintptr_t)chk->whoTo,
159 /* Clear any time, so NO RTT is being done. */
160 if (chk->do_rtt == 1) {
162 chk->whoTo->rto_needed = 1;
171 sctp_notify(struct sctp_inpcb *inp,
172 struct sctp_tcb *stcb,
173 struct sctp_nets *net,
181 if (icmp_type != ICMP_UNREACH) {
182 /* We only care about unreachable */
183 SCTP_TCB_UNLOCK(stcb);
186 if ((icmp_code == ICMP_UNREACH_NET) ||
187 (icmp_code == ICMP_UNREACH_HOST) ||
188 (icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
189 (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
190 (icmp_code == ICMP_UNREACH_ISOLATED) ||
191 (icmp_code == ICMP_UNREACH_NET_PROHIB) ||
192 (icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
193 (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
194 /* Mark the net unreachable. */
195 if (net->dest_state & SCTP_ADDR_REACHABLE) {
196 /* OK, that destination is NOT reachable. */
197 net->dest_state &= ~SCTP_ADDR_REACHABLE;
198 net->dest_state &= ~SCTP_ADDR_PF;
199 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
201 (void *)net, SCTP_SO_NOT_LOCKED);
203 SCTP_TCB_UNLOCK(stcb);
204 } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) ||
205 (icmp_code == ICMP_UNREACH_PORT)) {
206 /* Treat it like an ABORT. */
207 sctp_abort_notification(stcb, true, false, 0, NULL, SCTP_SO_NOT_LOCKED);
208 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
209 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
210 /* no need to unlock here, since the TCB is gone */
211 } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) {
212 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
213 SCTP_TCB_UNLOCK(stcb);
216 /* Find the next (smaller) MTU */
219 * Old type router that does not tell us what the
220 * next MTU is. Rats we will have to guess (in a
221 * educated fashion of course).
223 next_mtu = sctp_get_prev_mtu(ip_len);
225 /* Stop the PMTU timer. */
226 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
228 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
229 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
233 /* Update the path MTU. */
235 next_mtu -= sizeof(struct udphdr);
237 if (net->mtu > next_mtu) {
240 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu + sizeof(struct udphdr));
242 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu);
245 /* Update the association MTU */
246 if (stcb->asoc.smallest_mtu > next_mtu) {
247 sctp_pathmtu_adjustment(stcb, next_mtu, true);
249 /* Finally, start the PMTU timer if it was running before. */
251 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
253 SCTP_TCB_UNLOCK(stcb);
255 SCTP_TCB_UNLOCK(stcb);
260 sctp_ctlinput(struct icmp *icmp)
262 struct ip *inner_ip, *outer_ip;
264 struct sctp_inpcb *inp;
265 struct sctp_tcb *stcb;
266 struct sctp_nets *net;
267 struct sctp_init_chunk *ch;
268 struct sockaddr_in src, dst;
270 if (icmp_errmap(icmp) == 0)
273 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
274 inner_ip = &icmp->icmp_ip;
275 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
276 memset(&src, 0, sizeof(struct sockaddr_in));
277 src.sin_family = AF_INET;
278 src.sin_len = sizeof(struct sockaddr_in);
279 src.sin_port = sh->src_port;
280 src.sin_addr = inner_ip->ip_src;
281 memset(&dst, 0, sizeof(struct sockaddr_in));
282 dst.sin_family = AF_INET;
283 dst.sin_len = sizeof(struct sockaddr_in);
284 dst.sin_port = sh->dest_port;
285 dst.sin_addr = inner_ip->ip_dst;
287 * 'dst' holds the dest of the packet that failed to be sent. 'src'
288 * holds our local endpoint address. Thus we reverse the dst and the
293 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
294 (struct sockaddr *)&src,
297 if ((stcb != NULL) &&
300 /* Check the verification tag */
301 if (ntohl(sh->v_tag) != 0) {
303 * This must be the verification tag used for
304 * sending out packets. We don't consider packets
305 * reflecting the verification tag.
307 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
308 SCTP_TCB_UNLOCK(stcb);
312 if (ntohs(outer_ip->ip_len) >=
314 8 + (inner_ip->ip_hl << 2) + 20) {
316 * In this case we can check if we got an
317 * INIT chunk and if the initiate tag
320 ch = (struct sctp_init_chunk *)(sh + 1);
321 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
322 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
323 SCTP_TCB_UNLOCK(stcb);
327 SCTP_TCB_UNLOCK(stcb);
331 sctp_notify(inp, stcb, net,
334 ntohs(inner_ip->ip_len),
335 (uint32_t)ntohs(icmp->icmp_nextmtu));
337 if ((stcb == NULL) && (inp != NULL)) {
338 /* reduce ref-count */
340 SCTP_INP_DECR_REF(inp);
341 SCTP_INP_WUNLOCK(inp);
344 SCTP_TCB_UNLOCK(stcb);
351 sctp_getcred(SYSCTL_HANDLER_ARGS)
354 struct sockaddr_in addrs[2];
355 struct sctp_inpcb *inp;
356 struct sctp_nets *net;
357 struct sctp_tcb *stcb;
361 /* FIX, for non-bsd is this right? */
362 vrf_id = SCTP_DEFAULT_VRFID;
364 error = priv_check(req->td, PRIV_NETINET_GETCRED);
369 error = SYSCTL_IN(req, addrs, sizeof(addrs));
373 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
375 &inp, &net, 1, vrf_id);
376 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
377 if ((inp != NULL) && (stcb == NULL)) {
378 /* reduce ref-count */
380 SCTP_INP_DECR_REF(inp);
384 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
388 SCTP_TCB_UNLOCK(stcb);
390 * We use the write lock here, only since in the error leg we need
391 * it. If we used RLOCK, then we would have to
392 * wlock/decr/unlock/rlock. Which in theory could create a hole.
393 * Better to use higher wlock.
397 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
399 SCTP_INP_WUNLOCK(inp);
402 cru2x(inp->sctp_socket->so_cred, &xuc);
403 SCTP_INP_WUNLOCK(inp);
404 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
409 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred,
410 CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
411 0, 0, sctp_getcred, "S,ucred",
412 "Get the ucred of a SCTP connection");
415 sctp_abort(struct socket *so)
417 struct epoch_tracker et;
418 struct sctp_inpcb *inp;
420 inp = (struct sctp_inpcb *)so->so_pcb;
427 #ifdef SCTP_LOG_CLOSING
428 sctp_log_closing(inp, NULL, 17);
430 if (((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0)) {
431 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP;
432 #ifdef SCTP_LOG_CLOSING
433 sctp_log_closing(inp, NULL, 16);
435 SCTP_INP_WUNLOCK(inp);
436 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
437 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
439 KASSERT(!SOLISTENING(so),
440 ("sctp_abort: called on listening socket %p", so));
441 SCTP_SB_CLEAR(so->so_snd);
442 SCTP_SB_CLEAR(so->so_rcv);
443 /* Now null out the reference, we are completely detached. */
447 SCTP_INP_WUNLOCK(inp);
454 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
456 struct sctp_inpcb *inp;
457 struct inpcb *ip_inp;
459 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
461 inp = (struct sctp_inpcb *)so->so_pcb;
463 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
466 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
467 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
472 error = sctp_inpcb_alloc(so, vrf_id);
476 inp = (struct sctp_inpcb *)so->so_pcb;
478 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
479 ip_inp = &inp->ip_inp.inp;
480 ip_inp->inp_vflag |= INP_IPV4;
481 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
482 SCTP_INP_WUNLOCK(inp);
487 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
489 struct sctp_inpcb *inp;
491 inp = (struct sctp_inpcb *)so->so_pcb;
493 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
497 if ((addr->sa_family != AF_INET) ||
498 (addr->sa_len != sizeof(struct sockaddr_in))) {
499 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
503 return (sctp_inpcb_bind(so, addr, NULL, p));
508 sctp_close(struct socket *so)
510 struct epoch_tracker et;
511 struct sctp_inpcb *inp;
513 inp = (struct sctp_inpcb *)so->so_pcb;
518 * Inform all the lower layer assoc that we are done.
522 #ifdef SCTP_LOG_CLOSING
523 sctp_log_closing(inp, NULL, 17);
525 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
526 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP;
527 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
528 (SCTP_SBAVAIL(&so->so_rcv) > 0)) {
529 #ifdef SCTP_LOG_CLOSING
530 sctp_log_closing(inp, NULL, 13);
532 SCTP_INP_WUNLOCK(inp);
533 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
534 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
536 #ifdef SCTP_LOG_CLOSING
537 sctp_log_closing(inp, NULL, 14);
539 SCTP_INP_WUNLOCK(inp);
540 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
541 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
544 * The socket is now detached, no matter what the state of
545 * the SCTP association.
548 if (!SOLISTENING(so)) {
549 SCTP_SB_CLEAR(so->so_snd);
550 SCTP_SB_CLEAR(so->so_rcv);
552 /* Now null out the reference, we are completely detached. */
556 SCTP_INP_WUNLOCK(inp);
562 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
563 struct mbuf *control, struct thread *p);
566 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
567 struct mbuf *control, struct thread *p)
569 struct sctp_inpcb *inp;
572 inp = (struct sctp_inpcb *)so->so_pcb;
575 sctp_m_freem(control);
578 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
582 /* Got to have an to address if we are NOT a connected socket */
583 if ((addr == NULL) &&
584 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
585 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
591 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
592 error = EDESTADDRREQ;
593 } else if (addr->sa_family != AF_INET) {
594 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
595 error = EAFNOSUPPORT;
596 } else if (addr->sa_len != sizeof(struct sockaddr_in)) {
597 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
603 sctp_m_freem(control);
609 /* now what about control */
612 sctp_m_freem(inp->control);
615 inp->control = control;
619 SCTP_BUF_NEXT(inp->pkt_last) = m;
622 inp->pkt_last = inp->pkt = m;
625 /* FreeBSD uses a flag passed */
626 ((flags & PRUS_MORETOCOME) == 0)
629 * note with the current version this code will only be used
630 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
631 * re-defining sosend to use the sctp_sosend. One can
632 * optionally switch back to this code (by changing back the
633 * definitions) but this is not advisable. This code is used
634 * by FreeBSD when sending a file with sendfile() though.
636 struct epoch_tracker et;
640 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
651 sctp_disconnect(struct socket *so)
653 struct epoch_tracker et;
654 struct sctp_inpcb *inp;
655 struct sctp_association *asoc;
656 struct sctp_tcb *stcb;
658 inp = (struct sctp_inpcb *)so->so_pcb;
660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
664 KASSERT(inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE ||
665 inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL,
666 ("Not a one-to-one style socket"));
667 stcb = LIST_FIRST(&inp->sctp_asoc_list);
669 SCTP_INP_RUNLOCK(inp);
670 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
675 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
676 /* We are about to be freed, out of here */
677 SCTP_TCB_UNLOCK(stcb);
678 SCTP_INP_RUNLOCK(inp);
682 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
683 (SCTP_SBAVAIL(&so->so_rcv) > 0)) {
684 if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) {
685 /* Left with Data unread */
688 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
689 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
690 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
692 SCTP_INP_RUNLOCK(inp);
693 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
694 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
695 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
697 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
698 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
699 /* No unlock tcb assoc is gone */
703 if (TAILQ_EMPTY(&asoc->send_queue) &&
704 TAILQ_EMPTY(&asoc->sent_queue) &&
705 (asoc->stream_queue_cnt == 0)) {
706 /* there is nothing queued to send, so done */
707 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
710 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) &&
711 (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
712 /* only send SHUTDOWN 1st time thru */
713 struct sctp_nets *netp;
715 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
716 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
717 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
719 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
720 sctp_stop_timers_for_shutdown(stcb);
721 if (stcb->asoc.alternate) {
722 netp = stcb->asoc.alternate;
724 netp = stcb->asoc.primary_destination;
726 sctp_send_shutdown(stcb, netp);
727 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
728 stcb->sctp_ep, stcb, netp);
729 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
730 stcb->sctp_ep, stcb, NULL);
731 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
735 * we still got (or just got) data to send, so set
739 * XXX sockets draft says that SCTP_EOF should be sent with
740 * no data. currently, we will allow user data to be sent
741 * first and move to SHUTDOWN-PENDING
743 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
744 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
745 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
747 if (TAILQ_EMPTY(&asoc->send_queue) &&
748 TAILQ_EMPTY(&asoc->sent_queue) &&
749 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
753 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
754 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
755 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
756 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
757 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
758 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
759 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
761 SCTP_INP_RUNLOCK(inp);
762 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
763 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
767 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
770 soisdisconnecting(so);
772 SCTP_TCB_UNLOCK(stcb);
773 SCTP_INP_RUNLOCK(inp);
778 sctp_flush(struct socket *so, int how)
780 struct epoch_tracker et;
781 struct sctp_tcb *stcb;
782 struct sctp_queued_to_read *control, *ncontrol;
783 struct sctp_inpcb *inp;
784 struct mbuf *m, *op_err;
785 bool need_to_abort = false;
788 * For 1-to-1 style sockets, flush the read queue and trigger an
789 * ungraceful shutdown of the association, if and only if user
790 * messages are lost. Loosing notifications does not need to be
791 * signalled to the peer.
793 if (how == PRU_FLUSH_WR) {
794 /* This function is only relevant for the read directions. */
797 inp = (struct sctp_inpcb *)so->so_pcb;
799 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
803 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
804 /* For 1-to-many style sockets this function does nothing. */
805 SCTP_INP_WUNLOCK(inp);
808 stcb = LIST_FIRST(&inp->sctp_asoc_list);
812 SCTP_INP_READ_LOCK(inp);
813 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
815 TAILQ_FOREACH_SAFE(control, &inp->read_queue, next, ncontrol) {
816 if ((control->spec_flags & M_NOTIFICATION) == 0) {
817 need_to_abort = true;
819 TAILQ_REMOVE(&inp->read_queue, control, next);
820 control->on_read_q = 0;
821 for (m = control->data; m; m = SCTP_BUF_NEXT(m)) {
822 sctp_sbfree(control, control->stcb, &so->so_rcv, m);
824 if (control->on_strm_q == 0) {
825 sctp_free_remote_addr(control->whoFrom);
827 sctp_m_freem(control->data);
828 control->data = NULL;
830 sctp_free_a_readq(stcb, control);
832 stcb->asoc.size_on_all_streams += control->length;
836 SCTP_INP_READ_UNLOCK(inp);
837 if (need_to_abort && (stcb != NULL)) {
838 inp->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
839 SCTP_INP_WUNLOCK(inp);
840 op_err = sctp_generate_cause(SCTP_CAUSE_OUT_OF_RESC, "");
842 sctp_abort_an_association(inp, stcb, op_err, false, SCTP_SO_LOCKED);
844 return (ECONNABORTED);
847 SCTP_TCB_UNLOCK(stcb);
849 SCTP_INP_WUNLOCK(inp);
854 sctp_shutdown(struct socket *so)
856 struct sctp_inpcb *inp;
858 inp = (struct sctp_inpcb *)so->so_pcb;
860 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
864 /* For UDP model this is a invalid call */
865 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
866 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
867 /* Restore the flags that the soshutdown took away. */
868 SOCKBUF_LOCK(&so->so_rcv);
869 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
870 SOCKBUF_UNLOCK(&so->so_rcv);
871 /* This proc will wakeup for read and do nothing (I hope) */
872 SCTP_INP_RUNLOCK(inp);
873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
877 * Ok, if we reach here its the TCP model and it is either a
878 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
881 struct epoch_tracker et;
882 struct sctp_tcb *stcb;
883 struct sctp_association *asoc;
884 struct sctp_nets *netp;
887 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
888 SCTP_INP_RUNLOCK(inp);
893 stcb = LIST_FIRST(&inp->sctp_asoc_list);
896 * Ok, we hit the case that the shutdown call was
897 * made after an abort or something. Nothing to do
900 SCTP_INP_RUNLOCK(inp);
905 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
906 SCTP_TCB_UNLOCK(stcb);
907 SCTP_INP_RUNLOCK(inp);
910 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) &&
911 (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) &&
912 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) {
914 * If we are not in or before ESTABLISHED, there is
915 * no protocol action required.
917 SCTP_TCB_UNLOCK(stcb);
918 SCTP_INP_RUNLOCK(inp);
922 if (stcb->asoc.alternate) {
923 netp = stcb->asoc.alternate;
925 netp = stcb->asoc.primary_destination;
927 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) &&
928 TAILQ_EMPTY(&asoc->send_queue) &&
929 TAILQ_EMPTY(&asoc->sent_queue) &&
930 (asoc->stream_queue_cnt == 0)) {
931 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
934 /* there is nothing queued to send, so I'm done... */
935 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
936 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
937 sctp_stop_timers_for_shutdown(stcb);
938 sctp_send_shutdown(stcb, netp);
939 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
940 stcb->sctp_ep, stcb, netp);
941 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
942 stcb->sctp_ep, stcb, NULL);
945 * We still got (or just got) data to send, so set
948 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
949 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
950 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
952 if (TAILQ_EMPTY(&asoc->send_queue) &&
953 TAILQ_EMPTY(&asoc->sent_queue) &&
954 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
958 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
959 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
960 SCTP_INP_RUNLOCK(inp);
961 sctp_abort_an_association(stcb->sctp_ep, stcb,
962 op_err, false, SCTP_SO_LOCKED);
968 * XXX: Why do this in the case where we have still data
971 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
972 SCTP_TCB_UNLOCK(stcb);
973 SCTP_INP_RUNLOCK(inp);
980 * copies a "user" presentable address and removes embedded scope, etc.
981 * returns 0 on success, 1 on error
984 sctp_fill_user_address(struct sockaddr *dst, struct sockaddr *src)
987 struct sockaddr_in6 lsa6;
989 src = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)src,
992 memcpy(dst, src, src->sa_len);
997 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
998 struct sctp_tcb *stcb,
1000 struct sockaddr *addr,
1003 struct sctp_ifn *sctp_ifn;
1004 struct sctp_ifa *sctp_ifa;
1008 int ipv4_local_scope, ipv4_addr_legal;
1011 int local_scope, site_scope, ipv6_addr_legal;
1013 struct sctp_vrf *vrf;
1015 SCTP_IPI_ADDR_LOCK_ASSERT();
1021 /* Turn on all the appropriate scope */
1022 loopback_scope = stcb->asoc.scope.loopback_scope;
1024 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1025 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1028 local_scope = stcb->asoc.scope.local_scope;
1029 site_scope = stcb->asoc.scope.site_scope;
1030 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1033 /* Use generic values for endpoints. */
1036 ipv4_local_scope = 1;
1042 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1044 ipv6_addr_legal = 1;
1047 if (SCTP_IPV6_V6ONLY(inp)) {
1048 ipv4_addr_legal = 0;
1050 ipv4_addr_legal = 1;
1055 ipv6_addr_legal = 0;
1058 ipv4_addr_legal = 1;
1062 vrf = sctp_find_vrf(vrf_id);
1066 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1067 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1068 if ((loopback_scope == 0) &&
1069 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1070 /* Skip loopback if loopback_scope not set */
1073 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1076 * For the BOUND-ALL case, the list
1077 * associated with a TCB is Always
1078 * considered a reverse list.. i.e.
1079 * it lists addresses that are NOT
1080 * part of the association. If this
1081 * is one of those we must skip it.
1083 if (sctp_is_addr_restricted(stcb,
1088 switch (sctp_ifa->address.sa.sa_family) {
1091 if (ipv4_addr_legal) {
1092 struct sockaddr_in *sin;
1094 sin = &sctp_ifa->address.sin;
1095 if (sin->sin_addr.s_addr == 0) {
1103 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1104 &sin->sin_addr) != 0) {
1107 if ((ipv4_local_scope == 0) &&
1108 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1112 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1113 if (actual + sizeof(struct sockaddr_in6) > limit) {
1116 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)addr);
1117 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1118 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1119 actual += sizeof(struct sockaddr_in6);
1122 if (actual + sizeof(struct sockaddr_in) > limit) {
1125 memcpy(addr, sin, sizeof(struct sockaddr_in));
1126 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1127 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in));
1128 actual += sizeof(struct sockaddr_in);
1139 if (ipv6_addr_legal) {
1140 struct sockaddr_in6 *sin6;
1142 sin6 = &sctp_ifa->address.sin6;
1143 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1151 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1152 &sin6->sin6_addr) != 0) {
1155 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1156 if (local_scope == 0)
1158 if (sin6->sin6_scope_id == 0) {
1159 if (sa6_recoverscope(sin6) != 0)
1172 if ((site_scope == 0) &&
1173 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1176 if (actual + sizeof(struct sockaddr_in6) > limit) {
1179 memcpy(addr, sin6, sizeof(struct sockaddr_in6));
1180 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1181 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1182 actual += sizeof(struct sockaddr_in6);
1195 struct sctp_laddr *laddr;
1198 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1200 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1204 sa_len = laddr->ifa->address.sa.sa_len;
1205 if (actual + sa_len > limit) {
1208 if (sctp_fill_user_address(addr, &laddr->ifa->address.sa))
1210 switch (laddr->ifa->address.sa.sa_family) {
1213 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1218 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1225 addr = (struct sockaddr *)((caddr_t)addr + sa_len);
1233 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1234 struct sctp_tcb *stcb,
1236 struct sockaddr *addr)
1240 SCTP_IPI_ADDR_RLOCK();
1241 /* fill up addresses for the endpoint's default vrf */
1242 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, addr,
1244 SCTP_IPI_ADDR_RUNLOCK();
1249 sctp_max_size_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1251 struct sctp_vrf *vrf;
1255 * In both sub-set bound an bound_all cases we return the size of
1256 * the maximum number of addresses that you could get. In reality
1257 * the sub-set bound may have an exclusion list for a given TCB or
1258 * in the bound-all case a TCB may NOT include the loopback or other
1259 * addresses as well.
1261 SCTP_IPI_ADDR_LOCK_ASSERT();
1262 vrf = sctp_find_vrf(vrf_id);
1267 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1268 struct sctp_ifn *sctp_ifn;
1269 struct sctp_ifa *sctp_ifa;
1271 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1272 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1273 /* Count them if they are the right type */
1274 switch (sctp_ifa->address.sa.sa_family) {
1278 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1279 size += sizeof(struct sockaddr_in6);
1281 size += sizeof(struct sockaddr_in);
1283 size += sizeof(struct sockaddr_in);
1289 size += sizeof(struct sockaddr_in6);
1298 struct sctp_laddr *laddr;
1300 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1301 switch (laddr->ifa->address.sa.sa_family) {
1305 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1306 size += sizeof(struct sockaddr_in6);
1308 size += sizeof(struct sockaddr_in);
1310 size += sizeof(struct sockaddr_in);
1316 size += sizeof(struct sockaddr_in6);
1328 sctp_max_size_addresses(struct sctp_inpcb *inp)
1332 SCTP_IPI_ADDR_RLOCK();
1333 /* Maximum size of all addresses for the endpoint's default VRF */
1334 size = sctp_max_size_addresses_vrf(inp, inp->def_vrf_id);
1335 SCTP_IPI_ADDR_RUNLOCK();
1340 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1341 size_t optsize, void *p, int delay)
1344 int creat_lock_on = 0;
1345 struct sctp_tcb *stcb = NULL;
1346 struct sockaddr *sa;
1347 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1351 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1353 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1354 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1355 /* We are already connected AND the TCP model */
1356 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1357 return (EADDRINUSE);
1360 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1361 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1362 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1366 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1367 SCTP_INP_RLOCK(inp);
1368 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1369 SCTP_INP_RUNLOCK(inp);
1372 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1375 SCTP_INP_INCR_REF(inp);
1376 SCTP_ASOC_CREATE_LOCK(inp);
1378 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1379 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1380 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1384 totaddrp = (unsigned int *)optval;
1385 totaddr = *totaddrp;
1386 sa = (struct sockaddr *)(totaddrp + 1);
1387 error = sctp_connectx_helper_find(inp, sa, totaddr, &num_v4, &num_v6, (unsigned int)(optsize - sizeof(int)));
1389 /* Already have or am bring up an association */
1390 SCTP_ASOC_CREATE_UNLOCK(inp);
1392 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1396 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1401 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1403 if (SCTP_IPV6_V6ONLY(inp)) {
1405 * if IPV6_V6ONLY flag, ignore connections destined
1406 * to a v4 addr or v4-mapped addr
1408 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1414 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
1415 /* Bind a ephemeral port */
1416 error = sctp_inpcb_bind(so, NULL, NULL, p);
1422 /* FIX ME: do we want to pass in a vrf on the connect call? */
1423 vrf_id = inp->def_vrf_id;
1425 /* We are GOOD to go */
1426 stcb = sctp_aloc_assoc_connected(inp, sa, &error, 0, 0, vrf_id,
1427 inp->sctp_ep.pre_open_stream_count,
1430 SCTP_INITIALIZE_AUTH_PARAMS);
1432 /* Gak! no memory */
1435 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1436 /* move to second address */
1437 switch (sa->sa_family) {
1440 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1445 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1453 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1454 /* Fill in the return id */
1458 a_id = (sctp_assoc_t *)optval;
1459 *a_id = sctp_get_associd(stcb);
1462 /* doing delayed connection */
1463 stcb->asoc.delayed_connection = 1;
1464 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1466 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1467 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1469 SCTP_TCB_UNLOCK(stcb);
1471 if (creat_lock_on) {
1472 SCTP_ASOC_CREATE_UNLOCK(inp);
1474 SCTP_INP_DECR_REF(inp);
1478 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1479 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1480 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1481 SCTP_INP_RLOCK(inp); \
1482 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1484 SCTP_TCB_LOCK(stcb); \
1486 SCTP_INP_RUNLOCK(inp); \
1487 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1488 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1489 if (stcb == NULL) { \
1490 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1499 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1500 if (size < sizeof(type)) { \
1501 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1505 destp = (type *)srcp; \
1510 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1513 struct sctp_inpcb *inp = NULL;
1515 struct sctp_tcb *stcb = NULL;
1517 if (optval == NULL) {
1518 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1522 inp = (struct sctp_inpcb *)so->so_pcb;
1524 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1531 case SCTP_AUTOCLOSE:
1532 case SCTP_EXPLICIT_EOR:
1533 case SCTP_AUTO_ASCONF:
1534 case SCTP_DISABLE_FRAGMENTS:
1535 case SCTP_I_WANT_MAPPED_V4_ADDR:
1536 case SCTP_USE_EXT_RCVINFO:
1537 SCTP_INP_RLOCK(inp);
1539 case SCTP_DISABLE_FRAGMENTS:
1540 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1542 case SCTP_I_WANT_MAPPED_V4_ADDR:
1543 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1545 case SCTP_AUTO_ASCONF:
1546 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1547 /* only valid for bound all sockets */
1548 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1550 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1555 case SCTP_EXPLICIT_EOR:
1556 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1559 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1561 case SCTP_USE_EXT_RCVINFO:
1562 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1564 case SCTP_AUTOCLOSE:
1565 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1566 val = sctp_ticks_to_secs(inp->sctp_ep.auto_close_time);
1572 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1573 error = ENOPROTOOPT;
1574 } /* end switch (sopt->sopt_name) */
1575 if (*optsize < sizeof(val)) {
1576 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1580 SCTP_INP_RUNLOCK(inp);
1582 /* return the option value */
1583 *(int *)optval = val;
1584 *optsize = sizeof(val);
1587 case SCTP_GET_PACKET_LOG:
1589 #ifdef SCTP_PACKET_LOGGING
1593 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1594 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1597 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1602 case SCTP_REUSE_PORT:
1606 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1607 /* Can't do this for a 1-m socket */
1611 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1612 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1613 *optsize = sizeof(uint32_t);
1616 case SCTP_PARTIAL_DELIVERY_POINT:
1620 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1621 *value = inp->partial_delivery_point;
1622 *optsize = sizeof(uint32_t);
1625 case SCTP_FRAGMENT_INTERLEAVE:
1629 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1630 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1631 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1632 *value = SCTP_FRAG_LEVEL_2;
1634 *value = SCTP_FRAG_LEVEL_1;
1637 *value = SCTP_FRAG_LEVEL_0;
1639 *optsize = sizeof(uint32_t);
1642 case SCTP_INTERLEAVING_SUPPORTED:
1644 struct sctp_assoc_value *av;
1646 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1647 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1650 av->assoc_value = stcb->asoc.idata_supported;
1651 SCTP_TCB_UNLOCK(stcb);
1653 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1654 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1655 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1656 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1657 SCTP_INP_RLOCK(inp);
1658 if (inp->idata_supported) {
1659 av->assoc_value = 1;
1661 av->assoc_value = 0;
1663 SCTP_INP_RUNLOCK(inp);
1665 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1670 *optsize = sizeof(struct sctp_assoc_value);
1674 case SCTP_CMT_ON_OFF:
1676 struct sctp_assoc_value *av;
1678 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1679 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1681 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1682 SCTP_TCB_UNLOCK(stcb);
1684 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1685 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1686 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1687 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1688 SCTP_INP_RLOCK(inp);
1689 av->assoc_value = inp->sctp_cmt_on_off;
1690 SCTP_INP_RUNLOCK(inp);
1692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1697 *optsize = sizeof(struct sctp_assoc_value);
1701 case SCTP_PLUGGABLE_CC:
1703 struct sctp_assoc_value *av;
1705 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1706 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1708 av->assoc_value = stcb->asoc.congestion_control_module;
1709 SCTP_TCB_UNLOCK(stcb);
1711 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1712 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1713 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1714 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1715 SCTP_INP_RLOCK(inp);
1716 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1717 SCTP_INP_RUNLOCK(inp);
1719 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1724 *optsize = sizeof(struct sctp_assoc_value);
1728 case SCTP_CC_OPTION:
1730 struct sctp_cc_option *cc_opt;
1732 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1733 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1737 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1740 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1741 *optsize = sizeof(struct sctp_cc_option);
1743 SCTP_TCB_UNLOCK(stcb);
1747 case SCTP_STREAM_SCHEDULER:
1749 struct sctp_assoc_value *av;
1751 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1752 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1754 av->assoc_value = stcb->asoc.stream_scheduling_module;
1755 SCTP_TCB_UNLOCK(stcb);
1757 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1758 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1759 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1760 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1761 SCTP_INP_RLOCK(inp);
1762 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1763 SCTP_INP_RUNLOCK(inp);
1765 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1770 *optsize = sizeof(struct sctp_assoc_value);
1774 case SCTP_STREAM_SCHEDULER_VALUE:
1776 struct sctp_stream_value *av;
1778 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1779 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1781 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1782 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1783 &av->stream_value) < 0)) {
1784 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1787 *optsize = sizeof(struct sctp_stream_value);
1789 SCTP_TCB_UNLOCK(stcb);
1792 * Can't get stream value without
1795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1800 case SCTP_GET_ADDR_LEN:
1802 struct sctp_assoc_value *av;
1804 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1807 if (av->assoc_value == AF_INET) {
1808 av->assoc_value = sizeof(struct sockaddr_in);
1813 if (av->assoc_value == AF_INET6) {
1814 av->assoc_value = sizeof(struct sockaddr_in6);
1819 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1821 *optsize = sizeof(struct sctp_assoc_value);
1825 case SCTP_GET_ASSOC_NUMBER:
1827 uint32_t *value, cnt;
1829 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1830 SCTP_INP_RLOCK(inp);
1831 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1832 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1833 /* Can't do this for a 1-1 socket */
1835 SCTP_INP_RUNLOCK(inp);
1839 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1842 SCTP_INP_RUNLOCK(inp);
1844 *optsize = sizeof(uint32_t);
1847 case SCTP_GET_ASSOC_ID_LIST:
1849 struct sctp_assoc_ids *ids;
1853 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1854 SCTP_INP_RLOCK(inp);
1855 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1856 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1857 /* Can't do this for a 1-1 socket */
1859 SCTP_INP_RUNLOCK(inp);
1863 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1864 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1866 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1874 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1878 SCTP_INP_RUNLOCK(inp);
1880 ids->gaids_number_of_ids = at;
1881 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1887 struct sctp_assoc_value *av;
1889 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1890 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1893 av->assoc_value = stcb->asoc.context;
1894 SCTP_TCB_UNLOCK(stcb);
1896 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1897 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1898 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1899 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1900 SCTP_INP_RLOCK(inp);
1901 av->assoc_value = inp->sctp_context;
1902 SCTP_INP_RUNLOCK(inp);
1904 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1909 *optsize = sizeof(struct sctp_assoc_value);
1915 uint32_t *default_vrfid;
1917 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1918 *default_vrfid = inp->def_vrf_id;
1919 *optsize = sizeof(uint32_t);
1922 case SCTP_GET_ASOC_VRF:
1924 struct sctp_assoc_value *id;
1926 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1927 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1932 id->assoc_value = stcb->asoc.vrf_id;
1933 SCTP_TCB_UNLOCK(stcb);
1934 *optsize = sizeof(struct sctp_assoc_value);
1938 case SCTP_GET_VRF_IDS:
1940 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1944 case SCTP_GET_NONCE_VALUES:
1946 struct sctp_get_nonce_values *gnv;
1948 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1949 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1952 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1953 gnv->gn_local_tag = stcb->asoc.my_vtag;
1954 SCTP_TCB_UNLOCK(stcb);
1955 *optsize = sizeof(struct sctp_get_nonce_values);
1957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1962 case SCTP_DELAYED_SACK:
1964 struct sctp_sack_info *sack;
1966 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1967 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1969 sack->sack_delay = stcb->asoc.delayed_ack;
1970 sack->sack_freq = stcb->asoc.sack_freq;
1971 SCTP_TCB_UNLOCK(stcb);
1973 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1974 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1975 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1976 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC))) {
1977 SCTP_INP_RLOCK(inp);
1978 sack->sack_delay = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1979 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
1980 SCTP_INP_RUNLOCK(inp);
1982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1987 *optsize = sizeof(struct sctp_sack_info);
1991 case SCTP_GET_SNDBUF_USE:
1993 struct sctp_sockstat *ss;
1995 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
1996 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
1999 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2000 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2001 stcb->asoc.size_on_all_streams);
2002 SCTP_TCB_UNLOCK(stcb);
2003 *optsize = sizeof(struct sctp_sockstat);
2005 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2010 case SCTP_MAX_BURST:
2012 struct sctp_assoc_value *av;
2014 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2015 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2018 av->assoc_value = stcb->asoc.max_burst;
2019 SCTP_TCB_UNLOCK(stcb);
2021 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2022 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2023 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2024 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2025 SCTP_INP_RLOCK(inp);
2026 av->assoc_value = inp->sctp_ep.max_burst;
2027 SCTP_INP_RUNLOCK(inp);
2029 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2034 *optsize = sizeof(struct sctp_assoc_value);
2040 struct sctp_assoc_value *av;
2042 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2043 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2046 av->assoc_value = stcb->asoc.sctp_frag_point;
2047 SCTP_TCB_UNLOCK(stcb);
2049 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2050 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2051 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2052 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2053 SCTP_INP_RLOCK(inp);
2054 av->assoc_value = inp->sctp_frag_point;
2055 SCTP_INP_RUNLOCK(inp);
2057 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2062 *optsize = sizeof(struct sctp_assoc_value);
2066 case SCTP_GET_STAT_LOG:
2067 error = sctp_fill_stat_log(optval, optsize);
2071 struct sctp_event_subscribe *events;
2073 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2074 memset(events, 0, sizeof(struct sctp_event_subscribe));
2075 SCTP_INP_RLOCK(inp);
2076 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2077 events->sctp_data_io_event = 1;
2079 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2080 events->sctp_association_event = 1;
2082 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2083 events->sctp_address_event = 1;
2085 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2086 events->sctp_send_failure_event = 1;
2088 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2089 events->sctp_peer_error_event = 1;
2091 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2092 events->sctp_shutdown_event = 1;
2094 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2095 events->sctp_partial_delivery_event = 1;
2097 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2098 events->sctp_adaptation_layer_event = 1;
2100 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2101 events->sctp_authentication_event = 1;
2103 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2104 events->sctp_sender_dry_event = 1;
2106 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2107 events->sctp_stream_reset_event = 1;
2108 SCTP_INP_RUNLOCK(inp);
2109 *optsize = sizeof(struct sctp_event_subscribe);
2112 case SCTP_ADAPTATION_LAYER:
2116 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2118 SCTP_INP_RLOCK(inp);
2119 *value = inp->sctp_ep.adaptation_layer_indicator;
2120 SCTP_INP_RUNLOCK(inp);
2121 *optsize = sizeof(uint32_t);
2124 case SCTP_SET_INITIAL_DBG_SEQ:
2128 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2129 SCTP_INP_RLOCK(inp);
2130 *value = inp->sctp_ep.initial_sequence_debug;
2131 SCTP_INP_RUNLOCK(inp);
2132 *optsize = sizeof(uint32_t);
2135 case SCTP_GET_LOCAL_ADDR_SIZE:
2139 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2140 SCTP_INP_RLOCK(inp);
2141 *value = (uint32_t)sctp_max_size_addresses(inp);
2142 SCTP_INP_RUNLOCK(inp);
2143 *optsize = sizeof(uint32_t);
2146 case SCTP_GET_REMOTE_ADDR_SIZE:
2149 struct sctp_nets *net;
2152 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2153 /* FIXME MT: change to sctp_assoc_value? */
2154 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2158 /* Count the sizes */
2159 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2160 switch (net->ro._l_addr.sa.sa_family) {
2164 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2165 size += sizeof(struct sockaddr_in6);
2167 size += sizeof(struct sockaddr_in);
2170 size += sizeof(struct sockaddr_in);
2176 size += sizeof(struct sockaddr_in6);
2183 SCTP_TCB_UNLOCK(stcb);
2184 *value = (uint32_t)size;
2185 *optsize = sizeof(uint32_t);
2187 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2188 ((sctp_assoc_t)*value <= SCTP_ALL_ASSOC)) {
2193 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2197 case SCTP_GET_PEER_ADDRESSES:
2199 * Get the address information, an array is passed in to
2200 * fill up we pack it.
2204 struct sockaddr *addr;
2205 struct sctp_nets *net;
2206 struct sctp_getaddresses *saddr;
2208 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2209 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2212 left = *optsize - offsetof(struct sctp_getaddresses, addr);
2213 *optsize = offsetof(struct sctp_getaddresses, addr);
2214 addr = &saddr->addr[0].sa;
2216 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2217 switch (net->ro._l_addr.sa.sa_family) {
2221 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2222 cpsz = sizeof(struct sockaddr_in6);
2224 cpsz = sizeof(struct sockaddr_in);
2227 cpsz = sizeof(struct sockaddr_in);
2233 cpsz = sizeof(struct sockaddr_in6);
2244 /* not enough room. */
2247 #if defined(INET) && defined(INET6)
2248 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2249 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2250 /* Must map the address */
2251 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2252 (struct sockaddr_in6 *)addr);
2254 memcpy(addr, &net->ro._l_addr, cpsz);
2257 memcpy(addr, &net->ro._l_addr, cpsz);
2259 ((struct sockaddr_in *)addr)->sin_port = stcb->rport;
2261 addr = (struct sockaddr *)((caddr_t)addr + cpsz);
2265 SCTP_TCB_UNLOCK(stcb);
2267 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2268 (saddr->sget_assoc_id <= SCTP_ALL_ASSOC)) {
2273 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2277 case SCTP_GET_LOCAL_ADDRESSES:
2279 size_t limit, actual;
2280 struct sctp_getaddresses *saddr;
2282 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2283 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2285 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2286 ((saddr->sget_assoc_id == SCTP_CURRENT_ASSOC) ||
2287 (saddr->sget_assoc_id == SCTP_ALL_ASSOC))) {
2290 limit = *optsize - offsetof(struct sctp_getaddresses, addr);
2291 actual = sctp_fill_up_addresses(inp, stcb, limit, &saddr->addr[0].sa);
2292 *optsize = offsetof(struct sctp_getaddresses, addr) + actual;
2295 SCTP_TCB_UNLOCK(stcb);
2299 case SCTP_PEER_ADDR_PARAMS:
2301 struct sctp_paddrparams *paddrp;
2302 struct sctp_nets *net;
2303 struct sockaddr *addr;
2304 #if defined(INET) && defined(INET6)
2305 struct sockaddr_in sin_store;
2308 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2309 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2311 #if defined(INET) && defined(INET6)
2312 if (paddrp->spp_address.ss_family == AF_INET6) {
2313 struct sockaddr_in6 *sin6;
2315 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2316 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2317 in6_sin6_2_sin(&sin_store, sin6);
2318 addr = (struct sockaddr *)&sin_store;
2320 addr = (struct sockaddr *)&paddrp->spp_address;
2323 addr = (struct sockaddr *)&paddrp->spp_address;
2326 addr = (struct sockaddr *)&paddrp->spp_address;
2329 net = sctp_findnet(stcb, addr);
2332 * We increment here since
2333 * sctp_findassociation_ep_addr() wil do a
2334 * decrement if it finds the stcb as long as
2335 * the locked tcb (last argument) is NOT a
2339 SCTP_INP_INCR_REF(inp);
2340 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2342 SCTP_INP_DECR_REF(inp);
2345 if ((stcb != NULL) && (net == NULL)) {
2347 if (addr->sa_family == AF_INET) {
2348 struct sockaddr_in *sin;
2350 sin = (struct sockaddr_in *)addr;
2351 if (sin->sin_addr.s_addr != INADDR_ANY) {
2353 SCTP_TCB_UNLOCK(stcb);
2354 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2360 if (addr->sa_family == AF_INET6) {
2361 struct sockaddr_in6 *sin6;
2363 sin6 = (struct sockaddr_in6 *)addr;
2364 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2366 SCTP_TCB_UNLOCK(stcb);
2367 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2373 error = EAFNOSUPPORT;
2374 SCTP_TCB_UNLOCK(stcb);
2375 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2381 /* Applies to the specific association */
2382 paddrp->spp_flags = 0;
2384 paddrp->spp_hbinterval = net->heart_beat_delay;
2385 paddrp->spp_pathmaxrxt = net->failure_threshold;
2386 paddrp->spp_pathmtu = net->mtu;
2387 switch (net->ro._l_addr.sa.sa_family) {
2390 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2395 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2401 /* get flags for HB */
2402 if (net->dest_state & SCTP_ADDR_NOHB) {
2403 paddrp->spp_flags |= SPP_HB_DISABLE;
2405 paddrp->spp_flags |= SPP_HB_ENABLE;
2407 /* get flags for PMTU */
2408 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2409 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2411 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2413 if (net->dscp & 0x01) {
2414 paddrp->spp_dscp = net->dscp & 0xfc;
2415 paddrp->spp_flags |= SPP_DSCP;
2418 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2419 (net->flowlabel & 0x80000000)) {
2420 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2421 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2426 * No destination so return default
2429 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2430 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2431 if (stcb->asoc.default_dscp & 0x01) {
2432 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2433 paddrp->spp_flags |= SPP_DSCP;
2436 if (stcb->asoc.default_flowlabel & 0x80000000) {
2437 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2438 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2441 /* default settings should be these */
2442 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2443 paddrp->spp_flags |= SPP_HB_DISABLE;
2445 paddrp->spp_flags |= SPP_HB_ENABLE;
2447 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2448 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2450 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2452 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2454 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2455 SCTP_TCB_UNLOCK(stcb);
2457 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2458 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2459 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2460 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
2461 /* Use endpoint defaults */
2462 SCTP_INP_RLOCK(inp);
2463 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2464 paddrp->spp_hbinterval = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2465 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2466 /* get inp's default */
2467 if (inp->sctp_ep.default_dscp & 0x01) {
2468 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2469 paddrp->spp_flags |= SPP_DSCP;
2472 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2473 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2474 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2475 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2478 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2480 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2481 paddrp->spp_flags |= SPP_HB_ENABLE;
2483 paddrp->spp_flags |= SPP_HB_DISABLE;
2485 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2486 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2488 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2490 SCTP_INP_RUNLOCK(inp);
2492 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2497 *optsize = sizeof(struct sctp_paddrparams);
2501 case SCTP_GET_PEER_ADDR_INFO:
2503 struct sctp_paddrinfo *paddri;
2504 struct sctp_nets *net;
2505 struct sockaddr *addr;
2506 #if defined(INET) && defined(INET6)
2507 struct sockaddr_in sin_store;
2510 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2511 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2513 #if defined(INET) && defined(INET6)
2514 if (paddri->spinfo_address.ss_family == AF_INET6) {
2515 struct sockaddr_in6 *sin6;
2517 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2518 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2519 in6_sin6_2_sin(&sin_store, sin6);
2520 addr = (struct sockaddr *)&sin_store;
2522 addr = (struct sockaddr *)&paddri->spinfo_address;
2525 addr = (struct sockaddr *)&paddri->spinfo_address;
2528 addr = (struct sockaddr *)&paddri->spinfo_address;
2531 net = sctp_findnet(stcb, addr);
2534 * We increment here since
2535 * sctp_findassociation_ep_addr() wil do a
2536 * decrement if it finds the stcb as long as
2537 * the locked tcb (last argument) is NOT a
2541 SCTP_INP_INCR_REF(inp);
2542 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2544 SCTP_INP_DECR_REF(inp);
2548 if ((stcb != NULL) && (net != NULL)) {
2549 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2550 /* It's unconfirmed */
2551 paddri->spinfo_state = SCTP_UNCONFIRMED;
2552 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2554 paddri->spinfo_state = SCTP_ACTIVE;
2557 paddri->spinfo_state = SCTP_INACTIVE;
2559 paddri->spinfo_cwnd = net->cwnd;
2560 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2561 paddri->spinfo_rto = net->RTO;
2562 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2563 paddri->spinfo_mtu = net->mtu;
2564 switch (addr->sa_family) {
2567 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2572 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2578 SCTP_TCB_UNLOCK(stcb);
2579 *optsize = sizeof(struct sctp_paddrinfo);
2582 SCTP_TCB_UNLOCK(stcb);
2584 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2589 case SCTP_PCB_STATUS:
2591 struct sctp_pcbinfo *spcb;
2593 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2594 sctp_fill_pcbinfo(spcb);
2595 *optsize = sizeof(struct sctp_pcbinfo);
2600 struct sctp_nets *net;
2601 struct sctp_status *sstat;
2603 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2604 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2607 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2611 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2612 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2613 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2614 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2616 * We can't include chunks that have been passed to
2617 * the socket layer. Only things in queue.
2619 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2620 stcb->asoc.cnt_on_all_streams);
2621 sstat->sstat_instrms = stcb->asoc.streamincnt;
2622 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2623 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb);
2624 net = stcb->asoc.primary_destination;
2626 memcpy(&sstat->sstat_primary.spinfo_address,
2628 ((struct sockaddr *)(&net->ro._l_addr))->sa_len);
2629 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2631 * Again the user can get info from
2632 * sctp_constants.h for what the state of
2635 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2636 /* It's unconfirmed */
2637 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2638 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2640 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2643 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2645 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2646 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2647 sstat->sstat_primary.spinfo_rto = net->RTO;
2648 sstat->sstat_primary.spinfo_mtu = net->mtu;
2649 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2652 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2657 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2664 memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo));
2666 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2667 SCTP_TCB_UNLOCK(stcb);
2668 *optsize = sizeof(struct sctp_status);
2673 struct sctp_rtoinfo *srto;
2675 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2676 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2679 srto->srto_initial = stcb->asoc.initial_rto;
2680 srto->srto_max = stcb->asoc.maxrto;
2681 srto->srto_min = stcb->asoc.minrto;
2682 SCTP_TCB_UNLOCK(stcb);
2684 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2685 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2686 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2687 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
2688 SCTP_INP_RLOCK(inp);
2689 srto->srto_initial = inp->sctp_ep.initial_rto;
2690 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2691 srto->srto_min = inp->sctp_ep.sctp_minrto;
2692 SCTP_INP_RUNLOCK(inp);
2694 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2699 *optsize = sizeof(struct sctp_rtoinfo);
2705 struct sctp_timeouts *stimo;
2707 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2708 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2711 stimo->stimo_init = stcb->asoc.timoinit;
2712 stimo->stimo_data = stcb->asoc.timodata;
2713 stimo->stimo_sack = stcb->asoc.timosack;
2714 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2715 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2716 stimo->stimo_cookie = stcb->asoc.timocookie;
2717 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2718 SCTP_TCB_UNLOCK(stcb);
2719 *optsize = sizeof(struct sctp_timeouts);
2721 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2726 case SCTP_ASSOCINFO:
2728 struct sctp_assocparams *sasoc;
2730 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2731 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2734 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(stcb->asoc.cookie_life);
2735 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2736 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2737 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2738 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2739 SCTP_TCB_UNLOCK(stcb);
2741 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2742 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2743 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2744 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
2745 SCTP_INP_RLOCK(inp);
2746 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(inp->sctp_ep.def_cookie_life);
2747 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2748 sasoc->sasoc_number_peer_destinations = 0;
2749 sasoc->sasoc_peer_rwnd = 0;
2750 sasoc->sasoc_local_rwnd = (uint32_t)sbspace(&inp->sctp_socket->so_rcv);
2751 SCTP_INP_RUNLOCK(inp);
2753 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2758 *optsize = sizeof(struct sctp_assocparams);
2762 case SCTP_DEFAULT_SEND_PARAM:
2764 struct sctp_sndrcvinfo *s_info;
2766 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2767 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2770 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2771 SCTP_TCB_UNLOCK(stcb);
2773 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2774 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2775 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2776 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC))) {
2777 SCTP_INP_RLOCK(inp);
2778 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2779 SCTP_INP_RUNLOCK(inp);
2781 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2786 *optsize = sizeof(struct sctp_sndrcvinfo);
2792 struct sctp_initmsg *sinit;
2794 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2795 SCTP_INP_RLOCK(inp);
2796 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2797 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2798 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2799 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2800 SCTP_INP_RUNLOCK(inp);
2801 *optsize = sizeof(struct sctp_initmsg);
2804 case SCTP_PRIMARY_ADDR:
2805 /* we allow a "get" operation on this */
2807 struct sctp_setprim *ssp;
2809 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2810 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2813 union sctp_sockstore *addr;
2815 addr = &stcb->asoc.primary_destination->ro._l_addr;
2816 switch (addr->sa.sa_family) {
2820 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2821 in6_sin_2_v4mapsin6(&addr->sin,
2822 (struct sockaddr_in6 *)&ssp->ssp_addr);
2824 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2827 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2833 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2839 SCTP_TCB_UNLOCK(stcb);
2840 *optsize = sizeof(struct sctp_setprim);
2842 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2847 case SCTP_HMAC_IDENT:
2849 struct sctp_hmacalgo *shmac;
2850 sctp_hmaclist_t *hmaclist;
2854 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2856 SCTP_INP_RLOCK(inp);
2857 hmaclist = inp->sctp_ep.local_hmacs;
2858 if (hmaclist == NULL) {
2859 /* no HMACs to return */
2860 *optsize = sizeof(*shmac);
2861 SCTP_INP_RUNLOCK(inp);
2864 /* is there room for all of the hmac ids? */
2865 size = sizeof(*shmac) + (hmaclist->num_algo *
2866 sizeof(shmac->shmac_idents[0]));
2867 if (*optsize < size) {
2868 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2870 SCTP_INP_RUNLOCK(inp);
2873 /* copy in the list */
2874 shmac->shmac_number_of_idents = hmaclist->num_algo;
2875 for (i = 0; i < hmaclist->num_algo; i++) {
2876 shmac->shmac_idents[i] = hmaclist->hmac[i];
2878 SCTP_INP_RUNLOCK(inp);
2882 case SCTP_AUTH_ACTIVE_KEY:
2884 struct sctp_authkeyid *scact;
2886 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2887 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2890 /* get the active key on the assoc */
2891 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2892 SCTP_TCB_UNLOCK(stcb);
2894 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2895 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2896 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2897 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC))) {
2898 /* get the endpoint active key */
2899 SCTP_INP_RLOCK(inp);
2900 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2901 SCTP_INP_RUNLOCK(inp);
2903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2908 *optsize = sizeof(struct sctp_authkeyid);
2912 case SCTP_LOCAL_AUTH_CHUNKS:
2914 struct sctp_authchunks *sac;
2915 sctp_auth_chklist_t *chklist = NULL;
2918 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2919 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2922 /* get off the assoc */
2923 chklist = stcb->asoc.local_auth_chunks;
2924 /* is there enough space? */
2925 size = sctp_auth_get_chklist_size(chklist);
2926 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2928 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2930 /* copy in the chunks */
2931 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2932 sac->gauth_number_of_chunks = (uint32_t)size;
2933 *optsize = sizeof(struct sctp_authchunks) + size;
2935 SCTP_TCB_UNLOCK(stcb);
2937 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2938 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2939 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2940 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC))) {
2941 /* get off the endpoint */
2942 SCTP_INP_RLOCK(inp);
2943 chklist = inp->sctp_ep.local_auth_chunks;
2944 /* is there enough space? */
2945 size = sctp_auth_get_chklist_size(chklist);
2946 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2950 /* copy in the chunks */
2951 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2952 sac->gauth_number_of_chunks = (uint32_t)size;
2953 *optsize = sizeof(struct sctp_authchunks) + size;
2955 SCTP_INP_RUNLOCK(inp);
2957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2963 case SCTP_PEER_AUTH_CHUNKS:
2965 struct sctp_authchunks *sac;
2966 sctp_auth_chklist_t *chklist = NULL;
2969 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2970 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2973 /* get off the assoc */
2974 chklist = stcb->asoc.peer_auth_chunks;
2975 /* is there enough space? */
2976 size = sctp_auth_get_chklist_size(chklist);
2977 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2979 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2981 /* copy in the chunks */
2982 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2983 sac->gauth_number_of_chunks = (uint32_t)size;
2984 *optsize = sizeof(struct sctp_authchunks) + size;
2986 SCTP_TCB_UNLOCK(stcb);
2988 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2995 struct sctp_event *event;
2996 uint32_t event_type;
2998 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2999 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3001 switch (event->se_type) {
3002 case SCTP_ASSOC_CHANGE:
3003 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3005 case SCTP_PEER_ADDR_CHANGE:
3006 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3008 case SCTP_REMOTE_ERROR:
3009 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3011 case SCTP_SEND_FAILED:
3012 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3014 case SCTP_SHUTDOWN_EVENT:
3015 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3017 case SCTP_ADAPTATION_INDICATION:
3018 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3020 case SCTP_PARTIAL_DELIVERY_EVENT:
3021 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3023 case SCTP_AUTHENTICATION_EVENT:
3024 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3026 case SCTP_STREAM_RESET_EVENT:
3027 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3029 case SCTP_SENDER_DRY_EVENT:
3030 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3032 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3034 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3037 case SCTP_ASSOC_RESET_EVENT:
3038 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3040 case SCTP_STREAM_CHANGE_EVENT:
3041 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3043 case SCTP_SEND_FAILED_EVENT:
3044 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3048 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3052 if (event_type > 0) {
3054 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3056 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3057 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3058 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3059 (event->se_assoc_id == SCTP_FUTURE_ASSOC))) {
3060 SCTP_INP_RLOCK(inp);
3061 event->se_on = sctp_is_feature_on(inp, event_type);
3062 SCTP_INP_RUNLOCK(inp);
3064 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3070 SCTP_TCB_UNLOCK(stcb);
3073 *optsize = sizeof(struct sctp_event);
3077 case SCTP_RECVRCVINFO:
3078 if (*optsize < sizeof(int)) {
3079 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3082 SCTP_INP_RLOCK(inp);
3083 *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3084 SCTP_INP_RUNLOCK(inp);
3085 *optsize = sizeof(int);
3088 case SCTP_RECVNXTINFO:
3089 if (*optsize < sizeof(int)) {
3090 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3093 SCTP_INP_RLOCK(inp);
3094 *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3095 SCTP_INP_RUNLOCK(inp);
3096 *optsize = sizeof(int);
3099 case SCTP_DEFAULT_SNDINFO:
3101 struct sctp_sndinfo *info;
3103 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3104 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3107 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3108 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3109 info->snd_flags &= 0xfff0;
3110 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3111 info->snd_context = stcb->asoc.def_send.sinfo_context;
3112 SCTP_TCB_UNLOCK(stcb);
3114 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3115 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3116 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3117 (info->snd_assoc_id == SCTP_FUTURE_ASSOC))) {
3118 SCTP_INP_RLOCK(inp);
3119 info->snd_sid = inp->def_send.sinfo_stream;
3120 info->snd_flags = inp->def_send.sinfo_flags;
3121 info->snd_flags &= 0xfff0;
3122 info->snd_ppid = inp->def_send.sinfo_ppid;
3123 info->snd_context = inp->def_send.sinfo_context;
3124 SCTP_INP_RUNLOCK(inp);
3126 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3131 *optsize = sizeof(struct sctp_sndinfo);
3135 case SCTP_DEFAULT_PRINFO:
3137 struct sctp_default_prinfo *info;
3139 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3140 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3143 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3144 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3145 SCTP_TCB_UNLOCK(stcb);
3147 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3148 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3149 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3150 (info->pr_assoc_id == SCTP_FUTURE_ASSOC))) {
3151 SCTP_INP_RLOCK(inp);
3152 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3153 info->pr_value = inp->def_send.sinfo_timetolive;
3154 SCTP_INP_RUNLOCK(inp);
3156 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3161 *optsize = sizeof(struct sctp_default_prinfo);
3165 case SCTP_PEER_ADDR_THLDS:
3167 struct sctp_paddrthlds *thlds;
3168 struct sctp_nets *net;
3169 struct sockaddr *addr;
3170 #if defined(INET) && defined(INET6)
3171 struct sockaddr_in sin_store;
3174 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3175 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3177 #if defined(INET) && defined(INET6)
3178 if (thlds->spt_address.ss_family == AF_INET6) {
3179 struct sockaddr_in6 *sin6;
3181 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3182 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3183 in6_sin6_2_sin(&sin_store, sin6);
3184 addr = (struct sockaddr *)&sin_store;
3186 addr = (struct sockaddr *)&thlds->spt_address;
3189 addr = (struct sockaddr *)&thlds->spt_address;
3192 addr = (struct sockaddr *)&thlds->spt_address;
3195 net = sctp_findnet(stcb, addr);
3198 * We increment here since
3199 * sctp_findassociation_ep_addr() wil do a
3200 * decrement if it finds the stcb as long as
3201 * the locked tcb (last argument) is NOT a
3205 SCTP_INP_INCR_REF(inp);
3206 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3208 SCTP_INP_DECR_REF(inp);
3211 if ((stcb != NULL) && (net == NULL)) {
3213 if (addr->sa_family == AF_INET) {
3214 struct sockaddr_in *sin;
3216 sin = (struct sockaddr_in *)addr;
3217 if (sin->sin_addr.s_addr != INADDR_ANY) {
3219 SCTP_TCB_UNLOCK(stcb);
3220 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3226 if (addr->sa_family == AF_INET6) {
3227 struct sockaddr_in6 *sin6;
3229 sin6 = (struct sockaddr_in6 *)addr;
3230 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3232 SCTP_TCB_UNLOCK(stcb);
3233 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3239 error = EAFNOSUPPORT;
3240 SCTP_TCB_UNLOCK(stcb);
3241 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3248 thlds->spt_pathmaxrxt = net->failure_threshold;
3249 thlds->spt_pathpfthld = net->pf_threshold;
3250 thlds->spt_pathcpthld = 0xffff;
3252 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3253 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3254 thlds->spt_pathcpthld = 0xffff;
3256 thlds->spt_assoc_id = sctp_get_associd(stcb);
3257 SCTP_TCB_UNLOCK(stcb);
3259 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3260 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3261 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3262 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
3263 /* Use endpoint defaults */
3264 SCTP_INP_RLOCK(inp);
3265 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3266 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3267 thlds->spt_pathcpthld = 0xffff;
3268 SCTP_INP_RUNLOCK(inp);
3270 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3275 *optsize = sizeof(struct sctp_paddrthlds);
3279 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3281 struct sctp_udpencaps *encaps;
3282 struct sctp_nets *net;
3283 struct sockaddr *addr;
3284 #if defined(INET) && defined(INET6)
3285 struct sockaddr_in sin_store;
3288 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3289 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3291 #if defined(INET) && defined(INET6)
3292 if (encaps->sue_address.ss_family == AF_INET6) {
3293 struct sockaddr_in6 *sin6;
3295 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3296 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3297 in6_sin6_2_sin(&sin_store, sin6);
3298 addr = (struct sockaddr *)&sin_store;
3300 addr = (struct sockaddr *)&encaps->sue_address;
3303 addr = (struct sockaddr *)&encaps->sue_address;
3306 addr = (struct sockaddr *)&encaps->sue_address;
3309 net = sctp_findnet(stcb, addr);
3312 * We increment here since
3313 * sctp_findassociation_ep_addr() wil do a
3314 * decrement if it finds the stcb as long as
3315 * the locked tcb (last argument) is NOT a
3319 SCTP_INP_INCR_REF(inp);
3320 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3322 SCTP_INP_DECR_REF(inp);
3325 if ((stcb != NULL) && (net == NULL)) {
3327 if (addr->sa_family == AF_INET) {
3328 struct sockaddr_in *sin;
3330 sin = (struct sockaddr_in *)addr;
3331 if (sin->sin_addr.s_addr != INADDR_ANY) {
3333 SCTP_TCB_UNLOCK(stcb);
3334 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3340 if (addr->sa_family == AF_INET6) {
3341 struct sockaddr_in6 *sin6;
3343 sin6 = (struct sockaddr_in6 *)addr;
3344 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3346 SCTP_TCB_UNLOCK(stcb);
3347 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3353 error = EAFNOSUPPORT;
3354 SCTP_TCB_UNLOCK(stcb);
3355 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3362 encaps->sue_port = net->port;
3364 encaps->sue_port = stcb->asoc.port;
3366 SCTP_TCB_UNLOCK(stcb);
3368 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3369 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3370 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3371 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
3372 SCTP_INP_RLOCK(inp);
3373 encaps->sue_port = inp->sctp_ep.port;
3374 SCTP_INP_RUNLOCK(inp);
3376 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3381 *optsize = sizeof(struct sctp_udpencaps);
3385 case SCTP_ECN_SUPPORTED:
3387 struct sctp_assoc_value *av;
3389 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3390 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3393 av->assoc_value = stcb->asoc.ecn_supported;
3394 SCTP_TCB_UNLOCK(stcb);
3396 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3397 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3398 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3399 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3400 SCTP_INP_RLOCK(inp);
3401 av->assoc_value = inp->ecn_supported;
3402 SCTP_INP_RUNLOCK(inp);
3404 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3409 *optsize = sizeof(struct sctp_assoc_value);
3413 case SCTP_PR_SUPPORTED:
3415 struct sctp_assoc_value *av;
3417 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3418 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3421 av->assoc_value = stcb->asoc.prsctp_supported;
3422 SCTP_TCB_UNLOCK(stcb);
3424 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3425 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3426 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3427 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3428 SCTP_INP_RLOCK(inp);
3429 av->assoc_value = inp->prsctp_supported;
3430 SCTP_INP_RUNLOCK(inp);
3432 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3437 *optsize = sizeof(struct sctp_assoc_value);
3441 case SCTP_AUTH_SUPPORTED:
3443 struct sctp_assoc_value *av;
3445 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3446 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3449 av->assoc_value = stcb->asoc.auth_supported;
3450 SCTP_TCB_UNLOCK(stcb);
3452 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3453 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3454 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3455 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3456 SCTP_INP_RLOCK(inp);
3457 av->assoc_value = inp->auth_supported;
3458 SCTP_INP_RUNLOCK(inp);
3460 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3465 *optsize = sizeof(struct sctp_assoc_value);
3469 case SCTP_ASCONF_SUPPORTED:
3471 struct sctp_assoc_value *av;
3473 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3474 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3477 av->assoc_value = stcb->asoc.asconf_supported;
3478 SCTP_TCB_UNLOCK(stcb);
3480 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3481 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3482 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3483 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3484 SCTP_INP_RLOCK(inp);
3485 av->assoc_value = inp->asconf_supported;
3486 SCTP_INP_RUNLOCK(inp);
3488 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3493 *optsize = sizeof(struct sctp_assoc_value);
3497 case SCTP_RECONFIG_SUPPORTED:
3499 struct sctp_assoc_value *av;
3501 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3502 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3505 av->assoc_value = stcb->asoc.reconfig_supported;
3506 SCTP_TCB_UNLOCK(stcb);
3508 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3509 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3510 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3511 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3512 SCTP_INP_RLOCK(inp);
3513 av->assoc_value = inp->reconfig_supported;
3514 SCTP_INP_RUNLOCK(inp);
3516 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3521 *optsize = sizeof(struct sctp_assoc_value);
3525 case SCTP_NRSACK_SUPPORTED:
3527 struct sctp_assoc_value *av;
3529 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3530 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3533 av->assoc_value = stcb->asoc.nrsack_supported;
3534 SCTP_TCB_UNLOCK(stcb);
3536 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3537 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3538 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3539 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3540 SCTP_INP_RLOCK(inp);
3541 av->assoc_value = inp->nrsack_supported;
3542 SCTP_INP_RUNLOCK(inp);
3544 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3549 *optsize = sizeof(struct sctp_assoc_value);
3553 case SCTP_PKTDROP_SUPPORTED:
3555 struct sctp_assoc_value *av;
3557 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3558 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3561 av->assoc_value = stcb->asoc.pktdrop_supported;
3562 SCTP_TCB_UNLOCK(stcb);
3564 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3565 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3566 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3567 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3568 SCTP_INP_RLOCK(inp);
3569 av->assoc_value = inp->pktdrop_supported;
3570 SCTP_INP_RUNLOCK(inp);
3572 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3577 *optsize = sizeof(struct sctp_assoc_value);
3581 case SCTP_ENABLE_STREAM_RESET:
3583 struct sctp_assoc_value *av;
3585 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3586 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3589 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3590 SCTP_TCB_UNLOCK(stcb);
3592 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3593 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3594 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3595 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3596 SCTP_INP_RLOCK(inp);
3597 av->assoc_value = (uint32_t)inp->local_strreset_support;
3598 SCTP_INP_RUNLOCK(inp);
3600 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3605 *optsize = sizeof(struct sctp_assoc_value);
3609 case SCTP_PR_STREAM_STATUS:
3611 struct sctp_prstatus *sprstat;
3615 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3616 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3618 sid = sprstat->sprstat_sid;
3619 policy = sprstat->sprstat_policy;
3620 #if defined(SCTP_DETAILED_STR_STATS)
3621 if ((stcb != NULL) &&
3622 (sid < stcb->asoc.streamoutcnt) &&
3623 (policy != SCTP_PR_SCTP_NONE) &&
3624 ((policy <= SCTP_PR_SCTP_MAX) ||
3625 (policy == SCTP_PR_SCTP_ALL))) {
3626 if (policy == SCTP_PR_SCTP_ALL) {
3627 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3628 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3630 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3631 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3634 if ((stcb != NULL) &&
3635 (sid < stcb->asoc.streamoutcnt) &&
3636 (policy == SCTP_PR_SCTP_ALL)) {
3637 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3638 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3641 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3645 SCTP_TCB_UNLOCK(stcb);
3648 *optsize = sizeof(struct sctp_prstatus);
3652 case SCTP_PR_ASSOC_STATUS:
3654 struct sctp_prstatus *sprstat;
3657 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3658 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3660 policy = sprstat->sprstat_policy;
3661 if ((stcb != NULL) &&
3662 (policy != SCTP_PR_SCTP_NONE) &&
3663 ((policy <= SCTP_PR_SCTP_MAX) ||
3664 (policy == SCTP_PR_SCTP_ALL))) {
3665 if (policy == SCTP_PR_SCTP_ALL) {
3666 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3667 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3669 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3670 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3673 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3677 SCTP_TCB_UNLOCK(stcb);
3680 *optsize = sizeof(struct sctp_prstatus);
3686 struct sctp_assoc_value *av;
3688 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3689 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3692 av->assoc_value = stcb->asoc.max_cwnd;
3693 SCTP_TCB_UNLOCK(stcb);
3695 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3696 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3697 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3698 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3699 SCTP_INP_RLOCK(inp);
3700 av->assoc_value = inp->max_cwnd;
3701 SCTP_INP_RUNLOCK(inp);
3703 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3708 *optsize = sizeof(struct sctp_assoc_value);
3713 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3714 error = ENOPROTOOPT;
3716 } /* end switch (sopt->sopt_name) */
3724 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3729 struct sctp_tcb *stcb = NULL;
3730 struct sctp_inpcb *inp = NULL;
3733 if (optval == NULL) {
3734 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3737 inp = (struct sctp_inpcb *)so->so_pcb;
3739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3742 vrf_id = inp->def_vrf_id;
3747 case SCTP_AUTOCLOSE:
3748 case SCTP_AUTO_ASCONF:
3749 case SCTP_EXPLICIT_EOR:
3750 case SCTP_DISABLE_FRAGMENTS:
3751 case SCTP_USE_EXT_RCVINFO:
3752 case SCTP_I_WANT_MAPPED_V4_ADDR:
3753 /* copy in the option value */
3754 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3759 case SCTP_DISABLE_FRAGMENTS:
3760 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3762 case SCTP_AUTO_ASCONF:
3764 * NOTE: we don't really support this flag
3766 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3767 /* only valid for bound all sockets */
3768 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3770 /* forbidden by admin */
3771 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3774 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3780 case SCTP_EXPLICIT_EOR:
3781 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3783 case SCTP_USE_EXT_RCVINFO:
3784 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3786 case SCTP_I_WANT_MAPPED_V4_ADDR:
3787 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3788 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3790 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3795 set_opt = SCTP_PCB_FLAGS_NODELAY;
3797 case SCTP_AUTOCLOSE:
3798 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3799 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3803 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3805 * The value is in ticks. Note this does not effect
3806 * old associations, only new ones.
3808 inp->sctp_ep.auto_close_time = sctp_secs_to_ticks(*mopt);
3811 SCTP_INP_WLOCK(inp);
3813 sctp_feature_on(inp, set_opt);
3815 sctp_feature_off(inp, set_opt);
3817 SCTP_INP_WUNLOCK(inp);
3819 case SCTP_REUSE_PORT:
3821 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3822 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3823 /* Can't set it after we are bound */
3827 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3828 /* Can't do this for a 1-m socket */
3833 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3835 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3838 case SCTP_PARTIAL_DELIVERY_POINT:
3842 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3843 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3844 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3848 inp->partial_delivery_point = *value;
3851 case SCTP_FRAGMENT_INTERLEAVE:
3852 /* not yet until we re-write sctp_recvmsg() */
3856 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3857 if (*level == SCTP_FRAG_LEVEL_2) {
3858 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3859 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3860 } else if (*level == SCTP_FRAG_LEVEL_1) {
3861 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3862 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3863 } else if (*level == SCTP_FRAG_LEVEL_0) {
3864 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3865 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3868 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3873 case SCTP_INTERLEAVING_SUPPORTED:
3875 struct sctp_assoc_value *av;
3877 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3878 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3883 SCTP_TCB_UNLOCK(stcb);
3885 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3886 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3887 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3888 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3889 SCTP_INP_WLOCK(inp);
3890 if (av->assoc_value == 0) {
3891 inp->idata_supported = 0;
3893 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3894 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3895 inp->idata_supported = 1;
3903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3907 SCTP_INP_WUNLOCK(inp);
3909 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3915 case SCTP_CMT_ON_OFF:
3916 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3917 struct sctp_assoc_value *av;
3919 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3920 if (av->assoc_value > SCTP_CMT_MAX) {
3921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3925 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3927 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3928 SCTP_TCB_UNLOCK(stcb);
3930 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3931 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3932 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3933 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3934 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3935 SCTP_INP_WLOCK(inp);
3936 inp->sctp_cmt_on_off = av->assoc_value;
3937 SCTP_INP_WUNLOCK(inp);
3939 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3940 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3941 (av->assoc_id == SCTP_ALL_ASSOC))) {
3942 SCTP_INP_RLOCK(inp);
3943 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3944 SCTP_TCB_LOCK(stcb);
3945 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3946 SCTP_TCB_UNLOCK(stcb);
3948 SCTP_INP_RUNLOCK(inp);
3952 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3953 error = ENOPROTOOPT;
3956 case SCTP_PLUGGABLE_CC:
3958 struct sctp_assoc_value *av;
3959 struct sctp_nets *net;
3961 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3962 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3963 (av->assoc_value != SCTP_CC_HSTCP) &&
3964 (av->assoc_value != SCTP_CC_HTCP) &&
3965 (av->assoc_value != SCTP_CC_RTCC)) {
3966 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3970 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3972 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3973 stcb->asoc.congestion_control_module = av->assoc_value;
3974 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3975 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3976 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3979 SCTP_TCB_UNLOCK(stcb);
3981 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3982 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3983 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3984 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3985 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3986 SCTP_INP_WLOCK(inp);
3987 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3988 SCTP_INP_WUNLOCK(inp);
3990 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3991 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3992 (av->assoc_id == SCTP_ALL_ASSOC))) {
3993 SCTP_INP_RLOCK(inp);
3994 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3995 SCTP_TCB_LOCK(stcb);
3996 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3997 stcb->asoc.congestion_control_module = av->assoc_value;
3998 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3999 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4000 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4003 SCTP_TCB_UNLOCK(stcb);
4005 SCTP_INP_RUNLOCK(inp);
4010 case SCTP_CC_OPTION:
4012 struct sctp_cc_option *cc_opt;
4014 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4015 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4017 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4018 (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC)) {
4019 SCTP_INP_RLOCK(inp);
4020 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4021 SCTP_TCB_LOCK(stcb);
4022 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4023 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4025 SCTP_TCB_UNLOCK(stcb);
4027 SCTP_INP_RUNLOCK(inp);
4032 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4035 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4038 SCTP_TCB_UNLOCK(stcb);
4042 case SCTP_STREAM_SCHEDULER:
4044 struct sctp_assoc_value *av;
4046 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4047 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4048 (av->assoc_value != SCTP_SS_RR) &&
4049 (av->assoc_value != SCTP_SS_RR_PKT) &&
4050 (av->assoc_value != SCTP_SS_PRIO) &&
4051 (av->assoc_value != SCTP_SS_FB) &&
4052 (av->assoc_value != SCTP_SS_FCFS)) {
4053 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4057 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4059 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, true);
4060 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4061 stcb->asoc.stream_scheduling_module = av->assoc_value;
4062 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc);
4063 SCTP_TCB_UNLOCK(stcb);
4065 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4066 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4067 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4068 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4069 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4070 SCTP_INP_WLOCK(inp);
4071 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4072 SCTP_INP_WUNLOCK(inp);
4074 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4075 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4076 (av->assoc_id == SCTP_ALL_ASSOC))) {
4077 SCTP_INP_RLOCK(inp);
4078 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4079 SCTP_TCB_LOCK(stcb);
4080 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, true);
4081 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4082 stcb->asoc.stream_scheduling_module = av->assoc_value;
4083 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc);
4084 SCTP_TCB_UNLOCK(stcb);
4086 SCTP_INP_RUNLOCK(inp);
4091 case SCTP_STREAM_SCHEDULER_VALUE:
4093 struct sctp_stream_value *av;
4095 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4096 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4098 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4099 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4100 av->stream_value) < 0)) {
4101 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4104 SCTP_TCB_UNLOCK(stcb);
4106 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4107 (av->assoc_id == SCTP_CURRENT_ASSOC)) {
4108 SCTP_INP_RLOCK(inp);
4109 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4110 SCTP_TCB_LOCK(stcb);
4111 if (av->stream_id < stcb->asoc.streamoutcnt) {
4112 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4114 &stcb->asoc.strmout[av->stream_id],
4117 SCTP_TCB_UNLOCK(stcb);
4119 SCTP_INP_RUNLOCK(inp);
4122 * Can't set stream value without
4125 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4131 case SCTP_CLR_STAT_LOG:
4132 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4137 struct sctp_assoc_value *av;
4139 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4140 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4143 stcb->asoc.context = av->assoc_value;
4144 SCTP_TCB_UNLOCK(stcb);
4146 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4147 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4148 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4149 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4150 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4151 SCTP_INP_WLOCK(inp);
4152 inp->sctp_context = av->assoc_value;
4153 SCTP_INP_WUNLOCK(inp);
4155 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4156 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4157 (av->assoc_id == SCTP_ALL_ASSOC))) {
4158 SCTP_INP_RLOCK(inp);
4159 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4160 SCTP_TCB_LOCK(stcb);
4161 stcb->asoc.context = av->assoc_value;
4162 SCTP_TCB_UNLOCK(stcb);
4164 SCTP_INP_RUNLOCK(inp);
4171 uint32_t *default_vrfid;
4173 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4174 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4175 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4179 inp->def_vrf_id = *default_vrfid;
4182 case SCTP_DEL_VRF_ID:
4184 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4188 case SCTP_ADD_VRF_ID:
4190 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4194 case SCTP_DELAYED_SACK:
4196 struct sctp_sack_info *sack;
4198 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4199 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4200 if (sack->sack_delay) {
4201 if (sack->sack_delay > SCTP_MAX_SACK_DELAY) {
4204 SCTP_TCB_UNLOCK(stcb);
4210 if (sack->sack_delay) {
4211 stcb->asoc.delayed_ack = sack->sack_delay;
4213 if (sack->sack_freq) {
4214 stcb->asoc.sack_freq = sack->sack_freq;
4216 SCTP_TCB_UNLOCK(stcb);
4218 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4219 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4220 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4221 ((sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4222 (sack->sack_assoc_id == SCTP_ALL_ASSOC)))) {
4223 SCTP_INP_WLOCK(inp);
4224 if (sack->sack_delay) {
4225 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = sctp_msecs_to_ticks(sack->sack_delay);
4227 if (sack->sack_freq) {
4228 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4230 SCTP_INP_WUNLOCK(inp);
4232 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4233 ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4234 (sack->sack_assoc_id == SCTP_ALL_ASSOC))) {
4235 SCTP_INP_RLOCK(inp);
4236 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4237 SCTP_TCB_LOCK(stcb);
4238 if (sack->sack_delay) {
4239 stcb->asoc.delayed_ack = sack->sack_delay;
4241 if (sack->sack_freq) {
4242 stcb->asoc.sack_freq = sack->sack_freq;
4244 SCTP_TCB_UNLOCK(stcb);
4246 SCTP_INP_RUNLOCK(inp);
4251 case SCTP_AUTH_CHUNK:
4253 struct sctp_authchunk *sauth;
4255 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4257 SCTP_INP_WLOCK(inp);
4258 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4259 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4262 inp->auth_supported = 1;
4264 SCTP_INP_WUNLOCK(inp);
4269 struct sctp_authkey *sca;
4270 struct sctp_keyhead *shared_keys;
4271 sctp_sharedkey_t *shared_key;
4272 sctp_key_t *key = NULL;
4275 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4276 if (sca->sca_keylength == 0) {
4277 size = optsize - sizeof(struct sctp_authkey);
4279 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4280 size = sca->sca_keylength;
4282 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4287 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4290 shared_keys = &stcb->asoc.shared_keys;
4291 /* clear the cached keys for this key id */
4292 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4294 * create the new shared key and
4298 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4300 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4302 SCTP_TCB_UNLOCK(stcb);
4306 shared_key = sctp_alloc_sharedkey();
4307 if (shared_key == NULL) {
4309 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4311 SCTP_TCB_UNLOCK(stcb);
4314 shared_key->key = key;
4315 shared_key->keyid = sca->sca_keynumber;
4316 error = sctp_insert_sharedkey(shared_keys, shared_key);
4317 SCTP_TCB_UNLOCK(stcb);
4319 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4320 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4321 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4322 ((sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4323 (sca->sca_assoc_id == SCTP_ALL_ASSOC)))) {
4324 SCTP_INP_WLOCK(inp);
4325 shared_keys = &inp->sctp_ep.shared_keys;
4327 * clear the cached keys on all
4328 * assocs for this key id
4330 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4332 * create the new shared key and
4336 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4338 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4340 SCTP_INP_WUNLOCK(inp);
4344 shared_key = sctp_alloc_sharedkey();
4345 if (shared_key == NULL) {
4347 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4349 SCTP_INP_WUNLOCK(inp);
4352 shared_key->key = key;
4353 shared_key->keyid = sca->sca_keynumber;
4354 error = sctp_insert_sharedkey(shared_keys, shared_key);
4355 SCTP_INP_WUNLOCK(inp);
4357 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4358 ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4359 (sca->sca_assoc_id == SCTP_ALL_ASSOC))) {
4360 SCTP_INP_RLOCK(inp);
4361 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4362 SCTP_TCB_LOCK(stcb);
4363 shared_keys = &stcb->asoc.shared_keys;
4365 * clear the cached keys for
4368 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4370 * create the new shared key
4371 * and insert/replace it
4374 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4376 SCTP_TCB_UNLOCK(stcb);
4380 shared_key = sctp_alloc_sharedkey();
4381 if (shared_key == NULL) {
4383 SCTP_TCB_UNLOCK(stcb);
4386 shared_key->key = key;
4387 shared_key->keyid = sca->sca_keynumber;
4388 error = sctp_insert_sharedkey(shared_keys, shared_key);
4389 SCTP_TCB_UNLOCK(stcb);
4391 SCTP_INP_RUNLOCK(inp);
4396 case SCTP_HMAC_IDENT:
4398 struct sctp_hmacalgo *shmac;
4399 sctp_hmaclist_t *hmaclist;
4403 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4404 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4405 (shmac->shmac_number_of_idents > 0xffff)) {
4406 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4411 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4412 if (hmaclist == NULL) {
4413 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4417 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4418 hmacid = shmac->shmac_idents[i];
4419 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4420 /* invalid HMACs were found */ ;
4421 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4423 sctp_free_hmaclist(hmaclist);
4424 goto sctp_set_hmac_done;
4427 for (i = 0; i < hmaclist->num_algo; i++) {
4428 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4429 /* already in list */
4433 if (i == hmaclist->num_algo) {
4434 /* not found in list */
4435 sctp_free_hmaclist(hmaclist);
4436 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4440 /* set it on the endpoint */
4441 SCTP_INP_WLOCK(inp);
4442 if (inp->sctp_ep.local_hmacs)
4443 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4444 inp->sctp_ep.local_hmacs = hmaclist;
4445 SCTP_INP_WUNLOCK(inp);
4449 case SCTP_AUTH_ACTIVE_KEY:
4451 struct sctp_authkeyid *scact;
4453 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4454 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4456 /* set the active key on the right place */
4458 /* set the active key on the assoc */
4459 if (sctp_auth_setactivekey(stcb,
4460 scact->scact_keynumber)) {
4461 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4462 SCTP_FROM_SCTP_USRREQ,
4466 SCTP_TCB_UNLOCK(stcb);
4468 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4469 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4470 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4471 ((scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4472 (scact->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4473 SCTP_INP_WLOCK(inp);
4474 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4475 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4478 SCTP_INP_WUNLOCK(inp);
4480 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4481 ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4482 (scact->scact_assoc_id == SCTP_ALL_ASSOC))) {
4483 SCTP_INP_RLOCK(inp);
4484 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4485 SCTP_TCB_LOCK(stcb);
4486 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4487 SCTP_TCB_UNLOCK(stcb);
4489 SCTP_INP_RUNLOCK(inp);
4494 case SCTP_AUTH_DELETE_KEY:
4496 struct sctp_authkeyid *scdel;
4498 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4499 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4501 /* delete the key from the right place */
4503 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4504 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4507 SCTP_TCB_UNLOCK(stcb);
4509 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4510 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4511 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4512 ((scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4513 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4514 SCTP_INP_WLOCK(inp);
4515 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4516 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4519 SCTP_INP_WUNLOCK(inp);
4521 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4522 ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4523 (scdel->scact_assoc_id == SCTP_ALL_ASSOC))) {
4524 SCTP_INP_RLOCK(inp);
4525 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4526 SCTP_TCB_LOCK(stcb);
4527 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4528 SCTP_TCB_UNLOCK(stcb);
4530 SCTP_INP_RUNLOCK(inp);
4535 case SCTP_AUTH_DEACTIVATE_KEY:
4537 struct sctp_authkeyid *keyid;
4539 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4540 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4542 /* deactivate the key from the right place */
4544 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4545 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4548 SCTP_TCB_UNLOCK(stcb);
4550 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4551 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4552 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4553 ((keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4554 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4555 SCTP_INP_WLOCK(inp);
4556 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4557 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4560 SCTP_INP_WUNLOCK(inp);
4562 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4563 ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4564 (keyid->scact_assoc_id == SCTP_ALL_ASSOC))) {
4565 SCTP_INP_RLOCK(inp);
4566 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4567 SCTP_TCB_LOCK(stcb);
4568 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4569 SCTP_TCB_UNLOCK(stcb);
4571 SCTP_INP_RUNLOCK(inp);
4576 case SCTP_ENABLE_STREAM_RESET:
4578 struct sctp_assoc_value *av;
4580 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4581 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4582 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4586 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4588 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4589 SCTP_TCB_UNLOCK(stcb);
4591 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4592 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4593 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4594 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4595 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4596 SCTP_INP_WLOCK(inp);
4597 inp->local_strreset_support = (uint8_t)av->assoc_value;
4598 SCTP_INP_WUNLOCK(inp);
4600 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4601 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4602 (av->assoc_id == SCTP_ALL_ASSOC))) {
4603 SCTP_INP_RLOCK(inp);
4604 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4605 SCTP_TCB_LOCK(stcb);
4606 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4607 SCTP_TCB_UNLOCK(stcb);
4609 SCTP_INP_RUNLOCK(inp);
4614 case SCTP_RESET_STREAMS:
4616 struct sctp_reset_streams *strrst;
4617 int i, send_out = 0;
4620 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4621 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4623 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4627 if (stcb->asoc.reconfig_supported == 0) {
4629 * Peer does not support the chunk type.
4631 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4633 SCTP_TCB_UNLOCK(stcb);
4636 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4637 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4639 SCTP_TCB_UNLOCK(stcb);
4642 if (sizeof(struct sctp_reset_streams) +
4643 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4645 SCTP_TCB_UNLOCK(stcb);
4648 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4650 if (stcb->asoc.stream_reset_outstanding) {
4651 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4653 SCTP_TCB_UNLOCK(stcb);
4657 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4660 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4661 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4663 SCTP_TCB_UNLOCK(stcb);
4666 if ((send_in == 0) && (send_out == 0)) {
4667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4669 SCTP_TCB_UNLOCK(stcb);
4672 for (i = 0; i < strrst->srs_number_streams; i++) {
4674 (strrst->srs_stream_list[i] >= stcb->asoc.streamincnt)) {
4675 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4680 (strrst->srs_stream_list[i] >= stcb->asoc.streamoutcnt)) {
4681 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4687 SCTP_TCB_UNLOCK(stcb);
4694 if (strrst->srs_number_streams) {
4695 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4696 strm = strrst->srs_stream_list[i];
4697 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4698 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4704 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4705 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4706 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4713 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4714 strrst->srs_stream_list,
4715 send_in, 0, 0, 0, 0, 0);
4717 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4720 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4723 * For outgoing streams don't report any
4724 * problems in sending the request to the
4725 * application. XXX: Double check resetting
4730 SCTP_TCB_UNLOCK(stcb);
4733 case SCTP_ADD_STREAMS:
4735 struct sctp_add_streams *stradd;
4736 uint8_t addstream = 0;
4737 uint16_t add_o_strmcnt = 0;
4738 uint16_t add_i_strmcnt = 0;
4740 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4741 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4743 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4747 if (stcb->asoc.reconfig_supported == 0) {
4749 * Peer does not support the chunk type.
4751 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4753 SCTP_TCB_UNLOCK(stcb);
4756 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4757 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4759 SCTP_TCB_UNLOCK(stcb);
4762 if (stcb->asoc.stream_reset_outstanding) {
4763 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4765 SCTP_TCB_UNLOCK(stcb);
4768 if ((stradd->sas_outstrms == 0) &&
4769 (stradd->sas_instrms == 0)) {
4773 if (stradd->sas_outstrms) {
4775 /* We allocate here */
4776 add_o_strmcnt = stradd->sas_outstrms;
4777 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4778 /* You can't have more than 64k */
4783 if (stradd->sas_instrms) {
4788 * We allocate inside
4789 * sctp_send_str_reset_req()
4791 add_i_strmcnt = stradd->sas_instrms;
4792 cnt = add_i_strmcnt;
4793 cnt += stcb->asoc.streamincnt;
4794 if (cnt > 0x0000ffff) {
4795 /* You can't have more than 64k */
4799 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4800 /* More than you are allowed */
4805 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4806 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4808 SCTP_TCB_UNLOCK(stcb);
4811 case SCTP_RESET_ASSOC:
4816 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4817 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4819 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4823 if (stcb->asoc.reconfig_supported == 0) {
4825 * Peer does not support the chunk type.
4827 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4829 SCTP_TCB_UNLOCK(stcb);
4832 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4833 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4835 SCTP_TCB_UNLOCK(stcb);
4838 if (stcb->asoc.stream_reset_outstanding) {
4839 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4841 SCTP_TCB_UNLOCK(stcb);
4845 * Is there any data pending in the send or sent
4848 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4849 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4852 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4853 SCTP_TCB_UNLOCK(stcb);
4856 /* Do any streams have data queued? */
4857 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4858 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4862 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4863 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4864 SCTP_TCB_UNLOCK(stcb);
4867 case SCTP_CONNECT_X:
4868 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4873 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4875 case SCTP_CONNECT_X_DELAYED:
4876 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4877 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4881 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4883 case SCTP_CONNECT_X_COMPLETE:
4885 struct sockaddr *sa;
4887 /* FIXME MT: check correct? */
4888 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4891 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4892 SCTP_INP_RLOCK(inp);
4893 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4895 SCTP_TCB_LOCK(stcb);
4897 SCTP_INP_RUNLOCK(inp);
4900 * We increment here since
4901 * sctp_findassociation_ep_addr() wil do a
4902 * decrement if it finds the stcb as long as
4903 * the locked tcb (last argument) is NOT a
4906 SCTP_INP_INCR_REF(inp);
4907 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4909 SCTP_INP_DECR_REF(inp);
4914 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4918 if (stcb->asoc.delayed_connection == 1) {
4919 stcb->asoc.delayed_connection = 0;
4920 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4921 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4922 stcb->asoc.primary_destination,
4923 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4924 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4927 * already expired or did not use delayed
4930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4933 SCTP_TCB_UNLOCK(stcb);
4936 case SCTP_MAX_BURST:
4938 struct sctp_assoc_value *av;
4940 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4941 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4944 stcb->asoc.max_burst = av->assoc_value;
4945 SCTP_TCB_UNLOCK(stcb);
4947 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4948 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4949 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4950 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4951 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4952 SCTP_INP_WLOCK(inp);
4953 inp->sctp_ep.max_burst = av->assoc_value;
4954 SCTP_INP_WUNLOCK(inp);
4956 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4957 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4958 (av->assoc_id == SCTP_ALL_ASSOC))) {
4959 SCTP_INP_RLOCK(inp);
4960 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4961 SCTP_TCB_LOCK(stcb);
4962 stcb->asoc.max_burst = av->assoc_value;
4963 SCTP_TCB_UNLOCK(stcb);
4965 SCTP_INP_RUNLOCK(inp);
4972 struct sctp_assoc_value *av;
4974 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4975 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4978 stcb->asoc.sctp_frag_point = av->assoc_value;
4979 SCTP_TCB_UNLOCK(stcb);
4981 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4982 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4983 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4984 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
4985 SCTP_INP_WLOCK(inp);
4986 inp->sctp_frag_point = av->assoc_value;
4987 SCTP_INP_WUNLOCK(inp);
4989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4997 struct sctp_event_subscribe *events;
4999 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5001 SCTP_INP_WLOCK(inp);
5002 if (events->sctp_data_io_event) {
5003 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5005 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5008 if (events->sctp_association_event) {
5009 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5011 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5014 if (events->sctp_address_event) {
5015 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5017 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5020 if (events->sctp_send_failure_event) {
5021 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5023 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5026 if (events->sctp_peer_error_event) {
5027 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5029 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5032 if (events->sctp_shutdown_event) {
5033 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5035 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5038 if (events->sctp_partial_delivery_event) {
5039 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5041 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5044 if (events->sctp_adaptation_layer_event) {
5045 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5047 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5050 if (events->sctp_authentication_event) {
5051 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5053 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5056 if (events->sctp_sender_dry_event) {
5057 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5059 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5062 if (events->sctp_stream_reset_event) {
5063 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5065 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5068 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5069 SCTP_TCB_LOCK(stcb);
5070 if (events->sctp_association_event) {
5071 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5073 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5075 if (events->sctp_address_event) {
5076 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5078 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5080 if (events->sctp_send_failure_event) {
5081 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5083 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5085 if (events->sctp_peer_error_event) {
5086 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5088 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5090 if (events->sctp_shutdown_event) {
5091 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5093 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5095 if (events->sctp_partial_delivery_event) {
5096 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5098 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5100 if (events->sctp_adaptation_layer_event) {
5101 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5103 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5105 if (events->sctp_authentication_event) {
5106 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5108 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5110 if (events->sctp_sender_dry_event) {
5111 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5113 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5115 if (events->sctp_stream_reset_event) {
5116 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5118 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5120 SCTP_TCB_UNLOCK(stcb);
5123 * Send up the sender dry event only for 1-to-1
5126 if (events->sctp_sender_dry_event) {
5127 if (((inp->sctp_flags & (SCTP_PCB_FLAGS_TCPTYPE | SCTP_PCB_FLAGS_IN_TCPPOOL)) != 0) &&
5128 !SCTP_IS_LISTENING(inp)) {
5129 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5131 SCTP_TCB_LOCK(stcb);
5132 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5133 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5134 (stcb->asoc.stream_queue_cnt == 0)) {
5135 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5137 SCTP_TCB_UNLOCK(stcb);
5141 SCTP_INP_WUNLOCK(inp);
5144 case SCTP_ADAPTATION_LAYER:
5146 struct sctp_setadaptation *adap_bits;
5148 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5149 SCTP_INP_WLOCK(inp);
5150 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5151 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5152 SCTP_INP_WUNLOCK(inp);
5156 case SCTP_SET_INITIAL_DBG_SEQ:
5160 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5161 SCTP_INP_WLOCK(inp);
5162 inp->sctp_ep.initial_sequence_debug = *vvv;
5163 SCTP_INP_WUNLOCK(inp);
5167 case SCTP_DEFAULT_SEND_PARAM:
5169 struct sctp_sndrcvinfo *s_info;
5171 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5172 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5175 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5176 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5178 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5181 SCTP_TCB_UNLOCK(stcb);
5183 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5184 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5185 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5186 ((s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5187 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)))) {
5188 SCTP_INP_WLOCK(inp);
5189 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5190 SCTP_INP_WUNLOCK(inp);
5192 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5193 ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5194 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC))) {
5195 SCTP_INP_RLOCK(inp);
5196 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5197 SCTP_TCB_LOCK(stcb);
5198 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5199 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5201 SCTP_TCB_UNLOCK(stcb);
5203 SCTP_INP_RUNLOCK(inp);
5208 case SCTP_PEER_ADDR_PARAMS:
5210 struct sctp_paddrparams *paddrp;
5211 struct sctp_nets *net;
5212 struct sockaddr *addr;
5213 #if defined(INET) && defined(INET6)
5214 struct sockaddr_in sin_store;
5217 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5218 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5220 #if defined(INET) && defined(INET6)
5221 if (paddrp->spp_address.ss_family == AF_INET6) {
5222 struct sockaddr_in6 *sin6;
5224 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5225 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5226 in6_sin6_2_sin(&sin_store, sin6);
5227 addr = (struct sockaddr *)&sin_store;
5229 addr = (struct sockaddr *)&paddrp->spp_address;
5232 addr = (struct sockaddr *)&paddrp->spp_address;
5235 addr = (struct sockaddr *)&paddrp->spp_address;
5238 net = sctp_findnet(stcb, addr);
5241 * We increment here since
5242 * sctp_findassociation_ep_addr() wil do a
5243 * decrement if it finds the stcb as long as
5244 * the locked tcb (last argument) is NOT a
5248 SCTP_INP_INCR_REF(inp);
5249 stcb = sctp_findassociation_ep_addr(&inp, addr,
5252 SCTP_INP_DECR_REF(inp);
5255 if ((stcb != NULL) && (net == NULL)) {
5257 if (addr->sa_family == AF_INET) {
5258 struct sockaddr_in *sin;
5260 sin = (struct sockaddr_in *)addr;
5261 if (sin->sin_addr.s_addr != INADDR_ANY) {
5262 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5263 SCTP_TCB_UNLOCK(stcb);
5270 if (addr->sa_family == AF_INET6) {
5271 struct sockaddr_in6 *sin6;
5273 sin6 = (struct sockaddr_in6 *)addr;
5274 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5275 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5276 SCTP_TCB_UNLOCK(stcb);
5283 error = EAFNOSUPPORT;
5284 SCTP_TCB_UNLOCK(stcb);
5285 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5290 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5292 SCTP_TCB_UNLOCK(stcb);
5293 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5297 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5299 SCTP_TCB_UNLOCK(stcb);
5300 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5303 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) &&
5304 (paddrp->spp_pathmtu > 0) &&
5305 ((paddrp->spp_pathmtu < SCTP_SMALLEST_PMTU) ||
5306 (paddrp->spp_pathmtu > SCTP_LARGEST_PMTU))) {
5308 SCTP_TCB_UNLOCK(stcb);
5309 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5314 /************************TCB SPECIFIC SET ******************/
5316 /************************NET SPECIFIC SET ******************/
5317 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5318 if (((net->dest_state & SCTP_ADDR_UNCONFIRMED) == 0) &&
5319 ((net->dest_state & SCTP_ADDR_NOHB) == 0)) {
5320 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5321 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5323 net->dest_state |= SCTP_ADDR_NOHB;
5325 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5326 if (paddrp->spp_hbinterval) {
5327 net->heart_beat_delay = paddrp->spp_hbinterval;
5328 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5329 net->heart_beat_delay = 0;
5331 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5332 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5333 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5334 net->dest_state &= ~SCTP_ADDR_NOHB;
5336 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5337 if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
5338 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5339 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5340 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5343 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5344 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5345 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5346 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5348 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5349 if (paddrp->spp_pathmtu > 0) {
5350 net->mtu = paddrp->spp_pathmtu;
5351 switch (net->ro._l_addr.sa.sa_family) {
5354 net->mtu += SCTP_MIN_V4_OVERHEAD;
5359 net->mtu += SCTP_MIN_OVERHEAD;
5365 if (net->mtu < stcb->asoc.smallest_mtu) {
5366 sctp_pathmtu_adjustment(stcb, net->mtu, true);
5370 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5371 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5372 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5374 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5376 if (paddrp->spp_pathmaxrxt > 0) {
5377 if (net->dest_state & SCTP_ADDR_PF) {
5378 if (net->error_count > paddrp->spp_pathmaxrxt) {
5379 net->dest_state &= ~SCTP_ADDR_PF;
5382 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5383 (net->error_count > net->pf_threshold)) {
5384 net->dest_state |= SCTP_ADDR_PF;
5385 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5386 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5387 stcb->sctp_ep, stcb, net,
5388 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5389 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5392 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5393 if (net->error_count > paddrp->spp_pathmaxrxt) {
5394 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5395 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5398 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5399 net->dest_state |= SCTP_ADDR_REACHABLE;
5400 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5403 net->failure_threshold = paddrp->spp_pathmaxrxt;
5405 if (paddrp->spp_flags & SPP_DSCP) {
5406 net->dscp = paddrp->spp_dscp & 0xfc;
5410 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5411 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5412 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5413 net->flowlabel |= 0x80000000;
5418 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5419 if (paddrp->spp_pathmaxrxt > 0) {
5420 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5421 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5422 if (net->dest_state & SCTP_ADDR_PF) {
5423 if (net->error_count > paddrp->spp_pathmaxrxt) {
5424 net->dest_state &= ~SCTP_ADDR_PF;
5427 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5428 (net->error_count > net->pf_threshold)) {
5429 net->dest_state |= SCTP_ADDR_PF;
5430 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5431 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5432 stcb->sctp_ep, stcb, net,
5433 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5434 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5437 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5438 if (net->error_count > paddrp->spp_pathmaxrxt) {
5439 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5440 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5443 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5444 net->dest_state |= SCTP_ADDR_REACHABLE;
5445 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5448 net->failure_threshold = paddrp->spp_pathmaxrxt;
5451 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5452 if (paddrp->spp_hbinterval != 0) {
5453 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5454 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5455 stcb->asoc.heart_beat_delay = 0;
5457 /* Turn back on the timer */
5458 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5459 if (paddrp->spp_hbinterval != 0) {
5460 net->heart_beat_delay = paddrp->spp_hbinterval;
5461 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5462 net->heart_beat_delay = 0;
5464 if (net->dest_state & SCTP_ADDR_NOHB) {
5465 net->dest_state &= ~SCTP_ADDR_NOHB;
5467 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5468 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5469 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5471 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5473 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5474 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5475 if ((net->dest_state & SCTP_ADDR_NOHB) == 0) {
5476 net->dest_state |= SCTP_ADDR_NOHB;
5477 if ((net->dest_state & SCTP_ADDR_UNCONFIRMED) == 0) {
5478 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5480 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5484 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5486 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5487 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5488 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5489 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5490 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5492 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5493 if (paddrp->spp_pathmtu > 0) {
5494 net->mtu = paddrp->spp_pathmtu;
5495 switch (net->ro._l_addr.sa.sa_family) {
5498 net->mtu += SCTP_MIN_V4_OVERHEAD;
5503 net->mtu += SCTP_MIN_OVERHEAD;
5509 if (net->mtu < stcb->asoc.smallest_mtu) {
5510 sctp_pathmtu_adjustment(stcb, net->mtu, true);
5514 if (paddrp->spp_pathmtu > 0) {
5515 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5517 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5519 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5520 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5521 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5522 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5524 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5526 stcb->asoc.default_mtu = 0;
5527 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5529 if (paddrp->spp_flags & SPP_DSCP) {
5530 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5531 net->dscp = paddrp->spp_dscp & 0xfc;
5534 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5535 stcb->asoc.default_dscp |= 0x01;
5538 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5539 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5540 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5541 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5542 net->flowlabel |= 0x80000000;
5545 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5546 stcb->asoc.default_flowlabel |= 0x80000000;
5550 SCTP_TCB_UNLOCK(stcb);
5552 /************************NO TCB, SET TO default stuff ******************/
5553 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5554 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5555 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5556 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
5557 SCTP_INP_WLOCK(inp);
5559 * For the TOS/FLOWLABEL stuff you
5560 * set it with the options on the
5563 if (paddrp->spp_pathmaxrxt > 0) {
5564 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5567 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5568 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5569 else if (paddrp->spp_hbinterval != 0) {
5570 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5571 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5572 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5575 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5576 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5577 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5578 } else if (paddrp->spp_hbinterval) {
5579 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5581 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5582 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5583 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5585 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5586 inp->sctp_ep.default_mtu = 0;
5587 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5588 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5589 if (paddrp->spp_pathmtu > 0) {
5590 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5592 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5594 if (paddrp->spp_flags & SPP_DSCP) {
5595 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5596 inp->sctp_ep.default_dscp |= 0x01;
5599 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5600 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5601 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5602 inp->sctp_ep.default_flowlabel |= 0x80000000;
5606 SCTP_INP_WUNLOCK(inp);
5608 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5616 struct sctp_rtoinfo *srto;
5617 uint32_t new_init, new_min, new_max;
5619 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5620 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5623 if (srto->srto_initial)
5624 new_init = srto->srto_initial;
5626 new_init = stcb->asoc.initial_rto;
5628 new_max = srto->srto_max;
5630 new_max = stcb->asoc.maxrto;
5632 new_min = srto->srto_min;
5634 new_min = stcb->asoc.minrto;
5635 if ((new_min <= new_init) && (new_init <= new_max)) {
5636 stcb->asoc.initial_rto = new_init;
5637 stcb->asoc.maxrto = new_max;
5638 stcb->asoc.minrto = new_min;
5640 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5643 SCTP_TCB_UNLOCK(stcb);
5645 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5646 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5647 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5648 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
5649 SCTP_INP_WLOCK(inp);
5650 if (srto->srto_initial)
5651 new_init = srto->srto_initial;
5653 new_init = inp->sctp_ep.initial_rto;
5655 new_max = srto->srto_max;
5657 new_max = inp->sctp_ep.sctp_maxrto;
5659 new_min = srto->srto_min;
5661 new_min = inp->sctp_ep.sctp_minrto;
5662 if ((new_min <= new_init) && (new_init <= new_max)) {
5663 inp->sctp_ep.initial_rto = new_init;
5664 inp->sctp_ep.sctp_maxrto = new_max;
5665 inp->sctp_ep.sctp_minrto = new_min;
5667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5670 SCTP_INP_WUNLOCK(inp);
5672 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5678 case SCTP_ASSOCINFO:
5680 struct sctp_assocparams *sasoc;
5682 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5683 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5684 if (sasoc->sasoc_cookie_life > 0) {
5685 /* boundary check the cookie life */
5686 if (sasoc->sasoc_cookie_life < SCTP_MIN_COOKIE_LIFE) {
5687 sasoc->sasoc_cookie_life = SCTP_MIN_COOKIE_LIFE;
5689 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5690 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5694 if (sasoc->sasoc_asocmaxrxt > 0) {
5695 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5697 if (sasoc->sasoc_cookie_life > 0) {
5698 stcb->asoc.cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5700 SCTP_TCB_UNLOCK(stcb);
5702 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5703 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5704 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5705 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
5706 SCTP_INP_WLOCK(inp);
5707 if (sasoc->sasoc_asocmaxrxt > 0) {
5708 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5710 if (sasoc->sasoc_cookie_life > 0) {
5711 inp->sctp_ep.def_cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5713 SCTP_INP_WUNLOCK(inp);
5715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5723 struct sctp_initmsg *sinit;
5725 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5726 SCTP_INP_WLOCK(inp);
5727 if (sinit->sinit_num_ostreams)
5728 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5730 if (sinit->sinit_max_instreams)
5731 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5733 if (sinit->sinit_max_attempts)
5734 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5736 if (sinit->sinit_max_init_timeo)
5737 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5738 SCTP_INP_WUNLOCK(inp);
5741 case SCTP_PRIMARY_ADDR:
5743 struct sctp_setprim *spa;
5744 struct sctp_nets *net;
5745 struct sockaddr *addr;
5746 #if defined(INET) && defined(INET6)
5747 struct sockaddr_in sin_store;
5750 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5751 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5753 #if defined(INET) && defined(INET6)
5754 if (spa->ssp_addr.ss_family == AF_INET6) {
5755 struct sockaddr_in6 *sin6;
5757 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5758 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5759 in6_sin6_2_sin(&sin_store, sin6);
5760 addr = (struct sockaddr *)&sin_store;
5762 addr = (struct sockaddr *)&spa->ssp_addr;
5765 addr = (struct sockaddr *)&spa->ssp_addr;
5768 addr = (struct sockaddr *)&spa->ssp_addr;
5771 net = sctp_findnet(stcb, addr);
5774 * We increment here since
5775 * sctp_findassociation_ep_addr() wil do a
5776 * decrement if it finds the stcb as long as
5777 * the locked tcb (last argument) is NOT a
5781 SCTP_INP_INCR_REF(inp);
5782 stcb = sctp_findassociation_ep_addr(&inp, addr,
5785 SCTP_INP_DECR_REF(inp);
5789 if ((stcb != NULL) && (net != NULL)) {
5790 if (net != stcb->asoc.primary_destination) {
5791 if ((net->dest_state & SCTP_ADDR_UNCONFIRMED) == 0) {
5792 /* Ok we need to set it */
5793 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5794 if ((stcb->asoc.alternate) &&
5795 ((net->dest_state & SCTP_ADDR_PF) == 0) &&
5796 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5797 sctp_free_remote_addr(stcb->asoc.alternate);
5798 stcb->asoc.alternate = NULL;
5801 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5805 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5810 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5814 SCTP_TCB_UNLOCK(stcb);
5818 case SCTP_SET_DYNAMIC_PRIMARY:
5820 union sctp_sockstore *ss;
5822 error = priv_check(curthread,
5823 PRIV_NETINET_RESERVEDPORT);
5827 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5828 /* SUPER USER CHECK? */
5829 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5832 case SCTP_SET_PEER_PRIMARY_ADDR:
5834 struct sctp_setpeerprim *sspp;
5835 struct sockaddr *addr;
5836 #if defined(INET) && defined(INET6)
5837 struct sockaddr_in sin_store;
5840 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5841 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5843 struct sctp_ifa *ifa;
5845 #if defined(INET) && defined(INET6)
5846 if (sspp->sspp_addr.ss_family == AF_INET6) {
5847 struct sockaddr_in6 *sin6;
5849 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5850 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5851 in6_sin6_2_sin(&sin_store, sin6);
5852 addr = (struct sockaddr *)&sin_store;
5854 addr = (struct sockaddr *)&sspp->sspp_addr;
5857 addr = (struct sockaddr *)&sspp->sspp_addr;
5860 addr = (struct sockaddr *)&sspp->sspp_addr;
5862 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5864 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5868 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5870 * Must validate the ifa found is in
5873 struct sctp_laddr *laddr;
5876 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5877 if (laddr->ifa == NULL) {
5878 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5882 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5883 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5886 if (laddr->ifa == ifa) {
5892 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5897 switch (addr->sa_family) {
5901 struct sockaddr_in *sin;
5903 sin = (struct sockaddr_in *)addr;
5904 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5905 &sin->sin_addr) != 0) {
5906 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5916 struct sockaddr_in6 *sin6;
5918 sin6 = (struct sockaddr_in6 *)addr;
5919 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5920 &sin6->sin6_addr) != 0) {
5921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5929 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5934 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5935 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5938 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5940 SCTP_TCB_UNLOCK(stcb);
5942 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5947 case SCTP_BINDX_ADD_ADDR:
5949 struct sockaddr *sa;
5952 td = (struct thread *)p;
5953 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
5955 if (sa->sa_family == AF_INET) {
5956 if (optsize < sizeof(struct sockaddr_in)) {
5957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5962 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
5963 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5969 if (sa->sa_family == AF_INET6) {
5970 if (optsize < sizeof(struct sockaddr_in6)) {
5971 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5976 (error = prison_local_ip6(td->td_ucred,
5977 &(((struct sockaddr_in6 *)sa)->sin6_addr),
5978 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5979 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5985 error = EAFNOSUPPORT;
5988 sctp_bindx_add_address(so, inp, sa, vrf_id, &error, p);
5991 case SCTP_BINDX_REM_ADDR:
5993 struct sockaddr *sa;
5996 td = (struct thread *)p;
5998 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
6000 if (sa->sa_family == AF_INET) {
6001 if (optsize < sizeof(struct sockaddr_in)) {
6002 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6007 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
6008 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6014 if (sa->sa_family == AF_INET6) {
6015 if (optsize < sizeof(struct sockaddr_in6)) {
6016 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6021 (error = prison_local_ip6(td->td_ucred,
6022 &(((struct sockaddr_in6 *)sa)->sin6_addr),
6023 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6024 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6030 error = EAFNOSUPPORT;
6033 sctp_bindx_delete_address(inp, sa, vrf_id, &error);
6038 struct sctp_event *event;
6039 uint32_t event_type;
6041 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6042 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6043 switch (event->se_type) {
6044 case SCTP_ASSOC_CHANGE:
6045 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6047 case SCTP_PEER_ADDR_CHANGE:
6048 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6050 case SCTP_REMOTE_ERROR:
6051 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6053 case SCTP_SEND_FAILED:
6054 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6056 case SCTP_SHUTDOWN_EVENT:
6057 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6059 case SCTP_ADAPTATION_INDICATION:
6060 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6062 case SCTP_PARTIAL_DELIVERY_EVENT:
6063 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6065 case SCTP_AUTHENTICATION_EVENT:
6066 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6068 case SCTP_STREAM_RESET_EVENT:
6069 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6071 case SCTP_SENDER_DRY_EVENT:
6072 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6074 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6076 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6079 case SCTP_ASSOC_RESET_EVENT:
6080 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6082 case SCTP_STREAM_CHANGE_EVENT:
6083 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6085 case SCTP_SEND_FAILED_EVENT:
6086 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6090 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6094 if (event_type > 0) {
6097 sctp_stcb_feature_on(inp, stcb, event_type);
6098 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6099 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6100 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6101 (stcb->asoc.stream_queue_cnt == 0)) {
6102 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6106 sctp_stcb_feature_off(inp, stcb, event_type);
6108 SCTP_TCB_UNLOCK(stcb);
6111 * We don't want to send up a storm
6112 * of events, so return an error for
6115 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6116 (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6117 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6118 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6119 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6123 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6124 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6125 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6126 ((event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6127 (event->se_assoc_id == SCTP_ALL_ASSOC)))) {
6128 SCTP_INP_WLOCK(inp);
6130 sctp_feature_on(inp, event_type);
6132 sctp_feature_off(inp, event_type);
6134 SCTP_INP_WUNLOCK(inp);
6136 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6137 ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6138 (event->se_assoc_id == SCTP_ALL_ASSOC))) {
6139 SCTP_INP_RLOCK(inp);
6140 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6141 SCTP_TCB_LOCK(stcb);
6143 sctp_stcb_feature_on(inp, stcb, event_type);
6145 sctp_stcb_feature_off(inp, stcb, event_type);
6147 SCTP_TCB_UNLOCK(stcb);
6149 SCTP_INP_RUNLOCK(inp);
6154 SCTP_TCB_UNLOCK(stcb);
6159 case SCTP_RECVRCVINFO:
6163 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6164 SCTP_INP_WLOCK(inp);
6166 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6168 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6170 SCTP_INP_WUNLOCK(inp);
6173 case SCTP_RECVNXTINFO:
6177 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6178 SCTP_INP_WLOCK(inp);
6180 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6182 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6184 SCTP_INP_WUNLOCK(inp);
6187 case SCTP_DEFAULT_SNDINFO:
6189 struct sctp_sndinfo *info;
6192 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6193 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6196 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6197 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6198 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6199 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6200 stcb->asoc.def_send.sinfo_flags |= policy;
6201 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6202 stcb->asoc.def_send.sinfo_context = info->snd_context;
6204 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6207 SCTP_TCB_UNLOCK(stcb);
6209 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6210 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6211 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6212 ((info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6213 (info->snd_assoc_id == SCTP_ALL_ASSOC)))) {
6214 SCTP_INP_WLOCK(inp);
6215 inp->def_send.sinfo_stream = info->snd_sid;
6216 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6217 inp->def_send.sinfo_flags = info->snd_flags;
6218 inp->def_send.sinfo_flags |= policy;
6219 inp->def_send.sinfo_ppid = info->snd_ppid;
6220 inp->def_send.sinfo_context = info->snd_context;
6221 SCTP_INP_WUNLOCK(inp);
6223 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6224 ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6225 (info->snd_assoc_id == SCTP_ALL_ASSOC))) {
6226 SCTP_INP_RLOCK(inp);
6227 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6228 SCTP_TCB_LOCK(stcb);
6229 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6230 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6231 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6232 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6233 stcb->asoc.def_send.sinfo_flags |= policy;
6234 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6235 stcb->asoc.def_send.sinfo_context = info->snd_context;
6237 SCTP_TCB_UNLOCK(stcb);
6239 SCTP_INP_RUNLOCK(inp);
6244 case SCTP_DEFAULT_PRINFO:
6246 struct sctp_default_prinfo *info;
6248 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6249 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6251 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6253 SCTP_TCB_UNLOCK(stcb);
6255 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6260 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6261 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6262 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6263 SCTP_TCB_UNLOCK(stcb);
6265 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6266 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6267 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6268 ((info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6269 (info->pr_assoc_id == SCTP_ALL_ASSOC)))) {
6270 SCTP_INP_WLOCK(inp);
6271 inp->def_send.sinfo_flags &= 0xfff0;
6272 inp->def_send.sinfo_flags |= info->pr_policy;
6273 inp->def_send.sinfo_timetolive = info->pr_value;
6274 SCTP_INP_WUNLOCK(inp);
6276 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6277 ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6278 (info->pr_assoc_id == SCTP_ALL_ASSOC))) {
6279 SCTP_INP_RLOCK(inp);
6280 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6281 SCTP_TCB_LOCK(stcb);
6282 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6283 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6284 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6285 SCTP_TCB_UNLOCK(stcb);
6287 SCTP_INP_RUNLOCK(inp);
6292 case SCTP_PEER_ADDR_THLDS:
6293 /* Applies to the specific association */
6295 struct sctp_paddrthlds *thlds;
6296 struct sctp_nets *net;
6297 struct sockaddr *addr;
6298 #if defined(INET) && defined(INET6)
6299 struct sockaddr_in sin_store;
6302 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6303 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6305 #if defined(INET) && defined(INET6)
6306 if (thlds->spt_address.ss_family == AF_INET6) {
6307 struct sockaddr_in6 *sin6;
6309 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6310 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6311 in6_sin6_2_sin(&sin_store, sin6);
6312 addr = (struct sockaddr *)&sin_store;
6314 addr = (struct sockaddr *)&thlds->spt_address;
6317 addr = (struct sockaddr *)&thlds->spt_address;
6320 addr = (struct sockaddr *)&thlds->spt_address;
6323 net = sctp_findnet(stcb, addr);
6326 * We increment here since
6327 * sctp_findassociation_ep_addr() wil do a
6328 * decrement if it finds the stcb as long as
6329 * the locked tcb (last argument) is NOT a
6333 SCTP_INP_INCR_REF(inp);
6334 stcb = sctp_findassociation_ep_addr(&inp, addr,
6337 SCTP_INP_DECR_REF(inp);
6340 if ((stcb != NULL) && (net == NULL)) {
6342 if (addr->sa_family == AF_INET) {
6343 struct sockaddr_in *sin;
6345 sin = (struct sockaddr_in *)addr;
6346 if (sin->sin_addr.s_addr != INADDR_ANY) {
6347 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6348 SCTP_TCB_UNLOCK(stcb);
6355 if (addr->sa_family == AF_INET6) {
6356 struct sockaddr_in6 *sin6;
6358 sin6 = (struct sockaddr_in6 *)addr;
6359 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6360 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6361 SCTP_TCB_UNLOCK(stcb);
6368 error = EAFNOSUPPORT;
6369 SCTP_TCB_UNLOCK(stcb);
6370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6374 if (thlds->spt_pathcpthld != 0xffff) {
6376 SCTP_TCB_UNLOCK(stcb);
6379 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6384 net->failure_threshold = thlds->spt_pathmaxrxt;
6385 net->pf_threshold = thlds->spt_pathpfthld;
6386 if (net->dest_state & SCTP_ADDR_PF) {
6387 if ((net->error_count > net->failure_threshold) ||
6388 (net->error_count <= net->pf_threshold)) {
6389 net->dest_state &= ~SCTP_ADDR_PF;
6392 if ((net->error_count > net->pf_threshold) &&
6393 (net->error_count <= net->failure_threshold)) {
6394 net->dest_state |= SCTP_ADDR_PF;
6395 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6396 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6397 stcb->sctp_ep, stcb, net,
6398 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6399 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6402 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6403 if (net->error_count > net->failure_threshold) {
6404 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6405 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6408 if (net->error_count <= net->failure_threshold) {
6409 net->dest_state |= SCTP_ADDR_REACHABLE;
6410 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6414 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6415 net->failure_threshold = thlds->spt_pathmaxrxt;
6416 net->pf_threshold = thlds->spt_pathpfthld;
6417 if (net->dest_state & SCTP_ADDR_PF) {
6418 if ((net->error_count > net->failure_threshold) ||
6419 (net->error_count <= net->pf_threshold)) {
6420 net->dest_state &= ~SCTP_ADDR_PF;
6423 if ((net->error_count > net->pf_threshold) &&
6424 (net->error_count <= net->failure_threshold)) {
6425 net->dest_state |= SCTP_ADDR_PF;
6426 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6427 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6428 stcb->sctp_ep, stcb, net,
6429 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6430 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6433 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6434 if (net->error_count > net->failure_threshold) {
6435 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6436 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6439 if (net->error_count <= net->failure_threshold) {
6440 net->dest_state |= SCTP_ADDR_REACHABLE;
6441 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6445 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6446 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6448 SCTP_TCB_UNLOCK(stcb);
6450 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6451 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6452 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6453 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
6454 SCTP_INP_WLOCK(inp);
6455 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6456 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6457 SCTP_INP_WUNLOCK(inp);
6459 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6465 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6467 struct sctp_udpencaps *encaps;
6468 struct sctp_nets *net;
6469 struct sockaddr *addr;
6470 #if defined(INET) && defined(INET6)
6471 struct sockaddr_in sin_store;
6474 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6475 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6477 #if defined(INET) && defined(INET6)
6478 if (encaps->sue_address.ss_family == AF_INET6) {
6479 struct sockaddr_in6 *sin6;
6481 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6482 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6483 in6_sin6_2_sin(&sin_store, sin6);
6484 addr = (struct sockaddr *)&sin_store;
6486 addr = (struct sockaddr *)&encaps->sue_address;
6489 addr = (struct sockaddr *)&encaps->sue_address;
6492 addr = (struct sockaddr *)&encaps->sue_address;
6495 net = sctp_findnet(stcb, addr);
6498 * We increment here since
6499 * sctp_findassociation_ep_addr() wil do a
6500 * decrement if it finds the stcb as long as
6501 * the locked tcb (last argument) is NOT a
6505 SCTP_INP_INCR_REF(inp);
6506 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6508 SCTP_INP_DECR_REF(inp);
6511 if ((stcb != NULL) && (net == NULL)) {
6513 if (addr->sa_family == AF_INET) {
6514 struct sockaddr_in *sin;
6516 sin = (struct sockaddr_in *)addr;
6517 if (sin->sin_addr.s_addr != INADDR_ANY) {
6518 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6519 SCTP_TCB_UNLOCK(stcb);
6526 if (addr->sa_family == AF_INET6) {
6527 struct sockaddr_in6 *sin6;
6529 sin6 = (struct sockaddr_in6 *)addr;
6530 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6531 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6532 SCTP_TCB_UNLOCK(stcb);
6539 error = EAFNOSUPPORT;
6540 SCTP_TCB_UNLOCK(stcb);
6541 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6548 net->port = encaps->sue_port;
6550 stcb->asoc.port = encaps->sue_port;
6552 SCTP_TCB_UNLOCK(stcb);
6554 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6555 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6556 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6557 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
6558 SCTP_INP_WLOCK(inp);
6559 inp->sctp_ep.port = encaps->sue_port;
6560 SCTP_INP_WUNLOCK(inp);
6562 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6568 case SCTP_ECN_SUPPORTED:
6570 struct sctp_assoc_value *av;
6572 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6573 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6576 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6578 SCTP_TCB_UNLOCK(stcb);
6580 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6581 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6582 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6583 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6584 SCTP_INP_WLOCK(inp);
6585 if (av->assoc_value == 0) {
6586 inp->ecn_supported = 0;
6588 inp->ecn_supported = 1;
6590 SCTP_INP_WUNLOCK(inp);
6592 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6598 case SCTP_PR_SUPPORTED:
6600 struct sctp_assoc_value *av;
6602 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6603 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6606 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6608 SCTP_TCB_UNLOCK(stcb);
6610 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6611 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6612 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6613 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6614 SCTP_INP_WLOCK(inp);
6615 if (av->assoc_value == 0) {
6616 inp->prsctp_supported = 0;
6618 inp->prsctp_supported = 1;
6620 SCTP_INP_WUNLOCK(inp);
6622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6628 case SCTP_AUTH_SUPPORTED:
6630 struct sctp_assoc_value *av;
6632 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6633 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6636 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6638 SCTP_TCB_UNLOCK(stcb);
6640 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6641 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6642 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6643 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6644 if ((av->assoc_value == 0) &&
6645 (inp->asconf_supported == 1)) {
6647 * AUTH is required for
6650 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6653 SCTP_INP_WLOCK(inp);
6654 if (av->assoc_value == 0) {
6655 inp->auth_supported = 0;
6657 inp->auth_supported = 1;
6659 SCTP_INP_WUNLOCK(inp);
6662 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6668 case SCTP_ASCONF_SUPPORTED:
6670 struct sctp_assoc_value *av;
6672 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6673 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6676 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6678 SCTP_TCB_UNLOCK(stcb);
6680 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6681 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6682 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6683 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6684 if ((av->assoc_value != 0) &&
6685 (inp->auth_supported == 0)) {
6687 * AUTH is required for
6690 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6693 SCTP_INP_WLOCK(inp);
6694 if (av->assoc_value == 0) {
6695 inp->asconf_supported = 0;
6696 sctp_auth_delete_chunk(SCTP_ASCONF,
6697 inp->sctp_ep.local_auth_chunks);
6698 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6699 inp->sctp_ep.local_auth_chunks);
6701 inp->asconf_supported = 1;
6702 sctp_auth_add_chunk(SCTP_ASCONF,
6703 inp->sctp_ep.local_auth_chunks);
6704 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6705 inp->sctp_ep.local_auth_chunks);
6707 SCTP_INP_WUNLOCK(inp);
6710 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6716 case SCTP_RECONFIG_SUPPORTED:
6718 struct sctp_assoc_value *av;
6720 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6721 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6726 SCTP_TCB_UNLOCK(stcb);
6728 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6729 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6730 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6731 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6732 SCTP_INP_WLOCK(inp);
6733 if (av->assoc_value == 0) {
6734 inp->reconfig_supported = 0;
6736 inp->reconfig_supported = 1;
6738 SCTP_INP_WUNLOCK(inp);
6740 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6746 case SCTP_NRSACK_SUPPORTED:
6748 struct sctp_assoc_value *av;
6750 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6751 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6754 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6756 SCTP_TCB_UNLOCK(stcb);
6758 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6759 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6760 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6761 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6762 SCTP_INP_WLOCK(inp);
6763 if (av->assoc_value == 0) {
6764 inp->nrsack_supported = 0;
6766 inp->nrsack_supported = 1;
6768 SCTP_INP_WUNLOCK(inp);
6770 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6776 case SCTP_PKTDROP_SUPPORTED:
6778 struct sctp_assoc_value *av;
6780 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6781 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6784 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6786 SCTP_TCB_UNLOCK(stcb);
6788 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6789 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6790 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6791 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6792 SCTP_INP_WLOCK(inp);
6793 if (av->assoc_value == 0) {
6794 inp->pktdrop_supported = 0;
6796 inp->pktdrop_supported = 1;
6798 SCTP_INP_WUNLOCK(inp);
6800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6808 struct sctp_assoc_value *av;
6809 struct sctp_nets *net;
6811 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6812 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6815 stcb->asoc.max_cwnd = av->assoc_value;
6816 if (stcb->asoc.max_cwnd > 0) {
6817 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6818 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6819 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6820 net->cwnd = stcb->asoc.max_cwnd;
6821 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6822 net->cwnd = net->mtu - sizeof(struct sctphdr);
6827 SCTP_TCB_UNLOCK(stcb);
6829 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6830 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6831 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6832 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6833 SCTP_INP_WLOCK(inp);
6834 inp->max_cwnd = av->assoc_value;
6835 SCTP_INP_WUNLOCK(inp);
6837 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6843 case SCTP_ACCEPT_ZERO_CHECKSUM:
6847 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
6848 if ((*value == SCTP_EDMID_NONE) ||
6849 (*value == SCTP_EDMID_LOWER_LAYER_DTLS)) {
6850 SCTP_INP_WLOCK(inp);
6851 inp->rcv_edmid = *value;
6852 SCTP_INP_WUNLOCK(inp);
6854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6861 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6862 error = ENOPROTOOPT;
6864 } /* end switch (opt) */
6869 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6871 struct epoch_tracker et;
6872 struct sctp_inpcb *inp;
6873 void *optval = NULL;
6878 if ((sopt->sopt_level == SOL_SOCKET) &&
6879 (sopt->sopt_name == SO_SETFIB)) {
6880 inp = (struct sctp_inpcb *)so->so_pcb;
6882 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6885 SCTP_INP_WLOCK(inp);
6886 inp->fibnum = so->so_fibnum;
6887 SCTP_INP_WUNLOCK(inp);
6890 if (sopt->sopt_level != IPPROTO_SCTP) {
6891 /* wrong proto level... send back up to IP */
6893 if (INP_CHECK_SOCKAF(so, AF_INET6))
6894 error = ip6_ctloutput(so, sopt);
6896 #if defined(INET) && defined(INET6)
6900 error = ip_ctloutput(so, sopt);
6904 optsize = sopt->sopt_valsize;
6905 if (optsize > SCTP_SOCKET_OPTION_LIMIT) {
6906 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6910 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6911 if (optval == NULL) {
6912 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6915 error = sooptcopyin(sopt, optval, optsize, optsize);
6917 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6921 p = (void *)sopt->sopt_td;
6922 if (sopt->sopt_dir == SOPT_SET) {
6923 NET_EPOCH_ENTER(et);
6924 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6926 } else if (sopt->sopt_dir == SOPT_GET) {
6927 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6929 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6932 if ((error == 0) && (optval != NULL)) {
6933 error = sooptcopyout(sopt, optval, optsize);
6934 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6935 } else if (optval != NULL) {
6936 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6944 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6946 struct epoch_tracker et;
6948 int create_lock_on = 0;
6950 struct sctp_inpcb *inp;
6951 struct sctp_tcb *stcb = NULL;
6953 inp = (struct sctp_inpcb *)so->so_pcb;
6955 /* I made the same as TCP since we are not setup? */
6956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6957 return (ECONNRESET);
6960 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6964 switch (addr->sa_family) {
6968 struct sockaddr_in6 *sin6;
6970 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6971 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6974 sin6 = (struct sockaddr_in6 *)addr;
6975 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6->sin6_addr)) != 0) {
6976 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6985 struct sockaddr_in *sin;
6987 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6988 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6991 sin = (struct sockaddr_in *)addr;
6992 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sin->sin_addr)) != 0) {
6993 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
7001 return (EAFNOSUPPORT);
7003 SCTP_INP_INCR_REF(inp);
7004 SCTP_ASOC_CREATE_LOCK(inp);
7006 NET_EPOCH_ENTER(et);
7008 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
7009 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
7010 /* Should I really unlock ? */
7011 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
7016 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
7017 (addr->sa_family == AF_INET6)) {
7018 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7023 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7024 /* Bind a ephemeral port */
7025 error = sctp_inpcb_bind(so, NULL, NULL, p);
7030 /* Now do we connect? */
7031 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
7032 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
7033 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7037 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7038 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7039 /* We are already connected AND the TCP model */
7040 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7044 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7045 SCTP_INP_RLOCK(inp);
7046 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7047 SCTP_INP_RUNLOCK(inp);
7050 * We increment here since sctp_findassociation_ep_addr()
7051 * will do a decrement if it finds the stcb as long as the
7052 * locked tcb (last argument) is NOT a TCB.. aka NULL.
7054 SCTP_INP_INCR_REF(inp);
7055 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7057 SCTP_INP_DECR_REF(inp);
7059 SCTP_TCB_UNLOCK(stcb);
7063 /* Already have or am bring up an association */
7064 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7069 vrf_id = inp->def_vrf_id;
7070 /* We are GOOD to go */
7071 stcb = sctp_aloc_assoc_connected(inp, addr, &error, 0, 0, vrf_id,
7072 inp->sctp_ep.pre_open_stream_count,
7073 inp->sctp_ep.port, p,
7074 SCTP_INITIALIZE_AUTH_PARAMS);
7076 /* Gak! no memory */
7079 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7080 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7082 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7083 SCTP_TCB_UNLOCK(stcb);
7086 if (create_lock_on) {
7087 SCTP_ASOC_CREATE_UNLOCK(inp);
7089 SCTP_INP_DECR_REF(inp);
7095 sctp_listen(struct socket *so, int backlog, struct thread *p)
7098 * Note this module depends on the protocol processing being called
7099 * AFTER any socket level flags and backlog are applied to the
7100 * socket. The traditional way that the socket flags are applied is
7101 * AFTER protocol processing. We have made a change to the
7102 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7103 * place if the socket API for SCTP is to work properly.
7107 struct sctp_inpcb *inp;
7109 inp = (struct sctp_inpcb *)so->so_pcb;
7111 /* I made the same as TCP since we are not setup? */
7112 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7113 return (ECONNRESET);
7115 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7116 /* See if we have a listener */
7117 struct sctp_inpcb *tinp;
7118 union sctp_sockstore store;
7120 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7122 struct sctp_laddr *laddr;
7124 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7125 memcpy(&store, &laddr->ifa->address, sizeof(store));
7126 switch (store.sa.sa_family) {
7129 store.sin.sin_port = inp->sctp_lport;
7134 store.sin6.sin6_port = inp->sctp_lport;
7140 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7141 if (tinp && (tinp != inp) &&
7142 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7143 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7144 (SCTP_IS_LISTENING(tinp))) {
7146 * we have a listener already and
7149 SCTP_INP_DECR_REF(tinp);
7150 return (EADDRINUSE);
7152 SCTP_INP_DECR_REF(tinp);
7156 /* Setup a local addr bound all */
7157 memset(&store, 0, sizeof(store));
7159 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7160 store.sa.sa_family = AF_INET6;
7161 store.sa.sa_len = sizeof(struct sockaddr_in6);
7165 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7166 store.sa.sa_family = AF_INET;
7167 store.sa.sa_len = sizeof(struct sockaddr_in);
7170 switch (store.sa.sa_family) {
7173 store.sin.sin_port = inp->sctp_lport;
7178 store.sin6.sin6_port = inp->sctp_lport;
7184 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7185 if (tinp && (tinp != inp) &&
7186 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7187 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7188 (SCTP_IS_LISTENING(tinp))) {
7190 * we have a listener already and its not
7193 SCTP_INP_DECR_REF(tinp);
7194 return (EADDRINUSE);
7196 SCTP_INP_DECR_REF(tinp);
7200 SCTP_INP_INFO_WLOCK();
7201 SCTP_INP_WLOCK(inp);
7202 #ifdef SCTP_LOCK_LOGGING
7203 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7204 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7207 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7208 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7210 * The unlucky case - We are in the tcp pool with this guy.
7211 * - Someone else is in the main inp slot. - We must move
7212 * this guy (the listener) to the main slot - We must then
7213 * move the guy that was listener to the TCP Pool.
7215 if (sctp_swap_inpcb_for_listen(inp)) {
7217 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7222 error = solisten_proto_check(so);
7227 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7228 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7230 solisten_proto_abort(so);
7232 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7235 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7236 ((inp->sctp_flags & SCTP_PCB_FLAGS_WAS_CONNECTED) ||
7237 (inp->sctp_flags & SCTP_PCB_FLAGS_WAS_ABORTED))) {
7239 solisten_proto_abort(so);
7241 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7244 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7245 if ((error = sctp_inpcb_bind_locked(inp, NULL, NULL, p))) {
7247 solisten_proto_abort(so);
7248 /* bind error, probably perm */
7252 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7253 solisten_proto(so, backlog);
7255 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7257 solisten_proto_abort(so);
7260 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7262 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7266 SCTP_INP_WUNLOCK(inp);
7267 SCTP_INP_INFO_WUNLOCK();
7271 static int sctp_defered_wakeup_cnt = 0;
7274 sctp_accept(struct socket *so, struct sockaddr **addr)
7276 struct sctp_tcb *stcb;
7277 struct sctp_inpcb *inp;
7278 union sctp_sockstore store;
7282 inp = (struct sctp_inpcb *)so->so_pcb;
7285 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7286 return (ECONNRESET);
7288 SCTP_INP_WLOCK(inp);
7289 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7290 SCTP_INP_WUNLOCK(inp);
7291 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7292 return (EOPNOTSUPP);
7294 if (so->so_state & SS_ISDISCONNECTED) {
7295 SCTP_INP_WUNLOCK(inp);
7296 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7297 return (ECONNABORTED);
7299 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7301 SCTP_INP_WUNLOCK(inp);
7302 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7303 return (ECONNRESET);
7305 SCTP_TCB_LOCK(stcb);
7306 store = stcb->asoc.primary_destination->ro._l_addr;
7307 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7308 /* Wake any delayed sleep action */
7309 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7310 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7311 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7312 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7313 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7314 if (sowriteable(inp->sctp_socket)) {
7315 sowwakeup_locked(inp->sctp_socket);
7317 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7320 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7321 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7322 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7323 if (soreadable(inp->sctp_socket)) {
7324 sctp_defered_wakeup_cnt++;
7325 sorwakeup_locked(inp->sctp_socket);
7327 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7331 SCTP_INP_WUNLOCK(inp);
7332 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7333 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7334 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7336 SCTP_TCB_UNLOCK(stcb);
7338 switch (store.sa.sa_family) {
7342 struct sockaddr_in *sin;
7344 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7347 sin->sin_family = AF_INET;
7348 sin->sin_len = sizeof(*sin);
7349 sin->sin_port = store.sin.sin_port;
7350 sin->sin_addr = store.sin.sin_addr;
7351 *addr = (struct sockaddr *)sin;
7358 struct sockaddr_in6 *sin6;
7360 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7363 sin6->sin6_family = AF_INET6;
7364 sin6->sin6_len = sizeof(*sin6);
7365 sin6->sin6_port = store.sin6.sin6_port;
7366 sin6->sin6_addr = store.sin6.sin6_addr;
7367 if ((error = sa6_recoverscope(sin6)) != 0) {
7368 SCTP_FREE_SONAME(sin6);
7371 *addr = (struct sockaddr *)sin6;
7384 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7386 struct sockaddr_in *sin;
7388 struct sctp_inpcb *inp;
7389 struct sctp_ifa *sctp_ifa;
7392 * Do the malloc first in case it blocks.
7394 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7397 sin->sin_family = AF_INET;
7398 sin->sin_len = sizeof(*sin);
7399 inp = (struct sctp_inpcb *)so->so_pcb;
7401 SCTP_FREE_SONAME(sin);
7402 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7403 return (ECONNRESET);
7405 SCTP_INP_RLOCK(inp);
7406 sin->sin_port = inp->sctp_lport;
7407 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7408 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7409 struct sctp_tcb *stcb;
7410 struct sockaddr_in *sin_a;
7411 struct sctp_nets *net;
7414 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7420 SCTP_TCB_LOCK(stcb);
7421 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7422 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7424 /* this will make coverity happy */
7427 if (sin_a->sin_family == AF_INET) {
7432 if ((!fnd) || (sin_a == NULL)) {
7434 SCTP_TCB_UNLOCK(stcb);
7438 vrf_id = inp->def_vrf_id;
7439 sctp_ifa = sctp_source_address_selection(inp,
7441 (sctp_route_t *)&net->ro,
7444 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7445 sctp_free_ifa(sctp_ifa);
7447 SCTP_TCB_UNLOCK(stcb);
7449 /* For the bound all case you get back 0 */
7451 sin->sin_addr.s_addr = 0;
7455 /* Take the first IPv4 address in the list */
7456 struct sctp_laddr *laddr;
7459 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7460 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7461 struct sockaddr_in *sin_a;
7463 sin_a = &laddr->ifa->address.sin;
7464 sin->sin_addr = sin_a->sin_addr;
7470 SCTP_FREE_SONAME(sin);
7471 SCTP_INP_RUNLOCK(inp);
7472 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7476 SCTP_INP_RUNLOCK(inp);
7477 (*addr) = (struct sockaddr *)sin;
7482 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7484 struct sockaddr_in *sin;
7486 struct sockaddr_in *sin_a;
7487 struct sctp_inpcb *inp;
7488 struct sctp_tcb *stcb;
7489 struct sctp_nets *net;
7491 /* Do the malloc first in case it blocks. */
7492 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7495 sin->sin_family = AF_INET;
7496 sin->sin_len = sizeof(*sin);
7498 inp = (struct sctp_inpcb *)so->so_pcb;
7499 if ((inp == NULL) ||
7500 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7501 /* UDP type and listeners will drop out here */
7502 SCTP_FREE_SONAME(sin);
7503 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7506 SCTP_INP_RLOCK(inp);
7507 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7509 SCTP_TCB_LOCK(stcb);
7511 SCTP_INP_RUNLOCK(inp);
7513 SCTP_FREE_SONAME(sin);
7514 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7515 return (ECONNRESET);
7518 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7519 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7520 if (sin_a->sin_family == AF_INET) {
7522 sin->sin_port = stcb->rport;
7523 sin->sin_addr = sin_a->sin_addr;
7527 SCTP_TCB_UNLOCK(stcb);
7529 /* No IPv4 address */
7530 SCTP_FREE_SONAME(sin);
7531 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7534 (*addr) = (struct sockaddr *)sin;
7538 #define SCTP_PROTOSW \
7539 .pr_protocol = IPPROTO_SCTP, \
7540 .pr_ctloutput = sctp_ctloutput, \
7541 .pr_abort = sctp_abort, \
7542 .pr_accept = sctp_accept, \
7543 .pr_attach = sctp_attach, \
7544 .pr_bind = sctp_bind, \
7545 .pr_connect = sctp_connect, \
7546 .pr_control = in_control, \
7547 .pr_close = sctp_close, \
7548 .pr_detach = sctp_close, \
7549 .pr_sopoll = sopoll_generic, \
7550 .pr_flush = sctp_flush, \
7551 .pr_disconnect = sctp_disconnect, \
7552 .pr_listen = sctp_listen, \
7553 .pr_peeraddr = sctp_peeraddr, \
7554 .pr_send = sctp_sendm, \
7555 .pr_shutdown = sctp_shutdown, \
7556 .pr_sockaddr = sctp_ingetaddr, \
7557 .pr_sosend = sctp_sosend, \
7558 .pr_soreceive = sctp_soreceive \
7560 struct protosw sctp_seqpacket_protosw = {
7561 .pr_type = SOCK_SEQPACKET,
7562 .pr_flags = PR_WANTRCVD,
7566 struct protosw sctp_stream_protosw = {
7567 .pr_type = SOCK_STREAM,
7568 .pr_flags = PR_CONNREQUIRED | PR_WANTRCVD,