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) == 0) {
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 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_NOWAIT, 1, MT_DATA);
716 struct sctp_paramhdr *ph;
718 ph = mtod(err, struct sctp_paramhdr *);
719 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
720 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
721 ph->param_length = htons(SCTP_BUF_LEN(err));
723 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
724 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
726 SCTP_INP_RUNLOCK(inp);
727 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
728 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
729 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
731 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
732 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
733 /* No unlock tcb assoc is gone */
736 if (TAILQ_EMPTY(&asoc->send_queue) &&
737 TAILQ_EMPTY(&asoc->sent_queue) &&
738 (asoc->stream_queue_cnt == 0)) {
739 /* there is nothing queued to send, so done */
740 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
743 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
744 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
745 /* only send SHUTDOWN 1st time thru */
746 struct sctp_nets *netp;
748 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
749 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
750 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
752 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
753 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
754 sctp_stop_timers_for_shutdown(stcb);
755 if (stcb->asoc.alternate) {
756 netp = stcb->asoc.alternate;
758 netp = stcb->asoc.primary_destination;
760 sctp_send_shutdown(stcb, netp);
761 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
762 stcb->sctp_ep, stcb, netp);
763 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
764 stcb->sctp_ep, stcb, netp);
765 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
769 * we still got (or just got) data to send,
770 * so set SHUTDOWN_PENDING
773 * XXX sockets draft says that SCTP_EOF
774 * should be sent with no data. currently,
775 * we will allow user data to be sent first
776 * and move to SHUTDOWN-PENDING
778 struct sctp_nets *netp;
780 if (stcb->asoc.alternate) {
781 netp = stcb->asoc.alternate;
783 netp = stcb->asoc.primary_destination;
786 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
787 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
789 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
790 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
792 if (TAILQ_EMPTY(&asoc->send_queue) &&
793 TAILQ_EMPTY(&asoc->sent_queue) &&
794 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
798 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
799 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
800 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
801 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
802 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
803 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
804 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
806 SCTP_INP_RUNLOCK(inp);
807 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
808 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
811 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
814 soisdisconnecting(so);
815 SCTP_TCB_UNLOCK(stcb);
816 SCTP_INP_RUNLOCK(inp);
821 /* UDP model does not support this */
822 SCTP_INP_RUNLOCK(inp);
823 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
829 sctp_flush(struct socket *so, int how)
832 * We will just clear out the values and let subsequent close clear
833 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
834 * they will not be able to read the data, the socket will block
835 * that from happening.
837 struct sctp_inpcb *inp;
839 inp = (struct sctp_inpcb *)so->so_pcb;
841 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
845 /* For the 1 to many model this does nothing */
846 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
847 SCTP_INP_RUNLOCK(inp);
850 SCTP_INP_RUNLOCK(inp);
851 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
853 * First make sure the sb will be happy, we don't use these
854 * except maybe the count
857 SCTP_INP_READ_LOCK(inp);
858 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
859 SCTP_INP_READ_UNLOCK(inp);
860 SCTP_INP_WUNLOCK(inp);
861 so->so_rcv.sb_cc = 0;
862 so->so_rcv.sb_mbcnt = 0;
863 so->so_rcv.sb_mb = NULL;
865 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
867 * First make sure the sb will be happy, we don't use these
868 * except maybe the count
870 so->so_snd.sb_cc = 0;
871 so->so_snd.sb_mbcnt = 0;
872 so->so_snd.sb_mb = NULL;
879 sctp_shutdown(struct socket *so)
881 struct sctp_inpcb *inp;
883 inp = (struct sctp_inpcb *)so->so_pcb;
885 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
889 /* For UDP model this is a invalid call */
890 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
891 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
892 /* Restore the flags that the soshutdown took away. */
893 SOCKBUF_LOCK(&so->so_rcv);
894 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
895 SOCKBUF_UNLOCK(&so->so_rcv);
896 /* This proc will wakeup for read and do nothing (I hope) */
897 SCTP_INP_RUNLOCK(inp);
898 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
902 * Ok, if we reach here its the TCP model and it is either a
903 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
906 struct sctp_tcb *stcb;
907 struct sctp_association *asoc;
908 struct sctp_nets *netp;
911 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
912 SCTP_INP_RUNLOCK(inp);
917 stcb = LIST_FIRST(&inp->sctp_asoc_list);
920 * Ok, we hit the case that the shutdown call was
921 * made after an abort or something. Nothing to do
924 SCTP_INP_RUNLOCK(inp);
929 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
930 SCTP_TCB_UNLOCK(stcb);
931 SCTP_INP_RUNLOCK(inp);
934 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_WAIT) &&
935 (SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_ECHOED) &&
936 (SCTP_GET_STATE(asoc) != SCTP_STATE_OPEN)) {
938 * If we are not in or before ESTABLISHED, there is
939 * no protocol action required.
941 SCTP_TCB_UNLOCK(stcb);
942 SCTP_INP_RUNLOCK(inp);
945 if (stcb->asoc.alternate) {
946 netp = stcb->asoc.alternate;
948 netp = stcb->asoc.primary_destination;
950 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) &&
951 TAILQ_EMPTY(&asoc->send_queue) &&
952 TAILQ_EMPTY(&asoc->sent_queue) &&
953 (asoc->stream_queue_cnt == 0)) {
954 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
957 /* there is nothing queued to send, so I'm done... */
958 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
959 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
960 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
961 sctp_stop_timers_for_shutdown(stcb);
962 sctp_send_shutdown(stcb, netp);
963 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
964 stcb->sctp_ep, stcb, netp);
967 * We still got (or just got) data to send, so set
970 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
971 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
972 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_PARTIAL_MSG_LEFT);
974 if (TAILQ_EMPTY(&asoc->send_queue) &&
975 TAILQ_EMPTY(&asoc->sent_queue) &&
976 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
980 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
981 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
982 sctp_abort_an_association(stcb->sctp_ep, stcb,
983 op_err, SCTP_SO_LOCKED);
984 SCTP_INP_RUNLOCK(inp);
988 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp);
990 * XXX: Why do this in the case where we have still data
993 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
994 SCTP_TCB_UNLOCK(stcb);
995 SCTP_INP_RUNLOCK(inp);
1001 * copies a "user" presentable address and removes embedded scope, etc.
1002 * returns 0 on success, 1 on error
1005 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1008 struct sockaddr_in6 lsa6;
1010 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1013 memcpy(ss, sa, sa->sa_len);
1020 * NOTE: assumes addr lock is held
1023 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1024 struct sctp_tcb *stcb,
1026 struct sockaddr_storage *sas,
1029 struct sctp_ifn *sctp_ifn;
1030 struct sctp_ifa *sctp_ifa;
1034 int ipv4_local_scope, ipv4_addr_legal;
1037 int local_scope, site_scope, ipv6_addr_legal;
1039 struct sctp_vrf *vrf;
1046 /* Turn on all the appropriate scope */
1047 loopback_scope = stcb->asoc.scope.loopback_scope;
1049 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1050 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1053 local_scope = stcb->asoc.scope.local_scope;
1054 site_scope = stcb->asoc.scope.site_scope;
1055 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1058 /* Use generic values for endpoints. */
1061 ipv4_local_scope = 1;
1067 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1069 ipv6_addr_legal = 1;
1072 if (SCTP_IPV6_V6ONLY(inp)) {
1073 ipv4_addr_legal = 0;
1075 ipv4_addr_legal = 1;
1080 ipv6_addr_legal = 0;
1083 ipv4_addr_legal = 1;
1087 vrf = sctp_find_vrf(vrf_id);
1091 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1092 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1093 if ((loopback_scope == 0) &&
1094 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1095 /* Skip loopback if loopback_scope not set */
1098 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1101 * For the BOUND-ALL case, the list
1102 * associated with a TCB is Always
1103 * considered a reverse list.. i.e.
1104 * it lists addresses that are NOT
1105 * part of the association. If this
1106 * is one of those we must skip it.
1108 if (sctp_is_addr_restricted(stcb,
1113 switch (sctp_ifa->address.sa.sa_family) {
1116 if (ipv4_addr_legal) {
1117 struct sockaddr_in *sin;
1119 sin = &sctp_ifa->address.sin;
1120 if (sin->sin_addr.s_addr == 0) {
1128 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1129 &sin->sin_addr) != 0) {
1132 if ((ipv4_local_scope == 0) &&
1133 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1137 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1138 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1139 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1140 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1141 actual += sizeof(struct sockaddr_in6);
1144 memcpy(sas, sin, sizeof(*sin));
1145 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1146 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1147 actual += sizeof(*sin);
1151 if (actual >= limit) {
1161 if (ipv6_addr_legal) {
1162 struct sockaddr_in6 *sin6;
1164 sin6 = &sctp_ifa->address.sin6;
1165 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1173 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1174 &sin6->sin6_addr) != 0) {
1177 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1178 if (local_scope == 0)
1180 if (sin6->sin6_scope_id == 0) {
1181 if (sa6_recoverscope(sin6) != 0)
1194 if ((site_scope == 0) &&
1195 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1198 memcpy(sas, sin6, sizeof(*sin6));
1199 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1200 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1201 actual += sizeof(*sin6);
1202 if (actual >= limit) {
1217 struct sctp_laddr *laddr;
1219 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1221 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1225 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1227 switch (laddr->ifa->address.sa.sa_family) {
1230 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1235 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1242 sas = (struct sockaddr_storage *)((caddr_t)sas +
1243 laddr->ifa->address.sa.sa_len);
1244 actual += laddr->ifa->address.sa.sa_len;
1245 if (actual >= limit) {
1254 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1255 struct sctp_tcb *stcb,
1257 struct sockaddr_storage *sas)
1261 SCTP_IPI_ADDR_RLOCK();
1262 /* fill up addresses for the endpoint's default vrf */
1263 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1265 SCTP_IPI_ADDR_RUNLOCK();
1270 * NOTE: assumes addr lock is held
1273 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1276 struct sctp_vrf *vrf = NULL;
1279 * In both sub-set bound an bound_all cases we return the MAXIMUM
1280 * number of addresses that you COULD get. In reality the sub-set
1281 * bound may have an exclusion list for a given TCB OR in the
1282 * bound-all case a TCB may NOT include the loopback or other
1283 * addresses as well.
1285 vrf = sctp_find_vrf(vrf_id);
1289 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1290 struct sctp_ifn *sctp_ifn;
1291 struct sctp_ifa *sctp_ifa;
1293 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1294 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1295 /* Count them if they are the right type */
1296 switch (sctp_ifa->address.sa.sa_family) {
1300 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1301 cnt += sizeof(struct sockaddr_in6);
1303 cnt += sizeof(struct sockaddr_in);
1305 cnt += sizeof(struct sockaddr_in);
1311 cnt += sizeof(struct sockaddr_in6);
1320 struct sctp_laddr *laddr;
1322 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1323 switch (laddr->ifa->address.sa.sa_family) {
1327 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1328 cnt += sizeof(struct sockaddr_in6);
1330 cnt += sizeof(struct sockaddr_in);
1332 cnt += sizeof(struct sockaddr_in);
1338 cnt += sizeof(struct sockaddr_in6);
1350 sctp_count_max_addresses(struct sctp_inpcb *inp)
1354 SCTP_IPI_ADDR_RLOCK();
1355 /* count addresses for the endpoint's default VRF */
1356 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1357 SCTP_IPI_ADDR_RUNLOCK();
1362 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1363 size_t optsize, void *p, int delay)
1366 int creat_lock_on = 0;
1367 struct sctp_tcb *stcb = NULL;
1368 struct sockaddr *sa;
1369 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1371 int bad_addresses = 0;
1374 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1376 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1377 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1378 /* We are already connected AND the TCP model */
1379 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1380 return (EADDRINUSE);
1382 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1383 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1384 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1387 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1388 SCTP_INP_RLOCK(inp);
1389 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1390 SCTP_INP_RUNLOCK(inp);
1393 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1396 SCTP_INP_INCR_REF(inp);
1397 SCTP_ASOC_CREATE_LOCK(inp);
1399 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1400 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1401 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1405 totaddrp = (unsigned int *)optval;
1406 totaddr = *totaddrp;
1407 sa = (struct sockaddr *)(totaddrp + 1);
1408 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (unsigned int)(optsize - sizeof(int)), &bad_addresses);
1409 if ((stcb != NULL) || bad_addresses) {
1410 /* Already have or am bring up an association */
1411 SCTP_ASOC_CREATE_UNLOCK(inp);
1414 SCTP_TCB_UNLOCK(stcb);
1415 if (bad_addresses == 0) {
1416 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1422 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1427 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1429 struct in6pcb *inp6;
1431 inp6 = (struct in6pcb *)inp;
1432 if (SCTP_IPV6_V6ONLY(inp6)) {
1434 * if IPV6_V6ONLY flag, ignore connections destined
1435 * to a v4 addr or v4-mapped addr
1437 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1443 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1444 SCTP_PCB_FLAGS_UNBOUND) {
1445 /* Bind a ephemeral port */
1446 error = sctp_inpcb_bind(so, NULL, NULL, p);
1451 /* FIX ME: do we want to pass in a vrf on the connect call? */
1452 vrf_id = inp->def_vrf_id;
1455 /* We are GOOD to go */
1456 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1457 inp->sctp_ep.pre_open_stream_count,
1462 /* Gak! no memory */
1465 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1466 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1467 /* Set the connected flag so we can queue data */
1470 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1471 /* move to second address */
1472 switch (sa->sa_family) {
1475 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1480 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1488 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1489 /* Fill in the return id */
1491 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE,
1492 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
1495 a_id = (sctp_assoc_t *)optval;
1496 *a_id = sctp_get_associd(stcb);
1498 /* initialize authentication parameters for the assoc */
1499 sctp_initialize_auth_params(inp, stcb);
1502 /* doing delayed connection */
1503 stcb->asoc.delayed_connection = 1;
1504 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1506 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1507 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1509 SCTP_TCB_UNLOCK(stcb);
1511 if (creat_lock_on) {
1512 SCTP_ASOC_CREATE_UNLOCK(inp);
1514 SCTP_INP_DECR_REF(inp);
1518 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1519 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1520 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1521 SCTP_INP_RLOCK(inp); \
1522 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1524 SCTP_TCB_LOCK(stcb); \
1526 SCTP_INP_RUNLOCK(inp); \
1527 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1528 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1529 if (stcb == NULL) { \
1530 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1540 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1541 if (size < sizeof(type)) { \
1542 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1546 destp = (type *)srcp; \
1551 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1554 struct sctp_inpcb *inp = NULL;
1556 struct sctp_tcb *stcb = NULL;
1558 if (optval == NULL) {
1559 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1562 inp = (struct sctp_inpcb *)so->so_pcb;
1564 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1571 case SCTP_AUTOCLOSE:
1572 case SCTP_EXPLICIT_EOR:
1573 case SCTP_AUTO_ASCONF:
1574 case SCTP_DISABLE_FRAGMENTS:
1575 case SCTP_I_WANT_MAPPED_V4_ADDR:
1576 case SCTP_USE_EXT_RCVINFO:
1577 SCTP_INP_RLOCK(inp);
1579 case SCTP_DISABLE_FRAGMENTS:
1580 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1582 case SCTP_I_WANT_MAPPED_V4_ADDR:
1583 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1585 case SCTP_AUTO_ASCONF:
1586 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1587 /* only valid for bound all sockets */
1588 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1590 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1595 case SCTP_EXPLICIT_EOR:
1596 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1599 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1601 case SCTP_USE_EXT_RCVINFO:
1602 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1604 case SCTP_AUTOCLOSE:
1605 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1606 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1612 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1613 error = ENOPROTOOPT;
1614 } /* end switch (sopt->sopt_name) */
1615 if (*optsize < sizeof(val)) {
1616 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1620 SCTP_INP_RUNLOCK(inp);
1622 /* return the option value */
1623 *(int *)optval = val;
1624 *optsize = sizeof(val);
1627 case SCTP_GET_PACKET_LOG:
1629 #ifdef SCTP_PACKET_LOGGING
1633 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1634 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1637 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1642 case SCTP_REUSE_PORT:
1646 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1647 /* Can't do this for a 1-m socket */
1651 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1652 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1653 *optsize = sizeof(uint32_t);
1656 case SCTP_PARTIAL_DELIVERY_POINT:
1660 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1661 *value = inp->partial_delivery_point;
1662 *optsize = sizeof(uint32_t);
1665 case SCTP_FRAGMENT_INTERLEAVE:
1669 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1670 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1671 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1672 *value = SCTP_FRAG_LEVEL_2;
1674 *value = SCTP_FRAG_LEVEL_1;
1677 *value = SCTP_FRAG_LEVEL_0;
1679 *optsize = sizeof(uint32_t);
1682 case SCTP_INTERLEAVING_SUPPORTED:
1684 struct sctp_assoc_value *av;
1686 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1687 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1690 av->assoc_value = stcb->asoc.idata_supported;
1691 SCTP_TCB_UNLOCK(stcb);
1693 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1694 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1695 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1696 SCTP_INP_RLOCK(inp);
1697 if (inp->idata_supported) {
1698 av->assoc_value = 1;
1700 av->assoc_value = 0;
1702 SCTP_INP_RUNLOCK(inp);
1704 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1709 *optsize = sizeof(struct sctp_assoc_value);
1713 case SCTP_CMT_ON_OFF:
1715 struct sctp_assoc_value *av;
1717 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1718 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1720 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1721 SCTP_TCB_UNLOCK(stcb);
1723 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1724 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1725 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1726 SCTP_INP_RLOCK(inp);
1727 av->assoc_value = inp->sctp_cmt_on_off;
1728 SCTP_INP_RUNLOCK(inp);
1730 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1735 *optsize = sizeof(struct sctp_assoc_value);
1739 case SCTP_PLUGGABLE_CC:
1741 struct sctp_assoc_value *av;
1743 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1744 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1746 av->assoc_value = stcb->asoc.congestion_control_module;
1747 SCTP_TCB_UNLOCK(stcb);
1749 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1750 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1751 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1752 SCTP_INP_RLOCK(inp);
1753 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1754 SCTP_INP_RUNLOCK(inp);
1756 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1761 *optsize = sizeof(struct sctp_assoc_value);
1765 case SCTP_CC_OPTION:
1767 struct sctp_cc_option *cc_opt;
1769 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1770 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1774 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1777 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1778 *optsize = sizeof(struct sctp_cc_option);
1780 SCTP_TCB_UNLOCK(stcb);
1784 case SCTP_PLUGGABLE_SS:
1786 struct sctp_assoc_value *av;
1788 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1789 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1791 av->assoc_value = stcb->asoc.stream_scheduling_module;
1792 SCTP_TCB_UNLOCK(stcb);
1794 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1795 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1796 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1797 SCTP_INP_RLOCK(inp);
1798 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1799 SCTP_INP_RUNLOCK(inp);
1801 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1806 *optsize = sizeof(struct sctp_assoc_value);
1812 struct sctp_stream_value *av;
1814 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1815 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1817 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1818 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1819 &av->stream_value) < 0)) {
1820 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1823 *optsize = sizeof(struct sctp_stream_value);
1825 SCTP_TCB_UNLOCK(stcb);
1828 * Can't get stream value without
1831 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1836 case SCTP_GET_ADDR_LEN:
1838 struct sctp_assoc_value *av;
1840 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1843 if (av->assoc_value == AF_INET) {
1844 av->assoc_value = sizeof(struct sockaddr_in);
1849 if (av->assoc_value == AF_INET6) {
1850 av->assoc_value = sizeof(struct sockaddr_in6);
1855 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1857 *optsize = sizeof(struct sctp_assoc_value);
1861 case SCTP_GET_ASSOC_NUMBER:
1863 uint32_t *value, cnt;
1865 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1866 SCTP_INP_RLOCK(inp);
1867 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1868 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1869 /* Can't do this for a 1-1 socket */
1871 SCTP_INP_RUNLOCK(inp);
1875 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1878 SCTP_INP_RUNLOCK(inp);
1880 *optsize = sizeof(uint32_t);
1883 case SCTP_GET_ASSOC_ID_LIST:
1885 struct sctp_assoc_ids *ids;
1889 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1890 SCTP_INP_RLOCK(inp);
1891 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1892 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1893 /* Can't do this for a 1-1 socket */
1895 SCTP_INP_RUNLOCK(inp);
1899 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1900 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1902 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1905 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1914 SCTP_INP_RUNLOCK(inp);
1916 ids->gaids_number_of_ids = at;
1917 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1923 struct sctp_assoc_value *av;
1925 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1926 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1929 av->assoc_value = stcb->asoc.context;
1930 SCTP_TCB_UNLOCK(stcb);
1932 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1933 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1934 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1935 SCTP_INP_RLOCK(inp);
1936 av->assoc_value = inp->sctp_context;
1937 SCTP_INP_RUNLOCK(inp);
1939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1944 *optsize = sizeof(struct sctp_assoc_value);
1950 uint32_t *default_vrfid;
1952 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1953 *default_vrfid = inp->def_vrf_id;
1954 *optsize = sizeof(uint32_t);
1957 case SCTP_GET_ASOC_VRF:
1959 struct sctp_assoc_value *id;
1961 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1962 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1967 id->assoc_value = stcb->asoc.vrf_id;
1968 SCTP_TCB_UNLOCK(stcb);
1969 *optsize = sizeof(struct sctp_assoc_value);
1973 case SCTP_GET_VRF_IDS:
1975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1979 case SCTP_GET_NONCE_VALUES:
1981 struct sctp_get_nonce_values *gnv;
1983 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1984 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1987 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1988 gnv->gn_local_tag = stcb->asoc.my_vtag;
1989 SCTP_TCB_UNLOCK(stcb);
1990 *optsize = sizeof(struct sctp_get_nonce_values);
1992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1997 case SCTP_DELAYED_SACK:
1999 struct sctp_sack_info *sack;
2001 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2002 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2004 sack->sack_delay = stcb->asoc.delayed_ack;
2005 sack->sack_freq = stcb->asoc.sack_freq;
2006 SCTP_TCB_UNLOCK(stcb);
2008 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2009 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2010 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2011 SCTP_INP_RLOCK(inp);
2012 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2013 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2014 SCTP_INP_RUNLOCK(inp);
2016 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2021 *optsize = sizeof(struct sctp_sack_info);
2025 case SCTP_GET_SNDBUF_USE:
2027 struct sctp_sockstat *ss;
2029 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2030 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2033 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2034 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2035 stcb->asoc.size_on_all_streams);
2036 SCTP_TCB_UNLOCK(stcb);
2037 *optsize = sizeof(struct sctp_sockstat);
2039 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2044 case SCTP_MAX_BURST:
2046 struct sctp_assoc_value *av;
2048 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2049 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2052 av->assoc_value = stcb->asoc.max_burst;
2053 SCTP_TCB_UNLOCK(stcb);
2055 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2056 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2057 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2058 SCTP_INP_RLOCK(inp);
2059 av->assoc_value = inp->sctp_ep.max_burst;
2060 SCTP_INP_RUNLOCK(inp);
2062 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2067 *optsize = sizeof(struct sctp_assoc_value);
2073 struct sctp_assoc_value *av;
2076 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2077 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2080 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2081 SCTP_TCB_UNLOCK(stcb);
2083 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2084 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2085 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2086 SCTP_INP_RLOCK(inp);
2087 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2088 ovh = SCTP_MED_OVERHEAD;
2090 ovh = SCTP_MED_V4_OVERHEAD;
2092 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2093 av->assoc_value = 0;
2095 av->assoc_value = inp->sctp_frag_point - ovh;
2096 SCTP_INP_RUNLOCK(inp);
2098 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2103 *optsize = sizeof(struct sctp_assoc_value);
2107 case SCTP_GET_STAT_LOG:
2108 error = sctp_fill_stat_log(optval, optsize);
2112 struct sctp_event_subscribe *events;
2114 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2115 memset(events, 0, sizeof(struct sctp_event_subscribe));
2116 SCTP_INP_RLOCK(inp);
2117 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2118 events->sctp_data_io_event = 1;
2120 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2121 events->sctp_association_event = 1;
2123 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2124 events->sctp_address_event = 1;
2126 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2127 events->sctp_send_failure_event = 1;
2129 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2130 events->sctp_peer_error_event = 1;
2132 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2133 events->sctp_shutdown_event = 1;
2135 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2136 events->sctp_partial_delivery_event = 1;
2138 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2139 events->sctp_adaptation_layer_event = 1;
2141 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2142 events->sctp_authentication_event = 1;
2144 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2145 events->sctp_sender_dry_event = 1;
2147 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2148 events->sctp_stream_reset_event = 1;
2149 SCTP_INP_RUNLOCK(inp);
2150 *optsize = sizeof(struct sctp_event_subscribe);
2153 case SCTP_ADAPTATION_LAYER:
2157 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2159 SCTP_INP_RLOCK(inp);
2160 *value = inp->sctp_ep.adaptation_layer_indicator;
2161 SCTP_INP_RUNLOCK(inp);
2162 *optsize = sizeof(uint32_t);
2165 case SCTP_SET_INITIAL_DBG_SEQ:
2169 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2170 SCTP_INP_RLOCK(inp);
2171 *value = inp->sctp_ep.initial_sequence_debug;
2172 SCTP_INP_RUNLOCK(inp);
2173 *optsize = sizeof(uint32_t);
2176 case SCTP_GET_LOCAL_ADDR_SIZE:
2180 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2181 SCTP_INP_RLOCK(inp);
2182 *value = sctp_count_max_addresses(inp);
2183 SCTP_INP_RUNLOCK(inp);
2184 *optsize = sizeof(uint32_t);
2187 case SCTP_GET_REMOTE_ADDR_SIZE:
2191 struct sctp_nets *net;
2193 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2194 /* FIXME MT: change to sctp_assoc_value? */
2195 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2199 /* Count the sizes */
2200 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2201 switch (net->ro._l_addr.sa.sa_family) {
2205 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2206 size += sizeof(struct sockaddr_in6);
2208 size += sizeof(struct sockaddr_in);
2211 size += sizeof(struct sockaddr_in);
2217 size += sizeof(struct sockaddr_in6);
2224 SCTP_TCB_UNLOCK(stcb);
2225 *value = (uint32_t)size;
2226 *optsize = sizeof(uint32_t);
2228 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2233 case SCTP_GET_PEER_ADDRESSES:
2235 * Get the address information, an array is passed in to
2236 * fill up we pack it.
2240 struct sockaddr_storage *sas;
2241 struct sctp_nets *net;
2242 struct sctp_getaddresses *saddr;
2244 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2245 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2248 left = (*optsize) - sizeof(struct sctp_getaddresses);
2249 *optsize = sizeof(struct sctp_getaddresses);
2250 sas = (struct sockaddr_storage *)&saddr->addr[0];
2252 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2253 switch (net->ro._l_addr.sa.sa_family) {
2257 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2258 cpsz = sizeof(struct sockaddr_in6);
2260 cpsz = sizeof(struct sockaddr_in);
2263 cpsz = sizeof(struct sockaddr_in);
2269 cpsz = sizeof(struct sockaddr_in6);
2280 /* not enough room. */
2283 #if defined(INET) && defined(INET6)
2284 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2285 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2286 /* Must map the address */
2287 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2288 (struct sockaddr_in6 *)sas);
2290 memcpy(sas, &net->ro._l_addr, cpsz);
2293 memcpy(sas, &net->ro._l_addr, cpsz);
2295 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2297 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2301 SCTP_TCB_UNLOCK(stcb);
2303 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2308 case SCTP_GET_LOCAL_ADDRESSES:
2310 size_t limit, actual;
2311 struct sockaddr_storage *sas;
2312 struct sctp_getaddresses *saddr;
2314 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2315 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2317 sas = (struct sockaddr_storage *)&saddr->addr[0];
2318 limit = *optsize - sizeof(sctp_assoc_t);
2319 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2321 SCTP_TCB_UNLOCK(stcb);
2323 *optsize = sizeof(struct sockaddr_storage) + actual;
2326 case SCTP_PEER_ADDR_PARAMS:
2328 struct sctp_paddrparams *paddrp;
2329 struct sctp_nets *net;
2330 struct sockaddr *addr;
2331 #if defined(INET) && defined(INET6)
2332 struct sockaddr_in sin_store;
2335 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2336 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2338 #if defined(INET) && defined(INET6)
2339 if (paddrp->spp_address.ss_family == AF_INET6) {
2340 struct sockaddr_in6 *sin6;
2342 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2343 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2344 in6_sin6_2_sin(&sin_store, sin6);
2345 addr = (struct sockaddr *)&sin_store;
2347 addr = (struct sockaddr *)&paddrp->spp_address;
2350 addr = (struct sockaddr *)&paddrp->spp_address;
2353 addr = (struct sockaddr *)&paddrp->spp_address;
2356 net = sctp_findnet(stcb, addr);
2359 * We increment here since
2360 * sctp_findassociation_ep_addr() wil do a
2361 * decrement if it finds the stcb as long as
2362 * the locked tcb (last argument) is NOT a
2366 SCTP_INP_INCR_REF(inp);
2367 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2369 SCTP_INP_DECR_REF(inp);
2372 if ((stcb != NULL) && (net == NULL)) {
2374 if (addr->sa_family == AF_INET) {
2375 struct sockaddr_in *sin;
2377 sin = (struct sockaddr_in *)addr;
2378 if (sin->sin_addr.s_addr != INADDR_ANY) {
2380 SCTP_TCB_UNLOCK(stcb);
2381 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2387 if (addr->sa_family == AF_INET6) {
2388 struct sockaddr_in6 *sin6;
2390 sin6 = (struct sockaddr_in6 *)addr;
2391 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2393 SCTP_TCB_UNLOCK(stcb);
2394 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2400 error = EAFNOSUPPORT;
2401 SCTP_TCB_UNLOCK(stcb);
2402 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2407 /* Applies to the specific association */
2408 paddrp->spp_flags = 0;
2410 paddrp->spp_hbinterval = net->heart_beat_delay;
2411 paddrp->spp_pathmaxrxt = net->failure_threshold;
2412 paddrp->spp_pathmtu = net->mtu;
2413 switch (net->ro._l_addr.sa.sa_family) {
2416 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2421 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2427 /* get flags for HB */
2428 if (net->dest_state & SCTP_ADDR_NOHB) {
2429 paddrp->spp_flags |= SPP_HB_DISABLE;
2431 paddrp->spp_flags |= SPP_HB_ENABLE;
2433 /* get flags for PMTU */
2434 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2435 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2437 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2439 if (net->dscp & 0x01) {
2440 paddrp->spp_dscp = net->dscp & 0xfc;
2441 paddrp->spp_flags |= SPP_DSCP;
2444 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2445 (net->flowlabel & 0x80000000)) {
2446 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2447 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2452 * No destination so return default
2455 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2456 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2457 if (stcb->asoc.default_dscp & 0x01) {
2458 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2459 paddrp->spp_flags |= SPP_DSCP;
2462 if (stcb->asoc.default_flowlabel & 0x80000000) {
2463 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2464 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2467 /* default settings should be these */
2468 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2469 paddrp->spp_flags |= SPP_HB_DISABLE;
2471 paddrp->spp_flags |= SPP_HB_ENABLE;
2473 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2474 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2476 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2478 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2480 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2481 SCTP_TCB_UNLOCK(stcb);
2483 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2484 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2485 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2486 /* Use endpoint defaults */
2487 SCTP_INP_RLOCK(inp);
2488 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2489 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2490 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2491 /* get inp's default */
2492 if (inp->sctp_ep.default_dscp & 0x01) {
2493 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2494 paddrp->spp_flags |= SPP_DSCP;
2497 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2498 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2499 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2500 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2503 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2505 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2506 paddrp->spp_flags |= SPP_HB_ENABLE;
2508 paddrp->spp_flags |= SPP_HB_DISABLE;
2510 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2511 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2513 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2515 SCTP_INP_RUNLOCK(inp);
2517 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2522 *optsize = sizeof(struct sctp_paddrparams);
2526 case SCTP_GET_PEER_ADDR_INFO:
2528 struct sctp_paddrinfo *paddri;
2529 struct sctp_nets *net;
2530 struct sockaddr *addr;
2531 #if defined(INET) && defined(INET6)
2532 struct sockaddr_in sin_store;
2535 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2536 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2538 #if defined(INET) && defined(INET6)
2539 if (paddri->spinfo_address.ss_family == AF_INET6) {
2540 struct sockaddr_in6 *sin6;
2542 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2543 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2544 in6_sin6_2_sin(&sin_store, sin6);
2545 addr = (struct sockaddr *)&sin_store;
2547 addr = (struct sockaddr *)&paddri->spinfo_address;
2550 addr = (struct sockaddr *)&paddri->spinfo_address;
2553 addr = (struct sockaddr *)&paddri->spinfo_address;
2556 net = sctp_findnet(stcb, addr);
2559 * We increment here since
2560 * sctp_findassociation_ep_addr() wil do a
2561 * decrement if it finds the stcb as long as
2562 * the locked tcb (last argument) is NOT a
2566 SCTP_INP_INCR_REF(inp);
2567 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2569 SCTP_INP_DECR_REF(inp);
2573 if ((stcb != NULL) && (net != NULL)) {
2574 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2575 /* It's unconfirmed */
2576 paddri->spinfo_state = SCTP_UNCONFIRMED;
2577 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2579 paddri->spinfo_state = SCTP_ACTIVE;
2582 paddri->spinfo_state = SCTP_INACTIVE;
2584 paddri->spinfo_cwnd = net->cwnd;
2585 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2586 paddri->spinfo_rto = net->RTO;
2587 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2588 paddri->spinfo_mtu = net->mtu;
2589 switch (addr->sa_family) {
2592 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2597 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2603 SCTP_TCB_UNLOCK(stcb);
2604 *optsize = sizeof(struct sctp_paddrinfo);
2607 SCTP_TCB_UNLOCK(stcb);
2609 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2614 case SCTP_PCB_STATUS:
2616 struct sctp_pcbinfo *spcb;
2618 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2619 sctp_fill_pcbinfo(spcb);
2620 *optsize = sizeof(struct sctp_pcbinfo);
2625 struct sctp_nets *net;
2626 struct sctp_status *sstat;
2628 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2629 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2632 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2636 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2637 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2638 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2639 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2641 * We can't include chunks that have been passed to
2642 * the socket layer. Only things in queue.
2644 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2645 stcb->asoc.cnt_on_all_streams);
2648 sstat->sstat_instrms = stcb->asoc.streamincnt;
2649 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2650 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2651 memcpy(&sstat->sstat_primary.spinfo_address,
2652 &stcb->asoc.primary_destination->ro._l_addr,
2653 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2654 net = stcb->asoc.primary_destination;
2655 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2657 * Again the user can get info from sctp_constants.h
2658 * for what the state of the network is.
2660 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2661 /* It's unconfirmed */
2662 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2663 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2665 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2668 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2670 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2671 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2672 sstat->sstat_primary.spinfo_rto = net->RTO;
2673 sstat->sstat_primary.spinfo_mtu = net->mtu;
2674 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2677 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2682 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2688 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2689 SCTP_TCB_UNLOCK(stcb);
2690 *optsize = sizeof(struct sctp_status);
2695 struct sctp_rtoinfo *srto;
2697 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2698 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2701 srto->srto_initial = stcb->asoc.initial_rto;
2702 srto->srto_max = stcb->asoc.maxrto;
2703 srto->srto_min = stcb->asoc.minrto;
2704 SCTP_TCB_UNLOCK(stcb);
2706 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2707 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2708 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2709 SCTP_INP_RLOCK(inp);
2710 srto->srto_initial = inp->sctp_ep.initial_rto;
2711 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2712 srto->srto_min = inp->sctp_ep.sctp_minrto;
2713 SCTP_INP_RUNLOCK(inp);
2715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2720 *optsize = sizeof(struct sctp_rtoinfo);
2726 struct sctp_timeouts *stimo;
2728 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2729 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2732 stimo->stimo_init = stcb->asoc.timoinit;
2733 stimo->stimo_data = stcb->asoc.timodata;
2734 stimo->stimo_sack = stcb->asoc.timosack;
2735 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2736 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2737 stimo->stimo_cookie = stcb->asoc.timocookie;
2738 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2739 SCTP_TCB_UNLOCK(stcb);
2740 *optsize = sizeof(struct sctp_timeouts);
2742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2747 case SCTP_ASSOCINFO:
2749 struct sctp_assocparams *sasoc;
2751 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2752 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2755 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2756 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2757 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2758 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2759 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2760 SCTP_TCB_UNLOCK(stcb);
2762 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2763 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2764 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2765 SCTP_INP_RLOCK(inp);
2766 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2767 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2768 sasoc->sasoc_number_peer_destinations = 0;
2769 sasoc->sasoc_peer_rwnd = 0;
2770 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2771 SCTP_INP_RUNLOCK(inp);
2773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2778 *optsize = sizeof(struct sctp_assocparams);
2782 case SCTP_DEFAULT_SEND_PARAM:
2784 struct sctp_sndrcvinfo *s_info;
2786 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2787 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2790 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2791 SCTP_TCB_UNLOCK(stcb);
2793 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2794 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2795 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2796 SCTP_INP_RLOCK(inp);
2797 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2798 SCTP_INP_RUNLOCK(inp);
2800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2805 *optsize = sizeof(struct sctp_sndrcvinfo);
2811 struct sctp_initmsg *sinit;
2813 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2814 SCTP_INP_RLOCK(inp);
2815 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2816 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2817 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2818 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2819 SCTP_INP_RUNLOCK(inp);
2820 *optsize = sizeof(struct sctp_initmsg);
2823 case SCTP_PRIMARY_ADDR:
2824 /* we allow a "get" operation on this */
2826 struct sctp_setprim *ssp;
2828 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2829 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2832 union sctp_sockstore *addr;
2834 addr = &stcb->asoc.primary_destination->ro._l_addr;
2835 switch (addr->sa.sa_family) {
2839 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2840 in6_sin_2_v4mapsin6(&addr->sin,
2841 (struct sockaddr_in6 *)&ssp->ssp_addr);
2843 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2846 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2852 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2858 SCTP_TCB_UNLOCK(stcb);
2859 *optsize = sizeof(struct sctp_setprim);
2861 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2866 case SCTP_HMAC_IDENT:
2868 struct sctp_hmacalgo *shmac;
2869 sctp_hmaclist_t *hmaclist;
2873 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2875 SCTP_INP_RLOCK(inp);
2876 hmaclist = inp->sctp_ep.local_hmacs;
2877 if (hmaclist == NULL) {
2878 /* no HMACs to return */
2879 *optsize = sizeof(*shmac);
2880 SCTP_INP_RUNLOCK(inp);
2883 /* is there room for all of the hmac ids? */
2884 size = sizeof(*shmac) + (hmaclist->num_algo *
2885 sizeof(shmac->shmac_idents[0]));
2886 if ((size_t)(*optsize) < size) {
2887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2889 SCTP_INP_RUNLOCK(inp);
2892 /* copy in the list */
2893 shmac->shmac_number_of_idents = hmaclist->num_algo;
2894 for (i = 0; i < hmaclist->num_algo; i++) {
2895 shmac->shmac_idents[i] = hmaclist->hmac[i];
2897 SCTP_INP_RUNLOCK(inp);
2901 case SCTP_AUTH_ACTIVE_KEY:
2903 struct sctp_authkeyid *scact;
2905 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2906 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2909 /* get the active key on the assoc */
2910 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2911 SCTP_TCB_UNLOCK(stcb);
2913 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2914 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2915 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2916 /* get the endpoint active key */
2917 SCTP_INP_RLOCK(inp);
2918 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2919 SCTP_INP_RUNLOCK(inp);
2921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2926 *optsize = sizeof(struct sctp_authkeyid);
2930 case SCTP_LOCAL_AUTH_CHUNKS:
2932 struct sctp_authchunks *sac;
2933 sctp_auth_chklist_t *chklist = NULL;
2936 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2937 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2940 /* get off the assoc */
2941 chklist = stcb->asoc.local_auth_chunks;
2942 /* is there enough space? */
2943 size = sctp_auth_get_chklist_size(chklist);
2944 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2946 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2948 /* copy in the chunks */
2949 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2950 sac->gauth_number_of_chunks = (uint32_t)size;
2951 *optsize = sizeof(struct sctp_authchunks) + size;
2953 SCTP_TCB_UNLOCK(stcb);
2955 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2956 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2957 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2958 /* get off the endpoint */
2959 SCTP_INP_RLOCK(inp);
2960 chklist = inp->sctp_ep.local_auth_chunks;
2961 /* is there enough space? */
2962 size = sctp_auth_get_chklist_size(chklist);
2963 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2967 /* copy in the chunks */
2968 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2969 sac->gauth_number_of_chunks = (uint32_t)size;
2970 *optsize = sizeof(struct sctp_authchunks) + size;
2972 SCTP_INP_RUNLOCK(inp);
2974 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2980 case SCTP_PEER_AUTH_CHUNKS:
2982 struct sctp_authchunks *sac;
2983 sctp_auth_chklist_t *chklist = NULL;
2986 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2987 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2990 /* get off the assoc */
2991 chklist = stcb->asoc.peer_auth_chunks;
2992 /* is there enough space? */
2993 size = sctp_auth_get_chklist_size(chklist);
2994 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2996 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2998 /* copy in the chunks */
2999 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3000 sac->gauth_number_of_chunks = (uint32_t)size;
3001 *optsize = sizeof(struct sctp_authchunks) + size;
3003 SCTP_TCB_UNLOCK(stcb);
3005 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3012 struct sctp_event *event;
3013 uint32_t event_type;
3015 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3016 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3018 switch (event->se_type) {
3019 case SCTP_ASSOC_CHANGE:
3020 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3022 case SCTP_PEER_ADDR_CHANGE:
3023 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3025 case SCTP_REMOTE_ERROR:
3026 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3028 case SCTP_SEND_FAILED:
3029 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3031 case SCTP_SHUTDOWN_EVENT:
3032 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3034 case SCTP_ADAPTATION_INDICATION:
3035 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3037 case SCTP_PARTIAL_DELIVERY_EVENT:
3038 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3040 case SCTP_AUTHENTICATION_EVENT:
3041 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3043 case SCTP_STREAM_RESET_EVENT:
3044 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3046 case SCTP_SENDER_DRY_EVENT:
3047 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3049 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3051 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3054 case SCTP_ASSOC_RESET_EVENT:
3055 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3057 case SCTP_STREAM_CHANGE_EVENT:
3058 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3060 case SCTP_SEND_FAILED_EVENT:
3061 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3065 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3069 if (event_type > 0) {
3071 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3073 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3074 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3075 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3076 SCTP_INP_RLOCK(inp);
3077 event->se_on = sctp_is_feature_on(inp, event_type);
3078 SCTP_INP_RUNLOCK(inp);
3080 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3086 SCTP_TCB_UNLOCK(stcb);
3089 *optsize = sizeof(struct sctp_event);
3093 case SCTP_RECVRCVINFO:
3097 if (*optsize < sizeof(int)) {
3098 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3101 SCTP_INP_RLOCK(inp);
3102 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3103 SCTP_INP_RUNLOCK(inp);
3106 /* return the option value */
3107 *(int *)optval = onoff;
3108 *optsize = sizeof(int);
3112 case SCTP_RECVNXTINFO:
3116 if (*optsize < sizeof(int)) {
3117 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3120 SCTP_INP_RLOCK(inp);
3121 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3122 SCTP_INP_RUNLOCK(inp);
3125 /* return the option value */
3126 *(int *)optval = onoff;
3127 *optsize = sizeof(int);
3131 case SCTP_DEFAULT_SNDINFO:
3133 struct sctp_sndinfo *info;
3135 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3136 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3139 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3140 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3141 info->snd_flags &= 0xfff0;
3142 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3143 info->snd_context = stcb->asoc.def_send.sinfo_context;
3144 SCTP_TCB_UNLOCK(stcb);
3146 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3147 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3148 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3149 SCTP_INP_RLOCK(inp);
3150 info->snd_sid = inp->def_send.sinfo_stream;
3151 info->snd_flags = inp->def_send.sinfo_flags;
3152 info->snd_flags &= 0xfff0;
3153 info->snd_ppid = inp->def_send.sinfo_ppid;
3154 info->snd_context = inp->def_send.sinfo_context;
3155 SCTP_INP_RUNLOCK(inp);
3157 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3162 *optsize = sizeof(struct sctp_sndinfo);
3166 case SCTP_DEFAULT_PRINFO:
3168 struct sctp_default_prinfo *info;
3170 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3171 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3174 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3175 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3176 SCTP_TCB_UNLOCK(stcb);
3178 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3179 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3180 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3181 SCTP_INP_RLOCK(inp);
3182 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3183 info->pr_value = inp->def_send.sinfo_timetolive;
3184 SCTP_INP_RUNLOCK(inp);
3186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3191 *optsize = sizeof(struct sctp_default_prinfo);
3195 case SCTP_PEER_ADDR_THLDS:
3197 struct sctp_paddrthlds *thlds;
3198 struct sctp_nets *net;
3199 struct sockaddr *addr;
3200 #if defined(INET) && defined(INET6)
3201 struct sockaddr_in sin_store;
3204 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3205 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3207 #if defined(INET) && defined(INET6)
3208 if (thlds->spt_address.ss_family == AF_INET6) {
3209 struct sockaddr_in6 *sin6;
3211 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3212 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3213 in6_sin6_2_sin(&sin_store, sin6);
3214 addr = (struct sockaddr *)&sin_store;
3216 addr = (struct sockaddr *)&thlds->spt_address;
3219 addr = (struct sockaddr *)&thlds->spt_address;
3222 addr = (struct sockaddr *)&thlds->spt_address;
3225 net = sctp_findnet(stcb, addr);
3228 * We increment here since
3229 * sctp_findassociation_ep_addr() wil do a
3230 * decrement if it finds the stcb as long as
3231 * the locked tcb (last argument) is NOT a
3235 SCTP_INP_INCR_REF(inp);
3236 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3238 SCTP_INP_DECR_REF(inp);
3241 if ((stcb != NULL) && (net == NULL)) {
3243 if (addr->sa_family == AF_INET) {
3244 struct sockaddr_in *sin;
3246 sin = (struct sockaddr_in *)addr;
3247 if (sin->sin_addr.s_addr != INADDR_ANY) {
3249 SCTP_TCB_UNLOCK(stcb);
3250 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3256 if (addr->sa_family == AF_INET6) {
3257 struct sockaddr_in6 *sin6;
3259 sin6 = (struct sockaddr_in6 *)addr;
3260 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3262 SCTP_TCB_UNLOCK(stcb);
3263 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3269 error = EAFNOSUPPORT;
3270 SCTP_TCB_UNLOCK(stcb);
3271 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3277 thlds->spt_pathmaxrxt = net->failure_threshold;
3278 thlds->spt_pathpfthld = net->pf_threshold;
3279 thlds->spt_pathcpthld = 0xffff;
3281 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3282 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3283 thlds->spt_pathcpthld = 0xffff;
3285 thlds->spt_assoc_id = sctp_get_associd(stcb);
3286 SCTP_TCB_UNLOCK(stcb);
3288 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3289 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3290 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3291 /* Use endpoint defaults */
3292 SCTP_INP_RLOCK(inp);
3293 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3294 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3295 thlds->spt_pathcpthld = 0xffff;
3296 SCTP_INP_RUNLOCK(inp);
3298 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3303 *optsize = sizeof(struct sctp_paddrthlds);
3307 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3309 struct sctp_udpencaps *encaps;
3310 struct sctp_nets *net;
3311 struct sockaddr *addr;
3312 #if defined(INET) && defined(INET6)
3313 struct sockaddr_in sin_store;
3316 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3317 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3319 #if defined(INET) && defined(INET6)
3320 if (encaps->sue_address.ss_family == AF_INET6) {
3321 struct sockaddr_in6 *sin6;
3323 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3324 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3325 in6_sin6_2_sin(&sin_store, sin6);
3326 addr = (struct sockaddr *)&sin_store;
3328 addr = (struct sockaddr *)&encaps->sue_address;
3331 addr = (struct sockaddr *)&encaps->sue_address;
3334 addr = (struct sockaddr *)&encaps->sue_address;
3337 net = sctp_findnet(stcb, addr);
3340 * We increment here since
3341 * sctp_findassociation_ep_addr() wil do a
3342 * decrement if it finds the stcb as long as
3343 * the locked tcb (last argument) is NOT a
3347 SCTP_INP_INCR_REF(inp);
3348 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3350 SCTP_INP_DECR_REF(inp);
3353 if ((stcb != NULL) && (net == NULL)) {
3355 if (addr->sa_family == AF_INET) {
3356 struct sockaddr_in *sin;
3358 sin = (struct sockaddr_in *)addr;
3359 if (sin->sin_addr.s_addr != INADDR_ANY) {
3361 SCTP_TCB_UNLOCK(stcb);
3362 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3368 if (addr->sa_family == AF_INET6) {
3369 struct sockaddr_in6 *sin6;
3371 sin6 = (struct sockaddr_in6 *)addr;
3372 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3374 SCTP_TCB_UNLOCK(stcb);
3375 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3381 error = EAFNOSUPPORT;
3382 SCTP_TCB_UNLOCK(stcb);
3383 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3389 encaps->sue_port = net->port;
3391 encaps->sue_port = stcb->asoc.port;
3393 SCTP_TCB_UNLOCK(stcb);
3395 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3396 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3397 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3398 SCTP_INP_RLOCK(inp);
3399 encaps->sue_port = inp->sctp_ep.port;
3400 SCTP_INP_RUNLOCK(inp);
3402 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3407 *optsize = sizeof(struct sctp_udpencaps);
3411 case SCTP_ECN_SUPPORTED:
3413 struct sctp_assoc_value *av;
3415 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3416 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3419 av->assoc_value = stcb->asoc.ecn_supported;
3420 SCTP_TCB_UNLOCK(stcb);
3422 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3423 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3424 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3425 SCTP_INP_RLOCK(inp);
3426 av->assoc_value = inp->ecn_supported;
3427 SCTP_INP_RUNLOCK(inp);
3429 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3434 *optsize = sizeof(struct sctp_assoc_value);
3438 case SCTP_PR_SUPPORTED:
3440 struct sctp_assoc_value *av;
3442 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3443 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3446 av->assoc_value = stcb->asoc.prsctp_supported;
3447 SCTP_TCB_UNLOCK(stcb);
3449 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3450 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3451 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3452 SCTP_INP_RLOCK(inp);
3453 av->assoc_value = inp->prsctp_supported;
3454 SCTP_INP_RUNLOCK(inp);
3456 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3461 *optsize = sizeof(struct sctp_assoc_value);
3465 case SCTP_AUTH_SUPPORTED:
3467 struct sctp_assoc_value *av;
3469 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3470 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3473 av->assoc_value = stcb->asoc.auth_supported;
3474 SCTP_TCB_UNLOCK(stcb);
3476 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3477 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3478 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3479 SCTP_INP_RLOCK(inp);
3480 av->assoc_value = inp->auth_supported;
3481 SCTP_INP_RUNLOCK(inp);
3483 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3488 *optsize = sizeof(struct sctp_assoc_value);
3492 case SCTP_ASCONF_SUPPORTED:
3494 struct sctp_assoc_value *av;
3496 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3497 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3500 av->assoc_value = stcb->asoc.asconf_supported;
3501 SCTP_TCB_UNLOCK(stcb);
3503 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3504 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3505 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3506 SCTP_INP_RLOCK(inp);
3507 av->assoc_value = inp->asconf_supported;
3508 SCTP_INP_RUNLOCK(inp);
3510 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3515 *optsize = sizeof(struct sctp_assoc_value);
3519 case SCTP_RECONFIG_SUPPORTED:
3521 struct sctp_assoc_value *av;
3523 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3524 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3527 av->assoc_value = stcb->asoc.reconfig_supported;
3528 SCTP_TCB_UNLOCK(stcb);
3530 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3531 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3532 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3533 SCTP_INP_RLOCK(inp);
3534 av->assoc_value = inp->reconfig_supported;
3535 SCTP_INP_RUNLOCK(inp);
3537 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3542 *optsize = sizeof(struct sctp_assoc_value);
3546 case SCTP_NRSACK_SUPPORTED:
3548 struct sctp_assoc_value *av;
3550 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3551 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3554 av->assoc_value = stcb->asoc.nrsack_supported;
3555 SCTP_TCB_UNLOCK(stcb);
3557 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3558 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3559 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3560 SCTP_INP_RLOCK(inp);
3561 av->assoc_value = inp->nrsack_supported;
3562 SCTP_INP_RUNLOCK(inp);
3564 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3569 *optsize = sizeof(struct sctp_assoc_value);
3573 case SCTP_PKTDROP_SUPPORTED:
3575 struct sctp_assoc_value *av;
3577 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3578 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3581 av->assoc_value = stcb->asoc.pktdrop_supported;
3582 SCTP_TCB_UNLOCK(stcb);
3584 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3585 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3586 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3587 SCTP_INP_RLOCK(inp);
3588 av->assoc_value = inp->pktdrop_supported;
3589 SCTP_INP_RUNLOCK(inp);
3591 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3596 *optsize = sizeof(struct sctp_assoc_value);
3600 case SCTP_ENABLE_STREAM_RESET:
3602 struct sctp_assoc_value *av;
3604 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3605 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3608 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3609 SCTP_TCB_UNLOCK(stcb);
3611 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3612 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3613 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3614 SCTP_INP_RLOCK(inp);
3615 av->assoc_value = (uint32_t)inp->local_strreset_support;
3616 SCTP_INP_RUNLOCK(inp);
3618 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3623 *optsize = sizeof(struct sctp_assoc_value);
3627 case SCTP_PR_STREAM_STATUS:
3629 struct sctp_prstatus *sprstat;
3633 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3634 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3636 sid = sprstat->sprstat_sid;
3637 policy = sprstat->sprstat_policy;
3638 #if defined(SCTP_DETAILED_STR_STATS)
3639 if ((stcb != NULL) &&
3640 (sid < stcb->asoc.streamoutcnt) &&
3641 (policy != SCTP_PR_SCTP_NONE) &&
3642 ((policy <= SCTP_PR_SCTP_MAX) ||
3643 (policy == SCTP_PR_SCTP_ALL))) {
3644 if (policy == SCTP_PR_SCTP_ALL) {
3645 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3646 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3648 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3649 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3652 if ((stcb != NULL) &&
3653 (sid < stcb->asoc.streamoutcnt) &&
3654 (policy == SCTP_PR_SCTP_ALL)) {
3655 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3656 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3659 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3663 SCTP_TCB_UNLOCK(stcb);
3666 *optsize = sizeof(struct sctp_prstatus);
3670 case SCTP_PR_ASSOC_STATUS:
3672 struct sctp_prstatus *sprstat;
3675 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3676 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3678 policy = sprstat->sprstat_policy;
3679 if ((stcb != NULL) &&
3680 (policy != SCTP_PR_SCTP_NONE) &&
3681 ((policy <= SCTP_PR_SCTP_MAX) ||
3682 (policy == SCTP_PR_SCTP_ALL))) {
3683 if (policy == SCTP_PR_SCTP_ALL) {
3684 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3685 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3687 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3688 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3695 SCTP_TCB_UNLOCK(stcb);
3698 *optsize = sizeof(struct sctp_prstatus);
3704 struct sctp_assoc_value *av;
3706 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3707 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3710 av->assoc_value = stcb->asoc.max_cwnd;
3711 SCTP_TCB_UNLOCK(stcb);
3713 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3714 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3715 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3716 SCTP_INP_RLOCK(inp);
3717 av->assoc_value = inp->max_cwnd;
3718 SCTP_INP_RUNLOCK(inp);
3720 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3725 *optsize = sizeof(struct sctp_assoc_value);
3730 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3731 error = ENOPROTOOPT;
3733 } /* end switch (sopt->sopt_name) */
3741 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3746 struct sctp_tcb *stcb = NULL;
3747 struct sctp_inpcb *inp = NULL;
3750 if (optval == NULL) {
3751 SCTP_PRINTF("optval is NULL\n");
3752 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3755 inp = (struct sctp_inpcb *)so->so_pcb;
3757 SCTP_PRINTF("inp is NULL?\n");
3758 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3761 vrf_id = inp->def_vrf_id;
3766 case SCTP_AUTOCLOSE:
3767 case SCTP_AUTO_ASCONF:
3768 case SCTP_EXPLICIT_EOR:
3769 case SCTP_DISABLE_FRAGMENTS:
3770 case SCTP_USE_EXT_RCVINFO:
3771 case SCTP_I_WANT_MAPPED_V4_ADDR:
3772 /* copy in the option value */
3773 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3778 case SCTP_DISABLE_FRAGMENTS:
3779 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3781 case SCTP_AUTO_ASCONF:
3783 * NOTE: we don't really support this flag
3785 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3786 /* only valid for bound all sockets */
3787 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3789 /* forbidden by admin */
3790 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3793 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3799 case SCTP_EXPLICIT_EOR:
3800 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3802 case SCTP_USE_EXT_RCVINFO:
3803 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3805 case SCTP_I_WANT_MAPPED_V4_ADDR:
3806 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3807 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3809 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3814 set_opt = SCTP_PCB_FLAGS_NODELAY;
3816 case SCTP_AUTOCLOSE:
3817 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3818 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3819 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3822 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3824 * The value is in ticks. Note this does not effect
3825 * old associations, only new ones.
3827 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3830 SCTP_INP_WLOCK(inp);
3832 sctp_feature_on(inp, set_opt);
3834 sctp_feature_off(inp, set_opt);
3836 SCTP_INP_WUNLOCK(inp);
3838 case SCTP_REUSE_PORT:
3840 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3841 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3842 /* Can't set it after we are bound */
3846 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3847 /* Can't do this for a 1-m socket */
3852 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3854 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3857 case SCTP_PARTIAL_DELIVERY_POINT:
3861 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3862 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3863 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3867 inp->partial_delivery_point = *value;
3870 case SCTP_FRAGMENT_INTERLEAVE:
3871 /* not yet until we re-write sctp_recvmsg() */
3875 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3876 if (*level == SCTP_FRAG_LEVEL_2) {
3877 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3878 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3879 } else if (*level == SCTP_FRAG_LEVEL_1) {
3880 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3881 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3882 } else if (*level == SCTP_FRAG_LEVEL_0) {
3883 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3884 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3892 case SCTP_INTERLEAVING_SUPPORTED:
3894 struct sctp_assoc_value *av;
3896 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3897 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3900 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3902 SCTP_TCB_UNLOCK(stcb);
3904 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3905 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3906 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3907 SCTP_INP_WLOCK(inp);
3908 if (av->assoc_value == 0) {
3909 inp->idata_supported = 0;
3911 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3912 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3913 inp->idata_supported = 1;
3921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3925 SCTP_INP_WUNLOCK(inp);
3927 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3933 case SCTP_CMT_ON_OFF:
3934 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3935 struct sctp_assoc_value *av;
3937 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3938 if (av->assoc_value > SCTP_CMT_MAX) {
3939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3943 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3945 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3946 SCTP_TCB_UNLOCK(stcb);
3948 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3949 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3950 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3951 (av->assoc_id == SCTP_ALL_ASSOC)) {
3952 SCTP_INP_WLOCK(inp);
3953 inp->sctp_cmt_on_off = av->assoc_value;
3954 SCTP_INP_WUNLOCK(inp);
3956 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3957 (av->assoc_id == SCTP_ALL_ASSOC)) {
3958 SCTP_INP_RLOCK(inp);
3959 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3960 SCTP_TCB_LOCK(stcb);
3961 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3962 SCTP_TCB_UNLOCK(stcb);
3964 SCTP_INP_RUNLOCK(inp);
3968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3969 error = ENOPROTOOPT;
3972 case SCTP_PLUGGABLE_CC:
3974 struct sctp_assoc_value *av;
3975 struct sctp_nets *net;
3977 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3978 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3979 (av->assoc_value != SCTP_CC_HSTCP) &&
3980 (av->assoc_value != SCTP_CC_HTCP) &&
3981 (av->assoc_value != SCTP_CC_RTCC)) {
3982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3986 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3988 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3989 stcb->asoc.congestion_control_module = av->assoc_value;
3990 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3991 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3992 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3995 SCTP_TCB_UNLOCK(stcb);
3997 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3998 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3999 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4000 (av->assoc_id == SCTP_ALL_ASSOC)) {
4001 SCTP_INP_WLOCK(inp);
4002 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
4003 SCTP_INP_WUNLOCK(inp);
4005 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4006 (av->assoc_id == SCTP_ALL_ASSOC)) {
4007 SCTP_INP_RLOCK(inp);
4008 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4009 SCTP_TCB_LOCK(stcb);
4010 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4011 stcb->asoc.congestion_control_module = av->assoc_value;
4012 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4013 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4014 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4017 SCTP_TCB_UNLOCK(stcb);
4019 SCTP_INP_RUNLOCK(inp);
4024 case SCTP_CC_OPTION:
4026 struct sctp_cc_option *cc_opt;
4028 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4029 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4031 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4032 SCTP_INP_RLOCK(inp);
4033 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4034 SCTP_TCB_LOCK(stcb);
4035 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4036 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4038 SCTP_TCB_UNLOCK(stcb);
4040 SCTP_INP_RUNLOCK(inp);
4045 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4048 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4051 SCTP_TCB_UNLOCK(stcb);
4055 case SCTP_PLUGGABLE_SS:
4057 struct sctp_assoc_value *av;
4059 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4060 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4061 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4062 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4063 (av->assoc_value != SCTP_SS_PRIORITY) &&
4064 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4065 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4066 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4070 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4072 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4073 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4074 stcb->asoc.stream_scheduling_module = av->assoc_value;
4075 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4076 SCTP_TCB_UNLOCK(stcb);
4078 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4079 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4080 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4081 (av->assoc_id == SCTP_ALL_ASSOC)) {
4082 SCTP_INP_WLOCK(inp);
4083 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4084 SCTP_INP_WUNLOCK(inp);
4086 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4087 (av->assoc_id == SCTP_ALL_ASSOC)) {
4088 SCTP_INP_RLOCK(inp);
4089 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4090 SCTP_TCB_LOCK(stcb);
4091 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4092 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4093 stcb->asoc.stream_scheduling_module = av->assoc_value;
4094 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4095 SCTP_TCB_UNLOCK(stcb);
4097 SCTP_INP_RUNLOCK(inp);
4104 struct sctp_stream_value *av;
4106 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4107 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4109 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4110 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4111 av->stream_value) < 0)) {
4112 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4115 SCTP_TCB_UNLOCK(stcb);
4117 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4118 SCTP_INP_RLOCK(inp);
4119 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4120 SCTP_TCB_LOCK(stcb);
4121 if (av->stream_id < stcb->asoc.streamoutcnt) {
4122 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4124 &stcb->asoc.strmout[av->stream_id],
4127 SCTP_TCB_UNLOCK(stcb);
4129 SCTP_INP_RUNLOCK(inp);
4132 * Can't set stream value without
4135 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4141 case SCTP_CLR_STAT_LOG:
4142 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4147 struct sctp_assoc_value *av;
4149 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4150 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4153 stcb->asoc.context = av->assoc_value;
4154 SCTP_TCB_UNLOCK(stcb);
4156 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4157 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4158 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4159 (av->assoc_id == SCTP_ALL_ASSOC)) {
4160 SCTP_INP_WLOCK(inp);
4161 inp->sctp_context = av->assoc_value;
4162 SCTP_INP_WUNLOCK(inp);
4164 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4165 (av->assoc_id == SCTP_ALL_ASSOC)) {
4166 SCTP_INP_RLOCK(inp);
4167 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4168 SCTP_TCB_LOCK(stcb);
4169 stcb->asoc.context = av->assoc_value;
4170 SCTP_TCB_UNLOCK(stcb);
4172 SCTP_INP_RUNLOCK(inp);
4179 uint32_t *default_vrfid;
4181 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4182 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4183 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4187 inp->def_vrf_id = *default_vrfid;
4190 case SCTP_DEL_VRF_ID:
4192 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4196 case SCTP_ADD_VRF_ID:
4198 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4202 case SCTP_DELAYED_SACK:
4204 struct sctp_sack_info *sack;
4206 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4207 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4208 if (sack->sack_delay) {
4209 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4210 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4211 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4212 sack->sack_delay = TICKS_TO_MSEC(1);
4216 if (sack->sack_delay) {
4217 stcb->asoc.delayed_ack = sack->sack_delay;
4219 if (sack->sack_freq) {
4220 stcb->asoc.sack_freq = sack->sack_freq;
4222 SCTP_TCB_UNLOCK(stcb);
4224 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4225 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4226 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4227 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4228 SCTP_INP_WLOCK(inp);
4229 if (sack->sack_delay) {
4230 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4232 if (sack->sack_freq) {
4233 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4235 SCTP_INP_WUNLOCK(inp);
4237 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4238 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4239 SCTP_INP_RLOCK(inp);
4240 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4241 SCTP_TCB_LOCK(stcb);
4242 if (sack->sack_delay) {
4243 stcb->asoc.delayed_ack = sack->sack_delay;
4245 if (sack->sack_freq) {
4246 stcb->asoc.sack_freq = sack->sack_freq;
4248 SCTP_TCB_UNLOCK(stcb);
4250 SCTP_INP_RUNLOCK(inp);
4255 case SCTP_AUTH_CHUNK:
4257 struct sctp_authchunk *sauth;
4259 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4261 SCTP_INP_WLOCK(inp);
4262 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4263 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4266 SCTP_INP_WUNLOCK(inp);
4271 struct sctp_authkey *sca;
4272 struct sctp_keyhead *shared_keys;
4273 sctp_sharedkey_t *shared_key;
4274 sctp_key_t *key = NULL;
4277 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4278 if (sca->sca_keylength == 0) {
4279 size = optsize - sizeof(struct sctp_authkey);
4281 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4282 size = sca->sca_keylength;
4284 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4289 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4292 shared_keys = &stcb->asoc.shared_keys;
4293 /* clear the cached keys for this key id */
4294 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4296 * create the new shared key and
4300 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4302 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4304 SCTP_TCB_UNLOCK(stcb);
4308 shared_key = sctp_alloc_sharedkey();
4309 if (shared_key == NULL) {
4311 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4313 SCTP_TCB_UNLOCK(stcb);
4316 shared_key->key = key;
4317 shared_key->keyid = sca->sca_keynumber;
4318 error = sctp_insert_sharedkey(shared_keys, shared_key);
4319 SCTP_TCB_UNLOCK(stcb);
4321 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4322 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4323 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4324 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4325 SCTP_INP_WLOCK(inp);
4326 shared_keys = &inp->sctp_ep.shared_keys;
4328 * clear the cached keys on all
4329 * assocs for this key id
4331 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4333 * create the new shared key and
4337 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4339 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4341 SCTP_INP_WUNLOCK(inp);
4345 shared_key = sctp_alloc_sharedkey();
4346 if (shared_key == NULL) {
4348 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4350 SCTP_INP_WUNLOCK(inp);
4353 shared_key->key = key;
4354 shared_key->keyid = sca->sca_keynumber;
4355 error = sctp_insert_sharedkey(shared_keys, shared_key);
4356 SCTP_INP_WUNLOCK(inp);
4358 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4359 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4360 SCTP_INP_RLOCK(inp);
4361 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4362 SCTP_TCB_LOCK(stcb);
4363 shared_keys = &stcb->asoc.shared_keys;
4365 * clear the cached keys for
4368 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4370 * create the new shared key
4371 * and insert/replace it
4374 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4376 SCTP_TCB_UNLOCK(stcb);
4380 shared_key = sctp_alloc_sharedkey();
4381 if (shared_key == NULL) {
4383 SCTP_TCB_UNLOCK(stcb);
4386 shared_key->key = key;
4387 shared_key->keyid = sca->sca_keynumber;
4388 error = sctp_insert_sharedkey(shared_keys, shared_key);
4389 SCTP_TCB_UNLOCK(stcb);
4391 SCTP_INP_RUNLOCK(inp);
4396 case SCTP_HMAC_IDENT:
4398 struct sctp_hmacalgo *shmac;
4399 sctp_hmaclist_t *hmaclist;
4403 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4404 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4405 (shmac->shmac_number_of_idents > 0xffff)) {
4406 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4410 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4411 if (hmaclist == NULL) {
4412 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4416 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4417 hmacid = shmac->shmac_idents[i];
4418 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4419 /* invalid HMACs were found */ ;
4420 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4422 sctp_free_hmaclist(hmaclist);
4423 goto sctp_set_hmac_done;
4426 for (i = 0; i < hmaclist->num_algo; i++) {
4427 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4428 /* already in list */
4432 if (i == hmaclist->num_algo) {
4433 /* not found in list */
4434 sctp_free_hmaclist(hmaclist);
4435 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4439 /* set it on the endpoint */
4440 SCTP_INP_WLOCK(inp);
4441 if (inp->sctp_ep.local_hmacs)
4442 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4443 inp->sctp_ep.local_hmacs = hmaclist;
4444 SCTP_INP_WUNLOCK(inp);
4448 case SCTP_AUTH_ACTIVE_KEY:
4450 struct sctp_authkeyid *scact;
4452 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4453 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4455 /* set the active key on the right place */
4457 /* set the active key on the assoc */
4458 if (sctp_auth_setactivekey(stcb,
4459 scact->scact_keynumber)) {
4460 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4461 SCTP_FROM_SCTP_USRREQ,
4465 SCTP_TCB_UNLOCK(stcb);
4467 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4468 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4469 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4470 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4471 SCTP_INP_WLOCK(inp);
4472 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4473 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4476 SCTP_INP_WUNLOCK(inp);
4478 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4479 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4480 SCTP_INP_RLOCK(inp);
4481 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4482 SCTP_TCB_LOCK(stcb);
4483 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4484 SCTP_TCB_UNLOCK(stcb);
4486 SCTP_INP_RUNLOCK(inp);
4491 case SCTP_AUTH_DELETE_KEY:
4493 struct sctp_authkeyid *scdel;
4495 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4496 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4498 /* delete the key from the right place */
4500 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4501 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4504 SCTP_TCB_UNLOCK(stcb);
4506 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4507 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4508 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4509 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4510 SCTP_INP_WLOCK(inp);
4511 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4515 SCTP_INP_WUNLOCK(inp);
4517 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4518 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4519 SCTP_INP_RLOCK(inp);
4520 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4521 SCTP_TCB_LOCK(stcb);
4522 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4523 SCTP_TCB_UNLOCK(stcb);
4525 SCTP_INP_RUNLOCK(inp);
4530 case SCTP_AUTH_DEACTIVATE_KEY:
4532 struct sctp_authkeyid *keyid;
4534 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4535 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4537 /* deactivate the key from the right place */
4539 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4540 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4543 SCTP_TCB_UNLOCK(stcb);
4545 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4546 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4547 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4548 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4549 SCTP_INP_WLOCK(inp);
4550 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4551 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4554 SCTP_INP_WUNLOCK(inp);
4556 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4557 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4558 SCTP_INP_RLOCK(inp);
4559 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4560 SCTP_TCB_LOCK(stcb);
4561 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4562 SCTP_TCB_UNLOCK(stcb);
4564 SCTP_INP_RUNLOCK(inp);
4569 case SCTP_ENABLE_STREAM_RESET:
4571 struct sctp_assoc_value *av;
4573 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4574 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4575 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4579 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4581 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4582 SCTP_TCB_UNLOCK(stcb);
4584 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4585 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4586 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4587 (av->assoc_id == SCTP_ALL_ASSOC)) {
4588 SCTP_INP_WLOCK(inp);
4589 inp->local_strreset_support = (uint8_t)av->assoc_value;
4590 SCTP_INP_WUNLOCK(inp);
4592 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4593 (av->assoc_id == SCTP_ALL_ASSOC)) {
4594 SCTP_INP_RLOCK(inp);
4595 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4596 SCTP_TCB_LOCK(stcb);
4597 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4598 SCTP_TCB_UNLOCK(stcb);
4600 SCTP_INP_RUNLOCK(inp);
4605 case SCTP_RESET_STREAMS:
4607 struct sctp_reset_streams *strrst;
4608 int i, send_out = 0;
4611 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4612 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4614 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4618 if (stcb->asoc.reconfig_supported == 0) {
4620 * Peer does not support the chunk type.
4622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4624 SCTP_TCB_UNLOCK(stcb);
4627 if (sizeof(struct sctp_reset_streams) +
4628 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4630 SCTP_TCB_UNLOCK(stcb);
4633 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4635 if (stcb->asoc.stream_reset_outstanding) {
4636 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4638 SCTP_TCB_UNLOCK(stcb);
4642 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4645 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4646 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4648 SCTP_TCB_UNLOCK(stcb);
4651 if ((send_in == 0) && (send_out == 0)) {
4652 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4654 SCTP_TCB_UNLOCK(stcb);
4657 for (i = 0; i < strrst->srs_number_streams; i++) {
4659 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4665 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4672 SCTP_TCB_UNLOCK(stcb);
4679 if (strrst->srs_number_streams) {
4680 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4681 strm = strrst->srs_stream_list[i];
4682 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4683 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4689 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4690 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4691 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4698 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4699 strrst->srs_stream_list,
4700 send_in, 0, 0, 0, 0, 0);
4702 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4705 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4708 * For outgoing streams don't report any
4709 * problems in sending the request to the
4710 * application. XXX: Double check resetting
4715 SCTP_TCB_UNLOCK(stcb);
4718 case SCTP_ADD_STREAMS:
4720 struct sctp_add_streams *stradd;
4721 uint8_t addstream = 0;
4722 uint16_t add_o_strmcnt = 0;
4723 uint16_t add_i_strmcnt = 0;
4725 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4726 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4728 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4732 if (stcb->asoc.reconfig_supported == 0) {
4734 * Peer does not support the chunk type.
4736 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4738 SCTP_TCB_UNLOCK(stcb);
4741 if (stcb->asoc.stream_reset_outstanding) {
4742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4744 SCTP_TCB_UNLOCK(stcb);
4747 if ((stradd->sas_outstrms == 0) &&
4748 (stradd->sas_instrms == 0)) {
4752 if (stradd->sas_outstrms) {
4754 /* We allocate here */
4755 add_o_strmcnt = stradd->sas_outstrms;
4756 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4757 /* You can't have more than 64k */
4762 if (stradd->sas_instrms) {
4767 * We allocate inside
4768 * sctp_send_str_reset_req()
4770 add_i_strmcnt = stradd->sas_instrms;
4771 cnt = add_i_strmcnt;
4772 cnt += stcb->asoc.streamincnt;
4773 if (cnt > 0x0000ffff) {
4774 /* You can't have more than 64k */
4778 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4779 /* More than you are allowed */
4784 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4785 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4787 SCTP_TCB_UNLOCK(stcb);
4790 case SCTP_RESET_ASSOC:
4795 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4796 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4798 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4802 if (stcb->asoc.reconfig_supported == 0) {
4804 * Peer does not support the chunk type.
4806 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4808 SCTP_TCB_UNLOCK(stcb);
4811 if (stcb->asoc.stream_reset_outstanding) {
4812 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4814 SCTP_TCB_UNLOCK(stcb);
4818 * Is there any data pending in the send or sent
4821 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4822 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4825 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4826 SCTP_TCB_UNLOCK(stcb);
4829 /* Do any streams have data queued? */
4830 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4831 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4835 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4836 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4837 SCTP_TCB_UNLOCK(stcb);
4840 case SCTP_CONNECT_X:
4841 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4842 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4846 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4848 case SCTP_CONNECT_X_DELAYED:
4849 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4850 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4854 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4856 case SCTP_CONNECT_X_COMPLETE:
4858 struct sockaddr *sa;
4860 /* FIXME MT: check correct? */
4861 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4864 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4865 SCTP_INP_RLOCK(inp);
4866 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4868 SCTP_TCB_LOCK(stcb);
4870 SCTP_INP_RUNLOCK(inp);
4873 * We increment here since
4874 * sctp_findassociation_ep_addr() wil do a
4875 * decrement if it finds the stcb as long as
4876 * the locked tcb (last argument) is NOT a
4879 SCTP_INP_INCR_REF(inp);
4880 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4882 SCTP_INP_DECR_REF(inp);
4887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4891 if (stcb->asoc.delayed_connection == 1) {
4892 stcb->asoc.delayed_connection = 0;
4893 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4894 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4895 stcb->asoc.primary_destination,
4896 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4897 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4900 * already expired or did not use delayed
4903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4906 SCTP_TCB_UNLOCK(stcb);
4909 case SCTP_MAX_BURST:
4911 struct sctp_assoc_value *av;
4913 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4914 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4917 stcb->asoc.max_burst = av->assoc_value;
4918 SCTP_TCB_UNLOCK(stcb);
4920 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4921 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4922 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4923 (av->assoc_id == SCTP_ALL_ASSOC)) {
4924 SCTP_INP_WLOCK(inp);
4925 inp->sctp_ep.max_burst = av->assoc_value;
4926 SCTP_INP_WUNLOCK(inp);
4928 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4929 (av->assoc_id == SCTP_ALL_ASSOC)) {
4930 SCTP_INP_RLOCK(inp);
4931 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4932 SCTP_TCB_LOCK(stcb);
4933 stcb->asoc.max_burst = av->assoc_value;
4934 SCTP_TCB_UNLOCK(stcb);
4936 SCTP_INP_RUNLOCK(inp);
4943 struct sctp_assoc_value *av;
4946 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4947 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4949 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4950 ovh = SCTP_MED_OVERHEAD;
4952 ovh = SCTP_MED_V4_OVERHEAD;
4955 if (av->assoc_value) {
4956 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4958 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4960 SCTP_TCB_UNLOCK(stcb);
4962 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4963 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4964 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4965 SCTP_INP_WLOCK(inp);
4967 * FIXME MT: I think this is not in
4968 * tune with the API ID
4970 if (av->assoc_value) {
4971 inp->sctp_frag_point = (av->assoc_value + ovh);
4973 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4975 SCTP_INP_WUNLOCK(inp);
4977 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4985 struct sctp_event_subscribe *events;
4987 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4989 SCTP_INP_WLOCK(inp);
4990 if (events->sctp_data_io_event) {
4991 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4993 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4996 if (events->sctp_association_event) {
4997 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4999 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5002 if (events->sctp_address_event) {
5003 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5005 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5008 if (events->sctp_send_failure_event) {
5009 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5011 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5014 if (events->sctp_peer_error_event) {
5015 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5017 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5020 if (events->sctp_shutdown_event) {
5021 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5023 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5026 if (events->sctp_partial_delivery_event) {
5027 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5029 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5032 if (events->sctp_adaptation_layer_event) {
5033 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5035 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5038 if (events->sctp_authentication_event) {
5039 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5041 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5044 if (events->sctp_sender_dry_event) {
5045 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5047 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5050 if (events->sctp_stream_reset_event) {
5051 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5053 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5055 SCTP_INP_WUNLOCK(inp);
5057 SCTP_INP_RLOCK(inp);
5058 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5059 SCTP_TCB_LOCK(stcb);
5060 if (events->sctp_association_event) {
5061 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5063 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5065 if (events->sctp_address_event) {
5066 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5068 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5070 if (events->sctp_send_failure_event) {
5071 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5073 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5075 if (events->sctp_peer_error_event) {
5076 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5078 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5080 if (events->sctp_shutdown_event) {
5081 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5083 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5085 if (events->sctp_partial_delivery_event) {
5086 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5088 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5090 if (events->sctp_adaptation_layer_event) {
5091 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5093 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5095 if (events->sctp_authentication_event) {
5096 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5098 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5100 if (events->sctp_sender_dry_event) {
5101 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5103 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5105 if (events->sctp_stream_reset_event) {
5106 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5108 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5110 SCTP_TCB_UNLOCK(stcb);
5113 * Send up the sender dry event only for 1-to-1
5116 if (events->sctp_sender_dry_event) {
5117 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5118 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5119 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5121 SCTP_TCB_LOCK(stcb);
5122 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5123 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5124 (stcb->asoc.stream_queue_cnt == 0)) {
5125 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5127 SCTP_TCB_UNLOCK(stcb);
5131 SCTP_INP_RUNLOCK(inp);
5134 case SCTP_ADAPTATION_LAYER:
5136 struct sctp_setadaptation *adap_bits;
5138 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5139 SCTP_INP_WLOCK(inp);
5140 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5141 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5142 SCTP_INP_WUNLOCK(inp);
5146 case SCTP_SET_INITIAL_DBG_SEQ:
5150 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5151 SCTP_INP_WLOCK(inp);
5152 inp->sctp_ep.initial_sequence_debug = *vvv;
5153 SCTP_INP_WUNLOCK(inp);
5157 case SCTP_DEFAULT_SEND_PARAM:
5159 struct sctp_sndrcvinfo *s_info;
5161 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5162 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5165 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5166 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5168 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5171 SCTP_TCB_UNLOCK(stcb);
5173 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5174 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5175 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5176 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5177 SCTP_INP_WLOCK(inp);
5178 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5179 SCTP_INP_WUNLOCK(inp);
5181 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5182 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5183 SCTP_INP_RLOCK(inp);
5184 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5185 SCTP_TCB_LOCK(stcb);
5186 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5187 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5189 SCTP_TCB_UNLOCK(stcb);
5191 SCTP_INP_RUNLOCK(inp);
5196 case SCTP_PEER_ADDR_PARAMS:
5198 struct sctp_paddrparams *paddrp;
5199 struct sctp_nets *net;
5200 struct sockaddr *addr;
5201 #if defined(INET) && defined(INET6)
5202 struct sockaddr_in sin_store;
5205 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5206 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5208 #if defined(INET) && defined(INET6)
5209 if (paddrp->spp_address.ss_family == AF_INET6) {
5210 struct sockaddr_in6 *sin6;
5212 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5213 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5214 in6_sin6_2_sin(&sin_store, sin6);
5215 addr = (struct sockaddr *)&sin_store;
5217 addr = (struct sockaddr *)&paddrp->spp_address;
5220 addr = (struct sockaddr *)&paddrp->spp_address;
5223 addr = (struct sockaddr *)&paddrp->spp_address;
5226 net = sctp_findnet(stcb, addr);
5229 * We increment here since
5230 * sctp_findassociation_ep_addr() wil do a
5231 * decrement if it finds the stcb as long as
5232 * the locked tcb (last argument) is NOT a
5236 SCTP_INP_INCR_REF(inp);
5237 stcb = sctp_findassociation_ep_addr(&inp, addr,
5240 SCTP_INP_DECR_REF(inp);
5243 if ((stcb != NULL) && (net == NULL)) {
5245 if (addr->sa_family == AF_INET) {
5247 struct sockaddr_in *sin;
5249 sin = (struct sockaddr_in *)addr;
5250 if (sin->sin_addr.s_addr != INADDR_ANY) {
5251 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5252 SCTP_TCB_UNLOCK(stcb);
5259 if (addr->sa_family == AF_INET6) {
5260 struct sockaddr_in6 *sin6;
5262 sin6 = (struct sockaddr_in6 *)addr;
5263 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5264 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5265 SCTP_TCB_UNLOCK(stcb);
5272 error = EAFNOSUPPORT;
5273 SCTP_TCB_UNLOCK(stcb);
5274 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5279 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5281 SCTP_TCB_UNLOCK(stcb);
5282 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5285 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5287 SCTP_TCB_UNLOCK(stcb);
5288 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5292 /************************TCB SPECIFIC SET ******************/
5294 /************************NET SPECIFIC SET ******************/
5295 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5296 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5297 !(net->dest_state & SCTP_ADDR_NOHB)) {
5298 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5299 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5301 net->dest_state |= SCTP_ADDR_NOHB;
5303 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5304 if (paddrp->spp_hbinterval) {
5305 net->heart_beat_delay = paddrp->spp_hbinterval;
5306 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5307 net->heart_beat_delay = 0;
5309 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5310 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5311 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5312 net->dest_state &= ~SCTP_ADDR_NOHB;
5314 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5316 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5317 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5318 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5320 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5321 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5322 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5323 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5325 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5326 net->mtu = paddrp->spp_pathmtu;
5327 switch (net->ro._l_addr.sa.sa_family) {
5330 net->mtu += SCTP_MIN_V4_OVERHEAD;
5335 net->mtu += SCTP_MIN_OVERHEAD;
5341 if (net->mtu < stcb->asoc.smallest_mtu) {
5342 sctp_pathmtu_adjustment(stcb, net->mtu);
5345 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5346 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5347 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5349 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5351 if (paddrp->spp_pathmaxrxt) {
5352 if (net->dest_state & SCTP_ADDR_PF) {
5353 if (net->error_count > paddrp->spp_pathmaxrxt) {
5354 net->dest_state &= ~SCTP_ADDR_PF;
5357 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5358 (net->error_count > net->pf_threshold)) {
5359 net->dest_state |= SCTP_ADDR_PF;
5360 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5361 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5362 stcb->sctp_ep, stcb, net,
5363 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5364 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5367 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5368 if (net->error_count > paddrp->spp_pathmaxrxt) {
5369 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5370 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5373 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5374 net->dest_state |= SCTP_ADDR_REACHABLE;
5375 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5378 net->failure_threshold = paddrp->spp_pathmaxrxt;
5380 if (paddrp->spp_flags & SPP_DSCP) {
5381 net->dscp = paddrp->spp_dscp & 0xfc;
5385 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5386 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5387 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5388 net->flowlabel |= 0x80000000;
5393 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5394 if (paddrp->spp_pathmaxrxt != 0) {
5395 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5396 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5397 if (net->dest_state & SCTP_ADDR_PF) {
5398 if (net->error_count > paddrp->spp_pathmaxrxt) {
5399 net->dest_state &= ~SCTP_ADDR_PF;
5402 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5403 (net->error_count > net->pf_threshold)) {
5404 net->dest_state |= SCTP_ADDR_PF;
5405 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5406 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5407 stcb->sctp_ep, stcb, net,
5408 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5409 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5412 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5413 if (net->error_count > paddrp->spp_pathmaxrxt) {
5414 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5415 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5418 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5419 net->dest_state |= SCTP_ADDR_REACHABLE;
5420 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5423 net->failure_threshold = paddrp->spp_pathmaxrxt;
5426 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5427 if (paddrp->spp_hbinterval != 0) {
5428 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5429 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5430 stcb->asoc.heart_beat_delay = 0;
5432 /* Turn back on the timer */
5433 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5434 if (paddrp->spp_hbinterval != 0) {
5435 net->heart_beat_delay = paddrp->spp_hbinterval;
5436 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5437 net->heart_beat_delay = 0;
5439 if (net->dest_state & SCTP_ADDR_NOHB) {
5440 net->dest_state &= ~SCTP_ADDR_NOHB;
5442 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5443 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5444 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5446 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5448 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5449 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5450 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5451 net->dest_state |= SCTP_ADDR_NOHB;
5452 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5453 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5455 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5459 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5461 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5462 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5463 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5464 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5465 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5467 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5468 net->mtu = paddrp->spp_pathmtu;
5469 switch (net->ro._l_addr.sa.sa_family) {
5472 net->mtu += SCTP_MIN_V4_OVERHEAD;
5477 net->mtu += SCTP_MIN_OVERHEAD;
5483 if (net->mtu < stcb->asoc.smallest_mtu) {
5484 sctp_pathmtu_adjustment(stcb, net->mtu);
5487 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5488 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5490 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5491 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5492 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5493 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5495 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5497 stcb->asoc.default_mtu = 0;
5498 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5500 if (paddrp->spp_flags & SPP_DSCP) {
5501 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5502 net->dscp = paddrp->spp_dscp & 0xfc;
5505 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5506 stcb->asoc.default_dscp |= 0x01;
5509 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5510 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5511 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5512 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5513 net->flowlabel |= 0x80000000;
5516 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5517 stcb->asoc.default_flowlabel |= 0x80000000;
5521 SCTP_TCB_UNLOCK(stcb);
5523 /************************NO TCB, SET TO default stuff ******************/
5524 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5525 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5526 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5527 SCTP_INP_WLOCK(inp);
5529 * For the TOS/FLOWLABEL stuff you
5530 * set it with the options on the
5533 if (paddrp->spp_pathmaxrxt != 0) {
5534 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5536 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5537 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5538 else if (paddrp->spp_hbinterval != 0) {
5539 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5540 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5541 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5543 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5544 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5545 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5546 } else if (paddrp->spp_hbinterval) {
5547 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5549 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5550 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5551 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5553 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5554 inp->sctp_ep.default_mtu = 0;
5555 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5556 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5557 if (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU) {
5558 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5560 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5562 if (paddrp->spp_flags & SPP_DSCP) {
5563 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5564 inp->sctp_ep.default_dscp |= 0x01;
5567 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5568 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5569 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5570 inp->sctp_ep.default_flowlabel |= 0x80000000;
5574 SCTP_INP_WUNLOCK(inp);
5576 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5584 struct sctp_rtoinfo *srto;
5585 uint32_t new_init, new_min, new_max;
5587 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5588 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5591 if (srto->srto_initial)
5592 new_init = srto->srto_initial;
5594 new_init = stcb->asoc.initial_rto;
5596 new_max = srto->srto_max;
5598 new_max = stcb->asoc.maxrto;
5600 new_min = srto->srto_min;
5602 new_min = stcb->asoc.minrto;
5603 if ((new_min <= new_init) && (new_init <= new_max)) {
5604 stcb->asoc.initial_rto = new_init;
5605 stcb->asoc.maxrto = new_max;
5606 stcb->asoc.minrto = new_min;
5608 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5611 SCTP_TCB_UNLOCK(stcb);
5613 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5614 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5615 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5616 SCTP_INP_WLOCK(inp);
5617 if (srto->srto_initial)
5618 new_init = srto->srto_initial;
5620 new_init = inp->sctp_ep.initial_rto;
5622 new_max = srto->srto_max;
5624 new_max = inp->sctp_ep.sctp_maxrto;
5626 new_min = srto->srto_min;
5628 new_min = inp->sctp_ep.sctp_minrto;
5629 if ((new_min <= new_init) && (new_init <= new_max)) {
5630 inp->sctp_ep.initial_rto = new_init;
5631 inp->sctp_ep.sctp_maxrto = new_max;
5632 inp->sctp_ep.sctp_minrto = new_min;
5634 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5637 SCTP_INP_WUNLOCK(inp);
5639 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5645 case SCTP_ASSOCINFO:
5647 struct sctp_assocparams *sasoc;
5649 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5650 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5651 if (sasoc->sasoc_cookie_life) {
5652 /* boundary check the cookie life */
5653 if (sasoc->sasoc_cookie_life < 1000)
5654 sasoc->sasoc_cookie_life = 1000;
5655 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5656 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5660 if (sasoc->sasoc_asocmaxrxt)
5661 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5662 if (sasoc->sasoc_cookie_life) {
5663 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5665 SCTP_TCB_UNLOCK(stcb);
5667 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5668 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5669 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5670 SCTP_INP_WLOCK(inp);
5671 if (sasoc->sasoc_asocmaxrxt)
5672 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5673 if (sasoc->sasoc_cookie_life) {
5674 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5676 SCTP_INP_WUNLOCK(inp);
5678 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5686 struct sctp_initmsg *sinit;
5688 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5689 SCTP_INP_WLOCK(inp);
5690 if (sinit->sinit_num_ostreams)
5691 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5693 if (sinit->sinit_max_instreams)
5694 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5696 if (sinit->sinit_max_attempts)
5697 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5699 if (sinit->sinit_max_init_timeo)
5700 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5701 SCTP_INP_WUNLOCK(inp);
5704 case SCTP_PRIMARY_ADDR:
5706 struct sctp_setprim *spa;
5707 struct sctp_nets *net;
5708 struct sockaddr *addr;
5709 #if defined(INET) && defined(INET6)
5710 struct sockaddr_in sin_store;
5713 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5714 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5716 #if defined(INET) && defined(INET6)
5717 if (spa->ssp_addr.ss_family == AF_INET6) {
5718 struct sockaddr_in6 *sin6;
5720 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5721 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5722 in6_sin6_2_sin(&sin_store, sin6);
5723 addr = (struct sockaddr *)&sin_store;
5725 addr = (struct sockaddr *)&spa->ssp_addr;
5728 addr = (struct sockaddr *)&spa->ssp_addr;
5731 addr = (struct sockaddr *)&spa->ssp_addr;
5734 net = sctp_findnet(stcb, addr);
5737 * We increment here since
5738 * sctp_findassociation_ep_addr() wil do a
5739 * decrement if it finds the stcb as long as
5740 * the locked tcb (last argument) is NOT a
5744 SCTP_INP_INCR_REF(inp);
5745 stcb = sctp_findassociation_ep_addr(&inp, addr,
5748 SCTP_INP_DECR_REF(inp);
5752 if ((stcb != NULL) && (net != NULL)) {
5753 if (net != stcb->asoc.primary_destination) {
5754 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5755 /* Ok we need to set it */
5756 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5757 if ((stcb->asoc.alternate) &&
5758 (!(net->dest_state & SCTP_ADDR_PF)) &&
5759 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5760 sctp_free_remote_addr(stcb->asoc.alternate);
5761 stcb->asoc.alternate = NULL;
5764 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5768 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5777 SCTP_TCB_UNLOCK(stcb);
5781 case SCTP_SET_DYNAMIC_PRIMARY:
5783 union sctp_sockstore *ss;
5785 error = priv_check(curthread,
5786 PRIV_NETINET_RESERVEDPORT);
5790 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5791 /* SUPER USER CHECK? */
5792 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5795 case SCTP_SET_PEER_PRIMARY_ADDR:
5797 struct sctp_setpeerprim *sspp;
5798 struct sockaddr *addr;
5799 #if defined(INET) && defined(INET6)
5800 struct sockaddr_in sin_store;
5803 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5804 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5806 struct sctp_ifa *ifa;
5808 #if defined(INET) && defined(INET6)
5809 if (sspp->sspp_addr.ss_family == AF_INET6) {
5810 struct sockaddr_in6 *sin6;
5812 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5813 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5814 in6_sin6_2_sin(&sin_store, sin6);
5815 addr = (struct sockaddr *)&sin_store;
5817 addr = (struct sockaddr *)&sspp->sspp_addr;
5820 addr = (struct sockaddr *)&sspp->sspp_addr;
5823 addr = (struct sockaddr *)&sspp->sspp_addr;
5825 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5827 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5831 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5833 * Must validate the ifa found is in
5836 struct sctp_laddr *laddr;
5839 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5840 if (laddr->ifa == NULL) {
5841 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5845 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5846 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5849 if (laddr->ifa == ifa) {
5855 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5860 switch (addr->sa_family) {
5864 struct sockaddr_in *sin;
5866 sin = (struct sockaddr_in *)addr;
5867 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5868 &sin->sin_addr) != 0) {
5869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5879 struct sockaddr_in6 *sin6;
5881 sin6 = (struct sockaddr_in6 *)addr;
5882 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5883 &sin6->sin6_addr) != 0) {
5884 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5892 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5897 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5898 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5901 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5903 SCTP_TCB_UNLOCK(stcb);
5905 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5910 case SCTP_BINDX_ADD_ADDR:
5912 struct sctp_getaddresses *addrs;
5915 td = (struct thread *)p;
5916 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5919 if (addrs->addr->sa_family == AF_INET) {
5920 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5925 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5926 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5932 if (addrs->addr->sa_family == AF_INET6) {
5933 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5934 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5938 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5939 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5940 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5946 error = EAFNOSUPPORT;
5949 sctp_bindx_add_address(so, inp, addrs->addr,
5950 addrs->sget_assoc_id, vrf_id,
5954 case SCTP_BINDX_REM_ADDR:
5956 struct sctp_getaddresses *addrs;
5959 td = (struct thread *)p;
5961 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5963 if (addrs->addr->sa_family == AF_INET) {
5964 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5969 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5970 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5976 if (addrs->addr->sa_family == AF_INET6) {
5977 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5978 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5983 (error = prison_local_ip6(td->td_ucred,
5984 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5985 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5986 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5992 error = EAFNOSUPPORT;
5995 sctp_bindx_delete_address(inp, addrs->addr,
5996 addrs->sget_assoc_id, vrf_id,
6002 struct sctp_event *event;
6003 uint32_t event_type;
6005 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6006 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6007 switch (event->se_type) {
6008 case SCTP_ASSOC_CHANGE:
6009 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6011 case SCTP_PEER_ADDR_CHANGE:
6012 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6014 case SCTP_REMOTE_ERROR:
6015 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6017 case SCTP_SEND_FAILED:
6018 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6020 case SCTP_SHUTDOWN_EVENT:
6021 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6023 case SCTP_ADAPTATION_INDICATION:
6024 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6026 case SCTP_PARTIAL_DELIVERY_EVENT:
6027 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6029 case SCTP_AUTHENTICATION_EVENT:
6030 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6032 case SCTP_STREAM_RESET_EVENT:
6033 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6035 case SCTP_SENDER_DRY_EVENT:
6036 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6038 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6040 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6043 case SCTP_ASSOC_RESET_EVENT:
6044 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6046 case SCTP_STREAM_CHANGE_EVENT:
6047 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6049 case SCTP_SEND_FAILED_EVENT:
6050 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6054 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6058 if (event_type > 0) {
6061 sctp_stcb_feature_on(inp, stcb, event_type);
6062 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6063 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6064 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6065 (stcb->asoc.stream_queue_cnt == 0)) {
6066 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6070 sctp_stcb_feature_off(inp, stcb, event_type);
6072 SCTP_TCB_UNLOCK(stcb);
6075 * We don't want to send up a storm
6076 * of events, so return an error for
6079 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6080 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6081 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6082 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6083 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6084 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6088 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6089 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6090 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6091 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6092 SCTP_INP_WLOCK(inp);
6094 sctp_feature_on(inp, event_type);
6096 sctp_feature_off(inp, event_type);
6098 SCTP_INP_WUNLOCK(inp);
6100 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6101 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6102 SCTP_INP_RLOCK(inp);
6103 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6104 SCTP_TCB_LOCK(stcb);
6106 sctp_stcb_feature_on(inp, stcb, event_type);
6108 sctp_stcb_feature_off(inp, stcb, event_type);
6110 SCTP_TCB_UNLOCK(stcb);
6112 SCTP_INP_RUNLOCK(inp);
6118 case SCTP_RECVRCVINFO:
6122 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6123 SCTP_INP_WLOCK(inp);
6125 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6127 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6129 SCTP_INP_WUNLOCK(inp);
6132 case SCTP_RECVNXTINFO:
6136 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6137 SCTP_INP_WLOCK(inp);
6139 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6141 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6143 SCTP_INP_WUNLOCK(inp);
6146 case SCTP_DEFAULT_SNDINFO:
6148 struct sctp_sndinfo *info;
6151 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6152 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6155 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6156 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6157 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6158 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6159 stcb->asoc.def_send.sinfo_flags |= policy;
6160 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6161 stcb->asoc.def_send.sinfo_context = info->snd_context;
6163 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6166 SCTP_TCB_UNLOCK(stcb);
6168 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6169 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6170 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6171 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6172 SCTP_INP_WLOCK(inp);
6173 inp->def_send.sinfo_stream = info->snd_sid;
6174 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6175 inp->def_send.sinfo_flags = info->snd_flags;
6176 inp->def_send.sinfo_flags |= policy;
6177 inp->def_send.sinfo_ppid = info->snd_ppid;
6178 inp->def_send.sinfo_context = info->snd_context;
6179 SCTP_INP_WUNLOCK(inp);
6181 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6182 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6183 SCTP_INP_RLOCK(inp);
6184 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6185 SCTP_TCB_LOCK(stcb);
6186 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6187 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6188 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6189 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6190 stcb->asoc.def_send.sinfo_flags |= policy;
6191 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6192 stcb->asoc.def_send.sinfo_context = info->snd_context;
6194 SCTP_TCB_UNLOCK(stcb);
6196 SCTP_INP_RUNLOCK(inp);
6201 case SCTP_DEFAULT_PRINFO:
6203 struct sctp_default_prinfo *info;
6205 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6206 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6208 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6209 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6214 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6215 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6216 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6217 SCTP_TCB_UNLOCK(stcb);
6219 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6220 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6221 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6222 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6223 SCTP_INP_WLOCK(inp);
6224 inp->def_send.sinfo_flags &= 0xfff0;
6225 inp->def_send.sinfo_flags |= info->pr_policy;
6226 inp->def_send.sinfo_timetolive = info->pr_value;
6227 SCTP_INP_WUNLOCK(inp);
6229 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6230 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6231 SCTP_INP_RLOCK(inp);
6232 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6233 SCTP_TCB_LOCK(stcb);
6234 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6235 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6236 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6237 SCTP_TCB_UNLOCK(stcb);
6239 SCTP_INP_RUNLOCK(inp);
6244 case SCTP_PEER_ADDR_THLDS:
6245 /* Applies to the specific association */
6247 struct sctp_paddrthlds *thlds;
6248 struct sctp_nets *net;
6249 struct sockaddr *addr;
6250 #if defined(INET) && defined(INET6)
6251 struct sockaddr_in sin_store;
6254 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6255 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6257 #if defined(INET) && defined(INET6)
6258 if (thlds->spt_address.ss_family == AF_INET6) {
6259 struct sockaddr_in6 *sin6;
6261 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6262 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6263 in6_sin6_2_sin(&sin_store, sin6);
6264 addr = (struct sockaddr *)&sin_store;
6266 addr = (struct sockaddr *)&thlds->spt_address;
6269 addr = (struct sockaddr *)&thlds->spt_address;
6272 addr = (struct sockaddr *)&thlds->spt_address;
6275 net = sctp_findnet(stcb, addr);
6278 * We increment here since
6279 * sctp_findassociation_ep_addr() wil do a
6280 * decrement if it finds the stcb as long as
6281 * the locked tcb (last argument) is NOT a
6285 SCTP_INP_INCR_REF(inp);
6286 stcb = sctp_findassociation_ep_addr(&inp, addr,
6289 SCTP_INP_DECR_REF(inp);
6292 if ((stcb != NULL) && (net == NULL)) {
6294 if (addr->sa_family == AF_INET) {
6296 struct sockaddr_in *sin;
6298 sin = (struct sockaddr_in *)addr;
6299 if (sin->sin_addr.s_addr != INADDR_ANY) {
6300 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6301 SCTP_TCB_UNLOCK(stcb);
6308 if (addr->sa_family == AF_INET6) {
6309 struct sockaddr_in6 *sin6;
6311 sin6 = (struct sockaddr_in6 *)addr;
6312 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6313 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6314 SCTP_TCB_UNLOCK(stcb);
6321 error = EAFNOSUPPORT;
6322 SCTP_TCB_UNLOCK(stcb);
6323 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6327 if (thlds->spt_pathcpthld != 0xffff) {
6329 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6334 net->failure_threshold = thlds->spt_pathmaxrxt;
6335 net->pf_threshold = thlds->spt_pathpfthld;
6336 if (net->dest_state & SCTP_ADDR_PF) {
6337 if ((net->error_count > net->failure_threshold) ||
6338 (net->error_count <= net->pf_threshold)) {
6339 net->dest_state &= ~SCTP_ADDR_PF;
6342 if ((net->error_count > net->pf_threshold) &&
6343 (net->error_count <= net->failure_threshold)) {
6344 net->dest_state |= SCTP_ADDR_PF;
6345 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6346 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6347 stcb->sctp_ep, stcb, net,
6348 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6349 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6352 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6353 if (net->error_count > net->failure_threshold) {
6354 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6355 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6358 if (net->error_count <= net->failure_threshold) {
6359 net->dest_state |= SCTP_ADDR_REACHABLE;
6360 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6364 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6365 net->failure_threshold = thlds->spt_pathmaxrxt;
6366 net->pf_threshold = thlds->spt_pathpfthld;
6367 if (net->dest_state & SCTP_ADDR_PF) {
6368 if ((net->error_count > net->failure_threshold) ||
6369 (net->error_count <= net->pf_threshold)) {
6370 net->dest_state &= ~SCTP_ADDR_PF;
6373 if ((net->error_count > net->pf_threshold) &&
6374 (net->error_count <= net->failure_threshold)) {
6375 net->dest_state |= SCTP_ADDR_PF;
6376 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6377 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6378 stcb->sctp_ep, stcb, net,
6379 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6380 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6383 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6384 if (net->error_count > net->failure_threshold) {
6385 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6386 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6389 if (net->error_count <= net->failure_threshold) {
6390 net->dest_state |= SCTP_ADDR_REACHABLE;
6391 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6395 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6396 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6398 SCTP_TCB_UNLOCK(stcb);
6400 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6401 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6402 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6403 SCTP_INP_WLOCK(inp);
6404 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6405 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6406 SCTP_INP_WUNLOCK(inp);
6408 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6414 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6416 struct sctp_udpencaps *encaps;
6417 struct sctp_nets *net;
6418 struct sockaddr *addr;
6419 #if defined(INET) && defined(INET6)
6420 struct sockaddr_in sin_store;
6423 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6424 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6426 #if defined(INET) && defined(INET6)
6427 if (encaps->sue_address.ss_family == AF_INET6) {
6428 struct sockaddr_in6 *sin6;
6430 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6431 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6432 in6_sin6_2_sin(&sin_store, sin6);
6433 addr = (struct sockaddr *)&sin_store;
6435 addr = (struct sockaddr *)&encaps->sue_address;
6438 addr = (struct sockaddr *)&encaps->sue_address;
6441 addr = (struct sockaddr *)&encaps->sue_address;
6444 net = sctp_findnet(stcb, addr);
6447 * We increment here since
6448 * sctp_findassociation_ep_addr() wil do a
6449 * decrement if it finds the stcb as long as
6450 * the locked tcb (last argument) is NOT a
6454 SCTP_INP_INCR_REF(inp);
6455 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6457 SCTP_INP_DECR_REF(inp);
6460 if ((stcb != NULL) && (net == NULL)) {
6462 if (addr->sa_family == AF_INET) {
6464 struct sockaddr_in *sin;
6466 sin = (struct sockaddr_in *)addr;
6467 if (sin->sin_addr.s_addr != INADDR_ANY) {
6468 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6469 SCTP_TCB_UNLOCK(stcb);
6476 if (addr->sa_family == AF_INET6) {
6477 struct sockaddr_in6 *sin6;
6479 sin6 = (struct sockaddr_in6 *)addr;
6480 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6481 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6482 SCTP_TCB_UNLOCK(stcb);
6489 error = EAFNOSUPPORT;
6490 SCTP_TCB_UNLOCK(stcb);
6491 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6497 net->port = encaps->sue_port;
6499 stcb->asoc.port = encaps->sue_port;
6501 SCTP_TCB_UNLOCK(stcb);
6503 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6504 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6505 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6506 SCTP_INP_WLOCK(inp);
6507 inp->sctp_ep.port = encaps->sue_port;
6508 SCTP_INP_WUNLOCK(inp);
6510 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6516 case SCTP_ECN_SUPPORTED:
6518 struct sctp_assoc_value *av;
6520 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6521 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6524 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6526 SCTP_TCB_UNLOCK(stcb);
6528 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6529 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6530 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6531 SCTP_INP_WLOCK(inp);
6532 if (av->assoc_value == 0) {
6533 inp->ecn_supported = 0;
6535 inp->ecn_supported = 1;
6537 SCTP_INP_WUNLOCK(inp);
6539 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6545 case SCTP_PR_SUPPORTED:
6547 struct sctp_assoc_value *av;
6549 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6550 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6553 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6555 SCTP_TCB_UNLOCK(stcb);
6557 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6558 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6559 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6560 SCTP_INP_WLOCK(inp);
6561 if (av->assoc_value == 0) {
6562 inp->prsctp_supported = 0;
6564 inp->prsctp_supported = 1;
6566 SCTP_INP_WUNLOCK(inp);
6568 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6574 case SCTP_AUTH_SUPPORTED:
6576 struct sctp_assoc_value *av;
6578 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6579 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6582 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6584 SCTP_TCB_UNLOCK(stcb);
6586 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6587 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6588 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6589 if ((av->assoc_value == 0) &&
6590 (inp->asconf_supported == 1)) {
6592 * AUTH is required for
6595 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6598 SCTP_INP_WLOCK(inp);
6599 if (av->assoc_value == 0) {
6600 inp->auth_supported = 0;
6602 inp->auth_supported = 1;
6604 SCTP_INP_WUNLOCK(inp);
6607 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6613 case SCTP_ASCONF_SUPPORTED:
6615 struct sctp_assoc_value *av;
6617 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6618 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6623 SCTP_TCB_UNLOCK(stcb);
6625 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6626 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6627 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6628 if ((av->assoc_value != 0) &&
6629 (inp->auth_supported == 0)) {
6631 * AUTH is required for
6634 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6637 SCTP_INP_WLOCK(inp);
6638 if (av->assoc_value == 0) {
6639 inp->asconf_supported = 0;
6640 sctp_auth_delete_chunk(SCTP_ASCONF,
6641 inp->sctp_ep.local_auth_chunks);
6642 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6643 inp->sctp_ep.local_auth_chunks);
6645 inp->asconf_supported = 1;
6646 sctp_auth_add_chunk(SCTP_ASCONF,
6647 inp->sctp_ep.local_auth_chunks);
6648 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6649 inp->sctp_ep.local_auth_chunks);
6651 SCTP_INP_WUNLOCK(inp);
6654 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6660 case SCTP_RECONFIG_SUPPORTED:
6662 struct sctp_assoc_value *av;
6664 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6665 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6668 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6670 SCTP_TCB_UNLOCK(stcb);
6672 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6673 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6674 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6675 SCTP_INP_WLOCK(inp);
6676 if (av->assoc_value == 0) {
6677 inp->reconfig_supported = 0;
6679 inp->reconfig_supported = 1;
6681 SCTP_INP_WUNLOCK(inp);
6683 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6689 case SCTP_NRSACK_SUPPORTED:
6691 struct sctp_assoc_value *av;
6693 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6694 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6697 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6699 SCTP_TCB_UNLOCK(stcb);
6701 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6702 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6703 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6704 SCTP_INP_WLOCK(inp);
6705 if (av->assoc_value == 0) {
6706 inp->nrsack_supported = 0;
6708 inp->nrsack_supported = 1;
6710 SCTP_INP_WUNLOCK(inp);
6712 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6718 case SCTP_PKTDROP_SUPPORTED:
6720 struct sctp_assoc_value *av;
6722 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6723 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6726 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6728 SCTP_TCB_UNLOCK(stcb);
6730 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6731 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6732 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6733 SCTP_INP_WLOCK(inp);
6734 if (av->assoc_value == 0) {
6735 inp->pktdrop_supported = 0;
6737 inp->pktdrop_supported = 1;
6739 SCTP_INP_WUNLOCK(inp);
6741 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6749 struct sctp_assoc_value *av;
6750 struct sctp_nets *net;
6752 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6753 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6756 stcb->asoc.max_cwnd = av->assoc_value;
6757 if (stcb->asoc.max_cwnd > 0) {
6758 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6759 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6760 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6761 net->cwnd = stcb->asoc.max_cwnd;
6762 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6763 net->cwnd = net->mtu - sizeof(struct sctphdr);
6768 SCTP_TCB_UNLOCK(stcb);
6770 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6771 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6772 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6773 SCTP_INP_WLOCK(inp);
6774 inp->max_cwnd = av->assoc_value;
6775 SCTP_INP_WUNLOCK(inp);
6777 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6784 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6785 error = ENOPROTOOPT;
6787 } /* end switch (opt) */
6792 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6794 void *optval = NULL;
6798 struct sctp_inpcb *inp;
6800 if ((sopt->sopt_level == SOL_SOCKET) &&
6801 (sopt->sopt_name == SO_SETFIB)) {
6802 inp = (struct sctp_inpcb *)so->so_pcb;
6804 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6807 SCTP_INP_WLOCK(inp);
6808 inp->fibnum = so->so_fibnum;
6809 SCTP_INP_WUNLOCK(inp);
6812 if (sopt->sopt_level != IPPROTO_SCTP) {
6813 /* wrong proto level... send back up to IP */
6815 if (INP_CHECK_SOCKAF(so, AF_INET6))
6816 error = ip6_ctloutput(so, sopt);
6818 #if defined(INET) && defined(INET6)
6822 error = ip_ctloutput(so, sopt);
6826 optsize = sopt->sopt_valsize;
6828 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6829 if (optval == NULL) {
6830 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6833 error = sooptcopyin(sopt, optval, optsize, optsize);
6835 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6839 p = (void *)sopt->sopt_td;
6840 if (sopt->sopt_dir == SOPT_SET) {
6841 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6842 } else if (sopt->sopt_dir == SOPT_GET) {
6843 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6845 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6848 if ((error == 0) && (optval != NULL)) {
6849 error = sooptcopyout(sopt, optval, optsize);
6850 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6851 } else if (optval != NULL) {
6852 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6860 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6863 int create_lock_on = 0;
6865 struct sctp_inpcb *inp;
6866 struct sctp_tcb *stcb = NULL;
6868 inp = (struct sctp_inpcb *)so->so_pcb;
6870 /* I made the same as TCP since we are not setup? */
6871 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6872 return (ECONNRESET);
6875 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6878 switch (addr->sa_family) {
6882 struct sockaddr_in6 *sin6p;
6884 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6885 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6888 sin6p = (struct sockaddr_in6 *)addr;
6889 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6890 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6899 struct sockaddr_in *sinp;
6901 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6905 sinp = (struct sockaddr_in *)addr;
6906 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6907 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6914 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6915 return (EAFNOSUPPORT);
6917 SCTP_INP_INCR_REF(inp);
6918 SCTP_ASOC_CREATE_LOCK(inp);
6922 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6923 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6924 /* Should I really unlock ? */
6925 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6930 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6931 (addr->sa_family == AF_INET6)) {
6932 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6937 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6938 SCTP_PCB_FLAGS_UNBOUND) {
6939 /* Bind a ephemeral port */
6940 error = sctp_inpcb_bind(so, NULL, NULL, p);
6945 /* Now do we connect? */
6946 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6947 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6952 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6953 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6954 /* We are already connected AND the TCP model */
6955 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6959 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6960 SCTP_INP_RLOCK(inp);
6961 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6962 SCTP_INP_RUNLOCK(inp);
6965 * We increment here since sctp_findassociation_ep_addr()
6966 * will do a decrement if it finds the stcb as long as the
6967 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6969 SCTP_INP_INCR_REF(inp);
6970 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6972 SCTP_INP_DECR_REF(inp);
6974 SCTP_TCB_UNLOCK(stcb);
6978 /* Already have or am bring up an association */
6979 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6983 vrf_id = inp->def_vrf_id;
6984 /* We are GOOD to go */
6985 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
6986 inp->sctp_ep.pre_open_stream_count,
6987 inp->sctp_ep.port, p);
6989 /* Gak! no memory */
6992 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6993 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6994 /* Set the connected flag so we can queue data */
6997 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6998 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7000 /* initialize authentication parameters for the assoc */
7001 sctp_initialize_auth_params(inp, stcb);
7003 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7004 SCTP_TCB_UNLOCK(stcb);
7006 if (create_lock_on) {
7007 SCTP_ASOC_CREATE_UNLOCK(inp);
7009 SCTP_INP_DECR_REF(inp);
7015 sctp_listen(struct socket *so, int backlog, struct thread *p)
7018 * Note this module depends on the protocol processing being called
7019 * AFTER any socket level flags and backlog are applied to the
7020 * socket. The traditional way that the socket flags are applied is
7021 * AFTER protocol processing. We have made a change to the
7022 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7023 * place if the socket API for SCTP is to work properly.
7027 struct sctp_inpcb *inp;
7029 inp = (struct sctp_inpcb *)so->so_pcb;
7031 /* I made the same as TCP since we are not setup? */
7032 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7033 return (ECONNRESET);
7035 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7036 /* See if we have a listener */
7037 struct sctp_inpcb *tinp;
7038 union sctp_sockstore store;
7040 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7042 struct sctp_laddr *laddr;
7044 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7045 memcpy(&store, &laddr->ifa->address, sizeof(store));
7046 switch (store.sa.sa_family) {
7049 store.sin.sin_port = inp->sctp_lport;
7054 store.sin6.sin6_port = inp->sctp_lport;
7060 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7061 if (tinp && (tinp != inp) &&
7062 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7063 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7064 (SCTP_IS_LISTENING(tinp))) {
7066 * we have a listener already and
7069 SCTP_INP_DECR_REF(tinp);
7070 return (EADDRINUSE);
7072 SCTP_INP_DECR_REF(tinp);
7076 /* Setup a local addr bound all */
7077 memset(&store, 0, sizeof(store));
7079 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7080 store.sa.sa_family = AF_INET6;
7081 store.sa.sa_len = sizeof(struct sockaddr_in6);
7085 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7086 store.sa.sa_family = AF_INET;
7087 store.sa.sa_len = sizeof(struct sockaddr_in);
7090 switch (store.sa.sa_family) {
7093 store.sin.sin_port = inp->sctp_lport;
7098 store.sin6.sin6_port = inp->sctp_lport;
7104 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7105 if (tinp && (tinp != inp) &&
7106 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7107 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7108 (SCTP_IS_LISTENING(tinp))) {
7110 * we have a listener already and its not
7113 SCTP_INP_DECR_REF(tinp);
7114 return (EADDRINUSE);
7116 SCTP_INP_DECR_REF(tinp);
7120 SCTP_INP_RLOCK(inp);
7121 #ifdef SCTP_LOCK_LOGGING
7122 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7123 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7127 error = solisten_proto_check(so);
7130 SCTP_INP_RUNLOCK(inp);
7133 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7134 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7136 * The unlucky case - We are in the tcp pool with this guy.
7137 * - Someone else is in the main inp slot. - We must move
7138 * this guy (the listener) to the main slot - We must then
7139 * move the guy that was listener to the TCP Pool.
7141 if (sctp_swap_inpcb_for_listen(inp)) {
7142 SCTP_INP_RUNLOCK(inp);
7143 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7144 return (EADDRINUSE);
7147 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7148 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7149 /* We are already connected AND the TCP model */
7150 SCTP_INP_RUNLOCK(inp);
7151 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7152 return (EADDRINUSE);
7154 SCTP_INP_RUNLOCK(inp);
7155 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7156 /* We must do a bind. */
7157 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7158 /* bind error, probably perm */
7162 SCTP_INP_WLOCK(inp);
7163 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7165 solisten_proto(so, backlog);
7169 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7171 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7173 SCTP_INP_WUNLOCK(inp);
7177 static int sctp_defered_wakeup_cnt = 0;
7180 sctp_accept(struct socket *so, struct sockaddr **addr)
7182 struct sctp_tcb *stcb;
7183 struct sctp_inpcb *inp;
7184 union sctp_sockstore store;
7188 inp = (struct sctp_inpcb *)so->so_pcb;
7191 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7192 return (ECONNRESET);
7194 SCTP_INP_RLOCK(inp);
7195 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7196 SCTP_INP_RUNLOCK(inp);
7197 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7198 return (EOPNOTSUPP);
7200 if (so->so_state & SS_ISDISCONNECTED) {
7201 SCTP_INP_RUNLOCK(inp);
7202 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7203 return (ECONNABORTED);
7205 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7207 SCTP_INP_RUNLOCK(inp);
7208 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7209 return (ECONNRESET);
7211 SCTP_TCB_LOCK(stcb);
7212 SCTP_INP_RUNLOCK(inp);
7213 store = stcb->asoc.primary_destination->ro._l_addr;
7214 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7215 SCTP_TCB_UNLOCK(stcb);
7216 switch (store.sa.sa_family) {
7220 struct sockaddr_in *sin;
7222 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7225 sin->sin_family = AF_INET;
7226 sin->sin_len = sizeof(*sin);
7227 sin->sin_port = store.sin.sin_port;
7228 sin->sin_addr = store.sin.sin_addr;
7229 *addr = (struct sockaddr *)sin;
7236 struct sockaddr_in6 *sin6;
7238 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7241 sin6->sin6_family = AF_INET6;
7242 sin6->sin6_len = sizeof(*sin6);
7243 sin6->sin6_port = store.sin6.sin6_port;
7244 sin6->sin6_addr = store.sin6.sin6_addr;
7245 if ((error = sa6_recoverscope(sin6)) != 0) {
7246 SCTP_FREE_SONAME(sin6);
7249 *addr = (struct sockaddr *)sin6;
7257 /* Wake any delayed sleep action */
7258 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7259 SCTP_INP_WLOCK(inp);
7260 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7261 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7262 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7263 SCTP_INP_WUNLOCK(inp);
7264 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7265 if (sowriteable(inp->sctp_socket)) {
7266 sowwakeup_locked(inp->sctp_socket);
7268 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7270 SCTP_INP_WLOCK(inp);
7272 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7273 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7274 SCTP_INP_WUNLOCK(inp);
7275 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7276 if (soreadable(inp->sctp_socket)) {
7277 sctp_defered_wakeup_cnt++;
7278 sorwakeup_locked(inp->sctp_socket);
7280 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7282 SCTP_INP_WLOCK(inp);
7284 SCTP_INP_WUNLOCK(inp);
7286 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7287 SCTP_TCB_LOCK(stcb);
7288 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7289 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7296 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7298 struct sockaddr_in *sin;
7300 struct sctp_inpcb *inp;
7301 struct sctp_ifa *sctp_ifa;
7304 * Do the malloc first in case it blocks.
7306 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7309 sin->sin_family = AF_INET;
7310 sin->sin_len = sizeof(*sin);
7311 inp = (struct sctp_inpcb *)so->so_pcb;
7313 SCTP_FREE_SONAME(sin);
7314 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7315 return (ECONNRESET);
7317 SCTP_INP_RLOCK(inp);
7318 sin->sin_port = inp->sctp_lport;
7319 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7320 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7321 struct sctp_tcb *stcb;
7322 struct sockaddr_in *sin_a;
7323 struct sctp_nets *net;
7326 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7332 SCTP_TCB_LOCK(stcb);
7333 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7334 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7336 /* this will make coverity happy */
7339 if (sin_a->sin_family == AF_INET) {
7344 if ((!fnd) || (sin_a == NULL)) {
7346 SCTP_TCB_UNLOCK(stcb);
7349 vrf_id = inp->def_vrf_id;
7350 sctp_ifa = sctp_source_address_selection(inp,
7352 (sctp_route_t *)&net->ro,
7355 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7356 sctp_free_ifa(sctp_ifa);
7358 SCTP_TCB_UNLOCK(stcb);
7360 /* For the bound all case you get back 0 */
7362 sin->sin_addr.s_addr = 0;
7366 /* Take the first IPv4 address in the list */
7367 struct sctp_laddr *laddr;
7370 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7371 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7372 struct sockaddr_in *sin_a;
7374 sin_a = &laddr->ifa->address.sin;
7375 sin->sin_addr = sin_a->sin_addr;
7381 SCTP_FREE_SONAME(sin);
7382 SCTP_INP_RUNLOCK(inp);
7383 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7387 SCTP_INP_RUNLOCK(inp);
7388 (*addr) = (struct sockaddr *)sin;
7393 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7395 struct sockaddr_in *sin;
7397 struct sockaddr_in *sin_a;
7398 struct sctp_inpcb *inp;
7399 struct sctp_tcb *stcb;
7400 struct sctp_nets *net;
7402 /* Do the malloc first in case it blocks. */
7403 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7406 sin->sin_family = AF_INET;
7407 sin->sin_len = sizeof(*sin);
7409 inp = (struct sctp_inpcb *)so->so_pcb;
7410 if ((inp == NULL) ||
7411 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7412 /* UDP type and listeners will drop out here */
7413 SCTP_FREE_SONAME(sin);
7414 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7417 SCTP_INP_RLOCK(inp);
7418 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7420 SCTP_TCB_LOCK(stcb);
7422 SCTP_INP_RUNLOCK(inp);
7424 SCTP_FREE_SONAME(sin);
7425 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7426 return (ECONNRESET);
7429 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7430 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7431 if (sin_a->sin_family == AF_INET) {
7433 sin->sin_port = stcb->rport;
7434 sin->sin_addr = sin_a->sin_addr;
7438 SCTP_TCB_UNLOCK(stcb);
7440 /* No IPv4 address */
7441 SCTP_FREE_SONAME(sin);
7442 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7445 (*addr) = (struct sockaddr *)sin;
7449 struct pr_usrreqs sctp_usrreqs = {
7450 .pru_abort = sctp_abort,
7451 .pru_accept = sctp_accept,
7452 .pru_attach = sctp_attach,
7453 .pru_bind = sctp_bind,
7454 .pru_connect = sctp_connect,
7455 .pru_control = in_control,
7456 .pru_close = sctp_close,
7457 .pru_detach = sctp_close,
7458 .pru_sopoll = sopoll_generic,
7459 .pru_flush = sctp_flush,
7460 .pru_disconnect = sctp_disconnect,
7461 .pru_listen = sctp_listen,
7462 .pru_peeraddr = sctp_peeraddr,
7463 .pru_send = sctp_sendm,
7464 .pru_shutdown = sctp_shutdown,
7465 .pru_sockaddr = sctp_ingetaddr,
7466 .pru_sosend = sctp_sosend,
7467 .pru_soreceive = sctp_soreceive