2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
5 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
6 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * a) Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
14 * b) Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the distribution.
18 * c) Neither the name of Cisco Systems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <netinet/sctp_os.h>
40 #include <netinet/sctp_pcb.h>
41 #include <netinet/sctp_header.h>
42 #include <netinet/sctp_var.h>
44 #include <netinet6/sctp6_var.h>
46 #include <netinet/sctp_sysctl.h>
47 #include <netinet/sctp_output.h>
48 #include <netinet/sctp_uio.h>
49 #include <netinet/sctp_asconf.h>
50 #include <netinet/sctputil.h>
51 #include <netinet/sctp_indata.h>
52 #include <netinet/sctp_timer.h>
53 #include <netinet/sctp_auth.h>
54 #include <netinet/sctp_bsd_addr.h>
55 #include <netinet/udp.h>
59 extern const struct sctp_cc_functions sctp_cc_functions[];
60 extern const struct sctp_ss_functions sctp_ss_functions[];
67 /* Initialize and modify the sysctled variables */
69 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
70 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
72 * Allow a user to take no more than 1/2 the number of clusters or
73 * the SB_MAX whichever is smaller for the send window.
75 sb_max_adj = (u_long)((u_quad_t)(SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
76 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
77 (((uint32_t)nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
79 * Now for the recv window, should we take the same amount? or
80 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
81 * now I will just copy.
83 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
84 SCTP_BASE_VAR(first_time) = 0;
85 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
87 #if defined(SCTP_PACKET_LOGGING)
88 SCTP_BASE_VAR(packet_log_writers) = 0;
89 SCTP_BASE_VAR(packet_log_end) = 0;
90 memset(&SCTP_BASE_VAR(packet_log_buffer), 0, SCTP_PACKET_LOG_SIZE);
96 sctp_finish(void *unused __unused)
101 VNET_SYSUNINIT(sctp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, sctp_finish, NULL);
105 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
107 struct sctp_tmit_chunk *chk;
110 /* Adjust that too */
111 stcb->asoc.smallest_mtu = nxtsz;
112 /* now off to subtract IP_DF flag if needed */
113 overhead = IP_HDR_SIZE + sizeof(struct sctphdr);
114 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
115 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
117 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
118 if ((chk->send_size + overhead) > nxtsz) {
119 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
122 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
123 if ((chk->send_size + overhead) > nxtsz) {
125 * For this guy we also mark for immediate resend
126 * since we sent to big of chunk
128 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
129 if (chk->sent < SCTP_DATAGRAM_RESEND) {
130 sctp_flight_size_decrease(chk);
131 sctp_total_flight_decrease(stcb, chk);
132 chk->sent = SCTP_DATAGRAM_RESEND;
133 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
134 chk->rec.data.doing_fast_retransmit = 0;
135 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
136 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
137 chk->whoTo->flight_size,
139 (uint32_t)(uintptr_t)chk->whoTo,
142 /* Clear any time so NO RTT is being done */
151 sctp_notify(struct sctp_inpcb *inp,
152 struct sctp_tcb *stcb,
153 struct sctp_nets *net,
159 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
164 if (icmp_type != ICMP_UNREACH) {
165 /* We only care about unreachable */
166 SCTP_TCB_UNLOCK(stcb);
169 if ((icmp_code == ICMP_UNREACH_NET) ||
170 (icmp_code == ICMP_UNREACH_HOST) ||
171 (icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
172 (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
173 (icmp_code == ICMP_UNREACH_ISOLATED) ||
174 (icmp_code == ICMP_UNREACH_NET_PROHIB) ||
175 (icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
176 (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
177 /* Mark the net unreachable. */
178 if (net->dest_state & SCTP_ADDR_REACHABLE) {
179 /* OK, that destination is NOT reachable. */
180 net->dest_state &= ~SCTP_ADDR_REACHABLE;
181 net->dest_state &= ~SCTP_ADDR_PF;
182 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
184 (void *)net, SCTP_SO_NOT_LOCKED);
186 SCTP_TCB_UNLOCK(stcb);
187 } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) ||
188 (icmp_code == ICMP_UNREACH_PORT)) {
189 /* Treat it like an ABORT. */
190 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
191 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
192 so = SCTP_INP_SO(inp);
193 atomic_add_int(&stcb->asoc.refcnt, 1);
194 SCTP_TCB_UNLOCK(stcb);
195 SCTP_SOCKET_LOCK(so, 1);
197 atomic_subtract_int(&stcb->asoc.refcnt, 1);
199 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
200 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
201 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
202 SCTP_SOCKET_UNLOCK(so, 1);
203 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
205 /* no need to unlock here, since the TCB is gone */
206 } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) {
207 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
208 SCTP_TCB_UNLOCK(stcb);
211 /* Find the next (smaller) MTU */
214 * Old type router that does not tell us what the
215 * next MTU is. Rats we will have to guess (in a
216 * educated fashion of course).
218 next_mtu = sctp_get_prev_mtu(ip_len);
220 /* Stop the PMTU timer. */
221 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
223 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
224 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
228 /* Update the path MTU. */
230 next_mtu -= sizeof(struct udphdr);
232 if (net->mtu > next_mtu) {
235 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu + sizeof(struct udphdr));
237 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu);
240 /* Update the association MTU */
241 if (stcb->asoc.smallest_mtu > next_mtu) {
242 sctp_pathmtu_adjustment(stcb, next_mtu);
244 /* Finally, start the PMTU timer if it was running before. */
246 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
248 SCTP_TCB_UNLOCK(stcb);
250 SCTP_TCB_UNLOCK(stcb);
255 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
261 struct sctp_inpcb *inp;
262 struct sctp_tcb *stcb;
263 struct sctp_nets *net;
264 struct sctp_init_chunk *ch;
265 struct sockaddr_in src, dst;
267 if (sa->sa_family != AF_INET ||
268 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
271 if (PRC_IS_REDIRECT(cmd)) {
273 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
277 inner_ip = (struct ip *)vip;
278 icmp = (struct icmp *)((caddr_t)inner_ip -
279 (sizeof(struct icmp) - sizeof(struct ip)));
280 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
281 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
282 memset(&src, 0, sizeof(struct sockaddr_in));
283 src.sin_family = AF_INET;
284 src.sin_len = sizeof(struct sockaddr_in);
285 src.sin_port = sh->src_port;
286 src.sin_addr = inner_ip->ip_src;
287 memset(&dst, 0, sizeof(struct sockaddr_in));
288 dst.sin_family = AF_INET;
289 dst.sin_len = sizeof(struct sockaddr_in);
290 dst.sin_port = sh->dest_port;
291 dst.sin_addr = inner_ip->ip_dst;
293 * 'dst' holds the dest of the packet that failed to be
294 * sent. 'src' holds our local endpoint address. Thus we
295 * reverse the dst and the src in the lookup.
299 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
300 (struct sockaddr *)&src,
303 if ((stcb != NULL) &&
306 /* Check the verification tag */
307 if (ntohl(sh->v_tag) != 0) {
309 * This must be the verification tag used
310 * for sending out packets. We don't
311 * consider packets reflecting the
314 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
315 SCTP_TCB_UNLOCK(stcb);
319 if (ntohs(outer_ip->ip_len) >=
321 8 + (inner_ip->ip_hl << 2) + 20) {
323 * In this case we can check if we
324 * got an INIT chunk and if the
325 * initiate tag matches.
327 ch = (struct sctp_init_chunk *)(sh + 1);
328 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
329 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
330 SCTP_TCB_UNLOCK(stcb);
334 SCTP_TCB_UNLOCK(stcb);
338 sctp_notify(inp, stcb, net,
341 ntohs(inner_ip->ip_len),
342 (uint32_t)ntohs(icmp->icmp_nextmtu));
344 if ((stcb == NULL) && (inp != NULL)) {
345 /* reduce ref-count */
347 SCTP_INP_DECR_REF(inp);
348 SCTP_INP_WUNLOCK(inp);
351 SCTP_TCB_UNLOCK(stcb);
360 sctp_getcred(SYSCTL_HANDLER_ARGS)
363 struct sockaddr_in addrs[2];
364 struct sctp_inpcb *inp;
365 struct sctp_nets *net;
366 struct sctp_tcb *stcb;
370 /* FIX, for non-bsd is this right? */
371 vrf_id = SCTP_DEFAULT_VRFID;
373 error = priv_check(req->td, PRIV_NETINET_GETCRED);
378 error = SYSCTL_IN(req, addrs, sizeof(addrs));
382 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
384 &inp, &net, 1, vrf_id);
385 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
386 if ((inp != NULL) && (stcb == NULL)) {
387 /* reduce ref-count */
389 SCTP_INP_DECR_REF(inp);
393 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
397 SCTP_TCB_UNLOCK(stcb);
399 * We use the write lock here, only since in the error leg we need
400 * it. If we used RLOCK, then we would have to
401 * wlock/decr/unlock/rlock. Which in theory could create a hole.
402 * Better to use higher wlock.
406 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
408 SCTP_INP_WUNLOCK(inp);
411 cru2x(inp->sctp_socket->so_cred, &xuc);
412 SCTP_INP_WUNLOCK(inp);
413 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
418 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
419 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
424 sctp_abort(struct socket *so)
426 struct sctp_inpcb *inp;
429 inp = (struct sctp_inpcb *)so->so_pcb;
435 flags = inp->sctp_flags;
436 #ifdef SCTP_LOG_CLOSING
437 sctp_log_closing(inp, NULL, 17);
439 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
440 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
441 #ifdef SCTP_LOG_CLOSING
442 sctp_log_closing(inp, NULL, 16);
444 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
445 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
447 SCTP_SB_CLEAR(so->so_snd);
449 * same for the rcv ones, they are only here for the
452 SCTP_SB_CLEAR(so->so_rcv);
454 /* Now null out the reference, we are completely detached. */
458 flags = inp->sctp_flags;
459 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
460 goto sctp_must_try_again;
467 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
469 struct sctp_inpcb *inp;
470 struct inpcb *ip_inp;
472 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
474 inp = (struct sctp_inpcb *)so->so_pcb;
476 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
479 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
480 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
485 error = sctp_inpcb_alloc(so, vrf_id);
489 inp = (struct sctp_inpcb *)so->so_pcb;
491 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
492 ip_inp = &inp->ip_inp.inp;
493 ip_inp->inp_vflag |= INP_IPV4;
494 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
495 SCTP_INP_WUNLOCK(inp);
500 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
502 struct sctp_inpcb *inp;
504 inp = (struct sctp_inpcb *)so->so_pcb;
506 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
510 if ((addr->sa_family != AF_INET) ||
511 (addr->sa_len != sizeof(struct sockaddr_in))) {
512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
516 return (sctp_inpcb_bind(so, addr, NULL, p));
521 sctp_close(struct socket *so)
523 struct sctp_inpcb *inp;
526 inp = (struct sctp_inpcb *)so->so_pcb;
531 * Inform all the lower layer assoc that we are done.
534 flags = inp->sctp_flags;
535 #ifdef SCTP_LOG_CLOSING
536 sctp_log_closing(inp, NULL, 17);
538 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
539 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
540 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
541 (so->so_rcv.sb_cc > 0)) {
542 #ifdef SCTP_LOG_CLOSING
543 sctp_log_closing(inp, NULL, 13);
545 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
546 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
548 #ifdef SCTP_LOG_CLOSING
549 sctp_log_closing(inp, NULL, 14);
551 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
552 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
555 * The socket is now detached, no matter what the state of
556 * the SCTP association.
559 SCTP_SB_CLEAR(so->so_snd);
561 * same for the rcv ones, they are only here for the
564 SCTP_SB_CLEAR(so->so_rcv);
566 /* Now null out the reference, we are completely detached. */
570 flags = inp->sctp_flags;
571 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
572 goto sctp_must_try_again;
580 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
581 struct mbuf *control, struct thread *p);
585 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
586 struct mbuf *control, struct thread *p)
588 struct sctp_inpcb *inp;
591 inp = (struct sctp_inpcb *)so->so_pcb;
594 sctp_m_freem(control);
597 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
601 /* Got to have an to address if we are NOT a connected socket */
602 if ((addr == NULL) &&
603 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
604 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
606 } else if (addr == NULL) {
607 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
608 error = EDESTADDRREQ;
611 sctp_m_freem(control);
617 if (addr->sa_family != AF_INET) {
618 /* must be a v4 address! */
619 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
622 sctp_m_freem(control);
625 error = EDESTADDRREQ;
630 /* now what about control */
633 sctp_m_freem(inp->control);
636 inp->control = control;
640 SCTP_BUF_NEXT(inp->pkt_last) = m;
643 inp->pkt_last = inp->pkt = m;
646 /* FreeBSD uses a flag passed */
647 ((flags & PRUS_MORETOCOME) == 0)
650 * note with the current version this code will only be used
651 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
652 * re-defining sosend to use the sctp_sosend. One can
653 * optionally switch back to this code (by changing back the
654 * definitions) but this is not advisable. This code is used
655 * by FreeBSD when sending a file with sendfile() though.
659 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
669 sctp_disconnect(struct socket *so)
671 struct sctp_inpcb *inp;
673 inp = (struct sctp_inpcb *)so->so_pcb;
675 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
679 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
680 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
681 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
683 SCTP_INP_RUNLOCK(inp);
686 struct sctp_association *asoc;
687 struct sctp_tcb *stcb;
689 stcb = LIST_FIRST(&inp->sctp_asoc_list);
691 SCTP_INP_RUNLOCK(inp);
692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
697 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
698 /* We are about to be freed, out of here */
699 SCTP_TCB_UNLOCK(stcb);
700 SCTP_INP_RUNLOCK(inp);
703 if (((so->so_options & SO_LINGER) &&
704 (so->so_linger == 0)) ||
705 (so->so_rcv.sb_cc > 0)) {
706 if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) {
707 /* Left with Data unread */
710 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
711 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
712 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
714 SCTP_INP_RUNLOCK(inp);
715 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
716 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
717 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
719 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
720 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
721 /* No unlock tcb assoc is gone */
724 if (TAILQ_EMPTY(&asoc->send_queue) &&
725 TAILQ_EMPTY(&asoc->sent_queue) &&
726 (asoc->stream_queue_cnt == 0)) {
727 /* there is nothing queued to send, so done */
728 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
731 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) &&
732 (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
733 /* only send SHUTDOWN 1st time thru */
734 struct sctp_nets *netp;
736 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
737 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
738 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
740 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
741 sctp_stop_timers_for_shutdown(stcb);
742 if (stcb->asoc.alternate) {
743 netp = stcb->asoc.alternate;
745 netp = stcb->asoc.primary_destination;
747 sctp_send_shutdown(stcb, netp);
748 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
749 stcb->sctp_ep, stcb, netp);
750 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
751 stcb->sctp_ep, stcb, netp);
752 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
756 * we still got (or just got) data to send,
757 * so set SHUTDOWN_PENDING
760 * XXX sockets draft says that SCTP_EOF
761 * should be sent with no data. currently,
762 * we will allow user data to be sent first
763 * and move to SHUTDOWN-PENDING
765 struct sctp_nets *netp;
767 if (stcb->asoc.alternate) {
768 netp = stcb->asoc.alternate;
770 netp = stcb->asoc.primary_destination;
773 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
774 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
776 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
777 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
779 if (TAILQ_EMPTY(&asoc->send_queue) &&
780 TAILQ_EMPTY(&asoc->sent_queue) &&
781 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
785 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
786 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
787 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
788 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
789 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
790 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
791 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
793 SCTP_INP_RUNLOCK(inp);
794 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
795 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
798 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
801 soisdisconnecting(so);
802 SCTP_TCB_UNLOCK(stcb);
803 SCTP_INP_RUNLOCK(inp);
808 /* UDP model does not support this */
809 SCTP_INP_RUNLOCK(inp);
810 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
816 sctp_flush(struct socket *so, int how)
819 * We will just clear out the values and let subsequent close clear
820 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
821 * they will not be able to read the data, the socket will block
822 * that from happening.
824 struct sctp_inpcb *inp;
826 inp = (struct sctp_inpcb *)so->so_pcb;
828 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
832 /* For the 1 to many model this does nothing */
833 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
834 SCTP_INP_RUNLOCK(inp);
837 SCTP_INP_RUNLOCK(inp);
838 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
840 * First make sure the sb will be happy, we don't use these
841 * except maybe the count
844 SCTP_INP_READ_LOCK(inp);
845 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
846 SCTP_INP_READ_UNLOCK(inp);
847 SCTP_INP_WUNLOCK(inp);
848 so->so_rcv.sb_cc = 0;
849 so->so_rcv.sb_mbcnt = 0;
850 so->so_rcv.sb_mb = NULL;
852 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
854 * First make sure the sb will be happy, we don't use these
855 * except maybe the count
857 so->so_snd.sb_cc = 0;
858 so->so_snd.sb_mbcnt = 0;
859 so->so_snd.sb_mb = NULL;
866 sctp_shutdown(struct socket *so)
868 struct sctp_inpcb *inp;
870 inp = (struct sctp_inpcb *)so->so_pcb;
872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
876 /* For UDP model this is a invalid call */
877 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
878 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
879 /* Restore the flags that the soshutdown took away. */
880 SOCKBUF_LOCK(&so->so_rcv);
881 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
882 SOCKBUF_UNLOCK(&so->so_rcv);
883 /* This proc will wakeup for read and do nothing (I hope) */
884 SCTP_INP_RUNLOCK(inp);
885 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
889 * Ok, if we reach here its the TCP model and it is either a
890 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
893 struct sctp_tcb *stcb;
894 struct sctp_association *asoc;
895 struct sctp_nets *netp;
898 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
899 SCTP_INP_RUNLOCK(inp);
904 stcb = LIST_FIRST(&inp->sctp_asoc_list);
907 * Ok, we hit the case that the shutdown call was
908 * made after an abort or something. Nothing to do
911 SCTP_INP_RUNLOCK(inp);
916 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
917 SCTP_TCB_UNLOCK(stcb);
918 SCTP_INP_RUNLOCK(inp);
921 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) &&
922 (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) &&
923 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) {
925 * If we are not in or before ESTABLISHED, there is
926 * no protocol action required.
928 SCTP_TCB_UNLOCK(stcb);
929 SCTP_INP_RUNLOCK(inp);
932 if (stcb->asoc.alternate) {
933 netp = stcb->asoc.alternate;
935 netp = stcb->asoc.primary_destination;
937 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) &&
938 TAILQ_EMPTY(&asoc->send_queue) &&
939 TAILQ_EMPTY(&asoc->sent_queue) &&
940 (asoc->stream_queue_cnt == 0)) {
941 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
944 /* there is nothing queued to send, so I'm done... */
945 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
946 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
947 sctp_stop_timers_for_shutdown(stcb);
948 sctp_send_shutdown(stcb, netp);
949 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
950 stcb->sctp_ep, stcb, netp);
953 * We still got (or just got) data to send, so set
956 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
957 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
958 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
960 if (TAILQ_EMPTY(&asoc->send_queue) &&
961 TAILQ_EMPTY(&asoc->sent_queue) &&
962 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
966 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
967 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
968 SCTP_INP_RUNLOCK(inp);
969 sctp_abort_an_association(stcb->sctp_ep, stcb,
970 op_err, SCTP_SO_LOCKED);
974 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp);
976 * XXX: Why do this in the case where we have still data
979 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
980 SCTP_TCB_UNLOCK(stcb);
981 SCTP_INP_RUNLOCK(inp);
987 * copies a "user" presentable address and removes embedded scope, etc.
988 * returns 0 on success, 1 on error
991 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
994 struct sockaddr_in6 lsa6;
996 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
999 memcpy(ss, sa, sa->sa_len);
1006 * NOTE: assumes addr lock is held
1009 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1010 struct sctp_tcb *stcb,
1012 struct sockaddr_storage *sas,
1015 struct sctp_ifn *sctp_ifn;
1016 struct sctp_ifa *sctp_ifa;
1020 int ipv4_local_scope, ipv4_addr_legal;
1023 int local_scope, site_scope, ipv6_addr_legal;
1025 struct sctp_vrf *vrf;
1032 /* Turn on all the appropriate scope */
1033 loopback_scope = stcb->asoc.scope.loopback_scope;
1035 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1036 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1039 local_scope = stcb->asoc.scope.local_scope;
1040 site_scope = stcb->asoc.scope.site_scope;
1041 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1044 /* Use generic values for endpoints. */
1047 ipv4_local_scope = 1;
1053 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1055 ipv6_addr_legal = 1;
1058 if (SCTP_IPV6_V6ONLY(inp)) {
1059 ipv4_addr_legal = 0;
1061 ipv4_addr_legal = 1;
1066 ipv6_addr_legal = 0;
1069 ipv4_addr_legal = 1;
1073 vrf = sctp_find_vrf(vrf_id);
1077 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1078 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1079 if ((loopback_scope == 0) &&
1080 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1081 /* Skip loopback if loopback_scope not set */
1084 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1087 * For the BOUND-ALL case, the list
1088 * associated with a TCB is Always
1089 * considered a reverse list.. i.e.
1090 * it lists addresses that are NOT
1091 * part of the association. If this
1092 * is one of those we must skip it.
1094 if (sctp_is_addr_restricted(stcb,
1099 switch (sctp_ifa->address.sa.sa_family) {
1102 if (ipv4_addr_legal) {
1103 struct sockaddr_in *sin;
1105 sin = &sctp_ifa->address.sin;
1106 if (sin->sin_addr.s_addr == 0) {
1114 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1115 &sin->sin_addr) != 0) {
1118 if ((ipv4_local_scope == 0) &&
1119 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1123 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1124 if (actual + sizeof(struct sockaddr_in6) > limit) {
1127 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1128 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1129 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1130 actual += sizeof(struct sockaddr_in6);
1133 if (actual + sizeof(struct sockaddr_in) > limit) {
1136 memcpy(sas, sin, sizeof(struct sockaddr_in));
1137 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1138 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in));
1139 actual += sizeof(struct sockaddr_in);
1150 if (ipv6_addr_legal) {
1151 struct sockaddr_in6 *sin6;
1153 sin6 = &sctp_ifa->address.sin6;
1154 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1162 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1163 &sin6->sin6_addr) != 0) {
1166 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1167 if (local_scope == 0)
1169 if (sin6->sin6_scope_id == 0) {
1170 if (sa6_recoverscope(sin6) != 0)
1183 if ((site_scope == 0) &&
1184 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1187 if (actual + sizeof(struct sockaddr_in6) > limit) {
1190 memcpy(sas, sin6, sizeof(struct sockaddr_in6));
1191 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1192 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1193 actual += sizeof(struct sockaddr_in6);
1206 struct sctp_laddr *laddr;
1209 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1211 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1215 sa_len = laddr->ifa->address.sa.sa_len;
1216 if (actual + sa_len > limit) {
1219 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1221 switch (laddr->ifa->address.sa.sa_family) {
1224 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1229 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1236 sas = (struct sockaddr_storage *)((caddr_t)sas + sa_len);
1244 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1245 struct sctp_tcb *stcb,
1247 struct sockaddr_storage *sas)
1251 SCTP_IPI_ADDR_RLOCK();
1252 /* fill up addresses for the endpoint's default vrf */
1253 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1255 SCTP_IPI_ADDR_RUNLOCK();
1260 * NOTE: assumes addr lock is held
1263 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1266 struct sctp_vrf *vrf = NULL;
1269 * In both sub-set bound an bound_all cases we return the MAXIMUM
1270 * number of addresses that you COULD get. In reality the sub-set
1271 * bound may have an exclusion list for a given TCB OR in the
1272 * bound-all case a TCB may NOT include the loopback or other
1273 * addresses as well.
1275 vrf = sctp_find_vrf(vrf_id);
1279 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1280 struct sctp_ifn *sctp_ifn;
1281 struct sctp_ifa *sctp_ifa;
1283 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1284 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1285 /* Count them if they are the right type */
1286 switch (sctp_ifa->address.sa.sa_family) {
1290 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1291 cnt += sizeof(struct sockaddr_in6);
1293 cnt += sizeof(struct sockaddr_in);
1295 cnt += sizeof(struct sockaddr_in);
1301 cnt += sizeof(struct sockaddr_in6);
1310 struct sctp_laddr *laddr;
1312 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1313 switch (laddr->ifa->address.sa.sa_family) {
1317 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1318 cnt += sizeof(struct sockaddr_in6);
1320 cnt += sizeof(struct sockaddr_in);
1322 cnt += sizeof(struct sockaddr_in);
1328 cnt += sizeof(struct sockaddr_in6);
1340 sctp_count_max_addresses(struct sctp_inpcb *inp)
1344 SCTP_IPI_ADDR_RLOCK();
1345 /* count addresses for the endpoint's default VRF */
1346 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1347 SCTP_IPI_ADDR_RUNLOCK();
1352 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1353 size_t optsize, void *p, int delay)
1356 int creat_lock_on = 0;
1357 struct sctp_tcb *stcb = NULL;
1358 struct sockaddr *sa;
1359 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1363 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1365 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1366 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1367 /* We are already connected AND the TCP model */
1368 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1369 return (EADDRINUSE);
1372 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1373 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1374 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1378 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1379 SCTP_INP_RLOCK(inp);
1380 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1381 SCTP_INP_RUNLOCK(inp);
1384 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1387 SCTP_INP_INCR_REF(inp);
1388 SCTP_ASOC_CREATE_LOCK(inp);
1390 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1391 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1392 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1396 totaddrp = (unsigned int *)optval;
1397 totaddr = *totaddrp;
1398 sa = (struct sockaddr *)(totaddrp + 1);
1399 error = sctp_connectx_helper_find(inp, sa, totaddr, &num_v4, &num_v6, (unsigned int)(optsize - sizeof(int)));
1401 /* Already have or am bring up an association */
1402 SCTP_ASOC_CREATE_UNLOCK(inp);
1404 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1408 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1413 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1415 if (SCTP_IPV6_V6ONLY(inp)) {
1417 * if IPV6_V6ONLY flag, ignore connections destined
1418 * to a v4 addr or v4-mapped addr
1420 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1426 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1427 SCTP_PCB_FLAGS_UNBOUND) {
1428 /* Bind a ephemeral port */
1429 error = sctp_inpcb_bind(so, NULL, NULL, p);
1435 /* FIX ME: do we want to pass in a vrf on the connect call? */
1436 vrf_id = inp->def_vrf_id;
1439 /* We are GOOD to go */
1440 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1441 inp->sctp_ep.pre_open_stream_count,
1444 SCTP_INITIALIZE_AUTH_PARAMS);
1446 /* Gak! no memory */
1449 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1450 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1451 /* Set the connected flag so we can queue data */
1454 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1455 /* move to second address */
1456 switch (sa->sa_family) {
1459 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1464 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1472 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1473 /* Fill in the return id */
1477 a_id = (sctp_assoc_t *)optval;
1478 *a_id = sctp_get_associd(stcb);
1481 /* doing delayed connection */
1482 stcb->asoc.delayed_connection = 1;
1483 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1485 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1486 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1488 SCTP_TCB_UNLOCK(stcb);
1490 if (creat_lock_on) {
1491 SCTP_ASOC_CREATE_UNLOCK(inp);
1493 SCTP_INP_DECR_REF(inp);
1497 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1498 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1499 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1500 SCTP_INP_RLOCK(inp); \
1501 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1503 SCTP_TCB_LOCK(stcb); \
1505 SCTP_INP_RUNLOCK(inp); \
1506 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1507 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1508 if (stcb == NULL) { \
1509 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1519 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1520 if (size < sizeof(type)) { \
1521 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1525 destp = (type *)srcp; \
1530 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1533 struct sctp_inpcb *inp = NULL;
1535 struct sctp_tcb *stcb = NULL;
1537 if (optval == NULL) {
1538 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1542 inp = (struct sctp_inpcb *)so->so_pcb;
1544 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1551 case SCTP_AUTOCLOSE:
1552 case SCTP_EXPLICIT_EOR:
1553 case SCTP_AUTO_ASCONF:
1554 case SCTP_DISABLE_FRAGMENTS:
1555 case SCTP_I_WANT_MAPPED_V4_ADDR:
1556 case SCTP_USE_EXT_RCVINFO:
1557 SCTP_INP_RLOCK(inp);
1559 case SCTP_DISABLE_FRAGMENTS:
1560 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1562 case SCTP_I_WANT_MAPPED_V4_ADDR:
1563 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1565 case SCTP_AUTO_ASCONF:
1566 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1567 /* only valid for bound all sockets */
1568 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1570 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1575 case SCTP_EXPLICIT_EOR:
1576 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1579 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1581 case SCTP_USE_EXT_RCVINFO:
1582 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1584 case SCTP_AUTOCLOSE:
1585 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1586 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1592 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1593 error = ENOPROTOOPT;
1594 } /* end switch (sopt->sopt_name) */
1595 if (*optsize < sizeof(val)) {
1596 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1600 SCTP_INP_RUNLOCK(inp);
1602 /* return the option value */
1603 *(int *)optval = val;
1604 *optsize = sizeof(val);
1607 case SCTP_GET_PACKET_LOG:
1609 #ifdef SCTP_PACKET_LOGGING
1613 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1614 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1617 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1622 case SCTP_REUSE_PORT:
1626 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1627 /* Can't do this for a 1-m socket */
1631 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1632 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1633 *optsize = sizeof(uint32_t);
1636 case SCTP_PARTIAL_DELIVERY_POINT:
1640 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1641 *value = inp->partial_delivery_point;
1642 *optsize = sizeof(uint32_t);
1645 case SCTP_FRAGMENT_INTERLEAVE:
1649 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1650 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1651 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1652 *value = SCTP_FRAG_LEVEL_2;
1654 *value = SCTP_FRAG_LEVEL_1;
1657 *value = SCTP_FRAG_LEVEL_0;
1659 *optsize = sizeof(uint32_t);
1662 case SCTP_INTERLEAVING_SUPPORTED:
1664 struct sctp_assoc_value *av;
1666 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1667 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1670 av->assoc_value = stcb->asoc.idata_supported;
1671 SCTP_TCB_UNLOCK(stcb);
1673 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1674 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1675 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1676 SCTP_INP_RLOCK(inp);
1677 if (inp->idata_supported) {
1678 av->assoc_value = 1;
1680 av->assoc_value = 0;
1682 SCTP_INP_RUNLOCK(inp);
1684 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1689 *optsize = sizeof(struct sctp_assoc_value);
1693 case SCTP_CMT_ON_OFF:
1695 struct sctp_assoc_value *av;
1697 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1698 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1700 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1701 SCTP_TCB_UNLOCK(stcb);
1703 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1704 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1705 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1706 SCTP_INP_RLOCK(inp);
1707 av->assoc_value = inp->sctp_cmt_on_off;
1708 SCTP_INP_RUNLOCK(inp);
1710 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1715 *optsize = sizeof(struct sctp_assoc_value);
1719 case SCTP_PLUGGABLE_CC:
1721 struct sctp_assoc_value *av;
1723 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1724 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1726 av->assoc_value = stcb->asoc.congestion_control_module;
1727 SCTP_TCB_UNLOCK(stcb);
1729 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1730 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1731 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1732 SCTP_INP_RLOCK(inp);
1733 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1734 SCTP_INP_RUNLOCK(inp);
1736 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1741 *optsize = sizeof(struct sctp_assoc_value);
1745 case SCTP_CC_OPTION:
1747 struct sctp_cc_option *cc_opt;
1749 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1750 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1754 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1757 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1758 *optsize = sizeof(struct sctp_cc_option);
1760 SCTP_TCB_UNLOCK(stcb);
1764 case SCTP_PLUGGABLE_SS:
1766 struct sctp_assoc_value *av;
1768 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1769 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1771 av->assoc_value = stcb->asoc.stream_scheduling_module;
1772 SCTP_TCB_UNLOCK(stcb);
1774 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1775 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1776 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1777 SCTP_INP_RLOCK(inp);
1778 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1779 SCTP_INP_RUNLOCK(inp);
1781 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1786 *optsize = sizeof(struct sctp_assoc_value);
1792 struct sctp_stream_value *av;
1794 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1795 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1797 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1798 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1799 &av->stream_value) < 0)) {
1800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1803 *optsize = sizeof(struct sctp_stream_value);
1805 SCTP_TCB_UNLOCK(stcb);
1808 * Can't get stream value without
1811 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1816 case SCTP_GET_ADDR_LEN:
1818 struct sctp_assoc_value *av;
1820 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1823 if (av->assoc_value == AF_INET) {
1824 av->assoc_value = sizeof(struct sockaddr_in);
1829 if (av->assoc_value == AF_INET6) {
1830 av->assoc_value = sizeof(struct sockaddr_in6);
1835 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1837 *optsize = sizeof(struct sctp_assoc_value);
1841 case SCTP_GET_ASSOC_NUMBER:
1843 uint32_t *value, cnt;
1845 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1846 SCTP_INP_RLOCK(inp);
1847 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1848 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1849 /* Can't do this for a 1-1 socket */
1851 SCTP_INP_RUNLOCK(inp);
1855 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1858 SCTP_INP_RUNLOCK(inp);
1860 *optsize = sizeof(uint32_t);
1863 case SCTP_GET_ASSOC_ID_LIST:
1865 struct sctp_assoc_ids *ids;
1869 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1870 SCTP_INP_RLOCK(inp);
1871 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1872 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1873 /* Can't do this for a 1-1 socket */
1875 SCTP_INP_RUNLOCK(inp);
1879 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1880 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1882 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1885 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1890 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1894 SCTP_INP_RUNLOCK(inp);
1896 ids->gaids_number_of_ids = at;
1897 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1903 struct sctp_assoc_value *av;
1905 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1906 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1909 av->assoc_value = stcb->asoc.context;
1910 SCTP_TCB_UNLOCK(stcb);
1912 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1913 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1914 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1915 SCTP_INP_RLOCK(inp);
1916 av->assoc_value = inp->sctp_context;
1917 SCTP_INP_RUNLOCK(inp);
1919 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1924 *optsize = sizeof(struct sctp_assoc_value);
1930 uint32_t *default_vrfid;
1932 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1933 *default_vrfid = inp->def_vrf_id;
1934 *optsize = sizeof(uint32_t);
1937 case SCTP_GET_ASOC_VRF:
1939 struct sctp_assoc_value *id;
1941 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1942 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1945 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1947 id->assoc_value = stcb->asoc.vrf_id;
1948 SCTP_TCB_UNLOCK(stcb);
1949 *optsize = sizeof(struct sctp_assoc_value);
1953 case SCTP_GET_VRF_IDS:
1955 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1959 case SCTP_GET_NONCE_VALUES:
1961 struct sctp_get_nonce_values *gnv;
1963 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1964 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1967 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1968 gnv->gn_local_tag = stcb->asoc.my_vtag;
1969 SCTP_TCB_UNLOCK(stcb);
1970 *optsize = sizeof(struct sctp_get_nonce_values);
1972 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1977 case SCTP_DELAYED_SACK:
1979 struct sctp_sack_info *sack;
1981 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1982 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1984 sack->sack_delay = stcb->asoc.delayed_ack;
1985 sack->sack_freq = stcb->asoc.sack_freq;
1986 SCTP_TCB_UNLOCK(stcb);
1988 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1989 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1990 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
1991 SCTP_INP_RLOCK(inp);
1992 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1993 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
1994 SCTP_INP_RUNLOCK(inp);
1996 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2001 *optsize = sizeof(struct sctp_sack_info);
2005 case SCTP_GET_SNDBUF_USE:
2007 struct sctp_sockstat *ss;
2009 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2010 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2013 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2014 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2015 stcb->asoc.size_on_all_streams);
2016 SCTP_TCB_UNLOCK(stcb);
2017 *optsize = sizeof(struct sctp_sockstat);
2019 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2024 case SCTP_MAX_BURST:
2026 struct sctp_assoc_value *av;
2028 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2029 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2032 av->assoc_value = stcb->asoc.max_burst;
2033 SCTP_TCB_UNLOCK(stcb);
2035 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2036 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2037 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2038 SCTP_INP_RLOCK(inp);
2039 av->assoc_value = inp->sctp_ep.max_burst;
2040 SCTP_INP_RUNLOCK(inp);
2042 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2047 *optsize = sizeof(struct sctp_assoc_value);
2053 struct sctp_assoc_value *av;
2056 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2057 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2060 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2061 SCTP_TCB_UNLOCK(stcb);
2063 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2064 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2065 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2066 SCTP_INP_RLOCK(inp);
2067 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2068 ovh = SCTP_MED_OVERHEAD;
2070 ovh = SCTP_MED_V4_OVERHEAD;
2072 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2073 av->assoc_value = 0;
2075 av->assoc_value = inp->sctp_frag_point - ovh;
2076 SCTP_INP_RUNLOCK(inp);
2078 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2083 *optsize = sizeof(struct sctp_assoc_value);
2087 case SCTP_GET_STAT_LOG:
2088 error = sctp_fill_stat_log(optval, optsize);
2092 struct sctp_event_subscribe *events;
2094 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2095 memset(events, 0, sizeof(struct sctp_event_subscribe));
2096 SCTP_INP_RLOCK(inp);
2097 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2098 events->sctp_data_io_event = 1;
2100 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2101 events->sctp_association_event = 1;
2103 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2104 events->sctp_address_event = 1;
2106 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2107 events->sctp_send_failure_event = 1;
2109 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2110 events->sctp_peer_error_event = 1;
2112 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2113 events->sctp_shutdown_event = 1;
2115 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2116 events->sctp_partial_delivery_event = 1;
2118 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2119 events->sctp_adaptation_layer_event = 1;
2121 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2122 events->sctp_authentication_event = 1;
2124 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2125 events->sctp_sender_dry_event = 1;
2127 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2128 events->sctp_stream_reset_event = 1;
2129 SCTP_INP_RUNLOCK(inp);
2130 *optsize = sizeof(struct sctp_event_subscribe);
2133 case SCTP_ADAPTATION_LAYER:
2137 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2139 SCTP_INP_RLOCK(inp);
2140 *value = inp->sctp_ep.adaptation_layer_indicator;
2141 SCTP_INP_RUNLOCK(inp);
2142 *optsize = sizeof(uint32_t);
2145 case SCTP_SET_INITIAL_DBG_SEQ:
2149 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2150 SCTP_INP_RLOCK(inp);
2151 *value = inp->sctp_ep.initial_sequence_debug;
2152 SCTP_INP_RUNLOCK(inp);
2153 *optsize = sizeof(uint32_t);
2156 case SCTP_GET_LOCAL_ADDR_SIZE:
2160 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2161 SCTP_INP_RLOCK(inp);
2162 *value = sctp_count_max_addresses(inp);
2163 SCTP_INP_RUNLOCK(inp);
2164 *optsize = sizeof(uint32_t);
2167 case SCTP_GET_REMOTE_ADDR_SIZE:
2171 struct sctp_nets *net;
2173 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2174 /* FIXME MT: change to sctp_assoc_value? */
2175 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2179 /* Count the sizes */
2180 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2181 switch (net->ro._l_addr.sa.sa_family) {
2185 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2186 size += sizeof(struct sockaddr_in6);
2188 size += sizeof(struct sockaddr_in);
2191 size += sizeof(struct sockaddr_in);
2197 size += sizeof(struct sockaddr_in6);
2204 SCTP_TCB_UNLOCK(stcb);
2205 *value = (uint32_t)size;
2206 *optsize = sizeof(uint32_t);
2208 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2213 case SCTP_GET_PEER_ADDRESSES:
2215 * Get the address information, an array is passed in to
2216 * fill up we pack it.
2220 struct sockaddr_storage *sas;
2221 struct sctp_nets *net;
2222 struct sctp_getaddresses *saddr;
2224 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2225 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2228 left = (*optsize) - sizeof(sctp_assoc_t);
2229 *optsize = sizeof(sctp_assoc_t);
2230 sas = (struct sockaddr_storage *)&saddr->addr[0];
2232 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2233 switch (net->ro._l_addr.sa.sa_family) {
2237 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2238 cpsz = sizeof(struct sockaddr_in6);
2240 cpsz = sizeof(struct sockaddr_in);
2243 cpsz = sizeof(struct sockaddr_in);
2249 cpsz = sizeof(struct sockaddr_in6);
2260 /* not enough room. */
2263 #if defined(INET) && defined(INET6)
2264 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2265 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2266 /* Must map the address */
2267 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2268 (struct sockaddr_in6 *)sas);
2270 memcpy(sas, &net->ro._l_addr, cpsz);
2273 memcpy(sas, &net->ro._l_addr, cpsz);
2275 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2277 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2281 SCTP_TCB_UNLOCK(stcb);
2283 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2288 case SCTP_GET_LOCAL_ADDRESSES:
2290 size_t limit, actual;
2291 struct sockaddr_storage *sas;
2292 struct sctp_getaddresses *saddr;
2294 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2295 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2297 sas = (struct sockaddr_storage *)&saddr->addr[0];
2298 limit = *optsize - sizeof(sctp_assoc_t);
2299 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2301 SCTP_TCB_UNLOCK(stcb);
2303 *optsize = sizeof(sctp_assoc_t) + actual;
2306 case SCTP_PEER_ADDR_PARAMS:
2308 struct sctp_paddrparams *paddrp;
2309 struct sctp_nets *net;
2310 struct sockaddr *addr;
2311 #if defined(INET) && defined(INET6)
2312 struct sockaddr_in sin_store;
2315 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2316 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2318 #if defined(INET) && defined(INET6)
2319 if (paddrp->spp_address.ss_family == AF_INET6) {
2320 struct sockaddr_in6 *sin6;
2322 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2323 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2324 in6_sin6_2_sin(&sin_store, sin6);
2325 addr = (struct sockaddr *)&sin_store;
2327 addr = (struct sockaddr *)&paddrp->spp_address;
2330 addr = (struct sockaddr *)&paddrp->spp_address;
2333 addr = (struct sockaddr *)&paddrp->spp_address;
2336 net = sctp_findnet(stcb, addr);
2339 * We increment here since
2340 * sctp_findassociation_ep_addr() wil do a
2341 * decrement if it finds the stcb as long as
2342 * the locked tcb (last argument) is NOT a
2346 SCTP_INP_INCR_REF(inp);
2347 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2349 SCTP_INP_DECR_REF(inp);
2352 if ((stcb != NULL) && (net == NULL)) {
2354 if (addr->sa_family == AF_INET) {
2355 struct sockaddr_in *sin;
2357 sin = (struct sockaddr_in *)addr;
2358 if (sin->sin_addr.s_addr != INADDR_ANY) {
2360 SCTP_TCB_UNLOCK(stcb);
2361 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2367 if (addr->sa_family == AF_INET6) {
2368 struct sockaddr_in6 *sin6;
2370 sin6 = (struct sockaddr_in6 *)addr;
2371 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2373 SCTP_TCB_UNLOCK(stcb);
2374 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2380 error = EAFNOSUPPORT;
2381 SCTP_TCB_UNLOCK(stcb);
2382 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2388 /* Applies to the specific association */
2389 paddrp->spp_flags = 0;
2391 paddrp->spp_hbinterval = net->heart_beat_delay;
2392 paddrp->spp_pathmaxrxt = net->failure_threshold;
2393 paddrp->spp_pathmtu = net->mtu;
2394 switch (net->ro._l_addr.sa.sa_family) {
2397 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2402 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2408 /* get flags for HB */
2409 if (net->dest_state & SCTP_ADDR_NOHB) {
2410 paddrp->spp_flags |= SPP_HB_DISABLE;
2412 paddrp->spp_flags |= SPP_HB_ENABLE;
2414 /* get flags for PMTU */
2415 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2416 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2418 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2420 if (net->dscp & 0x01) {
2421 paddrp->spp_dscp = net->dscp & 0xfc;
2422 paddrp->spp_flags |= SPP_DSCP;
2425 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2426 (net->flowlabel & 0x80000000)) {
2427 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2428 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2433 * No destination so return default
2436 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2437 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2438 if (stcb->asoc.default_dscp & 0x01) {
2439 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2440 paddrp->spp_flags |= SPP_DSCP;
2443 if (stcb->asoc.default_flowlabel & 0x80000000) {
2444 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2445 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2448 /* default settings should be these */
2449 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2450 paddrp->spp_flags |= SPP_HB_DISABLE;
2452 paddrp->spp_flags |= SPP_HB_ENABLE;
2454 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2455 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2457 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2459 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2461 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2462 SCTP_TCB_UNLOCK(stcb);
2464 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2465 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2466 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2467 /* Use endpoint defaults */
2468 SCTP_INP_RLOCK(inp);
2469 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2470 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2471 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2472 /* get inp's default */
2473 if (inp->sctp_ep.default_dscp & 0x01) {
2474 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2475 paddrp->spp_flags |= SPP_DSCP;
2478 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2479 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2480 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2481 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2484 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2486 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2487 paddrp->spp_flags |= SPP_HB_ENABLE;
2489 paddrp->spp_flags |= SPP_HB_DISABLE;
2491 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2492 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2494 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2496 SCTP_INP_RUNLOCK(inp);
2498 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2503 *optsize = sizeof(struct sctp_paddrparams);
2507 case SCTP_GET_PEER_ADDR_INFO:
2509 struct sctp_paddrinfo *paddri;
2510 struct sctp_nets *net;
2511 struct sockaddr *addr;
2512 #if defined(INET) && defined(INET6)
2513 struct sockaddr_in sin_store;
2516 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2517 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2519 #if defined(INET) && defined(INET6)
2520 if (paddri->spinfo_address.ss_family == AF_INET6) {
2521 struct sockaddr_in6 *sin6;
2523 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2524 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2525 in6_sin6_2_sin(&sin_store, sin6);
2526 addr = (struct sockaddr *)&sin_store;
2528 addr = (struct sockaddr *)&paddri->spinfo_address;
2531 addr = (struct sockaddr *)&paddri->spinfo_address;
2534 addr = (struct sockaddr *)&paddri->spinfo_address;
2537 net = sctp_findnet(stcb, addr);
2540 * We increment here since
2541 * sctp_findassociation_ep_addr() wil do a
2542 * decrement if it finds the stcb as long as
2543 * the locked tcb (last argument) is NOT a
2547 SCTP_INP_INCR_REF(inp);
2548 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2550 SCTP_INP_DECR_REF(inp);
2554 if ((stcb != NULL) && (net != NULL)) {
2555 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2556 /* It's unconfirmed */
2557 paddri->spinfo_state = SCTP_UNCONFIRMED;
2558 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2560 paddri->spinfo_state = SCTP_ACTIVE;
2563 paddri->spinfo_state = SCTP_INACTIVE;
2565 paddri->spinfo_cwnd = net->cwnd;
2566 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2567 paddri->spinfo_rto = net->RTO;
2568 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2569 paddri->spinfo_mtu = net->mtu;
2570 switch (addr->sa_family) {
2573 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2578 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2584 SCTP_TCB_UNLOCK(stcb);
2585 *optsize = sizeof(struct sctp_paddrinfo);
2588 SCTP_TCB_UNLOCK(stcb);
2590 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2595 case SCTP_PCB_STATUS:
2597 struct sctp_pcbinfo *spcb;
2599 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2600 sctp_fill_pcbinfo(spcb);
2601 *optsize = sizeof(struct sctp_pcbinfo);
2606 struct sctp_nets *net;
2607 struct sctp_status *sstat;
2609 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2610 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2613 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2617 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2618 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2619 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2620 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2622 * We can't include chunks that have been passed to
2623 * the socket layer. Only things in queue.
2625 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2626 stcb->asoc.cnt_on_all_streams);
2629 sstat->sstat_instrms = stcb->asoc.streamincnt;
2630 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2631 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2632 net = stcb->asoc.primary_destination;
2634 memcpy(&sstat->sstat_primary.spinfo_address,
2635 &stcb->asoc.primary_destination->ro._l_addr,
2636 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2637 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2639 * Again the user can get info from
2640 * sctp_constants.h for what the state of
2643 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2644 /* It's unconfirmed */
2645 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2646 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2648 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2651 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2653 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2654 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2655 sstat->sstat_primary.spinfo_rto = net->RTO;
2656 sstat->sstat_primary.spinfo_mtu = net->mtu;
2657 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2660 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2665 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2672 memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo));
2674 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2675 SCTP_TCB_UNLOCK(stcb);
2676 *optsize = sizeof(struct sctp_status);
2681 struct sctp_rtoinfo *srto;
2683 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2684 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2687 srto->srto_initial = stcb->asoc.initial_rto;
2688 srto->srto_max = stcb->asoc.maxrto;
2689 srto->srto_min = stcb->asoc.minrto;
2690 SCTP_TCB_UNLOCK(stcb);
2692 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2693 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2694 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2695 SCTP_INP_RLOCK(inp);
2696 srto->srto_initial = inp->sctp_ep.initial_rto;
2697 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2698 srto->srto_min = inp->sctp_ep.sctp_minrto;
2699 SCTP_INP_RUNLOCK(inp);
2701 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2706 *optsize = sizeof(struct sctp_rtoinfo);
2712 struct sctp_timeouts *stimo;
2714 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2715 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2718 stimo->stimo_init = stcb->asoc.timoinit;
2719 stimo->stimo_data = stcb->asoc.timodata;
2720 stimo->stimo_sack = stcb->asoc.timosack;
2721 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2722 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2723 stimo->stimo_cookie = stcb->asoc.timocookie;
2724 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2725 SCTP_TCB_UNLOCK(stcb);
2726 *optsize = sizeof(struct sctp_timeouts);
2728 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2733 case SCTP_ASSOCINFO:
2735 struct sctp_assocparams *sasoc;
2737 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2738 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2741 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2742 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2743 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2744 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2745 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2746 SCTP_TCB_UNLOCK(stcb);
2748 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2749 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2750 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2751 SCTP_INP_RLOCK(inp);
2752 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2753 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2754 sasoc->sasoc_number_peer_destinations = 0;
2755 sasoc->sasoc_peer_rwnd = 0;
2756 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2757 SCTP_INP_RUNLOCK(inp);
2759 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2764 *optsize = sizeof(struct sctp_assocparams);
2768 case SCTP_DEFAULT_SEND_PARAM:
2770 struct sctp_sndrcvinfo *s_info;
2772 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2773 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2776 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2777 SCTP_TCB_UNLOCK(stcb);
2779 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2780 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2781 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2782 SCTP_INP_RLOCK(inp);
2783 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2784 SCTP_INP_RUNLOCK(inp);
2786 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2791 *optsize = sizeof(struct sctp_sndrcvinfo);
2797 struct sctp_initmsg *sinit;
2799 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2800 SCTP_INP_RLOCK(inp);
2801 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2802 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2803 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2804 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2805 SCTP_INP_RUNLOCK(inp);
2806 *optsize = sizeof(struct sctp_initmsg);
2809 case SCTP_PRIMARY_ADDR:
2810 /* we allow a "get" operation on this */
2812 struct sctp_setprim *ssp;
2814 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2815 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2818 union sctp_sockstore *addr;
2820 addr = &stcb->asoc.primary_destination->ro._l_addr;
2821 switch (addr->sa.sa_family) {
2825 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2826 in6_sin_2_v4mapsin6(&addr->sin,
2827 (struct sockaddr_in6 *)&ssp->ssp_addr);
2829 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2832 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2838 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2844 SCTP_TCB_UNLOCK(stcb);
2845 *optsize = sizeof(struct sctp_setprim);
2847 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2852 case SCTP_HMAC_IDENT:
2854 struct sctp_hmacalgo *shmac;
2855 sctp_hmaclist_t *hmaclist;
2859 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2861 SCTP_INP_RLOCK(inp);
2862 hmaclist = inp->sctp_ep.local_hmacs;
2863 if (hmaclist == NULL) {
2864 /* no HMACs to return */
2865 *optsize = sizeof(*shmac);
2866 SCTP_INP_RUNLOCK(inp);
2869 /* is there room for all of the hmac ids? */
2870 size = sizeof(*shmac) + (hmaclist->num_algo *
2871 sizeof(shmac->shmac_idents[0]));
2872 if ((size_t)(*optsize) < size) {
2873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2875 SCTP_INP_RUNLOCK(inp);
2878 /* copy in the list */
2879 shmac->shmac_number_of_idents = hmaclist->num_algo;
2880 for (i = 0; i < hmaclist->num_algo; i++) {
2881 shmac->shmac_idents[i] = hmaclist->hmac[i];
2883 SCTP_INP_RUNLOCK(inp);
2887 case SCTP_AUTH_ACTIVE_KEY:
2889 struct sctp_authkeyid *scact;
2891 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2892 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2895 /* get the active key on the assoc */
2896 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2897 SCTP_TCB_UNLOCK(stcb);
2899 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2900 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2901 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2902 /* get the endpoint active key */
2903 SCTP_INP_RLOCK(inp);
2904 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2905 SCTP_INP_RUNLOCK(inp);
2907 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2912 *optsize = sizeof(struct sctp_authkeyid);
2916 case SCTP_LOCAL_AUTH_CHUNKS:
2918 struct sctp_authchunks *sac;
2919 sctp_auth_chklist_t *chklist = NULL;
2922 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2923 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2926 /* get off the assoc */
2927 chklist = stcb->asoc.local_auth_chunks;
2928 /* is there enough space? */
2929 size = sctp_auth_get_chklist_size(chklist);
2930 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2932 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2934 /* copy in the chunks */
2935 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2936 sac->gauth_number_of_chunks = (uint32_t)size;
2937 *optsize = sizeof(struct sctp_authchunks) + size;
2939 SCTP_TCB_UNLOCK(stcb);
2941 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2942 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2943 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2944 /* get off the endpoint */
2945 SCTP_INP_RLOCK(inp);
2946 chklist = inp->sctp_ep.local_auth_chunks;
2947 /* is there enough space? */
2948 size = sctp_auth_get_chklist_size(chklist);
2949 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2953 /* copy in the chunks */
2954 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2955 sac->gauth_number_of_chunks = (uint32_t)size;
2956 *optsize = sizeof(struct sctp_authchunks) + size;
2958 SCTP_INP_RUNLOCK(inp);
2960 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2966 case SCTP_PEER_AUTH_CHUNKS:
2968 struct sctp_authchunks *sac;
2969 sctp_auth_chklist_t *chklist = NULL;
2972 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2973 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2976 /* get off the assoc */
2977 chklist = stcb->asoc.peer_auth_chunks;
2978 /* is there enough space? */
2979 size = sctp_auth_get_chklist_size(chklist);
2980 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2984 /* copy in the chunks */
2985 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2986 sac->gauth_number_of_chunks = (uint32_t)size;
2987 *optsize = sizeof(struct sctp_authchunks) + size;
2989 SCTP_TCB_UNLOCK(stcb);
2991 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2998 struct sctp_event *event;
2999 uint32_t event_type;
3001 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3002 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3004 switch (event->se_type) {
3005 case SCTP_ASSOC_CHANGE:
3006 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3008 case SCTP_PEER_ADDR_CHANGE:
3009 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3011 case SCTP_REMOTE_ERROR:
3012 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3014 case SCTP_SEND_FAILED:
3015 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3017 case SCTP_SHUTDOWN_EVENT:
3018 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3020 case SCTP_ADAPTATION_INDICATION:
3021 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3023 case SCTP_PARTIAL_DELIVERY_EVENT:
3024 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3026 case SCTP_AUTHENTICATION_EVENT:
3027 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3029 case SCTP_STREAM_RESET_EVENT:
3030 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3032 case SCTP_SENDER_DRY_EVENT:
3033 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3035 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3037 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3040 case SCTP_ASSOC_RESET_EVENT:
3041 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3043 case SCTP_STREAM_CHANGE_EVENT:
3044 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3046 case SCTP_SEND_FAILED_EVENT:
3047 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3051 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3055 if (event_type > 0) {
3057 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3059 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3060 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3061 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3062 SCTP_INP_RLOCK(inp);
3063 event->se_on = sctp_is_feature_on(inp, event_type);
3064 SCTP_INP_RUNLOCK(inp);
3066 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3072 SCTP_TCB_UNLOCK(stcb);
3075 *optsize = sizeof(struct sctp_event);
3079 case SCTP_RECVRCVINFO:
3083 if (*optsize < sizeof(int)) {
3084 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3087 SCTP_INP_RLOCK(inp);
3088 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3089 SCTP_INP_RUNLOCK(inp);
3092 /* return the option value */
3093 *(int *)optval = onoff;
3094 *optsize = sizeof(int);
3098 case SCTP_RECVNXTINFO:
3102 if (*optsize < sizeof(int)) {
3103 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3106 SCTP_INP_RLOCK(inp);
3107 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3108 SCTP_INP_RUNLOCK(inp);
3111 /* return the option value */
3112 *(int *)optval = onoff;
3113 *optsize = sizeof(int);
3117 case SCTP_DEFAULT_SNDINFO:
3119 struct sctp_sndinfo *info;
3121 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3122 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3125 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3126 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3127 info->snd_flags &= 0xfff0;
3128 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3129 info->snd_context = stcb->asoc.def_send.sinfo_context;
3130 SCTP_TCB_UNLOCK(stcb);
3132 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3133 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3134 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3135 SCTP_INP_RLOCK(inp);
3136 info->snd_sid = inp->def_send.sinfo_stream;
3137 info->snd_flags = inp->def_send.sinfo_flags;
3138 info->snd_flags &= 0xfff0;
3139 info->snd_ppid = inp->def_send.sinfo_ppid;
3140 info->snd_context = inp->def_send.sinfo_context;
3141 SCTP_INP_RUNLOCK(inp);
3143 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3148 *optsize = sizeof(struct sctp_sndinfo);
3152 case SCTP_DEFAULT_PRINFO:
3154 struct sctp_default_prinfo *info;
3156 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3157 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3160 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3161 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3162 SCTP_TCB_UNLOCK(stcb);
3164 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3165 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3166 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3167 SCTP_INP_RLOCK(inp);
3168 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3169 info->pr_value = inp->def_send.sinfo_timetolive;
3170 SCTP_INP_RUNLOCK(inp);
3172 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3177 *optsize = sizeof(struct sctp_default_prinfo);
3181 case SCTP_PEER_ADDR_THLDS:
3183 struct sctp_paddrthlds *thlds;
3184 struct sctp_nets *net;
3185 struct sockaddr *addr;
3186 #if defined(INET) && defined(INET6)
3187 struct sockaddr_in sin_store;
3190 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3191 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3193 #if defined(INET) && defined(INET6)
3194 if (thlds->spt_address.ss_family == AF_INET6) {
3195 struct sockaddr_in6 *sin6;
3197 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3198 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3199 in6_sin6_2_sin(&sin_store, sin6);
3200 addr = (struct sockaddr *)&sin_store;
3202 addr = (struct sockaddr *)&thlds->spt_address;
3205 addr = (struct sockaddr *)&thlds->spt_address;
3208 addr = (struct sockaddr *)&thlds->spt_address;
3211 net = sctp_findnet(stcb, addr);
3214 * We increment here since
3215 * sctp_findassociation_ep_addr() wil do a
3216 * decrement if it finds the stcb as long as
3217 * the locked tcb (last argument) is NOT a
3221 SCTP_INP_INCR_REF(inp);
3222 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3224 SCTP_INP_DECR_REF(inp);
3227 if ((stcb != NULL) && (net == NULL)) {
3229 if (addr->sa_family == AF_INET) {
3230 struct sockaddr_in *sin;
3232 sin = (struct sockaddr_in *)addr;
3233 if (sin->sin_addr.s_addr != INADDR_ANY) {
3235 SCTP_TCB_UNLOCK(stcb);
3236 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3242 if (addr->sa_family == AF_INET6) {
3243 struct sockaddr_in6 *sin6;
3245 sin6 = (struct sockaddr_in6 *)addr;
3246 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3248 SCTP_TCB_UNLOCK(stcb);
3249 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3255 error = EAFNOSUPPORT;
3256 SCTP_TCB_UNLOCK(stcb);
3257 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3264 thlds->spt_pathmaxrxt = net->failure_threshold;
3265 thlds->spt_pathpfthld = net->pf_threshold;
3266 thlds->spt_pathcpthld = 0xffff;
3268 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3269 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3270 thlds->spt_pathcpthld = 0xffff;
3272 thlds->spt_assoc_id = sctp_get_associd(stcb);
3273 SCTP_TCB_UNLOCK(stcb);
3275 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3276 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3277 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3278 /* Use endpoint defaults */
3279 SCTP_INP_RLOCK(inp);
3280 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3281 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3282 thlds->spt_pathcpthld = 0xffff;
3283 SCTP_INP_RUNLOCK(inp);
3285 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3290 *optsize = sizeof(struct sctp_paddrthlds);
3294 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3296 struct sctp_udpencaps *encaps;
3297 struct sctp_nets *net;
3298 struct sockaddr *addr;
3299 #if defined(INET) && defined(INET6)
3300 struct sockaddr_in sin_store;
3303 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3304 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3306 #if defined(INET) && defined(INET6)
3307 if (encaps->sue_address.ss_family == AF_INET6) {
3308 struct sockaddr_in6 *sin6;
3310 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3311 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3312 in6_sin6_2_sin(&sin_store, sin6);
3313 addr = (struct sockaddr *)&sin_store;
3315 addr = (struct sockaddr *)&encaps->sue_address;
3318 addr = (struct sockaddr *)&encaps->sue_address;
3321 addr = (struct sockaddr *)&encaps->sue_address;
3324 net = sctp_findnet(stcb, addr);
3327 * We increment here since
3328 * sctp_findassociation_ep_addr() wil do a
3329 * decrement if it finds the stcb as long as
3330 * the locked tcb (last argument) is NOT a
3334 SCTP_INP_INCR_REF(inp);
3335 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3337 SCTP_INP_DECR_REF(inp);
3340 if ((stcb != NULL) && (net == NULL)) {
3342 if (addr->sa_family == AF_INET) {
3343 struct sockaddr_in *sin;
3345 sin = (struct sockaddr_in *)addr;
3346 if (sin->sin_addr.s_addr != INADDR_ANY) {
3348 SCTP_TCB_UNLOCK(stcb);
3349 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3355 if (addr->sa_family == AF_INET6) {
3356 struct sockaddr_in6 *sin6;
3358 sin6 = (struct sockaddr_in6 *)addr;
3359 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3361 SCTP_TCB_UNLOCK(stcb);
3362 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3368 error = EAFNOSUPPORT;
3369 SCTP_TCB_UNLOCK(stcb);
3370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3377 encaps->sue_port = net->port;
3379 encaps->sue_port = stcb->asoc.port;
3381 SCTP_TCB_UNLOCK(stcb);
3383 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3384 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3385 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3386 SCTP_INP_RLOCK(inp);
3387 encaps->sue_port = inp->sctp_ep.port;
3388 SCTP_INP_RUNLOCK(inp);
3390 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3395 *optsize = sizeof(struct sctp_udpencaps);
3399 case SCTP_ECN_SUPPORTED:
3401 struct sctp_assoc_value *av;
3403 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3404 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3407 av->assoc_value = stcb->asoc.ecn_supported;
3408 SCTP_TCB_UNLOCK(stcb);
3410 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3411 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3412 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3413 SCTP_INP_RLOCK(inp);
3414 av->assoc_value = inp->ecn_supported;
3415 SCTP_INP_RUNLOCK(inp);
3417 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3422 *optsize = sizeof(struct sctp_assoc_value);
3426 case SCTP_PR_SUPPORTED:
3428 struct sctp_assoc_value *av;
3430 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3431 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3434 av->assoc_value = stcb->asoc.prsctp_supported;
3435 SCTP_TCB_UNLOCK(stcb);
3437 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3438 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3439 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3440 SCTP_INP_RLOCK(inp);
3441 av->assoc_value = inp->prsctp_supported;
3442 SCTP_INP_RUNLOCK(inp);
3444 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3449 *optsize = sizeof(struct sctp_assoc_value);
3453 case SCTP_AUTH_SUPPORTED:
3455 struct sctp_assoc_value *av;
3457 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3458 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3461 av->assoc_value = stcb->asoc.auth_supported;
3462 SCTP_TCB_UNLOCK(stcb);
3464 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3465 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3466 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3467 SCTP_INP_RLOCK(inp);
3468 av->assoc_value = inp->auth_supported;
3469 SCTP_INP_RUNLOCK(inp);
3471 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3476 *optsize = sizeof(struct sctp_assoc_value);
3480 case SCTP_ASCONF_SUPPORTED:
3482 struct sctp_assoc_value *av;
3484 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3485 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3488 av->assoc_value = stcb->asoc.asconf_supported;
3489 SCTP_TCB_UNLOCK(stcb);
3491 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3492 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3493 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3494 SCTP_INP_RLOCK(inp);
3495 av->assoc_value = inp->asconf_supported;
3496 SCTP_INP_RUNLOCK(inp);
3498 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3503 *optsize = sizeof(struct sctp_assoc_value);
3507 case SCTP_RECONFIG_SUPPORTED:
3509 struct sctp_assoc_value *av;
3511 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3512 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3515 av->assoc_value = stcb->asoc.reconfig_supported;
3516 SCTP_TCB_UNLOCK(stcb);
3518 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3519 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3520 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3521 SCTP_INP_RLOCK(inp);
3522 av->assoc_value = inp->reconfig_supported;
3523 SCTP_INP_RUNLOCK(inp);
3525 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3530 *optsize = sizeof(struct sctp_assoc_value);
3534 case SCTP_NRSACK_SUPPORTED:
3536 struct sctp_assoc_value *av;
3538 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3539 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3542 av->assoc_value = stcb->asoc.nrsack_supported;
3543 SCTP_TCB_UNLOCK(stcb);
3545 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3546 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3547 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3548 SCTP_INP_RLOCK(inp);
3549 av->assoc_value = inp->nrsack_supported;
3550 SCTP_INP_RUNLOCK(inp);
3552 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3557 *optsize = sizeof(struct sctp_assoc_value);
3561 case SCTP_PKTDROP_SUPPORTED:
3563 struct sctp_assoc_value *av;
3565 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3566 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3569 av->assoc_value = stcb->asoc.pktdrop_supported;
3570 SCTP_TCB_UNLOCK(stcb);
3572 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3573 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3574 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3575 SCTP_INP_RLOCK(inp);
3576 av->assoc_value = inp->pktdrop_supported;
3577 SCTP_INP_RUNLOCK(inp);
3579 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3584 *optsize = sizeof(struct sctp_assoc_value);
3588 case SCTP_ENABLE_STREAM_RESET:
3590 struct sctp_assoc_value *av;
3592 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3593 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3596 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3597 SCTP_TCB_UNLOCK(stcb);
3599 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3600 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3601 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3602 SCTP_INP_RLOCK(inp);
3603 av->assoc_value = (uint32_t)inp->local_strreset_support;
3604 SCTP_INP_RUNLOCK(inp);
3606 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3611 *optsize = sizeof(struct sctp_assoc_value);
3615 case SCTP_PR_STREAM_STATUS:
3617 struct sctp_prstatus *sprstat;
3621 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3622 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3624 sid = sprstat->sprstat_sid;
3625 policy = sprstat->sprstat_policy;
3626 #if defined(SCTP_DETAILED_STR_STATS)
3627 if ((stcb != NULL) &&
3628 (sid < stcb->asoc.streamoutcnt) &&
3629 (policy != SCTP_PR_SCTP_NONE) &&
3630 ((policy <= SCTP_PR_SCTP_MAX) ||
3631 (policy == SCTP_PR_SCTP_ALL))) {
3632 if (policy == SCTP_PR_SCTP_ALL) {
3633 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3634 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3636 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3637 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3640 if ((stcb != NULL) &&
3641 (sid < stcb->asoc.streamoutcnt) &&
3642 (policy == SCTP_PR_SCTP_ALL)) {
3643 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3644 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3647 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3651 SCTP_TCB_UNLOCK(stcb);
3654 *optsize = sizeof(struct sctp_prstatus);
3658 case SCTP_PR_ASSOC_STATUS:
3660 struct sctp_prstatus *sprstat;
3663 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3664 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3666 policy = sprstat->sprstat_policy;
3667 if ((stcb != NULL) &&
3668 (policy != SCTP_PR_SCTP_NONE) &&
3669 ((policy <= SCTP_PR_SCTP_MAX) ||
3670 (policy == SCTP_PR_SCTP_ALL))) {
3671 if (policy == SCTP_PR_SCTP_ALL) {
3672 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3673 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3675 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3676 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3679 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3683 SCTP_TCB_UNLOCK(stcb);
3686 *optsize = sizeof(struct sctp_prstatus);
3692 struct sctp_assoc_value *av;
3694 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3695 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3698 av->assoc_value = stcb->asoc.max_cwnd;
3699 SCTP_TCB_UNLOCK(stcb);
3701 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3702 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3703 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3704 SCTP_INP_RLOCK(inp);
3705 av->assoc_value = inp->max_cwnd;
3706 SCTP_INP_RUNLOCK(inp);
3708 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3713 *optsize = sizeof(struct sctp_assoc_value);
3718 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3719 error = ENOPROTOOPT;
3721 } /* end switch (sopt->sopt_name) */
3729 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3734 struct sctp_tcb *stcb = NULL;
3735 struct sctp_inpcb *inp = NULL;
3738 if (optval == NULL) {
3739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3742 inp = (struct sctp_inpcb *)so->so_pcb;
3744 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3747 vrf_id = inp->def_vrf_id;
3752 case SCTP_AUTOCLOSE:
3753 case SCTP_AUTO_ASCONF:
3754 case SCTP_EXPLICIT_EOR:
3755 case SCTP_DISABLE_FRAGMENTS:
3756 case SCTP_USE_EXT_RCVINFO:
3757 case SCTP_I_WANT_MAPPED_V4_ADDR:
3758 /* copy in the option value */
3759 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3764 case SCTP_DISABLE_FRAGMENTS:
3765 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3767 case SCTP_AUTO_ASCONF:
3769 * NOTE: we don't really support this flag
3771 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3772 /* only valid for bound all sockets */
3773 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3775 /* forbidden by admin */
3776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3779 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3781 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3785 case SCTP_EXPLICIT_EOR:
3786 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3788 case SCTP_USE_EXT_RCVINFO:
3789 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3791 case SCTP_I_WANT_MAPPED_V4_ADDR:
3792 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3793 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3800 set_opt = SCTP_PCB_FLAGS_NODELAY;
3802 case SCTP_AUTOCLOSE:
3803 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3804 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3805 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3808 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3810 * The value is in ticks. Note this does not effect
3811 * old associations, only new ones.
3813 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3816 SCTP_INP_WLOCK(inp);
3818 sctp_feature_on(inp, set_opt);
3820 sctp_feature_off(inp, set_opt);
3822 SCTP_INP_WUNLOCK(inp);
3824 case SCTP_REUSE_PORT:
3826 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3827 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3828 /* Can't set it after we are bound */
3832 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3833 /* Can't do this for a 1-m socket */
3838 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3840 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3843 case SCTP_PARTIAL_DELIVERY_POINT:
3847 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3848 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3849 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3853 inp->partial_delivery_point = *value;
3856 case SCTP_FRAGMENT_INTERLEAVE:
3857 /* not yet until we re-write sctp_recvmsg() */
3861 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3862 if (*level == SCTP_FRAG_LEVEL_2) {
3863 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3864 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3865 } else if (*level == SCTP_FRAG_LEVEL_1) {
3866 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3867 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3868 } else if (*level == SCTP_FRAG_LEVEL_0) {
3869 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3870 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3878 case SCTP_INTERLEAVING_SUPPORTED:
3880 struct sctp_assoc_value *av;
3882 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3883 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3886 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3888 SCTP_TCB_UNLOCK(stcb);
3890 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3891 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3892 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3893 SCTP_INP_WLOCK(inp);
3894 if (av->assoc_value == 0) {
3895 inp->idata_supported = 0;
3897 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3898 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3899 inp->idata_supported = 1;
3907 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3911 SCTP_INP_WUNLOCK(inp);
3913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3919 case SCTP_CMT_ON_OFF:
3920 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3921 struct sctp_assoc_value *av;
3923 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3924 if (av->assoc_value > SCTP_CMT_MAX) {
3925 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3929 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3931 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3932 SCTP_TCB_UNLOCK(stcb);
3934 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3935 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3936 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3937 (av->assoc_id == SCTP_ALL_ASSOC)) {
3938 SCTP_INP_WLOCK(inp);
3939 inp->sctp_cmt_on_off = av->assoc_value;
3940 SCTP_INP_WUNLOCK(inp);
3942 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3943 (av->assoc_id == SCTP_ALL_ASSOC)) {
3944 SCTP_INP_RLOCK(inp);
3945 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3946 SCTP_TCB_LOCK(stcb);
3947 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3948 SCTP_TCB_UNLOCK(stcb);
3950 SCTP_INP_RUNLOCK(inp);
3954 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3955 error = ENOPROTOOPT;
3958 case SCTP_PLUGGABLE_CC:
3960 struct sctp_assoc_value *av;
3961 struct sctp_nets *net;
3963 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3964 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3965 (av->assoc_value != SCTP_CC_HSTCP) &&
3966 (av->assoc_value != SCTP_CC_HTCP) &&
3967 (av->assoc_value != SCTP_CC_RTCC)) {
3968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3972 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3974 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3975 stcb->asoc.congestion_control_module = av->assoc_value;
3976 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3977 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3978 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3981 SCTP_TCB_UNLOCK(stcb);
3983 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3984 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3985 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3986 (av->assoc_id == SCTP_ALL_ASSOC)) {
3987 SCTP_INP_WLOCK(inp);
3988 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3989 SCTP_INP_WUNLOCK(inp);
3991 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3992 (av->assoc_id == SCTP_ALL_ASSOC)) {
3993 SCTP_INP_RLOCK(inp);
3994 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3995 SCTP_TCB_LOCK(stcb);
3996 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3997 stcb->asoc.congestion_control_module = av->assoc_value;
3998 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3999 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4000 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4003 SCTP_TCB_UNLOCK(stcb);
4005 SCTP_INP_RUNLOCK(inp);
4010 case SCTP_CC_OPTION:
4012 struct sctp_cc_option *cc_opt;
4014 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4015 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4017 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4018 SCTP_INP_RLOCK(inp);
4019 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4020 SCTP_TCB_LOCK(stcb);
4021 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4022 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4024 SCTP_TCB_UNLOCK(stcb);
4026 SCTP_INP_RUNLOCK(inp);
4031 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4034 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4037 SCTP_TCB_UNLOCK(stcb);
4041 case SCTP_PLUGGABLE_SS:
4043 struct sctp_assoc_value *av;
4045 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4046 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4047 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4048 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4049 (av->assoc_value != SCTP_SS_PRIORITY) &&
4050 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4051 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4052 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4056 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4058 SCTP_TCB_SEND_LOCK(stcb);
4059 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4060 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4061 stcb->asoc.stream_scheduling_module = av->assoc_value;
4062 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4063 SCTP_TCB_SEND_UNLOCK(stcb);
4064 SCTP_TCB_UNLOCK(stcb);
4066 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4067 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4068 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4069 (av->assoc_id == SCTP_ALL_ASSOC)) {
4070 SCTP_INP_WLOCK(inp);
4071 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4072 SCTP_INP_WUNLOCK(inp);
4074 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4075 (av->assoc_id == SCTP_ALL_ASSOC)) {
4076 SCTP_INP_RLOCK(inp);
4077 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4078 SCTP_TCB_LOCK(stcb);
4079 SCTP_TCB_SEND_LOCK(stcb);
4080 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4081 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4082 stcb->asoc.stream_scheduling_module = av->assoc_value;
4083 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4084 SCTP_TCB_SEND_UNLOCK(stcb);
4085 SCTP_TCB_UNLOCK(stcb);
4087 SCTP_INP_RUNLOCK(inp);
4094 struct sctp_stream_value *av;
4096 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4097 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4099 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4100 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4101 av->stream_value) < 0)) {
4102 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4105 SCTP_TCB_UNLOCK(stcb);
4107 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4108 SCTP_INP_RLOCK(inp);
4109 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4110 SCTP_TCB_LOCK(stcb);
4111 if (av->stream_id < stcb->asoc.streamoutcnt) {
4112 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4114 &stcb->asoc.strmout[av->stream_id],
4117 SCTP_TCB_UNLOCK(stcb);
4119 SCTP_INP_RUNLOCK(inp);
4122 * Can't set stream value without
4125 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4131 case SCTP_CLR_STAT_LOG:
4132 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4137 struct sctp_assoc_value *av;
4139 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4140 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4143 stcb->asoc.context = av->assoc_value;
4144 SCTP_TCB_UNLOCK(stcb);
4146 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4147 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4148 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4149 (av->assoc_id == SCTP_ALL_ASSOC)) {
4150 SCTP_INP_WLOCK(inp);
4151 inp->sctp_context = av->assoc_value;
4152 SCTP_INP_WUNLOCK(inp);
4154 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4155 (av->assoc_id == SCTP_ALL_ASSOC)) {
4156 SCTP_INP_RLOCK(inp);
4157 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4158 SCTP_TCB_LOCK(stcb);
4159 stcb->asoc.context = av->assoc_value;
4160 SCTP_TCB_UNLOCK(stcb);
4162 SCTP_INP_RUNLOCK(inp);
4169 uint32_t *default_vrfid;
4171 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4172 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4173 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4177 inp->def_vrf_id = *default_vrfid;
4180 case SCTP_DEL_VRF_ID:
4182 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4186 case SCTP_ADD_VRF_ID:
4188 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4192 case SCTP_DELAYED_SACK:
4194 struct sctp_sack_info *sack;
4196 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4197 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4198 if (sack->sack_delay) {
4199 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4200 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4201 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4202 sack->sack_delay = TICKS_TO_MSEC(1);
4206 if (sack->sack_delay) {
4207 stcb->asoc.delayed_ack = sack->sack_delay;
4209 if (sack->sack_freq) {
4210 stcb->asoc.sack_freq = sack->sack_freq;
4212 SCTP_TCB_UNLOCK(stcb);
4214 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4215 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4216 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4217 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4218 SCTP_INP_WLOCK(inp);
4219 if (sack->sack_delay) {
4220 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4222 if (sack->sack_freq) {
4223 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4225 SCTP_INP_WUNLOCK(inp);
4227 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4228 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4229 SCTP_INP_RLOCK(inp);
4230 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4231 SCTP_TCB_LOCK(stcb);
4232 if (sack->sack_delay) {
4233 stcb->asoc.delayed_ack = sack->sack_delay;
4235 if (sack->sack_freq) {
4236 stcb->asoc.sack_freq = sack->sack_freq;
4238 SCTP_TCB_UNLOCK(stcb);
4240 SCTP_INP_RUNLOCK(inp);
4245 case SCTP_AUTH_CHUNK:
4247 struct sctp_authchunk *sauth;
4249 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4251 SCTP_INP_WLOCK(inp);
4252 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4253 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4256 inp->auth_supported = 1;
4258 SCTP_INP_WUNLOCK(inp);
4263 struct sctp_authkey *sca;
4264 struct sctp_keyhead *shared_keys;
4265 sctp_sharedkey_t *shared_key;
4266 sctp_key_t *key = NULL;
4269 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4270 if (sca->sca_keylength == 0) {
4271 size = optsize - sizeof(struct sctp_authkey);
4273 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4274 size = sca->sca_keylength;
4276 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4281 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4284 shared_keys = &stcb->asoc.shared_keys;
4285 /* clear the cached keys for this key id */
4286 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4288 * create the new shared key and
4292 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4294 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4296 SCTP_TCB_UNLOCK(stcb);
4300 shared_key = sctp_alloc_sharedkey();
4301 if (shared_key == NULL) {
4303 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4305 SCTP_TCB_UNLOCK(stcb);
4308 shared_key->key = key;
4309 shared_key->keyid = sca->sca_keynumber;
4310 error = sctp_insert_sharedkey(shared_keys, shared_key);
4311 SCTP_TCB_UNLOCK(stcb);
4313 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4314 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4315 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4316 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4317 SCTP_INP_WLOCK(inp);
4318 shared_keys = &inp->sctp_ep.shared_keys;
4320 * clear the cached keys on all
4321 * assocs for this key id
4323 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4325 * create the new shared key and
4329 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4331 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4333 SCTP_INP_WUNLOCK(inp);
4337 shared_key = sctp_alloc_sharedkey();
4338 if (shared_key == NULL) {
4340 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4342 SCTP_INP_WUNLOCK(inp);
4345 shared_key->key = key;
4346 shared_key->keyid = sca->sca_keynumber;
4347 error = sctp_insert_sharedkey(shared_keys, shared_key);
4348 SCTP_INP_WUNLOCK(inp);
4350 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4351 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4352 SCTP_INP_RLOCK(inp);
4353 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4354 SCTP_TCB_LOCK(stcb);
4355 shared_keys = &stcb->asoc.shared_keys;
4357 * clear the cached keys for
4360 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4362 * create the new shared key
4363 * and insert/replace it
4366 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4368 SCTP_TCB_UNLOCK(stcb);
4372 shared_key = sctp_alloc_sharedkey();
4373 if (shared_key == NULL) {
4375 SCTP_TCB_UNLOCK(stcb);
4378 shared_key->key = key;
4379 shared_key->keyid = sca->sca_keynumber;
4380 error = sctp_insert_sharedkey(shared_keys, shared_key);
4381 SCTP_TCB_UNLOCK(stcb);
4383 SCTP_INP_RUNLOCK(inp);
4388 case SCTP_HMAC_IDENT:
4390 struct sctp_hmacalgo *shmac;
4391 sctp_hmaclist_t *hmaclist;
4395 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4396 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4397 (shmac->shmac_number_of_idents > 0xffff)) {
4398 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4403 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4404 if (hmaclist == NULL) {
4405 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4409 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4410 hmacid = shmac->shmac_idents[i];
4411 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4412 /* invalid HMACs were found */ ;
4413 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4415 sctp_free_hmaclist(hmaclist);
4416 goto sctp_set_hmac_done;
4419 for (i = 0; i < hmaclist->num_algo; i++) {
4420 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4421 /* already in list */
4425 if (i == hmaclist->num_algo) {
4426 /* not found in list */
4427 sctp_free_hmaclist(hmaclist);
4428 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4432 /* set it on the endpoint */
4433 SCTP_INP_WLOCK(inp);
4434 if (inp->sctp_ep.local_hmacs)
4435 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4436 inp->sctp_ep.local_hmacs = hmaclist;
4437 SCTP_INP_WUNLOCK(inp);
4441 case SCTP_AUTH_ACTIVE_KEY:
4443 struct sctp_authkeyid *scact;
4445 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4446 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4448 /* set the active key on the right place */
4450 /* set the active key on the assoc */
4451 if (sctp_auth_setactivekey(stcb,
4452 scact->scact_keynumber)) {
4453 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4454 SCTP_FROM_SCTP_USRREQ,
4458 SCTP_TCB_UNLOCK(stcb);
4460 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4461 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4462 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4463 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4464 SCTP_INP_WLOCK(inp);
4465 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4466 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4469 SCTP_INP_WUNLOCK(inp);
4471 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4472 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4473 SCTP_INP_RLOCK(inp);
4474 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4475 SCTP_TCB_LOCK(stcb);
4476 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4477 SCTP_TCB_UNLOCK(stcb);
4479 SCTP_INP_RUNLOCK(inp);
4484 case SCTP_AUTH_DELETE_KEY:
4486 struct sctp_authkeyid *scdel;
4488 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4489 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4491 /* delete the key from the right place */
4493 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4497 SCTP_TCB_UNLOCK(stcb);
4499 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4500 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4501 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4502 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4503 SCTP_INP_WLOCK(inp);
4504 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4505 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4508 SCTP_INP_WUNLOCK(inp);
4510 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4511 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4512 SCTP_INP_RLOCK(inp);
4513 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4514 SCTP_TCB_LOCK(stcb);
4515 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4516 SCTP_TCB_UNLOCK(stcb);
4518 SCTP_INP_RUNLOCK(inp);
4523 case SCTP_AUTH_DEACTIVATE_KEY:
4525 struct sctp_authkeyid *keyid;
4527 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4528 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4530 /* deactivate the key from the right place */
4532 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4533 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4536 SCTP_TCB_UNLOCK(stcb);
4538 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4539 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4540 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4541 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4542 SCTP_INP_WLOCK(inp);
4543 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4544 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4547 SCTP_INP_WUNLOCK(inp);
4549 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4550 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4551 SCTP_INP_RLOCK(inp);
4552 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4553 SCTP_TCB_LOCK(stcb);
4554 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4555 SCTP_TCB_UNLOCK(stcb);
4557 SCTP_INP_RUNLOCK(inp);
4562 case SCTP_ENABLE_STREAM_RESET:
4564 struct sctp_assoc_value *av;
4566 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4567 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4568 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4572 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4574 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4575 SCTP_TCB_UNLOCK(stcb);
4577 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4578 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4579 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4580 (av->assoc_id == SCTP_ALL_ASSOC)) {
4581 SCTP_INP_WLOCK(inp);
4582 inp->local_strreset_support = (uint8_t)av->assoc_value;
4583 SCTP_INP_WUNLOCK(inp);
4585 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4586 (av->assoc_id == SCTP_ALL_ASSOC)) {
4587 SCTP_INP_RLOCK(inp);
4588 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4589 SCTP_TCB_LOCK(stcb);
4590 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4591 SCTP_TCB_UNLOCK(stcb);
4593 SCTP_INP_RUNLOCK(inp);
4599 case SCTP_RESET_STREAMS:
4601 struct sctp_reset_streams *strrst;
4602 int i, send_out = 0;
4605 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4606 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4608 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4612 if (stcb->asoc.reconfig_supported == 0) {
4614 * Peer does not support the chunk type.
4616 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4618 SCTP_TCB_UNLOCK(stcb);
4621 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
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 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4744 SCTP_TCB_UNLOCK(stcb);
4747 if (stcb->asoc.stream_reset_outstanding) {
4748 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4750 SCTP_TCB_UNLOCK(stcb);
4753 if ((stradd->sas_outstrms == 0) &&
4754 (stradd->sas_instrms == 0)) {
4758 if (stradd->sas_outstrms) {
4760 /* We allocate here */
4761 add_o_strmcnt = stradd->sas_outstrms;
4762 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4763 /* You can't have more than 64k */
4768 if (stradd->sas_instrms) {
4773 * We allocate inside
4774 * sctp_send_str_reset_req()
4776 add_i_strmcnt = stradd->sas_instrms;
4777 cnt = add_i_strmcnt;
4778 cnt += stcb->asoc.streamincnt;
4779 if (cnt > 0x0000ffff) {
4780 /* You can't have more than 64k */
4784 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4785 /* More than you are allowed */
4790 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4791 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4793 SCTP_TCB_UNLOCK(stcb);
4796 case SCTP_RESET_ASSOC:
4801 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4802 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4808 if (stcb->asoc.reconfig_supported == 0) {
4810 * Peer does not support the chunk type.
4812 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4814 SCTP_TCB_UNLOCK(stcb);
4817 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4818 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4820 SCTP_TCB_UNLOCK(stcb);
4823 if (stcb->asoc.stream_reset_outstanding) {
4824 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4826 SCTP_TCB_UNLOCK(stcb);
4830 * Is there any data pending in the send or sent
4833 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4834 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4837 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4838 SCTP_TCB_UNLOCK(stcb);
4841 /* Do any streams have data queued? */
4842 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4843 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4847 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4848 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4849 SCTP_TCB_UNLOCK(stcb);
4852 case SCTP_CONNECT_X:
4853 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4858 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4860 case SCTP_CONNECT_X_DELAYED:
4861 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4862 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4866 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4868 case SCTP_CONNECT_X_COMPLETE:
4870 struct sockaddr *sa;
4872 /* FIXME MT: check correct? */
4873 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4876 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4877 SCTP_INP_RLOCK(inp);
4878 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4880 SCTP_TCB_LOCK(stcb);
4882 SCTP_INP_RUNLOCK(inp);
4885 * We increment here since
4886 * sctp_findassociation_ep_addr() wil do a
4887 * decrement if it finds the stcb as long as
4888 * the locked tcb (last argument) is NOT a
4891 SCTP_INP_INCR_REF(inp);
4892 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4894 SCTP_INP_DECR_REF(inp);
4899 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4903 if (stcb->asoc.delayed_connection == 1) {
4904 stcb->asoc.delayed_connection = 0;
4905 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4906 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4907 stcb->asoc.primary_destination,
4908 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4909 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4912 * already expired or did not use delayed
4915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4918 SCTP_TCB_UNLOCK(stcb);
4921 case SCTP_MAX_BURST:
4923 struct sctp_assoc_value *av;
4925 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4926 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4929 stcb->asoc.max_burst = av->assoc_value;
4930 SCTP_TCB_UNLOCK(stcb);
4932 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4933 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4934 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4935 (av->assoc_id == SCTP_ALL_ASSOC)) {
4936 SCTP_INP_WLOCK(inp);
4937 inp->sctp_ep.max_burst = av->assoc_value;
4938 SCTP_INP_WUNLOCK(inp);
4940 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4941 (av->assoc_id == SCTP_ALL_ASSOC)) {
4942 SCTP_INP_RLOCK(inp);
4943 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4944 SCTP_TCB_LOCK(stcb);
4945 stcb->asoc.max_burst = av->assoc_value;
4946 SCTP_TCB_UNLOCK(stcb);
4948 SCTP_INP_RUNLOCK(inp);
4955 struct sctp_assoc_value *av;
4958 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4959 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4961 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4962 ovh = SCTP_MED_OVERHEAD;
4964 ovh = SCTP_MED_V4_OVERHEAD;
4967 if (av->assoc_value) {
4968 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4970 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4972 SCTP_TCB_UNLOCK(stcb);
4974 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4975 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4976 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4977 SCTP_INP_WLOCK(inp);
4979 * FIXME MT: I think this is not in
4980 * tune with the API ID
4982 if (av->assoc_value) {
4983 inp->sctp_frag_point = (av->assoc_value + ovh);
4985 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4987 SCTP_INP_WUNLOCK(inp);
4989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4997 struct sctp_event_subscribe *events;
4999 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5001 SCTP_INP_WLOCK(inp);
5002 if (events->sctp_data_io_event) {
5003 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5005 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5008 if (events->sctp_association_event) {
5009 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5011 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5014 if (events->sctp_address_event) {
5015 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5017 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5020 if (events->sctp_send_failure_event) {
5021 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5023 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5026 if (events->sctp_peer_error_event) {
5027 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5029 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5032 if (events->sctp_shutdown_event) {
5033 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5035 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5038 if (events->sctp_partial_delivery_event) {
5039 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5041 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5044 if (events->sctp_adaptation_layer_event) {
5045 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5047 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5050 if (events->sctp_authentication_event) {
5051 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5053 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5056 if (events->sctp_sender_dry_event) {
5057 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5059 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5062 if (events->sctp_stream_reset_event) {
5063 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5065 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5067 SCTP_INP_WUNLOCK(inp);
5069 SCTP_INP_RLOCK(inp);
5070 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5071 SCTP_TCB_LOCK(stcb);
5072 if (events->sctp_association_event) {
5073 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5075 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5077 if (events->sctp_address_event) {
5078 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5080 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5082 if (events->sctp_send_failure_event) {
5083 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5085 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5087 if (events->sctp_peer_error_event) {
5088 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5090 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5092 if (events->sctp_shutdown_event) {
5093 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5095 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5097 if (events->sctp_partial_delivery_event) {
5098 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5100 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5102 if (events->sctp_adaptation_layer_event) {
5103 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5105 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5107 if (events->sctp_authentication_event) {
5108 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5110 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5112 if (events->sctp_sender_dry_event) {
5113 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5115 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5117 if (events->sctp_stream_reset_event) {
5118 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5120 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5122 SCTP_TCB_UNLOCK(stcb);
5125 * Send up the sender dry event only for 1-to-1
5128 if (events->sctp_sender_dry_event) {
5129 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5130 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5131 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5133 SCTP_TCB_LOCK(stcb);
5134 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5135 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5136 (stcb->asoc.stream_queue_cnt == 0)) {
5137 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5139 SCTP_TCB_UNLOCK(stcb);
5143 SCTP_INP_RUNLOCK(inp);
5146 case SCTP_ADAPTATION_LAYER:
5148 struct sctp_setadaptation *adap_bits;
5150 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5151 SCTP_INP_WLOCK(inp);
5152 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5153 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5154 SCTP_INP_WUNLOCK(inp);
5158 case SCTP_SET_INITIAL_DBG_SEQ:
5162 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5163 SCTP_INP_WLOCK(inp);
5164 inp->sctp_ep.initial_sequence_debug = *vvv;
5165 SCTP_INP_WUNLOCK(inp);
5169 case SCTP_DEFAULT_SEND_PARAM:
5171 struct sctp_sndrcvinfo *s_info;
5173 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5174 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5177 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5178 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5180 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5183 SCTP_TCB_UNLOCK(stcb);
5185 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5186 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5187 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5188 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5189 SCTP_INP_WLOCK(inp);
5190 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5191 SCTP_INP_WUNLOCK(inp);
5193 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5194 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5195 SCTP_INP_RLOCK(inp);
5196 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5197 SCTP_TCB_LOCK(stcb);
5198 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5199 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5201 SCTP_TCB_UNLOCK(stcb);
5203 SCTP_INP_RUNLOCK(inp);
5208 case SCTP_PEER_ADDR_PARAMS:
5210 struct sctp_paddrparams *paddrp;
5211 struct sctp_nets *net;
5212 struct sockaddr *addr;
5213 #if defined(INET) && defined(INET6)
5214 struct sockaddr_in sin_store;
5217 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5218 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5220 #if defined(INET) && defined(INET6)
5221 if (paddrp->spp_address.ss_family == AF_INET6) {
5222 struct sockaddr_in6 *sin6;
5224 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5225 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5226 in6_sin6_2_sin(&sin_store, sin6);
5227 addr = (struct sockaddr *)&sin_store;
5229 addr = (struct sockaddr *)&paddrp->spp_address;
5232 addr = (struct sockaddr *)&paddrp->spp_address;
5235 addr = (struct sockaddr *)&paddrp->spp_address;
5238 net = sctp_findnet(stcb, addr);
5241 * We increment here since
5242 * sctp_findassociation_ep_addr() wil do a
5243 * decrement if it finds the stcb as long as
5244 * the locked tcb (last argument) is NOT a
5248 SCTP_INP_INCR_REF(inp);
5249 stcb = sctp_findassociation_ep_addr(&inp, addr,
5252 SCTP_INP_DECR_REF(inp);
5255 if ((stcb != NULL) && (net == NULL)) {
5257 if (addr->sa_family == AF_INET) {
5259 struct sockaddr_in *sin;
5261 sin = (struct sockaddr_in *)addr;
5262 if (sin->sin_addr.s_addr != INADDR_ANY) {
5263 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5264 SCTP_TCB_UNLOCK(stcb);
5271 if (addr->sa_family == AF_INET6) {
5272 struct sockaddr_in6 *sin6;
5274 sin6 = (struct sockaddr_in6 *)addr;
5275 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5276 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5277 SCTP_TCB_UNLOCK(stcb);
5284 error = EAFNOSUPPORT;
5285 SCTP_TCB_UNLOCK(stcb);
5286 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5291 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5293 SCTP_TCB_UNLOCK(stcb);
5294 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5298 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5300 SCTP_TCB_UNLOCK(stcb);
5301 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5306 /************************TCB SPECIFIC SET ******************/
5308 /************************NET SPECIFIC SET ******************/
5309 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5310 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5311 !(net->dest_state & SCTP_ADDR_NOHB)) {
5312 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5313 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5315 net->dest_state |= SCTP_ADDR_NOHB;
5317 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5318 if (paddrp->spp_hbinterval) {
5319 net->heart_beat_delay = paddrp->spp_hbinterval;
5320 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5321 net->heart_beat_delay = 0;
5323 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5324 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5325 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5326 net->dest_state &= ~SCTP_ADDR_NOHB;
5328 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5329 if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
5330 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5331 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5332 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5335 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5336 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5337 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5338 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5340 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5341 net->mtu = paddrp->spp_pathmtu;
5342 switch (net->ro._l_addr.sa.sa_family) {
5345 net->mtu += SCTP_MIN_V4_OVERHEAD;
5350 net->mtu += SCTP_MIN_OVERHEAD;
5356 if (net->mtu < stcb->asoc.smallest_mtu) {
5357 sctp_pathmtu_adjustment(stcb, net->mtu);
5360 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5361 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5362 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5364 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5366 if (paddrp->spp_pathmaxrxt) {
5367 if (net->dest_state & SCTP_ADDR_PF) {
5368 if (net->error_count > paddrp->spp_pathmaxrxt) {
5369 net->dest_state &= ~SCTP_ADDR_PF;
5372 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5373 (net->error_count > net->pf_threshold)) {
5374 net->dest_state |= SCTP_ADDR_PF;
5375 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5376 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5377 stcb->sctp_ep, stcb, net,
5378 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5379 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5382 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5383 if (net->error_count > paddrp->spp_pathmaxrxt) {
5384 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5385 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5388 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5389 net->dest_state |= SCTP_ADDR_REACHABLE;
5390 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5393 net->failure_threshold = paddrp->spp_pathmaxrxt;
5395 if (paddrp->spp_flags & SPP_DSCP) {
5396 net->dscp = paddrp->spp_dscp & 0xfc;
5400 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5401 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5402 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5403 net->flowlabel |= 0x80000000;
5408 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5409 if (paddrp->spp_pathmaxrxt != 0) {
5410 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5411 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5412 if (net->dest_state & SCTP_ADDR_PF) {
5413 if (net->error_count > paddrp->spp_pathmaxrxt) {
5414 net->dest_state &= ~SCTP_ADDR_PF;
5417 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5418 (net->error_count > net->pf_threshold)) {
5419 net->dest_state |= SCTP_ADDR_PF;
5420 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5421 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5422 stcb->sctp_ep, stcb, net,
5423 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5424 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5427 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5428 if (net->error_count > paddrp->spp_pathmaxrxt) {
5429 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5430 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5433 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5434 net->dest_state |= SCTP_ADDR_REACHABLE;
5435 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5438 net->failure_threshold = paddrp->spp_pathmaxrxt;
5442 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5443 if (paddrp->spp_hbinterval != 0) {
5444 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5445 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5446 stcb->asoc.heart_beat_delay = 0;
5448 /* Turn back on the timer */
5449 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5450 if (paddrp->spp_hbinterval != 0) {
5451 net->heart_beat_delay = paddrp->spp_hbinterval;
5452 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5453 net->heart_beat_delay = 0;
5455 if (net->dest_state & SCTP_ADDR_NOHB) {
5456 net->dest_state &= ~SCTP_ADDR_NOHB;
5458 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5459 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5460 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5462 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5464 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5465 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5466 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5467 net->dest_state |= SCTP_ADDR_NOHB;
5468 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5469 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5471 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5475 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5477 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5478 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5479 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5480 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5481 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5483 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5484 net->mtu = paddrp->spp_pathmtu;
5485 switch (net->ro._l_addr.sa.sa_family) {
5488 net->mtu += SCTP_MIN_V4_OVERHEAD;
5493 net->mtu += SCTP_MIN_OVERHEAD;
5499 if (net->mtu < stcb->asoc.smallest_mtu) {
5500 sctp_pathmtu_adjustment(stcb, net->mtu);
5503 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5504 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5506 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5507 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5508 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5509 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5511 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5513 stcb->asoc.default_mtu = 0;
5514 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5516 if (paddrp->spp_flags & SPP_DSCP) {
5517 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5518 net->dscp = paddrp->spp_dscp & 0xfc;
5521 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5522 stcb->asoc.default_dscp |= 0x01;
5525 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5526 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5527 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5528 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5529 net->flowlabel |= 0x80000000;
5532 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5533 stcb->asoc.default_flowlabel |= 0x80000000;
5537 SCTP_TCB_UNLOCK(stcb);
5539 /************************NO TCB, SET TO default stuff ******************/
5540 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5541 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5542 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5543 SCTP_INP_WLOCK(inp);
5545 * For the TOS/FLOWLABEL stuff you
5546 * set it with the options on the
5549 if (paddrp->spp_pathmaxrxt != 0) {
5550 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5553 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5554 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5555 else if (paddrp->spp_hbinterval != 0) {
5556 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5557 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5558 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5561 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5562 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5563 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5564 } else if (paddrp->spp_hbinterval) {
5565 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5567 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5568 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5569 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5571 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5572 inp->sctp_ep.default_mtu = 0;
5573 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5574 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5575 if (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU) {
5576 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5578 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5580 if (paddrp->spp_flags & SPP_DSCP) {
5581 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5582 inp->sctp_ep.default_dscp |= 0x01;
5585 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5586 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5587 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5588 inp->sctp_ep.default_flowlabel |= 0x80000000;
5592 SCTP_INP_WUNLOCK(inp);
5594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5602 struct sctp_rtoinfo *srto;
5603 uint32_t new_init, new_min, new_max;
5605 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5606 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5609 if (srto->srto_initial)
5610 new_init = srto->srto_initial;
5612 new_init = stcb->asoc.initial_rto;
5614 new_max = srto->srto_max;
5616 new_max = stcb->asoc.maxrto;
5618 new_min = srto->srto_min;
5620 new_min = stcb->asoc.minrto;
5621 if ((new_min <= new_init) && (new_init <= new_max)) {
5622 stcb->asoc.initial_rto = new_init;
5623 stcb->asoc.maxrto = new_max;
5624 stcb->asoc.minrto = new_min;
5626 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5629 SCTP_TCB_UNLOCK(stcb);
5631 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5632 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5633 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5634 SCTP_INP_WLOCK(inp);
5635 if (srto->srto_initial)
5636 new_init = srto->srto_initial;
5638 new_init = inp->sctp_ep.initial_rto;
5640 new_max = srto->srto_max;
5642 new_max = inp->sctp_ep.sctp_maxrto;
5644 new_min = srto->srto_min;
5646 new_min = inp->sctp_ep.sctp_minrto;
5647 if ((new_min <= new_init) && (new_init <= new_max)) {
5648 inp->sctp_ep.initial_rto = new_init;
5649 inp->sctp_ep.sctp_maxrto = new_max;
5650 inp->sctp_ep.sctp_minrto = new_min;
5652 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5655 SCTP_INP_WUNLOCK(inp);
5657 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5663 case SCTP_ASSOCINFO:
5665 struct sctp_assocparams *sasoc;
5667 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5668 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5669 if (sasoc->sasoc_cookie_life) {
5670 /* boundary check the cookie life */
5671 if (sasoc->sasoc_cookie_life < 1000)
5672 sasoc->sasoc_cookie_life = 1000;
5673 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5674 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5678 if (sasoc->sasoc_asocmaxrxt)
5679 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5680 if (sasoc->sasoc_cookie_life) {
5681 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5683 SCTP_TCB_UNLOCK(stcb);
5685 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5686 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5687 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5688 SCTP_INP_WLOCK(inp);
5689 if (sasoc->sasoc_asocmaxrxt)
5690 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5691 if (sasoc->sasoc_cookie_life) {
5692 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5694 SCTP_INP_WUNLOCK(inp);
5696 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5704 struct sctp_initmsg *sinit;
5706 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5707 SCTP_INP_WLOCK(inp);
5708 if (sinit->sinit_num_ostreams)
5709 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5711 if (sinit->sinit_max_instreams)
5712 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5714 if (sinit->sinit_max_attempts)
5715 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5717 if (sinit->sinit_max_init_timeo)
5718 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5719 SCTP_INP_WUNLOCK(inp);
5722 case SCTP_PRIMARY_ADDR:
5724 struct sctp_setprim *spa;
5725 struct sctp_nets *net;
5726 struct sockaddr *addr;
5727 #if defined(INET) && defined(INET6)
5728 struct sockaddr_in sin_store;
5731 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5732 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5734 #if defined(INET) && defined(INET6)
5735 if (spa->ssp_addr.ss_family == AF_INET6) {
5736 struct sockaddr_in6 *sin6;
5738 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5739 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5740 in6_sin6_2_sin(&sin_store, sin6);
5741 addr = (struct sockaddr *)&sin_store;
5743 addr = (struct sockaddr *)&spa->ssp_addr;
5746 addr = (struct sockaddr *)&spa->ssp_addr;
5749 addr = (struct sockaddr *)&spa->ssp_addr;
5752 net = sctp_findnet(stcb, addr);
5755 * We increment here since
5756 * sctp_findassociation_ep_addr() wil do a
5757 * decrement if it finds the stcb as long as
5758 * the locked tcb (last argument) is NOT a
5762 SCTP_INP_INCR_REF(inp);
5763 stcb = sctp_findassociation_ep_addr(&inp, addr,
5766 SCTP_INP_DECR_REF(inp);
5770 if ((stcb != NULL) && (net != NULL)) {
5771 if (net != stcb->asoc.primary_destination) {
5772 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5773 /* Ok we need to set it */
5774 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5775 if ((stcb->asoc.alternate) &&
5776 (!(net->dest_state & SCTP_ADDR_PF)) &&
5777 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5778 sctp_free_remote_addr(stcb->asoc.alternate);
5779 stcb->asoc.alternate = NULL;
5782 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5786 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5791 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5795 SCTP_TCB_UNLOCK(stcb);
5799 case SCTP_SET_DYNAMIC_PRIMARY:
5801 union sctp_sockstore *ss;
5803 error = priv_check(curthread,
5804 PRIV_NETINET_RESERVEDPORT);
5808 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5809 /* SUPER USER CHECK? */
5810 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5813 case SCTP_SET_PEER_PRIMARY_ADDR:
5815 struct sctp_setpeerprim *sspp;
5816 struct sockaddr *addr;
5817 #if defined(INET) && defined(INET6)
5818 struct sockaddr_in sin_store;
5821 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5822 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5824 struct sctp_ifa *ifa;
5826 #if defined(INET) && defined(INET6)
5827 if (sspp->sspp_addr.ss_family == AF_INET6) {
5828 struct sockaddr_in6 *sin6;
5830 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5831 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5832 in6_sin6_2_sin(&sin_store, sin6);
5833 addr = (struct sockaddr *)&sin_store;
5835 addr = (struct sockaddr *)&sspp->sspp_addr;
5838 addr = (struct sockaddr *)&sspp->sspp_addr;
5841 addr = (struct sockaddr *)&sspp->sspp_addr;
5843 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5845 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5849 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5851 * Must validate the ifa found is in
5854 struct sctp_laddr *laddr;
5857 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5858 if (laddr->ifa == NULL) {
5859 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5863 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5864 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5867 if (laddr->ifa == ifa) {
5873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5878 switch (addr->sa_family) {
5882 struct sockaddr_in *sin;
5884 sin = (struct sockaddr_in *)addr;
5885 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5886 &sin->sin_addr) != 0) {
5887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5897 struct sockaddr_in6 *sin6;
5899 sin6 = (struct sockaddr_in6 *)addr;
5900 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5901 &sin6->sin6_addr) != 0) {
5902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5915 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5919 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5921 SCTP_TCB_UNLOCK(stcb);
5923 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5928 case SCTP_BINDX_ADD_ADDR:
5930 struct sctp_getaddresses *addrs;
5933 td = (struct thread *)p;
5934 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5937 if (addrs->addr->sa_family == AF_INET) {
5938 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5943 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5944 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5950 if (addrs->addr->sa_family == AF_INET6) {
5951 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5952 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5956 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5957 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5958 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5964 error = EAFNOSUPPORT;
5967 sctp_bindx_add_address(so, inp, addrs->addr,
5968 addrs->sget_assoc_id, vrf_id,
5972 case SCTP_BINDX_REM_ADDR:
5974 struct sctp_getaddresses *addrs;
5977 td = (struct thread *)p;
5979 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5981 if (addrs->addr->sa_family == AF_INET) {
5982 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5983 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5987 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5988 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5994 if (addrs->addr->sa_family == AF_INET6) {
5995 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5996 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6001 (error = prison_local_ip6(td->td_ucred,
6002 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
6003 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6004 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6010 error = EAFNOSUPPORT;
6013 sctp_bindx_delete_address(inp, addrs->addr,
6014 addrs->sget_assoc_id, vrf_id,
6020 struct sctp_event *event;
6021 uint32_t event_type;
6023 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6024 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6025 switch (event->se_type) {
6026 case SCTP_ASSOC_CHANGE:
6027 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6029 case SCTP_PEER_ADDR_CHANGE:
6030 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6032 case SCTP_REMOTE_ERROR:
6033 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6035 case SCTP_SEND_FAILED:
6036 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6038 case SCTP_SHUTDOWN_EVENT:
6039 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6041 case SCTP_ADAPTATION_INDICATION:
6042 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6044 case SCTP_PARTIAL_DELIVERY_EVENT:
6045 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6047 case SCTP_AUTHENTICATION_EVENT:
6048 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6050 case SCTP_STREAM_RESET_EVENT:
6051 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6053 case SCTP_SENDER_DRY_EVENT:
6054 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6056 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6058 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6061 case SCTP_ASSOC_RESET_EVENT:
6062 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6064 case SCTP_STREAM_CHANGE_EVENT:
6065 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6067 case SCTP_SEND_FAILED_EVENT:
6068 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6072 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6076 if (event_type > 0) {
6079 sctp_stcb_feature_on(inp, stcb, event_type);
6080 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6081 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6082 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6083 (stcb->asoc.stream_queue_cnt == 0)) {
6084 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6088 sctp_stcb_feature_off(inp, stcb, event_type);
6090 SCTP_TCB_UNLOCK(stcb);
6093 * We don't want to send up a storm
6094 * of events, so return an error for
6097 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6098 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6099 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6100 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6101 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6102 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6106 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6107 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6108 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6109 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6110 SCTP_INP_WLOCK(inp);
6112 sctp_feature_on(inp, event_type);
6114 sctp_feature_off(inp, event_type);
6116 SCTP_INP_WUNLOCK(inp);
6118 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6119 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6120 SCTP_INP_RLOCK(inp);
6121 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6122 SCTP_TCB_LOCK(stcb);
6124 sctp_stcb_feature_on(inp, stcb, event_type);
6126 sctp_stcb_feature_off(inp, stcb, event_type);
6128 SCTP_TCB_UNLOCK(stcb);
6130 SCTP_INP_RUNLOCK(inp);
6135 SCTP_TCB_UNLOCK(stcb);
6140 case SCTP_RECVRCVINFO:
6144 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6145 SCTP_INP_WLOCK(inp);
6147 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6149 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6151 SCTP_INP_WUNLOCK(inp);
6154 case SCTP_RECVNXTINFO:
6158 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6159 SCTP_INP_WLOCK(inp);
6161 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6163 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6165 SCTP_INP_WUNLOCK(inp);
6168 case SCTP_DEFAULT_SNDINFO:
6170 struct sctp_sndinfo *info;
6173 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6174 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6177 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6178 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6179 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6180 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6181 stcb->asoc.def_send.sinfo_flags |= policy;
6182 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6183 stcb->asoc.def_send.sinfo_context = info->snd_context;
6185 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6188 SCTP_TCB_UNLOCK(stcb);
6190 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6191 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6192 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6193 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6194 SCTP_INP_WLOCK(inp);
6195 inp->def_send.sinfo_stream = info->snd_sid;
6196 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6197 inp->def_send.sinfo_flags = info->snd_flags;
6198 inp->def_send.sinfo_flags |= policy;
6199 inp->def_send.sinfo_ppid = info->snd_ppid;
6200 inp->def_send.sinfo_context = info->snd_context;
6201 SCTP_INP_WUNLOCK(inp);
6203 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6204 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6205 SCTP_INP_RLOCK(inp);
6206 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6207 SCTP_TCB_LOCK(stcb);
6208 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6209 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6210 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6211 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6212 stcb->asoc.def_send.sinfo_flags |= policy;
6213 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6214 stcb->asoc.def_send.sinfo_context = info->snd_context;
6216 SCTP_TCB_UNLOCK(stcb);
6218 SCTP_INP_RUNLOCK(inp);
6223 case SCTP_DEFAULT_PRINFO:
6225 struct sctp_default_prinfo *info;
6227 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6228 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6230 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6232 SCTP_TCB_UNLOCK(stcb);
6234 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6239 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6240 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6241 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6242 SCTP_TCB_UNLOCK(stcb);
6244 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6245 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6246 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6247 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6248 SCTP_INP_WLOCK(inp);
6249 inp->def_send.sinfo_flags &= 0xfff0;
6250 inp->def_send.sinfo_flags |= info->pr_policy;
6251 inp->def_send.sinfo_timetolive = info->pr_value;
6252 SCTP_INP_WUNLOCK(inp);
6254 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6255 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6256 SCTP_INP_RLOCK(inp);
6257 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6258 SCTP_TCB_LOCK(stcb);
6259 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6260 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6261 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6262 SCTP_TCB_UNLOCK(stcb);
6264 SCTP_INP_RUNLOCK(inp);
6269 case SCTP_PEER_ADDR_THLDS:
6270 /* Applies to the specific association */
6272 struct sctp_paddrthlds *thlds;
6273 struct sctp_nets *net;
6274 struct sockaddr *addr;
6275 #if defined(INET) && defined(INET6)
6276 struct sockaddr_in sin_store;
6279 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6280 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6282 #if defined(INET) && defined(INET6)
6283 if (thlds->spt_address.ss_family == AF_INET6) {
6284 struct sockaddr_in6 *sin6;
6286 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6287 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6288 in6_sin6_2_sin(&sin_store, sin6);
6289 addr = (struct sockaddr *)&sin_store;
6291 addr = (struct sockaddr *)&thlds->spt_address;
6294 addr = (struct sockaddr *)&thlds->spt_address;
6297 addr = (struct sockaddr *)&thlds->spt_address;
6300 net = sctp_findnet(stcb, addr);
6303 * We increment here since
6304 * sctp_findassociation_ep_addr() wil do a
6305 * decrement if it finds the stcb as long as
6306 * the locked tcb (last argument) is NOT a
6310 SCTP_INP_INCR_REF(inp);
6311 stcb = sctp_findassociation_ep_addr(&inp, addr,
6314 SCTP_INP_DECR_REF(inp);
6317 if ((stcb != NULL) && (net == NULL)) {
6319 if (addr->sa_family == AF_INET) {
6321 struct sockaddr_in *sin;
6323 sin = (struct sockaddr_in *)addr;
6324 if (sin->sin_addr.s_addr != INADDR_ANY) {
6325 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6326 SCTP_TCB_UNLOCK(stcb);
6333 if (addr->sa_family == AF_INET6) {
6334 struct sockaddr_in6 *sin6;
6336 sin6 = (struct sockaddr_in6 *)addr;
6337 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6338 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6339 SCTP_TCB_UNLOCK(stcb);
6346 error = EAFNOSUPPORT;
6347 SCTP_TCB_UNLOCK(stcb);
6348 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6352 if (thlds->spt_pathcpthld != 0xffff) {
6354 SCTP_TCB_UNLOCK(stcb);
6357 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6362 net->failure_threshold = thlds->spt_pathmaxrxt;
6363 net->pf_threshold = thlds->spt_pathpfthld;
6364 if (net->dest_state & SCTP_ADDR_PF) {
6365 if ((net->error_count > net->failure_threshold) ||
6366 (net->error_count <= net->pf_threshold)) {
6367 net->dest_state &= ~SCTP_ADDR_PF;
6370 if ((net->error_count > net->pf_threshold) &&
6371 (net->error_count <= net->failure_threshold)) {
6372 net->dest_state |= SCTP_ADDR_PF;
6373 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6374 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6375 stcb->sctp_ep, stcb, net,
6376 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6377 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6380 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6381 if (net->error_count > net->failure_threshold) {
6382 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6383 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6386 if (net->error_count <= net->failure_threshold) {
6387 net->dest_state |= SCTP_ADDR_REACHABLE;
6388 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6392 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6393 net->failure_threshold = thlds->spt_pathmaxrxt;
6394 net->pf_threshold = thlds->spt_pathpfthld;
6395 if (net->dest_state & SCTP_ADDR_PF) {
6396 if ((net->error_count > net->failure_threshold) ||
6397 (net->error_count <= net->pf_threshold)) {
6398 net->dest_state &= ~SCTP_ADDR_PF;
6401 if ((net->error_count > net->pf_threshold) &&
6402 (net->error_count <= net->failure_threshold)) {
6403 net->dest_state |= SCTP_ADDR_PF;
6404 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6405 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6406 stcb->sctp_ep, stcb, net,
6407 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6408 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6411 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6412 if (net->error_count > net->failure_threshold) {
6413 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6414 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6417 if (net->error_count <= net->failure_threshold) {
6418 net->dest_state |= SCTP_ADDR_REACHABLE;
6419 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6423 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6424 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6426 SCTP_TCB_UNLOCK(stcb);
6428 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6429 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6430 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6431 SCTP_INP_WLOCK(inp);
6432 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6433 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6434 SCTP_INP_WUNLOCK(inp);
6436 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6442 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6444 struct sctp_udpencaps *encaps;
6445 struct sctp_nets *net;
6446 struct sockaddr *addr;
6447 #if defined(INET) && defined(INET6)
6448 struct sockaddr_in sin_store;
6451 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6452 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6454 #if defined(INET) && defined(INET6)
6455 if (encaps->sue_address.ss_family == AF_INET6) {
6456 struct sockaddr_in6 *sin6;
6458 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6459 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6460 in6_sin6_2_sin(&sin_store, sin6);
6461 addr = (struct sockaddr *)&sin_store;
6463 addr = (struct sockaddr *)&encaps->sue_address;
6466 addr = (struct sockaddr *)&encaps->sue_address;
6469 addr = (struct sockaddr *)&encaps->sue_address;
6472 net = sctp_findnet(stcb, addr);
6475 * We increment here since
6476 * sctp_findassociation_ep_addr() wil do a
6477 * decrement if it finds the stcb as long as
6478 * the locked tcb (last argument) is NOT a
6482 SCTP_INP_INCR_REF(inp);
6483 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6485 SCTP_INP_DECR_REF(inp);
6488 if ((stcb != NULL) && (net == NULL)) {
6490 if (addr->sa_family == AF_INET) {
6492 struct sockaddr_in *sin;
6494 sin = (struct sockaddr_in *)addr;
6495 if (sin->sin_addr.s_addr != INADDR_ANY) {
6496 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6497 SCTP_TCB_UNLOCK(stcb);
6504 if (addr->sa_family == AF_INET6) {
6505 struct sockaddr_in6 *sin6;
6507 sin6 = (struct sockaddr_in6 *)addr;
6508 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6509 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6510 SCTP_TCB_UNLOCK(stcb);
6517 error = EAFNOSUPPORT;
6518 SCTP_TCB_UNLOCK(stcb);
6519 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6526 net->port = encaps->sue_port;
6528 stcb->asoc.port = encaps->sue_port;
6530 SCTP_TCB_UNLOCK(stcb);
6532 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6533 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6534 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6535 SCTP_INP_WLOCK(inp);
6536 inp->sctp_ep.port = encaps->sue_port;
6537 SCTP_INP_WUNLOCK(inp);
6539 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6545 case SCTP_ECN_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->ecn_supported = 0;
6564 inp->ecn_supported = 1;
6566 SCTP_INP_WUNLOCK(inp);
6568 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6574 case SCTP_PR_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 SCTP_INP_WLOCK(inp);
6590 if (av->assoc_value == 0) {
6591 inp->prsctp_supported = 0;
6593 inp->prsctp_supported = 1;
6595 SCTP_INP_WUNLOCK(inp);
6597 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6603 case SCTP_AUTH_SUPPORTED:
6605 struct sctp_assoc_value *av;
6607 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6608 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6611 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6613 SCTP_TCB_UNLOCK(stcb);
6615 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6616 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6617 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6618 if ((av->assoc_value == 0) &&
6619 (inp->asconf_supported == 1)) {
6621 * AUTH is required for
6624 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6627 SCTP_INP_WLOCK(inp);
6628 if (av->assoc_value == 0) {
6629 inp->auth_supported = 0;
6631 inp->auth_supported = 1;
6633 SCTP_INP_WUNLOCK(inp);
6636 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6642 case SCTP_ASCONF_SUPPORTED:
6644 struct sctp_assoc_value *av;
6646 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6647 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6650 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6652 SCTP_TCB_UNLOCK(stcb);
6654 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6655 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6656 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6657 if ((av->assoc_value != 0) &&
6658 (inp->auth_supported == 0)) {
6660 * AUTH is required for
6663 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6666 SCTP_INP_WLOCK(inp);
6667 if (av->assoc_value == 0) {
6668 inp->asconf_supported = 0;
6669 sctp_auth_delete_chunk(SCTP_ASCONF,
6670 inp->sctp_ep.local_auth_chunks);
6671 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6672 inp->sctp_ep.local_auth_chunks);
6674 inp->asconf_supported = 1;
6675 sctp_auth_add_chunk(SCTP_ASCONF,
6676 inp->sctp_ep.local_auth_chunks);
6677 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6678 inp->sctp_ep.local_auth_chunks);
6680 SCTP_INP_WUNLOCK(inp);
6683 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6689 case SCTP_RECONFIG_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->reconfig_supported = 0;
6708 inp->reconfig_supported = 1;
6710 SCTP_INP_WUNLOCK(inp);
6712 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6718 case SCTP_NRSACK_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->nrsack_supported = 0;
6737 inp->nrsack_supported = 1;
6739 SCTP_INP_WUNLOCK(inp);
6741 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6747 case SCTP_PKTDROP_SUPPORTED:
6749 struct sctp_assoc_value *av;
6751 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6752 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6755 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6757 SCTP_TCB_UNLOCK(stcb);
6759 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6760 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6761 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6762 SCTP_INP_WLOCK(inp);
6763 if (av->assoc_value == 0) {
6764 inp->pktdrop_supported = 0;
6766 inp->pktdrop_supported = 1;
6768 SCTP_INP_WUNLOCK(inp);
6770 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6778 struct sctp_assoc_value *av;
6779 struct sctp_nets *net;
6781 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6782 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6785 stcb->asoc.max_cwnd = av->assoc_value;
6786 if (stcb->asoc.max_cwnd > 0) {
6787 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6788 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6789 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6790 net->cwnd = stcb->asoc.max_cwnd;
6791 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6792 net->cwnd = net->mtu - sizeof(struct sctphdr);
6797 SCTP_TCB_UNLOCK(stcb);
6799 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6800 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6801 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6802 SCTP_INP_WLOCK(inp);
6803 inp->max_cwnd = av->assoc_value;
6804 SCTP_INP_WUNLOCK(inp);
6806 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6813 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6814 error = ENOPROTOOPT;
6816 } /* end switch (opt) */
6821 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6823 void *optval = NULL;
6827 struct sctp_inpcb *inp;
6829 if ((sopt->sopt_level == SOL_SOCKET) &&
6830 (sopt->sopt_name == SO_SETFIB)) {
6831 inp = (struct sctp_inpcb *)so->so_pcb;
6833 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6836 SCTP_INP_WLOCK(inp);
6837 inp->fibnum = so->so_fibnum;
6838 SCTP_INP_WUNLOCK(inp);
6841 if (sopt->sopt_level != IPPROTO_SCTP) {
6842 /* wrong proto level... send back up to IP */
6844 if (INP_CHECK_SOCKAF(so, AF_INET6))
6845 error = ip6_ctloutput(so, sopt);
6847 #if defined(INET) && defined(INET6)
6851 error = ip_ctloutput(so, sopt);
6855 optsize = sopt->sopt_valsize;
6856 if (optsize > SCTP_SOCKET_OPTION_LIMIT) {
6857 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6861 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6862 if (optval == NULL) {
6863 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6866 error = sooptcopyin(sopt, optval, optsize, optsize);
6868 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6872 p = (void *)sopt->sopt_td;
6873 if (sopt->sopt_dir == SOPT_SET) {
6874 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6875 } else if (sopt->sopt_dir == SOPT_GET) {
6876 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6878 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6881 if ((error == 0) && (optval != NULL)) {
6882 error = sooptcopyout(sopt, optval, optsize);
6883 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6884 } else if (optval != NULL) {
6885 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6893 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6896 int create_lock_on = 0;
6898 struct sctp_inpcb *inp;
6899 struct sctp_tcb *stcb = NULL;
6901 inp = (struct sctp_inpcb *)so->so_pcb;
6903 /* I made the same as TCP since we are not setup? */
6904 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6905 return (ECONNRESET);
6908 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6912 switch (addr->sa_family) {
6916 struct sockaddr_in6 *sin6;
6918 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6919 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6922 sin6 = (struct sockaddr_in6 *)addr;
6923 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6->sin6_addr)) != 0) {
6924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6933 struct sockaddr_in *sin;
6935 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6936 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6939 sin = (struct sockaddr_in *)addr;
6940 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sin->sin_addr)) != 0) {
6941 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6949 return (EAFNOSUPPORT);
6951 SCTP_INP_INCR_REF(inp);
6952 SCTP_ASOC_CREATE_LOCK(inp);
6956 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6957 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6958 /* Should I really unlock ? */
6959 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6964 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6965 (addr->sa_family == AF_INET6)) {
6966 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6971 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6972 SCTP_PCB_FLAGS_UNBOUND) {
6973 /* Bind a ephemeral port */
6974 error = sctp_inpcb_bind(so, NULL, NULL, p);
6979 /* Now do we connect? */
6980 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6981 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6986 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6987 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6988 /* We are already connected AND the TCP model */
6989 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6993 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6994 SCTP_INP_RLOCK(inp);
6995 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6996 SCTP_INP_RUNLOCK(inp);
6999 * We increment here since sctp_findassociation_ep_addr()
7000 * will do a decrement if it finds the stcb as long as the
7001 * locked tcb (last argument) is NOT a TCB.. aka NULL.
7003 SCTP_INP_INCR_REF(inp);
7004 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7006 SCTP_INP_DECR_REF(inp);
7008 SCTP_TCB_UNLOCK(stcb);
7012 /* Already have or am bring up an association */
7013 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7018 vrf_id = inp->def_vrf_id;
7019 /* We are GOOD to go */
7020 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
7021 inp->sctp_ep.pre_open_stream_count,
7022 inp->sctp_ep.port, p,
7023 SCTP_INITIALIZE_AUTH_PARAMS);
7025 /* Gak! no memory */
7028 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7029 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7030 /* Set the connected flag so we can queue data */
7033 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7034 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7036 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7037 SCTP_TCB_UNLOCK(stcb);
7039 if (create_lock_on) {
7040 SCTP_ASOC_CREATE_UNLOCK(inp);
7043 SCTP_INP_DECR_REF(inp);
7049 sctp_listen(struct socket *so, int backlog, struct thread *p)
7052 * Note this module depends on the protocol processing being called
7053 * AFTER any socket level flags and backlog are applied to the
7054 * socket. The traditional way that the socket flags are applied is
7055 * AFTER protocol processing. We have made a change to the
7056 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7057 * place if the socket API for SCTP is to work properly.
7061 struct sctp_inpcb *inp;
7063 inp = (struct sctp_inpcb *)so->so_pcb;
7065 /* I made the same as TCP since we are not setup? */
7066 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7067 return (ECONNRESET);
7069 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7070 /* See if we have a listener */
7071 struct sctp_inpcb *tinp;
7072 union sctp_sockstore store;
7074 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7076 struct sctp_laddr *laddr;
7078 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7079 memcpy(&store, &laddr->ifa->address, sizeof(store));
7080 switch (store.sa.sa_family) {
7083 store.sin.sin_port = inp->sctp_lport;
7088 store.sin6.sin6_port = inp->sctp_lport;
7094 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7095 if (tinp && (tinp != inp) &&
7096 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7097 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7098 (SCTP_IS_LISTENING(tinp))) {
7100 * we have a listener already and
7103 SCTP_INP_DECR_REF(tinp);
7104 return (EADDRINUSE);
7106 SCTP_INP_DECR_REF(tinp);
7110 /* Setup a local addr bound all */
7111 memset(&store, 0, sizeof(store));
7113 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7114 store.sa.sa_family = AF_INET6;
7115 store.sa.sa_len = sizeof(struct sockaddr_in6);
7119 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7120 store.sa.sa_family = AF_INET;
7121 store.sa.sa_len = sizeof(struct sockaddr_in);
7124 switch (store.sa.sa_family) {
7127 store.sin.sin_port = inp->sctp_lport;
7132 store.sin6.sin6_port = inp->sctp_lport;
7138 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7139 if (tinp && (tinp != inp) &&
7140 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7141 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7142 (SCTP_IS_LISTENING(tinp))) {
7144 * we have a listener already and its not
7147 SCTP_INP_DECR_REF(tinp);
7148 return (EADDRINUSE);
7150 SCTP_INP_DECR_REF(tinp);
7154 SCTP_INP_RLOCK(inp);
7155 #ifdef SCTP_LOCK_LOGGING
7156 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7157 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7161 error = solisten_proto_check(so);
7164 SCTP_INP_RUNLOCK(inp);
7167 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7168 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7170 * The unlucky case - We are in the tcp pool with this guy.
7171 * - Someone else is in the main inp slot. - We must move
7172 * this guy (the listener) to the main slot - We must then
7173 * move the guy that was listener to the TCP Pool.
7175 if (sctp_swap_inpcb_for_listen(inp)) {
7176 SCTP_INP_RUNLOCK(inp);
7177 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7178 return (EADDRINUSE);
7182 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7183 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7184 /* We are already connected AND the TCP model */
7185 SCTP_INP_RUNLOCK(inp);
7186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7187 return (EADDRINUSE);
7189 SCTP_INP_RUNLOCK(inp);
7190 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7191 /* We must do a bind. */
7192 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7193 /* bind error, probably perm */
7197 SCTP_INP_WLOCK(inp);
7198 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7200 solisten_proto(so, backlog);
7204 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7206 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7208 SCTP_INP_WUNLOCK(inp);
7212 static int sctp_defered_wakeup_cnt = 0;
7215 sctp_accept(struct socket *so, struct sockaddr **addr)
7217 struct sctp_tcb *stcb;
7218 struct sctp_inpcb *inp;
7219 union sctp_sockstore store;
7223 inp = (struct sctp_inpcb *)so->so_pcb;
7226 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7227 return (ECONNRESET);
7229 SCTP_INP_WLOCK(inp);
7230 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7231 SCTP_INP_WUNLOCK(inp);
7232 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7233 return (EOPNOTSUPP);
7235 if (so->so_state & SS_ISDISCONNECTED) {
7236 SCTP_INP_WUNLOCK(inp);
7237 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7238 return (ECONNABORTED);
7240 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7242 SCTP_INP_WUNLOCK(inp);
7243 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7244 return (ECONNRESET);
7246 SCTP_TCB_LOCK(stcb);
7247 store = stcb->asoc.primary_destination->ro._l_addr;
7248 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7249 /* Wake any delayed sleep action */
7250 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7251 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7252 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7253 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7254 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7255 if (sowriteable(inp->sctp_socket)) {
7256 sowwakeup_locked(inp->sctp_socket);
7258 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7261 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7262 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7263 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7264 if (soreadable(inp->sctp_socket)) {
7265 sctp_defered_wakeup_cnt++;
7266 sorwakeup_locked(inp->sctp_socket);
7268 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7272 SCTP_INP_WUNLOCK(inp);
7273 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7274 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7275 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7277 SCTP_TCB_UNLOCK(stcb);
7279 switch (store.sa.sa_family) {
7283 struct sockaddr_in *sin;
7285 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7288 sin->sin_family = AF_INET;
7289 sin->sin_len = sizeof(*sin);
7290 sin->sin_port = store.sin.sin_port;
7291 sin->sin_addr = store.sin.sin_addr;
7292 *addr = (struct sockaddr *)sin;
7299 struct sockaddr_in6 *sin6;
7301 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7304 sin6->sin6_family = AF_INET6;
7305 sin6->sin6_len = sizeof(*sin6);
7306 sin6->sin6_port = store.sin6.sin6_port;
7307 sin6->sin6_addr = store.sin6.sin6_addr;
7308 if ((error = sa6_recoverscope(sin6)) != 0) {
7309 SCTP_FREE_SONAME(sin6);
7312 *addr = (struct sockaddr *)sin6;
7325 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7327 struct sockaddr_in *sin;
7329 struct sctp_inpcb *inp;
7330 struct sctp_ifa *sctp_ifa;
7333 * Do the malloc first in case it blocks.
7335 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7338 sin->sin_family = AF_INET;
7339 sin->sin_len = sizeof(*sin);
7340 inp = (struct sctp_inpcb *)so->so_pcb;
7342 SCTP_FREE_SONAME(sin);
7343 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7344 return (ECONNRESET);
7346 SCTP_INP_RLOCK(inp);
7347 sin->sin_port = inp->sctp_lport;
7348 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7349 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7350 struct sctp_tcb *stcb;
7351 struct sockaddr_in *sin_a;
7352 struct sctp_nets *net;
7355 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7361 SCTP_TCB_LOCK(stcb);
7362 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7363 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7365 /* this will make coverity happy */
7368 if (sin_a->sin_family == AF_INET) {
7373 if ((!fnd) || (sin_a == NULL)) {
7375 SCTP_TCB_UNLOCK(stcb);
7379 vrf_id = inp->def_vrf_id;
7380 sctp_ifa = sctp_source_address_selection(inp,
7382 (sctp_route_t *)&net->ro,
7385 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7386 sctp_free_ifa(sctp_ifa);
7388 SCTP_TCB_UNLOCK(stcb);
7390 /* For the bound all case you get back 0 */
7392 sin->sin_addr.s_addr = 0;
7396 /* Take the first IPv4 address in the list */
7397 struct sctp_laddr *laddr;
7400 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7401 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7402 struct sockaddr_in *sin_a;
7404 sin_a = &laddr->ifa->address.sin;
7405 sin->sin_addr = sin_a->sin_addr;
7411 SCTP_FREE_SONAME(sin);
7412 SCTP_INP_RUNLOCK(inp);
7413 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7417 SCTP_INP_RUNLOCK(inp);
7418 (*addr) = (struct sockaddr *)sin;
7423 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7425 struct sockaddr_in *sin;
7427 struct sockaddr_in *sin_a;
7428 struct sctp_inpcb *inp;
7429 struct sctp_tcb *stcb;
7430 struct sctp_nets *net;
7432 /* Do the malloc first in case it blocks. */
7433 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7436 sin->sin_family = AF_INET;
7437 sin->sin_len = sizeof(*sin);
7439 inp = (struct sctp_inpcb *)so->so_pcb;
7440 if ((inp == NULL) ||
7441 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7442 /* UDP type and listeners will drop out here */
7443 SCTP_FREE_SONAME(sin);
7444 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7447 SCTP_INP_RLOCK(inp);
7448 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7450 SCTP_TCB_LOCK(stcb);
7452 SCTP_INP_RUNLOCK(inp);
7454 SCTP_FREE_SONAME(sin);
7455 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7456 return (ECONNRESET);
7459 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7460 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7461 if (sin_a->sin_family == AF_INET) {
7463 sin->sin_port = stcb->rport;
7464 sin->sin_addr = sin_a->sin_addr;
7468 SCTP_TCB_UNLOCK(stcb);
7470 /* No IPv4 address */
7471 SCTP_FREE_SONAME(sin);
7472 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7475 (*addr) = (struct sockaddr *)sin;
7479 struct pr_usrreqs sctp_usrreqs = {
7480 .pru_abort = sctp_abort,
7481 .pru_accept = sctp_accept,
7482 .pru_attach = sctp_attach,
7483 .pru_bind = sctp_bind,
7484 .pru_connect = sctp_connect,
7485 .pru_control = in_control,
7486 .pru_close = sctp_close,
7487 .pru_detach = sctp_close,
7488 .pru_sopoll = sopoll_generic,
7489 .pru_flush = sctp_flush,
7490 .pru_disconnect = sctp_disconnect,
7491 .pru_listen = sctp_listen,
7492 .pru_peeraddr = sctp_peeraddr,
7493 .pru_send = sctp_sendm,
7494 .pru_shutdown = sctp_shutdown,
7495 .pru_sockaddr = sctp_ingetaddr,
7496 .pru_sosend = sctp_sosend,
7497 .pru_soreceive = sctp_soreceive