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 struct in6pcb *inp6;
1417 inp6 = (struct in6pcb *)inp;
1418 if (SCTP_IPV6_V6ONLY(inp6)) {
1420 * if IPV6_V6ONLY flag, ignore connections destined
1421 * to a v4 addr or v4-mapped addr
1423 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1429 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1430 SCTP_PCB_FLAGS_UNBOUND) {
1431 /* Bind a ephemeral port */
1432 error = sctp_inpcb_bind(so, NULL, NULL, p);
1438 /* FIX ME: do we want to pass in a vrf on the connect call? */
1439 vrf_id = inp->def_vrf_id;
1442 /* We are GOOD to go */
1443 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1444 inp->sctp_ep.pre_open_stream_count,
1447 SCTP_INITIALIZE_AUTH_PARAMS);
1449 /* Gak! no memory */
1452 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1453 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1454 /* Set the connected flag so we can queue data */
1457 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1458 /* move to second address */
1459 switch (sa->sa_family) {
1462 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1467 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1475 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1476 /* Fill in the return id */
1480 a_id = (sctp_assoc_t *)optval;
1481 *a_id = sctp_get_associd(stcb);
1484 /* doing delayed connection */
1485 stcb->asoc.delayed_connection = 1;
1486 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1488 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1489 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1491 SCTP_TCB_UNLOCK(stcb);
1493 if (creat_lock_on) {
1494 SCTP_ASOC_CREATE_UNLOCK(inp);
1496 SCTP_INP_DECR_REF(inp);
1500 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1501 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1502 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1503 SCTP_INP_RLOCK(inp); \
1504 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1506 SCTP_TCB_LOCK(stcb); \
1508 SCTP_INP_RUNLOCK(inp); \
1509 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1510 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1511 if (stcb == NULL) { \
1512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1522 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1523 if (size < sizeof(type)) { \
1524 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1528 destp = (type *)srcp; \
1533 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1536 struct sctp_inpcb *inp = NULL;
1538 struct sctp_tcb *stcb = NULL;
1540 if (optval == NULL) {
1541 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1545 inp = (struct sctp_inpcb *)so->so_pcb;
1547 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1554 case SCTP_AUTOCLOSE:
1555 case SCTP_EXPLICIT_EOR:
1556 case SCTP_AUTO_ASCONF:
1557 case SCTP_DISABLE_FRAGMENTS:
1558 case SCTP_I_WANT_MAPPED_V4_ADDR:
1559 case SCTP_USE_EXT_RCVINFO:
1560 SCTP_INP_RLOCK(inp);
1562 case SCTP_DISABLE_FRAGMENTS:
1563 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1565 case SCTP_I_WANT_MAPPED_V4_ADDR:
1566 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1568 case SCTP_AUTO_ASCONF:
1569 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1570 /* only valid for bound all sockets */
1571 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1573 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1578 case SCTP_EXPLICIT_EOR:
1579 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1582 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1584 case SCTP_USE_EXT_RCVINFO:
1585 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1587 case SCTP_AUTOCLOSE:
1588 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1589 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1595 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1596 error = ENOPROTOOPT;
1597 } /* end switch (sopt->sopt_name) */
1598 if (*optsize < sizeof(val)) {
1599 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1603 SCTP_INP_RUNLOCK(inp);
1605 /* return the option value */
1606 *(int *)optval = val;
1607 *optsize = sizeof(val);
1610 case SCTP_GET_PACKET_LOG:
1612 #ifdef SCTP_PACKET_LOGGING
1616 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1617 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1620 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1625 case SCTP_REUSE_PORT:
1629 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1630 /* Can't do this for a 1-m socket */
1634 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1635 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1636 *optsize = sizeof(uint32_t);
1639 case SCTP_PARTIAL_DELIVERY_POINT:
1643 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1644 *value = inp->partial_delivery_point;
1645 *optsize = sizeof(uint32_t);
1648 case SCTP_FRAGMENT_INTERLEAVE:
1652 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1653 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1654 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1655 *value = SCTP_FRAG_LEVEL_2;
1657 *value = SCTP_FRAG_LEVEL_1;
1660 *value = SCTP_FRAG_LEVEL_0;
1662 *optsize = sizeof(uint32_t);
1665 case SCTP_INTERLEAVING_SUPPORTED:
1667 struct sctp_assoc_value *av;
1669 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1670 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1673 av->assoc_value = stcb->asoc.idata_supported;
1674 SCTP_TCB_UNLOCK(stcb);
1676 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1677 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1678 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1679 SCTP_INP_RLOCK(inp);
1680 if (inp->idata_supported) {
1681 av->assoc_value = 1;
1683 av->assoc_value = 0;
1685 SCTP_INP_RUNLOCK(inp);
1687 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1692 *optsize = sizeof(struct sctp_assoc_value);
1696 case SCTP_CMT_ON_OFF:
1698 struct sctp_assoc_value *av;
1700 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1701 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1703 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1704 SCTP_TCB_UNLOCK(stcb);
1706 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1707 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1708 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1709 SCTP_INP_RLOCK(inp);
1710 av->assoc_value = inp->sctp_cmt_on_off;
1711 SCTP_INP_RUNLOCK(inp);
1713 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1718 *optsize = sizeof(struct sctp_assoc_value);
1722 case SCTP_PLUGGABLE_CC:
1724 struct sctp_assoc_value *av;
1726 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1727 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1729 av->assoc_value = stcb->asoc.congestion_control_module;
1730 SCTP_TCB_UNLOCK(stcb);
1732 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1733 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1734 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1735 SCTP_INP_RLOCK(inp);
1736 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1737 SCTP_INP_RUNLOCK(inp);
1739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1744 *optsize = sizeof(struct sctp_assoc_value);
1748 case SCTP_CC_OPTION:
1750 struct sctp_cc_option *cc_opt;
1752 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1753 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1757 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1760 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1761 *optsize = sizeof(struct sctp_cc_option);
1763 SCTP_TCB_UNLOCK(stcb);
1767 case SCTP_PLUGGABLE_SS:
1769 struct sctp_assoc_value *av;
1771 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1772 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1774 av->assoc_value = stcb->asoc.stream_scheduling_module;
1775 SCTP_TCB_UNLOCK(stcb);
1777 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1778 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1779 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1780 SCTP_INP_RLOCK(inp);
1781 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1782 SCTP_INP_RUNLOCK(inp);
1784 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1789 *optsize = sizeof(struct sctp_assoc_value);
1795 struct sctp_stream_value *av;
1797 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1798 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1800 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1801 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1802 &av->stream_value) < 0)) {
1803 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1806 *optsize = sizeof(struct sctp_stream_value);
1808 SCTP_TCB_UNLOCK(stcb);
1811 * Can't get stream value without
1814 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1819 case SCTP_GET_ADDR_LEN:
1821 struct sctp_assoc_value *av;
1823 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1826 if (av->assoc_value == AF_INET) {
1827 av->assoc_value = sizeof(struct sockaddr_in);
1832 if (av->assoc_value == AF_INET6) {
1833 av->assoc_value = sizeof(struct sockaddr_in6);
1838 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1840 *optsize = sizeof(struct sctp_assoc_value);
1844 case SCTP_GET_ASSOC_NUMBER:
1846 uint32_t *value, cnt;
1848 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1849 SCTP_INP_RLOCK(inp);
1850 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1851 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1852 /* Can't do this for a 1-1 socket */
1854 SCTP_INP_RUNLOCK(inp);
1858 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1861 SCTP_INP_RUNLOCK(inp);
1863 *optsize = sizeof(uint32_t);
1866 case SCTP_GET_ASSOC_ID_LIST:
1868 struct sctp_assoc_ids *ids;
1872 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1873 SCTP_INP_RLOCK(inp);
1874 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1875 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1876 /* Can't do this for a 1-1 socket */
1878 SCTP_INP_RUNLOCK(inp);
1882 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1883 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1885 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1888 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1893 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1897 SCTP_INP_RUNLOCK(inp);
1899 ids->gaids_number_of_ids = at;
1900 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1906 struct sctp_assoc_value *av;
1908 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1909 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1912 av->assoc_value = stcb->asoc.context;
1913 SCTP_TCB_UNLOCK(stcb);
1915 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1916 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1917 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1918 SCTP_INP_RLOCK(inp);
1919 av->assoc_value = inp->sctp_context;
1920 SCTP_INP_RUNLOCK(inp);
1922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1927 *optsize = sizeof(struct sctp_assoc_value);
1933 uint32_t *default_vrfid;
1935 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1936 *default_vrfid = inp->def_vrf_id;
1937 *optsize = sizeof(uint32_t);
1940 case SCTP_GET_ASOC_VRF:
1942 struct sctp_assoc_value *id;
1944 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1945 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1950 id->assoc_value = stcb->asoc.vrf_id;
1951 SCTP_TCB_UNLOCK(stcb);
1952 *optsize = sizeof(struct sctp_assoc_value);
1956 case SCTP_GET_VRF_IDS:
1958 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1962 case SCTP_GET_NONCE_VALUES:
1964 struct sctp_get_nonce_values *gnv;
1966 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1967 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1970 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1971 gnv->gn_local_tag = stcb->asoc.my_vtag;
1972 SCTP_TCB_UNLOCK(stcb);
1973 *optsize = sizeof(struct sctp_get_nonce_values);
1975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1980 case SCTP_DELAYED_SACK:
1982 struct sctp_sack_info *sack;
1984 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1985 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1987 sack->sack_delay = stcb->asoc.delayed_ack;
1988 sack->sack_freq = stcb->asoc.sack_freq;
1989 SCTP_TCB_UNLOCK(stcb);
1991 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1992 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1993 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
1994 SCTP_INP_RLOCK(inp);
1995 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1996 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
1997 SCTP_INP_RUNLOCK(inp);
1999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2004 *optsize = sizeof(struct sctp_sack_info);
2008 case SCTP_GET_SNDBUF_USE:
2010 struct sctp_sockstat *ss;
2012 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2013 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2016 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2017 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2018 stcb->asoc.size_on_all_streams);
2019 SCTP_TCB_UNLOCK(stcb);
2020 *optsize = sizeof(struct sctp_sockstat);
2022 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2027 case SCTP_MAX_BURST:
2029 struct sctp_assoc_value *av;
2031 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2032 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2035 av->assoc_value = stcb->asoc.max_burst;
2036 SCTP_TCB_UNLOCK(stcb);
2038 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2039 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2040 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2041 SCTP_INP_RLOCK(inp);
2042 av->assoc_value = inp->sctp_ep.max_burst;
2043 SCTP_INP_RUNLOCK(inp);
2045 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2050 *optsize = sizeof(struct sctp_assoc_value);
2056 struct sctp_assoc_value *av;
2059 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2060 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2063 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2064 SCTP_TCB_UNLOCK(stcb);
2066 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2067 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2068 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2069 SCTP_INP_RLOCK(inp);
2070 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2071 ovh = SCTP_MED_OVERHEAD;
2073 ovh = SCTP_MED_V4_OVERHEAD;
2075 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2076 av->assoc_value = 0;
2078 av->assoc_value = inp->sctp_frag_point - ovh;
2079 SCTP_INP_RUNLOCK(inp);
2081 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2086 *optsize = sizeof(struct sctp_assoc_value);
2090 case SCTP_GET_STAT_LOG:
2091 error = sctp_fill_stat_log(optval, optsize);
2095 struct sctp_event_subscribe *events;
2097 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2098 memset(events, 0, sizeof(struct sctp_event_subscribe));
2099 SCTP_INP_RLOCK(inp);
2100 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2101 events->sctp_data_io_event = 1;
2103 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2104 events->sctp_association_event = 1;
2106 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2107 events->sctp_address_event = 1;
2109 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2110 events->sctp_send_failure_event = 1;
2112 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2113 events->sctp_peer_error_event = 1;
2115 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2116 events->sctp_shutdown_event = 1;
2118 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2119 events->sctp_partial_delivery_event = 1;
2121 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2122 events->sctp_adaptation_layer_event = 1;
2124 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2125 events->sctp_authentication_event = 1;
2127 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2128 events->sctp_sender_dry_event = 1;
2130 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2131 events->sctp_stream_reset_event = 1;
2132 SCTP_INP_RUNLOCK(inp);
2133 *optsize = sizeof(struct sctp_event_subscribe);
2136 case SCTP_ADAPTATION_LAYER:
2140 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2142 SCTP_INP_RLOCK(inp);
2143 *value = inp->sctp_ep.adaptation_layer_indicator;
2144 SCTP_INP_RUNLOCK(inp);
2145 *optsize = sizeof(uint32_t);
2148 case SCTP_SET_INITIAL_DBG_SEQ:
2152 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2153 SCTP_INP_RLOCK(inp);
2154 *value = inp->sctp_ep.initial_sequence_debug;
2155 SCTP_INP_RUNLOCK(inp);
2156 *optsize = sizeof(uint32_t);
2159 case SCTP_GET_LOCAL_ADDR_SIZE:
2163 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2164 SCTP_INP_RLOCK(inp);
2165 *value = sctp_count_max_addresses(inp);
2166 SCTP_INP_RUNLOCK(inp);
2167 *optsize = sizeof(uint32_t);
2170 case SCTP_GET_REMOTE_ADDR_SIZE:
2174 struct sctp_nets *net;
2176 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2177 /* FIXME MT: change to sctp_assoc_value? */
2178 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2182 /* Count the sizes */
2183 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2184 switch (net->ro._l_addr.sa.sa_family) {
2188 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2189 size += sizeof(struct sockaddr_in6);
2191 size += sizeof(struct sockaddr_in);
2194 size += sizeof(struct sockaddr_in);
2200 size += sizeof(struct sockaddr_in6);
2207 SCTP_TCB_UNLOCK(stcb);
2208 *value = (uint32_t)size;
2209 *optsize = sizeof(uint32_t);
2211 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2216 case SCTP_GET_PEER_ADDRESSES:
2218 * Get the address information, an array is passed in to
2219 * fill up we pack it.
2223 struct sockaddr_storage *sas;
2224 struct sctp_nets *net;
2225 struct sctp_getaddresses *saddr;
2227 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2228 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2231 left = (*optsize) - sizeof(sctp_assoc_t);
2232 *optsize = sizeof(sctp_assoc_t);
2233 sas = (struct sockaddr_storage *)&saddr->addr[0];
2235 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2236 switch (net->ro._l_addr.sa.sa_family) {
2240 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2241 cpsz = sizeof(struct sockaddr_in6);
2243 cpsz = sizeof(struct sockaddr_in);
2246 cpsz = sizeof(struct sockaddr_in);
2252 cpsz = sizeof(struct sockaddr_in6);
2263 /* not enough room. */
2266 #if defined(INET) && defined(INET6)
2267 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2268 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2269 /* Must map the address */
2270 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2271 (struct sockaddr_in6 *)sas);
2273 memcpy(sas, &net->ro._l_addr, cpsz);
2276 memcpy(sas, &net->ro._l_addr, cpsz);
2278 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2280 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2284 SCTP_TCB_UNLOCK(stcb);
2286 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2291 case SCTP_GET_LOCAL_ADDRESSES:
2293 size_t limit, actual;
2294 struct sockaddr_storage *sas;
2295 struct sctp_getaddresses *saddr;
2297 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2298 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2300 sas = (struct sockaddr_storage *)&saddr->addr[0];
2301 limit = *optsize - sizeof(sctp_assoc_t);
2302 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2304 SCTP_TCB_UNLOCK(stcb);
2306 *optsize = sizeof(sctp_assoc_t) + actual;
2309 case SCTP_PEER_ADDR_PARAMS:
2311 struct sctp_paddrparams *paddrp;
2312 struct sctp_nets *net;
2313 struct sockaddr *addr;
2314 #if defined(INET) && defined(INET6)
2315 struct sockaddr_in sin_store;
2318 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2319 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2321 #if defined(INET) && defined(INET6)
2322 if (paddrp->spp_address.ss_family == AF_INET6) {
2323 struct sockaddr_in6 *sin6;
2325 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2326 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2327 in6_sin6_2_sin(&sin_store, sin6);
2328 addr = (struct sockaddr *)&sin_store;
2330 addr = (struct sockaddr *)&paddrp->spp_address;
2333 addr = (struct sockaddr *)&paddrp->spp_address;
2336 addr = (struct sockaddr *)&paddrp->spp_address;
2339 net = sctp_findnet(stcb, addr);
2342 * We increment here since
2343 * sctp_findassociation_ep_addr() wil do a
2344 * decrement if it finds the stcb as long as
2345 * the locked tcb (last argument) is NOT a
2349 SCTP_INP_INCR_REF(inp);
2350 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2352 SCTP_INP_DECR_REF(inp);
2355 if ((stcb != NULL) && (net == NULL)) {
2357 if (addr->sa_family == AF_INET) {
2358 struct sockaddr_in *sin;
2360 sin = (struct sockaddr_in *)addr;
2361 if (sin->sin_addr.s_addr != INADDR_ANY) {
2363 SCTP_TCB_UNLOCK(stcb);
2364 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2370 if (addr->sa_family == AF_INET6) {
2371 struct sockaddr_in6 *sin6;
2373 sin6 = (struct sockaddr_in6 *)addr;
2374 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2376 SCTP_TCB_UNLOCK(stcb);
2377 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2383 error = EAFNOSUPPORT;
2384 SCTP_TCB_UNLOCK(stcb);
2385 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2391 /* Applies to the specific association */
2392 paddrp->spp_flags = 0;
2394 paddrp->spp_hbinterval = net->heart_beat_delay;
2395 paddrp->spp_pathmaxrxt = net->failure_threshold;
2396 paddrp->spp_pathmtu = net->mtu;
2397 switch (net->ro._l_addr.sa.sa_family) {
2400 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2405 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2411 /* get flags for HB */
2412 if (net->dest_state & SCTP_ADDR_NOHB) {
2413 paddrp->spp_flags |= SPP_HB_DISABLE;
2415 paddrp->spp_flags |= SPP_HB_ENABLE;
2417 /* get flags for PMTU */
2418 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2419 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2421 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2423 if (net->dscp & 0x01) {
2424 paddrp->spp_dscp = net->dscp & 0xfc;
2425 paddrp->spp_flags |= SPP_DSCP;
2428 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2429 (net->flowlabel & 0x80000000)) {
2430 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2431 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2436 * No destination so return default
2439 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2440 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2441 if (stcb->asoc.default_dscp & 0x01) {
2442 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2443 paddrp->spp_flags |= SPP_DSCP;
2446 if (stcb->asoc.default_flowlabel & 0x80000000) {
2447 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2448 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2451 /* default settings should be these */
2452 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2453 paddrp->spp_flags |= SPP_HB_DISABLE;
2455 paddrp->spp_flags |= SPP_HB_ENABLE;
2457 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2458 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2460 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2462 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2464 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2465 SCTP_TCB_UNLOCK(stcb);
2467 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2468 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2469 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2470 /* Use endpoint defaults */
2471 SCTP_INP_RLOCK(inp);
2472 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2473 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2474 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2475 /* get inp's default */
2476 if (inp->sctp_ep.default_dscp & 0x01) {
2477 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2478 paddrp->spp_flags |= SPP_DSCP;
2481 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2482 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2483 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2484 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2487 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2489 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2490 paddrp->spp_flags |= SPP_HB_ENABLE;
2492 paddrp->spp_flags |= SPP_HB_DISABLE;
2494 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2495 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2497 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2499 SCTP_INP_RUNLOCK(inp);
2501 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2506 *optsize = sizeof(struct sctp_paddrparams);
2510 case SCTP_GET_PEER_ADDR_INFO:
2512 struct sctp_paddrinfo *paddri;
2513 struct sctp_nets *net;
2514 struct sockaddr *addr;
2515 #if defined(INET) && defined(INET6)
2516 struct sockaddr_in sin_store;
2519 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2520 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2522 #if defined(INET) && defined(INET6)
2523 if (paddri->spinfo_address.ss_family == AF_INET6) {
2524 struct sockaddr_in6 *sin6;
2526 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2527 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2528 in6_sin6_2_sin(&sin_store, sin6);
2529 addr = (struct sockaddr *)&sin_store;
2531 addr = (struct sockaddr *)&paddri->spinfo_address;
2534 addr = (struct sockaddr *)&paddri->spinfo_address;
2537 addr = (struct sockaddr *)&paddri->spinfo_address;
2540 net = sctp_findnet(stcb, addr);
2543 * We increment here since
2544 * sctp_findassociation_ep_addr() wil do a
2545 * decrement if it finds the stcb as long as
2546 * the locked tcb (last argument) is NOT a
2550 SCTP_INP_INCR_REF(inp);
2551 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2553 SCTP_INP_DECR_REF(inp);
2557 if ((stcb != NULL) && (net != NULL)) {
2558 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2559 /* It's unconfirmed */
2560 paddri->spinfo_state = SCTP_UNCONFIRMED;
2561 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2563 paddri->spinfo_state = SCTP_ACTIVE;
2566 paddri->spinfo_state = SCTP_INACTIVE;
2568 paddri->spinfo_cwnd = net->cwnd;
2569 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2570 paddri->spinfo_rto = net->RTO;
2571 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2572 paddri->spinfo_mtu = net->mtu;
2573 switch (addr->sa_family) {
2576 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2581 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2587 SCTP_TCB_UNLOCK(stcb);
2588 *optsize = sizeof(struct sctp_paddrinfo);
2591 SCTP_TCB_UNLOCK(stcb);
2593 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2598 case SCTP_PCB_STATUS:
2600 struct sctp_pcbinfo *spcb;
2602 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2603 sctp_fill_pcbinfo(spcb);
2604 *optsize = sizeof(struct sctp_pcbinfo);
2609 struct sctp_nets *net;
2610 struct sctp_status *sstat;
2612 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2613 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2616 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2620 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2621 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2622 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2623 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2625 * We can't include chunks that have been passed to
2626 * the socket layer. Only things in queue.
2628 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2629 stcb->asoc.cnt_on_all_streams);
2632 sstat->sstat_instrms = stcb->asoc.streamincnt;
2633 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2634 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2635 net = stcb->asoc.primary_destination;
2637 memcpy(&sstat->sstat_primary.spinfo_address,
2638 &stcb->asoc.primary_destination->ro._l_addr,
2639 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2640 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2642 * Again the user can get info from
2643 * sctp_constants.h for what the state of
2646 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2647 /* It's unconfirmed */
2648 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2649 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2651 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2654 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2656 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2657 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2658 sstat->sstat_primary.spinfo_rto = net->RTO;
2659 sstat->sstat_primary.spinfo_mtu = net->mtu;
2660 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2663 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2668 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2675 memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo));
2677 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2678 SCTP_TCB_UNLOCK(stcb);
2679 *optsize = sizeof(struct sctp_status);
2684 struct sctp_rtoinfo *srto;
2686 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2687 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2690 srto->srto_initial = stcb->asoc.initial_rto;
2691 srto->srto_max = stcb->asoc.maxrto;
2692 srto->srto_min = stcb->asoc.minrto;
2693 SCTP_TCB_UNLOCK(stcb);
2695 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2696 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2697 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2698 SCTP_INP_RLOCK(inp);
2699 srto->srto_initial = inp->sctp_ep.initial_rto;
2700 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2701 srto->srto_min = inp->sctp_ep.sctp_minrto;
2702 SCTP_INP_RUNLOCK(inp);
2704 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2709 *optsize = sizeof(struct sctp_rtoinfo);
2715 struct sctp_timeouts *stimo;
2717 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2718 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2721 stimo->stimo_init = stcb->asoc.timoinit;
2722 stimo->stimo_data = stcb->asoc.timodata;
2723 stimo->stimo_sack = stcb->asoc.timosack;
2724 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2725 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2726 stimo->stimo_cookie = stcb->asoc.timocookie;
2727 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2728 SCTP_TCB_UNLOCK(stcb);
2729 *optsize = sizeof(struct sctp_timeouts);
2731 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2736 case SCTP_ASSOCINFO:
2738 struct sctp_assocparams *sasoc;
2740 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2741 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2744 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2745 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2746 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2747 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2748 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2749 SCTP_TCB_UNLOCK(stcb);
2751 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2752 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2753 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2754 SCTP_INP_RLOCK(inp);
2755 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2756 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2757 sasoc->sasoc_number_peer_destinations = 0;
2758 sasoc->sasoc_peer_rwnd = 0;
2759 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2760 SCTP_INP_RUNLOCK(inp);
2762 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2767 *optsize = sizeof(struct sctp_assocparams);
2771 case SCTP_DEFAULT_SEND_PARAM:
2773 struct sctp_sndrcvinfo *s_info;
2775 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2776 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2779 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2780 SCTP_TCB_UNLOCK(stcb);
2782 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2783 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2784 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2785 SCTP_INP_RLOCK(inp);
2786 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2787 SCTP_INP_RUNLOCK(inp);
2789 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2794 *optsize = sizeof(struct sctp_sndrcvinfo);
2800 struct sctp_initmsg *sinit;
2802 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2803 SCTP_INP_RLOCK(inp);
2804 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2805 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2806 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2807 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2808 SCTP_INP_RUNLOCK(inp);
2809 *optsize = sizeof(struct sctp_initmsg);
2812 case SCTP_PRIMARY_ADDR:
2813 /* we allow a "get" operation on this */
2815 struct sctp_setprim *ssp;
2817 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2818 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2821 union sctp_sockstore *addr;
2823 addr = &stcb->asoc.primary_destination->ro._l_addr;
2824 switch (addr->sa.sa_family) {
2828 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2829 in6_sin_2_v4mapsin6(&addr->sin,
2830 (struct sockaddr_in6 *)&ssp->ssp_addr);
2832 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2835 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2841 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2847 SCTP_TCB_UNLOCK(stcb);
2848 *optsize = sizeof(struct sctp_setprim);
2850 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2855 case SCTP_HMAC_IDENT:
2857 struct sctp_hmacalgo *shmac;
2858 sctp_hmaclist_t *hmaclist;
2862 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2864 SCTP_INP_RLOCK(inp);
2865 hmaclist = inp->sctp_ep.local_hmacs;
2866 if (hmaclist == NULL) {
2867 /* no HMACs to return */
2868 *optsize = sizeof(*shmac);
2869 SCTP_INP_RUNLOCK(inp);
2872 /* is there room for all of the hmac ids? */
2873 size = sizeof(*shmac) + (hmaclist->num_algo *
2874 sizeof(shmac->shmac_idents[0]));
2875 if ((size_t)(*optsize) < size) {
2876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2878 SCTP_INP_RUNLOCK(inp);
2881 /* copy in the list */
2882 shmac->shmac_number_of_idents = hmaclist->num_algo;
2883 for (i = 0; i < hmaclist->num_algo; i++) {
2884 shmac->shmac_idents[i] = hmaclist->hmac[i];
2886 SCTP_INP_RUNLOCK(inp);
2890 case SCTP_AUTH_ACTIVE_KEY:
2892 struct sctp_authkeyid *scact;
2894 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2895 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2898 /* get the active key on the assoc */
2899 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2900 SCTP_TCB_UNLOCK(stcb);
2902 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2903 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2904 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2905 /* get the endpoint active key */
2906 SCTP_INP_RLOCK(inp);
2907 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2908 SCTP_INP_RUNLOCK(inp);
2910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2915 *optsize = sizeof(struct sctp_authkeyid);
2919 case SCTP_LOCAL_AUTH_CHUNKS:
2921 struct sctp_authchunks *sac;
2922 sctp_auth_chklist_t *chklist = NULL;
2925 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2926 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2929 /* get off the assoc */
2930 chklist = stcb->asoc.local_auth_chunks;
2931 /* is there enough space? */
2932 size = sctp_auth_get_chklist_size(chklist);
2933 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2935 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2937 /* copy in the chunks */
2938 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2939 sac->gauth_number_of_chunks = (uint32_t)size;
2940 *optsize = sizeof(struct sctp_authchunks) + size;
2942 SCTP_TCB_UNLOCK(stcb);
2944 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2945 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2946 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2947 /* get off the endpoint */
2948 SCTP_INP_RLOCK(inp);
2949 chklist = inp->sctp_ep.local_auth_chunks;
2950 /* is there enough space? */
2951 size = sctp_auth_get_chklist_size(chklist);
2952 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2954 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2956 /* copy in the chunks */
2957 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2958 sac->gauth_number_of_chunks = (uint32_t)size;
2959 *optsize = sizeof(struct sctp_authchunks) + size;
2961 SCTP_INP_RUNLOCK(inp);
2963 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2969 case SCTP_PEER_AUTH_CHUNKS:
2971 struct sctp_authchunks *sac;
2972 sctp_auth_chklist_t *chklist = NULL;
2975 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2976 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2979 /* get off the assoc */
2980 chklist = stcb->asoc.peer_auth_chunks;
2981 /* is there enough space? */
2982 size = sctp_auth_get_chklist_size(chklist);
2983 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2985 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2987 /* copy in the chunks */
2988 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2989 sac->gauth_number_of_chunks = (uint32_t)size;
2990 *optsize = sizeof(struct sctp_authchunks) + size;
2992 SCTP_TCB_UNLOCK(stcb);
2994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3001 struct sctp_event *event;
3002 uint32_t event_type;
3004 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3005 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3007 switch (event->se_type) {
3008 case SCTP_ASSOC_CHANGE:
3009 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3011 case SCTP_PEER_ADDR_CHANGE:
3012 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3014 case SCTP_REMOTE_ERROR:
3015 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3017 case SCTP_SEND_FAILED:
3018 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3020 case SCTP_SHUTDOWN_EVENT:
3021 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3023 case SCTP_ADAPTATION_INDICATION:
3024 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3026 case SCTP_PARTIAL_DELIVERY_EVENT:
3027 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3029 case SCTP_AUTHENTICATION_EVENT:
3030 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3032 case SCTP_STREAM_RESET_EVENT:
3033 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3035 case SCTP_SENDER_DRY_EVENT:
3036 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3038 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3040 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3043 case SCTP_ASSOC_RESET_EVENT:
3044 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3046 case SCTP_STREAM_CHANGE_EVENT:
3047 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3049 case SCTP_SEND_FAILED_EVENT:
3050 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3054 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3058 if (event_type > 0) {
3060 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3062 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3063 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3064 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3065 SCTP_INP_RLOCK(inp);
3066 event->se_on = sctp_is_feature_on(inp, event_type);
3067 SCTP_INP_RUNLOCK(inp);
3069 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3075 SCTP_TCB_UNLOCK(stcb);
3078 *optsize = sizeof(struct sctp_event);
3082 case SCTP_RECVRCVINFO:
3086 if (*optsize < sizeof(int)) {
3087 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3090 SCTP_INP_RLOCK(inp);
3091 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3092 SCTP_INP_RUNLOCK(inp);
3095 /* return the option value */
3096 *(int *)optval = onoff;
3097 *optsize = sizeof(int);
3101 case SCTP_RECVNXTINFO:
3105 if (*optsize < sizeof(int)) {
3106 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3109 SCTP_INP_RLOCK(inp);
3110 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3111 SCTP_INP_RUNLOCK(inp);
3114 /* return the option value */
3115 *(int *)optval = onoff;
3116 *optsize = sizeof(int);
3120 case SCTP_DEFAULT_SNDINFO:
3122 struct sctp_sndinfo *info;
3124 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3125 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3128 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3129 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3130 info->snd_flags &= 0xfff0;
3131 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3132 info->snd_context = stcb->asoc.def_send.sinfo_context;
3133 SCTP_TCB_UNLOCK(stcb);
3135 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3136 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3137 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3138 SCTP_INP_RLOCK(inp);
3139 info->snd_sid = inp->def_send.sinfo_stream;
3140 info->snd_flags = inp->def_send.sinfo_flags;
3141 info->snd_flags &= 0xfff0;
3142 info->snd_ppid = inp->def_send.sinfo_ppid;
3143 info->snd_context = inp->def_send.sinfo_context;
3144 SCTP_INP_RUNLOCK(inp);
3146 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3151 *optsize = sizeof(struct sctp_sndinfo);
3155 case SCTP_DEFAULT_PRINFO:
3157 struct sctp_default_prinfo *info;
3159 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3160 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3163 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3164 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3165 SCTP_TCB_UNLOCK(stcb);
3167 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3168 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3169 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3170 SCTP_INP_RLOCK(inp);
3171 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3172 info->pr_value = inp->def_send.sinfo_timetolive;
3173 SCTP_INP_RUNLOCK(inp);
3175 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3180 *optsize = sizeof(struct sctp_default_prinfo);
3184 case SCTP_PEER_ADDR_THLDS:
3186 struct sctp_paddrthlds *thlds;
3187 struct sctp_nets *net;
3188 struct sockaddr *addr;
3189 #if defined(INET) && defined(INET6)
3190 struct sockaddr_in sin_store;
3193 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3194 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3196 #if defined(INET) && defined(INET6)
3197 if (thlds->spt_address.ss_family == AF_INET6) {
3198 struct sockaddr_in6 *sin6;
3200 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3201 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3202 in6_sin6_2_sin(&sin_store, sin6);
3203 addr = (struct sockaddr *)&sin_store;
3205 addr = (struct sockaddr *)&thlds->spt_address;
3208 addr = (struct sockaddr *)&thlds->spt_address;
3211 addr = (struct sockaddr *)&thlds->spt_address;
3214 net = sctp_findnet(stcb, addr);
3217 * We increment here since
3218 * sctp_findassociation_ep_addr() wil do a
3219 * decrement if it finds the stcb as long as
3220 * the locked tcb (last argument) is NOT a
3224 SCTP_INP_INCR_REF(inp);
3225 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3227 SCTP_INP_DECR_REF(inp);
3230 if ((stcb != NULL) && (net == NULL)) {
3232 if (addr->sa_family == AF_INET) {
3233 struct sockaddr_in *sin;
3235 sin = (struct sockaddr_in *)addr;
3236 if (sin->sin_addr.s_addr != INADDR_ANY) {
3238 SCTP_TCB_UNLOCK(stcb);
3239 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3245 if (addr->sa_family == AF_INET6) {
3246 struct sockaddr_in6 *sin6;
3248 sin6 = (struct sockaddr_in6 *)addr;
3249 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3251 SCTP_TCB_UNLOCK(stcb);
3252 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3258 error = EAFNOSUPPORT;
3259 SCTP_TCB_UNLOCK(stcb);
3260 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3267 thlds->spt_pathmaxrxt = net->failure_threshold;
3268 thlds->spt_pathpfthld = net->pf_threshold;
3269 thlds->spt_pathcpthld = 0xffff;
3271 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3272 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3273 thlds->spt_pathcpthld = 0xffff;
3275 thlds->spt_assoc_id = sctp_get_associd(stcb);
3276 SCTP_TCB_UNLOCK(stcb);
3278 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3279 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3280 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3281 /* Use endpoint defaults */
3282 SCTP_INP_RLOCK(inp);
3283 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3284 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3285 thlds->spt_pathcpthld = 0xffff;
3286 SCTP_INP_RUNLOCK(inp);
3288 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3293 *optsize = sizeof(struct sctp_paddrthlds);
3297 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3299 struct sctp_udpencaps *encaps;
3300 struct sctp_nets *net;
3301 struct sockaddr *addr;
3302 #if defined(INET) && defined(INET6)
3303 struct sockaddr_in sin_store;
3306 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3307 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3309 #if defined(INET) && defined(INET6)
3310 if (encaps->sue_address.ss_family == AF_INET6) {
3311 struct sockaddr_in6 *sin6;
3313 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3314 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3315 in6_sin6_2_sin(&sin_store, sin6);
3316 addr = (struct sockaddr *)&sin_store;
3318 addr = (struct sockaddr *)&encaps->sue_address;
3321 addr = (struct sockaddr *)&encaps->sue_address;
3324 addr = (struct sockaddr *)&encaps->sue_address;
3327 net = sctp_findnet(stcb, addr);
3330 * We increment here since
3331 * sctp_findassociation_ep_addr() wil do a
3332 * decrement if it finds the stcb as long as
3333 * the locked tcb (last argument) is NOT a
3337 SCTP_INP_INCR_REF(inp);
3338 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3340 SCTP_INP_DECR_REF(inp);
3343 if ((stcb != NULL) && (net == NULL)) {
3345 if (addr->sa_family == AF_INET) {
3346 struct sockaddr_in *sin;
3348 sin = (struct sockaddr_in *)addr;
3349 if (sin->sin_addr.s_addr != INADDR_ANY) {
3351 SCTP_TCB_UNLOCK(stcb);
3352 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3358 if (addr->sa_family == AF_INET6) {
3359 struct sockaddr_in6 *sin6;
3361 sin6 = (struct sockaddr_in6 *)addr;
3362 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3364 SCTP_TCB_UNLOCK(stcb);
3365 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3371 error = EAFNOSUPPORT;
3372 SCTP_TCB_UNLOCK(stcb);
3373 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3380 encaps->sue_port = net->port;
3382 encaps->sue_port = stcb->asoc.port;
3384 SCTP_TCB_UNLOCK(stcb);
3386 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3387 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3388 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3389 SCTP_INP_RLOCK(inp);
3390 encaps->sue_port = inp->sctp_ep.port;
3391 SCTP_INP_RUNLOCK(inp);
3393 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3398 *optsize = sizeof(struct sctp_udpencaps);
3402 case SCTP_ECN_SUPPORTED:
3404 struct sctp_assoc_value *av;
3406 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3407 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3410 av->assoc_value = stcb->asoc.ecn_supported;
3411 SCTP_TCB_UNLOCK(stcb);
3413 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3414 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3415 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3416 SCTP_INP_RLOCK(inp);
3417 av->assoc_value = inp->ecn_supported;
3418 SCTP_INP_RUNLOCK(inp);
3420 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3425 *optsize = sizeof(struct sctp_assoc_value);
3429 case SCTP_PR_SUPPORTED:
3431 struct sctp_assoc_value *av;
3433 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3434 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3437 av->assoc_value = stcb->asoc.prsctp_supported;
3438 SCTP_TCB_UNLOCK(stcb);
3440 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3441 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3442 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3443 SCTP_INP_RLOCK(inp);
3444 av->assoc_value = inp->prsctp_supported;
3445 SCTP_INP_RUNLOCK(inp);
3447 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3452 *optsize = sizeof(struct sctp_assoc_value);
3456 case SCTP_AUTH_SUPPORTED:
3458 struct sctp_assoc_value *av;
3460 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3461 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3464 av->assoc_value = stcb->asoc.auth_supported;
3465 SCTP_TCB_UNLOCK(stcb);
3467 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3468 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3469 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3470 SCTP_INP_RLOCK(inp);
3471 av->assoc_value = inp->auth_supported;
3472 SCTP_INP_RUNLOCK(inp);
3474 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3479 *optsize = sizeof(struct sctp_assoc_value);
3483 case SCTP_ASCONF_SUPPORTED:
3485 struct sctp_assoc_value *av;
3487 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3488 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3491 av->assoc_value = stcb->asoc.asconf_supported;
3492 SCTP_TCB_UNLOCK(stcb);
3494 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3495 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3496 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3497 SCTP_INP_RLOCK(inp);
3498 av->assoc_value = inp->asconf_supported;
3499 SCTP_INP_RUNLOCK(inp);
3501 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3506 *optsize = sizeof(struct sctp_assoc_value);
3510 case SCTP_RECONFIG_SUPPORTED:
3512 struct sctp_assoc_value *av;
3514 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3515 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3518 av->assoc_value = stcb->asoc.reconfig_supported;
3519 SCTP_TCB_UNLOCK(stcb);
3521 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3522 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3523 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3524 SCTP_INP_RLOCK(inp);
3525 av->assoc_value = inp->reconfig_supported;
3526 SCTP_INP_RUNLOCK(inp);
3528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3533 *optsize = sizeof(struct sctp_assoc_value);
3537 case SCTP_NRSACK_SUPPORTED:
3539 struct sctp_assoc_value *av;
3541 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3542 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3545 av->assoc_value = stcb->asoc.nrsack_supported;
3546 SCTP_TCB_UNLOCK(stcb);
3548 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3549 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3550 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3551 SCTP_INP_RLOCK(inp);
3552 av->assoc_value = inp->nrsack_supported;
3553 SCTP_INP_RUNLOCK(inp);
3555 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3560 *optsize = sizeof(struct sctp_assoc_value);
3564 case SCTP_PKTDROP_SUPPORTED:
3566 struct sctp_assoc_value *av;
3568 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3569 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3572 av->assoc_value = stcb->asoc.pktdrop_supported;
3573 SCTP_TCB_UNLOCK(stcb);
3575 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3576 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3577 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3578 SCTP_INP_RLOCK(inp);
3579 av->assoc_value = inp->pktdrop_supported;
3580 SCTP_INP_RUNLOCK(inp);
3582 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3587 *optsize = sizeof(struct sctp_assoc_value);
3591 case SCTP_ENABLE_STREAM_RESET:
3593 struct sctp_assoc_value *av;
3595 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3596 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3599 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3600 SCTP_TCB_UNLOCK(stcb);
3602 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3603 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3604 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3605 SCTP_INP_RLOCK(inp);
3606 av->assoc_value = (uint32_t)inp->local_strreset_support;
3607 SCTP_INP_RUNLOCK(inp);
3609 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3614 *optsize = sizeof(struct sctp_assoc_value);
3618 case SCTP_PR_STREAM_STATUS:
3620 struct sctp_prstatus *sprstat;
3624 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3625 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3627 sid = sprstat->sprstat_sid;
3628 policy = sprstat->sprstat_policy;
3629 #if defined(SCTP_DETAILED_STR_STATS)
3630 if ((stcb != NULL) &&
3631 (sid < stcb->asoc.streamoutcnt) &&
3632 (policy != SCTP_PR_SCTP_NONE) &&
3633 ((policy <= SCTP_PR_SCTP_MAX) ||
3634 (policy == SCTP_PR_SCTP_ALL))) {
3635 if (policy == SCTP_PR_SCTP_ALL) {
3636 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3637 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3639 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3640 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3643 if ((stcb != NULL) &&
3644 (sid < stcb->asoc.streamoutcnt) &&
3645 (policy == SCTP_PR_SCTP_ALL)) {
3646 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3647 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3650 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3654 SCTP_TCB_UNLOCK(stcb);
3657 *optsize = sizeof(struct sctp_prstatus);
3661 case SCTP_PR_ASSOC_STATUS:
3663 struct sctp_prstatus *sprstat;
3666 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3667 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3669 policy = sprstat->sprstat_policy;
3670 if ((stcb != NULL) &&
3671 (policy != SCTP_PR_SCTP_NONE) &&
3672 ((policy <= SCTP_PR_SCTP_MAX) ||
3673 (policy == SCTP_PR_SCTP_ALL))) {
3674 if (policy == SCTP_PR_SCTP_ALL) {
3675 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3676 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3678 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3679 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3682 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3686 SCTP_TCB_UNLOCK(stcb);
3689 *optsize = sizeof(struct sctp_prstatus);
3695 struct sctp_assoc_value *av;
3697 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3698 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3701 av->assoc_value = stcb->asoc.max_cwnd;
3702 SCTP_TCB_UNLOCK(stcb);
3704 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3705 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3706 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3707 SCTP_INP_RLOCK(inp);
3708 av->assoc_value = inp->max_cwnd;
3709 SCTP_INP_RUNLOCK(inp);
3711 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3716 *optsize = sizeof(struct sctp_assoc_value);
3721 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3722 error = ENOPROTOOPT;
3724 } /* end switch (sopt->sopt_name) */
3732 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3737 struct sctp_tcb *stcb = NULL;
3738 struct sctp_inpcb *inp = NULL;
3741 if (optval == NULL) {
3742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3745 inp = (struct sctp_inpcb *)so->so_pcb;
3747 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3750 vrf_id = inp->def_vrf_id;
3755 case SCTP_AUTOCLOSE:
3756 case SCTP_AUTO_ASCONF:
3757 case SCTP_EXPLICIT_EOR:
3758 case SCTP_DISABLE_FRAGMENTS:
3759 case SCTP_USE_EXT_RCVINFO:
3760 case SCTP_I_WANT_MAPPED_V4_ADDR:
3761 /* copy in the option value */
3762 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3767 case SCTP_DISABLE_FRAGMENTS:
3768 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3770 case SCTP_AUTO_ASCONF:
3772 * NOTE: we don't really support this flag
3774 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3775 /* only valid for bound all sockets */
3776 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3778 /* forbidden by admin */
3779 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3782 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3784 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3788 case SCTP_EXPLICIT_EOR:
3789 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3791 case SCTP_USE_EXT_RCVINFO:
3792 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3794 case SCTP_I_WANT_MAPPED_V4_ADDR:
3795 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3796 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3798 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3803 set_opt = SCTP_PCB_FLAGS_NODELAY;
3805 case SCTP_AUTOCLOSE:
3806 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3807 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3808 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3811 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3813 * The value is in ticks. Note this does not effect
3814 * old associations, only new ones.
3816 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3819 SCTP_INP_WLOCK(inp);
3821 sctp_feature_on(inp, set_opt);
3823 sctp_feature_off(inp, set_opt);
3825 SCTP_INP_WUNLOCK(inp);
3827 case SCTP_REUSE_PORT:
3829 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3830 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3831 /* Can't set it after we are bound */
3835 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3836 /* Can't do this for a 1-m socket */
3841 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3843 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3846 case SCTP_PARTIAL_DELIVERY_POINT:
3850 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3851 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3852 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3856 inp->partial_delivery_point = *value;
3859 case SCTP_FRAGMENT_INTERLEAVE:
3860 /* not yet until we re-write sctp_recvmsg() */
3864 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3865 if (*level == SCTP_FRAG_LEVEL_2) {
3866 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3867 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3868 } else if (*level == SCTP_FRAG_LEVEL_1) {
3869 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3870 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3871 } else if (*level == SCTP_FRAG_LEVEL_0) {
3872 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3873 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3881 case SCTP_INTERLEAVING_SUPPORTED:
3883 struct sctp_assoc_value *av;
3885 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3886 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3889 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3891 SCTP_TCB_UNLOCK(stcb);
3893 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3894 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3895 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3896 SCTP_INP_WLOCK(inp);
3897 if (av->assoc_value == 0) {
3898 inp->idata_supported = 0;
3900 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3901 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3902 inp->idata_supported = 1;
3910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3914 SCTP_INP_WUNLOCK(inp);
3916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3922 case SCTP_CMT_ON_OFF:
3923 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3924 struct sctp_assoc_value *av;
3926 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3927 if (av->assoc_value > SCTP_CMT_MAX) {
3928 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3932 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3934 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3935 SCTP_TCB_UNLOCK(stcb);
3937 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3938 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3939 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3940 (av->assoc_id == SCTP_ALL_ASSOC)) {
3941 SCTP_INP_WLOCK(inp);
3942 inp->sctp_cmt_on_off = av->assoc_value;
3943 SCTP_INP_WUNLOCK(inp);
3945 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3946 (av->assoc_id == SCTP_ALL_ASSOC)) {
3947 SCTP_INP_RLOCK(inp);
3948 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3949 SCTP_TCB_LOCK(stcb);
3950 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3951 SCTP_TCB_UNLOCK(stcb);
3953 SCTP_INP_RUNLOCK(inp);
3957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3958 error = ENOPROTOOPT;
3961 case SCTP_PLUGGABLE_CC:
3963 struct sctp_assoc_value *av;
3964 struct sctp_nets *net;
3966 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3967 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3968 (av->assoc_value != SCTP_CC_HSTCP) &&
3969 (av->assoc_value != SCTP_CC_HTCP) &&
3970 (av->assoc_value != SCTP_CC_RTCC)) {
3971 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3975 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3977 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3978 stcb->asoc.congestion_control_module = av->assoc_value;
3979 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3980 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3981 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3984 SCTP_TCB_UNLOCK(stcb);
3986 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3987 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3988 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3989 (av->assoc_id == SCTP_ALL_ASSOC)) {
3990 SCTP_INP_WLOCK(inp);
3991 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3992 SCTP_INP_WUNLOCK(inp);
3994 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3995 (av->assoc_id == SCTP_ALL_ASSOC)) {
3996 SCTP_INP_RLOCK(inp);
3997 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3998 SCTP_TCB_LOCK(stcb);
3999 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4000 stcb->asoc.congestion_control_module = av->assoc_value;
4001 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4002 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4003 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4006 SCTP_TCB_UNLOCK(stcb);
4008 SCTP_INP_RUNLOCK(inp);
4013 case SCTP_CC_OPTION:
4015 struct sctp_cc_option *cc_opt;
4017 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4018 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4020 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4021 SCTP_INP_RLOCK(inp);
4022 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4023 SCTP_TCB_LOCK(stcb);
4024 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4025 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4027 SCTP_TCB_UNLOCK(stcb);
4029 SCTP_INP_RUNLOCK(inp);
4034 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4037 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4040 SCTP_TCB_UNLOCK(stcb);
4044 case SCTP_PLUGGABLE_SS:
4046 struct sctp_assoc_value *av;
4048 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4049 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4050 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4051 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4052 (av->assoc_value != SCTP_SS_PRIORITY) &&
4053 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4054 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4055 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4059 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4061 SCTP_TCB_SEND_LOCK(stcb);
4062 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4063 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4064 stcb->asoc.stream_scheduling_module = av->assoc_value;
4065 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4066 SCTP_TCB_SEND_UNLOCK(stcb);
4067 SCTP_TCB_UNLOCK(stcb);
4069 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4070 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4071 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4072 (av->assoc_id == SCTP_ALL_ASSOC)) {
4073 SCTP_INP_WLOCK(inp);
4074 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4075 SCTP_INP_WUNLOCK(inp);
4077 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4078 (av->assoc_id == SCTP_ALL_ASSOC)) {
4079 SCTP_INP_RLOCK(inp);
4080 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4081 SCTP_TCB_LOCK(stcb);
4082 SCTP_TCB_SEND_LOCK(stcb);
4083 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4084 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4085 stcb->asoc.stream_scheduling_module = av->assoc_value;
4086 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4087 SCTP_TCB_SEND_UNLOCK(stcb);
4088 SCTP_TCB_UNLOCK(stcb);
4090 SCTP_INP_RUNLOCK(inp);
4097 struct sctp_stream_value *av;
4099 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4100 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4102 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4103 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4104 av->stream_value) < 0)) {
4105 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4108 SCTP_TCB_UNLOCK(stcb);
4110 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4111 SCTP_INP_RLOCK(inp);
4112 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4113 SCTP_TCB_LOCK(stcb);
4114 if (av->stream_id < stcb->asoc.streamoutcnt) {
4115 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4117 &stcb->asoc.strmout[av->stream_id],
4120 SCTP_TCB_UNLOCK(stcb);
4122 SCTP_INP_RUNLOCK(inp);
4125 * Can't set stream value without
4128 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4134 case SCTP_CLR_STAT_LOG:
4135 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4140 struct sctp_assoc_value *av;
4142 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4143 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4146 stcb->asoc.context = av->assoc_value;
4147 SCTP_TCB_UNLOCK(stcb);
4149 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4150 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4151 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4152 (av->assoc_id == SCTP_ALL_ASSOC)) {
4153 SCTP_INP_WLOCK(inp);
4154 inp->sctp_context = av->assoc_value;
4155 SCTP_INP_WUNLOCK(inp);
4157 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4158 (av->assoc_id == SCTP_ALL_ASSOC)) {
4159 SCTP_INP_RLOCK(inp);
4160 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4161 SCTP_TCB_LOCK(stcb);
4162 stcb->asoc.context = av->assoc_value;
4163 SCTP_TCB_UNLOCK(stcb);
4165 SCTP_INP_RUNLOCK(inp);
4172 uint32_t *default_vrfid;
4174 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4175 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4176 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4180 inp->def_vrf_id = *default_vrfid;
4183 case SCTP_DEL_VRF_ID:
4185 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4189 case SCTP_ADD_VRF_ID:
4191 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4195 case SCTP_DELAYED_SACK:
4197 struct sctp_sack_info *sack;
4199 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4200 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4201 if (sack->sack_delay) {
4202 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4203 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4204 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4205 sack->sack_delay = TICKS_TO_MSEC(1);
4209 if (sack->sack_delay) {
4210 stcb->asoc.delayed_ack = sack->sack_delay;
4212 if (sack->sack_freq) {
4213 stcb->asoc.sack_freq = sack->sack_freq;
4215 SCTP_TCB_UNLOCK(stcb);
4217 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4218 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4219 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4220 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4221 SCTP_INP_WLOCK(inp);
4222 if (sack->sack_delay) {
4223 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4225 if (sack->sack_freq) {
4226 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4228 SCTP_INP_WUNLOCK(inp);
4230 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4231 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4232 SCTP_INP_RLOCK(inp);
4233 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4234 SCTP_TCB_LOCK(stcb);
4235 if (sack->sack_delay) {
4236 stcb->asoc.delayed_ack = sack->sack_delay;
4238 if (sack->sack_freq) {
4239 stcb->asoc.sack_freq = sack->sack_freq;
4241 SCTP_TCB_UNLOCK(stcb);
4243 SCTP_INP_RUNLOCK(inp);
4248 case SCTP_AUTH_CHUNK:
4250 struct sctp_authchunk *sauth;
4252 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4254 SCTP_INP_WLOCK(inp);
4255 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4256 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4259 inp->auth_supported = 1;
4261 SCTP_INP_WUNLOCK(inp);
4266 struct sctp_authkey *sca;
4267 struct sctp_keyhead *shared_keys;
4268 sctp_sharedkey_t *shared_key;
4269 sctp_key_t *key = NULL;
4272 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4273 if (sca->sca_keylength == 0) {
4274 size = optsize - sizeof(struct sctp_authkey);
4276 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4277 size = sca->sca_keylength;
4279 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4284 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4287 shared_keys = &stcb->asoc.shared_keys;
4288 /* clear the cached keys for this key id */
4289 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4291 * create the new shared key and
4295 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4297 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4299 SCTP_TCB_UNLOCK(stcb);
4303 shared_key = sctp_alloc_sharedkey();
4304 if (shared_key == NULL) {
4306 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4308 SCTP_TCB_UNLOCK(stcb);
4311 shared_key->key = key;
4312 shared_key->keyid = sca->sca_keynumber;
4313 error = sctp_insert_sharedkey(shared_keys, shared_key);
4314 SCTP_TCB_UNLOCK(stcb);
4316 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4317 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4318 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4319 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4320 SCTP_INP_WLOCK(inp);
4321 shared_keys = &inp->sctp_ep.shared_keys;
4323 * clear the cached keys on all
4324 * assocs for this key id
4326 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4328 * create the new shared key and
4332 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4334 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4336 SCTP_INP_WUNLOCK(inp);
4340 shared_key = sctp_alloc_sharedkey();
4341 if (shared_key == NULL) {
4343 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4345 SCTP_INP_WUNLOCK(inp);
4348 shared_key->key = key;
4349 shared_key->keyid = sca->sca_keynumber;
4350 error = sctp_insert_sharedkey(shared_keys, shared_key);
4351 SCTP_INP_WUNLOCK(inp);
4353 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4354 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4355 SCTP_INP_RLOCK(inp);
4356 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4357 SCTP_TCB_LOCK(stcb);
4358 shared_keys = &stcb->asoc.shared_keys;
4360 * clear the cached keys for
4363 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4365 * create the new shared key
4366 * and insert/replace it
4369 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4371 SCTP_TCB_UNLOCK(stcb);
4375 shared_key = sctp_alloc_sharedkey();
4376 if (shared_key == NULL) {
4378 SCTP_TCB_UNLOCK(stcb);
4381 shared_key->key = key;
4382 shared_key->keyid = sca->sca_keynumber;
4383 error = sctp_insert_sharedkey(shared_keys, shared_key);
4384 SCTP_TCB_UNLOCK(stcb);
4386 SCTP_INP_RUNLOCK(inp);
4391 case SCTP_HMAC_IDENT:
4393 struct sctp_hmacalgo *shmac;
4394 sctp_hmaclist_t *hmaclist;
4398 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4399 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4400 (shmac->shmac_number_of_idents > 0xffff)) {
4401 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4406 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4407 if (hmaclist == NULL) {
4408 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4412 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4413 hmacid = shmac->shmac_idents[i];
4414 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4415 /* invalid HMACs were found */ ;
4416 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4418 sctp_free_hmaclist(hmaclist);
4419 goto sctp_set_hmac_done;
4422 for (i = 0; i < hmaclist->num_algo; i++) {
4423 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4424 /* already in list */
4428 if (i == hmaclist->num_algo) {
4429 /* not found in list */
4430 sctp_free_hmaclist(hmaclist);
4431 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4435 /* set it on the endpoint */
4436 SCTP_INP_WLOCK(inp);
4437 if (inp->sctp_ep.local_hmacs)
4438 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4439 inp->sctp_ep.local_hmacs = hmaclist;
4440 SCTP_INP_WUNLOCK(inp);
4444 case SCTP_AUTH_ACTIVE_KEY:
4446 struct sctp_authkeyid *scact;
4448 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4449 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4451 /* set the active key on the right place */
4453 /* set the active key on the assoc */
4454 if (sctp_auth_setactivekey(stcb,
4455 scact->scact_keynumber)) {
4456 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4457 SCTP_FROM_SCTP_USRREQ,
4461 SCTP_TCB_UNLOCK(stcb);
4463 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4464 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4465 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4466 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4467 SCTP_INP_WLOCK(inp);
4468 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4469 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4472 SCTP_INP_WUNLOCK(inp);
4474 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4475 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4476 SCTP_INP_RLOCK(inp);
4477 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4478 SCTP_TCB_LOCK(stcb);
4479 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4480 SCTP_TCB_UNLOCK(stcb);
4482 SCTP_INP_RUNLOCK(inp);
4487 case SCTP_AUTH_DELETE_KEY:
4489 struct sctp_authkeyid *scdel;
4491 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4492 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4494 /* delete the key from the right place */
4496 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4500 SCTP_TCB_UNLOCK(stcb);
4502 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4503 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4504 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4505 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4506 SCTP_INP_WLOCK(inp);
4507 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4508 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4511 SCTP_INP_WUNLOCK(inp);
4513 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4514 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4515 SCTP_INP_RLOCK(inp);
4516 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4517 SCTP_TCB_LOCK(stcb);
4518 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4519 SCTP_TCB_UNLOCK(stcb);
4521 SCTP_INP_RUNLOCK(inp);
4526 case SCTP_AUTH_DEACTIVATE_KEY:
4528 struct sctp_authkeyid *keyid;
4530 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4531 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4533 /* deactivate the key from the right place */
4535 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4536 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4539 SCTP_TCB_UNLOCK(stcb);
4541 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4542 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4543 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4544 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4545 SCTP_INP_WLOCK(inp);
4546 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4547 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4550 SCTP_INP_WUNLOCK(inp);
4552 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4553 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4554 SCTP_INP_RLOCK(inp);
4555 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4556 SCTP_TCB_LOCK(stcb);
4557 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4558 SCTP_TCB_UNLOCK(stcb);
4560 SCTP_INP_RUNLOCK(inp);
4565 case SCTP_ENABLE_STREAM_RESET:
4567 struct sctp_assoc_value *av;
4569 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4570 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4571 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4575 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4577 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4578 SCTP_TCB_UNLOCK(stcb);
4580 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4581 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4582 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4583 (av->assoc_id == SCTP_ALL_ASSOC)) {
4584 SCTP_INP_WLOCK(inp);
4585 inp->local_strreset_support = (uint8_t)av->assoc_value;
4586 SCTP_INP_WUNLOCK(inp);
4588 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4589 (av->assoc_id == SCTP_ALL_ASSOC)) {
4590 SCTP_INP_RLOCK(inp);
4591 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4592 SCTP_TCB_LOCK(stcb);
4593 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4594 SCTP_TCB_UNLOCK(stcb);
4596 SCTP_INP_RUNLOCK(inp);
4602 case SCTP_RESET_STREAMS:
4604 struct sctp_reset_streams *strrst;
4605 int i, send_out = 0;
4608 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4609 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4611 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4615 if (stcb->asoc.reconfig_supported == 0) {
4617 * Peer does not support the chunk type.
4619 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4621 SCTP_TCB_UNLOCK(stcb);
4624 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4625 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4627 SCTP_TCB_UNLOCK(stcb);
4630 if (sizeof(struct sctp_reset_streams) +
4631 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4633 SCTP_TCB_UNLOCK(stcb);
4636 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4638 if (stcb->asoc.stream_reset_outstanding) {
4639 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4641 SCTP_TCB_UNLOCK(stcb);
4645 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4648 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4649 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4651 SCTP_TCB_UNLOCK(stcb);
4654 if ((send_in == 0) && (send_out == 0)) {
4655 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4657 SCTP_TCB_UNLOCK(stcb);
4660 for (i = 0; i < strrst->srs_number_streams; i++) {
4662 (strrst->srs_stream_list[i] >= stcb->asoc.streamincnt)) {
4663 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4668 (strrst->srs_stream_list[i] >= stcb->asoc.streamoutcnt)) {
4669 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4675 SCTP_TCB_UNLOCK(stcb);
4682 if (strrst->srs_number_streams) {
4683 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4684 strm = strrst->srs_stream_list[i];
4685 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4686 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4692 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4693 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4694 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4701 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4702 strrst->srs_stream_list,
4703 send_in, 0, 0, 0, 0, 0);
4705 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4708 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4711 * For outgoing streams don't report any
4712 * problems in sending the request to the
4713 * application. XXX: Double check resetting
4718 SCTP_TCB_UNLOCK(stcb);
4721 case SCTP_ADD_STREAMS:
4723 struct sctp_add_streams *stradd;
4724 uint8_t addstream = 0;
4725 uint16_t add_o_strmcnt = 0;
4726 uint16_t add_i_strmcnt = 0;
4728 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4729 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4731 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4735 if (stcb->asoc.reconfig_supported == 0) {
4737 * Peer does not support the chunk type.
4739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4741 SCTP_TCB_UNLOCK(stcb);
4744 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4745 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4747 SCTP_TCB_UNLOCK(stcb);
4750 if (stcb->asoc.stream_reset_outstanding) {
4751 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4753 SCTP_TCB_UNLOCK(stcb);
4756 if ((stradd->sas_outstrms == 0) &&
4757 (stradd->sas_instrms == 0)) {
4761 if (stradd->sas_outstrms) {
4763 /* We allocate here */
4764 add_o_strmcnt = stradd->sas_outstrms;
4765 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4766 /* You can't have more than 64k */
4771 if (stradd->sas_instrms) {
4776 * We allocate inside
4777 * sctp_send_str_reset_req()
4779 add_i_strmcnt = stradd->sas_instrms;
4780 cnt = add_i_strmcnt;
4781 cnt += stcb->asoc.streamincnt;
4782 if (cnt > 0x0000ffff) {
4783 /* You can't have more than 64k */
4787 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4788 /* More than you are allowed */
4793 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4794 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4796 SCTP_TCB_UNLOCK(stcb);
4799 case SCTP_RESET_ASSOC:
4804 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4805 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4807 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4811 if (stcb->asoc.reconfig_supported == 0) {
4813 * Peer does not support the chunk type.
4815 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4817 SCTP_TCB_UNLOCK(stcb);
4820 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4821 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4823 SCTP_TCB_UNLOCK(stcb);
4826 if (stcb->asoc.stream_reset_outstanding) {
4827 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4829 SCTP_TCB_UNLOCK(stcb);
4833 * Is there any data pending in the send or sent
4836 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4837 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4840 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4841 SCTP_TCB_UNLOCK(stcb);
4844 /* Do any streams have data queued? */
4845 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4846 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4850 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4851 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4852 SCTP_TCB_UNLOCK(stcb);
4855 case SCTP_CONNECT_X:
4856 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4857 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4861 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4863 case SCTP_CONNECT_X_DELAYED:
4864 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4865 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4869 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4871 case SCTP_CONNECT_X_COMPLETE:
4873 struct sockaddr *sa;
4875 /* FIXME MT: check correct? */
4876 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4879 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4880 SCTP_INP_RLOCK(inp);
4881 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4883 SCTP_TCB_LOCK(stcb);
4885 SCTP_INP_RUNLOCK(inp);
4888 * We increment here since
4889 * sctp_findassociation_ep_addr() wil do a
4890 * decrement if it finds the stcb as long as
4891 * the locked tcb (last argument) is NOT a
4894 SCTP_INP_INCR_REF(inp);
4895 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4897 SCTP_INP_DECR_REF(inp);
4902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4906 if (stcb->asoc.delayed_connection == 1) {
4907 stcb->asoc.delayed_connection = 0;
4908 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4909 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4910 stcb->asoc.primary_destination,
4911 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4912 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4915 * already expired or did not use delayed
4918 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4921 SCTP_TCB_UNLOCK(stcb);
4924 case SCTP_MAX_BURST:
4926 struct sctp_assoc_value *av;
4928 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4929 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4932 stcb->asoc.max_burst = av->assoc_value;
4933 SCTP_TCB_UNLOCK(stcb);
4935 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4936 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4937 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4938 (av->assoc_id == SCTP_ALL_ASSOC)) {
4939 SCTP_INP_WLOCK(inp);
4940 inp->sctp_ep.max_burst = av->assoc_value;
4941 SCTP_INP_WUNLOCK(inp);
4943 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4944 (av->assoc_id == SCTP_ALL_ASSOC)) {
4945 SCTP_INP_RLOCK(inp);
4946 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4947 SCTP_TCB_LOCK(stcb);
4948 stcb->asoc.max_burst = av->assoc_value;
4949 SCTP_TCB_UNLOCK(stcb);
4951 SCTP_INP_RUNLOCK(inp);
4958 struct sctp_assoc_value *av;
4961 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4962 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4964 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4965 ovh = SCTP_MED_OVERHEAD;
4967 ovh = SCTP_MED_V4_OVERHEAD;
4970 if (av->assoc_value) {
4971 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4973 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4975 SCTP_TCB_UNLOCK(stcb);
4977 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4978 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4979 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4980 SCTP_INP_WLOCK(inp);
4982 * FIXME MT: I think this is not in
4983 * tune with the API ID
4985 if (av->assoc_value) {
4986 inp->sctp_frag_point = (av->assoc_value + ovh);
4988 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4990 SCTP_INP_WUNLOCK(inp);
4992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5000 struct sctp_event_subscribe *events;
5002 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5004 SCTP_INP_WLOCK(inp);
5005 if (events->sctp_data_io_event) {
5006 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5008 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5011 if (events->sctp_association_event) {
5012 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5014 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5017 if (events->sctp_address_event) {
5018 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5020 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5023 if (events->sctp_send_failure_event) {
5024 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5026 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5029 if (events->sctp_peer_error_event) {
5030 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5032 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5035 if (events->sctp_shutdown_event) {
5036 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5038 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5041 if (events->sctp_partial_delivery_event) {
5042 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5044 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5047 if (events->sctp_adaptation_layer_event) {
5048 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5050 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5053 if (events->sctp_authentication_event) {
5054 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5056 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5059 if (events->sctp_sender_dry_event) {
5060 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5062 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5065 if (events->sctp_stream_reset_event) {
5066 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5068 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5070 SCTP_INP_WUNLOCK(inp);
5072 SCTP_INP_RLOCK(inp);
5073 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5074 SCTP_TCB_LOCK(stcb);
5075 if (events->sctp_association_event) {
5076 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5078 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5080 if (events->sctp_address_event) {
5081 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5083 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5085 if (events->sctp_send_failure_event) {
5086 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5088 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5090 if (events->sctp_peer_error_event) {
5091 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5093 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5095 if (events->sctp_shutdown_event) {
5096 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5098 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5100 if (events->sctp_partial_delivery_event) {
5101 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5103 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5105 if (events->sctp_adaptation_layer_event) {
5106 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5108 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5110 if (events->sctp_authentication_event) {
5111 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5113 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5115 if (events->sctp_sender_dry_event) {
5116 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5118 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5120 if (events->sctp_stream_reset_event) {
5121 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5123 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5125 SCTP_TCB_UNLOCK(stcb);
5128 * Send up the sender dry event only for 1-to-1
5131 if (events->sctp_sender_dry_event) {
5132 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5133 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5134 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5136 SCTP_TCB_LOCK(stcb);
5137 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5138 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5139 (stcb->asoc.stream_queue_cnt == 0)) {
5140 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5142 SCTP_TCB_UNLOCK(stcb);
5146 SCTP_INP_RUNLOCK(inp);
5149 case SCTP_ADAPTATION_LAYER:
5151 struct sctp_setadaptation *adap_bits;
5153 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5154 SCTP_INP_WLOCK(inp);
5155 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5156 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5157 SCTP_INP_WUNLOCK(inp);
5161 case SCTP_SET_INITIAL_DBG_SEQ:
5165 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5166 SCTP_INP_WLOCK(inp);
5167 inp->sctp_ep.initial_sequence_debug = *vvv;
5168 SCTP_INP_WUNLOCK(inp);
5172 case SCTP_DEFAULT_SEND_PARAM:
5174 struct sctp_sndrcvinfo *s_info;
5176 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5177 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5180 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5181 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5183 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5186 SCTP_TCB_UNLOCK(stcb);
5188 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5189 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5190 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5191 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5192 SCTP_INP_WLOCK(inp);
5193 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5194 SCTP_INP_WUNLOCK(inp);
5196 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5197 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5198 SCTP_INP_RLOCK(inp);
5199 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5200 SCTP_TCB_LOCK(stcb);
5201 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5202 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5204 SCTP_TCB_UNLOCK(stcb);
5206 SCTP_INP_RUNLOCK(inp);
5211 case SCTP_PEER_ADDR_PARAMS:
5213 struct sctp_paddrparams *paddrp;
5214 struct sctp_nets *net;
5215 struct sockaddr *addr;
5216 #if defined(INET) && defined(INET6)
5217 struct sockaddr_in sin_store;
5220 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5221 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5223 #if defined(INET) && defined(INET6)
5224 if (paddrp->spp_address.ss_family == AF_INET6) {
5225 struct sockaddr_in6 *sin6;
5227 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5228 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5229 in6_sin6_2_sin(&sin_store, sin6);
5230 addr = (struct sockaddr *)&sin_store;
5232 addr = (struct sockaddr *)&paddrp->spp_address;
5235 addr = (struct sockaddr *)&paddrp->spp_address;
5238 addr = (struct sockaddr *)&paddrp->spp_address;
5241 net = sctp_findnet(stcb, addr);
5244 * We increment here since
5245 * sctp_findassociation_ep_addr() wil do a
5246 * decrement if it finds the stcb as long as
5247 * the locked tcb (last argument) is NOT a
5251 SCTP_INP_INCR_REF(inp);
5252 stcb = sctp_findassociation_ep_addr(&inp, addr,
5255 SCTP_INP_DECR_REF(inp);
5258 if ((stcb != NULL) && (net == NULL)) {
5260 if (addr->sa_family == AF_INET) {
5262 struct sockaddr_in *sin;
5264 sin = (struct sockaddr_in *)addr;
5265 if (sin->sin_addr.s_addr != INADDR_ANY) {
5266 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5267 SCTP_TCB_UNLOCK(stcb);
5274 if (addr->sa_family == AF_INET6) {
5275 struct sockaddr_in6 *sin6;
5277 sin6 = (struct sockaddr_in6 *)addr;
5278 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5279 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5280 SCTP_TCB_UNLOCK(stcb);
5287 error = EAFNOSUPPORT;
5288 SCTP_TCB_UNLOCK(stcb);
5289 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5294 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5296 SCTP_TCB_UNLOCK(stcb);
5297 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5301 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5303 SCTP_TCB_UNLOCK(stcb);
5304 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5309 /************************TCB SPECIFIC SET ******************/
5311 /************************NET SPECIFIC SET ******************/
5312 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5313 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5314 !(net->dest_state & SCTP_ADDR_NOHB)) {
5315 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5316 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5318 net->dest_state |= SCTP_ADDR_NOHB;
5320 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5321 if (paddrp->spp_hbinterval) {
5322 net->heart_beat_delay = paddrp->spp_hbinterval;
5323 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5324 net->heart_beat_delay = 0;
5326 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5327 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5328 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5329 net->dest_state &= ~SCTP_ADDR_NOHB;
5331 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5332 if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
5333 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5334 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5335 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5338 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5339 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5340 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5341 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5343 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5344 net->mtu = paddrp->spp_pathmtu;
5345 switch (net->ro._l_addr.sa.sa_family) {
5348 net->mtu += SCTP_MIN_V4_OVERHEAD;
5353 net->mtu += SCTP_MIN_OVERHEAD;
5359 if (net->mtu < stcb->asoc.smallest_mtu) {
5360 sctp_pathmtu_adjustment(stcb, net->mtu);
5363 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5364 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5365 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5367 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5369 if (paddrp->spp_pathmaxrxt) {
5370 if (net->dest_state & SCTP_ADDR_PF) {
5371 if (net->error_count > paddrp->spp_pathmaxrxt) {
5372 net->dest_state &= ~SCTP_ADDR_PF;
5375 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5376 (net->error_count > net->pf_threshold)) {
5377 net->dest_state |= SCTP_ADDR_PF;
5378 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5379 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5380 stcb->sctp_ep, stcb, net,
5381 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5382 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5385 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5386 if (net->error_count > paddrp->spp_pathmaxrxt) {
5387 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5388 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5391 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5392 net->dest_state |= SCTP_ADDR_REACHABLE;
5393 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5396 net->failure_threshold = paddrp->spp_pathmaxrxt;
5398 if (paddrp->spp_flags & SPP_DSCP) {
5399 net->dscp = paddrp->spp_dscp & 0xfc;
5403 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5404 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5405 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5406 net->flowlabel |= 0x80000000;
5411 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5412 if (paddrp->spp_pathmaxrxt != 0) {
5413 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5414 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5415 if (net->dest_state & SCTP_ADDR_PF) {
5416 if (net->error_count > paddrp->spp_pathmaxrxt) {
5417 net->dest_state &= ~SCTP_ADDR_PF;
5420 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5421 (net->error_count > net->pf_threshold)) {
5422 net->dest_state |= SCTP_ADDR_PF;
5423 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5424 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5425 stcb->sctp_ep, stcb, net,
5426 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5427 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5430 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5431 if (net->error_count > paddrp->spp_pathmaxrxt) {
5432 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5433 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5436 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5437 net->dest_state |= SCTP_ADDR_REACHABLE;
5438 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5441 net->failure_threshold = paddrp->spp_pathmaxrxt;
5445 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5446 if (paddrp->spp_hbinterval != 0) {
5447 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5448 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5449 stcb->asoc.heart_beat_delay = 0;
5451 /* Turn back on the timer */
5452 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5453 if (paddrp->spp_hbinterval != 0) {
5454 net->heart_beat_delay = paddrp->spp_hbinterval;
5455 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5456 net->heart_beat_delay = 0;
5458 if (net->dest_state & SCTP_ADDR_NOHB) {
5459 net->dest_state &= ~SCTP_ADDR_NOHB;
5461 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5462 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5463 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5465 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5467 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5468 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5469 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5470 net->dest_state |= SCTP_ADDR_NOHB;
5471 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5472 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5474 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5478 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5480 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5481 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5482 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5483 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5484 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5486 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5487 net->mtu = paddrp->spp_pathmtu;
5488 switch (net->ro._l_addr.sa.sa_family) {
5491 net->mtu += SCTP_MIN_V4_OVERHEAD;
5496 net->mtu += SCTP_MIN_OVERHEAD;
5502 if (net->mtu < stcb->asoc.smallest_mtu) {
5503 sctp_pathmtu_adjustment(stcb, net->mtu);
5506 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5507 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5509 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5510 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5511 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5512 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5514 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5516 stcb->asoc.default_mtu = 0;
5517 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5519 if (paddrp->spp_flags & SPP_DSCP) {
5520 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5521 net->dscp = paddrp->spp_dscp & 0xfc;
5524 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5525 stcb->asoc.default_dscp |= 0x01;
5528 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5529 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5530 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5531 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5532 net->flowlabel |= 0x80000000;
5535 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5536 stcb->asoc.default_flowlabel |= 0x80000000;
5540 SCTP_TCB_UNLOCK(stcb);
5542 /************************NO TCB, SET TO default stuff ******************/
5543 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5544 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5545 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5546 SCTP_INP_WLOCK(inp);
5548 * For the TOS/FLOWLABEL stuff you
5549 * set it with the options on the
5552 if (paddrp->spp_pathmaxrxt != 0) {
5553 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5556 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5557 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5558 else if (paddrp->spp_hbinterval != 0) {
5559 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5560 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5561 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5564 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5565 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5566 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5567 } else if (paddrp->spp_hbinterval) {
5568 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5570 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5571 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5572 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5574 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5575 inp->sctp_ep.default_mtu = 0;
5576 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5577 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5578 if (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU) {
5579 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5581 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5583 if (paddrp->spp_flags & SPP_DSCP) {
5584 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5585 inp->sctp_ep.default_dscp |= 0x01;
5588 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5589 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5590 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5591 inp->sctp_ep.default_flowlabel |= 0x80000000;
5595 SCTP_INP_WUNLOCK(inp);
5597 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5605 struct sctp_rtoinfo *srto;
5606 uint32_t new_init, new_min, new_max;
5608 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5609 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5612 if (srto->srto_initial)
5613 new_init = srto->srto_initial;
5615 new_init = stcb->asoc.initial_rto;
5617 new_max = srto->srto_max;
5619 new_max = stcb->asoc.maxrto;
5621 new_min = srto->srto_min;
5623 new_min = stcb->asoc.minrto;
5624 if ((new_min <= new_init) && (new_init <= new_max)) {
5625 stcb->asoc.initial_rto = new_init;
5626 stcb->asoc.maxrto = new_max;
5627 stcb->asoc.minrto = new_min;
5629 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5632 SCTP_TCB_UNLOCK(stcb);
5634 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5635 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5636 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5637 SCTP_INP_WLOCK(inp);
5638 if (srto->srto_initial)
5639 new_init = srto->srto_initial;
5641 new_init = inp->sctp_ep.initial_rto;
5643 new_max = srto->srto_max;
5645 new_max = inp->sctp_ep.sctp_maxrto;
5647 new_min = srto->srto_min;
5649 new_min = inp->sctp_ep.sctp_minrto;
5650 if ((new_min <= new_init) && (new_init <= new_max)) {
5651 inp->sctp_ep.initial_rto = new_init;
5652 inp->sctp_ep.sctp_maxrto = new_max;
5653 inp->sctp_ep.sctp_minrto = new_min;
5655 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5658 SCTP_INP_WUNLOCK(inp);
5660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5666 case SCTP_ASSOCINFO:
5668 struct sctp_assocparams *sasoc;
5670 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5671 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5672 if (sasoc->sasoc_cookie_life) {
5673 /* boundary check the cookie life */
5674 if (sasoc->sasoc_cookie_life < 1000)
5675 sasoc->sasoc_cookie_life = 1000;
5676 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5677 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5681 if (sasoc->sasoc_asocmaxrxt)
5682 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5683 if (sasoc->sasoc_cookie_life) {
5684 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5686 SCTP_TCB_UNLOCK(stcb);
5688 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5689 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5690 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5691 SCTP_INP_WLOCK(inp);
5692 if (sasoc->sasoc_asocmaxrxt)
5693 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5694 if (sasoc->sasoc_cookie_life) {
5695 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5697 SCTP_INP_WUNLOCK(inp);
5699 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5707 struct sctp_initmsg *sinit;
5709 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5710 SCTP_INP_WLOCK(inp);
5711 if (sinit->sinit_num_ostreams)
5712 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5714 if (sinit->sinit_max_instreams)
5715 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5717 if (sinit->sinit_max_attempts)
5718 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5720 if (sinit->sinit_max_init_timeo)
5721 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5722 SCTP_INP_WUNLOCK(inp);
5725 case SCTP_PRIMARY_ADDR:
5727 struct sctp_setprim *spa;
5728 struct sctp_nets *net;
5729 struct sockaddr *addr;
5730 #if defined(INET) && defined(INET6)
5731 struct sockaddr_in sin_store;
5734 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5735 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5737 #if defined(INET) && defined(INET6)
5738 if (spa->ssp_addr.ss_family == AF_INET6) {
5739 struct sockaddr_in6 *sin6;
5741 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5742 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5743 in6_sin6_2_sin(&sin_store, sin6);
5744 addr = (struct sockaddr *)&sin_store;
5746 addr = (struct sockaddr *)&spa->ssp_addr;
5749 addr = (struct sockaddr *)&spa->ssp_addr;
5752 addr = (struct sockaddr *)&spa->ssp_addr;
5755 net = sctp_findnet(stcb, addr);
5758 * We increment here since
5759 * sctp_findassociation_ep_addr() wil do a
5760 * decrement if it finds the stcb as long as
5761 * the locked tcb (last argument) is NOT a
5765 SCTP_INP_INCR_REF(inp);
5766 stcb = sctp_findassociation_ep_addr(&inp, addr,
5769 SCTP_INP_DECR_REF(inp);
5773 if ((stcb != NULL) && (net != NULL)) {
5774 if (net != stcb->asoc.primary_destination) {
5775 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5776 /* Ok we need to set it */
5777 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5778 if ((stcb->asoc.alternate) &&
5779 (!(net->dest_state & SCTP_ADDR_PF)) &&
5780 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5781 sctp_free_remote_addr(stcb->asoc.alternate);
5782 stcb->asoc.alternate = NULL;
5785 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5789 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5798 SCTP_TCB_UNLOCK(stcb);
5802 case SCTP_SET_DYNAMIC_PRIMARY:
5804 union sctp_sockstore *ss;
5806 error = priv_check(curthread,
5807 PRIV_NETINET_RESERVEDPORT);
5811 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5812 /* SUPER USER CHECK? */
5813 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5816 case SCTP_SET_PEER_PRIMARY_ADDR:
5818 struct sctp_setpeerprim *sspp;
5819 struct sockaddr *addr;
5820 #if defined(INET) && defined(INET6)
5821 struct sockaddr_in sin_store;
5824 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5825 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5827 struct sctp_ifa *ifa;
5829 #if defined(INET) && defined(INET6)
5830 if (sspp->sspp_addr.ss_family == AF_INET6) {
5831 struct sockaddr_in6 *sin6;
5833 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5834 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5835 in6_sin6_2_sin(&sin_store, sin6);
5836 addr = (struct sockaddr *)&sin_store;
5838 addr = (struct sockaddr *)&sspp->sspp_addr;
5841 addr = (struct sockaddr *)&sspp->sspp_addr;
5844 addr = (struct sockaddr *)&sspp->sspp_addr;
5846 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5848 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5852 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5854 * Must validate the ifa found is in
5857 struct sctp_laddr *laddr;
5860 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5861 if (laddr->ifa == NULL) {
5862 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5866 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5867 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5870 if (laddr->ifa == ifa) {
5876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5881 switch (addr->sa_family) {
5885 struct sockaddr_in *sin;
5887 sin = (struct sockaddr_in *)addr;
5888 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5889 &sin->sin_addr) != 0) {
5890 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5900 struct sockaddr_in6 *sin6;
5902 sin6 = (struct sockaddr_in6 *)addr;
5903 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5904 &sin6->sin6_addr) != 0) {
5905 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5918 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5919 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5922 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5924 SCTP_TCB_UNLOCK(stcb);
5926 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5931 case SCTP_BINDX_ADD_ADDR:
5933 struct sctp_getaddresses *addrs;
5936 td = (struct thread *)p;
5937 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5940 if (addrs->addr->sa_family == AF_INET) {
5941 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5942 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5946 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5947 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5953 if (addrs->addr->sa_family == AF_INET6) {
5954 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5955 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5959 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5960 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5961 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5967 error = EAFNOSUPPORT;
5970 sctp_bindx_add_address(so, inp, addrs->addr,
5971 addrs->sget_assoc_id, vrf_id,
5975 case SCTP_BINDX_REM_ADDR:
5977 struct sctp_getaddresses *addrs;
5980 td = (struct thread *)p;
5982 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5984 if (addrs->addr->sa_family == AF_INET) {
5985 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5986 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5990 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5991 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5997 if (addrs->addr->sa_family == AF_INET6) {
5998 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6004 (error = prison_local_ip6(td->td_ucred,
6005 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
6006 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6007 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6013 error = EAFNOSUPPORT;
6016 sctp_bindx_delete_address(inp, addrs->addr,
6017 addrs->sget_assoc_id, vrf_id,
6023 struct sctp_event *event;
6024 uint32_t event_type;
6026 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6027 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6028 switch (event->se_type) {
6029 case SCTP_ASSOC_CHANGE:
6030 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6032 case SCTP_PEER_ADDR_CHANGE:
6033 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6035 case SCTP_REMOTE_ERROR:
6036 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6038 case SCTP_SEND_FAILED:
6039 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6041 case SCTP_SHUTDOWN_EVENT:
6042 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6044 case SCTP_ADAPTATION_INDICATION:
6045 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6047 case SCTP_PARTIAL_DELIVERY_EVENT:
6048 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6050 case SCTP_AUTHENTICATION_EVENT:
6051 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6053 case SCTP_STREAM_RESET_EVENT:
6054 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6056 case SCTP_SENDER_DRY_EVENT:
6057 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6059 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6061 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6064 case SCTP_ASSOC_RESET_EVENT:
6065 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6067 case SCTP_STREAM_CHANGE_EVENT:
6068 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6070 case SCTP_SEND_FAILED_EVENT:
6071 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6075 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6079 if (event_type > 0) {
6082 sctp_stcb_feature_on(inp, stcb, event_type);
6083 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6084 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6085 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6086 (stcb->asoc.stream_queue_cnt == 0)) {
6087 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6091 sctp_stcb_feature_off(inp, stcb, event_type);
6093 SCTP_TCB_UNLOCK(stcb);
6096 * We don't want to send up a storm
6097 * of events, so return an error for
6100 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6101 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6102 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6103 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6104 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6105 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6109 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6110 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6111 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6112 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6113 SCTP_INP_WLOCK(inp);
6115 sctp_feature_on(inp, event_type);
6117 sctp_feature_off(inp, event_type);
6119 SCTP_INP_WUNLOCK(inp);
6121 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6122 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6123 SCTP_INP_RLOCK(inp);
6124 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6125 SCTP_TCB_LOCK(stcb);
6127 sctp_stcb_feature_on(inp, stcb, event_type);
6129 sctp_stcb_feature_off(inp, stcb, event_type);
6131 SCTP_TCB_UNLOCK(stcb);
6133 SCTP_INP_RUNLOCK(inp);
6138 SCTP_TCB_UNLOCK(stcb);
6143 case SCTP_RECVRCVINFO:
6147 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6148 SCTP_INP_WLOCK(inp);
6150 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6152 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6154 SCTP_INP_WUNLOCK(inp);
6157 case SCTP_RECVNXTINFO:
6161 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6162 SCTP_INP_WLOCK(inp);
6164 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6166 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6168 SCTP_INP_WUNLOCK(inp);
6171 case SCTP_DEFAULT_SNDINFO:
6173 struct sctp_sndinfo *info;
6176 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6177 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6180 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6181 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6182 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6183 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6184 stcb->asoc.def_send.sinfo_flags |= policy;
6185 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6186 stcb->asoc.def_send.sinfo_context = info->snd_context;
6188 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6191 SCTP_TCB_UNLOCK(stcb);
6193 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6194 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6195 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6196 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6197 SCTP_INP_WLOCK(inp);
6198 inp->def_send.sinfo_stream = info->snd_sid;
6199 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6200 inp->def_send.sinfo_flags = info->snd_flags;
6201 inp->def_send.sinfo_flags |= policy;
6202 inp->def_send.sinfo_ppid = info->snd_ppid;
6203 inp->def_send.sinfo_context = info->snd_context;
6204 SCTP_INP_WUNLOCK(inp);
6206 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6207 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6208 SCTP_INP_RLOCK(inp);
6209 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6210 SCTP_TCB_LOCK(stcb);
6211 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6212 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6213 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6214 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6215 stcb->asoc.def_send.sinfo_flags |= policy;
6216 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6217 stcb->asoc.def_send.sinfo_context = info->snd_context;
6219 SCTP_TCB_UNLOCK(stcb);
6221 SCTP_INP_RUNLOCK(inp);
6226 case SCTP_DEFAULT_PRINFO:
6228 struct sctp_default_prinfo *info;
6230 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6231 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6233 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6235 SCTP_TCB_UNLOCK(stcb);
6237 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6242 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6243 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6244 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6245 SCTP_TCB_UNLOCK(stcb);
6247 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6248 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6249 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6250 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6251 SCTP_INP_WLOCK(inp);
6252 inp->def_send.sinfo_flags &= 0xfff0;
6253 inp->def_send.sinfo_flags |= info->pr_policy;
6254 inp->def_send.sinfo_timetolive = info->pr_value;
6255 SCTP_INP_WUNLOCK(inp);
6257 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6258 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6259 SCTP_INP_RLOCK(inp);
6260 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6261 SCTP_TCB_LOCK(stcb);
6262 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6263 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6264 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6265 SCTP_TCB_UNLOCK(stcb);
6267 SCTP_INP_RUNLOCK(inp);
6272 case SCTP_PEER_ADDR_THLDS:
6273 /* Applies to the specific association */
6275 struct sctp_paddrthlds *thlds;
6276 struct sctp_nets *net;
6277 struct sockaddr *addr;
6278 #if defined(INET) && defined(INET6)
6279 struct sockaddr_in sin_store;
6282 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6283 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6285 #if defined(INET) && defined(INET6)
6286 if (thlds->spt_address.ss_family == AF_INET6) {
6287 struct sockaddr_in6 *sin6;
6289 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6290 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6291 in6_sin6_2_sin(&sin_store, sin6);
6292 addr = (struct sockaddr *)&sin_store;
6294 addr = (struct sockaddr *)&thlds->spt_address;
6297 addr = (struct sockaddr *)&thlds->spt_address;
6300 addr = (struct sockaddr *)&thlds->spt_address;
6303 net = sctp_findnet(stcb, addr);
6306 * We increment here since
6307 * sctp_findassociation_ep_addr() wil do a
6308 * decrement if it finds the stcb as long as
6309 * the locked tcb (last argument) is NOT a
6313 SCTP_INP_INCR_REF(inp);
6314 stcb = sctp_findassociation_ep_addr(&inp, addr,
6317 SCTP_INP_DECR_REF(inp);
6320 if ((stcb != NULL) && (net == NULL)) {
6322 if (addr->sa_family == AF_INET) {
6324 struct sockaddr_in *sin;
6326 sin = (struct sockaddr_in *)addr;
6327 if (sin->sin_addr.s_addr != INADDR_ANY) {
6328 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6329 SCTP_TCB_UNLOCK(stcb);
6336 if (addr->sa_family == AF_INET6) {
6337 struct sockaddr_in6 *sin6;
6339 sin6 = (struct sockaddr_in6 *)addr;
6340 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6341 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6342 SCTP_TCB_UNLOCK(stcb);
6349 error = EAFNOSUPPORT;
6350 SCTP_TCB_UNLOCK(stcb);
6351 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6355 if (thlds->spt_pathcpthld != 0xffff) {
6357 SCTP_TCB_UNLOCK(stcb);
6360 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6365 net->failure_threshold = thlds->spt_pathmaxrxt;
6366 net->pf_threshold = thlds->spt_pathpfthld;
6367 if (net->dest_state & SCTP_ADDR_PF) {
6368 if ((net->error_count > net->failure_threshold) ||
6369 (net->error_count <= net->pf_threshold)) {
6370 net->dest_state &= ~SCTP_ADDR_PF;
6373 if ((net->error_count > net->pf_threshold) &&
6374 (net->error_count <= net->failure_threshold)) {
6375 net->dest_state |= SCTP_ADDR_PF;
6376 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6377 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6378 stcb->sctp_ep, stcb, net,
6379 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6380 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6383 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6384 if (net->error_count > net->failure_threshold) {
6385 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6386 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6389 if (net->error_count <= net->failure_threshold) {
6390 net->dest_state |= SCTP_ADDR_REACHABLE;
6391 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6395 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6396 net->failure_threshold = thlds->spt_pathmaxrxt;
6397 net->pf_threshold = thlds->spt_pathpfthld;
6398 if (net->dest_state & SCTP_ADDR_PF) {
6399 if ((net->error_count > net->failure_threshold) ||
6400 (net->error_count <= net->pf_threshold)) {
6401 net->dest_state &= ~SCTP_ADDR_PF;
6404 if ((net->error_count > net->pf_threshold) &&
6405 (net->error_count <= net->failure_threshold)) {
6406 net->dest_state |= SCTP_ADDR_PF;
6407 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6408 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6409 stcb->sctp_ep, stcb, net,
6410 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6411 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6414 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6415 if (net->error_count > net->failure_threshold) {
6416 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6417 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6420 if (net->error_count <= net->failure_threshold) {
6421 net->dest_state |= SCTP_ADDR_REACHABLE;
6422 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6426 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6427 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6429 SCTP_TCB_UNLOCK(stcb);
6431 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6432 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6433 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6434 SCTP_INP_WLOCK(inp);
6435 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6436 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6437 SCTP_INP_WUNLOCK(inp);
6439 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6445 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6447 struct sctp_udpencaps *encaps;
6448 struct sctp_nets *net;
6449 struct sockaddr *addr;
6450 #if defined(INET) && defined(INET6)
6451 struct sockaddr_in sin_store;
6454 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6455 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6457 #if defined(INET) && defined(INET6)
6458 if (encaps->sue_address.ss_family == AF_INET6) {
6459 struct sockaddr_in6 *sin6;
6461 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6462 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6463 in6_sin6_2_sin(&sin_store, sin6);
6464 addr = (struct sockaddr *)&sin_store;
6466 addr = (struct sockaddr *)&encaps->sue_address;
6469 addr = (struct sockaddr *)&encaps->sue_address;
6472 addr = (struct sockaddr *)&encaps->sue_address;
6475 net = sctp_findnet(stcb, addr);
6478 * We increment here since
6479 * sctp_findassociation_ep_addr() wil do a
6480 * decrement if it finds the stcb as long as
6481 * the locked tcb (last argument) is NOT a
6485 SCTP_INP_INCR_REF(inp);
6486 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6488 SCTP_INP_DECR_REF(inp);
6491 if ((stcb != NULL) && (net == NULL)) {
6493 if (addr->sa_family == AF_INET) {
6495 struct sockaddr_in *sin;
6497 sin = (struct sockaddr_in *)addr;
6498 if (sin->sin_addr.s_addr != INADDR_ANY) {
6499 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6500 SCTP_TCB_UNLOCK(stcb);
6507 if (addr->sa_family == AF_INET6) {
6508 struct sockaddr_in6 *sin6;
6510 sin6 = (struct sockaddr_in6 *)addr;
6511 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6513 SCTP_TCB_UNLOCK(stcb);
6520 error = EAFNOSUPPORT;
6521 SCTP_TCB_UNLOCK(stcb);
6522 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6529 net->port = encaps->sue_port;
6531 stcb->asoc.port = encaps->sue_port;
6533 SCTP_TCB_UNLOCK(stcb);
6535 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6536 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6537 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6538 SCTP_INP_WLOCK(inp);
6539 inp->sctp_ep.port = encaps->sue_port;
6540 SCTP_INP_WUNLOCK(inp);
6542 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6548 case SCTP_ECN_SUPPORTED:
6550 struct sctp_assoc_value *av;
6552 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6553 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6556 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6558 SCTP_TCB_UNLOCK(stcb);
6560 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6561 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6562 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6563 SCTP_INP_WLOCK(inp);
6564 if (av->assoc_value == 0) {
6565 inp->ecn_supported = 0;
6567 inp->ecn_supported = 1;
6569 SCTP_INP_WUNLOCK(inp);
6571 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6577 case SCTP_PR_SUPPORTED:
6579 struct sctp_assoc_value *av;
6581 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6582 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6585 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6587 SCTP_TCB_UNLOCK(stcb);
6589 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6590 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6591 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6592 SCTP_INP_WLOCK(inp);
6593 if (av->assoc_value == 0) {
6594 inp->prsctp_supported = 0;
6596 inp->prsctp_supported = 1;
6598 SCTP_INP_WUNLOCK(inp);
6600 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6606 case SCTP_AUTH_SUPPORTED:
6608 struct sctp_assoc_value *av;
6610 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6611 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6614 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6616 SCTP_TCB_UNLOCK(stcb);
6618 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6619 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6620 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6621 if ((av->assoc_value == 0) &&
6622 (inp->asconf_supported == 1)) {
6624 * AUTH is required for
6627 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6630 SCTP_INP_WLOCK(inp);
6631 if (av->assoc_value == 0) {
6632 inp->auth_supported = 0;
6634 inp->auth_supported = 1;
6636 SCTP_INP_WUNLOCK(inp);
6639 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6645 case SCTP_ASCONF_SUPPORTED:
6647 struct sctp_assoc_value *av;
6649 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6650 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6653 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6655 SCTP_TCB_UNLOCK(stcb);
6657 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6658 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6659 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6660 if ((av->assoc_value != 0) &&
6661 (inp->auth_supported == 0)) {
6663 * AUTH is required for
6666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6669 SCTP_INP_WLOCK(inp);
6670 if (av->assoc_value == 0) {
6671 inp->asconf_supported = 0;
6672 sctp_auth_delete_chunk(SCTP_ASCONF,
6673 inp->sctp_ep.local_auth_chunks);
6674 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6675 inp->sctp_ep.local_auth_chunks);
6677 inp->asconf_supported = 1;
6678 sctp_auth_add_chunk(SCTP_ASCONF,
6679 inp->sctp_ep.local_auth_chunks);
6680 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6681 inp->sctp_ep.local_auth_chunks);
6683 SCTP_INP_WUNLOCK(inp);
6686 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6692 case SCTP_RECONFIG_SUPPORTED:
6694 struct sctp_assoc_value *av;
6696 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6697 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6700 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6702 SCTP_TCB_UNLOCK(stcb);
6704 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6705 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6706 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6707 SCTP_INP_WLOCK(inp);
6708 if (av->assoc_value == 0) {
6709 inp->reconfig_supported = 0;
6711 inp->reconfig_supported = 1;
6713 SCTP_INP_WUNLOCK(inp);
6715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6721 case SCTP_NRSACK_SUPPORTED:
6723 struct sctp_assoc_value *av;
6725 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6726 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6729 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6731 SCTP_TCB_UNLOCK(stcb);
6733 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6734 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6735 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6736 SCTP_INP_WLOCK(inp);
6737 if (av->assoc_value == 0) {
6738 inp->nrsack_supported = 0;
6740 inp->nrsack_supported = 1;
6742 SCTP_INP_WUNLOCK(inp);
6744 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6750 case SCTP_PKTDROP_SUPPORTED:
6752 struct sctp_assoc_value *av;
6754 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6755 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6758 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6760 SCTP_TCB_UNLOCK(stcb);
6762 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6763 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6764 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6765 SCTP_INP_WLOCK(inp);
6766 if (av->assoc_value == 0) {
6767 inp->pktdrop_supported = 0;
6769 inp->pktdrop_supported = 1;
6771 SCTP_INP_WUNLOCK(inp);
6773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6781 struct sctp_assoc_value *av;
6782 struct sctp_nets *net;
6784 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6785 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6788 stcb->asoc.max_cwnd = av->assoc_value;
6789 if (stcb->asoc.max_cwnd > 0) {
6790 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6791 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6792 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6793 net->cwnd = stcb->asoc.max_cwnd;
6794 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6795 net->cwnd = net->mtu - sizeof(struct sctphdr);
6800 SCTP_TCB_UNLOCK(stcb);
6802 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6803 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6804 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6805 SCTP_INP_WLOCK(inp);
6806 inp->max_cwnd = av->assoc_value;
6807 SCTP_INP_WUNLOCK(inp);
6809 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6816 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6817 error = ENOPROTOOPT;
6819 } /* end switch (opt) */
6824 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6826 void *optval = NULL;
6830 struct sctp_inpcb *inp;
6832 if ((sopt->sopt_level == SOL_SOCKET) &&
6833 (sopt->sopt_name == SO_SETFIB)) {
6834 inp = (struct sctp_inpcb *)so->so_pcb;
6836 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6839 SCTP_INP_WLOCK(inp);
6840 inp->fibnum = so->so_fibnum;
6841 SCTP_INP_WUNLOCK(inp);
6844 if (sopt->sopt_level != IPPROTO_SCTP) {
6845 /* wrong proto level... send back up to IP */
6847 if (INP_CHECK_SOCKAF(so, AF_INET6))
6848 error = ip6_ctloutput(so, sopt);
6850 #if defined(INET) && defined(INET6)
6854 error = ip_ctloutput(so, sopt);
6858 optsize = sopt->sopt_valsize;
6859 if (optsize > SCTP_SOCKET_OPTION_LIMIT) {
6860 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6864 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6865 if (optval == NULL) {
6866 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6869 error = sooptcopyin(sopt, optval, optsize, optsize);
6871 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6875 p = (void *)sopt->sopt_td;
6876 if (sopt->sopt_dir == SOPT_SET) {
6877 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6878 } else if (sopt->sopt_dir == SOPT_GET) {
6879 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6881 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6884 if ((error == 0) && (optval != NULL)) {
6885 error = sooptcopyout(sopt, optval, optsize);
6886 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6887 } else if (optval != NULL) {
6888 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6896 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6899 int create_lock_on = 0;
6901 struct sctp_inpcb *inp;
6902 struct sctp_tcb *stcb = NULL;
6904 inp = (struct sctp_inpcb *)so->so_pcb;
6906 /* I made the same as TCP since we are not setup? */
6907 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6908 return (ECONNRESET);
6911 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6915 switch (addr->sa_family) {
6919 struct sockaddr_in6 *sin6p;
6921 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6925 sin6p = (struct sockaddr_in6 *)addr;
6926 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6927 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6936 struct sockaddr_in *sinp;
6938 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6942 sinp = (struct sockaddr_in *)addr;
6943 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6944 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6952 return (EAFNOSUPPORT);
6954 SCTP_INP_INCR_REF(inp);
6955 SCTP_ASOC_CREATE_LOCK(inp);
6959 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6960 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6961 /* Should I really unlock ? */
6962 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6967 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6968 (addr->sa_family == AF_INET6)) {
6969 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6974 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6975 SCTP_PCB_FLAGS_UNBOUND) {
6976 /* Bind a ephemeral port */
6977 error = sctp_inpcb_bind(so, NULL, NULL, p);
6982 /* Now do we connect? */
6983 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6984 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6985 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6989 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6990 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6991 /* We are already connected AND the TCP model */
6992 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6996 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6997 SCTP_INP_RLOCK(inp);
6998 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6999 SCTP_INP_RUNLOCK(inp);
7002 * We increment here since sctp_findassociation_ep_addr()
7003 * will do a decrement if it finds the stcb as long as the
7004 * locked tcb (last argument) is NOT a TCB.. aka NULL.
7006 SCTP_INP_INCR_REF(inp);
7007 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7009 SCTP_INP_DECR_REF(inp);
7011 SCTP_TCB_UNLOCK(stcb);
7015 /* Already have or am bring up an association */
7016 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7021 vrf_id = inp->def_vrf_id;
7022 /* We are GOOD to go */
7023 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
7024 inp->sctp_ep.pre_open_stream_count,
7025 inp->sctp_ep.port, p,
7026 SCTP_INITIALIZE_AUTH_PARAMS);
7028 /* Gak! no memory */
7031 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7032 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7033 /* Set the connected flag so we can queue data */
7036 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7037 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7039 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7040 SCTP_TCB_UNLOCK(stcb);
7042 if (create_lock_on) {
7043 SCTP_ASOC_CREATE_UNLOCK(inp);
7046 SCTP_INP_DECR_REF(inp);
7052 sctp_listen(struct socket *so, int backlog, struct thread *p)
7055 * Note this module depends on the protocol processing being called
7056 * AFTER any socket level flags and backlog are applied to the
7057 * socket. The traditional way that the socket flags are applied is
7058 * AFTER protocol processing. We have made a change to the
7059 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7060 * place if the socket API for SCTP is to work properly.
7064 struct sctp_inpcb *inp;
7066 inp = (struct sctp_inpcb *)so->so_pcb;
7068 /* I made the same as TCP since we are not setup? */
7069 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7070 return (ECONNRESET);
7072 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7073 /* See if we have a listener */
7074 struct sctp_inpcb *tinp;
7075 union sctp_sockstore store;
7077 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7079 struct sctp_laddr *laddr;
7081 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7082 memcpy(&store, &laddr->ifa->address, sizeof(store));
7083 switch (store.sa.sa_family) {
7086 store.sin.sin_port = inp->sctp_lport;
7091 store.sin6.sin6_port = inp->sctp_lport;
7097 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7098 if (tinp && (tinp != inp) &&
7099 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7100 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7101 (SCTP_IS_LISTENING(tinp))) {
7103 * we have a listener already and
7106 SCTP_INP_DECR_REF(tinp);
7107 return (EADDRINUSE);
7109 SCTP_INP_DECR_REF(tinp);
7113 /* Setup a local addr bound all */
7114 memset(&store, 0, sizeof(store));
7116 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7117 store.sa.sa_family = AF_INET6;
7118 store.sa.sa_len = sizeof(struct sockaddr_in6);
7122 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7123 store.sa.sa_family = AF_INET;
7124 store.sa.sa_len = sizeof(struct sockaddr_in);
7127 switch (store.sa.sa_family) {
7130 store.sin.sin_port = inp->sctp_lport;
7135 store.sin6.sin6_port = inp->sctp_lport;
7141 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7142 if (tinp && (tinp != inp) &&
7143 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7144 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7145 (SCTP_IS_LISTENING(tinp))) {
7147 * we have a listener already and its not
7150 SCTP_INP_DECR_REF(tinp);
7151 return (EADDRINUSE);
7153 SCTP_INP_DECR_REF(tinp);
7157 SCTP_INP_RLOCK(inp);
7158 #ifdef SCTP_LOCK_LOGGING
7159 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7160 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7164 error = solisten_proto_check(so);
7167 SCTP_INP_RUNLOCK(inp);
7170 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7171 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7173 * The unlucky case - We are in the tcp pool with this guy.
7174 * - Someone else is in the main inp slot. - We must move
7175 * this guy (the listener) to the main slot - We must then
7176 * move the guy that was listener to the TCP Pool.
7178 if (sctp_swap_inpcb_for_listen(inp)) {
7179 SCTP_INP_RUNLOCK(inp);
7180 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7181 return (EADDRINUSE);
7185 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7186 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7187 /* We are already connected AND the TCP model */
7188 SCTP_INP_RUNLOCK(inp);
7189 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7190 return (EADDRINUSE);
7192 SCTP_INP_RUNLOCK(inp);
7193 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7194 /* We must do a bind. */
7195 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7196 /* bind error, probably perm */
7200 SCTP_INP_WLOCK(inp);
7201 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7203 solisten_proto(so, backlog);
7207 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7209 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7211 SCTP_INP_WUNLOCK(inp);
7215 static int sctp_defered_wakeup_cnt = 0;
7218 sctp_accept(struct socket *so, struct sockaddr **addr)
7220 struct sctp_tcb *stcb;
7221 struct sctp_inpcb *inp;
7222 union sctp_sockstore store;
7226 inp = (struct sctp_inpcb *)so->so_pcb;
7229 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7230 return (ECONNRESET);
7232 SCTP_INP_WLOCK(inp);
7233 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7234 SCTP_INP_WUNLOCK(inp);
7235 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7236 return (EOPNOTSUPP);
7238 if (so->so_state & SS_ISDISCONNECTED) {
7239 SCTP_INP_WUNLOCK(inp);
7240 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7241 return (ECONNABORTED);
7243 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7245 SCTP_INP_WUNLOCK(inp);
7246 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7247 return (ECONNRESET);
7249 SCTP_TCB_LOCK(stcb);
7250 store = stcb->asoc.primary_destination->ro._l_addr;
7251 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7252 /* Wake any delayed sleep action */
7253 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7254 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7255 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7256 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7257 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7258 if (sowriteable(inp->sctp_socket)) {
7259 sowwakeup_locked(inp->sctp_socket);
7261 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7264 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7265 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7266 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7267 if (soreadable(inp->sctp_socket)) {
7268 sctp_defered_wakeup_cnt++;
7269 sorwakeup_locked(inp->sctp_socket);
7271 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7275 SCTP_INP_WUNLOCK(inp);
7276 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7277 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7278 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7280 SCTP_TCB_UNLOCK(stcb);
7282 switch (store.sa.sa_family) {
7286 struct sockaddr_in *sin;
7288 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7291 sin->sin_family = AF_INET;
7292 sin->sin_len = sizeof(*sin);
7293 sin->sin_port = store.sin.sin_port;
7294 sin->sin_addr = store.sin.sin_addr;
7295 *addr = (struct sockaddr *)sin;
7302 struct sockaddr_in6 *sin6;
7304 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7307 sin6->sin6_family = AF_INET6;
7308 sin6->sin6_len = sizeof(*sin6);
7309 sin6->sin6_port = store.sin6.sin6_port;
7310 sin6->sin6_addr = store.sin6.sin6_addr;
7311 if ((error = sa6_recoverscope(sin6)) != 0) {
7312 SCTP_FREE_SONAME(sin6);
7315 *addr = (struct sockaddr *)sin6;
7328 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7330 struct sockaddr_in *sin;
7332 struct sctp_inpcb *inp;
7333 struct sctp_ifa *sctp_ifa;
7336 * Do the malloc first in case it blocks.
7338 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7341 sin->sin_family = AF_INET;
7342 sin->sin_len = sizeof(*sin);
7343 inp = (struct sctp_inpcb *)so->so_pcb;
7345 SCTP_FREE_SONAME(sin);
7346 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7347 return (ECONNRESET);
7349 SCTP_INP_RLOCK(inp);
7350 sin->sin_port = inp->sctp_lport;
7351 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7352 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7353 struct sctp_tcb *stcb;
7354 struct sockaddr_in *sin_a;
7355 struct sctp_nets *net;
7358 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7364 SCTP_TCB_LOCK(stcb);
7365 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7366 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7368 /* this will make coverity happy */
7371 if (sin_a->sin_family == AF_INET) {
7376 if ((!fnd) || (sin_a == NULL)) {
7378 SCTP_TCB_UNLOCK(stcb);
7382 vrf_id = inp->def_vrf_id;
7383 sctp_ifa = sctp_source_address_selection(inp,
7385 (sctp_route_t *)&net->ro,
7388 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7389 sctp_free_ifa(sctp_ifa);
7391 SCTP_TCB_UNLOCK(stcb);
7393 /* For the bound all case you get back 0 */
7395 sin->sin_addr.s_addr = 0;
7399 /* Take the first IPv4 address in the list */
7400 struct sctp_laddr *laddr;
7403 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7404 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7405 struct sockaddr_in *sin_a;
7407 sin_a = &laddr->ifa->address.sin;
7408 sin->sin_addr = sin_a->sin_addr;
7414 SCTP_FREE_SONAME(sin);
7415 SCTP_INP_RUNLOCK(inp);
7416 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7420 SCTP_INP_RUNLOCK(inp);
7421 (*addr) = (struct sockaddr *)sin;
7426 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7428 struct sockaddr_in *sin;
7430 struct sockaddr_in *sin_a;
7431 struct sctp_inpcb *inp;
7432 struct sctp_tcb *stcb;
7433 struct sctp_nets *net;
7435 /* Do the malloc first in case it blocks. */
7436 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7439 sin->sin_family = AF_INET;
7440 sin->sin_len = sizeof(*sin);
7442 inp = (struct sctp_inpcb *)so->so_pcb;
7443 if ((inp == NULL) ||
7444 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7445 /* UDP type and listeners will drop out here */
7446 SCTP_FREE_SONAME(sin);
7447 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7450 SCTP_INP_RLOCK(inp);
7451 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7453 SCTP_TCB_LOCK(stcb);
7455 SCTP_INP_RUNLOCK(inp);
7457 SCTP_FREE_SONAME(sin);
7458 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7459 return (ECONNRESET);
7462 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7463 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7464 if (sin_a->sin_family == AF_INET) {
7466 sin->sin_port = stcb->rport;
7467 sin->sin_addr = sin_a->sin_addr;
7471 SCTP_TCB_UNLOCK(stcb);
7473 /* No IPv4 address */
7474 SCTP_FREE_SONAME(sin);
7475 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7478 (*addr) = (struct sockaddr *)sin;
7482 struct pr_usrreqs sctp_usrreqs = {
7483 .pru_abort = sctp_abort,
7484 .pru_accept = sctp_accept,
7485 .pru_attach = sctp_attach,
7486 .pru_bind = sctp_bind,
7487 .pru_connect = sctp_connect,
7488 .pru_control = in_control,
7489 .pru_close = sctp_close,
7490 .pru_detach = sctp_close,
7491 .pru_sopoll = sopoll_generic,
7492 .pru_flush = sctp_flush,
7493 .pru_disconnect = sctp_disconnect,
7494 .pru_listen = sctp_listen,
7495 .pru_peeraddr = sctp_peeraddr,
7496 .pru_send = sctp_sendm,
7497 .pru_shutdown = sctp_shutdown,
7498 .pru_sockaddr = sctp_ingetaddr,
7499 .pru_sosend = sctp_sosend,
7500 .pru_soreceive = sctp_soreceive