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, CTLTYPE_OPAQUE | CTLFLAG_RW,
410 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
415 sctp_abort(struct socket *so)
417 struct sctp_inpcb *inp;
420 inp = (struct sctp_inpcb *)so->so_pcb;
426 flags = inp->sctp_flags;
427 #ifdef SCTP_LOG_CLOSING
428 sctp_log_closing(inp, NULL, 17);
430 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
431 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
432 #ifdef SCTP_LOG_CLOSING
433 sctp_log_closing(inp, NULL, 16);
435 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
436 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
438 SCTP_SB_CLEAR(so->so_snd);
440 * same for the rcv ones, they are only here for the
443 SCTP_SB_CLEAR(so->so_rcv);
445 /* Now null out the reference, we are completely detached. */
449 flags = inp->sctp_flags;
450 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
451 goto sctp_must_try_again;
458 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
460 struct sctp_inpcb *inp;
461 struct inpcb *ip_inp;
463 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
465 inp = (struct sctp_inpcb *)so->so_pcb;
467 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
470 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
471 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
476 error = sctp_inpcb_alloc(so, vrf_id);
480 inp = (struct sctp_inpcb *)so->so_pcb;
482 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
483 ip_inp = &inp->ip_inp.inp;
484 ip_inp->inp_vflag |= INP_IPV4;
485 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
486 SCTP_INP_WUNLOCK(inp);
491 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
493 struct sctp_inpcb *inp;
495 inp = (struct sctp_inpcb *)so->so_pcb;
497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
501 if ((addr->sa_family != AF_INET) ||
502 (addr->sa_len != sizeof(struct sockaddr_in))) {
503 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
507 return (sctp_inpcb_bind(so, addr, NULL, p));
512 sctp_close(struct socket *so)
514 struct sctp_inpcb *inp;
517 inp = (struct sctp_inpcb *)so->so_pcb;
522 * Inform all the lower layer assoc that we are done.
525 flags = inp->sctp_flags;
526 #ifdef SCTP_LOG_CLOSING
527 sctp_log_closing(inp, NULL, 17);
529 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
530 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
531 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
532 (so->so_rcv.sb_cc > 0)) {
533 #ifdef SCTP_LOG_CLOSING
534 sctp_log_closing(inp, NULL, 13);
536 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
537 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
539 #ifdef SCTP_LOG_CLOSING
540 sctp_log_closing(inp, NULL, 14);
542 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
543 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
546 * The socket is now detached, no matter what the state of
547 * the SCTP association.
550 SCTP_SB_CLEAR(so->so_snd);
552 * same for the rcv ones, they are only here for the
555 SCTP_SB_CLEAR(so->so_rcv);
557 /* Now null out the reference, we are completely detached. */
561 flags = inp->sctp_flags;
562 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
563 goto sctp_must_try_again;
571 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
572 struct mbuf *control, struct thread *p);
576 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
577 struct mbuf *control, struct thread *p)
579 struct sctp_inpcb *inp;
582 inp = (struct sctp_inpcb *)so->so_pcb;
585 sctp_m_freem(control);
588 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
592 /* Got to have an to address if we are NOT a connected socket */
593 if ((addr == NULL) &&
594 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
595 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
597 } else if (addr == NULL) {
598 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
599 error = EDESTADDRREQ;
602 sctp_m_freem(control);
608 if (addr->sa_family != AF_INET) {
609 /* must be a v4 address! */
610 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
613 sctp_m_freem(control);
616 error = EDESTADDRREQ;
621 /* now what about control */
624 sctp_m_freem(inp->control);
627 inp->control = control;
631 SCTP_BUF_NEXT(inp->pkt_last) = m;
634 inp->pkt_last = inp->pkt = m;
637 /* FreeBSD uses a flag passed */
638 ((flags & PRUS_MORETOCOME) == 0)
641 * note with the current version this code will only be used
642 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
643 * re-defining sosend to use the sctp_sosend. One can
644 * optionally switch back to this code (by changing back the
645 * definitions) but this is not advisable. This code is used
646 * by FreeBSD when sending a file with sendfile() though.
650 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
660 sctp_disconnect(struct socket *so)
662 struct sctp_inpcb *inp;
664 inp = (struct sctp_inpcb *)so->so_pcb;
666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
670 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
671 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
672 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
674 SCTP_INP_RUNLOCK(inp);
677 struct sctp_association *asoc;
678 struct sctp_tcb *stcb;
680 stcb = LIST_FIRST(&inp->sctp_asoc_list);
682 SCTP_INP_RUNLOCK(inp);
683 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
688 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
689 /* We are about to be freed, out of here */
690 SCTP_TCB_UNLOCK(stcb);
691 SCTP_INP_RUNLOCK(inp);
694 if (((so->so_options & SO_LINGER) &&
695 (so->so_linger == 0)) ||
696 (so->so_rcv.sb_cc > 0)) {
697 if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) {
698 /* Left with Data unread */
701 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
702 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
703 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
705 SCTP_INP_RUNLOCK(inp);
706 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
707 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
708 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
710 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
711 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
712 /* No unlock tcb assoc is gone */
715 if (TAILQ_EMPTY(&asoc->send_queue) &&
716 TAILQ_EMPTY(&asoc->sent_queue) &&
717 (asoc->stream_queue_cnt == 0)) {
718 /* there is nothing queued to send, so done */
719 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
722 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) &&
723 (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
724 /* only send SHUTDOWN 1st time thru */
725 struct sctp_nets *netp;
727 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
728 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
729 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
731 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
732 sctp_stop_timers_for_shutdown(stcb);
733 if (stcb->asoc.alternate) {
734 netp = stcb->asoc.alternate;
736 netp = stcb->asoc.primary_destination;
738 sctp_send_shutdown(stcb, netp);
739 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
740 stcb->sctp_ep, stcb, netp);
741 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
742 stcb->sctp_ep, stcb, NULL);
743 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
747 * we still got (or just got) data to send,
748 * so set SHUTDOWN_PENDING
751 * XXX sockets draft says that SCTP_EOF
752 * should be sent with no data. currently,
753 * we will allow user data to be sent first
754 * and move to SHUTDOWN-PENDING
756 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
757 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
758 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
759 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
761 if (TAILQ_EMPTY(&asoc->send_queue) &&
762 TAILQ_EMPTY(&asoc->sent_queue) &&
763 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
767 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
768 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
769 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
770 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
771 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
772 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
773 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
775 SCTP_INP_RUNLOCK(inp);
776 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
777 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
780 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
783 soisdisconnecting(so);
784 SCTP_TCB_UNLOCK(stcb);
785 SCTP_INP_RUNLOCK(inp);
790 /* UDP model does not support this */
791 SCTP_INP_RUNLOCK(inp);
792 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
798 sctp_flush(struct socket *so, int how)
801 * We will just clear out the values and let subsequent close clear
802 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
803 * they will not be able to read the data, the socket will block
804 * that from happening.
806 struct sctp_inpcb *inp;
808 inp = (struct sctp_inpcb *)so->so_pcb;
810 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
814 /* For the 1 to many model this does nothing */
815 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
816 SCTP_INP_RUNLOCK(inp);
819 SCTP_INP_RUNLOCK(inp);
820 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
822 * First make sure the sb will be happy, we don't use these
823 * except maybe the count
826 SCTP_INP_READ_LOCK(inp);
827 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
828 SCTP_INP_READ_UNLOCK(inp);
829 SCTP_INP_WUNLOCK(inp);
830 so->so_rcv.sb_cc = 0;
831 so->so_rcv.sb_mbcnt = 0;
832 so->so_rcv.sb_mb = NULL;
834 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
836 * First make sure the sb will be happy, we don't use these
837 * except maybe the count
839 so->so_snd.sb_cc = 0;
840 so->so_snd.sb_mbcnt = 0;
841 so->so_snd.sb_mb = NULL;
848 sctp_shutdown(struct socket *so)
850 struct sctp_inpcb *inp;
852 inp = (struct sctp_inpcb *)so->so_pcb;
854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
858 /* For UDP model this is a invalid call */
859 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
860 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
861 /* Restore the flags that the soshutdown took away. */
862 SOCKBUF_LOCK(&so->so_rcv);
863 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
864 SOCKBUF_UNLOCK(&so->so_rcv);
865 /* This proc will wakeup for read and do nothing (I hope) */
866 SCTP_INP_RUNLOCK(inp);
867 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
871 * Ok, if we reach here its the TCP model and it is either a
872 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
875 struct sctp_tcb *stcb;
876 struct sctp_association *asoc;
877 struct sctp_nets *netp;
880 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
881 SCTP_INP_RUNLOCK(inp);
886 stcb = LIST_FIRST(&inp->sctp_asoc_list);
889 * Ok, we hit the case that the shutdown call was
890 * made after an abort or something. Nothing to do
893 SCTP_INP_RUNLOCK(inp);
898 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
899 SCTP_TCB_UNLOCK(stcb);
900 SCTP_INP_RUNLOCK(inp);
903 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) &&
904 (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) &&
905 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) {
907 * If we are not in or before ESTABLISHED, there is
908 * no protocol action required.
910 SCTP_TCB_UNLOCK(stcb);
911 SCTP_INP_RUNLOCK(inp);
914 if (stcb->asoc.alternate) {
915 netp = stcb->asoc.alternate;
917 netp = stcb->asoc.primary_destination;
919 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) &&
920 TAILQ_EMPTY(&asoc->send_queue) &&
921 TAILQ_EMPTY(&asoc->sent_queue) &&
922 (asoc->stream_queue_cnt == 0)) {
923 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
926 /* there is nothing queued to send, so I'm done... */
927 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
928 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
929 sctp_stop_timers_for_shutdown(stcb);
930 sctp_send_shutdown(stcb, netp);
931 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
932 stcb->sctp_ep, stcb, netp);
935 * We still got (or just got) data to send, so set
938 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
939 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
940 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
942 if (TAILQ_EMPTY(&asoc->send_queue) &&
943 TAILQ_EMPTY(&asoc->sent_queue) &&
944 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
948 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
949 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
950 SCTP_INP_RUNLOCK(inp);
951 sctp_abort_an_association(stcb->sctp_ep, stcb,
952 op_err, SCTP_SO_LOCKED);
956 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL);
958 * XXX: Why do this in the case where we have still data
961 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
962 SCTP_TCB_UNLOCK(stcb);
963 SCTP_INP_RUNLOCK(inp);
969 * copies a "user" presentable address and removes embedded scope, etc.
970 * returns 0 on success, 1 on error
973 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
976 struct sockaddr_in6 lsa6;
978 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
981 memcpy(ss, sa, sa->sa_len);
988 * NOTE: assumes addr lock is held
991 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
992 struct sctp_tcb *stcb,
994 struct sockaddr_storage *sas,
997 struct sctp_ifn *sctp_ifn;
998 struct sctp_ifa *sctp_ifa;
1002 int ipv4_local_scope, ipv4_addr_legal;
1005 int local_scope, site_scope, ipv6_addr_legal;
1007 struct sctp_vrf *vrf;
1014 /* Turn on all the appropriate scope */
1015 loopback_scope = stcb->asoc.scope.loopback_scope;
1017 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1018 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1021 local_scope = stcb->asoc.scope.local_scope;
1022 site_scope = stcb->asoc.scope.site_scope;
1023 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1026 /* Use generic values for endpoints. */
1029 ipv4_local_scope = 1;
1035 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1037 ipv6_addr_legal = 1;
1040 if (SCTP_IPV6_V6ONLY(inp)) {
1041 ipv4_addr_legal = 0;
1043 ipv4_addr_legal = 1;
1048 ipv6_addr_legal = 0;
1051 ipv4_addr_legal = 1;
1055 vrf = sctp_find_vrf(vrf_id);
1059 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1060 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1061 if ((loopback_scope == 0) &&
1062 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1063 /* Skip loopback if loopback_scope not set */
1066 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1069 * For the BOUND-ALL case, the list
1070 * associated with a TCB is Always
1071 * considered a reverse list.. i.e.
1072 * it lists addresses that are NOT
1073 * part of the association. If this
1074 * is one of those we must skip it.
1076 if (sctp_is_addr_restricted(stcb,
1081 switch (sctp_ifa->address.sa.sa_family) {
1084 if (ipv4_addr_legal) {
1085 struct sockaddr_in *sin;
1087 sin = &sctp_ifa->address.sin;
1088 if (sin->sin_addr.s_addr == 0) {
1096 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1097 &sin->sin_addr) != 0) {
1100 if ((ipv4_local_scope == 0) &&
1101 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1105 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1106 if (actual + sizeof(struct sockaddr_in6) > limit) {
1109 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1110 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1111 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1112 actual += sizeof(struct sockaddr_in6);
1115 if (actual + sizeof(struct sockaddr_in) > limit) {
1118 memcpy(sas, sin, sizeof(struct sockaddr_in));
1119 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1120 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in));
1121 actual += sizeof(struct sockaddr_in);
1132 if (ipv6_addr_legal) {
1133 struct sockaddr_in6 *sin6;
1135 sin6 = &sctp_ifa->address.sin6;
1136 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1144 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1145 &sin6->sin6_addr) != 0) {
1148 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1149 if (local_scope == 0)
1151 if (sin6->sin6_scope_id == 0) {
1152 if (sa6_recoverscope(sin6) != 0)
1165 if ((site_scope == 0) &&
1166 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1169 if (actual + sizeof(struct sockaddr_in6) > limit) {
1172 memcpy(sas, sin6, sizeof(struct sockaddr_in6));
1173 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1174 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1175 actual += sizeof(struct sockaddr_in6);
1188 struct sctp_laddr *laddr;
1191 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1193 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1197 sa_len = laddr->ifa->address.sa.sa_len;
1198 if (actual + sa_len > limit) {
1201 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1203 switch (laddr->ifa->address.sa.sa_family) {
1206 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1211 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1218 sas = (struct sockaddr_storage *)((caddr_t)sas + sa_len);
1226 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1227 struct sctp_tcb *stcb,
1229 struct sockaddr_storage *sas)
1233 SCTP_IPI_ADDR_RLOCK();
1234 /* fill up addresses for the endpoint's default vrf */
1235 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1237 SCTP_IPI_ADDR_RUNLOCK();
1242 * NOTE: assumes addr lock is held
1245 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1248 struct sctp_vrf *vrf = NULL;
1251 * In both sub-set bound an bound_all cases we return the MAXIMUM
1252 * number of addresses that you COULD get. In reality the sub-set
1253 * bound may have an exclusion list for a given TCB OR in the
1254 * bound-all case a TCB may NOT include the loopback or other
1255 * addresses as well.
1257 vrf = sctp_find_vrf(vrf_id);
1261 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1262 struct sctp_ifn *sctp_ifn;
1263 struct sctp_ifa *sctp_ifa;
1265 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1266 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1267 /* Count them if they are the right type */
1268 switch (sctp_ifa->address.sa.sa_family) {
1272 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1273 cnt += sizeof(struct sockaddr_in6);
1275 cnt += sizeof(struct sockaddr_in);
1277 cnt += sizeof(struct sockaddr_in);
1283 cnt += sizeof(struct sockaddr_in6);
1292 struct sctp_laddr *laddr;
1294 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1295 switch (laddr->ifa->address.sa.sa_family) {
1299 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1300 cnt += sizeof(struct sockaddr_in6);
1302 cnt += sizeof(struct sockaddr_in);
1304 cnt += sizeof(struct sockaddr_in);
1310 cnt += sizeof(struct sockaddr_in6);
1322 sctp_count_max_addresses(struct sctp_inpcb *inp)
1326 SCTP_IPI_ADDR_RLOCK();
1327 /* count addresses for the endpoint's default VRF */
1328 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1329 SCTP_IPI_ADDR_RUNLOCK();
1334 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1335 size_t optsize, void *p, int delay)
1338 int creat_lock_on = 0;
1339 struct sctp_tcb *stcb = NULL;
1340 struct sockaddr *sa;
1341 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1345 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1347 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1348 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1349 /* We are already connected AND the TCP model */
1350 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1351 return (EADDRINUSE);
1354 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1355 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1356 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1360 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1361 SCTP_INP_RLOCK(inp);
1362 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1363 SCTP_INP_RUNLOCK(inp);
1366 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1369 SCTP_INP_INCR_REF(inp);
1370 SCTP_ASOC_CREATE_LOCK(inp);
1372 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1373 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1374 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1378 totaddrp = (unsigned int *)optval;
1379 totaddr = *totaddrp;
1380 sa = (struct sockaddr *)(totaddrp + 1);
1381 error = sctp_connectx_helper_find(inp, sa, totaddr, &num_v4, &num_v6, (unsigned int)(optsize - sizeof(int)));
1383 /* Already have or am bring up an association */
1384 SCTP_ASOC_CREATE_UNLOCK(inp);
1386 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1390 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1395 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1397 if (SCTP_IPV6_V6ONLY(inp)) {
1399 * if IPV6_V6ONLY flag, ignore connections destined
1400 * to a v4 addr or v4-mapped addr
1402 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1408 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1409 SCTP_PCB_FLAGS_UNBOUND) {
1410 /* Bind a ephemeral port */
1411 error = sctp_inpcb_bind(so, NULL, NULL, p);
1417 /* FIX ME: do we want to pass in a vrf on the connect call? */
1418 vrf_id = inp->def_vrf_id;
1421 /* We are GOOD to go */
1422 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1423 inp->sctp_ep.pre_open_stream_count,
1426 SCTP_INITIALIZE_AUTH_PARAMS);
1428 /* Gak! no memory */
1431 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1432 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1433 /* Set the connected flag so we can queue data */
1436 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1437 /* move to second address */
1438 switch (sa->sa_family) {
1441 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1446 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1454 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1455 /* Fill in the return id */
1459 a_id = (sctp_assoc_t *)optval;
1460 *a_id = sctp_get_associd(stcb);
1463 /* doing delayed connection */
1464 stcb->asoc.delayed_connection = 1;
1465 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1467 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1468 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1470 SCTP_TCB_UNLOCK(stcb);
1472 if (creat_lock_on) {
1473 SCTP_ASOC_CREATE_UNLOCK(inp);
1475 SCTP_INP_DECR_REF(inp);
1479 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1480 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1481 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1482 SCTP_INP_RLOCK(inp); \
1483 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1485 SCTP_TCB_LOCK(stcb); \
1487 SCTP_INP_RUNLOCK(inp); \
1488 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1489 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1490 if (stcb == NULL) { \
1491 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1501 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1502 if (size < sizeof(type)) { \
1503 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1507 destp = (type *)srcp; \
1512 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1515 struct sctp_inpcb *inp = NULL;
1517 struct sctp_tcb *stcb = NULL;
1519 if (optval == NULL) {
1520 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1524 inp = (struct sctp_inpcb *)so->so_pcb;
1526 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1533 case SCTP_AUTOCLOSE:
1534 case SCTP_EXPLICIT_EOR:
1535 case SCTP_AUTO_ASCONF:
1536 case SCTP_DISABLE_FRAGMENTS:
1537 case SCTP_I_WANT_MAPPED_V4_ADDR:
1538 case SCTP_USE_EXT_RCVINFO:
1539 SCTP_INP_RLOCK(inp);
1541 case SCTP_DISABLE_FRAGMENTS:
1542 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1544 case SCTP_I_WANT_MAPPED_V4_ADDR:
1545 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1547 case SCTP_AUTO_ASCONF:
1548 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1549 /* only valid for bound all sockets */
1550 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1552 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1557 case SCTP_EXPLICIT_EOR:
1558 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1561 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1563 case SCTP_USE_EXT_RCVINFO:
1564 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1566 case SCTP_AUTOCLOSE:
1567 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1568 val = sctp_ticks_to_secs(inp->sctp_ep.auto_close_time);
1574 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1575 error = ENOPROTOOPT;
1576 } /* end switch (sopt->sopt_name) */
1577 if (*optsize < sizeof(val)) {
1578 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1582 SCTP_INP_RUNLOCK(inp);
1584 /* return the option value */
1585 *(int *)optval = val;
1586 *optsize = sizeof(val);
1589 case SCTP_GET_PACKET_LOG:
1591 #ifdef SCTP_PACKET_LOGGING
1595 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1596 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1599 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1604 case SCTP_REUSE_PORT:
1608 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1609 /* Can't do this for a 1-m socket */
1613 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1614 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1615 *optsize = sizeof(uint32_t);
1618 case SCTP_PARTIAL_DELIVERY_POINT:
1622 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1623 *value = inp->partial_delivery_point;
1624 *optsize = sizeof(uint32_t);
1627 case SCTP_FRAGMENT_INTERLEAVE:
1631 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1632 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1633 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1634 *value = SCTP_FRAG_LEVEL_2;
1636 *value = SCTP_FRAG_LEVEL_1;
1639 *value = SCTP_FRAG_LEVEL_0;
1641 *optsize = sizeof(uint32_t);
1644 case SCTP_INTERLEAVING_SUPPORTED:
1646 struct sctp_assoc_value *av;
1648 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1649 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1652 av->assoc_value = stcb->asoc.idata_supported;
1653 SCTP_TCB_UNLOCK(stcb);
1655 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1656 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1657 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1658 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1659 SCTP_INP_RLOCK(inp);
1660 if (inp->idata_supported) {
1661 av->assoc_value = 1;
1663 av->assoc_value = 0;
1665 SCTP_INP_RUNLOCK(inp);
1667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1672 *optsize = sizeof(struct sctp_assoc_value);
1676 case SCTP_CMT_ON_OFF:
1678 struct sctp_assoc_value *av;
1680 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1681 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1683 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1684 SCTP_TCB_UNLOCK(stcb);
1686 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1687 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1688 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1689 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1690 SCTP_INP_RLOCK(inp);
1691 av->assoc_value = inp->sctp_cmt_on_off;
1692 SCTP_INP_RUNLOCK(inp);
1694 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1699 *optsize = sizeof(struct sctp_assoc_value);
1703 case SCTP_PLUGGABLE_CC:
1705 struct sctp_assoc_value *av;
1707 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1708 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1710 av->assoc_value = stcb->asoc.congestion_control_module;
1711 SCTP_TCB_UNLOCK(stcb);
1713 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1714 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1715 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1716 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1717 SCTP_INP_RLOCK(inp);
1718 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1719 SCTP_INP_RUNLOCK(inp);
1721 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1726 *optsize = sizeof(struct sctp_assoc_value);
1730 case SCTP_CC_OPTION:
1732 struct sctp_cc_option *cc_opt;
1734 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1735 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1739 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1742 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1743 *optsize = sizeof(struct sctp_cc_option);
1745 SCTP_TCB_UNLOCK(stcb);
1749 case SCTP_PLUGGABLE_SS:
1751 struct sctp_assoc_value *av;
1753 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1754 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1756 av->assoc_value = stcb->asoc.stream_scheduling_module;
1757 SCTP_TCB_UNLOCK(stcb);
1759 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1760 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1761 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1762 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1763 SCTP_INP_RLOCK(inp);
1764 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1765 SCTP_INP_RUNLOCK(inp);
1767 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1772 *optsize = sizeof(struct sctp_assoc_value);
1778 struct sctp_stream_value *av;
1780 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1781 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1783 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1784 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1785 &av->stream_value) < 0)) {
1786 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1789 *optsize = sizeof(struct sctp_stream_value);
1791 SCTP_TCB_UNLOCK(stcb);
1794 * Can't get stream value without
1797 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1802 case SCTP_GET_ADDR_LEN:
1804 struct sctp_assoc_value *av;
1806 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1809 if (av->assoc_value == AF_INET) {
1810 av->assoc_value = sizeof(struct sockaddr_in);
1815 if (av->assoc_value == AF_INET6) {
1816 av->assoc_value = sizeof(struct sockaddr_in6);
1821 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1823 *optsize = sizeof(struct sctp_assoc_value);
1827 case SCTP_GET_ASSOC_NUMBER:
1829 uint32_t *value, cnt;
1831 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1832 SCTP_INP_RLOCK(inp);
1833 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1834 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1835 /* Can't do this for a 1-1 socket */
1837 SCTP_INP_RUNLOCK(inp);
1841 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1844 SCTP_INP_RUNLOCK(inp);
1846 *optsize = sizeof(uint32_t);
1849 case SCTP_GET_ASSOC_ID_LIST:
1851 struct sctp_assoc_ids *ids;
1855 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1856 SCTP_INP_RLOCK(inp);
1857 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1858 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1859 /* Can't do this for a 1-1 socket */
1861 SCTP_INP_RUNLOCK(inp);
1865 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1866 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1868 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1871 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1880 SCTP_INP_RUNLOCK(inp);
1882 ids->gaids_number_of_ids = at;
1883 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1889 struct sctp_assoc_value *av;
1891 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1892 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1895 av->assoc_value = stcb->asoc.context;
1896 SCTP_TCB_UNLOCK(stcb);
1898 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1899 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1900 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1901 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
1902 SCTP_INP_RLOCK(inp);
1903 av->assoc_value = inp->sctp_context;
1904 SCTP_INP_RUNLOCK(inp);
1906 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1911 *optsize = sizeof(struct sctp_assoc_value);
1917 uint32_t *default_vrfid;
1919 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1920 *default_vrfid = inp->def_vrf_id;
1921 *optsize = sizeof(uint32_t);
1924 case SCTP_GET_ASOC_VRF:
1926 struct sctp_assoc_value *id;
1928 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1929 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1932 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1934 id->assoc_value = stcb->asoc.vrf_id;
1935 SCTP_TCB_UNLOCK(stcb);
1936 *optsize = sizeof(struct sctp_assoc_value);
1940 case SCTP_GET_VRF_IDS:
1942 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1946 case SCTP_GET_NONCE_VALUES:
1948 struct sctp_get_nonce_values *gnv;
1950 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1951 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1954 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1955 gnv->gn_local_tag = stcb->asoc.my_vtag;
1956 SCTP_TCB_UNLOCK(stcb);
1957 *optsize = sizeof(struct sctp_get_nonce_values);
1959 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1964 case SCTP_DELAYED_SACK:
1966 struct sctp_sack_info *sack;
1968 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1969 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1971 sack->sack_delay = stcb->asoc.delayed_ack;
1972 sack->sack_freq = stcb->asoc.sack_freq;
1973 SCTP_TCB_UNLOCK(stcb);
1975 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1976 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1977 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
1978 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC))) {
1979 SCTP_INP_RLOCK(inp);
1980 sack->sack_delay = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1981 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
1982 SCTP_INP_RUNLOCK(inp);
1984 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1989 *optsize = sizeof(struct sctp_sack_info);
1993 case SCTP_GET_SNDBUF_USE:
1995 struct sctp_sockstat *ss;
1997 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
1998 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2001 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2002 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2003 stcb->asoc.size_on_all_streams);
2004 SCTP_TCB_UNLOCK(stcb);
2005 *optsize = sizeof(struct sctp_sockstat);
2007 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2012 case SCTP_MAX_BURST:
2014 struct sctp_assoc_value *av;
2016 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2017 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2020 av->assoc_value = stcb->asoc.max_burst;
2021 SCTP_TCB_UNLOCK(stcb);
2023 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2024 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2025 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2026 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2027 SCTP_INP_RLOCK(inp);
2028 av->assoc_value = inp->sctp_ep.max_burst;
2029 SCTP_INP_RUNLOCK(inp);
2031 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2036 *optsize = sizeof(struct sctp_assoc_value);
2042 struct sctp_assoc_value *av;
2045 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2046 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2049 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2050 SCTP_TCB_UNLOCK(stcb);
2052 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2053 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2054 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2055 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
2056 SCTP_INP_RLOCK(inp);
2057 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2058 ovh = SCTP_MED_OVERHEAD;
2060 ovh = SCTP_MED_V4_OVERHEAD;
2062 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2063 av->assoc_value = 0;
2065 av->assoc_value = inp->sctp_frag_point - ovh;
2066 SCTP_INP_RUNLOCK(inp);
2068 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2073 *optsize = sizeof(struct sctp_assoc_value);
2077 case SCTP_GET_STAT_LOG:
2078 error = sctp_fill_stat_log(optval, optsize);
2082 struct sctp_event_subscribe *events;
2084 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2085 memset(events, 0, sizeof(struct sctp_event_subscribe));
2086 SCTP_INP_RLOCK(inp);
2087 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2088 events->sctp_data_io_event = 1;
2090 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2091 events->sctp_association_event = 1;
2093 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2094 events->sctp_address_event = 1;
2096 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2097 events->sctp_send_failure_event = 1;
2099 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2100 events->sctp_peer_error_event = 1;
2102 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2103 events->sctp_shutdown_event = 1;
2105 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2106 events->sctp_partial_delivery_event = 1;
2108 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2109 events->sctp_adaptation_layer_event = 1;
2111 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2112 events->sctp_authentication_event = 1;
2114 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2115 events->sctp_sender_dry_event = 1;
2117 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2118 events->sctp_stream_reset_event = 1;
2119 SCTP_INP_RUNLOCK(inp);
2120 *optsize = sizeof(struct sctp_event_subscribe);
2123 case SCTP_ADAPTATION_LAYER:
2127 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2129 SCTP_INP_RLOCK(inp);
2130 *value = inp->sctp_ep.adaptation_layer_indicator;
2131 SCTP_INP_RUNLOCK(inp);
2132 *optsize = sizeof(uint32_t);
2135 case SCTP_SET_INITIAL_DBG_SEQ:
2139 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2140 SCTP_INP_RLOCK(inp);
2141 *value = inp->sctp_ep.initial_sequence_debug;
2142 SCTP_INP_RUNLOCK(inp);
2143 *optsize = sizeof(uint32_t);
2146 case SCTP_GET_LOCAL_ADDR_SIZE:
2150 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2151 SCTP_INP_RLOCK(inp);
2152 *value = sctp_count_max_addresses(inp);
2153 SCTP_INP_RUNLOCK(inp);
2154 *optsize = sizeof(uint32_t);
2157 case SCTP_GET_REMOTE_ADDR_SIZE:
2161 struct sctp_nets *net;
2163 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2164 /* FIXME MT: change to sctp_assoc_value? */
2165 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2169 /* Count the sizes */
2170 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2171 switch (net->ro._l_addr.sa.sa_family) {
2175 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2176 size += sizeof(struct sockaddr_in6);
2178 size += sizeof(struct sockaddr_in);
2181 size += sizeof(struct sockaddr_in);
2187 size += sizeof(struct sockaddr_in6);
2194 SCTP_TCB_UNLOCK(stcb);
2195 *value = (uint32_t)size;
2196 *optsize = sizeof(uint32_t);
2198 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2203 case SCTP_GET_PEER_ADDRESSES:
2205 * Get the address information, an array is passed in to
2206 * fill up we pack it.
2210 struct sockaddr_storage *sas;
2211 struct sctp_nets *net;
2212 struct sctp_getaddresses *saddr;
2214 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2215 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2218 left = (*optsize) - sizeof(sctp_assoc_t);
2219 *optsize = sizeof(sctp_assoc_t);
2220 sas = (struct sockaddr_storage *)&saddr->addr[0];
2222 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2223 switch (net->ro._l_addr.sa.sa_family) {
2227 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2228 cpsz = sizeof(struct sockaddr_in6);
2230 cpsz = sizeof(struct sockaddr_in);
2233 cpsz = sizeof(struct sockaddr_in);
2239 cpsz = sizeof(struct sockaddr_in6);
2250 /* not enough room. */
2253 #if defined(INET) && defined(INET6)
2254 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2255 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2256 /* Must map the address */
2257 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2258 (struct sockaddr_in6 *)sas);
2260 memcpy(sas, &net->ro._l_addr, cpsz);
2263 memcpy(sas, &net->ro._l_addr, cpsz);
2265 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2267 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2271 SCTP_TCB_UNLOCK(stcb);
2273 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2278 case SCTP_GET_LOCAL_ADDRESSES:
2280 size_t limit, actual;
2281 struct sockaddr_storage *sas;
2282 struct sctp_getaddresses *saddr;
2284 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2285 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2287 sas = (struct sockaddr_storage *)&saddr->addr[0];
2288 limit = *optsize - sizeof(sctp_assoc_t);
2289 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2291 SCTP_TCB_UNLOCK(stcb);
2293 *optsize = sizeof(sctp_assoc_t) + actual;
2296 case SCTP_PEER_ADDR_PARAMS:
2298 struct sctp_paddrparams *paddrp;
2299 struct sctp_nets *net;
2300 struct sockaddr *addr;
2301 #if defined(INET) && defined(INET6)
2302 struct sockaddr_in sin_store;
2305 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2306 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2308 #if defined(INET) && defined(INET6)
2309 if (paddrp->spp_address.ss_family == AF_INET6) {
2310 struct sockaddr_in6 *sin6;
2312 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2313 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2314 in6_sin6_2_sin(&sin_store, sin6);
2315 addr = (struct sockaddr *)&sin_store;
2317 addr = (struct sockaddr *)&paddrp->spp_address;
2320 addr = (struct sockaddr *)&paddrp->spp_address;
2323 addr = (struct sockaddr *)&paddrp->spp_address;
2326 net = sctp_findnet(stcb, addr);
2329 * We increment here since
2330 * sctp_findassociation_ep_addr() wil do a
2331 * decrement if it finds the stcb as long as
2332 * the locked tcb (last argument) is NOT a
2336 SCTP_INP_INCR_REF(inp);
2337 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2339 SCTP_INP_DECR_REF(inp);
2342 if ((stcb != NULL) && (net == NULL)) {
2344 if (addr->sa_family == AF_INET) {
2345 struct sockaddr_in *sin;
2347 sin = (struct sockaddr_in *)addr;
2348 if (sin->sin_addr.s_addr != INADDR_ANY) {
2350 SCTP_TCB_UNLOCK(stcb);
2351 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2357 if (addr->sa_family == AF_INET6) {
2358 struct sockaddr_in6 *sin6;
2360 sin6 = (struct sockaddr_in6 *)addr;
2361 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2363 SCTP_TCB_UNLOCK(stcb);
2364 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2370 error = EAFNOSUPPORT;
2371 SCTP_TCB_UNLOCK(stcb);
2372 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2378 /* Applies to the specific association */
2379 paddrp->spp_flags = 0;
2381 paddrp->spp_hbinterval = net->heart_beat_delay;
2382 paddrp->spp_pathmaxrxt = net->failure_threshold;
2383 paddrp->spp_pathmtu = net->mtu;
2384 switch (net->ro._l_addr.sa.sa_family) {
2387 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2392 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2398 /* get flags for HB */
2399 if (net->dest_state & SCTP_ADDR_NOHB) {
2400 paddrp->spp_flags |= SPP_HB_DISABLE;
2402 paddrp->spp_flags |= SPP_HB_ENABLE;
2404 /* get flags for PMTU */
2405 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2406 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2408 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2410 if (net->dscp & 0x01) {
2411 paddrp->spp_dscp = net->dscp & 0xfc;
2412 paddrp->spp_flags |= SPP_DSCP;
2415 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2416 (net->flowlabel & 0x80000000)) {
2417 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2418 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2423 * No destination so return default
2426 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2427 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2428 if (stcb->asoc.default_dscp & 0x01) {
2429 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2430 paddrp->spp_flags |= SPP_DSCP;
2433 if (stcb->asoc.default_flowlabel & 0x80000000) {
2434 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2435 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2438 /* default settings should be these */
2439 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2440 paddrp->spp_flags |= SPP_HB_DISABLE;
2442 paddrp->spp_flags |= SPP_HB_ENABLE;
2444 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2445 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2447 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2449 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2451 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2452 SCTP_TCB_UNLOCK(stcb);
2454 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2455 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2456 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2457 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
2458 /* Use endpoint defaults */
2459 SCTP_INP_RLOCK(inp);
2460 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2461 paddrp->spp_hbinterval = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2462 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2463 /* get inp's default */
2464 if (inp->sctp_ep.default_dscp & 0x01) {
2465 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2466 paddrp->spp_flags |= SPP_DSCP;
2469 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2470 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2471 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2472 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2475 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2477 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2478 paddrp->spp_flags |= SPP_HB_ENABLE;
2480 paddrp->spp_flags |= SPP_HB_DISABLE;
2482 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2483 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2485 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2487 SCTP_INP_RUNLOCK(inp);
2489 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2494 *optsize = sizeof(struct sctp_paddrparams);
2498 case SCTP_GET_PEER_ADDR_INFO:
2500 struct sctp_paddrinfo *paddri;
2501 struct sctp_nets *net;
2502 struct sockaddr *addr;
2503 #if defined(INET) && defined(INET6)
2504 struct sockaddr_in sin_store;
2507 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2508 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2510 #if defined(INET) && defined(INET6)
2511 if (paddri->spinfo_address.ss_family == AF_INET6) {
2512 struct sockaddr_in6 *sin6;
2514 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2515 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2516 in6_sin6_2_sin(&sin_store, sin6);
2517 addr = (struct sockaddr *)&sin_store;
2519 addr = (struct sockaddr *)&paddri->spinfo_address;
2522 addr = (struct sockaddr *)&paddri->spinfo_address;
2525 addr = (struct sockaddr *)&paddri->spinfo_address;
2528 net = sctp_findnet(stcb, addr);
2531 * We increment here since
2532 * sctp_findassociation_ep_addr() wil do a
2533 * decrement if it finds the stcb as long as
2534 * the locked tcb (last argument) is NOT a
2538 SCTP_INP_INCR_REF(inp);
2539 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2541 SCTP_INP_DECR_REF(inp);
2545 if ((stcb != NULL) && (net != NULL)) {
2546 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2547 /* It's unconfirmed */
2548 paddri->spinfo_state = SCTP_UNCONFIRMED;
2549 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2551 paddri->spinfo_state = SCTP_ACTIVE;
2554 paddri->spinfo_state = SCTP_INACTIVE;
2556 paddri->spinfo_cwnd = net->cwnd;
2557 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2558 paddri->spinfo_rto = net->RTO;
2559 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2560 paddri->spinfo_mtu = net->mtu;
2561 switch (addr->sa_family) {
2564 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2569 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2575 SCTP_TCB_UNLOCK(stcb);
2576 *optsize = sizeof(struct sctp_paddrinfo);
2579 SCTP_TCB_UNLOCK(stcb);
2581 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2586 case SCTP_PCB_STATUS:
2588 struct sctp_pcbinfo *spcb;
2590 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2591 sctp_fill_pcbinfo(spcb);
2592 *optsize = sizeof(struct sctp_pcbinfo);
2597 struct sctp_nets *net;
2598 struct sctp_status *sstat;
2600 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2601 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2604 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2608 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2609 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2610 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2611 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2613 * We can't include chunks that have been passed to
2614 * the socket layer. Only things in queue.
2616 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2617 stcb->asoc.cnt_on_all_streams);
2620 sstat->sstat_instrms = stcb->asoc.streamincnt;
2621 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2622 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2623 net = stcb->asoc.primary_destination;
2625 memcpy(&sstat->sstat_primary.spinfo_address,
2627 ((struct sockaddr *)(&net->ro._l_addr))->sa_len);
2628 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2630 * Again the user can get info from
2631 * sctp_constants.h for what the state of
2634 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2635 /* It's unconfirmed */
2636 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2637 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2639 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2642 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2644 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2645 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2646 sstat->sstat_primary.spinfo_rto = net->RTO;
2647 sstat->sstat_primary.spinfo_mtu = net->mtu;
2648 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2651 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2656 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2663 memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo));
2665 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2666 SCTP_TCB_UNLOCK(stcb);
2667 *optsize = sizeof(struct sctp_status);
2672 struct sctp_rtoinfo *srto;
2674 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2675 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2678 srto->srto_initial = stcb->asoc.initial_rto;
2679 srto->srto_max = stcb->asoc.maxrto;
2680 srto->srto_min = stcb->asoc.minrto;
2681 SCTP_TCB_UNLOCK(stcb);
2683 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2684 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2685 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2686 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
2687 SCTP_INP_RLOCK(inp);
2688 srto->srto_initial = inp->sctp_ep.initial_rto;
2689 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2690 srto->srto_min = inp->sctp_ep.sctp_minrto;
2691 SCTP_INP_RUNLOCK(inp);
2693 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2698 *optsize = sizeof(struct sctp_rtoinfo);
2704 struct sctp_timeouts *stimo;
2706 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2707 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2710 stimo->stimo_init = stcb->asoc.timoinit;
2711 stimo->stimo_data = stcb->asoc.timodata;
2712 stimo->stimo_sack = stcb->asoc.timosack;
2713 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2714 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2715 stimo->stimo_cookie = stcb->asoc.timocookie;
2716 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2717 SCTP_TCB_UNLOCK(stcb);
2718 *optsize = sizeof(struct sctp_timeouts);
2720 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2725 case SCTP_ASSOCINFO:
2727 struct sctp_assocparams *sasoc;
2729 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2730 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2733 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(stcb->asoc.cookie_life);
2734 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2735 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2736 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2737 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2738 SCTP_TCB_UNLOCK(stcb);
2740 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2741 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2742 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2743 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
2744 SCTP_INP_RLOCK(inp);
2745 sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(inp->sctp_ep.def_cookie_life);
2746 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2747 sasoc->sasoc_number_peer_destinations = 0;
2748 sasoc->sasoc_peer_rwnd = 0;
2749 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2750 SCTP_INP_RUNLOCK(inp);
2752 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2757 *optsize = sizeof(struct sctp_assocparams);
2761 case SCTP_DEFAULT_SEND_PARAM:
2763 struct sctp_sndrcvinfo *s_info;
2765 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2766 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2769 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2770 SCTP_TCB_UNLOCK(stcb);
2772 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2773 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2774 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2775 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC))) {
2776 SCTP_INP_RLOCK(inp);
2777 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2778 SCTP_INP_RUNLOCK(inp);
2780 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2785 *optsize = sizeof(struct sctp_sndrcvinfo);
2791 struct sctp_initmsg *sinit;
2793 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2794 SCTP_INP_RLOCK(inp);
2795 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2796 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2797 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2798 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2799 SCTP_INP_RUNLOCK(inp);
2800 *optsize = sizeof(struct sctp_initmsg);
2803 case SCTP_PRIMARY_ADDR:
2804 /* we allow a "get" operation on this */
2806 struct sctp_setprim *ssp;
2808 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2809 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2812 union sctp_sockstore *addr;
2814 addr = &stcb->asoc.primary_destination->ro._l_addr;
2815 switch (addr->sa.sa_family) {
2819 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2820 in6_sin_2_v4mapsin6(&addr->sin,
2821 (struct sockaddr_in6 *)&ssp->ssp_addr);
2823 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2826 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2832 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2838 SCTP_TCB_UNLOCK(stcb);
2839 *optsize = sizeof(struct sctp_setprim);
2841 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2846 case SCTP_HMAC_IDENT:
2848 struct sctp_hmacalgo *shmac;
2849 sctp_hmaclist_t *hmaclist;
2853 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2855 SCTP_INP_RLOCK(inp);
2856 hmaclist = inp->sctp_ep.local_hmacs;
2857 if (hmaclist == NULL) {
2858 /* no HMACs to return */
2859 *optsize = sizeof(*shmac);
2860 SCTP_INP_RUNLOCK(inp);
2863 /* is there room for all of the hmac ids? */
2864 size = sizeof(*shmac) + (hmaclist->num_algo *
2865 sizeof(shmac->shmac_idents[0]));
2866 if ((size_t)(*optsize) < size) {
2867 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2869 SCTP_INP_RUNLOCK(inp);
2872 /* copy in the list */
2873 shmac->shmac_number_of_idents = hmaclist->num_algo;
2874 for (i = 0; i < hmaclist->num_algo; i++) {
2875 shmac->shmac_idents[i] = hmaclist->hmac[i];
2877 SCTP_INP_RUNLOCK(inp);
2881 case SCTP_AUTH_ACTIVE_KEY:
2883 struct sctp_authkeyid *scact;
2885 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2886 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2889 /* get the active key on the assoc */
2890 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2891 SCTP_TCB_UNLOCK(stcb);
2893 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2894 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2895 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2896 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC))) {
2897 /* get the endpoint active key */
2898 SCTP_INP_RLOCK(inp);
2899 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2900 SCTP_INP_RUNLOCK(inp);
2902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2907 *optsize = sizeof(struct sctp_authkeyid);
2911 case SCTP_LOCAL_AUTH_CHUNKS:
2913 struct sctp_authchunks *sac;
2914 sctp_auth_chklist_t *chklist = NULL;
2917 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2918 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2921 /* get off the assoc */
2922 chklist = stcb->asoc.local_auth_chunks;
2923 /* is there enough space? */
2924 size = sctp_auth_get_chklist_size(chklist);
2925 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2927 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2929 /* copy in the chunks */
2930 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2931 sac->gauth_number_of_chunks = (uint32_t)size;
2932 *optsize = sizeof(struct sctp_authchunks) + size;
2934 SCTP_TCB_UNLOCK(stcb);
2936 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2937 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2938 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
2939 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC))) {
2940 /* get off the endpoint */
2941 SCTP_INP_RLOCK(inp);
2942 chklist = inp->sctp_ep.local_auth_chunks;
2943 /* is there enough space? */
2944 size = sctp_auth_get_chklist_size(chklist);
2945 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2947 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2949 /* copy in the chunks */
2950 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2951 sac->gauth_number_of_chunks = (uint32_t)size;
2952 *optsize = sizeof(struct sctp_authchunks) + size;
2954 SCTP_INP_RUNLOCK(inp);
2956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2962 case SCTP_PEER_AUTH_CHUNKS:
2964 struct sctp_authchunks *sac;
2965 sctp_auth_chklist_t *chklist = NULL;
2968 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2969 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2972 /* get off the assoc */
2973 chklist = stcb->asoc.peer_auth_chunks;
2974 /* is there enough space? */
2975 size = sctp_auth_get_chklist_size(chklist);
2976 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2978 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2980 /* copy in the chunks */
2981 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2982 sac->gauth_number_of_chunks = (uint32_t)size;
2983 *optsize = sizeof(struct sctp_authchunks) + size;
2985 SCTP_TCB_UNLOCK(stcb);
2987 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2994 struct sctp_event *event;
2995 uint32_t event_type;
2997 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2998 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3000 switch (event->se_type) {
3001 case SCTP_ASSOC_CHANGE:
3002 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3004 case SCTP_PEER_ADDR_CHANGE:
3005 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3007 case SCTP_REMOTE_ERROR:
3008 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3010 case SCTP_SEND_FAILED:
3011 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3013 case SCTP_SHUTDOWN_EVENT:
3014 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3016 case SCTP_ADAPTATION_INDICATION:
3017 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3019 case SCTP_PARTIAL_DELIVERY_EVENT:
3020 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3022 case SCTP_AUTHENTICATION_EVENT:
3023 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3025 case SCTP_STREAM_RESET_EVENT:
3026 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3028 case SCTP_SENDER_DRY_EVENT:
3029 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3031 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3033 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3036 case SCTP_ASSOC_RESET_EVENT:
3037 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3039 case SCTP_STREAM_CHANGE_EVENT:
3040 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3042 case SCTP_SEND_FAILED_EVENT:
3043 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3047 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3051 if (event_type > 0) {
3053 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3055 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3056 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3057 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3058 (event->se_assoc_id == SCTP_FUTURE_ASSOC))) {
3059 SCTP_INP_RLOCK(inp);
3060 event->se_on = sctp_is_feature_on(inp, event_type);
3061 SCTP_INP_RUNLOCK(inp);
3063 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3069 SCTP_TCB_UNLOCK(stcb);
3072 *optsize = sizeof(struct sctp_event);
3076 case SCTP_RECVRCVINFO:
3080 if (*optsize < sizeof(int)) {
3081 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3084 SCTP_INP_RLOCK(inp);
3085 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3086 SCTP_INP_RUNLOCK(inp);
3089 /* return the option value */
3090 *(int *)optval = onoff;
3091 *optsize = sizeof(int);
3095 case SCTP_RECVNXTINFO:
3099 if (*optsize < sizeof(int)) {
3100 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3103 SCTP_INP_RLOCK(inp);
3104 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3105 SCTP_INP_RUNLOCK(inp);
3108 /* return the option value */
3109 *(int *)optval = onoff;
3110 *optsize = sizeof(int);
3114 case SCTP_DEFAULT_SNDINFO:
3116 struct sctp_sndinfo *info;
3118 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3119 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3122 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3123 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3124 info->snd_flags &= 0xfff0;
3125 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3126 info->snd_context = stcb->asoc.def_send.sinfo_context;
3127 SCTP_TCB_UNLOCK(stcb);
3129 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3130 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3131 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3132 (info->snd_assoc_id == SCTP_FUTURE_ASSOC))) {
3133 SCTP_INP_RLOCK(inp);
3134 info->snd_sid = inp->def_send.sinfo_stream;
3135 info->snd_flags = inp->def_send.sinfo_flags;
3136 info->snd_flags &= 0xfff0;
3137 info->snd_ppid = inp->def_send.sinfo_ppid;
3138 info->snd_context = inp->def_send.sinfo_context;
3139 SCTP_INP_RUNLOCK(inp);
3141 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3146 *optsize = sizeof(struct sctp_sndinfo);
3150 case SCTP_DEFAULT_PRINFO:
3152 struct sctp_default_prinfo *info;
3154 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3155 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3158 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3159 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3160 SCTP_TCB_UNLOCK(stcb);
3162 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3163 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3164 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3165 (info->pr_assoc_id == SCTP_FUTURE_ASSOC))) {
3166 SCTP_INP_RLOCK(inp);
3167 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3168 info->pr_value = inp->def_send.sinfo_timetolive;
3169 SCTP_INP_RUNLOCK(inp);
3171 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3176 *optsize = sizeof(struct sctp_default_prinfo);
3180 case SCTP_PEER_ADDR_THLDS:
3182 struct sctp_paddrthlds *thlds;
3183 struct sctp_nets *net;
3184 struct sockaddr *addr;
3185 #if defined(INET) && defined(INET6)
3186 struct sockaddr_in sin_store;
3189 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3190 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3192 #if defined(INET) && defined(INET6)
3193 if (thlds->spt_address.ss_family == AF_INET6) {
3194 struct sockaddr_in6 *sin6;
3196 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3197 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3198 in6_sin6_2_sin(&sin_store, sin6);
3199 addr = (struct sockaddr *)&sin_store;
3201 addr = (struct sockaddr *)&thlds->spt_address;
3204 addr = (struct sockaddr *)&thlds->spt_address;
3207 addr = (struct sockaddr *)&thlds->spt_address;
3210 net = sctp_findnet(stcb, addr);
3213 * We increment here since
3214 * sctp_findassociation_ep_addr() wil do a
3215 * decrement if it finds the stcb as long as
3216 * the locked tcb (last argument) is NOT a
3220 SCTP_INP_INCR_REF(inp);
3221 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3223 SCTP_INP_DECR_REF(inp);
3226 if ((stcb != NULL) && (net == NULL)) {
3228 if (addr->sa_family == AF_INET) {
3229 struct sockaddr_in *sin;
3231 sin = (struct sockaddr_in *)addr;
3232 if (sin->sin_addr.s_addr != INADDR_ANY) {
3234 SCTP_TCB_UNLOCK(stcb);
3235 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3241 if (addr->sa_family == AF_INET6) {
3242 struct sockaddr_in6 *sin6;
3244 sin6 = (struct sockaddr_in6 *)addr;
3245 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3247 SCTP_TCB_UNLOCK(stcb);
3248 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3254 error = EAFNOSUPPORT;
3255 SCTP_TCB_UNLOCK(stcb);
3256 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3263 thlds->spt_pathmaxrxt = net->failure_threshold;
3264 thlds->spt_pathpfthld = net->pf_threshold;
3265 thlds->spt_pathcpthld = 0xffff;
3267 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3268 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3269 thlds->spt_pathcpthld = 0xffff;
3271 thlds->spt_assoc_id = sctp_get_associd(stcb);
3272 SCTP_TCB_UNLOCK(stcb);
3274 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3275 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3276 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3277 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
3278 /* Use endpoint defaults */
3279 SCTP_INP_RLOCK(inp);
3280 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3281 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3282 thlds->spt_pathcpthld = 0xffff;
3283 SCTP_INP_RUNLOCK(inp);
3285 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3290 *optsize = sizeof(struct sctp_paddrthlds);
3294 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3296 struct sctp_udpencaps *encaps;
3297 struct sctp_nets *net;
3298 struct sockaddr *addr;
3299 #if defined(INET) && defined(INET6)
3300 struct sockaddr_in sin_store;
3303 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3304 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3306 #if defined(INET) && defined(INET6)
3307 if (encaps->sue_address.ss_family == AF_INET6) {
3308 struct sockaddr_in6 *sin6;
3310 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3311 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3312 in6_sin6_2_sin(&sin_store, sin6);
3313 addr = (struct sockaddr *)&sin_store;
3315 addr = (struct sockaddr *)&encaps->sue_address;
3318 addr = (struct sockaddr *)&encaps->sue_address;
3321 addr = (struct sockaddr *)&encaps->sue_address;
3324 net = sctp_findnet(stcb, addr);
3327 * We increment here since
3328 * sctp_findassociation_ep_addr() wil do a
3329 * decrement if it finds the stcb as long as
3330 * the locked tcb (last argument) is NOT a
3334 SCTP_INP_INCR_REF(inp);
3335 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3337 SCTP_INP_DECR_REF(inp);
3340 if ((stcb != NULL) && (net == NULL)) {
3342 if (addr->sa_family == AF_INET) {
3343 struct sockaddr_in *sin;
3345 sin = (struct sockaddr_in *)addr;
3346 if (sin->sin_addr.s_addr != INADDR_ANY) {
3348 SCTP_TCB_UNLOCK(stcb);
3349 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3355 if (addr->sa_family == AF_INET6) {
3356 struct sockaddr_in6 *sin6;
3358 sin6 = (struct sockaddr_in6 *)addr;
3359 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3361 SCTP_TCB_UNLOCK(stcb);
3362 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3368 error = EAFNOSUPPORT;
3369 SCTP_TCB_UNLOCK(stcb);
3370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3377 encaps->sue_port = net->port;
3379 encaps->sue_port = stcb->asoc.port;
3381 SCTP_TCB_UNLOCK(stcb);
3383 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3384 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3385 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3386 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
3387 SCTP_INP_RLOCK(inp);
3388 encaps->sue_port = inp->sctp_ep.port;
3389 SCTP_INP_RUNLOCK(inp);
3391 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3396 *optsize = sizeof(struct sctp_udpencaps);
3400 case SCTP_ECN_SUPPORTED:
3402 struct sctp_assoc_value *av;
3404 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3405 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3408 av->assoc_value = stcb->asoc.ecn_supported;
3409 SCTP_TCB_UNLOCK(stcb);
3411 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3412 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3413 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3414 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3415 SCTP_INP_RLOCK(inp);
3416 av->assoc_value = inp->ecn_supported;
3417 SCTP_INP_RUNLOCK(inp);
3419 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3424 *optsize = sizeof(struct sctp_assoc_value);
3428 case SCTP_PR_SUPPORTED:
3430 struct sctp_assoc_value *av;
3432 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3433 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3436 av->assoc_value = stcb->asoc.prsctp_supported;
3437 SCTP_TCB_UNLOCK(stcb);
3439 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3440 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3441 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3442 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3443 SCTP_INP_RLOCK(inp);
3444 av->assoc_value = inp->prsctp_supported;
3445 SCTP_INP_RUNLOCK(inp);
3447 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3452 *optsize = sizeof(struct sctp_assoc_value);
3456 case SCTP_AUTH_SUPPORTED:
3458 struct sctp_assoc_value *av;
3460 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3461 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3464 av->assoc_value = stcb->asoc.auth_supported;
3465 SCTP_TCB_UNLOCK(stcb);
3467 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3468 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3469 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3470 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3471 SCTP_INP_RLOCK(inp);
3472 av->assoc_value = inp->auth_supported;
3473 SCTP_INP_RUNLOCK(inp);
3475 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3480 *optsize = sizeof(struct sctp_assoc_value);
3484 case SCTP_ASCONF_SUPPORTED:
3486 struct sctp_assoc_value *av;
3488 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3489 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3492 av->assoc_value = stcb->asoc.asconf_supported;
3493 SCTP_TCB_UNLOCK(stcb);
3495 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3496 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3497 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3498 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3499 SCTP_INP_RLOCK(inp);
3500 av->assoc_value = inp->asconf_supported;
3501 SCTP_INP_RUNLOCK(inp);
3503 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3508 *optsize = sizeof(struct sctp_assoc_value);
3512 case SCTP_RECONFIG_SUPPORTED:
3514 struct sctp_assoc_value *av;
3516 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3517 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3520 av->assoc_value = stcb->asoc.reconfig_supported;
3521 SCTP_TCB_UNLOCK(stcb);
3523 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3524 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3525 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3526 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3527 SCTP_INP_RLOCK(inp);
3528 av->assoc_value = inp->reconfig_supported;
3529 SCTP_INP_RUNLOCK(inp);
3531 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3536 *optsize = sizeof(struct sctp_assoc_value);
3540 case SCTP_NRSACK_SUPPORTED:
3542 struct sctp_assoc_value *av;
3544 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3545 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3548 av->assoc_value = stcb->asoc.nrsack_supported;
3549 SCTP_TCB_UNLOCK(stcb);
3551 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3552 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3553 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3554 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3555 SCTP_INP_RLOCK(inp);
3556 av->assoc_value = inp->nrsack_supported;
3557 SCTP_INP_RUNLOCK(inp);
3559 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3564 *optsize = sizeof(struct sctp_assoc_value);
3568 case SCTP_PKTDROP_SUPPORTED:
3570 struct sctp_assoc_value *av;
3572 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3573 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3576 av->assoc_value = stcb->asoc.pktdrop_supported;
3577 SCTP_TCB_UNLOCK(stcb);
3579 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3580 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3581 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3582 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3583 SCTP_INP_RLOCK(inp);
3584 av->assoc_value = inp->pktdrop_supported;
3585 SCTP_INP_RUNLOCK(inp);
3587 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3592 *optsize = sizeof(struct sctp_assoc_value);
3596 case SCTP_ENABLE_STREAM_RESET:
3598 struct sctp_assoc_value *av;
3600 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3601 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3604 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3605 SCTP_TCB_UNLOCK(stcb);
3607 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3608 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3609 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3610 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3611 SCTP_INP_RLOCK(inp);
3612 av->assoc_value = (uint32_t)inp->local_strreset_support;
3613 SCTP_INP_RUNLOCK(inp);
3615 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3620 *optsize = sizeof(struct sctp_assoc_value);
3624 case SCTP_PR_STREAM_STATUS:
3626 struct sctp_prstatus *sprstat;
3630 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3631 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3633 sid = sprstat->sprstat_sid;
3634 policy = sprstat->sprstat_policy;
3635 #if defined(SCTP_DETAILED_STR_STATS)
3636 if ((stcb != NULL) &&
3637 (sid < stcb->asoc.streamoutcnt) &&
3638 (policy != SCTP_PR_SCTP_NONE) &&
3639 ((policy <= SCTP_PR_SCTP_MAX) ||
3640 (policy == SCTP_PR_SCTP_ALL))) {
3641 if (policy == SCTP_PR_SCTP_ALL) {
3642 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3643 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3645 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3646 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3649 if ((stcb != NULL) &&
3650 (sid < stcb->asoc.streamoutcnt) &&
3651 (policy == SCTP_PR_SCTP_ALL)) {
3652 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3653 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3656 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3660 SCTP_TCB_UNLOCK(stcb);
3663 *optsize = sizeof(struct sctp_prstatus);
3667 case SCTP_PR_ASSOC_STATUS:
3669 struct sctp_prstatus *sprstat;
3672 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3673 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3675 policy = sprstat->sprstat_policy;
3676 if ((stcb != NULL) &&
3677 (policy != SCTP_PR_SCTP_NONE) &&
3678 ((policy <= SCTP_PR_SCTP_MAX) ||
3679 (policy == SCTP_PR_SCTP_ALL))) {
3680 if (policy == SCTP_PR_SCTP_ALL) {
3681 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3682 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3684 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3685 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3688 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3692 SCTP_TCB_UNLOCK(stcb);
3695 *optsize = sizeof(struct sctp_prstatus);
3701 struct sctp_assoc_value *av;
3703 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3704 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3707 av->assoc_value = stcb->asoc.max_cwnd;
3708 SCTP_TCB_UNLOCK(stcb);
3710 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3711 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3712 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3713 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3714 SCTP_INP_RLOCK(inp);
3715 av->assoc_value = inp->max_cwnd;
3716 SCTP_INP_RUNLOCK(inp);
3718 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3723 *optsize = sizeof(struct sctp_assoc_value);
3728 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3729 error = ENOPROTOOPT;
3731 } /* end switch (sopt->sopt_name) */
3739 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3744 struct sctp_tcb *stcb = NULL;
3745 struct sctp_inpcb *inp = NULL;
3748 if (optval == NULL) {
3749 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3752 inp = (struct sctp_inpcb *)so->so_pcb;
3754 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3757 vrf_id = inp->def_vrf_id;
3762 case SCTP_AUTOCLOSE:
3763 case SCTP_AUTO_ASCONF:
3764 case SCTP_EXPLICIT_EOR:
3765 case SCTP_DISABLE_FRAGMENTS:
3766 case SCTP_USE_EXT_RCVINFO:
3767 case SCTP_I_WANT_MAPPED_V4_ADDR:
3768 /* copy in the option value */
3769 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3774 case SCTP_DISABLE_FRAGMENTS:
3775 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3777 case SCTP_AUTO_ASCONF:
3779 * NOTE: we don't really support this flag
3781 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3782 /* only valid for bound all sockets */
3783 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3785 /* forbidden by admin */
3786 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3789 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3791 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3795 case SCTP_EXPLICIT_EOR:
3796 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3798 case SCTP_USE_EXT_RCVINFO:
3799 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3801 case SCTP_I_WANT_MAPPED_V4_ADDR:
3802 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3803 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3805 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3810 set_opt = SCTP_PCB_FLAGS_NODELAY;
3812 case SCTP_AUTOCLOSE:
3813 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3814 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3815 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3818 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3820 * The value is in ticks. Note this does not effect
3821 * old associations, only new ones.
3823 inp->sctp_ep.auto_close_time = sctp_secs_to_ticks(*mopt);
3826 SCTP_INP_WLOCK(inp);
3828 sctp_feature_on(inp, set_opt);
3830 sctp_feature_off(inp, set_opt);
3832 SCTP_INP_WUNLOCK(inp);
3834 case SCTP_REUSE_PORT:
3836 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3837 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3838 /* Can't set it after we are bound */
3842 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3843 /* Can't do this for a 1-m socket */
3848 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3850 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3853 case SCTP_PARTIAL_DELIVERY_POINT:
3857 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3858 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3859 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3863 inp->partial_delivery_point = *value;
3866 case SCTP_FRAGMENT_INTERLEAVE:
3867 /* not yet until we re-write sctp_recvmsg() */
3871 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3872 if (*level == SCTP_FRAG_LEVEL_2) {
3873 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3874 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3875 } else if (*level == SCTP_FRAG_LEVEL_1) {
3876 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3877 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3878 } else if (*level == SCTP_FRAG_LEVEL_0) {
3879 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3880 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3883 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3888 case SCTP_INTERLEAVING_SUPPORTED:
3890 struct sctp_assoc_value *av;
3892 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3893 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3896 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3898 SCTP_TCB_UNLOCK(stcb);
3900 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3901 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3902 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3903 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
3904 SCTP_INP_WLOCK(inp);
3905 if (av->assoc_value == 0) {
3906 inp->idata_supported = 0;
3908 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3909 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3910 inp->idata_supported = 1;
3918 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3922 SCTP_INP_WUNLOCK(inp);
3924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3930 case SCTP_CMT_ON_OFF:
3931 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3932 struct sctp_assoc_value *av;
3934 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3935 if (av->assoc_value > SCTP_CMT_MAX) {
3936 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3940 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3942 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3943 SCTP_TCB_UNLOCK(stcb);
3945 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3946 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3947 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3948 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3949 (av->assoc_id == SCTP_ALL_ASSOC)))) {
3950 SCTP_INP_WLOCK(inp);
3951 inp->sctp_cmt_on_off = av->assoc_value;
3952 SCTP_INP_WUNLOCK(inp);
3954 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3955 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3956 (av->assoc_id == SCTP_ALL_ASSOC))) {
3957 SCTP_INP_RLOCK(inp);
3958 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3959 SCTP_TCB_LOCK(stcb);
3960 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3961 SCTP_TCB_UNLOCK(stcb);
3963 SCTP_INP_RUNLOCK(inp);
3967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3968 error = ENOPROTOOPT;
3971 case SCTP_PLUGGABLE_CC:
3973 struct sctp_assoc_value *av;
3974 struct sctp_nets *net;
3976 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3977 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3978 (av->assoc_value != SCTP_CC_HSTCP) &&
3979 (av->assoc_value != SCTP_CC_HTCP) &&
3980 (av->assoc_value != SCTP_CC_RTCC)) {
3981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3985 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3987 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3988 stcb->asoc.congestion_control_module = av->assoc_value;
3989 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3990 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3991 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3994 SCTP_TCB_UNLOCK(stcb);
3996 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3997 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3998 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
3999 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4000 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4001 SCTP_INP_WLOCK(inp);
4002 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
4003 SCTP_INP_WUNLOCK(inp);
4005 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4006 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4007 (av->assoc_id == SCTP_ALL_ASSOC))) {
4008 SCTP_INP_RLOCK(inp);
4009 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4010 SCTP_TCB_LOCK(stcb);
4011 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4012 stcb->asoc.congestion_control_module = av->assoc_value;
4013 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4014 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4015 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4018 SCTP_TCB_UNLOCK(stcb);
4020 SCTP_INP_RUNLOCK(inp);
4025 case SCTP_CC_OPTION:
4027 struct sctp_cc_option *cc_opt;
4029 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4030 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4032 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4033 (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC)) {
4034 SCTP_INP_RLOCK(inp);
4035 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4036 SCTP_TCB_LOCK(stcb);
4037 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4038 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4040 SCTP_TCB_UNLOCK(stcb);
4042 SCTP_INP_RUNLOCK(inp);
4047 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4050 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4053 SCTP_TCB_UNLOCK(stcb);
4057 case SCTP_PLUGGABLE_SS:
4059 struct sctp_assoc_value *av;
4061 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4062 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4063 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4064 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4065 (av->assoc_value != SCTP_SS_PRIORITY) &&
4066 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4067 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4068 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4072 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4074 SCTP_TCB_SEND_LOCK(stcb);
4075 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4076 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4077 stcb->asoc.stream_scheduling_module = av->assoc_value;
4078 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4079 SCTP_TCB_SEND_UNLOCK(stcb);
4080 SCTP_TCB_UNLOCK(stcb);
4082 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4083 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4084 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4085 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4086 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4087 SCTP_INP_WLOCK(inp);
4088 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4089 SCTP_INP_WUNLOCK(inp);
4091 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4092 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4093 (av->assoc_id == SCTP_ALL_ASSOC))) {
4094 SCTP_INP_RLOCK(inp);
4095 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4096 SCTP_TCB_LOCK(stcb);
4097 SCTP_TCB_SEND_LOCK(stcb);
4098 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4099 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4100 stcb->asoc.stream_scheduling_module = av->assoc_value;
4101 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4102 SCTP_TCB_SEND_UNLOCK(stcb);
4103 SCTP_TCB_UNLOCK(stcb);
4105 SCTP_INP_RUNLOCK(inp);
4112 struct sctp_stream_value *av;
4114 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4115 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4117 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4118 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4119 av->stream_value) < 0)) {
4120 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4123 SCTP_TCB_UNLOCK(stcb);
4125 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4126 (av->assoc_id == SCTP_CURRENT_ASSOC)) {
4127 SCTP_INP_RLOCK(inp);
4128 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4129 SCTP_TCB_LOCK(stcb);
4130 if (av->stream_id < stcb->asoc.streamoutcnt) {
4131 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4133 &stcb->asoc.strmout[av->stream_id],
4136 SCTP_TCB_UNLOCK(stcb);
4138 SCTP_INP_RUNLOCK(inp);
4141 * Can't set stream value without
4144 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4150 case SCTP_CLR_STAT_LOG:
4151 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4156 struct sctp_assoc_value *av;
4158 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4159 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4162 stcb->asoc.context = av->assoc_value;
4163 SCTP_TCB_UNLOCK(stcb);
4165 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4166 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4167 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4168 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4169 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4170 SCTP_INP_WLOCK(inp);
4171 inp->sctp_context = av->assoc_value;
4172 SCTP_INP_WUNLOCK(inp);
4174 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4175 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4176 (av->assoc_id == SCTP_ALL_ASSOC))) {
4177 SCTP_INP_RLOCK(inp);
4178 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4179 SCTP_TCB_LOCK(stcb);
4180 stcb->asoc.context = av->assoc_value;
4181 SCTP_TCB_UNLOCK(stcb);
4183 SCTP_INP_RUNLOCK(inp);
4190 uint32_t *default_vrfid;
4192 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4193 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4194 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4198 inp->def_vrf_id = *default_vrfid;
4201 case SCTP_DEL_VRF_ID:
4203 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4207 case SCTP_ADD_VRF_ID:
4209 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4213 case SCTP_DELAYED_SACK:
4215 struct sctp_sack_info *sack;
4217 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4218 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4219 if (sack->sack_delay) {
4220 if (sack->sack_delay > SCTP_MAX_SACK_DELAY) {
4223 SCTP_TCB_UNLOCK(stcb);
4229 if (sack->sack_delay) {
4230 stcb->asoc.delayed_ack = sack->sack_delay;
4232 if (sack->sack_freq) {
4233 stcb->asoc.sack_freq = sack->sack_freq;
4235 SCTP_TCB_UNLOCK(stcb);
4237 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4238 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4239 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4240 ((sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4241 (sack->sack_assoc_id == SCTP_ALL_ASSOC)))) {
4242 SCTP_INP_WLOCK(inp);
4243 if (sack->sack_delay) {
4244 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = sctp_msecs_to_ticks(sack->sack_delay);
4246 if (sack->sack_freq) {
4247 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4249 SCTP_INP_WUNLOCK(inp);
4251 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4252 ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4253 (sack->sack_assoc_id == SCTP_ALL_ASSOC))) {
4254 SCTP_INP_RLOCK(inp);
4255 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4256 SCTP_TCB_LOCK(stcb);
4257 if (sack->sack_delay) {
4258 stcb->asoc.delayed_ack = sack->sack_delay;
4260 if (sack->sack_freq) {
4261 stcb->asoc.sack_freq = sack->sack_freq;
4263 SCTP_TCB_UNLOCK(stcb);
4265 SCTP_INP_RUNLOCK(inp);
4270 case SCTP_AUTH_CHUNK:
4272 struct sctp_authchunk *sauth;
4274 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4276 SCTP_INP_WLOCK(inp);
4277 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4278 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4281 inp->auth_supported = 1;
4283 SCTP_INP_WUNLOCK(inp);
4288 struct sctp_authkey *sca;
4289 struct sctp_keyhead *shared_keys;
4290 sctp_sharedkey_t *shared_key;
4291 sctp_key_t *key = NULL;
4294 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4295 if (sca->sca_keylength == 0) {
4296 size = optsize - sizeof(struct sctp_authkey);
4298 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4299 size = sca->sca_keylength;
4301 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4306 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4309 shared_keys = &stcb->asoc.shared_keys;
4310 /* clear the cached keys for this key id */
4311 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4313 * create the new shared key and
4317 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4319 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4321 SCTP_TCB_UNLOCK(stcb);
4325 shared_key = sctp_alloc_sharedkey();
4326 if (shared_key == NULL) {
4328 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4330 SCTP_TCB_UNLOCK(stcb);
4333 shared_key->key = key;
4334 shared_key->keyid = sca->sca_keynumber;
4335 error = sctp_insert_sharedkey(shared_keys, shared_key);
4336 SCTP_TCB_UNLOCK(stcb);
4338 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4339 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4340 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4341 ((sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4342 (sca->sca_assoc_id == SCTP_ALL_ASSOC)))) {
4343 SCTP_INP_WLOCK(inp);
4344 shared_keys = &inp->sctp_ep.shared_keys;
4346 * clear the cached keys on all
4347 * assocs for this key id
4349 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4351 * create the new shared key and
4355 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4357 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4359 SCTP_INP_WUNLOCK(inp);
4363 shared_key = sctp_alloc_sharedkey();
4364 if (shared_key == NULL) {
4366 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4368 SCTP_INP_WUNLOCK(inp);
4371 shared_key->key = key;
4372 shared_key->keyid = sca->sca_keynumber;
4373 error = sctp_insert_sharedkey(shared_keys, shared_key);
4374 SCTP_INP_WUNLOCK(inp);
4376 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4377 ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4378 (sca->sca_assoc_id == SCTP_ALL_ASSOC))) {
4379 SCTP_INP_RLOCK(inp);
4380 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4381 SCTP_TCB_LOCK(stcb);
4382 shared_keys = &stcb->asoc.shared_keys;
4384 * clear the cached keys for
4387 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4389 * create the new shared key
4390 * and insert/replace it
4393 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4395 SCTP_TCB_UNLOCK(stcb);
4399 shared_key = sctp_alloc_sharedkey();
4400 if (shared_key == NULL) {
4402 SCTP_TCB_UNLOCK(stcb);
4405 shared_key->key = key;
4406 shared_key->keyid = sca->sca_keynumber;
4407 error = sctp_insert_sharedkey(shared_keys, shared_key);
4408 SCTP_TCB_UNLOCK(stcb);
4410 SCTP_INP_RUNLOCK(inp);
4415 case SCTP_HMAC_IDENT:
4417 struct sctp_hmacalgo *shmac;
4418 sctp_hmaclist_t *hmaclist;
4422 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4423 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4424 (shmac->shmac_number_of_idents > 0xffff)) {
4425 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4430 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4431 if (hmaclist == NULL) {
4432 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4436 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4437 hmacid = shmac->shmac_idents[i];
4438 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4439 /* invalid HMACs were found */ ;
4440 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4442 sctp_free_hmaclist(hmaclist);
4443 goto sctp_set_hmac_done;
4446 for (i = 0; i < hmaclist->num_algo; i++) {
4447 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4448 /* already in list */
4452 if (i == hmaclist->num_algo) {
4453 /* not found in list */
4454 sctp_free_hmaclist(hmaclist);
4455 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4459 /* set it on the endpoint */
4460 SCTP_INP_WLOCK(inp);
4461 if (inp->sctp_ep.local_hmacs)
4462 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4463 inp->sctp_ep.local_hmacs = hmaclist;
4464 SCTP_INP_WUNLOCK(inp);
4468 case SCTP_AUTH_ACTIVE_KEY:
4470 struct sctp_authkeyid *scact;
4472 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4473 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4475 /* set the active key on the right place */
4477 /* set the active key on the assoc */
4478 if (sctp_auth_setactivekey(stcb,
4479 scact->scact_keynumber)) {
4480 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4481 SCTP_FROM_SCTP_USRREQ,
4485 SCTP_TCB_UNLOCK(stcb);
4487 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4488 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4489 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4490 ((scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4491 (scact->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4492 SCTP_INP_WLOCK(inp);
4493 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4497 SCTP_INP_WUNLOCK(inp);
4499 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4500 ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4501 (scact->scact_assoc_id == SCTP_ALL_ASSOC))) {
4502 SCTP_INP_RLOCK(inp);
4503 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4504 SCTP_TCB_LOCK(stcb);
4505 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4506 SCTP_TCB_UNLOCK(stcb);
4508 SCTP_INP_RUNLOCK(inp);
4513 case SCTP_AUTH_DELETE_KEY:
4515 struct sctp_authkeyid *scdel;
4517 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4518 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4520 /* delete the key from the right place */
4522 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4523 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4526 SCTP_TCB_UNLOCK(stcb);
4528 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4529 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4530 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4531 ((scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4532 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4533 SCTP_INP_WLOCK(inp);
4534 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4535 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4538 SCTP_INP_WUNLOCK(inp);
4540 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4541 ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4542 (scdel->scact_assoc_id == SCTP_ALL_ASSOC))) {
4543 SCTP_INP_RLOCK(inp);
4544 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4545 SCTP_TCB_LOCK(stcb);
4546 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4547 SCTP_TCB_UNLOCK(stcb);
4549 SCTP_INP_RUNLOCK(inp);
4554 case SCTP_AUTH_DEACTIVATE_KEY:
4556 struct sctp_authkeyid *keyid;
4558 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4559 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4561 /* deactivate the key from the right place */
4563 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4564 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4567 SCTP_TCB_UNLOCK(stcb);
4569 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4570 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4571 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4572 ((keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4573 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)))) {
4574 SCTP_INP_WLOCK(inp);
4575 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4576 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4579 SCTP_INP_WUNLOCK(inp);
4581 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4582 ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4583 (keyid->scact_assoc_id == SCTP_ALL_ASSOC))) {
4584 SCTP_INP_RLOCK(inp);
4585 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4586 SCTP_TCB_LOCK(stcb);
4587 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4588 SCTP_TCB_UNLOCK(stcb);
4590 SCTP_INP_RUNLOCK(inp);
4595 case SCTP_ENABLE_STREAM_RESET:
4597 struct sctp_assoc_value *av;
4599 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4600 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4601 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4605 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4607 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4608 SCTP_TCB_UNLOCK(stcb);
4610 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4611 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4612 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4613 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4614 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4615 SCTP_INP_WLOCK(inp);
4616 inp->local_strreset_support = (uint8_t)av->assoc_value;
4617 SCTP_INP_WUNLOCK(inp);
4619 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4620 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4621 (av->assoc_id == SCTP_ALL_ASSOC))) {
4622 SCTP_INP_RLOCK(inp);
4623 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4624 SCTP_TCB_LOCK(stcb);
4625 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4626 SCTP_TCB_UNLOCK(stcb);
4628 SCTP_INP_RUNLOCK(inp);
4634 case SCTP_RESET_STREAMS:
4636 struct sctp_reset_streams *strrst;
4637 int i, send_out = 0;
4640 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4641 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4643 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4647 if (stcb->asoc.reconfig_supported == 0) {
4649 * Peer does not support the chunk type.
4651 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4653 SCTP_TCB_UNLOCK(stcb);
4656 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4657 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4659 SCTP_TCB_UNLOCK(stcb);
4662 if (sizeof(struct sctp_reset_streams) +
4663 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4665 SCTP_TCB_UNLOCK(stcb);
4668 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4670 if (stcb->asoc.stream_reset_outstanding) {
4671 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4673 SCTP_TCB_UNLOCK(stcb);
4677 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4680 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4681 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4683 SCTP_TCB_UNLOCK(stcb);
4686 if ((send_in == 0) && (send_out == 0)) {
4687 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4689 SCTP_TCB_UNLOCK(stcb);
4692 for (i = 0; i < strrst->srs_number_streams; i++) {
4694 (strrst->srs_stream_list[i] >= stcb->asoc.streamincnt)) {
4695 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4700 (strrst->srs_stream_list[i] >= stcb->asoc.streamoutcnt)) {
4701 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4707 SCTP_TCB_UNLOCK(stcb);
4714 if (strrst->srs_number_streams) {
4715 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4716 strm = strrst->srs_stream_list[i];
4717 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4718 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4724 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4725 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4726 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4733 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4734 strrst->srs_stream_list,
4735 send_in, 0, 0, 0, 0, 0);
4737 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4740 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4743 * For outgoing streams don't report any
4744 * problems in sending the request to the
4745 * application. XXX: Double check resetting
4750 SCTP_TCB_UNLOCK(stcb);
4753 case SCTP_ADD_STREAMS:
4755 struct sctp_add_streams *stradd;
4756 uint8_t addstream = 0;
4757 uint16_t add_o_strmcnt = 0;
4758 uint16_t add_i_strmcnt = 0;
4760 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4761 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4763 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4767 if (stcb->asoc.reconfig_supported == 0) {
4769 * Peer does not support the chunk type.
4771 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4773 SCTP_TCB_UNLOCK(stcb);
4776 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4777 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4779 SCTP_TCB_UNLOCK(stcb);
4782 if (stcb->asoc.stream_reset_outstanding) {
4783 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4785 SCTP_TCB_UNLOCK(stcb);
4788 if ((stradd->sas_outstrms == 0) &&
4789 (stradd->sas_instrms == 0)) {
4793 if (stradd->sas_outstrms) {
4795 /* We allocate here */
4796 add_o_strmcnt = stradd->sas_outstrms;
4797 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4798 /* You can't have more than 64k */
4803 if (stradd->sas_instrms) {
4808 * We allocate inside
4809 * sctp_send_str_reset_req()
4811 add_i_strmcnt = stradd->sas_instrms;
4812 cnt = add_i_strmcnt;
4813 cnt += stcb->asoc.streamincnt;
4814 if (cnt > 0x0000ffff) {
4815 /* You can't have more than 64k */
4819 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4820 /* More than you are allowed */
4825 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4826 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4828 SCTP_TCB_UNLOCK(stcb);
4831 case SCTP_RESET_ASSOC:
4836 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4837 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4839 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4843 if (stcb->asoc.reconfig_supported == 0) {
4845 * Peer does not support the chunk type.
4847 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4849 SCTP_TCB_UNLOCK(stcb);
4852 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4853 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4855 SCTP_TCB_UNLOCK(stcb);
4858 if (stcb->asoc.stream_reset_outstanding) {
4859 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4861 SCTP_TCB_UNLOCK(stcb);
4865 * Is there any data pending in the send or sent
4868 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4869 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4873 SCTP_TCB_UNLOCK(stcb);
4876 /* Do any streams have data queued? */
4877 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4878 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4882 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4883 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4884 SCTP_TCB_UNLOCK(stcb);
4887 case SCTP_CONNECT_X:
4888 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4889 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4893 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4895 case SCTP_CONNECT_X_DELAYED:
4896 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4901 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4903 case SCTP_CONNECT_X_COMPLETE:
4905 struct sockaddr *sa;
4907 /* FIXME MT: check correct? */
4908 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4911 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4912 SCTP_INP_RLOCK(inp);
4913 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4915 SCTP_TCB_LOCK(stcb);
4917 SCTP_INP_RUNLOCK(inp);
4920 * We increment here since
4921 * sctp_findassociation_ep_addr() wil do a
4922 * decrement if it finds the stcb as long as
4923 * the locked tcb (last argument) is NOT a
4926 SCTP_INP_INCR_REF(inp);
4927 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4929 SCTP_INP_DECR_REF(inp);
4934 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4938 if (stcb->asoc.delayed_connection == 1) {
4939 stcb->asoc.delayed_connection = 0;
4940 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4941 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4942 stcb->asoc.primary_destination,
4943 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4944 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4947 * already expired or did not use delayed
4950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4953 SCTP_TCB_UNLOCK(stcb);
4956 case SCTP_MAX_BURST:
4958 struct sctp_assoc_value *av;
4960 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4961 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4964 stcb->asoc.max_burst = av->assoc_value;
4965 SCTP_TCB_UNLOCK(stcb);
4967 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4968 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4969 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4970 ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
4971 (av->assoc_id == SCTP_ALL_ASSOC)))) {
4972 SCTP_INP_WLOCK(inp);
4973 inp->sctp_ep.max_burst = av->assoc_value;
4974 SCTP_INP_WUNLOCK(inp);
4976 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
4977 ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4978 (av->assoc_id == SCTP_ALL_ASSOC))) {
4979 SCTP_INP_RLOCK(inp);
4980 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4981 SCTP_TCB_LOCK(stcb);
4982 stcb->asoc.max_burst = av->assoc_value;
4983 SCTP_TCB_UNLOCK(stcb);
4985 SCTP_INP_RUNLOCK(inp);
4992 struct sctp_assoc_value *av;
4995 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4996 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4998 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4999 ovh = SCTP_MED_OVERHEAD;
5001 ovh = SCTP_MED_V4_OVERHEAD;
5004 if (av->assoc_value) {
5005 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
5007 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
5009 SCTP_TCB_UNLOCK(stcb);
5011 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5012 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5013 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5014 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
5015 SCTP_INP_WLOCK(inp);
5017 * FIXME MT: I think this is not in
5018 * tune with the API ID
5020 if (av->assoc_value) {
5021 inp->sctp_frag_point = (av->assoc_value + ovh);
5023 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
5025 SCTP_INP_WUNLOCK(inp);
5027 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5035 struct sctp_event_subscribe *events;
5037 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5039 SCTP_INP_WLOCK(inp);
5040 if (events->sctp_data_io_event) {
5041 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5043 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5046 if (events->sctp_association_event) {
5047 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5049 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5052 if (events->sctp_address_event) {
5053 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5055 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5058 if (events->sctp_send_failure_event) {
5059 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5061 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5064 if (events->sctp_peer_error_event) {
5065 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5067 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5070 if (events->sctp_shutdown_event) {
5071 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5073 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5076 if (events->sctp_partial_delivery_event) {
5077 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5079 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5082 if (events->sctp_adaptation_layer_event) {
5083 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5085 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5088 if (events->sctp_authentication_event) {
5089 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5091 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5094 if (events->sctp_sender_dry_event) {
5095 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5097 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5100 if (events->sctp_stream_reset_event) {
5101 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5103 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5105 SCTP_INP_WUNLOCK(inp);
5107 SCTP_INP_RLOCK(inp);
5108 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5109 SCTP_TCB_LOCK(stcb);
5110 if (events->sctp_association_event) {
5111 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5113 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5115 if (events->sctp_address_event) {
5116 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5118 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5120 if (events->sctp_send_failure_event) {
5121 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5123 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5125 if (events->sctp_peer_error_event) {
5126 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5128 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5130 if (events->sctp_shutdown_event) {
5131 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5133 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5135 if (events->sctp_partial_delivery_event) {
5136 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5138 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5140 if (events->sctp_adaptation_layer_event) {
5141 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5143 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5145 if (events->sctp_authentication_event) {
5146 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5148 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5150 if (events->sctp_sender_dry_event) {
5151 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5153 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5155 if (events->sctp_stream_reset_event) {
5156 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5158 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5160 SCTP_TCB_UNLOCK(stcb);
5163 * Send up the sender dry event only for 1-to-1
5166 if (events->sctp_sender_dry_event) {
5167 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5168 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5169 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5171 SCTP_TCB_LOCK(stcb);
5172 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5173 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5174 (stcb->asoc.stream_queue_cnt == 0)) {
5175 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5177 SCTP_TCB_UNLOCK(stcb);
5181 SCTP_INP_RUNLOCK(inp);
5184 case SCTP_ADAPTATION_LAYER:
5186 struct sctp_setadaptation *adap_bits;
5188 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5189 SCTP_INP_WLOCK(inp);
5190 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5191 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5192 SCTP_INP_WUNLOCK(inp);
5196 case SCTP_SET_INITIAL_DBG_SEQ:
5200 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5201 SCTP_INP_WLOCK(inp);
5202 inp->sctp_ep.initial_sequence_debug = *vvv;
5203 SCTP_INP_WUNLOCK(inp);
5207 case SCTP_DEFAULT_SEND_PARAM:
5209 struct sctp_sndrcvinfo *s_info;
5211 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5212 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5215 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5216 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5218 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5221 SCTP_TCB_UNLOCK(stcb);
5223 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5224 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5225 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5226 ((s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5227 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)))) {
5228 SCTP_INP_WLOCK(inp);
5229 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5230 SCTP_INP_WUNLOCK(inp);
5232 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5233 ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5234 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC))) {
5235 SCTP_INP_RLOCK(inp);
5236 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5237 SCTP_TCB_LOCK(stcb);
5238 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5239 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5241 SCTP_TCB_UNLOCK(stcb);
5243 SCTP_INP_RUNLOCK(inp);
5248 case SCTP_PEER_ADDR_PARAMS:
5250 struct sctp_paddrparams *paddrp;
5251 struct sctp_nets *net;
5252 struct sockaddr *addr;
5253 #if defined(INET) && defined(INET6)
5254 struct sockaddr_in sin_store;
5257 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5258 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5260 #if defined(INET) && defined(INET6)
5261 if (paddrp->spp_address.ss_family == AF_INET6) {
5262 struct sockaddr_in6 *sin6;
5264 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5265 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5266 in6_sin6_2_sin(&sin_store, sin6);
5267 addr = (struct sockaddr *)&sin_store;
5269 addr = (struct sockaddr *)&paddrp->spp_address;
5272 addr = (struct sockaddr *)&paddrp->spp_address;
5275 addr = (struct sockaddr *)&paddrp->spp_address;
5278 net = sctp_findnet(stcb, addr);
5281 * We increment here since
5282 * sctp_findassociation_ep_addr() wil do a
5283 * decrement if it finds the stcb as long as
5284 * the locked tcb (last argument) is NOT a
5288 SCTP_INP_INCR_REF(inp);
5289 stcb = sctp_findassociation_ep_addr(&inp, addr,
5292 SCTP_INP_DECR_REF(inp);
5295 if ((stcb != NULL) && (net == NULL)) {
5297 if (addr->sa_family == AF_INET) {
5299 struct sockaddr_in *sin;
5301 sin = (struct sockaddr_in *)addr;
5302 if (sin->sin_addr.s_addr != INADDR_ANY) {
5303 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5304 SCTP_TCB_UNLOCK(stcb);
5311 if (addr->sa_family == AF_INET6) {
5312 struct sockaddr_in6 *sin6;
5314 sin6 = (struct sockaddr_in6 *)addr;
5315 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5316 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5317 SCTP_TCB_UNLOCK(stcb);
5324 error = EAFNOSUPPORT;
5325 SCTP_TCB_UNLOCK(stcb);
5326 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5331 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5333 SCTP_TCB_UNLOCK(stcb);
5334 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5338 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5340 SCTP_TCB_UNLOCK(stcb);
5341 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5344 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) &&
5345 ((paddrp->spp_pathmtu < SCTP_SMALLEST_PMTU) ||
5346 (paddrp->spp_pathmtu > SCTP_LARGEST_PMTU))) {
5348 SCTP_TCB_UNLOCK(stcb);
5349 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5354 /************************TCB SPECIFIC SET ******************/
5356 /************************NET SPECIFIC SET ******************/
5357 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5358 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5359 !(net->dest_state & SCTP_ADDR_NOHB)) {
5360 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5361 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5363 net->dest_state |= SCTP_ADDR_NOHB;
5365 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5366 if (paddrp->spp_hbinterval) {
5367 net->heart_beat_delay = paddrp->spp_hbinterval;
5368 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5369 net->heart_beat_delay = 0;
5371 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5372 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5373 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5374 net->dest_state &= ~SCTP_ADDR_NOHB;
5376 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5377 if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
5378 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5379 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5380 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5383 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5384 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5385 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5386 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5388 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5389 net->mtu = paddrp->spp_pathmtu;
5390 switch (net->ro._l_addr.sa.sa_family) {
5393 net->mtu += SCTP_MIN_V4_OVERHEAD;
5398 net->mtu += SCTP_MIN_OVERHEAD;
5404 if (net->mtu < stcb->asoc.smallest_mtu) {
5405 sctp_pathmtu_adjustment(stcb, net->mtu);
5408 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5409 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5410 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5412 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5414 if (paddrp->spp_pathmaxrxt) {
5415 if (net->dest_state & SCTP_ADDR_PF) {
5416 if (net->error_count > paddrp->spp_pathmaxrxt) {
5417 net->dest_state &= ~SCTP_ADDR_PF;
5420 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5421 (net->error_count > net->pf_threshold)) {
5422 net->dest_state |= SCTP_ADDR_PF;
5423 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5424 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5425 stcb->sctp_ep, stcb, net,
5426 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5427 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5430 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5431 if (net->error_count > paddrp->spp_pathmaxrxt) {
5432 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5433 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5436 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5437 net->dest_state |= SCTP_ADDR_REACHABLE;
5438 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5441 net->failure_threshold = paddrp->spp_pathmaxrxt;
5443 if (paddrp->spp_flags & SPP_DSCP) {
5444 net->dscp = paddrp->spp_dscp & 0xfc;
5448 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5449 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5450 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5451 net->flowlabel |= 0x80000000;
5456 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5457 if (paddrp->spp_pathmaxrxt != 0) {
5458 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5459 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5460 if (net->dest_state & SCTP_ADDR_PF) {
5461 if (net->error_count > paddrp->spp_pathmaxrxt) {
5462 net->dest_state &= ~SCTP_ADDR_PF;
5465 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5466 (net->error_count > net->pf_threshold)) {
5467 net->dest_state |= SCTP_ADDR_PF;
5468 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5469 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5470 stcb->sctp_ep, stcb, net,
5471 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5472 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5475 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5476 if (net->error_count > paddrp->spp_pathmaxrxt) {
5477 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5478 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5481 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5482 net->dest_state |= SCTP_ADDR_REACHABLE;
5483 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5486 net->failure_threshold = paddrp->spp_pathmaxrxt;
5490 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5491 if (paddrp->spp_hbinterval != 0) {
5492 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5493 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5494 stcb->asoc.heart_beat_delay = 0;
5496 /* Turn back on the timer */
5497 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5498 if (paddrp->spp_hbinterval != 0) {
5499 net->heart_beat_delay = paddrp->spp_hbinterval;
5500 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5501 net->heart_beat_delay = 0;
5503 if (net->dest_state & SCTP_ADDR_NOHB) {
5504 net->dest_state &= ~SCTP_ADDR_NOHB;
5506 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5507 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5508 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5510 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5512 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5513 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5514 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5515 net->dest_state |= SCTP_ADDR_NOHB;
5516 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5517 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5519 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5523 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5525 if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5526 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5527 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5528 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5529 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5531 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5532 net->mtu = paddrp->spp_pathmtu;
5533 switch (net->ro._l_addr.sa.sa_family) {
5536 net->mtu += SCTP_MIN_V4_OVERHEAD;
5541 net->mtu += SCTP_MIN_OVERHEAD;
5547 if (net->mtu < stcb->asoc.smallest_mtu) {
5548 sctp_pathmtu_adjustment(stcb, net->mtu);
5551 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5552 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5554 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5555 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5556 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5557 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5559 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5561 stcb->asoc.default_mtu = 0;
5562 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5564 if (paddrp->spp_flags & SPP_DSCP) {
5565 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5566 net->dscp = paddrp->spp_dscp & 0xfc;
5569 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5570 stcb->asoc.default_dscp |= 0x01;
5573 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5574 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5575 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5576 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5577 net->flowlabel |= 0x80000000;
5580 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5581 stcb->asoc.default_flowlabel |= 0x80000000;
5585 SCTP_TCB_UNLOCK(stcb);
5587 /************************NO TCB, SET TO default stuff ******************/
5588 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5589 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5590 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5591 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) {
5592 SCTP_INP_WLOCK(inp);
5594 * For the TOS/FLOWLABEL stuff you
5595 * set it with the options on the
5598 if (paddrp->spp_pathmaxrxt != 0) {
5599 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5602 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5603 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5604 else if (paddrp->spp_hbinterval != 0) {
5605 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5606 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5607 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5610 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5611 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5612 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5613 } else if (paddrp->spp_hbinterval) {
5614 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval);
5616 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5617 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5618 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5620 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5621 inp->sctp_ep.default_mtu = 0;
5622 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5623 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5624 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5625 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5627 if (paddrp->spp_flags & SPP_DSCP) {
5628 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5629 inp->sctp_ep.default_dscp |= 0x01;
5632 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5633 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5634 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5635 inp->sctp_ep.default_flowlabel |= 0x80000000;
5639 SCTP_INP_WUNLOCK(inp);
5641 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5649 struct sctp_rtoinfo *srto;
5650 uint32_t new_init, new_min, new_max;
5652 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5653 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5656 if (srto->srto_initial)
5657 new_init = srto->srto_initial;
5659 new_init = stcb->asoc.initial_rto;
5661 new_max = srto->srto_max;
5663 new_max = stcb->asoc.maxrto;
5665 new_min = srto->srto_min;
5667 new_min = stcb->asoc.minrto;
5668 if ((new_min <= new_init) && (new_init <= new_max)) {
5669 stcb->asoc.initial_rto = new_init;
5670 stcb->asoc.maxrto = new_max;
5671 stcb->asoc.minrto = new_min;
5673 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5676 SCTP_TCB_UNLOCK(stcb);
5678 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5679 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5680 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5681 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) {
5682 SCTP_INP_WLOCK(inp);
5683 if (srto->srto_initial)
5684 new_init = srto->srto_initial;
5686 new_init = inp->sctp_ep.initial_rto;
5688 new_max = srto->srto_max;
5690 new_max = inp->sctp_ep.sctp_maxrto;
5692 new_min = srto->srto_min;
5694 new_min = inp->sctp_ep.sctp_minrto;
5695 if ((new_min <= new_init) && (new_init <= new_max)) {
5696 inp->sctp_ep.initial_rto = new_init;
5697 inp->sctp_ep.sctp_maxrto = new_max;
5698 inp->sctp_ep.sctp_minrto = new_min;
5700 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5703 SCTP_INP_WUNLOCK(inp);
5705 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5711 case SCTP_ASSOCINFO:
5713 struct sctp_assocparams *sasoc;
5715 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5716 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5717 if (sasoc->sasoc_cookie_life) {
5718 /* boundary check the cookie life */
5719 if (sasoc->sasoc_cookie_life < 1000)
5720 sasoc->sasoc_cookie_life = 1000;
5721 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5722 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5726 if (sasoc->sasoc_asocmaxrxt)
5727 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5728 if (sasoc->sasoc_cookie_life) {
5729 stcb->asoc.cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5731 SCTP_TCB_UNLOCK(stcb);
5733 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5734 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5735 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
5736 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) {
5737 SCTP_INP_WLOCK(inp);
5738 if (sasoc->sasoc_asocmaxrxt)
5739 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5740 if (sasoc->sasoc_cookie_life) {
5741 inp->sctp_ep.def_cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life);
5743 SCTP_INP_WUNLOCK(inp);
5745 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5753 struct sctp_initmsg *sinit;
5755 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5756 SCTP_INP_WLOCK(inp);
5757 if (sinit->sinit_num_ostreams)
5758 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5760 if (sinit->sinit_max_instreams)
5761 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5763 if (sinit->sinit_max_attempts)
5764 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5766 if (sinit->sinit_max_init_timeo)
5767 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5768 SCTP_INP_WUNLOCK(inp);
5771 case SCTP_PRIMARY_ADDR:
5773 struct sctp_setprim *spa;
5774 struct sctp_nets *net;
5775 struct sockaddr *addr;
5776 #if defined(INET) && defined(INET6)
5777 struct sockaddr_in sin_store;
5780 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5781 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5783 #if defined(INET) && defined(INET6)
5784 if (spa->ssp_addr.ss_family == AF_INET6) {
5785 struct sockaddr_in6 *sin6;
5787 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5788 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5789 in6_sin6_2_sin(&sin_store, sin6);
5790 addr = (struct sockaddr *)&sin_store;
5792 addr = (struct sockaddr *)&spa->ssp_addr;
5795 addr = (struct sockaddr *)&spa->ssp_addr;
5798 addr = (struct sockaddr *)&spa->ssp_addr;
5801 net = sctp_findnet(stcb, addr);
5804 * We increment here since
5805 * sctp_findassociation_ep_addr() wil do a
5806 * decrement if it finds the stcb as long as
5807 * the locked tcb (last argument) is NOT a
5811 SCTP_INP_INCR_REF(inp);
5812 stcb = sctp_findassociation_ep_addr(&inp, addr,
5815 SCTP_INP_DECR_REF(inp);
5819 if ((stcb != NULL) && (net != NULL)) {
5820 if (net != stcb->asoc.primary_destination) {
5821 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5822 /* Ok we need to set it */
5823 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5824 if ((stcb->asoc.alternate) &&
5825 (!(net->dest_state & SCTP_ADDR_PF)) &&
5826 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5827 sctp_free_remote_addr(stcb->asoc.alternate);
5828 stcb->asoc.alternate = NULL;
5831 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5835 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5840 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5844 SCTP_TCB_UNLOCK(stcb);
5848 case SCTP_SET_DYNAMIC_PRIMARY:
5850 union sctp_sockstore *ss;
5852 error = priv_check(curthread,
5853 PRIV_NETINET_RESERVEDPORT);
5857 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5858 /* SUPER USER CHECK? */
5859 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5862 case SCTP_SET_PEER_PRIMARY_ADDR:
5864 struct sctp_setpeerprim *sspp;
5865 struct sockaddr *addr;
5866 #if defined(INET) && defined(INET6)
5867 struct sockaddr_in sin_store;
5870 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5871 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5873 struct sctp_ifa *ifa;
5875 #if defined(INET) && defined(INET6)
5876 if (sspp->sspp_addr.ss_family == AF_INET6) {
5877 struct sockaddr_in6 *sin6;
5879 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5880 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5881 in6_sin6_2_sin(&sin_store, sin6);
5882 addr = (struct sockaddr *)&sin_store;
5884 addr = (struct sockaddr *)&sspp->sspp_addr;
5887 addr = (struct sockaddr *)&sspp->sspp_addr;
5890 addr = (struct sockaddr *)&sspp->sspp_addr;
5892 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5894 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5898 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5900 * Must validate the ifa found is in
5903 struct sctp_laddr *laddr;
5906 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5907 if (laddr->ifa == NULL) {
5908 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5912 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5913 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5916 if (laddr->ifa == ifa) {
5922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5927 switch (addr->sa_family) {
5931 struct sockaddr_in *sin;
5933 sin = (struct sockaddr_in *)addr;
5934 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5935 &sin->sin_addr) != 0) {
5936 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5946 struct sockaddr_in6 *sin6;
5948 sin6 = (struct sockaddr_in6 *)addr;
5949 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5950 &sin6->sin6_addr) != 0) {
5951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5959 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5964 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5968 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5970 SCTP_TCB_UNLOCK(stcb);
5972 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5977 case SCTP_BINDX_ADD_ADDR:
5979 struct sockaddr *sa;
5982 td = (struct thread *)p;
5983 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
5985 if (sa->sa_family == AF_INET) {
5986 if (optsize < sizeof(struct sockaddr_in)) {
5987 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5992 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
5993 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5999 if (sa->sa_family == AF_INET6) {
6000 if (optsize < sizeof(struct sockaddr_in6)) {
6001 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6006 (error = prison_local_ip6(td->td_ucred,
6007 &(((struct sockaddr_in6 *)sa)->sin6_addr),
6008 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6009 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6015 error = EAFNOSUPPORT;
6018 sctp_bindx_add_address(so, inp, sa, vrf_id, &error, p);
6021 case SCTP_BINDX_REM_ADDR:
6023 struct sockaddr *sa;
6026 td = (struct thread *)p;
6028 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
6030 if (sa->sa_family == AF_INET) {
6031 if (optsize < sizeof(struct sockaddr_in)) {
6032 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6037 (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) {
6038 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6044 if (sa->sa_family == AF_INET6) {
6045 if (optsize < sizeof(struct sockaddr_in6)) {
6046 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6051 (error = prison_local_ip6(td->td_ucred,
6052 &(((struct sockaddr_in6 *)sa)->sin6_addr),
6053 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6054 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6060 error = EAFNOSUPPORT;
6063 sctp_bindx_delete_address(inp, sa, vrf_id, &error);
6068 struct sctp_event *event;
6069 uint32_t event_type;
6071 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6072 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6073 switch (event->se_type) {
6074 case SCTP_ASSOC_CHANGE:
6075 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6077 case SCTP_PEER_ADDR_CHANGE:
6078 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6080 case SCTP_REMOTE_ERROR:
6081 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6083 case SCTP_SEND_FAILED:
6084 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6086 case SCTP_SHUTDOWN_EVENT:
6087 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6089 case SCTP_ADAPTATION_INDICATION:
6090 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6092 case SCTP_PARTIAL_DELIVERY_EVENT:
6093 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6095 case SCTP_AUTHENTICATION_EVENT:
6096 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6098 case SCTP_STREAM_RESET_EVENT:
6099 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6101 case SCTP_SENDER_DRY_EVENT:
6102 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6104 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6106 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6109 case SCTP_ASSOC_RESET_EVENT:
6110 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6112 case SCTP_STREAM_CHANGE_EVENT:
6113 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6115 case SCTP_SEND_FAILED_EVENT:
6116 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6120 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6124 if (event_type > 0) {
6127 sctp_stcb_feature_on(inp, stcb, event_type);
6128 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6129 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6130 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6131 (stcb->asoc.stream_queue_cnt == 0)) {
6132 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6136 sctp_stcb_feature_off(inp, stcb, event_type);
6138 SCTP_TCB_UNLOCK(stcb);
6141 * We don't want to send up a storm
6142 * of events, so return an error for
6145 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6146 (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6147 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6148 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6149 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6153 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6154 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6155 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6156 ((event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6157 (event->se_assoc_id == SCTP_ALL_ASSOC)))) {
6158 SCTP_INP_WLOCK(inp);
6160 sctp_feature_on(inp, event_type);
6162 sctp_feature_off(inp, event_type);
6164 SCTP_INP_WUNLOCK(inp);
6166 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6167 ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6168 (event->se_assoc_id == SCTP_ALL_ASSOC))) {
6169 SCTP_INP_RLOCK(inp);
6170 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6171 SCTP_TCB_LOCK(stcb);
6173 sctp_stcb_feature_on(inp, stcb, event_type);
6175 sctp_stcb_feature_off(inp, stcb, event_type);
6177 SCTP_TCB_UNLOCK(stcb);
6179 SCTP_INP_RUNLOCK(inp);
6184 SCTP_TCB_UNLOCK(stcb);
6189 case SCTP_RECVRCVINFO:
6193 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6194 SCTP_INP_WLOCK(inp);
6196 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6198 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6200 SCTP_INP_WUNLOCK(inp);
6203 case SCTP_RECVNXTINFO:
6207 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6208 SCTP_INP_WLOCK(inp);
6210 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6212 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6214 SCTP_INP_WUNLOCK(inp);
6217 case SCTP_DEFAULT_SNDINFO:
6219 struct sctp_sndinfo *info;
6222 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6223 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6226 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6227 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6228 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6229 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6230 stcb->asoc.def_send.sinfo_flags |= policy;
6231 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6232 stcb->asoc.def_send.sinfo_context = info->snd_context;
6234 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6237 SCTP_TCB_UNLOCK(stcb);
6239 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6240 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6241 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6242 ((info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6243 (info->snd_assoc_id == SCTP_ALL_ASSOC)))) {
6244 SCTP_INP_WLOCK(inp);
6245 inp->def_send.sinfo_stream = info->snd_sid;
6246 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6247 inp->def_send.sinfo_flags = info->snd_flags;
6248 inp->def_send.sinfo_flags |= policy;
6249 inp->def_send.sinfo_ppid = info->snd_ppid;
6250 inp->def_send.sinfo_context = info->snd_context;
6251 SCTP_INP_WUNLOCK(inp);
6253 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6254 ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6255 (info->snd_assoc_id == SCTP_ALL_ASSOC))) {
6256 SCTP_INP_RLOCK(inp);
6257 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6258 SCTP_TCB_LOCK(stcb);
6259 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6260 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6261 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6262 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6263 stcb->asoc.def_send.sinfo_flags |= policy;
6264 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6265 stcb->asoc.def_send.sinfo_context = info->snd_context;
6267 SCTP_TCB_UNLOCK(stcb);
6269 SCTP_INP_RUNLOCK(inp);
6274 case SCTP_DEFAULT_PRINFO:
6276 struct sctp_default_prinfo *info;
6278 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6279 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6281 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6283 SCTP_TCB_UNLOCK(stcb);
6285 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6290 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6291 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6292 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6293 SCTP_TCB_UNLOCK(stcb);
6295 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6296 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6297 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6298 ((info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6299 (info->pr_assoc_id == SCTP_ALL_ASSOC)))) {
6300 SCTP_INP_WLOCK(inp);
6301 inp->def_send.sinfo_flags &= 0xfff0;
6302 inp->def_send.sinfo_flags |= info->pr_policy;
6303 inp->def_send.sinfo_timetolive = info->pr_value;
6304 SCTP_INP_WUNLOCK(inp);
6306 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6307 ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6308 (info->pr_assoc_id == SCTP_ALL_ASSOC))) {
6309 SCTP_INP_RLOCK(inp);
6310 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6311 SCTP_TCB_LOCK(stcb);
6312 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6313 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6314 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6315 SCTP_TCB_UNLOCK(stcb);
6317 SCTP_INP_RUNLOCK(inp);
6322 case SCTP_PEER_ADDR_THLDS:
6323 /* Applies to the specific association */
6325 struct sctp_paddrthlds *thlds;
6326 struct sctp_nets *net;
6327 struct sockaddr *addr;
6328 #if defined(INET) && defined(INET6)
6329 struct sockaddr_in sin_store;
6332 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6333 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6335 #if defined(INET) && defined(INET6)
6336 if (thlds->spt_address.ss_family == AF_INET6) {
6337 struct sockaddr_in6 *sin6;
6339 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6340 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6341 in6_sin6_2_sin(&sin_store, sin6);
6342 addr = (struct sockaddr *)&sin_store;
6344 addr = (struct sockaddr *)&thlds->spt_address;
6347 addr = (struct sockaddr *)&thlds->spt_address;
6350 addr = (struct sockaddr *)&thlds->spt_address;
6353 net = sctp_findnet(stcb, addr);
6356 * We increment here since
6357 * sctp_findassociation_ep_addr() wil do a
6358 * decrement if it finds the stcb as long as
6359 * the locked tcb (last argument) is NOT a
6363 SCTP_INP_INCR_REF(inp);
6364 stcb = sctp_findassociation_ep_addr(&inp, addr,
6367 SCTP_INP_DECR_REF(inp);
6370 if ((stcb != NULL) && (net == NULL)) {
6372 if (addr->sa_family == AF_INET) {
6374 struct sockaddr_in *sin;
6376 sin = (struct sockaddr_in *)addr;
6377 if (sin->sin_addr.s_addr != INADDR_ANY) {
6378 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6379 SCTP_TCB_UNLOCK(stcb);
6386 if (addr->sa_family == AF_INET6) {
6387 struct sockaddr_in6 *sin6;
6389 sin6 = (struct sockaddr_in6 *)addr;
6390 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6391 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6392 SCTP_TCB_UNLOCK(stcb);
6399 error = EAFNOSUPPORT;
6400 SCTP_TCB_UNLOCK(stcb);
6401 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6405 if (thlds->spt_pathcpthld != 0xffff) {
6407 SCTP_TCB_UNLOCK(stcb);
6410 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6415 net->failure_threshold = thlds->spt_pathmaxrxt;
6416 net->pf_threshold = thlds->spt_pathpfthld;
6417 if (net->dest_state & SCTP_ADDR_PF) {
6418 if ((net->error_count > net->failure_threshold) ||
6419 (net->error_count <= net->pf_threshold)) {
6420 net->dest_state &= ~SCTP_ADDR_PF;
6423 if ((net->error_count > net->pf_threshold) &&
6424 (net->error_count <= net->failure_threshold)) {
6425 net->dest_state |= SCTP_ADDR_PF;
6426 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6427 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6428 stcb->sctp_ep, stcb, net,
6429 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6430 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6433 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6434 if (net->error_count > net->failure_threshold) {
6435 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6436 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6439 if (net->error_count <= net->failure_threshold) {
6440 net->dest_state |= SCTP_ADDR_REACHABLE;
6441 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6445 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6446 net->failure_threshold = thlds->spt_pathmaxrxt;
6447 net->pf_threshold = thlds->spt_pathpfthld;
6448 if (net->dest_state & SCTP_ADDR_PF) {
6449 if ((net->error_count > net->failure_threshold) ||
6450 (net->error_count <= net->pf_threshold)) {
6451 net->dest_state &= ~SCTP_ADDR_PF;
6454 if ((net->error_count > net->pf_threshold) &&
6455 (net->error_count <= net->failure_threshold)) {
6456 net->dest_state |= SCTP_ADDR_PF;
6457 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6458 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6459 stcb->sctp_ep, stcb, net,
6460 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6461 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6464 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6465 if (net->error_count > net->failure_threshold) {
6466 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6467 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6470 if (net->error_count <= net->failure_threshold) {
6471 net->dest_state |= SCTP_ADDR_REACHABLE;
6472 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6476 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6477 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6479 SCTP_TCB_UNLOCK(stcb);
6481 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6482 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6483 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6484 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) {
6485 SCTP_INP_WLOCK(inp);
6486 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6487 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6488 SCTP_INP_WUNLOCK(inp);
6490 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6496 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6498 struct sctp_udpencaps *encaps;
6499 struct sctp_nets *net;
6500 struct sockaddr *addr;
6501 #if defined(INET) && defined(INET6)
6502 struct sockaddr_in sin_store;
6505 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6506 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6508 #if defined(INET) && defined(INET6)
6509 if (encaps->sue_address.ss_family == AF_INET6) {
6510 struct sockaddr_in6 *sin6;
6512 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6513 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6514 in6_sin6_2_sin(&sin_store, sin6);
6515 addr = (struct sockaddr *)&sin_store;
6517 addr = (struct sockaddr *)&encaps->sue_address;
6520 addr = (struct sockaddr *)&encaps->sue_address;
6523 addr = (struct sockaddr *)&encaps->sue_address;
6526 net = sctp_findnet(stcb, addr);
6529 * We increment here since
6530 * sctp_findassociation_ep_addr() wil do a
6531 * decrement if it finds the stcb as long as
6532 * the locked tcb (last argument) is NOT a
6536 SCTP_INP_INCR_REF(inp);
6537 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6539 SCTP_INP_DECR_REF(inp);
6542 if ((stcb != NULL) && (net == NULL)) {
6544 if (addr->sa_family == AF_INET) {
6546 struct sockaddr_in *sin;
6548 sin = (struct sockaddr_in *)addr;
6549 if (sin->sin_addr.s_addr != INADDR_ANY) {
6550 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6551 SCTP_TCB_UNLOCK(stcb);
6558 if (addr->sa_family == AF_INET6) {
6559 struct sockaddr_in6 *sin6;
6561 sin6 = (struct sockaddr_in6 *)addr;
6562 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6563 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6564 SCTP_TCB_UNLOCK(stcb);
6571 error = EAFNOSUPPORT;
6572 SCTP_TCB_UNLOCK(stcb);
6573 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6580 net->port = encaps->sue_port;
6582 stcb->asoc.port = encaps->sue_port;
6584 SCTP_TCB_UNLOCK(stcb);
6586 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6587 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6588 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6589 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) {
6590 SCTP_INP_WLOCK(inp);
6591 inp->sctp_ep.port = encaps->sue_port;
6592 SCTP_INP_WUNLOCK(inp);
6594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6600 case SCTP_ECN_SUPPORTED:
6602 struct sctp_assoc_value *av;
6604 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6605 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6608 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6610 SCTP_TCB_UNLOCK(stcb);
6612 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6613 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6614 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6615 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6616 SCTP_INP_WLOCK(inp);
6617 if (av->assoc_value == 0) {
6618 inp->ecn_supported = 0;
6620 inp->ecn_supported = 1;
6622 SCTP_INP_WUNLOCK(inp);
6624 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6630 case SCTP_PR_SUPPORTED:
6632 struct sctp_assoc_value *av;
6634 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6635 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6638 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6640 SCTP_TCB_UNLOCK(stcb);
6642 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6643 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6644 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6645 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6646 SCTP_INP_WLOCK(inp);
6647 if (av->assoc_value == 0) {
6648 inp->prsctp_supported = 0;
6650 inp->prsctp_supported = 1;
6652 SCTP_INP_WUNLOCK(inp);
6654 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6660 case SCTP_AUTH_SUPPORTED:
6662 struct sctp_assoc_value *av;
6664 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6665 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6668 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6670 SCTP_TCB_UNLOCK(stcb);
6672 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6673 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6674 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6675 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6676 if ((av->assoc_value == 0) &&
6677 (inp->asconf_supported == 1)) {
6679 * AUTH is required for
6682 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6685 SCTP_INP_WLOCK(inp);
6686 if (av->assoc_value == 0) {
6687 inp->auth_supported = 0;
6689 inp->auth_supported = 1;
6691 SCTP_INP_WUNLOCK(inp);
6694 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6700 case SCTP_ASCONF_SUPPORTED:
6702 struct sctp_assoc_value *av;
6704 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6705 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6708 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6710 SCTP_TCB_UNLOCK(stcb);
6712 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6713 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6714 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6715 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6716 if ((av->assoc_value != 0) &&
6717 (inp->auth_supported == 0)) {
6719 * AUTH is required for
6722 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6725 SCTP_INP_WLOCK(inp);
6726 if (av->assoc_value == 0) {
6727 inp->asconf_supported = 0;
6728 sctp_auth_delete_chunk(SCTP_ASCONF,
6729 inp->sctp_ep.local_auth_chunks);
6730 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6731 inp->sctp_ep.local_auth_chunks);
6733 inp->asconf_supported = 1;
6734 sctp_auth_add_chunk(SCTP_ASCONF,
6735 inp->sctp_ep.local_auth_chunks);
6736 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6737 inp->sctp_ep.local_auth_chunks);
6739 SCTP_INP_WUNLOCK(inp);
6742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6748 case SCTP_RECONFIG_SUPPORTED:
6750 struct sctp_assoc_value *av;
6752 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6753 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6756 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6758 SCTP_TCB_UNLOCK(stcb);
6760 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6761 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6762 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6763 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6764 SCTP_INP_WLOCK(inp);
6765 if (av->assoc_value == 0) {
6766 inp->reconfig_supported = 0;
6768 inp->reconfig_supported = 1;
6770 SCTP_INP_WUNLOCK(inp);
6772 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6778 case SCTP_NRSACK_SUPPORTED:
6780 struct sctp_assoc_value *av;
6782 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6783 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6786 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6788 SCTP_TCB_UNLOCK(stcb);
6790 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6791 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6792 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6793 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6794 SCTP_INP_WLOCK(inp);
6795 if (av->assoc_value == 0) {
6796 inp->nrsack_supported = 0;
6798 inp->nrsack_supported = 1;
6800 SCTP_INP_WUNLOCK(inp);
6802 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6808 case SCTP_PKTDROP_SUPPORTED:
6810 struct sctp_assoc_value *av;
6812 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6813 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6816 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6818 SCTP_TCB_UNLOCK(stcb);
6820 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6821 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6822 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6823 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6824 SCTP_INP_WLOCK(inp);
6825 if (av->assoc_value == 0) {
6826 inp->pktdrop_supported = 0;
6828 inp->pktdrop_supported = 1;
6830 SCTP_INP_WUNLOCK(inp);
6832 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6840 struct sctp_assoc_value *av;
6841 struct sctp_nets *net;
6843 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6844 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6847 stcb->asoc.max_cwnd = av->assoc_value;
6848 if (stcb->asoc.max_cwnd > 0) {
6849 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6850 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6851 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6852 net->cwnd = stcb->asoc.max_cwnd;
6853 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6854 net->cwnd = net->mtu - sizeof(struct sctphdr);
6859 SCTP_TCB_UNLOCK(stcb);
6861 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6862 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6863 ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
6864 (av->assoc_id == SCTP_FUTURE_ASSOC))) {
6865 SCTP_INP_WLOCK(inp);
6866 inp->max_cwnd = av->assoc_value;
6867 SCTP_INP_WUNLOCK(inp);
6869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6877 error = ENOPROTOOPT;
6879 } /* end switch (opt) */
6884 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6886 void *optval = NULL;
6890 struct sctp_inpcb *inp;
6892 if ((sopt->sopt_level == SOL_SOCKET) &&
6893 (sopt->sopt_name == SO_SETFIB)) {
6894 inp = (struct sctp_inpcb *)so->so_pcb;
6896 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6899 SCTP_INP_WLOCK(inp);
6900 inp->fibnum = so->so_fibnum;
6901 SCTP_INP_WUNLOCK(inp);
6904 if (sopt->sopt_level != IPPROTO_SCTP) {
6905 /* wrong proto level... send back up to IP */
6907 if (INP_CHECK_SOCKAF(so, AF_INET6))
6908 error = ip6_ctloutput(so, sopt);
6910 #if defined(INET) && defined(INET6)
6914 error = ip_ctloutput(so, sopt);
6918 optsize = sopt->sopt_valsize;
6919 if (optsize > SCTP_SOCKET_OPTION_LIMIT) {
6920 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6924 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6925 if (optval == NULL) {
6926 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6929 error = sooptcopyin(sopt, optval, optsize, optsize);
6931 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6935 p = (void *)sopt->sopt_td;
6936 if (sopt->sopt_dir == SOPT_SET) {
6937 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6938 } else if (sopt->sopt_dir == SOPT_GET) {
6939 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6941 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6944 if ((error == 0) && (optval != NULL)) {
6945 error = sooptcopyout(sopt, optval, optsize);
6946 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6947 } else if (optval != NULL) {
6948 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6956 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6959 int create_lock_on = 0;
6961 struct sctp_inpcb *inp;
6962 struct sctp_tcb *stcb = NULL;
6964 inp = (struct sctp_inpcb *)so->so_pcb;
6966 /* I made the same as TCP since we are not setup? */
6967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6968 return (ECONNRESET);
6971 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6975 switch (addr->sa_family) {
6979 struct sockaddr_in6 *sin6;
6981 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6985 sin6 = (struct sockaddr_in6 *)addr;
6986 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6->sin6_addr)) != 0) {
6987 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6996 struct sockaddr_in *sin;
6998 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7002 sin = (struct sockaddr_in *)addr;
7003 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sin->sin_addr)) != 0) {
7004 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
7011 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
7012 return (EAFNOSUPPORT);
7014 SCTP_INP_INCR_REF(inp);
7015 SCTP_ASOC_CREATE_LOCK(inp);
7019 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
7020 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
7021 /* Should I really unlock ? */
7022 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
7027 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
7028 (addr->sa_family == AF_INET6)) {
7029 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7034 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
7035 SCTP_PCB_FLAGS_UNBOUND) {
7036 /* Bind a ephemeral port */
7037 error = sctp_inpcb_bind(so, NULL, NULL, p);
7042 /* Now do we connect? */
7043 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
7044 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
7045 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7049 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7050 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7051 /* We are already connected AND the TCP model */
7052 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7056 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7057 SCTP_INP_RLOCK(inp);
7058 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7059 SCTP_INP_RUNLOCK(inp);
7062 * We increment here since sctp_findassociation_ep_addr()
7063 * will do a decrement if it finds the stcb as long as the
7064 * locked tcb (last argument) is NOT a TCB.. aka NULL.
7066 SCTP_INP_INCR_REF(inp);
7067 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7069 SCTP_INP_DECR_REF(inp);
7071 SCTP_TCB_UNLOCK(stcb);
7075 /* Already have or am bring up an association */
7076 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7081 vrf_id = inp->def_vrf_id;
7082 /* We are GOOD to go */
7083 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
7084 inp->sctp_ep.pre_open_stream_count,
7085 inp->sctp_ep.port, p,
7086 SCTP_INITIALIZE_AUTH_PARAMS);
7088 /* Gak! no memory */
7091 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7092 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7093 /* Set the connected flag so we can queue data */
7096 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7097 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7099 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7100 SCTP_TCB_UNLOCK(stcb);
7102 if (create_lock_on) {
7103 SCTP_ASOC_CREATE_UNLOCK(inp);
7106 SCTP_INP_DECR_REF(inp);
7112 sctp_listen(struct socket *so, int backlog, struct thread *p)
7115 * Note this module depends on the protocol processing being called
7116 * AFTER any socket level flags and backlog are applied to the
7117 * socket. The traditional way that the socket flags are applied is
7118 * AFTER protocol processing. We have made a change to the
7119 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7120 * place if the socket API for SCTP is to work properly.
7124 struct sctp_inpcb *inp;
7126 inp = (struct sctp_inpcb *)so->so_pcb;
7128 /* I made the same as TCP since we are not setup? */
7129 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7130 return (ECONNRESET);
7132 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7133 /* See if we have a listener */
7134 struct sctp_inpcb *tinp;
7135 union sctp_sockstore store;
7137 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7139 struct sctp_laddr *laddr;
7141 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7142 memcpy(&store, &laddr->ifa->address, sizeof(store));
7143 switch (store.sa.sa_family) {
7146 store.sin.sin_port = inp->sctp_lport;
7151 store.sin6.sin6_port = inp->sctp_lport;
7157 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7158 if (tinp && (tinp != inp) &&
7159 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7160 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7161 (SCTP_IS_LISTENING(tinp))) {
7163 * we have a listener already and
7166 SCTP_INP_DECR_REF(tinp);
7167 return (EADDRINUSE);
7169 SCTP_INP_DECR_REF(tinp);
7173 /* Setup a local addr bound all */
7174 memset(&store, 0, sizeof(store));
7176 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7177 store.sa.sa_family = AF_INET6;
7178 store.sa.sa_len = sizeof(struct sockaddr_in6);
7182 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7183 store.sa.sa_family = AF_INET;
7184 store.sa.sa_len = sizeof(struct sockaddr_in);
7187 switch (store.sa.sa_family) {
7190 store.sin.sin_port = inp->sctp_lport;
7195 store.sin6.sin6_port = inp->sctp_lport;
7201 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7202 if (tinp && (tinp != inp) &&
7203 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7204 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7205 (SCTP_IS_LISTENING(tinp))) {
7207 * we have a listener already and its not
7210 SCTP_INP_DECR_REF(tinp);
7211 return (EADDRINUSE);
7213 SCTP_INP_DECR_REF(tinp);
7217 SCTP_INP_RLOCK(inp);
7218 #ifdef SCTP_LOCK_LOGGING
7219 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7220 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7224 error = solisten_proto_check(so);
7227 SCTP_INP_RUNLOCK(inp);
7230 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7231 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7233 * The unlucky case - We are in the tcp pool with this guy.
7234 * - Someone else is in the main inp slot. - We must move
7235 * this guy (the listener) to the main slot - We must then
7236 * move the guy that was listener to the TCP Pool.
7238 if (sctp_swap_inpcb_for_listen(inp)) {
7239 SCTP_INP_RUNLOCK(inp);
7240 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7241 return (EADDRINUSE);
7245 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7246 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7247 /* We are already connected AND the TCP model */
7248 SCTP_INP_RUNLOCK(inp);
7249 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7250 return (EADDRINUSE);
7252 SCTP_INP_RUNLOCK(inp);
7253 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7254 /* We must do a bind. */
7255 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7256 /* bind error, probably perm */
7260 SCTP_INP_WLOCK(inp);
7261 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7263 solisten_proto(so, backlog);
7267 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7269 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7271 SCTP_INP_WUNLOCK(inp);
7275 static int sctp_defered_wakeup_cnt = 0;
7278 sctp_accept(struct socket *so, struct sockaddr **addr)
7280 struct sctp_tcb *stcb;
7281 struct sctp_inpcb *inp;
7282 union sctp_sockstore store;
7286 inp = (struct sctp_inpcb *)so->so_pcb;
7289 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7290 return (ECONNRESET);
7292 SCTP_INP_WLOCK(inp);
7293 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7294 SCTP_INP_WUNLOCK(inp);
7295 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7296 return (EOPNOTSUPP);
7298 if (so->so_state & SS_ISDISCONNECTED) {
7299 SCTP_INP_WUNLOCK(inp);
7300 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7301 return (ECONNABORTED);
7303 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7305 SCTP_INP_WUNLOCK(inp);
7306 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7307 return (ECONNRESET);
7309 SCTP_TCB_LOCK(stcb);
7310 store = stcb->asoc.primary_destination->ro._l_addr;
7311 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7312 /* Wake any delayed sleep action */
7313 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7314 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7315 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7316 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7317 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7318 if (sowriteable(inp->sctp_socket)) {
7319 sowwakeup_locked(inp->sctp_socket);
7321 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7324 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7325 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7326 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7327 if (soreadable(inp->sctp_socket)) {
7328 sctp_defered_wakeup_cnt++;
7329 sorwakeup_locked(inp->sctp_socket);
7331 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7335 SCTP_INP_WUNLOCK(inp);
7336 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7337 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7338 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7340 SCTP_TCB_UNLOCK(stcb);
7342 switch (store.sa.sa_family) {
7346 struct sockaddr_in *sin;
7348 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7351 sin->sin_family = AF_INET;
7352 sin->sin_len = sizeof(*sin);
7353 sin->sin_port = store.sin.sin_port;
7354 sin->sin_addr = store.sin.sin_addr;
7355 *addr = (struct sockaddr *)sin;
7362 struct sockaddr_in6 *sin6;
7364 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7367 sin6->sin6_family = AF_INET6;
7368 sin6->sin6_len = sizeof(*sin6);
7369 sin6->sin6_port = store.sin6.sin6_port;
7370 sin6->sin6_addr = store.sin6.sin6_addr;
7371 if ((error = sa6_recoverscope(sin6)) != 0) {
7372 SCTP_FREE_SONAME(sin6);
7375 *addr = (struct sockaddr *)sin6;
7388 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7390 struct sockaddr_in *sin;
7392 struct sctp_inpcb *inp;
7393 struct sctp_ifa *sctp_ifa;
7396 * Do the malloc first in case it blocks.
7398 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7401 sin->sin_family = AF_INET;
7402 sin->sin_len = sizeof(*sin);
7403 inp = (struct sctp_inpcb *)so->so_pcb;
7405 SCTP_FREE_SONAME(sin);
7406 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7407 return (ECONNRESET);
7409 SCTP_INP_RLOCK(inp);
7410 sin->sin_port = inp->sctp_lport;
7411 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7412 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7413 struct sctp_tcb *stcb;
7414 struct sockaddr_in *sin_a;
7415 struct sctp_nets *net;
7418 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7424 SCTP_TCB_LOCK(stcb);
7425 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7426 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7428 /* this will make coverity happy */
7431 if (sin_a->sin_family == AF_INET) {
7436 if ((!fnd) || (sin_a == NULL)) {
7438 SCTP_TCB_UNLOCK(stcb);
7442 vrf_id = inp->def_vrf_id;
7443 sctp_ifa = sctp_source_address_selection(inp,
7445 (sctp_route_t *)&net->ro,
7448 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7449 sctp_free_ifa(sctp_ifa);
7451 SCTP_TCB_UNLOCK(stcb);
7453 /* For the bound all case you get back 0 */
7455 sin->sin_addr.s_addr = 0;
7459 /* Take the first IPv4 address in the list */
7460 struct sctp_laddr *laddr;
7463 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7464 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7465 struct sockaddr_in *sin_a;
7467 sin_a = &laddr->ifa->address.sin;
7468 sin->sin_addr = sin_a->sin_addr;
7474 SCTP_FREE_SONAME(sin);
7475 SCTP_INP_RUNLOCK(inp);
7476 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7480 SCTP_INP_RUNLOCK(inp);
7481 (*addr) = (struct sockaddr *)sin;
7486 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7488 struct sockaddr_in *sin;
7490 struct sockaddr_in *sin_a;
7491 struct sctp_inpcb *inp;
7492 struct sctp_tcb *stcb;
7493 struct sctp_nets *net;
7495 /* Do the malloc first in case it blocks. */
7496 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7499 sin->sin_family = AF_INET;
7500 sin->sin_len = sizeof(*sin);
7502 inp = (struct sctp_inpcb *)so->so_pcb;
7503 if ((inp == NULL) ||
7504 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7505 /* UDP type and listeners will drop out here */
7506 SCTP_FREE_SONAME(sin);
7507 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7510 SCTP_INP_RLOCK(inp);
7511 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7513 SCTP_TCB_LOCK(stcb);
7515 SCTP_INP_RUNLOCK(inp);
7517 SCTP_FREE_SONAME(sin);
7518 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7519 return (ECONNRESET);
7522 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7523 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7524 if (sin_a->sin_family == AF_INET) {
7526 sin->sin_port = stcb->rport;
7527 sin->sin_addr = sin_a->sin_addr;
7531 SCTP_TCB_UNLOCK(stcb);
7533 /* No IPv4 address */
7534 SCTP_FREE_SONAME(sin);
7535 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7538 (*addr) = (struct sockaddr *)sin;
7542 struct pr_usrreqs sctp_usrreqs = {
7543 .pru_abort = sctp_abort,
7544 .pru_accept = sctp_accept,
7545 .pru_attach = sctp_attach,
7546 .pru_bind = sctp_bind,
7547 .pru_connect = sctp_connect,
7548 .pru_control = in_control,
7549 .pru_close = sctp_close,
7550 .pru_detach = sctp_close,
7551 .pru_sopoll = sopoll_generic,
7552 .pru_flush = sctp_flush,
7553 .pru_disconnect = sctp_disconnect,
7554 .pru_listen = sctp_listen,
7555 .pru_peeraddr = sctp_peeraddr,
7556 .pru_send = sctp_sendm,
7557 .pru_shutdown = sctp_shutdown,
7558 .pru_sockaddr = sctp_ingetaddr,
7559 .pru_sosend = sctp_sosend,
7560 .pru_soreceive = sctp_soreceive