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_PRINTF("huh? control set?\n");
634 sctp_m_freem(inp->control);
637 inp->control = control;
641 SCTP_BUF_NEXT(inp->pkt_last) = m;
644 inp->pkt_last = inp->pkt = m;
647 /* FreeBSD uses a flag passed */
648 ((flags & PRUS_MORETOCOME) == 0)
651 * note with the current version this code will only be used
652 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
653 * re-defining sosend to use the sctp_sosend. One can
654 * optionally switch back to this code (by changing back the
655 * definitions) but this is not advisable. This code is used
656 * by FreeBSD when sending a file with sendfile() though.
660 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
670 sctp_disconnect(struct socket *so)
672 struct sctp_inpcb *inp;
674 inp = (struct sctp_inpcb *)so->so_pcb;
676 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
680 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
681 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
682 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
684 SCTP_INP_RUNLOCK(inp);
687 struct sctp_association *asoc;
688 struct sctp_tcb *stcb;
690 stcb = LIST_FIRST(&inp->sctp_asoc_list);
692 SCTP_INP_RUNLOCK(inp);
693 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
698 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
699 /* We are about to be freed, out of here */
700 SCTP_TCB_UNLOCK(stcb);
701 SCTP_INP_RUNLOCK(inp);
704 if (((so->so_options & SO_LINGER) &&
705 (so->so_linger == 0)) ||
706 (so->so_rcv.sb_cc > 0)) {
707 if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) {
708 /* Left with Data unread */
711 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
712 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
713 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
715 SCTP_INP_RUNLOCK(inp);
716 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
717 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
718 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
720 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
721 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
722 /* No unlock tcb assoc is gone */
725 if (TAILQ_EMPTY(&asoc->send_queue) &&
726 TAILQ_EMPTY(&asoc->sent_queue) &&
727 (asoc->stream_queue_cnt == 0)) {
728 /* there is nothing queued to send, so done */
729 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
732 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) &&
733 (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
734 /* only send SHUTDOWN 1st time thru */
735 struct sctp_nets *netp;
737 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
738 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
739 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
741 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
742 sctp_stop_timers_for_shutdown(stcb);
743 if (stcb->asoc.alternate) {
744 netp = stcb->asoc.alternate;
746 netp = stcb->asoc.primary_destination;
748 sctp_send_shutdown(stcb, netp);
749 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
750 stcb->sctp_ep, stcb, netp);
751 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
752 stcb->sctp_ep, stcb, netp);
753 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
757 * we still got (or just got) data to send,
758 * so set SHUTDOWN_PENDING
761 * XXX sockets draft says that SCTP_EOF
762 * should be sent with no data. currently,
763 * we will allow user data to be sent first
764 * and move to SHUTDOWN-PENDING
766 struct sctp_nets *netp;
768 if (stcb->asoc.alternate) {
769 netp = stcb->asoc.alternate;
771 netp = stcb->asoc.primary_destination;
774 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
775 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
777 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
778 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
780 if (TAILQ_EMPTY(&asoc->send_queue) &&
781 TAILQ_EMPTY(&asoc->sent_queue) &&
782 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
786 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
787 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
788 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
789 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
790 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
791 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
792 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
794 SCTP_INP_RUNLOCK(inp);
795 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
796 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
799 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
802 soisdisconnecting(so);
803 SCTP_TCB_UNLOCK(stcb);
804 SCTP_INP_RUNLOCK(inp);
809 /* UDP model does not support this */
810 SCTP_INP_RUNLOCK(inp);
811 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
817 sctp_flush(struct socket *so, int how)
820 * We will just clear out the values and let subsequent close clear
821 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
822 * they will not be able to read the data, the socket will block
823 * that from happening.
825 struct sctp_inpcb *inp;
827 inp = (struct sctp_inpcb *)so->so_pcb;
829 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
833 /* For the 1 to many model this does nothing */
834 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
835 SCTP_INP_RUNLOCK(inp);
838 SCTP_INP_RUNLOCK(inp);
839 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
841 * First make sure the sb will be happy, we don't use these
842 * except maybe the count
845 SCTP_INP_READ_LOCK(inp);
846 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
847 SCTP_INP_READ_UNLOCK(inp);
848 SCTP_INP_WUNLOCK(inp);
849 so->so_rcv.sb_cc = 0;
850 so->so_rcv.sb_mbcnt = 0;
851 so->so_rcv.sb_mb = NULL;
853 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
855 * First make sure the sb will be happy, we don't use these
856 * except maybe the count
858 so->so_snd.sb_cc = 0;
859 so->so_snd.sb_mbcnt = 0;
860 so->so_snd.sb_mb = NULL;
867 sctp_shutdown(struct socket *so)
869 struct sctp_inpcb *inp;
871 inp = (struct sctp_inpcb *)so->so_pcb;
873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
877 /* For UDP model this is a invalid call */
878 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
879 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
880 /* Restore the flags that the soshutdown took away. */
881 SOCKBUF_LOCK(&so->so_rcv);
882 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
883 SOCKBUF_UNLOCK(&so->so_rcv);
884 /* This proc will wakeup for read and do nothing (I hope) */
885 SCTP_INP_RUNLOCK(inp);
886 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
890 * Ok, if we reach here its the TCP model and it is either a
891 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
894 struct sctp_tcb *stcb;
895 struct sctp_association *asoc;
896 struct sctp_nets *netp;
899 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
900 SCTP_INP_RUNLOCK(inp);
905 stcb = LIST_FIRST(&inp->sctp_asoc_list);
908 * Ok, we hit the case that the shutdown call was
909 * made after an abort or something. Nothing to do
912 SCTP_INP_RUNLOCK(inp);
917 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
918 SCTP_TCB_UNLOCK(stcb);
919 SCTP_INP_RUNLOCK(inp);
922 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) &&
923 (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) &&
924 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) {
926 * If we are not in or before ESTABLISHED, there is
927 * no protocol action required.
929 SCTP_TCB_UNLOCK(stcb);
930 SCTP_INP_RUNLOCK(inp);
933 if (stcb->asoc.alternate) {
934 netp = stcb->asoc.alternate;
936 netp = stcb->asoc.primary_destination;
938 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) &&
939 TAILQ_EMPTY(&asoc->send_queue) &&
940 TAILQ_EMPTY(&asoc->sent_queue) &&
941 (asoc->stream_queue_cnt == 0)) {
942 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
945 /* there is nothing queued to send, so I'm done... */
946 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
947 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
948 sctp_stop_timers_for_shutdown(stcb);
949 sctp_send_shutdown(stcb, netp);
950 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
951 stcb->sctp_ep, stcb, netp);
954 * We still got (or just got) data to send, so set
957 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
958 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
959 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
961 if (TAILQ_EMPTY(&asoc->send_queue) &&
962 TAILQ_EMPTY(&asoc->sent_queue) &&
963 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
967 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
968 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
969 sctp_abort_an_association(stcb->sctp_ep, stcb,
970 op_err, SCTP_SO_LOCKED);
971 SCTP_INP_RUNLOCK(inp);
975 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp);
977 * XXX: Why do this in the case where we have still data
980 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
981 SCTP_TCB_UNLOCK(stcb);
982 SCTP_INP_RUNLOCK(inp);
988 * copies a "user" presentable address and removes embedded scope, etc.
989 * returns 0 on success, 1 on error
992 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
995 struct sockaddr_in6 lsa6;
997 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1000 memcpy(ss, sa, sa->sa_len);
1007 * NOTE: assumes addr lock is held
1010 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1011 struct sctp_tcb *stcb,
1013 struct sockaddr_storage *sas,
1016 struct sctp_ifn *sctp_ifn;
1017 struct sctp_ifa *sctp_ifa;
1021 int ipv4_local_scope, ipv4_addr_legal;
1024 int local_scope, site_scope, ipv6_addr_legal;
1026 struct sctp_vrf *vrf;
1033 /* Turn on all the appropriate scope */
1034 loopback_scope = stcb->asoc.scope.loopback_scope;
1036 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1037 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1040 local_scope = stcb->asoc.scope.local_scope;
1041 site_scope = stcb->asoc.scope.site_scope;
1042 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1045 /* Use generic values for endpoints. */
1048 ipv4_local_scope = 1;
1054 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1056 ipv6_addr_legal = 1;
1059 if (SCTP_IPV6_V6ONLY(inp)) {
1060 ipv4_addr_legal = 0;
1062 ipv4_addr_legal = 1;
1067 ipv6_addr_legal = 0;
1070 ipv4_addr_legal = 1;
1074 vrf = sctp_find_vrf(vrf_id);
1078 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1079 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1080 if ((loopback_scope == 0) &&
1081 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1082 /* Skip loopback if loopback_scope not set */
1085 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1088 * For the BOUND-ALL case, the list
1089 * associated with a TCB is Always
1090 * considered a reverse list.. i.e.
1091 * it lists addresses that are NOT
1092 * part of the association. If this
1093 * is one of those we must skip it.
1095 if (sctp_is_addr_restricted(stcb,
1100 switch (sctp_ifa->address.sa.sa_family) {
1103 if (ipv4_addr_legal) {
1104 struct sockaddr_in *sin;
1106 sin = &sctp_ifa->address.sin;
1107 if (sin->sin_addr.s_addr == 0) {
1115 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1116 &sin->sin_addr) != 0) {
1119 if ((ipv4_local_scope == 0) &&
1120 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1124 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1125 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1126 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1127 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1128 actual += sizeof(struct sockaddr_in6);
1131 memcpy(sas, sin, sizeof(*sin));
1132 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1133 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1134 actual += sizeof(*sin);
1138 if (actual >= limit) {
1148 if (ipv6_addr_legal) {
1149 struct sockaddr_in6 *sin6;
1151 sin6 = &sctp_ifa->address.sin6;
1152 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1160 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1161 &sin6->sin6_addr) != 0) {
1164 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1165 if (local_scope == 0)
1167 if (sin6->sin6_scope_id == 0) {
1168 if (sa6_recoverscope(sin6) != 0)
1181 if ((site_scope == 0) &&
1182 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1185 memcpy(sas, sin6, sizeof(*sin6));
1186 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1187 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1188 actual += sizeof(*sin6);
1189 if (actual >= limit) {
1204 struct sctp_laddr *laddr;
1206 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1208 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1212 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1214 switch (laddr->ifa->address.sa.sa_family) {
1217 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1222 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1229 sas = (struct sockaddr_storage *)((caddr_t)sas +
1230 laddr->ifa->address.sa.sa_len);
1231 actual += laddr->ifa->address.sa.sa_len;
1232 if (actual >= limit) {
1241 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1242 struct sctp_tcb *stcb,
1244 struct sockaddr_storage *sas)
1248 SCTP_IPI_ADDR_RLOCK();
1249 /* fill up addresses for the endpoint's default vrf */
1250 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1252 SCTP_IPI_ADDR_RUNLOCK();
1257 * NOTE: assumes addr lock is held
1260 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1263 struct sctp_vrf *vrf = NULL;
1266 * In both sub-set bound an bound_all cases we return the MAXIMUM
1267 * number of addresses that you COULD get. In reality the sub-set
1268 * bound may have an exclusion list for a given TCB OR in the
1269 * bound-all case a TCB may NOT include the loopback or other
1270 * addresses as well.
1272 vrf = sctp_find_vrf(vrf_id);
1276 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1277 struct sctp_ifn *sctp_ifn;
1278 struct sctp_ifa *sctp_ifa;
1280 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1281 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1282 /* Count them if they are the right type */
1283 switch (sctp_ifa->address.sa.sa_family) {
1287 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1288 cnt += sizeof(struct sockaddr_in6);
1290 cnt += sizeof(struct sockaddr_in);
1292 cnt += sizeof(struct sockaddr_in);
1298 cnt += sizeof(struct sockaddr_in6);
1307 struct sctp_laddr *laddr;
1309 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1310 switch (laddr->ifa->address.sa.sa_family) {
1314 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1315 cnt += sizeof(struct sockaddr_in6);
1317 cnt += sizeof(struct sockaddr_in);
1319 cnt += sizeof(struct sockaddr_in);
1325 cnt += sizeof(struct sockaddr_in6);
1337 sctp_count_max_addresses(struct sctp_inpcb *inp)
1341 SCTP_IPI_ADDR_RLOCK();
1342 /* count addresses for the endpoint's default VRF */
1343 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1344 SCTP_IPI_ADDR_RUNLOCK();
1349 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1350 size_t optsize, void *p, int delay)
1353 int creat_lock_on = 0;
1354 struct sctp_tcb *stcb = NULL;
1355 struct sockaddr *sa;
1356 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1358 int bad_addresses = 0;
1361 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1363 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1364 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1365 /* We are already connected AND the TCP model */
1366 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1367 return (EADDRINUSE);
1370 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1371 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1372 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1376 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1377 SCTP_INP_RLOCK(inp);
1378 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1379 SCTP_INP_RUNLOCK(inp);
1382 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1385 SCTP_INP_INCR_REF(inp);
1386 SCTP_ASOC_CREATE_LOCK(inp);
1388 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1389 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1390 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1394 totaddrp = (unsigned int *)optval;
1395 totaddr = *totaddrp;
1396 sa = (struct sockaddr *)(totaddrp + 1);
1397 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (unsigned int)(optsize - sizeof(int)), &bad_addresses);
1398 if ((stcb != NULL) || bad_addresses) {
1399 /* Already have or am bring up an association */
1400 SCTP_ASOC_CREATE_UNLOCK(inp);
1403 SCTP_TCB_UNLOCK(stcb);
1404 if (bad_addresses == 0) {
1405 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1411 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1416 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1418 struct in6pcb *inp6;
1420 inp6 = (struct in6pcb *)inp;
1421 if (SCTP_IPV6_V6ONLY(inp6)) {
1423 * if IPV6_V6ONLY flag, ignore connections destined
1424 * to a v4 addr or v4-mapped addr
1426 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1432 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1433 SCTP_PCB_FLAGS_UNBOUND) {
1434 /* Bind a ephemeral port */
1435 error = sctp_inpcb_bind(so, NULL, NULL, p);
1441 /* FIX ME: do we want to pass in a vrf on the connect call? */
1442 vrf_id = inp->def_vrf_id;
1445 /* We are GOOD to go */
1446 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1447 inp->sctp_ep.pre_open_stream_count,
1452 /* Gak! no memory */
1455 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1456 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1457 /* Set the connected flag so we can queue data */
1460 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1461 /* move to second address */
1462 switch (sa->sa_family) {
1465 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1470 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1478 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1479 /* Fill in the return id */
1481 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE,
1482 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
1485 a_id = (sctp_assoc_t *)optval;
1486 *a_id = sctp_get_associd(stcb);
1488 /* initialize authentication parameters for the assoc */
1489 sctp_initialize_auth_params(inp, stcb);
1492 /* doing delayed connection */
1493 stcb->asoc.delayed_connection = 1;
1494 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1496 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1497 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1499 SCTP_TCB_UNLOCK(stcb);
1501 if (creat_lock_on) {
1502 SCTP_ASOC_CREATE_UNLOCK(inp);
1504 SCTP_INP_DECR_REF(inp);
1508 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1509 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1510 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1511 SCTP_INP_RLOCK(inp); \
1512 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1514 SCTP_TCB_LOCK(stcb); \
1516 SCTP_INP_RUNLOCK(inp); \
1517 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1518 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1519 if (stcb == NULL) { \
1520 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1530 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1531 if (size < sizeof(type)) { \
1532 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1536 destp = (type *)srcp; \
1541 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1544 struct sctp_inpcb *inp = NULL;
1546 struct sctp_tcb *stcb = NULL;
1548 if (optval == NULL) {
1549 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1553 inp = (struct sctp_inpcb *)so->so_pcb;
1555 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1562 case SCTP_AUTOCLOSE:
1563 case SCTP_EXPLICIT_EOR:
1564 case SCTP_AUTO_ASCONF:
1565 case SCTP_DISABLE_FRAGMENTS:
1566 case SCTP_I_WANT_MAPPED_V4_ADDR:
1567 case SCTP_USE_EXT_RCVINFO:
1568 SCTP_INP_RLOCK(inp);
1570 case SCTP_DISABLE_FRAGMENTS:
1571 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1573 case SCTP_I_WANT_MAPPED_V4_ADDR:
1574 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1576 case SCTP_AUTO_ASCONF:
1577 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1578 /* only valid for bound all sockets */
1579 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1581 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1586 case SCTP_EXPLICIT_EOR:
1587 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1590 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1592 case SCTP_USE_EXT_RCVINFO:
1593 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1595 case SCTP_AUTOCLOSE:
1596 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1597 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1603 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1604 error = ENOPROTOOPT;
1605 } /* end switch (sopt->sopt_name) */
1606 if (*optsize < sizeof(val)) {
1607 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1611 SCTP_INP_RUNLOCK(inp);
1613 /* return the option value */
1614 *(int *)optval = val;
1615 *optsize = sizeof(val);
1618 case SCTP_GET_PACKET_LOG:
1620 #ifdef SCTP_PACKET_LOGGING
1624 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1625 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1628 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1633 case SCTP_REUSE_PORT:
1637 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1638 /* Can't do this for a 1-m socket */
1642 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1643 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1644 *optsize = sizeof(uint32_t);
1647 case SCTP_PARTIAL_DELIVERY_POINT:
1651 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1652 *value = inp->partial_delivery_point;
1653 *optsize = sizeof(uint32_t);
1656 case SCTP_FRAGMENT_INTERLEAVE:
1660 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1661 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1662 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1663 *value = SCTP_FRAG_LEVEL_2;
1665 *value = SCTP_FRAG_LEVEL_1;
1668 *value = SCTP_FRAG_LEVEL_0;
1670 *optsize = sizeof(uint32_t);
1673 case SCTP_INTERLEAVING_SUPPORTED:
1675 struct sctp_assoc_value *av;
1677 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1678 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1681 av->assoc_value = stcb->asoc.idata_supported;
1682 SCTP_TCB_UNLOCK(stcb);
1684 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1685 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1686 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1687 SCTP_INP_RLOCK(inp);
1688 if (inp->idata_supported) {
1689 av->assoc_value = 1;
1691 av->assoc_value = 0;
1693 SCTP_INP_RUNLOCK(inp);
1695 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1700 *optsize = sizeof(struct sctp_assoc_value);
1704 case SCTP_CMT_ON_OFF:
1706 struct sctp_assoc_value *av;
1708 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1709 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1711 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1712 SCTP_TCB_UNLOCK(stcb);
1714 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1715 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1716 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1717 SCTP_INP_RLOCK(inp);
1718 av->assoc_value = inp->sctp_cmt_on_off;
1719 SCTP_INP_RUNLOCK(inp);
1721 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1726 *optsize = sizeof(struct sctp_assoc_value);
1730 case SCTP_PLUGGABLE_CC:
1732 struct sctp_assoc_value *av;
1734 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1735 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1737 av->assoc_value = stcb->asoc.congestion_control_module;
1738 SCTP_TCB_UNLOCK(stcb);
1740 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1741 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1742 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1743 SCTP_INP_RLOCK(inp);
1744 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1745 SCTP_INP_RUNLOCK(inp);
1747 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1752 *optsize = sizeof(struct sctp_assoc_value);
1756 case SCTP_CC_OPTION:
1758 struct sctp_cc_option *cc_opt;
1760 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1761 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1765 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1768 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1769 *optsize = sizeof(struct sctp_cc_option);
1771 SCTP_TCB_UNLOCK(stcb);
1775 case SCTP_PLUGGABLE_SS:
1777 struct sctp_assoc_value *av;
1779 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1780 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1782 av->assoc_value = stcb->asoc.stream_scheduling_module;
1783 SCTP_TCB_UNLOCK(stcb);
1785 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1786 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1787 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1788 SCTP_INP_RLOCK(inp);
1789 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1790 SCTP_INP_RUNLOCK(inp);
1792 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1797 *optsize = sizeof(struct sctp_assoc_value);
1803 struct sctp_stream_value *av;
1805 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1806 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1808 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1809 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1810 &av->stream_value) < 0)) {
1811 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1814 *optsize = sizeof(struct sctp_stream_value);
1816 SCTP_TCB_UNLOCK(stcb);
1819 * Can't get stream value without
1822 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1827 case SCTP_GET_ADDR_LEN:
1829 struct sctp_assoc_value *av;
1831 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1834 if (av->assoc_value == AF_INET) {
1835 av->assoc_value = sizeof(struct sockaddr_in);
1840 if (av->assoc_value == AF_INET6) {
1841 av->assoc_value = sizeof(struct sockaddr_in6);
1846 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1848 *optsize = sizeof(struct sctp_assoc_value);
1852 case SCTP_GET_ASSOC_NUMBER:
1854 uint32_t *value, cnt;
1856 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1857 SCTP_INP_RLOCK(inp);
1858 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1859 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1860 /* Can't do this for a 1-1 socket */
1862 SCTP_INP_RUNLOCK(inp);
1866 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1869 SCTP_INP_RUNLOCK(inp);
1871 *optsize = sizeof(uint32_t);
1874 case SCTP_GET_ASSOC_ID_LIST:
1876 struct sctp_assoc_ids *ids;
1880 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1881 SCTP_INP_RLOCK(inp);
1882 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1883 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1884 /* Can't do this for a 1-1 socket */
1886 SCTP_INP_RUNLOCK(inp);
1890 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1891 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1893 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1896 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1901 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1905 SCTP_INP_RUNLOCK(inp);
1907 ids->gaids_number_of_ids = at;
1908 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1914 struct sctp_assoc_value *av;
1916 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1917 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1920 av->assoc_value = stcb->asoc.context;
1921 SCTP_TCB_UNLOCK(stcb);
1923 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1924 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1925 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1926 SCTP_INP_RLOCK(inp);
1927 av->assoc_value = inp->sctp_context;
1928 SCTP_INP_RUNLOCK(inp);
1930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1935 *optsize = sizeof(struct sctp_assoc_value);
1941 uint32_t *default_vrfid;
1943 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1944 *default_vrfid = inp->def_vrf_id;
1945 *optsize = sizeof(uint32_t);
1948 case SCTP_GET_ASOC_VRF:
1950 struct sctp_assoc_value *id;
1952 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1953 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1958 id->assoc_value = stcb->asoc.vrf_id;
1959 SCTP_TCB_UNLOCK(stcb);
1960 *optsize = sizeof(struct sctp_assoc_value);
1964 case SCTP_GET_VRF_IDS:
1966 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1970 case SCTP_GET_NONCE_VALUES:
1972 struct sctp_get_nonce_values *gnv;
1974 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1975 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1978 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1979 gnv->gn_local_tag = stcb->asoc.my_vtag;
1980 SCTP_TCB_UNLOCK(stcb);
1981 *optsize = sizeof(struct sctp_get_nonce_values);
1983 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1988 case SCTP_DELAYED_SACK:
1990 struct sctp_sack_info *sack;
1992 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1993 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1995 sack->sack_delay = stcb->asoc.delayed_ack;
1996 sack->sack_freq = stcb->asoc.sack_freq;
1997 SCTP_TCB_UNLOCK(stcb);
1999 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2000 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2001 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2002 SCTP_INP_RLOCK(inp);
2003 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2004 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2005 SCTP_INP_RUNLOCK(inp);
2007 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2012 *optsize = sizeof(struct sctp_sack_info);
2016 case SCTP_GET_SNDBUF_USE:
2018 struct sctp_sockstat *ss;
2020 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2021 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2024 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2025 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2026 stcb->asoc.size_on_all_streams);
2027 SCTP_TCB_UNLOCK(stcb);
2028 *optsize = sizeof(struct sctp_sockstat);
2030 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2035 case SCTP_MAX_BURST:
2037 struct sctp_assoc_value *av;
2039 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2040 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2043 av->assoc_value = stcb->asoc.max_burst;
2044 SCTP_TCB_UNLOCK(stcb);
2046 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2047 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2048 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2049 SCTP_INP_RLOCK(inp);
2050 av->assoc_value = inp->sctp_ep.max_burst;
2051 SCTP_INP_RUNLOCK(inp);
2053 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2058 *optsize = sizeof(struct sctp_assoc_value);
2064 struct sctp_assoc_value *av;
2067 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2068 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2071 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2072 SCTP_TCB_UNLOCK(stcb);
2074 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2075 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2076 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2077 SCTP_INP_RLOCK(inp);
2078 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2079 ovh = SCTP_MED_OVERHEAD;
2081 ovh = SCTP_MED_V4_OVERHEAD;
2083 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2084 av->assoc_value = 0;
2086 av->assoc_value = inp->sctp_frag_point - ovh;
2087 SCTP_INP_RUNLOCK(inp);
2089 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2094 *optsize = sizeof(struct sctp_assoc_value);
2098 case SCTP_GET_STAT_LOG:
2099 error = sctp_fill_stat_log(optval, optsize);
2103 struct sctp_event_subscribe *events;
2105 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2106 memset(events, 0, sizeof(struct sctp_event_subscribe));
2107 SCTP_INP_RLOCK(inp);
2108 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2109 events->sctp_data_io_event = 1;
2111 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2112 events->sctp_association_event = 1;
2114 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2115 events->sctp_address_event = 1;
2117 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2118 events->sctp_send_failure_event = 1;
2120 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2121 events->sctp_peer_error_event = 1;
2123 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2124 events->sctp_shutdown_event = 1;
2126 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2127 events->sctp_partial_delivery_event = 1;
2129 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2130 events->sctp_adaptation_layer_event = 1;
2132 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2133 events->sctp_authentication_event = 1;
2135 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2136 events->sctp_sender_dry_event = 1;
2138 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2139 events->sctp_stream_reset_event = 1;
2140 SCTP_INP_RUNLOCK(inp);
2141 *optsize = sizeof(struct sctp_event_subscribe);
2144 case SCTP_ADAPTATION_LAYER:
2148 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2150 SCTP_INP_RLOCK(inp);
2151 *value = inp->sctp_ep.adaptation_layer_indicator;
2152 SCTP_INP_RUNLOCK(inp);
2153 *optsize = sizeof(uint32_t);
2156 case SCTP_SET_INITIAL_DBG_SEQ:
2160 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2161 SCTP_INP_RLOCK(inp);
2162 *value = inp->sctp_ep.initial_sequence_debug;
2163 SCTP_INP_RUNLOCK(inp);
2164 *optsize = sizeof(uint32_t);
2167 case SCTP_GET_LOCAL_ADDR_SIZE:
2171 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2172 SCTP_INP_RLOCK(inp);
2173 *value = sctp_count_max_addresses(inp);
2174 SCTP_INP_RUNLOCK(inp);
2175 *optsize = sizeof(uint32_t);
2178 case SCTP_GET_REMOTE_ADDR_SIZE:
2182 struct sctp_nets *net;
2184 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2185 /* FIXME MT: change to sctp_assoc_value? */
2186 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2190 /* Count the sizes */
2191 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2192 switch (net->ro._l_addr.sa.sa_family) {
2196 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2197 size += sizeof(struct sockaddr_in6);
2199 size += sizeof(struct sockaddr_in);
2202 size += sizeof(struct sockaddr_in);
2208 size += sizeof(struct sockaddr_in6);
2215 SCTP_TCB_UNLOCK(stcb);
2216 *value = (uint32_t)size;
2217 *optsize = sizeof(uint32_t);
2219 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2224 case SCTP_GET_PEER_ADDRESSES:
2226 * Get the address information, an array is passed in to
2227 * fill up we pack it.
2231 struct sockaddr_storage *sas;
2232 struct sctp_nets *net;
2233 struct sctp_getaddresses *saddr;
2235 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2236 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2239 left = (*optsize) - sizeof(struct sctp_getaddresses);
2240 *optsize = sizeof(struct sctp_getaddresses);
2241 sas = (struct sockaddr_storage *)&saddr->addr[0];
2243 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2244 switch (net->ro._l_addr.sa.sa_family) {
2248 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2249 cpsz = sizeof(struct sockaddr_in6);
2251 cpsz = sizeof(struct sockaddr_in);
2254 cpsz = sizeof(struct sockaddr_in);
2260 cpsz = sizeof(struct sockaddr_in6);
2271 /* not enough room. */
2274 #if defined(INET) && defined(INET6)
2275 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2276 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2277 /* Must map the address */
2278 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2279 (struct sockaddr_in6 *)sas);
2281 memcpy(sas, &net->ro._l_addr, cpsz);
2284 memcpy(sas, &net->ro._l_addr, cpsz);
2286 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2288 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2292 SCTP_TCB_UNLOCK(stcb);
2294 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2299 case SCTP_GET_LOCAL_ADDRESSES:
2301 size_t limit, actual;
2302 struct sockaddr_storage *sas;
2303 struct sctp_getaddresses *saddr;
2305 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2306 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2308 sas = (struct sockaddr_storage *)&saddr->addr[0];
2309 limit = *optsize - sizeof(sctp_assoc_t);
2310 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2312 SCTP_TCB_UNLOCK(stcb);
2314 *optsize = sizeof(struct sockaddr_storage) + actual;
2317 case SCTP_PEER_ADDR_PARAMS:
2319 struct sctp_paddrparams *paddrp;
2320 struct sctp_nets *net;
2321 struct sockaddr *addr;
2322 #if defined(INET) && defined(INET6)
2323 struct sockaddr_in sin_store;
2326 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2327 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2329 #if defined(INET) && defined(INET6)
2330 if (paddrp->spp_address.ss_family == AF_INET6) {
2331 struct sockaddr_in6 *sin6;
2333 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2334 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2335 in6_sin6_2_sin(&sin_store, sin6);
2336 addr = (struct sockaddr *)&sin_store;
2338 addr = (struct sockaddr *)&paddrp->spp_address;
2341 addr = (struct sockaddr *)&paddrp->spp_address;
2344 addr = (struct sockaddr *)&paddrp->spp_address;
2347 net = sctp_findnet(stcb, addr);
2350 * We increment here since
2351 * sctp_findassociation_ep_addr() wil do a
2352 * decrement if it finds the stcb as long as
2353 * the locked tcb (last argument) is NOT a
2357 SCTP_INP_INCR_REF(inp);
2358 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2360 SCTP_INP_DECR_REF(inp);
2363 if ((stcb != NULL) && (net == NULL)) {
2365 if (addr->sa_family == AF_INET) {
2366 struct sockaddr_in *sin;
2368 sin = (struct sockaddr_in *)addr;
2369 if (sin->sin_addr.s_addr != INADDR_ANY) {
2371 SCTP_TCB_UNLOCK(stcb);
2372 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2378 if (addr->sa_family == AF_INET6) {
2379 struct sockaddr_in6 *sin6;
2381 sin6 = (struct sockaddr_in6 *)addr;
2382 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2384 SCTP_TCB_UNLOCK(stcb);
2385 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2391 error = EAFNOSUPPORT;
2392 SCTP_TCB_UNLOCK(stcb);
2393 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2399 /* Applies to the specific association */
2400 paddrp->spp_flags = 0;
2402 paddrp->spp_hbinterval = net->heart_beat_delay;
2403 paddrp->spp_pathmaxrxt = net->failure_threshold;
2404 paddrp->spp_pathmtu = net->mtu;
2405 switch (net->ro._l_addr.sa.sa_family) {
2408 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2413 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2419 /* get flags for HB */
2420 if (net->dest_state & SCTP_ADDR_NOHB) {
2421 paddrp->spp_flags |= SPP_HB_DISABLE;
2423 paddrp->spp_flags |= SPP_HB_ENABLE;
2425 /* get flags for PMTU */
2426 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2427 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2429 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2431 if (net->dscp & 0x01) {
2432 paddrp->spp_dscp = net->dscp & 0xfc;
2433 paddrp->spp_flags |= SPP_DSCP;
2436 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2437 (net->flowlabel & 0x80000000)) {
2438 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2439 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2444 * No destination so return default
2447 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2448 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2449 if (stcb->asoc.default_dscp & 0x01) {
2450 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2451 paddrp->spp_flags |= SPP_DSCP;
2454 if (stcb->asoc.default_flowlabel & 0x80000000) {
2455 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2456 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2459 /* default settings should be these */
2460 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2461 paddrp->spp_flags |= SPP_HB_DISABLE;
2463 paddrp->spp_flags |= SPP_HB_ENABLE;
2465 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2466 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2468 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2470 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2472 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2473 SCTP_TCB_UNLOCK(stcb);
2475 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2476 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2477 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2478 /* Use endpoint defaults */
2479 SCTP_INP_RLOCK(inp);
2480 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2481 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2482 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2483 /* get inp's default */
2484 if (inp->sctp_ep.default_dscp & 0x01) {
2485 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2486 paddrp->spp_flags |= SPP_DSCP;
2489 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2490 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2491 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2492 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2495 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2497 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2498 paddrp->spp_flags |= SPP_HB_ENABLE;
2500 paddrp->spp_flags |= SPP_HB_DISABLE;
2502 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2503 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2505 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2507 SCTP_INP_RUNLOCK(inp);
2509 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2514 *optsize = sizeof(struct sctp_paddrparams);
2518 case SCTP_GET_PEER_ADDR_INFO:
2520 struct sctp_paddrinfo *paddri;
2521 struct sctp_nets *net;
2522 struct sockaddr *addr;
2523 #if defined(INET) && defined(INET6)
2524 struct sockaddr_in sin_store;
2527 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2528 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2530 #if defined(INET) && defined(INET6)
2531 if (paddri->spinfo_address.ss_family == AF_INET6) {
2532 struct sockaddr_in6 *sin6;
2534 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2535 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2536 in6_sin6_2_sin(&sin_store, sin6);
2537 addr = (struct sockaddr *)&sin_store;
2539 addr = (struct sockaddr *)&paddri->spinfo_address;
2542 addr = (struct sockaddr *)&paddri->spinfo_address;
2545 addr = (struct sockaddr *)&paddri->spinfo_address;
2548 net = sctp_findnet(stcb, addr);
2551 * We increment here since
2552 * sctp_findassociation_ep_addr() wil do a
2553 * decrement if it finds the stcb as long as
2554 * the locked tcb (last argument) is NOT a
2558 SCTP_INP_INCR_REF(inp);
2559 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2561 SCTP_INP_DECR_REF(inp);
2565 if ((stcb != NULL) && (net != NULL)) {
2566 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2567 /* It's unconfirmed */
2568 paddri->spinfo_state = SCTP_UNCONFIRMED;
2569 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2571 paddri->spinfo_state = SCTP_ACTIVE;
2574 paddri->spinfo_state = SCTP_INACTIVE;
2576 paddri->spinfo_cwnd = net->cwnd;
2577 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2578 paddri->spinfo_rto = net->RTO;
2579 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2580 paddri->spinfo_mtu = net->mtu;
2581 switch (addr->sa_family) {
2584 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2589 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2595 SCTP_TCB_UNLOCK(stcb);
2596 *optsize = sizeof(struct sctp_paddrinfo);
2599 SCTP_TCB_UNLOCK(stcb);
2601 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2606 case SCTP_PCB_STATUS:
2608 struct sctp_pcbinfo *spcb;
2610 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2611 sctp_fill_pcbinfo(spcb);
2612 *optsize = sizeof(struct sctp_pcbinfo);
2617 struct sctp_nets *net;
2618 struct sctp_status *sstat;
2620 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2621 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2624 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2628 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2629 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2630 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2631 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2633 * We can't include chunks that have been passed to
2634 * the socket layer. Only things in queue.
2636 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2637 stcb->asoc.cnt_on_all_streams);
2640 sstat->sstat_instrms = stcb->asoc.streamincnt;
2641 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2642 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2643 memcpy(&sstat->sstat_primary.spinfo_address,
2644 &stcb->asoc.primary_destination->ro._l_addr,
2645 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2646 net = stcb->asoc.primary_destination;
2647 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2649 * Again the user can get info from sctp_constants.h
2650 * for what the state of the network is.
2652 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2653 /* It's unconfirmed */
2654 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2655 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2657 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2660 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2662 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2663 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2664 sstat->sstat_primary.spinfo_rto = net->RTO;
2665 sstat->sstat_primary.spinfo_mtu = net->mtu;
2666 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2669 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2674 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2680 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2681 SCTP_TCB_UNLOCK(stcb);
2682 *optsize = sizeof(struct sctp_status);
2687 struct sctp_rtoinfo *srto;
2689 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2690 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2693 srto->srto_initial = stcb->asoc.initial_rto;
2694 srto->srto_max = stcb->asoc.maxrto;
2695 srto->srto_min = stcb->asoc.minrto;
2696 SCTP_TCB_UNLOCK(stcb);
2698 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2699 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2700 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2701 SCTP_INP_RLOCK(inp);
2702 srto->srto_initial = inp->sctp_ep.initial_rto;
2703 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2704 srto->srto_min = inp->sctp_ep.sctp_minrto;
2705 SCTP_INP_RUNLOCK(inp);
2707 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2712 *optsize = sizeof(struct sctp_rtoinfo);
2718 struct sctp_timeouts *stimo;
2720 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2721 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2724 stimo->stimo_init = stcb->asoc.timoinit;
2725 stimo->stimo_data = stcb->asoc.timodata;
2726 stimo->stimo_sack = stcb->asoc.timosack;
2727 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2728 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2729 stimo->stimo_cookie = stcb->asoc.timocookie;
2730 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2731 SCTP_TCB_UNLOCK(stcb);
2732 *optsize = sizeof(struct sctp_timeouts);
2734 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2739 case SCTP_ASSOCINFO:
2741 struct sctp_assocparams *sasoc;
2743 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2744 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2747 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2748 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2749 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2750 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2751 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2752 SCTP_TCB_UNLOCK(stcb);
2754 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2755 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2756 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2757 SCTP_INP_RLOCK(inp);
2758 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2759 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2760 sasoc->sasoc_number_peer_destinations = 0;
2761 sasoc->sasoc_peer_rwnd = 0;
2762 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2763 SCTP_INP_RUNLOCK(inp);
2765 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2770 *optsize = sizeof(struct sctp_assocparams);
2774 case SCTP_DEFAULT_SEND_PARAM:
2776 struct sctp_sndrcvinfo *s_info;
2778 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2779 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2782 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2783 SCTP_TCB_UNLOCK(stcb);
2785 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2786 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2787 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2788 SCTP_INP_RLOCK(inp);
2789 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2790 SCTP_INP_RUNLOCK(inp);
2792 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2797 *optsize = sizeof(struct sctp_sndrcvinfo);
2803 struct sctp_initmsg *sinit;
2805 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2806 SCTP_INP_RLOCK(inp);
2807 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2808 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2809 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2810 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2811 SCTP_INP_RUNLOCK(inp);
2812 *optsize = sizeof(struct sctp_initmsg);
2815 case SCTP_PRIMARY_ADDR:
2816 /* we allow a "get" operation on this */
2818 struct sctp_setprim *ssp;
2820 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2821 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2824 union sctp_sockstore *addr;
2826 addr = &stcb->asoc.primary_destination->ro._l_addr;
2827 switch (addr->sa.sa_family) {
2831 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2832 in6_sin_2_v4mapsin6(&addr->sin,
2833 (struct sockaddr_in6 *)&ssp->ssp_addr);
2835 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2838 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2844 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2850 SCTP_TCB_UNLOCK(stcb);
2851 *optsize = sizeof(struct sctp_setprim);
2853 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2858 case SCTP_HMAC_IDENT:
2860 struct sctp_hmacalgo *shmac;
2861 sctp_hmaclist_t *hmaclist;
2865 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2867 SCTP_INP_RLOCK(inp);
2868 hmaclist = inp->sctp_ep.local_hmacs;
2869 if (hmaclist == NULL) {
2870 /* no HMACs to return */
2871 *optsize = sizeof(*shmac);
2872 SCTP_INP_RUNLOCK(inp);
2875 /* is there room for all of the hmac ids? */
2876 size = sizeof(*shmac) + (hmaclist->num_algo *
2877 sizeof(shmac->shmac_idents[0]));
2878 if ((size_t)(*optsize) < size) {
2879 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2881 SCTP_INP_RUNLOCK(inp);
2884 /* copy in the list */
2885 shmac->shmac_number_of_idents = hmaclist->num_algo;
2886 for (i = 0; i < hmaclist->num_algo; i++) {
2887 shmac->shmac_idents[i] = hmaclist->hmac[i];
2889 SCTP_INP_RUNLOCK(inp);
2893 case SCTP_AUTH_ACTIVE_KEY:
2895 struct sctp_authkeyid *scact;
2897 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2898 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2901 /* get the active key on the assoc */
2902 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2903 SCTP_TCB_UNLOCK(stcb);
2905 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2906 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2907 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2908 /* get the endpoint active key */
2909 SCTP_INP_RLOCK(inp);
2910 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2911 SCTP_INP_RUNLOCK(inp);
2913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2918 *optsize = sizeof(struct sctp_authkeyid);
2922 case SCTP_LOCAL_AUTH_CHUNKS:
2924 struct sctp_authchunks *sac;
2925 sctp_auth_chklist_t *chklist = NULL;
2928 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2929 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2932 /* get off the assoc */
2933 chklist = stcb->asoc.local_auth_chunks;
2934 /* is there enough space? */
2935 size = sctp_auth_get_chklist_size(chklist);
2936 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2940 /* copy in the chunks */
2941 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2942 sac->gauth_number_of_chunks = (uint32_t)size;
2943 *optsize = sizeof(struct sctp_authchunks) + size;
2945 SCTP_TCB_UNLOCK(stcb);
2947 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2948 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2949 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2950 /* get off the endpoint */
2951 SCTP_INP_RLOCK(inp);
2952 chklist = inp->sctp_ep.local_auth_chunks;
2953 /* is there enough space? */
2954 size = sctp_auth_get_chklist_size(chklist);
2955 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2959 /* copy in the chunks */
2960 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2961 sac->gauth_number_of_chunks = (uint32_t)size;
2962 *optsize = sizeof(struct sctp_authchunks) + size;
2964 SCTP_INP_RUNLOCK(inp);
2966 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2972 case SCTP_PEER_AUTH_CHUNKS:
2974 struct sctp_authchunks *sac;
2975 sctp_auth_chklist_t *chklist = NULL;
2978 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2979 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2982 /* get off the assoc */
2983 chklist = stcb->asoc.peer_auth_chunks;
2984 /* is there enough space? */
2985 size = sctp_auth_get_chklist_size(chklist);
2986 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2988 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2990 /* copy in the chunks */
2991 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2992 sac->gauth_number_of_chunks = (uint32_t)size;
2993 *optsize = sizeof(struct sctp_authchunks) + size;
2995 SCTP_TCB_UNLOCK(stcb);
2997 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3004 struct sctp_event *event;
3005 uint32_t event_type;
3007 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3008 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3010 switch (event->se_type) {
3011 case SCTP_ASSOC_CHANGE:
3012 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3014 case SCTP_PEER_ADDR_CHANGE:
3015 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3017 case SCTP_REMOTE_ERROR:
3018 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3020 case SCTP_SEND_FAILED:
3021 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3023 case SCTP_SHUTDOWN_EVENT:
3024 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3026 case SCTP_ADAPTATION_INDICATION:
3027 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3029 case SCTP_PARTIAL_DELIVERY_EVENT:
3030 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3032 case SCTP_AUTHENTICATION_EVENT:
3033 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3035 case SCTP_STREAM_RESET_EVENT:
3036 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3038 case SCTP_SENDER_DRY_EVENT:
3039 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3041 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3043 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3046 case SCTP_ASSOC_RESET_EVENT:
3047 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3049 case SCTP_STREAM_CHANGE_EVENT:
3050 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3052 case SCTP_SEND_FAILED_EVENT:
3053 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3057 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3061 if (event_type > 0) {
3063 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3065 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3066 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3067 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3068 SCTP_INP_RLOCK(inp);
3069 event->se_on = sctp_is_feature_on(inp, event_type);
3070 SCTP_INP_RUNLOCK(inp);
3072 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3078 SCTP_TCB_UNLOCK(stcb);
3081 *optsize = sizeof(struct sctp_event);
3085 case SCTP_RECVRCVINFO:
3089 if (*optsize < sizeof(int)) {
3090 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3093 SCTP_INP_RLOCK(inp);
3094 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3095 SCTP_INP_RUNLOCK(inp);
3098 /* return the option value */
3099 *(int *)optval = onoff;
3100 *optsize = sizeof(int);
3104 case SCTP_RECVNXTINFO:
3108 if (*optsize < sizeof(int)) {
3109 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3112 SCTP_INP_RLOCK(inp);
3113 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3114 SCTP_INP_RUNLOCK(inp);
3117 /* return the option value */
3118 *(int *)optval = onoff;
3119 *optsize = sizeof(int);
3123 case SCTP_DEFAULT_SNDINFO:
3125 struct sctp_sndinfo *info;
3127 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3128 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3131 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3132 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3133 info->snd_flags &= 0xfff0;
3134 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3135 info->snd_context = stcb->asoc.def_send.sinfo_context;
3136 SCTP_TCB_UNLOCK(stcb);
3138 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3139 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3140 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3141 SCTP_INP_RLOCK(inp);
3142 info->snd_sid = inp->def_send.sinfo_stream;
3143 info->snd_flags = inp->def_send.sinfo_flags;
3144 info->snd_flags &= 0xfff0;
3145 info->snd_ppid = inp->def_send.sinfo_ppid;
3146 info->snd_context = inp->def_send.sinfo_context;
3147 SCTP_INP_RUNLOCK(inp);
3149 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3154 *optsize = sizeof(struct sctp_sndinfo);
3158 case SCTP_DEFAULT_PRINFO:
3160 struct sctp_default_prinfo *info;
3162 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3163 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3166 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3167 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3168 SCTP_TCB_UNLOCK(stcb);
3170 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3171 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3172 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3173 SCTP_INP_RLOCK(inp);
3174 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3175 info->pr_value = inp->def_send.sinfo_timetolive;
3176 SCTP_INP_RUNLOCK(inp);
3178 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3183 *optsize = sizeof(struct sctp_default_prinfo);
3187 case SCTP_PEER_ADDR_THLDS:
3189 struct sctp_paddrthlds *thlds;
3190 struct sctp_nets *net;
3191 struct sockaddr *addr;
3192 #if defined(INET) && defined(INET6)
3193 struct sockaddr_in sin_store;
3196 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3197 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3199 #if defined(INET) && defined(INET6)
3200 if (thlds->spt_address.ss_family == AF_INET6) {
3201 struct sockaddr_in6 *sin6;
3203 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3204 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3205 in6_sin6_2_sin(&sin_store, sin6);
3206 addr = (struct sockaddr *)&sin_store;
3208 addr = (struct sockaddr *)&thlds->spt_address;
3211 addr = (struct sockaddr *)&thlds->spt_address;
3214 addr = (struct sockaddr *)&thlds->spt_address;
3217 net = sctp_findnet(stcb, addr);
3220 * We increment here since
3221 * sctp_findassociation_ep_addr() wil do a
3222 * decrement if it finds the stcb as long as
3223 * the locked tcb (last argument) is NOT a
3227 SCTP_INP_INCR_REF(inp);
3228 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3230 SCTP_INP_DECR_REF(inp);
3233 if ((stcb != NULL) && (net == NULL)) {
3235 if (addr->sa_family == AF_INET) {
3236 struct sockaddr_in *sin;
3238 sin = (struct sockaddr_in *)addr;
3239 if (sin->sin_addr.s_addr != INADDR_ANY) {
3241 SCTP_TCB_UNLOCK(stcb);
3242 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3248 if (addr->sa_family == AF_INET6) {
3249 struct sockaddr_in6 *sin6;
3251 sin6 = (struct sockaddr_in6 *)addr;
3252 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3254 SCTP_TCB_UNLOCK(stcb);
3255 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3261 error = EAFNOSUPPORT;
3262 SCTP_TCB_UNLOCK(stcb);
3263 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3270 thlds->spt_pathmaxrxt = net->failure_threshold;
3271 thlds->spt_pathpfthld = net->pf_threshold;
3272 thlds->spt_pathcpthld = 0xffff;
3274 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3275 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3276 thlds->spt_pathcpthld = 0xffff;
3278 thlds->spt_assoc_id = sctp_get_associd(stcb);
3279 SCTP_TCB_UNLOCK(stcb);
3281 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3282 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3283 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3284 /* Use endpoint defaults */
3285 SCTP_INP_RLOCK(inp);
3286 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3287 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3288 thlds->spt_pathcpthld = 0xffff;
3289 SCTP_INP_RUNLOCK(inp);
3291 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3296 *optsize = sizeof(struct sctp_paddrthlds);
3300 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3302 struct sctp_udpencaps *encaps;
3303 struct sctp_nets *net;
3304 struct sockaddr *addr;
3305 #if defined(INET) && defined(INET6)
3306 struct sockaddr_in sin_store;
3309 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3310 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3312 #if defined(INET) && defined(INET6)
3313 if (encaps->sue_address.ss_family == AF_INET6) {
3314 struct sockaddr_in6 *sin6;
3316 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3317 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3318 in6_sin6_2_sin(&sin_store, sin6);
3319 addr = (struct sockaddr *)&sin_store;
3321 addr = (struct sockaddr *)&encaps->sue_address;
3324 addr = (struct sockaddr *)&encaps->sue_address;
3327 addr = (struct sockaddr *)&encaps->sue_address;
3330 net = sctp_findnet(stcb, addr);
3333 * We increment here since
3334 * sctp_findassociation_ep_addr() wil do a
3335 * decrement if it finds the stcb as long as
3336 * the locked tcb (last argument) is NOT a
3340 SCTP_INP_INCR_REF(inp);
3341 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3343 SCTP_INP_DECR_REF(inp);
3346 if ((stcb != NULL) && (net == NULL)) {
3348 if (addr->sa_family == AF_INET) {
3349 struct sockaddr_in *sin;
3351 sin = (struct sockaddr_in *)addr;
3352 if (sin->sin_addr.s_addr != INADDR_ANY) {
3354 SCTP_TCB_UNLOCK(stcb);
3355 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3361 if (addr->sa_family == AF_INET6) {
3362 struct sockaddr_in6 *sin6;
3364 sin6 = (struct sockaddr_in6 *)addr;
3365 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3367 SCTP_TCB_UNLOCK(stcb);
3368 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3374 error = EAFNOSUPPORT;
3375 SCTP_TCB_UNLOCK(stcb);
3376 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3383 encaps->sue_port = net->port;
3385 encaps->sue_port = stcb->asoc.port;
3387 SCTP_TCB_UNLOCK(stcb);
3389 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3390 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3391 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3392 SCTP_INP_RLOCK(inp);
3393 encaps->sue_port = inp->sctp_ep.port;
3394 SCTP_INP_RUNLOCK(inp);
3396 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3401 *optsize = sizeof(struct sctp_udpencaps);
3405 case SCTP_ECN_SUPPORTED:
3407 struct sctp_assoc_value *av;
3409 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3410 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3413 av->assoc_value = stcb->asoc.ecn_supported;
3414 SCTP_TCB_UNLOCK(stcb);
3416 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3417 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3418 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3419 SCTP_INP_RLOCK(inp);
3420 av->assoc_value = inp->ecn_supported;
3421 SCTP_INP_RUNLOCK(inp);
3423 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3428 *optsize = sizeof(struct sctp_assoc_value);
3432 case SCTP_PR_SUPPORTED:
3434 struct sctp_assoc_value *av;
3436 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3437 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3440 av->assoc_value = stcb->asoc.prsctp_supported;
3441 SCTP_TCB_UNLOCK(stcb);
3443 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3444 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3445 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3446 SCTP_INP_RLOCK(inp);
3447 av->assoc_value = inp->prsctp_supported;
3448 SCTP_INP_RUNLOCK(inp);
3450 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3455 *optsize = sizeof(struct sctp_assoc_value);
3459 case SCTP_AUTH_SUPPORTED:
3461 struct sctp_assoc_value *av;
3463 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3464 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3467 av->assoc_value = stcb->asoc.auth_supported;
3468 SCTP_TCB_UNLOCK(stcb);
3470 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3471 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3472 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3473 SCTP_INP_RLOCK(inp);
3474 av->assoc_value = inp->auth_supported;
3475 SCTP_INP_RUNLOCK(inp);
3477 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3482 *optsize = sizeof(struct sctp_assoc_value);
3486 case SCTP_ASCONF_SUPPORTED:
3488 struct sctp_assoc_value *av;
3490 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3491 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3494 av->assoc_value = stcb->asoc.asconf_supported;
3495 SCTP_TCB_UNLOCK(stcb);
3497 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3498 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3499 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3500 SCTP_INP_RLOCK(inp);
3501 av->assoc_value = inp->asconf_supported;
3502 SCTP_INP_RUNLOCK(inp);
3504 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3509 *optsize = sizeof(struct sctp_assoc_value);
3513 case SCTP_RECONFIG_SUPPORTED:
3515 struct sctp_assoc_value *av;
3517 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3518 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3521 av->assoc_value = stcb->asoc.reconfig_supported;
3522 SCTP_TCB_UNLOCK(stcb);
3524 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3525 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3526 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3527 SCTP_INP_RLOCK(inp);
3528 av->assoc_value = inp->reconfig_supported;
3529 SCTP_INP_RUNLOCK(inp);
3531 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3536 *optsize = sizeof(struct sctp_assoc_value);
3540 case SCTP_NRSACK_SUPPORTED:
3542 struct sctp_assoc_value *av;
3544 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3545 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3548 av->assoc_value = stcb->asoc.nrsack_supported;
3549 SCTP_TCB_UNLOCK(stcb);
3551 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3552 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3553 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3554 SCTP_INP_RLOCK(inp);
3555 av->assoc_value = inp->nrsack_supported;
3556 SCTP_INP_RUNLOCK(inp);
3558 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3563 *optsize = sizeof(struct sctp_assoc_value);
3567 case SCTP_PKTDROP_SUPPORTED:
3569 struct sctp_assoc_value *av;
3571 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3572 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3575 av->assoc_value = stcb->asoc.pktdrop_supported;
3576 SCTP_TCB_UNLOCK(stcb);
3578 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3579 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3580 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3581 SCTP_INP_RLOCK(inp);
3582 av->assoc_value = inp->pktdrop_supported;
3583 SCTP_INP_RUNLOCK(inp);
3585 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3590 *optsize = sizeof(struct sctp_assoc_value);
3594 case SCTP_ENABLE_STREAM_RESET:
3596 struct sctp_assoc_value *av;
3598 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3599 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3602 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3603 SCTP_TCB_UNLOCK(stcb);
3605 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3606 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3607 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3608 SCTP_INP_RLOCK(inp);
3609 av->assoc_value = (uint32_t)inp->local_strreset_support;
3610 SCTP_INP_RUNLOCK(inp);
3612 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3617 *optsize = sizeof(struct sctp_assoc_value);
3621 case SCTP_PR_STREAM_STATUS:
3623 struct sctp_prstatus *sprstat;
3627 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3628 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3630 sid = sprstat->sprstat_sid;
3631 policy = sprstat->sprstat_policy;
3632 #if defined(SCTP_DETAILED_STR_STATS)
3633 if ((stcb != NULL) &&
3634 (sid < stcb->asoc.streamoutcnt) &&
3635 (policy != SCTP_PR_SCTP_NONE) &&
3636 ((policy <= SCTP_PR_SCTP_MAX) ||
3637 (policy == SCTP_PR_SCTP_ALL))) {
3638 if (policy == SCTP_PR_SCTP_ALL) {
3639 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3640 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3642 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3643 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3646 if ((stcb != NULL) &&
3647 (sid < stcb->asoc.streamoutcnt) &&
3648 (policy == SCTP_PR_SCTP_ALL)) {
3649 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3650 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3653 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3657 SCTP_TCB_UNLOCK(stcb);
3660 *optsize = sizeof(struct sctp_prstatus);
3664 case SCTP_PR_ASSOC_STATUS:
3666 struct sctp_prstatus *sprstat;
3669 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3670 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3672 policy = sprstat->sprstat_policy;
3673 if ((stcb != NULL) &&
3674 (policy != SCTP_PR_SCTP_NONE) &&
3675 ((policy <= SCTP_PR_SCTP_MAX) ||
3676 (policy == SCTP_PR_SCTP_ALL))) {
3677 if (policy == SCTP_PR_SCTP_ALL) {
3678 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3679 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3681 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3682 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3689 SCTP_TCB_UNLOCK(stcb);
3692 *optsize = sizeof(struct sctp_prstatus);
3698 struct sctp_assoc_value *av;
3700 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3701 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3704 av->assoc_value = stcb->asoc.max_cwnd;
3705 SCTP_TCB_UNLOCK(stcb);
3707 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3708 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3709 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3710 SCTP_INP_RLOCK(inp);
3711 av->assoc_value = inp->max_cwnd;
3712 SCTP_INP_RUNLOCK(inp);
3714 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3719 *optsize = sizeof(struct sctp_assoc_value);
3724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3725 error = ENOPROTOOPT;
3727 } /* end switch (sopt->sopt_name) */
3735 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3740 struct sctp_tcb *stcb = NULL;
3741 struct sctp_inpcb *inp = NULL;
3744 if (optval == NULL) {
3745 SCTP_PRINTF("optval is NULL\n");
3746 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3749 inp = (struct sctp_inpcb *)so->so_pcb;
3751 SCTP_PRINTF("inp is NULL?\n");
3752 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3755 vrf_id = inp->def_vrf_id;
3760 case SCTP_AUTOCLOSE:
3761 case SCTP_AUTO_ASCONF:
3762 case SCTP_EXPLICIT_EOR:
3763 case SCTP_DISABLE_FRAGMENTS:
3764 case SCTP_USE_EXT_RCVINFO:
3765 case SCTP_I_WANT_MAPPED_V4_ADDR:
3766 /* copy in the option value */
3767 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3772 case SCTP_DISABLE_FRAGMENTS:
3773 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3775 case SCTP_AUTO_ASCONF:
3777 * NOTE: we don't really support this flag
3779 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3780 /* only valid for bound all sockets */
3781 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3783 /* forbidden by admin */
3784 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3787 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3789 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3793 case SCTP_EXPLICIT_EOR:
3794 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3796 case SCTP_USE_EXT_RCVINFO:
3797 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3799 case SCTP_I_WANT_MAPPED_V4_ADDR:
3800 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3801 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3803 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3808 set_opt = SCTP_PCB_FLAGS_NODELAY;
3810 case SCTP_AUTOCLOSE:
3811 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3812 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3813 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3816 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3818 * The value is in ticks. Note this does not effect
3819 * old associations, only new ones.
3821 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3824 SCTP_INP_WLOCK(inp);
3826 sctp_feature_on(inp, set_opt);
3828 sctp_feature_off(inp, set_opt);
3830 SCTP_INP_WUNLOCK(inp);
3832 case SCTP_REUSE_PORT:
3834 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3835 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3836 /* Can't set it after we are bound */
3840 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3841 /* Can't do this for a 1-m socket */
3846 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3848 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3851 case SCTP_PARTIAL_DELIVERY_POINT:
3855 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3856 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3857 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3861 inp->partial_delivery_point = *value;
3864 case SCTP_FRAGMENT_INTERLEAVE:
3865 /* not yet until we re-write sctp_recvmsg() */
3869 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3870 if (*level == SCTP_FRAG_LEVEL_2) {
3871 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3872 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3873 } else if (*level == SCTP_FRAG_LEVEL_1) {
3874 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3875 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3876 } else if (*level == SCTP_FRAG_LEVEL_0) {
3877 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3878 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3886 case SCTP_INTERLEAVING_SUPPORTED:
3888 struct sctp_assoc_value *av;
3890 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3891 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3894 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3896 SCTP_TCB_UNLOCK(stcb);
3898 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3899 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3900 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3901 SCTP_INP_WLOCK(inp);
3902 if (av->assoc_value == 0) {
3903 inp->idata_supported = 0;
3905 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3906 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3907 inp->idata_supported = 1;
3915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3919 SCTP_INP_WUNLOCK(inp);
3921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3927 case SCTP_CMT_ON_OFF:
3928 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3929 struct sctp_assoc_value *av;
3931 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3932 if (av->assoc_value > SCTP_CMT_MAX) {
3933 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3937 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3939 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3940 SCTP_TCB_UNLOCK(stcb);
3942 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3943 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3944 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3945 (av->assoc_id == SCTP_ALL_ASSOC)) {
3946 SCTP_INP_WLOCK(inp);
3947 inp->sctp_cmt_on_off = av->assoc_value;
3948 SCTP_INP_WUNLOCK(inp);
3950 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3951 (av->assoc_id == SCTP_ALL_ASSOC)) {
3952 SCTP_INP_RLOCK(inp);
3953 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3954 SCTP_TCB_LOCK(stcb);
3955 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3956 SCTP_TCB_UNLOCK(stcb);
3958 SCTP_INP_RUNLOCK(inp);
3962 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3963 error = ENOPROTOOPT;
3966 case SCTP_PLUGGABLE_CC:
3968 struct sctp_assoc_value *av;
3969 struct sctp_nets *net;
3971 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3972 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3973 (av->assoc_value != SCTP_CC_HSTCP) &&
3974 (av->assoc_value != SCTP_CC_HTCP) &&
3975 (av->assoc_value != SCTP_CC_RTCC)) {
3976 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3980 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3982 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3983 stcb->asoc.congestion_control_module = av->assoc_value;
3984 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3985 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3986 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3989 SCTP_TCB_UNLOCK(stcb);
3991 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3992 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3993 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3994 (av->assoc_id == SCTP_ALL_ASSOC)) {
3995 SCTP_INP_WLOCK(inp);
3996 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3997 SCTP_INP_WUNLOCK(inp);
3999 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4000 (av->assoc_id == SCTP_ALL_ASSOC)) {
4001 SCTP_INP_RLOCK(inp);
4002 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4003 SCTP_TCB_LOCK(stcb);
4004 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4005 stcb->asoc.congestion_control_module = av->assoc_value;
4006 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4007 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4008 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4011 SCTP_TCB_UNLOCK(stcb);
4013 SCTP_INP_RUNLOCK(inp);
4018 case SCTP_CC_OPTION:
4020 struct sctp_cc_option *cc_opt;
4022 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4023 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4025 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4026 SCTP_INP_RLOCK(inp);
4027 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4028 SCTP_TCB_LOCK(stcb);
4029 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4030 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4032 SCTP_TCB_UNLOCK(stcb);
4034 SCTP_INP_RUNLOCK(inp);
4039 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4042 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4045 SCTP_TCB_UNLOCK(stcb);
4049 case SCTP_PLUGGABLE_SS:
4051 struct sctp_assoc_value *av;
4053 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4054 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4055 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4056 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4057 (av->assoc_value != SCTP_SS_PRIORITY) &&
4058 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4059 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4060 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4064 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4066 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4067 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4068 stcb->asoc.stream_scheduling_module = av->assoc_value;
4069 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4070 SCTP_TCB_UNLOCK(stcb);
4072 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4073 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4074 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4075 (av->assoc_id == SCTP_ALL_ASSOC)) {
4076 SCTP_INP_WLOCK(inp);
4077 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4078 SCTP_INP_WUNLOCK(inp);
4080 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4081 (av->assoc_id == SCTP_ALL_ASSOC)) {
4082 SCTP_INP_RLOCK(inp);
4083 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4084 SCTP_TCB_LOCK(stcb);
4085 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4086 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4087 stcb->asoc.stream_scheduling_module = av->assoc_value;
4088 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4089 SCTP_TCB_UNLOCK(stcb);
4091 SCTP_INP_RUNLOCK(inp);
4098 struct sctp_stream_value *av;
4100 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4101 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4103 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4104 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4105 av->stream_value) < 0)) {
4106 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4109 SCTP_TCB_UNLOCK(stcb);
4111 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4112 SCTP_INP_RLOCK(inp);
4113 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4114 SCTP_TCB_LOCK(stcb);
4115 if (av->stream_id < stcb->asoc.streamoutcnt) {
4116 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4118 &stcb->asoc.strmout[av->stream_id],
4121 SCTP_TCB_UNLOCK(stcb);
4123 SCTP_INP_RUNLOCK(inp);
4126 * Can't set stream value without
4129 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4135 case SCTP_CLR_STAT_LOG:
4136 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4141 struct sctp_assoc_value *av;
4143 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4144 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4147 stcb->asoc.context = av->assoc_value;
4148 SCTP_TCB_UNLOCK(stcb);
4150 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4151 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4152 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4153 (av->assoc_id == SCTP_ALL_ASSOC)) {
4154 SCTP_INP_WLOCK(inp);
4155 inp->sctp_context = av->assoc_value;
4156 SCTP_INP_WUNLOCK(inp);
4158 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4159 (av->assoc_id == SCTP_ALL_ASSOC)) {
4160 SCTP_INP_RLOCK(inp);
4161 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4162 SCTP_TCB_LOCK(stcb);
4163 stcb->asoc.context = av->assoc_value;
4164 SCTP_TCB_UNLOCK(stcb);
4166 SCTP_INP_RUNLOCK(inp);
4173 uint32_t *default_vrfid;
4175 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4176 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4177 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4181 inp->def_vrf_id = *default_vrfid;
4184 case SCTP_DEL_VRF_ID:
4186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4190 case SCTP_ADD_VRF_ID:
4192 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4196 case SCTP_DELAYED_SACK:
4198 struct sctp_sack_info *sack;
4200 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4201 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4202 if (sack->sack_delay) {
4203 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4204 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4205 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4206 sack->sack_delay = TICKS_TO_MSEC(1);
4210 if (sack->sack_delay) {
4211 stcb->asoc.delayed_ack = sack->sack_delay;
4213 if (sack->sack_freq) {
4214 stcb->asoc.sack_freq = sack->sack_freq;
4216 SCTP_TCB_UNLOCK(stcb);
4218 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4219 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4220 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4221 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4222 SCTP_INP_WLOCK(inp);
4223 if (sack->sack_delay) {
4224 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4226 if (sack->sack_freq) {
4227 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4229 SCTP_INP_WUNLOCK(inp);
4231 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4232 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4233 SCTP_INP_RLOCK(inp);
4234 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4235 SCTP_TCB_LOCK(stcb);
4236 if (sack->sack_delay) {
4237 stcb->asoc.delayed_ack = sack->sack_delay;
4239 if (sack->sack_freq) {
4240 stcb->asoc.sack_freq = sack->sack_freq;
4242 SCTP_TCB_UNLOCK(stcb);
4244 SCTP_INP_RUNLOCK(inp);
4249 case SCTP_AUTH_CHUNK:
4251 struct sctp_authchunk *sauth;
4253 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4255 SCTP_INP_WLOCK(inp);
4256 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4257 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4260 inp->auth_supported = 1;
4262 SCTP_INP_WUNLOCK(inp);
4267 struct sctp_authkey *sca;
4268 struct sctp_keyhead *shared_keys;
4269 sctp_sharedkey_t *shared_key;
4270 sctp_key_t *key = NULL;
4273 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4274 if (sca->sca_keylength == 0) {
4275 size = optsize - sizeof(struct sctp_authkey);
4277 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4278 size = sca->sca_keylength;
4280 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4285 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4288 shared_keys = &stcb->asoc.shared_keys;
4289 /* clear the cached keys for this key id */
4290 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4292 * create the new shared key and
4296 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4298 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4300 SCTP_TCB_UNLOCK(stcb);
4304 shared_key = sctp_alloc_sharedkey();
4305 if (shared_key == NULL) {
4307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4309 SCTP_TCB_UNLOCK(stcb);
4312 shared_key->key = key;
4313 shared_key->keyid = sca->sca_keynumber;
4314 error = sctp_insert_sharedkey(shared_keys, shared_key);
4315 SCTP_TCB_UNLOCK(stcb);
4317 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4318 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4319 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4320 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4321 SCTP_INP_WLOCK(inp);
4322 shared_keys = &inp->sctp_ep.shared_keys;
4324 * clear the cached keys on all
4325 * assocs for this key id
4327 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4329 * create the new shared key and
4333 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4335 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4337 SCTP_INP_WUNLOCK(inp);
4341 shared_key = sctp_alloc_sharedkey();
4342 if (shared_key == NULL) {
4344 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4346 SCTP_INP_WUNLOCK(inp);
4349 shared_key->key = key;
4350 shared_key->keyid = sca->sca_keynumber;
4351 error = sctp_insert_sharedkey(shared_keys, shared_key);
4352 SCTP_INP_WUNLOCK(inp);
4354 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4355 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4356 SCTP_INP_RLOCK(inp);
4357 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4358 SCTP_TCB_LOCK(stcb);
4359 shared_keys = &stcb->asoc.shared_keys;
4361 * clear the cached keys for
4364 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4366 * create the new shared key
4367 * and insert/replace it
4370 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4372 SCTP_TCB_UNLOCK(stcb);
4376 shared_key = sctp_alloc_sharedkey();
4377 if (shared_key == NULL) {
4379 SCTP_TCB_UNLOCK(stcb);
4382 shared_key->key = key;
4383 shared_key->keyid = sca->sca_keynumber;
4384 error = sctp_insert_sharedkey(shared_keys, shared_key);
4385 SCTP_TCB_UNLOCK(stcb);
4387 SCTP_INP_RUNLOCK(inp);
4392 case SCTP_HMAC_IDENT:
4394 struct sctp_hmacalgo *shmac;
4395 sctp_hmaclist_t *hmaclist;
4399 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4400 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4401 (shmac->shmac_number_of_idents > 0xffff)) {
4402 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4407 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4408 if (hmaclist == NULL) {
4409 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4413 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4414 hmacid = shmac->shmac_idents[i];
4415 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4416 /* invalid HMACs were found */ ;
4417 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4419 sctp_free_hmaclist(hmaclist);
4420 goto sctp_set_hmac_done;
4423 for (i = 0; i < hmaclist->num_algo; i++) {
4424 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4425 /* already in list */
4429 if (i == hmaclist->num_algo) {
4430 /* not found in list */
4431 sctp_free_hmaclist(hmaclist);
4432 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4436 /* set it on the endpoint */
4437 SCTP_INP_WLOCK(inp);
4438 if (inp->sctp_ep.local_hmacs)
4439 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4440 inp->sctp_ep.local_hmacs = hmaclist;
4441 SCTP_INP_WUNLOCK(inp);
4445 case SCTP_AUTH_ACTIVE_KEY:
4447 struct sctp_authkeyid *scact;
4449 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4450 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4452 /* set the active key on the right place */
4454 /* set the active key on the assoc */
4455 if (sctp_auth_setactivekey(stcb,
4456 scact->scact_keynumber)) {
4457 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4458 SCTP_FROM_SCTP_USRREQ,
4462 SCTP_TCB_UNLOCK(stcb);
4464 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4465 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4466 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4467 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4468 SCTP_INP_WLOCK(inp);
4469 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4470 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4473 SCTP_INP_WUNLOCK(inp);
4475 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4476 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4477 SCTP_INP_RLOCK(inp);
4478 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4479 SCTP_TCB_LOCK(stcb);
4480 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4481 SCTP_TCB_UNLOCK(stcb);
4483 SCTP_INP_RUNLOCK(inp);
4488 case SCTP_AUTH_DELETE_KEY:
4490 struct sctp_authkeyid *scdel;
4492 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4493 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4495 /* delete the key from the right place */
4497 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4498 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4501 SCTP_TCB_UNLOCK(stcb);
4503 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4504 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4505 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4506 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4507 SCTP_INP_WLOCK(inp);
4508 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4509 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4512 SCTP_INP_WUNLOCK(inp);
4514 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4515 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4516 SCTP_INP_RLOCK(inp);
4517 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4518 SCTP_TCB_LOCK(stcb);
4519 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4520 SCTP_TCB_UNLOCK(stcb);
4522 SCTP_INP_RUNLOCK(inp);
4527 case SCTP_AUTH_DEACTIVATE_KEY:
4529 struct sctp_authkeyid *keyid;
4531 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4532 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4534 /* deactivate the key from the right place */
4536 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4537 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4540 SCTP_TCB_UNLOCK(stcb);
4542 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4543 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4544 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4545 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4546 SCTP_INP_WLOCK(inp);
4547 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4548 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4551 SCTP_INP_WUNLOCK(inp);
4553 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4554 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4555 SCTP_INP_RLOCK(inp);
4556 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4557 SCTP_TCB_LOCK(stcb);
4558 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4559 SCTP_TCB_UNLOCK(stcb);
4561 SCTP_INP_RUNLOCK(inp);
4566 case SCTP_ENABLE_STREAM_RESET:
4568 struct sctp_assoc_value *av;
4570 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4571 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4572 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4576 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4578 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4579 SCTP_TCB_UNLOCK(stcb);
4581 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4582 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4583 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4584 (av->assoc_id == SCTP_ALL_ASSOC)) {
4585 SCTP_INP_WLOCK(inp);
4586 inp->local_strreset_support = (uint8_t)av->assoc_value;
4587 SCTP_INP_WUNLOCK(inp);
4589 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4590 (av->assoc_id == SCTP_ALL_ASSOC)) {
4591 SCTP_INP_RLOCK(inp);
4592 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4593 SCTP_TCB_LOCK(stcb);
4594 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4595 SCTP_TCB_UNLOCK(stcb);
4597 SCTP_INP_RUNLOCK(inp);
4603 case SCTP_RESET_STREAMS:
4605 struct sctp_reset_streams *strrst;
4606 int i, send_out = 0;
4609 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4610 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4612 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4616 if (stcb->asoc.reconfig_supported == 0) {
4618 * Peer does not support the chunk type.
4620 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4622 SCTP_TCB_UNLOCK(stcb);
4625 if (sizeof(struct sctp_reset_streams) +
4626 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4628 SCTP_TCB_UNLOCK(stcb);
4631 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4633 if (stcb->asoc.stream_reset_outstanding) {
4634 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4636 SCTP_TCB_UNLOCK(stcb);
4640 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4643 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4644 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4646 SCTP_TCB_UNLOCK(stcb);
4649 if ((send_in == 0) && (send_out == 0)) {
4650 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4652 SCTP_TCB_UNLOCK(stcb);
4655 for (i = 0; i < strrst->srs_number_streams; i++) {
4657 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4658 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4663 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4664 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4670 SCTP_TCB_UNLOCK(stcb);
4677 if (strrst->srs_number_streams) {
4678 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4679 strm = strrst->srs_stream_list[i];
4680 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4681 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4687 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4688 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4689 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4696 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4697 strrst->srs_stream_list,
4698 send_in, 0, 0, 0, 0, 0);
4700 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4703 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4706 * For outgoing streams don't report any
4707 * problems in sending the request to the
4708 * application. XXX: Double check resetting
4713 SCTP_TCB_UNLOCK(stcb);
4716 case SCTP_ADD_STREAMS:
4718 struct sctp_add_streams *stradd;
4719 uint8_t addstream = 0;
4720 uint16_t add_o_strmcnt = 0;
4721 uint16_t add_i_strmcnt = 0;
4723 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4724 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4726 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4730 if (stcb->asoc.reconfig_supported == 0) {
4732 * Peer does not support the chunk type.
4734 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4736 SCTP_TCB_UNLOCK(stcb);
4739 if (stcb->asoc.stream_reset_outstanding) {
4740 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4742 SCTP_TCB_UNLOCK(stcb);
4745 if ((stradd->sas_outstrms == 0) &&
4746 (stradd->sas_instrms == 0)) {
4750 if (stradd->sas_outstrms) {
4752 /* We allocate here */
4753 add_o_strmcnt = stradd->sas_outstrms;
4754 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4755 /* You can't have more than 64k */
4760 if (stradd->sas_instrms) {
4765 * We allocate inside
4766 * sctp_send_str_reset_req()
4768 add_i_strmcnt = stradd->sas_instrms;
4769 cnt = add_i_strmcnt;
4770 cnt += stcb->asoc.streamincnt;
4771 if (cnt > 0x0000ffff) {
4772 /* You can't have more than 64k */
4776 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4777 /* More than you are allowed */
4782 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4783 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4785 SCTP_TCB_UNLOCK(stcb);
4788 case SCTP_RESET_ASSOC:
4793 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4794 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4796 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4800 if (stcb->asoc.reconfig_supported == 0) {
4802 * Peer does not support the chunk type.
4804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4806 SCTP_TCB_UNLOCK(stcb);
4809 if (stcb->asoc.stream_reset_outstanding) {
4810 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4812 SCTP_TCB_UNLOCK(stcb);
4816 * Is there any data pending in the send or sent
4819 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4820 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4823 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4824 SCTP_TCB_UNLOCK(stcb);
4827 /* Do any streams have data queued? */
4828 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4829 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4833 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4834 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4835 SCTP_TCB_UNLOCK(stcb);
4838 case SCTP_CONNECT_X:
4839 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4840 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4844 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4846 case SCTP_CONNECT_X_DELAYED:
4847 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4848 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4852 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4854 case SCTP_CONNECT_X_COMPLETE:
4856 struct sockaddr *sa;
4858 /* FIXME MT: check correct? */
4859 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4862 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4863 SCTP_INP_RLOCK(inp);
4864 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4866 SCTP_TCB_LOCK(stcb);
4868 SCTP_INP_RUNLOCK(inp);
4871 * We increment here since
4872 * sctp_findassociation_ep_addr() wil do a
4873 * decrement if it finds the stcb as long as
4874 * the locked tcb (last argument) is NOT a
4877 SCTP_INP_INCR_REF(inp);
4878 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4880 SCTP_INP_DECR_REF(inp);
4885 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4889 if (stcb->asoc.delayed_connection == 1) {
4890 stcb->asoc.delayed_connection = 0;
4891 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4892 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4893 stcb->asoc.primary_destination,
4894 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4895 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4898 * already expired or did not use delayed
4901 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4904 SCTP_TCB_UNLOCK(stcb);
4907 case SCTP_MAX_BURST:
4909 struct sctp_assoc_value *av;
4911 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4912 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4915 stcb->asoc.max_burst = av->assoc_value;
4916 SCTP_TCB_UNLOCK(stcb);
4918 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4919 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4920 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4921 (av->assoc_id == SCTP_ALL_ASSOC)) {
4922 SCTP_INP_WLOCK(inp);
4923 inp->sctp_ep.max_burst = av->assoc_value;
4924 SCTP_INP_WUNLOCK(inp);
4926 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4927 (av->assoc_id == SCTP_ALL_ASSOC)) {
4928 SCTP_INP_RLOCK(inp);
4929 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4930 SCTP_TCB_LOCK(stcb);
4931 stcb->asoc.max_burst = av->assoc_value;
4932 SCTP_TCB_UNLOCK(stcb);
4934 SCTP_INP_RUNLOCK(inp);
4941 struct sctp_assoc_value *av;
4944 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4945 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4947 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4948 ovh = SCTP_MED_OVERHEAD;
4950 ovh = SCTP_MED_V4_OVERHEAD;
4953 if (av->assoc_value) {
4954 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4956 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4958 SCTP_TCB_UNLOCK(stcb);
4960 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4961 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4962 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4963 SCTP_INP_WLOCK(inp);
4965 * FIXME MT: I think this is not in
4966 * tune with the API ID
4968 if (av->assoc_value) {
4969 inp->sctp_frag_point = (av->assoc_value + ovh);
4971 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4973 SCTP_INP_WUNLOCK(inp);
4975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4983 struct sctp_event_subscribe *events;
4985 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4987 SCTP_INP_WLOCK(inp);
4988 if (events->sctp_data_io_event) {
4989 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4991 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4994 if (events->sctp_association_event) {
4995 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4997 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5000 if (events->sctp_address_event) {
5001 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5003 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5006 if (events->sctp_send_failure_event) {
5007 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5009 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5012 if (events->sctp_peer_error_event) {
5013 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5015 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5018 if (events->sctp_shutdown_event) {
5019 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5021 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5024 if (events->sctp_partial_delivery_event) {
5025 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5027 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5030 if (events->sctp_adaptation_layer_event) {
5031 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5033 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5036 if (events->sctp_authentication_event) {
5037 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5039 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5042 if (events->sctp_sender_dry_event) {
5043 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5045 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5048 if (events->sctp_stream_reset_event) {
5049 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5051 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5053 SCTP_INP_WUNLOCK(inp);
5055 SCTP_INP_RLOCK(inp);
5056 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5057 SCTP_TCB_LOCK(stcb);
5058 if (events->sctp_association_event) {
5059 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5061 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5063 if (events->sctp_address_event) {
5064 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5066 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5068 if (events->sctp_send_failure_event) {
5069 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5071 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5073 if (events->sctp_peer_error_event) {
5074 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5076 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5078 if (events->sctp_shutdown_event) {
5079 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5081 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5083 if (events->sctp_partial_delivery_event) {
5084 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5086 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5088 if (events->sctp_adaptation_layer_event) {
5089 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5091 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5093 if (events->sctp_authentication_event) {
5094 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5096 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5098 if (events->sctp_sender_dry_event) {
5099 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5101 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5103 if (events->sctp_stream_reset_event) {
5104 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5106 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5108 SCTP_TCB_UNLOCK(stcb);
5111 * Send up the sender dry event only for 1-to-1
5114 if (events->sctp_sender_dry_event) {
5115 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5116 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5117 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5119 SCTP_TCB_LOCK(stcb);
5120 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5121 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5122 (stcb->asoc.stream_queue_cnt == 0)) {
5123 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5125 SCTP_TCB_UNLOCK(stcb);
5129 SCTP_INP_RUNLOCK(inp);
5132 case SCTP_ADAPTATION_LAYER:
5134 struct sctp_setadaptation *adap_bits;
5136 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5137 SCTP_INP_WLOCK(inp);
5138 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5139 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5140 SCTP_INP_WUNLOCK(inp);
5144 case SCTP_SET_INITIAL_DBG_SEQ:
5148 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5149 SCTP_INP_WLOCK(inp);
5150 inp->sctp_ep.initial_sequence_debug = *vvv;
5151 SCTP_INP_WUNLOCK(inp);
5155 case SCTP_DEFAULT_SEND_PARAM:
5157 struct sctp_sndrcvinfo *s_info;
5159 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5160 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5163 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5164 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5166 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5169 SCTP_TCB_UNLOCK(stcb);
5171 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5172 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5173 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5174 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5175 SCTP_INP_WLOCK(inp);
5176 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5177 SCTP_INP_WUNLOCK(inp);
5179 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5180 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5181 SCTP_INP_RLOCK(inp);
5182 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5183 SCTP_TCB_LOCK(stcb);
5184 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5185 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5187 SCTP_TCB_UNLOCK(stcb);
5189 SCTP_INP_RUNLOCK(inp);
5194 case SCTP_PEER_ADDR_PARAMS:
5196 struct sctp_paddrparams *paddrp;
5197 struct sctp_nets *net;
5198 struct sockaddr *addr;
5199 #if defined(INET) && defined(INET6)
5200 struct sockaddr_in sin_store;
5203 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5204 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5206 #if defined(INET) && defined(INET6)
5207 if (paddrp->spp_address.ss_family == AF_INET6) {
5208 struct sockaddr_in6 *sin6;
5210 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5211 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5212 in6_sin6_2_sin(&sin_store, sin6);
5213 addr = (struct sockaddr *)&sin_store;
5215 addr = (struct sockaddr *)&paddrp->spp_address;
5218 addr = (struct sockaddr *)&paddrp->spp_address;
5221 addr = (struct sockaddr *)&paddrp->spp_address;
5224 net = sctp_findnet(stcb, addr);
5227 * We increment here since
5228 * sctp_findassociation_ep_addr() wil do a
5229 * decrement if it finds the stcb as long as
5230 * the locked tcb (last argument) is NOT a
5234 SCTP_INP_INCR_REF(inp);
5235 stcb = sctp_findassociation_ep_addr(&inp, addr,
5238 SCTP_INP_DECR_REF(inp);
5241 if ((stcb != NULL) && (net == NULL)) {
5243 if (addr->sa_family == AF_INET) {
5245 struct sockaddr_in *sin;
5247 sin = (struct sockaddr_in *)addr;
5248 if (sin->sin_addr.s_addr != INADDR_ANY) {
5249 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5250 SCTP_TCB_UNLOCK(stcb);
5257 if (addr->sa_family == AF_INET6) {
5258 struct sockaddr_in6 *sin6;
5260 sin6 = (struct sockaddr_in6 *)addr;
5261 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5262 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5263 SCTP_TCB_UNLOCK(stcb);
5270 error = EAFNOSUPPORT;
5271 SCTP_TCB_UNLOCK(stcb);
5272 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5277 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5279 SCTP_TCB_UNLOCK(stcb);
5280 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5284 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5286 SCTP_TCB_UNLOCK(stcb);
5287 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5292 /************************TCB SPECIFIC SET ******************/
5294 /************************NET SPECIFIC SET ******************/
5295 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5296 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5297 !(net->dest_state & SCTP_ADDR_NOHB)) {
5298 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5299 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5301 net->dest_state |= SCTP_ADDR_NOHB;
5303 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5304 if (paddrp->spp_hbinterval) {
5305 net->heart_beat_delay = paddrp->spp_hbinterval;
5306 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5307 net->heart_beat_delay = 0;
5309 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5310 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5311 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5312 net->dest_state &= ~SCTP_ADDR_NOHB;
5314 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5316 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5317 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5318 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5320 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5321 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5322 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5323 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5325 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5326 net->mtu = paddrp->spp_pathmtu;
5327 switch (net->ro._l_addr.sa.sa_family) {
5330 net->mtu += SCTP_MIN_V4_OVERHEAD;
5335 net->mtu += SCTP_MIN_OVERHEAD;
5341 if (net->mtu < stcb->asoc.smallest_mtu) {
5342 sctp_pathmtu_adjustment(stcb, net->mtu);
5345 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5346 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5347 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5349 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5351 if (paddrp->spp_pathmaxrxt) {
5352 if (net->dest_state & SCTP_ADDR_PF) {
5353 if (net->error_count > paddrp->spp_pathmaxrxt) {
5354 net->dest_state &= ~SCTP_ADDR_PF;
5357 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5358 (net->error_count > net->pf_threshold)) {
5359 net->dest_state |= SCTP_ADDR_PF;
5360 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5361 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5362 stcb->sctp_ep, stcb, net,
5363 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5364 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5367 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5368 if (net->error_count > paddrp->spp_pathmaxrxt) {
5369 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5370 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5373 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5374 net->dest_state |= SCTP_ADDR_REACHABLE;
5375 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5378 net->failure_threshold = paddrp->spp_pathmaxrxt;
5380 if (paddrp->spp_flags & SPP_DSCP) {
5381 net->dscp = paddrp->spp_dscp & 0xfc;
5385 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5386 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5387 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5388 net->flowlabel |= 0x80000000;
5393 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5394 if (paddrp->spp_pathmaxrxt != 0) {
5395 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5396 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5397 if (net->dest_state & SCTP_ADDR_PF) {
5398 if (net->error_count > paddrp->spp_pathmaxrxt) {
5399 net->dest_state &= ~SCTP_ADDR_PF;
5402 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5403 (net->error_count > net->pf_threshold)) {
5404 net->dest_state |= SCTP_ADDR_PF;
5405 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5406 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5407 stcb->sctp_ep, stcb, net,
5408 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5409 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5412 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5413 if (net->error_count > paddrp->spp_pathmaxrxt) {
5414 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5415 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5418 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5419 net->dest_state |= SCTP_ADDR_REACHABLE;
5420 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5423 net->failure_threshold = paddrp->spp_pathmaxrxt;
5427 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5428 if (paddrp->spp_hbinterval != 0) {
5429 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5430 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5431 stcb->asoc.heart_beat_delay = 0;
5433 /* Turn back on the timer */
5434 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5435 if (paddrp->spp_hbinterval != 0) {
5436 net->heart_beat_delay = paddrp->spp_hbinterval;
5437 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5438 net->heart_beat_delay = 0;
5440 if (net->dest_state & SCTP_ADDR_NOHB) {
5441 net->dest_state &= ~SCTP_ADDR_NOHB;
5443 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5444 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5445 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5447 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5449 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5450 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5451 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5452 net->dest_state |= SCTP_ADDR_NOHB;
5453 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5454 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5456 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5460 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5462 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5463 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5464 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5465 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5466 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5468 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5469 net->mtu = paddrp->spp_pathmtu;
5470 switch (net->ro._l_addr.sa.sa_family) {
5473 net->mtu += SCTP_MIN_V4_OVERHEAD;
5478 net->mtu += SCTP_MIN_OVERHEAD;
5484 if (net->mtu < stcb->asoc.smallest_mtu) {
5485 sctp_pathmtu_adjustment(stcb, net->mtu);
5488 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5489 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5491 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5492 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5493 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5494 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5496 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5498 stcb->asoc.default_mtu = 0;
5499 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5501 if (paddrp->spp_flags & SPP_DSCP) {
5502 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5503 net->dscp = paddrp->spp_dscp & 0xfc;
5506 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5507 stcb->asoc.default_dscp |= 0x01;
5510 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5511 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5512 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5513 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5514 net->flowlabel |= 0x80000000;
5517 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5518 stcb->asoc.default_flowlabel |= 0x80000000;
5522 SCTP_TCB_UNLOCK(stcb);
5524 /************************NO TCB, SET TO default stuff ******************/
5525 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5526 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5527 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5528 SCTP_INP_WLOCK(inp);
5530 * For the TOS/FLOWLABEL stuff you
5531 * set it with the options on the
5534 if (paddrp->spp_pathmaxrxt != 0) {
5535 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5538 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5539 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5540 else if (paddrp->spp_hbinterval != 0) {
5541 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5542 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5543 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5546 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5547 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5548 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5549 } else if (paddrp->spp_hbinterval) {
5550 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5552 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5553 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5554 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5556 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5557 inp->sctp_ep.default_mtu = 0;
5558 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5559 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5560 if (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU) {
5561 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5563 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5565 if (paddrp->spp_flags & SPP_DSCP) {
5566 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5567 inp->sctp_ep.default_dscp |= 0x01;
5570 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5571 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5572 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5573 inp->sctp_ep.default_flowlabel |= 0x80000000;
5577 SCTP_INP_WUNLOCK(inp);
5579 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5587 struct sctp_rtoinfo *srto;
5588 uint32_t new_init, new_min, new_max;
5590 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5591 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5594 if (srto->srto_initial)
5595 new_init = srto->srto_initial;
5597 new_init = stcb->asoc.initial_rto;
5599 new_max = srto->srto_max;
5601 new_max = stcb->asoc.maxrto;
5603 new_min = srto->srto_min;
5605 new_min = stcb->asoc.minrto;
5606 if ((new_min <= new_init) && (new_init <= new_max)) {
5607 stcb->asoc.initial_rto = new_init;
5608 stcb->asoc.maxrto = new_max;
5609 stcb->asoc.minrto = new_min;
5611 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5614 SCTP_TCB_UNLOCK(stcb);
5616 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5617 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5618 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5619 SCTP_INP_WLOCK(inp);
5620 if (srto->srto_initial)
5621 new_init = srto->srto_initial;
5623 new_init = inp->sctp_ep.initial_rto;
5625 new_max = srto->srto_max;
5627 new_max = inp->sctp_ep.sctp_maxrto;
5629 new_min = srto->srto_min;
5631 new_min = inp->sctp_ep.sctp_minrto;
5632 if ((new_min <= new_init) && (new_init <= new_max)) {
5633 inp->sctp_ep.initial_rto = new_init;
5634 inp->sctp_ep.sctp_maxrto = new_max;
5635 inp->sctp_ep.sctp_minrto = new_min;
5637 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5640 SCTP_INP_WUNLOCK(inp);
5642 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5648 case SCTP_ASSOCINFO:
5650 struct sctp_assocparams *sasoc;
5652 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5653 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5654 if (sasoc->sasoc_cookie_life) {
5655 /* boundary check the cookie life */
5656 if (sasoc->sasoc_cookie_life < 1000)
5657 sasoc->sasoc_cookie_life = 1000;
5658 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5659 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5663 if (sasoc->sasoc_asocmaxrxt)
5664 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5665 if (sasoc->sasoc_cookie_life) {
5666 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5668 SCTP_TCB_UNLOCK(stcb);
5670 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5671 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5672 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5673 SCTP_INP_WLOCK(inp);
5674 if (sasoc->sasoc_asocmaxrxt)
5675 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5676 if (sasoc->sasoc_cookie_life) {
5677 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5679 SCTP_INP_WUNLOCK(inp);
5681 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5689 struct sctp_initmsg *sinit;
5691 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5692 SCTP_INP_WLOCK(inp);
5693 if (sinit->sinit_num_ostreams)
5694 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5696 if (sinit->sinit_max_instreams)
5697 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5699 if (sinit->sinit_max_attempts)
5700 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5702 if (sinit->sinit_max_init_timeo)
5703 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5704 SCTP_INP_WUNLOCK(inp);
5707 case SCTP_PRIMARY_ADDR:
5709 struct sctp_setprim *spa;
5710 struct sctp_nets *net;
5711 struct sockaddr *addr;
5712 #if defined(INET) && defined(INET6)
5713 struct sockaddr_in sin_store;
5716 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5717 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5719 #if defined(INET) && defined(INET6)
5720 if (spa->ssp_addr.ss_family == AF_INET6) {
5721 struct sockaddr_in6 *sin6;
5723 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5724 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5725 in6_sin6_2_sin(&sin_store, sin6);
5726 addr = (struct sockaddr *)&sin_store;
5728 addr = (struct sockaddr *)&spa->ssp_addr;
5731 addr = (struct sockaddr *)&spa->ssp_addr;
5734 addr = (struct sockaddr *)&spa->ssp_addr;
5737 net = sctp_findnet(stcb, addr);
5740 * We increment here since
5741 * sctp_findassociation_ep_addr() wil do a
5742 * decrement if it finds the stcb as long as
5743 * the locked tcb (last argument) is NOT a
5747 SCTP_INP_INCR_REF(inp);
5748 stcb = sctp_findassociation_ep_addr(&inp, addr,
5751 SCTP_INP_DECR_REF(inp);
5755 if ((stcb != NULL) && (net != NULL)) {
5756 if (net != stcb->asoc.primary_destination) {
5757 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5758 /* Ok we need to set it */
5759 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5760 if ((stcb->asoc.alternate) &&
5761 (!(net->dest_state & SCTP_ADDR_PF)) &&
5762 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5763 sctp_free_remote_addr(stcb->asoc.alternate);
5764 stcb->asoc.alternate = NULL;
5767 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5771 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5780 SCTP_TCB_UNLOCK(stcb);
5784 case SCTP_SET_DYNAMIC_PRIMARY:
5786 union sctp_sockstore *ss;
5788 error = priv_check(curthread,
5789 PRIV_NETINET_RESERVEDPORT);
5793 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5794 /* SUPER USER CHECK? */
5795 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5798 case SCTP_SET_PEER_PRIMARY_ADDR:
5800 struct sctp_setpeerprim *sspp;
5801 struct sockaddr *addr;
5802 #if defined(INET) && defined(INET6)
5803 struct sockaddr_in sin_store;
5806 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5807 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5809 struct sctp_ifa *ifa;
5811 #if defined(INET) && defined(INET6)
5812 if (sspp->sspp_addr.ss_family == AF_INET6) {
5813 struct sockaddr_in6 *sin6;
5815 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5816 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5817 in6_sin6_2_sin(&sin_store, sin6);
5818 addr = (struct sockaddr *)&sin_store;
5820 addr = (struct sockaddr *)&sspp->sspp_addr;
5823 addr = (struct sockaddr *)&sspp->sspp_addr;
5826 addr = (struct sockaddr *)&sspp->sspp_addr;
5828 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5830 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5834 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5836 * Must validate the ifa found is in
5839 struct sctp_laddr *laddr;
5842 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5843 if (laddr->ifa == NULL) {
5844 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5848 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5849 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5852 if (laddr->ifa == ifa) {
5858 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5863 switch (addr->sa_family) {
5867 struct sockaddr_in *sin;
5869 sin = (struct sockaddr_in *)addr;
5870 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5871 &sin->sin_addr) != 0) {
5872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5882 struct sockaddr_in6 *sin6;
5884 sin6 = (struct sockaddr_in6 *)addr;
5885 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5886 &sin6->sin6_addr) != 0) {
5887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5895 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5900 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5901 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5904 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5906 SCTP_TCB_UNLOCK(stcb);
5908 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5913 case SCTP_BINDX_ADD_ADDR:
5915 struct sctp_getaddresses *addrs;
5918 td = (struct thread *)p;
5919 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5922 if (addrs->addr->sa_family == AF_INET) {
5923 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5928 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5929 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5935 if (addrs->addr->sa_family == AF_INET6) {
5936 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5937 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5941 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5942 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5943 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5949 error = EAFNOSUPPORT;
5952 sctp_bindx_add_address(so, inp, addrs->addr,
5953 addrs->sget_assoc_id, vrf_id,
5957 case SCTP_BINDX_REM_ADDR:
5959 struct sctp_getaddresses *addrs;
5962 td = (struct thread *)p;
5964 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5966 if (addrs->addr->sa_family == AF_INET) {
5967 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5972 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5973 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5979 if (addrs->addr->sa_family == AF_INET6) {
5980 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5986 (error = prison_local_ip6(td->td_ucred,
5987 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5988 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5989 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5995 error = EAFNOSUPPORT;
5998 sctp_bindx_delete_address(inp, addrs->addr,
5999 addrs->sget_assoc_id, vrf_id,
6005 struct sctp_event *event;
6006 uint32_t event_type;
6008 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6009 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6010 switch (event->se_type) {
6011 case SCTP_ASSOC_CHANGE:
6012 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6014 case SCTP_PEER_ADDR_CHANGE:
6015 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6017 case SCTP_REMOTE_ERROR:
6018 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6020 case SCTP_SEND_FAILED:
6021 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6023 case SCTP_SHUTDOWN_EVENT:
6024 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6026 case SCTP_ADAPTATION_INDICATION:
6027 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6029 case SCTP_PARTIAL_DELIVERY_EVENT:
6030 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6032 case SCTP_AUTHENTICATION_EVENT:
6033 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6035 case SCTP_STREAM_RESET_EVENT:
6036 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6038 case SCTP_SENDER_DRY_EVENT:
6039 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6041 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6043 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6046 case SCTP_ASSOC_RESET_EVENT:
6047 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6049 case SCTP_STREAM_CHANGE_EVENT:
6050 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6052 case SCTP_SEND_FAILED_EVENT:
6053 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6057 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6061 if (event_type > 0) {
6064 sctp_stcb_feature_on(inp, stcb, event_type);
6065 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6066 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6067 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6068 (stcb->asoc.stream_queue_cnt == 0)) {
6069 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6073 sctp_stcb_feature_off(inp, stcb, event_type);
6075 SCTP_TCB_UNLOCK(stcb);
6078 * We don't want to send up a storm
6079 * of events, so return an error for
6082 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6083 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6084 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6085 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6086 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6087 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6091 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6092 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6093 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6094 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6095 SCTP_INP_WLOCK(inp);
6097 sctp_feature_on(inp, event_type);
6099 sctp_feature_off(inp, event_type);
6101 SCTP_INP_WUNLOCK(inp);
6103 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6104 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6105 SCTP_INP_RLOCK(inp);
6106 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6107 SCTP_TCB_LOCK(stcb);
6109 sctp_stcb_feature_on(inp, stcb, event_type);
6111 sctp_stcb_feature_off(inp, stcb, event_type);
6113 SCTP_TCB_UNLOCK(stcb);
6115 SCTP_INP_RUNLOCK(inp);
6121 case SCTP_RECVRCVINFO:
6125 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6126 SCTP_INP_WLOCK(inp);
6128 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6130 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6132 SCTP_INP_WUNLOCK(inp);
6135 case SCTP_RECVNXTINFO:
6139 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6140 SCTP_INP_WLOCK(inp);
6142 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6144 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6146 SCTP_INP_WUNLOCK(inp);
6149 case SCTP_DEFAULT_SNDINFO:
6151 struct sctp_sndinfo *info;
6154 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6155 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6158 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6159 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6160 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6161 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6162 stcb->asoc.def_send.sinfo_flags |= policy;
6163 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6164 stcb->asoc.def_send.sinfo_context = info->snd_context;
6166 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6169 SCTP_TCB_UNLOCK(stcb);
6171 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6172 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6173 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6174 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6175 SCTP_INP_WLOCK(inp);
6176 inp->def_send.sinfo_stream = info->snd_sid;
6177 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6178 inp->def_send.sinfo_flags = info->snd_flags;
6179 inp->def_send.sinfo_flags |= policy;
6180 inp->def_send.sinfo_ppid = info->snd_ppid;
6181 inp->def_send.sinfo_context = info->snd_context;
6182 SCTP_INP_WUNLOCK(inp);
6184 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6185 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6186 SCTP_INP_RLOCK(inp);
6187 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6188 SCTP_TCB_LOCK(stcb);
6189 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6190 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6191 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6192 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6193 stcb->asoc.def_send.sinfo_flags |= policy;
6194 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6195 stcb->asoc.def_send.sinfo_context = info->snd_context;
6197 SCTP_TCB_UNLOCK(stcb);
6199 SCTP_INP_RUNLOCK(inp);
6204 case SCTP_DEFAULT_PRINFO:
6206 struct sctp_default_prinfo *info;
6208 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6209 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6211 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6212 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6217 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6218 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6219 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6220 SCTP_TCB_UNLOCK(stcb);
6222 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6223 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6224 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6225 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6226 SCTP_INP_WLOCK(inp);
6227 inp->def_send.sinfo_flags &= 0xfff0;
6228 inp->def_send.sinfo_flags |= info->pr_policy;
6229 inp->def_send.sinfo_timetolive = info->pr_value;
6230 SCTP_INP_WUNLOCK(inp);
6232 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6233 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6234 SCTP_INP_RLOCK(inp);
6235 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6236 SCTP_TCB_LOCK(stcb);
6237 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6238 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6239 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6240 SCTP_TCB_UNLOCK(stcb);
6242 SCTP_INP_RUNLOCK(inp);
6247 case SCTP_PEER_ADDR_THLDS:
6248 /* Applies to the specific association */
6250 struct sctp_paddrthlds *thlds;
6251 struct sctp_nets *net;
6252 struct sockaddr *addr;
6253 #if defined(INET) && defined(INET6)
6254 struct sockaddr_in sin_store;
6257 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6258 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6260 #if defined(INET) && defined(INET6)
6261 if (thlds->spt_address.ss_family == AF_INET6) {
6262 struct sockaddr_in6 *sin6;
6264 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6265 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6266 in6_sin6_2_sin(&sin_store, sin6);
6267 addr = (struct sockaddr *)&sin_store;
6269 addr = (struct sockaddr *)&thlds->spt_address;
6272 addr = (struct sockaddr *)&thlds->spt_address;
6275 addr = (struct sockaddr *)&thlds->spt_address;
6278 net = sctp_findnet(stcb, addr);
6281 * We increment here since
6282 * sctp_findassociation_ep_addr() wil do a
6283 * decrement if it finds the stcb as long as
6284 * the locked tcb (last argument) is NOT a
6288 SCTP_INP_INCR_REF(inp);
6289 stcb = sctp_findassociation_ep_addr(&inp, addr,
6292 SCTP_INP_DECR_REF(inp);
6295 if ((stcb != NULL) && (net == NULL)) {
6297 if (addr->sa_family == AF_INET) {
6299 struct sockaddr_in *sin;
6301 sin = (struct sockaddr_in *)addr;
6302 if (sin->sin_addr.s_addr != INADDR_ANY) {
6303 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6304 SCTP_TCB_UNLOCK(stcb);
6311 if (addr->sa_family == AF_INET6) {
6312 struct sockaddr_in6 *sin6;
6314 sin6 = (struct sockaddr_in6 *)addr;
6315 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6316 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6317 SCTP_TCB_UNLOCK(stcb);
6324 error = EAFNOSUPPORT;
6325 SCTP_TCB_UNLOCK(stcb);
6326 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6330 if (thlds->spt_pathcpthld != 0xffff) {
6332 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6337 net->failure_threshold = thlds->spt_pathmaxrxt;
6338 net->pf_threshold = thlds->spt_pathpfthld;
6339 if (net->dest_state & SCTP_ADDR_PF) {
6340 if ((net->error_count > net->failure_threshold) ||
6341 (net->error_count <= net->pf_threshold)) {
6342 net->dest_state &= ~SCTP_ADDR_PF;
6345 if ((net->error_count > net->pf_threshold) &&
6346 (net->error_count <= net->failure_threshold)) {
6347 net->dest_state |= SCTP_ADDR_PF;
6348 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6349 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6350 stcb->sctp_ep, stcb, net,
6351 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6352 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6355 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6356 if (net->error_count > net->failure_threshold) {
6357 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6358 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6361 if (net->error_count <= net->failure_threshold) {
6362 net->dest_state |= SCTP_ADDR_REACHABLE;
6363 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6367 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6368 net->failure_threshold = thlds->spt_pathmaxrxt;
6369 net->pf_threshold = thlds->spt_pathpfthld;
6370 if (net->dest_state & SCTP_ADDR_PF) {
6371 if ((net->error_count > net->failure_threshold) ||
6372 (net->error_count <= net->pf_threshold)) {
6373 net->dest_state &= ~SCTP_ADDR_PF;
6376 if ((net->error_count > net->pf_threshold) &&
6377 (net->error_count <= net->failure_threshold)) {
6378 net->dest_state |= SCTP_ADDR_PF;
6379 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6380 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6381 stcb->sctp_ep, stcb, net,
6382 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6383 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6386 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6387 if (net->error_count > net->failure_threshold) {
6388 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6389 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6392 if (net->error_count <= net->failure_threshold) {
6393 net->dest_state |= SCTP_ADDR_REACHABLE;
6394 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6398 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6399 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6401 SCTP_TCB_UNLOCK(stcb);
6403 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6404 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6405 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6406 SCTP_INP_WLOCK(inp);
6407 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6408 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6409 SCTP_INP_WUNLOCK(inp);
6411 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6417 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6419 struct sctp_udpencaps *encaps;
6420 struct sctp_nets *net;
6421 struct sockaddr *addr;
6422 #if defined(INET) && defined(INET6)
6423 struct sockaddr_in sin_store;
6426 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6427 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6429 #if defined(INET) && defined(INET6)
6430 if (encaps->sue_address.ss_family == AF_INET6) {
6431 struct sockaddr_in6 *sin6;
6433 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6434 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6435 in6_sin6_2_sin(&sin_store, sin6);
6436 addr = (struct sockaddr *)&sin_store;
6438 addr = (struct sockaddr *)&encaps->sue_address;
6441 addr = (struct sockaddr *)&encaps->sue_address;
6444 addr = (struct sockaddr *)&encaps->sue_address;
6447 net = sctp_findnet(stcb, addr);
6450 * We increment here since
6451 * sctp_findassociation_ep_addr() wil do a
6452 * decrement if it finds the stcb as long as
6453 * the locked tcb (last argument) is NOT a
6457 SCTP_INP_INCR_REF(inp);
6458 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6460 SCTP_INP_DECR_REF(inp);
6463 if ((stcb != NULL) && (net == NULL)) {
6465 if (addr->sa_family == AF_INET) {
6467 struct sockaddr_in *sin;
6469 sin = (struct sockaddr_in *)addr;
6470 if (sin->sin_addr.s_addr != INADDR_ANY) {
6471 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6472 SCTP_TCB_UNLOCK(stcb);
6479 if (addr->sa_family == AF_INET6) {
6480 struct sockaddr_in6 *sin6;
6482 sin6 = (struct sockaddr_in6 *)addr;
6483 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6484 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6485 SCTP_TCB_UNLOCK(stcb);
6492 error = EAFNOSUPPORT;
6493 SCTP_TCB_UNLOCK(stcb);
6494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6501 net->port = encaps->sue_port;
6503 stcb->asoc.port = encaps->sue_port;
6505 SCTP_TCB_UNLOCK(stcb);
6507 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6508 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6509 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6510 SCTP_INP_WLOCK(inp);
6511 inp->sctp_ep.port = encaps->sue_port;
6512 SCTP_INP_WUNLOCK(inp);
6514 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6520 case SCTP_ECN_SUPPORTED:
6522 struct sctp_assoc_value *av;
6524 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6525 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6530 SCTP_TCB_UNLOCK(stcb);
6532 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6533 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6534 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6535 SCTP_INP_WLOCK(inp);
6536 if (av->assoc_value == 0) {
6537 inp->ecn_supported = 0;
6539 inp->ecn_supported = 1;
6541 SCTP_INP_WUNLOCK(inp);
6543 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6549 case SCTP_PR_SUPPORTED:
6551 struct sctp_assoc_value *av;
6553 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6554 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6557 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6559 SCTP_TCB_UNLOCK(stcb);
6561 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6562 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6563 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6564 SCTP_INP_WLOCK(inp);
6565 if (av->assoc_value == 0) {
6566 inp->prsctp_supported = 0;
6568 inp->prsctp_supported = 1;
6570 SCTP_INP_WUNLOCK(inp);
6572 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6578 case SCTP_AUTH_SUPPORTED:
6580 struct sctp_assoc_value *av;
6582 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6583 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6586 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6588 SCTP_TCB_UNLOCK(stcb);
6590 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6591 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6592 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6593 if ((av->assoc_value == 0) &&
6594 (inp->asconf_supported == 1)) {
6596 * AUTH is required for
6599 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6602 SCTP_INP_WLOCK(inp);
6603 if (av->assoc_value == 0) {
6604 inp->auth_supported = 0;
6606 inp->auth_supported = 1;
6608 SCTP_INP_WUNLOCK(inp);
6611 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6617 case SCTP_ASCONF_SUPPORTED:
6619 struct sctp_assoc_value *av;
6621 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6622 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6625 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6627 SCTP_TCB_UNLOCK(stcb);
6629 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6630 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6631 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6632 if ((av->assoc_value != 0) &&
6633 (inp->auth_supported == 0)) {
6635 * AUTH is required for
6638 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6641 SCTP_INP_WLOCK(inp);
6642 if (av->assoc_value == 0) {
6643 inp->asconf_supported = 0;
6644 sctp_auth_delete_chunk(SCTP_ASCONF,
6645 inp->sctp_ep.local_auth_chunks);
6646 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6647 inp->sctp_ep.local_auth_chunks);
6649 inp->asconf_supported = 1;
6650 sctp_auth_add_chunk(SCTP_ASCONF,
6651 inp->sctp_ep.local_auth_chunks);
6652 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6653 inp->sctp_ep.local_auth_chunks);
6655 SCTP_INP_WUNLOCK(inp);
6658 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6664 case SCTP_RECONFIG_SUPPORTED:
6666 struct sctp_assoc_value *av;
6668 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6669 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6672 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6674 SCTP_TCB_UNLOCK(stcb);
6676 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6677 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6678 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6679 SCTP_INP_WLOCK(inp);
6680 if (av->assoc_value == 0) {
6681 inp->reconfig_supported = 0;
6683 inp->reconfig_supported = 1;
6685 SCTP_INP_WUNLOCK(inp);
6687 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6693 case SCTP_NRSACK_SUPPORTED:
6695 struct sctp_assoc_value *av;
6697 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6698 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6701 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6703 SCTP_TCB_UNLOCK(stcb);
6705 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6706 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6707 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6708 SCTP_INP_WLOCK(inp);
6709 if (av->assoc_value == 0) {
6710 inp->nrsack_supported = 0;
6712 inp->nrsack_supported = 1;
6714 SCTP_INP_WUNLOCK(inp);
6716 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6722 case SCTP_PKTDROP_SUPPORTED:
6724 struct sctp_assoc_value *av;
6726 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6727 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6730 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6732 SCTP_TCB_UNLOCK(stcb);
6734 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6735 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6736 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6737 SCTP_INP_WLOCK(inp);
6738 if (av->assoc_value == 0) {
6739 inp->pktdrop_supported = 0;
6741 inp->pktdrop_supported = 1;
6743 SCTP_INP_WUNLOCK(inp);
6745 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6753 struct sctp_assoc_value *av;
6754 struct sctp_nets *net;
6756 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6757 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6760 stcb->asoc.max_cwnd = av->assoc_value;
6761 if (stcb->asoc.max_cwnd > 0) {
6762 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6763 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6764 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6765 net->cwnd = stcb->asoc.max_cwnd;
6766 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6767 net->cwnd = net->mtu - sizeof(struct sctphdr);
6772 SCTP_TCB_UNLOCK(stcb);
6774 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6775 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6776 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6777 SCTP_INP_WLOCK(inp);
6778 inp->max_cwnd = av->assoc_value;
6779 SCTP_INP_WUNLOCK(inp);
6781 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6788 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6789 error = ENOPROTOOPT;
6791 } /* end switch (opt) */
6796 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6798 void *optval = NULL;
6802 struct sctp_inpcb *inp;
6804 if ((sopt->sopt_level == SOL_SOCKET) &&
6805 (sopt->sopt_name == SO_SETFIB)) {
6806 inp = (struct sctp_inpcb *)so->so_pcb;
6808 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6811 SCTP_INP_WLOCK(inp);
6812 inp->fibnum = so->so_fibnum;
6813 SCTP_INP_WUNLOCK(inp);
6816 if (sopt->sopt_level != IPPROTO_SCTP) {
6817 /* wrong proto level... send back up to IP */
6819 if (INP_CHECK_SOCKAF(so, AF_INET6))
6820 error = ip6_ctloutput(so, sopt);
6822 #if defined(INET) && defined(INET6)
6826 error = ip_ctloutput(so, sopt);
6830 optsize = sopt->sopt_valsize;
6832 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6833 if (optval == NULL) {
6834 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6837 error = sooptcopyin(sopt, optval, optsize, optsize);
6839 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6843 p = (void *)sopt->sopt_td;
6844 if (sopt->sopt_dir == SOPT_SET) {
6845 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6846 } else if (sopt->sopt_dir == SOPT_GET) {
6847 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6849 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6852 if ((error == 0) && (optval != NULL)) {
6853 error = sooptcopyout(sopt, optval, optsize);
6854 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6855 } else if (optval != NULL) {
6856 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6864 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6867 int create_lock_on = 0;
6869 struct sctp_inpcb *inp;
6870 struct sctp_tcb *stcb = NULL;
6872 inp = (struct sctp_inpcb *)so->so_pcb;
6874 /* I made the same as TCP since we are not setup? */
6875 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6876 return (ECONNRESET);
6879 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6883 switch (addr->sa_family) {
6887 struct sockaddr_in6 *sin6p;
6889 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6890 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6893 sin6p = (struct sockaddr_in6 *)addr;
6894 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6895 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6904 struct sockaddr_in *sinp;
6906 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6907 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6910 sinp = (struct sockaddr_in *)addr;
6911 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6912 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6919 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6920 return (EAFNOSUPPORT);
6922 SCTP_INP_INCR_REF(inp);
6923 SCTP_ASOC_CREATE_LOCK(inp);
6927 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6928 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6929 /* Should I really unlock ? */
6930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6935 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6936 (addr->sa_family == AF_INET6)) {
6937 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6942 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6943 SCTP_PCB_FLAGS_UNBOUND) {
6944 /* Bind a ephemeral port */
6945 error = sctp_inpcb_bind(so, NULL, NULL, p);
6950 /* Now do we connect? */
6951 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6952 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6953 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6957 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6958 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6959 /* We are already connected AND the TCP model */
6960 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6964 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6965 SCTP_INP_RLOCK(inp);
6966 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6967 SCTP_INP_RUNLOCK(inp);
6970 * We increment here since sctp_findassociation_ep_addr()
6971 * will do a decrement if it finds the stcb as long as the
6972 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6974 SCTP_INP_INCR_REF(inp);
6975 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6977 SCTP_INP_DECR_REF(inp);
6979 SCTP_TCB_UNLOCK(stcb);
6983 /* Already have or am bring up an association */
6984 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6989 vrf_id = inp->def_vrf_id;
6990 /* We are GOOD to go */
6991 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
6992 inp->sctp_ep.pre_open_stream_count,
6993 inp->sctp_ep.port, p);
6995 /* Gak! no memory */
6998 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6999 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7000 /* Set the connected flag so we can queue data */
7003 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7004 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7006 /* initialize authentication parameters for the assoc */
7007 sctp_initialize_auth_params(inp, stcb);
7009 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7010 SCTP_TCB_UNLOCK(stcb);
7012 if (create_lock_on) {
7013 SCTP_ASOC_CREATE_UNLOCK(inp);
7016 SCTP_INP_DECR_REF(inp);
7022 sctp_listen(struct socket *so, int backlog, struct thread *p)
7025 * Note this module depends on the protocol processing being called
7026 * AFTER any socket level flags and backlog are applied to the
7027 * socket. The traditional way that the socket flags are applied is
7028 * AFTER protocol processing. We have made a change to the
7029 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7030 * place if the socket API for SCTP is to work properly.
7034 struct sctp_inpcb *inp;
7036 inp = (struct sctp_inpcb *)so->so_pcb;
7038 /* I made the same as TCP since we are not setup? */
7039 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7040 return (ECONNRESET);
7042 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7043 /* See if we have a listener */
7044 struct sctp_inpcb *tinp;
7045 union sctp_sockstore store;
7047 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7049 struct sctp_laddr *laddr;
7051 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7052 memcpy(&store, &laddr->ifa->address, sizeof(store));
7053 switch (store.sa.sa_family) {
7056 store.sin.sin_port = inp->sctp_lport;
7061 store.sin6.sin6_port = inp->sctp_lport;
7067 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7068 if (tinp && (tinp != inp) &&
7069 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7070 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7071 (SCTP_IS_LISTENING(tinp))) {
7073 * we have a listener already and
7076 SCTP_INP_DECR_REF(tinp);
7077 return (EADDRINUSE);
7079 SCTP_INP_DECR_REF(tinp);
7083 /* Setup a local addr bound all */
7084 memset(&store, 0, sizeof(store));
7086 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7087 store.sa.sa_family = AF_INET6;
7088 store.sa.sa_len = sizeof(struct sockaddr_in6);
7092 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7093 store.sa.sa_family = AF_INET;
7094 store.sa.sa_len = sizeof(struct sockaddr_in);
7097 switch (store.sa.sa_family) {
7100 store.sin.sin_port = inp->sctp_lport;
7105 store.sin6.sin6_port = inp->sctp_lport;
7111 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7112 if (tinp && (tinp != inp) &&
7113 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7114 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7115 (SCTP_IS_LISTENING(tinp))) {
7117 * we have a listener already and its not
7120 SCTP_INP_DECR_REF(tinp);
7121 return (EADDRINUSE);
7123 SCTP_INP_DECR_REF(tinp);
7127 SCTP_INP_RLOCK(inp);
7128 #ifdef SCTP_LOCK_LOGGING
7129 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7130 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7134 error = solisten_proto_check(so);
7137 SCTP_INP_RUNLOCK(inp);
7140 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7141 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7143 * The unlucky case - We are in the tcp pool with this guy.
7144 * - Someone else is in the main inp slot. - We must move
7145 * this guy (the listener) to the main slot - We must then
7146 * move the guy that was listener to the TCP Pool.
7148 if (sctp_swap_inpcb_for_listen(inp)) {
7149 SCTP_INP_RUNLOCK(inp);
7150 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7151 return (EADDRINUSE);
7155 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7156 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7157 /* We are already connected AND the TCP model */
7158 SCTP_INP_RUNLOCK(inp);
7159 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7160 return (EADDRINUSE);
7162 SCTP_INP_RUNLOCK(inp);
7163 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7164 /* We must do a bind. */
7165 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7166 /* bind error, probably perm */
7170 SCTP_INP_WLOCK(inp);
7171 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7173 solisten_proto(so, backlog);
7177 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7179 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7181 SCTP_INP_WUNLOCK(inp);
7185 static int sctp_defered_wakeup_cnt = 0;
7188 sctp_accept(struct socket *so, struct sockaddr **addr)
7190 struct sctp_tcb *stcb;
7191 struct sctp_inpcb *inp;
7192 union sctp_sockstore store;
7196 inp = (struct sctp_inpcb *)so->so_pcb;
7199 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7200 return (ECONNRESET);
7202 SCTP_INP_RLOCK(inp);
7203 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7204 SCTP_INP_RUNLOCK(inp);
7205 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7206 return (EOPNOTSUPP);
7208 if (so->so_state & SS_ISDISCONNECTED) {
7209 SCTP_INP_RUNLOCK(inp);
7210 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7211 return (ECONNABORTED);
7213 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7215 SCTP_INP_RUNLOCK(inp);
7216 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7217 return (ECONNRESET);
7219 SCTP_TCB_LOCK(stcb);
7220 SCTP_INP_RUNLOCK(inp);
7221 store = stcb->asoc.primary_destination->ro._l_addr;
7222 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7223 SCTP_TCB_UNLOCK(stcb);
7224 switch (store.sa.sa_family) {
7228 struct sockaddr_in *sin;
7230 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7233 sin->sin_family = AF_INET;
7234 sin->sin_len = sizeof(*sin);
7235 sin->sin_port = store.sin.sin_port;
7236 sin->sin_addr = store.sin.sin_addr;
7237 *addr = (struct sockaddr *)sin;
7244 struct sockaddr_in6 *sin6;
7246 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7249 sin6->sin6_family = AF_INET6;
7250 sin6->sin6_len = sizeof(*sin6);
7251 sin6->sin6_port = store.sin6.sin6_port;
7252 sin6->sin6_addr = store.sin6.sin6_addr;
7253 if ((error = sa6_recoverscope(sin6)) != 0) {
7254 SCTP_FREE_SONAME(sin6);
7257 *addr = (struct sockaddr *)sin6;
7265 /* Wake any delayed sleep action */
7266 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7267 SCTP_INP_WLOCK(inp);
7268 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7269 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7270 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7271 SCTP_INP_WUNLOCK(inp);
7272 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7273 if (sowriteable(inp->sctp_socket)) {
7274 sowwakeup_locked(inp->sctp_socket);
7276 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7278 SCTP_INP_WLOCK(inp);
7280 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7281 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7282 SCTP_INP_WUNLOCK(inp);
7283 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7284 if (soreadable(inp->sctp_socket)) {
7285 sctp_defered_wakeup_cnt++;
7286 sorwakeup_locked(inp->sctp_socket);
7288 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7290 SCTP_INP_WLOCK(inp);
7292 SCTP_INP_WUNLOCK(inp);
7294 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7295 SCTP_TCB_LOCK(stcb);
7296 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7297 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7304 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7306 struct sockaddr_in *sin;
7308 struct sctp_inpcb *inp;
7309 struct sctp_ifa *sctp_ifa;
7312 * Do the malloc first in case it blocks.
7314 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7317 sin->sin_family = AF_INET;
7318 sin->sin_len = sizeof(*sin);
7319 inp = (struct sctp_inpcb *)so->so_pcb;
7321 SCTP_FREE_SONAME(sin);
7322 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7323 return (ECONNRESET);
7325 SCTP_INP_RLOCK(inp);
7326 sin->sin_port = inp->sctp_lport;
7327 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7328 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7329 struct sctp_tcb *stcb;
7330 struct sockaddr_in *sin_a;
7331 struct sctp_nets *net;
7334 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7340 SCTP_TCB_LOCK(stcb);
7341 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7342 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7344 /* this will make coverity happy */
7347 if (sin_a->sin_family == AF_INET) {
7352 if ((!fnd) || (sin_a == NULL)) {
7354 SCTP_TCB_UNLOCK(stcb);
7358 vrf_id = inp->def_vrf_id;
7359 sctp_ifa = sctp_source_address_selection(inp,
7361 (sctp_route_t *)&net->ro,
7364 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7365 sctp_free_ifa(sctp_ifa);
7367 SCTP_TCB_UNLOCK(stcb);
7369 /* For the bound all case you get back 0 */
7371 sin->sin_addr.s_addr = 0;
7375 /* Take the first IPv4 address in the list */
7376 struct sctp_laddr *laddr;
7379 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7380 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7381 struct sockaddr_in *sin_a;
7383 sin_a = &laddr->ifa->address.sin;
7384 sin->sin_addr = sin_a->sin_addr;
7390 SCTP_FREE_SONAME(sin);
7391 SCTP_INP_RUNLOCK(inp);
7392 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7396 SCTP_INP_RUNLOCK(inp);
7397 (*addr) = (struct sockaddr *)sin;
7402 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7404 struct sockaddr_in *sin;
7406 struct sockaddr_in *sin_a;
7407 struct sctp_inpcb *inp;
7408 struct sctp_tcb *stcb;
7409 struct sctp_nets *net;
7411 /* Do the malloc first in case it blocks. */
7412 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7415 sin->sin_family = AF_INET;
7416 sin->sin_len = sizeof(*sin);
7418 inp = (struct sctp_inpcb *)so->so_pcb;
7419 if ((inp == NULL) ||
7420 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7421 /* UDP type and listeners will drop out here */
7422 SCTP_FREE_SONAME(sin);
7423 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7426 SCTP_INP_RLOCK(inp);
7427 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7429 SCTP_TCB_LOCK(stcb);
7431 SCTP_INP_RUNLOCK(inp);
7433 SCTP_FREE_SONAME(sin);
7434 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7435 return (ECONNRESET);
7438 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7439 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7440 if (sin_a->sin_family == AF_INET) {
7442 sin->sin_port = stcb->rport;
7443 sin->sin_addr = sin_a->sin_addr;
7447 SCTP_TCB_UNLOCK(stcb);
7449 /* No IPv4 address */
7450 SCTP_FREE_SONAME(sin);
7451 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7454 (*addr) = (struct sockaddr *)sin;
7458 struct pr_usrreqs sctp_usrreqs = {
7459 .pru_abort = sctp_abort,
7460 .pru_accept = sctp_accept,
7461 .pru_attach = sctp_attach,
7462 .pru_bind = sctp_bind,
7463 .pru_connect = sctp_connect,
7464 .pru_control = in_control,
7465 .pru_close = sctp_close,
7466 .pru_detach = sctp_close,
7467 .pru_sopoll = sopoll_generic,
7468 .pru_flush = sctp_flush,
7469 .pru_disconnect = sctp_disconnect,
7470 .pru_listen = sctp_listen,
7471 .pru_peeraddr = sctp_peeraddr,
7472 .pru_send = sctp_sendm,
7473 .pru_shutdown = sctp_shutdown,
7474 .pru_sockaddr = sctp_ingetaddr,
7475 .pru_sosend = sctp_sosend,
7476 .pru_soreceive = sctp_soreceive