2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
5 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
6 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * a) Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
14 * b) Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the distribution.
18 * c) Neither the name of Cisco Systems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <netinet/sctp_os.h>
40 #include <netinet/sctp_pcb.h>
41 #include <netinet/sctp_header.h>
42 #include <netinet/sctp_var.h>
44 #include <netinet6/sctp6_var.h>
46 #include <netinet/sctp_sysctl.h>
47 #include <netinet/sctp_output.h>
48 #include <netinet/sctp_uio.h>
49 #include <netinet/sctp_asconf.h>
50 #include <netinet/sctputil.h>
51 #include <netinet/sctp_indata.h>
52 #include <netinet/sctp_timer.h>
53 #include <netinet/sctp_auth.h>
54 #include <netinet/sctp_bsd_addr.h>
55 #include <netinet/udp.h>
59 extern const struct sctp_cc_functions sctp_cc_functions[];
60 extern const struct sctp_ss_functions sctp_ss_functions[];
67 /* Initialize and modify the sysctled variables */
69 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
70 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
72 * Allow a user to take no more than 1/2 the number of clusters or
73 * the SB_MAX whichever is smaller for the send window.
75 sb_max_adj = (u_long)((u_quad_t)(SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
76 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
77 (((uint32_t)nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
79 * Now for the recv window, should we take the same amount? or
80 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
81 * now I will just copy.
83 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
84 SCTP_BASE_VAR(first_time) = 0;
85 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
87 #if defined(SCTP_PACKET_LOGGING)
88 SCTP_BASE_VAR(packet_log_writers) = 0;
89 SCTP_BASE_VAR(packet_log_end) = 0;
90 memset(&SCTP_BASE_VAR(packet_log_buffer), 0, SCTP_PACKET_LOG_SIZE);
96 sctp_finish(void *unused __unused)
101 VNET_SYSUNINIT(sctp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, sctp_finish, NULL);
105 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
107 struct sctp_tmit_chunk *chk;
110 /* Adjust that too */
111 stcb->asoc.smallest_mtu = nxtsz;
112 /* now off to subtract IP_DF flag if needed */
113 overhead = IP_HDR_SIZE + sizeof(struct sctphdr);
114 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
115 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
117 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
118 if ((chk->send_size + overhead) > nxtsz) {
119 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
122 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
123 if ((chk->send_size + overhead) > nxtsz) {
125 * For this guy we also mark for immediate resend
126 * since we sent to big of chunk
128 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
129 if (chk->sent < SCTP_DATAGRAM_RESEND) {
130 sctp_flight_size_decrease(chk);
131 sctp_total_flight_decrease(stcb, chk);
132 chk->sent = SCTP_DATAGRAM_RESEND;
133 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
134 chk->rec.data.doing_fast_retransmit = 0;
135 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
136 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
137 chk->whoTo->flight_size,
139 (uint32_t)(uintptr_t)chk->whoTo,
142 /* Clear any time so NO RTT is being done */
151 sctp_notify(struct sctp_inpcb *inp,
152 struct sctp_tcb *stcb,
153 struct sctp_nets *net,
159 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
164 if (icmp_type != ICMP_UNREACH) {
165 /* We only care about unreachable */
166 SCTP_TCB_UNLOCK(stcb);
169 if ((icmp_code == ICMP_UNREACH_NET) ||
170 (icmp_code == ICMP_UNREACH_HOST) ||
171 (icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
172 (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
173 (icmp_code == ICMP_UNREACH_ISOLATED) ||
174 (icmp_code == ICMP_UNREACH_NET_PROHIB) ||
175 (icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
176 (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
177 /* Mark the net unreachable. */
178 if (net->dest_state & SCTP_ADDR_REACHABLE) {
179 /* OK, that destination is NOT reachable. */
180 net->dest_state &= ~SCTP_ADDR_REACHABLE;
181 net->dest_state &= ~SCTP_ADDR_PF;
182 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
184 (void *)net, SCTP_SO_NOT_LOCKED);
186 SCTP_TCB_UNLOCK(stcb);
187 } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) ||
188 (icmp_code == ICMP_UNREACH_PORT)) {
189 /* Treat it like an ABORT. */
190 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
191 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
192 so = SCTP_INP_SO(inp);
193 atomic_add_int(&stcb->asoc.refcnt, 1);
194 SCTP_TCB_UNLOCK(stcb);
195 SCTP_SOCKET_LOCK(so, 1);
197 atomic_subtract_int(&stcb->asoc.refcnt, 1);
199 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
200 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
201 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
202 SCTP_SOCKET_UNLOCK(so, 1);
203 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
205 /* no need to unlock here, since the TCB is gone */
206 } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) {
207 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
208 SCTP_TCB_UNLOCK(stcb);
211 /* Find the next (smaller) MTU */
214 * Old type router that does not tell us what the
215 * next MTU is. Rats we will have to guess (in a
216 * educated fashion of course).
218 next_mtu = sctp_get_prev_mtu(ip_len);
220 /* Stop the PMTU timer. */
221 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
223 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
224 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
228 /* Update the path MTU. */
230 next_mtu -= sizeof(struct udphdr);
232 if (net->mtu > next_mtu) {
235 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu + sizeof(struct udphdr));
237 sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu);
240 /* Update the association MTU */
241 if (stcb->asoc.smallest_mtu > next_mtu) {
242 sctp_pathmtu_adjustment(stcb, next_mtu);
244 /* Finally, start the PMTU timer if it was running before. */
246 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
248 SCTP_TCB_UNLOCK(stcb);
250 SCTP_TCB_UNLOCK(stcb);
255 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
261 struct sctp_inpcb *inp;
262 struct sctp_tcb *stcb;
263 struct sctp_nets *net;
264 struct sctp_init_chunk *ch;
265 struct sockaddr_in src, dst;
267 if (sa->sa_family != AF_INET ||
268 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
271 if (PRC_IS_REDIRECT(cmd)) {
273 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
277 inner_ip = (struct ip *)vip;
278 icmp = (struct icmp *)((caddr_t)inner_ip -
279 (sizeof(struct icmp) - sizeof(struct ip)));
280 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
281 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
282 memset(&src, 0, sizeof(struct sockaddr_in));
283 src.sin_family = AF_INET;
284 src.sin_len = sizeof(struct sockaddr_in);
285 src.sin_port = sh->src_port;
286 src.sin_addr = inner_ip->ip_src;
287 memset(&dst, 0, sizeof(struct sockaddr_in));
288 dst.sin_family = AF_INET;
289 dst.sin_len = sizeof(struct sockaddr_in);
290 dst.sin_port = sh->dest_port;
291 dst.sin_addr = inner_ip->ip_dst;
293 * 'dst' holds the dest of the packet that failed to be
294 * sent. 'src' holds our local endpoint address. Thus we
295 * reverse the dst and the src in the lookup.
299 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
300 (struct sockaddr *)&src,
303 if ((stcb != NULL) &&
306 /* Check the verification tag */
307 if (ntohl(sh->v_tag) != 0) {
309 * This must be the verification tag used
310 * for sending out packets. We don't
311 * consider packets reflecting the
314 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
315 SCTP_TCB_UNLOCK(stcb);
319 if (ntohs(outer_ip->ip_len) >=
321 8 + (inner_ip->ip_hl << 2) + 20) {
323 * In this case we can check if we
324 * got an INIT chunk and if the
325 * initiate tag matches.
327 ch = (struct sctp_init_chunk *)(sh + 1);
328 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
329 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
330 SCTP_TCB_UNLOCK(stcb);
334 SCTP_TCB_UNLOCK(stcb);
338 sctp_notify(inp, stcb, net,
341 ntohs(inner_ip->ip_len),
342 (uint32_t)ntohs(icmp->icmp_nextmtu));
344 if ((stcb == NULL) && (inp != NULL)) {
345 /* reduce ref-count */
347 SCTP_INP_DECR_REF(inp);
348 SCTP_INP_WUNLOCK(inp);
351 SCTP_TCB_UNLOCK(stcb);
360 sctp_getcred(SYSCTL_HANDLER_ARGS)
363 struct sockaddr_in addrs[2];
364 struct sctp_inpcb *inp;
365 struct sctp_nets *net;
366 struct sctp_tcb *stcb;
370 /* FIX, for non-bsd is this right? */
371 vrf_id = SCTP_DEFAULT_VRFID;
373 error = priv_check(req->td, PRIV_NETINET_GETCRED);
378 error = SYSCTL_IN(req, addrs, sizeof(addrs));
382 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
384 &inp, &net, 1, vrf_id);
385 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
386 if ((inp != NULL) && (stcb == NULL)) {
387 /* reduce ref-count */
389 SCTP_INP_DECR_REF(inp);
393 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
397 SCTP_TCB_UNLOCK(stcb);
399 * We use the write lock here, only since in the error leg we need
400 * it. If we used RLOCK, then we would have to
401 * wlock/decr/unlock/rlock. Which in theory could create a hole.
402 * Better to use higher wlock.
406 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
408 SCTP_INP_WUNLOCK(inp);
411 cru2x(inp->sctp_socket->so_cred, &xuc);
412 SCTP_INP_WUNLOCK(inp);
413 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
418 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
419 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
424 sctp_abort(struct socket *so)
426 struct sctp_inpcb *inp;
429 inp = (struct sctp_inpcb *)so->so_pcb;
435 flags = inp->sctp_flags;
436 #ifdef SCTP_LOG_CLOSING
437 sctp_log_closing(inp, NULL, 17);
439 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
440 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
441 #ifdef SCTP_LOG_CLOSING
442 sctp_log_closing(inp, NULL, 16);
444 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
445 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
447 SCTP_SB_CLEAR(so->so_snd);
449 * same for the rcv ones, they are only here for the
452 SCTP_SB_CLEAR(so->so_rcv);
454 /* Now null out the reference, we are completely detached. */
458 flags = inp->sctp_flags;
459 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
460 goto sctp_must_try_again;
467 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
469 struct sctp_inpcb *inp;
470 struct inpcb *ip_inp;
472 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
474 inp = (struct sctp_inpcb *)so->so_pcb;
476 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
479 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
480 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
485 error = sctp_inpcb_alloc(so, vrf_id);
489 inp = (struct sctp_inpcb *)so->so_pcb;
491 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
492 ip_inp = &inp->ip_inp.inp;
493 ip_inp->inp_vflag |= INP_IPV4;
494 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
495 SCTP_INP_WUNLOCK(inp);
500 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
502 struct sctp_inpcb *inp;
504 inp = (struct sctp_inpcb *)so->so_pcb;
506 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
510 if ((addr->sa_family != AF_INET) ||
511 (addr->sa_len != sizeof(struct sockaddr_in))) {
512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
516 return (sctp_inpcb_bind(so, addr, NULL, p));
521 sctp_close(struct socket *so)
523 struct sctp_inpcb *inp;
526 inp = (struct sctp_inpcb *)so->so_pcb;
531 * Inform all the lower layer assoc that we are done.
534 flags = inp->sctp_flags;
535 #ifdef SCTP_LOG_CLOSING
536 sctp_log_closing(inp, NULL, 17);
538 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
539 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
540 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
541 (so->so_rcv.sb_cc > 0)) {
542 #ifdef SCTP_LOG_CLOSING
543 sctp_log_closing(inp, NULL, 13);
545 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
546 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
548 #ifdef SCTP_LOG_CLOSING
549 sctp_log_closing(inp, NULL, 14);
551 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
552 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
555 * The socket is now detached, no matter what the state of
556 * the SCTP association.
559 SCTP_SB_CLEAR(so->so_snd);
561 * same for the rcv ones, they are only here for the
564 SCTP_SB_CLEAR(so->so_rcv);
566 /* Now null out the reference, we are completely detached. */
570 flags = inp->sctp_flags;
571 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
572 goto sctp_must_try_again;
580 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
581 struct mbuf *control, struct thread *p);
585 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
586 struct mbuf *control, struct thread *p)
588 struct sctp_inpcb *inp;
591 inp = (struct sctp_inpcb *)so->so_pcb;
594 sctp_m_freem(control);
597 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
601 /* Got to have an to address if we are NOT a connected socket */
602 if ((addr == NULL) &&
603 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
604 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
606 } else if (addr == NULL) {
607 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
608 error = EDESTADDRREQ;
611 sctp_m_freem(control);
617 if (addr->sa_family != AF_INET) {
618 /* must be a v4 address! */
619 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
622 sctp_m_freem(control);
625 error = EDESTADDRREQ;
630 /* now what about control */
633 sctp_m_freem(inp->control);
636 inp->control = control;
640 SCTP_BUF_NEXT(inp->pkt_last) = m;
643 inp->pkt_last = inp->pkt = m;
646 /* FreeBSD uses a flag passed */
647 ((flags & PRUS_MORETOCOME) == 0)
650 * note with the current version this code will only be used
651 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
652 * re-defining sosend to use the sctp_sosend. One can
653 * optionally switch back to this code (by changing back the
654 * definitions) but this is not advisable. This code is used
655 * by FreeBSD when sending a file with sendfile() though.
659 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
669 sctp_disconnect(struct socket *so)
671 struct sctp_inpcb *inp;
673 inp = (struct sctp_inpcb *)so->so_pcb;
675 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
679 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
680 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
681 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
683 SCTP_INP_RUNLOCK(inp);
686 struct sctp_association *asoc;
687 struct sctp_tcb *stcb;
689 stcb = LIST_FIRST(&inp->sctp_asoc_list);
691 SCTP_INP_RUNLOCK(inp);
692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
697 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
698 /* We are about to be freed, out of here */
699 SCTP_TCB_UNLOCK(stcb);
700 SCTP_INP_RUNLOCK(inp);
703 if (((so->so_options & SO_LINGER) &&
704 (so->so_linger == 0)) ||
705 (so->so_rcv.sb_cc > 0)) {
706 if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) {
707 /* Left with Data unread */
710 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
711 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
712 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
714 SCTP_INP_RUNLOCK(inp);
715 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
716 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
717 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
719 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
720 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
721 /* No unlock tcb assoc is gone */
724 if (TAILQ_EMPTY(&asoc->send_queue) &&
725 TAILQ_EMPTY(&asoc->sent_queue) &&
726 (asoc->stream_queue_cnt == 0)) {
727 /* there is nothing queued to send, so done */
728 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
731 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) &&
732 (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
733 /* only send SHUTDOWN 1st time thru */
734 struct sctp_nets *netp;
736 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
737 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
738 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
740 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
741 sctp_stop_timers_for_shutdown(stcb);
742 if (stcb->asoc.alternate) {
743 netp = stcb->asoc.alternate;
745 netp = stcb->asoc.primary_destination;
747 sctp_send_shutdown(stcb, netp);
748 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
749 stcb->sctp_ep, stcb, netp);
750 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
751 stcb->sctp_ep, stcb, netp);
752 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
756 * we still got (or just got) data to send,
757 * so set SHUTDOWN_PENDING
760 * XXX sockets draft says that SCTP_EOF
761 * should be sent with no data. currently,
762 * we will allow user data to be sent first
763 * and move to SHUTDOWN-PENDING
765 struct sctp_nets *netp;
767 if (stcb->asoc.alternate) {
768 netp = stcb->asoc.alternate;
770 netp = stcb->asoc.primary_destination;
773 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
774 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
776 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
777 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
779 if (TAILQ_EMPTY(&asoc->send_queue) &&
780 TAILQ_EMPTY(&asoc->sent_queue) &&
781 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
785 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
786 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
787 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
788 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
789 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
790 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
791 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
793 SCTP_INP_RUNLOCK(inp);
794 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
795 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
798 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
801 soisdisconnecting(so);
802 SCTP_TCB_UNLOCK(stcb);
803 SCTP_INP_RUNLOCK(inp);
808 /* UDP model does not support this */
809 SCTP_INP_RUNLOCK(inp);
810 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
816 sctp_flush(struct socket *so, int how)
819 * We will just clear out the values and let subsequent close clear
820 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
821 * they will not be able to read the data, the socket will block
822 * that from happening.
824 struct sctp_inpcb *inp;
826 inp = (struct sctp_inpcb *)so->so_pcb;
828 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
832 /* For the 1 to many model this does nothing */
833 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
834 SCTP_INP_RUNLOCK(inp);
837 SCTP_INP_RUNLOCK(inp);
838 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
840 * First make sure the sb will be happy, we don't use these
841 * except maybe the count
844 SCTP_INP_READ_LOCK(inp);
845 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
846 SCTP_INP_READ_UNLOCK(inp);
847 SCTP_INP_WUNLOCK(inp);
848 so->so_rcv.sb_cc = 0;
849 so->so_rcv.sb_mbcnt = 0;
850 so->so_rcv.sb_mb = NULL;
852 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
854 * First make sure the sb will be happy, we don't use these
855 * except maybe the count
857 so->so_snd.sb_cc = 0;
858 so->so_snd.sb_mbcnt = 0;
859 so->so_snd.sb_mb = NULL;
866 sctp_shutdown(struct socket *so)
868 struct sctp_inpcb *inp;
870 inp = (struct sctp_inpcb *)so->so_pcb;
872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
876 /* For UDP model this is a invalid call */
877 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
878 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
879 /* Restore the flags that the soshutdown took away. */
880 SOCKBUF_LOCK(&so->so_rcv);
881 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
882 SOCKBUF_UNLOCK(&so->so_rcv);
883 /* This proc will wakeup for read and do nothing (I hope) */
884 SCTP_INP_RUNLOCK(inp);
885 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
889 * Ok, if we reach here its the TCP model and it is either a
890 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
893 struct sctp_tcb *stcb;
894 struct sctp_association *asoc;
895 struct sctp_nets *netp;
898 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
899 SCTP_INP_RUNLOCK(inp);
904 stcb = LIST_FIRST(&inp->sctp_asoc_list);
907 * Ok, we hit the case that the shutdown call was
908 * made after an abort or something. Nothing to do
911 SCTP_INP_RUNLOCK(inp);
916 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
917 SCTP_TCB_UNLOCK(stcb);
918 SCTP_INP_RUNLOCK(inp);
921 if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) &&
922 (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) &&
923 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) {
925 * If we are not in or before ESTABLISHED, there is
926 * no protocol action required.
928 SCTP_TCB_UNLOCK(stcb);
929 SCTP_INP_RUNLOCK(inp);
932 if (stcb->asoc.alternate) {
933 netp = stcb->asoc.alternate;
935 netp = stcb->asoc.primary_destination;
937 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) &&
938 TAILQ_EMPTY(&asoc->send_queue) &&
939 TAILQ_EMPTY(&asoc->sent_queue) &&
940 (asoc->stream_queue_cnt == 0)) {
941 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
944 /* there is nothing queued to send, so I'm done... */
945 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
946 SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
947 sctp_stop_timers_for_shutdown(stcb);
948 sctp_send_shutdown(stcb, netp);
949 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
950 stcb->sctp_ep, stcb, netp);
953 * We still got (or just got) data to send, so set
956 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
957 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
958 SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT);
960 if (TAILQ_EMPTY(&asoc->send_queue) &&
961 TAILQ_EMPTY(&asoc->sent_queue) &&
962 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
966 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
967 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
968 sctp_abort_an_association(stcb->sctp_ep, stcb,
969 op_err, SCTP_SO_LOCKED);
970 SCTP_INP_RUNLOCK(inp);
974 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp);
976 * XXX: Why do this in the case where we have still data
979 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
980 SCTP_TCB_UNLOCK(stcb);
981 SCTP_INP_RUNLOCK(inp);
987 * copies a "user" presentable address and removes embedded scope, etc.
988 * returns 0 on success, 1 on error
991 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
994 struct sockaddr_in6 lsa6;
996 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
999 memcpy(ss, sa, sa->sa_len);
1006 * NOTE: assumes addr lock is held
1009 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1010 struct sctp_tcb *stcb,
1012 struct sockaddr_storage *sas,
1015 struct sctp_ifn *sctp_ifn;
1016 struct sctp_ifa *sctp_ifa;
1020 int ipv4_local_scope, ipv4_addr_legal;
1023 int local_scope, site_scope, ipv6_addr_legal;
1025 struct sctp_vrf *vrf;
1032 /* Turn on all the appropriate scope */
1033 loopback_scope = stcb->asoc.scope.loopback_scope;
1035 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1036 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1039 local_scope = stcb->asoc.scope.local_scope;
1040 site_scope = stcb->asoc.scope.site_scope;
1041 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1044 /* Use generic values for endpoints. */
1047 ipv4_local_scope = 1;
1053 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1055 ipv6_addr_legal = 1;
1058 if (SCTP_IPV6_V6ONLY(inp)) {
1059 ipv4_addr_legal = 0;
1061 ipv4_addr_legal = 1;
1066 ipv6_addr_legal = 0;
1069 ipv4_addr_legal = 1;
1073 vrf = sctp_find_vrf(vrf_id);
1077 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1078 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1079 if ((loopback_scope == 0) &&
1080 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1081 /* Skip loopback if loopback_scope not set */
1084 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1087 * For the BOUND-ALL case, the list
1088 * associated with a TCB is Always
1089 * considered a reverse list.. i.e.
1090 * it lists addresses that are NOT
1091 * part of the association. If this
1092 * is one of those we must skip it.
1094 if (sctp_is_addr_restricted(stcb,
1099 switch (sctp_ifa->address.sa.sa_family) {
1102 if (ipv4_addr_legal) {
1103 struct sockaddr_in *sin;
1105 sin = &sctp_ifa->address.sin;
1106 if (sin->sin_addr.s_addr == 0) {
1114 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1115 &sin->sin_addr) != 0) {
1118 if ((ipv4_local_scope == 0) &&
1119 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1123 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1124 if (actual + sizeof(struct sockaddr_in6) > limit) {
1127 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1128 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1129 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1130 actual += sizeof(struct sockaddr_in6);
1133 if (actual + sizeof(struct sockaddr_in) > limit) {
1136 memcpy(sas, sin, sizeof(struct sockaddr_in));
1137 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1138 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in));
1139 actual += sizeof(struct sockaddr_in);
1150 if (ipv6_addr_legal) {
1151 struct sockaddr_in6 *sin6;
1153 sin6 = &sctp_ifa->address.sin6;
1154 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1162 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1163 &sin6->sin6_addr) != 0) {
1166 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1167 if (local_scope == 0)
1169 if (sin6->sin6_scope_id == 0) {
1170 if (sa6_recoverscope(sin6) != 0)
1183 if ((site_scope == 0) &&
1184 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1187 if (actual + sizeof(struct sockaddr_in6) > limit) {
1190 memcpy(sas, sin6, sizeof(struct sockaddr_in6));
1191 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1192 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1193 actual += sizeof(struct sockaddr_in6);
1206 struct sctp_laddr *laddr;
1209 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1211 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1215 sa_len = laddr->ifa->address.sa.sa_len;
1216 if (actual + sa_len > limit) {
1219 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1221 switch (laddr->ifa->address.sa.sa_family) {
1224 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1229 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1236 sas = (struct sockaddr_storage *)((caddr_t)sas + sa_len);
1244 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1245 struct sctp_tcb *stcb,
1247 struct sockaddr_storage *sas)
1251 SCTP_IPI_ADDR_RLOCK();
1252 /* fill up addresses for the endpoint's default vrf */
1253 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1255 SCTP_IPI_ADDR_RUNLOCK();
1260 * NOTE: assumes addr lock is held
1263 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1266 struct sctp_vrf *vrf = NULL;
1269 * In both sub-set bound an bound_all cases we return the MAXIMUM
1270 * number of addresses that you COULD get. In reality the sub-set
1271 * bound may have an exclusion list for a given TCB OR in the
1272 * bound-all case a TCB may NOT include the loopback or other
1273 * addresses as well.
1275 vrf = sctp_find_vrf(vrf_id);
1279 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1280 struct sctp_ifn *sctp_ifn;
1281 struct sctp_ifa *sctp_ifa;
1283 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1284 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1285 /* Count them if they are the right type */
1286 switch (sctp_ifa->address.sa.sa_family) {
1290 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1291 cnt += sizeof(struct sockaddr_in6);
1293 cnt += sizeof(struct sockaddr_in);
1295 cnt += sizeof(struct sockaddr_in);
1301 cnt += sizeof(struct sockaddr_in6);
1310 struct sctp_laddr *laddr;
1312 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1313 switch (laddr->ifa->address.sa.sa_family) {
1317 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1318 cnt += sizeof(struct sockaddr_in6);
1320 cnt += sizeof(struct sockaddr_in);
1322 cnt += sizeof(struct sockaddr_in);
1328 cnt += sizeof(struct sockaddr_in6);
1340 sctp_count_max_addresses(struct sctp_inpcb *inp)
1344 SCTP_IPI_ADDR_RLOCK();
1345 /* count addresses for the endpoint's default VRF */
1346 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1347 SCTP_IPI_ADDR_RUNLOCK();
1352 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1353 size_t optsize, void *p, int delay)
1356 int creat_lock_on = 0;
1357 struct sctp_tcb *stcb = NULL;
1358 struct sockaddr *sa;
1359 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1363 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1365 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1366 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1367 /* We are already connected AND the TCP model */
1368 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1369 return (EADDRINUSE);
1372 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1373 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1374 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1378 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1379 SCTP_INP_RLOCK(inp);
1380 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1381 SCTP_INP_RUNLOCK(inp);
1384 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1387 SCTP_INP_INCR_REF(inp);
1388 SCTP_ASOC_CREATE_LOCK(inp);
1390 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1391 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1392 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1396 totaddrp = (unsigned int *)optval;
1397 totaddr = *totaddrp;
1398 sa = (struct sockaddr *)(totaddrp + 1);
1399 error = sctp_connectx_helper_find(inp, sa, totaddr, &num_v4, &num_v6, (unsigned int)(optsize - sizeof(int)));
1401 /* Already have or am bring up an association */
1402 SCTP_ASOC_CREATE_UNLOCK(inp);
1404 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1408 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1413 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1415 struct in6pcb *inp6;
1417 inp6 = (struct in6pcb *)inp;
1418 if (SCTP_IPV6_V6ONLY(inp6)) {
1420 * if IPV6_V6ONLY flag, ignore connections destined
1421 * to a v4 addr or v4-mapped addr
1423 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1429 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1430 SCTP_PCB_FLAGS_UNBOUND) {
1431 /* Bind a ephemeral port */
1432 error = sctp_inpcb_bind(so, NULL, NULL, p);
1438 /* FIX ME: do we want to pass in a vrf on the connect call? */
1439 vrf_id = inp->def_vrf_id;
1442 /* We are GOOD to go */
1443 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1444 inp->sctp_ep.pre_open_stream_count,
1449 /* Gak! no memory */
1452 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1453 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1454 /* Set the connected flag so we can queue data */
1457 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
1458 /* move to second address */
1459 switch (sa->sa_family) {
1462 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1467 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1475 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1476 /* Fill in the return id */
1480 a_id = (sctp_assoc_t *)optval;
1481 *a_id = sctp_get_associd(stcb);
1483 /* initialize authentication parameters for the assoc */
1484 sctp_initialize_auth_params(inp, stcb);
1487 /* doing delayed connection */
1488 stcb->asoc.delayed_connection = 1;
1489 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1491 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1492 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1494 SCTP_TCB_UNLOCK(stcb);
1496 if (creat_lock_on) {
1497 SCTP_ASOC_CREATE_UNLOCK(inp);
1499 SCTP_INP_DECR_REF(inp);
1503 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1504 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1505 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1506 SCTP_INP_RLOCK(inp); \
1507 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1509 SCTP_TCB_LOCK(stcb); \
1511 SCTP_INP_RUNLOCK(inp); \
1512 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1513 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1514 if (stcb == NULL) { \
1515 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1525 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1526 if (size < sizeof(type)) { \
1527 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1531 destp = (type *)srcp; \
1536 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1539 struct sctp_inpcb *inp = NULL;
1541 struct sctp_tcb *stcb = NULL;
1543 if (optval == NULL) {
1544 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1548 inp = (struct sctp_inpcb *)so->so_pcb;
1550 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1557 case SCTP_AUTOCLOSE:
1558 case SCTP_EXPLICIT_EOR:
1559 case SCTP_AUTO_ASCONF:
1560 case SCTP_DISABLE_FRAGMENTS:
1561 case SCTP_I_WANT_MAPPED_V4_ADDR:
1562 case SCTP_USE_EXT_RCVINFO:
1563 SCTP_INP_RLOCK(inp);
1565 case SCTP_DISABLE_FRAGMENTS:
1566 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1568 case SCTP_I_WANT_MAPPED_V4_ADDR:
1569 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1571 case SCTP_AUTO_ASCONF:
1572 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1573 /* only valid for bound all sockets */
1574 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1576 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1581 case SCTP_EXPLICIT_EOR:
1582 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1585 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1587 case SCTP_USE_EXT_RCVINFO:
1588 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1590 case SCTP_AUTOCLOSE:
1591 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1592 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1598 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1599 error = ENOPROTOOPT;
1600 } /* end switch (sopt->sopt_name) */
1601 if (*optsize < sizeof(val)) {
1602 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1606 SCTP_INP_RUNLOCK(inp);
1608 /* return the option value */
1609 *(int *)optval = val;
1610 *optsize = sizeof(val);
1613 case SCTP_GET_PACKET_LOG:
1615 #ifdef SCTP_PACKET_LOGGING
1619 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1620 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1623 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1628 case SCTP_REUSE_PORT:
1632 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1633 /* Can't do this for a 1-m socket */
1637 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1638 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1639 *optsize = sizeof(uint32_t);
1642 case SCTP_PARTIAL_DELIVERY_POINT:
1646 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1647 *value = inp->partial_delivery_point;
1648 *optsize = sizeof(uint32_t);
1651 case SCTP_FRAGMENT_INTERLEAVE:
1655 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1656 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1657 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1658 *value = SCTP_FRAG_LEVEL_2;
1660 *value = SCTP_FRAG_LEVEL_1;
1663 *value = SCTP_FRAG_LEVEL_0;
1665 *optsize = sizeof(uint32_t);
1668 case SCTP_INTERLEAVING_SUPPORTED:
1670 struct sctp_assoc_value *av;
1672 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1673 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1676 av->assoc_value = stcb->asoc.idata_supported;
1677 SCTP_TCB_UNLOCK(stcb);
1679 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1680 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1681 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1682 SCTP_INP_RLOCK(inp);
1683 if (inp->idata_supported) {
1684 av->assoc_value = 1;
1686 av->assoc_value = 0;
1688 SCTP_INP_RUNLOCK(inp);
1690 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1695 *optsize = sizeof(struct sctp_assoc_value);
1699 case SCTP_CMT_ON_OFF:
1701 struct sctp_assoc_value *av;
1703 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1704 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1706 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1707 SCTP_TCB_UNLOCK(stcb);
1709 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1710 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1711 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1712 SCTP_INP_RLOCK(inp);
1713 av->assoc_value = inp->sctp_cmt_on_off;
1714 SCTP_INP_RUNLOCK(inp);
1716 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1721 *optsize = sizeof(struct sctp_assoc_value);
1725 case SCTP_PLUGGABLE_CC:
1727 struct sctp_assoc_value *av;
1729 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1730 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1732 av->assoc_value = stcb->asoc.congestion_control_module;
1733 SCTP_TCB_UNLOCK(stcb);
1735 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1736 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1737 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1738 SCTP_INP_RLOCK(inp);
1739 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1740 SCTP_INP_RUNLOCK(inp);
1742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1747 *optsize = sizeof(struct sctp_assoc_value);
1751 case SCTP_CC_OPTION:
1753 struct sctp_cc_option *cc_opt;
1755 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1756 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1760 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1763 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1764 *optsize = sizeof(struct sctp_cc_option);
1766 SCTP_TCB_UNLOCK(stcb);
1770 case SCTP_PLUGGABLE_SS:
1772 struct sctp_assoc_value *av;
1774 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1775 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1777 av->assoc_value = stcb->asoc.stream_scheduling_module;
1778 SCTP_TCB_UNLOCK(stcb);
1780 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1781 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1782 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1783 SCTP_INP_RLOCK(inp);
1784 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1785 SCTP_INP_RUNLOCK(inp);
1787 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1792 *optsize = sizeof(struct sctp_assoc_value);
1798 struct sctp_stream_value *av;
1800 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1801 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1803 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1804 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1805 &av->stream_value) < 0)) {
1806 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1809 *optsize = sizeof(struct sctp_stream_value);
1811 SCTP_TCB_UNLOCK(stcb);
1814 * Can't get stream value without
1817 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1822 case SCTP_GET_ADDR_LEN:
1824 struct sctp_assoc_value *av;
1826 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1829 if (av->assoc_value == AF_INET) {
1830 av->assoc_value = sizeof(struct sockaddr_in);
1835 if (av->assoc_value == AF_INET6) {
1836 av->assoc_value = sizeof(struct sockaddr_in6);
1841 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1843 *optsize = sizeof(struct sctp_assoc_value);
1847 case SCTP_GET_ASSOC_NUMBER:
1849 uint32_t *value, cnt;
1851 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1852 SCTP_INP_RLOCK(inp);
1853 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1854 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1855 /* Can't do this for a 1-1 socket */
1857 SCTP_INP_RUNLOCK(inp);
1861 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1864 SCTP_INP_RUNLOCK(inp);
1866 *optsize = sizeof(uint32_t);
1869 case SCTP_GET_ASSOC_ID_LIST:
1871 struct sctp_assoc_ids *ids;
1875 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1876 SCTP_INP_RLOCK(inp);
1877 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1878 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1879 /* Can't do this for a 1-1 socket */
1881 SCTP_INP_RUNLOCK(inp);
1885 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1886 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1888 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1896 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1900 SCTP_INP_RUNLOCK(inp);
1902 ids->gaids_number_of_ids = at;
1903 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1909 struct sctp_assoc_value *av;
1911 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1912 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1915 av->assoc_value = stcb->asoc.context;
1916 SCTP_TCB_UNLOCK(stcb);
1918 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1919 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1920 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1921 SCTP_INP_RLOCK(inp);
1922 av->assoc_value = inp->sctp_context;
1923 SCTP_INP_RUNLOCK(inp);
1925 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1930 *optsize = sizeof(struct sctp_assoc_value);
1936 uint32_t *default_vrfid;
1938 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1939 *default_vrfid = inp->def_vrf_id;
1940 *optsize = sizeof(uint32_t);
1943 case SCTP_GET_ASOC_VRF:
1945 struct sctp_assoc_value *id;
1947 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1948 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1951 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1953 id->assoc_value = stcb->asoc.vrf_id;
1954 SCTP_TCB_UNLOCK(stcb);
1955 *optsize = sizeof(struct sctp_assoc_value);
1959 case SCTP_GET_VRF_IDS:
1961 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1965 case SCTP_GET_NONCE_VALUES:
1967 struct sctp_get_nonce_values *gnv;
1969 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1970 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1973 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1974 gnv->gn_local_tag = stcb->asoc.my_vtag;
1975 SCTP_TCB_UNLOCK(stcb);
1976 *optsize = sizeof(struct sctp_get_nonce_values);
1978 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1983 case SCTP_DELAYED_SACK:
1985 struct sctp_sack_info *sack;
1987 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
1988 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
1990 sack->sack_delay = stcb->asoc.delayed_ack;
1991 sack->sack_freq = stcb->asoc.sack_freq;
1992 SCTP_TCB_UNLOCK(stcb);
1994 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1995 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1996 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
1997 SCTP_INP_RLOCK(inp);
1998 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
1999 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2000 SCTP_INP_RUNLOCK(inp);
2002 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2007 *optsize = sizeof(struct sctp_sack_info);
2011 case SCTP_GET_SNDBUF_USE:
2013 struct sctp_sockstat *ss;
2015 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2016 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2019 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2020 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2021 stcb->asoc.size_on_all_streams);
2022 SCTP_TCB_UNLOCK(stcb);
2023 *optsize = sizeof(struct sctp_sockstat);
2025 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2030 case SCTP_MAX_BURST:
2032 struct sctp_assoc_value *av;
2034 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2035 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2038 av->assoc_value = stcb->asoc.max_burst;
2039 SCTP_TCB_UNLOCK(stcb);
2041 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2042 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2043 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2044 SCTP_INP_RLOCK(inp);
2045 av->assoc_value = inp->sctp_ep.max_burst;
2046 SCTP_INP_RUNLOCK(inp);
2048 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2053 *optsize = sizeof(struct sctp_assoc_value);
2059 struct sctp_assoc_value *av;
2062 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2063 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2066 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2067 SCTP_TCB_UNLOCK(stcb);
2069 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2070 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2071 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2072 SCTP_INP_RLOCK(inp);
2073 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2074 ovh = SCTP_MED_OVERHEAD;
2076 ovh = SCTP_MED_V4_OVERHEAD;
2078 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2079 av->assoc_value = 0;
2081 av->assoc_value = inp->sctp_frag_point - ovh;
2082 SCTP_INP_RUNLOCK(inp);
2084 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2089 *optsize = sizeof(struct sctp_assoc_value);
2093 case SCTP_GET_STAT_LOG:
2094 error = sctp_fill_stat_log(optval, optsize);
2098 struct sctp_event_subscribe *events;
2100 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2101 memset(events, 0, sizeof(struct sctp_event_subscribe));
2102 SCTP_INP_RLOCK(inp);
2103 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2104 events->sctp_data_io_event = 1;
2106 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2107 events->sctp_association_event = 1;
2109 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2110 events->sctp_address_event = 1;
2112 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2113 events->sctp_send_failure_event = 1;
2115 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2116 events->sctp_peer_error_event = 1;
2118 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2119 events->sctp_shutdown_event = 1;
2121 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2122 events->sctp_partial_delivery_event = 1;
2124 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2125 events->sctp_adaptation_layer_event = 1;
2127 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2128 events->sctp_authentication_event = 1;
2130 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2131 events->sctp_sender_dry_event = 1;
2133 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2134 events->sctp_stream_reset_event = 1;
2135 SCTP_INP_RUNLOCK(inp);
2136 *optsize = sizeof(struct sctp_event_subscribe);
2139 case SCTP_ADAPTATION_LAYER:
2143 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2145 SCTP_INP_RLOCK(inp);
2146 *value = inp->sctp_ep.adaptation_layer_indicator;
2147 SCTP_INP_RUNLOCK(inp);
2148 *optsize = sizeof(uint32_t);
2151 case SCTP_SET_INITIAL_DBG_SEQ:
2155 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2156 SCTP_INP_RLOCK(inp);
2157 *value = inp->sctp_ep.initial_sequence_debug;
2158 SCTP_INP_RUNLOCK(inp);
2159 *optsize = sizeof(uint32_t);
2162 case SCTP_GET_LOCAL_ADDR_SIZE:
2166 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2167 SCTP_INP_RLOCK(inp);
2168 *value = sctp_count_max_addresses(inp);
2169 SCTP_INP_RUNLOCK(inp);
2170 *optsize = sizeof(uint32_t);
2173 case SCTP_GET_REMOTE_ADDR_SIZE:
2177 struct sctp_nets *net;
2179 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2180 /* FIXME MT: change to sctp_assoc_value? */
2181 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
2185 /* Count the sizes */
2186 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2187 switch (net->ro._l_addr.sa.sa_family) {
2191 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2192 size += sizeof(struct sockaddr_in6);
2194 size += sizeof(struct sockaddr_in);
2197 size += sizeof(struct sockaddr_in);
2203 size += sizeof(struct sockaddr_in6);
2210 SCTP_TCB_UNLOCK(stcb);
2211 *value = (uint32_t)size;
2212 *optsize = sizeof(uint32_t);
2214 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2219 case SCTP_GET_PEER_ADDRESSES:
2221 * Get the address information, an array is passed in to
2222 * fill up we pack it.
2226 struct sockaddr_storage *sas;
2227 struct sctp_nets *net;
2228 struct sctp_getaddresses *saddr;
2230 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2231 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2234 left = (*optsize) - sizeof(sctp_assoc_t);
2235 *optsize = sizeof(sctp_assoc_t);
2236 sas = (struct sockaddr_storage *)&saddr->addr[0];
2238 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2239 switch (net->ro._l_addr.sa.sa_family) {
2243 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2244 cpsz = sizeof(struct sockaddr_in6);
2246 cpsz = sizeof(struct sockaddr_in);
2249 cpsz = sizeof(struct sockaddr_in);
2255 cpsz = sizeof(struct sockaddr_in6);
2266 /* not enough room. */
2269 #if defined(INET) && defined(INET6)
2270 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2271 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2272 /* Must map the address */
2273 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2274 (struct sockaddr_in6 *)sas);
2276 memcpy(sas, &net->ro._l_addr, cpsz);
2279 memcpy(sas, &net->ro._l_addr, cpsz);
2281 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2283 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2287 SCTP_TCB_UNLOCK(stcb);
2289 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2294 case SCTP_GET_LOCAL_ADDRESSES:
2296 size_t limit, actual;
2297 struct sockaddr_storage *sas;
2298 struct sctp_getaddresses *saddr;
2300 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2301 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2303 sas = (struct sockaddr_storage *)&saddr->addr[0];
2304 limit = *optsize - sizeof(sctp_assoc_t);
2305 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2307 SCTP_TCB_UNLOCK(stcb);
2309 *optsize = sizeof(sctp_assoc_t) + actual;
2312 case SCTP_PEER_ADDR_PARAMS:
2314 struct sctp_paddrparams *paddrp;
2315 struct sctp_nets *net;
2316 struct sockaddr *addr;
2317 #if defined(INET) && defined(INET6)
2318 struct sockaddr_in sin_store;
2321 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2322 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2324 #if defined(INET) && defined(INET6)
2325 if (paddrp->spp_address.ss_family == AF_INET6) {
2326 struct sockaddr_in6 *sin6;
2328 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2329 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2330 in6_sin6_2_sin(&sin_store, sin6);
2331 addr = (struct sockaddr *)&sin_store;
2333 addr = (struct sockaddr *)&paddrp->spp_address;
2336 addr = (struct sockaddr *)&paddrp->spp_address;
2339 addr = (struct sockaddr *)&paddrp->spp_address;
2342 net = sctp_findnet(stcb, addr);
2345 * We increment here since
2346 * sctp_findassociation_ep_addr() wil do a
2347 * decrement if it finds the stcb as long as
2348 * the locked tcb (last argument) is NOT a
2352 SCTP_INP_INCR_REF(inp);
2353 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2355 SCTP_INP_DECR_REF(inp);
2358 if ((stcb != NULL) && (net == NULL)) {
2360 if (addr->sa_family == AF_INET) {
2361 struct sockaddr_in *sin;
2363 sin = (struct sockaddr_in *)addr;
2364 if (sin->sin_addr.s_addr != INADDR_ANY) {
2366 SCTP_TCB_UNLOCK(stcb);
2367 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2373 if (addr->sa_family == AF_INET6) {
2374 struct sockaddr_in6 *sin6;
2376 sin6 = (struct sockaddr_in6 *)addr;
2377 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2379 SCTP_TCB_UNLOCK(stcb);
2380 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2386 error = EAFNOSUPPORT;
2387 SCTP_TCB_UNLOCK(stcb);
2388 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2394 /* Applies to the specific association */
2395 paddrp->spp_flags = 0;
2397 paddrp->spp_hbinterval = net->heart_beat_delay;
2398 paddrp->spp_pathmaxrxt = net->failure_threshold;
2399 paddrp->spp_pathmtu = net->mtu;
2400 switch (net->ro._l_addr.sa.sa_family) {
2403 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2408 paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD;
2414 /* get flags for HB */
2415 if (net->dest_state & SCTP_ADDR_NOHB) {
2416 paddrp->spp_flags |= SPP_HB_DISABLE;
2418 paddrp->spp_flags |= SPP_HB_ENABLE;
2420 /* get flags for PMTU */
2421 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2422 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2424 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2426 if (net->dscp & 0x01) {
2427 paddrp->spp_dscp = net->dscp & 0xfc;
2428 paddrp->spp_flags |= SPP_DSCP;
2431 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2432 (net->flowlabel & 0x80000000)) {
2433 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2434 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2439 * No destination so return default
2442 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2443 paddrp->spp_pathmtu = stcb->asoc.default_mtu;
2444 if (stcb->asoc.default_dscp & 0x01) {
2445 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2446 paddrp->spp_flags |= SPP_DSCP;
2449 if (stcb->asoc.default_flowlabel & 0x80000000) {
2450 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2451 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2454 /* default settings should be these */
2455 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2456 paddrp->spp_flags |= SPP_HB_DISABLE;
2458 paddrp->spp_flags |= SPP_HB_ENABLE;
2460 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2461 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2463 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2465 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2467 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2468 SCTP_TCB_UNLOCK(stcb);
2470 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2471 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2472 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2473 /* Use endpoint defaults */
2474 SCTP_INP_RLOCK(inp);
2475 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2476 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2477 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2478 /* get inp's default */
2479 if (inp->sctp_ep.default_dscp & 0x01) {
2480 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2481 paddrp->spp_flags |= SPP_DSCP;
2484 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2485 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2486 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2487 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2490 paddrp->spp_pathmtu = inp->sctp_ep.default_mtu;
2492 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2493 paddrp->spp_flags |= SPP_HB_ENABLE;
2495 paddrp->spp_flags |= SPP_HB_DISABLE;
2497 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2498 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2500 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2502 SCTP_INP_RUNLOCK(inp);
2504 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2509 *optsize = sizeof(struct sctp_paddrparams);
2513 case SCTP_GET_PEER_ADDR_INFO:
2515 struct sctp_paddrinfo *paddri;
2516 struct sctp_nets *net;
2517 struct sockaddr *addr;
2518 #if defined(INET) && defined(INET6)
2519 struct sockaddr_in sin_store;
2522 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2523 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2525 #if defined(INET) && defined(INET6)
2526 if (paddri->spinfo_address.ss_family == AF_INET6) {
2527 struct sockaddr_in6 *sin6;
2529 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2530 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2531 in6_sin6_2_sin(&sin_store, sin6);
2532 addr = (struct sockaddr *)&sin_store;
2534 addr = (struct sockaddr *)&paddri->spinfo_address;
2537 addr = (struct sockaddr *)&paddri->spinfo_address;
2540 addr = (struct sockaddr *)&paddri->spinfo_address;
2543 net = sctp_findnet(stcb, addr);
2546 * We increment here since
2547 * sctp_findassociation_ep_addr() wil do a
2548 * decrement if it finds the stcb as long as
2549 * the locked tcb (last argument) is NOT a
2553 SCTP_INP_INCR_REF(inp);
2554 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2556 SCTP_INP_DECR_REF(inp);
2560 if ((stcb != NULL) && (net != NULL)) {
2561 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2562 /* It's unconfirmed */
2563 paddri->spinfo_state = SCTP_UNCONFIRMED;
2564 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2566 paddri->spinfo_state = SCTP_ACTIVE;
2569 paddri->spinfo_state = SCTP_INACTIVE;
2571 paddri->spinfo_cwnd = net->cwnd;
2572 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2573 paddri->spinfo_rto = net->RTO;
2574 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2575 paddri->spinfo_mtu = net->mtu;
2576 switch (addr->sa_family) {
2579 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2584 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2590 SCTP_TCB_UNLOCK(stcb);
2591 *optsize = sizeof(struct sctp_paddrinfo);
2594 SCTP_TCB_UNLOCK(stcb);
2596 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2601 case SCTP_PCB_STATUS:
2603 struct sctp_pcbinfo *spcb;
2605 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2606 sctp_fill_pcbinfo(spcb);
2607 *optsize = sizeof(struct sctp_pcbinfo);
2612 struct sctp_nets *net;
2613 struct sctp_status *sstat;
2615 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2616 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2619 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2623 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2624 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2625 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2626 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2628 * We can't include chunks that have been passed to
2629 * the socket layer. Only things in queue.
2631 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2632 stcb->asoc.cnt_on_all_streams);
2635 sstat->sstat_instrms = stcb->asoc.streamincnt;
2636 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2637 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2638 net = stcb->asoc.primary_destination;
2640 memcpy(&sstat->sstat_primary.spinfo_address,
2641 &stcb->asoc.primary_destination->ro._l_addr,
2642 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2643 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2645 * Again the user can get info from
2646 * sctp_constants.h for what the state of
2649 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2650 /* It's unconfirmed */
2651 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2652 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2654 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2657 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2659 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2660 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2661 sstat->sstat_primary.spinfo_rto = net->RTO;
2662 sstat->sstat_primary.spinfo_mtu = net->mtu;
2663 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2666 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2671 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2678 memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo));
2680 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2681 SCTP_TCB_UNLOCK(stcb);
2682 *optsize = sizeof(struct sctp_status);
2687 struct sctp_rtoinfo *srto;
2689 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2690 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2693 srto->srto_initial = stcb->asoc.initial_rto;
2694 srto->srto_max = stcb->asoc.maxrto;
2695 srto->srto_min = stcb->asoc.minrto;
2696 SCTP_TCB_UNLOCK(stcb);
2698 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2699 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2700 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2701 SCTP_INP_RLOCK(inp);
2702 srto->srto_initial = inp->sctp_ep.initial_rto;
2703 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2704 srto->srto_min = inp->sctp_ep.sctp_minrto;
2705 SCTP_INP_RUNLOCK(inp);
2707 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2712 *optsize = sizeof(struct sctp_rtoinfo);
2718 struct sctp_timeouts *stimo;
2720 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2721 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2724 stimo->stimo_init = stcb->asoc.timoinit;
2725 stimo->stimo_data = stcb->asoc.timodata;
2726 stimo->stimo_sack = stcb->asoc.timosack;
2727 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2728 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2729 stimo->stimo_cookie = stcb->asoc.timocookie;
2730 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2731 SCTP_TCB_UNLOCK(stcb);
2732 *optsize = sizeof(struct sctp_timeouts);
2734 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2739 case SCTP_ASSOCINFO:
2741 struct sctp_assocparams *sasoc;
2743 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2744 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2747 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2748 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2749 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2750 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2751 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2752 SCTP_TCB_UNLOCK(stcb);
2754 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2755 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2756 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2757 SCTP_INP_RLOCK(inp);
2758 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2759 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2760 sasoc->sasoc_number_peer_destinations = 0;
2761 sasoc->sasoc_peer_rwnd = 0;
2762 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2763 SCTP_INP_RUNLOCK(inp);
2765 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2770 *optsize = sizeof(struct sctp_assocparams);
2774 case SCTP_DEFAULT_SEND_PARAM:
2776 struct sctp_sndrcvinfo *s_info;
2778 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2779 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2782 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2783 SCTP_TCB_UNLOCK(stcb);
2785 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2786 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2787 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2788 SCTP_INP_RLOCK(inp);
2789 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2790 SCTP_INP_RUNLOCK(inp);
2792 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2797 *optsize = sizeof(struct sctp_sndrcvinfo);
2803 struct sctp_initmsg *sinit;
2805 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2806 SCTP_INP_RLOCK(inp);
2807 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2808 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2809 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2810 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2811 SCTP_INP_RUNLOCK(inp);
2812 *optsize = sizeof(struct sctp_initmsg);
2815 case SCTP_PRIMARY_ADDR:
2816 /* we allow a "get" operation on this */
2818 struct sctp_setprim *ssp;
2820 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2821 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2824 union sctp_sockstore *addr;
2826 addr = &stcb->asoc.primary_destination->ro._l_addr;
2827 switch (addr->sa.sa_family) {
2831 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2832 in6_sin_2_v4mapsin6(&addr->sin,
2833 (struct sockaddr_in6 *)&ssp->ssp_addr);
2835 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2838 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2844 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2850 SCTP_TCB_UNLOCK(stcb);
2851 *optsize = sizeof(struct sctp_setprim);
2853 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2858 case SCTP_HMAC_IDENT:
2860 struct sctp_hmacalgo *shmac;
2861 sctp_hmaclist_t *hmaclist;
2865 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2867 SCTP_INP_RLOCK(inp);
2868 hmaclist = inp->sctp_ep.local_hmacs;
2869 if (hmaclist == NULL) {
2870 /* no HMACs to return */
2871 *optsize = sizeof(*shmac);
2872 SCTP_INP_RUNLOCK(inp);
2875 /* is there room for all of the hmac ids? */
2876 size = sizeof(*shmac) + (hmaclist->num_algo *
2877 sizeof(shmac->shmac_idents[0]));
2878 if ((size_t)(*optsize) < size) {
2879 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2881 SCTP_INP_RUNLOCK(inp);
2884 /* copy in the list */
2885 shmac->shmac_number_of_idents = hmaclist->num_algo;
2886 for (i = 0; i < hmaclist->num_algo; i++) {
2887 shmac->shmac_idents[i] = hmaclist->hmac[i];
2889 SCTP_INP_RUNLOCK(inp);
2893 case SCTP_AUTH_ACTIVE_KEY:
2895 struct sctp_authkeyid *scact;
2897 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2898 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2901 /* get the active key on the assoc */
2902 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2903 SCTP_TCB_UNLOCK(stcb);
2905 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2906 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2907 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2908 /* get the endpoint active key */
2909 SCTP_INP_RLOCK(inp);
2910 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2911 SCTP_INP_RUNLOCK(inp);
2913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2918 *optsize = sizeof(struct sctp_authkeyid);
2922 case SCTP_LOCAL_AUTH_CHUNKS:
2924 struct sctp_authchunks *sac;
2925 sctp_auth_chklist_t *chklist = NULL;
2928 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2929 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2932 /* get off the assoc */
2933 chklist = stcb->asoc.local_auth_chunks;
2934 /* is there enough space? */
2935 size = sctp_auth_get_chklist_size(chklist);
2936 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2940 /* copy in the chunks */
2941 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2942 sac->gauth_number_of_chunks = (uint32_t)size;
2943 *optsize = sizeof(struct sctp_authchunks) + size;
2945 SCTP_TCB_UNLOCK(stcb);
2947 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2948 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2949 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2950 /* get off the endpoint */
2951 SCTP_INP_RLOCK(inp);
2952 chklist = inp->sctp_ep.local_auth_chunks;
2953 /* is there enough space? */
2954 size = sctp_auth_get_chklist_size(chklist);
2955 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2959 /* copy in the chunks */
2960 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2961 sac->gauth_number_of_chunks = (uint32_t)size;
2962 *optsize = sizeof(struct sctp_authchunks) + size;
2964 SCTP_INP_RUNLOCK(inp);
2966 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2972 case SCTP_PEER_AUTH_CHUNKS:
2974 struct sctp_authchunks *sac;
2975 sctp_auth_chklist_t *chklist = NULL;
2978 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2979 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2982 /* get off the assoc */
2983 chklist = stcb->asoc.peer_auth_chunks;
2984 /* is there enough space? */
2985 size = sctp_auth_get_chklist_size(chklist);
2986 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2988 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2990 /* copy in the chunks */
2991 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2992 sac->gauth_number_of_chunks = (uint32_t)size;
2993 *optsize = sizeof(struct sctp_authchunks) + size;
2995 SCTP_TCB_UNLOCK(stcb);
2997 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3004 struct sctp_event *event;
3005 uint32_t event_type;
3007 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3008 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3010 switch (event->se_type) {
3011 case SCTP_ASSOC_CHANGE:
3012 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3014 case SCTP_PEER_ADDR_CHANGE:
3015 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3017 case SCTP_REMOTE_ERROR:
3018 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3020 case SCTP_SEND_FAILED:
3021 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3023 case SCTP_SHUTDOWN_EVENT:
3024 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3026 case SCTP_ADAPTATION_INDICATION:
3027 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3029 case SCTP_PARTIAL_DELIVERY_EVENT:
3030 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3032 case SCTP_AUTHENTICATION_EVENT:
3033 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3035 case SCTP_STREAM_RESET_EVENT:
3036 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3038 case SCTP_SENDER_DRY_EVENT:
3039 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3041 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3043 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3046 case SCTP_ASSOC_RESET_EVENT:
3047 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3049 case SCTP_STREAM_CHANGE_EVENT:
3050 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3052 case SCTP_SEND_FAILED_EVENT:
3053 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3057 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3061 if (event_type > 0) {
3063 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3065 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3066 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3067 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3068 SCTP_INP_RLOCK(inp);
3069 event->se_on = sctp_is_feature_on(inp, event_type);
3070 SCTP_INP_RUNLOCK(inp);
3072 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3078 SCTP_TCB_UNLOCK(stcb);
3081 *optsize = sizeof(struct sctp_event);
3085 case SCTP_RECVRCVINFO:
3089 if (*optsize < sizeof(int)) {
3090 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3093 SCTP_INP_RLOCK(inp);
3094 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3095 SCTP_INP_RUNLOCK(inp);
3098 /* return the option value */
3099 *(int *)optval = onoff;
3100 *optsize = sizeof(int);
3104 case SCTP_RECVNXTINFO:
3108 if (*optsize < sizeof(int)) {
3109 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3112 SCTP_INP_RLOCK(inp);
3113 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3114 SCTP_INP_RUNLOCK(inp);
3117 /* return the option value */
3118 *(int *)optval = onoff;
3119 *optsize = sizeof(int);
3123 case SCTP_DEFAULT_SNDINFO:
3125 struct sctp_sndinfo *info;
3127 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3128 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3131 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3132 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3133 info->snd_flags &= 0xfff0;
3134 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3135 info->snd_context = stcb->asoc.def_send.sinfo_context;
3136 SCTP_TCB_UNLOCK(stcb);
3138 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3139 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3140 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3141 SCTP_INP_RLOCK(inp);
3142 info->snd_sid = inp->def_send.sinfo_stream;
3143 info->snd_flags = inp->def_send.sinfo_flags;
3144 info->snd_flags &= 0xfff0;
3145 info->snd_ppid = inp->def_send.sinfo_ppid;
3146 info->snd_context = inp->def_send.sinfo_context;
3147 SCTP_INP_RUNLOCK(inp);
3149 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3154 *optsize = sizeof(struct sctp_sndinfo);
3158 case SCTP_DEFAULT_PRINFO:
3160 struct sctp_default_prinfo *info;
3162 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3163 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3166 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3167 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3168 SCTP_TCB_UNLOCK(stcb);
3170 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3171 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3172 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3173 SCTP_INP_RLOCK(inp);
3174 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3175 info->pr_value = inp->def_send.sinfo_timetolive;
3176 SCTP_INP_RUNLOCK(inp);
3178 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3183 *optsize = sizeof(struct sctp_default_prinfo);
3187 case SCTP_PEER_ADDR_THLDS:
3189 struct sctp_paddrthlds *thlds;
3190 struct sctp_nets *net;
3191 struct sockaddr *addr;
3192 #if defined(INET) && defined(INET6)
3193 struct sockaddr_in sin_store;
3196 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3197 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3199 #if defined(INET) && defined(INET6)
3200 if (thlds->spt_address.ss_family == AF_INET6) {
3201 struct sockaddr_in6 *sin6;
3203 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3204 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3205 in6_sin6_2_sin(&sin_store, sin6);
3206 addr = (struct sockaddr *)&sin_store;
3208 addr = (struct sockaddr *)&thlds->spt_address;
3211 addr = (struct sockaddr *)&thlds->spt_address;
3214 addr = (struct sockaddr *)&thlds->spt_address;
3217 net = sctp_findnet(stcb, addr);
3220 * We increment here since
3221 * sctp_findassociation_ep_addr() wil do a
3222 * decrement if it finds the stcb as long as
3223 * the locked tcb (last argument) is NOT a
3227 SCTP_INP_INCR_REF(inp);
3228 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3230 SCTP_INP_DECR_REF(inp);
3233 if ((stcb != NULL) && (net == NULL)) {
3235 if (addr->sa_family == AF_INET) {
3236 struct sockaddr_in *sin;
3238 sin = (struct sockaddr_in *)addr;
3239 if (sin->sin_addr.s_addr != INADDR_ANY) {
3241 SCTP_TCB_UNLOCK(stcb);
3242 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3248 if (addr->sa_family == AF_INET6) {
3249 struct sockaddr_in6 *sin6;
3251 sin6 = (struct sockaddr_in6 *)addr;
3252 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3254 SCTP_TCB_UNLOCK(stcb);
3255 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3261 error = EAFNOSUPPORT;
3262 SCTP_TCB_UNLOCK(stcb);
3263 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3270 thlds->spt_pathmaxrxt = net->failure_threshold;
3271 thlds->spt_pathpfthld = net->pf_threshold;
3272 thlds->spt_pathcpthld = 0xffff;
3274 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3275 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3276 thlds->spt_pathcpthld = 0xffff;
3278 thlds->spt_assoc_id = sctp_get_associd(stcb);
3279 SCTP_TCB_UNLOCK(stcb);
3281 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3282 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3283 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3284 /* Use endpoint defaults */
3285 SCTP_INP_RLOCK(inp);
3286 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3287 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3288 thlds->spt_pathcpthld = 0xffff;
3289 SCTP_INP_RUNLOCK(inp);
3291 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3296 *optsize = sizeof(struct sctp_paddrthlds);
3300 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3302 struct sctp_udpencaps *encaps;
3303 struct sctp_nets *net;
3304 struct sockaddr *addr;
3305 #if defined(INET) && defined(INET6)
3306 struct sockaddr_in sin_store;
3309 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3310 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3312 #if defined(INET) && defined(INET6)
3313 if (encaps->sue_address.ss_family == AF_INET6) {
3314 struct sockaddr_in6 *sin6;
3316 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3317 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3318 in6_sin6_2_sin(&sin_store, sin6);
3319 addr = (struct sockaddr *)&sin_store;
3321 addr = (struct sockaddr *)&encaps->sue_address;
3324 addr = (struct sockaddr *)&encaps->sue_address;
3327 addr = (struct sockaddr *)&encaps->sue_address;
3330 net = sctp_findnet(stcb, addr);
3333 * We increment here since
3334 * sctp_findassociation_ep_addr() wil do a
3335 * decrement if it finds the stcb as long as
3336 * the locked tcb (last argument) is NOT a
3340 SCTP_INP_INCR_REF(inp);
3341 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3343 SCTP_INP_DECR_REF(inp);
3346 if ((stcb != NULL) && (net == NULL)) {
3348 if (addr->sa_family == AF_INET) {
3349 struct sockaddr_in *sin;
3351 sin = (struct sockaddr_in *)addr;
3352 if (sin->sin_addr.s_addr != INADDR_ANY) {
3354 SCTP_TCB_UNLOCK(stcb);
3355 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3361 if (addr->sa_family == AF_INET6) {
3362 struct sockaddr_in6 *sin6;
3364 sin6 = (struct sockaddr_in6 *)addr;
3365 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3367 SCTP_TCB_UNLOCK(stcb);
3368 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3374 error = EAFNOSUPPORT;
3375 SCTP_TCB_UNLOCK(stcb);
3376 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3383 encaps->sue_port = net->port;
3385 encaps->sue_port = stcb->asoc.port;
3387 SCTP_TCB_UNLOCK(stcb);
3389 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3390 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3391 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3392 SCTP_INP_RLOCK(inp);
3393 encaps->sue_port = inp->sctp_ep.port;
3394 SCTP_INP_RUNLOCK(inp);
3396 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3401 *optsize = sizeof(struct sctp_udpencaps);
3405 case SCTP_ECN_SUPPORTED:
3407 struct sctp_assoc_value *av;
3409 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3410 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3413 av->assoc_value = stcb->asoc.ecn_supported;
3414 SCTP_TCB_UNLOCK(stcb);
3416 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3417 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3418 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3419 SCTP_INP_RLOCK(inp);
3420 av->assoc_value = inp->ecn_supported;
3421 SCTP_INP_RUNLOCK(inp);
3423 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3428 *optsize = sizeof(struct sctp_assoc_value);
3432 case SCTP_PR_SUPPORTED:
3434 struct sctp_assoc_value *av;
3436 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3437 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3440 av->assoc_value = stcb->asoc.prsctp_supported;
3441 SCTP_TCB_UNLOCK(stcb);
3443 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3444 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3445 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3446 SCTP_INP_RLOCK(inp);
3447 av->assoc_value = inp->prsctp_supported;
3448 SCTP_INP_RUNLOCK(inp);
3450 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3455 *optsize = sizeof(struct sctp_assoc_value);
3459 case SCTP_AUTH_SUPPORTED:
3461 struct sctp_assoc_value *av;
3463 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3464 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3467 av->assoc_value = stcb->asoc.auth_supported;
3468 SCTP_TCB_UNLOCK(stcb);
3470 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3471 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3472 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3473 SCTP_INP_RLOCK(inp);
3474 av->assoc_value = inp->auth_supported;
3475 SCTP_INP_RUNLOCK(inp);
3477 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3482 *optsize = sizeof(struct sctp_assoc_value);
3486 case SCTP_ASCONF_SUPPORTED:
3488 struct sctp_assoc_value *av;
3490 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3491 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3494 av->assoc_value = stcb->asoc.asconf_supported;
3495 SCTP_TCB_UNLOCK(stcb);
3497 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3498 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3499 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3500 SCTP_INP_RLOCK(inp);
3501 av->assoc_value = inp->asconf_supported;
3502 SCTP_INP_RUNLOCK(inp);
3504 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3509 *optsize = sizeof(struct sctp_assoc_value);
3513 case SCTP_RECONFIG_SUPPORTED:
3515 struct sctp_assoc_value *av;
3517 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3518 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3521 av->assoc_value = stcb->asoc.reconfig_supported;
3522 SCTP_TCB_UNLOCK(stcb);
3524 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3525 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3526 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3527 SCTP_INP_RLOCK(inp);
3528 av->assoc_value = inp->reconfig_supported;
3529 SCTP_INP_RUNLOCK(inp);
3531 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3536 *optsize = sizeof(struct sctp_assoc_value);
3540 case SCTP_NRSACK_SUPPORTED:
3542 struct sctp_assoc_value *av;
3544 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3545 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3548 av->assoc_value = stcb->asoc.nrsack_supported;
3549 SCTP_TCB_UNLOCK(stcb);
3551 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3552 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3553 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3554 SCTP_INP_RLOCK(inp);
3555 av->assoc_value = inp->nrsack_supported;
3556 SCTP_INP_RUNLOCK(inp);
3558 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3563 *optsize = sizeof(struct sctp_assoc_value);
3567 case SCTP_PKTDROP_SUPPORTED:
3569 struct sctp_assoc_value *av;
3571 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3572 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3575 av->assoc_value = stcb->asoc.pktdrop_supported;
3576 SCTP_TCB_UNLOCK(stcb);
3578 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3579 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3580 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3581 SCTP_INP_RLOCK(inp);
3582 av->assoc_value = inp->pktdrop_supported;
3583 SCTP_INP_RUNLOCK(inp);
3585 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3590 *optsize = sizeof(struct sctp_assoc_value);
3594 case SCTP_ENABLE_STREAM_RESET:
3596 struct sctp_assoc_value *av;
3598 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3599 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3602 av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support;
3603 SCTP_TCB_UNLOCK(stcb);
3605 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3606 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3607 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3608 SCTP_INP_RLOCK(inp);
3609 av->assoc_value = (uint32_t)inp->local_strreset_support;
3610 SCTP_INP_RUNLOCK(inp);
3612 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3617 *optsize = sizeof(struct sctp_assoc_value);
3621 case SCTP_PR_STREAM_STATUS:
3623 struct sctp_prstatus *sprstat;
3627 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3628 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3630 sid = sprstat->sprstat_sid;
3631 policy = sprstat->sprstat_policy;
3632 #if defined(SCTP_DETAILED_STR_STATS)
3633 if ((stcb != NULL) &&
3634 (sid < stcb->asoc.streamoutcnt) &&
3635 (policy != SCTP_PR_SCTP_NONE) &&
3636 ((policy <= SCTP_PR_SCTP_MAX) ||
3637 (policy == SCTP_PR_SCTP_ALL))) {
3638 if (policy == SCTP_PR_SCTP_ALL) {
3639 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3640 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3642 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3643 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3646 if ((stcb != NULL) &&
3647 (sid < stcb->asoc.streamoutcnt) &&
3648 (policy == SCTP_PR_SCTP_ALL)) {
3649 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3650 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3653 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3657 SCTP_TCB_UNLOCK(stcb);
3660 *optsize = sizeof(struct sctp_prstatus);
3664 case SCTP_PR_ASSOC_STATUS:
3666 struct sctp_prstatus *sprstat;
3669 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3670 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3672 policy = sprstat->sprstat_policy;
3673 if ((stcb != NULL) &&
3674 (policy != SCTP_PR_SCTP_NONE) &&
3675 ((policy <= SCTP_PR_SCTP_MAX) ||
3676 (policy == SCTP_PR_SCTP_ALL))) {
3677 if (policy == SCTP_PR_SCTP_ALL) {
3678 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3679 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3681 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3682 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3689 SCTP_TCB_UNLOCK(stcb);
3692 *optsize = sizeof(struct sctp_prstatus);
3698 struct sctp_assoc_value *av;
3700 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3701 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3704 av->assoc_value = stcb->asoc.max_cwnd;
3705 SCTP_TCB_UNLOCK(stcb);
3707 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3708 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3709 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3710 SCTP_INP_RLOCK(inp);
3711 av->assoc_value = inp->max_cwnd;
3712 SCTP_INP_RUNLOCK(inp);
3714 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3719 *optsize = sizeof(struct sctp_assoc_value);
3724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3725 error = ENOPROTOOPT;
3727 } /* end switch (sopt->sopt_name) */
3735 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3740 struct sctp_tcb *stcb = NULL;
3741 struct sctp_inpcb *inp = NULL;
3744 if (optval == NULL) {
3745 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3748 inp = (struct sctp_inpcb *)so->so_pcb;
3750 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3753 vrf_id = inp->def_vrf_id;
3758 case SCTP_AUTOCLOSE:
3759 case SCTP_AUTO_ASCONF:
3760 case SCTP_EXPLICIT_EOR:
3761 case SCTP_DISABLE_FRAGMENTS:
3762 case SCTP_USE_EXT_RCVINFO:
3763 case SCTP_I_WANT_MAPPED_V4_ADDR:
3764 /* copy in the option value */
3765 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3770 case SCTP_DISABLE_FRAGMENTS:
3771 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3773 case SCTP_AUTO_ASCONF:
3775 * NOTE: we don't really support this flag
3777 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3778 /* only valid for bound all sockets */
3779 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3781 /* forbidden by admin */
3782 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3785 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3787 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3791 case SCTP_EXPLICIT_EOR:
3792 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3794 case SCTP_USE_EXT_RCVINFO:
3795 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3797 case SCTP_I_WANT_MAPPED_V4_ADDR:
3798 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3799 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3801 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3806 set_opt = SCTP_PCB_FLAGS_NODELAY;
3808 case SCTP_AUTOCLOSE:
3809 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3810 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3811 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3814 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3816 * The value is in ticks. Note this does not effect
3817 * old associations, only new ones.
3819 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3822 SCTP_INP_WLOCK(inp);
3824 sctp_feature_on(inp, set_opt);
3826 sctp_feature_off(inp, set_opt);
3828 SCTP_INP_WUNLOCK(inp);
3830 case SCTP_REUSE_PORT:
3832 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3833 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3834 /* Can't set it after we are bound */
3838 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3839 /* Can't do this for a 1-m socket */
3844 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3846 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3849 case SCTP_PARTIAL_DELIVERY_POINT:
3853 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3854 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3855 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3859 inp->partial_delivery_point = *value;
3862 case SCTP_FRAGMENT_INTERLEAVE:
3863 /* not yet until we re-write sctp_recvmsg() */
3867 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3868 if (*level == SCTP_FRAG_LEVEL_2) {
3869 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3870 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3871 } else if (*level == SCTP_FRAG_LEVEL_1) {
3872 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3873 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3874 } else if (*level == SCTP_FRAG_LEVEL_0) {
3875 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3876 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3879 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3884 case SCTP_INTERLEAVING_SUPPORTED:
3886 struct sctp_assoc_value *av;
3888 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3889 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3892 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3894 SCTP_TCB_UNLOCK(stcb);
3896 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3897 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3898 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3899 SCTP_INP_WLOCK(inp);
3900 if (av->assoc_value == 0) {
3901 inp->idata_supported = 0;
3903 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3904 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3905 inp->idata_supported = 1;
3913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3917 SCTP_INP_WUNLOCK(inp);
3919 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3925 case SCTP_CMT_ON_OFF:
3926 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3927 struct sctp_assoc_value *av;
3929 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3930 if (av->assoc_value > SCTP_CMT_MAX) {
3931 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3935 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3937 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3938 SCTP_TCB_UNLOCK(stcb);
3940 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3941 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3942 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3943 (av->assoc_id == SCTP_ALL_ASSOC)) {
3944 SCTP_INP_WLOCK(inp);
3945 inp->sctp_cmt_on_off = av->assoc_value;
3946 SCTP_INP_WUNLOCK(inp);
3948 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3949 (av->assoc_id == SCTP_ALL_ASSOC)) {
3950 SCTP_INP_RLOCK(inp);
3951 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3952 SCTP_TCB_LOCK(stcb);
3953 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3954 SCTP_TCB_UNLOCK(stcb);
3956 SCTP_INP_RUNLOCK(inp);
3960 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3961 error = ENOPROTOOPT;
3964 case SCTP_PLUGGABLE_CC:
3966 struct sctp_assoc_value *av;
3967 struct sctp_nets *net;
3969 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3970 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3971 (av->assoc_value != SCTP_CC_HSTCP) &&
3972 (av->assoc_value != SCTP_CC_HTCP) &&
3973 (av->assoc_value != SCTP_CC_RTCC)) {
3974 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3978 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3980 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3981 stcb->asoc.congestion_control_module = av->assoc_value;
3982 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3983 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3984 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3987 SCTP_TCB_UNLOCK(stcb);
3989 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3990 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3991 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3992 (av->assoc_id == SCTP_ALL_ASSOC)) {
3993 SCTP_INP_WLOCK(inp);
3994 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3995 SCTP_INP_WUNLOCK(inp);
3997 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3998 (av->assoc_id == SCTP_ALL_ASSOC)) {
3999 SCTP_INP_RLOCK(inp);
4000 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4001 SCTP_TCB_LOCK(stcb);
4002 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4003 stcb->asoc.congestion_control_module = av->assoc_value;
4004 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4005 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4006 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4009 SCTP_TCB_UNLOCK(stcb);
4011 SCTP_INP_RUNLOCK(inp);
4016 case SCTP_CC_OPTION:
4018 struct sctp_cc_option *cc_opt;
4020 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4021 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4023 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4024 SCTP_INP_RLOCK(inp);
4025 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4026 SCTP_TCB_LOCK(stcb);
4027 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4028 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4030 SCTP_TCB_UNLOCK(stcb);
4032 SCTP_INP_RUNLOCK(inp);
4037 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4040 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4043 SCTP_TCB_UNLOCK(stcb);
4047 case SCTP_PLUGGABLE_SS:
4049 struct sctp_assoc_value *av;
4051 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4052 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4053 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4054 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4055 (av->assoc_value != SCTP_SS_PRIORITY) &&
4056 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4057 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4058 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4062 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4064 SCTP_TCB_SEND_LOCK(stcb);
4065 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4066 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4067 stcb->asoc.stream_scheduling_module = av->assoc_value;
4068 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4069 SCTP_TCB_SEND_UNLOCK(stcb);
4070 SCTP_TCB_UNLOCK(stcb);
4072 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4073 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4074 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4075 (av->assoc_id == SCTP_ALL_ASSOC)) {
4076 SCTP_INP_WLOCK(inp);
4077 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4078 SCTP_INP_WUNLOCK(inp);
4080 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4081 (av->assoc_id == SCTP_ALL_ASSOC)) {
4082 SCTP_INP_RLOCK(inp);
4083 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4084 SCTP_TCB_LOCK(stcb);
4085 SCTP_TCB_SEND_LOCK(stcb);
4086 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4087 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4088 stcb->asoc.stream_scheduling_module = av->assoc_value;
4089 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4090 SCTP_TCB_SEND_UNLOCK(stcb);
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 (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4628 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4630 SCTP_TCB_UNLOCK(stcb);
4633 if (sizeof(struct sctp_reset_streams) +
4634 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4636 SCTP_TCB_UNLOCK(stcb);
4639 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4641 if (stcb->asoc.stream_reset_outstanding) {
4642 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4644 SCTP_TCB_UNLOCK(stcb);
4648 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4651 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4652 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4654 SCTP_TCB_UNLOCK(stcb);
4657 if ((send_in == 0) && (send_out == 0)) {
4658 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4660 SCTP_TCB_UNLOCK(stcb);
4663 for (i = 0; i < strrst->srs_number_streams; i++) {
4665 (strrst->srs_stream_list[i] >= stcb->asoc.streamincnt)) {
4666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4671 (strrst->srs_stream_list[i] >= stcb->asoc.streamoutcnt)) {
4672 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4678 SCTP_TCB_UNLOCK(stcb);
4685 if (strrst->srs_number_streams) {
4686 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4687 strm = strrst->srs_stream_list[i];
4688 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4689 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4695 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4696 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4697 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4704 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4705 strrst->srs_stream_list,
4706 send_in, 0, 0, 0, 0, 0);
4708 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4711 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4714 * For outgoing streams don't report any
4715 * problems in sending the request to the
4716 * application. XXX: Double check resetting
4721 SCTP_TCB_UNLOCK(stcb);
4724 case SCTP_ADD_STREAMS:
4726 struct sctp_add_streams *stradd;
4727 uint8_t addstream = 0;
4728 uint16_t add_o_strmcnt = 0;
4729 uint16_t add_i_strmcnt = 0;
4731 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4732 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4734 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4738 if (stcb->asoc.reconfig_supported == 0) {
4740 * Peer does not support the chunk type.
4742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4744 SCTP_TCB_UNLOCK(stcb);
4747 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4748 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4750 SCTP_TCB_UNLOCK(stcb);
4753 if (stcb->asoc.stream_reset_outstanding) {
4754 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4756 SCTP_TCB_UNLOCK(stcb);
4759 if ((stradd->sas_outstrms == 0) &&
4760 (stradd->sas_instrms == 0)) {
4764 if (stradd->sas_outstrms) {
4766 /* We allocate here */
4767 add_o_strmcnt = stradd->sas_outstrms;
4768 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4769 /* You can't have more than 64k */
4774 if (stradd->sas_instrms) {
4779 * We allocate inside
4780 * sctp_send_str_reset_req()
4782 add_i_strmcnt = stradd->sas_instrms;
4783 cnt = add_i_strmcnt;
4784 cnt += stcb->asoc.streamincnt;
4785 if (cnt > 0x0000ffff) {
4786 /* You can't have more than 64k */
4790 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4791 /* More than you are allowed */
4796 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4797 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4799 SCTP_TCB_UNLOCK(stcb);
4802 case SCTP_RESET_ASSOC:
4807 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4808 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value);
4810 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4814 if (stcb->asoc.reconfig_supported == 0) {
4816 * Peer does not support the chunk type.
4818 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4820 SCTP_TCB_UNLOCK(stcb);
4823 if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) {
4824 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4826 SCTP_TCB_UNLOCK(stcb);
4829 if (stcb->asoc.stream_reset_outstanding) {
4830 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4832 SCTP_TCB_UNLOCK(stcb);
4836 * Is there any data pending in the send or sent
4839 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4840 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4843 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4844 SCTP_TCB_UNLOCK(stcb);
4847 /* Do any streams have data queued? */
4848 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4849 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4853 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4854 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4855 SCTP_TCB_UNLOCK(stcb);
4858 case SCTP_CONNECT_X:
4859 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4860 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4864 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4866 case SCTP_CONNECT_X_DELAYED:
4867 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4868 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4872 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4874 case SCTP_CONNECT_X_COMPLETE:
4876 struct sockaddr *sa;
4878 /* FIXME MT: check correct? */
4879 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4882 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4883 SCTP_INP_RLOCK(inp);
4884 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4886 SCTP_TCB_LOCK(stcb);
4888 SCTP_INP_RUNLOCK(inp);
4891 * We increment here since
4892 * sctp_findassociation_ep_addr() wil do a
4893 * decrement if it finds the stcb as long as
4894 * the locked tcb (last argument) is NOT a
4897 SCTP_INP_INCR_REF(inp);
4898 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4900 SCTP_INP_DECR_REF(inp);
4905 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4909 if (stcb->asoc.delayed_connection == 1) {
4910 stcb->asoc.delayed_connection = 0;
4911 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4912 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4913 stcb->asoc.primary_destination,
4914 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4915 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4918 * already expired or did not use delayed
4921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4924 SCTP_TCB_UNLOCK(stcb);
4927 case SCTP_MAX_BURST:
4929 struct sctp_assoc_value *av;
4931 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4932 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4935 stcb->asoc.max_burst = av->assoc_value;
4936 SCTP_TCB_UNLOCK(stcb);
4938 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4939 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4940 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4941 (av->assoc_id == SCTP_ALL_ASSOC)) {
4942 SCTP_INP_WLOCK(inp);
4943 inp->sctp_ep.max_burst = av->assoc_value;
4944 SCTP_INP_WUNLOCK(inp);
4946 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4947 (av->assoc_id == SCTP_ALL_ASSOC)) {
4948 SCTP_INP_RLOCK(inp);
4949 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4950 SCTP_TCB_LOCK(stcb);
4951 stcb->asoc.max_burst = av->assoc_value;
4952 SCTP_TCB_UNLOCK(stcb);
4954 SCTP_INP_RUNLOCK(inp);
4961 struct sctp_assoc_value *av;
4964 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4965 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4967 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4968 ovh = SCTP_MED_OVERHEAD;
4970 ovh = SCTP_MED_V4_OVERHEAD;
4973 if (av->assoc_value) {
4974 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4976 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4978 SCTP_TCB_UNLOCK(stcb);
4980 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4981 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4982 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4983 SCTP_INP_WLOCK(inp);
4985 * FIXME MT: I think this is not in
4986 * tune with the API ID
4988 if (av->assoc_value) {
4989 inp->sctp_frag_point = (av->assoc_value + ovh);
4991 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4993 SCTP_INP_WUNLOCK(inp);
4995 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5003 struct sctp_event_subscribe *events;
5005 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5007 SCTP_INP_WLOCK(inp);
5008 if (events->sctp_data_io_event) {
5009 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5011 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5014 if (events->sctp_association_event) {
5015 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5017 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5020 if (events->sctp_address_event) {
5021 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5023 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5026 if (events->sctp_send_failure_event) {
5027 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5029 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5032 if (events->sctp_peer_error_event) {
5033 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5035 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5038 if (events->sctp_shutdown_event) {
5039 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5041 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5044 if (events->sctp_partial_delivery_event) {
5045 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5047 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5050 if (events->sctp_adaptation_layer_event) {
5051 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5053 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5056 if (events->sctp_authentication_event) {
5057 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5059 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5062 if (events->sctp_sender_dry_event) {
5063 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5065 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5068 if (events->sctp_stream_reset_event) {
5069 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5071 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5073 SCTP_INP_WUNLOCK(inp);
5075 SCTP_INP_RLOCK(inp);
5076 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5077 SCTP_TCB_LOCK(stcb);
5078 if (events->sctp_association_event) {
5079 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5081 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5083 if (events->sctp_address_event) {
5084 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5086 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5088 if (events->sctp_send_failure_event) {
5089 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5091 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5093 if (events->sctp_peer_error_event) {
5094 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5096 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5098 if (events->sctp_shutdown_event) {
5099 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5101 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5103 if (events->sctp_partial_delivery_event) {
5104 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5106 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5108 if (events->sctp_adaptation_layer_event) {
5109 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5111 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5113 if (events->sctp_authentication_event) {
5114 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5116 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5118 if (events->sctp_sender_dry_event) {
5119 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5121 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5123 if (events->sctp_stream_reset_event) {
5124 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5126 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5128 SCTP_TCB_UNLOCK(stcb);
5131 * Send up the sender dry event only for 1-to-1
5134 if (events->sctp_sender_dry_event) {
5135 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5136 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5137 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5139 SCTP_TCB_LOCK(stcb);
5140 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5141 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5142 (stcb->asoc.stream_queue_cnt == 0)) {
5143 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5145 SCTP_TCB_UNLOCK(stcb);
5149 SCTP_INP_RUNLOCK(inp);
5152 case SCTP_ADAPTATION_LAYER:
5154 struct sctp_setadaptation *adap_bits;
5156 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5157 SCTP_INP_WLOCK(inp);
5158 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5159 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5160 SCTP_INP_WUNLOCK(inp);
5164 case SCTP_SET_INITIAL_DBG_SEQ:
5168 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5169 SCTP_INP_WLOCK(inp);
5170 inp->sctp_ep.initial_sequence_debug = *vvv;
5171 SCTP_INP_WUNLOCK(inp);
5175 case SCTP_DEFAULT_SEND_PARAM:
5177 struct sctp_sndrcvinfo *s_info;
5179 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5180 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5183 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5184 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5189 SCTP_TCB_UNLOCK(stcb);
5191 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5192 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5193 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5194 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5195 SCTP_INP_WLOCK(inp);
5196 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5197 SCTP_INP_WUNLOCK(inp);
5199 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5200 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5201 SCTP_INP_RLOCK(inp);
5202 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5203 SCTP_TCB_LOCK(stcb);
5204 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5205 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5207 SCTP_TCB_UNLOCK(stcb);
5209 SCTP_INP_RUNLOCK(inp);
5214 case SCTP_PEER_ADDR_PARAMS:
5216 struct sctp_paddrparams *paddrp;
5217 struct sctp_nets *net;
5218 struct sockaddr *addr;
5219 #if defined(INET) && defined(INET6)
5220 struct sockaddr_in sin_store;
5223 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5224 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5226 #if defined(INET) && defined(INET6)
5227 if (paddrp->spp_address.ss_family == AF_INET6) {
5228 struct sockaddr_in6 *sin6;
5230 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5231 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5232 in6_sin6_2_sin(&sin_store, sin6);
5233 addr = (struct sockaddr *)&sin_store;
5235 addr = (struct sockaddr *)&paddrp->spp_address;
5238 addr = (struct sockaddr *)&paddrp->spp_address;
5241 addr = (struct sockaddr *)&paddrp->spp_address;
5244 net = sctp_findnet(stcb, addr);
5247 * We increment here since
5248 * sctp_findassociation_ep_addr() wil do a
5249 * decrement if it finds the stcb as long as
5250 * the locked tcb (last argument) is NOT a
5254 SCTP_INP_INCR_REF(inp);
5255 stcb = sctp_findassociation_ep_addr(&inp, addr,
5258 SCTP_INP_DECR_REF(inp);
5261 if ((stcb != NULL) && (net == NULL)) {
5263 if (addr->sa_family == AF_INET) {
5265 struct sockaddr_in *sin;
5267 sin = (struct sockaddr_in *)addr;
5268 if (sin->sin_addr.s_addr != INADDR_ANY) {
5269 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5270 SCTP_TCB_UNLOCK(stcb);
5277 if (addr->sa_family == AF_INET6) {
5278 struct sockaddr_in6 *sin6;
5280 sin6 = (struct sockaddr_in6 *)addr;
5281 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5282 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5283 SCTP_TCB_UNLOCK(stcb);
5290 error = EAFNOSUPPORT;
5291 SCTP_TCB_UNLOCK(stcb);
5292 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5297 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5299 SCTP_TCB_UNLOCK(stcb);
5300 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5304 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5306 SCTP_TCB_UNLOCK(stcb);
5307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5312 /************************TCB SPECIFIC SET ******************/
5314 /************************NET SPECIFIC SET ******************/
5315 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5316 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5317 !(net->dest_state & SCTP_ADDR_NOHB)) {
5318 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5319 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5321 net->dest_state |= SCTP_ADDR_NOHB;
5323 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5324 if (paddrp->spp_hbinterval) {
5325 net->heart_beat_delay = paddrp->spp_hbinterval;
5326 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5327 net->heart_beat_delay = 0;
5329 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5330 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5331 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5332 net->dest_state &= ~SCTP_ADDR_NOHB;
5334 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5335 if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
5336 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5337 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5338 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5341 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5342 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5343 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5344 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5346 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5347 net->mtu = paddrp->spp_pathmtu;
5348 switch (net->ro._l_addr.sa.sa_family) {
5351 net->mtu += SCTP_MIN_V4_OVERHEAD;
5356 net->mtu += SCTP_MIN_OVERHEAD;
5362 if (net->mtu < stcb->asoc.smallest_mtu) {
5363 sctp_pathmtu_adjustment(stcb, net->mtu);
5366 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5367 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5368 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5370 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5372 if (paddrp->spp_pathmaxrxt) {
5373 if (net->dest_state & SCTP_ADDR_PF) {
5374 if (net->error_count > paddrp->spp_pathmaxrxt) {
5375 net->dest_state &= ~SCTP_ADDR_PF;
5378 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5379 (net->error_count > net->pf_threshold)) {
5380 net->dest_state |= SCTP_ADDR_PF;
5381 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5382 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5383 stcb->sctp_ep, stcb, net,
5384 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5385 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5388 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5389 if (net->error_count > paddrp->spp_pathmaxrxt) {
5390 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5391 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5394 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5395 net->dest_state |= SCTP_ADDR_REACHABLE;
5396 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5399 net->failure_threshold = paddrp->spp_pathmaxrxt;
5401 if (paddrp->spp_flags & SPP_DSCP) {
5402 net->dscp = paddrp->spp_dscp & 0xfc;
5406 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5407 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5408 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5409 net->flowlabel |= 0x80000000;
5414 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5415 if (paddrp->spp_pathmaxrxt != 0) {
5416 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5417 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5418 if (net->dest_state & SCTP_ADDR_PF) {
5419 if (net->error_count > paddrp->spp_pathmaxrxt) {
5420 net->dest_state &= ~SCTP_ADDR_PF;
5423 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5424 (net->error_count > net->pf_threshold)) {
5425 net->dest_state |= SCTP_ADDR_PF;
5426 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5427 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5428 stcb->sctp_ep, stcb, net,
5429 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5430 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5433 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5434 if (net->error_count > paddrp->spp_pathmaxrxt) {
5435 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5436 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5439 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5440 net->dest_state |= SCTP_ADDR_REACHABLE;
5441 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5444 net->failure_threshold = paddrp->spp_pathmaxrxt;
5448 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5449 if (paddrp->spp_hbinterval != 0) {
5450 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5451 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5452 stcb->asoc.heart_beat_delay = 0;
5454 /* Turn back on the timer */
5455 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5456 if (paddrp->spp_hbinterval != 0) {
5457 net->heart_beat_delay = paddrp->spp_hbinterval;
5458 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5459 net->heart_beat_delay = 0;
5461 if (net->dest_state & SCTP_ADDR_NOHB) {
5462 net->dest_state &= ~SCTP_ADDR_NOHB;
5464 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5465 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5466 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5468 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5470 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5471 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5472 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5473 net->dest_state |= SCTP_ADDR_NOHB;
5474 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5475 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5477 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5481 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5483 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5484 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5485 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5486 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5487 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5489 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5490 net->mtu = paddrp->spp_pathmtu;
5491 switch (net->ro._l_addr.sa.sa_family) {
5494 net->mtu += SCTP_MIN_V4_OVERHEAD;
5499 net->mtu += SCTP_MIN_OVERHEAD;
5505 if (net->mtu < stcb->asoc.smallest_mtu) {
5506 sctp_pathmtu_adjustment(stcb, net->mtu);
5509 stcb->asoc.default_mtu = paddrp->spp_pathmtu;
5510 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5512 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5513 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5514 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5515 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5517 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5519 stcb->asoc.default_mtu = 0;
5520 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5522 if (paddrp->spp_flags & SPP_DSCP) {
5523 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5524 net->dscp = paddrp->spp_dscp & 0xfc;
5527 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5528 stcb->asoc.default_dscp |= 0x01;
5531 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5532 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5533 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5534 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5535 net->flowlabel |= 0x80000000;
5538 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5539 stcb->asoc.default_flowlabel |= 0x80000000;
5543 SCTP_TCB_UNLOCK(stcb);
5545 /************************NO TCB, SET TO default stuff ******************/
5546 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5547 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5548 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5549 SCTP_INP_WLOCK(inp);
5551 * For the TOS/FLOWLABEL stuff you
5552 * set it with the options on the
5555 if (paddrp->spp_pathmaxrxt != 0) {
5556 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5559 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5560 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5561 else if (paddrp->spp_hbinterval != 0) {
5562 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5563 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5564 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5567 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5568 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5569 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5570 } else if (paddrp->spp_hbinterval) {
5571 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5573 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5574 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5575 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5577 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5578 inp->sctp_ep.default_mtu = 0;
5579 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5580 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5581 if (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU) {
5582 inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
5584 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5586 if (paddrp->spp_flags & SPP_DSCP) {
5587 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5588 inp->sctp_ep.default_dscp |= 0x01;
5591 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5592 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5593 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5594 inp->sctp_ep.default_flowlabel |= 0x80000000;
5598 SCTP_INP_WUNLOCK(inp);
5600 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5608 struct sctp_rtoinfo *srto;
5609 uint32_t new_init, new_min, new_max;
5611 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5612 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5615 if (srto->srto_initial)
5616 new_init = srto->srto_initial;
5618 new_init = stcb->asoc.initial_rto;
5620 new_max = srto->srto_max;
5622 new_max = stcb->asoc.maxrto;
5624 new_min = srto->srto_min;
5626 new_min = stcb->asoc.minrto;
5627 if ((new_min <= new_init) && (new_init <= new_max)) {
5628 stcb->asoc.initial_rto = new_init;
5629 stcb->asoc.maxrto = new_max;
5630 stcb->asoc.minrto = new_min;
5632 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5635 SCTP_TCB_UNLOCK(stcb);
5637 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5638 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5639 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5640 SCTP_INP_WLOCK(inp);
5641 if (srto->srto_initial)
5642 new_init = srto->srto_initial;
5644 new_init = inp->sctp_ep.initial_rto;
5646 new_max = srto->srto_max;
5648 new_max = inp->sctp_ep.sctp_maxrto;
5650 new_min = srto->srto_min;
5652 new_min = inp->sctp_ep.sctp_minrto;
5653 if ((new_min <= new_init) && (new_init <= new_max)) {
5654 inp->sctp_ep.initial_rto = new_init;
5655 inp->sctp_ep.sctp_maxrto = new_max;
5656 inp->sctp_ep.sctp_minrto = new_min;
5658 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5661 SCTP_INP_WUNLOCK(inp);
5663 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5669 case SCTP_ASSOCINFO:
5671 struct sctp_assocparams *sasoc;
5673 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5674 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5675 if (sasoc->sasoc_cookie_life) {
5676 /* boundary check the cookie life */
5677 if (sasoc->sasoc_cookie_life < 1000)
5678 sasoc->sasoc_cookie_life = 1000;
5679 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5680 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5684 if (sasoc->sasoc_asocmaxrxt)
5685 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5686 if (sasoc->sasoc_cookie_life) {
5687 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5689 SCTP_TCB_UNLOCK(stcb);
5691 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5692 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5693 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5694 SCTP_INP_WLOCK(inp);
5695 if (sasoc->sasoc_asocmaxrxt)
5696 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5697 if (sasoc->sasoc_cookie_life) {
5698 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5700 SCTP_INP_WUNLOCK(inp);
5702 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5710 struct sctp_initmsg *sinit;
5712 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5713 SCTP_INP_WLOCK(inp);
5714 if (sinit->sinit_num_ostreams)
5715 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5717 if (sinit->sinit_max_instreams)
5718 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5720 if (sinit->sinit_max_attempts)
5721 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5723 if (sinit->sinit_max_init_timeo)
5724 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5725 SCTP_INP_WUNLOCK(inp);
5728 case SCTP_PRIMARY_ADDR:
5730 struct sctp_setprim *spa;
5731 struct sctp_nets *net;
5732 struct sockaddr *addr;
5733 #if defined(INET) && defined(INET6)
5734 struct sockaddr_in sin_store;
5737 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5738 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5740 #if defined(INET) && defined(INET6)
5741 if (spa->ssp_addr.ss_family == AF_INET6) {
5742 struct sockaddr_in6 *sin6;
5744 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5745 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5746 in6_sin6_2_sin(&sin_store, sin6);
5747 addr = (struct sockaddr *)&sin_store;
5749 addr = (struct sockaddr *)&spa->ssp_addr;
5752 addr = (struct sockaddr *)&spa->ssp_addr;
5755 addr = (struct sockaddr *)&spa->ssp_addr;
5758 net = sctp_findnet(stcb, addr);
5761 * We increment here since
5762 * sctp_findassociation_ep_addr() wil do a
5763 * decrement if it finds the stcb as long as
5764 * the locked tcb (last argument) is NOT a
5768 SCTP_INP_INCR_REF(inp);
5769 stcb = sctp_findassociation_ep_addr(&inp, addr,
5772 SCTP_INP_DECR_REF(inp);
5776 if ((stcb != NULL) && (net != NULL)) {
5777 if (net != stcb->asoc.primary_destination) {
5778 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5779 /* Ok we need to set it */
5780 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5781 if ((stcb->asoc.alternate) &&
5782 (!(net->dest_state & SCTP_ADDR_PF)) &&
5783 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5784 sctp_free_remote_addr(stcb->asoc.alternate);
5785 stcb->asoc.alternate = NULL;
5788 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5792 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5797 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5801 SCTP_TCB_UNLOCK(stcb);
5805 case SCTP_SET_DYNAMIC_PRIMARY:
5807 union sctp_sockstore *ss;
5809 error = priv_check(curthread,
5810 PRIV_NETINET_RESERVEDPORT);
5814 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5815 /* SUPER USER CHECK? */
5816 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5819 case SCTP_SET_PEER_PRIMARY_ADDR:
5821 struct sctp_setpeerprim *sspp;
5822 struct sockaddr *addr;
5823 #if defined(INET) && defined(INET6)
5824 struct sockaddr_in sin_store;
5827 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5828 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5830 struct sctp_ifa *ifa;
5832 #if defined(INET) && defined(INET6)
5833 if (sspp->sspp_addr.ss_family == AF_INET6) {
5834 struct sockaddr_in6 *sin6;
5836 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5837 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5838 in6_sin6_2_sin(&sin_store, sin6);
5839 addr = (struct sockaddr *)&sin_store;
5841 addr = (struct sockaddr *)&sspp->sspp_addr;
5844 addr = (struct sockaddr *)&sspp->sspp_addr;
5847 addr = (struct sockaddr *)&sspp->sspp_addr;
5849 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5851 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5855 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5857 * Must validate the ifa found is in
5860 struct sctp_laddr *laddr;
5863 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5864 if (laddr->ifa == NULL) {
5865 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5869 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5870 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5873 if (laddr->ifa == ifa) {
5879 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5884 switch (addr->sa_family) {
5888 struct sockaddr_in *sin;
5890 sin = (struct sockaddr_in *)addr;
5891 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5892 &sin->sin_addr) != 0) {
5893 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5903 struct sockaddr_in6 *sin6;
5905 sin6 = (struct sockaddr_in6 *)addr;
5906 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5907 &sin6->sin6_addr) != 0) {
5908 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5921 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5925 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5927 SCTP_TCB_UNLOCK(stcb);
5929 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5934 case SCTP_BINDX_ADD_ADDR:
5936 struct sctp_getaddresses *addrs;
5939 td = (struct thread *)p;
5940 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5943 if (addrs->addr->sa_family == AF_INET) {
5944 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5945 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5949 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5950 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5956 if (addrs->addr->sa_family == AF_INET6) {
5957 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5958 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5962 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5963 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5964 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5970 error = EAFNOSUPPORT;
5973 sctp_bindx_add_address(so, inp, addrs->addr,
5974 addrs->sget_assoc_id, vrf_id,
5978 case SCTP_BINDX_REM_ADDR:
5980 struct sctp_getaddresses *addrs;
5983 td = (struct thread *)p;
5985 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5987 if (addrs->addr->sa_family == AF_INET) {
5988 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5993 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5994 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6000 if (addrs->addr->sa_family == AF_INET6) {
6001 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
6002 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6007 (error = prison_local_ip6(td->td_ucred,
6008 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
6009 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6010 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6016 error = EAFNOSUPPORT;
6019 sctp_bindx_delete_address(inp, addrs->addr,
6020 addrs->sget_assoc_id, vrf_id,
6026 struct sctp_event *event;
6027 uint32_t event_type;
6029 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6030 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6031 switch (event->se_type) {
6032 case SCTP_ASSOC_CHANGE:
6033 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6035 case SCTP_PEER_ADDR_CHANGE:
6036 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6038 case SCTP_REMOTE_ERROR:
6039 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6041 case SCTP_SEND_FAILED:
6042 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6044 case SCTP_SHUTDOWN_EVENT:
6045 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6047 case SCTP_ADAPTATION_INDICATION:
6048 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6050 case SCTP_PARTIAL_DELIVERY_EVENT:
6051 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6053 case SCTP_AUTHENTICATION_EVENT:
6054 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6056 case SCTP_STREAM_RESET_EVENT:
6057 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6059 case SCTP_SENDER_DRY_EVENT:
6060 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6062 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6064 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6067 case SCTP_ASSOC_RESET_EVENT:
6068 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6070 case SCTP_STREAM_CHANGE_EVENT:
6071 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6073 case SCTP_SEND_FAILED_EVENT:
6074 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6078 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6082 if (event_type > 0) {
6085 sctp_stcb_feature_on(inp, stcb, event_type);
6086 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6087 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6088 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6089 (stcb->asoc.stream_queue_cnt == 0)) {
6090 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6094 sctp_stcb_feature_off(inp, stcb, event_type);
6096 SCTP_TCB_UNLOCK(stcb);
6099 * We don't want to send up a storm
6100 * of events, so return an error for
6103 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6104 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6105 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6106 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6107 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6108 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6112 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6113 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6114 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6115 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6116 SCTP_INP_WLOCK(inp);
6118 sctp_feature_on(inp, event_type);
6120 sctp_feature_off(inp, event_type);
6122 SCTP_INP_WUNLOCK(inp);
6124 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6125 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6126 SCTP_INP_RLOCK(inp);
6127 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6128 SCTP_TCB_LOCK(stcb);
6130 sctp_stcb_feature_on(inp, stcb, event_type);
6132 sctp_stcb_feature_off(inp, stcb, event_type);
6134 SCTP_TCB_UNLOCK(stcb);
6136 SCTP_INP_RUNLOCK(inp);
6141 SCTP_TCB_UNLOCK(stcb);
6146 case SCTP_RECVRCVINFO:
6150 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6151 SCTP_INP_WLOCK(inp);
6153 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6155 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6157 SCTP_INP_WUNLOCK(inp);
6160 case SCTP_RECVNXTINFO:
6164 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6165 SCTP_INP_WLOCK(inp);
6167 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6169 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6171 SCTP_INP_WUNLOCK(inp);
6174 case SCTP_DEFAULT_SNDINFO:
6176 struct sctp_sndinfo *info;
6179 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6180 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6183 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6184 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6185 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6186 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6187 stcb->asoc.def_send.sinfo_flags |= policy;
6188 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6189 stcb->asoc.def_send.sinfo_context = info->snd_context;
6191 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6194 SCTP_TCB_UNLOCK(stcb);
6196 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6197 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6198 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6199 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6200 SCTP_INP_WLOCK(inp);
6201 inp->def_send.sinfo_stream = info->snd_sid;
6202 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6203 inp->def_send.sinfo_flags = info->snd_flags;
6204 inp->def_send.sinfo_flags |= policy;
6205 inp->def_send.sinfo_ppid = info->snd_ppid;
6206 inp->def_send.sinfo_context = info->snd_context;
6207 SCTP_INP_WUNLOCK(inp);
6209 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6210 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6211 SCTP_INP_RLOCK(inp);
6212 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6213 SCTP_TCB_LOCK(stcb);
6214 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6215 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6216 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6217 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6218 stcb->asoc.def_send.sinfo_flags |= policy;
6219 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6220 stcb->asoc.def_send.sinfo_context = info->snd_context;
6222 SCTP_TCB_UNLOCK(stcb);
6224 SCTP_INP_RUNLOCK(inp);
6229 case SCTP_DEFAULT_PRINFO:
6231 struct sctp_default_prinfo *info;
6233 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6234 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6236 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6238 SCTP_TCB_UNLOCK(stcb);
6240 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6245 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6246 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6247 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6248 SCTP_TCB_UNLOCK(stcb);
6250 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6251 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6252 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6253 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6254 SCTP_INP_WLOCK(inp);
6255 inp->def_send.sinfo_flags &= 0xfff0;
6256 inp->def_send.sinfo_flags |= info->pr_policy;
6257 inp->def_send.sinfo_timetolive = info->pr_value;
6258 SCTP_INP_WUNLOCK(inp);
6260 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6261 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6262 SCTP_INP_RLOCK(inp);
6263 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6264 SCTP_TCB_LOCK(stcb);
6265 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6266 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6267 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6268 SCTP_TCB_UNLOCK(stcb);
6270 SCTP_INP_RUNLOCK(inp);
6275 case SCTP_PEER_ADDR_THLDS:
6276 /* Applies to the specific association */
6278 struct sctp_paddrthlds *thlds;
6279 struct sctp_nets *net;
6280 struct sockaddr *addr;
6281 #if defined(INET) && defined(INET6)
6282 struct sockaddr_in sin_store;
6285 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6286 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6288 #if defined(INET) && defined(INET6)
6289 if (thlds->spt_address.ss_family == AF_INET6) {
6290 struct sockaddr_in6 *sin6;
6292 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6293 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6294 in6_sin6_2_sin(&sin_store, sin6);
6295 addr = (struct sockaddr *)&sin_store;
6297 addr = (struct sockaddr *)&thlds->spt_address;
6300 addr = (struct sockaddr *)&thlds->spt_address;
6303 addr = (struct sockaddr *)&thlds->spt_address;
6306 net = sctp_findnet(stcb, addr);
6309 * We increment here since
6310 * sctp_findassociation_ep_addr() wil do a
6311 * decrement if it finds the stcb as long as
6312 * the locked tcb (last argument) is NOT a
6316 SCTP_INP_INCR_REF(inp);
6317 stcb = sctp_findassociation_ep_addr(&inp, addr,
6320 SCTP_INP_DECR_REF(inp);
6323 if ((stcb != NULL) && (net == NULL)) {
6325 if (addr->sa_family == AF_INET) {
6327 struct sockaddr_in *sin;
6329 sin = (struct sockaddr_in *)addr;
6330 if (sin->sin_addr.s_addr != INADDR_ANY) {
6331 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6332 SCTP_TCB_UNLOCK(stcb);
6339 if (addr->sa_family == AF_INET6) {
6340 struct sockaddr_in6 *sin6;
6342 sin6 = (struct sockaddr_in6 *)addr;
6343 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6344 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6345 SCTP_TCB_UNLOCK(stcb);
6352 error = EAFNOSUPPORT;
6353 SCTP_TCB_UNLOCK(stcb);
6354 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6358 if (thlds->spt_pathcpthld != 0xffff) {
6360 SCTP_TCB_UNLOCK(stcb);
6363 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6368 net->failure_threshold = thlds->spt_pathmaxrxt;
6369 net->pf_threshold = thlds->spt_pathpfthld;
6370 if (net->dest_state & SCTP_ADDR_PF) {
6371 if ((net->error_count > net->failure_threshold) ||
6372 (net->error_count <= net->pf_threshold)) {
6373 net->dest_state &= ~SCTP_ADDR_PF;
6376 if ((net->error_count > net->pf_threshold) &&
6377 (net->error_count <= net->failure_threshold)) {
6378 net->dest_state |= SCTP_ADDR_PF;
6379 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6380 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6381 stcb->sctp_ep, stcb, net,
6382 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6383 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6386 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6387 if (net->error_count > net->failure_threshold) {
6388 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6389 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6392 if (net->error_count <= net->failure_threshold) {
6393 net->dest_state |= SCTP_ADDR_REACHABLE;
6394 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6398 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6399 net->failure_threshold = thlds->spt_pathmaxrxt;
6400 net->pf_threshold = thlds->spt_pathpfthld;
6401 if (net->dest_state & SCTP_ADDR_PF) {
6402 if ((net->error_count > net->failure_threshold) ||
6403 (net->error_count <= net->pf_threshold)) {
6404 net->dest_state &= ~SCTP_ADDR_PF;
6407 if ((net->error_count > net->pf_threshold) &&
6408 (net->error_count <= net->failure_threshold)) {
6409 net->dest_state |= SCTP_ADDR_PF;
6410 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6411 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6412 stcb->sctp_ep, stcb, net,
6413 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6414 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6417 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6418 if (net->error_count > net->failure_threshold) {
6419 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6420 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6423 if (net->error_count <= net->failure_threshold) {
6424 net->dest_state |= SCTP_ADDR_REACHABLE;
6425 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6429 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6430 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6432 SCTP_TCB_UNLOCK(stcb);
6434 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6435 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6436 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6437 SCTP_INP_WLOCK(inp);
6438 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6439 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6440 SCTP_INP_WUNLOCK(inp);
6442 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6448 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6450 struct sctp_udpencaps *encaps;
6451 struct sctp_nets *net;
6452 struct sockaddr *addr;
6453 #if defined(INET) && defined(INET6)
6454 struct sockaddr_in sin_store;
6457 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6458 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6460 #if defined(INET) && defined(INET6)
6461 if (encaps->sue_address.ss_family == AF_INET6) {
6462 struct sockaddr_in6 *sin6;
6464 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6465 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6466 in6_sin6_2_sin(&sin_store, sin6);
6467 addr = (struct sockaddr *)&sin_store;
6469 addr = (struct sockaddr *)&encaps->sue_address;
6472 addr = (struct sockaddr *)&encaps->sue_address;
6475 addr = (struct sockaddr *)&encaps->sue_address;
6478 net = sctp_findnet(stcb, addr);
6481 * We increment here since
6482 * sctp_findassociation_ep_addr() wil do a
6483 * decrement if it finds the stcb as long as
6484 * the locked tcb (last argument) is NOT a
6488 SCTP_INP_INCR_REF(inp);
6489 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6491 SCTP_INP_DECR_REF(inp);
6494 if ((stcb != NULL) && (net == NULL)) {
6496 if (addr->sa_family == AF_INET) {
6498 struct sockaddr_in *sin;
6500 sin = (struct sockaddr_in *)addr;
6501 if (sin->sin_addr.s_addr != INADDR_ANY) {
6502 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6503 SCTP_TCB_UNLOCK(stcb);
6510 if (addr->sa_family == AF_INET6) {
6511 struct sockaddr_in6 *sin6;
6513 sin6 = (struct sockaddr_in6 *)addr;
6514 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6515 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6516 SCTP_TCB_UNLOCK(stcb);
6523 error = EAFNOSUPPORT;
6524 SCTP_TCB_UNLOCK(stcb);
6525 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6532 net->port = encaps->sue_port;
6534 stcb->asoc.port = encaps->sue_port;
6536 SCTP_TCB_UNLOCK(stcb);
6538 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6539 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6540 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6541 SCTP_INP_WLOCK(inp);
6542 inp->sctp_ep.port = encaps->sue_port;
6543 SCTP_INP_WUNLOCK(inp);
6545 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6551 case SCTP_ECN_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->ecn_supported = 0;
6570 inp->ecn_supported = 1;
6572 SCTP_INP_WUNLOCK(inp);
6574 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6580 case SCTP_PR_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 SCTP_INP_WLOCK(inp);
6596 if (av->assoc_value == 0) {
6597 inp->prsctp_supported = 0;
6599 inp->prsctp_supported = 1;
6601 SCTP_INP_WUNLOCK(inp);
6603 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6609 case SCTP_AUTH_SUPPORTED:
6611 struct sctp_assoc_value *av;
6613 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6614 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6617 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6619 SCTP_TCB_UNLOCK(stcb);
6621 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6622 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6623 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6624 if ((av->assoc_value == 0) &&
6625 (inp->asconf_supported == 1)) {
6627 * AUTH is required for
6630 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6633 SCTP_INP_WLOCK(inp);
6634 if (av->assoc_value == 0) {
6635 inp->auth_supported = 0;
6637 inp->auth_supported = 1;
6639 SCTP_INP_WUNLOCK(inp);
6642 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6648 case SCTP_ASCONF_SUPPORTED:
6650 struct sctp_assoc_value *av;
6652 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6653 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6656 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6658 SCTP_TCB_UNLOCK(stcb);
6660 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6661 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6662 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6663 if ((av->assoc_value != 0) &&
6664 (inp->auth_supported == 0)) {
6666 * AUTH is required for
6669 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6672 SCTP_INP_WLOCK(inp);
6673 if (av->assoc_value == 0) {
6674 inp->asconf_supported = 0;
6675 sctp_auth_delete_chunk(SCTP_ASCONF,
6676 inp->sctp_ep.local_auth_chunks);
6677 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6678 inp->sctp_ep.local_auth_chunks);
6680 inp->asconf_supported = 1;
6681 sctp_auth_add_chunk(SCTP_ASCONF,
6682 inp->sctp_ep.local_auth_chunks);
6683 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6684 inp->sctp_ep.local_auth_chunks);
6686 SCTP_INP_WUNLOCK(inp);
6689 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6695 case SCTP_RECONFIG_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->reconfig_supported = 0;
6714 inp->reconfig_supported = 1;
6716 SCTP_INP_WUNLOCK(inp);
6718 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6724 case SCTP_NRSACK_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->nrsack_supported = 0;
6743 inp->nrsack_supported = 1;
6745 SCTP_INP_WUNLOCK(inp);
6747 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6753 case SCTP_PKTDROP_SUPPORTED:
6755 struct sctp_assoc_value *av;
6757 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6758 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6761 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6763 SCTP_TCB_UNLOCK(stcb);
6765 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6766 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6767 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6768 SCTP_INP_WLOCK(inp);
6769 if (av->assoc_value == 0) {
6770 inp->pktdrop_supported = 0;
6772 inp->pktdrop_supported = 1;
6774 SCTP_INP_WUNLOCK(inp);
6776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6784 struct sctp_assoc_value *av;
6785 struct sctp_nets *net;
6787 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6788 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6791 stcb->asoc.max_cwnd = av->assoc_value;
6792 if (stcb->asoc.max_cwnd > 0) {
6793 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6794 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6795 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6796 net->cwnd = stcb->asoc.max_cwnd;
6797 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6798 net->cwnd = net->mtu - sizeof(struct sctphdr);
6803 SCTP_TCB_UNLOCK(stcb);
6805 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6806 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6807 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6808 SCTP_INP_WLOCK(inp);
6809 inp->max_cwnd = av->assoc_value;
6810 SCTP_INP_WUNLOCK(inp);
6812 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6819 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6820 error = ENOPROTOOPT;
6822 } /* end switch (opt) */
6827 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6829 void *optval = NULL;
6833 struct sctp_inpcb *inp;
6835 if ((sopt->sopt_level == SOL_SOCKET) &&
6836 (sopt->sopt_name == SO_SETFIB)) {
6837 inp = (struct sctp_inpcb *)so->so_pcb;
6839 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6842 SCTP_INP_WLOCK(inp);
6843 inp->fibnum = so->so_fibnum;
6844 SCTP_INP_WUNLOCK(inp);
6847 if (sopt->sopt_level != IPPROTO_SCTP) {
6848 /* wrong proto level... send back up to IP */
6850 if (INP_CHECK_SOCKAF(so, AF_INET6))
6851 error = ip6_ctloutput(so, sopt);
6853 #if defined(INET) && defined(INET6)
6857 error = ip_ctloutput(so, sopt);
6861 optsize = sopt->sopt_valsize;
6862 if (optsize > SCTP_SOCKET_OPTION_LIMIT) {
6863 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6867 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6868 if (optval == NULL) {
6869 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6872 error = sooptcopyin(sopt, optval, optsize, optsize);
6874 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6878 p = (void *)sopt->sopt_td;
6879 if (sopt->sopt_dir == SOPT_SET) {
6880 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6881 } else if (sopt->sopt_dir == SOPT_GET) {
6882 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6884 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6887 if ((error == 0) && (optval != NULL)) {
6888 error = sooptcopyout(sopt, optval, optsize);
6889 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6890 } else if (optval != NULL) {
6891 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6899 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6902 int create_lock_on = 0;
6904 struct sctp_inpcb *inp;
6905 struct sctp_tcb *stcb = NULL;
6907 inp = (struct sctp_inpcb *)so->so_pcb;
6909 /* I made the same as TCP since we are not setup? */
6910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6911 return (ECONNRESET);
6914 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6918 switch (addr->sa_family) {
6922 struct sockaddr_in6 *sin6p;
6924 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6925 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6928 sin6p = (struct sockaddr_in6 *)addr;
6929 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6939 struct sockaddr_in *sinp;
6941 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6942 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6945 sinp = (struct sockaddr_in *)addr;
6946 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6947 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6954 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6955 return (EAFNOSUPPORT);
6957 SCTP_INP_INCR_REF(inp);
6958 SCTP_ASOC_CREATE_LOCK(inp);
6962 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6963 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6964 /* Should I really unlock ? */
6965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6970 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6971 (addr->sa_family == AF_INET6)) {
6972 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6977 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6978 SCTP_PCB_FLAGS_UNBOUND) {
6979 /* Bind a ephemeral port */
6980 error = sctp_inpcb_bind(so, NULL, NULL, p);
6985 /* Now do we connect? */
6986 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6987 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6988 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6992 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6993 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6994 /* We are already connected AND the TCP model */
6995 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6999 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7000 SCTP_INP_RLOCK(inp);
7001 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7002 SCTP_INP_RUNLOCK(inp);
7005 * We increment here since sctp_findassociation_ep_addr()
7006 * will do a decrement if it finds the stcb as long as the
7007 * locked tcb (last argument) is NOT a TCB.. aka NULL.
7009 SCTP_INP_INCR_REF(inp);
7010 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
7012 SCTP_INP_DECR_REF(inp);
7014 SCTP_TCB_UNLOCK(stcb);
7018 /* Already have or am bring up an association */
7019 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7024 vrf_id = inp->def_vrf_id;
7025 /* We are GOOD to go */
7026 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
7027 inp->sctp_ep.pre_open_stream_count,
7028 inp->sctp_ep.port, p);
7030 /* Gak! no memory */
7033 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7034 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7035 /* Set the connected flag so we can queue data */
7038 SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
7039 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7041 /* initialize authentication parameters for the assoc */
7042 sctp_initialize_auth_params(inp, stcb);
7044 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7045 SCTP_TCB_UNLOCK(stcb);
7047 if (create_lock_on) {
7048 SCTP_ASOC_CREATE_UNLOCK(inp);
7051 SCTP_INP_DECR_REF(inp);
7057 sctp_listen(struct socket *so, int backlog, struct thread *p)
7060 * Note this module depends on the protocol processing being called
7061 * AFTER any socket level flags and backlog are applied to the
7062 * socket. The traditional way that the socket flags are applied is
7063 * AFTER protocol processing. We have made a change to the
7064 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7065 * place if the socket API for SCTP is to work properly.
7069 struct sctp_inpcb *inp;
7071 inp = (struct sctp_inpcb *)so->so_pcb;
7073 /* I made the same as TCP since we are not setup? */
7074 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7075 return (ECONNRESET);
7077 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7078 /* See if we have a listener */
7079 struct sctp_inpcb *tinp;
7080 union sctp_sockstore store;
7082 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7084 struct sctp_laddr *laddr;
7086 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7087 memcpy(&store, &laddr->ifa->address, sizeof(store));
7088 switch (store.sa.sa_family) {
7091 store.sin.sin_port = inp->sctp_lport;
7096 store.sin6.sin6_port = inp->sctp_lport;
7102 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7103 if (tinp && (tinp != inp) &&
7104 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7105 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7106 (SCTP_IS_LISTENING(tinp))) {
7108 * we have a listener already and
7111 SCTP_INP_DECR_REF(tinp);
7112 return (EADDRINUSE);
7114 SCTP_INP_DECR_REF(tinp);
7118 /* Setup a local addr bound all */
7119 memset(&store, 0, sizeof(store));
7121 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7122 store.sa.sa_family = AF_INET6;
7123 store.sa.sa_len = sizeof(struct sockaddr_in6);
7127 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7128 store.sa.sa_family = AF_INET;
7129 store.sa.sa_len = sizeof(struct sockaddr_in);
7132 switch (store.sa.sa_family) {
7135 store.sin.sin_port = inp->sctp_lport;
7140 store.sin6.sin6_port = inp->sctp_lport;
7146 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7147 if (tinp && (tinp != inp) &&
7148 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7149 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7150 (SCTP_IS_LISTENING(tinp))) {
7152 * we have a listener already and its not
7155 SCTP_INP_DECR_REF(tinp);
7156 return (EADDRINUSE);
7158 SCTP_INP_DECR_REF(tinp);
7162 SCTP_INP_RLOCK(inp);
7163 #ifdef SCTP_LOCK_LOGGING
7164 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7165 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7169 error = solisten_proto_check(so);
7172 SCTP_INP_RUNLOCK(inp);
7175 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7176 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7178 * The unlucky case - We are in the tcp pool with this guy.
7179 * - Someone else is in the main inp slot. - We must move
7180 * this guy (the listener) to the main slot - We must then
7181 * move the guy that was listener to the TCP Pool.
7183 if (sctp_swap_inpcb_for_listen(inp)) {
7184 SCTP_INP_RUNLOCK(inp);
7185 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7186 return (EADDRINUSE);
7190 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7191 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7192 /* We are already connected AND the TCP model */
7193 SCTP_INP_RUNLOCK(inp);
7194 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7195 return (EADDRINUSE);
7197 SCTP_INP_RUNLOCK(inp);
7198 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7199 /* We must do a bind. */
7200 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7201 /* bind error, probably perm */
7205 SCTP_INP_WLOCK(inp);
7206 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) {
7208 solisten_proto(so, backlog);
7212 inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING;
7214 inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING;
7216 SCTP_INP_WUNLOCK(inp);
7220 static int sctp_defered_wakeup_cnt = 0;
7223 sctp_accept(struct socket *so, struct sockaddr **addr)
7225 struct sctp_tcb *stcb;
7226 struct sctp_inpcb *inp;
7227 union sctp_sockstore store;
7231 inp = (struct sctp_inpcb *)so->so_pcb;
7234 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7235 return (ECONNRESET);
7237 SCTP_INP_RLOCK(inp);
7238 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7239 SCTP_INP_RUNLOCK(inp);
7240 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7241 return (EOPNOTSUPP);
7243 if (so->so_state & SS_ISDISCONNECTED) {
7244 SCTP_INP_RUNLOCK(inp);
7245 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7246 return (ECONNABORTED);
7248 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7250 SCTP_INP_RUNLOCK(inp);
7251 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7252 return (ECONNRESET);
7254 SCTP_TCB_LOCK(stcb);
7255 SCTP_INP_RUNLOCK(inp);
7256 store = stcb->asoc.primary_destination->ro._l_addr;
7257 SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE);
7258 SCTP_TCB_UNLOCK(stcb);
7259 switch (store.sa.sa_family) {
7263 struct sockaddr_in *sin;
7265 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7268 sin->sin_family = AF_INET;
7269 sin->sin_len = sizeof(*sin);
7270 sin->sin_port = store.sin.sin_port;
7271 sin->sin_addr = store.sin.sin_addr;
7272 *addr = (struct sockaddr *)sin;
7279 struct sockaddr_in6 *sin6;
7281 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7284 sin6->sin6_family = AF_INET6;
7285 sin6->sin6_len = sizeof(*sin6);
7286 sin6->sin6_port = store.sin6.sin6_port;
7287 sin6->sin6_addr = store.sin6.sin6_addr;
7288 if ((error = sa6_recoverscope(sin6)) != 0) {
7289 SCTP_FREE_SONAME(sin6);
7292 *addr = (struct sockaddr *)sin6;
7300 /* Wake any delayed sleep action */
7301 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7302 SCTP_INP_WLOCK(inp);
7303 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7304 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7305 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7306 SCTP_INP_WUNLOCK(inp);
7307 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7308 if (sowriteable(inp->sctp_socket)) {
7309 sowwakeup_locked(inp->sctp_socket);
7311 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7313 SCTP_INP_WLOCK(inp);
7315 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7316 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7317 SCTP_INP_WUNLOCK(inp);
7318 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7319 if (soreadable(inp->sctp_socket)) {
7320 sctp_defered_wakeup_cnt++;
7321 sorwakeup_locked(inp->sctp_socket);
7323 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7325 SCTP_INP_WLOCK(inp);
7327 SCTP_INP_WUNLOCK(inp);
7329 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7330 SCTP_TCB_LOCK(stcb);
7331 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7332 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7339 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7341 struct sockaddr_in *sin;
7343 struct sctp_inpcb *inp;
7344 struct sctp_ifa *sctp_ifa;
7347 * Do the malloc first in case it blocks.
7349 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7352 sin->sin_family = AF_INET;
7353 sin->sin_len = sizeof(*sin);
7354 inp = (struct sctp_inpcb *)so->so_pcb;
7356 SCTP_FREE_SONAME(sin);
7357 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7358 return (ECONNRESET);
7360 SCTP_INP_RLOCK(inp);
7361 sin->sin_port = inp->sctp_lport;
7362 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7363 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7364 struct sctp_tcb *stcb;
7365 struct sockaddr_in *sin_a;
7366 struct sctp_nets *net;
7369 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7375 SCTP_TCB_LOCK(stcb);
7376 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7377 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7379 /* this will make coverity happy */
7382 if (sin_a->sin_family == AF_INET) {
7387 if ((!fnd) || (sin_a == NULL)) {
7389 SCTP_TCB_UNLOCK(stcb);
7393 vrf_id = inp->def_vrf_id;
7394 sctp_ifa = sctp_source_address_selection(inp,
7396 (sctp_route_t *)&net->ro,
7399 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7400 sctp_free_ifa(sctp_ifa);
7402 SCTP_TCB_UNLOCK(stcb);
7404 /* For the bound all case you get back 0 */
7406 sin->sin_addr.s_addr = 0;
7410 /* Take the first IPv4 address in the list */
7411 struct sctp_laddr *laddr;
7414 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7415 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7416 struct sockaddr_in *sin_a;
7418 sin_a = &laddr->ifa->address.sin;
7419 sin->sin_addr = sin_a->sin_addr;
7425 SCTP_FREE_SONAME(sin);
7426 SCTP_INP_RUNLOCK(inp);
7427 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7431 SCTP_INP_RUNLOCK(inp);
7432 (*addr) = (struct sockaddr *)sin;
7437 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7439 struct sockaddr_in *sin;
7441 struct sockaddr_in *sin_a;
7442 struct sctp_inpcb *inp;
7443 struct sctp_tcb *stcb;
7444 struct sctp_nets *net;
7446 /* Do the malloc first in case it blocks. */
7447 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7450 sin->sin_family = AF_INET;
7451 sin->sin_len = sizeof(*sin);
7453 inp = (struct sctp_inpcb *)so->so_pcb;
7454 if ((inp == NULL) ||
7455 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7456 /* UDP type and listeners will drop out here */
7457 SCTP_FREE_SONAME(sin);
7458 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7461 SCTP_INP_RLOCK(inp);
7462 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7464 SCTP_TCB_LOCK(stcb);
7466 SCTP_INP_RUNLOCK(inp);
7468 SCTP_FREE_SONAME(sin);
7469 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7470 return (ECONNRESET);
7473 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7474 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7475 if (sin_a->sin_family == AF_INET) {
7477 sin->sin_port = stcb->rport;
7478 sin->sin_addr = sin_a->sin_addr;
7482 SCTP_TCB_UNLOCK(stcb);
7484 /* No IPv4 address */
7485 SCTP_FREE_SONAME(sin);
7486 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7489 (*addr) = (struct sockaddr *)sin;
7493 struct pr_usrreqs sctp_usrreqs = {
7494 .pru_abort = sctp_abort,
7495 .pru_accept = sctp_accept,
7496 .pru_attach = sctp_attach,
7497 .pru_bind = sctp_bind,
7498 .pru_connect = sctp_connect,
7499 .pru_control = in_control,
7500 .pru_close = sctp_close,
7501 .pru_detach = sctp_close,
7502 .pru_sopoll = sopoll_generic,
7503 .pru_flush = sctp_flush,
7504 .pru_disconnect = sctp_disconnect,
7505 .pru_listen = sctp_listen,
7506 .pru_peeraddr = sctp_peeraddr,
7507 .pru_send = sctp_sendm,
7508 .pru_shutdown = sctp_shutdown,
7509 .pru_sockaddr = sctp_ingetaddr,
7510 .pru_sosend = sctp_sosend,
7511 .pru_soreceive = sctp_soreceive