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_abort_an_association(stcb->sctp_ep, stcb,
969 op_err, SCTP_SO_LOCKED);
970 SCTP_INP_RUNLOCK(inp);
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;
1361 int bad_addresses = 0;
1364 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1366 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1367 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1368 /* We are already connected AND the TCP model */
1369 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1370 return (EADDRINUSE);
1373 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1374 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1375 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1379 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1380 SCTP_INP_RLOCK(inp);
1381 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1382 SCTP_INP_RUNLOCK(inp);
1385 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1388 SCTP_INP_INCR_REF(inp);
1389 SCTP_ASOC_CREATE_LOCK(inp);
1391 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1392 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1393 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1397 totaddrp = (unsigned int *)optval;
1398 totaddr = *totaddrp;
1399 sa = (struct sockaddr *)(totaddrp + 1);
1400 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (unsigned int)(optsize - sizeof(int)), &bad_addresses);
1401 if ((stcb != NULL) || bad_addresses) {
1402 /* Already have or am bring up an association */
1403 SCTP_ASOC_CREATE_UNLOCK(inp);
1406 SCTP_TCB_UNLOCK(stcb);
1407 if (bad_addresses == 0) {
1408 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1414 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1419 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1421 struct in6pcb *inp6;
1423 inp6 = (struct in6pcb *)inp;
1424 if (SCTP_IPV6_V6ONLY(inp6)) {
1426 * if IPV6_V6ONLY flag, ignore connections destined
1427 * to a v4 addr or v4-mapped addr
1429 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1435 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1436 SCTP_PCB_FLAGS_UNBOUND) {
1437 /* Bind a ephemeral port */
1438 error = sctp_inpcb_bind(so, NULL, NULL, p);
1444 /* FIX ME: do we want to pass in a vrf on the connect call? */
1445 vrf_id = inp->def_vrf_id;
1448 /* We are GOOD to go */
1449 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1450 inp->sctp_ep.pre_open_stream_count,
1455 /* Gak! no memory */
1458 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1459 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1460 /* Set the connected flag so we can queue data */
1463 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1464 /* move to second address */
1465 switch (sa->sa_family) {
1468 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1473 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1481 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1482 /* Fill in the return id */
1484 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE,
1485 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
1488 a_id = (sctp_assoc_t *)optval;
1489 *a_id = sctp_get_associd(stcb);
1491 /* initialize authentication parameters for the assoc */
1492 sctp_initialize_auth_params(inp, stcb);
1495 /* doing delayed connection */
1496 stcb->asoc.delayed_connection = 1;
1497 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1499 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1500 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1502 SCTP_TCB_UNLOCK(stcb);
1504 if (creat_lock_on) {
1505 SCTP_ASOC_CREATE_UNLOCK(inp);
1507 SCTP_INP_DECR_REF(inp);
1511 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1512 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1513 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1514 SCTP_INP_RLOCK(inp); \
1515 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1517 SCTP_TCB_LOCK(stcb); \
1519 SCTP_INP_RUNLOCK(inp); \
1520 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1521 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1522 if (stcb == NULL) { \
1523 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1533 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1534 if (size < sizeof(type)) { \
1535 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1539 destp = (type *)srcp; \
1544 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1547 struct sctp_inpcb *inp = NULL;
1549 struct sctp_tcb *stcb = NULL;
1551 if (optval == NULL) {
1552 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1556 inp = (struct sctp_inpcb *)so->so_pcb;
1558 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1565 case SCTP_AUTOCLOSE:
1566 case SCTP_EXPLICIT_EOR:
1567 case SCTP_AUTO_ASCONF:
1568 case SCTP_DISABLE_FRAGMENTS:
1569 case SCTP_I_WANT_MAPPED_V4_ADDR:
1570 case SCTP_USE_EXT_RCVINFO:
1571 SCTP_INP_RLOCK(inp);
1573 case SCTP_DISABLE_FRAGMENTS:
1574 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1576 case SCTP_I_WANT_MAPPED_V4_ADDR:
1577 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1579 case SCTP_AUTO_ASCONF:
1580 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1581 /* only valid for bound all sockets */
1582 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1584 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1589 case SCTP_EXPLICIT_EOR:
1590 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1593 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1595 case SCTP_USE_EXT_RCVINFO:
1596 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1598 case SCTP_AUTOCLOSE:
1599 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1600 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1606 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1607 error = ENOPROTOOPT;
1608 } /* end switch (sopt->sopt_name) */
1609 if (*optsize < sizeof(val)) {
1610 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1614 SCTP_INP_RUNLOCK(inp);
1616 /* return the option value */
1617 *(int *)optval = val;
1618 *optsize = sizeof(val);
1621 case SCTP_GET_PACKET_LOG:
1623 #ifdef SCTP_PACKET_LOGGING
1627 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1628 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1631 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1636 case SCTP_REUSE_PORT:
1640 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1641 /* Can't do this for a 1-m socket */
1645 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1646 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1647 *optsize = sizeof(uint32_t);
1650 case SCTP_PARTIAL_DELIVERY_POINT:
1654 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1655 *value = inp->partial_delivery_point;
1656 *optsize = sizeof(uint32_t);
1659 case SCTP_FRAGMENT_INTERLEAVE:
1663 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1664 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1665 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1666 *value = SCTP_FRAG_LEVEL_2;
1668 *value = SCTP_FRAG_LEVEL_1;
1671 *value = SCTP_FRAG_LEVEL_0;
1673 *optsize = sizeof(uint32_t);
1676 case SCTP_INTERLEAVING_SUPPORTED:
1678 struct sctp_assoc_value *av;
1680 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1681 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1684 av->assoc_value = stcb->asoc.idata_supported;
1685 SCTP_TCB_UNLOCK(stcb);
1687 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1688 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1689 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1690 SCTP_INP_RLOCK(inp);
1691 if (inp->idata_supported) {
1692 av->assoc_value = 1;
1694 av->assoc_value = 0;
1696 SCTP_INP_RUNLOCK(inp);
1698 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1703 *optsize = sizeof(struct sctp_assoc_value);
1707 case SCTP_CMT_ON_OFF:
1709 struct sctp_assoc_value *av;
1711 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1712 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1714 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1715 SCTP_TCB_UNLOCK(stcb);
1717 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1718 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1719 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1720 SCTP_INP_RLOCK(inp);
1721 av->assoc_value = inp->sctp_cmt_on_off;
1722 SCTP_INP_RUNLOCK(inp);
1724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1729 *optsize = sizeof(struct sctp_assoc_value);
1733 case SCTP_PLUGGABLE_CC:
1735 struct sctp_assoc_value *av;
1737 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1738 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1740 av->assoc_value = stcb->asoc.congestion_control_module;
1741 SCTP_TCB_UNLOCK(stcb);
1743 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1744 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1745 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1746 SCTP_INP_RLOCK(inp);
1747 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1748 SCTP_INP_RUNLOCK(inp);
1750 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1755 *optsize = sizeof(struct sctp_assoc_value);
1759 case SCTP_CC_OPTION:
1761 struct sctp_cc_option *cc_opt;
1763 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1764 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1768 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1771 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1772 *optsize = sizeof(struct sctp_cc_option);
1774 SCTP_TCB_UNLOCK(stcb);
1778 case SCTP_PLUGGABLE_SS:
1780 struct sctp_assoc_value *av;
1782 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1783 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1785 av->assoc_value = stcb->asoc.stream_scheduling_module;
1786 SCTP_TCB_UNLOCK(stcb);
1788 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1789 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1790 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1791 SCTP_INP_RLOCK(inp);
1792 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1793 SCTP_INP_RUNLOCK(inp);
1795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1800 *optsize = sizeof(struct sctp_assoc_value);
1806 struct sctp_stream_value *av;
1808 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1809 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1811 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1812 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1813 &av->stream_value) < 0)) {
1814 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1817 *optsize = sizeof(struct sctp_stream_value);
1819 SCTP_TCB_UNLOCK(stcb);
1822 * Can't get stream value without
1825 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1830 case SCTP_GET_ADDR_LEN:
1832 struct sctp_assoc_value *av;
1834 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1837 if (av->assoc_value == AF_INET) {
1838 av->assoc_value = sizeof(struct sockaddr_in);
1843 if (av->assoc_value == AF_INET6) {
1844 av->assoc_value = sizeof(struct sockaddr_in6);
1849 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1851 *optsize = sizeof(struct sctp_assoc_value);
1855 case SCTP_GET_ASSOC_NUMBER:
1857 uint32_t *value, cnt;
1859 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1860 SCTP_INP_RLOCK(inp);
1861 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1862 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1863 /* Can't do this for a 1-1 socket */
1865 SCTP_INP_RUNLOCK(inp);
1869 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1872 SCTP_INP_RUNLOCK(inp);
1874 *optsize = sizeof(uint32_t);
1877 case SCTP_GET_ASSOC_ID_LIST:
1879 struct sctp_assoc_ids *ids;
1883 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1884 SCTP_INP_RLOCK(inp);
1885 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1886 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1887 /* Can't do this for a 1-1 socket */
1889 SCTP_INP_RUNLOCK(inp);
1893 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1894 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1896 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1899 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1904 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1908 SCTP_INP_RUNLOCK(inp);
1910 ids->gaids_number_of_ids = at;
1911 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1917 struct sctp_assoc_value *av;
1919 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1920 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1923 av->assoc_value = stcb->asoc.context;
1924 SCTP_TCB_UNLOCK(stcb);
1926 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1927 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1928 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1929 SCTP_INP_RLOCK(inp);
1930 av->assoc_value = inp->sctp_context;
1931 SCTP_INP_RUNLOCK(inp);
1933 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1938 *optsize = sizeof(struct sctp_assoc_value);
1944 uint32_t *default_vrfid;
1946 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1947 *default_vrfid = inp->def_vrf_id;
1948 *optsize = sizeof(uint32_t);
1951 case SCTP_GET_ASOC_VRF:
1953 struct sctp_assoc_value *id;
1955 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1956 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1959 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1961 id->assoc_value = stcb->asoc.vrf_id;
1962 SCTP_TCB_UNLOCK(stcb);
1963 *optsize = sizeof(struct sctp_assoc_value);
1967 case SCTP_GET_VRF_IDS:
1969 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1973 case SCTP_GET_NONCE_VALUES:
1975 struct sctp_get_nonce_values *gnv;
1977 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1978 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1981 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1982 gnv->gn_local_tag = stcb->asoc.my_vtag;
1983 SCTP_TCB_UNLOCK(stcb);
1984 *optsize = sizeof(struct sctp_get_nonce_values);
1986 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1991 case SCTP_DELAYED_SACK:
1993 struct sctp_sack_info *sack;
1995 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1996 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1998 sack->sack_delay = stcb->asoc.delayed_ack;
1999 sack->sack_freq = stcb->asoc.sack_freq;
2000 SCTP_TCB_UNLOCK(stcb);
2002 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2003 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2004 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2005 SCTP_INP_RLOCK(inp);
2006 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2007 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2008 SCTP_INP_RUNLOCK(inp);
2010 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2015 *optsize = sizeof(struct sctp_sack_info);
2019 case SCTP_GET_SNDBUF_USE:
2021 struct sctp_sockstat *ss;
2023 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2024 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2027 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2028 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2029 stcb->asoc.size_on_all_streams);
2030 SCTP_TCB_UNLOCK(stcb);
2031 *optsize = sizeof(struct sctp_sockstat);
2033 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2038 case SCTP_MAX_BURST:
2040 struct sctp_assoc_value *av;
2042 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2043 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2046 av->assoc_value = stcb->asoc.max_burst;
2047 SCTP_TCB_UNLOCK(stcb);
2049 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2050 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2051 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2052 SCTP_INP_RLOCK(inp);
2053 av->assoc_value = inp->sctp_ep.max_burst;
2054 SCTP_INP_RUNLOCK(inp);
2056 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2061 *optsize = sizeof(struct sctp_assoc_value);
2067 struct sctp_assoc_value *av;
2070 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2071 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2074 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2075 SCTP_TCB_UNLOCK(stcb);
2077 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2078 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2079 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2080 SCTP_INP_RLOCK(inp);
2081 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2082 ovh = SCTP_MED_OVERHEAD;
2084 ovh = SCTP_MED_V4_OVERHEAD;
2086 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2087 av->assoc_value = 0;
2089 av->assoc_value = inp->sctp_frag_point - ovh;
2090 SCTP_INP_RUNLOCK(inp);
2092 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2097 *optsize = sizeof(struct sctp_assoc_value);
2101 case SCTP_GET_STAT_LOG:
2102 error = sctp_fill_stat_log(optval, optsize);
2106 struct sctp_event_subscribe *events;
2108 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2109 memset(events, 0, sizeof(struct sctp_event_subscribe));
2110 SCTP_INP_RLOCK(inp);
2111 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2112 events->sctp_data_io_event = 1;
2114 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2115 events->sctp_association_event = 1;
2117 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2118 events->sctp_address_event = 1;
2120 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2121 events->sctp_send_failure_event = 1;
2123 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2124 events->sctp_peer_error_event = 1;
2126 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2127 events->sctp_shutdown_event = 1;
2129 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2130 events->sctp_partial_delivery_event = 1;
2132 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2133 events->sctp_adaptation_layer_event = 1;
2135 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2136 events->sctp_authentication_event = 1;
2138 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2139 events->sctp_sender_dry_event = 1;
2141 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2142 events->sctp_stream_reset_event = 1;
2143 SCTP_INP_RUNLOCK(inp);
2144 *optsize = sizeof(struct sctp_event_subscribe);
2147 case SCTP_ADAPTATION_LAYER:
2151 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2153 SCTP_INP_RLOCK(inp);
2154 *value = inp->sctp_ep.adaptation_layer_indicator;
2155 SCTP_INP_RUNLOCK(inp);
2156 *optsize = sizeof(uint32_t);
2159 case SCTP_SET_INITIAL_DBG_SEQ:
2163 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2164 SCTP_INP_RLOCK(inp);
2165 *value = inp->sctp_ep.initial_sequence_debug;
2166 SCTP_INP_RUNLOCK(inp);
2167 *optsize = sizeof(uint32_t);
2170 case SCTP_GET_LOCAL_ADDR_SIZE:
2174 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2175 SCTP_INP_RLOCK(inp);
2176 *value = sctp_count_max_addresses(inp);
2177 SCTP_INP_RUNLOCK(inp);
2178 *optsize = sizeof(uint32_t);
2181 case SCTP_GET_REMOTE_ADDR_SIZE:
2185 struct sctp_nets *net;
2187 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2188 /* FIXME MT: change to sctp_assoc_value? */
2189 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2193 /* Count the sizes */
2194 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2195 switch (net->ro._l_addr.sa.sa_family) {
2199 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2200 size += sizeof(struct sockaddr_in6);
2202 size += sizeof(struct sockaddr_in);
2205 size += sizeof(struct sockaddr_in);
2211 size += sizeof(struct sockaddr_in6);
2218 SCTP_TCB_UNLOCK(stcb);
2219 *value = (uint32_t)size;
2220 *optsize = sizeof(uint32_t);
2222 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2227 case SCTP_GET_PEER_ADDRESSES:
2229 * Get the address information, an array is passed in to
2230 * fill up we pack it.
2234 struct sockaddr_storage *sas;
2235 struct sctp_nets *net;
2236 struct sctp_getaddresses *saddr;
2238 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2239 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2242 left = (*optsize) - sizeof(sctp_assoc_t);
2243 *optsize = sizeof(sctp_assoc_t);
2244 sas = (struct sockaddr_storage *)&saddr->addr[0];
2246 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2247 switch (net->ro._l_addr.sa.sa_family) {
2251 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2252 cpsz = sizeof(struct sockaddr_in6);
2254 cpsz = sizeof(struct sockaddr_in);
2257 cpsz = sizeof(struct sockaddr_in);
2263 cpsz = sizeof(struct sockaddr_in6);
2274 /* not enough room. */
2277 #if defined(INET) && defined(INET6)
2278 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2279 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2280 /* Must map the address */
2281 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2282 (struct sockaddr_in6 *)sas);
2284 memcpy(sas, &net->ro._l_addr, cpsz);
2287 memcpy(sas, &net->ro._l_addr, cpsz);
2289 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2291 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2295 SCTP_TCB_UNLOCK(stcb);
2297 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2302 case SCTP_GET_LOCAL_ADDRESSES:
2304 size_t limit, actual;
2305 struct sockaddr_storage *sas;
2306 struct sctp_getaddresses *saddr;
2308 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2309 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2311 sas = (struct sockaddr_storage *)&saddr->addr[0];
2312 limit = *optsize - sizeof(sctp_assoc_t);
2313 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2315 SCTP_TCB_UNLOCK(stcb);
2317 *optsize = sizeof(sctp_assoc_t) + actual;
2320 case SCTP_PEER_ADDR_PARAMS:
2322 struct sctp_paddrparams *paddrp;
2323 struct sctp_nets *net;
2324 struct sockaddr *addr;
2325 #if defined(INET) && defined(INET6)
2326 struct sockaddr_in sin_store;
2329 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2330 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2332 #if defined(INET) && defined(INET6)
2333 if (paddrp->spp_address.ss_family == AF_INET6) {
2334 struct sockaddr_in6 *sin6;
2336 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2337 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2338 in6_sin6_2_sin(&sin_store, sin6);
2339 addr = (struct sockaddr *)&sin_store;
2341 addr = (struct sockaddr *)&paddrp->spp_address;
2344 addr = (struct sockaddr *)&paddrp->spp_address;
2347 addr = (struct sockaddr *)&paddrp->spp_address;
2350 net = sctp_findnet(stcb, addr);
2353 * We increment here since
2354 * sctp_findassociation_ep_addr() wil do a
2355 * decrement if it finds the stcb as long as
2356 * the locked tcb (last argument) is NOT a
2360 SCTP_INP_INCR_REF(inp);
2361 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2363 SCTP_INP_DECR_REF(inp);
2366 if ((stcb != NULL) && (net == NULL)) {
2368 if (addr->sa_family == AF_INET) {
2369 struct sockaddr_in *sin;
2371 sin = (struct sockaddr_in *)addr;
2372 if (sin->sin_addr.s_addr != INADDR_ANY) {
2374 SCTP_TCB_UNLOCK(stcb);
2375 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2381 if (addr->sa_family == AF_INET6) {
2382 struct sockaddr_in6 *sin6;
2384 sin6 = (struct sockaddr_in6 *)addr;
2385 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2387 SCTP_TCB_UNLOCK(stcb);
2388 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2394 error = EAFNOSUPPORT;
2395 SCTP_TCB_UNLOCK(stcb);
2396 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2402 /* Applies to the specific association */
2403 paddrp->spp_flags = 0;
2405 paddrp->spp_hbinterval = net->heart_beat_delay;
2406 paddrp->spp_pathmaxrxt = net->failure_threshold;
2407 paddrp->spp_pathmtu = net->mtu;
2408 switch (net->ro._l_addr.sa.sa_family) {
2411 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2416 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2422 /* get flags for HB */
2423 if (net->dest_state & SCTP_ADDR_NOHB) {
2424 paddrp->spp_flags |= SPP_HB_DISABLE;
2426 paddrp->spp_flags |= SPP_HB_ENABLE;
2428 /* get flags for PMTU */
2429 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2430 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2432 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2434 if (net->dscp & 0x01) {
2435 paddrp->spp_dscp = net->dscp & 0xfc;
2436 paddrp->spp_flags |= SPP_DSCP;
2439 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2440 (net->flowlabel & 0x80000000)) {
2441 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2442 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2447 * No destination so return default
2450 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2451 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2452 if (stcb->asoc.default_dscp & 0x01) {
2453 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2454 paddrp->spp_flags |= SPP_DSCP;
2457 if (stcb->asoc.default_flowlabel & 0x80000000) {
2458 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2459 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2462 /* default settings should be these */
2463 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2464 paddrp->spp_flags |= SPP_HB_DISABLE;
2466 paddrp->spp_flags |= SPP_HB_ENABLE;
2468 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2469 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2471 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2473 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2475 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2476 SCTP_TCB_UNLOCK(stcb);
2478 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2479 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2480 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2481 /* Use endpoint defaults */
2482 SCTP_INP_RLOCK(inp);
2483 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2484 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2485 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2486 /* get inp's default */
2487 if (inp->sctp_ep.default_dscp & 0x01) {
2488 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2489 paddrp->spp_flags |= SPP_DSCP;
2492 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2493 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2494 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2495 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2498 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2500 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2501 paddrp->spp_flags |= SPP_HB_ENABLE;
2503 paddrp->spp_flags |= SPP_HB_DISABLE;
2505 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2506 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2508 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2510 SCTP_INP_RUNLOCK(inp);
2512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2517 *optsize = sizeof(struct sctp_paddrparams);
2521 case SCTP_GET_PEER_ADDR_INFO:
2523 struct sctp_paddrinfo *paddri;
2524 struct sctp_nets *net;
2525 struct sockaddr *addr;
2526 #if defined(INET) && defined(INET6)
2527 struct sockaddr_in sin_store;
2530 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2531 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2533 #if defined(INET) && defined(INET6)
2534 if (paddri->spinfo_address.ss_family == AF_INET6) {
2535 struct sockaddr_in6 *sin6;
2537 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2538 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2539 in6_sin6_2_sin(&sin_store, sin6);
2540 addr = (struct sockaddr *)&sin_store;
2542 addr = (struct sockaddr *)&paddri->spinfo_address;
2545 addr = (struct sockaddr *)&paddri->spinfo_address;
2548 addr = (struct sockaddr *)&paddri->spinfo_address;
2551 net = sctp_findnet(stcb, addr);
2554 * We increment here since
2555 * sctp_findassociation_ep_addr() wil do a
2556 * decrement if it finds the stcb as long as
2557 * the locked tcb (last argument) is NOT a
2561 SCTP_INP_INCR_REF(inp);
2562 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2564 SCTP_INP_DECR_REF(inp);
2568 if ((stcb != NULL) && (net != NULL)) {
2569 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2570 /* It's unconfirmed */
2571 paddri->spinfo_state = SCTP_UNCONFIRMED;
2572 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2574 paddri->spinfo_state = SCTP_ACTIVE;
2577 paddri->spinfo_state = SCTP_INACTIVE;
2579 paddri->spinfo_cwnd = net->cwnd;
2580 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2581 paddri->spinfo_rto = net->RTO;
2582 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2583 paddri->spinfo_mtu = net->mtu;
2584 switch (addr->sa_family) {
2587 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2592 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2598 SCTP_TCB_UNLOCK(stcb);
2599 *optsize = sizeof(struct sctp_paddrinfo);
2602 SCTP_TCB_UNLOCK(stcb);
2604 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2609 case SCTP_PCB_STATUS:
2611 struct sctp_pcbinfo *spcb;
2613 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2614 sctp_fill_pcbinfo(spcb);
2615 *optsize = sizeof(struct sctp_pcbinfo);
2620 struct sctp_nets *net;
2621 struct sctp_status *sstat;
2623 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2624 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2627 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2631 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2632 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2633 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2634 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2636 * We can't include chunks that have been passed to
2637 * the socket layer. Only things in queue.
2639 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2640 stcb->asoc.cnt_on_all_streams);
2643 sstat->sstat_instrms = stcb->asoc.streamincnt;
2644 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2645 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2646 net = stcb->asoc.primary_destination;
2648 memcpy(&sstat->sstat_primary.spinfo_address,
2649 &stcb->asoc.primary_destination->ro._l_addr,
2650 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2651 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2653 * Again the user can get info from
2654 * sctp_constants.h for what the state of
2657 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2658 /* It's unconfirmed */
2659 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2660 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2662 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2665 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2667 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2668 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2669 sstat->sstat_primary.spinfo_rto = net->RTO;
2670 sstat->sstat_primary.spinfo_mtu = net->mtu;
2671 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2674 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2679 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2686 memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo));
2688 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2689 SCTP_TCB_UNLOCK(stcb);
2690 *optsize = sizeof(struct sctp_status);
2695 struct sctp_rtoinfo *srto;
2697 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2698 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2701 srto->srto_initial = stcb->asoc.initial_rto;
2702 srto->srto_max = stcb->asoc.maxrto;
2703 srto->srto_min = stcb->asoc.minrto;
2704 SCTP_TCB_UNLOCK(stcb);
2706 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2707 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2708 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2709 SCTP_INP_RLOCK(inp);
2710 srto->srto_initial = inp->sctp_ep.initial_rto;
2711 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2712 srto->srto_min = inp->sctp_ep.sctp_minrto;
2713 SCTP_INP_RUNLOCK(inp);
2715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2720 *optsize = sizeof(struct sctp_rtoinfo);
2726 struct sctp_timeouts *stimo;
2728 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2729 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2732 stimo->stimo_init = stcb->asoc.timoinit;
2733 stimo->stimo_data = stcb->asoc.timodata;
2734 stimo->stimo_sack = stcb->asoc.timosack;
2735 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2736 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2737 stimo->stimo_cookie = stcb->asoc.timocookie;
2738 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2739 SCTP_TCB_UNLOCK(stcb);
2740 *optsize = sizeof(struct sctp_timeouts);
2742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2747 case SCTP_ASSOCINFO:
2749 struct sctp_assocparams *sasoc;
2751 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2752 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2755 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2756 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2757 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2758 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2759 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2760 SCTP_TCB_UNLOCK(stcb);
2762 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2763 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2764 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2765 SCTP_INP_RLOCK(inp);
2766 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2767 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2768 sasoc->sasoc_number_peer_destinations = 0;
2769 sasoc->sasoc_peer_rwnd = 0;
2770 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2771 SCTP_INP_RUNLOCK(inp);
2773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2778 *optsize = sizeof(struct sctp_assocparams);
2782 case SCTP_DEFAULT_SEND_PARAM:
2784 struct sctp_sndrcvinfo *s_info;
2786 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2787 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2790 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2791 SCTP_TCB_UNLOCK(stcb);
2793 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2794 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2795 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2796 SCTP_INP_RLOCK(inp);
2797 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2798 SCTP_INP_RUNLOCK(inp);
2800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2805 *optsize = sizeof(struct sctp_sndrcvinfo);
2811 struct sctp_initmsg *sinit;
2813 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2814 SCTP_INP_RLOCK(inp);
2815 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2816 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2817 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2818 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2819 SCTP_INP_RUNLOCK(inp);
2820 *optsize = sizeof(struct sctp_initmsg);
2823 case SCTP_PRIMARY_ADDR:
2824 /* we allow a "get" operation on this */
2826 struct sctp_setprim *ssp;
2828 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2829 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2832 union sctp_sockstore *addr;
2834 addr = &stcb->asoc.primary_destination->ro._l_addr;
2835 switch (addr->sa.sa_family) {
2839 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2840 in6_sin_2_v4mapsin6(&addr->sin,
2841 (struct sockaddr_in6 *)&ssp->ssp_addr);
2843 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2846 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2852 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2858 SCTP_TCB_UNLOCK(stcb);
2859 *optsize = sizeof(struct sctp_setprim);
2861 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2866 case SCTP_HMAC_IDENT:
2868 struct sctp_hmacalgo *shmac;
2869 sctp_hmaclist_t *hmaclist;
2873 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2875 SCTP_INP_RLOCK(inp);
2876 hmaclist = inp->sctp_ep.local_hmacs;
2877 if (hmaclist == NULL) {
2878 /* no HMACs to return */
2879 *optsize = sizeof(*shmac);
2880 SCTP_INP_RUNLOCK(inp);
2883 /* is there room for all of the hmac ids? */
2884 size = sizeof(*shmac) + (hmaclist->num_algo *
2885 sizeof(shmac->shmac_idents[0]));
2886 if ((size_t)(*optsize) < size) {
2887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2889 SCTP_INP_RUNLOCK(inp);
2892 /* copy in the list */
2893 shmac->shmac_number_of_idents = hmaclist->num_algo;
2894 for (i = 0; i < hmaclist->num_algo; i++) {
2895 shmac->shmac_idents[i] = hmaclist->hmac[i];
2897 SCTP_INP_RUNLOCK(inp);
2901 case SCTP_AUTH_ACTIVE_KEY:
2903 struct sctp_authkeyid *scact;
2905 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2906 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2909 /* get the active key on the assoc */
2910 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2911 SCTP_TCB_UNLOCK(stcb);
2913 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2914 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2915 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2916 /* get the endpoint active key */
2917 SCTP_INP_RLOCK(inp);
2918 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2919 SCTP_INP_RUNLOCK(inp);
2921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2926 *optsize = sizeof(struct sctp_authkeyid);
2930 case SCTP_LOCAL_AUTH_CHUNKS:
2932 struct sctp_authchunks *sac;
2933 sctp_auth_chklist_t *chklist = NULL;
2936 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2937 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2940 /* get off the assoc */
2941 chklist = stcb->asoc.local_auth_chunks;
2942 /* is there enough space? */
2943 size = sctp_auth_get_chklist_size(chklist);
2944 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2946 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2948 /* copy in the chunks */
2949 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2950 sac->gauth_number_of_chunks = (uint32_t)size;
2951 *optsize = sizeof(struct sctp_authchunks) + size;
2953 SCTP_TCB_UNLOCK(stcb);
2955 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2956 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2957 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2958 /* get off the endpoint */
2959 SCTP_INP_RLOCK(inp);
2960 chklist = inp->sctp_ep.local_auth_chunks;
2961 /* is there enough space? */
2962 size = sctp_auth_get_chklist_size(chklist);
2963 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2967 /* copy in the chunks */
2968 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2969 sac->gauth_number_of_chunks = (uint32_t)size;
2970 *optsize = sizeof(struct sctp_authchunks) + size;
2972 SCTP_INP_RUNLOCK(inp);
2974 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2980 case SCTP_PEER_AUTH_CHUNKS:
2982 struct sctp_authchunks *sac;
2983 sctp_auth_chklist_t *chklist = NULL;
2986 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2987 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2990 /* get off the assoc */
2991 chklist = stcb->asoc.peer_auth_chunks;
2992 /* is there enough space? */
2993 size = sctp_auth_get_chklist_size(chklist);
2994 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2996 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2998 /* copy in the chunks */
2999 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3000 sac->gauth_number_of_chunks = (uint32_t)size;
3001 *optsize = sizeof(struct sctp_authchunks) + size;
3003 SCTP_TCB_UNLOCK(stcb);
3005 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3012 struct sctp_event *event;
3013 uint32_t event_type;
3015 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3016 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3018 switch (event->se_type) {
3019 case SCTP_ASSOC_CHANGE:
3020 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3022 case SCTP_PEER_ADDR_CHANGE:
3023 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3025 case SCTP_REMOTE_ERROR:
3026 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3028 case SCTP_SEND_FAILED:
3029 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3031 case SCTP_SHUTDOWN_EVENT:
3032 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3034 case SCTP_ADAPTATION_INDICATION:
3035 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3037 case SCTP_PARTIAL_DELIVERY_EVENT:
3038 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3040 case SCTP_AUTHENTICATION_EVENT:
3041 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3043 case SCTP_STREAM_RESET_EVENT:
3044 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3046 case SCTP_SENDER_DRY_EVENT:
3047 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3049 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3051 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3054 case SCTP_ASSOC_RESET_EVENT:
3055 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3057 case SCTP_STREAM_CHANGE_EVENT:
3058 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3060 case SCTP_SEND_FAILED_EVENT:
3061 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3065 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3069 if (event_type > 0) {
3071 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3073 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3074 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3075 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3076 SCTP_INP_RLOCK(inp);
3077 event->se_on = sctp_is_feature_on(inp, event_type);
3078 SCTP_INP_RUNLOCK(inp);
3080 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3086 SCTP_TCB_UNLOCK(stcb);
3089 *optsize = sizeof(struct sctp_event);
3093 case SCTP_RECVRCVINFO:
3097 if (*optsize < sizeof(int)) {
3098 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3101 SCTP_INP_RLOCK(inp);
3102 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3103 SCTP_INP_RUNLOCK(inp);
3106 /* return the option value */
3107 *(int *)optval = onoff;
3108 *optsize = sizeof(int);
3112 case SCTP_RECVNXTINFO:
3116 if (*optsize < sizeof(int)) {
3117 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3120 SCTP_INP_RLOCK(inp);
3121 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3122 SCTP_INP_RUNLOCK(inp);
3125 /* return the option value */
3126 *(int *)optval = onoff;
3127 *optsize = sizeof(int);
3131 case SCTP_DEFAULT_SNDINFO:
3133 struct sctp_sndinfo *info;
3135 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3136 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3139 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3140 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3141 info->snd_flags &= 0xfff0;
3142 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3143 info->snd_context = stcb->asoc.def_send.sinfo_context;
3144 SCTP_TCB_UNLOCK(stcb);
3146 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3147 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3148 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3149 SCTP_INP_RLOCK(inp);
3150 info->snd_sid = inp->def_send.sinfo_stream;
3151 info->snd_flags = inp->def_send.sinfo_flags;
3152 info->snd_flags &= 0xfff0;
3153 info->snd_ppid = inp->def_send.sinfo_ppid;
3154 info->snd_context = inp->def_send.sinfo_context;
3155 SCTP_INP_RUNLOCK(inp);
3157 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3162 *optsize = sizeof(struct sctp_sndinfo);
3166 case SCTP_DEFAULT_PRINFO:
3168 struct sctp_default_prinfo *info;
3170 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3171 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3174 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3175 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3176 SCTP_TCB_UNLOCK(stcb);
3178 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3179 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3180 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3181 SCTP_INP_RLOCK(inp);
3182 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3183 info->pr_value = inp->def_send.sinfo_timetolive;
3184 SCTP_INP_RUNLOCK(inp);
3186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3191 *optsize = sizeof(struct sctp_default_prinfo);
3195 case SCTP_PEER_ADDR_THLDS:
3197 struct sctp_paddrthlds *thlds;
3198 struct sctp_nets *net;
3199 struct sockaddr *addr;
3200 #if defined(INET) && defined(INET6)
3201 struct sockaddr_in sin_store;
3204 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3205 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3207 #if defined(INET) && defined(INET6)
3208 if (thlds->spt_address.ss_family == AF_INET6) {
3209 struct sockaddr_in6 *sin6;
3211 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3212 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3213 in6_sin6_2_sin(&sin_store, sin6);
3214 addr = (struct sockaddr *)&sin_store;
3216 addr = (struct sockaddr *)&thlds->spt_address;
3219 addr = (struct sockaddr *)&thlds->spt_address;
3222 addr = (struct sockaddr *)&thlds->spt_address;
3225 net = sctp_findnet(stcb, addr);
3228 * We increment here since
3229 * sctp_findassociation_ep_addr() wil do a
3230 * decrement if it finds the stcb as long as
3231 * the locked tcb (last argument) is NOT a
3235 SCTP_INP_INCR_REF(inp);
3236 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3238 SCTP_INP_DECR_REF(inp);
3241 if ((stcb != NULL) && (net == NULL)) {
3243 if (addr->sa_family == AF_INET) {
3244 struct sockaddr_in *sin;
3246 sin = (struct sockaddr_in *)addr;
3247 if (sin->sin_addr.s_addr != INADDR_ANY) {
3249 SCTP_TCB_UNLOCK(stcb);
3250 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3256 if (addr->sa_family == AF_INET6) {
3257 struct sockaddr_in6 *sin6;
3259 sin6 = (struct sockaddr_in6 *)addr;
3260 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3262 SCTP_TCB_UNLOCK(stcb);
3263 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3269 error = EAFNOSUPPORT;
3270 SCTP_TCB_UNLOCK(stcb);
3271 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3278 thlds->spt_pathmaxrxt = net->failure_threshold;
3279 thlds->spt_pathpfthld = net->pf_threshold;
3280 thlds->spt_pathcpthld = 0xffff;
3282 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3283 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3284 thlds->spt_pathcpthld = 0xffff;
3286 thlds->spt_assoc_id = sctp_get_associd(stcb);
3287 SCTP_TCB_UNLOCK(stcb);
3289 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3290 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3291 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3292 /* Use endpoint defaults */
3293 SCTP_INP_RLOCK(inp);
3294 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3295 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3296 thlds->spt_pathcpthld = 0xffff;
3297 SCTP_INP_RUNLOCK(inp);
3299 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3304 *optsize = sizeof(struct sctp_paddrthlds);
3308 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3310 struct sctp_udpencaps *encaps;
3311 struct sctp_nets *net;
3312 struct sockaddr *addr;
3313 #if defined(INET) && defined(INET6)
3314 struct sockaddr_in sin_store;
3317 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3318 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3320 #if defined(INET) && defined(INET6)
3321 if (encaps->sue_address.ss_family == AF_INET6) {
3322 struct sockaddr_in6 *sin6;
3324 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3325 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3326 in6_sin6_2_sin(&sin_store, sin6);
3327 addr = (struct sockaddr *)&sin_store;
3329 addr = (struct sockaddr *)&encaps->sue_address;
3332 addr = (struct sockaddr *)&encaps->sue_address;
3335 addr = (struct sockaddr *)&encaps->sue_address;
3338 net = sctp_findnet(stcb, addr);
3341 * We increment here since
3342 * sctp_findassociation_ep_addr() wil do a
3343 * decrement if it finds the stcb as long as
3344 * the locked tcb (last argument) is NOT a
3348 SCTP_INP_INCR_REF(inp);
3349 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3351 SCTP_INP_DECR_REF(inp);
3354 if ((stcb != NULL) && (net == NULL)) {
3356 if (addr->sa_family == AF_INET) {
3357 struct sockaddr_in *sin;
3359 sin = (struct sockaddr_in *)addr;
3360 if (sin->sin_addr.s_addr != INADDR_ANY) {
3362 SCTP_TCB_UNLOCK(stcb);
3363 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3369 if (addr->sa_family == AF_INET6) {
3370 struct sockaddr_in6 *sin6;
3372 sin6 = (struct sockaddr_in6 *)addr;
3373 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3375 SCTP_TCB_UNLOCK(stcb);
3376 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3382 error = EAFNOSUPPORT;
3383 SCTP_TCB_UNLOCK(stcb);
3384 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3391 encaps->sue_port = net->port;
3393 encaps->sue_port = stcb->asoc.port;
3395 SCTP_TCB_UNLOCK(stcb);
3397 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3398 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3399 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3400 SCTP_INP_RLOCK(inp);
3401 encaps->sue_port = inp->sctp_ep.port;
3402 SCTP_INP_RUNLOCK(inp);
3404 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3409 *optsize = sizeof(struct sctp_udpencaps);
3413 case SCTP_ECN_SUPPORTED:
3415 struct sctp_assoc_value *av;
3417 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3418 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3421 av->assoc_value = stcb->asoc.ecn_supported;
3422 SCTP_TCB_UNLOCK(stcb);
3424 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3425 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3426 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3427 SCTP_INP_RLOCK(inp);
3428 av->assoc_value = inp->ecn_supported;
3429 SCTP_INP_RUNLOCK(inp);
3431 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3436 *optsize = sizeof(struct sctp_assoc_value);
3440 case SCTP_PR_SUPPORTED:
3442 struct sctp_assoc_value *av;
3444 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3445 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3448 av->assoc_value = stcb->asoc.prsctp_supported;
3449 SCTP_TCB_UNLOCK(stcb);
3451 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3452 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3453 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3454 SCTP_INP_RLOCK(inp);
3455 av->assoc_value = inp->prsctp_supported;
3456 SCTP_INP_RUNLOCK(inp);
3458 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3463 *optsize = sizeof(struct sctp_assoc_value);
3467 case SCTP_AUTH_SUPPORTED:
3469 struct sctp_assoc_value *av;
3471 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3472 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3475 av->assoc_value = stcb->asoc.auth_supported;
3476 SCTP_TCB_UNLOCK(stcb);
3478 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3479 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3480 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3481 SCTP_INP_RLOCK(inp);
3482 av->assoc_value = inp->auth_supported;
3483 SCTP_INP_RUNLOCK(inp);
3485 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3490 *optsize = sizeof(struct sctp_assoc_value);
3494 case SCTP_ASCONF_SUPPORTED:
3496 struct sctp_assoc_value *av;
3498 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3499 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3502 av->assoc_value = stcb->asoc.asconf_supported;
3503 SCTP_TCB_UNLOCK(stcb);
3505 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3506 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3507 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3508 SCTP_INP_RLOCK(inp);
3509 av->assoc_value = inp->asconf_supported;
3510 SCTP_INP_RUNLOCK(inp);
3512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3517 *optsize = sizeof(struct sctp_assoc_value);
3521 case SCTP_RECONFIG_SUPPORTED:
3523 struct sctp_assoc_value *av;
3525 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3526 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3529 av->assoc_value = stcb->asoc.reconfig_supported;
3530 SCTP_TCB_UNLOCK(stcb);
3532 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3533 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3534 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3535 SCTP_INP_RLOCK(inp);
3536 av->assoc_value = inp->reconfig_supported;
3537 SCTP_INP_RUNLOCK(inp);
3539 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3544 *optsize = sizeof(struct sctp_assoc_value);
3548 case SCTP_NRSACK_SUPPORTED:
3550 struct sctp_assoc_value *av;
3552 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3553 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3556 av->assoc_value = stcb->asoc.nrsack_supported;
3557 SCTP_TCB_UNLOCK(stcb);
3559 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3560 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3561 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3562 SCTP_INP_RLOCK(inp);
3563 av->assoc_value = inp->nrsack_supported;
3564 SCTP_INP_RUNLOCK(inp);
3566 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3571 *optsize = sizeof(struct sctp_assoc_value);
3575 case SCTP_PKTDROP_SUPPORTED:
3577 struct sctp_assoc_value *av;
3579 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3580 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3583 av->assoc_value = stcb->asoc.pktdrop_supported;
3584 SCTP_TCB_UNLOCK(stcb);
3586 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3587 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3588 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3589 SCTP_INP_RLOCK(inp);
3590 av->assoc_value = inp->pktdrop_supported;
3591 SCTP_INP_RUNLOCK(inp);
3593 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3598 *optsize = sizeof(struct sctp_assoc_value);
3602 case SCTP_ENABLE_STREAM_RESET:
3604 struct sctp_assoc_value *av;
3606 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3607 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3610 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3611 SCTP_TCB_UNLOCK(stcb);
3613 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3614 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3615 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3616 SCTP_INP_RLOCK(inp);
3617 av->assoc_value = (uint32_t)inp->local_strreset_support;
3618 SCTP_INP_RUNLOCK(inp);
3620 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3625 *optsize = sizeof(struct sctp_assoc_value);
3629 case SCTP_PR_STREAM_STATUS:
3631 struct sctp_prstatus *sprstat;
3635 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3636 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3638 sid = sprstat->sprstat_sid;
3639 policy = sprstat->sprstat_policy;
3640 #if defined(SCTP_DETAILED_STR_STATS)
3641 if ((stcb != NULL) &&
3642 (sid < stcb->asoc.streamoutcnt) &&
3643 (policy != SCTP_PR_SCTP_NONE) &&
3644 ((policy <= SCTP_PR_SCTP_MAX) ||
3645 (policy == SCTP_PR_SCTP_ALL))) {
3646 if (policy == SCTP_PR_SCTP_ALL) {
3647 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3648 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3650 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3651 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3654 if ((stcb != NULL) &&
3655 (sid < stcb->asoc.streamoutcnt) &&
3656 (policy == SCTP_PR_SCTP_ALL)) {
3657 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3658 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3661 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3665 SCTP_TCB_UNLOCK(stcb);
3668 *optsize = sizeof(struct sctp_prstatus);
3672 case SCTP_PR_ASSOC_STATUS:
3674 struct sctp_prstatus *sprstat;
3677 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3678 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3680 policy = sprstat->sprstat_policy;
3681 if ((stcb != NULL) &&
3682 (policy != SCTP_PR_SCTP_NONE) &&
3683 ((policy <= SCTP_PR_SCTP_MAX) ||
3684 (policy == SCTP_PR_SCTP_ALL))) {
3685 if (policy == SCTP_PR_SCTP_ALL) {
3686 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3687 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3689 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3690 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3693 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3697 SCTP_TCB_UNLOCK(stcb);
3700 *optsize = sizeof(struct sctp_prstatus);
3706 struct sctp_assoc_value *av;
3708 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3709 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3712 av->assoc_value = stcb->asoc.max_cwnd;
3713 SCTP_TCB_UNLOCK(stcb);
3715 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3716 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3717 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3718 SCTP_INP_RLOCK(inp);
3719 av->assoc_value = inp->max_cwnd;
3720 SCTP_INP_RUNLOCK(inp);
3722 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3727 *optsize = sizeof(struct sctp_assoc_value);
3732 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3733 error = ENOPROTOOPT;
3735 } /* end switch (sopt->sopt_name) */
3743 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3748 struct sctp_tcb *stcb = NULL;
3749 struct sctp_inpcb *inp = NULL;
3752 if (optval == NULL) {
3753 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3756 inp = (struct sctp_inpcb *)so->so_pcb;
3758 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3761 vrf_id = inp->def_vrf_id;
3766 case SCTP_AUTOCLOSE:
3767 case SCTP_AUTO_ASCONF:
3768 case SCTP_EXPLICIT_EOR:
3769 case SCTP_DISABLE_FRAGMENTS:
3770 case SCTP_USE_EXT_RCVINFO:
3771 case SCTP_I_WANT_MAPPED_V4_ADDR:
3772 /* copy in the option value */
3773 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3778 case SCTP_DISABLE_FRAGMENTS:
3779 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3781 case SCTP_AUTO_ASCONF:
3783 * NOTE: we don't really support this flag
3785 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3786 /* only valid for bound all sockets */
3787 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3789 /* forbidden by admin */
3790 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3793 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3799 case SCTP_EXPLICIT_EOR:
3800 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3802 case SCTP_USE_EXT_RCVINFO:
3803 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3805 case SCTP_I_WANT_MAPPED_V4_ADDR:
3806 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3807 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3809 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3814 set_opt = SCTP_PCB_FLAGS_NODELAY;
3816 case SCTP_AUTOCLOSE:
3817 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3818 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3819 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3822 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3824 * The value is in ticks. Note this does not effect
3825 * old associations, only new ones.
3827 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3830 SCTP_INP_WLOCK(inp);
3832 sctp_feature_on(inp, set_opt);
3834 sctp_feature_off(inp, set_opt);
3836 SCTP_INP_WUNLOCK(inp);
3838 case SCTP_REUSE_PORT:
3840 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3841 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3842 /* Can't set it after we are bound */
3846 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3847 /* Can't do this for a 1-m socket */
3852 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3854 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3857 case SCTP_PARTIAL_DELIVERY_POINT:
3861 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3862 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3863 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3867 inp->partial_delivery_point = *value;
3870 case SCTP_FRAGMENT_INTERLEAVE:
3871 /* not yet until we re-write sctp_recvmsg() */
3875 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3876 if (*level == SCTP_FRAG_LEVEL_2) {
3877 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3878 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3879 } else if (*level == SCTP_FRAG_LEVEL_1) {
3880 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3881 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3882 } else if (*level == SCTP_FRAG_LEVEL_0) {
3883 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3884 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3892 case SCTP_INTERLEAVING_SUPPORTED:
3894 struct sctp_assoc_value *av;
3896 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3897 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3900 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3902 SCTP_TCB_UNLOCK(stcb);
3904 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3905 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3906 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3907 SCTP_INP_WLOCK(inp);
3908 if (av->assoc_value == 0) {
3909 inp->idata_supported = 0;
3911 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3912 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3913 inp->idata_supported = 1;
3921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3925 SCTP_INP_WUNLOCK(inp);
3927 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3933 case SCTP_CMT_ON_OFF:
3934 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3935 struct sctp_assoc_value *av;
3937 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3938 if (av->assoc_value > SCTP_CMT_MAX) {
3939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3943 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3945 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3946 SCTP_TCB_UNLOCK(stcb);
3948 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3949 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3950 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3951 (av->assoc_id == SCTP_ALL_ASSOC)) {
3952 SCTP_INP_WLOCK(inp);
3953 inp->sctp_cmt_on_off = av->assoc_value;
3954 SCTP_INP_WUNLOCK(inp);
3956 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3957 (av->assoc_id == SCTP_ALL_ASSOC)) {
3958 SCTP_INP_RLOCK(inp);
3959 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3960 SCTP_TCB_LOCK(stcb);
3961 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3962 SCTP_TCB_UNLOCK(stcb);
3964 SCTP_INP_RUNLOCK(inp);
3968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3969 error = ENOPROTOOPT;
3972 case SCTP_PLUGGABLE_CC:
3974 struct sctp_assoc_value *av;
3975 struct sctp_nets *net;
3977 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3978 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3979 (av->assoc_value != SCTP_CC_HSTCP) &&
3980 (av->assoc_value != SCTP_CC_HTCP) &&
3981 (av->assoc_value != SCTP_CC_RTCC)) {
3982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3986 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3988 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3989 stcb->asoc.congestion_control_module = av->assoc_value;
3990 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3991 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3992 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3995 SCTP_TCB_UNLOCK(stcb);
3997 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3998 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3999 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4000 (av->assoc_id == SCTP_ALL_ASSOC)) {
4001 SCTP_INP_WLOCK(inp);
4002 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
4003 SCTP_INP_WUNLOCK(inp);
4005 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4006 (av->assoc_id == SCTP_ALL_ASSOC)) {
4007 SCTP_INP_RLOCK(inp);
4008 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4009 SCTP_TCB_LOCK(stcb);
4010 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4011 stcb->asoc.congestion_control_module = av->assoc_value;
4012 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4013 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4014 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4017 SCTP_TCB_UNLOCK(stcb);
4019 SCTP_INP_RUNLOCK(inp);
4024 case SCTP_CC_OPTION:
4026 struct sctp_cc_option *cc_opt;
4028 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4029 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4031 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4032 SCTP_INP_RLOCK(inp);
4033 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4034 SCTP_TCB_LOCK(stcb);
4035 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4036 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4038 SCTP_TCB_UNLOCK(stcb);
4040 SCTP_INP_RUNLOCK(inp);
4045 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4048 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4051 SCTP_TCB_UNLOCK(stcb);
4055 case SCTP_PLUGGABLE_SS:
4057 struct sctp_assoc_value *av;
4059 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4060 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4061 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4062 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4063 (av->assoc_value != SCTP_SS_PRIORITY) &&
4064 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4065 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4066 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4070 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4072 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4073 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4074 stcb->asoc.stream_scheduling_module = av->assoc_value;
4075 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4076 SCTP_TCB_UNLOCK(stcb);
4078 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4079 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4080 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4081 (av->assoc_id == SCTP_ALL_ASSOC)) {
4082 SCTP_INP_WLOCK(inp);
4083 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4084 SCTP_INP_WUNLOCK(inp);
4086 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4087 (av->assoc_id == SCTP_ALL_ASSOC)) {
4088 SCTP_INP_RLOCK(inp);
4089 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4090 SCTP_TCB_LOCK(stcb);
4091 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4092 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4093 stcb->asoc.stream_scheduling_module = av->assoc_value;
4094 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4095 SCTP_TCB_UNLOCK(stcb);
4097 SCTP_INP_RUNLOCK(inp);
4104 struct sctp_stream_value *av;
4106 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4107 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4109 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4110 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4111 av->stream_value) < 0)) {
4112 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4115 SCTP_TCB_UNLOCK(stcb);
4117 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4118 SCTP_INP_RLOCK(inp);
4119 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4120 SCTP_TCB_LOCK(stcb);
4121 if (av->stream_id < stcb->asoc.streamoutcnt) {
4122 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4124 &stcb->asoc.strmout[av->stream_id],
4127 SCTP_TCB_UNLOCK(stcb);
4129 SCTP_INP_RUNLOCK(inp);
4132 * Can't set stream value without
4135 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4141 case SCTP_CLR_STAT_LOG:
4142 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4147 struct sctp_assoc_value *av;
4149 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4150 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4153 stcb->asoc.context = av->assoc_value;
4154 SCTP_TCB_UNLOCK(stcb);
4156 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4157 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4158 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4159 (av->assoc_id == SCTP_ALL_ASSOC)) {
4160 SCTP_INP_WLOCK(inp);
4161 inp->sctp_context = av->assoc_value;
4162 SCTP_INP_WUNLOCK(inp);
4164 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4165 (av->assoc_id == SCTP_ALL_ASSOC)) {
4166 SCTP_INP_RLOCK(inp);
4167 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4168 SCTP_TCB_LOCK(stcb);
4169 stcb->asoc.context = av->assoc_value;
4170 SCTP_TCB_UNLOCK(stcb);
4172 SCTP_INP_RUNLOCK(inp);
4179 uint32_t *default_vrfid;
4181 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4182 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4183 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4187 inp->def_vrf_id = *default_vrfid;
4190 case SCTP_DEL_VRF_ID:
4192 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4196 case SCTP_ADD_VRF_ID:
4198 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4202 case SCTP_DELAYED_SACK:
4204 struct sctp_sack_info *sack;
4206 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4207 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4208 if (sack->sack_delay) {
4209 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4210 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4211 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4212 sack->sack_delay = TICKS_TO_MSEC(1);
4216 if (sack->sack_delay) {
4217 stcb->asoc.delayed_ack = sack->sack_delay;
4219 if (sack->sack_freq) {
4220 stcb->asoc.sack_freq = sack->sack_freq;
4222 SCTP_TCB_UNLOCK(stcb);
4224 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4225 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4226 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4227 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4228 SCTP_INP_WLOCK(inp);
4229 if (sack->sack_delay) {
4230 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4232 if (sack->sack_freq) {
4233 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4235 SCTP_INP_WUNLOCK(inp);
4237 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4238 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4239 SCTP_INP_RLOCK(inp);
4240 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4241 SCTP_TCB_LOCK(stcb);
4242 if (sack->sack_delay) {
4243 stcb->asoc.delayed_ack = sack->sack_delay;
4245 if (sack->sack_freq) {
4246 stcb->asoc.sack_freq = sack->sack_freq;
4248 SCTP_TCB_UNLOCK(stcb);
4250 SCTP_INP_RUNLOCK(inp);
4255 case SCTP_AUTH_CHUNK:
4257 struct sctp_authchunk *sauth;
4259 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4261 SCTP_INP_WLOCK(inp);
4262 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4263 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4266 inp->auth_supported = 1;
4268 SCTP_INP_WUNLOCK(inp);
4273 struct sctp_authkey *sca;
4274 struct sctp_keyhead *shared_keys;
4275 sctp_sharedkey_t *shared_key;
4276 sctp_key_t *key = NULL;
4279 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4280 if (sca->sca_keylength == 0) {
4281 size = optsize - sizeof(struct sctp_authkey);
4283 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4284 size = sca->sca_keylength;
4286 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4291 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4294 shared_keys = &stcb->asoc.shared_keys;
4295 /* clear the cached keys for this key id */
4296 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4298 * create the new shared key and
4302 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4304 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4306 SCTP_TCB_UNLOCK(stcb);
4310 shared_key = sctp_alloc_sharedkey();
4311 if (shared_key == NULL) {
4313 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4315 SCTP_TCB_UNLOCK(stcb);
4318 shared_key->key = key;
4319 shared_key->keyid = sca->sca_keynumber;
4320 error = sctp_insert_sharedkey(shared_keys, shared_key);
4321 SCTP_TCB_UNLOCK(stcb);
4323 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4324 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4325 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4326 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4327 SCTP_INP_WLOCK(inp);
4328 shared_keys = &inp->sctp_ep.shared_keys;
4330 * clear the cached keys on all
4331 * assocs for this key id
4333 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4335 * create the new shared key and
4339 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4341 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4343 SCTP_INP_WUNLOCK(inp);
4347 shared_key = sctp_alloc_sharedkey();
4348 if (shared_key == NULL) {
4350 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4352 SCTP_INP_WUNLOCK(inp);
4355 shared_key->key = key;
4356 shared_key->keyid = sca->sca_keynumber;
4357 error = sctp_insert_sharedkey(shared_keys, shared_key);
4358 SCTP_INP_WUNLOCK(inp);
4360 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4361 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4362 SCTP_INP_RLOCK(inp);
4363 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4364 SCTP_TCB_LOCK(stcb);
4365 shared_keys = &stcb->asoc.shared_keys;
4367 * clear the cached keys for
4370 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4372 * create the new shared key
4373 * and insert/replace it
4376 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4378 SCTP_TCB_UNLOCK(stcb);
4382 shared_key = sctp_alloc_sharedkey();
4383 if (shared_key == NULL) {
4385 SCTP_TCB_UNLOCK(stcb);
4388 shared_key->key = key;
4389 shared_key->keyid = sca->sca_keynumber;
4390 error = sctp_insert_sharedkey(shared_keys, shared_key);
4391 SCTP_TCB_UNLOCK(stcb);
4393 SCTP_INP_RUNLOCK(inp);
4398 case SCTP_HMAC_IDENT:
4400 struct sctp_hmacalgo *shmac;
4401 sctp_hmaclist_t *hmaclist;
4405 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4406 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4407 (shmac->shmac_number_of_idents > 0xffff)) {
4408 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4413 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4414 if (hmaclist == NULL) {
4415 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4419 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4420 hmacid = shmac->shmac_idents[i];
4421 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4422 /* invalid HMACs were found */ ;
4423 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4425 sctp_free_hmaclist(hmaclist);
4426 goto sctp_set_hmac_done;
4429 for (i = 0; i < hmaclist->num_algo; i++) {
4430 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4431 /* already in list */
4435 if (i == hmaclist->num_algo) {
4436 /* not found in list */
4437 sctp_free_hmaclist(hmaclist);
4438 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4442 /* set it on the endpoint */
4443 SCTP_INP_WLOCK(inp);
4444 if (inp->sctp_ep.local_hmacs)
4445 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4446 inp->sctp_ep.local_hmacs = hmaclist;
4447 SCTP_INP_WUNLOCK(inp);
4451 case SCTP_AUTH_ACTIVE_KEY:
4453 struct sctp_authkeyid *scact;
4455 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4456 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4458 /* set the active key on the right place */
4460 /* set the active key on the assoc */
4461 if (sctp_auth_setactivekey(stcb,
4462 scact->scact_keynumber)) {
4463 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4464 SCTP_FROM_SCTP_USRREQ,
4468 SCTP_TCB_UNLOCK(stcb);
4470 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4471 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4472 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4473 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4474 SCTP_INP_WLOCK(inp);
4475 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4476 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4479 SCTP_INP_WUNLOCK(inp);
4481 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4482 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4483 SCTP_INP_RLOCK(inp);
4484 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4485 SCTP_TCB_LOCK(stcb);
4486 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4487 SCTP_TCB_UNLOCK(stcb);
4489 SCTP_INP_RUNLOCK(inp);
4494 case SCTP_AUTH_DELETE_KEY:
4496 struct sctp_authkeyid *scdel;
4498 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4499 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4501 /* delete the key from the right place */
4503 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4504 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4507 SCTP_TCB_UNLOCK(stcb);
4509 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4510 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4511 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4512 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4513 SCTP_INP_WLOCK(inp);
4514 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4515 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4518 SCTP_INP_WUNLOCK(inp);
4520 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4521 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4522 SCTP_INP_RLOCK(inp);
4523 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4524 SCTP_TCB_LOCK(stcb);
4525 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4526 SCTP_TCB_UNLOCK(stcb);
4528 SCTP_INP_RUNLOCK(inp);
4533 case SCTP_AUTH_DEACTIVATE_KEY:
4535 struct sctp_authkeyid *keyid;
4537 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4538 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4540 /* deactivate the key from the right place */
4542 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4543 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4546 SCTP_TCB_UNLOCK(stcb);
4548 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4549 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4550 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4551 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4552 SCTP_INP_WLOCK(inp);
4553 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4554 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4557 SCTP_INP_WUNLOCK(inp);
4559 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4560 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4561 SCTP_INP_RLOCK(inp);
4562 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4563 SCTP_TCB_LOCK(stcb);
4564 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4565 SCTP_TCB_UNLOCK(stcb);
4567 SCTP_INP_RUNLOCK(inp);
4572 case SCTP_ENABLE_STREAM_RESET:
4574 struct sctp_assoc_value *av;
4576 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4577 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4578 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4582 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4584 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4585 SCTP_TCB_UNLOCK(stcb);
4587 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4588 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4589 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4590 (av->assoc_id == SCTP_ALL_ASSOC)) {
4591 SCTP_INP_WLOCK(inp);
4592 inp->local_strreset_support = (uint8_t)av->assoc_value;
4593 SCTP_INP_WUNLOCK(inp);
4595 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4596 (av->assoc_id == SCTP_ALL_ASSOC)) {
4597 SCTP_INP_RLOCK(inp);
4598 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4599 SCTP_TCB_LOCK(stcb);
4600 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4601 SCTP_TCB_UNLOCK(stcb);
4603 SCTP_INP_RUNLOCK(inp);
4609 case SCTP_RESET_STREAMS:
4611 struct sctp_reset_streams *strrst;
4612 int i, send_out = 0;
4615 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4616 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4618 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4622 if (stcb->asoc.reconfig_supported == 0) {
4624 * Peer does not support the chunk type.
4626 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4628 SCTP_TCB_UNLOCK(stcb);
4631 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4632 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4634 SCTP_TCB_UNLOCK(stcb);
4637 if (sizeof(struct sctp_reset_streams) +
4638 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4640 SCTP_TCB_UNLOCK(stcb);
4643 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4645 if (stcb->asoc.stream_reset_outstanding) {
4646 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4648 SCTP_TCB_UNLOCK(stcb);
4652 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4655 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4656 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4658 SCTP_TCB_UNLOCK(stcb);
4661 if ((send_in == 0) && (send_out == 0)) {
4662 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4664 SCTP_TCB_UNLOCK(stcb);
4667 for (i = 0; i < strrst->srs_number_streams; i++) {
4669 (strrst->srs_stream_list[i] >= stcb->asoc.streamincnt)) {
4670 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4675 (strrst->srs_stream_list[i] >= stcb->asoc.streamoutcnt)) {
4676 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4682 SCTP_TCB_UNLOCK(stcb);
4689 if (strrst->srs_number_streams) {
4690 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4691 strm = strrst->srs_stream_list[i];
4692 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4693 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4699 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4700 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4701 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4708 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4709 strrst->srs_stream_list,
4710 send_in, 0, 0, 0, 0, 0);
4712 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4715 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4718 * For outgoing streams don't report any
4719 * problems in sending the request to the
4720 * application. XXX: Double check resetting
4725 SCTP_TCB_UNLOCK(stcb);
4728 case SCTP_ADD_STREAMS:
4730 struct sctp_add_streams *stradd;
4731 uint8_t addstream = 0;
4732 uint16_t add_o_strmcnt = 0;
4733 uint16_t add_i_strmcnt = 0;
4735 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4736 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4738 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4742 if (stcb->asoc.reconfig_supported == 0) {
4744 * Peer does not support the chunk type.
4746 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4748 SCTP_TCB_UNLOCK(stcb);
4751 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4752 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4754 SCTP_TCB_UNLOCK(stcb);
4757 if (stcb->asoc.stream_reset_outstanding) {
4758 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4760 SCTP_TCB_UNLOCK(stcb);
4763 if ((stradd->sas_outstrms == 0) &&
4764 (stradd->sas_instrms == 0)) {
4768 if (stradd->sas_outstrms) {
4770 /* We allocate here */
4771 add_o_strmcnt = stradd->sas_outstrms;
4772 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4773 /* You can't have more than 64k */
4778 if (stradd->sas_instrms) {
4783 * We allocate inside
4784 * sctp_send_str_reset_req()
4786 add_i_strmcnt = stradd->sas_instrms;
4787 cnt = add_i_strmcnt;
4788 cnt += stcb->asoc.streamincnt;
4789 if (cnt > 0x0000ffff) {
4790 /* You can't have more than 64k */
4794 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4795 /* More than you are allowed */
4800 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4801 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4803 SCTP_TCB_UNLOCK(stcb);
4806 case SCTP_RESET_ASSOC:
4811 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4812 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4814 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4818 if (stcb->asoc.reconfig_supported == 0) {
4820 * Peer does not support the chunk type.
4822 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4824 SCTP_TCB_UNLOCK(stcb);
4827 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4828 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4830 SCTP_TCB_UNLOCK(stcb);
4833 if (stcb->asoc.stream_reset_outstanding) {
4834 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4836 SCTP_TCB_UNLOCK(stcb);
4840 * Is there any data pending in the send or sent
4843 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4844 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4847 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4848 SCTP_TCB_UNLOCK(stcb);
4851 /* Do any streams have data queued? */
4852 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4853 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4857 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4858 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4859 SCTP_TCB_UNLOCK(stcb);
4862 case SCTP_CONNECT_X:
4863 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4864 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4868 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4870 case SCTP_CONNECT_X_DELAYED:
4871 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4876 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4878 case SCTP_CONNECT_X_COMPLETE:
4880 struct sockaddr *sa;
4882 /* FIXME MT: check correct? */
4883 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4886 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4887 SCTP_INP_RLOCK(inp);
4888 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4890 SCTP_TCB_LOCK(stcb);
4892 SCTP_INP_RUNLOCK(inp);
4895 * We increment here since
4896 * sctp_findassociation_ep_addr() wil do a
4897 * decrement if it finds the stcb as long as
4898 * the locked tcb (last argument) is NOT a
4901 SCTP_INP_INCR_REF(inp);
4902 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4904 SCTP_INP_DECR_REF(inp);
4909 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4913 if (stcb->asoc.delayed_connection == 1) {
4914 stcb->asoc.delayed_connection = 0;
4915 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4916 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4917 stcb->asoc.primary_destination,
4918 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4919 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4922 * already expired or did not use delayed
4925 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4928 SCTP_TCB_UNLOCK(stcb);
4931 case SCTP_MAX_BURST:
4933 struct sctp_assoc_value *av;
4935 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4936 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4939 stcb->asoc.max_burst = av->assoc_value;
4940 SCTP_TCB_UNLOCK(stcb);
4942 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4943 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4944 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4945 (av->assoc_id == SCTP_ALL_ASSOC)) {
4946 SCTP_INP_WLOCK(inp);
4947 inp->sctp_ep.max_burst = av->assoc_value;
4948 SCTP_INP_WUNLOCK(inp);
4950 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4951 (av->assoc_id == SCTP_ALL_ASSOC)) {
4952 SCTP_INP_RLOCK(inp);
4953 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4954 SCTP_TCB_LOCK(stcb);
4955 stcb->asoc.max_burst = av->assoc_value;
4956 SCTP_TCB_UNLOCK(stcb);
4958 SCTP_INP_RUNLOCK(inp);
4965 struct sctp_assoc_value *av;
4968 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4969 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4971 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4972 ovh = SCTP_MED_OVERHEAD;
4974 ovh = SCTP_MED_V4_OVERHEAD;
4977 if (av->assoc_value) {
4978 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4980 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4982 SCTP_TCB_UNLOCK(stcb);
4984 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4985 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4986 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4987 SCTP_INP_WLOCK(inp);
4989 * FIXME MT: I think this is not in
4990 * tune with the API ID
4992 if (av->assoc_value) {
4993 inp->sctp_frag_point = (av->assoc_value + ovh);
4995 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4997 SCTP_INP_WUNLOCK(inp);
4999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5007 struct sctp_event_subscribe *events;
5009 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5011 SCTP_INP_WLOCK(inp);
5012 if (events->sctp_data_io_event) {
5013 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5015 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5018 if (events->sctp_association_event) {
5019 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5021 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5024 if (events->sctp_address_event) {
5025 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5027 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5030 if (events->sctp_send_failure_event) {
5031 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5033 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5036 if (events->sctp_peer_error_event) {
5037 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5039 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5042 if (events->sctp_shutdown_event) {
5043 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5045 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5048 if (events->sctp_partial_delivery_event) {
5049 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5051 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5054 if (events->sctp_adaptation_layer_event) {
5055 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5057 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5060 if (events->sctp_authentication_event) {
5061 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5063 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5066 if (events->sctp_sender_dry_event) {
5067 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5069 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5072 if (events->sctp_stream_reset_event) {
5073 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5075 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5077 SCTP_INP_WUNLOCK(inp);
5079 SCTP_INP_RLOCK(inp);
5080 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5081 SCTP_TCB_LOCK(stcb);
5082 if (events->sctp_association_event) {
5083 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5085 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5087 if (events->sctp_address_event) {
5088 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5090 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5092 if (events->sctp_send_failure_event) {
5093 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5095 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5097 if (events->sctp_peer_error_event) {
5098 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5100 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5102 if (events->sctp_shutdown_event) {
5103 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5105 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5107 if (events->sctp_partial_delivery_event) {
5108 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5110 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5112 if (events->sctp_adaptation_layer_event) {
5113 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5115 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5117 if (events->sctp_authentication_event) {
5118 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5120 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5122 if (events->sctp_sender_dry_event) {
5123 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5125 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5127 if (events->sctp_stream_reset_event) {
5128 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5130 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5132 SCTP_TCB_UNLOCK(stcb);
5135 * Send up the sender dry event only for 1-to-1
5138 if (events->sctp_sender_dry_event) {
5139 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5140 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5141 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5143 SCTP_TCB_LOCK(stcb);
5144 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5145 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5146 (stcb->asoc.stream_queue_cnt == 0)) {
5147 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5149 SCTP_TCB_UNLOCK(stcb);
5153 SCTP_INP_RUNLOCK(inp);
5156 case SCTP_ADAPTATION_LAYER:
5158 struct sctp_setadaptation *adap_bits;
5160 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5161 SCTP_INP_WLOCK(inp);
5162 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5163 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5164 SCTP_INP_WUNLOCK(inp);
5168 case SCTP_SET_INITIAL_DBG_SEQ:
5172 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5173 SCTP_INP_WLOCK(inp);
5174 inp->sctp_ep.initial_sequence_debug = *vvv;
5175 SCTP_INP_WUNLOCK(inp);
5179 case SCTP_DEFAULT_SEND_PARAM:
5181 struct sctp_sndrcvinfo *s_info;
5183 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5184 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5187 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5188 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5190 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5193 SCTP_TCB_UNLOCK(stcb);
5195 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5196 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5197 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5198 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5199 SCTP_INP_WLOCK(inp);
5200 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5201 SCTP_INP_WUNLOCK(inp);
5203 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5204 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5205 SCTP_INP_RLOCK(inp);
5206 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5207 SCTP_TCB_LOCK(stcb);
5208 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5209 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5211 SCTP_TCB_UNLOCK(stcb);
5213 SCTP_INP_RUNLOCK(inp);
5218 case SCTP_PEER_ADDR_PARAMS:
5220 struct sctp_paddrparams *paddrp;
5221 struct sctp_nets *net;
5222 struct sockaddr *addr;
5223 #if defined(INET) && defined(INET6)
5224 struct sockaddr_in sin_store;
5227 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5228 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5230 #if defined(INET) && defined(INET6)
5231 if (paddrp->spp_address.ss_family == AF_INET6) {
5232 struct sockaddr_in6 *sin6;
5234 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5235 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5236 in6_sin6_2_sin(&sin_store, sin6);
5237 addr = (struct sockaddr *)&sin_store;
5239 addr = (struct sockaddr *)&paddrp->spp_address;
5242 addr = (struct sockaddr *)&paddrp->spp_address;
5245 addr = (struct sockaddr *)&paddrp->spp_address;
5248 net = sctp_findnet(stcb, addr);
5251 * We increment here since
5252 * sctp_findassociation_ep_addr() wil do a
5253 * decrement if it finds the stcb as long as
5254 * the locked tcb (last argument) is NOT a
5258 SCTP_INP_INCR_REF(inp);
5259 stcb = sctp_findassociation_ep_addr(&inp, addr,
5262 SCTP_INP_DECR_REF(inp);
5265 if ((stcb != NULL) && (net == NULL)) {
5267 if (addr->sa_family == AF_INET) {
5269 struct sockaddr_in *sin;
5271 sin = (struct sockaddr_in *)addr;
5272 if (sin->sin_addr.s_addr != INADDR_ANY) {
5273 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5274 SCTP_TCB_UNLOCK(stcb);
5281 if (addr->sa_family == AF_INET6) {
5282 struct sockaddr_in6 *sin6;
5284 sin6 = (struct sockaddr_in6 *)addr;
5285 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5286 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5287 SCTP_TCB_UNLOCK(stcb);
5294 error = EAFNOSUPPORT;
5295 SCTP_TCB_UNLOCK(stcb);
5296 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5301 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5303 SCTP_TCB_UNLOCK(stcb);
5304 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5308 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5310 SCTP_TCB_UNLOCK(stcb);
5311 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5316 /************************TCB SPECIFIC SET ******************/
5318 /************************NET SPECIFIC SET ******************/
5319 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5320 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5321 !(net->dest_state & SCTP_ADDR_NOHB)) {
5322 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5323 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5325 net->dest_state |= SCTP_ADDR_NOHB;
5327 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5328 if (paddrp->spp_hbinterval) {
5329 net->heart_beat_delay = paddrp->spp_hbinterval;
5330 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5331 net->heart_beat_delay = 0;
5333 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5334 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5335 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5336 net->dest_state &= ~SCTP_ADDR_NOHB;
5338 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5340 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5341 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5342 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5344 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5345 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5346 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5347 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5349 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5350 net->mtu = paddrp->spp_pathmtu;
5351 switch (net->ro._l_addr.sa.sa_family) {
5354 net->mtu += SCTP_MIN_V4_OVERHEAD;
5359 net->mtu += SCTP_MIN_OVERHEAD;
5365 if (net->mtu < stcb->asoc.smallest_mtu) {
5366 sctp_pathmtu_adjustment(stcb, net->mtu);
5369 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5370 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5371 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5373 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5375 if (paddrp->spp_pathmaxrxt) {
5376 if (net->dest_state & SCTP_ADDR_PF) {
5377 if (net->error_count > paddrp->spp_pathmaxrxt) {
5378 net->dest_state &= ~SCTP_ADDR_PF;
5381 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5382 (net->error_count > net->pf_threshold)) {
5383 net->dest_state |= SCTP_ADDR_PF;
5384 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5385 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5386 stcb->sctp_ep, stcb, net,
5387 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5388 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5391 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5392 if (net->error_count > paddrp->spp_pathmaxrxt) {
5393 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5394 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5397 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5398 net->dest_state |= SCTP_ADDR_REACHABLE;
5399 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5402 net->failure_threshold = paddrp->spp_pathmaxrxt;
5404 if (paddrp->spp_flags & SPP_DSCP) {
5405 net->dscp = paddrp->spp_dscp & 0xfc;
5409 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5410 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5411 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5412 net->flowlabel |= 0x80000000;
5417 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5418 if (paddrp->spp_pathmaxrxt != 0) {
5419 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5420 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5421 if (net->dest_state & SCTP_ADDR_PF) {
5422 if (net->error_count > paddrp->spp_pathmaxrxt) {
5423 net->dest_state &= ~SCTP_ADDR_PF;
5426 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5427 (net->error_count > net->pf_threshold)) {
5428 net->dest_state |= SCTP_ADDR_PF;
5429 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5430 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5431 stcb->sctp_ep, stcb, net,
5432 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5433 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5436 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5437 if (net->error_count > paddrp->spp_pathmaxrxt) {
5438 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5439 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5442 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5443 net->dest_state |= SCTP_ADDR_REACHABLE;
5444 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5447 net->failure_threshold = paddrp->spp_pathmaxrxt;
5451 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5452 if (paddrp->spp_hbinterval != 0) {
5453 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5454 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5455 stcb->asoc.heart_beat_delay = 0;
5457 /* Turn back on the timer */
5458 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5459 if (paddrp->spp_hbinterval != 0) {
5460 net->heart_beat_delay = paddrp->spp_hbinterval;
5461 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5462 net->heart_beat_delay = 0;
5464 if (net->dest_state & SCTP_ADDR_NOHB) {
5465 net->dest_state &= ~SCTP_ADDR_NOHB;
5467 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5468 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5469 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5471 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5473 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5474 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5475 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5476 net->dest_state |= SCTP_ADDR_NOHB;
5477 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5478 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5480 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5484 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5486 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5487 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5488 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5489 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5490 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5492 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5493 net->mtu = paddrp->spp_pathmtu;
5494 switch (net->ro._l_addr.sa.sa_family) {
5497 net->mtu += SCTP_MIN_V4_OVERHEAD;
5502 net->mtu += SCTP_MIN_OVERHEAD;
5508 if (net->mtu < stcb->asoc.smallest_mtu) {
5509 sctp_pathmtu_adjustment(stcb, net->mtu);
5512 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5513 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5515 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5516 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5517 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5518 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5520 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5522 stcb->asoc.default_mtu = 0;
5523 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5525 if (paddrp->spp_flags & SPP_DSCP) {
5526 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5527 net->dscp = paddrp->spp_dscp & 0xfc;
5530 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5531 stcb->asoc.default_dscp |= 0x01;
5534 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5535 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5536 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5537 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5538 net->flowlabel |= 0x80000000;
5541 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5542 stcb->asoc.default_flowlabel |= 0x80000000;
5546 SCTP_TCB_UNLOCK(stcb);
5548 /************************NO TCB, SET TO default stuff ******************/
5549 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5550 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5551 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5552 SCTP_INP_WLOCK(inp);
5554 * For the TOS/FLOWLABEL stuff you
5555 * set it with the options on the
5558 if (paddrp->spp_pathmaxrxt != 0) {
5559 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5562 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5563 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5564 else if (paddrp->spp_hbinterval != 0) {
5565 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5566 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5567 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5570 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5571 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5572 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5573 } else if (paddrp->spp_hbinterval) {
5574 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5576 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5577 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5578 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5580 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5581 inp->sctp_ep.default_mtu = 0;
5582 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5583 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5584 if (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU) {
5585 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5587 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5589 if (paddrp->spp_flags & SPP_DSCP) {
5590 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5591 inp->sctp_ep.default_dscp |= 0x01;
5594 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5595 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5596 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5597 inp->sctp_ep.default_flowlabel |= 0x80000000;
5601 SCTP_INP_WUNLOCK(inp);
5603 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5611 struct sctp_rtoinfo *srto;
5612 uint32_t new_init, new_min, new_max;
5614 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5615 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5618 if (srto->srto_initial)
5619 new_init = srto->srto_initial;
5621 new_init = stcb->asoc.initial_rto;
5623 new_max = srto->srto_max;
5625 new_max = stcb->asoc.maxrto;
5627 new_min = srto->srto_min;
5629 new_min = stcb->asoc.minrto;
5630 if ((new_min <= new_init) && (new_init <= new_max)) {
5631 stcb->asoc.initial_rto = new_init;
5632 stcb->asoc.maxrto = new_max;
5633 stcb->asoc.minrto = new_min;
5635 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5638 SCTP_TCB_UNLOCK(stcb);
5640 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5641 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5642 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5643 SCTP_INP_WLOCK(inp);
5644 if (srto->srto_initial)
5645 new_init = srto->srto_initial;
5647 new_init = inp->sctp_ep.initial_rto;
5649 new_max = srto->srto_max;
5651 new_max = inp->sctp_ep.sctp_maxrto;
5653 new_min = srto->srto_min;
5655 new_min = inp->sctp_ep.sctp_minrto;
5656 if ((new_min <= new_init) && (new_init <= new_max)) {
5657 inp->sctp_ep.initial_rto = new_init;
5658 inp->sctp_ep.sctp_maxrto = new_max;
5659 inp->sctp_ep.sctp_minrto = new_min;
5661 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5664 SCTP_INP_WUNLOCK(inp);
5666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5672 case SCTP_ASSOCINFO:
5674 struct sctp_assocparams *sasoc;
5676 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5677 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5678 if (sasoc->sasoc_cookie_life) {
5679 /* boundary check the cookie life */
5680 if (sasoc->sasoc_cookie_life < 1000)
5681 sasoc->sasoc_cookie_life = 1000;
5682 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5683 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5687 if (sasoc->sasoc_asocmaxrxt)
5688 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5689 if (sasoc->sasoc_cookie_life) {
5690 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5692 SCTP_TCB_UNLOCK(stcb);
5694 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5695 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5696 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5697 SCTP_INP_WLOCK(inp);
5698 if (sasoc->sasoc_asocmaxrxt)
5699 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5700 if (sasoc->sasoc_cookie_life) {
5701 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5703 SCTP_INP_WUNLOCK(inp);
5705 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5713 struct sctp_initmsg *sinit;
5715 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5716 SCTP_INP_WLOCK(inp);
5717 if (sinit->sinit_num_ostreams)
5718 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5720 if (sinit->sinit_max_instreams)
5721 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5723 if (sinit->sinit_max_attempts)
5724 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5726 if (sinit->sinit_max_init_timeo)
5727 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5728 SCTP_INP_WUNLOCK(inp);
5731 case SCTP_PRIMARY_ADDR:
5733 struct sctp_setprim *spa;
5734 struct sctp_nets *net;
5735 struct sockaddr *addr;
5736 #if defined(INET) && defined(INET6)
5737 struct sockaddr_in sin_store;
5740 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5741 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5743 #if defined(INET) && defined(INET6)
5744 if (spa->ssp_addr.ss_family == AF_INET6) {
5745 struct sockaddr_in6 *sin6;
5747 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5748 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5749 in6_sin6_2_sin(&sin_store, sin6);
5750 addr = (struct sockaddr *)&sin_store;
5752 addr = (struct sockaddr *)&spa->ssp_addr;
5755 addr = (struct sockaddr *)&spa->ssp_addr;
5758 addr = (struct sockaddr *)&spa->ssp_addr;
5761 net = sctp_findnet(stcb, addr);
5764 * We increment here since
5765 * sctp_findassociation_ep_addr() wil do a
5766 * decrement if it finds the stcb as long as
5767 * the locked tcb (last argument) is NOT a
5771 SCTP_INP_INCR_REF(inp);
5772 stcb = sctp_findassociation_ep_addr(&inp, addr,
5775 SCTP_INP_DECR_REF(inp);
5779 if ((stcb != NULL) && (net != NULL)) {
5780 if (net != stcb->asoc.primary_destination) {
5781 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5782 /* Ok we need to set it */
5783 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5784 if ((stcb->asoc.alternate) &&
5785 (!(net->dest_state & SCTP_ADDR_PF)) &&
5786 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5787 sctp_free_remote_addr(stcb->asoc.alternate);
5788 stcb->asoc.alternate = NULL;
5791 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5804 SCTP_TCB_UNLOCK(stcb);
5808 case SCTP_SET_DYNAMIC_PRIMARY:
5810 union sctp_sockstore *ss;
5812 error = priv_check(curthread,
5813 PRIV_NETINET_RESERVEDPORT);
5817 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5818 /* SUPER USER CHECK? */
5819 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5822 case SCTP_SET_PEER_PRIMARY_ADDR:
5824 struct sctp_setpeerprim *sspp;
5825 struct sockaddr *addr;
5826 #if defined(INET) && defined(INET6)
5827 struct sockaddr_in sin_store;
5830 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5831 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5833 struct sctp_ifa *ifa;
5835 #if defined(INET) && defined(INET6)
5836 if (sspp->sspp_addr.ss_family == AF_INET6) {
5837 struct sockaddr_in6 *sin6;
5839 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5840 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5841 in6_sin6_2_sin(&sin_store, sin6);
5842 addr = (struct sockaddr *)&sin_store;
5844 addr = (struct sockaddr *)&sspp->sspp_addr;
5847 addr = (struct sockaddr *)&sspp->sspp_addr;
5850 addr = (struct sockaddr *)&sspp->sspp_addr;
5852 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5858 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5860 * Must validate the ifa found is in
5863 struct sctp_laddr *laddr;
5866 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5867 if (laddr->ifa == NULL) {
5868 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5872 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5873 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5876 if (laddr->ifa == ifa) {
5882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5887 switch (addr->sa_family) {
5891 struct sockaddr_in *sin;
5893 sin = (struct sockaddr_in *)addr;
5894 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5895 &sin->sin_addr) != 0) {
5896 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5906 struct sockaddr_in6 *sin6;
5908 sin6 = (struct sockaddr_in6 *)addr;
5909 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5910 &sin6->sin6_addr) != 0) {
5911 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5919 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5924 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5925 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5928 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5930 SCTP_TCB_UNLOCK(stcb);
5932 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5937 case SCTP_BINDX_ADD_ADDR:
5939 struct sctp_getaddresses *addrs;
5942 td = (struct thread *)p;
5943 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5946 if (addrs->addr->sa_family == AF_INET) {
5947 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5952 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5953 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5959 if (addrs->addr->sa_family == AF_INET6) {
5960 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5961 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5965 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5966 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5967 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5973 error = EAFNOSUPPORT;
5976 sctp_bindx_add_address(so, inp, addrs->addr,
5977 addrs->sget_assoc_id, vrf_id,
5981 case SCTP_BINDX_REM_ADDR:
5983 struct sctp_getaddresses *addrs;
5986 td = (struct thread *)p;
5988 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5990 if (addrs->addr->sa_family == AF_INET) {
5991 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5996 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5997 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6003 if (addrs->addr->sa_family == AF_INET6) {
6004 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
6005 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6010 (error = prison_local_ip6(td->td_ucred,
6011 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
6012 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6013 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6019 error = EAFNOSUPPORT;
6022 sctp_bindx_delete_address(inp, addrs->addr,
6023 addrs->sget_assoc_id, vrf_id,
6029 struct sctp_event *event;
6030 uint32_t event_type;
6032 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6033 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6034 switch (event->se_type) {
6035 case SCTP_ASSOC_CHANGE:
6036 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6038 case SCTP_PEER_ADDR_CHANGE:
6039 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6041 case SCTP_REMOTE_ERROR:
6042 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6044 case SCTP_SEND_FAILED:
6045 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6047 case SCTP_SHUTDOWN_EVENT:
6048 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6050 case SCTP_ADAPTATION_INDICATION:
6051 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6053 case SCTP_PARTIAL_DELIVERY_EVENT:
6054 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6056 case SCTP_AUTHENTICATION_EVENT:
6057 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6059 case SCTP_STREAM_RESET_EVENT:
6060 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6062 case SCTP_SENDER_DRY_EVENT:
6063 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6065 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6067 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6070 case SCTP_ASSOC_RESET_EVENT:
6071 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6073 case SCTP_STREAM_CHANGE_EVENT:
6074 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6076 case SCTP_SEND_FAILED_EVENT:
6077 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6081 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6085 if (event_type > 0) {
6088 sctp_stcb_feature_on(inp, stcb, event_type);
6089 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6090 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6091 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6092 (stcb->asoc.stream_queue_cnt == 0)) {
6093 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6097 sctp_stcb_feature_off(inp, stcb, event_type);
6099 SCTP_TCB_UNLOCK(stcb);
6102 * We don't want to send up a storm
6103 * of events, so return an error for
6106 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6107 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6108 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6109 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6110 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6111 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6115 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6116 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6117 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6118 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6119 SCTP_INP_WLOCK(inp);
6121 sctp_feature_on(inp, event_type);
6123 sctp_feature_off(inp, event_type);
6125 SCTP_INP_WUNLOCK(inp);
6127 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6128 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6129 SCTP_INP_RLOCK(inp);
6130 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6131 SCTP_TCB_LOCK(stcb);
6133 sctp_stcb_feature_on(inp, stcb, event_type);
6135 sctp_stcb_feature_off(inp, stcb, event_type);
6137 SCTP_TCB_UNLOCK(stcb);
6139 SCTP_INP_RUNLOCK(inp);
6144 SCTP_TCB_UNLOCK(stcb);
6149 case SCTP_RECVRCVINFO:
6153 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6154 SCTP_INP_WLOCK(inp);
6156 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6158 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6160 SCTP_INP_WUNLOCK(inp);
6163 case SCTP_RECVNXTINFO:
6167 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6168 SCTP_INP_WLOCK(inp);
6170 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6172 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6174 SCTP_INP_WUNLOCK(inp);
6177 case SCTP_DEFAULT_SNDINFO:
6179 struct sctp_sndinfo *info;
6182 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6183 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6186 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6187 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6188 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6189 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6190 stcb->asoc.def_send.sinfo_flags |= policy;
6191 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6192 stcb->asoc.def_send.sinfo_context = info->snd_context;
6194 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6197 SCTP_TCB_UNLOCK(stcb);
6199 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6200 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6201 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6202 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6203 SCTP_INP_WLOCK(inp);
6204 inp->def_send.sinfo_stream = info->snd_sid;
6205 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6206 inp->def_send.sinfo_flags = info->snd_flags;
6207 inp->def_send.sinfo_flags |= policy;
6208 inp->def_send.sinfo_ppid = info->snd_ppid;
6209 inp->def_send.sinfo_context = info->snd_context;
6210 SCTP_INP_WUNLOCK(inp);
6212 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6213 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6214 SCTP_INP_RLOCK(inp);
6215 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6216 SCTP_TCB_LOCK(stcb);
6217 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6218 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6219 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6220 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6221 stcb->asoc.def_send.sinfo_flags |= policy;
6222 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6223 stcb->asoc.def_send.sinfo_context = info->snd_context;
6225 SCTP_TCB_UNLOCK(stcb);
6227 SCTP_INP_RUNLOCK(inp);
6232 case SCTP_DEFAULT_PRINFO:
6234 struct sctp_default_prinfo *info;
6236 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6237 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6239 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6241 SCTP_TCB_UNLOCK(stcb);
6243 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6248 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6249 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6250 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6251 SCTP_TCB_UNLOCK(stcb);
6253 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6254 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6255 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6256 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6257 SCTP_INP_WLOCK(inp);
6258 inp->def_send.sinfo_flags &= 0xfff0;
6259 inp->def_send.sinfo_flags |= info->pr_policy;
6260 inp->def_send.sinfo_timetolive = info->pr_value;
6261 SCTP_INP_WUNLOCK(inp);
6263 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6264 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6265 SCTP_INP_RLOCK(inp);
6266 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6267 SCTP_TCB_LOCK(stcb);
6268 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6269 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6270 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6271 SCTP_TCB_UNLOCK(stcb);
6273 SCTP_INP_RUNLOCK(inp);
6278 case SCTP_PEER_ADDR_THLDS:
6279 /* Applies to the specific association */
6281 struct sctp_paddrthlds *thlds;
6282 struct sctp_nets *net;
6283 struct sockaddr *addr;
6284 #if defined(INET) && defined(INET6)
6285 struct sockaddr_in sin_store;
6288 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6289 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6291 #if defined(INET) && defined(INET6)
6292 if (thlds->spt_address.ss_family == AF_INET6) {
6293 struct sockaddr_in6 *sin6;
6295 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6296 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6297 in6_sin6_2_sin(&sin_store, sin6);
6298 addr = (struct sockaddr *)&sin_store;
6300 addr = (struct sockaddr *)&thlds->spt_address;
6303 addr = (struct sockaddr *)&thlds->spt_address;
6306 addr = (struct sockaddr *)&thlds->spt_address;
6309 net = sctp_findnet(stcb, addr);
6312 * We increment here since
6313 * sctp_findassociation_ep_addr() wil do a
6314 * decrement if it finds the stcb as long as
6315 * the locked tcb (last argument) is NOT a
6319 SCTP_INP_INCR_REF(inp);
6320 stcb = sctp_findassociation_ep_addr(&inp, addr,
6323 SCTP_INP_DECR_REF(inp);
6326 if ((stcb != NULL) && (net == NULL)) {
6328 if (addr->sa_family == AF_INET) {
6330 struct sockaddr_in *sin;
6332 sin = (struct sockaddr_in *)addr;
6333 if (sin->sin_addr.s_addr != INADDR_ANY) {
6334 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6335 SCTP_TCB_UNLOCK(stcb);
6342 if (addr->sa_family == AF_INET6) {
6343 struct sockaddr_in6 *sin6;
6345 sin6 = (struct sockaddr_in6 *)addr;
6346 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6347 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6348 SCTP_TCB_UNLOCK(stcb);
6355 error = EAFNOSUPPORT;
6356 SCTP_TCB_UNLOCK(stcb);
6357 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6361 if (thlds->spt_pathcpthld != 0xffff) {
6363 SCTP_TCB_UNLOCK(stcb);
6366 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6371 net->failure_threshold = thlds->spt_pathmaxrxt;
6372 net->pf_threshold = thlds->spt_pathpfthld;
6373 if (net->dest_state & SCTP_ADDR_PF) {
6374 if ((net->error_count > net->failure_threshold) ||
6375 (net->error_count <= net->pf_threshold)) {
6376 net->dest_state &= ~SCTP_ADDR_PF;
6379 if ((net->error_count > net->pf_threshold) &&
6380 (net->error_count <= net->failure_threshold)) {
6381 net->dest_state |= SCTP_ADDR_PF;
6382 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6383 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6384 stcb->sctp_ep, stcb, net,
6385 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6386 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6389 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6390 if (net->error_count > net->failure_threshold) {
6391 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6392 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6395 if (net->error_count <= net->failure_threshold) {
6396 net->dest_state |= SCTP_ADDR_REACHABLE;
6397 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6401 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6402 net->failure_threshold = thlds->spt_pathmaxrxt;
6403 net->pf_threshold = thlds->spt_pathpfthld;
6404 if (net->dest_state & SCTP_ADDR_PF) {
6405 if ((net->error_count > net->failure_threshold) ||
6406 (net->error_count <= net->pf_threshold)) {
6407 net->dest_state &= ~SCTP_ADDR_PF;
6410 if ((net->error_count > net->pf_threshold) &&
6411 (net->error_count <= net->failure_threshold)) {
6412 net->dest_state |= SCTP_ADDR_PF;
6413 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6414 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6415 stcb->sctp_ep, stcb, net,
6416 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6417 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6420 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6421 if (net->error_count > net->failure_threshold) {
6422 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6423 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6426 if (net->error_count <= net->failure_threshold) {
6427 net->dest_state |= SCTP_ADDR_REACHABLE;
6428 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6432 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6433 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6435 SCTP_TCB_UNLOCK(stcb);
6437 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6438 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6439 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6440 SCTP_INP_WLOCK(inp);
6441 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6442 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6443 SCTP_INP_WUNLOCK(inp);
6445 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6451 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6453 struct sctp_udpencaps *encaps;
6454 struct sctp_nets *net;
6455 struct sockaddr *addr;
6456 #if defined(INET) && defined(INET6)
6457 struct sockaddr_in sin_store;
6460 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6461 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6463 #if defined(INET) && defined(INET6)
6464 if (encaps->sue_address.ss_family == AF_INET6) {
6465 struct sockaddr_in6 *sin6;
6467 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6468 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6469 in6_sin6_2_sin(&sin_store, sin6);
6470 addr = (struct sockaddr *)&sin_store;
6472 addr = (struct sockaddr *)&encaps->sue_address;
6475 addr = (struct sockaddr *)&encaps->sue_address;
6478 addr = (struct sockaddr *)&encaps->sue_address;
6481 net = sctp_findnet(stcb, addr);
6484 * We increment here since
6485 * sctp_findassociation_ep_addr() wil do a
6486 * decrement if it finds the stcb as long as
6487 * the locked tcb (last argument) is NOT a
6491 SCTP_INP_INCR_REF(inp);
6492 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6494 SCTP_INP_DECR_REF(inp);
6497 if ((stcb != NULL) && (net == NULL)) {
6499 if (addr->sa_family == AF_INET) {
6501 struct sockaddr_in *sin;
6503 sin = (struct sockaddr_in *)addr;
6504 if (sin->sin_addr.s_addr != INADDR_ANY) {
6505 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6506 SCTP_TCB_UNLOCK(stcb);
6513 if (addr->sa_family == AF_INET6) {
6514 struct sockaddr_in6 *sin6;
6516 sin6 = (struct sockaddr_in6 *)addr;
6517 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6518 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6519 SCTP_TCB_UNLOCK(stcb);
6526 error = EAFNOSUPPORT;
6527 SCTP_TCB_UNLOCK(stcb);
6528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6535 net->port = encaps->sue_port;
6537 stcb->asoc.port = encaps->sue_port;
6539 SCTP_TCB_UNLOCK(stcb);
6541 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6542 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6543 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6544 SCTP_INP_WLOCK(inp);
6545 inp->sctp_ep.port = encaps->sue_port;
6546 SCTP_INP_WUNLOCK(inp);
6548 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6554 case SCTP_ECN_SUPPORTED:
6556 struct sctp_assoc_value *av;
6558 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6559 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6562 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6564 SCTP_TCB_UNLOCK(stcb);
6566 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6567 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6568 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6569 SCTP_INP_WLOCK(inp);
6570 if (av->assoc_value == 0) {
6571 inp->ecn_supported = 0;
6573 inp->ecn_supported = 1;
6575 SCTP_INP_WUNLOCK(inp);
6577 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6583 case SCTP_PR_SUPPORTED:
6585 struct sctp_assoc_value *av;
6587 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6588 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6591 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6593 SCTP_TCB_UNLOCK(stcb);
6595 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6596 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6597 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6598 SCTP_INP_WLOCK(inp);
6599 if (av->assoc_value == 0) {
6600 inp->prsctp_supported = 0;
6602 inp->prsctp_supported = 1;
6604 SCTP_INP_WUNLOCK(inp);
6606 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6612 case SCTP_AUTH_SUPPORTED:
6614 struct sctp_assoc_value *av;
6616 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6617 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6620 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6622 SCTP_TCB_UNLOCK(stcb);
6624 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6625 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6626 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6627 if ((av->assoc_value == 0) &&
6628 (inp->asconf_supported == 1)) {
6630 * AUTH is required for
6633 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6636 SCTP_INP_WLOCK(inp);
6637 if (av->assoc_value == 0) {
6638 inp->auth_supported = 0;
6640 inp->auth_supported = 1;
6642 SCTP_INP_WUNLOCK(inp);
6645 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6651 case SCTP_ASCONF_SUPPORTED:
6653 struct sctp_assoc_value *av;
6655 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6656 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6659 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6661 SCTP_TCB_UNLOCK(stcb);
6663 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6664 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6665 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6666 if ((av->assoc_value != 0) &&
6667 (inp->auth_supported == 0)) {
6669 * AUTH is required for
6672 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6675 SCTP_INP_WLOCK(inp);
6676 if (av->assoc_value == 0) {
6677 inp->asconf_supported = 0;
6678 sctp_auth_delete_chunk(SCTP_ASCONF,
6679 inp->sctp_ep.local_auth_chunks);
6680 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6681 inp->sctp_ep.local_auth_chunks);
6683 inp->asconf_supported = 1;
6684 sctp_auth_add_chunk(SCTP_ASCONF,
6685 inp->sctp_ep.local_auth_chunks);
6686 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6687 inp->sctp_ep.local_auth_chunks);
6689 SCTP_INP_WUNLOCK(inp);
6692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6698 case SCTP_RECONFIG_SUPPORTED:
6700 struct sctp_assoc_value *av;
6702 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6703 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6706 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6708 SCTP_TCB_UNLOCK(stcb);
6710 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6711 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6712 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6713 SCTP_INP_WLOCK(inp);
6714 if (av->assoc_value == 0) {
6715 inp->reconfig_supported = 0;
6717 inp->reconfig_supported = 1;
6719 SCTP_INP_WUNLOCK(inp);
6721 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6727 case SCTP_NRSACK_SUPPORTED:
6729 struct sctp_assoc_value *av;
6731 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6732 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6735 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6737 SCTP_TCB_UNLOCK(stcb);
6739 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6740 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6741 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6742 SCTP_INP_WLOCK(inp);
6743 if (av->assoc_value == 0) {
6744 inp->nrsack_supported = 0;
6746 inp->nrsack_supported = 1;
6748 SCTP_INP_WUNLOCK(inp);
6750 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6756 case SCTP_PKTDROP_SUPPORTED:
6758 struct sctp_assoc_value *av;
6760 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6761 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6764 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6766 SCTP_TCB_UNLOCK(stcb);
6768 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6769 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6770 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6771 SCTP_INP_WLOCK(inp);
6772 if (av->assoc_value == 0) {
6773 inp->pktdrop_supported = 0;
6775 inp->pktdrop_supported = 1;
6777 SCTP_INP_WUNLOCK(inp);
6779 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6787 struct sctp_assoc_value *av;
6788 struct sctp_nets *net;
6790 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6791 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6794 stcb->asoc.max_cwnd = av->assoc_value;
6795 if (stcb->asoc.max_cwnd > 0) {
6796 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6797 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6798 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6799 net->cwnd = stcb->asoc.max_cwnd;
6800 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6801 net->cwnd = net->mtu - sizeof(struct sctphdr);
6806 SCTP_TCB_UNLOCK(stcb);
6808 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6809 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6810 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6811 SCTP_INP_WLOCK(inp);
6812 inp->max_cwnd = av->assoc_value;
6813 SCTP_INP_WUNLOCK(inp);
6815 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6822 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6823 error = ENOPROTOOPT;
6825 } /* end switch (opt) */
6830 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6832 void *optval = NULL;
6836 struct sctp_inpcb *inp;
6838 if ((sopt->sopt_level == SOL_SOCKET) &&
6839 (sopt->sopt_name == SO_SETFIB)) {
6840 inp = (struct sctp_inpcb *)so->so_pcb;
6842 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6845 SCTP_INP_WLOCK(inp);
6846 inp->fibnum = so->so_fibnum;
6847 SCTP_INP_WUNLOCK(inp);
6850 if (sopt->sopt_level != IPPROTO_SCTP) {
6851 /* wrong proto level... send back up to IP */
6853 if (INP_CHECK_SOCKAF(so, AF_INET6))
6854 error = ip6_ctloutput(so, sopt);
6856 #if defined(INET) && defined(INET6)
6860 error = ip_ctloutput(so, sopt);
6864 optsize = sopt->sopt_valsize;
6865 if (optsize > SCTP_SOCKET_OPTION_LIMIT) {
6866 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6870 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6871 if (optval == NULL) {
6872 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6875 error = sooptcopyin(sopt, optval, optsize, optsize);
6877 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6881 p = (void *)sopt->sopt_td;
6882 if (sopt->sopt_dir == SOPT_SET) {
6883 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6884 } else if (sopt->sopt_dir == SOPT_GET) {
6885 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6887 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6890 if ((error == 0) && (optval != NULL)) {
6891 error = sooptcopyout(sopt, optval, optsize);
6892 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6893 } else if (optval != NULL) {
6894 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6902 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6905 int create_lock_on = 0;
6907 struct sctp_inpcb *inp;
6908 struct sctp_tcb *stcb = NULL;
6910 inp = (struct sctp_inpcb *)so->so_pcb;
6912 /* I made the same as TCP since we are not setup? */
6913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6914 return (ECONNRESET);
6917 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6921 switch (addr->sa_family) {
6925 struct sockaddr_in6 *sin6p;
6927 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6928 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6931 sin6p = (struct sockaddr_in6 *)addr;
6932 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6933 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6942 struct sockaddr_in *sinp;
6944 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6945 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6948 sinp = (struct sockaddr_in *)addr;
6949 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6958 return (EAFNOSUPPORT);
6960 SCTP_INP_INCR_REF(inp);
6961 SCTP_ASOC_CREATE_LOCK(inp);
6965 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6966 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6967 /* Should I really unlock ? */
6968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6973 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6974 (addr->sa_family == AF_INET6)) {
6975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6980 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6981 SCTP_PCB_FLAGS_UNBOUND) {
6982 /* Bind a ephemeral port */
6983 error = sctp_inpcb_bind(so, NULL, NULL, p);
6988 /* Now do we connect? */
6989 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6990 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6991 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6995 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6996 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6997 /* We are already connected AND the TCP model */
6998 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7002 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7003 SCTP_INP_RLOCK(inp);
7004 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7005 SCTP_INP_RUNLOCK(inp);
7008 * We increment here since sctp_findassociation_ep_addr()
7009 * will do a decrement if it finds the stcb as long as the
7010 * locked tcb (last argument) is NOT a TCB.. aka NULL.
7012 SCTP_INP_INCR_REF(inp);
7013 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7015 SCTP_INP_DECR_REF(inp);
7017 SCTP_TCB_UNLOCK(stcb);
7021 /* Already have or am bring up an association */
7022 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7027 vrf_id = inp->def_vrf_id;
7028 /* We are GOOD to go */
7029 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
7030 inp->sctp_ep.pre_open_stream_count,
7031 inp->sctp_ep.port, p);
7033 /* Gak! no memory */
7036 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7037 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7038 /* Set the connected flag so we can queue data */
7041 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7042 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7044 /* initialize authentication parameters for the assoc */
7045 sctp_initialize_auth_params(inp, stcb);
7047 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7048 SCTP_TCB_UNLOCK(stcb);
7050 if (create_lock_on) {
7051 SCTP_ASOC_CREATE_UNLOCK(inp);
7054 SCTP_INP_DECR_REF(inp);
7060 sctp_listen(struct socket *so, int backlog, struct thread *p)
7063 * Note this module depends on the protocol processing being called
7064 * AFTER any socket level flags and backlog are applied to the
7065 * socket. The traditional way that the socket flags are applied is
7066 * AFTER protocol processing. We have made a change to the
7067 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7068 * place if the socket API for SCTP is to work properly.
7072 struct sctp_inpcb *inp;
7074 inp = (struct sctp_inpcb *)so->so_pcb;
7076 /* I made the same as TCP since we are not setup? */
7077 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7078 return (ECONNRESET);
7080 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7081 /* See if we have a listener */
7082 struct sctp_inpcb *tinp;
7083 union sctp_sockstore store;
7085 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7087 struct sctp_laddr *laddr;
7089 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7090 memcpy(&store, &laddr->ifa->address, sizeof(store));
7091 switch (store.sa.sa_family) {
7094 store.sin.sin_port = inp->sctp_lport;
7099 store.sin6.sin6_port = inp->sctp_lport;
7105 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7106 if (tinp && (tinp != inp) &&
7107 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7108 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7109 (SCTP_IS_LISTENING(tinp))) {
7111 * we have a listener already and
7114 SCTP_INP_DECR_REF(tinp);
7115 return (EADDRINUSE);
7117 SCTP_INP_DECR_REF(tinp);
7121 /* Setup a local addr bound all */
7122 memset(&store, 0, sizeof(store));
7124 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7125 store.sa.sa_family = AF_INET6;
7126 store.sa.sa_len = sizeof(struct sockaddr_in6);
7130 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7131 store.sa.sa_family = AF_INET;
7132 store.sa.sa_len = sizeof(struct sockaddr_in);
7135 switch (store.sa.sa_family) {
7138 store.sin.sin_port = inp->sctp_lport;
7143 store.sin6.sin6_port = inp->sctp_lport;
7149 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7150 if (tinp && (tinp != inp) &&
7151 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7152 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7153 (SCTP_IS_LISTENING(tinp))) {
7155 * we have a listener already and its not
7158 SCTP_INP_DECR_REF(tinp);
7159 return (EADDRINUSE);
7161 SCTP_INP_DECR_REF(tinp);
7165 SCTP_INP_RLOCK(inp);
7166 #ifdef SCTP_LOCK_LOGGING
7167 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7168 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7172 error = solisten_proto_check(so);
7175 SCTP_INP_RUNLOCK(inp);
7178 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7179 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7181 * The unlucky case - We are in the tcp pool with this guy.
7182 * - Someone else is in the main inp slot. - We must move
7183 * this guy (the listener) to the main slot - We must then
7184 * move the guy that was listener to the TCP Pool.
7186 if (sctp_swap_inpcb_for_listen(inp)) {
7187 SCTP_INP_RUNLOCK(inp);
7188 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7189 return (EADDRINUSE);
7193 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7194 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7195 /* We are already connected AND the TCP model */
7196 SCTP_INP_RUNLOCK(inp);
7197 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7198 return (EADDRINUSE);
7200 SCTP_INP_RUNLOCK(inp);
7201 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7202 /* We must do a bind. */
7203 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7204 /* bind error, probably perm */
7208 SCTP_INP_WLOCK(inp);
7209 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7211 solisten_proto(so, backlog);
7215 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7217 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7219 SCTP_INP_WUNLOCK(inp);
7223 static int sctp_defered_wakeup_cnt = 0;
7226 sctp_accept(struct socket *so, struct sockaddr **addr)
7228 struct sctp_tcb *stcb;
7229 struct sctp_inpcb *inp;
7230 union sctp_sockstore store;
7234 inp = (struct sctp_inpcb *)so->so_pcb;
7237 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7238 return (ECONNRESET);
7240 SCTP_INP_RLOCK(inp);
7241 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7242 SCTP_INP_RUNLOCK(inp);
7243 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7244 return (EOPNOTSUPP);
7246 if (so->so_state & SS_ISDISCONNECTED) {
7247 SCTP_INP_RUNLOCK(inp);
7248 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7249 return (ECONNABORTED);
7251 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7253 SCTP_INP_RUNLOCK(inp);
7254 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7255 return (ECONNRESET);
7257 SCTP_TCB_LOCK(stcb);
7258 SCTP_INP_RUNLOCK(inp);
7259 store = stcb->asoc.primary_destination->ro._l_addr;
7260 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7261 SCTP_TCB_UNLOCK(stcb);
7262 switch (store.sa.sa_family) {
7266 struct sockaddr_in *sin;
7268 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7271 sin->sin_family = AF_INET;
7272 sin->sin_len = sizeof(*sin);
7273 sin->sin_port = store.sin.sin_port;
7274 sin->sin_addr = store.sin.sin_addr;
7275 *addr = (struct sockaddr *)sin;
7282 struct sockaddr_in6 *sin6;
7284 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7287 sin6->sin6_family = AF_INET6;
7288 sin6->sin6_len = sizeof(*sin6);
7289 sin6->sin6_port = store.sin6.sin6_port;
7290 sin6->sin6_addr = store.sin6.sin6_addr;
7291 if ((error = sa6_recoverscope(sin6)) != 0) {
7292 SCTP_FREE_SONAME(sin6);
7295 *addr = (struct sockaddr *)sin6;
7303 /* Wake any delayed sleep action */
7304 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7305 SCTP_INP_WLOCK(inp);
7306 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7307 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7308 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7309 SCTP_INP_WUNLOCK(inp);
7310 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7311 if (sowriteable(inp->sctp_socket)) {
7312 sowwakeup_locked(inp->sctp_socket);
7314 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7316 SCTP_INP_WLOCK(inp);
7318 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7319 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7320 SCTP_INP_WUNLOCK(inp);
7321 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7322 if (soreadable(inp->sctp_socket)) {
7323 sctp_defered_wakeup_cnt++;
7324 sorwakeup_locked(inp->sctp_socket);
7326 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7328 SCTP_INP_WLOCK(inp);
7330 SCTP_INP_WUNLOCK(inp);
7332 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7333 SCTP_TCB_LOCK(stcb);
7334 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7335 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7342 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7344 struct sockaddr_in *sin;
7346 struct sctp_inpcb *inp;
7347 struct sctp_ifa *sctp_ifa;
7350 * Do the malloc first in case it blocks.
7352 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7355 sin->sin_family = AF_INET;
7356 sin->sin_len = sizeof(*sin);
7357 inp = (struct sctp_inpcb *)so->so_pcb;
7359 SCTP_FREE_SONAME(sin);
7360 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7361 return (ECONNRESET);
7363 SCTP_INP_RLOCK(inp);
7364 sin->sin_port = inp->sctp_lport;
7365 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7366 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7367 struct sctp_tcb *stcb;
7368 struct sockaddr_in *sin_a;
7369 struct sctp_nets *net;
7372 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7378 SCTP_TCB_LOCK(stcb);
7379 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7380 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7382 /* this will make coverity happy */
7385 if (sin_a->sin_family == AF_INET) {
7390 if ((!fnd) || (sin_a == NULL)) {
7392 SCTP_TCB_UNLOCK(stcb);
7396 vrf_id = inp->def_vrf_id;
7397 sctp_ifa = sctp_source_address_selection(inp,
7399 (sctp_route_t *)&net->ro,
7402 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7403 sctp_free_ifa(sctp_ifa);
7405 SCTP_TCB_UNLOCK(stcb);
7407 /* For the bound all case you get back 0 */
7409 sin->sin_addr.s_addr = 0;
7413 /* Take the first IPv4 address in the list */
7414 struct sctp_laddr *laddr;
7417 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7418 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7419 struct sockaddr_in *sin_a;
7421 sin_a = &laddr->ifa->address.sin;
7422 sin->sin_addr = sin_a->sin_addr;
7428 SCTP_FREE_SONAME(sin);
7429 SCTP_INP_RUNLOCK(inp);
7430 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7434 SCTP_INP_RUNLOCK(inp);
7435 (*addr) = (struct sockaddr *)sin;
7440 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7442 struct sockaddr_in *sin;
7444 struct sockaddr_in *sin_a;
7445 struct sctp_inpcb *inp;
7446 struct sctp_tcb *stcb;
7447 struct sctp_nets *net;
7449 /* Do the malloc first in case it blocks. */
7450 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7453 sin->sin_family = AF_INET;
7454 sin->sin_len = sizeof(*sin);
7456 inp = (struct sctp_inpcb *)so->so_pcb;
7457 if ((inp == NULL) ||
7458 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7459 /* UDP type and listeners will drop out here */
7460 SCTP_FREE_SONAME(sin);
7461 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7464 SCTP_INP_RLOCK(inp);
7465 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7467 SCTP_TCB_LOCK(stcb);
7469 SCTP_INP_RUNLOCK(inp);
7471 SCTP_FREE_SONAME(sin);
7472 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7473 return (ECONNRESET);
7476 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7477 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7478 if (sin_a->sin_family == AF_INET) {
7480 sin->sin_port = stcb->rport;
7481 sin->sin_addr = sin_a->sin_addr;
7485 SCTP_TCB_UNLOCK(stcb);
7487 /* No IPv4 address */
7488 SCTP_FREE_SONAME(sin);
7489 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7492 (*addr) = (struct sockaddr *)sin;
7496 struct pr_usrreqs sctp_usrreqs = {
7497 .pru_abort = sctp_abort,
7498 .pru_accept = sctp_accept,
7499 .pru_attach = sctp_attach,
7500 .pru_bind = sctp_bind,
7501 .pru_connect = sctp_connect,
7502 .pru_control = in_control,
7503 .pru_close = sctp_close,
7504 .pru_detach = sctp_close,
7505 .pru_sopoll = sopoll_generic,
7506 .pru_flush = sctp_flush,
7507 .pru_disconnect = sctp_disconnect,
7508 .pru_listen = sctp_listen,
7509 .pru_peeraddr = sctp_peeraddr,
7510 .pru_send = sctp_sendm,
7511 .pru_shutdown = sctp_shutdown,
7512 .pru_sockaddr = sctp_ingetaddr,
7513 .pru_sosend = sctp_sosend,
7514 .pru_soreceive = sctp_soreceive