2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
5 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
6 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * a) Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
14 * b) Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the distribution.
18 * c) Neither the name of Cisco Systems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <netinet/sctp_os.h>
40 #include <netinet/sctp_pcb.h>
41 #include <netinet/sctp_header.h>
42 #include <netinet/sctp_var.h>
44 #include <netinet6/sctp6_var.h>
46 #include <netinet/sctp_sysctl.h>
47 #include <netinet/sctp_output.h>
48 #include <netinet/sctp_uio.h>
49 #include <netinet/sctp_asconf.h>
50 #include <netinet/sctputil.h>
51 #include <netinet/sctp_indata.h>
52 #include <netinet/sctp_timer.h>
53 #include <netinet/sctp_auth.h>
54 #include <netinet/sctp_bsd_addr.h>
55 #include <netinet/udp.h>
56 #include <sys/eventhandler.h>
59 extern const struct sctp_cc_functions sctp_cc_functions[];
60 extern const struct sctp_ss_functions sctp_ss_functions[];
67 /* Initialize and modify the sysctled variables */
69 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
70 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
72 * Allow a user to take no more than 1/2 the number of clusters or
73 * the SB_MAX, whichever is smaller, for the send window.
75 sb_max_adj = (u_long)((u_quad_t)(SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
76 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
77 (((uint32_t)nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
79 * Now for the recv window, should we take the same amount? or
80 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
81 * now I will just copy.
83 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
84 SCTP_BASE_VAR(first_time) = 0;
85 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
87 #if defined(SCTP_PACKET_LOGGING)
88 SCTP_BASE_VAR(packet_log_writers) = 0;
89 SCTP_BASE_VAR(packet_log_end) = 0;
90 memset(&SCTP_BASE_VAR(packet_log_buffer), 0, SCTP_PACKET_LOG_SIZE);
92 SCTP_BASE_VAR(eh_tag) = EVENTHANDLER_REGISTER(rt_addrmsg,
93 sctp_addr_change_event_handler, NULL, EVENTHANDLER_PRI_FIRST);
98 sctp_finish(void *unused __unused)
100 EVENTHANDLER_DEREGISTER(rt_addrmsg, SCTP_BASE_VAR(eh_tag));
104 VNET_SYSUNINIT(sctp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, sctp_finish, NULL);
108 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
110 struct sctp_tmit_chunk *chk;
113 /* Adjust that too */
114 stcb->asoc.smallest_mtu = nxtsz;
115 /* now off to subtract IP_DF flag if needed */
116 overhead = IP_HDR_SIZE + sizeof(struct sctphdr);
117 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
118 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
120 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
121 if ((chk->send_size + overhead) > nxtsz) {
122 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
125 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
126 if ((chk->send_size + overhead) > nxtsz) {
128 * For this guy we also mark for immediate resend
129 * since we sent to big of chunk
131 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
132 if (chk->sent < SCTP_DATAGRAM_RESEND) {
133 sctp_flight_size_decrease(chk);
134 sctp_total_flight_decrease(stcb, chk);
135 chk->sent = SCTP_DATAGRAM_RESEND;
136 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
137 chk->rec.data.doing_fast_retransmit = 0;
138 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
139 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
140 chk->whoTo->flight_size,
142 (uint32_t)(uintptr_t)chk->whoTo,
145 /* Clear any time so NO RTT is being done */
146 if (chk->do_rtt == 1) {
148 chk->whoTo->rto_needed = 1;
157 sctp_notify(struct sctp_inpcb *inp,
158 struct sctp_tcb *stcb,
159 struct sctp_nets *net,
167 if (icmp_type != ICMP_UNREACH) {
168 /* We only care about unreachable */
169 SCTP_TCB_UNLOCK(stcb);
172 if ((icmp_code == ICMP_UNREACH_NET) ||
173 (icmp_code == ICMP_UNREACH_HOST) ||
174 (icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
175 (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
176 (icmp_code == ICMP_UNREACH_ISOLATED) ||
177 (icmp_code == ICMP_UNREACH_NET_PROHIB) ||
178 (icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
179 (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
180 /* Mark the net unreachable. */
181 if (net->dest_state & SCTP_ADDR_REACHABLE) {
182 /* OK, that destination is NOT reachable. */
183 net->dest_state &= ~SCTP_ADDR_REACHABLE;
184 net->dest_state &= ~SCTP_ADDR_PF;
185 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
187 (void *)net, SCTP_SO_NOT_LOCKED);
189 SCTP_TCB_UNLOCK(stcb);
190 } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) ||
191 (icmp_code == ICMP_UNREACH_PORT)) {
192 /* Treat it like an ABORT. */
193 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
194 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
195 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
196 /* no need to unlock here, since the TCB is gone */
197 } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) {
198 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
199 SCTP_TCB_UNLOCK(stcb);
202 /* Find the next (smaller) MTU */
205 * Old type router that does not tell us what the
206 * next MTU is. Rats we will have to guess (in a
207 * educated fashion of course).
209 next_mtu = sctp_get_prev_mtu(ip_len);
211 /* Stop the PMTU timer. */
212 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
214 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
215 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
219 /* Update the path MTU. */
221 next_mtu -= sizeof(struct udphdr);
223 if (net->mtu > next_mtu) {
226 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu + sizeof(struct udphdr));
228 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu);
231 /* Update the association MTU */
232 if (stcb->asoc.smallest_mtu > next_mtu) {
233 sctp_pathmtu_adjustment(stcb, next_mtu);
235 /* Finally, start the PMTU timer if it was running before. */
237 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
239 SCTP_TCB_UNLOCK(stcb);
241 SCTP_TCB_UNLOCK(stcb);
246 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
252 struct sctp_inpcb *inp;
253 struct sctp_tcb *stcb;
254 struct sctp_nets *net;
255 struct sctp_init_chunk *ch;
256 struct sockaddr_in src, dst;
258 if (sa->sa_family != AF_INET ||
259 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
262 if (PRC_IS_REDIRECT(cmd)) {
264 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
268 inner_ip = (struct ip *)vip;
269 icmp = (struct icmp *)((caddr_t)inner_ip -
270 (sizeof(struct icmp) - sizeof(struct ip)));
271 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
272 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
273 memset(&src, 0, sizeof(struct sockaddr_in));
274 src.sin_family = AF_INET;
275 src.sin_len = sizeof(struct sockaddr_in);
276 src.sin_port = sh->src_port;
277 src.sin_addr = inner_ip->ip_src;
278 memset(&dst, 0, sizeof(struct sockaddr_in));
279 dst.sin_family = AF_INET;
280 dst.sin_len = sizeof(struct sockaddr_in);
281 dst.sin_port = sh->dest_port;
282 dst.sin_addr = inner_ip->ip_dst;
284 * 'dst' holds the dest of the packet that failed to be
285 * sent. 'src' holds our local endpoint address. Thus we
286 * reverse the dst and the src in the lookup.
290 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
291 (struct sockaddr *)&src,
294 if ((stcb != NULL) &&
297 /* Check the verification tag */
298 if (ntohl(sh->v_tag) != 0) {
300 * This must be the verification tag used
301 * for sending out packets. We don't
302 * consider packets reflecting the
305 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
306 SCTP_TCB_UNLOCK(stcb);
310 if (ntohs(outer_ip->ip_len) >=
312 8 + (inner_ip->ip_hl << 2) + 20) {
314 * In this case we can check if we
315 * got an INIT chunk and if the
316 * initiate tag matches.
318 ch = (struct sctp_init_chunk *)(sh + 1);
319 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
320 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
321 SCTP_TCB_UNLOCK(stcb);
325 SCTP_TCB_UNLOCK(stcb);
329 sctp_notify(inp, stcb, net,
332 ntohs(inner_ip->ip_len),
333 (uint32_t)ntohs(icmp->icmp_nextmtu));
335 if ((stcb == NULL) && (inp != NULL)) {
336 /* reduce ref-count */
338 SCTP_INP_DECR_REF(inp);
339 SCTP_INP_WUNLOCK(inp);
342 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");
417 sctp_abort(struct socket *so)
419 struct epoch_tracker et;
420 struct sctp_inpcb *inp;
423 inp = (struct sctp_inpcb *)so->so_pcb;
430 flags = inp->sctp_flags;
431 #ifdef SCTP_LOG_CLOSING
432 sctp_log_closing(inp, NULL, 17);
434 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
435 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
436 #ifdef SCTP_LOG_CLOSING
437 sctp_log_closing(inp, NULL, 16);
439 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
440 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
442 SCTP_SB_CLEAR(so->so_snd);
444 * same for the rcv ones, they are only here for the
447 SCTP_SB_CLEAR(so->so_rcv);
449 /* Now null out the reference, we are completely detached. */
453 flags = inp->sctp_flags;
454 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
455 goto sctp_must_try_again;
463 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
465 struct sctp_inpcb *inp;
466 struct inpcb *ip_inp;
468 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
470 inp = (struct sctp_inpcb *)so->so_pcb;
472 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
475 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
476 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
481 error = sctp_inpcb_alloc(so, vrf_id);
485 inp = (struct sctp_inpcb *)so->so_pcb;
487 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
488 ip_inp = &inp->ip_inp.inp;
489 ip_inp->inp_vflag |= INP_IPV4;
490 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
491 SCTP_INP_WUNLOCK(inp);
496 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
498 struct sctp_inpcb *inp;
500 inp = (struct sctp_inpcb *)so->so_pcb;
502 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
506 if ((addr->sa_family != AF_INET) ||
507 (addr->sa_len != sizeof(struct sockaddr_in))) {
508 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
512 return (sctp_inpcb_bind(so, addr, NULL, p));
517 sctp_close(struct socket *so)
519 struct epoch_tracker et;
520 struct sctp_inpcb *inp;
523 inp = (struct sctp_inpcb *)so->so_pcb;
528 * Inform all the lower layer assoc that we are done.
532 flags = inp->sctp_flags;
533 #ifdef SCTP_LOG_CLOSING
534 sctp_log_closing(inp, NULL, 17);
536 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
537 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
538 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
539 (so->so_rcv.sb_cc > 0)) {
540 #ifdef SCTP_LOG_CLOSING
541 sctp_log_closing(inp, NULL, 13);
543 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
544 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
546 #ifdef SCTP_LOG_CLOSING
547 sctp_log_closing(inp, NULL, 14);
549 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
550 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
553 * The socket is now detached, no matter what the state of
554 * the SCTP association.
557 SCTP_SB_CLEAR(so->so_snd);
559 * same for the rcv ones, they are only here for the
562 SCTP_SB_CLEAR(so->so_rcv);
564 /* Now null out the reference, we are completely detached. */
568 flags = inp->sctp_flags;
569 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
570 goto sctp_must_try_again;
579 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
580 struct mbuf *control, struct thread *p);
584 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
585 struct mbuf *control, struct thread *p)
587 struct sctp_inpcb *inp;
590 inp = (struct sctp_inpcb *)so->so_pcb;
593 sctp_m_freem(control);
596 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
600 /* Got to have an to address if we are NOT a connected socket */
601 if ((addr == NULL) &&
602 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
603 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
605 } else if (addr == NULL) {
606 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
607 error = EDESTADDRREQ;
610 sctp_m_freem(control);
616 if (addr->sa_family != AF_INET) {
617 /* must be a v4 address! */
618 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
621 sctp_m_freem(control);
624 error = EDESTADDRREQ;
629 /* now what about control */
632 sctp_m_freem(inp->control);
635 inp->control = control;
639 SCTP_BUF_NEXT(inp->pkt_last) = m;
642 inp->pkt_last = inp->pkt = m;
645 /* FreeBSD uses a flag passed */
646 ((flags & PRUS_MORETOCOME) == 0)
649 * note with the current version this code will only be used
650 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
651 * re-defining sosend to use the sctp_sosend. One can
652 * optionally switch back to this code (by changing back the
653 * definitions) but this is not advisable. This code is used
654 * by FreeBSD when sending a file with sendfile() though.
656 struct epoch_tracker et;
660 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
671 sctp_disconnect(struct socket *so)
673 struct sctp_inpcb *inp;
675 inp = (struct sctp_inpcb *)so->so_pcb;
677 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
681 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
682 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
683 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
685 SCTP_INP_RUNLOCK(inp);
688 struct epoch_tracker et;
689 struct sctp_association *asoc;
690 struct sctp_tcb *stcb;
692 stcb = LIST_FIRST(&inp->sctp_asoc_list);
694 SCTP_INP_RUNLOCK(inp);
695 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
700 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
701 /* We are about to be freed, out of here */
702 SCTP_TCB_UNLOCK(stcb);
703 SCTP_INP_RUNLOCK(inp);
707 if (((so->so_options & SO_LINGER) &&
708 (so->so_linger == 0)) ||
709 (so->so_rcv.sb_cc > 0)) {
710 if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) {
711 /* Left with Data unread */
714 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
715 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
716 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
718 SCTP_INP_RUNLOCK(inp);
719 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
720 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
721 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
723 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
724 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
725 /* No unlock tcb assoc is gone */
729 if (TAILQ_EMPTY(&asoc->send_queue) &&
730 TAILQ_EMPTY(&asoc->sent_queue) &&
731 (asoc->stream_queue_cnt == 0)) {
732 /* there is nothing queued to send, so done */
733 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
736 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) &&
737 (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
738 /* only send SHUTDOWN 1st time thru */
739 struct sctp_nets *netp;
741 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
742 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
743 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
745 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
746 sctp_stop_timers_for_shutdown(stcb);
747 if (stcb->asoc.alternate) {
748 netp = stcb->asoc.alternate;
750 netp = stcb->asoc.primary_destination;
752 sctp_send_shutdown(stcb, netp);
753 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
754 stcb->sctp_ep, stcb, netp);
755 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
756 stcb->sctp_ep, stcb, NULL);
757 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
761 * we still got (or just got) data to send,
762 * so set SHUTDOWN_PENDING
765 * XXX sockets draft says that SCTP_EOF
766 * should be sent with no data. currently,
767 * we will allow user data to be sent first
768 * and move to SHUTDOWN-PENDING
770 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
771 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
772 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
773 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
775 if (TAILQ_EMPTY(&asoc->send_queue) &&
776 TAILQ_EMPTY(&asoc->sent_queue) &&
777 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
781 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
782 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
783 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
784 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
785 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
786 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
787 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
789 SCTP_INP_RUNLOCK(inp);
790 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
791 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
795 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
798 soisdisconnecting(so);
800 SCTP_TCB_UNLOCK(stcb);
801 SCTP_INP_RUNLOCK(inp);
806 /* UDP model does not support this */
807 SCTP_INP_RUNLOCK(inp);
808 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
814 sctp_flush(struct socket *so, int how)
817 * We will just clear out the values and let subsequent close clear
818 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
819 * they will not be able to read the data, the socket will block
820 * that from happening.
822 struct sctp_inpcb *inp;
824 inp = (struct sctp_inpcb *)so->so_pcb;
826 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
830 /* For the 1 to many model this does nothing */
831 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
832 SCTP_INP_RUNLOCK(inp);
835 SCTP_INP_RUNLOCK(inp);
836 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
838 * First make sure the sb will be happy, we don't use these
839 * except maybe the count
842 SCTP_INP_READ_LOCK(inp);
843 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
844 SCTP_INP_READ_UNLOCK(inp);
845 SCTP_INP_WUNLOCK(inp);
846 so->so_rcv.sb_cc = 0;
847 so->so_rcv.sb_mbcnt = 0;
848 so->so_rcv.sb_mb = NULL;
850 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
852 * First make sure the sb will be happy, we don't use these
853 * except maybe the count
855 so->so_snd.sb_cc = 0;
856 so->so_snd.sb_mbcnt = 0;
857 so->so_snd.sb_mb = NULL;
864 sctp_shutdown(struct socket *so)
866 struct sctp_inpcb *inp;
868 inp = (struct sctp_inpcb *)so->so_pcb;
870 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
874 /* For UDP model this is a invalid call */
875 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
876 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
877 /* Restore the flags that the soshutdown took away. */
878 SOCKBUF_LOCK(&so->so_rcv);
879 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
880 SOCKBUF_UNLOCK(&so->so_rcv);
881 /* This proc will wakeup for read and do nothing (I hope) */
882 SCTP_INP_RUNLOCK(inp);
883 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
887 * Ok, if we reach here its the TCP model and it is either a
888 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
891 struct epoch_tracker et;
892 struct sctp_tcb *stcb;
893 struct sctp_association *asoc;
894 struct sctp_nets *netp;
897 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
898 SCTP_INP_RUNLOCK(inp);
903 stcb = LIST_FIRST(&inp->sctp_asoc_list);
906 * Ok, we hit the case that the shutdown call was
907 * made after an abort or something. Nothing to do
910 SCTP_INP_RUNLOCK(inp);
915 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
916 SCTP_TCB_UNLOCK(stcb);
917 SCTP_INP_RUNLOCK(inp);
920 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) &&
921 (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) &&
922 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) {
924 * If we are not in or before ESTABLISHED, there is
925 * no protocol action required.
927 SCTP_TCB_UNLOCK(stcb);
928 SCTP_INP_RUNLOCK(inp);
932 if (stcb->asoc.alternate) {
933 netp = stcb->asoc.alternate;
935 netp = stcb->asoc.primary_destination;
937 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) &&
938 TAILQ_EMPTY(&asoc->send_queue) &&
939 TAILQ_EMPTY(&asoc->sent_queue) &&
940 (asoc->stream_queue_cnt == 0)) {
941 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
944 /* there is nothing queued to send, so I'm done... */
945 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
946 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
947 sctp_stop_timers_for_shutdown(stcb);
948 sctp_send_shutdown(stcb, netp);
949 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
950 stcb->sctp_ep, stcb, netp);
953 * We still got (or just got) data to send, so set
956 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
957 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
958 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
960 if (TAILQ_EMPTY(&asoc->send_queue) &&
961 TAILQ_EMPTY(&asoc->sent_queue) &&
962 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
966 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
967 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
968 SCTP_INP_RUNLOCK(inp);
969 sctp_abort_an_association(stcb->sctp_ep, stcb,
970 op_err, SCTP_SO_LOCKED);
975 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
977 * XXX: Why do this in the case where we have still data
980 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
981 SCTP_TCB_UNLOCK(stcb);
982 SCTP_INP_RUNLOCK(inp);
989 * copies a "user" presentable address and removes embedded scope, etc.
990 * returns 0 on success, 1 on error
993 sctp_fill_user_address(struct sockaddr *dst, struct sockaddr *src)
996 struct sockaddr_in6 lsa6;
998 src = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)src,
1001 memcpy(dst, src, src->sa_len);
1008 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1009 struct sctp_tcb *stcb,
1011 struct sockaddr *addr,
1014 struct sctp_ifn *sctp_ifn;
1015 struct sctp_ifa *sctp_ifa;
1019 int ipv4_local_scope, ipv4_addr_legal;
1022 int local_scope, site_scope, ipv6_addr_legal;
1024 struct sctp_vrf *vrf;
1026 SCTP_IPI_ADDR_LOCK_ASSERT();
1032 /* Turn on all the appropriate scope */
1033 loopback_scope = stcb->asoc.scope.loopback_scope;
1035 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1036 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1039 local_scope = stcb->asoc.scope.local_scope;
1040 site_scope = stcb->asoc.scope.site_scope;
1041 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1044 /* Use generic values for endpoints. */
1047 ipv4_local_scope = 1;
1053 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1055 ipv6_addr_legal = 1;
1058 if (SCTP_IPV6_V6ONLY(inp)) {
1059 ipv4_addr_legal = 0;
1061 ipv4_addr_legal = 1;
1066 ipv6_addr_legal = 0;
1069 ipv4_addr_legal = 1;
1073 vrf = sctp_find_vrf(vrf_id);
1077 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1078 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1079 if ((loopback_scope == 0) &&
1080 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1081 /* Skip loopback if loopback_scope not set */
1084 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1087 * For the BOUND-ALL case, the list
1088 * associated with a TCB is Always
1089 * considered a reverse list.. i.e.
1090 * it lists addresses that are NOT
1091 * part of the association. If this
1092 * is one of those we must skip it.
1094 if (sctp_is_addr_restricted(stcb,
1099 switch (sctp_ifa->address.sa.sa_family) {
1102 if (ipv4_addr_legal) {
1103 struct sockaddr_in *sin;
1105 sin = &sctp_ifa->address.sin;
1106 if (sin->sin_addr.s_addr == 0) {
1114 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1115 &sin->sin_addr) != 0) {
1118 if ((ipv4_local_scope == 0) &&
1119 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1123 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1124 if (actual + sizeof(struct sockaddr_in6) > limit) {
1127 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)addr);
1128 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1129 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1130 actual += sizeof(struct sockaddr_in6);
1133 if (actual + sizeof(struct sockaddr_in) > limit) {
1136 memcpy(addr, sin, sizeof(struct sockaddr_in));
1137 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1138 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in));
1139 actual += sizeof(struct sockaddr_in);
1150 if (ipv6_addr_legal) {
1151 struct sockaddr_in6 *sin6;
1153 sin6 = &sctp_ifa->address.sin6;
1154 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1162 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1163 &sin6->sin6_addr) != 0) {
1166 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1167 if (local_scope == 0)
1169 if (sin6->sin6_scope_id == 0) {
1170 if (sa6_recoverscope(sin6) != 0)
1183 if ((site_scope == 0) &&
1184 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1187 if (actual + sizeof(struct sockaddr_in6) > limit) {
1190 memcpy(addr, sin6, sizeof(struct sockaddr_in6));
1191 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1192 addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6));
1193 actual += sizeof(struct sockaddr_in6);
1206 struct sctp_laddr *laddr;
1209 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1211 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1215 sa_len = laddr->ifa->address.sa.sa_len;
1216 if (actual + sa_len > limit) {
1219 if (sctp_fill_user_address(addr, &laddr->ifa->address.sa))
1221 switch (laddr->ifa->address.sa.sa_family) {
1224 ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport;
1229 ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport;
1236 addr = (struct sockaddr *)((caddr_t)addr + sa_len);
1244 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1245 struct sctp_tcb *stcb,
1247 struct sockaddr *addr)
1251 SCTP_IPI_ADDR_RLOCK();
1252 /* fill up addresses for the endpoint's default vrf */
1253 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, addr,
1255 SCTP_IPI_ADDR_RUNLOCK();
1260 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1263 struct sctp_vrf *vrf = NULL;
1266 * In both sub-set bound an bound_all cases we return the MAXIMUM
1267 * number of addresses that you COULD get. In reality the sub-set
1268 * bound may have an exclusion list for a given TCB OR in the
1269 * bound-all case a TCB may NOT include the loopback or other
1270 * addresses as well.
1272 SCTP_IPI_ADDR_LOCK_ASSERT();
1273 vrf = sctp_find_vrf(vrf_id);
1277 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1278 struct sctp_ifn *sctp_ifn;
1279 struct sctp_ifa *sctp_ifa;
1281 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1282 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1283 /* Count them if they are the right type */
1284 switch (sctp_ifa->address.sa.sa_family) {
1288 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1289 cnt += sizeof(struct sockaddr_in6);
1291 cnt += sizeof(struct sockaddr_in);
1293 cnt += sizeof(struct sockaddr_in);
1299 cnt += sizeof(struct sockaddr_in6);
1308 struct sctp_laddr *laddr;
1310 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1311 switch (laddr->ifa->address.sa.sa_family) {
1315 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1316 cnt += sizeof(struct sockaddr_in6);
1318 cnt += sizeof(struct sockaddr_in);
1320 cnt += sizeof(struct sockaddr_in);
1326 cnt += sizeof(struct sockaddr_in6);
1338 sctp_count_max_addresses(struct sctp_inpcb *inp)
1342 SCTP_IPI_ADDR_RLOCK();
1343 /* count addresses for the endpoint's default VRF */
1344 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1345 SCTP_IPI_ADDR_RUNLOCK();
1350 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1351 size_t optsize, void *p, int delay)
1354 int creat_lock_on = 0;
1355 struct sctp_tcb *stcb = NULL;
1356 struct sockaddr *sa;
1357 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1361 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1363 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1364 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1365 /* We are already connected AND the TCP model */
1366 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1367 return (EADDRINUSE);
1370 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1371 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1372 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1376 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1377 SCTP_INP_RLOCK(inp);
1378 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1379 SCTP_INP_RUNLOCK(inp);
1382 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1385 SCTP_INP_INCR_REF(inp);
1386 SCTP_ASOC_CREATE_LOCK(inp);
1388 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1389 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1390 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1394 totaddrp = (unsigned int *)optval;
1395 totaddr = *totaddrp;
1396 sa = (struct sockaddr *)(totaddrp + 1);
1397 error = sctp_connectx_helper_find(inp, sa, totaddr, &num_v4, &num_v6, (unsigned int)(optsize - sizeof(int)));
1399 /* Already have or am bring up an association */
1400 SCTP_ASOC_CREATE_UNLOCK(inp);
1402 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1406 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1411 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1413 if (SCTP_IPV6_V6ONLY(inp)) {
1415 * if IPV6_V6ONLY flag, ignore connections destined
1416 * to a v4 addr or v4-mapped addr
1418 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1424 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1425 SCTP_PCB_FLAGS_UNBOUND) {
1426 /* Bind a ephemeral port */
1427 error = sctp_inpcb_bind(so, NULL, NULL, p);
1433 /* FIX ME: do we want to pass in a vrf on the connect call? */
1434 vrf_id = inp->def_vrf_id;
1437 /* We are GOOD to go */
1438 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1439 inp->sctp_ep.pre_open_stream_count,
1442 SCTP_INITIALIZE_AUTH_PARAMS);
1444 /* Gak! no memory */
1447 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1448 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1449 /* Set the connected flag so we can queue data */
1452 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1453 /* move to second address */
1454 switch (sa->sa_family) {
1457 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1462 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1470 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1471 /* Fill in the return id */
1475 a_id = (sctp_assoc_t *)optval;
1476 *a_id = sctp_get_associd(stcb);
1479 /* doing delayed connection */
1480 stcb->asoc.delayed_connection = 1;
1481 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1483 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1484 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1486 SCTP_TCB_UNLOCK(stcb);
1488 if (creat_lock_on) {
1489 SCTP_ASOC_CREATE_UNLOCK(inp);
1491 SCTP_INP_DECR_REF(inp);
1495 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1496 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1497 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1498 SCTP_INP_RLOCK(inp); \
1499 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1501 SCTP_TCB_LOCK(stcb); \
1503 SCTP_INP_RUNLOCK(inp); \
1504 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1505 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1506 if (stcb == NULL) { \
1507 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1517 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1518 if (size < sizeof(type)) { \
1519 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1523 destp = (type *)srcp; \
1528 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1531 struct sctp_inpcb *inp = NULL;
1533 struct sctp_tcb *stcb = NULL;
1535 if (optval == NULL) {
1536 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1540 inp = (struct sctp_inpcb *)so->so_pcb;
1542 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1549 case SCTP_AUTOCLOSE:
1550 case SCTP_EXPLICIT_EOR:
1551 case SCTP_AUTO_ASCONF:
1552 case SCTP_DISABLE_FRAGMENTS:
1553 case SCTP_I_WANT_MAPPED_V4_ADDR:
1554 case SCTP_USE_EXT_RCVINFO:
1555 SCTP_INP_RLOCK(inp);
1557 case SCTP_DISABLE_FRAGMENTS:
1558 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1560 case SCTP_I_WANT_MAPPED_V4_ADDR:
1561 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1563 case SCTP_AUTO_ASCONF:
1564 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1565 /* only valid for bound all sockets */
1566 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1568 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1573 case SCTP_EXPLICIT_EOR:
1574 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1577 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1579 case SCTP_USE_EXT_RCVINFO:
1580 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1582 case SCTP_AUTOCLOSE:
1583 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1584 val = sctp_ticks_to_secs(inp->sctp_ep.auto_close_time);
1590 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1591 error = ENOPROTOOPT;
1592 } /* end switch (sopt->sopt_name) */
1593 if (*optsize < sizeof(val)) {
1594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1598 SCTP_INP_RUNLOCK(inp);
1600 /* return the option value */
1601 *(int *)optval = val;
1602 *optsize = sizeof(val);
1605 case SCTP_GET_PACKET_LOG:
1607 #ifdef SCTP_PACKET_LOGGING
1611 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1612 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1615 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1620 case SCTP_REUSE_PORT:
1624 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1625 /* Can't do this for a 1-m socket */
1629 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1630 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1631 *optsize = sizeof(uint32_t);
1634 case SCTP_PARTIAL_DELIVERY_POINT:
1638 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1639 *value = inp->partial_delivery_point;
1640 *optsize = sizeof(uint32_t);
1643 case SCTP_FRAGMENT_INTERLEAVE:
1647 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1648 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1649 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1650 *value = SCTP_FRAG_LEVEL_2;
1652 *value = SCTP_FRAG_LEVEL_1;
1655 *value = SCTP_FRAG_LEVEL_0;
1657 *optsize = sizeof(uint32_t);
1660 case SCTP_INTERLEAVING_SUPPORTED:
1662 struct sctp_assoc_value *av;
1664 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1665 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1668 av->assoc_value = stcb->asoc.idata_supported;
1669 SCTP_TCB_UNLOCK(stcb);
1671 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1672 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1673 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1674 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1675 SCTP_INP_RLOCK(inp);
1676 if (inp->idata_supported) {
1677 av->assoc_value = 1;
1679 av->assoc_value = 0;
1681 SCTP_INP_RUNLOCK(inp);
1683 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1688 *optsize = sizeof(struct sctp_assoc_value);
1692 case SCTP_CMT_ON_OFF:
1694 struct sctp_assoc_value *av;
1696 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1697 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1699 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1700 SCTP_TCB_UNLOCK(stcb);
1702 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1703 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1704 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1705 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1706 SCTP_INP_RLOCK(inp);
1707 av->assoc_value = inp->sctp_cmt_on_off;
1708 SCTP_INP_RUNLOCK(inp);
1710 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1715 *optsize = sizeof(struct sctp_assoc_value);
1719 case SCTP_PLUGGABLE_CC:
1721 struct sctp_assoc_value *av;
1723 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1724 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1726 av->assoc_value = stcb->asoc.congestion_control_module;
1727 SCTP_TCB_UNLOCK(stcb);
1729 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1730 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1731 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1732 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1733 SCTP_INP_RLOCK(inp);
1734 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1735 SCTP_INP_RUNLOCK(inp);
1737 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1742 *optsize = sizeof(struct sctp_assoc_value);
1746 case SCTP_CC_OPTION:
1748 struct sctp_cc_option *cc_opt;
1750 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1751 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1755 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1758 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1759 *optsize = sizeof(struct sctp_cc_option);
1761 SCTP_TCB_UNLOCK(stcb);
1765 case SCTP_PLUGGABLE_SS:
1767 struct sctp_assoc_value *av;
1769 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1770 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1772 av->assoc_value = stcb->asoc.stream_scheduling_module;
1773 SCTP_TCB_UNLOCK(stcb);
1775 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1776 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1777 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1778 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1779 SCTP_INP_RLOCK(inp);
1780 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1781 SCTP_INP_RUNLOCK(inp);
1783 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1788 *optsize = sizeof(struct sctp_assoc_value);
1794 struct sctp_stream_value *av;
1796 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1797 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1799 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1800 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1801 &av->stream_value) < 0)) {
1802 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1805 *optsize = sizeof(struct sctp_stream_value);
1807 SCTP_TCB_UNLOCK(stcb);
1810 * Can't get stream value without
1813 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1818 case SCTP_GET_ADDR_LEN:
1820 struct sctp_assoc_value *av;
1822 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1825 if (av->assoc_value == AF_INET) {
1826 av->assoc_value = sizeof(struct sockaddr_in);
1831 if (av->assoc_value == AF_INET6) {
1832 av->assoc_value = sizeof(struct sockaddr_in6);
1837 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1839 *optsize = sizeof(struct sctp_assoc_value);
1843 case SCTP_GET_ASSOC_NUMBER:
1845 uint32_t *value, cnt;
1847 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1848 SCTP_INP_RLOCK(inp);
1849 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1850 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1851 /* Can't do this for a 1-1 socket */
1853 SCTP_INP_RUNLOCK(inp);
1857 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1860 SCTP_INP_RUNLOCK(inp);
1862 *optsize = sizeof(uint32_t);
1865 case SCTP_GET_ASSOC_ID_LIST:
1867 struct sctp_assoc_ids *ids;
1871 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1872 SCTP_INP_RLOCK(inp);
1873 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1874 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1875 /* Can't do this for a 1-1 socket */
1877 SCTP_INP_RUNLOCK(inp);
1881 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1882 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1884 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1892 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1896 SCTP_INP_RUNLOCK(inp);
1898 ids->gaids_number_of_ids = at;
1899 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1905 struct sctp_assoc_value *av;
1907 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1908 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1911 av->assoc_value = stcb->asoc.context;
1912 SCTP_TCB_UNLOCK(stcb);
1914 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1915 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1916 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1917 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1918 SCTP_INP_RLOCK(inp);
1919 av->assoc_value = inp->sctp_context;
1920 SCTP_INP_RUNLOCK(inp);
1922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1927 *optsize = sizeof(struct sctp_assoc_value);
1933 uint32_t *default_vrfid;
1935 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1936 *default_vrfid = inp->def_vrf_id;
1937 *optsize = sizeof(uint32_t);
1940 case SCTP_GET_ASOC_VRF:
1942 struct sctp_assoc_value *id;
1944 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1945 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1950 id->assoc_value = stcb->asoc.vrf_id;
1951 SCTP_TCB_UNLOCK(stcb);
1952 *optsize = sizeof(struct sctp_assoc_value);
1956 case SCTP_GET_VRF_IDS:
1958 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1962 case SCTP_GET_NONCE_VALUES:
1964 struct sctp_get_nonce_values *gnv;
1966 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1967 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1970 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1971 gnv->gn_local_tag = stcb->asoc.my_vtag;
1972 SCTP_TCB_UNLOCK(stcb);
1973 *optsize = sizeof(struct sctp_get_nonce_values);
1975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1980 case SCTP_DELAYED_SACK:
1982 struct sctp_sack_info *sack;
1984 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1985 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1987 sack->sack_delay = stcb->asoc.delayed_ack;
1988 sack->sack_freq = stcb->asoc.sack_freq;
1989 SCTP_TCB_UNLOCK(stcb);
1991 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1992 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1993 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1994 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC))) {
1995 SCTP_INP_RLOCK(inp);
1996 sack->sack_delay = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1997 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
1998 SCTP_INP_RUNLOCK(inp);
2000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2005 *optsize = sizeof(struct sctp_sack_info);
2009 case SCTP_GET_SNDBUF_USE:
2011 struct sctp_sockstat *ss;
2013 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2014 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2017 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2018 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2019 stcb->asoc.size_on_all_streams);
2020 SCTP_TCB_UNLOCK(stcb);
2021 *optsize = sizeof(struct sctp_sockstat);
2023 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2028 case SCTP_MAX_BURST:
2030 struct sctp_assoc_value *av;
2032 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2033 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2036 av->assoc_value = stcb->asoc.max_burst;
2037 SCTP_TCB_UNLOCK(stcb);
2039 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2040 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2041 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2042 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2043 SCTP_INP_RLOCK(inp);
2044 av->assoc_value = inp->sctp_ep.max_burst;
2045 SCTP_INP_RUNLOCK(inp);
2047 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2052 *optsize = sizeof(struct sctp_assoc_value);
2058 struct sctp_assoc_value *av;
2061 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2062 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2065 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2066 SCTP_TCB_UNLOCK(stcb);
2068 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2069 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2070 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2071 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2072 SCTP_INP_RLOCK(inp);
2073 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2074 ovh = SCTP_MED_OVERHEAD;
2076 ovh = SCTP_MED_V4_OVERHEAD;
2078 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2079 av->assoc_value = 0;
2081 av->assoc_value = inp->sctp_frag_point - ovh;
2082 SCTP_INP_RUNLOCK(inp);
2084 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2089 *optsize = sizeof(struct sctp_assoc_value);
2093 case SCTP_GET_STAT_LOG:
2094 error = sctp_fill_stat_log(optval, optsize);
2098 struct sctp_event_subscribe *events;
2100 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2101 memset(events, 0, sizeof(struct sctp_event_subscribe));
2102 SCTP_INP_RLOCK(inp);
2103 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2104 events->sctp_data_io_event = 1;
2106 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2107 events->sctp_association_event = 1;
2109 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2110 events->sctp_address_event = 1;
2112 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2113 events->sctp_send_failure_event = 1;
2115 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2116 events->sctp_peer_error_event = 1;
2118 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2119 events->sctp_shutdown_event = 1;
2121 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2122 events->sctp_partial_delivery_event = 1;
2124 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2125 events->sctp_adaptation_layer_event = 1;
2127 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2128 events->sctp_authentication_event = 1;
2130 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2131 events->sctp_sender_dry_event = 1;
2133 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2134 events->sctp_stream_reset_event = 1;
2135 SCTP_INP_RUNLOCK(inp);
2136 *optsize = sizeof(struct sctp_event_subscribe);
2139 case SCTP_ADAPTATION_LAYER:
2143 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2145 SCTP_INP_RLOCK(inp);
2146 *value = inp->sctp_ep.adaptation_layer_indicator;
2147 SCTP_INP_RUNLOCK(inp);
2148 *optsize = sizeof(uint32_t);
2151 case SCTP_SET_INITIAL_DBG_SEQ:
2155 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2156 SCTP_INP_RLOCK(inp);
2157 *value = inp->sctp_ep.initial_sequence_debug;
2158 SCTP_INP_RUNLOCK(inp);
2159 *optsize = sizeof(uint32_t);
2162 case SCTP_GET_LOCAL_ADDR_SIZE:
2166 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2167 SCTP_INP_RLOCK(inp);
2168 *value = sctp_count_max_addresses(inp);
2169 SCTP_INP_RUNLOCK(inp);
2170 *optsize = sizeof(uint32_t);
2173 case SCTP_GET_REMOTE_ADDR_SIZE:
2177 struct sctp_nets *net;
2179 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2180 /* FIXME MT: change to sctp_assoc_value? */
2181 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2185 /* Count the sizes */
2186 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2187 switch (net->ro._l_addr.sa.sa_family) {
2191 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2192 size += sizeof(struct sockaddr_in6);
2194 size += sizeof(struct sockaddr_in);
2197 size += sizeof(struct sockaddr_in);
2203 size += sizeof(struct sockaddr_in6);
2210 SCTP_TCB_UNLOCK(stcb);
2211 *value = (uint32_t)size;
2212 *optsize = sizeof(uint32_t);
2214 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2219 case SCTP_GET_PEER_ADDRESSES:
2221 * Get the address information, an array is passed in to
2222 * fill up we pack it.
2226 struct sockaddr *addr;
2227 struct sctp_nets *net;
2228 struct sctp_getaddresses *saddr;
2230 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2231 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2234 left = *optsize - offsetof(struct sctp_getaddresses, addr);
2235 *optsize = offsetof(struct sctp_getaddresses, addr);
2236 addr = &saddr->addr[0].sa;
2238 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2239 switch (net->ro._l_addr.sa.sa_family) {
2243 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2244 cpsz = sizeof(struct sockaddr_in6);
2246 cpsz = sizeof(struct sockaddr_in);
2249 cpsz = sizeof(struct sockaddr_in);
2255 cpsz = sizeof(struct sockaddr_in6);
2266 /* not enough room. */
2269 #if defined(INET) && defined(INET6)
2270 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2271 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2272 /* Must map the address */
2273 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2274 (struct sockaddr_in6 *)addr);
2276 memcpy(addr, &net->ro._l_addr, cpsz);
2279 memcpy(addr, &net->ro._l_addr, cpsz);
2281 ((struct sockaddr_in *)addr)->sin_port = stcb->rport;
2283 addr = (struct sockaddr *)((caddr_t)addr + cpsz);
2287 SCTP_TCB_UNLOCK(stcb);
2289 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2294 case SCTP_GET_LOCAL_ADDRESSES:
2296 size_t limit, actual;
2297 struct sctp_getaddresses *saddr;
2299 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2300 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2302 limit = *optsize - offsetof(struct sctp_getaddresses, addr);
2303 actual = sctp_fill_up_addresses(inp, stcb, limit, &saddr->addr[0].sa);
2305 SCTP_TCB_UNLOCK(stcb);
2307 *optsize = offsetof(struct sctp_getaddresses, addr) + actual;
2310 case SCTP_PEER_ADDR_PARAMS:
2312 struct sctp_paddrparams *paddrp;
2313 struct sctp_nets *net;
2314 struct sockaddr *addr;
2315 #if defined(INET) && defined(INET6)
2316 struct sockaddr_in sin_store;
2319 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2320 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2322 #if defined(INET) && defined(INET6)
2323 if (paddrp->spp_address.ss_family == AF_INET6) {
2324 struct sockaddr_in6 *sin6;
2326 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2327 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2328 in6_sin6_2_sin(&sin_store, sin6);
2329 addr = (struct sockaddr *)&sin_store;
2331 addr = (struct sockaddr *)&paddrp->spp_address;
2334 addr = (struct sockaddr *)&paddrp->spp_address;
2337 addr = (struct sockaddr *)&paddrp->spp_address;
2340 net = sctp_findnet(stcb, addr);
2343 * We increment here since
2344 * sctp_findassociation_ep_addr() wil do a
2345 * decrement if it finds the stcb as long as
2346 * the locked tcb (last argument) is NOT a
2350 SCTP_INP_INCR_REF(inp);
2351 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2353 SCTP_INP_DECR_REF(inp);
2356 if ((stcb != NULL) && (net == NULL)) {
2358 if (addr->sa_family == AF_INET) {
2359 struct sockaddr_in *sin;
2361 sin = (struct sockaddr_in *)addr;
2362 if (sin->sin_addr.s_addr != INADDR_ANY) {
2364 SCTP_TCB_UNLOCK(stcb);
2365 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2371 if (addr->sa_family == AF_INET6) {
2372 struct sockaddr_in6 *sin6;
2374 sin6 = (struct sockaddr_in6 *)addr;
2375 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2377 SCTP_TCB_UNLOCK(stcb);
2378 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2384 error = EAFNOSUPPORT;
2385 SCTP_TCB_UNLOCK(stcb);
2386 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2392 /* Applies to the specific association */
2393 paddrp->spp_flags = 0;
2395 paddrp->spp_hbinterval = net->heart_beat_delay;
2396 paddrp->spp_pathmaxrxt = net->failure_threshold;
2397 paddrp->spp_pathmtu = net->mtu;
2398 switch (net->ro._l_addr.sa.sa_family) {
2401 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2406 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2412 /* get flags for HB */
2413 if (net->dest_state & SCTP_ADDR_NOHB) {
2414 paddrp->spp_flags |= SPP_HB_DISABLE;
2416 paddrp->spp_flags |= SPP_HB_ENABLE;
2418 /* get flags for PMTU */
2419 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2420 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2422 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2424 if (net->dscp & 0x01) {
2425 paddrp->spp_dscp = net->dscp & 0xfc;
2426 paddrp->spp_flags |= SPP_DSCP;
2429 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2430 (net->flowlabel & 0x80000000)) {
2431 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2432 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2437 * No destination so return default
2440 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2441 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2442 if (stcb->asoc.default_dscp & 0x01) {
2443 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2444 paddrp->spp_flags |= SPP_DSCP;
2447 if (stcb->asoc.default_flowlabel & 0x80000000) {
2448 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2449 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2452 /* default settings should be these */
2453 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2454 paddrp->spp_flags |= SPP_HB_DISABLE;
2456 paddrp->spp_flags |= SPP_HB_ENABLE;
2458 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2459 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2461 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2463 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2465 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2466 SCTP_TCB_UNLOCK(stcb);
2468 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2469 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2470 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2471 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
2472 /* Use endpoint defaults */
2473 SCTP_INP_RLOCK(inp);
2474 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2475 paddrp->spp_hbinterval = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2476 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2477 /* get inp's default */
2478 if (inp->sctp_ep.default_dscp & 0x01) {
2479 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2480 paddrp->spp_flags |= SPP_DSCP;
2483 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2484 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2485 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2486 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2489 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2491 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2492 paddrp->spp_flags |= SPP_HB_ENABLE;
2494 paddrp->spp_flags |= SPP_HB_DISABLE;
2496 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2497 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2499 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2501 SCTP_INP_RUNLOCK(inp);
2503 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2508 *optsize = sizeof(struct sctp_paddrparams);
2512 case SCTP_GET_PEER_ADDR_INFO:
2514 struct sctp_paddrinfo *paddri;
2515 struct sctp_nets *net;
2516 struct sockaddr *addr;
2517 #if defined(INET) && defined(INET6)
2518 struct sockaddr_in sin_store;
2521 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2522 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2524 #if defined(INET) && defined(INET6)
2525 if (paddri->spinfo_address.ss_family == AF_INET6) {
2526 struct sockaddr_in6 *sin6;
2528 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2529 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2530 in6_sin6_2_sin(&sin_store, sin6);
2531 addr = (struct sockaddr *)&sin_store;
2533 addr = (struct sockaddr *)&paddri->spinfo_address;
2536 addr = (struct sockaddr *)&paddri->spinfo_address;
2539 addr = (struct sockaddr *)&paddri->spinfo_address;
2542 net = sctp_findnet(stcb, addr);
2545 * We increment here since
2546 * sctp_findassociation_ep_addr() wil do a
2547 * decrement if it finds the stcb as long as
2548 * the locked tcb (last argument) is NOT a
2552 SCTP_INP_INCR_REF(inp);
2553 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2555 SCTP_INP_DECR_REF(inp);
2559 if ((stcb != NULL) && (net != NULL)) {
2560 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2561 /* It's unconfirmed */
2562 paddri->spinfo_state = SCTP_UNCONFIRMED;
2563 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2565 paddri->spinfo_state = SCTP_ACTIVE;
2568 paddri->spinfo_state = SCTP_INACTIVE;
2570 paddri->spinfo_cwnd = net->cwnd;
2571 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2572 paddri->spinfo_rto = net->RTO;
2573 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2574 paddri->spinfo_mtu = net->mtu;
2575 switch (addr->sa_family) {
2578 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2583 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2589 SCTP_TCB_UNLOCK(stcb);
2590 *optsize = sizeof(struct sctp_paddrinfo);
2593 SCTP_TCB_UNLOCK(stcb);
2595 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2600 case SCTP_PCB_STATUS:
2602 struct sctp_pcbinfo *spcb;
2604 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2605 sctp_fill_pcbinfo(spcb);
2606 *optsize = sizeof(struct sctp_pcbinfo);
2611 struct sctp_nets *net;
2612 struct sctp_status *sstat;
2614 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2615 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2618 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2622 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2623 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2624 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2625 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2627 * We can't include chunks that have been passed to
2628 * the socket layer. Only things in queue.
2630 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2631 stcb->asoc.cnt_on_all_streams);
2634 sstat->sstat_instrms = stcb->asoc.streamincnt;
2635 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2636 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2637 net = stcb->asoc.primary_destination;
2639 memcpy(&sstat->sstat_primary.spinfo_address,
2641 ((struct sockaddr *)(&net->ro._l_addr))->sa_len);
2642 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2644 * Again the user can get info from
2645 * sctp_constants.h for what the state of
2648 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2649 /* It's unconfirmed */
2650 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2651 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2653 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2656 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2658 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2659 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2660 sstat->sstat_primary.spinfo_rto = net->RTO;
2661 sstat->sstat_primary.spinfo_mtu = net->mtu;
2662 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2665 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2670 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2677 memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo));
2679 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2680 SCTP_TCB_UNLOCK(stcb);
2681 *optsize = sizeof(struct sctp_status);
2686 struct sctp_rtoinfo *srto;
2688 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2689 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2692 srto->srto_initial = stcb->asoc.initial_rto;
2693 srto->srto_max = stcb->asoc.maxrto;
2694 srto->srto_min = stcb->asoc.minrto;
2695 SCTP_TCB_UNLOCK(stcb);
2697 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2698 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2699 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2700 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
2701 SCTP_INP_RLOCK(inp);
2702 srto->srto_initial = inp->sctp_ep.initial_rto;
2703 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2704 srto->srto_min = inp->sctp_ep.sctp_minrto;
2705 SCTP_INP_RUNLOCK(inp);
2707 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2712 *optsize = sizeof(struct sctp_rtoinfo);
2718 struct sctp_timeouts *stimo;
2720 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2721 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2724 stimo->stimo_init = stcb->asoc.timoinit;
2725 stimo->stimo_data = stcb->asoc.timodata;
2726 stimo->stimo_sack = stcb->asoc.timosack;
2727 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2728 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2729 stimo->stimo_cookie = stcb->asoc.timocookie;
2730 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2731 SCTP_TCB_UNLOCK(stcb);
2732 *optsize = sizeof(struct sctp_timeouts);
2734 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2739 case SCTP_ASSOCINFO:
2741 struct sctp_assocparams *sasoc;
2743 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2744 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2747 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(stcb->asoc.cookie_life);
2748 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2749 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2750 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2751 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2752 SCTP_TCB_UNLOCK(stcb);
2754 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2755 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2756 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2757 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
2758 SCTP_INP_RLOCK(inp);
2759 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(inp->sctp_ep.def_cookie_life);
2760 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2761 sasoc->sasoc_number_peer_destinations = 0;
2762 sasoc->sasoc_peer_rwnd = 0;
2763 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2764 SCTP_INP_RUNLOCK(inp);
2766 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2771 *optsize = sizeof(struct sctp_assocparams);
2775 case SCTP_DEFAULT_SEND_PARAM:
2777 struct sctp_sndrcvinfo *s_info;
2779 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2780 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2783 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2784 SCTP_TCB_UNLOCK(stcb);
2786 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2787 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2788 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2789 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC))) {
2790 SCTP_INP_RLOCK(inp);
2791 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2792 SCTP_INP_RUNLOCK(inp);
2794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2799 *optsize = sizeof(struct sctp_sndrcvinfo);
2805 struct sctp_initmsg *sinit;
2807 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2808 SCTP_INP_RLOCK(inp);
2809 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2810 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2811 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2812 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2813 SCTP_INP_RUNLOCK(inp);
2814 *optsize = sizeof(struct sctp_initmsg);
2817 case SCTP_PRIMARY_ADDR:
2818 /* we allow a "get" operation on this */
2820 struct sctp_setprim *ssp;
2822 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2823 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2826 union sctp_sockstore *addr;
2828 addr = &stcb->asoc.primary_destination->ro._l_addr;
2829 switch (addr->sa.sa_family) {
2833 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2834 in6_sin_2_v4mapsin6(&addr->sin,
2835 (struct sockaddr_in6 *)&ssp->ssp_addr);
2837 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2840 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2846 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2852 SCTP_TCB_UNLOCK(stcb);
2853 *optsize = sizeof(struct sctp_setprim);
2855 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2860 case SCTP_HMAC_IDENT:
2862 struct sctp_hmacalgo *shmac;
2863 sctp_hmaclist_t *hmaclist;
2867 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2869 SCTP_INP_RLOCK(inp);
2870 hmaclist = inp->sctp_ep.local_hmacs;
2871 if (hmaclist == NULL) {
2872 /* no HMACs to return */
2873 *optsize = sizeof(*shmac);
2874 SCTP_INP_RUNLOCK(inp);
2877 /* is there room for all of the hmac ids? */
2878 size = sizeof(*shmac) + (hmaclist->num_algo *
2879 sizeof(shmac->shmac_idents[0]));
2880 if ((size_t)(*optsize) < size) {
2881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2883 SCTP_INP_RUNLOCK(inp);
2886 /* copy in the list */
2887 shmac->shmac_number_of_idents = hmaclist->num_algo;
2888 for (i = 0; i < hmaclist->num_algo; i++) {
2889 shmac->shmac_idents[i] = hmaclist->hmac[i];
2891 SCTP_INP_RUNLOCK(inp);
2895 case SCTP_AUTH_ACTIVE_KEY:
2897 struct sctp_authkeyid *scact;
2899 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2900 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2903 /* get the active key on the assoc */
2904 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2905 SCTP_TCB_UNLOCK(stcb);
2907 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2908 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2909 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2910 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC))) {
2911 /* get the endpoint active key */
2912 SCTP_INP_RLOCK(inp);
2913 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2914 SCTP_INP_RUNLOCK(inp);
2916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2921 *optsize = sizeof(struct sctp_authkeyid);
2925 case SCTP_LOCAL_AUTH_CHUNKS:
2927 struct sctp_authchunks *sac;
2928 sctp_auth_chklist_t *chklist = NULL;
2931 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2932 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2935 /* get off the assoc */
2936 chklist = stcb->asoc.local_auth_chunks;
2937 /* is there enough space? */
2938 size = sctp_auth_get_chklist_size(chklist);
2939 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2941 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2943 /* copy in the chunks */
2944 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2945 sac->gauth_number_of_chunks = (uint32_t)size;
2946 *optsize = sizeof(struct sctp_authchunks) + size;
2948 SCTP_TCB_UNLOCK(stcb);
2950 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2951 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2952 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2953 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC))) {
2954 /* get off the endpoint */
2955 SCTP_INP_RLOCK(inp);
2956 chklist = inp->sctp_ep.local_auth_chunks;
2957 /* is there enough space? */
2958 size = sctp_auth_get_chklist_size(chklist);
2959 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2961 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2963 /* copy in the chunks */
2964 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2965 sac->gauth_number_of_chunks = (uint32_t)size;
2966 *optsize = sizeof(struct sctp_authchunks) + size;
2968 SCTP_INP_RUNLOCK(inp);
2970 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2976 case SCTP_PEER_AUTH_CHUNKS:
2978 struct sctp_authchunks *sac;
2979 sctp_auth_chklist_t *chklist = NULL;
2982 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2983 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2986 /* get off the assoc */
2987 chklist = stcb->asoc.peer_auth_chunks;
2988 /* is there enough space? */
2989 size = sctp_auth_get_chklist_size(chklist);
2990 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2994 /* copy in the chunks */
2995 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2996 sac->gauth_number_of_chunks = (uint32_t)size;
2997 *optsize = sizeof(struct sctp_authchunks) + size;
2999 SCTP_TCB_UNLOCK(stcb);
3001 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3008 struct sctp_event *event;
3009 uint32_t event_type;
3011 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3012 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3014 switch (event->se_type) {
3015 case SCTP_ASSOC_CHANGE:
3016 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3018 case SCTP_PEER_ADDR_CHANGE:
3019 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3021 case SCTP_REMOTE_ERROR:
3022 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3024 case SCTP_SEND_FAILED:
3025 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3027 case SCTP_SHUTDOWN_EVENT:
3028 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3030 case SCTP_ADAPTATION_INDICATION:
3031 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3033 case SCTP_PARTIAL_DELIVERY_EVENT:
3034 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3036 case SCTP_AUTHENTICATION_EVENT:
3037 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3039 case SCTP_STREAM_RESET_EVENT:
3040 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3042 case SCTP_SENDER_DRY_EVENT:
3043 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3045 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3047 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3050 case SCTP_ASSOC_RESET_EVENT:
3051 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3053 case SCTP_STREAM_CHANGE_EVENT:
3054 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3056 case SCTP_SEND_FAILED_EVENT:
3057 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3061 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3065 if (event_type > 0) {
3067 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3069 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3070 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3071 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3072 (event->se_assoc_id == SCTP_FUTURE_ASSOC))) {
3073 SCTP_INP_RLOCK(inp);
3074 event->se_on = sctp_is_feature_on(inp, event_type);
3075 SCTP_INP_RUNLOCK(inp);
3077 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3083 SCTP_TCB_UNLOCK(stcb);
3086 *optsize = sizeof(struct sctp_event);
3090 case SCTP_RECVRCVINFO:
3094 if (*optsize < sizeof(int)) {
3095 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3098 SCTP_INP_RLOCK(inp);
3099 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3100 SCTP_INP_RUNLOCK(inp);
3103 /* return the option value */
3104 *(int *)optval = onoff;
3105 *optsize = sizeof(int);
3109 case SCTP_RECVNXTINFO:
3113 if (*optsize < sizeof(int)) {
3114 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3117 SCTP_INP_RLOCK(inp);
3118 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3119 SCTP_INP_RUNLOCK(inp);
3122 /* return the option value */
3123 *(int *)optval = onoff;
3124 *optsize = sizeof(int);
3128 case SCTP_DEFAULT_SNDINFO:
3130 struct sctp_sndinfo *info;
3132 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3133 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3136 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3137 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3138 info->snd_flags &= 0xfff0;
3139 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3140 info->snd_context = stcb->asoc.def_send.sinfo_context;
3141 SCTP_TCB_UNLOCK(stcb);
3143 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3144 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3145 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3146 (info->snd_assoc_id == SCTP_FUTURE_ASSOC))) {
3147 SCTP_INP_RLOCK(inp);
3148 info->snd_sid = inp->def_send.sinfo_stream;
3149 info->snd_flags = inp->def_send.sinfo_flags;
3150 info->snd_flags &= 0xfff0;
3151 info->snd_ppid = inp->def_send.sinfo_ppid;
3152 info->snd_context = inp->def_send.sinfo_context;
3153 SCTP_INP_RUNLOCK(inp);
3155 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3160 *optsize = sizeof(struct sctp_sndinfo);
3164 case SCTP_DEFAULT_PRINFO:
3166 struct sctp_default_prinfo *info;
3168 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3169 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3172 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3173 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3174 SCTP_TCB_UNLOCK(stcb);
3176 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3177 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3178 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3179 (info->pr_assoc_id == SCTP_FUTURE_ASSOC))) {
3180 SCTP_INP_RLOCK(inp);
3181 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3182 info->pr_value = inp->def_send.sinfo_timetolive;
3183 SCTP_INP_RUNLOCK(inp);
3185 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3190 *optsize = sizeof(struct sctp_default_prinfo);
3194 case SCTP_PEER_ADDR_THLDS:
3196 struct sctp_paddrthlds *thlds;
3197 struct sctp_nets *net;
3198 struct sockaddr *addr;
3199 #if defined(INET) && defined(INET6)
3200 struct sockaddr_in sin_store;
3203 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3204 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3206 #if defined(INET) && defined(INET6)
3207 if (thlds->spt_address.ss_family == AF_INET6) {
3208 struct sockaddr_in6 *sin6;
3210 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3211 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3212 in6_sin6_2_sin(&sin_store, sin6);
3213 addr = (struct sockaddr *)&sin_store;
3215 addr = (struct sockaddr *)&thlds->spt_address;
3218 addr = (struct sockaddr *)&thlds->spt_address;
3221 addr = (struct sockaddr *)&thlds->spt_address;
3224 net = sctp_findnet(stcb, addr);
3227 * We increment here since
3228 * sctp_findassociation_ep_addr() wil do a
3229 * decrement if it finds the stcb as long as
3230 * the locked tcb (last argument) is NOT a
3234 SCTP_INP_INCR_REF(inp);
3235 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3237 SCTP_INP_DECR_REF(inp);
3240 if ((stcb != NULL) && (net == NULL)) {
3242 if (addr->sa_family == AF_INET) {
3243 struct sockaddr_in *sin;
3245 sin = (struct sockaddr_in *)addr;
3246 if (sin->sin_addr.s_addr != INADDR_ANY) {
3248 SCTP_TCB_UNLOCK(stcb);
3249 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3255 if (addr->sa_family == AF_INET6) {
3256 struct sockaddr_in6 *sin6;
3258 sin6 = (struct sockaddr_in6 *)addr;
3259 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3261 SCTP_TCB_UNLOCK(stcb);
3262 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3268 error = EAFNOSUPPORT;
3269 SCTP_TCB_UNLOCK(stcb);
3270 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3277 thlds->spt_pathmaxrxt = net->failure_threshold;
3278 thlds->spt_pathpfthld = net->pf_threshold;
3279 thlds->spt_pathcpthld = 0xffff;
3281 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3282 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3283 thlds->spt_pathcpthld = 0xffff;
3285 thlds->spt_assoc_id = sctp_get_associd(stcb);
3286 SCTP_TCB_UNLOCK(stcb);
3288 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3289 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3290 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3291 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
3292 /* Use endpoint defaults */
3293 SCTP_INP_RLOCK(inp);
3294 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3295 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3296 thlds->spt_pathcpthld = 0xffff;
3297 SCTP_INP_RUNLOCK(inp);
3299 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3304 *optsize = sizeof(struct sctp_paddrthlds);
3308 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3310 struct sctp_udpencaps *encaps;
3311 struct sctp_nets *net;
3312 struct sockaddr *addr;
3313 #if defined(INET) && defined(INET6)
3314 struct sockaddr_in sin_store;
3317 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3318 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3320 #if defined(INET) && defined(INET6)
3321 if (encaps->sue_address.ss_family == AF_INET6) {
3322 struct sockaddr_in6 *sin6;
3324 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3325 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3326 in6_sin6_2_sin(&sin_store, sin6);
3327 addr = (struct sockaddr *)&sin_store;
3329 addr = (struct sockaddr *)&encaps->sue_address;
3332 addr = (struct sockaddr *)&encaps->sue_address;
3335 addr = (struct sockaddr *)&encaps->sue_address;
3338 net = sctp_findnet(stcb, addr);
3341 * We increment here since
3342 * sctp_findassociation_ep_addr() wil do a
3343 * decrement if it finds the stcb as long as
3344 * the locked tcb (last argument) is NOT a
3348 SCTP_INP_INCR_REF(inp);
3349 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3351 SCTP_INP_DECR_REF(inp);
3354 if ((stcb != NULL) && (net == NULL)) {
3356 if (addr->sa_family == AF_INET) {
3357 struct sockaddr_in *sin;
3359 sin = (struct sockaddr_in *)addr;
3360 if (sin->sin_addr.s_addr != INADDR_ANY) {
3362 SCTP_TCB_UNLOCK(stcb);
3363 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3369 if (addr->sa_family == AF_INET6) {
3370 struct sockaddr_in6 *sin6;
3372 sin6 = (struct sockaddr_in6 *)addr;
3373 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3375 SCTP_TCB_UNLOCK(stcb);
3376 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3382 error = EAFNOSUPPORT;
3383 SCTP_TCB_UNLOCK(stcb);
3384 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3391 encaps->sue_port = net->port;
3393 encaps->sue_port = stcb->asoc.port;
3395 SCTP_TCB_UNLOCK(stcb);
3397 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3398 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3399 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3400 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
3401 SCTP_INP_RLOCK(inp);
3402 encaps->sue_port = inp->sctp_ep.port;
3403 SCTP_INP_RUNLOCK(inp);
3405 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3410 *optsize = sizeof(struct sctp_udpencaps);
3414 case SCTP_ECN_SUPPORTED:
3416 struct sctp_assoc_value *av;
3418 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3419 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3422 av->assoc_value = stcb->asoc.ecn_supported;
3423 SCTP_TCB_UNLOCK(stcb);
3425 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3426 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3427 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3428 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3429 SCTP_INP_RLOCK(inp);
3430 av->assoc_value = inp->ecn_supported;
3431 SCTP_INP_RUNLOCK(inp);
3433 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3438 *optsize = sizeof(struct sctp_assoc_value);
3442 case SCTP_PR_SUPPORTED:
3444 struct sctp_assoc_value *av;
3446 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3447 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3450 av->assoc_value = stcb->asoc.prsctp_supported;
3451 SCTP_TCB_UNLOCK(stcb);
3453 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3454 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3455 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3456 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3457 SCTP_INP_RLOCK(inp);
3458 av->assoc_value = inp->prsctp_supported;
3459 SCTP_INP_RUNLOCK(inp);
3461 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3466 *optsize = sizeof(struct sctp_assoc_value);
3470 case SCTP_AUTH_SUPPORTED:
3472 struct sctp_assoc_value *av;
3474 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3475 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3478 av->assoc_value = stcb->asoc.auth_supported;
3479 SCTP_TCB_UNLOCK(stcb);
3481 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3482 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3483 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3484 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3485 SCTP_INP_RLOCK(inp);
3486 av->assoc_value = inp->auth_supported;
3487 SCTP_INP_RUNLOCK(inp);
3489 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3494 *optsize = sizeof(struct sctp_assoc_value);
3498 case SCTP_ASCONF_SUPPORTED:
3500 struct sctp_assoc_value *av;
3502 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3503 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3506 av->assoc_value = stcb->asoc.asconf_supported;
3507 SCTP_TCB_UNLOCK(stcb);
3509 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3510 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3511 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3512 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3513 SCTP_INP_RLOCK(inp);
3514 av->assoc_value = inp->asconf_supported;
3515 SCTP_INP_RUNLOCK(inp);
3517 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3522 *optsize = sizeof(struct sctp_assoc_value);
3526 case SCTP_RECONFIG_SUPPORTED:
3528 struct sctp_assoc_value *av;
3530 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3531 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3534 av->assoc_value = stcb->asoc.reconfig_supported;
3535 SCTP_TCB_UNLOCK(stcb);
3537 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3538 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3539 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3540 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3541 SCTP_INP_RLOCK(inp);
3542 av->assoc_value = inp->reconfig_supported;
3543 SCTP_INP_RUNLOCK(inp);
3545 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3550 *optsize = sizeof(struct sctp_assoc_value);
3554 case SCTP_NRSACK_SUPPORTED:
3556 struct sctp_assoc_value *av;
3558 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3559 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3562 av->assoc_value = stcb->asoc.nrsack_supported;
3563 SCTP_TCB_UNLOCK(stcb);
3565 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3566 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3567 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3568 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3569 SCTP_INP_RLOCK(inp);
3570 av->assoc_value = inp->nrsack_supported;
3571 SCTP_INP_RUNLOCK(inp);
3573 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3578 *optsize = sizeof(struct sctp_assoc_value);
3582 case SCTP_PKTDROP_SUPPORTED:
3584 struct sctp_assoc_value *av;
3586 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3587 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3590 av->assoc_value = stcb->asoc.pktdrop_supported;
3591 SCTP_TCB_UNLOCK(stcb);
3593 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3594 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3595 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3596 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3597 SCTP_INP_RLOCK(inp);
3598 av->assoc_value = inp->pktdrop_supported;
3599 SCTP_INP_RUNLOCK(inp);
3601 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3606 *optsize = sizeof(struct sctp_assoc_value);
3610 case SCTP_ENABLE_STREAM_RESET:
3612 struct sctp_assoc_value *av;
3614 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3615 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3618 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3619 SCTP_TCB_UNLOCK(stcb);
3621 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3622 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3623 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3624 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3625 SCTP_INP_RLOCK(inp);
3626 av->assoc_value = (uint32_t)inp->local_strreset_support;
3627 SCTP_INP_RUNLOCK(inp);
3629 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3634 *optsize = sizeof(struct sctp_assoc_value);
3638 case SCTP_PR_STREAM_STATUS:
3640 struct sctp_prstatus *sprstat;
3644 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3645 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3647 sid = sprstat->sprstat_sid;
3648 policy = sprstat->sprstat_policy;
3649 #if defined(SCTP_DETAILED_STR_STATS)
3650 if ((stcb != NULL) &&
3651 (sid < stcb->asoc.streamoutcnt) &&
3652 (policy != SCTP_PR_SCTP_NONE) &&
3653 ((policy <= SCTP_PR_SCTP_MAX) ||
3654 (policy == SCTP_PR_SCTP_ALL))) {
3655 if (policy == SCTP_PR_SCTP_ALL) {
3656 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3657 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3659 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3660 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3663 if ((stcb != NULL) &&
3664 (sid < stcb->asoc.streamoutcnt) &&
3665 (policy == SCTP_PR_SCTP_ALL)) {
3666 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3667 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3670 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3674 SCTP_TCB_UNLOCK(stcb);
3677 *optsize = sizeof(struct sctp_prstatus);
3681 case SCTP_PR_ASSOC_STATUS:
3683 struct sctp_prstatus *sprstat;
3686 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3687 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3689 policy = sprstat->sprstat_policy;
3690 if ((stcb != NULL) &&
3691 (policy != SCTP_PR_SCTP_NONE) &&
3692 ((policy <= SCTP_PR_SCTP_MAX) ||
3693 (policy == SCTP_PR_SCTP_ALL))) {
3694 if (policy == SCTP_PR_SCTP_ALL) {
3695 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3696 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3698 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3699 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3702 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3706 SCTP_TCB_UNLOCK(stcb);
3709 *optsize = sizeof(struct sctp_prstatus);
3715 struct sctp_assoc_value *av;
3717 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3718 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3721 av->assoc_value = stcb->asoc.max_cwnd;
3722 SCTP_TCB_UNLOCK(stcb);
3724 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3725 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3726 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3727 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3728 SCTP_INP_RLOCK(inp);
3729 av->assoc_value = inp->max_cwnd;
3730 SCTP_INP_RUNLOCK(inp);
3732 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3737 *optsize = sizeof(struct sctp_assoc_value);
3742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3743 error = ENOPROTOOPT;
3745 } /* end switch (sopt->sopt_name) */
3753 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3758 struct sctp_tcb *stcb = NULL;
3759 struct sctp_inpcb *inp = NULL;
3762 if (optval == NULL) {
3763 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3766 inp = (struct sctp_inpcb *)so->so_pcb;
3768 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3771 vrf_id = inp->def_vrf_id;
3776 case SCTP_AUTOCLOSE:
3777 case SCTP_AUTO_ASCONF:
3778 case SCTP_EXPLICIT_EOR:
3779 case SCTP_DISABLE_FRAGMENTS:
3780 case SCTP_USE_EXT_RCVINFO:
3781 case SCTP_I_WANT_MAPPED_V4_ADDR:
3782 /* copy in the option value */
3783 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3788 case SCTP_DISABLE_FRAGMENTS:
3789 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3791 case SCTP_AUTO_ASCONF:
3793 * NOTE: we don't really support this flag
3795 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3796 /* only valid for bound all sockets */
3797 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3799 /* forbidden by admin */
3800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3803 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3805 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3809 case SCTP_EXPLICIT_EOR:
3810 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3812 case SCTP_USE_EXT_RCVINFO:
3813 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3815 case SCTP_I_WANT_MAPPED_V4_ADDR:
3816 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3817 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3819 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3824 set_opt = SCTP_PCB_FLAGS_NODELAY;
3826 case SCTP_AUTOCLOSE:
3827 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3828 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3829 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3832 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3834 * The value is in ticks. Note this does not effect
3835 * old associations, only new ones.
3837 inp->sctp_ep.auto_close_time = sctp_secs_to_ticks(*mopt);
3840 SCTP_INP_WLOCK(inp);
3842 sctp_feature_on(inp, set_opt);
3844 sctp_feature_off(inp, set_opt);
3846 SCTP_INP_WUNLOCK(inp);
3848 case SCTP_REUSE_PORT:
3850 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3851 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3852 /* Can't set it after we are bound */
3856 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3857 /* Can't do this for a 1-m socket */
3862 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3864 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3867 case SCTP_PARTIAL_DELIVERY_POINT:
3871 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3872 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3877 inp->partial_delivery_point = *value;
3880 case SCTP_FRAGMENT_INTERLEAVE:
3881 /* not yet until we re-write sctp_recvmsg() */
3885 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3886 if (*level == SCTP_FRAG_LEVEL_2) {
3887 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3888 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3889 } else if (*level == SCTP_FRAG_LEVEL_1) {
3890 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3891 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3892 } else if (*level == SCTP_FRAG_LEVEL_0) {
3893 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3894 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3902 case SCTP_INTERLEAVING_SUPPORTED:
3904 struct sctp_assoc_value *av;
3906 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3907 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3912 SCTP_TCB_UNLOCK(stcb);
3914 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3915 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3916 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3917 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3918 SCTP_INP_WLOCK(inp);
3919 if (av->assoc_value == 0) {
3920 inp->idata_supported = 0;
3922 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3923 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3924 inp->idata_supported = 1;
3932 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3936 SCTP_INP_WUNLOCK(inp);
3938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3944 case SCTP_CMT_ON_OFF:
3945 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3946 struct sctp_assoc_value *av;
3948 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3949 if (av->assoc_value > SCTP_CMT_MAX) {
3950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3954 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3956 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3957 SCTP_TCB_UNLOCK(stcb);
3959 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3960 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3961 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3962 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3963 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3964 SCTP_INP_WLOCK(inp);
3965 inp->sctp_cmt_on_off = av->assoc_value;
3966 SCTP_INP_WUNLOCK(inp);
3968 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3969 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3970 (av->assoc_id == SCTP_ALL_ASSOC))) {
3971 SCTP_INP_RLOCK(inp);
3972 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3973 SCTP_TCB_LOCK(stcb);
3974 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3975 SCTP_TCB_UNLOCK(stcb);
3977 SCTP_INP_RUNLOCK(inp);
3981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3982 error = ENOPROTOOPT;
3985 case SCTP_PLUGGABLE_CC:
3987 struct sctp_assoc_value *av;
3988 struct sctp_nets *net;
3990 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3991 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3992 (av->assoc_value != SCTP_CC_HSTCP) &&
3993 (av->assoc_value != SCTP_CC_HTCP) &&
3994 (av->assoc_value != SCTP_CC_RTCC)) {
3995 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3999 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4001 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4002 stcb->asoc.congestion_control_module = av->assoc_value;
4003 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4004 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4005 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4008 SCTP_TCB_UNLOCK(stcb);
4010 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4011 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4012 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4013 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4014 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4015 SCTP_INP_WLOCK(inp);
4016 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
4017 SCTP_INP_WUNLOCK(inp);
4019 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4020 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4021 (av->assoc_id == SCTP_ALL_ASSOC))) {
4022 SCTP_INP_RLOCK(inp);
4023 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4024 SCTP_TCB_LOCK(stcb);
4025 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4026 stcb->asoc.congestion_control_module = av->assoc_value;
4027 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4028 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4029 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4032 SCTP_TCB_UNLOCK(stcb);
4034 SCTP_INP_RUNLOCK(inp);
4039 case SCTP_CC_OPTION:
4041 struct sctp_cc_option *cc_opt;
4043 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4044 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4046 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4047 (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC)) {
4048 SCTP_INP_RLOCK(inp);
4049 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4050 SCTP_TCB_LOCK(stcb);
4051 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4052 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4054 SCTP_TCB_UNLOCK(stcb);
4056 SCTP_INP_RUNLOCK(inp);
4061 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4064 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4067 SCTP_TCB_UNLOCK(stcb);
4071 case SCTP_PLUGGABLE_SS:
4073 struct sctp_assoc_value *av;
4075 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4076 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4077 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4078 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4079 (av->assoc_value != SCTP_SS_PRIORITY) &&
4080 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4081 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4082 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4086 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4088 SCTP_TCB_SEND_LOCK(stcb);
4089 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4090 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4091 stcb->asoc.stream_scheduling_module = av->assoc_value;
4092 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4093 SCTP_TCB_SEND_UNLOCK(stcb);
4094 SCTP_TCB_UNLOCK(stcb);
4096 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4097 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4098 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4099 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4100 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4101 SCTP_INP_WLOCK(inp);
4102 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4103 SCTP_INP_WUNLOCK(inp);
4105 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4106 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4107 (av->assoc_id == SCTP_ALL_ASSOC))) {
4108 SCTP_INP_RLOCK(inp);
4109 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4110 SCTP_TCB_LOCK(stcb);
4111 SCTP_TCB_SEND_LOCK(stcb);
4112 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4113 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4114 stcb->asoc.stream_scheduling_module = av->assoc_value;
4115 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4116 SCTP_TCB_SEND_UNLOCK(stcb);
4117 SCTP_TCB_UNLOCK(stcb);
4119 SCTP_INP_RUNLOCK(inp);
4126 struct sctp_stream_value *av;
4128 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4129 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4131 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4132 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4133 av->stream_value) < 0)) {
4134 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4137 SCTP_TCB_UNLOCK(stcb);
4139 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4140 (av->assoc_id == SCTP_CURRENT_ASSOC)) {
4141 SCTP_INP_RLOCK(inp);
4142 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4143 SCTP_TCB_LOCK(stcb);
4144 if (av->stream_id < stcb->asoc.streamoutcnt) {
4145 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4147 &stcb->asoc.strmout[av->stream_id],
4150 SCTP_TCB_UNLOCK(stcb);
4152 SCTP_INP_RUNLOCK(inp);
4155 * Can't set stream value without
4158 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4164 case SCTP_CLR_STAT_LOG:
4165 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4170 struct sctp_assoc_value *av;
4172 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4173 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4176 stcb->asoc.context = av->assoc_value;
4177 SCTP_TCB_UNLOCK(stcb);
4179 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4180 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4181 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4182 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4183 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4184 SCTP_INP_WLOCK(inp);
4185 inp->sctp_context = av->assoc_value;
4186 SCTP_INP_WUNLOCK(inp);
4188 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4189 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4190 (av->assoc_id == SCTP_ALL_ASSOC))) {
4191 SCTP_INP_RLOCK(inp);
4192 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4193 SCTP_TCB_LOCK(stcb);
4194 stcb->asoc.context = av->assoc_value;
4195 SCTP_TCB_UNLOCK(stcb);
4197 SCTP_INP_RUNLOCK(inp);
4204 uint32_t *default_vrfid;
4206 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4207 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4208 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4212 inp->def_vrf_id = *default_vrfid;
4215 case SCTP_DEL_VRF_ID:
4217 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4221 case SCTP_ADD_VRF_ID:
4223 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4227 case SCTP_DELAYED_SACK:
4229 struct sctp_sack_info *sack;
4231 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4232 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4233 if (sack->sack_delay) {
4234 if (sack->sack_delay > SCTP_MAX_SACK_DELAY) {
4237 SCTP_TCB_UNLOCK(stcb);
4243 if (sack->sack_delay) {
4244 stcb->asoc.delayed_ack = sack->sack_delay;
4246 if (sack->sack_freq) {
4247 stcb->asoc.sack_freq = sack->sack_freq;
4249 SCTP_TCB_UNLOCK(stcb);
4251 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4252 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4253 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4254 ((sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4255 (sack->sack_assoc_id == SCTP_ALL_ASSOC)))) {
4256 SCTP_INP_WLOCK(inp);
4257 if (sack->sack_delay) {
4258 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = sctp_msecs_to_ticks(sack->sack_delay);
4260 if (sack->sack_freq) {
4261 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4263 SCTP_INP_WUNLOCK(inp);
4265 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4266 ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4267 (sack->sack_assoc_id == SCTP_ALL_ASSOC))) {
4268 SCTP_INP_RLOCK(inp);
4269 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4270 SCTP_TCB_LOCK(stcb);
4271 if (sack->sack_delay) {
4272 stcb->asoc.delayed_ack = sack->sack_delay;
4274 if (sack->sack_freq) {
4275 stcb->asoc.sack_freq = sack->sack_freq;
4277 SCTP_TCB_UNLOCK(stcb);
4279 SCTP_INP_RUNLOCK(inp);
4284 case SCTP_AUTH_CHUNK:
4286 struct sctp_authchunk *sauth;
4288 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4290 SCTP_INP_WLOCK(inp);
4291 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4292 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4295 inp->auth_supported = 1;
4297 SCTP_INP_WUNLOCK(inp);
4302 struct sctp_authkey *sca;
4303 struct sctp_keyhead *shared_keys;
4304 sctp_sharedkey_t *shared_key;
4305 sctp_key_t *key = NULL;
4308 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4309 if (sca->sca_keylength == 0) {
4310 size = optsize - sizeof(struct sctp_authkey);
4312 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4313 size = sca->sca_keylength;
4315 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4320 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4323 shared_keys = &stcb->asoc.shared_keys;
4324 /* clear the cached keys for this key id */
4325 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4327 * create the new shared key and
4331 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4333 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4335 SCTP_TCB_UNLOCK(stcb);
4339 shared_key = sctp_alloc_sharedkey();
4340 if (shared_key == NULL) {
4342 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4344 SCTP_TCB_UNLOCK(stcb);
4347 shared_key->key = key;
4348 shared_key->keyid = sca->sca_keynumber;
4349 error = sctp_insert_sharedkey(shared_keys, shared_key);
4350 SCTP_TCB_UNLOCK(stcb);
4352 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4353 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4354 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4355 ((sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4356 (sca->sca_assoc_id == SCTP_ALL_ASSOC)))) {
4357 SCTP_INP_WLOCK(inp);
4358 shared_keys = &inp->sctp_ep.shared_keys;
4360 * clear the cached keys on all
4361 * assocs for this key id
4363 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4365 * create the new shared key and
4369 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4371 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4373 SCTP_INP_WUNLOCK(inp);
4377 shared_key = sctp_alloc_sharedkey();
4378 if (shared_key == NULL) {
4380 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4382 SCTP_INP_WUNLOCK(inp);
4385 shared_key->key = key;
4386 shared_key->keyid = sca->sca_keynumber;
4387 error = sctp_insert_sharedkey(shared_keys, shared_key);
4388 SCTP_INP_WUNLOCK(inp);
4390 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4391 ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4392 (sca->sca_assoc_id == SCTP_ALL_ASSOC))) {
4393 SCTP_INP_RLOCK(inp);
4394 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4395 SCTP_TCB_LOCK(stcb);
4396 shared_keys = &stcb->asoc.shared_keys;
4398 * clear the cached keys for
4401 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4403 * create the new shared key
4404 * and insert/replace it
4407 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4409 SCTP_TCB_UNLOCK(stcb);
4413 shared_key = sctp_alloc_sharedkey();
4414 if (shared_key == NULL) {
4416 SCTP_TCB_UNLOCK(stcb);
4419 shared_key->key = key;
4420 shared_key->keyid = sca->sca_keynumber;
4421 error = sctp_insert_sharedkey(shared_keys, shared_key);
4422 SCTP_TCB_UNLOCK(stcb);
4424 SCTP_INP_RUNLOCK(inp);
4429 case SCTP_HMAC_IDENT:
4431 struct sctp_hmacalgo *shmac;
4432 sctp_hmaclist_t *hmaclist;
4436 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4437 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4438 (shmac->shmac_number_of_idents > 0xffff)) {
4439 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4444 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4445 if (hmaclist == NULL) {
4446 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4450 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4451 hmacid = shmac->shmac_idents[i];
4452 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4453 /* invalid HMACs were found */ ;
4454 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4456 sctp_free_hmaclist(hmaclist);
4457 goto sctp_set_hmac_done;
4460 for (i = 0; i < hmaclist->num_algo; i++) {
4461 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4462 /* already in list */
4466 if (i == hmaclist->num_algo) {
4467 /* not found in list */
4468 sctp_free_hmaclist(hmaclist);
4469 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4473 /* set it on the endpoint */
4474 SCTP_INP_WLOCK(inp);
4475 if (inp->sctp_ep.local_hmacs)
4476 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4477 inp->sctp_ep.local_hmacs = hmaclist;
4478 SCTP_INP_WUNLOCK(inp);
4482 case SCTP_AUTH_ACTIVE_KEY:
4484 struct sctp_authkeyid *scact;
4486 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4487 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4489 /* set the active key on the right place */
4491 /* set the active key on the assoc */
4492 if (sctp_auth_setactivekey(stcb,
4493 scact->scact_keynumber)) {
4494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4495 SCTP_FROM_SCTP_USRREQ,
4499 SCTP_TCB_UNLOCK(stcb);
4501 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4502 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4503 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4504 ((scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4505 (scact->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4506 SCTP_INP_WLOCK(inp);
4507 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4508 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4511 SCTP_INP_WUNLOCK(inp);
4513 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4514 ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4515 (scact->scact_assoc_id == SCTP_ALL_ASSOC))) {
4516 SCTP_INP_RLOCK(inp);
4517 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4518 SCTP_TCB_LOCK(stcb);
4519 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4520 SCTP_TCB_UNLOCK(stcb);
4522 SCTP_INP_RUNLOCK(inp);
4527 case SCTP_AUTH_DELETE_KEY:
4529 struct sctp_authkeyid *scdel;
4531 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4532 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4534 /* delete the key from the right place */
4536 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4537 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4540 SCTP_TCB_UNLOCK(stcb);
4542 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4543 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4544 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4545 ((scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4546 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4547 SCTP_INP_WLOCK(inp);
4548 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4549 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4552 SCTP_INP_WUNLOCK(inp);
4554 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4555 ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4556 (scdel->scact_assoc_id == SCTP_ALL_ASSOC))) {
4557 SCTP_INP_RLOCK(inp);
4558 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4559 SCTP_TCB_LOCK(stcb);
4560 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4561 SCTP_TCB_UNLOCK(stcb);
4563 SCTP_INP_RUNLOCK(inp);
4568 case SCTP_AUTH_DEACTIVATE_KEY:
4570 struct sctp_authkeyid *keyid;
4572 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4573 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4575 /* deactivate the key from the right place */
4577 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4578 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4581 SCTP_TCB_UNLOCK(stcb);
4583 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4584 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4585 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4586 ((keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4587 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4588 SCTP_INP_WLOCK(inp);
4589 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4590 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4593 SCTP_INP_WUNLOCK(inp);
4595 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4596 ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4597 (keyid->scact_assoc_id == SCTP_ALL_ASSOC))) {
4598 SCTP_INP_RLOCK(inp);
4599 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4600 SCTP_TCB_LOCK(stcb);
4601 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4602 SCTP_TCB_UNLOCK(stcb);
4604 SCTP_INP_RUNLOCK(inp);
4609 case SCTP_ENABLE_STREAM_RESET:
4611 struct sctp_assoc_value *av;
4613 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4614 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4615 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4619 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4621 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4622 SCTP_TCB_UNLOCK(stcb);
4624 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4625 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4626 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4627 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4628 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4629 SCTP_INP_WLOCK(inp);
4630 inp->local_strreset_support = (uint8_t)av->assoc_value;
4631 SCTP_INP_WUNLOCK(inp);
4633 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4634 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4635 (av->assoc_id == SCTP_ALL_ASSOC))) {
4636 SCTP_INP_RLOCK(inp);
4637 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4638 SCTP_TCB_LOCK(stcb);
4639 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4640 SCTP_TCB_UNLOCK(stcb);
4642 SCTP_INP_RUNLOCK(inp);
4648 case SCTP_RESET_STREAMS:
4650 struct sctp_reset_streams *strrst;
4651 int i, send_out = 0;
4654 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4655 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4657 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4661 if (stcb->asoc.reconfig_supported == 0) {
4663 * Peer does not support the chunk type.
4665 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4667 SCTP_TCB_UNLOCK(stcb);
4670 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4671 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4673 SCTP_TCB_UNLOCK(stcb);
4676 if (sizeof(struct sctp_reset_streams) +
4677 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4679 SCTP_TCB_UNLOCK(stcb);
4682 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4684 if (stcb->asoc.stream_reset_outstanding) {
4685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4687 SCTP_TCB_UNLOCK(stcb);
4691 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4694 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4695 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4697 SCTP_TCB_UNLOCK(stcb);
4700 if ((send_in == 0) && (send_out == 0)) {
4701 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4703 SCTP_TCB_UNLOCK(stcb);
4706 for (i = 0; i < strrst->srs_number_streams; i++) {
4708 (strrst->srs_stream_list[i] >= stcb->asoc.streamincnt)) {
4709 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4714 (strrst->srs_stream_list[i] >= stcb->asoc.streamoutcnt)) {
4715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4721 SCTP_TCB_UNLOCK(stcb);
4728 if (strrst->srs_number_streams) {
4729 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4730 strm = strrst->srs_stream_list[i];
4731 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4732 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4738 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4739 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4740 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4747 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4748 strrst->srs_stream_list,
4749 send_in, 0, 0, 0, 0, 0);
4751 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4754 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4757 * For outgoing streams don't report any
4758 * problems in sending the request to the
4759 * application. XXX: Double check resetting
4764 SCTP_TCB_UNLOCK(stcb);
4767 case SCTP_ADD_STREAMS:
4769 struct sctp_add_streams *stradd;
4770 uint8_t addstream = 0;
4771 uint16_t add_o_strmcnt = 0;
4772 uint16_t add_i_strmcnt = 0;
4774 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4775 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4777 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4781 if (stcb->asoc.reconfig_supported == 0) {
4783 * Peer does not support the chunk type.
4785 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4787 SCTP_TCB_UNLOCK(stcb);
4790 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4791 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4793 SCTP_TCB_UNLOCK(stcb);
4796 if (stcb->asoc.stream_reset_outstanding) {
4797 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4799 SCTP_TCB_UNLOCK(stcb);
4802 if ((stradd->sas_outstrms == 0) &&
4803 (stradd->sas_instrms == 0)) {
4807 if (stradd->sas_outstrms) {
4809 /* We allocate here */
4810 add_o_strmcnt = stradd->sas_outstrms;
4811 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4812 /* You can't have more than 64k */
4817 if (stradd->sas_instrms) {
4822 * We allocate inside
4823 * sctp_send_str_reset_req()
4825 add_i_strmcnt = stradd->sas_instrms;
4826 cnt = add_i_strmcnt;
4827 cnt += stcb->asoc.streamincnt;
4828 if (cnt > 0x0000ffff) {
4829 /* You can't have more than 64k */
4833 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4834 /* More than you are allowed */
4839 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4840 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4842 SCTP_TCB_UNLOCK(stcb);
4845 case SCTP_RESET_ASSOC:
4850 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4851 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4853 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4857 if (stcb->asoc.reconfig_supported == 0) {
4859 * Peer does not support the chunk type.
4861 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4863 SCTP_TCB_UNLOCK(stcb);
4866 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4867 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4869 SCTP_TCB_UNLOCK(stcb);
4872 if (stcb->asoc.stream_reset_outstanding) {
4873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4875 SCTP_TCB_UNLOCK(stcb);
4879 * Is there any data pending in the send or sent
4882 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4883 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4886 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4887 SCTP_TCB_UNLOCK(stcb);
4890 /* Do any streams have data queued? */
4891 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4892 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4896 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4897 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4898 SCTP_TCB_UNLOCK(stcb);
4901 case SCTP_CONNECT_X:
4902 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4907 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4909 case SCTP_CONNECT_X_DELAYED:
4910 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4911 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4915 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4917 case SCTP_CONNECT_X_COMPLETE:
4919 struct sockaddr *sa;
4921 /* FIXME MT: check correct? */
4922 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4925 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4926 SCTP_INP_RLOCK(inp);
4927 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4929 SCTP_TCB_LOCK(stcb);
4931 SCTP_INP_RUNLOCK(inp);
4934 * We increment here since
4935 * sctp_findassociation_ep_addr() wil do a
4936 * decrement if it finds the stcb as long as
4937 * the locked tcb (last argument) is NOT a
4940 SCTP_INP_INCR_REF(inp);
4941 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4943 SCTP_INP_DECR_REF(inp);
4948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4952 if (stcb->asoc.delayed_connection == 1) {
4953 stcb->asoc.delayed_connection = 0;
4954 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4955 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4956 stcb->asoc.primary_destination,
4957 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4958 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4961 * already expired or did not use delayed
4964 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4967 SCTP_TCB_UNLOCK(stcb);
4970 case SCTP_MAX_BURST:
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.max_burst = 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 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4986 SCTP_INP_WLOCK(inp);
4987 inp->sctp_ep.max_burst = av->assoc_value;
4988 SCTP_INP_WUNLOCK(inp);
4990 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4991 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4992 (av->assoc_id == SCTP_ALL_ASSOC))) {
4993 SCTP_INP_RLOCK(inp);
4994 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4995 SCTP_TCB_LOCK(stcb);
4996 stcb->asoc.max_burst = av->assoc_value;
4997 SCTP_TCB_UNLOCK(stcb);
4999 SCTP_INP_RUNLOCK(inp);
5006 struct sctp_assoc_value *av;
5009 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
5010 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
5012 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5013 ovh = SCTP_MED_OVERHEAD;
5015 ovh = SCTP_MED_V4_OVERHEAD;
5018 if (av->assoc_value) {
5019 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
5021 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
5023 SCTP_TCB_UNLOCK(stcb);
5025 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5026 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5027 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5028 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
5029 SCTP_INP_WLOCK(inp);
5031 * FIXME MT: I think this is not in
5032 * tune with the API ID
5034 if (av->assoc_value) {
5035 inp->sctp_frag_point = (av->assoc_value + ovh);
5037 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
5039 SCTP_INP_WUNLOCK(inp);
5041 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5049 struct sctp_event_subscribe *events;
5051 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5053 SCTP_INP_WLOCK(inp);
5054 if (events->sctp_data_io_event) {
5055 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5057 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5060 if (events->sctp_association_event) {
5061 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5063 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5066 if (events->sctp_address_event) {
5067 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5069 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5072 if (events->sctp_send_failure_event) {
5073 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5075 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5078 if (events->sctp_peer_error_event) {
5079 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5081 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5084 if (events->sctp_shutdown_event) {
5085 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5087 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5090 if (events->sctp_partial_delivery_event) {
5091 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5093 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5096 if (events->sctp_adaptation_layer_event) {
5097 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5099 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5102 if (events->sctp_authentication_event) {
5103 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5105 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5108 if (events->sctp_sender_dry_event) {
5109 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5111 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5114 if (events->sctp_stream_reset_event) {
5115 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5117 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5119 SCTP_INP_WUNLOCK(inp);
5121 SCTP_INP_RLOCK(inp);
5122 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5123 SCTP_TCB_LOCK(stcb);
5124 if (events->sctp_association_event) {
5125 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5127 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5129 if (events->sctp_address_event) {
5130 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5132 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5134 if (events->sctp_send_failure_event) {
5135 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5137 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5139 if (events->sctp_peer_error_event) {
5140 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5142 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5144 if (events->sctp_shutdown_event) {
5145 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5147 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5149 if (events->sctp_partial_delivery_event) {
5150 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5152 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5154 if (events->sctp_adaptation_layer_event) {
5155 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5157 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5159 if (events->sctp_authentication_event) {
5160 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5162 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5164 if (events->sctp_sender_dry_event) {
5165 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5167 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5169 if (events->sctp_stream_reset_event) {
5170 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5172 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5174 SCTP_TCB_UNLOCK(stcb);
5177 * Send up the sender dry event only for 1-to-1
5180 if (events->sctp_sender_dry_event) {
5181 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5182 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5183 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5185 SCTP_TCB_LOCK(stcb);
5186 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5187 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5188 (stcb->asoc.stream_queue_cnt == 0)) {
5189 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5191 SCTP_TCB_UNLOCK(stcb);
5195 SCTP_INP_RUNLOCK(inp);
5198 case SCTP_ADAPTATION_LAYER:
5200 struct sctp_setadaptation *adap_bits;
5202 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5203 SCTP_INP_WLOCK(inp);
5204 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5205 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5206 SCTP_INP_WUNLOCK(inp);
5210 case SCTP_SET_INITIAL_DBG_SEQ:
5214 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5215 SCTP_INP_WLOCK(inp);
5216 inp->sctp_ep.initial_sequence_debug = *vvv;
5217 SCTP_INP_WUNLOCK(inp);
5221 case SCTP_DEFAULT_SEND_PARAM:
5223 struct sctp_sndrcvinfo *s_info;
5225 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5226 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5229 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5230 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5232 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5235 SCTP_TCB_UNLOCK(stcb);
5237 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5238 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5239 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5240 ((s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5241 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)))) {
5242 SCTP_INP_WLOCK(inp);
5243 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5244 SCTP_INP_WUNLOCK(inp);
5246 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5247 ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5248 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC))) {
5249 SCTP_INP_RLOCK(inp);
5250 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5251 SCTP_TCB_LOCK(stcb);
5252 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5253 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5255 SCTP_TCB_UNLOCK(stcb);
5257 SCTP_INP_RUNLOCK(inp);
5262 case SCTP_PEER_ADDR_PARAMS:
5264 struct sctp_paddrparams *paddrp;
5265 struct sctp_nets *net;
5266 struct sockaddr *addr;
5267 #if defined(INET) && defined(INET6)
5268 struct sockaddr_in sin_store;
5271 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5272 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5274 #if defined(INET) && defined(INET6)
5275 if (paddrp->spp_address.ss_family == AF_INET6) {
5276 struct sockaddr_in6 *sin6;
5278 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5279 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5280 in6_sin6_2_sin(&sin_store, sin6);
5281 addr = (struct sockaddr *)&sin_store;
5283 addr = (struct sockaddr *)&paddrp->spp_address;
5286 addr = (struct sockaddr *)&paddrp->spp_address;
5289 addr = (struct sockaddr *)&paddrp->spp_address;
5292 net = sctp_findnet(stcb, addr);
5295 * We increment here since
5296 * sctp_findassociation_ep_addr() wil do a
5297 * decrement if it finds the stcb as long as
5298 * the locked tcb (last argument) is NOT a
5302 SCTP_INP_INCR_REF(inp);
5303 stcb = sctp_findassociation_ep_addr(&inp, addr,
5306 SCTP_INP_DECR_REF(inp);
5309 if ((stcb != NULL) && (net == NULL)) {
5311 if (addr->sa_family == AF_INET) {
5313 struct sockaddr_in *sin;
5315 sin = (struct sockaddr_in *)addr;
5316 if (sin->sin_addr.s_addr != INADDR_ANY) {
5317 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5318 SCTP_TCB_UNLOCK(stcb);
5325 if (addr->sa_family == AF_INET6) {
5326 struct sockaddr_in6 *sin6;
5328 sin6 = (struct sockaddr_in6 *)addr;
5329 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5330 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5331 SCTP_TCB_UNLOCK(stcb);
5338 error = EAFNOSUPPORT;
5339 SCTP_TCB_UNLOCK(stcb);
5340 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5345 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5347 SCTP_TCB_UNLOCK(stcb);
5348 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5352 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5354 SCTP_TCB_UNLOCK(stcb);
5355 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5358 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) &&
5359 ((paddrp->spp_pathmtu < SCTP_SMALLEST_PMTU) ||
5360 (paddrp->spp_pathmtu > SCTP_LARGEST_PMTU))) {
5362 SCTP_TCB_UNLOCK(stcb);
5363 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5368 /************************TCB SPECIFIC SET ******************/
5370 /************************NET SPECIFIC SET ******************/
5371 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5372 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5373 !(net->dest_state & SCTP_ADDR_NOHB)) {
5374 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5375 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5377 net->dest_state |= SCTP_ADDR_NOHB;
5379 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5380 if (paddrp->spp_hbinterval) {
5381 net->heart_beat_delay = paddrp->spp_hbinterval;
5382 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5383 net->heart_beat_delay = 0;
5385 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5386 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5387 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5388 net->dest_state &= ~SCTP_ADDR_NOHB;
5390 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5391 if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
5392 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5393 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5394 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5397 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5398 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5399 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5400 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5402 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5403 net->mtu = paddrp->spp_pathmtu;
5404 switch (net->ro._l_addr.sa.sa_family) {
5407 net->mtu += SCTP_MIN_V4_OVERHEAD;
5412 net->mtu += SCTP_MIN_OVERHEAD;
5418 if (net->mtu < stcb->asoc.smallest_mtu) {
5419 sctp_pathmtu_adjustment(stcb, net->mtu);
5422 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5423 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5424 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5426 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5428 if (paddrp->spp_pathmaxrxt) {
5429 if (net->dest_state & SCTP_ADDR_PF) {
5430 if (net->error_count > paddrp->spp_pathmaxrxt) {
5431 net->dest_state &= ~SCTP_ADDR_PF;
5434 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5435 (net->error_count > net->pf_threshold)) {
5436 net->dest_state |= SCTP_ADDR_PF;
5437 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5438 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5439 stcb->sctp_ep, stcb, net,
5440 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5441 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5444 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5445 if (net->error_count > paddrp->spp_pathmaxrxt) {
5446 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5447 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5450 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5451 net->dest_state |= SCTP_ADDR_REACHABLE;
5452 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5455 net->failure_threshold = paddrp->spp_pathmaxrxt;
5457 if (paddrp->spp_flags & SPP_DSCP) {
5458 net->dscp = paddrp->spp_dscp & 0xfc;
5462 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5463 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5464 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5465 net->flowlabel |= 0x80000000;
5470 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5471 if (paddrp->spp_pathmaxrxt != 0) {
5472 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5473 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5474 if (net->dest_state & SCTP_ADDR_PF) {
5475 if (net->error_count > paddrp->spp_pathmaxrxt) {
5476 net->dest_state &= ~SCTP_ADDR_PF;
5479 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5480 (net->error_count > net->pf_threshold)) {
5481 net->dest_state |= SCTP_ADDR_PF;
5482 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5483 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5484 stcb->sctp_ep, stcb, net,
5485 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5486 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5489 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5490 if (net->error_count > paddrp->spp_pathmaxrxt) {
5491 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5492 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5495 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5496 net->dest_state |= SCTP_ADDR_REACHABLE;
5497 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5500 net->failure_threshold = paddrp->spp_pathmaxrxt;
5504 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5505 if (paddrp->spp_hbinterval != 0) {
5506 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5507 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5508 stcb->asoc.heart_beat_delay = 0;
5510 /* Turn back on the timer */
5511 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5512 if (paddrp->spp_hbinterval != 0) {
5513 net->heart_beat_delay = paddrp->spp_hbinterval;
5514 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5515 net->heart_beat_delay = 0;
5517 if (net->dest_state & SCTP_ADDR_NOHB) {
5518 net->dest_state &= ~SCTP_ADDR_NOHB;
5520 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5521 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5522 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5524 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5526 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5527 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5528 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5529 net->dest_state |= SCTP_ADDR_NOHB;
5530 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5531 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5533 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5537 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5539 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5540 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5541 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5542 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5543 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5545 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5546 net->mtu = paddrp->spp_pathmtu;
5547 switch (net->ro._l_addr.sa.sa_family) {
5550 net->mtu += SCTP_MIN_V4_OVERHEAD;
5555 net->mtu += SCTP_MIN_OVERHEAD;
5561 if (net->mtu < stcb->asoc.smallest_mtu) {
5562 sctp_pathmtu_adjustment(stcb, net->mtu);
5565 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5566 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5568 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5569 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5570 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5571 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5573 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5575 stcb->asoc.default_mtu = 0;
5576 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5578 if (paddrp->spp_flags & SPP_DSCP) {
5579 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5580 net->dscp = paddrp->spp_dscp & 0xfc;
5583 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5584 stcb->asoc.default_dscp |= 0x01;
5587 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5588 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5589 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5590 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5591 net->flowlabel |= 0x80000000;
5594 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5595 stcb->asoc.default_flowlabel |= 0x80000000;
5599 SCTP_TCB_UNLOCK(stcb);
5601 /************************NO TCB, SET TO default stuff ******************/
5602 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5603 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5604 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5605 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
5606 SCTP_INP_WLOCK(inp);
5608 * For the TOS/FLOWLABEL stuff you
5609 * set it with the options on the
5612 if (paddrp->spp_pathmaxrxt != 0) {
5613 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5616 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5617 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5618 else if (paddrp->spp_hbinterval != 0) {
5619 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5620 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5621 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5624 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5625 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5626 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5627 } else if (paddrp->spp_hbinterval) {
5628 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5630 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5631 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5632 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5634 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5635 inp->sctp_ep.default_mtu = 0;
5636 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5637 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5638 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5639 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5641 if (paddrp->spp_flags & SPP_DSCP) {
5642 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5643 inp->sctp_ep.default_dscp |= 0x01;
5646 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5647 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5648 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5649 inp->sctp_ep.default_flowlabel |= 0x80000000;
5653 SCTP_INP_WUNLOCK(inp);
5655 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5663 struct sctp_rtoinfo *srto;
5664 uint32_t new_init, new_min, new_max;
5666 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5667 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5670 if (srto->srto_initial)
5671 new_init = srto->srto_initial;
5673 new_init = stcb->asoc.initial_rto;
5675 new_max = srto->srto_max;
5677 new_max = stcb->asoc.maxrto;
5679 new_min = srto->srto_min;
5681 new_min = stcb->asoc.minrto;
5682 if ((new_min <= new_init) && (new_init <= new_max)) {
5683 stcb->asoc.initial_rto = new_init;
5684 stcb->asoc.maxrto = new_max;
5685 stcb->asoc.minrto = new_min;
5687 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5690 SCTP_TCB_UNLOCK(stcb);
5692 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5693 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5694 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5695 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
5696 SCTP_INP_WLOCK(inp);
5697 if (srto->srto_initial)
5698 new_init = srto->srto_initial;
5700 new_init = inp->sctp_ep.initial_rto;
5702 new_max = srto->srto_max;
5704 new_max = inp->sctp_ep.sctp_maxrto;
5706 new_min = srto->srto_min;
5708 new_min = inp->sctp_ep.sctp_minrto;
5709 if ((new_min <= new_init) && (new_init <= new_max)) {
5710 inp->sctp_ep.initial_rto = new_init;
5711 inp->sctp_ep.sctp_maxrto = new_max;
5712 inp->sctp_ep.sctp_minrto = new_min;
5714 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5717 SCTP_INP_WUNLOCK(inp);
5719 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5725 case SCTP_ASSOCINFO:
5727 struct sctp_assocparams *sasoc;
5729 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5730 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5731 if (sasoc->sasoc_cookie_life) {
5732 /* boundary check the cookie life */
5733 if (sasoc->sasoc_cookie_life < 1000)
5734 sasoc->sasoc_cookie_life = 1000;
5735 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5736 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5740 if (sasoc->sasoc_asocmaxrxt)
5741 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5742 if (sasoc->sasoc_cookie_life) {
5743 stcb->asoc.cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5745 SCTP_TCB_UNLOCK(stcb);
5747 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5748 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5749 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5750 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
5751 SCTP_INP_WLOCK(inp);
5752 if (sasoc->sasoc_asocmaxrxt)
5753 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5754 if (sasoc->sasoc_cookie_life) {
5755 inp->sctp_ep.def_cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5757 SCTP_INP_WUNLOCK(inp);
5759 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5767 struct sctp_initmsg *sinit;
5769 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5770 SCTP_INP_WLOCK(inp);
5771 if (sinit->sinit_num_ostreams)
5772 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5774 if (sinit->sinit_max_instreams)
5775 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5777 if (sinit->sinit_max_attempts)
5778 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5780 if (sinit->sinit_max_init_timeo)
5781 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5782 SCTP_INP_WUNLOCK(inp);
5785 case SCTP_PRIMARY_ADDR:
5787 struct sctp_setprim *spa;
5788 struct sctp_nets *net;
5789 struct sockaddr *addr;
5790 #if defined(INET) && defined(INET6)
5791 struct sockaddr_in sin_store;
5794 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5795 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5797 #if defined(INET) && defined(INET6)
5798 if (spa->ssp_addr.ss_family == AF_INET6) {
5799 struct sockaddr_in6 *sin6;
5801 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5802 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5803 in6_sin6_2_sin(&sin_store, sin6);
5804 addr = (struct sockaddr *)&sin_store;
5806 addr = (struct sockaddr *)&spa->ssp_addr;
5809 addr = (struct sockaddr *)&spa->ssp_addr;
5812 addr = (struct sockaddr *)&spa->ssp_addr;
5815 net = sctp_findnet(stcb, addr);
5818 * We increment here since
5819 * sctp_findassociation_ep_addr() wil do a
5820 * decrement if it finds the stcb as long as
5821 * the locked tcb (last argument) is NOT a
5825 SCTP_INP_INCR_REF(inp);
5826 stcb = sctp_findassociation_ep_addr(&inp, addr,
5829 SCTP_INP_DECR_REF(inp);
5833 if ((stcb != NULL) && (net != NULL)) {
5834 if (net != stcb->asoc.primary_destination) {
5835 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5836 /* Ok we need to set it */
5837 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5838 if ((stcb->asoc.alternate) &&
5839 (!(net->dest_state & SCTP_ADDR_PF)) &&
5840 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5841 sctp_free_remote_addr(stcb->asoc.alternate);
5842 stcb->asoc.alternate = NULL;
5845 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5849 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5858 SCTP_TCB_UNLOCK(stcb);
5862 case SCTP_SET_DYNAMIC_PRIMARY:
5864 union sctp_sockstore *ss;
5866 error = priv_check(curthread,
5867 PRIV_NETINET_RESERVEDPORT);
5871 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5872 /* SUPER USER CHECK? */
5873 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5876 case SCTP_SET_PEER_PRIMARY_ADDR:
5878 struct sctp_setpeerprim *sspp;
5879 struct sockaddr *addr;
5880 #if defined(INET) && defined(INET6)
5881 struct sockaddr_in sin_store;
5884 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5885 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5887 struct sctp_ifa *ifa;
5889 #if defined(INET) && defined(INET6)
5890 if (sspp->sspp_addr.ss_family == AF_INET6) {
5891 struct sockaddr_in6 *sin6;
5893 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5894 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5895 in6_sin6_2_sin(&sin_store, sin6);
5896 addr = (struct sockaddr *)&sin_store;
5898 addr = (struct sockaddr *)&sspp->sspp_addr;
5901 addr = (struct sockaddr *)&sspp->sspp_addr;
5904 addr = (struct sockaddr *)&sspp->sspp_addr;
5906 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5908 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5912 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5914 * Must validate the ifa found is in
5917 struct sctp_laddr *laddr;
5920 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5921 if (laddr->ifa == NULL) {
5922 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5926 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5927 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5930 if (laddr->ifa == ifa) {
5936 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5941 switch (addr->sa_family) {
5945 struct sockaddr_in *sin;
5947 sin = (struct sockaddr_in *)addr;
5948 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5949 &sin->sin_addr) != 0) {
5950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5960 struct sockaddr_in6 *sin6;
5962 sin6 = (struct sockaddr_in6 *)addr;
5963 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5964 &sin6->sin6_addr) != 0) {
5965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5973 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5978 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5979 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5982 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5984 SCTP_TCB_UNLOCK(stcb);
5986 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5991 case SCTP_BINDX_ADD_ADDR:
5993 struct sockaddr *sa;
5996 td = (struct thread *)p;
5997 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
5999 if (sa->sa_family == AF_INET) {
6000 if (optsize < sizeof(struct sockaddr_in)) {
6001 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6006 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
6007 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6013 if (sa->sa_family == AF_INET6) {
6014 if (optsize < sizeof(struct sockaddr_in6)) {
6015 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6020 (error = prison_local_ip6(td->td_ucred,
6021 &(((struct sockaddr_in6 *)sa)->sin6_addr),
6022 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6023 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6029 error = EAFNOSUPPORT;
6032 sctp_bindx_add_address(so, inp, sa, vrf_id, &error, p);
6035 case SCTP_BINDX_REM_ADDR:
6037 struct sockaddr *sa;
6040 td = (struct thread *)p;
6042 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
6044 if (sa->sa_family == AF_INET) {
6045 if (optsize < sizeof(struct sockaddr_in)) {
6046 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6051 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
6052 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6058 if (sa->sa_family == AF_INET6) {
6059 if (optsize < sizeof(struct sockaddr_in6)) {
6060 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6065 (error = prison_local_ip6(td->td_ucred,
6066 &(((struct sockaddr_in6 *)sa)->sin6_addr),
6067 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6068 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6074 error = EAFNOSUPPORT;
6077 sctp_bindx_delete_address(inp, sa, vrf_id, &error);
6082 struct sctp_event *event;
6083 uint32_t event_type;
6085 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6086 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6087 switch (event->se_type) {
6088 case SCTP_ASSOC_CHANGE:
6089 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6091 case SCTP_PEER_ADDR_CHANGE:
6092 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6094 case SCTP_REMOTE_ERROR:
6095 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6097 case SCTP_SEND_FAILED:
6098 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6100 case SCTP_SHUTDOWN_EVENT:
6101 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6103 case SCTP_ADAPTATION_INDICATION:
6104 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6106 case SCTP_PARTIAL_DELIVERY_EVENT:
6107 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6109 case SCTP_AUTHENTICATION_EVENT:
6110 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6112 case SCTP_STREAM_RESET_EVENT:
6113 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6115 case SCTP_SENDER_DRY_EVENT:
6116 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6118 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6120 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6123 case SCTP_ASSOC_RESET_EVENT:
6124 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6126 case SCTP_STREAM_CHANGE_EVENT:
6127 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6129 case SCTP_SEND_FAILED_EVENT:
6130 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6134 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6138 if (event_type > 0) {
6141 sctp_stcb_feature_on(inp, stcb, event_type);
6142 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6143 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6144 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6145 (stcb->asoc.stream_queue_cnt == 0)) {
6146 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6150 sctp_stcb_feature_off(inp, stcb, event_type);
6152 SCTP_TCB_UNLOCK(stcb);
6155 * We don't want to send up a storm
6156 * of events, so return an error for
6159 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6160 (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6161 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6162 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6163 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6167 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6168 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6169 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6170 ((event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6171 (event->se_assoc_id == SCTP_ALL_ASSOC)))) {
6172 SCTP_INP_WLOCK(inp);
6174 sctp_feature_on(inp, event_type);
6176 sctp_feature_off(inp, event_type);
6178 SCTP_INP_WUNLOCK(inp);
6180 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6181 ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6182 (event->se_assoc_id == SCTP_ALL_ASSOC))) {
6183 SCTP_INP_RLOCK(inp);
6184 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6185 SCTP_TCB_LOCK(stcb);
6187 sctp_stcb_feature_on(inp, stcb, event_type);
6189 sctp_stcb_feature_off(inp, stcb, event_type);
6191 SCTP_TCB_UNLOCK(stcb);
6193 SCTP_INP_RUNLOCK(inp);
6198 SCTP_TCB_UNLOCK(stcb);
6203 case SCTP_RECVRCVINFO:
6207 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6208 SCTP_INP_WLOCK(inp);
6210 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6212 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6214 SCTP_INP_WUNLOCK(inp);
6217 case SCTP_RECVNXTINFO:
6221 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6222 SCTP_INP_WLOCK(inp);
6224 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6226 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6228 SCTP_INP_WUNLOCK(inp);
6231 case SCTP_DEFAULT_SNDINFO:
6233 struct sctp_sndinfo *info;
6236 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6237 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6240 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6241 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6242 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6243 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6244 stcb->asoc.def_send.sinfo_flags |= policy;
6245 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6246 stcb->asoc.def_send.sinfo_context = info->snd_context;
6248 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6251 SCTP_TCB_UNLOCK(stcb);
6253 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6254 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6255 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6256 ((info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6257 (info->snd_assoc_id == SCTP_ALL_ASSOC)))) {
6258 SCTP_INP_WLOCK(inp);
6259 inp->def_send.sinfo_stream = info->snd_sid;
6260 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6261 inp->def_send.sinfo_flags = info->snd_flags;
6262 inp->def_send.sinfo_flags |= policy;
6263 inp->def_send.sinfo_ppid = info->snd_ppid;
6264 inp->def_send.sinfo_context = info->snd_context;
6265 SCTP_INP_WUNLOCK(inp);
6267 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6268 ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6269 (info->snd_assoc_id == SCTP_ALL_ASSOC))) {
6270 SCTP_INP_RLOCK(inp);
6271 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6272 SCTP_TCB_LOCK(stcb);
6273 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6274 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6275 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6276 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6277 stcb->asoc.def_send.sinfo_flags |= policy;
6278 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6279 stcb->asoc.def_send.sinfo_context = info->snd_context;
6281 SCTP_TCB_UNLOCK(stcb);
6283 SCTP_INP_RUNLOCK(inp);
6288 case SCTP_DEFAULT_PRINFO:
6290 struct sctp_default_prinfo *info;
6292 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6293 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6295 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6297 SCTP_TCB_UNLOCK(stcb);
6299 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6304 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6305 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6306 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6307 SCTP_TCB_UNLOCK(stcb);
6309 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6310 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6311 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6312 ((info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6313 (info->pr_assoc_id == SCTP_ALL_ASSOC)))) {
6314 SCTP_INP_WLOCK(inp);
6315 inp->def_send.sinfo_flags &= 0xfff0;
6316 inp->def_send.sinfo_flags |= info->pr_policy;
6317 inp->def_send.sinfo_timetolive = info->pr_value;
6318 SCTP_INP_WUNLOCK(inp);
6320 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6321 ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6322 (info->pr_assoc_id == SCTP_ALL_ASSOC))) {
6323 SCTP_INP_RLOCK(inp);
6324 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6325 SCTP_TCB_LOCK(stcb);
6326 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6327 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6328 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6329 SCTP_TCB_UNLOCK(stcb);
6331 SCTP_INP_RUNLOCK(inp);
6336 case SCTP_PEER_ADDR_THLDS:
6337 /* Applies to the specific association */
6339 struct sctp_paddrthlds *thlds;
6340 struct sctp_nets *net;
6341 struct sockaddr *addr;
6342 #if defined(INET) && defined(INET6)
6343 struct sockaddr_in sin_store;
6346 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6347 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6349 #if defined(INET) && defined(INET6)
6350 if (thlds->spt_address.ss_family == AF_INET6) {
6351 struct sockaddr_in6 *sin6;
6353 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6354 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6355 in6_sin6_2_sin(&sin_store, sin6);
6356 addr = (struct sockaddr *)&sin_store;
6358 addr = (struct sockaddr *)&thlds->spt_address;
6361 addr = (struct sockaddr *)&thlds->spt_address;
6364 addr = (struct sockaddr *)&thlds->spt_address;
6367 net = sctp_findnet(stcb, addr);
6370 * We increment here since
6371 * sctp_findassociation_ep_addr() wil do a
6372 * decrement if it finds the stcb as long as
6373 * the locked tcb (last argument) is NOT a
6377 SCTP_INP_INCR_REF(inp);
6378 stcb = sctp_findassociation_ep_addr(&inp, addr,
6381 SCTP_INP_DECR_REF(inp);
6384 if ((stcb != NULL) && (net == NULL)) {
6386 if (addr->sa_family == AF_INET) {
6388 struct sockaddr_in *sin;
6390 sin = (struct sockaddr_in *)addr;
6391 if (sin->sin_addr.s_addr != INADDR_ANY) {
6392 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6393 SCTP_TCB_UNLOCK(stcb);
6400 if (addr->sa_family == AF_INET6) {
6401 struct sockaddr_in6 *sin6;
6403 sin6 = (struct sockaddr_in6 *)addr;
6404 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6405 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6406 SCTP_TCB_UNLOCK(stcb);
6413 error = EAFNOSUPPORT;
6414 SCTP_TCB_UNLOCK(stcb);
6415 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6419 if (thlds->spt_pathcpthld != 0xffff) {
6421 SCTP_TCB_UNLOCK(stcb);
6424 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6429 net->failure_threshold = thlds->spt_pathmaxrxt;
6430 net->pf_threshold = thlds->spt_pathpfthld;
6431 if (net->dest_state & SCTP_ADDR_PF) {
6432 if ((net->error_count > net->failure_threshold) ||
6433 (net->error_count <= net->pf_threshold)) {
6434 net->dest_state &= ~SCTP_ADDR_PF;
6437 if ((net->error_count > net->pf_threshold) &&
6438 (net->error_count <= net->failure_threshold)) {
6439 net->dest_state |= SCTP_ADDR_PF;
6440 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6441 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6442 stcb->sctp_ep, stcb, net,
6443 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6444 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6447 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6448 if (net->error_count > net->failure_threshold) {
6449 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6450 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6453 if (net->error_count <= net->failure_threshold) {
6454 net->dest_state |= SCTP_ADDR_REACHABLE;
6455 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6459 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6460 net->failure_threshold = thlds->spt_pathmaxrxt;
6461 net->pf_threshold = thlds->spt_pathpfthld;
6462 if (net->dest_state & SCTP_ADDR_PF) {
6463 if ((net->error_count > net->failure_threshold) ||
6464 (net->error_count <= net->pf_threshold)) {
6465 net->dest_state &= ~SCTP_ADDR_PF;
6468 if ((net->error_count > net->pf_threshold) &&
6469 (net->error_count <= net->failure_threshold)) {
6470 net->dest_state |= SCTP_ADDR_PF;
6471 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6472 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6473 stcb->sctp_ep, stcb, net,
6474 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6475 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6478 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6479 if (net->error_count > net->failure_threshold) {
6480 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6481 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6484 if (net->error_count <= net->failure_threshold) {
6485 net->dest_state |= SCTP_ADDR_REACHABLE;
6486 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6490 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6491 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6493 SCTP_TCB_UNLOCK(stcb);
6495 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6496 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6497 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6498 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
6499 SCTP_INP_WLOCK(inp);
6500 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6501 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6502 SCTP_INP_WUNLOCK(inp);
6504 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6510 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6512 struct sctp_udpencaps *encaps;
6513 struct sctp_nets *net;
6514 struct sockaddr *addr;
6515 #if defined(INET) && defined(INET6)
6516 struct sockaddr_in sin_store;
6519 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6520 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6522 #if defined(INET) && defined(INET6)
6523 if (encaps->sue_address.ss_family == AF_INET6) {
6524 struct sockaddr_in6 *sin6;
6526 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6527 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6528 in6_sin6_2_sin(&sin_store, sin6);
6529 addr = (struct sockaddr *)&sin_store;
6531 addr = (struct sockaddr *)&encaps->sue_address;
6534 addr = (struct sockaddr *)&encaps->sue_address;
6537 addr = (struct sockaddr *)&encaps->sue_address;
6540 net = sctp_findnet(stcb, addr);
6543 * We increment here since
6544 * sctp_findassociation_ep_addr() wil do a
6545 * decrement if it finds the stcb as long as
6546 * the locked tcb (last argument) is NOT a
6550 SCTP_INP_INCR_REF(inp);
6551 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6553 SCTP_INP_DECR_REF(inp);
6556 if ((stcb != NULL) && (net == NULL)) {
6558 if (addr->sa_family == AF_INET) {
6560 struct sockaddr_in *sin;
6562 sin = (struct sockaddr_in *)addr;
6563 if (sin->sin_addr.s_addr != INADDR_ANY) {
6564 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6565 SCTP_TCB_UNLOCK(stcb);
6572 if (addr->sa_family == AF_INET6) {
6573 struct sockaddr_in6 *sin6;
6575 sin6 = (struct sockaddr_in6 *)addr;
6576 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6577 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6578 SCTP_TCB_UNLOCK(stcb);
6585 error = EAFNOSUPPORT;
6586 SCTP_TCB_UNLOCK(stcb);
6587 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6594 net->port = encaps->sue_port;
6596 stcb->asoc.port = encaps->sue_port;
6598 SCTP_TCB_UNLOCK(stcb);
6600 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6601 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6602 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6603 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
6604 SCTP_INP_WLOCK(inp);
6605 inp->sctp_ep.port = encaps->sue_port;
6606 SCTP_INP_WUNLOCK(inp);
6608 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6614 case SCTP_ECN_SUPPORTED:
6616 struct sctp_assoc_value *av;
6618 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6619 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6624 SCTP_TCB_UNLOCK(stcb);
6626 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6627 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6628 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6629 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6630 SCTP_INP_WLOCK(inp);
6631 if (av->assoc_value == 0) {
6632 inp->ecn_supported = 0;
6634 inp->ecn_supported = 1;
6636 SCTP_INP_WUNLOCK(inp);
6638 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6644 case SCTP_PR_SUPPORTED:
6646 struct sctp_assoc_value *av;
6648 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6649 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6652 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6654 SCTP_TCB_UNLOCK(stcb);
6656 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6657 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6658 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6659 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6660 SCTP_INP_WLOCK(inp);
6661 if (av->assoc_value == 0) {
6662 inp->prsctp_supported = 0;
6664 inp->prsctp_supported = 1;
6666 SCTP_INP_WUNLOCK(inp);
6668 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6674 case SCTP_AUTH_SUPPORTED:
6676 struct sctp_assoc_value *av;
6678 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6679 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6682 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6684 SCTP_TCB_UNLOCK(stcb);
6686 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6687 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6688 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6689 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6690 if ((av->assoc_value == 0) &&
6691 (inp->asconf_supported == 1)) {
6693 * AUTH is required for
6696 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6699 SCTP_INP_WLOCK(inp);
6700 if (av->assoc_value == 0) {
6701 inp->auth_supported = 0;
6703 inp->auth_supported = 1;
6705 SCTP_INP_WUNLOCK(inp);
6708 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6714 case SCTP_ASCONF_SUPPORTED:
6716 struct sctp_assoc_value *av;
6718 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6719 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6722 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6724 SCTP_TCB_UNLOCK(stcb);
6726 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6727 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6728 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6729 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6730 if ((av->assoc_value != 0) &&
6731 (inp->auth_supported == 0)) {
6733 * AUTH is required for
6736 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6739 SCTP_INP_WLOCK(inp);
6740 if (av->assoc_value == 0) {
6741 inp->asconf_supported = 0;
6742 sctp_auth_delete_chunk(SCTP_ASCONF,
6743 inp->sctp_ep.local_auth_chunks);
6744 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6745 inp->sctp_ep.local_auth_chunks);
6747 inp->asconf_supported = 1;
6748 sctp_auth_add_chunk(SCTP_ASCONF,
6749 inp->sctp_ep.local_auth_chunks);
6750 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6751 inp->sctp_ep.local_auth_chunks);
6753 SCTP_INP_WUNLOCK(inp);
6756 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6762 case SCTP_RECONFIG_SUPPORTED:
6764 struct sctp_assoc_value *av;
6766 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6767 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6770 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6772 SCTP_TCB_UNLOCK(stcb);
6774 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6775 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6776 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6777 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6778 SCTP_INP_WLOCK(inp);
6779 if (av->assoc_value == 0) {
6780 inp->reconfig_supported = 0;
6782 inp->reconfig_supported = 1;
6784 SCTP_INP_WUNLOCK(inp);
6786 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6792 case SCTP_NRSACK_SUPPORTED:
6794 struct sctp_assoc_value *av;
6796 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6797 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6802 SCTP_TCB_UNLOCK(stcb);
6804 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6805 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6806 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6807 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6808 SCTP_INP_WLOCK(inp);
6809 if (av->assoc_value == 0) {
6810 inp->nrsack_supported = 0;
6812 inp->nrsack_supported = 1;
6814 SCTP_INP_WUNLOCK(inp);
6816 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6822 case SCTP_PKTDROP_SUPPORTED:
6824 struct sctp_assoc_value *av;
6826 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6827 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6830 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6832 SCTP_TCB_UNLOCK(stcb);
6834 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6835 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6836 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6837 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6838 SCTP_INP_WLOCK(inp);
6839 if (av->assoc_value == 0) {
6840 inp->pktdrop_supported = 0;
6842 inp->pktdrop_supported = 1;
6844 SCTP_INP_WUNLOCK(inp);
6846 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6854 struct sctp_assoc_value *av;
6855 struct sctp_nets *net;
6857 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6858 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6861 stcb->asoc.max_cwnd = av->assoc_value;
6862 if (stcb->asoc.max_cwnd > 0) {
6863 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6864 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6865 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6866 net->cwnd = stcb->asoc.max_cwnd;
6867 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6868 net->cwnd = net->mtu - sizeof(struct sctphdr);
6873 SCTP_TCB_UNLOCK(stcb);
6875 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6876 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6877 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6878 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6879 SCTP_INP_WLOCK(inp);
6880 inp->max_cwnd = av->assoc_value;
6881 SCTP_INP_WUNLOCK(inp);
6883 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6890 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6891 error = ENOPROTOOPT;
6893 } /* end switch (opt) */
6898 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6900 struct epoch_tracker et;
6901 struct sctp_inpcb *inp;
6902 void *optval = NULL;
6907 if ((sopt->sopt_level == SOL_SOCKET) &&
6908 (sopt->sopt_name == SO_SETFIB)) {
6909 inp = (struct sctp_inpcb *)so->so_pcb;
6911 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6914 SCTP_INP_WLOCK(inp);
6915 inp->fibnum = so->so_fibnum;
6916 SCTP_INP_WUNLOCK(inp);
6919 if (sopt->sopt_level != IPPROTO_SCTP) {
6920 /* wrong proto level... send back up to IP */
6922 if (INP_CHECK_SOCKAF(so, AF_INET6))
6923 error = ip6_ctloutput(so, sopt);
6925 #if defined(INET) && defined(INET6)
6929 error = ip_ctloutput(so, sopt);
6933 optsize = sopt->sopt_valsize;
6934 if (optsize > SCTP_SOCKET_OPTION_LIMIT) {
6935 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6939 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6940 if (optval == NULL) {
6941 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6944 error = sooptcopyin(sopt, optval, optsize, optsize);
6946 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6950 p = (void *)sopt->sopt_td;
6951 if (sopt->sopt_dir == SOPT_SET) {
6952 NET_EPOCH_ENTER(et);
6953 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6955 } else if (sopt->sopt_dir == SOPT_GET) {
6956 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6958 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6961 if ((error == 0) && (optval != NULL)) {
6962 error = sooptcopyout(sopt, optval, optsize);
6963 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6964 } else if (optval != NULL) {
6965 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6973 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6975 struct epoch_tracker et;
6977 int create_lock_on = 0;
6979 struct sctp_inpcb *inp;
6980 struct sctp_tcb *stcb = NULL;
6982 inp = (struct sctp_inpcb *)so->so_pcb;
6984 /* I made the same as TCP since we are not setup? */
6985 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6986 return (ECONNRESET);
6989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6993 switch (addr->sa_family) {
6997 struct sockaddr_in6 *sin6;
6999 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
7000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7003 sin6 = (struct sockaddr_in6 *)addr;
7004 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6->sin6_addr)) != 0) {
7005 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7014 struct sockaddr_in *sin;
7016 if (addr->sa_len != sizeof(struct sockaddr_in)) {
7017 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7020 sin = (struct sockaddr_in *)addr;
7021 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sin->sin_addr)) != 0) {
7022 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7029 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
7030 return (EAFNOSUPPORT);
7032 SCTP_INP_INCR_REF(inp);
7033 SCTP_ASOC_CREATE_LOCK(inp);
7035 NET_EPOCH_ENTER(et);
7037 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
7038 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
7039 /* Should I really unlock ? */
7040 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
7045 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
7046 (addr->sa_family == AF_INET6)) {
7047 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7052 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
7053 SCTP_PCB_FLAGS_UNBOUND) {
7054 /* Bind a ephemeral port */
7055 error = sctp_inpcb_bind(so, NULL, NULL, p);
7060 /* Now do we connect? */
7061 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
7062 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
7063 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7067 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7068 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7069 /* We are already connected AND the TCP model */
7070 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7074 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7075 SCTP_INP_RLOCK(inp);
7076 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7077 SCTP_INP_RUNLOCK(inp);
7080 * We increment here since sctp_findassociation_ep_addr()
7081 * will do a decrement if it finds the stcb as long as the
7082 * locked tcb (last argument) is NOT a TCB.. aka NULL.
7084 SCTP_INP_INCR_REF(inp);
7085 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7087 SCTP_INP_DECR_REF(inp);
7089 SCTP_TCB_UNLOCK(stcb);
7093 /* Already have or am bring up an association */
7094 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7099 vrf_id = inp->def_vrf_id;
7100 /* We are GOOD to go */
7101 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
7102 inp->sctp_ep.pre_open_stream_count,
7103 inp->sctp_ep.port, p,
7104 SCTP_INITIALIZE_AUTH_PARAMS);
7106 /* Gak! no memory */
7109 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7110 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7111 /* Set the connected flag so we can queue data */
7114 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7115 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7117 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7118 SCTP_TCB_UNLOCK(stcb);
7121 if (create_lock_on) {
7122 SCTP_ASOC_CREATE_UNLOCK(inp);
7124 SCTP_INP_DECR_REF(inp);
7130 sctp_listen(struct socket *so, int backlog, struct thread *p)
7133 * Note this module depends on the protocol processing being called
7134 * AFTER any socket level flags and backlog are applied to the
7135 * socket. The traditional way that the socket flags are applied is
7136 * AFTER protocol processing. We have made a change to the
7137 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7138 * place if the socket API for SCTP is to work properly.
7142 struct sctp_inpcb *inp;
7144 inp = (struct sctp_inpcb *)so->so_pcb;
7146 /* I made the same as TCP since we are not setup? */
7147 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7148 return (ECONNRESET);
7150 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7151 /* See if we have a listener */
7152 struct sctp_inpcb *tinp;
7153 union sctp_sockstore store;
7155 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7157 struct sctp_laddr *laddr;
7159 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7160 memcpy(&store, &laddr->ifa->address, sizeof(store));
7161 switch (store.sa.sa_family) {
7164 store.sin.sin_port = inp->sctp_lport;
7169 store.sin6.sin6_port = inp->sctp_lport;
7175 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7176 if (tinp && (tinp != inp) &&
7177 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7178 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7179 (SCTP_IS_LISTENING(tinp))) {
7181 * we have a listener already and
7184 SCTP_INP_DECR_REF(tinp);
7185 return (EADDRINUSE);
7187 SCTP_INP_DECR_REF(tinp);
7191 /* Setup a local addr bound all */
7192 memset(&store, 0, sizeof(store));
7194 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7195 store.sa.sa_family = AF_INET6;
7196 store.sa.sa_len = sizeof(struct sockaddr_in6);
7200 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7201 store.sa.sa_family = AF_INET;
7202 store.sa.sa_len = sizeof(struct sockaddr_in);
7205 switch (store.sa.sa_family) {
7208 store.sin.sin_port = inp->sctp_lport;
7213 store.sin6.sin6_port = inp->sctp_lport;
7219 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7220 if (tinp && (tinp != inp) &&
7221 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7222 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7223 (SCTP_IS_LISTENING(tinp))) {
7225 * we have a listener already and its not
7228 SCTP_INP_DECR_REF(tinp);
7229 return (EADDRINUSE);
7231 SCTP_INP_DECR_REF(tinp);
7235 SCTP_INP_RLOCK(inp);
7236 #ifdef SCTP_LOCK_LOGGING
7237 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7238 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7242 error = solisten_proto_check(so);
7245 SCTP_INP_RUNLOCK(inp);
7248 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7249 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7251 * The unlucky case - We are in the tcp pool with this guy.
7252 * - Someone else is in the main inp slot. - We must move
7253 * this guy (the listener) to the main slot - We must then
7254 * move the guy that was listener to the TCP Pool.
7256 if (sctp_swap_inpcb_for_listen(inp)) {
7257 SCTP_INP_RUNLOCK(inp);
7258 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7259 return (EADDRINUSE);
7263 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7264 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7265 /* We are already connected AND the TCP model */
7266 SCTP_INP_RUNLOCK(inp);
7267 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7268 return (EADDRINUSE);
7270 SCTP_INP_RUNLOCK(inp);
7271 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7272 /* We must do a bind. */
7273 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7274 /* bind error, probably perm */
7278 SCTP_INP_WLOCK(inp);
7279 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7281 solisten_proto(so, backlog);
7285 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7287 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7289 SCTP_INP_WUNLOCK(inp);
7293 static int sctp_defered_wakeup_cnt = 0;
7296 sctp_accept(struct socket *so, struct sockaddr **addr)
7298 struct sctp_tcb *stcb;
7299 struct sctp_inpcb *inp;
7300 union sctp_sockstore store;
7304 inp = (struct sctp_inpcb *)so->so_pcb;
7307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7308 return (ECONNRESET);
7310 SCTP_INP_WLOCK(inp);
7311 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7312 SCTP_INP_WUNLOCK(inp);
7313 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7314 return (EOPNOTSUPP);
7316 if (so->so_state & SS_ISDISCONNECTED) {
7317 SCTP_INP_WUNLOCK(inp);
7318 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7319 return (ECONNABORTED);
7321 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7323 SCTP_INP_WUNLOCK(inp);
7324 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7325 return (ECONNRESET);
7327 SCTP_TCB_LOCK(stcb);
7328 store = stcb->asoc.primary_destination->ro._l_addr;
7329 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7330 /* Wake any delayed sleep action */
7331 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7332 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7333 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7334 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7335 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7336 if (sowriteable(inp->sctp_socket)) {
7337 sowwakeup_locked(inp->sctp_socket);
7339 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7342 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7343 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7344 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7345 if (soreadable(inp->sctp_socket)) {
7346 sctp_defered_wakeup_cnt++;
7347 sorwakeup_locked(inp->sctp_socket);
7349 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7353 SCTP_INP_WUNLOCK(inp);
7354 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7355 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7356 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7358 SCTP_TCB_UNLOCK(stcb);
7360 switch (store.sa.sa_family) {
7364 struct sockaddr_in *sin;
7366 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7369 sin->sin_family = AF_INET;
7370 sin->sin_len = sizeof(*sin);
7371 sin->sin_port = store.sin.sin_port;
7372 sin->sin_addr = store.sin.sin_addr;
7373 *addr = (struct sockaddr *)sin;
7380 struct sockaddr_in6 *sin6;
7382 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7385 sin6->sin6_family = AF_INET6;
7386 sin6->sin6_len = sizeof(*sin6);
7387 sin6->sin6_port = store.sin6.sin6_port;
7388 sin6->sin6_addr = store.sin6.sin6_addr;
7389 if ((error = sa6_recoverscope(sin6)) != 0) {
7390 SCTP_FREE_SONAME(sin6);
7393 *addr = (struct sockaddr *)sin6;
7406 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7408 struct sockaddr_in *sin;
7410 struct sctp_inpcb *inp;
7411 struct sctp_ifa *sctp_ifa;
7414 * Do the malloc first in case it blocks.
7416 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7419 sin->sin_family = AF_INET;
7420 sin->sin_len = sizeof(*sin);
7421 inp = (struct sctp_inpcb *)so->so_pcb;
7423 SCTP_FREE_SONAME(sin);
7424 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7425 return (ECONNRESET);
7427 SCTP_INP_RLOCK(inp);
7428 sin->sin_port = inp->sctp_lport;
7429 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7430 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7431 struct sctp_tcb *stcb;
7432 struct sockaddr_in *sin_a;
7433 struct sctp_nets *net;
7436 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7442 SCTP_TCB_LOCK(stcb);
7443 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7444 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7446 /* this will make coverity happy */
7449 if (sin_a->sin_family == AF_INET) {
7454 if ((!fnd) || (sin_a == NULL)) {
7456 SCTP_TCB_UNLOCK(stcb);
7460 vrf_id = inp->def_vrf_id;
7461 sctp_ifa = sctp_source_address_selection(inp,
7463 (sctp_route_t *)&net->ro,
7466 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7467 sctp_free_ifa(sctp_ifa);
7469 SCTP_TCB_UNLOCK(stcb);
7471 /* For the bound all case you get back 0 */
7473 sin->sin_addr.s_addr = 0;
7477 /* Take the first IPv4 address in the list */
7478 struct sctp_laddr *laddr;
7481 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7482 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7483 struct sockaddr_in *sin_a;
7485 sin_a = &laddr->ifa->address.sin;
7486 sin->sin_addr = sin_a->sin_addr;
7492 SCTP_FREE_SONAME(sin);
7493 SCTP_INP_RUNLOCK(inp);
7494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7498 SCTP_INP_RUNLOCK(inp);
7499 (*addr) = (struct sockaddr *)sin;
7504 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7506 struct sockaddr_in *sin;
7508 struct sockaddr_in *sin_a;
7509 struct sctp_inpcb *inp;
7510 struct sctp_tcb *stcb;
7511 struct sctp_nets *net;
7513 /* Do the malloc first in case it blocks. */
7514 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7517 sin->sin_family = AF_INET;
7518 sin->sin_len = sizeof(*sin);
7520 inp = (struct sctp_inpcb *)so->so_pcb;
7521 if ((inp == NULL) ||
7522 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7523 /* UDP type and listeners will drop out here */
7524 SCTP_FREE_SONAME(sin);
7525 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7528 SCTP_INP_RLOCK(inp);
7529 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7531 SCTP_TCB_LOCK(stcb);
7533 SCTP_INP_RUNLOCK(inp);
7535 SCTP_FREE_SONAME(sin);
7536 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7537 return (ECONNRESET);
7540 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7541 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7542 if (sin_a->sin_family == AF_INET) {
7544 sin->sin_port = stcb->rport;
7545 sin->sin_addr = sin_a->sin_addr;
7549 SCTP_TCB_UNLOCK(stcb);
7551 /* No IPv4 address */
7552 SCTP_FREE_SONAME(sin);
7553 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7556 (*addr) = (struct sockaddr *)sin;
7560 struct pr_usrreqs sctp_usrreqs = {
7561 .pru_abort = sctp_abort,
7562 .pru_accept = sctp_accept,
7563 .pru_attach = sctp_attach,
7564 .pru_bind = sctp_bind,
7565 .pru_connect = sctp_connect,
7566 .pru_control = in_control,
7567 .pru_close = sctp_close,
7568 .pru_detach = sctp_close,
7569 .pru_sopoll = sopoll_generic,
7570 .pru_flush = sctp_flush,
7571 .pru_disconnect = sctp_disconnect,
7572 .pru_listen = sctp_listen,
7573 .pru_peeraddr = sctp_peeraddr,
7574 .pru_send = sctp_sendm,
7575 .pru_shutdown = sctp_shutdown,
7576 .pru_sockaddr = sctp_ingetaddr,
7577 .pru_sosend = sctp_sosend,
7578 .pru_soreceive = sctp_soreceive