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>
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);
96 sctp_finish(void *unused __unused)
101 VNET_SYSUNINIT(sctp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, sctp_finish, NULL);
105 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
107 struct sctp_tmit_chunk *chk;
110 /* Adjust that too */
111 stcb->asoc.smallest_mtu = nxtsz;
112 /* now off to subtract IP_DF flag if needed */
113 overhead = IP_HDR_SIZE + sizeof(struct sctphdr);
114 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
115 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
117 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
118 if ((chk->send_size + overhead) > nxtsz) {
119 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
122 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
123 if ((chk->send_size + overhead) > nxtsz) {
125 * For this guy we also mark for immediate resend
126 * since we sent to big of chunk
128 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
129 if (chk->sent < SCTP_DATAGRAM_RESEND) {
130 sctp_flight_size_decrease(chk);
131 sctp_total_flight_decrease(stcb, chk);
132 chk->sent = SCTP_DATAGRAM_RESEND;
133 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
134 chk->rec.data.doing_fast_retransmit = 0;
135 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
136 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
137 chk->whoTo->flight_size,
139 (uint32_t)(uintptr_t)chk->whoTo,
142 /* Clear any time so NO RTT is being done */
151 sctp_notify(struct sctp_inpcb *inp,
152 struct sctp_tcb *stcb,
153 struct sctp_nets *net,
159 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
164 if (icmp_type != ICMP_UNREACH) {
165 /* We only care about unreachable */
166 SCTP_TCB_UNLOCK(stcb);
169 if ((icmp_code == ICMP_UNREACH_NET) ||
170 (icmp_code == ICMP_UNREACH_HOST) ||
171 (icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
172 (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
173 (icmp_code == ICMP_UNREACH_ISOLATED) ||
174 (icmp_code == ICMP_UNREACH_NET_PROHIB) ||
175 (icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
176 (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
177 /* Mark the net unreachable. */
178 if (net->dest_state & SCTP_ADDR_REACHABLE) {
179 /* OK, that destination is NOT reachable. */
180 net->dest_state &= ~SCTP_ADDR_REACHABLE;
181 net->dest_state &= ~SCTP_ADDR_PF;
182 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
184 (void *)net, SCTP_SO_NOT_LOCKED);
186 SCTP_TCB_UNLOCK(stcb);
187 } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) ||
188 (icmp_code == ICMP_UNREACH_PORT)) {
189 /* Treat it like an ABORT. */
190 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
191 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
192 so = SCTP_INP_SO(inp);
193 atomic_add_int(&stcb->asoc.refcnt, 1);
194 SCTP_TCB_UNLOCK(stcb);
195 SCTP_SOCKET_LOCK(so, 1);
197 atomic_subtract_int(&stcb->asoc.refcnt, 1);
199 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
200 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
201 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
202 SCTP_SOCKET_UNLOCK(so, 1);
203 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
205 /* no need to unlock here, since the TCB is gone */
206 } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) {
207 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
208 SCTP_TCB_UNLOCK(stcb);
211 /* Find the next (smaller) MTU */
214 * Old type router that does not tell us what the
215 * next MTU is. Rats we will have to guess (in a
216 * educated fashion of course).
218 next_mtu = sctp_get_prev_mtu(ip_len);
220 /* Stop the PMTU timer. */
221 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
223 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
224 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
228 /* Update the path MTU. */
230 next_mtu -= sizeof(struct udphdr);
232 if (net->mtu > next_mtu) {
235 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu + sizeof(struct udphdr));
237 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu);
240 /* Update the association MTU */
241 if (stcb->asoc.smallest_mtu > next_mtu) {
242 sctp_pathmtu_adjustment(stcb, next_mtu);
244 /* Finally, start the PMTU timer if it was running before. */
246 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
248 SCTP_TCB_UNLOCK(stcb);
250 SCTP_TCB_UNLOCK(stcb);
255 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
261 struct sctp_inpcb *inp;
262 struct sctp_tcb *stcb;
263 struct sctp_nets *net;
264 struct sctp_init_chunk *ch;
265 struct sockaddr_in src, dst;
267 if (sa->sa_family != AF_INET ||
268 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
271 if (PRC_IS_REDIRECT(cmd)) {
273 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
277 inner_ip = (struct ip *)vip;
278 icmp = (struct icmp *)((caddr_t)inner_ip -
279 (sizeof(struct icmp) - sizeof(struct ip)));
280 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
281 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
282 memset(&src, 0, sizeof(struct sockaddr_in));
283 src.sin_family = AF_INET;
284 src.sin_len = sizeof(struct sockaddr_in);
285 src.sin_port = sh->src_port;
286 src.sin_addr = inner_ip->ip_src;
287 memset(&dst, 0, sizeof(struct sockaddr_in));
288 dst.sin_family = AF_INET;
289 dst.sin_len = sizeof(struct sockaddr_in);
290 dst.sin_port = sh->dest_port;
291 dst.sin_addr = inner_ip->ip_dst;
293 * 'dst' holds the dest of the packet that failed to be
294 * sent. 'src' holds our local endpoint address. Thus we
295 * reverse the dst and the src in the lookup.
299 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
300 (struct sockaddr *)&src,
303 if ((stcb != NULL) &&
306 /* Check the verification tag */
307 if (ntohl(sh->v_tag) != 0) {
309 * This must be the verification tag used
310 * for sending out packets. We don't
311 * consider packets reflecting the
314 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
315 SCTP_TCB_UNLOCK(stcb);
319 if (ntohs(outer_ip->ip_len) >=
321 8 + (inner_ip->ip_hl << 2) + 20) {
323 * In this case we can check if we
324 * got an INIT chunk and if the
325 * initiate tag matches.
327 ch = (struct sctp_init_chunk *)(sh + 1);
328 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
329 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
330 SCTP_TCB_UNLOCK(stcb);
334 SCTP_TCB_UNLOCK(stcb);
338 sctp_notify(inp, stcb, net,
341 ntohs(inner_ip->ip_len),
342 (uint32_t)ntohs(icmp->icmp_nextmtu));
344 if ((stcb == NULL) && (inp != NULL)) {
345 /* reduce ref-count */
347 SCTP_INP_DECR_REF(inp);
348 SCTP_INP_WUNLOCK(inp);
351 SCTP_TCB_UNLOCK(stcb);
360 sctp_getcred(SYSCTL_HANDLER_ARGS)
363 struct sockaddr_in addrs[2];
364 struct sctp_inpcb *inp;
365 struct sctp_nets *net;
366 struct sctp_tcb *stcb;
370 /* FIX, for non-bsd is this right? */
371 vrf_id = SCTP_DEFAULT_VRFID;
373 error = priv_check(req->td, PRIV_NETINET_GETCRED);
378 error = SYSCTL_IN(req, addrs, sizeof(addrs));
382 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
384 &inp, &net, 1, vrf_id);
385 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
386 if ((inp != NULL) && (stcb == NULL)) {
387 /* reduce ref-count */
389 SCTP_INP_DECR_REF(inp);
392 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
396 SCTP_TCB_UNLOCK(stcb);
398 * We use the write lock here, only since in the error leg we need
399 * it. If we used RLOCK, then we would have to
400 * wlock/decr/unlock/rlock. Which in theory could create a hole.
401 * Better to use higher wlock.
405 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
407 SCTP_INP_WUNLOCK(inp);
410 cru2x(inp->sctp_socket->so_cred, &xuc);
411 SCTP_INP_WUNLOCK(inp);
412 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
417 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
418 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
423 sctp_abort(struct socket *so)
425 struct sctp_inpcb *inp;
428 inp = (struct sctp_inpcb *)so->so_pcb;
433 flags = inp->sctp_flags;
434 #ifdef SCTP_LOG_CLOSING
435 sctp_log_closing(inp, NULL, 17);
437 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
438 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
439 #ifdef SCTP_LOG_CLOSING
440 sctp_log_closing(inp, NULL, 16);
442 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
443 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
445 SCTP_SB_CLEAR(so->so_snd);
447 * same for the rcv ones, they are only here for the
450 SCTP_SB_CLEAR(so->so_rcv);
452 /* Now null out the reference, we are completely detached. */
456 flags = inp->sctp_flags;
457 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
458 goto sctp_must_try_again;
465 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
467 struct sctp_inpcb *inp;
468 struct inpcb *ip_inp;
470 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
472 inp = (struct sctp_inpcb *)so->so_pcb;
474 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
477 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
478 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
483 error = sctp_inpcb_alloc(so, vrf_id);
487 inp = (struct sctp_inpcb *)so->so_pcb;
489 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
490 ip_inp = &inp->ip_inp.inp;
491 ip_inp->inp_vflag |= INP_IPV4;
492 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
493 SCTP_INP_WUNLOCK(inp);
498 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
500 struct sctp_inpcb *inp;
502 inp = (struct sctp_inpcb *)so->so_pcb;
504 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
508 if ((addr->sa_family != AF_INET) ||
509 (addr->sa_len != sizeof(struct sockaddr_in))) {
510 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
514 return (sctp_inpcb_bind(so, addr, NULL, p));
519 sctp_close(struct socket *so)
521 struct sctp_inpcb *inp;
524 inp = (struct sctp_inpcb *)so->so_pcb;
529 * Inform all the lower layer assoc that we are done.
532 flags = inp->sctp_flags;
533 #ifdef SCTP_LOG_CLOSING
534 sctp_log_closing(inp, NULL, 17);
536 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
537 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
538 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
539 (so->so_rcv.sb_cc > 0)) {
540 #ifdef SCTP_LOG_CLOSING
541 sctp_log_closing(inp, NULL, 13);
543 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
544 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
546 #ifdef SCTP_LOG_CLOSING
547 sctp_log_closing(inp, NULL, 14);
549 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
550 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
553 * The socket is now detached, no matter what the state of
554 * the SCTP association.
557 SCTP_SB_CLEAR(so->so_snd);
559 * same for the rcv ones, they are only here for the
562 SCTP_SB_CLEAR(so->so_rcv);
564 /* Now null out the reference, we are completely detached. */
568 flags = inp->sctp_flags;
569 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
570 goto sctp_must_try_again;
578 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
579 struct mbuf *control, struct thread *p);
583 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
584 struct mbuf *control, struct thread *p)
586 struct sctp_inpcb *inp;
589 inp = (struct sctp_inpcb *)so->so_pcb;
592 sctp_m_freem(control);
595 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
599 /* Got to have an to address if we are NOT a connected socket */
600 if ((addr == NULL) &&
601 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
602 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
604 } else if (addr == NULL) {
605 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
606 error = EDESTADDRREQ;
609 sctp_m_freem(control);
615 if (addr->sa_family != AF_INET) {
616 /* must be a v4 address! */
617 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
620 sctp_m_freem(control);
623 error = EDESTADDRREQ;
628 /* now what about control */
631 SCTP_PRINTF("huh? control set?\n");
632 sctp_m_freem(inp->control);
635 inp->control = control;
639 SCTP_BUF_NEXT(inp->pkt_last) = m;
642 inp->pkt_last = inp->pkt = m;
645 /* FreeBSD uses a flag passed */
646 ((flags & PRUS_MORETOCOME) == 0)
649 * note with the current version this code will only be used
650 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
651 * re-defining sosend to use the sctp_sosend. One can
652 * optionally switch back to this code (by changing back the
653 * definitions) but this is not advisable. This code is used
654 * by FreeBSD when sending a file with sendfile() though.
658 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
668 sctp_disconnect(struct socket *so)
670 struct sctp_inpcb *inp;
672 inp = (struct sctp_inpcb *)so->so_pcb;
674 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
678 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
679 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
680 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
682 SCTP_INP_RUNLOCK(inp);
685 struct sctp_association *asoc;
686 struct sctp_tcb *stcb;
688 stcb = LIST_FIRST(&inp->sctp_asoc_list);
690 SCTP_INP_RUNLOCK(inp);
691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
696 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
697 /* We are about to be freed, out of here */
698 SCTP_TCB_UNLOCK(stcb);
699 SCTP_INP_RUNLOCK(inp);
702 if (((so->so_options & SO_LINGER) &&
703 (so->so_linger == 0)) ||
704 (so->so_rcv.sb_cc > 0)) {
705 if (SCTP_GET_STATE(asoc) !=
706 SCTP_STATE_COOKIE_WAIT) {
707 /* Left with Data unread */
710 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
711 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
712 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
714 SCTP_INP_RUNLOCK(inp);
715 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
716 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
717 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
719 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
720 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
721 /* No unlock tcb assoc is gone */
724 if (TAILQ_EMPTY(&asoc->send_queue) &&
725 TAILQ_EMPTY(&asoc->sent_queue) &&
726 (asoc->stream_queue_cnt == 0)) {
727 /* there is nothing queued to send, so done */
728 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
731 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
732 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
733 /* only send SHUTDOWN 1st time thru */
734 struct sctp_nets *netp;
736 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
737 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
738 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
740 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
741 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
742 sctp_stop_timers_for_shutdown(stcb);
743 if (stcb->asoc.alternate) {
744 netp = stcb->asoc.alternate;
746 netp = stcb->asoc.primary_destination;
748 sctp_send_shutdown(stcb, netp);
749 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
750 stcb->sctp_ep, stcb, netp);
751 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
752 stcb->sctp_ep, stcb, netp);
753 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
757 * we still got (or just got) data to send,
758 * so set SHUTDOWN_PENDING
761 * XXX sockets draft says that SCTP_EOF
762 * should be sent with no data. currently,
763 * we will allow user data to be sent first
764 * and move to SHUTDOWN-PENDING
766 struct sctp_nets *netp;
768 if (stcb->asoc.alternate) {
769 netp = stcb->asoc.alternate;
771 netp = stcb->asoc.primary_destination;
774 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
775 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
777 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
778 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
780 if (TAILQ_EMPTY(&asoc->send_queue) &&
781 TAILQ_EMPTY(&asoc->sent_queue) &&
782 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
786 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
787 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
788 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
789 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
790 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
791 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
792 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
794 SCTP_INP_RUNLOCK(inp);
795 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
796 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
799 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
802 soisdisconnecting(so);
803 SCTP_TCB_UNLOCK(stcb);
804 SCTP_INP_RUNLOCK(inp);
809 /* UDP model does not support this */
810 SCTP_INP_RUNLOCK(inp);
811 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
817 sctp_flush(struct socket *so, int how)
820 * We will just clear out the values and let subsequent close clear
821 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
822 * they will not be able to read the data, the socket will block
823 * that from happening.
825 struct sctp_inpcb *inp;
827 inp = (struct sctp_inpcb *)so->so_pcb;
829 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
833 /* For the 1 to many model this does nothing */
834 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
835 SCTP_INP_RUNLOCK(inp);
838 SCTP_INP_RUNLOCK(inp);
839 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
841 * First make sure the sb will be happy, we don't use these
842 * except maybe the count
845 SCTP_INP_READ_LOCK(inp);
846 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
847 SCTP_INP_READ_UNLOCK(inp);
848 SCTP_INP_WUNLOCK(inp);
849 so->so_rcv.sb_cc = 0;
850 so->so_rcv.sb_mbcnt = 0;
851 so->so_rcv.sb_mb = NULL;
853 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
855 * First make sure the sb will be happy, we don't use these
856 * except maybe the count
858 so->so_snd.sb_cc = 0;
859 so->so_snd.sb_mbcnt = 0;
860 so->so_snd.sb_mb = NULL;
867 sctp_shutdown(struct socket *so)
869 struct sctp_inpcb *inp;
871 inp = (struct sctp_inpcb *)so->so_pcb;
873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
877 /* For UDP model this is a invalid call */
878 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
879 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
880 /* Restore the flags that the soshutdown took away. */
881 SOCKBUF_LOCK(&so->so_rcv);
882 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
883 SOCKBUF_UNLOCK(&so->so_rcv);
884 /* This proc will wakeup for read and do nothing (I hope) */
885 SCTP_INP_RUNLOCK(inp);
886 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
890 * Ok, if we reach here its the TCP model and it is either a
891 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
894 struct sctp_tcb *stcb;
895 struct sctp_association *asoc;
896 struct sctp_nets *netp;
899 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
900 SCTP_INP_RUNLOCK(inp);
905 stcb = LIST_FIRST(&inp->sctp_asoc_list);
908 * Ok, we hit the case that the shutdown call was
909 * made after an abort or something. Nothing to do
912 SCTP_INP_RUNLOCK(inp);
917 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
918 SCTP_TCB_UNLOCK(stcb);
919 SCTP_INP_RUNLOCK(inp);
922 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_WAIT) &&
923 (SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_ECHOED) &&
924 (SCTP_GET_STATE(asoc) != SCTP_STATE_OPEN)) {
926 * If we are not in or before ESTABLISHED, there is
927 * no protocol action required.
929 SCTP_TCB_UNLOCK(stcb);
930 SCTP_INP_RUNLOCK(inp);
933 if (stcb->asoc.alternate) {
934 netp = stcb->asoc.alternate;
936 netp = stcb->asoc.primary_destination;
938 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) &&
939 TAILQ_EMPTY(&asoc->send_queue) &&
940 TAILQ_EMPTY(&asoc->sent_queue) &&
941 (asoc->stream_queue_cnt == 0)) {
942 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
945 /* there is nothing queued to send, so I'm done... */
946 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
947 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
948 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
949 sctp_stop_timers_for_shutdown(stcb);
950 sctp_send_shutdown(stcb, netp);
951 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
952 stcb->sctp_ep, stcb, netp);
955 * We still got (or just got) data to send, so set
958 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
959 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
960 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_PARTIAL_MSG_LEFT);
962 if (TAILQ_EMPTY(&asoc->send_queue) &&
963 TAILQ_EMPTY(&asoc->sent_queue) &&
964 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
968 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
969 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
970 sctp_abort_an_association(stcb->sctp_ep, stcb,
971 op_err, SCTP_SO_LOCKED);
972 SCTP_INP_RUNLOCK(inp);
976 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp);
978 * XXX: Why do this in the case where we have still data
981 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
982 SCTP_TCB_UNLOCK(stcb);
983 SCTP_INP_RUNLOCK(inp);
989 * copies a "user" presentable address and removes embedded scope, etc.
990 * returns 0 on success, 1 on error
993 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
996 struct sockaddr_in6 lsa6;
998 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1001 memcpy(ss, sa, sa->sa_len);
1008 * NOTE: assumes addr lock is held
1011 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1012 struct sctp_tcb *stcb,
1014 struct sockaddr_storage *sas,
1017 struct sctp_ifn *sctp_ifn;
1018 struct sctp_ifa *sctp_ifa;
1022 int ipv4_local_scope, ipv4_addr_legal;
1025 int local_scope, site_scope, ipv6_addr_legal;
1027 struct sctp_vrf *vrf;
1034 /* Turn on all the appropriate scope */
1035 loopback_scope = stcb->asoc.scope.loopback_scope;
1037 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1038 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1041 local_scope = stcb->asoc.scope.local_scope;
1042 site_scope = stcb->asoc.scope.site_scope;
1043 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1046 /* Use generic values for endpoints. */
1049 ipv4_local_scope = 1;
1055 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1057 ipv6_addr_legal = 1;
1060 if (SCTP_IPV6_V6ONLY(inp)) {
1061 ipv4_addr_legal = 0;
1063 ipv4_addr_legal = 1;
1068 ipv6_addr_legal = 0;
1071 ipv4_addr_legal = 1;
1075 vrf = sctp_find_vrf(vrf_id);
1079 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1080 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1081 if ((loopback_scope == 0) &&
1082 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1083 /* Skip loopback if loopback_scope not set */
1086 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1089 * For the BOUND-ALL case, the list
1090 * associated with a TCB is Always
1091 * considered a reverse list.. i.e.
1092 * it lists addresses that are NOT
1093 * part of the association. If this
1094 * is one of those we must skip it.
1096 if (sctp_is_addr_restricted(stcb,
1101 switch (sctp_ifa->address.sa.sa_family) {
1104 if (ipv4_addr_legal) {
1105 struct sockaddr_in *sin;
1107 sin = &sctp_ifa->address.sin;
1108 if (sin->sin_addr.s_addr == 0) {
1116 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1117 &sin->sin_addr) != 0) {
1120 if ((ipv4_local_scope == 0) &&
1121 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1125 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1126 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1127 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1128 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1129 actual += sizeof(struct sockaddr_in6);
1132 memcpy(sas, sin, sizeof(*sin));
1133 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1134 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1135 actual += sizeof(*sin);
1139 if (actual >= limit) {
1149 if (ipv6_addr_legal) {
1150 struct sockaddr_in6 *sin6;
1152 sin6 = &sctp_ifa->address.sin6;
1153 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1161 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1162 &sin6->sin6_addr) != 0) {
1165 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1166 if (local_scope == 0)
1168 if (sin6->sin6_scope_id == 0) {
1169 if (sa6_recoverscope(sin6) != 0)
1182 if ((site_scope == 0) &&
1183 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1186 memcpy(sas, sin6, sizeof(*sin6));
1187 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1188 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1189 actual += sizeof(*sin6);
1190 if (actual >= limit) {
1205 struct sctp_laddr *laddr;
1207 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1209 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1213 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1215 switch (laddr->ifa->address.sa.sa_family) {
1218 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1223 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1230 sas = (struct sockaddr_storage *)((caddr_t)sas +
1231 laddr->ifa->address.sa.sa_len);
1232 actual += laddr->ifa->address.sa.sa_len;
1233 if (actual >= limit) {
1242 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1243 struct sctp_tcb *stcb,
1245 struct sockaddr_storage *sas)
1249 SCTP_IPI_ADDR_RLOCK();
1250 /* fill up addresses for the endpoint's default vrf */
1251 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1253 SCTP_IPI_ADDR_RUNLOCK();
1258 * NOTE: assumes addr lock is held
1261 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1264 struct sctp_vrf *vrf = NULL;
1267 * In both sub-set bound an bound_all cases we return the MAXIMUM
1268 * number of addresses that you COULD get. In reality the sub-set
1269 * bound may have an exclusion list for a given TCB OR in the
1270 * bound-all case a TCB may NOT include the loopback or other
1271 * addresses as well.
1273 vrf = sctp_find_vrf(vrf_id);
1277 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1278 struct sctp_ifn *sctp_ifn;
1279 struct sctp_ifa *sctp_ifa;
1281 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1282 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1283 /* Count them if they are the right type */
1284 switch (sctp_ifa->address.sa.sa_family) {
1288 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1289 cnt += sizeof(struct sockaddr_in6);
1291 cnt += sizeof(struct sockaddr_in);
1293 cnt += sizeof(struct sockaddr_in);
1299 cnt += sizeof(struct sockaddr_in6);
1308 struct sctp_laddr *laddr;
1310 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1311 switch (laddr->ifa->address.sa.sa_family) {
1315 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1316 cnt += sizeof(struct sockaddr_in6);
1318 cnt += sizeof(struct sockaddr_in);
1320 cnt += sizeof(struct sockaddr_in);
1326 cnt += sizeof(struct sockaddr_in6);
1338 sctp_count_max_addresses(struct sctp_inpcb *inp)
1342 SCTP_IPI_ADDR_RLOCK();
1343 /* count addresses for the endpoint's default VRF */
1344 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1345 SCTP_IPI_ADDR_RUNLOCK();
1350 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1351 size_t optsize, void *p, int delay)
1354 int creat_lock_on = 0;
1355 struct sctp_tcb *stcb = NULL;
1356 struct sockaddr *sa;
1357 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1359 int bad_addresses = 0;
1362 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1364 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1365 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1366 /* We are already connected AND the TCP model */
1367 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1368 return (EADDRINUSE);
1370 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1371 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1372 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1375 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1376 SCTP_INP_RLOCK(inp);
1377 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1378 SCTP_INP_RUNLOCK(inp);
1381 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1384 SCTP_INP_INCR_REF(inp);
1385 SCTP_ASOC_CREATE_LOCK(inp);
1387 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1388 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1389 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1393 totaddrp = (unsigned int *)optval;
1394 totaddr = *totaddrp;
1395 sa = (struct sockaddr *)(totaddrp + 1);
1396 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (unsigned int)(optsize - sizeof(int)), &bad_addresses);
1397 if ((stcb != NULL) || bad_addresses) {
1398 /* Already have or am bring up an association */
1399 SCTP_ASOC_CREATE_UNLOCK(inp);
1402 SCTP_TCB_UNLOCK(stcb);
1403 if (bad_addresses == 0) {
1404 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1410 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1415 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1417 struct in6pcb *inp6;
1419 inp6 = (struct in6pcb *)inp;
1420 if (SCTP_IPV6_V6ONLY(inp6)) {
1422 * if IPV6_V6ONLY flag, ignore connections destined
1423 * to a v4 addr or v4-mapped addr
1425 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1431 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1432 SCTP_PCB_FLAGS_UNBOUND) {
1433 /* Bind a ephemeral port */
1434 error = sctp_inpcb_bind(so, NULL, NULL, p);
1439 /* FIX ME: do we want to pass in a vrf on the connect call? */
1440 vrf_id = inp->def_vrf_id;
1443 /* We are GOOD to go */
1444 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1445 inp->sctp_ep.pre_open_stream_count,
1450 /* Gak! no memory */
1453 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1454 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1455 /* Set the connected flag so we can queue data */
1458 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1459 /* move to second address */
1460 switch (sa->sa_family) {
1463 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1468 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1476 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1477 /* Fill in the return id */
1479 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE,
1480 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
1483 a_id = (sctp_assoc_t *)optval;
1484 *a_id = sctp_get_associd(stcb);
1486 /* initialize authentication parameters for the assoc */
1487 sctp_initialize_auth_params(inp, stcb);
1490 /* doing delayed connection */
1491 stcb->asoc.delayed_connection = 1;
1492 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1494 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1495 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1497 SCTP_TCB_UNLOCK(stcb);
1499 if (creat_lock_on) {
1500 SCTP_ASOC_CREATE_UNLOCK(inp);
1502 SCTP_INP_DECR_REF(inp);
1506 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1507 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1508 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1509 SCTP_INP_RLOCK(inp); \
1510 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1512 SCTP_TCB_LOCK(stcb); \
1514 SCTP_INP_RUNLOCK(inp); \
1515 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1516 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1517 if (stcb == NULL) { \
1518 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1528 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1529 if (size < sizeof(type)) { \
1530 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1534 destp = (type *)srcp; \
1539 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1542 struct sctp_inpcb *inp = NULL;
1544 struct sctp_tcb *stcb = NULL;
1546 if (optval == NULL) {
1547 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1550 inp = (struct sctp_inpcb *)so->so_pcb;
1552 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1559 case SCTP_AUTOCLOSE:
1560 case SCTP_EXPLICIT_EOR:
1561 case SCTP_AUTO_ASCONF:
1562 case SCTP_DISABLE_FRAGMENTS:
1563 case SCTP_I_WANT_MAPPED_V4_ADDR:
1564 case SCTP_USE_EXT_RCVINFO:
1565 SCTP_INP_RLOCK(inp);
1567 case SCTP_DISABLE_FRAGMENTS:
1568 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1570 case SCTP_I_WANT_MAPPED_V4_ADDR:
1571 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1573 case SCTP_AUTO_ASCONF:
1574 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1575 /* only valid for bound all sockets */
1576 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1578 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1583 case SCTP_EXPLICIT_EOR:
1584 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1587 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1589 case SCTP_USE_EXT_RCVINFO:
1590 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1592 case SCTP_AUTOCLOSE:
1593 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1594 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1600 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1601 error = ENOPROTOOPT;
1602 } /* end switch (sopt->sopt_name) */
1603 if (*optsize < sizeof(val)) {
1604 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1608 SCTP_INP_RUNLOCK(inp);
1610 /* return the option value */
1611 *(int *)optval = val;
1612 *optsize = sizeof(val);
1615 case SCTP_GET_PACKET_LOG:
1617 #ifdef SCTP_PACKET_LOGGING
1621 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1622 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1625 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1630 case SCTP_REUSE_PORT:
1634 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1635 /* Can't do this for a 1-m socket */
1639 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1640 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1641 *optsize = sizeof(uint32_t);
1644 case SCTP_PARTIAL_DELIVERY_POINT:
1648 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1649 *value = inp->partial_delivery_point;
1650 *optsize = sizeof(uint32_t);
1653 case SCTP_FRAGMENT_INTERLEAVE:
1657 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1658 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1659 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1660 *value = SCTP_FRAG_LEVEL_2;
1662 *value = SCTP_FRAG_LEVEL_1;
1665 *value = SCTP_FRAG_LEVEL_0;
1667 *optsize = sizeof(uint32_t);
1670 case SCTP_INTERLEAVING_SUPPORTED:
1672 struct sctp_assoc_value *av;
1674 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1675 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1678 av->assoc_value = stcb->asoc.idata_supported;
1679 SCTP_TCB_UNLOCK(stcb);
1681 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1682 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1683 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1684 SCTP_INP_RLOCK(inp);
1685 if (inp->idata_supported) {
1686 av->assoc_value = 1;
1688 av->assoc_value = 0;
1690 SCTP_INP_RUNLOCK(inp);
1692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1697 *optsize = sizeof(struct sctp_assoc_value);
1701 case SCTP_CMT_ON_OFF:
1703 struct sctp_assoc_value *av;
1705 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1706 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1708 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1709 SCTP_TCB_UNLOCK(stcb);
1711 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1712 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1713 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1714 SCTP_INP_RLOCK(inp);
1715 av->assoc_value = inp->sctp_cmt_on_off;
1716 SCTP_INP_RUNLOCK(inp);
1718 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1723 *optsize = sizeof(struct sctp_assoc_value);
1727 case SCTP_PLUGGABLE_CC:
1729 struct sctp_assoc_value *av;
1731 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1732 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1734 av->assoc_value = stcb->asoc.congestion_control_module;
1735 SCTP_TCB_UNLOCK(stcb);
1737 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1738 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1739 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1740 SCTP_INP_RLOCK(inp);
1741 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1742 SCTP_INP_RUNLOCK(inp);
1744 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1749 *optsize = sizeof(struct sctp_assoc_value);
1753 case SCTP_CC_OPTION:
1755 struct sctp_cc_option *cc_opt;
1757 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1758 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1762 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1765 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1766 *optsize = sizeof(struct sctp_cc_option);
1768 SCTP_TCB_UNLOCK(stcb);
1772 case SCTP_PLUGGABLE_SS:
1774 struct sctp_assoc_value *av;
1776 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1777 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1779 av->assoc_value = stcb->asoc.stream_scheduling_module;
1780 SCTP_TCB_UNLOCK(stcb);
1782 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1783 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1784 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1785 SCTP_INP_RLOCK(inp);
1786 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1787 SCTP_INP_RUNLOCK(inp);
1789 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1794 *optsize = sizeof(struct sctp_assoc_value);
1800 struct sctp_stream_value *av;
1802 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1803 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1805 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1806 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1807 &av->stream_value) < 0)) {
1808 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1811 *optsize = sizeof(struct sctp_stream_value);
1813 SCTP_TCB_UNLOCK(stcb);
1816 * Can't get stream value without
1819 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1824 case SCTP_GET_ADDR_LEN:
1826 struct sctp_assoc_value *av;
1828 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1831 if (av->assoc_value == AF_INET) {
1832 av->assoc_value = sizeof(struct sockaddr_in);
1837 if (av->assoc_value == AF_INET6) {
1838 av->assoc_value = sizeof(struct sockaddr_in6);
1843 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1845 *optsize = sizeof(struct sctp_assoc_value);
1849 case SCTP_GET_ASSOC_NUMBER:
1851 uint32_t *value, cnt;
1853 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1854 SCTP_INP_RLOCK(inp);
1855 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1856 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1857 /* Can't do this for a 1-1 socket */
1859 SCTP_INP_RUNLOCK(inp);
1863 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1866 SCTP_INP_RUNLOCK(inp);
1868 *optsize = sizeof(uint32_t);
1871 case SCTP_GET_ASSOC_ID_LIST:
1873 struct sctp_assoc_ids *ids;
1877 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1878 SCTP_INP_RLOCK(inp);
1879 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1880 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1881 /* Can't do this for a 1-1 socket */
1883 SCTP_INP_RUNLOCK(inp);
1887 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1888 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1890 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1893 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1898 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1902 SCTP_INP_RUNLOCK(inp);
1904 ids->gaids_number_of_ids = at;
1905 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1911 struct sctp_assoc_value *av;
1913 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1914 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1917 av->assoc_value = stcb->asoc.context;
1918 SCTP_TCB_UNLOCK(stcb);
1920 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1921 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1922 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1923 SCTP_INP_RLOCK(inp);
1924 av->assoc_value = inp->sctp_context;
1925 SCTP_INP_RUNLOCK(inp);
1927 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1932 *optsize = sizeof(struct sctp_assoc_value);
1938 uint32_t *default_vrfid;
1940 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1941 *default_vrfid = inp->def_vrf_id;
1942 *optsize = sizeof(uint32_t);
1945 case SCTP_GET_ASOC_VRF:
1947 struct sctp_assoc_value *id;
1949 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1950 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1953 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1955 id->assoc_value = stcb->asoc.vrf_id;
1956 SCTP_TCB_UNLOCK(stcb);
1957 *optsize = sizeof(struct sctp_assoc_value);
1961 case SCTP_GET_VRF_IDS:
1963 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1967 case SCTP_GET_NONCE_VALUES:
1969 struct sctp_get_nonce_values *gnv;
1971 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1972 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1975 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1976 gnv->gn_local_tag = stcb->asoc.my_vtag;
1977 SCTP_TCB_UNLOCK(stcb);
1978 *optsize = sizeof(struct sctp_get_nonce_values);
1980 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1985 case SCTP_DELAYED_SACK:
1987 struct sctp_sack_info *sack;
1989 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1990 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1992 sack->sack_delay = stcb->asoc.delayed_ack;
1993 sack->sack_freq = stcb->asoc.sack_freq;
1994 SCTP_TCB_UNLOCK(stcb);
1996 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1997 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1998 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
1999 SCTP_INP_RLOCK(inp);
2000 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2001 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2002 SCTP_INP_RUNLOCK(inp);
2004 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2009 *optsize = sizeof(struct sctp_sack_info);
2013 case SCTP_GET_SNDBUF_USE:
2015 struct sctp_sockstat *ss;
2017 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2018 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2021 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2022 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2023 stcb->asoc.size_on_all_streams);
2024 SCTP_TCB_UNLOCK(stcb);
2025 *optsize = sizeof(struct sctp_sockstat);
2027 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2032 case SCTP_MAX_BURST:
2034 struct sctp_assoc_value *av;
2036 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2037 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2040 av->assoc_value = stcb->asoc.max_burst;
2041 SCTP_TCB_UNLOCK(stcb);
2043 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2044 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2045 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2046 SCTP_INP_RLOCK(inp);
2047 av->assoc_value = inp->sctp_ep.max_burst;
2048 SCTP_INP_RUNLOCK(inp);
2050 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2055 *optsize = sizeof(struct sctp_assoc_value);
2061 struct sctp_assoc_value *av;
2064 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2065 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2068 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2069 SCTP_TCB_UNLOCK(stcb);
2071 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2072 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2073 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2074 SCTP_INP_RLOCK(inp);
2075 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2076 ovh = SCTP_MED_OVERHEAD;
2078 ovh = SCTP_MED_V4_OVERHEAD;
2080 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2081 av->assoc_value = 0;
2083 av->assoc_value = inp->sctp_frag_point - ovh;
2084 SCTP_INP_RUNLOCK(inp);
2086 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2091 *optsize = sizeof(struct sctp_assoc_value);
2095 case SCTP_GET_STAT_LOG:
2096 error = sctp_fill_stat_log(optval, optsize);
2100 struct sctp_event_subscribe *events;
2102 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2103 memset(events, 0, sizeof(struct sctp_event_subscribe));
2104 SCTP_INP_RLOCK(inp);
2105 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2106 events->sctp_data_io_event = 1;
2108 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2109 events->sctp_association_event = 1;
2111 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2112 events->sctp_address_event = 1;
2114 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2115 events->sctp_send_failure_event = 1;
2117 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2118 events->sctp_peer_error_event = 1;
2120 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2121 events->sctp_shutdown_event = 1;
2123 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2124 events->sctp_partial_delivery_event = 1;
2126 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2127 events->sctp_adaptation_layer_event = 1;
2129 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2130 events->sctp_authentication_event = 1;
2132 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2133 events->sctp_sender_dry_event = 1;
2135 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2136 events->sctp_stream_reset_event = 1;
2137 SCTP_INP_RUNLOCK(inp);
2138 *optsize = sizeof(struct sctp_event_subscribe);
2141 case SCTP_ADAPTATION_LAYER:
2145 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2147 SCTP_INP_RLOCK(inp);
2148 *value = inp->sctp_ep.adaptation_layer_indicator;
2149 SCTP_INP_RUNLOCK(inp);
2150 *optsize = sizeof(uint32_t);
2153 case SCTP_SET_INITIAL_DBG_SEQ:
2157 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2158 SCTP_INP_RLOCK(inp);
2159 *value = inp->sctp_ep.initial_sequence_debug;
2160 SCTP_INP_RUNLOCK(inp);
2161 *optsize = sizeof(uint32_t);
2164 case SCTP_GET_LOCAL_ADDR_SIZE:
2168 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2169 SCTP_INP_RLOCK(inp);
2170 *value = sctp_count_max_addresses(inp);
2171 SCTP_INP_RUNLOCK(inp);
2172 *optsize = sizeof(uint32_t);
2175 case SCTP_GET_REMOTE_ADDR_SIZE:
2179 struct sctp_nets *net;
2181 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2182 /* FIXME MT: change to sctp_assoc_value? */
2183 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2187 /* Count the sizes */
2188 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2189 switch (net->ro._l_addr.sa.sa_family) {
2193 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2194 size += sizeof(struct sockaddr_in6);
2196 size += sizeof(struct sockaddr_in);
2199 size += sizeof(struct sockaddr_in);
2205 size += sizeof(struct sockaddr_in6);
2212 SCTP_TCB_UNLOCK(stcb);
2213 *value = (uint32_t)size;
2214 *optsize = sizeof(uint32_t);
2216 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2221 case SCTP_GET_PEER_ADDRESSES:
2223 * Get the address information, an array is passed in to
2224 * fill up we pack it.
2228 struct sockaddr_storage *sas;
2229 struct sctp_nets *net;
2230 struct sctp_getaddresses *saddr;
2232 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2233 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2236 left = (*optsize) - sizeof(struct sctp_getaddresses);
2237 *optsize = sizeof(struct sctp_getaddresses);
2238 sas = (struct sockaddr_storage *)&saddr->addr[0];
2240 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2241 switch (net->ro._l_addr.sa.sa_family) {
2245 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2246 cpsz = sizeof(struct sockaddr_in6);
2248 cpsz = sizeof(struct sockaddr_in);
2251 cpsz = sizeof(struct sockaddr_in);
2257 cpsz = sizeof(struct sockaddr_in6);
2268 /* not enough room. */
2271 #if defined(INET) && defined(INET6)
2272 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2273 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2274 /* Must map the address */
2275 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2276 (struct sockaddr_in6 *)sas);
2278 memcpy(sas, &net->ro._l_addr, cpsz);
2281 memcpy(sas, &net->ro._l_addr, cpsz);
2283 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2285 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2289 SCTP_TCB_UNLOCK(stcb);
2291 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2296 case SCTP_GET_LOCAL_ADDRESSES:
2298 size_t limit, actual;
2299 struct sockaddr_storage *sas;
2300 struct sctp_getaddresses *saddr;
2302 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2303 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2305 sas = (struct sockaddr_storage *)&saddr->addr[0];
2306 limit = *optsize - sizeof(sctp_assoc_t);
2307 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2309 SCTP_TCB_UNLOCK(stcb);
2311 *optsize = sizeof(struct sockaddr_storage) + actual;
2314 case SCTP_PEER_ADDR_PARAMS:
2316 struct sctp_paddrparams *paddrp;
2317 struct sctp_nets *net;
2318 struct sockaddr *addr;
2319 #if defined(INET) && defined(INET6)
2320 struct sockaddr_in sin_store;
2323 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2324 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2326 #if defined(INET) && defined(INET6)
2327 if (paddrp->spp_address.ss_family == AF_INET6) {
2328 struct sockaddr_in6 *sin6;
2330 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2331 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2332 in6_sin6_2_sin(&sin_store, sin6);
2333 addr = (struct sockaddr *)&sin_store;
2335 addr = (struct sockaddr *)&paddrp->spp_address;
2338 addr = (struct sockaddr *)&paddrp->spp_address;
2341 addr = (struct sockaddr *)&paddrp->spp_address;
2344 net = sctp_findnet(stcb, addr);
2347 * We increment here since
2348 * sctp_findassociation_ep_addr() wil do a
2349 * decrement if it finds the stcb as long as
2350 * the locked tcb (last argument) is NOT a
2354 SCTP_INP_INCR_REF(inp);
2355 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2357 SCTP_INP_DECR_REF(inp);
2360 if ((stcb != NULL) && (net == NULL)) {
2362 if (addr->sa_family == AF_INET) {
2363 struct sockaddr_in *sin;
2365 sin = (struct sockaddr_in *)addr;
2366 if (sin->sin_addr.s_addr != INADDR_ANY) {
2368 SCTP_TCB_UNLOCK(stcb);
2369 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2375 if (addr->sa_family == AF_INET6) {
2376 struct sockaddr_in6 *sin6;
2378 sin6 = (struct sockaddr_in6 *)addr;
2379 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2381 SCTP_TCB_UNLOCK(stcb);
2382 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2388 error = EAFNOSUPPORT;
2389 SCTP_TCB_UNLOCK(stcb);
2390 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2395 /* Applies to the specific association */
2396 paddrp->spp_flags = 0;
2398 paddrp->spp_hbinterval = net->heart_beat_delay;
2399 paddrp->spp_pathmaxrxt = net->failure_threshold;
2400 paddrp->spp_pathmtu = net->mtu;
2401 switch (net->ro._l_addr.sa.sa_family) {
2404 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2409 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2415 /* get flags for HB */
2416 if (net->dest_state & SCTP_ADDR_NOHB) {
2417 paddrp->spp_flags |= SPP_HB_DISABLE;
2419 paddrp->spp_flags |= SPP_HB_ENABLE;
2421 /* get flags for PMTU */
2422 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2423 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2425 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2427 if (net->dscp & 0x01) {
2428 paddrp->spp_dscp = net->dscp & 0xfc;
2429 paddrp->spp_flags |= SPP_DSCP;
2432 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2433 (net->flowlabel & 0x80000000)) {
2434 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2435 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2440 * No destination so return default
2443 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2444 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2445 if (stcb->asoc.default_dscp & 0x01) {
2446 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2447 paddrp->spp_flags |= SPP_DSCP;
2450 if (stcb->asoc.default_flowlabel & 0x80000000) {
2451 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2452 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2455 /* default settings should be these */
2456 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2457 paddrp->spp_flags |= SPP_HB_DISABLE;
2459 paddrp->spp_flags |= SPP_HB_ENABLE;
2461 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2462 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2464 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2466 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2468 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2469 SCTP_TCB_UNLOCK(stcb);
2471 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2472 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2473 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2474 /* Use endpoint defaults */
2475 SCTP_INP_RLOCK(inp);
2476 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2477 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2478 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2479 /* get inp's default */
2480 if (inp->sctp_ep.default_dscp & 0x01) {
2481 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2482 paddrp->spp_flags |= SPP_DSCP;
2485 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2486 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2487 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2488 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2491 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2493 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2494 paddrp->spp_flags |= SPP_HB_ENABLE;
2496 paddrp->spp_flags |= SPP_HB_DISABLE;
2498 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2499 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2501 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2503 SCTP_INP_RUNLOCK(inp);
2505 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2510 *optsize = sizeof(struct sctp_paddrparams);
2514 case SCTP_GET_PEER_ADDR_INFO:
2516 struct sctp_paddrinfo *paddri;
2517 struct sctp_nets *net;
2518 struct sockaddr *addr;
2519 #if defined(INET) && defined(INET6)
2520 struct sockaddr_in sin_store;
2523 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2524 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2526 #if defined(INET) && defined(INET6)
2527 if (paddri->spinfo_address.ss_family == AF_INET6) {
2528 struct sockaddr_in6 *sin6;
2530 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2531 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2532 in6_sin6_2_sin(&sin_store, sin6);
2533 addr = (struct sockaddr *)&sin_store;
2535 addr = (struct sockaddr *)&paddri->spinfo_address;
2538 addr = (struct sockaddr *)&paddri->spinfo_address;
2541 addr = (struct sockaddr *)&paddri->spinfo_address;
2544 net = sctp_findnet(stcb, addr);
2547 * We increment here since
2548 * sctp_findassociation_ep_addr() wil do a
2549 * decrement if it finds the stcb as long as
2550 * the locked tcb (last argument) is NOT a
2554 SCTP_INP_INCR_REF(inp);
2555 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2557 SCTP_INP_DECR_REF(inp);
2561 if ((stcb != NULL) && (net != NULL)) {
2562 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2563 /* It's unconfirmed */
2564 paddri->spinfo_state = SCTP_UNCONFIRMED;
2565 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2567 paddri->spinfo_state = SCTP_ACTIVE;
2570 paddri->spinfo_state = SCTP_INACTIVE;
2572 paddri->spinfo_cwnd = net->cwnd;
2573 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2574 paddri->spinfo_rto = net->RTO;
2575 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2576 paddri->spinfo_mtu = net->mtu;
2577 switch (addr->sa_family) {
2580 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2585 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2591 SCTP_TCB_UNLOCK(stcb);
2592 *optsize = sizeof(struct sctp_paddrinfo);
2595 SCTP_TCB_UNLOCK(stcb);
2597 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2602 case SCTP_PCB_STATUS:
2604 struct sctp_pcbinfo *spcb;
2606 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2607 sctp_fill_pcbinfo(spcb);
2608 *optsize = sizeof(struct sctp_pcbinfo);
2613 struct sctp_nets *net;
2614 struct sctp_status *sstat;
2616 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2617 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2620 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2624 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2625 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2626 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2627 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2629 * We can't include chunks that have been passed to
2630 * the socket layer. Only things in queue.
2632 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2633 stcb->asoc.cnt_on_all_streams);
2636 sstat->sstat_instrms = stcb->asoc.streamincnt;
2637 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2638 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2639 memcpy(&sstat->sstat_primary.spinfo_address,
2640 &stcb->asoc.primary_destination->ro._l_addr,
2641 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2642 net = stcb->asoc.primary_destination;
2643 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2645 * Again the user can get info from sctp_constants.h
2646 * for what the state of the network is.
2648 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2649 /* It's unconfirmed */
2650 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2651 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2653 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2656 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2658 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2659 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2660 sstat->sstat_primary.spinfo_rto = net->RTO;
2661 sstat->sstat_primary.spinfo_mtu = net->mtu;
2662 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2665 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2670 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2676 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2677 SCTP_TCB_UNLOCK(stcb);
2678 *optsize = sizeof(struct sctp_status);
2683 struct sctp_rtoinfo *srto;
2685 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2686 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2689 srto->srto_initial = stcb->asoc.initial_rto;
2690 srto->srto_max = stcb->asoc.maxrto;
2691 srto->srto_min = stcb->asoc.minrto;
2692 SCTP_TCB_UNLOCK(stcb);
2694 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2695 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2696 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2697 SCTP_INP_RLOCK(inp);
2698 srto->srto_initial = inp->sctp_ep.initial_rto;
2699 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2700 srto->srto_min = inp->sctp_ep.sctp_minrto;
2701 SCTP_INP_RUNLOCK(inp);
2703 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2708 *optsize = sizeof(struct sctp_rtoinfo);
2714 struct sctp_timeouts *stimo;
2716 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2717 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2720 stimo->stimo_init = stcb->asoc.timoinit;
2721 stimo->stimo_data = stcb->asoc.timodata;
2722 stimo->stimo_sack = stcb->asoc.timosack;
2723 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2724 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2725 stimo->stimo_cookie = stcb->asoc.timocookie;
2726 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2727 SCTP_TCB_UNLOCK(stcb);
2728 *optsize = sizeof(struct sctp_timeouts);
2730 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2735 case SCTP_ASSOCINFO:
2737 struct sctp_assocparams *sasoc;
2739 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2740 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2743 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2744 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2745 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2746 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2747 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2748 SCTP_TCB_UNLOCK(stcb);
2750 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2751 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2752 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2753 SCTP_INP_RLOCK(inp);
2754 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2755 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2756 sasoc->sasoc_number_peer_destinations = 0;
2757 sasoc->sasoc_peer_rwnd = 0;
2758 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2759 SCTP_INP_RUNLOCK(inp);
2761 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2766 *optsize = sizeof(struct sctp_assocparams);
2770 case SCTP_DEFAULT_SEND_PARAM:
2772 struct sctp_sndrcvinfo *s_info;
2774 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2775 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2778 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2779 SCTP_TCB_UNLOCK(stcb);
2781 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2782 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2783 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2784 SCTP_INP_RLOCK(inp);
2785 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2786 SCTP_INP_RUNLOCK(inp);
2788 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2793 *optsize = sizeof(struct sctp_sndrcvinfo);
2799 struct sctp_initmsg *sinit;
2801 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2802 SCTP_INP_RLOCK(inp);
2803 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2804 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2805 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2806 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2807 SCTP_INP_RUNLOCK(inp);
2808 *optsize = sizeof(struct sctp_initmsg);
2811 case SCTP_PRIMARY_ADDR:
2812 /* we allow a "get" operation on this */
2814 struct sctp_setprim *ssp;
2816 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2817 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2820 union sctp_sockstore *addr;
2822 addr = &stcb->asoc.primary_destination->ro._l_addr;
2823 switch (addr->sa.sa_family) {
2827 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2828 in6_sin_2_v4mapsin6(&addr->sin,
2829 (struct sockaddr_in6 *)&ssp->ssp_addr);
2831 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2834 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2840 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2846 SCTP_TCB_UNLOCK(stcb);
2847 *optsize = sizeof(struct sctp_setprim);
2849 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2854 case SCTP_HMAC_IDENT:
2856 struct sctp_hmacalgo *shmac;
2857 sctp_hmaclist_t *hmaclist;
2861 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2863 SCTP_INP_RLOCK(inp);
2864 hmaclist = inp->sctp_ep.local_hmacs;
2865 if (hmaclist == NULL) {
2866 /* no HMACs to return */
2867 *optsize = sizeof(*shmac);
2868 SCTP_INP_RUNLOCK(inp);
2871 /* is there room for all of the hmac ids? */
2872 size = sizeof(*shmac) + (hmaclist->num_algo *
2873 sizeof(shmac->shmac_idents[0]));
2874 if ((size_t)(*optsize) < size) {
2875 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2877 SCTP_INP_RUNLOCK(inp);
2880 /* copy in the list */
2881 shmac->shmac_number_of_idents = hmaclist->num_algo;
2882 for (i = 0; i < hmaclist->num_algo; i++) {
2883 shmac->shmac_idents[i] = hmaclist->hmac[i];
2885 SCTP_INP_RUNLOCK(inp);
2889 case SCTP_AUTH_ACTIVE_KEY:
2891 struct sctp_authkeyid *scact;
2893 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2894 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2897 /* get the active key on the assoc */
2898 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2899 SCTP_TCB_UNLOCK(stcb);
2901 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2902 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2903 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2904 /* get the endpoint active key */
2905 SCTP_INP_RLOCK(inp);
2906 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2907 SCTP_INP_RUNLOCK(inp);
2909 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2914 *optsize = sizeof(struct sctp_authkeyid);
2918 case SCTP_LOCAL_AUTH_CHUNKS:
2920 struct sctp_authchunks *sac;
2921 sctp_auth_chklist_t *chklist = NULL;
2924 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2925 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2928 /* get off the assoc */
2929 chklist = stcb->asoc.local_auth_chunks;
2930 /* is there enough space? */
2931 size = sctp_auth_get_chklist_size(chklist);
2932 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2934 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2936 /* copy in the chunks */
2937 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2938 sac->gauth_number_of_chunks = (uint32_t)size;
2939 *optsize = sizeof(struct sctp_authchunks) + size;
2941 SCTP_TCB_UNLOCK(stcb);
2943 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2944 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2945 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2946 /* get off the endpoint */
2947 SCTP_INP_RLOCK(inp);
2948 chklist = inp->sctp_ep.local_auth_chunks;
2949 /* is there enough space? */
2950 size = sctp_auth_get_chklist_size(chklist);
2951 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2953 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2955 /* copy in the chunks */
2956 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2957 sac->gauth_number_of_chunks = (uint32_t)size;
2958 *optsize = sizeof(struct sctp_authchunks) + size;
2960 SCTP_INP_RUNLOCK(inp);
2962 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2968 case SCTP_PEER_AUTH_CHUNKS:
2970 struct sctp_authchunks *sac;
2971 sctp_auth_chklist_t *chklist = NULL;
2974 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2975 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2978 /* get off the assoc */
2979 chklist = stcb->asoc.peer_auth_chunks;
2980 /* is there enough space? */
2981 size = sctp_auth_get_chklist_size(chklist);
2982 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2984 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2986 /* copy in the chunks */
2987 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2988 sac->gauth_number_of_chunks = (uint32_t)size;
2989 *optsize = sizeof(struct sctp_authchunks) + size;
2991 SCTP_TCB_UNLOCK(stcb);
2993 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3000 struct sctp_event *event;
3001 uint32_t event_type;
3003 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3004 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3006 switch (event->se_type) {
3007 case SCTP_ASSOC_CHANGE:
3008 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3010 case SCTP_PEER_ADDR_CHANGE:
3011 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3013 case SCTP_REMOTE_ERROR:
3014 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3016 case SCTP_SEND_FAILED:
3017 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3019 case SCTP_SHUTDOWN_EVENT:
3020 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3022 case SCTP_ADAPTATION_INDICATION:
3023 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3025 case SCTP_PARTIAL_DELIVERY_EVENT:
3026 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3028 case SCTP_AUTHENTICATION_EVENT:
3029 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3031 case SCTP_STREAM_RESET_EVENT:
3032 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3034 case SCTP_SENDER_DRY_EVENT:
3035 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3037 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3039 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3042 case SCTP_ASSOC_RESET_EVENT:
3043 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3045 case SCTP_STREAM_CHANGE_EVENT:
3046 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3048 case SCTP_SEND_FAILED_EVENT:
3049 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3053 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3057 if (event_type > 0) {
3059 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3061 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3062 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3063 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3064 SCTP_INP_RLOCK(inp);
3065 event->se_on = sctp_is_feature_on(inp, event_type);
3066 SCTP_INP_RUNLOCK(inp);
3068 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3074 SCTP_TCB_UNLOCK(stcb);
3077 *optsize = sizeof(struct sctp_event);
3081 case SCTP_RECVRCVINFO:
3085 if (*optsize < sizeof(int)) {
3086 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3089 SCTP_INP_RLOCK(inp);
3090 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3091 SCTP_INP_RUNLOCK(inp);
3094 /* return the option value */
3095 *(int *)optval = onoff;
3096 *optsize = sizeof(int);
3100 case SCTP_RECVNXTINFO:
3104 if (*optsize < sizeof(int)) {
3105 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3108 SCTP_INP_RLOCK(inp);
3109 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3110 SCTP_INP_RUNLOCK(inp);
3113 /* return the option value */
3114 *(int *)optval = onoff;
3115 *optsize = sizeof(int);
3119 case SCTP_DEFAULT_SNDINFO:
3121 struct sctp_sndinfo *info;
3123 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3124 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3127 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3128 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3129 info->snd_flags &= 0xfff0;
3130 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3131 info->snd_context = stcb->asoc.def_send.sinfo_context;
3132 SCTP_TCB_UNLOCK(stcb);
3134 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3135 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3136 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3137 SCTP_INP_RLOCK(inp);
3138 info->snd_sid = inp->def_send.sinfo_stream;
3139 info->snd_flags = inp->def_send.sinfo_flags;
3140 info->snd_flags &= 0xfff0;
3141 info->snd_ppid = inp->def_send.sinfo_ppid;
3142 info->snd_context = inp->def_send.sinfo_context;
3143 SCTP_INP_RUNLOCK(inp);
3145 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3150 *optsize = sizeof(struct sctp_sndinfo);
3154 case SCTP_DEFAULT_PRINFO:
3156 struct sctp_default_prinfo *info;
3158 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3159 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3162 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3163 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3164 SCTP_TCB_UNLOCK(stcb);
3166 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3167 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3168 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3169 SCTP_INP_RLOCK(inp);
3170 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3171 info->pr_value = inp->def_send.sinfo_timetolive;
3172 SCTP_INP_RUNLOCK(inp);
3174 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3179 *optsize = sizeof(struct sctp_default_prinfo);
3183 case SCTP_PEER_ADDR_THLDS:
3185 struct sctp_paddrthlds *thlds;
3186 struct sctp_nets *net;
3187 struct sockaddr *addr;
3188 #if defined(INET) && defined(INET6)
3189 struct sockaddr_in sin_store;
3192 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3193 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3195 #if defined(INET) && defined(INET6)
3196 if (thlds->spt_address.ss_family == AF_INET6) {
3197 struct sockaddr_in6 *sin6;
3199 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3200 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3201 in6_sin6_2_sin(&sin_store, sin6);
3202 addr = (struct sockaddr *)&sin_store;
3204 addr = (struct sockaddr *)&thlds->spt_address;
3207 addr = (struct sockaddr *)&thlds->spt_address;
3210 addr = (struct sockaddr *)&thlds->spt_address;
3213 net = sctp_findnet(stcb, addr);
3216 * We increment here since
3217 * sctp_findassociation_ep_addr() wil do a
3218 * decrement if it finds the stcb as long as
3219 * the locked tcb (last argument) is NOT a
3223 SCTP_INP_INCR_REF(inp);
3224 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3226 SCTP_INP_DECR_REF(inp);
3229 if ((stcb != NULL) && (net == NULL)) {
3231 if (addr->sa_family == AF_INET) {
3232 struct sockaddr_in *sin;
3234 sin = (struct sockaddr_in *)addr;
3235 if (sin->sin_addr.s_addr != INADDR_ANY) {
3237 SCTP_TCB_UNLOCK(stcb);
3238 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3244 if (addr->sa_family == AF_INET6) {
3245 struct sockaddr_in6 *sin6;
3247 sin6 = (struct sockaddr_in6 *)addr;
3248 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3250 SCTP_TCB_UNLOCK(stcb);
3251 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3257 error = EAFNOSUPPORT;
3258 SCTP_TCB_UNLOCK(stcb);
3259 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3265 thlds->spt_pathmaxrxt = net->failure_threshold;
3266 thlds->spt_pathpfthld = net->pf_threshold;
3267 thlds->spt_pathcpthld = 0xffff;
3269 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3270 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3271 thlds->spt_pathcpthld = 0xffff;
3273 thlds->spt_assoc_id = sctp_get_associd(stcb);
3274 SCTP_TCB_UNLOCK(stcb);
3276 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3277 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3278 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3279 /* Use endpoint defaults */
3280 SCTP_INP_RLOCK(inp);
3281 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3282 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3283 thlds->spt_pathcpthld = 0xffff;
3284 SCTP_INP_RUNLOCK(inp);
3286 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3291 *optsize = sizeof(struct sctp_paddrthlds);
3295 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3297 struct sctp_udpencaps *encaps;
3298 struct sctp_nets *net;
3299 struct sockaddr *addr;
3300 #if defined(INET) && defined(INET6)
3301 struct sockaddr_in sin_store;
3304 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3305 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3307 #if defined(INET) && defined(INET6)
3308 if (encaps->sue_address.ss_family == AF_INET6) {
3309 struct sockaddr_in6 *sin6;
3311 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3312 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3313 in6_sin6_2_sin(&sin_store, sin6);
3314 addr = (struct sockaddr *)&sin_store;
3316 addr = (struct sockaddr *)&encaps->sue_address;
3319 addr = (struct sockaddr *)&encaps->sue_address;
3322 addr = (struct sockaddr *)&encaps->sue_address;
3325 net = sctp_findnet(stcb, addr);
3328 * We increment here since
3329 * sctp_findassociation_ep_addr() wil do a
3330 * decrement if it finds the stcb as long as
3331 * the locked tcb (last argument) is NOT a
3335 SCTP_INP_INCR_REF(inp);
3336 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3338 SCTP_INP_DECR_REF(inp);
3341 if ((stcb != NULL) && (net == NULL)) {
3343 if (addr->sa_family == AF_INET) {
3344 struct sockaddr_in *sin;
3346 sin = (struct sockaddr_in *)addr;
3347 if (sin->sin_addr.s_addr != INADDR_ANY) {
3349 SCTP_TCB_UNLOCK(stcb);
3350 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3356 if (addr->sa_family == AF_INET6) {
3357 struct sockaddr_in6 *sin6;
3359 sin6 = (struct sockaddr_in6 *)addr;
3360 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3362 SCTP_TCB_UNLOCK(stcb);
3363 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3369 error = EAFNOSUPPORT;
3370 SCTP_TCB_UNLOCK(stcb);
3371 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 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3386 SCTP_INP_RLOCK(inp);
3387 encaps->sue_port = inp->sctp_ep.port;
3388 SCTP_INP_RUNLOCK(inp);
3390 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3395 *optsize = sizeof(struct sctp_udpencaps);
3399 case SCTP_ECN_SUPPORTED:
3401 struct sctp_assoc_value *av;
3403 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3404 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3407 av->assoc_value = stcb->asoc.ecn_supported;
3408 SCTP_TCB_UNLOCK(stcb);
3410 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3411 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3412 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3413 SCTP_INP_RLOCK(inp);
3414 av->assoc_value = inp->ecn_supported;
3415 SCTP_INP_RUNLOCK(inp);
3417 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3422 *optsize = sizeof(struct sctp_assoc_value);
3426 case SCTP_PR_SUPPORTED:
3428 struct sctp_assoc_value *av;
3430 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3431 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3434 av->assoc_value = stcb->asoc.prsctp_supported;
3435 SCTP_TCB_UNLOCK(stcb);
3437 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3438 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3439 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3440 SCTP_INP_RLOCK(inp);
3441 av->assoc_value = inp->prsctp_supported;
3442 SCTP_INP_RUNLOCK(inp);
3444 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3449 *optsize = sizeof(struct sctp_assoc_value);
3453 case SCTP_AUTH_SUPPORTED:
3455 struct sctp_assoc_value *av;
3457 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3458 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3461 av->assoc_value = stcb->asoc.auth_supported;
3462 SCTP_TCB_UNLOCK(stcb);
3464 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3465 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3466 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3467 SCTP_INP_RLOCK(inp);
3468 av->assoc_value = inp->auth_supported;
3469 SCTP_INP_RUNLOCK(inp);
3471 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3476 *optsize = sizeof(struct sctp_assoc_value);
3480 case SCTP_ASCONF_SUPPORTED:
3482 struct sctp_assoc_value *av;
3484 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3485 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3488 av->assoc_value = stcb->asoc.asconf_supported;
3489 SCTP_TCB_UNLOCK(stcb);
3491 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3492 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3493 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3494 SCTP_INP_RLOCK(inp);
3495 av->assoc_value = inp->asconf_supported;
3496 SCTP_INP_RUNLOCK(inp);
3498 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3503 *optsize = sizeof(struct sctp_assoc_value);
3507 case SCTP_RECONFIG_SUPPORTED:
3509 struct sctp_assoc_value *av;
3511 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3512 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3515 av->assoc_value = stcb->asoc.reconfig_supported;
3516 SCTP_TCB_UNLOCK(stcb);
3518 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3519 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3520 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3521 SCTP_INP_RLOCK(inp);
3522 av->assoc_value = inp->reconfig_supported;
3523 SCTP_INP_RUNLOCK(inp);
3525 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3530 *optsize = sizeof(struct sctp_assoc_value);
3534 case SCTP_NRSACK_SUPPORTED:
3536 struct sctp_assoc_value *av;
3538 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3539 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3542 av->assoc_value = stcb->asoc.nrsack_supported;
3543 SCTP_TCB_UNLOCK(stcb);
3545 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3546 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3547 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3548 SCTP_INP_RLOCK(inp);
3549 av->assoc_value = inp->nrsack_supported;
3550 SCTP_INP_RUNLOCK(inp);
3552 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3557 *optsize = sizeof(struct sctp_assoc_value);
3561 case SCTP_PKTDROP_SUPPORTED:
3563 struct sctp_assoc_value *av;
3565 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3566 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3569 av->assoc_value = stcb->asoc.pktdrop_supported;
3570 SCTP_TCB_UNLOCK(stcb);
3572 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3573 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3574 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3575 SCTP_INP_RLOCK(inp);
3576 av->assoc_value = inp->pktdrop_supported;
3577 SCTP_INP_RUNLOCK(inp);
3579 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3584 *optsize = sizeof(struct sctp_assoc_value);
3588 case SCTP_ENABLE_STREAM_RESET:
3590 struct sctp_assoc_value *av;
3592 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3593 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3596 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3597 SCTP_TCB_UNLOCK(stcb);
3599 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3600 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3601 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3602 SCTP_INP_RLOCK(inp);
3603 av->assoc_value = (uint32_t)inp->local_strreset_support;
3604 SCTP_INP_RUNLOCK(inp);
3606 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3611 *optsize = sizeof(struct sctp_assoc_value);
3615 case SCTP_PR_STREAM_STATUS:
3617 struct sctp_prstatus *sprstat;
3621 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3622 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3624 sid = sprstat->sprstat_sid;
3625 policy = sprstat->sprstat_policy;
3626 #if defined(SCTP_DETAILED_STR_STATS)
3627 if ((stcb != NULL) &&
3628 (sid < stcb->asoc.streamoutcnt) &&
3629 (policy != SCTP_PR_SCTP_NONE) &&
3630 ((policy <= SCTP_PR_SCTP_MAX) ||
3631 (policy == SCTP_PR_SCTP_ALL))) {
3632 if (policy == SCTP_PR_SCTP_ALL) {
3633 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3634 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3636 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3637 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3640 if ((stcb != NULL) &&
3641 (sid < stcb->asoc.streamoutcnt) &&
3642 (policy == SCTP_PR_SCTP_ALL)) {
3643 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3644 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3647 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3651 SCTP_TCB_UNLOCK(stcb);
3654 *optsize = sizeof(struct sctp_prstatus);
3658 case SCTP_PR_ASSOC_STATUS:
3660 struct sctp_prstatus *sprstat;
3663 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3664 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3666 policy = sprstat->sprstat_policy;
3667 if ((stcb != NULL) &&
3668 (policy != SCTP_PR_SCTP_NONE) &&
3669 ((policy <= SCTP_PR_SCTP_MAX) ||
3670 (policy == SCTP_PR_SCTP_ALL))) {
3671 if (policy == SCTP_PR_SCTP_ALL) {
3672 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3673 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3675 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3676 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3679 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3683 SCTP_TCB_UNLOCK(stcb);
3686 *optsize = sizeof(struct sctp_prstatus);
3692 struct sctp_assoc_value *av;
3694 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3695 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3698 av->assoc_value = stcb->asoc.max_cwnd;
3699 SCTP_TCB_UNLOCK(stcb);
3701 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3702 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3703 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3704 SCTP_INP_RLOCK(inp);
3705 av->assoc_value = inp->max_cwnd;
3706 SCTP_INP_RUNLOCK(inp);
3708 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3713 *optsize = sizeof(struct sctp_assoc_value);
3718 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3719 error = ENOPROTOOPT;
3721 } /* end switch (sopt->sopt_name) */
3729 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3734 struct sctp_tcb *stcb = NULL;
3735 struct sctp_inpcb *inp = NULL;
3738 if (optval == NULL) {
3739 SCTP_PRINTF("optval is NULL\n");
3740 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3743 inp = (struct sctp_inpcb *)so->so_pcb;
3745 SCTP_PRINTF("inp is NULL?\n");
3746 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3749 vrf_id = inp->def_vrf_id;
3754 case SCTP_AUTOCLOSE:
3755 case SCTP_AUTO_ASCONF:
3756 case SCTP_EXPLICIT_EOR:
3757 case SCTP_DISABLE_FRAGMENTS:
3758 case SCTP_USE_EXT_RCVINFO:
3759 case SCTP_I_WANT_MAPPED_V4_ADDR:
3760 /* copy in the option value */
3761 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3766 case SCTP_DISABLE_FRAGMENTS:
3767 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3769 case SCTP_AUTO_ASCONF:
3771 * NOTE: we don't really support this flag
3773 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3774 /* only valid for bound all sockets */
3775 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3777 /* forbidden by admin */
3778 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3781 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3783 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3787 case SCTP_EXPLICIT_EOR:
3788 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3790 case SCTP_USE_EXT_RCVINFO:
3791 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3793 case SCTP_I_WANT_MAPPED_V4_ADDR:
3794 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3795 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3797 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3802 set_opt = SCTP_PCB_FLAGS_NODELAY;
3804 case SCTP_AUTOCLOSE:
3805 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3806 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3807 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3810 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3812 * The value is in ticks. Note this does not effect
3813 * old associations, only new ones.
3815 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3818 SCTP_INP_WLOCK(inp);
3820 sctp_feature_on(inp, set_opt);
3822 sctp_feature_off(inp, set_opt);
3824 SCTP_INP_WUNLOCK(inp);
3826 case SCTP_REUSE_PORT:
3828 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3829 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3830 /* Can't set it after we are bound */
3834 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3835 /* Can't do this for a 1-m socket */
3840 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3842 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3845 case SCTP_PARTIAL_DELIVERY_POINT:
3849 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3850 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3851 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3855 inp->partial_delivery_point = *value;
3858 case SCTP_FRAGMENT_INTERLEAVE:
3859 /* not yet until we re-write sctp_recvmsg() */
3863 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3864 if (*level == SCTP_FRAG_LEVEL_2) {
3865 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3866 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3867 } else if (*level == SCTP_FRAG_LEVEL_1) {
3868 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3869 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3870 } else if (*level == SCTP_FRAG_LEVEL_0) {
3871 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3872 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3875 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3880 case SCTP_INTERLEAVING_SUPPORTED:
3882 struct sctp_assoc_value *av;
3884 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3885 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3888 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3890 SCTP_TCB_UNLOCK(stcb);
3892 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3893 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3894 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3895 SCTP_INP_WLOCK(inp);
3896 if (av->assoc_value == 0) {
3897 inp->idata_supported = 0;
3899 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3900 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3901 inp->idata_supported = 1;
3909 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3913 SCTP_INP_WUNLOCK(inp);
3915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3921 case SCTP_CMT_ON_OFF:
3922 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3923 struct sctp_assoc_value *av;
3925 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3926 if (av->assoc_value > SCTP_CMT_MAX) {
3927 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3931 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3933 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3934 SCTP_TCB_UNLOCK(stcb);
3936 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3937 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3938 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3939 (av->assoc_id == SCTP_ALL_ASSOC)) {
3940 SCTP_INP_WLOCK(inp);
3941 inp->sctp_cmt_on_off = av->assoc_value;
3942 SCTP_INP_WUNLOCK(inp);
3944 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3945 (av->assoc_id == SCTP_ALL_ASSOC)) {
3946 SCTP_INP_RLOCK(inp);
3947 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3948 SCTP_TCB_LOCK(stcb);
3949 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3950 SCTP_TCB_UNLOCK(stcb);
3952 SCTP_INP_RUNLOCK(inp);
3956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3957 error = ENOPROTOOPT;
3960 case SCTP_PLUGGABLE_CC:
3962 struct sctp_assoc_value *av;
3963 struct sctp_nets *net;
3965 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3966 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3967 (av->assoc_value != SCTP_CC_HSTCP) &&
3968 (av->assoc_value != SCTP_CC_HTCP) &&
3969 (av->assoc_value != SCTP_CC_RTCC)) {
3970 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3974 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3976 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3977 stcb->asoc.congestion_control_module = av->assoc_value;
3978 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3979 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3980 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3983 SCTP_TCB_UNLOCK(stcb);
3985 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3986 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3987 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3988 (av->assoc_id == SCTP_ALL_ASSOC)) {
3989 SCTP_INP_WLOCK(inp);
3990 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3991 SCTP_INP_WUNLOCK(inp);
3993 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3994 (av->assoc_id == SCTP_ALL_ASSOC)) {
3995 SCTP_INP_RLOCK(inp);
3996 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3997 SCTP_TCB_LOCK(stcb);
3998 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3999 stcb->asoc.congestion_control_module = av->assoc_value;
4000 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4001 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4002 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4005 SCTP_TCB_UNLOCK(stcb);
4007 SCTP_INP_RUNLOCK(inp);
4012 case SCTP_CC_OPTION:
4014 struct sctp_cc_option *cc_opt;
4016 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4017 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4019 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4020 SCTP_INP_RLOCK(inp);
4021 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4022 SCTP_TCB_LOCK(stcb);
4023 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4024 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4026 SCTP_TCB_UNLOCK(stcb);
4028 SCTP_INP_RUNLOCK(inp);
4033 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4036 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4039 SCTP_TCB_UNLOCK(stcb);
4043 case SCTP_PLUGGABLE_SS:
4045 struct sctp_assoc_value *av;
4047 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4048 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4049 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4050 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4051 (av->assoc_value != SCTP_SS_PRIORITY) &&
4052 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4053 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4054 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4058 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4060 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4061 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4062 stcb->asoc.stream_scheduling_module = av->assoc_value;
4063 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4064 SCTP_TCB_UNLOCK(stcb);
4066 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4067 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4068 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4069 (av->assoc_id == SCTP_ALL_ASSOC)) {
4070 SCTP_INP_WLOCK(inp);
4071 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4072 SCTP_INP_WUNLOCK(inp);
4074 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4075 (av->assoc_id == SCTP_ALL_ASSOC)) {
4076 SCTP_INP_RLOCK(inp);
4077 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4078 SCTP_TCB_LOCK(stcb);
4079 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4080 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4081 stcb->asoc.stream_scheduling_module = av->assoc_value;
4082 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4083 SCTP_TCB_UNLOCK(stcb);
4085 SCTP_INP_RUNLOCK(inp);
4092 struct sctp_stream_value *av;
4094 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4095 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4097 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4098 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4099 av->stream_value) < 0)) {
4100 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4103 SCTP_TCB_UNLOCK(stcb);
4105 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4106 SCTP_INP_RLOCK(inp);
4107 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4108 SCTP_TCB_LOCK(stcb);
4109 if (av->stream_id < stcb->asoc.streamoutcnt) {
4110 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4112 &stcb->asoc.strmout[av->stream_id],
4115 SCTP_TCB_UNLOCK(stcb);
4117 SCTP_INP_RUNLOCK(inp);
4120 * Can't set stream value without
4123 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4129 case SCTP_CLR_STAT_LOG:
4130 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4135 struct sctp_assoc_value *av;
4137 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4138 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4141 stcb->asoc.context = av->assoc_value;
4142 SCTP_TCB_UNLOCK(stcb);
4144 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4145 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4146 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4147 (av->assoc_id == SCTP_ALL_ASSOC)) {
4148 SCTP_INP_WLOCK(inp);
4149 inp->sctp_context = av->assoc_value;
4150 SCTP_INP_WUNLOCK(inp);
4152 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4153 (av->assoc_id == SCTP_ALL_ASSOC)) {
4154 SCTP_INP_RLOCK(inp);
4155 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4156 SCTP_TCB_LOCK(stcb);
4157 stcb->asoc.context = av->assoc_value;
4158 SCTP_TCB_UNLOCK(stcb);
4160 SCTP_INP_RUNLOCK(inp);
4167 uint32_t *default_vrfid;
4169 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4170 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4171 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4175 inp->def_vrf_id = *default_vrfid;
4178 case SCTP_DEL_VRF_ID:
4180 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4184 case SCTP_ADD_VRF_ID:
4186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4190 case SCTP_DELAYED_SACK:
4192 struct sctp_sack_info *sack;
4194 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4195 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4196 if (sack->sack_delay) {
4197 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4198 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4199 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4200 sack->sack_delay = TICKS_TO_MSEC(1);
4204 if (sack->sack_delay) {
4205 stcb->asoc.delayed_ack = sack->sack_delay;
4207 if (sack->sack_freq) {
4208 stcb->asoc.sack_freq = sack->sack_freq;
4210 SCTP_TCB_UNLOCK(stcb);
4212 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4213 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4214 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4215 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4216 SCTP_INP_WLOCK(inp);
4217 if (sack->sack_delay) {
4218 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4220 if (sack->sack_freq) {
4221 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4223 SCTP_INP_WUNLOCK(inp);
4225 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4226 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4227 SCTP_INP_RLOCK(inp);
4228 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4229 SCTP_TCB_LOCK(stcb);
4230 if (sack->sack_delay) {
4231 stcb->asoc.delayed_ack = sack->sack_delay;
4233 if (sack->sack_freq) {
4234 stcb->asoc.sack_freq = sack->sack_freq;
4236 SCTP_TCB_UNLOCK(stcb);
4238 SCTP_INP_RUNLOCK(inp);
4243 case SCTP_AUTH_CHUNK:
4245 struct sctp_authchunk *sauth;
4247 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4249 SCTP_INP_WLOCK(inp);
4250 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4251 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4254 SCTP_INP_WUNLOCK(inp);
4259 struct sctp_authkey *sca;
4260 struct sctp_keyhead *shared_keys;
4261 sctp_sharedkey_t *shared_key;
4262 sctp_key_t *key = NULL;
4265 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4266 if (sca->sca_keylength == 0) {
4267 size = optsize - sizeof(struct sctp_authkey);
4269 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4270 size = sca->sca_keylength;
4272 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4277 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4280 shared_keys = &stcb->asoc.shared_keys;
4281 /* clear the cached keys for this key id */
4282 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4284 * create the new shared key and
4288 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4290 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4292 SCTP_TCB_UNLOCK(stcb);
4296 shared_key = sctp_alloc_sharedkey();
4297 if (shared_key == NULL) {
4299 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4301 SCTP_TCB_UNLOCK(stcb);
4304 shared_key->key = key;
4305 shared_key->keyid = sca->sca_keynumber;
4306 error = sctp_insert_sharedkey(shared_keys, shared_key);
4307 SCTP_TCB_UNLOCK(stcb);
4309 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4310 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4311 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4312 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4313 SCTP_INP_WLOCK(inp);
4314 shared_keys = &inp->sctp_ep.shared_keys;
4316 * clear the cached keys on all
4317 * assocs for this key id
4319 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4321 * create the new shared key and
4325 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4327 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4329 SCTP_INP_WUNLOCK(inp);
4333 shared_key = sctp_alloc_sharedkey();
4334 if (shared_key == NULL) {
4336 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4338 SCTP_INP_WUNLOCK(inp);
4341 shared_key->key = key;
4342 shared_key->keyid = sca->sca_keynumber;
4343 error = sctp_insert_sharedkey(shared_keys, shared_key);
4344 SCTP_INP_WUNLOCK(inp);
4346 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4347 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4348 SCTP_INP_RLOCK(inp);
4349 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4350 SCTP_TCB_LOCK(stcb);
4351 shared_keys = &stcb->asoc.shared_keys;
4353 * clear the cached keys for
4356 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4358 * create the new shared key
4359 * and insert/replace it
4362 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4364 SCTP_TCB_UNLOCK(stcb);
4368 shared_key = sctp_alloc_sharedkey();
4369 if (shared_key == NULL) {
4371 SCTP_TCB_UNLOCK(stcb);
4374 shared_key->key = key;
4375 shared_key->keyid = sca->sca_keynumber;
4376 error = sctp_insert_sharedkey(shared_keys, shared_key);
4377 SCTP_TCB_UNLOCK(stcb);
4379 SCTP_INP_RUNLOCK(inp);
4384 case SCTP_HMAC_IDENT:
4386 struct sctp_hmacalgo *shmac;
4387 sctp_hmaclist_t *hmaclist;
4391 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4392 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4393 (shmac->shmac_number_of_idents > 0xffff)) {
4394 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4398 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4399 if (hmaclist == NULL) {
4400 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4404 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4405 hmacid = shmac->shmac_idents[i];
4406 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4407 /* invalid HMACs were found */ ;
4408 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4410 sctp_free_hmaclist(hmaclist);
4411 goto sctp_set_hmac_done;
4414 for (i = 0; i < hmaclist->num_algo; i++) {
4415 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4416 /* already in list */
4420 if (i == hmaclist->num_algo) {
4421 /* not found in list */
4422 sctp_free_hmaclist(hmaclist);
4423 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4427 /* set it on the endpoint */
4428 SCTP_INP_WLOCK(inp);
4429 if (inp->sctp_ep.local_hmacs)
4430 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4431 inp->sctp_ep.local_hmacs = hmaclist;
4432 SCTP_INP_WUNLOCK(inp);
4436 case SCTP_AUTH_ACTIVE_KEY:
4438 struct sctp_authkeyid *scact;
4440 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4441 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4443 /* set the active key on the right place */
4445 /* set the active key on the assoc */
4446 if (sctp_auth_setactivekey(stcb,
4447 scact->scact_keynumber)) {
4448 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4449 SCTP_FROM_SCTP_USRREQ,
4453 SCTP_TCB_UNLOCK(stcb);
4455 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4456 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4457 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4458 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4459 SCTP_INP_WLOCK(inp);
4460 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4461 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4464 SCTP_INP_WUNLOCK(inp);
4466 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4467 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4468 SCTP_INP_RLOCK(inp);
4469 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4470 SCTP_TCB_LOCK(stcb);
4471 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4472 SCTP_TCB_UNLOCK(stcb);
4474 SCTP_INP_RUNLOCK(inp);
4479 case SCTP_AUTH_DELETE_KEY:
4481 struct sctp_authkeyid *scdel;
4483 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4484 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4486 /* delete the key from the right place */
4488 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4489 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4492 SCTP_TCB_UNLOCK(stcb);
4494 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4495 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4496 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4497 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4498 SCTP_INP_WLOCK(inp);
4499 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4500 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4503 SCTP_INP_WUNLOCK(inp);
4505 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4506 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4507 SCTP_INP_RLOCK(inp);
4508 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4509 SCTP_TCB_LOCK(stcb);
4510 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4511 SCTP_TCB_UNLOCK(stcb);
4513 SCTP_INP_RUNLOCK(inp);
4518 case SCTP_AUTH_DEACTIVATE_KEY:
4520 struct sctp_authkeyid *keyid;
4522 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4523 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4525 /* deactivate the key from the right place */
4527 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4531 SCTP_TCB_UNLOCK(stcb);
4533 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4534 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4535 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4536 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4537 SCTP_INP_WLOCK(inp);
4538 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4539 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4542 SCTP_INP_WUNLOCK(inp);
4544 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4545 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4546 SCTP_INP_RLOCK(inp);
4547 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4548 SCTP_TCB_LOCK(stcb);
4549 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4550 SCTP_TCB_UNLOCK(stcb);
4552 SCTP_INP_RUNLOCK(inp);
4557 case SCTP_ENABLE_STREAM_RESET:
4559 struct sctp_assoc_value *av;
4561 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4562 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4563 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4567 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4569 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4570 SCTP_TCB_UNLOCK(stcb);
4572 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4573 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4574 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4575 (av->assoc_id == SCTP_ALL_ASSOC)) {
4576 SCTP_INP_WLOCK(inp);
4577 inp->local_strreset_support = (uint8_t)av->assoc_value;
4578 SCTP_INP_WUNLOCK(inp);
4580 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4581 (av->assoc_id == SCTP_ALL_ASSOC)) {
4582 SCTP_INP_RLOCK(inp);
4583 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4584 SCTP_TCB_LOCK(stcb);
4585 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4586 SCTP_TCB_UNLOCK(stcb);
4588 SCTP_INP_RUNLOCK(inp);
4593 case SCTP_RESET_STREAMS:
4595 struct sctp_reset_streams *strrst;
4596 int i, send_out = 0;
4599 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4600 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4602 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4606 if (stcb->asoc.reconfig_supported == 0) {
4608 * Peer does not support the chunk type.
4610 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4612 SCTP_TCB_UNLOCK(stcb);
4615 if (sizeof(struct sctp_reset_streams) +
4616 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4618 SCTP_TCB_UNLOCK(stcb);
4621 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4623 if (stcb->asoc.stream_reset_outstanding) {
4624 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4626 SCTP_TCB_UNLOCK(stcb);
4630 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4633 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4634 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4636 SCTP_TCB_UNLOCK(stcb);
4639 if ((send_in == 0) && (send_out == 0)) {
4640 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4642 SCTP_TCB_UNLOCK(stcb);
4645 for (i = 0; i < strrst->srs_number_streams; i++) {
4647 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4648 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4653 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4654 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4660 SCTP_TCB_UNLOCK(stcb);
4667 if (strrst->srs_number_streams) {
4668 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4669 strm = strrst->srs_stream_list[i];
4670 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4671 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4677 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4678 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4679 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4686 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4687 strrst->srs_stream_list,
4688 send_in, 0, 0, 0, 0, 0);
4690 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4693 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4696 * For outgoing streams don't report any
4697 * problems in sending the request to the
4698 * application. XXX: Double check resetting
4703 SCTP_TCB_UNLOCK(stcb);
4706 case SCTP_ADD_STREAMS:
4708 struct sctp_add_streams *stradd;
4709 uint8_t addstream = 0;
4710 uint16_t add_o_strmcnt = 0;
4711 uint16_t add_i_strmcnt = 0;
4713 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4714 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4716 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4720 if (stcb->asoc.reconfig_supported == 0) {
4722 * Peer does not support the chunk type.
4724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4726 SCTP_TCB_UNLOCK(stcb);
4729 if (stcb->asoc.stream_reset_outstanding) {
4730 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4732 SCTP_TCB_UNLOCK(stcb);
4735 if ((stradd->sas_outstrms == 0) &&
4736 (stradd->sas_instrms == 0)) {
4740 if (stradd->sas_outstrms) {
4742 /* We allocate here */
4743 add_o_strmcnt = stradd->sas_outstrms;
4744 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4745 /* You can't have more than 64k */
4750 if (stradd->sas_instrms) {
4755 * We allocate inside
4756 * sctp_send_str_reset_req()
4758 add_i_strmcnt = stradd->sas_instrms;
4759 cnt = add_i_strmcnt;
4760 cnt += stcb->asoc.streamincnt;
4761 if (cnt > 0x0000ffff) {
4762 /* You can't have more than 64k */
4766 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4767 /* More than you are allowed */
4772 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4773 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4775 SCTP_TCB_UNLOCK(stcb);
4778 case SCTP_RESET_ASSOC:
4783 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4784 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4786 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4790 if (stcb->asoc.reconfig_supported == 0) {
4792 * Peer does not support the chunk type.
4794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4796 SCTP_TCB_UNLOCK(stcb);
4799 if (stcb->asoc.stream_reset_outstanding) {
4800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4802 SCTP_TCB_UNLOCK(stcb);
4806 * Is there any data pending in the send or sent
4809 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4810 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4813 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4814 SCTP_TCB_UNLOCK(stcb);
4817 /* Do any streams have data queued? */
4818 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4819 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4823 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4824 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4825 SCTP_TCB_UNLOCK(stcb);
4828 case SCTP_CONNECT_X:
4829 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4830 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4834 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4836 case SCTP_CONNECT_X_DELAYED:
4837 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4838 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4842 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4844 case SCTP_CONNECT_X_COMPLETE:
4846 struct sockaddr *sa;
4848 /* FIXME MT: check correct? */
4849 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4852 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4853 SCTP_INP_RLOCK(inp);
4854 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4856 SCTP_TCB_LOCK(stcb);
4858 SCTP_INP_RUNLOCK(inp);
4861 * We increment here since
4862 * sctp_findassociation_ep_addr() wil do a
4863 * decrement if it finds the stcb as long as
4864 * the locked tcb (last argument) is NOT a
4867 SCTP_INP_INCR_REF(inp);
4868 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4870 SCTP_INP_DECR_REF(inp);
4875 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4879 if (stcb->asoc.delayed_connection == 1) {
4880 stcb->asoc.delayed_connection = 0;
4881 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4882 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4883 stcb->asoc.primary_destination,
4884 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4885 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4888 * already expired or did not use delayed
4891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4894 SCTP_TCB_UNLOCK(stcb);
4897 case SCTP_MAX_BURST:
4899 struct sctp_assoc_value *av;
4901 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4902 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4905 stcb->asoc.max_burst = av->assoc_value;
4906 SCTP_TCB_UNLOCK(stcb);
4908 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4909 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4910 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4911 (av->assoc_id == SCTP_ALL_ASSOC)) {
4912 SCTP_INP_WLOCK(inp);
4913 inp->sctp_ep.max_burst = av->assoc_value;
4914 SCTP_INP_WUNLOCK(inp);
4916 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4917 (av->assoc_id == SCTP_ALL_ASSOC)) {
4918 SCTP_INP_RLOCK(inp);
4919 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4920 SCTP_TCB_LOCK(stcb);
4921 stcb->asoc.max_burst = av->assoc_value;
4922 SCTP_TCB_UNLOCK(stcb);
4924 SCTP_INP_RUNLOCK(inp);
4931 struct sctp_assoc_value *av;
4934 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4935 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4937 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4938 ovh = SCTP_MED_OVERHEAD;
4940 ovh = SCTP_MED_V4_OVERHEAD;
4943 if (av->assoc_value) {
4944 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4946 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4948 SCTP_TCB_UNLOCK(stcb);
4950 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4951 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4952 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4953 SCTP_INP_WLOCK(inp);
4955 * FIXME MT: I think this is not in
4956 * tune with the API ID
4958 if (av->assoc_value) {
4959 inp->sctp_frag_point = (av->assoc_value + ovh);
4961 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4963 SCTP_INP_WUNLOCK(inp);
4965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4973 struct sctp_event_subscribe *events;
4975 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4977 SCTP_INP_WLOCK(inp);
4978 if (events->sctp_data_io_event) {
4979 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4981 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4984 if (events->sctp_association_event) {
4985 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4987 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4990 if (events->sctp_address_event) {
4991 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4993 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4996 if (events->sctp_send_failure_event) {
4997 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4999 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5002 if (events->sctp_peer_error_event) {
5003 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5005 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5008 if (events->sctp_shutdown_event) {
5009 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5011 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5014 if (events->sctp_partial_delivery_event) {
5015 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5017 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5020 if (events->sctp_adaptation_layer_event) {
5021 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5023 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5026 if (events->sctp_authentication_event) {
5027 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5029 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5032 if (events->sctp_sender_dry_event) {
5033 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5035 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5038 if (events->sctp_stream_reset_event) {
5039 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5041 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5043 SCTP_INP_WUNLOCK(inp);
5045 SCTP_INP_RLOCK(inp);
5046 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5047 SCTP_TCB_LOCK(stcb);
5048 if (events->sctp_association_event) {
5049 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5051 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5053 if (events->sctp_address_event) {
5054 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5056 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5058 if (events->sctp_send_failure_event) {
5059 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5061 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5063 if (events->sctp_peer_error_event) {
5064 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5066 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5068 if (events->sctp_shutdown_event) {
5069 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5071 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5073 if (events->sctp_partial_delivery_event) {
5074 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5076 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5078 if (events->sctp_adaptation_layer_event) {
5079 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5081 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5083 if (events->sctp_authentication_event) {
5084 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5086 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5088 if (events->sctp_sender_dry_event) {
5089 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5091 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5093 if (events->sctp_stream_reset_event) {
5094 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5096 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5098 SCTP_TCB_UNLOCK(stcb);
5101 * Send up the sender dry event only for 1-to-1
5104 if (events->sctp_sender_dry_event) {
5105 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5106 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5107 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5109 SCTP_TCB_LOCK(stcb);
5110 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5111 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5112 (stcb->asoc.stream_queue_cnt == 0)) {
5113 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5115 SCTP_TCB_UNLOCK(stcb);
5119 SCTP_INP_RUNLOCK(inp);
5122 case SCTP_ADAPTATION_LAYER:
5124 struct sctp_setadaptation *adap_bits;
5126 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5127 SCTP_INP_WLOCK(inp);
5128 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5129 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5130 SCTP_INP_WUNLOCK(inp);
5134 case SCTP_SET_INITIAL_DBG_SEQ:
5138 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5139 SCTP_INP_WLOCK(inp);
5140 inp->sctp_ep.initial_sequence_debug = *vvv;
5141 SCTP_INP_WUNLOCK(inp);
5145 case SCTP_DEFAULT_SEND_PARAM:
5147 struct sctp_sndrcvinfo *s_info;
5149 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5150 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5153 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5154 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5156 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5159 SCTP_TCB_UNLOCK(stcb);
5161 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5162 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5163 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5164 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5165 SCTP_INP_WLOCK(inp);
5166 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5167 SCTP_INP_WUNLOCK(inp);
5169 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5170 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5171 SCTP_INP_RLOCK(inp);
5172 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5173 SCTP_TCB_LOCK(stcb);
5174 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5175 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5177 SCTP_TCB_UNLOCK(stcb);
5179 SCTP_INP_RUNLOCK(inp);
5184 case SCTP_PEER_ADDR_PARAMS:
5186 struct sctp_paddrparams *paddrp;
5187 struct sctp_nets *net;
5188 struct sockaddr *addr;
5189 #if defined(INET) && defined(INET6)
5190 struct sockaddr_in sin_store;
5193 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5194 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5196 #if defined(INET) && defined(INET6)
5197 if (paddrp->spp_address.ss_family == AF_INET6) {
5198 struct sockaddr_in6 *sin6;
5200 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5201 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5202 in6_sin6_2_sin(&sin_store, sin6);
5203 addr = (struct sockaddr *)&sin_store;
5205 addr = (struct sockaddr *)&paddrp->spp_address;
5208 addr = (struct sockaddr *)&paddrp->spp_address;
5211 addr = (struct sockaddr *)&paddrp->spp_address;
5214 net = sctp_findnet(stcb, addr);
5217 * We increment here since
5218 * sctp_findassociation_ep_addr() wil do a
5219 * decrement if it finds the stcb as long as
5220 * the locked tcb (last argument) is NOT a
5224 SCTP_INP_INCR_REF(inp);
5225 stcb = sctp_findassociation_ep_addr(&inp, addr,
5228 SCTP_INP_DECR_REF(inp);
5231 if ((stcb != NULL) && (net == NULL)) {
5233 if (addr->sa_family == AF_INET) {
5235 struct sockaddr_in *sin;
5237 sin = (struct sockaddr_in *)addr;
5238 if (sin->sin_addr.s_addr != INADDR_ANY) {
5239 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5240 SCTP_TCB_UNLOCK(stcb);
5247 if (addr->sa_family == AF_INET6) {
5248 struct sockaddr_in6 *sin6;
5250 sin6 = (struct sockaddr_in6 *)addr;
5251 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5252 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5253 SCTP_TCB_UNLOCK(stcb);
5260 error = EAFNOSUPPORT;
5261 SCTP_TCB_UNLOCK(stcb);
5262 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5267 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5269 SCTP_TCB_UNLOCK(stcb);
5270 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5273 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5275 SCTP_TCB_UNLOCK(stcb);
5276 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5280 /************************TCB SPECIFIC SET ******************/
5282 /************************NET SPECIFIC SET ******************/
5283 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5284 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5285 !(net->dest_state & SCTP_ADDR_NOHB)) {
5286 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5287 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5289 net->dest_state |= SCTP_ADDR_NOHB;
5291 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5292 if (paddrp->spp_hbinterval) {
5293 net->heart_beat_delay = paddrp->spp_hbinterval;
5294 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5295 net->heart_beat_delay = 0;
5297 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5298 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5299 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5300 net->dest_state &= ~SCTP_ADDR_NOHB;
5302 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5304 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5305 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5306 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5308 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5309 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5310 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5311 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5313 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5314 net->mtu = paddrp->spp_pathmtu;
5315 switch (net->ro._l_addr.sa.sa_family) {
5318 net->mtu += SCTP_MIN_V4_OVERHEAD;
5323 net->mtu += SCTP_MIN_OVERHEAD;
5329 if (net->mtu < stcb->asoc.smallest_mtu) {
5330 sctp_pathmtu_adjustment(stcb, net->mtu);
5333 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5334 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5335 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5337 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5339 if (paddrp->spp_pathmaxrxt) {
5340 if (net->dest_state & SCTP_ADDR_PF) {
5341 if (net->error_count > paddrp->spp_pathmaxrxt) {
5342 net->dest_state &= ~SCTP_ADDR_PF;
5345 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5346 (net->error_count > net->pf_threshold)) {
5347 net->dest_state |= SCTP_ADDR_PF;
5348 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5349 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5350 stcb->sctp_ep, stcb, net,
5351 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5352 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5355 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5356 if (net->error_count > paddrp->spp_pathmaxrxt) {
5357 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5358 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5361 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5362 net->dest_state |= SCTP_ADDR_REACHABLE;
5363 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5366 net->failure_threshold = paddrp->spp_pathmaxrxt;
5368 if (paddrp->spp_flags & SPP_DSCP) {
5369 net->dscp = paddrp->spp_dscp & 0xfc;
5373 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5374 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5375 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5376 net->flowlabel |= 0x80000000;
5381 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5382 if (paddrp->spp_pathmaxrxt != 0) {
5383 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5384 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5385 if (net->dest_state & SCTP_ADDR_PF) {
5386 if (net->error_count > paddrp->spp_pathmaxrxt) {
5387 net->dest_state &= ~SCTP_ADDR_PF;
5390 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5391 (net->error_count > net->pf_threshold)) {
5392 net->dest_state |= SCTP_ADDR_PF;
5393 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5394 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5395 stcb->sctp_ep, stcb, net,
5396 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5397 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5400 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5401 if (net->error_count > paddrp->spp_pathmaxrxt) {
5402 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5403 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5406 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5407 net->dest_state |= SCTP_ADDR_REACHABLE;
5408 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5411 net->failure_threshold = paddrp->spp_pathmaxrxt;
5414 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5415 if (paddrp->spp_hbinterval != 0) {
5416 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5417 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5418 stcb->asoc.heart_beat_delay = 0;
5420 /* Turn back on the timer */
5421 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5422 if (paddrp->spp_hbinterval != 0) {
5423 net->heart_beat_delay = paddrp->spp_hbinterval;
5424 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5425 net->heart_beat_delay = 0;
5427 if (net->dest_state & SCTP_ADDR_NOHB) {
5428 net->dest_state &= ~SCTP_ADDR_NOHB;
5430 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5431 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5432 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5434 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5436 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5437 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5438 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5439 net->dest_state |= SCTP_ADDR_NOHB;
5440 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5441 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5443 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5447 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5449 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5450 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5451 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5452 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5453 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5455 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5456 net->mtu = paddrp->spp_pathmtu;
5457 switch (net->ro._l_addr.sa.sa_family) {
5460 net->mtu += SCTP_MIN_V4_OVERHEAD;
5465 net->mtu += SCTP_MIN_OVERHEAD;
5471 if (net->mtu < stcb->asoc.smallest_mtu) {
5472 sctp_pathmtu_adjustment(stcb, net->mtu);
5475 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5476 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5478 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5479 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5480 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5481 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5483 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5485 stcb->asoc.default_mtu = 0;
5486 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5488 if (paddrp->spp_flags & SPP_DSCP) {
5489 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5490 net->dscp = paddrp->spp_dscp & 0xfc;
5493 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5494 stcb->asoc.default_dscp |= 0x01;
5497 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5498 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5499 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5500 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5501 net->flowlabel |= 0x80000000;
5504 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5505 stcb->asoc.default_flowlabel |= 0x80000000;
5509 SCTP_TCB_UNLOCK(stcb);
5511 /************************NO TCB, SET TO default stuff ******************/
5512 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5513 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5514 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5515 SCTP_INP_WLOCK(inp);
5517 * For the TOS/FLOWLABEL stuff you
5518 * set it with the options on the
5521 if (paddrp->spp_pathmaxrxt != 0) {
5522 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5524 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5525 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5526 else if (paddrp->spp_hbinterval != 0) {
5527 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5528 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5529 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5531 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5532 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5533 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5534 } else if (paddrp->spp_hbinterval) {
5535 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5537 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5538 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5539 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5541 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5542 inp->sctp_ep.default_mtu = 0;
5543 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5544 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5545 if (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU) {
5546 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5548 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5550 if (paddrp->spp_flags & SPP_DSCP) {
5551 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5552 inp->sctp_ep.default_dscp |= 0x01;
5555 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5556 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5557 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5558 inp->sctp_ep.default_flowlabel |= 0x80000000;
5562 SCTP_INP_WUNLOCK(inp);
5564 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5572 struct sctp_rtoinfo *srto;
5573 uint32_t new_init, new_min, new_max;
5575 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5576 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5579 if (srto->srto_initial)
5580 new_init = srto->srto_initial;
5582 new_init = stcb->asoc.initial_rto;
5584 new_max = srto->srto_max;
5586 new_max = stcb->asoc.maxrto;
5588 new_min = srto->srto_min;
5590 new_min = stcb->asoc.minrto;
5591 if ((new_min <= new_init) && (new_init <= new_max)) {
5592 stcb->asoc.initial_rto = new_init;
5593 stcb->asoc.maxrto = new_max;
5594 stcb->asoc.minrto = new_min;
5596 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5599 SCTP_TCB_UNLOCK(stcb);
5601 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5602 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5603 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5604 SCTP_INP_WLOCK(inp);
5605 if (srto->srto_initial)
5606 new_init = srto->srto_initial;
5608 new_init = inp->sctp_ep.initial_rto;
5610 new_max = srto->srto_max;
5612 new_max = inp->sctp_ep.sctp_maxrto;
5614 new_min = srto->srto_min;
5616 new_min = inp->sctp_ep.sctp_minrto;
5617 if ((new_min <= new_init) && (new_init <= new_max)) {
5618 inp->sctp_ep.initial_rto = new_init;
5619 inp->sctp_ep.sctp_maxrto = new_max;
5620 inp->sctp_ep.sctp_minrto = new_min;
5622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5625 SCTP_INP_WUNLOCK(inp);
5627 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5633 case SCTP_ASSOCINFO:
5635 struct sctp_assocparams *sasoc;
5637 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5638 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5639 if (sasoc->sasoc_cookie_life) {
5640 /* boundary check the cookie life */
5641 if (sasoc->sasoc_cookie_life < 1000)
5642 sasoc->sasoc_cookie_life = 1000;
5643 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5644 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5648 if (sasoc->sasoc_asocmaxrxt)
5649 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5650 if (sasoc->sasoc_cookie_life) {
5651 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5653 SCTP_TCB_UNLOCK(stcb);
5655 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5656 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5657 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5658 SCTP_INP_WLOCK(inp);
5659 if (sasoc->sasoc_asocmaxrxt)
5660 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5661 if (sasoc->sasoc_cookie_life) {
5662 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5664 SCTP_INP_WUNLOCK(inp);
5666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5674 struct sctp_initmsg *sinit;
5676 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5677 SCTP_INP_WLOCK(inp);
5678 if (sinit->sinit_num_ostreams)
5679 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5681 if (sinit->sinit_max_instreams)
5682 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5684 if (sinit->sinit_max_attempts)
5685 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5687 if (sinit->sinit_max_init_timeo)
5688 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5689 SCTP_INP_WUNLOCK(inp);
5692 case SCTP_PRIMARY_ADDR:
5694 struct sctp_setprim *spa;
5695 struct sctp_nets *net;
5696 struct sockaddr *addr;
5697 #if defined(INET) && defined(INET6)
5698 struct sockaddr_in sin_store;
5701 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5702 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5704 #if defined(INET) && defined(INET6)
5705 if (spa->ssp_addr.ss_family == AF_INET6) {
5706 struct sockaddr_in6 *sin6;
5708 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5709 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5710 in6_sin6_2_sin(&sin_store, sin6);
5711 addr = (struct sockaddr *)&sin_store;
5713 addr = (struct sockaddr *)&spa->ssp_addr;
5716 addr = (struct sockaddr *)&spa->ssp_addr;
5719 addr = (struct sockaddr *)&spa->ssp_addr;
5722 net = sctp_findnet(stcb, addr);
5725 * We increment here since
5726 * sctp_findassociation_ep_addr() wil do a
5727 * decrement if it finds the stcb as long as
5728 * the locked tcb (last argument) is NOT a
5732 SCTP_INP_INCR_REF(inp);
5733 stcb = sctp_findassociation_ep_addr(&inp, addr,
5736 SCTP_INP_DECR_REF(inp);
5740 if ((stcb != NULL) && (net != NULL)) {
5741 if (net != stcb->asoc.primary_destination) {
5742 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5743 /* Ok we need to set it */
5744 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5745 if ((stcb->asoc.alternate) &&
5746 (!(net->dest_state & SCTP_ADDR_PF)) &&
5747 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5748 sctp_free_remote_addr(stcb->asoc.alternate);
5749 stcb->asoc.alternate = NULL;
5752 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5756 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5761 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5765 SCTP_TCB_UNLOCK(stcb);
5769 case SCTP_SET_DYNAMIC_PRIMARY:
5771 union sctp_sockstore *ss;
5773 error = priv_check(curthread,
5774 PRIV_NETINET_RESERVEDPORT);
5778 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5779 /* SUPER USER CHECK? */
5780 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5783 case SCTP_SET_PEER_PRIMARY_ADDR:
5785 struct sctp_setpeerprim *sspp;
5786 struct sockaddr *addr;
5787 #if defined(INET) && defined(INET6)
5788 struct sockaddr_in sin_store;
5791 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5792 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5794 struct sctp_ifa *ifa;
5796 #if defined(INET) && defined(INET6)
5797 if (sspp->sspp_addr.ss_family == AF_INET6) {
5798 struct sockaddr_in6 *sin6;
5800 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5801 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5802 in6_sin6_2_sin(&sin_store, sin6);
5803 addr = (struct sockaddr *)&sin_store;
5805 addr = (struct sockaddr *)&sspp->sspp_addr;
5808 addr = (struct sockaddr *)&sspp->sspp_addr;
5811 addr = (struct sockaddr *)&sspp->sspp_addr;
5813 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5815 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5819 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5821 * Must validate the ifa found is in
5824 struct sctp_laddr *laddr;
5827 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5828 if (laddr->ifa == NULL) {
5829 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5833 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5834 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5837 if (laddr->ifa == ifa) {
5843 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5848 switch (addr->sa_family) {
5852 struct sockaddr_in *sin;
5854 sin = (struct sockaddr_in *)addr;
5855 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5856 &sin->sin_addr) != 0) {
5857 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5867 struct sockaddr_in6 *sin6;
5869 sin6 = (struct sockaddr_in6 *)addr;
5870 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5871 &sin6->sin6_addr) != 0) {
5872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5880 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5885 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5886 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5889 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5891 SCTP_TCB_UNLOCK(stcb);
5893 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5898 case SCTP_BINDX_ADD_ADDR:
5900 struct sctp_getaddresses *addrs;
5903 td = (struct thread *)p;
5904 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5907 if (addrs->addr->sa_family == AF_INET) {
5908 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5909 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5913 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5914 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5920 if (addrs->addr->sa_family == AF_INET6) {
5921 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5926 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5927 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5928 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5934 error = EAFNOSUPPORT;
5937 sctp_bindx_add_address(so, inp, addrs->addr,
5938 addrs->sget_assoc_id, vrf_id,
5942 case SCTP_BINDX_REM_ADDR:
5944 struct sctp_getaddresses *addrs;
5947 td = (struct thread *)p;
5949 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5951 if (addrs->addr->sa_family == AF_INET) {
5952 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5953 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5957 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5958 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5964 if (addrs->addr->sa_family == AF_INET6) {
5965 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5966 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5971 (error = prison_local_ip6(td->td_ucred,
5972 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5973 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5974 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5980 error = EAFNOSUPPORT;
5983 sctp_bindx_delete_address(inp, addrs->addr,
5984 addrs->sget_assoc_id, vrf_id,
5990 struct sctp_event *event;
5991 uint32_t event_type;
5993 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5994 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5995 switch (event->se_type) {
5996 case SCTP_ASSOC_CHANGE:
5997 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5999 case SCTP_PEER_ADDR_CHANGE:
6000 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6002 case SCTP_REMOTE_ERROR:
6003 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6005 case SCTP_SEND_FAILED:
6006 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6008 case SCTP_SHUTDOWN_EVENT:
6009 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6011 case SCTP_ADAPTATION_INDICATION:
6012 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6014 case SCTP_PARTIAL_DELIVERY_EVENT:
6015 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6017 case SCTP_AUTHENTICATION_EVENT:
6018 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6020 case SCTP_STREAM_RESET_EVENT:
6021 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6023 case SCTP_SENDER_DRY_EVENT:
6024 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6026 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6028 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6031 case SCTP_ASSOC_RESET_EVENT:
6032 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6034 case SCTP_STREAM_CHANGE_EVENT:
6035 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6037 case SCTP_SEND_FAILED_EVENT:
6038 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6042 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6046 if (event_type > 0) {
6049 sctp_stcb_feature_on(inp, stcb, event_type);
6050 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6051 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6052 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6053 (stcb->asoc.stream_queue_cnt == 0)) {
6054 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6058 sctp_stcb_feature_off(inp, stcb, event_type);
6060 SCTP_TCB_UNLOCK(stcb);
6063 * We don't want to send up a storm
6064 * of events, so return an error for
6067 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6068 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6069 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6070 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6071 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6072 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6076 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6077 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6078 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6079 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6080 SCTP_INP_WLOCK(inp);
6082 sctp_feature_on(inp, event_type);
6084 sctp_feature_off(inp, event_type);
6086 SCTP_INP_WUNLOCK(inp);
6088 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6089 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6090 SCTP_INP_RLOCK(inp);
6091 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6092 SCTP_TCB_LOCK(stcb);
6094 sctp_stcb_feature_on(inp, stcb, event_type);
6096 sctp_stcb_feature_off(inp, stcb, event_type);
6098 SCTP_TCB_UNLOCK(stcb);
6100 SCTP_INP_RUNLOCK(inp);
6106 case SCTP_RECVRCVINFO:
6110 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6111 SCTP_INP_WLOCK(inp);
6113 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6115 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6117 SCTP_INP_WUNLOCK(inp);
6120 case SCTP_RECVNXTINFO:
6124 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6125 SCTP_INP_WLOCK(inp);
6127 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6129 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6131 SCTP_INP_WUNLOCK(inp);
6134 case SCTP_DEFAULT_SNDINFO:
6136 struct sctp_sndinfo *info;
6139 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6140 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6143 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6144 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6145 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6146 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6147 stcb->asoc.def_send.sinfo_flags |= policy;
6148 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6149 stcb->asoc.def_send.sinfo_context = info->snd_context;
6151 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6154 SCTP_TCB_UNLOCK(stcb);
6156 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6157 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6158 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6159 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6160 SCTP_INP_WLOCK(inp);
6161 inp->def_send.sinfo_stream = info->snd_sid;
6162 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6163 inp->def_send.sinfo_flags = info->snd_flags;
6164 inp->def_send.sinfo_flags |= policy;
6165 inp->def_send.sinfo_ppid = info->snd_ppid;
6166 inp->def_send.sinfo_context = info->snd_context;
6167 SCTP_INP_WUNLOCK(inp);
6169 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6170 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6171 SCTP_INP_RLOCK(inp);
6172 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6173 SCTP_TCB_LOCK(stcb);
6174 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6175 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6176 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6177 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6178 stcb->asoc.def_send.sinfo_flags |= policy;
6179 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6180 stcb->asoc.def_send.sinfo_context = info->snd_context;
6182 SCTP_TCB_UNLOCK(stcb);
6184 SCTP_INP_RUNLOCK(inp);
6189 case SCTP_DEFAULT_PRINFO:
6191 struct sctp_default_prinfo *info;
6193 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6194 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6196 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6197 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6202 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6203 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6204 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6205 SCTP_TCB_UNLOCK(stcb);
6207 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6208 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6209 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6210 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6211 SCTP_INP_WLOCK(inp);
6212 inp->def_send.sinfo_flags &= 0xfff0;
6213 inp->def_send.sinfo_flags |= info->pr_policy;
6214 inp->def_send.sinfo_timetolive = info->pr_value;
6215 SCTP_INP_WUNLOCK(inp);
6217 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6218 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6219 SCTP_INP_RLOCK(inp);
6220 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6221 SCTP_TCB_LOCK(stcb);
6222 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6223 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6224 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6225 SCTP_TCB_UNLOCK(stcb);
6227 SCTP_INP_RUNLOCK(inp);
6232 case SCTP_PEER_ADDR_THLDS:
6233 /* Applies to the specific association */
6235 struct sctp_paddrthlds *thlds;
6236 struct sctp_nets *net;
6237 struct sockaddr *addr;
6238 #if defined(INET) && defined(INET6)
6239 struct sockaddr_in sin_store;
6242 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6243 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6245 #if defined(INET) && defined(INET6)
6246 if (thlds->spt_address.ss_family == AF_INET6) {
6247 struct sockaddr_in6 *sin6;
6249 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6250 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6251 in6_sin6_2_sin(&sin_store, sin6);
6252 addr = (struct sockaddr *)&sin_store;
6254 addr = (struct sockaddr *)&thlds->spt_address;
6257 addr = (struct sockaddr *)&thlds->spt_address;
6260 addr = (struct sockaddr *)&thlds->spt_address;
6263 net = sctp_findnet(stcb, addr);
6266 * We increment here since
6267 * sctp_findassociation_ep_addr() wil do a
6268 * decrement if it finds the stcb as long as
6269 * the locked tcb (last argument) is NOT a
6273 SCTP_INP_INCR_REF(inp);
6274 stcb = sctp_findassociation_ep_addr(&inp, addr,
6277 SCTP_INP_DECR_REF(inp);
6280 if ((stcb != NULL) && (net == NULL)) {
6282 if (addr->sa_family == AF_INET) {
6284 struct sockaddr_in *sin;
6286 sin = (struct sockaddr_in *)addr;
6287 if (sin->sin_addr.s_addr != INADDR_ANY) {
6288 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6289 SCTP_TCB_UNLOCK(stcb);
6296 if (addr->sa_family == AF_INET6) {
6297 struct sockaddr_in6 *sin6;
6299 sin6 = (struct sockaddr_in6 *)addr;
6300 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6301 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6302 SCTP_TCB_UNLOCK(stcb);
6309 error = EAFNOSUPPORT;
6310 SCTP_TCB_UNLOCK(stcb);
6311 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6315 if (thlds->spt_pathcpthld != 0xffff) {
6317 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6322 net->failure_threshold = thlds->spt_pathmaxrxt;
6323 net->pf_threshold = thlds->spt_pathpfthld;
6324 if (net->dest_state & SCTP_ADDR_PF) {
6325 if ((net->error_count > net->failure_threshold) ||
6326 (net->error_count <= net->pf_threshold)) {
6327 net->dest_state &= ~SCTP_ADDR_PF;
6330 if ((net->error_count > net->pf_threshold) &&
6331 (net->error_count <= net->failure_threshold)) {
6332 net->dest_state |= SCTP_ADDR_PF;
6333 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6334 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6335 stcb->sctp_ep, stcb, net,
6336 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6337 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6340 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6341 if (net->error_count > net->failure_threshold) {
6342 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6343 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6346 if (net->error_count <= net->failure_threshold) {
6347 net->dest_state |= SCTP_ADDR_REACHABLE;
6348 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6352 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6353 net->failure_threshold = thlds->spt_pathmaxrxt;
6354 net->pf_threshold = thlds->spt_pathpfthld;
6355 if (net->dest_state & SCTP_ADDR_PF) {
6356 if ((net->error_count > net->failure_threshold) ||
6357 (net->error_count <= net->pf_threshold)) {
6358 net->dest_state &= ~SCTP_ADDR_PF;
6361 if ((net->error_count > net->pf_threshold) &&
6362 (net->error_count <= net->failure_threshold)) {
6363 net->dest_state |= SCTP_ADDR_PF;
6364 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6365 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6366 stcb->sctp_ep, stcb, net,
6367 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6368 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6371 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6372 if (net->error_count > net->failure_threshold) {
6373 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6374 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6377 if (net->error_count <= net->failure_threshold) {
6378 net->dest_state |= SCTP_ADDR_REACHABLE;
6379 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6383 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6384 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6386 SCTP_TCB_UNLOCK(stcb);
6388 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6389 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6390 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6391 SCTP_INP_WLOCK(inp);
6392 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6393 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6394 SCTP_INP_WUNLOCK(inp);
6396 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6402 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6404 struct sctp_udpencaps *encaps;
6405 struct sctp_nets *net;
6406 struct sockaddr *addr;
6407 #if defined(INET) && defined(INET6)
6408 struct sockaddr_in sin_store;
6411 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6412 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6414 #if defined(INET) && defined(INET6)
6415 if (encaps->sue_address.ss_family == AF_INET6) {
6416 struct sockaddr_in6 *sin6;
6418 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6419 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6420 in6_sin6_2_sin(&sin_store, sin6);
6421 addr = (struct sockaddr *)&sin_store;
6423 addr = (struct sockaddr *)&encaps->sue_address;
6426 addr = (struct sockaddr *)&encaps->sue_address;
6429 addr = (struct sockaddr *)&encaps->sue_address;
6432 net = sctp_findnet(stcb, addr);
6435 * We increment here since
6436 * sctp_findassociation_ep_addr() wil do a
6437 * decrement if it finds the stcb as long as
6438 * the locked tcb (last argument) is NOT a
6442 SCTP_INP_INCR_REF(inp);
6443 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6445 SCTP_INP_DECR_REF(inp);
6448 if ((stcb != NULL) && (net == NULL)) {
6450 if (addr->sa_family == AF_INET) {
6452 struct sockaddr_in *sin;
6454 sin = (struct sockaddr_in *)addr;
6455 if (sin->sin_addr.s_addr != INADDR_ANY) {
6456 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6457 SCTP_TCB_UNLOCK(stcb);
6464 if (addr->sa_family == AF_INET6) {
6465 struct sockaddr_in6 *sin6;
6467 sin6 = (struct sockaddr_in6 *)addr;
6468 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6469 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6470 SCTP_TCB_UNLOCK(stcb);
6477 error = EAFNOSUPPORT;
6478 SCTP_TCB_UNLOCK(stcb);
6479 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6485 net->port = encaps->sue_port;
6487 stcb->asoc.port = encaps->sue_port;
6489 SCTP_TCB_UNLOCK(stcb);
6491 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6492 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6493 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6494 SCTP_INP_WLOCK(inp);
6495 inp->sctp_ep.port = encaps->sue_port;
6496 SCTP_INP_WUNLOCK(inp);
6498 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6504 case SCTP_ECN_SUPPORTED:
6506 struct sctp_assoc_value *av;
6508 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6509 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6514 SCTP_TCB_UNLOCK(stcb);
6516 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6517 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6518 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6519 SCTP_INP_WLOCK(inp);
6520 if (av->assoc_value == 0) {
6521 inp->ecn_supported = 0;
6523 inp->ecn_supported = 1;
6525 SCTP_INP_WUNLOCK(inp);
6527 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6533 case SCTP_PR_SUPPORTED:
6535 struct sctp_assoc_value *av;
6537 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6538 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6541 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6543 SCTP_TCB_UNLOCK(stcb);
6545 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6546 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6547 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6548 SCTP_INP_WLOCK(inp);
6549 if (av->assoc_value == 0) {
6550 inp->prsctp_supported = 0;
6552 inp->prsctp_supported = 1;
6554 SCTP_INP_WUNLOCK(inp);
6556 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6562 case SCTP_AUTH_SUPPORTED:
6564 struct sctp_assoc_value *av;
6566 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6567 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6570 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6572 SCTP_TCB_UNLOCK(stcb);
6574 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6575 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6576 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6577 if ((av->assoc_value == 0) &&
6578 (inp->asconf_supported == 1)) {
6580 * AUTH is required for
6583 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6586 SCTP_INP_WLOCK(inp);
6587 if (av->assoc_value == 0) {
6588 inp->auth_supported = 0;
6590 inp->auth_supported = 1;
6592 SCTP_INP_WUNLOCK(inp);
6595 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6601 case SCTP_ASCONF_SUPPORTED:
6603 struct sctp_assoc_value *av;
6605 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6606 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6609 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6611 SCTP_TCB_UNLOCK(stcb);
6613 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6614 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6615 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6616 if ((av->assoc_value != 0) &&
6617 (inp->auth_supported == 0)) {
6619 * AUTH is required for
6622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6625 SCTP_INP_WLOCK(inp);
6626 if (av->assoc_value == 0) {
6627 inp->asconf_supported = 0;
6628 sctp_auth_delete_chunk(SCTP_ASCONF,
6629 inp->sctp_ep.local_auth_chunks);
6630 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6631 inp->sctp_ep.local_auth_chunks);
6633 inp->asconf_supported = 1;
6634 sctp_auth_add_chunk(SCTP_ASCONF,
6635 inp->sctp_ep.local_auth_chunks);
6636 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6637 inp->sctp_ep.local_auth_chunks);
6639 SCTP_INP_WUNLOCK(inp);
6642 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6648 case SCTP_RECONFIG_SUPPORTED:
6650 struct sctp_assoc_value *av;
6652 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6653 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6656 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6658 SCTP_TCB_UNLOCK(stcb);
6660 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6661 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6662 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6663 SCTP_INP_WLOCK(inp);
6664 if (av->assoc_value == 0) {
6665 inp->reconfig_supported = 0;
6667 inp->reconfig_supported = 1;
6669 SCTP_INP_WUNLOCK(inp);
6671 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6677 case SCTP_NRSACK_SUPPORTED:
6679 struct sctp_assoc_value *av;
6681 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6682 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6687 SCTP_TCB_UNLOCK(stcb);
6689 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6690 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6691 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6692 SCTP_INP_WLOCK(inp);
6693 if (av->assoc_value == 0) {
6694 inp->nrsack_supported = 0;
6696 inp->nrsack_supported = 1;
6698 SCTP_INP_WUNLOCK(inp);
6700 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6706 case SCTP_PKTDROP_SUPPORTED:
6708 struct sctp_assoc_value *av;
6710 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6711 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6714 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6716 SCTP_TCB_UNLOCK(stcb);
6718 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6719 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6720 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6721 SCTP_INP_WLOCK(inp);
6722 if (av->assoc_value == 0) {
6723 inp->pktdrop_supported = 0;
6725 inp->pktdrop_supported = 1;
6727 SCTP_INP_WUNLOCK(inp);
6729 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6737 struct sctp_assoc_value *av;
6738 struct sctp_nets *net;
6740 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6741 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6744 stcb->asoc.max_cwnd = av->assoc_value;
6745 if (stcb->asoc.max_cwnd > 0) {
6746 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6747 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6748 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6749 net->cwnd = stcb->asoc.max_cwnd;
6750 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6751 net->cwnd = net->mtu - sizeof(struct sctphdr);
6756 SCTP_TCB_UNLOCK(stcb);
6758 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6759 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6760 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6761 SCTP_INP_WLOCK(inp);
6762 inp->max_cwnd = av->assoc_value;
6763 SCTP_INP_WUNLOCK(inp);
6765 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6772 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6773 error = ENOPROTOOPT;
6775 } /* end switch (opt) */
6780 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6782 void *optval = NULL;
6786 struct sctp_inpcb *inp;
6788 if ((sopt->sopt_level == SOL_SOCKET) &&
6789 (sopt->sopt_name == SO_SETFIB)) {
6790 inp = (struct sctp_inpcb *)so->so_pcb;
6792 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6795 SCTP_INP_WLOCK(inp);
6796 inp->fibnum = so->so_fibnum;
6797 SCTP_INP_WUNLOCK(inp);
6800 if (sopt->sopt_level != IPPROTO_SCTP) {
6801 /* wrong proto level... send back up to IP */
6803 if (INP_CHECK_SOCKAF(so, AF_INET6))
6804 error = ip6_ctloutput(so, sopt);
6806 #if defined(INET) && defined(INET6)
6810 error = ip_ctloutput(so, sopt);
6814 optsize = sopt->sopt_valsize;
6816 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6817 if (optval == NULL) {
6818 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6821 error = sooptcopyin(sopt, optval, optsize, optsize);
6823 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6827 p = (void *)sopt->sopt_td;
6828 if (sopt->sopt_dir == SOPT_SET) {
6829 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6830 } else if (sopt->sopt_dir == SOPT_GET) {
6831 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6833 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6836 if ((error == 0) && (optval != NULL)) {
6837 error = sooptcopyout(sopt, optval, optsize);
6838 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6839 } else if (optval != NULL) {
6840 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6848 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6851 int create_lock_on = 0;
6853 struct sctp_inpcb *inp;
6854 struct sctp_tcb *stcb = NULL;
6856 inp = (struct sctp_inpcb *)so->so_pcb;
6858 /* I made the same as TCP since we are not setup? */
6859 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6860 return (ECONNRESET);
6863 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6866 switch (addr->sa_family) {
6870 struct sockaddr_in6 *sin6p;
6872 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6876 sin6p = (struct sockaddr_in6 *)addr;
6877 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6878 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6887 struct sockaddr_in *sinp;
6889 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6890 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6893 sinp = (struct sockaddr_in *)addr;
6894 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6895 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6903 return (EAFNOSUPPORT);
6905 SCTP_INP_INCR_REF(inp);
6906 SCTP_ASOC_CREATE_LOCK(inp);
6910 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6911 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6912 /* Should I really unlock ? */
6913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6918 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6919 (addr->sa_family == AF_INET6)) {
6920 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6925 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6926 SCTP_PCB_FLAGS_UNBOUND) {
6927 /* Bind a ephemeral port */
6928 error = sctp_inpcb_bind(so, NULL, NULL, p);
6933 /* Now do we connect? */
6934 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6935 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6936 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6940 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6941 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6942 /* We are already connected AND the TCP model */
6943 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6947 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6948 SCTP_INP_RLOCK(inp);
6949 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6950 SCTP_INP_RUNLOCK(inp);
6953 * We increment here since sctp_findassociation_ep_addr()
6954 * will do a decrement if it finds the stcb as long as the
6955 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6957 SCTP_INP_INCR_REF(inp);
6958 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6960 SCTP_INP_DECR_REF(inp);
6962 SCTP_TCB_UNLOCK(stcb);
6966 /* Already have or am bring up an association */
6967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6971 vrf_id = inp->def_vrf_id;
6972 /* We are GOOD to go */
6973 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
6974 inp->sctp_ep.pre_open_stream_count,
6975 inp->sctp_ep.port, p);
6977 /* Gak! no memory */
6980 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6981 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6982 /* Set the connected flag so we can queue data */
6985 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6986 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6988 /* initialize authentication parameters for the assoc */
6989 sctp_initialize_auth_params(inp, stcb);
6991 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6992 SCTP_TCB_UNLOCK(stcb);
6994 if (create_lock_on) {
6995 SCTP_ASOC_CREATE_UNLOCK(inp);
6997 SCTP_INP_DECR_REF(inp);
7003 sctp_listen(struct socket *so, int backlog, struct thread *p)
7006 * Note this module depends on the protocol processing being called
7007 * AFTER any socket level flags and backlog are applied to the
7008 * socket. The traditional way that the socket flags are applied is
7009 * AFTER protocol processing. We have made a change to the
7010 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7011 * place if the socket API for SCTP is to work properly.
7015 struct sctp_inpcb *inp;
7017 inp = (struct sctp_inpcb *)so->so_pcb;
7019 /* I made the same as TCP since we are not setup? */
7020 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7021 return (ECONNRESET);
7023 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7024 /* See if we have a listener */
7025 struct sctp_inpcb *tinp;
7026 union sctp_sockstore store;
7028 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7030 struct sctp_laddr *laddr;
7032 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7033 memcpy(&store, &laddr->ifa->address, sizeof(store));
7034 switch (store.sa.sa_family) {
7037 store.sin.sin_port = inp->sctp_lport;
7042 store.sin6.sin6_port = inp->sctp_lport;
7048 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7049 if (tinp && (tinp != inp) &&
7050 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7051 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7052 (SCTP_IS_LISTENING(tinp))) {
7054 * we have a listener already and
7057 SCTP_INP_DECR_REF(tinp);
7058 return (EADDRINUSE);
7060 SCTP_INP_DECR_REF(tinp);
7064 /* Setup a local addr bound all */
7065 memset(&store, 0, sizeof(store));
7067 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7068 store.sa.sa_family = AF_INET6;
7069 store.sa.sa_len = sizeof(struct sockaddr_in6);
7073 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7074 store.sa.sa_family = AF_INET;
7075 store.sa.sa_len = sizeof(struct sockaddr_in);
7078 switch (store.sa.sa_family) {
7081 store.sin.sin_port = inp->sctp_lport;
7086 store.sin6.sin6_port = inp->sctp_lport;
7092 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7093 if (tinp && (tinp != inp) &&
7094 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7095 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7096 (SCTP_IS_LISTENING(tinp))) {
7098 * we have a listener already and its not
7101 SCTP_INP_DECR_REF(tinp);
7102 return (EADDRINUSE);
7104 SCTP_INP_DECR_REF(tinp);
7108 SCTP_INP_RLOCK(inp);
7109 #ifdef SCTP_LOCK_LOGGING
7110 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7111 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7115 error = solisten_proto_check(so);
7118 SCTP_INP_RUNLOCK(inp);
7121 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7122 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7124 * The unlucky case - We are in the tcp pool with this guy.
7125 * - Someone else is in the main inp slot. - We must move
7126 * this guy (the listener) to the main slot - We must then
7127 * move the guy that was listener to the TCP Pool.
7129 if (sctp_swap_inpcb_for_listen(inp)) {
7130 SCTP_INP_RUNLOCK(inp);
7131 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7132 return (EADDRINUSE);
7135 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7136 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7137 /* We are already connected AND the TCP model */
7138 SCTP_INP_RUNLOCK(inp);
7139 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7140 return (EADDRINUSE);
7142 SCTP_INP_RUNLOCK(inp);
7143 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7144 /* We must do a bind. */
7145 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7146 /* bind error, probably perm */
7150 SCTP_INP_WLOCK(inp);
7151 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7153 solisten_proto(so, backlog);
7157 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7159 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7161 SCTP_INP_WUNLOCK(inp);
7165 static int sctp_defered_wakeup_cnt = 0;
7168 sctp_accept(struct socket *so, struct sockaddr **addr)
7170 struct sctp_tcb *stcb;
7171 struct sctp_inpcb *inp;
7172 union sctp_sockstore store;
7176 inp = (struct sctp_inpcb *)so->so_pcb;
7179 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7180 return (ECONNRESET);
7182 SCTP_INP_RLOCK(inp);
7183 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7184 SCTP_INP_RUNLOCK(inp);
7185 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7186 return (EOPNOTSUPP);
7188 if (so->so_state & SS_ISDISCONNECTED) {
7189 SCTP_INP_RUNLOCK(inp);
7190 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7191 return (ECONNABORTED);
7193 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7195 SCTP_INP_RUNLOCK(inp);
7196 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7197 return (ECONNRESET);
7199 SCTP_TCB_LOCK(stcb);
7200 SCTP_INP_RUNLOCK(inp);
7201 store = stcb->asoc.primary_destination->ro._l_addr;
7202 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7203 SCTP_TCB_UNLOCK(stcb);
7204 switch (store.sa.sa_family) {
7208 struct sockaddr_in *sin;
7210 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7213 sin->sin_family = AF_INET;
7214 sin->sin_len = sizeof(*sin);
7215 sin->sin_port = store.sin.sin_port;
7216 sin->sin_addr = store.sin.sin_addr;
7217 *addr = (struct sockaddr *)sin;
7224 struct sockaddr_in6 *sin6;
7226 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7229 sin6->sin6_family = AF_INET6;
7230 sin6->sin6_len = sizeof(*sin6);
7231 sin6->sin6_port = store.sin6.sin6_port;
7232 sin6->sin6_addr = store.sin6.sin6_addr;
7233 if ((error = sa6_recoverscope(sin6)) != 0) {
7234 SCTP_FREE_SONAME(sin6);
7237 *addr = (struct sockaddr *)sin6;
7245 /* Wake any delayed sleep action */
7246 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7247 SCTP_INP_WLOCK(inp);
7248 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7249 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7250 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7251 SCTP_INP_WUNLOCK(inp);
7252 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7253 if (sowriteable(inp->sctp_socket)) {
7254 sowwakeup_locked(inp->sctp_socket);
7256 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7258 SCTP_INP_WLOCK(inp);
7260 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7261 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7262 SCTP_INP_WUNLOCK(inp);
7263 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7264 if (soreadable(inp->sctp_socket)) {
7265 sctp_defered_wakeup_cnt++;
7266 sorwakeup_locked(inp->sctp_socket);
7268 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7270 SCTP_INP_WLOCK(inp);
7272 SCTP_INP_WUNLOCK(inp);
7274 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7275 SCTP_TCB_LOCK(stcb);
7276 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7277 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7284 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7286 struct sockaddr_in *sin;
7288 struct sctp_inpcb *inp;
7289 struct sctp_ifa *sctp_ifa;
7292 * Do the malloc first in case it blocks.
7294 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7297 sin->sin_family = AF_INET;
7298 sin->sin_len = sizeof(*sin);
7299 inp = (struct sctp_inpcb *)so->so_pcb;
7301 SCTP_FREE_SONAME(sin);
7302 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7303 return (ECONNRESET);
7305 SCTP_INP_RLOCK(inp);
7306 sin->sin_port = inp->sctp_lport;
7307 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7308 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7309 struct sctp_tcb *stcb;
7310 struct sockaddr_in *sin_a;
7311 struct sctp_nets *net;
7314 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7320 SCTP_TCB_LOCK(stcb);
7321 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7322 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7324 /* this will make coverity happy */
7327 if (sin_a->sin_family == AF_INET) {
7332 if ((!fnd) || (sin_a == NULL)) {
7334 SCTP_TCB_UNLOCK(stcb);
7337 vrf_id = inp->def_vrf_id;
7338 sctp_ifa = sctp_source_address_selection(inp,
7340 (sctp_route_t *)&net->ro,
7343 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7344 sctp_free_ifa(sctp_ifa);
7346 SCTP_TCB_UNLOCK(stcb);
7348 /* For the bound all case you get back 0 */
7350 sin->sin_addr.s_addr = 0;
7354 /* Take the first IPv4 address in the list */
7355 struct sctp_laddr *laddr;
7358 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7359 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7360 struct sockaddr_in *sin_a;
7362 sin_a = &laddr->ifa->address.sin;
7363 sin->sin_addr = sin_a->sin_addr;
7369 SCTP_FREE_SONAME(sin);
7370 SCTP_INP_RUNLOCK(inp);
7371 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7375 SCTP_INP_RUNLOCK(inp);
7376 (*addr) = (struct sockaddr *)sin;
7381 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7383 struct sockaddr_in *sin;
7385 struct sockaddr_in *sin_a;
7386 struct sctp_inpcb *inp;
7387 struct sctp_tcb *stcb;
7388 struct sctp_nets *net;
7390 /* Do the malloc first in case it blocks. */
7391 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7394 sin->sin_family = AF_INET;
7395 sin->sin_len = sizeof(*sin);
7397 inp = (struct sctp_inpcb *)so->so_pcb;
7398 if ((inp == NULL) ||
7399 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7400 /* UDP type and listeners will drop out here */
7401 SCTP_FREE_SONAME(sin);
7402 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7405 SCTP_INP_RLOCK(inp);
7406 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7408 SCTP_TCB_LOCK(stcb);
7410 SCTP_INP_RUNLOCK(inp);
7412 SCTP_FREE_SONAME(sin);
7413 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7414 return (ECONNRESET);
7417 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7418 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7419 if (sin_a->sin_family == AF_INET) {
7421 sin->sin_port = stcb->rport;
7422 sin->sin_addr = sin_a->sin_addr;
7426 SCTP_TCB_UNLOCK(stcb);
7428 /* No IPv4 address */
7429 SCTP_FREE_SONAME(sin);
7430 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7433 (*addr) = (struct sockaddr *)sin;
7437 struct pr_usrreqs sctp_usrreqs = {
7438 .pru_abort = sctp_abort,
7439 .pru_accept = sctp_accept,
7440 .pru_attach = sctp_attach,
7441 .pru_bind = sctp_bind,
7442 .pru_connect = sctp_connect,
7443 .pru_control = in_control,
7444 .pru_close = sctp_close,
7445 .pru_detach = sctp_close,
7446 .pru_sopoll = sopoll_generic,
7447 .pru_flush = sctp_flush,
7448 .pru_disconnect = sctp_disconnect,
7449 .pru_listen = sctp_listen,
7450 .pru_peeraddr = sctp_peeraddr,
7451 .pru_send = sctp_sendm,
7452 .pru_shutdown = sctp_shutdown,
7453 .pru_sockaddr = sctp_ingetaddr,
7454 .pru_sosend = sctp_sosend,
7455 .pru_soreceive = sctp_soreceive