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_CLEAR_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
743 sctp_stop_timers_for_shutdown(stcb);
744 if (stcb->asoc.alternate) {
745 netp = stcb->asoc.alternate;
747 netp = stcb->asoc.primary_destination;
749 sctp_send_shutdown(stcb, netp);
750 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
751 stcb->sctp_ep, stcb, netp);
752 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
753 stcb->sctp_ep, stcb, netp);
754 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
758 * we still got (or just got) data to send,
759 * so set SHUTDOWN_PENDING
762 * XXX sockets draft says that SCTP_EOF
763 * should be sent with no data. currently,
764 * we will allow user data to be sent first
765 * and move to SHUTDOWN-PENDING
767 struct sctp_nets *netp;
769 if (stcb->asoc.alternate) {
770 netp = stcb->asoc.alternate;
772 netp = stcb->asoc.primary_destination;
775 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
776 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
778 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
779 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
781 if (TAILQ_EMPTY(&asoc->send_queue) &&
782 TAILQ_EMPTY(&asoc->sent_queue) &&
783 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
787 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
788 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
789 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
790 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
791 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
792 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
793 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
795 SCTP_INP_RUNLOCK(inp);
796 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
797 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
800 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
803 soisdisconnecting(so);
804 SCTP_TCB_UNLOCK(stcb);
805 SCTP_INP_RUNLOCK(inp);
810 /* UDP model does not support this */
811 SCTP_INP_RUNLOCK(inp);
812 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
818 sctp_flush(struct socket *so, int how)
821 * We will just clear out the values and let subsequent close clear
822 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
823 * they will not be able to read the data, the socket will block
824 * that from happening.
826 struct sctp_inpcb *inp;
828 inp = (struct sctp_inpcb *)so->so_pcb;
830 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
834 /* For the 1 to many model this does nothing */
835 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
836 SCTP_INP_RUNLOCK(inp);
839 SCTP_INP_RUNLOCK(inp);
840 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
842 * First make sure the sb will be happy, we don't use these
843 * except maybe the count
846 SCTP_INP_READ_LOCK(inp);
847 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
848 SCTP_INP_READ_UNLOCK(inp);
849 SCTP_INP_WUNLOCK(inp);
850 so->so_rcv.sb_cc = 0;
851 so->so_rcv.sb_mbcnt = 0;
852 so->so_rcv.sb_mb = NULL;
854 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
856 * First make sure the sb will be happy, we don't use these
857 * except maybe the count
859 so->so_snd.sb_cc = 0;
860 so->so_snd.sb_mbcnt = 0;
861 so->so_snd.sb_mb = NULL;
868 sctp_shutdown(struct socket *so)
870 struct sctp_inpcb *inp;
872 inp = (struct sctp_inpcb *)so->so_pcb;
874 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
878 /* For UDP model this is a invalid call */
879 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
880 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
881 /* Restore the flags that the soshutdown took away. */
882 SOCKBUF_LOCK(&so->so_rcv);
883 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
884 SOCKBUF_UNLOCK(&so->so_rcv);
885 /* This proc will wakeup for read and do nothing (I hope) */
886 SCTP_INP_RUNLOCK(inp);
887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
891 * Ok, if we reach here its the TCP model and it is either a
892 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
895 struct sctp_tcb *stcb;
896 struct sctp_association *asoc;
897 struct sctp_nets *netp;
900 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
901 SCTP_INP_RUNLOCK(inp);
906 stcb = LIST_FIRST(&inp->sctp_asoc_list);
909 * Ok, we hit the case that the shutdown call was
910 * made after an abort or something. Nothing to do
913 SCTP_INP_RUNLOCK(inp);
918 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
919 SCTP_TCB_UNLOCK(stcb);
920 SCTP_INP_RUNLOCK(inp);
923 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) &&
924 (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) &&
925 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) {
927 * If we are not in or before ESTABLISHED, there is
928 * no protocol action required.
930 SCTP_TCB_UNLOCK(stcb);
931 SCTP_INP_RUNLOCK(inp);
934 if (stcb->asoc.alternate) {
935 netp = stcb->asoc.alternate;
937 netp = stcb->asoc.primary_destination;
939 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) &&
940 TAILQ_EMPTY(&asoc->send_queue) &&
941 TAILQ_EMPTY(&asoc->sent_queue) &&
942 (asoc->stream_queue_cnt == 0)) {
943 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
946 /* there is nothing queued to send, so I'm done... */
947 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
948 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
949 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
950 sctp_stop_timers_for_shutdown(stcb);
951 sctp_send_shutdown(stcb, netp);
952 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
953 stcb->sctp_ep, stcb, netp);
956 * We still got (or just got) data to send, so set
959 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
960 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
961 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
963 if (TAILQ_EMPTY(&asoc->send_queue) &&
964 TAILQ_EMPTY(&asoc->sent_queue) &&
965 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
969 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
970 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
971 sctp_abort_an_association(stcb->sctp_ep, stcb,
972 op_err, SCTP_SO_LOCKED);
973 SCTP_INP_RUNLOCK(inp);
977 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp);
979 * XXX: Why do this in the case where we have still data
982 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
983 SCTP_TCB_UNLOCK(stcb);
984 SCTP_INP_RUNLOCK(inp);
990 * copies a "user" presentable address and removes embedded scope, etc.
991 * returns 0 on success, 1 on error
994 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
997 struct sockaddr_in6 lsa6;
999 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1002 memcpy(ss, sa, sa->sa_len);
1009 * NOTE: assumes addr lock is held
1012 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1013 struct sctp_tcb *stcb,
1015 struct sockaddr_storage *sas,
1018 struct sctp_ifn *sctp_ifn;
1019 struct sctp_ifa *sctp_ifa;
1023 int ipv4_local_scope, ipv4_addr_legal;
1026 int local_scope, site_scope, ipv6_addr_legal;
1028 struct sctp_vrf *vrf;
1035 /* Turn on all the appropriate scope */
1036 loopback_scope = stcb->asoc.scope.loopback_scope;
1038 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1039 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1042 local_scope = stcb->asoc.scope.local_scope;
1043 site_scope = stcb->asoc.scope.site_scope;
1044 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1047 /* Use generic values for endpoints. */
1050 ipv4_local_scope = 1;
1056 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1058 ipv6_addr_legal = 1;
1061 if (SCTP_IPV6_V6ONLY(inp)) {
1062 ipv4_addr_legal = 0;
1064 ipv4_addr_legal = 1;
1069 ipv6_addr_legal = 0;
1072 ipv4_addr_legal = 1;
1076 vrf = sctp_find_vrf(vrf_id);
1080 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1081 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1082 if ((loopback_scope == 0) &&
1083 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1084 /* Skip loopback if loopback_scope not set */
1087 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1090 * For the BOUND-ALL case, the list
1091 * associated with a TCB is Always
1092 * considered a reverse list.. i.e.
1093 * it lists addresses that are NOT
1094 * part of the association. If this
1095 * is one of those we must skip it.
1097 if (sctp_is_addr_restricted(stcb,
1102 switch (sctp_ifa->address.sa.sa_family) {
1105 if (ipv4_addr_legal) {
1106 struct sockaddr_in *sin;
1108 sin = &sctp_ifa->address.sin;
1109 if (sin->sin_addr.s_addr == 0) {
1117 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1118 &sin->sin_addr) != 0) {
1121 if ((ipv4_local_scope == 0) &&
1122 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1126 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1127 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1128 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1129 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1130 actual += sizeof(struct sockaddr_in6);
1133 memcpy(sas, sin, sizeof(*sin));
1134 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1135 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1136 actual += sizeof(*sin);
1140 if (actual >= limit) {
1150 if (ipv6_addr_legal) {
1151 struct sockaddr_in6 *sin6;
1153 sin6 = &sctp_ifa->address.sin6;
1154 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1162 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1163 &sin6->sin6_addr) != 0) {
1166 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1167 if (local_scope == 0)
1169 if (sin6->sin6_scope_id == 0) {
1170 if (sa6_recoverscope(sin6) != 0)
1183 if ((site_scope == 0) &&
1184 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1187 memcpy(sas, sin6, sizeof(*sin6));
1188 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1189 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1190 actual += sizeof(*sin6);
1191 if (actual >= limit) {
1206 struct sctp_laddr *laddr;
1208 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1210 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1214 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1216 switch (laddr->ifa->address.sa.sa_family) {
1219 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1224 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1231 sas = (struct sockaddr_storage *)((caddr_t)sas +
1232 laddr->ifa->address.sa.sa_len);
1233 actual += laddr->ifa->address.sa.sa_len;
1234 if (actual >= limit) {
1243 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1244 struct sctp_tcb *stcb,
1246 struct sockaddr_storage *sas)
1250 SCTP_IPI_ADDR_RLOCK();
1251 /* fill up addresses for the endpoint's default vrf */
1252 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1254 SCTP_IPI_ADDR_RUNLOCK();
1259 * NOTE: assumes addr lock is held
1262 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1265 struct sctp_vrf *vrf = NULL;
1268 * In both sub-set bound an bound_all cases we return the MAXIMUM
1269 * number of addresses that you COULD get. In reality the sub-set
1270 * bound may have an exclusion list for a given TCB OR in the
1271 * bound-all case a TCB may NOT include the loopback or other
1272 * addresses as well.
1274 vrf = sctp_find_vrf(vrf_id);
1278 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1279 struct sctp_ifn *sctp_ifn;
1280 struct sctp_ifa *sctp_ifa;
1282 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1283 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1284 /* Count them if they are the right type */
1285 switch (sctp_ifa->address.sa.sa_family) {
1289 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1290 cnt += sizeof(struct sockaddr_in6);
1292 cnt += sizeof(struct sockaddr_in);
1294 cnt += sizeof(struct sockaddr_in);
1300 cnt += sizeof(struct sockaddr_in6);
1309 struct sctp_laddr *laddr;
1311 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1312 switch (laddr->ifa->address.sa.sa_family) {
1316 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1317 cnt += sizeof(struct sockaddr_in6);
1319 cnt += sizeof(struct sockaddr_in);
1321 cnt += sizeof(struct sockaddr_in);
1327 cnt += sizeof(struct sockaddr_in6);
1339 sctp_count_max_addresses(struct sctp_inpcb *inp)
1343 SCTP_IPI_ADDR_RLOCK();
1344 /* count addresses for the endpoint's default VRF */
1345 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1346 SCTP_IPI_ADDR_RUNLOCK();
1351 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1352 size_t optsize, void *p, int delay)
1355 int creat_lock_on = 0;
1356 struct sctp_tcb *stcb = NULL;
1357 struct sockaddr *sa;
1358 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1360 int bad_addresses = 0;
1363 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1365 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1366 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1367 /* We are already connected AND the TCP model */
1368 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1369 return (EADDRINUSE);
1372 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1373 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1374 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1378 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1379 SCTP_INP_RLOCK(inp);
1380 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1381 SCTP_INP_RUNLOCK(inp);
1384 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1387 SCTP_INP_INCR_REF(inp);
1388 SCTP_ASOC_CREATE_LOCK(inp);
1390 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1391 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1392 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1396 totaddrp = (unsigned int *)optval;
1397 totaddr = *totaddrp;
1398 sa = (struct sockaddr *)(totaddrp + 1);
1399 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (unsigned int)(optsize - sizeof(int)), &bad_addresses);
1400 if ((stcb != NULL) || bad_addresses) {
1401 /* Already have or am bring up an association */
1402 SCTP_ASOC_CREATE_UNLOCK(inp);
1405 SCTP_TCB_UNLOCK(stcb);
1406 if (bad_addresses == 0) {
1407 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1413 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1418 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1420 struct in6pcb *inp6;
1422 inp6 = (struct in6pcb *)inp;
1423 if (SCTP_IPV6_V6ONLY(inp6)) {
1425 * if IPV6_V6ONLY flag, ignore connections destined
1426 * to a v4 addr or v4-mapped addr
1428 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1434 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1435 SCTP_PCB_FLAGS_UNBOUND) {
1436 /* Bind a ephemeral port */
1437 error = sctp_inpcb_bind(so, NULL, NULL, p);
1443 /* FIX ME: do we want to pass in a vrf on the connect call? */
1444 vrf_id = inp->def_vrf_id;
1447 /* We are GOOD to go */
1448 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1449 inp->sctp_ep.pre_open_stream_count,
1454 /* Gak! no memory */
1457 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1458 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1459 /* Set the connected flag so we can queue data */
1462 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1463 /* move to second address */
1464 switch (sa->sa_family) {
1467 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1472 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1480 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1481 /* Fill in the return id */
1483 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE,
1484 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
1487 a_id = (sctp_assoc_t *)optval;
1488 *a_id = sctp_get_associd(stcb);
1490 /* initialize authentication parameters for the assoc */
1491 sctp_initialize_auth_params(inp, stcb);
1494 /* doing delayed connection */
1495 stcb->asoc.delayed_connection = 1;
1496 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1498 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1499 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1501 SCTP_TCB_UNLOCK(stcb);
1503 if (creat_lock_on) {
1504 SCTP_ASOC_CREATE_UNLOCK(inp);
1506 SCTP_INP_DECR_REF(inp);
1510 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1511 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1512 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1513 SCTP_INP_RLOCK(inp); \
1514 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1516 SCTP_TCB_LOCK(stcb); \
1518 SCTP_INP_RUNLOCK(inp); \
1519 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1520 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1521 if (stcb == NULL) { \
1522 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1532 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1533 if (size < sizeof(type)) { \
1534 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1538 destp = (type *)srcp; \
1543 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1546 struct sctp_inpcb *inp = NULL;
1548 struct sctp_tcb *stcb = NULL;
1550 if (optval == NULL) {
1551 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1555 inp = (struct sctp_inpcb *)so->so_pcb;
1557 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1564 case SCTP_AUTOCLOSE:
1565 case SCTP_EXPLICIT_EOR:
1566 case SCTP_AUTO_ASCONF:
1567 case SCTP_DISABLE_FRAGMENTS:
1568 case SCTP_I_WANT_MAPPED_V4_ADDR:
1569 case SCTP_USE_EXT_RCVINFO:
1570 SCTP_INP_RLOCK(inp);
1572 case SCTP_DISABLE_FRAGMENTS:
1573 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1575 case SCTP_I_WANT_MAPPED_V4_ADDR:
1576 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1578 case SCTP_AUTO_ASCONF:
1579 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1580 /* only valid for bound all sockets */
1581 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1583 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1588 case SCTP_EXPLICIT_EOR:
1589 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1592 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1594 case SCTP_USE_EXT_RCVINFO:
1595 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1597 case SCTP_AUTOCLOSE:
1598 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1599 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1605 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1606 error = ENOPROTOOPT;
1607 } /* end switch (sopt->sopt_name) */
1608 if (*optsize < sizeof(val)) {
1609 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1613 SCTP_INP_RUNLOCK(inp);
1615 /* return the option value */
1616 *(int *)optval = val;
1617 *optsize = sizeof(val);
1620 case SCTP_GET_PACKET_LOG:
1622 #ifdef SCTP_PACKET_LOGGING
1626 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1627 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1630 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1635 case SCTP_REUSE_PORT:
1639 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1640 /* Can't do this for a 1-m socket */
1644 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1645 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1646 *optsize = sizeof(uint32_t);
1649 case SCTP_PARTIAL_DELIVERY_POINT:
1653 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1654 *value = inp->partial_delivery_point;
1655 *optsize = sizeof(uint32_t);
1658 case SCTP_FRAGMENT_INTERLEAVE:
1662 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1663 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1664 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1665 *value = SCTP_FRAG_LEVEL_2;
1667 *value = SCTP_FRAG_LEVEL_1;
1670 *value = SCTP_FRAG_LEVEL_0;
1672 *optsize = sizeof(uint32_t);
1675 case SCTP_INTERLEAVING_SUPPORTED:
1677 struct sctp_assoc_value *av;
1679 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1680 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1683 av->assoc_value = stcb->asoc.idata_supported;
1684 SCTP_TCB_UNLOCK(stcb);
1686 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1687 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1688 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1689 SCTP_INP_RLOCK(inp);
1690 if (inp->idata_supported) {
1691 av->assoc_value = 1;
1693 av->assoc_value = 0;
1695 SCTP_INP_RUNLOCK(inp);
1697 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1702 *optsize = sizeof(struct sctp_assoc_value);
1706 case SCTP_CMT_ON_OFF:
1708 struct sctp_assoc_value *av;
1710 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1711 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1713 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1714 SCTP_TCB_UNLOCK(stcb);
1716 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1717 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1718 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1719 SCTP_INP_RLOCK(inp);
1720 av->assoc_value = inp->sctp_cmt_on_off;
1721 SCTP_INP_RUNLOCK(inp);
1723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1728 *optsize = sizeof(struct sctp_assoc_value);
1732 case SCTP_PLUGGABLE_CC:
1734 struct sctp_assoc_value *av;
1736 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1737 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1739 av->assoc_value = stcb->asoc.congestion_control_module;
1740 SCTP_TCB_UNLOCK(stcb);
1742 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1743 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1744 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1745 SCTP_INP_RLOCK(inp);
1746 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1747 SCTP_INP_RUNLOCK(inp);
1749 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1754 *optsize = sizeof(struct sctp_assoc_value);
1758 case SCTP_CC_OPTION:
1760 struct sctp_cc_option *cc_opt;
1762 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1763 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1767 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1770 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1771 *optsize = sizeof(struct sctp_cc_option);
1773 SCTP_TCB_UNLOCK(stcb);
1777 case SCTP_PLUGGABLE_SS:
1779 struct sctp_assoc_value *av;
1781 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1782 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1784 av->assoc_value = stcb->asoc.stream_scheduling_module;
1785 SCTP_TCB_UNLOCK(stcb);
1787 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1788 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1789 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1790 SCTP_INP_RLOCK(inp);
1791 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1792 SCTP_INP_RUNLOCK(inp);
1794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1799 *optsize = sizeof(struct sctp_assoc_value);
1805 struct sctp_stream_value *av;
1807 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1808 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1810 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1811 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1812 &av->stream_value) < 0)) {
1813 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1816 *optsize = sizeof(struct sctp_stream_value);
1818 SCTP_TCB_UNLOCK(stcb);
1821 * Can't get stream value without
1824 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1829 case SCTP_GET_ADDR_LEN:
1831 struct sctp_assoc_value *av;
1833 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1836 if (av->assoc_value == AF_INET) {
1837 av->assoc_value = sizeof(struct sockaddr_in);
1842 if (av->assoc_value == AF_INET6) {
1843 av->assoc_value = sizeof(struct sockaddr_in6);
1848 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1850 *optsize = sizeof(struct sctp_assoc_value);
1854 case SCTP_GET_ASSOC_NUMBER:
1856 uint32_t *value, cnt;
1858 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1859 SCTP_INP_RLOCK(inp);
1860 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1861 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1862 /* Can't do this for a 1-1 socket */
1864 SCTP_INP_RUNLOCK(inp);
1868 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1871 SCTP_INP_RUNLOCK(inp);
1873 *optsize = sizeof(uint32_t);
1876 case SCTP_GET_ASSOC_ID_LIST:
1878 struct sctp_assoc_ids *ids;
1882 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1883 SCTP_INP_RLOCK(inp);
1884 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1885 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1886 /* Can't do this for a 1-1 socket */
1888 SCTP_INP_RUNLOCK(inp);
1892 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1893 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1895 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1898 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1907 SCTP_INP_RUNLOCK(inp);
1909 ids->gaids_number_of_ids = at;
1910 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1916 struct sctp_assoc_value *av;
1918 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1919 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1922 av->assoc_value = stcb->asoc.context;
1923 SCTP_TCB_UNLOCK(stcb);
1925 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1926 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1927 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1928 SCTP_INP_RLOCK(inp);
1929 av->assoc_value = inp->sctp_context;
1930 SCTP_INP_RUNLOCK(inp);
1932 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1937 *optsize = sizeof(struct sctp_assoc_value);
1943 uint32_t *default_vrfid;
1945 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1946 *default_vrfid = inp->def_vrf_id;
1947 *optsize = sizeof(uint32_t);
1950 case SCTP_GET_ASOC_VRF:
1952 struct sctp_assoc_value *id;
1954 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1955 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1958 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1960 id->assoc_value = stcb->asoc.vrf_id;
1961 SCTP_TCB_UNLOCK(stcb);
1962 *optsize = sizeof(struct sctp_assoc_value);
1966 case SCTP_GET_VRF_IDS:
1968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1972 case SCTP_GET_NONCE_VALUES:
1974 struct sctp_get_nonce_values *gnv;
1976 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1977 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1980 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1981 gnv->gn_local_tag = stcb->asoc.my_vtag;
1982 SCTP_TCB_UNLOCK(stcb);
1983 *optsize = sizeof(struct sctp_get_nonce_values);
1985 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1990 case SCTP_DELAYED_SACK:
1992 struct sctp_sack_info *sack;
1994 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1995 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1997 sack->sack_delay = stcb->asoc.delayed_ack;
1998 sack->sack_freq = stcb->asoc.sack_freq;
1999 SCTP_TCB_UNLOCK(stcb);
2001 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2002 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2003 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2004 SCTP_INP_RLOCK(inp);
2005 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2006 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2007 SCTP_INP_RUNLOCK(inp);
2009 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2014 *optsize = sizeof(struct sctp_sack_info);
2018 case SCTP_GET_SNDBUF_USE:
2020 struct sctp_sockstat *ss;
2022 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2023 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2026 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2027 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2028 stcb->asoc.size_on_all_streams);
2029 SCTP_TCB_UNLOCK(stcb);
2030 *optsize = sizeof(struct sctp_sockstat);
2032 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2037 case SCTP_MAX_BURST:
2039 struct sctp_assoc_value *av;
2041 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2042 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2045 av->assoc_value = stcb->asoc.max_burst;
2046 SCTP_TCB_UNLOCK(stcb);
2048 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2049 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2050 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2051 SCTP_INP_RLOCK(inp);
2052 av->assoc_value = inp->sctp_ep.max_burst;
2053 SCTP_INP_RUNLOCK(inp);
2055 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2060 *optsize = sizeof(struct sctp_assoc_value);
2066 struct sctp_assoc_value *av;
2069 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2070 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2073 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2074 SCTP_TCB_UNLOCK(stcb);
2076 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2077 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2078 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2079 SCTP_INP_RLOCK(inp);
2080 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2081 ovh = SCTP_MED_OVERHEAD;
2083 ovh = SCTP_MED_V4_OVERHEAD;
2085 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2086 av->assoc_value = 0;
2088 av->assoc_value = inp->sctp_frag_point - ovh;
2089 SCTP_INP_RUNLOCK(inp);
2091 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2096 *optsize = sizeof(struct sctp_assoc_value);
2100 case SCTP_GET_STAT_LOG:
2101 error = sctp_fill_stat_log(optval, optsize);
2105 struct sctp_event_subscribe *events;
2107 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2108 memset(events, 0, sizeof(struct sctp_event_subscribe));
2109 SCTP_INP_RLOCK(inp);
2110 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2111 events->sctp_data_io_event = 1;
2113 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2114 events->sctp_association_event = 1;
2116 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2117 events->sctp_address_event = 1;
2119 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2120 events->sctp_send_failure_event = 1;
2122 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2123 events->sctp_peer_error_event = 1;
2125 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2126 events->sctp_shutdown_event = 1;
2128 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2129 events->sctp_partial_delivery_event = 1;
2131 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2132 events->sctp_adaptation_layer_event = 1;
2134 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2135 events->sctp_authentication_event = 1;
2137 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2138 events->sctp_sender_dry_event = 1;
2140 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2141 events->sctp_stream_reset_event = 1;
2142 SCTP_INP_RUNLOCK(inp);
2143 *optsize = sizeof(struct sctp_event_subscribe);
2146 case SCTP_ADAPTATION_LAYER:
2150 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2152 SCTP_INP_RLOCK(inp);
2153 *value = inp->sctp_ep.adaptation_layer_indicator;
2154 SCTP_INP_RUNLOCK(inp);
2155 *optsize = sizeof(uint32_t);
2158 case SCTP_SET_INITIAL_DBG_SEQ:
2162 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2163 SCTP_INP_RLOCK(inp);
2164 *value = inp->sctp_ep.initial_sequence_debug;
2165 SCTP_INP_RUNLOCK(inp);
2166 *optsize = sizeof(uint32_t);
2169 case SCTP_GET_LOCAL_ADDR_SIZE:
2173 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2174 SCTP_INP_RLOCK(inp);
2175 *value = sctp_count_max_addresses(inp);
2176 SCTP_INP_RUNLOCK(inp);
2177 *optsize = sizeof(uint32_t);
2180 case SCTP_GET_REMOTE_ADDR_SIZE:
2184 struct sctp_nets *net;
2186 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2187 /* FIXME MT: change to sctp_assoc_value? */
2188 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2192 /* Count the sizes */
2193 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2194 switch (net->ro._l_addr.sa.sa_family) {
2198 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2199 size += sizeof(struct sockaddr_in6);
2201 size += sizeof(struct sockaddr_in);
2204 size += sizeof(struct sockaddr_in);
2210 size += sizeof(struct sockaddr_in6);
2217 SCTP_TCB_UNLOCK(stcb);
2218 *value = (uint32_t)size;
2219 *optsize = sizeof(uint32_t);
2221 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2226 case SCTP_GET_PEER_ADDRESSES:
2228 * Get the address information, an array is passed in to
2229 * fill up we pack it.
2233 struct sockaddr_storage *sas;
2234 struct sctp_nets *net;
2235 struct sctp_getaddresses *saddr;
2237 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2238 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2241 left = (*optsize) - sizeof(struct sctp_getaddresses);
2242 *optsize = sizeof(struct sctp_getaddresses);
2243 sas = (struct sockaddr_storage *)&saddr->addr[0];
2245 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2246 switch (net->ro._l_addr.sa.sa_family) {
2250 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2251 cpsz = sizeof(struct sockaddr_in6);
2253 cpsz = sizeof(struct sockaddr_in);
2256 cpsz = sizeof(struct sockaddr_in);
2262 cpsz = sizeof(struct sockaddr_in6);
2273 /* not enough room. */
2276 #if defined(INET) && defined(INET6)
2277 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2278 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2279 /* Must map the address */
2280 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2281 (struct sockaddr_in6 *)sas);
2283 memcpy(sas, &net->ro._l_addr, cpsz);
2286 memcpy(sas, &net->ro._l_addr, cpsz);
2288 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2290 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2294 SCTP_TCB_UNLOCK(stcb);
2296 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2301 case SCTP_GET_LOCAL_ADDRESSES:
2303 size_t limit, actual;
2304 struct sockaddr_storage *sas;
2305 struct sctp_getaddresses *saddr;
2307 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2308 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2310 sas = (struct sockaddr_storage *)&saddr->addr[0];
2311 limit = *optsize - sizeof(sctp_assoc_t);
2312 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2314 SCTP_TCB_UNLOCK(stcb);
2316 *optsize = sizeof(struct sockaddr_storage) + actual;
2319 case SCTP_PEER_ADDR_PARAMS:
2321 struct sctp_paddrparams *paddrp;
2322 struct sctp_nets *net;
2323 struct sockaddr *addr;
2324 #if defined(INET) && defined(INET6)
2325 struct sockaddr_in sin_store;
2328 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2329 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2331 #if defined(INET) && defined(INET6)
2332 if (paddrp->spp_address.ss_family == AF_INET6) {
2333 struct sockaddr_in6 *sin6;
2335 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2336 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2337 in6_sin6_2_sin(&sin_store, sin6);
2338 addr = (struct sockaddr *)&sin_store;
2340 addr = (struct sockaddr *)&paddrp->spp_address;
2343 addr = (struct sockaddr *)&paddrp->spp_address;
2346 addr = (struct sockaddr *)&paddrp->spp_address;
2349 net = sctp_findnet(stcb, addr);
2352 * We increment here since
2353 * sctp_findassociation_ep_addr() wil do a
2354 * decrement if it finds the stcb as long as
2355 * the locked tcb (last argument) is NOT a
2359 SCTP_INP_INCR_REF(inp);
2360 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2362 SCTP_INP_DECR_REF(inp);
2365 if ((stcb != NULL) && (net == NULL)) {
2367 if (addr->sa_family == AF_INET) {
2368 struct sockaddr_in *sin;
2370 sin = (struct sockaddr_in *)addr;
2371 if (sin->sin_addr.s_addr != INADDR_ANY) {
2373 SCTP_TCB_UNLOCK(stcb);
2374 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2380 if (addr->sa_family == AF_INET6) {
2381 struct sockaddr_in6 *sin6;
2383 sin6 = (struct sockaddr_in6 *)addr;
2384 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2386 SCTP_TCB_UNLOCK(stcb);
2387 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2393 error = EAFNOSUPPORT;
2394 SCTP_TCB_UNLOCK(stcb);
2395 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2401 /* Applies to the specific association */
2402 paddrp->spp_flags = 0;
2404 paddrp->spp_hbinterval = net->heart_beat_delay;
2405 paddrp->spp_pathmaxrxt = net->failure_threshold;
2406 paddrp->spp_pathmtu = net->mtu;
2407 switch (net->ro._l_addr.sa.sa_family) {
2410 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2415 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2421 /* get flags for HB */
2422 if (net->dest_state & SCTP_ADDR_NOHB) {
2423 paddrp->spp_flags |= SPP_HB_DISABLE;
2425 paddrp->spp_flags |= SPP_HB_ENABLE;
2427 /* get flags for PMTU */
2428 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2429 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2431 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2433 if (net->dscp & 0x01) {
2434 paddrp->spp_dscp = net->dscp & 0xfc;
2435 paddrp->spp_flags |= SPP_DSCP;
2438 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2439 (net->flowlabel & 0x80000000)) {
2440 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2441 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2446 * No destination so return default
2449 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2450 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2451 if (stcb->asoc.default_dscp & 0x01) {
2452 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2453 paddrp->spp_flags |= SPP_DSCP;
2456 if (stcb->asoc.default_flowlabel & 0x80000000) {
2457 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2458 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2461 /* default settings should be these */
2462 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2463 paddrp->spp_flags |= SPP_HB_DISABLE;
2465 paddrp->spp_flags |= SPP_HB_ENABLE;
2467 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2468 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2470 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2472 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2474 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2475 SCTP_TCB_UNLOCK(stcb);
2477 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2478 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2479 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2480 /* Use endpoint defaults */
2481 SCTP_INP_RLOCK(inp);
2482 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2483 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2484 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2485 /* get inp's default */
2486 if (inp->sctp_ep.default_dscp & 0x01) {
2487 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2488 paddrp->spp_flags |= SPP_DSCP;
2491 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2492 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2493 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2494 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2497 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2499 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2500 paddrp->spp_flags |= SPP_HB_ENABLE;
2502 paddrp->spp_flags |= SPP_HB_DISABLE;
2504 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2505 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2507 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2509 SCTP_INP_RUNLOCK(inp);
2511 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2516 *optsize = sizeof(struct sctp_paddrparams);
2520 case SCTP_GET_PEER_ADDR_INFO:
2522 struct sctp_paddrinfo *paddri;
2523 struct sctp_nets *net;
2524 struct sockaddr *addr;
2525 #if defined(INET) && defined(INET6)
2526 struct sockaddr_in sin_store;
2529 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2530 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2532 #if defined(INET) && defined(INET6)
2533 if (paddri->spinfo_address.ss_family == AF_INET6) {
2534 struct sockaddr_in6 *sin6;
2536 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2537 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2538 in6_sin6_2_sin(&sin_store, sin6);
2539 addr = (struct sockaddr *)&sin_store;
2541 addr = (struct sockaddr *)&paddri->spinfo_address;
2544 addr = (struct sockaddr *)&paddri->spinfo_address;
2547 addr = (struct sockaddr *)&paddri->spinfo_address;
2550 net = sctp_findnet(stcb, addr);
2553 * We increment here since
2554 * sctp_findassociation_ep_addr() wil do a
2555 * decrement if it finds the stcb as long as
2556 * the locked tcb (last argument) is NOT a
2560 SCTP_INP_INCR_REF(inp);
2561 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2563 SCTP_INP_DECR_REF(inp);
2567 if ((stcb != NULL) && (net != NULL)) {
2568 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2569 /* It's unconfirmed */
2570 paddri->spinfo_state = SCTP_UNCONFIRMED;
2571 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2573 paddri->spinfo_state = SCTP_ACTIVE;
2576 paddri->spinfo_state = SCTP_INACTIVE;
2578 paddri->spinfo_cwnd = net->cwnd;
2579 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2580 paddri->spinfo_rto = net->RTO;
2581 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2582 paddri->spinfo_mtu = net->mtu;
2583 switch (addr->sa_family) {
2586 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2591 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2597 SCTP_TCB_UNLOCK(stcb);
2598 *optsize = sizeof(struct sctp_paddrinfo);
2601 SCTP_TCB_UNLOCK(stcb);
2603 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2608 case SCTP_PCB_STATUS:
2610 struct sctp_pcbinfo *spcb;
2612 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2613 sctp_fill_pcbinfo(spcb);
2614 *optsize = sizeof(struct sctp_pcbinfo);
2619 struct sctp_nets *net;
2620 struct sctp_status *sstat;
2622 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2623 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2626 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2630 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2631 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2632 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2633 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2635 * We can't include chunks that have been passed to
2636 * the socket layer. Only things in queue.
2638 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2639 stcb->asoc.cnt_on_all_streams);
2642 sstat->sstat_instrms = stcb->asoc.streamincnt;
2643 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2644 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2645 memcpy(&sstat->sstat_primary.spinfo_address,
2646 &stcb->asoc.primary_destination->ro._l_addr,
2647 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2648 net = stcb->asoc.primary_destination;
2649 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2651 * Again the user can get info from sctp_constants.h
2652 * for what the state of the network is.
2654 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2655 /* It's unconfirmed */
2656 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2657 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2659 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2662 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2664 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2665 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2666 sstat->sstat_primary.spinfo_rto = net->RTO;
2667 sstat->sstat_primary.spinfo_mtu = net->mtu;
2668 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2671 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2676 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2682 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2683 SCTP_TCB_UNLOCK(stcb);
2684 *optsize = sizeof(struct sctp_status);
2689 struct sctp_rtoinfo *srto;
2691 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2692 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2695 srto->srto_initial = stcb->asoc.initial_rto;
2696 srto->srto_max = stcb->asoc.maxrto;
2697 srto->srto_min = stcb->asoc.minrto;
2698 SCTP_TCB_UNLOCK(stcb);
2700 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2701 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2702 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2703 SCTP_INP_RLOCK(inp);
2704 srto->srto_initial = inp->sctp_ep.initial_rto;
2705 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2706 srto->srto_min = inp->sctp_ep.sctp_minrto;
2707 SCTP_INP_RUNLOCK(inp);
2709 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2714 *optsize = sizeof(struct sctp_rtoinfo);
2720 struct sctp_timeouts *stimo;
2722 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2723 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2726 stimo->stimo_init = stcb->asoc.timoinit;
2727 stimo->stimo_data = stcb->asoc.timodata;
2728 stimo->stimo_sack = stcb->asoc.timosack;
2729 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2730 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2731 stimo->stimo_cookie = stcb->asoc.timocookie;
2732 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2733 SCTP_TCB_UNLOCK(stcb);
2734 *optsize = sizeof(struct sctp_timeouts);
2736 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2741 case SCTP_ASSOCINFO:
2743 struct sctp_assocparams *sasoc;
2745 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2746 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2749 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2750 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2751 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2752 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2753 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2754 SCTP_TCB_UNLOCK(stcb);
2756 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2757 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2758 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2759 SCTP_INP_RLOCK(inp);
2760 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2761 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2762 sasoc->sasoc_number_peer_destinations = 0;
2763 sasoc->sasoc_peer_rwnd = 0;
2764 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2765 SCTP_INP_RUNLOCK(inp);
2767 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2772 *optsize = sizeof(struct sctp_assocparams);
2776 case SCTP_DEFAULT_SEND_PARAM:
2778 struct sctp_sndrcvinfo *s_info;
2780 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2781 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2784 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2785 SCTP_TCB_UNLOCK(stcb);
2787 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2788 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2789 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2790 SCTP_INP_RLOCK(inp);
2791 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2792 SCTP_INP_RUNLOCK(inp);
2794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2799 *optsize = sizeof(struct sctp_sndrcvinfo);
2805 struct sctp_initmsg *sinit;
2807 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2808 SCTP_INP_RLOCK(inp);
2809 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2810 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2811 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2812 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2813 SCTP_INP_RUNLOCK(inp);
2814 *optsize = sizeof(struct sctp_initmsg);
2817 case SCTP_PRIMARY_ADDR:
2818 /* we allow a "get" operation on this */
2820 struct sctp_setprim *ssp;
2822 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2823 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2826 union sctp_sockstore *addr;
2828 addr = &stcb->asoc.primary_destination->ro._l_addr;
2829 switch (addr->sa.sa_family) {
2833 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2834 in6_sin_2_v4mapsin6(&addr->sin,
2835 (struct sockaddr_in6 *)&ssp->ssp_addr);
2837 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2840 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2846 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2852 SCTP_TCB_UNLOCK(stcb);
2853 *optsize = sizeof(struct sctp_setprim);
2855 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2860 case SCTP_HMAC_IDENT:
2862 struct sctp_hmacalgo *shmac;
2863 sctp_hmaclist_t *hmaclist;
2867 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2869 SCTP_INP_RLOCK(inp);
2870 hmaclist = inp->sctp_ep.local_hmacs;
2871 if (hmaclist == NULL) {
2872 /* no HMACs to return */
2873 *optsize = sizeof(*shmac);
2874 SCTP_INP_RUNLOCK(inp);
2877 /* is there room for all of the hmac ids? */
2878 size = sizeof(*shmac) + (hmaclist->num_algo *
2879 sizeof(shmac->shmac_idents[0]));
2880 if ((size_t)(*optsize) < size) {
2881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2883 SCTP_INP_RUNLOCK(inp);
2886 /* copy in the list */
2887 shmac->shmac_number_of_idents = hmaclist->num_algo;
2888 for (i = 0; i < hmaclist->num_algo; i++) {
2889 shmac->shmac_idents[i] = hmaclist->hmac[i];
2891 SCTP_INP_RUNLOCK(inp);
2895 case SCTP_AUTH_ACTIVE_KEY:
2897 struct sctp_authkeyid *scact;
2899 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2900 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2903 /* get the active key on the assoc */
2904 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2905 SCTP_TCB_UNLOCK(stcb);
2907 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2908 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2909 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2910 /* get the endpoint active key */
2911 SCTP_INP_RLOCK(inp);
2912 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2913 SCTP_INP_RUNLOCK(inp);
2915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2920 *optsize = sizeof(struct sctp_authkeyid);
2924 case SCTP_LOCAL_AUTH_CHUNKS:
2926 struct sctp_authchunks *sac;
2927 sctp_auth_chklist_t *chklist = NULL;
2930 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2931 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2934 /* get off the assoc */
2935 chklist = stcb->asoc.local_auth_chunks;
2936 /* is there enough space? */
2937 size = sctp_auth_get_chklist_size(chklist);
2938 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2940 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2942 /* copy in the chunks */
2943 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2944 sac->gauth_number_of_chunks = (uint32_t)size;
2945 *optsize = sizeof(struct sctp_authchunks) + size;
2947 SCTP_TCB_UNLOCK(stcb);
2949 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2950 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2951 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2952 /* get off the endpoint */
2953 SCTP_INP_RLOCK(inp);
2954 chklist = inp->sctp_ep.local_auth_chunks;
2955 /* is there enough space? */
2956 size = sctp_auth_get_chklist_size(chklist);
2957 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2959 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2961 /* copy in the chunks */
2962 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2963 sac->gauth_number_of_chunks = (uint32_t)size;
2964 *optsize = sizeof(struct sctp_authchunks) + size;
2966 SCTP_INP_RUNLOCK(inp);
2968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2974 case SCTP_PEER_AUTH_CHUNKS:
2976 struct sctp_authchunks *sac;
2977 sctp_auth_chklist_t *chklist = NULL;
2980 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2981 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2984 /* get off the assoc */
2985 chklist = stcb->asoc.peer_auth_chunks;
2986 /* is there enough space? */
2987 size = sctp_auth_get_chklist_size(chklist);
2988 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2990 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2992 /* copy in the chunks */
2993 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2994 sac->gauth_number_of_chunks = (uint32_t)size;
2995 *optsize = sizeof(struct sctp_authchunks) + size;
2997 SCTP_TCB_UNLOCK(stcb);
2999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3006 struct sctp_event *event;
3007 uint32_t event_type;
3009 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3010 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3012 switch (event->se_type) {
3013 case SCTP_ASSOC_CHANGE:
3014 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3016 case SCTP_PEER_ADDR_CHANGE:
3017 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3019 case SCTP_REMOTE_ERROR:
3020 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3022 case SCTP_SEND_FAILED:
3023 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3025 case SCTP_SHUTDOWN_EVENT:
3026 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3028 case SCTP_ADAPTATION_INDICATION:
3029 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3031 case SCTP_PARTIAL_DELIVERY_EVENT:
3032 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3034 case SCTP_AUTHENTICATION_EVENT:
3035 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3037 case SCTP_STREAM_RESET_EVENT:
3038 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3040 case SCTP_SENDER_DRY_EVENT:
3041 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3043 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3045 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3048 case SCTP_ASSOC_RESET_EVENT:
3049 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3051 case SCTP_STREAM_CHANGE_EVENT:
3052 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3054 case SCTP_SEND_FAILED_EVENT:
3055 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3059 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3063 if (event_type > 0) {
3065 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3067 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3068 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3069 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3070 SCTP_INP_RLOCK(inp);
3071 event->se_on = sctp_is_feature_on(inp, event_type);
3072 SCTP_INP_RUNLOCK(inp);
3074 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3080 SCTP_TCB_UNLOCK(stcb);
3083 *optsize = sizeof(struct sctp_event);
3087 case SCTP_RECVRCVINFO:
3091 if (*optsize < sizeof(int)) {
3092 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3095 SCTP_INP_RLOCK(inp);
3096 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3097 SCTP_INP_RUNLOCK(inp);
3100 /* return the option value */
3101 *(int *)optval = onoff;
3102 *optsize = sizeof(int);
3106 case SCTP_RECVNXTINFO:
3110 if (*optsize < sizeof(int)) {
3111 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3114 SCTP_INP_RLOCK(inp);
3115 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3116 SCTP_INP_RUNLOCK(inp);
3119 /* return the option value */
3120 *(int *)optval = onoff;
3121 *optsize = sizeof(int);
3125 case SCTP_DEFAULT_SNDINFO:
3127 struct sctp_sndinfo *info;
3129 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3130 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3133 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3134 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3135 info->snd_flags &= 0xfff0;
3136 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3137 info->snd_context = stcb->asoc.def_send.sinfo_context;
3138 SCTP_TCB_UNLOCK(stcb);
3140 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3141 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3142 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3143 SCTP_INP_RLOCK(inp);
3144 info->snd_sid = inp->def_send.sinfo_stream;
3145 info->snd_flags = inp->def_send.sinfo_flags;
3146 info->snd_flags &= 0xfff0;
3147 info->snd_ppid = inp->def_send.sinfo_ppid;
3148 info->snd_context = inp->def_send.sinfo_context;
3149 SCTP_INP_RUNLOCK(inp);
3151 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3156 *optsize = sizeof(struct sctp_sndinfo);
3160 case SCTP_DEFAULT_PRINFO:
3162 struct sctp_default_prinfo *info;
3164 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3165 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3168 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3169 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3170 SCTP_TCB_UNLOCK(stcb);
3172 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3173 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3174 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3175 SCTP_INP_RLOCK(inp);
3176 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3177 info->pr_value = inp->def_send.sinfo_timetolive;
3178 SCTP_INP_RUNLOCK(inp);
3180 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3185 *optsize = sizeof(struct sctp_default_prinfo);
3189 case SCTP_PEER_ADDR_THLDS:
3191 struct sctp_paddrthlds *thlds;
3192 struct sctp_nets *net;
3193 struct sockaddr *addr;
3194 #if defined(INET) && defined(INET6)
3195 struct sockaddr_in sin_store;
3198 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3199 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3201 #if defined(INET) && defined(INET6)
3202 if (thlds->spt_address.ss_family == AF_INET6) {
3203 struct sockaddr_in6 *sin6;
3205 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3206 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3207 in6_sin6_2_sin(&sin_store, sin6);
3208 addr = (struct sockaddr *)&sin_store;
3210 addr = (struct sockaddr *)&thlds->spt_address;
3213 addr = (struct sockaddr *)&thlds->spt_address;
3216 addr = (struct sockaddr *)&thlds->spt_address;
3219 net = sctp_findnet(stcb, addr);
3222 * We increment here since
3223 * sctp_findassociation_ep_addr() wil do a
3224 * decrement if it finds the stcb as long as
3225 * the locked tcb (last argument) is NOT a
3229 SCTP_INP_INCR_REF(inp);
3230 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3232 SCTP_INP_DECR_REF(inp);
3235 if ((stcb != NULL) && (net == NULL)) {
3237 if (addr->sa_family == AF_INET) {
3238 struct sockaddr_in *sin;
3240 sin = (struct sockaddr_in *)addr;
3241 if (sin->sin_addr.s_addr != INADDR_ANY) {
3243 SCTP_TCB_UNLOCK(stcb);
3244 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3250 if (addr->sa_family == AF_INET6) {
3251 struct sockaddr_in6 *sin6;
3253 sin6 = (struct sockaddr_in6 *)addr;
3254 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3256 SCTP_TCB_UNLOCK(stcb);
3257 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3263 error = EAFNOSUPPORT;
3264 SCTP_TCB_UNLOCK(stcb);
3265 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3272 thlds->spt_pathmaxrxt = net->failure_threshold;
3273 thlds->spt_pathpfthld = net->pf_threshold;
3274 thlds->spt_pathcpthld = 0xffff;
3276 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3277 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3278 thlds->spt_pathcpthld = 0xffff;
3280 thlds->spt_assoc_id = sctp_get_associd(stcb);
3281 SCTP_TCB_UNLOCK(stcb);
3283 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3284 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3285 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3286 /* Use endpoint defaults */
3287 SCTP_INP_RLOCK(inp);
3288 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3289 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3290 thlds->spt_pathcpthld = 0xffff;
3291 SCTP_INP_RUNLOCK(inp);
3293 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3298 *optsize = sizeof(struct sctp_paddrthlds);
3302 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3304 struct sctp_udpencaps *encaps;
3305 struct sctp_nets *net;
3306 struct sockaddr *addr;
3307 #if defined(INET) && defined(INET6)
3308 struct sockaddr_in sin_store;
3311 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3312 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3314 #if defined(INET) && defined(INET6)
3315 if (encaps->sue_address.ss_family == AF_INET6) {
3316 struct sockaddr_in6 *sin6;
3318 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3319 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3320 in6_sin6_2_sin(&sin_store, sin6);
3321 addr = (struct sockaddr *)&sin_store;
3323 addr = (struct sockaddr *)&encaps->sue_address;
3326 addr = (struct sockaddr *)&encaps->sue_address;
3329 addr = (struct sockaddr *)&encaps->sue_address;
3332 net = sctp_findnet(stcb, addr);
3335 * We increment here since
3336 * sctp_findassociation_ep_addr() wil do a
3337 * decrement if it finds the stcb as long as
3338 * the locked tcb (last argument) is NOT a
3342 SCTP_INP_INCR_REF(inp);
3343 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3345 SCTP_INP_DECR_REF(inp);
3348 if ((stcb != NULL) && (net == NULL)) {
3350 if (addr->sa_family == AF_INET) {
3351 struct sockaddr_in *sin;
3353 sin = (struct sockaddr_in *)addr;
3354 if (sin->sin_addr.s_addr != INADDR_ANY) {
3356 SCTP_TCB_UNLOCK(stcb);
3357 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3363 if (addr->sa_family == AF_INET6) {
3364 struct sockaddr_in6 *sin6;
3366 sin6 = (struct sockaddr_in6 *)addr;
3367 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3369 SCTP_TCB_UNLOCK(stcb);
3370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3376 error = EAFNOSUPPORT;
3377 SCTP_TCB_UNLOCK(stcb);
3378 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3385 encaps->sue_port = net->port;
3387 encaps->sue_port = stcb->asoc.port;
3389 SCTP_TCB_UNLOCK(stcb);
3391 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3392 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3393 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3394 SCTP_INP_RLOCK(inp);
3395 encaps->sue_port = inp->sctp_ep.port;
3396 SCTP_INP_RUNLOCK(inp);
3398 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3403 *optsize = sizeof(struct sctp_udpencaps);
3407 case SCTP_ECN_SUPPORTED:
3409 struct sctp_assoc_value *av;
3411 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3412 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3415 av->assoc_value = stcb->asoc.ecn_supported;
3416 SCTP_TCB_UNLOCK(stcb);
3418 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3419 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3420 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3421 SCTP_INP_RLOCK(inp);
3422 av->assoc_value = inp->ecn_supported;
3423 SCTP_INP_RUNLOCK(inp);
3425 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3430 *optsize = sizeof(struct sctp_assoc_value);
3434 case SCTP_PR_SUPPORTED:
3436 struct sctp_assoc_value *av;
3438 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3439 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3442 av->assoc_value = stcb->asoc.prsctp_supported;
3443 SCTP_TCB_UNLOCK(stcb);
3445 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3446 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3447 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3448 SCTP_INP_RLOCK(inp);
3449 av->assoc_value = inp->prsctp_supported;
3450 SCTP_INP_RUNLOCK(inp);
3452 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3457 *optsize = sizeof(struct sctp_assoc_value);
3461 case SCTP_AUTH_SUPPORTED:
3463 struct sctp_assoc_value *av;
3465 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3466 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3469 av->assoc_value = stcb->asoc.auth_supported;
3470 SCTP_TCB_UNLOCK(stcb);
3472 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3473 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3474 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3475 SCTP_INP_RLOCK(inp);
3476 av->assoc_value = inp->auth_supported;
3477 SCTP_INP_RUNLOCK(inp);
3479 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3484 *optsize = sizeof(struct sctp_assoc_value);
3488 case SCTP_ASCONF_SUPPORTED:
3490 struct sctp_assoc_value *av;
3492 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3493 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3496 av->assoc_value = stcb->asoc.asconf_supported;
3497 SCTP_TCB_UNLOCK(stcb);
3499 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3500 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3501 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3502 SCTP_INP_RLOCK(inp);
3503 av->assoc_value = inp->asconf_supported;
3504 SCTP_INP_RUNLOCK(inp);
3506 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3511 *optsize = sizeof(struct sctp_assoc_value);
3515 case SCTP_RECONFIG_SUPPORTED:
3517 struct sctp_assoc_value *av;
3519 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3520 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3523 av->assoc_value = stcb->asoc.reconfig_supported;
3524 SCTP_TCB_UNLOCK(stcb);
3526 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3527 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3528 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3529 SCTP_INP_RLOCK(inp);
3530 av->assoc_value = inp->reconfig_supported;
3531 SCTP_INP_RUNLOCK(inp);
3533 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3538 *optsize = sizeof(struct sctp_assoc_value);
3542 case SCTP_NRSACK_SUPPORTED:
3544 struct sctp_assoc_value *av;
3546 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3547 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3550 av->assoc_value = stcb->asoc.nrsack_supported;
3551 SCTP_TCB_UNLOCK(stcb);
3553 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3554 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3555 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3556 SCTP_INP_RLOCK(inp);
3557 av->assoc_value = inp->nrsack_supported;
3558 SCTP_INP_RUNLOCK(inp);
3560 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3565 *optsize = sizeof(struct sctp_assoc_value);
3569 case SCTP_PKTDROP_SUPPORTED:
3571 struct sctp_assoc_value *av;
3573 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3574 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3577 av->assoc_value = stcb->asoc.pktdrop_supported;
3578 SCTP_TCB_UNLOCK(stcb);
3580 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3581 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3582 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3583 SCTP_INP_RLOCK(inp);
3584 av->assoc_value = inp->pktdrop_supported;
3585 SCTP_INP_RUNLOCK(inp);
3587 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3592 *optsize = sizeof(struct sctp_assoc_value);
3596 case SCTP_ENABLE_STREAM_RESET:
3598 struct sctp_assoc_value *av;
3600 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3601 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3604 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3605 SCTP_TCB_UNLOCK(stcb);
3607 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3608 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3609 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3610 SCTP_INP_RLOCK(inp);
3611 av->assoc_value = (uint32_t)inp->local_strreset_support;
3612 SCTP_INP_RUNLOCK(inp);
3614 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3619 *optsize = sizeof(struct sctp_assoc_value);
3623 case SCTP_PR_STREAM_STATUS:
3625 struct sctp_prstatus *sprstat;
3629 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3630 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3632 sid = sprstat->sprstat_sid;
3633 policy = sprstat->sprstat_policy;
3634 #if defined(SCTP_DETAILED_STR_STATS)
3635 if ((stcb != NULL) &&
3636 (sid < stcb->asoc.streamoutcnt) &&
3637 (policy != SCTP_PR_SCTP_NONE) &&
3638 ((policy <= SCTP_PR_SCTP_MAX) ||
3639 (policy == SCTP_PR_SCTP_ALL))) {
3640 if (policy == SCTP_PR_SCTP_ALL) {
3641 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3642 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3644 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3645 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3648 if ((stcb != NULL) &&
3649 (sid < stcb->asoc.streamoutcnt) &&
3650 (policy == SCTP_PR_SCTP_ALL)) {
3651 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3652 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3655 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3659 SCTP_TCB_UNLOCK(stcb);
3662 *optsize = sizeof(struct sctp_prstatus);
3666 case SCTP_PR_ASSOC_STATUS:
3668 struct sctp_prstatus *sprstat;
3671 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3672 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3674 policy = sprstat->sprstat_policy;
3675 if ((stcb != NULL) &&
3676 (policy != SCTP_PR_SCTP_NONE) &&
3677 ((policy <= SCTP_PR_SCTP_MAX) ||
3678 (policy == SCTP_PR_SCTP_ALL))) {
3679 if (policy == SCTP_PR_SCTP_ALL) {
3680 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3681 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3683 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3684 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3687 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3691 SCTP_TCB_UNLOCK(stcb);
3694 *optsize = sizeof(struct sctp_prstatus);
3700 struct sctp_assoc_value *av;
3702 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3703 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3706 av->assoc_value = stcb->asoc.max_cwnd;
3707 SCTP_TCB_UNLOCK(stcb);
3709 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3710 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3711 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3712 SCTP_INP_RLOCK(inp);
3713 av->assoc_value = inp->max_cwnd;
3714 SCTP_INP_RUNLOCK(inp);
3716 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3721 *optsize = sizeof(struct sctp_assoc_value);
3726 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3727 error = ENOPROTOOPT;
3729 } /* end switch (sopt->sopt_name) */
3737 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3742 struct sctp_tcb *stcb = NULL;
3743 struct sctp_inpcb *inp = NULL;
3746 if (optval == NULL) {
3747 SCTP_PRINTF("optval is NULL\n");
3748 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3751 inp = (struct sctp_inpcb *)so->so_pcb;
3753 SCTP_PRINTF("inp is NULL?\n");
3754 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3757 vrf_id = inp->def_vrf_id;
3762 case SCTP_AUTOCLOSE:
3763 case SCTP_AUTO_ASCONF:
3764 case SCTP_EXPLICIT_EOR:
3765 case SCTP_DISABLE_FRAGMENTS:
3766 case SCTP_USE_EXT_RCVINFO:
3767 case SCTP_I_WANT_MAPPED_V4_ADDR:
3768 /* copy in the option value */
3769 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3774 case SCTP_DISABLE_FRAGMENTS:
3775 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3777 case SCTP_AUTO_ASCONF:
3779 * NOTE: we don't really support this flag
3781 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3782 /* only valid for bound all sockets */
3783 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3785 /* forbidden by admin */
3786 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3789 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3791 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3795 case SCTP_EXPLICIT_EOR:
3796 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3798 case SCTP_USE_EXT_RCVINFO:
3799 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3801 case SCTP_I_WANT_MAPPED_V4_ADDR:
3802 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3803 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3805 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3810 set_opt = SCTP_PCB_FLAGS_NODELAY;
3812 case SCTP_AUTOCLOSE:
3813 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3814 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3815 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3818 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3820 * The value is in ticks. Note this does not effect
3821 * old associations, only new ones.
3823 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3826 SCTP_INP_WLOCK(inp);
3828 sctp_feature_on(inp, set_opt);
3830 sctp_feature_off(inp, set_opt);
3832 SCTP_INP_WUNLOCK(inp);
3834 case SCTP_REUSE_PORT:
3836 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3837 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3838 /* Can't set it after we are bound */
3842 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3843 /* Can't do this for a 1-m socket */
3848 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3850 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3853 case SCTP_PARTIAL_DELIVERY_POINT:
3857 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3858 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3859 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3863 inp->partial_delivery_point = *value;
3866 case SCTP_FRAGMENT_INTERLEAVE:
3867 /* not yet until we re-write sctp_recvmsg() */
3871 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3872 if (*level == SCTP_FRAG_LEVEL_2) {
3873 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3874 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3875 } else if (*level == SCTP_FRAG_LEVEL_1) {
3876 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3877 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3878 } else if (*level == SCTP_FRAG_LEVEL_0) {
3879 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3880 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3883 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3888 case SCTP_INTERLEAVING_SUPPORTED:
3890 struct sctp_assoc_value *av;
3892 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3893 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3896 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3898 SCTP_TCB_UNLOCK(stcb);
3900 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3901 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3902 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3903 SCTP_INP_WLOCK(inp);
3904 if (av->assoc_value == 0) {
3905 inp->idata_supported = 0;
3907 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3908 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3909 inp->idata_supported = 1;
3917 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3921 SCTP_INP_WUNLOCK(inp);
3923 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3929 case SCTP_CMT_ON_OFF:
3930 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3931 struct sctp_assoc_value *av;
3933 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3934 if (av->assoc_value > SCTP_CMT_MAX) {
3935 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3939 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3941 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3942 SCTP_TCB_UNLOCK(stcb);
3944 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3945 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3946 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3947 (av->assoc_id == SCTP_ALL_ASSOC)) {
3948 SCTP_INP_WLOCK(inp);
3949 inp->sctp_cmt_on_off = av->assoc_value;
3950 SCTP_INP_WUNLOCK(inp);
3952 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3953 (av->assoc_id == SCTP_ALL_ASSOC)) {
3954 SCTP_INP_RLOCK(inp);
3955 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3956 SCTP_TCB_LOCK(stcb);
3957 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3958 SCTP_TCB_UNLOCK(stcb);
3960 SCTP_INP_RUNLOCK(inp);
3964 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3965 error = ENOPROTOOPT;
3968 case SCTP_PLUGGABLE_CC:
3970 struct sctp_assoc_value *av;
3971 struct sctp_nets *net;
3973 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3974 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3975 (av->assoc_value != SCTP_CC_HSTCP) &&
3976 (av->assoc_value != SCTP_CC_HTCP) &&
3977 (av->assoc_value != SCTP_CC_RTCC)) {
3978 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3982 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3984 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3985 stcb->asoc.congestion_control_module = av->assoc_value;
3986 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3987 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3988 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3991 SCTP_TCB_UNLOCK(stcb);
3993 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3994 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3995 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3996 (av->assoc_id == SCTP_ALL_ASSOC)) {
3997 SCTP_INP_WLOCK(inp);
3998 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3999 SCTP_INP_WUNLOCK(inp);
4001 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4002 (av->assoc_id == SCTP_ALL_ASSOC)) {
4003 SCTP_INP_RLOCK(inp);
4004 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4005 SCTP_TCB_LOCK(stcb);
4006 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4007 stcb->asoc.congestion_control_module = av->assoc_value;
4008 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4009 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4010 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4013 SCTP_TCB_UNLOCK(stcb);
4015 SCTP_INP_RUNLOCK(inp);
4020 case SCTP_CC_OPTION:
4022 struct sctp_cc_option *cc_opt;
4024 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4025 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4027 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4028 SCTP_INP_RLOCK(inp);
4029 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4030 SCTP_TCB_LOCK(stcb);
4031 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4032 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4034 SCTP_TCB_UNLOCK(stcb);
4036 SCTP_INP_RUNLOCK(inp);
4041 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4044 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4047 SCTP_TCB_UNLOCK(stcb);
4051 case SCTP_PLUGGABLE_SS:
4053 struct sctp_assoc_value *av;
4055 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4056 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4057 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4058 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4059 (av->assoc_value != SCTP_SS_PRIORITY) &&
4060 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4061 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4062 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4066 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4068 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4069 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4070 stcb->asoc.stream_scheduling_module = av->assoc_value;
4071 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4072 SCTP_TCB_UNLOCK(stcb);
4074 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4075 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4076 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4077 (av->assoc_id == SCTP_ALL_ASSOC)) {
4078 SCTP_INP_WLOCK(inp);
4079 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4080 SCTP_INP_WUNLOCK(inp);
4082 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4083 (av->assoc_id == SCTP_ALL_ASSOC)) {
4084 SCTP_INP_RLOCK(inp);
4085 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4086 SCTP_TCB_LOCK(stcb);
4087 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4088 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4089 stcb->asoc.stream_scheduling_module = av->assoc_value;
4090 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4091 SCTP_TCB_UNLOCK(stcb);
4093 SCTP_INP_RUNLOCK(inp);
4100 struct sctp_stream_value *av;
4102 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4103 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4105 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4106 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4107 av->stream_value) < 0)) {
4108 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4111 SCTP_TCB_UNLOCK(stcb);
4113 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4114 SCTP_INP_RLOCK(inp);
4115 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4116 SCTP_TCB_LOCK(stcb);
4117 if (av->stream_id < stcb->asoc.streamoutcnt) {
4118 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4120 &stcb->asoc.strmout[av->stream_id],
4123 SCTP_TCB_UNLOCK(stcb);
4125 SCTP_INP_RUNLOCK(inp);
4128 * Can't set stream value without
4131 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4137 case SCTP_CLR_STAT_LOG:
4138 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4143 struct sctp_assoc_value *av;
4145 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4146 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4149 stcb->asoc.context = av->assoc_value;
4150 SCTP_TCB_UNLOCK(stcb);
4152 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4153 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4154 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4155 (av->assoc_id == SCTP_ALL_ASSOC)) {
4156 SCTP_INP_WLOCK(inp);
4157 inp->sctp_context = av->assoc_value;
4158 SCTP_INP_WUNLOCK(inp);
4160 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4161 (av->assoc_id == SCTP_ALL_ASSOC)) {
4162 SCTP_INP_RLOCK(inp);
4163 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4164 SCTP_TCB_LOCK(stcb);
4165 stcb->asoc.context = av->assoc_value;
4166 SCTP_TCB_UNLOCK(stcb);
4168 SCTP_INP_RUNLOCK(inp);
4175 uint32_t *default_vrfid;
4177 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4178 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4179 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4183 inp->def_vrf_id = *default_vrfid;
4186 case SCTP_DEL_VRF_ID:
4188 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4192 case SCTP_ADD_VRF_ID:
4194 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4198 case SCTP_DELAYED_SACK:
4200 struct sctp_sack_info *sack;
4202 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4203 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4204 if (sack->sack_delay) {
4205 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4206 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4207 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4208 sack->sack_delay = TICKS_TO_MSEC(1);
4212 if (sack->sack_delay) {
4213 stcb->asoc.delayed_ack = sack->sack_delay;
4215 if (sack->sack_freq) {
4216 stcb->asoc.sack_freq = sack->sack_freq;
4218 SCTP_TCB_UNLOCK(stcb);
4220 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4221 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4222 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4223 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4224 SCTP_INP_WLOCK(inp);
4225 if (sack->sack_delay) {
4226 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4228 if (sack->sack_freq) {
4229 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4231 SCTP_INP_WUNLOCK(inp);
4233 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4234 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4235 SCTP_INP_RLOCK(inp);
4236 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4237 SCTP_TCB_LOCK(stcb);
4238 if (sack->sack_delay) {
4239 stcb->asoc.delayed_ack = sack->sack_delay;
4241 if (sack->sack_freq) {
4242 stcb->asoc.sack_freq = sack->sack_freq;
4244 SCTP_TCB_UNLOCK(stcb);
4246 SCTP_INP_RUNLOCK(inp);
4251 case SCTP_AUTH_CHUNK:
4253 struct sctp_authchunk *sauth;
4255 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4257 SCTP_INP_WLOCK(inp);
4258 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4259 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4262 inp->auth_supported = 1;
4264 SCTP_INP_WUNLOCK(inp);
4269 struct sctp_authkey *sca;
4270 struct sctp_keyhead *shared_keys;
4271 sctp_sharedkey_t *shared_key;
4272 sctp_key_t *key = NULL;
4275 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4276 if (sca->sca_keylength == 0) {
4277 size = optsize - sizeof(struct sctp_authkey);
4279 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4280 size = sca->sca_keylength;
4282 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4287 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4290 shared_keys = &stcb->asoc.shared_keys;
4291 /* clear the cached keys for this key id */
4292 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4294 * create the new shared key and
4298 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4300 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4302 SCTP_TCB_UNLOCK(stcb);
4306 shared_key = sctp_alloc_sharedkey();
4307 if (shared_key == NULL) {
4309 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4311 SCTP_TCB_UNLOCK(stcb);
4314 shared_key->key = key;
4315 shared_key->keyid = sca->sca_keynumber;
4316 error = sctp_insert_sharedkey(shared_keys, shared_key);
4317 SCTP_TCB_UNLOCK(stcb);
4319 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4320 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4321 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4322 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4323 SCTP_INP_WLOCK(inp);
4324 shared_keys = &inp->sctp_ep.shared_keys;
4326 * clear the cached keys on all
4327 * assocs for this key id
4329 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4331 * create the new shared key and
4335 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4337 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4339 SCTP_INP_WUNLOCK(inp);
4343 shared_key = sctp_alloc_sharedkey();
4344 if (shared_key == NULL) {
4346 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4348 SCTP_INP_WUNLOCK(inp);
4351 shared_key->key = key;
4352 shared_key->keyid = sca->sca_keynumber;
4353 error = sctp_insert_sharedkey(shared_keys, shared_key);
4354 SCTP_INP_WUNLOCK(inp);
4356 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4357 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4358 SCTP_INP_RLOCK(inp);
4359 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4360 SCTP_TCB_LOCK(stcb);
4361 shared_keys = &stcb->asoc.shared_keys;
4363 * clear the cached keys for
4366 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4368 * create the new shared key
4369 * and insert/replace it
4372 key = sctp_set_key(sca->sca_key, (uint32_t)size);
4374 SCTP_TCB_UNLOCK(stcb);
4378 shared_key = sctp_alloc_sharedkey();
4379 if (shared_key == NULL) {
4381 SCTP_TCB_UNLOCK(stcb);
4384 shared_key->key = key;
4385 shared_key->keyid = sca->sca_keynumber;
4386 error = sctp_insert_sharedkey(shared_keys, shared_key);
4387 SCTP_TCB_UNLOCK(stcb);
4389 SCTP_INP_RUNLOCK(inp);
4394 case SCTP_HMAC_IDENT:
4396 struct sctp_hmacalgo *shmac;
4397 sctp_hmaclist_t *hmaclist;
4401 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4402 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4403 (shmac->shmac_number_of_idents > 0xffff)) {
4404 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4409 hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents);
4410 if (hmaclist == NULL) {
4411 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4415 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4416 hmacid = shmac->shmac_idents[i];
4417 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4418 /* invalid HMACs were found */ ;
4419 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4421 sctp_free_hmaclist(hmaclist);
4422 goto sctp_set_hmac_done;
4425 for (i = 0; i < hmaclist->num_algo; i++) {
4426 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4427 /* already in list */
4431 if (i == hmaclist->num_algo) {
4432 /* not found in list */
4433 sctp_free_hmaclist(hmaclist);
4434 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4438 /* set it on the endpoint */
4439 SCTP_INP_WLOCK(inp);
4440 if (inp->sctp_ep.local_hmacs)
4441 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4442 inp->sctp_ep.local_hmacs = hmaclist;
4443 SCTP_INP_WUNLOCK(inp);
4447 case SCTP_AUTH_ACTIVE_KEY:
4449 struct sctp_authkeyid *scact;
4451 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4452 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4454 /* set the active key on the right place */
4456 /* set the active key on the assoc */
4457 if (sctp_auth_setactivekey(stcb,
4458 scact->scact_keynumber)) {
4459 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4460 SCTP_FROM_SCTP_USRREQ,
4464 SCTP_TCB_UNLOCK(stcb);
4466 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4467 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4468 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4469 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4470 SCTP_INP_WLOCK(inp);
4471 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4472 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4475 SCTP_INP_WUNLOCK(inp);
4477 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4478 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4479 SCTP_INP_RLOCK(inp);
4480 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4481 SCTP_TCB_LOCK(stcb);
4482 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4483 SCTP_TCB_UNLOCK(stcb);
4485 SCTP_INP_RUNLOCK(inp);
4490 case SCTP_AUTH_DELETE_KEY:
4492 struct sctp_authkeyid *scdel;
4494 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4495 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4497 /* delete the key from the right place */
4499 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4500 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4503 SCTP_TCB_UNLOCK(stcb);
4505 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4506 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4507 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4508 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4509 SCTP_INP_WLOCK(inp);
4510 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4511 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4514 SCTP_INP_WUNLOCK(inp);
4516 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4517 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4518 SCTP_INP_RLOCK(inp);
4519 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4520 SCTP_TCB_LOCK(stcb);
4521 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4522 SCTP_TCB_UNLOCK(stcb);
4524 SCTP_INP_RUNLOCK(inp);
4529 case SCTP_AUTH_DEACTIVATE_KEY:
4531 struct sctp_authkeyid *keyid;
4533 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4534 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4536 /* deactivate the key from the right place */
4538 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4539 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4542 SCTP_TCB_UNLOCK(stcb);
4544 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4545 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4546 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4547 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4548 SCTP_INP_WLOCK(inp);
4549 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4550 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4553 SCTP_INP_WUNLOCK(inp);
4555 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4556 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4557 SCTP_INP_RLOCK(inp);
4558 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4559 SCTP_TCB_LOCK(stcb);
4560 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4561 SCTP_TCB_UNLOCK(stcb);
4563 SCTP_INP_RUNLOCK(inp);
4568 case SCTP_ENABLE_STREAM_RESET:
4570 struct sctp_assoc_value *av;
4572 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4573 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4574 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4578 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4580 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4581 SCTP_TCB_UNLOCK(stcb);
4583 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4584 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4585 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4586 (av->assoc_id == SCTP_ALL_ASSOC)) {
4587 SCTP_INP_WLOCK(inp);
4588 inp->local_strreset_support = (uint8_t)av->assoc_value;
4589 SCTP_INP_WUNLOCK(inp);
4591 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4592 (av->assoc_id == SCTP_ALL_ASSOC)) {
4593 SCTP_INP_RLOCK(inp);
4594 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4595 SCTP_TCB_LOCK(stcb);
4596 stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value;
4597 SCTP_TCB_UNLOCK(stcb);
4599 SCTP_INP_RUNLOCK(inp);
4605 case SCTP_RESET_STREAMS:
4607 struct sctp_reset_streams *strrst;
4608 int i, send_out = 0;
4611 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4612 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4614 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4618 if (stcb->asoc.reconfig_supported == 0) {
4620 * Peer does not support the chunk type.
4622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4624 SCTP_TCB_UNLOCK(stcb);
4627 if (sizeof(struct sctp_reset_streams) +
4628 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4630 SCTP_TCB_UNLOCK(stcb);
4633 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4635 if (stcb->asoc.stream_reset_outstanding) {
4636 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4638 SCTP_TCB_UNLOCK(stcb);
4642 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4645 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4646 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4648 SCTP_TCB_UNLOCK(stcb);
4651 if ((send_in == 0) && (send_out == 0)) {
4652 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4654 SCTP_TCB_UNLOCK(stcb);
4657 for (i = 0; i < strrst->srs_number_streams; i++) {
4659 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4665 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4672 SCTP_TCB_UNLOCK(stcb);
4679 if (strrst->srs_number_streams) {
4680 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4681 strm = strrst->srs_stream_list[i];
4682 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4683 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4689 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4690 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4691 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4698 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4699 strrst->srs_stream_list,
4700 send_in, 0, 0, 0, 0, 0);
4702 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4705 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4708 * For outgoing streams don't report any
4709 * problems in sending the request to the
4710 * application. XXX: Double check resetting
4715 SCTP_TCB_UNLOCK(stcb);
4718 case SCTP_ADD_STREAMS:
4720 struct sctp_add_streams *stradd;
4721 uint8_t addstream = 0;
4722 uint16_t add_o_strmcnt = 0;
4723 uint16_t add_i_strmcnt = 0;
4725 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4726 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4728 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4732 if (stcb->asoc.reconfig_supported == 0) {
4734 * Peer does not support the chunk type.
4736 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4738 SCTP_TCB_UNLOCK(stcb);
4741 if (stcb->asoc.stream_reset_outstanding) {
4742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4744 SCTP_TCB_UNLOCK(stcb);
4747 if ((stradd->sas_outstrms == 0) &&
4748 (stradd->sas_instrms == 0)) {
4752 if (stradd->sas_outstrms) {
4754 /* We allocate here */
4755 add_o_strmcnt = stradd->sas_outstrms;
4756 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4757 /* You can't have more than 64k */
4762 if (stradd->sas_instrms) {
4767 * We allocate inside
4768 * sctp_send_str_reset_req()
4770 add_i_strmcnt = stradd->sas_instrms;
4771 cnt = add_i_strmcnt;
4772 cnt += stcb->asoc.streamincnt;
4773 if (cnt > 0x0000ffff) {
4774 /* You can't have more than 64k */
4778 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4779 /* More than you are allowed */
4784 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4785 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4787 SCTP_TCB_UNLOCK(stcb);
4790 case SCTP_RESET_ASSOC:
4795 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4796 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4798 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4802 if (stcb->asoc.reconfig_supported == 0) {
4804 * Peer does not support the chunk type.
4806 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4808 SCTP_TCB_UNLOCK(stcb);
4811 if (stcb->asoc.stream_reset_outstanding) {
4812 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4814 SCTP_TCB_UNLOCK(stcb);
4818 * Is there any data pending in the send or sent
4821 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4822 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4825 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4826 SCTP_TCB_UNLOCK(stcb);
4829 /* Do any streams have data queued? */
4830 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4831 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4835 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4836 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4837 SCTP_TCB_UNLOCK(stcb);
4840 case SCTP_CONNECT_X:
4841 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4842 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4846 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4848 case SCTP_CONNECT_X_DELAYED:
4849 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4850 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4854 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4856 case SCTP_CONNECT_X_COMPLETE:
4858 struct sockaddr *sa;
4860 /* FIXME MT: check correct? */
4861 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4864 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4865 SCTP_INP_RLOCK(inp);
4866 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4868 SCTP_TCB_LOCK(stcb);
4870 SCTP_INP_RUNLOCK(inp);
4873 * We increment here since
4874 * sctp_findassociation_ep_addr() wil do a
4875 * decrement if it finds the stcb as long as
4876 * the locked tcb (last argument) is NOT a
4879 SCTP_INP_INCR_REF(inp);
4880 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4882 SCTP_INP_DECR_REF(inp);
4887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4891 if (stcb->asoc.delayed_connection == 1) {
4892 stcb->asoc.delayed_connection = 0;
4893 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4894 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4895 stcb->asoc.primary_destination,
4896 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4897 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4900 * already expired or did not use delayed
4903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4906 SCTP_TCB_UNLOCK(stcb);
4909 case SCTP_MAX_BURST:
4911 struct sctp_assoc_value *av;
4913 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4914 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4917 stcb->asoc.max_burst = av->assoc_value;
4918 SCTP_TCB_UNLOCK(stcb);
4920 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4921 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4922 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4923 (av->assoc_id == SCTP_ALL_ASSOC)) {
4924 SCTP_INP_WLOCK(inp);
4925 inp->sctp_ep.max_burst = av->assoc_value;
4926 SCTP_INP_WUNLOCK(inp);
4928 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4929 (av->assoc_id == SCTP_ALL_ASSOC)) {
4930 SCTP_INP_RLOCK(inp);
4931 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4932 SCTP_TCB_LOCK(stcb);
4933 stcb->asoc.max_burst = av->assoc_value;
4934 SCTP_TCB_UNLOCK(stcb);
4936 SCTP_INP_RUNLOCK(inp);
4943 struct sctp_assoc_value *av;
4946 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4947 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4949 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4950 ovh = SCTP_MED_OVERHEAD;
4952 ovh = SCTP_MED_V4_OVERHEAD;
4955 if (av->assoc_value) {
4956 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4958 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4960 SCTP_TCB_UNLOCK(stcb);
4962 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4963 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4964 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4965 SCTP_INP_WLOCK(inp);
4967 * FIXME MT: I think this is not in
4968 * tune with the API ID
4970 if (av->assoc_value) {
4971 inp->sctp_frag_point = (av->assoc_value + ovh);
4973 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4975 SCTP_INP_WUNLOCK(inp);
4977 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4985 struct sctp_event_subscribe *events;
4987 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4989 SCTP_INP_WLOCK(inp);
4990 if (events->sctp_data_io_event) {
4991 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4993 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4996 if (events->sctp_association_event) {
4997 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4999 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5002 if (events->sctp_address_event) {
5003 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5005 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5008 if (events->sctp_send_failure_event) {
5009 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5011 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5014 if (events->sctp_peer_error_event) {
5015 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5017 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5020 if (events->sctp_shutdown_event) {
5021 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5023 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5026 if (events->sctp_partial_delivery_event) {
5027 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5029 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5032 if (events->sctp_adaptation_layer_event) {
5033 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5035 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5038 if (events->sctp_authentication_event) {
5039 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5041 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5044 if (events->sctp_sender_dry_event) {
5045 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5047 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5050 if (events->sctp_stream_reset_event) {
5051 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5053 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5055 SCTP_INP_WUNLOCK(inp);
5057 SCTP_INP_RLOCK(inp);
5058 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5059 SCTP_TCB_LOCK(stcb);
5060 if (events->sctp_association_event) {
5061 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5063 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5065 if (events->sctp_address_event) {
5066 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5068 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5070 if (events->sctp_send_failure_event) {
5071 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5073 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5075 if (events->sctp_peer_error_event) {
5076 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5078 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5080 if (events->sctp_shutdown_event) {
5081 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5083 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5085 if (events->sctp_partial_delivery_event) {
5086 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5088 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5090 if (events->sctp_adaptation_layer_event) {
5091 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5093 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5095 if (events->sctp_authentication_event) {
5096 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5098 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5100 if (events->sctp_sender_dry_event) {
5101 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5103 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5105 if (events->sctp_stream_reset_event) {
5106 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5108 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5110 SCTP_TCB_UNLOCK(stcb);
5113 * Send up the sender dry event only for 1-to-1
5116 if (events->sctp_sender_dry_event) {
5117 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5118 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5119 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5121 SCTP_TCB_LOCK(stcb);
5122 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5123 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5124 (stcb->asoc.stream_queue_cnt == 0)) {
5125 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5127 SCTP_TCB_UNLOCK(stcb);
5131 SCTP_INP_RUNLOCK(inp);
5134 case SCTP_ADAPTATION_LAYER:
5136 struct sctp_setadaptation *adap_bits;
5138 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5139 SCTP_INP_WLOCK(inp);
5140 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5141 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5142 SCTP_INP_WUNLOCK(inp);
5146 case SCTP_SET_INITIAL_DBG_SEQ:
5150 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5151 SCTP_INP_WLOCK(inp);
5152 inp->sctp_ep.initial_sequence_debug = *vvv;
5153 SCTP_INP_WUNLOCK(inp);
5157 case SCTP_DEFAULT_SEND_PARAM:
5159 struct sctp_sndrcvinfo *s_info;
5161 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5162 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5165 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5166 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5168 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5171 SCTP_TCB_UNLOCK(stcb);
5173 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5174 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5175 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5176 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5177 SCTP_INP_WLOCK(inp);
5178 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5179 SCTP_INP_WUNLOCK(inp);
5181 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5182 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5183 SCTP_INP_RLOCK(inp);
5184 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5185 SCTP_TCB_LOCK(stcb);
5186 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5187 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5189 SCTP_TCB_UNLOCK(stcb);
5191 SCTP_INP_RUNLOCK(inp);
5196 case SCTP_PEER_ADDR_PARAMS:
5198 struct sctp_paddrparams *paddrp;
5199 struct sctp_nets *net;
5200 struct sockaddr *addr;
5201 #if defined(INET) && defined(INET6)
5202 struct sockaddr_in sin_store;
5205 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5206 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5208 #if defined(INET) && defined(INET6)
5209 if (paddrp->spp_address.ss_family == AF_INET6) {
5210 struct sockaddr_in6 *sin6;
5212 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5213 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5214 in6_sin6_2_sin(&sin_store, sin6);
5215 addr = (struct sockaddr *)&sin_store;
5217 addr = (struct sockaddr *)&paddrp->spp_address;
5220 addr = (struct sockaddr *)&paddrp->spp_address;
5223 addr = (struct sockaddr *)&paddrp->spp_address;
5226 net = sctp_findnet(stcb, addr);
5229 * We increment here since
5230 * sctp_findassociation_ep_addr() wil do a
5231 * decrement if it finds the stcb as long as
5232 * the locked tcb (last argument) is NOT a
5236 SCTP_INP_INCR_REF(inp);
5237 stcb = sctp_findassociation_ep_addr(&inp, addr,
5240 SCTP_INP_DECR_REF(inp);
5243 if ((stcb != NULL) && (net == NULL)) {
5245 if (addr->sa_family == AF_INET) {
5247 struct sockaddr_in *sin;
5249 sin = (struct sockaddr_in *)addr;
5250 if (sin->sin_addr.s_addr != INADDR_ANY) {
5251 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5252 SCTP_TCB_UNLOCK(stcb);
5259 if (addr->sa_family == AF_INET6) {
5260 struct sockaddr_in6 *sin6;
5262 sin6 = (struct sockaddr_in6 *)addr;
5263 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5264 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5265 SCTP_TCB_UNLOCK(stcb);
5272 error = EAFNOSUPPORT;
5273 SCTP_TCB_UNLOCK(stcb);
5274 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5279 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5281 SCTP_TCB_UNLOCK(stcb);
5282 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5286 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5288 SCTP_TCB_UNLOCK(stcb);
5289 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5294 /************************TCB SPECIFIC SET ******************/
5296 /************************NET SPECIFIC SET ******************/
5297 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5298 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5299 !(net->dest_state & SCTP_ADDR_NOHB)) {
5300 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5301 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5303 net->dest_state |= SCTP_ADDR_NOHB;
5305 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5306 if (paddrp->spp_hbinterval) {
5307 net->heart_beat_delay = paddrp->spp_hbinterval;
5308 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5309 net->heart_beat_delay = 0;
5311 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5312 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5313 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5314 net->dest_state &= ~SCTP_ADDR_NOHB;
5316 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5318 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5319 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5320 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5322 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5323 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5324 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5325 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5327 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5328 net->mtu = paddrp->spp_pathmtu;
5329 switch (net->ro._l_addr.sa.sa_family) {
5332 net->mtu += SCTP_MIN_V4_OVERHEAD;
5337 net->mtu += SCTP_MIN_OVERHEAD;
5343 if (net->mtu < stcb->asoc.smallest_mtu) {
5344 sctp_pathmtu_adjustment(stcb, net->mtu);
5347 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5348 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5349 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5351 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5353 if (paddrp->spp_pathmaxrxt) {
5354 if (net->dest_state & SCTP_ADDR_PF) {
5355 if (net->error_count > paddrp->spp_pathmaxrxt) {
5356 net->dest_state &= ~SCTP_ADDR_PF;
5359 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5360 (net->error_count > net->pf_threshold)) {
5361 net->dest_state |= SCTP_ADDR_PF;
5362 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5363 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5364 stcb->sctp_ep, stcb, net,
5365 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5366 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5369 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5370 if (net->error_count > paddrp->spp_pathmaxrxt) {
5371 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5372 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5375 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5376 net->dest_state |= SCTP_ADDR_REACHABLE;
5377 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5380 net->failure_threshold = paddrp->spp_pathmaxrxt;
5382 if (paddrp->spp_flags & SPP_DSCP) {
5383 net->dscp = paddrp->spp_dscp & 0xfc;
5387 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5388 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5389 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5390 net->flowlabel |= 0x80000000;
5395 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5396 if (paddrp->spp_pathmaxrxt != 0) {
5397 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5398 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5399 if (net->dest_state & SCTP_ADDR_PF) {
5400 if (net->error_count > paddrp->spp_pathmaxrxt) {
5401 net->dest_state &= ~SCTP_ADDR_PF;
5404 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5405 (net->error_count > net->pf_threshold)) {
5406 net->dest_state |= SCTP_ADDR_PF;
5407 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5408 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5409 stcb->sctp_ep, stcb, net,
5410 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5411 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5414 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5415 if (net->error_count > paddrp->spp_pathmaxrxt) {
5416 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5417 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5420 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5421 net->dest_state |= SCTP_ADDR_REACHABLE;
5422 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5425 net->failure_threshold = paddrp->spp_pathmaxrxt;
5429 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5430 if (paddrp->spp_hbinterval != 0) {
5431 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5432 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5433 stcb->asoc.heart_beat_delay = 0;
5435 /* Turn back on the timer */
5436 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5437 if (paddrp->spp_hbinterval != 0) {
5438 net->heart_beat_delay = paddrp->spp_hbinterval;
5439 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5440 net->heart_beat_delay = 0;
5442 if (net->dest_state & SCTP_ADDR_NOHB) {
5443 net->dest_state &= ~SCTP_ADDR_NOHB;
5445 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5446 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5447 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5449 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5451 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5452 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5453 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5454 net->dest_state |= SCTP_ADDR_NOHB;
5455 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5456 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5458 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5462 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5464 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5465 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5466 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5467 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5468 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5470 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5471 net->mtu = paddrp->spp_pathmtu;
5472 switch (net->ro._l_addr.sa.sa_family) {
5475 net->mtu += SCTP_MIN_V4_OVERHEAD;
5480 net->mtu += SCTP_MIN_OVERHEAD;
5486 if (net->mtu < stcb->asoc.smallest_mtu) {
5487 sctp_pathmtu_adjustment(stcb, net->mtu);
5490 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5491 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5493 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5494 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5495 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5496 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5498 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5500 stcb->asoc.default_mtu = 0;
5501 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5503 if (paddrp->spp_flags & SPP_DSCP) {
5504 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5505 net->dscp = paddrp->spp_dscp & 0xfc;
5508 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5509 stcb->asoc.default_dscp |= 0x01;
5512 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5513 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5514 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5515 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5516 net->flowlabel |= 0x80000000;
5519 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5520 stcb->asoc.default_flowlabel |= 0x80000000;
5524 SCTP_TCB_UNLOCK(stcb);
5526 /************************NO TCB, SET TO default stuff ******************/
5527 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5528 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5529 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5530 SCTP_INP_WLOCK(inp);
5532 * For the TOS/FLOWLABEL stuff you
5533 * set it with the options on the
5536 if (paddrp->spp_pathmaxrxt != 0) {
5537 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5540 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5541 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5542 else if (paddrp->spp_hbinterval != 0) {
5543 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5544 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5545 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5548 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5549 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5550 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5551 } else if (paddrp->spp_hbinterval) {
5552 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5554 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5555 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5556 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5558 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5559 inp->sctp_ep.default_mtu = 0;
5560 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5561 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5562 if (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU) {
5563 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5565 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5567 if (paddrp->spp_flags & SPP_DSCP) {
5568 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5569 inp->sctp_ep.default_dscp |= 0x01;
5572 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5573 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5574 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5575 inp->sctp_ep.default_flowlabel |= 0x80000000;
5579 SCTP_INP_WUNLOCK(inp);
5581 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5589 struct sctp_rtoinfo *srto;
5590 uint32_t new_init, new_min, new_max;
5592 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5593 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5596 if (srto->srto_initial)
5597 new_init = srto->srto_initial;
5599 new_init = stcb->asoc.initial_rto;
5601 new_max = srto->srto_max;
5603 new_max = stcb->asoc.maxrto;
5605 new_min = srto->srto_min;
5607 new_min = stcb->asoc.minrto;
5608 if ((new_min <= new_init) && (new_init <= new_max)) {
5609 stcb->asoc.initial_rto = new_init;
5610 stcb->asoc.maxrto = new_max;
5611 stcb->asoc.minrto = new_min;
5613 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5616 SCTP_TCB_UNLOCK(stcb);
5618 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5619 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5620 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5621 SCTP_INP_WLOCK(inp);
5622 if (srto->srto_initial)
5623 new_init = srto->srto_initial;
5625 new_init = inp->sctp_ep.initial_rto;
5627 new_max = srto->srto_max;
5629 new_max = inp->sctp_ep.sctp_maxrto;
5631 new_min = srto->srto_min;
5633 new_min = inp->sctp_ep.sctp_minrto;
5634 if ((new_min <= new_init) && (new_init <= new_max)) {
5635 inp->sctp_ep.initial_rto = new_init;
5636 inp->sctp_ep.sctp_maxrto = new_max;
5637 inp->sctp_ep.sctp_minrto = new_min;
5639 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5642 SCTP_INP_WUNLOCK(inp);
5644 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5650 case SCTP_ASSOCINFO:
5652 struct sctp_assocparams *sasoc;
5654 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5655 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5656 if (sasoc->sasoc_cookie_life) {
5657 /* boundary check the cookie life */
5658 if (sasoc->sasoc_cookie_life < 1000)
5659 sasoc->sasoc_cookie_life = 1000;
5660 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5661 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5665 if (sasoc->sasoc_asocmaxrxt)
5666 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5667 if (sasoc->sasoc_cookie_life) {
5668 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5670 SCTP_TCB_UNLOCK(stcb);
5672 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5673 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5674 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5675 SCTP_INP_WLOCK(inp);
5676 if (sasoc->sasoc_asocmaxrxt)
5677 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5678 if (sasoc->sasoc_cookie_life) {
5679 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5681 SCTP_INP_WUNLOCK(inp);
5683 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5691 struct sctp_initmsg *sinit;
5693 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5694 SCTP_INP_WLOCK(inp);
5695 if (sinit->sinit_num_ostreams)
5696 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5698 if (sinit->sinit_max_instreams)
5699 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5701 if (sinit->sinit_max_attempts)
5702 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5704 if (sinit->sinit_max_init_timeo)
5705 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5706 SCTP_INP_WUNLOCK(inp);
5709 case SCTP_PRIMARY_ADDR:
5711 struct sctp_setprim *spa;
5712 struct sctp_nets *net;
5713 struct sockaddr *addr;
5714 #if defined(INET) && defined(INET6)
5715 struct sockaddr_in sin_store;
5718 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5719 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5721 #if defined(INET) && defined(INET6)
5722 if (spa->ssp_addr.ss_family == AF_INET6) {
5723 struct sockaddr_in6 *sin6;
5725 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5726 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5727 in6_sin6_2_sin(&sin_store, sin6);
5728 addr = (struct sockaddr *)&sin_store;
5730 addr = (struct sockaddr *)&spa->ssp_addr;
5733 addr = (struct sockaddr *)&spa->ssp_addr;
5736 addr = (struct sockaddr *)&spa->ssp_addr;
5739 net = sctp_findnet(stcb, addr);
5742 * We increment here since
5743 * sctp_findassociation_ep_addr() wil do a
5744 * decrement if it finds the stcb as long as
5745 * the locked tcb (last argument) is NOT a
5749 SCTP_INP_INCR_REF(inp);
5750 stcb = sctp_findassociation_ep_addr(&inp, addr,
5753 SCTP_INP_DECR_REF(inp);
5757 if ((stcb != NULL) && (net != NULL)) {
5758 if (net != stcb->asoc.primary_destination) {
5759 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5760 /* Ok we need to set it */
5761 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5762 if ((stcb->asoc.alternate) &&
5763 (!(net->dest_state & SCTP_ADDR_PF)) &&
5764 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5765 sctp_free_remote_addr(stcb->asoc.alternate);
5766 stcb->asoc.alternate = NULL;
5769 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5778 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5782 SCTP_TCB_UNLOCK(stcb);
5786 case SCTP_SET_DYNAMIC_PRIMARY:
5788 union sctp_sockstore *ss;
5790 error = priv_check(curthread,
5791 PRIV_NETINET_RESERVEDPORT);
5795 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5796 /* SUPER USER CHECK? */
5797 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5800 case SCTP_SET_PEER_PRIMARY_ADDR:
5802 struct sctp_setpeerprim *sspp;
5803 struct sockaddr *addr;
5804 #if defined(INET) && defined(INET6)
5805 struct sockaddr_in sin_store;
5808 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5809 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5811 struct sctp_ifa *ifa;
5813 #if defined(INET) && defined(INET6)
5814 if (sspp->sspp_addr.ss_family == AF_INET6) {
5815 struct sockaddr_in6 *sin6;
5817 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5818 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5819 in6_sin6_2_sin(&sin_store, sin6);
5820 addr = (struct sockaddr *)&sin_store;
5822 addr = (struct sockaddr *)&sspp->sspp_addr;
5825 addr = (struct sockaddr *)&sspp->sspp_addr;
5828 addr = (struct sockaddr *)&sspp->sspp_addr;
5830 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5832 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5836 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5838 * Must validate the ifa found is in
5841 struct sctp_laddr *laddr;
5844 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5845 if (laddr->ifa == NULL) {
5846 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5850 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5851 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5854 if (laddr->ifa == ifa) {
5860 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5865 switch (addr->sa_family) {
5869 struct sockaddr_in *sin;
5871 sin = (struct sockaddr_in *)addr;
5872 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5873 &sin->sin_addr) != 0) {
5874 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5884 struct sockaddr_in6 *sin6;
5886 sin6 = (struct sockaddr_in6 *)addr;
5887 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5888 &sin6->sin6_addr) != 0) {
5889 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5902 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5906 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5908 SCTP_TCB_UNLOCK(stcb);
5910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5915 case SCTP_BINDX_ADD_ADDR:
5917 struct sctp_getaddresses *addrs;
5920 td = (struct thread *)p;
5921 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5924 if (addrs->addr->sa_family == AF_INET) {
5925 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5926 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5930 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5931 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5937 if (addrs->addr->sa_family == AF_INET6) {
5938 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5943 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5944 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5945 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5951 error = EAFNOSUPPORT;
5954 sctp_bindx_add_address(so, inp, addrs->addr,
5955 addrs->sget_assoc_id, vrf_id,
5959 case SCTP_BINDX_REM_ADDR:
5961 struct sctp_getaddresses *addrs;
5964 td = (struct thread *)p;
5966 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5968 if (addrs->addr->sa_family == AF_INET) {
5969 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5970 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5974 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5975 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5981 if (addrs->addr->sa_family == AF_INET6) {
5982 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5983 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5988 (error = prison_local_ip6(td->td_ucred,
5989 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5990 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5991 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5997 error = EAFNOSUPPORT;
6000 sctp_bindx_delete_address(inp, addrs->addr,
6001 addrs->sget_assoc_id, vrf_id,
6007 struct sctp_event *event;
6008 uint32_t event_type;
6010 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6011 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6012 switch (event->se_type) {
6013 case SCTP_ASSOC_CHANGE:
6014 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6016 case SCTP_PEER_ADDR_CHANGE:
6017 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6019 case SCTP_REMOTE_ERROR:
6020 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6022 case SCTP_SEND_FAILED:
6023 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6025 case SCTP_SHUTDOWN_EVENT:
6026 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6028 case SCTP_ADAPTATION_INDICATION:
6029 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6031 case SCTP_PARTIAL_DELIVERY_EVENT:
6032 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6034 case SCTP_AUTHENTICATION_EVENT:
6035 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6037 case SCTP_STREAM_RESET_EVENT:
6038 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6040 case SCTP_SENDER_DRY_EVENT:
6041 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6043 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6045 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6048 case SCTP_ASSOC_RESET_EVENT:
6049 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6051 case SCTP_STREAM_CHANGE_EVENT:
6052 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6054 case SCTP_SEND_FAILED_EVENT:
6055 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6059 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6063 if (event_type > 0) {
6066 sctp_stcb_feature_on(inp, stcb, event_type);
6067 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6068 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6069 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6070 (stcb->asoc.stream_queue_cnt == 0)) {
6071 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6075 sctp_stcb_feature_off(inp, stcb, event_type);
6077 SCTP_TCB_UNLOCK(stcb);
6080 * We don't want to send up a storm
6081 * of events, so return an error for
6084 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6085 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6086 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6087 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6088 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6089 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6093 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6094 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6095 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6096 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6097 SCTP_INP_WLOCK(inp);
6099 sctp_feature_on(inp, event_type);
6101 sctp_feature_off(inp, event_type);
6103 SCTP_INP_WUNLOCK(inp);
6105 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6106 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6107 SCTP_INP_RLOCK(inp);
6108 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6109 SCTP_TCB_LOCK(stcb);
6111 sctp_stcb_feature_on(inp, stcb, event_type);
6113 sctp_stcb_feature_off(inp, stcb, event_type);
6115 SCTP_TCB_UNLOCK(stcb);
6117 SCTP_INP_RUNLOCK(inp);
6123 case SCTP_RECVRCVINFO:
6127 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6128 SCTP_INP_WLOCK(inp);
6130 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6132 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6134 SCTP_INP_WUNLOCK(inp);
6137 case SCTP_RECVNXTINFO:
6141 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6142 SCTP_INP_WLOCK(inp);
6144 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6146 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6148 SCTP_INP_WUNLOCK(inp);
6151 case SCTP_DEFAULT_SNDINFO:
6153 struct sctp_sndinfo *info;
6156 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6157 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6160 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6161 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6162 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6163 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6164 stcb->asoc.def_send.sinfo_flags |= policy;
6165 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6166 stcb->asoc.def_send.sinfo_context = info->snd_context;
6168 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6171 SCTP_TCB_UNLOCK(stcb);
6173 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6174 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6175 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6176 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6177 SCTP_INP_WLOCK(inp);
6178 inp->def_send.sinfo_stream = info->snd_sid;
6179 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6180 inp->def_send.sinfo_flags = info->snd_flags;
6181 inp->def_send.sinfo_flags |= policy;
6182 inp->def_send.sinfo_ppid = info->snd_ppid;
6183 inp->def_send.sinfo_context = info->snd_context;
6184 SCTP_INP_WUNLOCK(inp);
6186 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6187 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6188 SCTP_INP_RLOCK(inp);
6189 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6190 SCTP_TCB_LOCK(stcb);
6191 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6192 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6193 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6194 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6195 stcb->asoc.def_send.sinfo_flags |= policy;
6196 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6197 stcb->asoc.def_send.sinfo_context = info->snd_context;
6199 SCTP_TCB_UNLOCK(stcb);
6201 SCTP_INP_RUNLOCK(inp);
6206 case SCTP_DEFAULT_PRINFO:
6208 struct sctp_default_prinfo *info;
6210 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6211 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6213 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6214 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6219 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6220 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6221 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6222 SCTP_TCB_UNLOCK(stcb);
6224 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6225 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6226 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6227 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6228 SCTP_INP_WLOCK(inp);
6229 inp->def_send.sinfo_flags &= 0xfff0;
6230 inp->def_send.sinfo_flags |= info->pr_policy;
6231 inp->def_send.sinfo_timetolive = info->pr_value;
6232 SCTP_INP_WUNLOCK(inp);
6234 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6235 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6236 SCTP_INP_RLOCK(inp);
6237 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6238 SCTP_TCB_LOCK(stcb);
6239 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6240 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6241 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6242 SCTP_TCB_UNLOCK(stcb);
6244 SCTP_INP_RUNLOCK(inp);
6249 case SCTP_PEER_ADDR_THLDS:
6250 /* Applies to the specific association */
6252 struct sctp_paddrthlds *thlds;
6253 struct sctp_nets *net;
6254 struct sockaddr *addr;
6255 #if defined(INET) && defined(INET6)
6256 struct sockaddr_in sin_store;
6259 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6260 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6262 #if defined(INET) && defined(INET6)
6263 if (thlds->spt_address.ss_family == AF_INET6) {
6264 struct sockaddr_in6 *sin6;
6266 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6267 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6268 in6_sin6_2_sin(&sin_store, sin6);
6269 addr = (struct sockaddr *)&sin_store;
6271 addr = (struct sockaddr *)&thlds->spt_address;
6274 addr = (struct sockaddr *)&thlds->spt_address;
6277 addr = (struct sockaddr *)&thlds->spt_address;
6280 net = sctp_findnet(stcb, addr);
6283 * We increment here since
6284 * sctp_findassociation_ep_addr() wil do a
6285 * decrement if it finds the stcb as long as
6286 * the locked tcb (last argument) is NOT a
6290 SCTP_INP_INCR_REF(inp);
6291 stcb = sctp_findassociation_ep_addr(&inp, addr,
6294 SCTP_INP_DECR_REF(inp);
6297 if ((stcb != NULL) && (net == NULL)) {
6299 if (addr->sa_family == AF_INET) {
6301 struct sockaddr_in *sin;
6303 sin = (struct sockaddr_in *)addr;
6304 if (sin->sin_addr.s_addr != INADDR_ANY) {
6305 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6306 SCTP_TCB_UNLOCK(stcb);
6313 if (addr->sa_family == AF_INET6) {
6314 struct sockaddr_in6 *sin6;
6316 sin6 = (struct sockaddr_in6 *)addr;
6317 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6318 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6319 SCTP_TCB_UNLOCK(stcb);
6326 error = EAFNOSUPPORT;
6327 SCTP_TCB_UNLOCK(stcb);
6328 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6332 if (thlds->spt_pathcpthld != 0xffff) {
6334 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6339 net->failure_threshold = thlds->spt_pathmaxrxt;
6340 net->pf_threshold = thlds->spt_pathpfthld;
6341 if (net->dest_state & SCTP_ADDR_PF) {
6342 if ((net->error_count > net->failure_threshold) ||
6343 (net->error_count <= net->pf_threshold)) {
6344 net->dest_state &= ~SCTP_ADDR_PF;
6347 if ((net->error_count > net->pf_threshold) &&
6348 (net->error_count <= net->failure_threshold)) {
6349 net->dest_state |= SCTP_ADDR_PF;
6350 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6351 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6352 stcb->sctp_ep, stcb, net,
6353 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6354 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6357 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6358 if (net->error_count > net->failure_threshold) {
6359 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6360 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6363 if (net->error_count <= net->failure_threshold) {
6364 net->dest_state |= SCTP_ADDR_REACHABLE;
6365 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6369 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6370 net->failure_threshold = thlds->spt_pathmaxrxt;
6371 net->pf_threshold = thlds->spt_pathpfthld;
6372 if (net->dest_state & SCTP_ADDR_PF) {
6373 if ((net->error_count > net->failure_threshold) ||
6374 (net->error_count <= net->pf_threshold)) {
6375 net->dest_state &= ~SCTP_ADDR_PF;
6378 if ((net->error_count > net->pf_threshold) &&
6379 (net->error_count <= net->failure_threshold)) {
6380 net->dest_state |= SCTP_ADDR_PF;
6381 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6382 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6383 stcb->sctp_ep, stcb, net,
6384 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6385 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6388 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6389 if (net->error_count > net->failure_threshold) {
6390 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6391 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6394 if (net->error_count <= net->failure_threshold) {
6395 net->dest_state |= SCTP_ADDR_REACHABLE;
6396 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6400 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6401 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6403 SCTP_TCB_UNLOCK(stcb);
6405 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6406 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6407 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6408 SCTP_INP_WLOCK(inp);
6409 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6410 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6411 SCTP_INP_WUNLOCK(inp);
6413 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6419 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6421 struct sctp_udpencaps *encaps;
6422 struct sctp_nets *net;
6423 struct sockaddr *addr;
6424 #if defined(INET) && defined(INET6)
6425 struct sockaddr_in sin_store;
6428 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6429 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6431 #if defined(INET) && defined(INET6)
6432 if (encaps->sue_address.ss_family == AF_INET6) {
6433 struct sockaddr_in6 *sin6;
6435 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6436 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6437 in6_sin6_2_sin(&sin_store, sin6);
6438 addr = (struct sockaddr *)&sin_store;
6440 addr = (struct sockaddr *)&encaps->sue_address;
6443 addr = (struct sockaddr *)&encaps->sue_address;
6446 addr = (struct sockaddr *)&encaps->sue_address;
6449 net = sctp_findnet(stcb, addr);
6452 * We increment here since
6453 * sctp_findassociation_ep_addr() wil do a
6454 * decrement if it finds the stcb as long as
6455 * the locked tcb (last argument) is NOT a
6459 SCTP_INP_INCR_REF(inp);
6460 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6462 SCTP_INP_DECR_REF(inp);
6465 if ((stcb != NULL) && (net == NULL)) {
6467 if (addr->sa_family == AF_INET) {
6469 struct sockaddr_in *sin;
6471 sin = (struct sockaddr_in *)addr;
6472 if (sin->sin_addr.s_addr != INADDR_ANY) {
6473 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6474 SCTP_TCB_UNLOCK(stcb);
6481 if (addr->sa_family == AF_INET6) {
6482 struct sockaddr_in6 *sin6;
6484 sin6 = (struct sockaddr_in6 *)addr;
6485 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6486 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6487 SCTP_TCB_UNLOCK(stcb);
6494 error = EAFNOSUPPORT;
6495 SCTP_TCB_UNLOCK(stcb);
6496 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6503 net->port = encaps->sue_port;
6505 stcb->asoc.port = encaps->sue_port;
6507 SCTP_TCB_UNLOCK(stcb);
6509 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6510 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6511 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6512 SCTP_INP_WLOCK(inp);
6513 inp->sctp_ep.port = encaps->sue_port;
6514 SCTP_INP_WUNLOCK(inp);
6516 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6522 case SCTP_ECN_SUPPORTED:
6524 struct sctp_assoc_value *av;
6526 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6527 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6530 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6532 SCTP_TCB_UNLOCK(stcb);
6534 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6535 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6536 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6537 SCTP_INP_WLOCK(inp);
6538 if (av->assoc_value == 0) {
6539 inp->ecn_supported = 0;
6541 inp->ecn_supported = 1;
6543 SCTP_INP_WUNLOCK(inp);
6545 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6551 case SCTP_PR_SUPPORTED:
6553 struct sctp_assoc_value *av;
6555 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6556 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6559 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6561 SCTP_TCB_UNLOCK(stcb);
6563 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6564 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6565 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6566 SCTP_INP_WLOCK(inp);
6567 if (av->assoc_value == 0) {
6568 inp->prsctp_supported = 0;
6570 inp->prsctp_supported = 1;
6572 SCTP_INP_WUNLOCK(inp);
6574 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6580 case SCTP_AUTH_SUPPORTED:
6582 struct sctp_assoc_value *av;
6584 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6585 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6588 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6590 SCTP_TCB_UNLOCK(stcb);
6592 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6593 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6594 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6595 if ((av->assoc_value == 0) &&
6596 (inp->asconf_supported == 1)) {
6598 * AUTH is required for
6601 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6604 SCTP_INP_WLOCK(inp);
6605 if (av->assoc_value == 0) {
6606 inp->auth_supported = 0;
6608 inp->auth_supported = 1;
6610 SCTP_INP_WUNLOCK(inp);
6613 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6619 case SCTP_ASCONF_SUPPORTED:
6621 struct sctp_assoc_value *av;
6623 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6624 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6627 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6629 SCTP_TCB_UNLOCK(stcb);
6631 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6632 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6633 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6634 if ((av->assoc_value != 0) &&
6635 (inp->auth_supported == 0)) {
6637 * AUTH is required for
6640 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6643 SCTP_INP_WLOCK(inp);
6644 if (av->assoc_value == 0) {
6645 inp->asconf_supported = 0;
6646 sctp_auth_delete_chunk(SCTP_ASCONF,
6647 inp->sctp_ep.local_auth_chunks);
6648 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6649 inp->sctp_ep.local_auth_chunks);
6651 inp->asconf_supported = 1;
6652 sctp_auth_add_chunk(SCTP_ASCONF,
6653 inp->sctp_ep.local_auth_chunks);
6654 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6655 inp->sctp_ep.local_auth_chunks);
6657 SCTP_INP_WUNLOCK(inp);
6660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6666 case SCTP_RECONFIG_SUPPORTED:
6668 struct sctp_assoc_value *av;
6670 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6671 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6674 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6676 SCTP_TCB_UNLOCK(stcb);
6678 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6679 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6680 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6681 SCTP_INP_WLOCK(inp);
6682 if (av->assoc_value == 0) {
6683 inp->reconfig_supported = 0;
6685 inp->reconfig_supported = 1;
6687 SCTP_INP_WUNLOCK(inp);
6689 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6695 case SCTP_NRSACK_SUPPORTED:
6697 struct sctp_assoc_value *av;
6699 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6700 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6703 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6705 SCTP_TCB_UNLOCK(stcb);
6707 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6708 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6709 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6710 SCTP_INP_WLOCK(inp);
6711 if (av->assoc_value == 0) {
6712 inp->nrsack_supported = 0;
6714 inp->nrsack_supported = 1;
6716 SCTP_INP_WUNLOCK(inp);
6718 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6724 case SCTP_PKTDROP_SUPPORTED:
6726 struct sctp_assoc_value *av;
6728 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6729 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6732 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6734 SCTP_TCB_UNLOCK(stcb);
6736 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6737 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6738 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6739 SCTP_INP_WLOCK(inp);
6740 if (av->assoc_value == 0) {
6741 inp->pktdrop_supported = 0;
6743 inp->pktdrop_supported = 1;
6745 SCTP_INP_WUNLOCK(inp);
6747 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6755 struct sctp_assoc_value *av;
6756 struct sctp_nets *net;
6758 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6759 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6762 stcb->asoc.max_cwnd = av->assoc_value;
6763 if (stcb->asoc.max_cwnd > 0) {
6764 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6765 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6766 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6767 net->cwnd = stcb->asoc.max_cwnd;
6768 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6769 net->cwnd = net->mtu - sizeof(struct sctphdr);
6774 SCTP_TCB_UNLOCK(stcb);
6776 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6777 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6778 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6779 SCTP_INP_WLOCK(inp);
6780 inp->max_cwnd = av->assoc_value;
6781 SCTP_INP_WUNLOCK(inp);
6783 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6790 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6791 error = ENOPROTOOPT;
6793 } /* end switch (opt) */
6798 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6800 void *optval = NULL;
6804 struct sctp_inpcb *inp;
6806 if ((sopt->sopt_level == SOL_SOCKET) &&
6807 (sopt->sopt_name == SO_SETFIB)) {
6808 inp = (struct sctp_inpcb *)so->so_pcb;
6810 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6813 SCTP_INP_WLOCK(inp);
6814 inp->fibnum = so->so_fibnum;
6815 SCTP_INP_WUNLOCK(inp);
6818 if (sopt->sopt_level != IPPROTO_SCTP) {
6819 /* wrong proto level... send back up to IP */
6821 if (INP_CHECK_SOCKAF(so, AF_INET6))
6822 error = ip6_ctloutput(so, sopt);
6824 #if defined(INET) && defined(INET6)
6828 error = ip_ctloutput(so, sopt);
6832 optsize = sopt->sopt_valsize;
6834 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6835 if (optval == NULL) {
6836 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6839 error = sooptcopyin(sopt, optval, optsize, optsize);
6841 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6845 p = (void *)sopt->sopt_td;
6846 if (sopt->sopt_dir == SOPT_SET) {
6847 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6848 } else if (sopt->sopt_dir == SOPT_GET) {
6849 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6851 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6854 if ((error == 0) && (optval != NULL)) {
6855 error = sooptcopyout(sopt, optval, optsize);
6856 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6857 } else if (optval != NULL) {
6858 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6866 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6869 int create_lock_on = 0;
6871 struct sctp_inpcb *inp;
6872 struct sctp_tcb *stcb = NULL;
6874 inp = (struct sctp_inpcb *)so->so_pcb;
6876 /* I made the same as TCP since we are not setup? */
6877 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6878 return (ECONNRESET);
6881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6885 switch (addr->sa_family) {
6889 struct sockaddr_in6 *sin6p;
6891 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6892 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6895 sin6p = (struct sockaddr_in6 *)addr;
6896 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6906 struct sockaddr_in *sinp;
6908 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6909 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6912 sinp = (struct sockaddr_in *)addr;
6913 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6914 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6922 return (EAFNOSUPPORT);
6924 SCTP_INP_INCR_REF(inp);
6925 SCTP_ASOC_CREATE_LOCK(inp);
6929 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6930 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6931 /* Should I really unlock ? */
6932 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6937 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6938 (addr->sa_family == AF_INET6)) {
6939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6944 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6945 SCTP_PCB_FLAGS_UNBOUND) {
6946 /* Bind a ephemeral port */
6947 error = sctp_inpcb_bind(so, NULL, NULL, p);
6952 /* Now do we connect? */
6953 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6954 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6955 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6959 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6960 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6961 /* We are already connected AND the TCP model */
6962 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6966 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6967 SCTP_INP_RLOCK(inp);
6968 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6969 SCTP_INP_RUNLOCK(inp);
6972 * We increment here since sctp_findassociation_ep_addr()
6973 * will do a decrement if it finds the stcb as long as the
6974 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6976 SCTP_INP_INCR_REF(inp);
6977 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6979 SCTP_INP_DECR_REF(inp);
6981 SCTP_TCB_UNLOCK(stcb);
6985 /* Already have or am bring up an association */
6986 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6991 vrf_id = inp->def_vrf_id;
6992 /* We are GOOD to go */
6993 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
6994 inp->sctp_ep.pre_open_stream_count,
6995 inp->sctp_ep.port, p);
6997 /* Gak! no memory */
7000 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7001 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7002 /* Set the connected flag so we can queue data */
7005 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7006 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7008 /* initialize authentication parameters for the assoc */
7009 sctp_initialize_auth_params(inp, stcb);
7011 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7012 SCTP_TCB_UNLOCK(stcb);
7014 if (create_lock_on) {
7015 SCTP_ASOC_CREATE_UNLOCK(inp);
7018 SCTP_INP_DECR_REF(inp);
7024 sctp_listen(struct socket *so, int backlog, struct thread *p)
7027 * Note this module depends on the protocol processing being called
7028 * AFTER any socket level flags and backlog are applied to the
7029 * socket. The traditional way that the socket flags are applied is
7030 * AFTER protocol processing. We have made a change to the
7031 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7032 * place if the socket API for SCTP is to work properly.
7036 struct sctp_inpcb *inp;
7038 inp = (struct sctp_inpcb *)so->so_pcb;
7040 /* I made the same as TCP since we are not setup? */
7041 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7042 return (ECONNRESET);
7044 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7045 /* See if we have a listener */
7046 struct sctp_inpcb *tinp;
7047 union sctp_sockstore store;
7049 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7051 struct sctp_laddr *laddr;
7053 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7054 memcpy(&store, &laddr->ifa->address, sizeof(store));
7055 switch (store.sa.sa_family) {
7058 store.sin.sin_port = inp->sctp_lport;
7063 store.sin6.sin6_port = inp->sctp_lport;
7069 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7070 if (tinp && (tinp != inp) &&
7071 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7072 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7073 (SCTP_IS_LISTENING(tinp))) {
7075 * we have a listener already and
7078 SCTP_INP_DECR_REF(tinp);
7079 return (EADDRINUSE);
7081 SCTP_INP_DECR_REF(tinp);
7085 /* Setup a local addr bound all */
7086 memset(&store, 0, sizeof(store));
7088 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7089 store.sa.sa_family = AF_INET6;
7090 store.sa.sa_len = sizeof(struct sockaddr_in6);
7094 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7095 store.sa.sa_family = AF_INET;
7096 store.sa.sa_len = sizeof(struct sockaddr_in);
7099 switch (store.sa.sa_family) {
7102 store.sin.sin_port = inp->sctp_lport;
7107 store.sin6.sin6_port = inp->sctp_lport;
7113 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7114 if (tinp && (tinp != inp) &&
7115 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7116 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7117 (SCTP_IS_LISTENING(tinp))) {
7119 * we have a listener already and its not
7122 SCTP_INP_DECR_REF(tinp);
7123 return (EADDRINUSE);
7125 SCTP_INP_DECR_REF(tinp);
7129 SCTP_INP_RLOCK(inp);
7130 #ifdef SCTP_LOCK_LOGGING
7131 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7132 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7136 error = solisten_proto_check(so);
7139 SCTP_INP_RUNLOCK(inp);
7142 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7143 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7145 * The unlucky case - We are in the tcp pool with this guy.
7146 * - Someone else is in the main inp slot. - We must move
7147 * this guy (the listener) to the main slot - We must then
7148 * move the guy that was listener to the TCP Pool.
7150 if (sctp_swap_inpcb_for_listen(inp)) {
7151 SCTP_INP_RUNLOCK(inp);
7152 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7153 return (EADDRINUSE);
7157 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7158 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7159 /* We are already connected AND the TCP model */
7160 SCTP_INP_RUNLOCK(inp);
7161 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7162 return (EADDRINUSE);
7164 SCTP_INP_RUNLOCK(inp);
7165 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7166 /* We must do a bind. */
7167 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7168 /* bind error, probably perm */
7172 SCTP_INP_WLOCK(inp);
7173 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7175 solisten_proto(so, backlog);
7179 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7181 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7183 SCTP_INP_WUNLOCK(inp);
7187 static int sctp_defered_wakeup_cnt = 0;
7190 sctp_accept(struct socket *so, struct sockaddr **addr)
7192 struct sctp_tcb *stcb;
7193 struct sctp_inpcb *inp;
7194 union sctp_sockstore store;
7198 inp = (struct sctp_inpcb *)so->so_pcb;
7201 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7202 return (ECONNRESET);
7204 SCTP_INP_RLOCK(inp);
7205 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7206 SCTP_INP_RUNLOCK(inp);
7207 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7208 return (EOPNOTSUPP);
7210 if (so->so_state & SS_ISDISCONNECTED) {
7211 SCTP_INP_RUNLOCK(inp);
7212 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7213 return (ECONNABORTED);
7215 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7217 SCTP_INP_RUNLOCK(inp);
7218 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7219 return (ECONNRESET);
7221 SCTP_TCB_LOCK(stcb);
7222 SCTP_INP_RUNLOCK(inp);
7223 store = stcb->asoc.primary_destination->ro._l_addr;
7224 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7225 SCTP_TCB_UNLOCK(stcb);
7226 switch (store.sa.sa_family) {
7230 struct sockaddr_in *sin;
7232 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7235 sin->sin_family = AF_INET;
7236 sin->sin_len = sizeof(*sin);
7237 sin->sin_port = store.sin.sin_port;
7238 sin->sin_addr = store.sin.sin_addr;
7239 *addr = (struct sockaddr *)sin;
7246 struct sockaddr_in6 *sin6;
7248 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7251 sin6->sin6_family = AF_INET6;
7252 sin6->sin6_len = sizeof(*sin6);
7253 sin6->sin6_port = store.sin6.sin6_port;
7254 sin6->sin6_addr = store.sin6.sin6_addr;
7255 if ((error = sa6_recoverscope(sin6)) != 0) {
7256 SCTP_FREE_SONAME(sin6);
7259 *addr = (struct sockaddr *)sin6;
7267 /* Wake any delayed sleep action */
7268 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7269 SCTP_INP_WLOCK(inp);
7270 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7271 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7272 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7273 SCTP_INP_WUNLOCK(inp);
7274 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7275 if (sowriteable(inp->sctp_socket)) {
7276 sowwakeup_locked(inp->sctp_socket);
7278 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7280 SCTP_INP_WLOCK(inp);
7282 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7283 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7284 SCTP_INP_WUNLOCK(inp);
7285 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7286 if (soreadable(inp->sctp_socket)) {
7287 sctp_defered_wakeup_cnt++;
7288 sorwakeup_locked(inp->sctp_socket);
7290 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7292 SCTP_INP_WLOCK(inp);
7294 SCTP_INP_WUNLOCK(inp);
7296 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7297 SCTP_TCB_LOCK(stcb);
7298 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7299 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7306 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7308 struct sockaddr_in *sin;
7310 struct sctp_inpcb *inp;
7311 struct sctp_ifa *sctp_ifa;
7314 * Do the malloc first in case it blocks.
7316 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7319 sin->sin_family = AF_INET;
7320 sin->sin_len = sizeof(*sin);
7321 inp = (struct sctp_inpcb *)so->so_pcb;
7323 SCTP_FREE_SONAME(sin);
7324 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7325 return (ECONNRESET);
7327 SCTP_INP_RLOCK(inp);
7328 sin->sin_port = inp->sctp_lport;
7329 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7330 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7331 struct sctp_tcb *stcb;
7332 struct sockaddr_in *sin_a;
7333 struct sctp_nets *net;
7336 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7342 SCTP_TCB_LOCK(stcb);
7343 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7344 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7346 /* this will make coverity happy */
7349 if (sin_a->sin_family == AF_INET) {
7354 if ((!fnd) || (sin_a == NULL)) {
7356 SCTP_TCB_UNLOCK(stcb);
7360 vrf_id = inp->def_vrf_id;
7361 sctp_ifa = sctp_source_address_selection(inp,
7363 (sctp_route_t *)&net->ro,
7366 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7367 sctp_free_ifa(sctp_ifa);
7369 SCTP_TCB_UNLOCK(stcb);
7371 /* For the bound all case you get back 0 */
7373 sin->sin_addr.s_addr = 0;
7377 /* Take the first IPv4 address in the list */
7378 struct sctp_laddr *laddr;
7381 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7382 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7383 struct sockaddr_in *sin_a;
7385 sin_a = &laddr->ifa->address.sin;
7386 sin->sin_addr = sin_a->sin_addr;
7392 SCTP_FREE_SONAME(sin);
7393 SCTP_INP_RUNLOCK(inp);
7394 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7398 SCTP_INP_RUNLOCK(inp);
7399 (*addr) = (struct sockaddr *)sin;
7404 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7406 struct sockaddr_in *sin;
7408 struct sockaddr_in *sin_a;
7409 struct sctp_inpcb *inp;
7410 struct sctp_tcb *stcb;
7411 struct sctp_nets *net;
7413 /* Do the malloc first in case it blocks. */
7414 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7417 sin->sin_family = AF_INET;
7418 sin->sin_len = sizeof(*sin);
7420 inp = (struct sctp_inpcb *)so->so_pcb;
7421 if ((inp == NULL) ||
7422 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7423 /* UDP type and listeners will drop out here */
7424 SCTP_FREE_SONAME(sin);
7425 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7428 SCTP_INP_RLOCK(inp);
7429 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7431 SCTP_TCB_LOCK(stcb);
7433 SCTP_INP_RUNLOCK(inp);
7435 SCTP_FREE_SONAME(sin);
7436 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7437 return (ECONNRESET);
7440 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7441 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7442 if (sin_a->sin_family == AF_INET) {
7444 sin->sin_port = stcb->rport;
7445 sin->sin_addr = sin_a->sin_addr;
7449 SCTP_TCB_UNLOCK(stcb);
7451 /* No IPv4 address */
7452 SCTP_FREE_SONAME(sin);
7453 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7456 (*addr) = (struct sockaddr *)sin;
7460 struct pr_usrreqs sctp_usrreqs = {
7461 .pru_abort = sctp_abort,
7462 .pru_accept = sctp_accept,
7463 .pru_attach = sctp_attach,
7464 .pru_bind = sctp_bind,
7465 .pru_connect = sctp_connect,
7466 .pru_control = in_control,
7467 .pru_close = sctp_close,
7468 .pru_detach = sctp_close,
7469 .pru_sopoll = sopoll_generic,
7470 .pru_flush = sctp_flush,
7471 .pru_disconnect = sctp_disconnect,
7472 .pru_listen = sctp_listen,
7473 .pru_peeraddr = sctp_peeraddr,
7474 .pru_send = sctp_sendm,
7475 .pru_shutdown = sctp_shutdown,
7476 .pru_sockaddr = sctp_ingetaddr,
7477 .pru_sosend = sctp_sosend,
7478 .pru_soreceive = sctp_soreceive