2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <netinet/sctp_os.h>
38 #include <netinet/sctp_pcb.h>
39 #include <netinet/sctp_header.h>
40 #include <netinet/sctp_var.h>
42 #include <netinet6/sctp6_var.h>
44 #include <netinet/sctp_sysctl.h>
45 #include <netinet/sctp_output.h>
46 #include <netinet/sctp_uio.h>
47 #include <netinet/sctp_asconf.h>
48 #include <netinet/sctputil.h>
49 #include <netinet/sctp_indata.h>
50 #include <netinet/sctp_timer.h>
51 #include <netinet/sctp_auth.h>
52 #include <netinet/sctp_bsd_addr.h>
53 #include <netinet/udp.h>
57 extern const struct sctp_cc_functions sctp_cc_functions[];
58 extern const struct sctp_ss_functions sctp_ss_functions[];
65 /* Initialize and modify the sysctled variables */
67 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
68 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
70 * Allow a user to take no more than 1/2 the number of clusters or
71 * the SB_MAX whichever is smaller for the send window.
73 sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
74 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
75 (((uint32_t) nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
77 * Now for the recv window, should we take the same amount? or
78 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
79 * now I will just copy.
81 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
82 SCTP_BASE_VAR(first_time) = 0;
83 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
85 #if defined(SCTP_PACKET_LOGGING)
86 SCTP_BASE_VAR(packet_log_writers) = 0;
87 SCTP_BASE_VAR(packet_log_end) = 0;
88 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
101 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
103 struct sctp_tmit_chunk *chk;
106 /* Adjust that too */
107 stcb->asoc.smallest_mtu = nxtsz;
108 /* now off to subtract IP_DF flag if needed */
109 overhead = IP_HDR_SIZE;
110 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
111 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
113 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
114 if ((chk->send_size + overhead) > nxtsz) {
115 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
118 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
119 if ((chk->send_size + overhead) > nxtsz) {
121 * For this guy we also mark for immediate resend
122 * since we sent to big of chunk
124 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
125 if (chk->sent < SCTP_DATAGRAM_RESEND) {
126 sctp_flight_size_decrease(chk);
127 sctp_total_flight_decrease(stcb, chk);
128 chk->sent = SCTP_DATAGRAM_RESEND;
129 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
130 chk->rec.data.doing_fast_retransmit = 0;
131 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
132 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
133 chk->whoTo->flight_size,
135 (uint32_t) (uintptr_t) chk->whoTo,
136 chk->rec.data.TSN_seq);
138 /* Clear any time so NO RTT is being done */
147 sctp_notify(struct sctp_inpcb *inp,
148 struct sctp_tcb *stcb,
149 struct sctp_nets *net,
155 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
161 if (icmp_type != ICMP_UNREACH) {
162 /* We only care about unreachable */
163 SCTP_TCB_UNLOCK(stcb);
166 if ((icmp_code == ICMP_UNREACH_NET) ||
167 (icmp_code == ICMP_UNREACH_HOST) ||
168 (icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
169 (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
170 (icmp_code == ICMP_UNREACH_ISOLATED) ||
171 (icmp_code == ICMP_UNREACH_NET_PROHIB) ||
172 (icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
173 (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
174 /* Mark the net unreachable. */
175 if (net->dest_state & SCTP_ADDR_REACHABLE) {
176 /* OK, that destination is NOT reachable. */
177 net->dest_state &= ~SCTP_ADDR_REACHABLE;
178 net->dest_state &= ~SCTP_ADDR_PF;
179 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
181 (void *)net, SCTP_SO_NOT_LOCKED);
183 SCTP_TCB_UNLOCK(stcb);
184 } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) ||
185 (icmp_code == ICMP_UNREACH_PORT)) {
186 /* Treat it like an ABORT. */
187 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
188 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
189 so = SCTP_INP_SO(inp);
190 atomic_add_int(&stcb->asoc.refcnt, 1);
191 SCTP_TCB_UNLOCK(stcb);
192 SCTP_SOCKET_LOCK(so, 1);
194 atomic_subtract_int(&stcb->asoc.refcnt, 1);
196 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
197 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
198 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
199 SCTP_SOCKET_UNLOCK(so, 1);
200 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
202 /* no need to unlock here, since the TCB is gone */
203 } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) {
204 /* Find the next (smaller) MTU */
207 * Old type router that does not tell us what the
208 * next MTU is. Rats we will have to guess (in a
209 * educated fashion of course).
211 next_mtu = sctp_get_prev_mtu(ip_len);
213 /* Stop the PMTU timer. */
214 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
216 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
217 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
221 /* Update the path MTU. */
222 if (net->mtu > next_mtu) {
225 net->mtu -= sizeof(struct udphdr);
228 /* Update the association MTU */
229 if (stcb->asoc.smallest_mtu > next_mtu) {
230 sctp_pathmtu_adjustment(stcb, next_mtu);
232 /* Finally, start the PMTU timer if it was running before. */
234 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
236 SCTP_TCB_UNLOCK(stcb);
238 SCTP_TCB_UNLOCK(stcb);
243 sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
249 struct sctp_inpcb *inp;
250 struct sctp_tcb *stcb;
251 struct sctp_nets *net;
252 struct sctp_init_chunk *ch;
253 struct sockaddr_in src, dst;
255 if (sa->sa_family != AF_INET ||
256 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
259 if (PRC_IS_REDIRECT(cmd)) {
261 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
265 inner_ip = (struct ip *)vip;
266 icmp = (struct icmp *)((caddr_t)inner_ip -
267 (sizeof(struct icmp) - sizeof(struct ip)));
268 outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
269 sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
270 memset(&src, 0, sizeof(struct sockaddr_in));
271 src.sin_family = AF_INET;
272 src.sin_len = sizeof(struct sockaddr_in);
273 src.sin_port = sh->src_port;
274 src.sin_addr = inner_ip->ip_src;
275 memset(&dst, 0, sizeof(struct sockaddr_in));
276 dst.sin_family = AF_INET;
277 dst.sin_len = sizeof(struct sockaddr_in);
278 dst.sin_port = sh->dest_port;
279 dst.sin_addr = inner_ip->ip_dst;
281 * 'dst' holds the dest of the packet that failed to be
282 * sent. 'src' holds our local endpoint address. Thus we
283 * reverse the dst and the src in the lookup.
287 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
288 (struct sockaddr *)&src,
291 if ((stcb != NULL) &&
294 (inp->sctp_socket != NULL)) {
295 /* Check the verification tag */
296 if (ntohl(sh->v_tag) != 0) {
298 * This must be the verification tag used
299 * for sending out packets. We don't
300 * consider packets reflecting the
303 if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
304 SCTP_TCB_UNLOCK(stcb);
308 if (ntohs(outer_ip->ip_len) >=
310 8 + (inner_ip->ip_hl << 2) + 20) {
312 * In this case we can check if we
313 * got an INIT chunk and if the
314 * initiate tag matches.
316 ch = (struct sctp_init_chunk *)(sh + 1);
317 if ((ch->ch.chunk_type != SCTP_INITIATION) ||
318 (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
319 SCTP_TCB_UNLOCK(stcb);
323 SCTP_TCB_UNLOCK(stcb);
327 sctp_notify(inp, stcb, net,
330 ntohs(inner_ip->ip_len),
331 ntohs(icmp->icmp_nextmtu));
333 if ((stcb == NULL) && (inp != NULL)) {
334 /* reduce ref-count */
336 SCTP_INP_DECR_REF(inp);
337 SCTP_INP_WUNLOCK(inp);
340 SCTP_TCB_UNLOCK(stcb);
350 sctp_getcred(SYSCTL_HANDLER_ARGS)
353 struct sockaddr_in addrs[2];
354 struct sctp_inpcb *inp;
355 struct sctp_nets *net;
356 struct sctp_tcb *stcb;
360 /* FIX, for non-bsd is this right? */
361 vrf_id = SCTP_DEFAULT_VRFID;
363 error = priv_check(req->td, PRIV_NETINET_GETCRED);
368 error = SYSCTL_IN(req, addrs, sizeof(addrs));
372 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
374 &inp, &net, 1, vrf_id);
375 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
376 if ((inp != NULL) && (stcb == NULL)) {
377 /* reduce ref-count */
379 SCTP_INP_DECR_REF(inp);
382 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
386 SCTP_TCB_UNLOCK(stcb);
388 * We use the write lock here, only since in the error leg we need
389 * it. If we used RLOCK, then we would have to
390 * wlock/decr/unlock/rlock. Which in theory could create a hole.
391 * Better to use higher wlock.
395 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
397 SCTP_INP_WUNLOCK(inp);
400 cru2x(inp->sctp_socket->so_cred, &xuc);
401 SCTP_INP_WUNLOCK(inp);
402 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
407 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
408 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
413 sctp_abort(struct socket *so)
415 struct sctp_inpcb *inp;
418 inp = (struct sctp_inpcb *)so->so_pcb;
423 flags = inp->sctp_flags;
424 #ifdef SCTP_LOG_CLOSING
425 sctp_log_closing(inp, NULL, 17);
427 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
428 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
429 #ifdef SCTP_LOG_CLOSING
430 sctp_log_closing(inp, NULL, 16);
432 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
433 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
435 SCTP_SB_CLEAR(so->so_snd);
437 * same for the rcv ones, they are only here for the
440 SCTP_SB_CLEAR(so->so_rcv);
442 /* Now null out the reference, we are completely detached. */
446 flags = inp->sctp_flags;
447 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
448 goto sctp_must_try_again;
455 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
457 struct sctp_inpcb *inp;
458 struct inpcb *ip_inp;
460 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
462 inp = (struct sctp_inpcb *)so->so_pcb;
464 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
467 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
468 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
473 error = sctp_inpcb_alloc(so, vrf_id);
477 inp = (struct sctp_inpcb *)so->so_pcb;
479 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
480 ip_inp = &inp->ip_inp.inp;
481 ip_inp->inp_vflag |= INP_IPV4;
482 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
483 SCTP_INP_WUNLOCK(inp);
488 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
490 struct sctp_inpcb *inp;
492 inp = (struct sctp_inpcb *)so->so_pcb;
494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
498 if ((addr->sa_family != AF_INET) ||
499 (addr->sa_len != sizeof(struct sockaddr_in))) {
500 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
504 return (sctp_inpcb_bind(so, addr, NULL, p));
509 sctp_close(struct socket *so)
511 struct sctp_inpcb *inp;
514 inp = (struct sctp_inpcb *)so->so_pcb;
519 * Inform all the lower layer assoc that we are done.
522 flags = inp->sctp_flags;
523 #ifdef SCTP_LOG_CLOSING
524 sctp_log_closing(inp, NULL, 17);
526 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
527 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
528 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
529 (so->so_rcv.sb_cc > 0)) {
530 #ifdef SCTP_LOG_CLOSING
531 sctp_log_closing(inp, NULL, 13);
533 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
534 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
536 #ifdef SCTP_LOG_CLOSING
537 sctp_log_closing(inp, NULL, 14);
539 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
540 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
543 * The socket is now detached, no matter what the state of
544 * the SCTP association.
547 SCTP_SB_CLEAR(so->so_snd);
549 * same for the rcv ones, they are only here for the
552 SCTP_SB_CLEAR(so->so_rcv);
554 /* Now null out the reference, we are completely detached. */
558 flags = inp->sctp_flags;
559 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
560 goto sctp_must_try_again;
568 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
569 struct mbuf *control, struct thread *p);
573 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
574 struct mbuf *control, struct thread *p)
576 struct sctp_inpcb *inp;
579 inp = (struct sctp_inpcb *)so->so_pcb;
582 sctp_m_freem(control);
585 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
589 /* Got to have an to address if we are NOT a connected socket */
590 if ((addr == NULL) &&
591 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
592 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
594 } else if (addr == NULL) {
595 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
596 error = EDESTADDRREQ;
599 sctp_m_freem(control);
605 if (addr->sa_family != AF_INET) {
606 /* must be a v4 address! */
607 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
610 sctp_m_freem(control);
613 error = EDESTADDRREQ;
618 /* now what about control */
621 SCTP_PRINTF("huh? control set?\n");
622 sctp_m_freem(inp->control);
625 inp->control = control;
629 SCTP_BUF_NEXT(inp->pkt_last) = m;
632 inp->pkt_last = inp->pkt = m;
635 /* FreeBSD uses a flag passed */
636 ((flags & PRUS_MORETOCOME) == 0)
639 * note with the current version this code will only be used
640 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
641 * re-defining sosend to use the sctp_sosend. One can
642 * optionally switch back to this code (by changing back the
643 * definitions) but this is not advisable. This code is used
644 * by FreeBSD when sending a file with sendfile() though.
648 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
658 sctp_disconnect(struct socket *so)
660 struct sctp_inpcb *inp;
662 inp = (struct sctp_inpcb *)so->so_pcb;
664 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
668 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
669 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
670 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
672 SCTP_INP_RUNLOCK(inp);
675 struct sctp_association *asoc;
676 struct sctp_tcb *stcb;
678 stcb = LIST_FIRST(&inp->sctp_asoc_list);
680 SCTP_INP_RUNLOCK(inp);
681 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
686 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
687 /* We are about to be freed, out of here */
688 SCTP_TCB_UNLOCK(stcb);
689 SCTP_INP_RUNLOCK(inp);
692 if (((so->so_options & SO_LINGER) &&
693 (so->so_linger == 0)) ||
694 (so->so_rcv.sb_cc > 0)) {
695 if (SCTP_GET_STATE(asoc) !=
696 SCTP_STATE_COOKIE_WAIT) {
697 /* Left with Data unread */
700 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_NOWAIT, 1, MT_DATA);
706 struct sctp_paramhdr *ph;
708 ph = mtod(err, struct sctp_paramhdr *);
709 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
710 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
711 ph->param_length = htons(SCTP_BUF_LEN(err));
713 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
714 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
716 SCTP_INP_RUNLOCK(inp);
717 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
718 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
719 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
721 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
722 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
723 /* No unlock tcb assoc is gone */
726 if (TAILQ_EMPTY(&asoc->send_queue) &&
727 TAILQ_EMPTY(&asoc->sent_queue) &&
728 (asoc->stream_queue_cnt == 0)) {
729 /* there is nothing queued to send, so done */
730 if (asoc->locked_on_sending) {
733 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
734 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
735 /* only send SHUTDOWN 1st time thru */
736 struct sctp_nets *netp;
738 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
739 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
740 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
742 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
743 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
744 sctp_stop_timers_for_shutdown(stcb);
745 if (stcb->asoc.alternate) {
746 netp = stcb->asoc.alternate;
748 netp = stcb->asoc.primary_destination;
750 sctp_send_shutdown(stcb, netp);
751 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
752 stcb->sctp_ep, stcb, netp);
753 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
754 stcb->sctp_ep, stcb, netp);
755 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
759 * we still got (or just got) data to send,
760 * so set SHUTDOWN_PENDING
763 * XXX sockets draft says that SCTP_EOF
764 * should be sent with no data. currently,
765 * we will allow user data to be sent first
766 * and move to SHUTDOWN-PENDING
768 struct sctp_nets *netp;
770 if (stcb->asoc.alternate) {
771 netp = stcb->asoc.alternate;
773 netp = stcb->asoc.primary_destination;
776 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
777 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
779 if (asoc->locked_on_sending) {
780 /* Locked to send out the data */
781 struct sctp_stream_queue_pending *sp;
783 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
785 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
786 asoc->locked_on_sending->stream_no);
788 if ((sp->length == 0) && (sp->msg_is_complete == 0))
789 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
792 if (TAILQ_EMPTY(&asoc->send_queue) &&
793 TAILQ_EMPTY(&asoc->sent_queue) &&
794 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
798 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
799 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
800 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
801 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
802 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
803 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
804 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
806 SCTP_INP_RUNLOCK(inp);
807 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
808 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
811 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
814 soisdisconnecting(so);
815 SCTP_TCB_UNLOCK(stcb);
816 SCTP_INP_RUNLOCK(inp);
821 /* UDP model does not support this */
822 SCTP_INP_RUNLOCK(inp);
823 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
829 sctp_flush(struct socket *so, int how)
832 * We will just clear out the values and let subsequent close clear
833 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
834 * they will not be able to read the data, the socket will block
835 * that from happening.
837 struct sctp_inpcb *inp;
839 inp = (struct sctp_inpcb *)so->so_pcb;
841 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
845 /* For the 1 to many model this does nothing */
846 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
847 SCTP_INP_RUNLOCK(inp);
850 SCTP_INP_RUNLOCK(inp);
851 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
853 * First make sure the sb will be happy, we don't use these
854 * except maybe the count
857 SCTP_INP_READ_LOCK(inp);
858 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
859 SCTP_INP_READ_UNLOCK(inp);
860 SCTP_INP_WUNLOCK(inp);
861 so->so_rcv.sb_cc = 0;
862 so->so_rcv.sb_mbcnt = 0;
863 so->so_rcv.sb_mb = NULL;
865 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
867 * First make sure the sb will be happy, we don't use these
868 * except maybe the count
870 so->so_snd.sb_cc = 0;
871 so->so_snd.sb_mbcnt = 0;
872 so->so_snd.sb_mb = NULL;
879 sctp_shutdown(struct socket *so)
881 struct sctp_inpcb *inp;
883 inp = (struct sctp_inpcb *)so->so_pcb;
885 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
889 /* For UDP model this is a invalid call */
890 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
891 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
892 /* Restore the flags that the soshutdown took away. */
893 SOCKBUF_LOCK(&so->so_rcv);
894 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
895 SOCKBUF_UNLOCK(&so->so_rcv);
896 /* This proc will wakeup for read and do nothing (I hope) */
897 SCTP_INP_RUNLOCK(inp);
898 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
902 * Ok, if we reach here its the TCP model and it is either a
903 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
906 struct sctp_tcb *stcb;
907 struct sctp_association *asoc;
908 struct sctp_nets *netp;
911 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
912 SCTP_INP_RUNLOCK(inp);
917 stcb = LIST_FIRST(&inp->sctp_asoc_list);
920 * Ok, we hit the case that the shutdown call was
921 * made after an abort or something. Nothing to do
924 SCTP_INP_RUNLOCK(inp);
929 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
930 SCTP_TCB_UNLOCK(stcb);
931 SCTP_INP_RUNLOCK(inp);
934 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_WAIT) &&
935 (SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_ECHOED) &&
936 (SCTP_GET_STATE(asoc) != SCTP_STATE_OPEN)) {
938 * If we are not in or before ESTABLISHED, there is
939 * no protocol action required.
941 SCTP_TCB_UNLOCK(stcb);
942 SCTP_INP_RUNLOCK(inp);
945 if (stcb->asoc.alternate) {
946 netp = stcb->asoc.alternate;
948 netp = stcb->asoc.primary_destination;
950 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) &&
951 TAILQ_EMPTY(&asoc->send_queue) &&
952 TAILQ_EMPTY(&asoc->sent_queue) &&
953 (asoc->stream_queue_cnt == 0)) {
954 if (asoc->locked_on_sending) {
957 /* there is nothing queued to send, so I'm done... */
958 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
959 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
960 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
961 sctp_stop_timers_for_shutdown(stcb);
962 sctp_send_shutdown(stcb, netp);
963 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
964 stcb->sctp_ep, stcb, netp);
967 * We still got (or just got) data to send, so set
970 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
971 if (asoc->locked_on_sending) {
972 /* Locked to send out the data */
973 struct sctp_stream_queue_pending *sp;
975 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
977 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
978 asoc->locked_on_sending->stream_no);
980 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
981 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_PARTIAL_MSG_LEFT);
985 if (TAILQ_EMPTY(&asoc->send_queue) &&
986 TAILQ_EMPTY(&asoc->sent_queue) &&
987 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
991 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
992 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
993 sctp_abort_an_association(stcb->sctp_ep, stcb,
994 op_err, SCTP_SO_LOCKED);
995 SCTP_INP_RUNLOCK(inp);
999 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp);
1001 * XXX: Why do this in the case where we have still data
1004 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1005 SCTP_TCB_UNLOCK(stcb);
1006 SCTP_INP_RUNLOCK(inp);
1012 * copies a "user" presentable address and removes embedded scope, etc.
1013 * returns 0 on success, 1 on error
1016 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1019 struct sockaddr_in6 lsa6;
1021 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1024 memcpy(ss, sa, sa->sa_len);
1031 * NOTE: assumes addr lock is held
1034 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1035 struct sctp_tcb *stcb,
1037 struct sockaddr_storage *sas,
1040 struct sctp_ifn *sctp_ifn;
1041 struct sctp_ifa *sctp_ifa;
1046 int ipv4_local_scope, ipv4_addr_legal;
1050 int local_scope, site_scope, ipv6_addr_legal;
1053 struct sctp_vrf *vrf;
1060 /* Turn on all the appropriate scope */
1061 loopback_scope = stcb->asoc.scope.loopback_scope;
1063 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1064 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1067 local_scope = stcb->asoc.scope.local_scope;
1068 site_scope = stcb->asoc.scope.site_scope;
1069 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1072 /* Use generic values for endpoints. */
1075 ipv4_local_scope = 1;
1081 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1083 ipv6_addr_legal = 1;
1086 if (SCTP_IPV6_V6ONLY(inp)) {
1087 ipv4_addr_legal = 0;
1089 ipv4_addr_legal = 1;
1094 ipv6_addr_legal = 0;
1097 ipv4_addr_legal = 1;
1101 vrf = sctp_find_vrf(vrf_id);
1105 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1106 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1107 if ((loopback_scope == 0) &&
1108 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1109 /* Skip loopback if loopback_scope not set */
1112 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1115 * For the BOUND-ALL case, the list
1116 * associated with a TCB is Always
1117 * considered a reverse list.. i.e.
1118 * it lists addresses that are NOT
1119 * part of the association. If this
1120 * is one of those we must skip it.
1122 if (sctp_is_addr_restricted(stcb,
1127 switch (sctp_ifa->address.sa.sa_family) {
1130 if (ipv4_addr_legal) {
1131 struct sockaddr_in *sin;
1133 sin = &sctp_ifa->address.sin;
1134 if (sin->sin_addr.s_addr == 0) {
1142 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1143 &sin->sin_addr) != 0) {
1146 if ((ipv4_local_scope == 0) &&
1147 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1151 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1152 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1153 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1154 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1155 actual += sizeof(struct sockaddr_in6);
1158 memcpy(sas, sin, sizeof(*sin));
1159 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1160 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1161 actual += sizeof(*sin);
1165 if (actual >= limit) {
1175 if (ipv6_addr_legal) {
1176 struct sockaddr_in6 *sin6;
1178 sin6 = &sctp_ifa->address.sin6;
1179 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1187 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1188 &sin6->sin6_addr) != 0) {
1191 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1192 if (local_scope == 0)
1194 if (sin6->sin6_scope_id == 0) {
1195 if (sa6_recoverscope(sin6) != 0)
1213 if ((site_scope == 0) &&
1214 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1217 memcpy(sas, sin6, sizeof(*sin6));
1218 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1219 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1220 actual += sizeof(*sin6);
1221 if (actual >= limit) {
1236 struct sctp_laddr *laddr;
1238 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1240 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1244 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1246 switch (laddr->ifa->address.sa.sa_family) {
1249 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1254 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1261 sas = (struct sockaddr_storage *)((caddr_t)sas +
1262 laddr->ifa->address.sa.sa_len);
1263 actual += laddr->ifa->address.sa.sa_len;
1264 if (actual >= limit) {
1273 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1274 struct sctp_tcb *stcb,
1276 struct sockaddr_storage *sas)
1280 SCTP_IPI_ADDR_RLOCK();
1281 /* fill up addresses for the endpoint's default vrf */
1282 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1284 SCTP_IPI_ADDR_RUNLOCK();
1289 * NOTE: assumes addr lock is held
1292 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1295 struct sctp_vrf *vrf = NULL;
1298 * In both sub-set bound an bound_all cases we return the MAXIMUM
1299 * number of addresses that you COULD get. In reality the sub-set
1300 * bound may have an exclusion list for a given TCB OR in the
1301 * bound-all case a TCB may NOT include the loopback or other
1302 * addresses as well.
1304 vrf = sctp_find_vrf(vrf_id);
1308 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1309 struct sctp_ifn *sctp_ifn;
1310 struct sctp_ifa *sctp_ifa;
1312 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1313 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1314 /* Count them if they are the right type */
1315 switch (sctp_ifa->address.sa.sa_family) {
1319 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1320 cnt += sizeof(struct sockaddr_in6);
1322 cnt += sizeof(struct sockaddr_in);
1324 cnt += sizeof(struct sockaddr_in);
1330 cnt += sizeof(struct sockaddr_in6);
1339 struct sctp_laddr *laddr;
1341 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1342 switch (laddr->ifa->address.sa.sa_family) {
1346 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1347 cnt += sizeof(struct sockaddr_in6);
1349 cnt += sizeof(struct sockaddr_in);
1351 cnt += sizeof(struct sockaddr_in);
1357 cnt += sizeof(struct sockaddr_in6);
1369 sctp_count_max_addresses(struct sctp_inpcb *inp)
1373 SCTP_IPI_ADDR_RLOCK();
1374 /* count addresses for the endpoint's default VRF */
1375 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1376 SCTP_IPI_ADDR_RUNLOCK();
1381 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1382 size_t optsize, void *p, int delay)
1385 int creat_lock_on = 0;
1386 struct sctp_tcb *stcb = NULL;
1387 struct sockaddr *sa;
1388 unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1390 int bad_addresses = 0;
1393 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1395 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1396 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1397 /* We are already connected AND the TCP model */
1398 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1399 return (EADDRINUSE);
1401 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1402 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1403 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1406 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1407 SCTP_INP_RLOCK(inp);
1408 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1409 SCTP_INP_RUNLOCK(inp);
1412 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1415 SCTP_INP_INCR_REF(inp);
1416 SCTP_ASOC_CREATE_LOCK(inp);
1418 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1419 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1420 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1424 totaddrp = (unsigned int *)optval;
1425 totaddr = *totaddrp;
1426 sa = (struct sockaddr *)(totaddrp + 1);
1427 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (unsigned int)(optsize - sizeof(int)), &bad_addresses);
1428 if ((stcb != NULL) || bad_addresses) {
1429 /* Already have or am bring up an association */
1430 SCTP_ASOC_CREATE_UNLOCK(inp);
1433 SCTP_TCB_UNLOCK(stcb);
1434 if (bad_addresses == 0) {
1435 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1441 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1446 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1448 struct in6pcb *inp6;
1450 inp6 = (struct in6pcb *)inp;
1451 if (SCTP_IPV6_V6ONLY(inp6)) {
1453 * if IPV6_V6ONLY flag, ignore connections destined
1454 * to a v4 addr or v4-mapped addr
1456 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1462 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1463 SCTP_PCB_FLAGS_UNBOUND) {
1464 /* Bind a ephemeral port */
1465 error = sctp_inpcb_bind(so, NULL, NULL, p);
1470 /* FIX ME: do we want to pass in a vrf on the connect call? */
1471 vrf_id = inp->def_vrf_id;
1474 /* We are GOOD to go */
1475 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1476 inp->sctp_ep.pre_open_stream_count,
1481 /* Gak! no memory */
1484 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1485 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1486 /* Set the connected flag so we can queue data */
1489 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1490 /* move to second address */
1491 switch (sa->sa_family) {
1494 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1499 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1507 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1508 /* Fill in the return id */
1510 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE,
1511 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
1514 a_id = (sctp_assoc_t *) optval;
1515 *a_id = sctp_get_associd(stcb);
1517 /* initialize authentication parameters for the assoc */
1518 sctp_initialize_auth_params(inp, stcb);
1521 /* doing delayed connection */
1522 stcb->asoc.delayed_connection = 1;
1523 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1525 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1526 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1528 SCTP_TCB_UNLOCK(stcb);
1529 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1530 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1531 /* Set the connected flag so we can queue data */
1535 if (creat_lock_on) {
1536 SCTP_ASOC_CREATE_UNLOCK(inp);
1538 SCTP_INP_DECR_REF(inp);
1542 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1543 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1544 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1545 SCTP_INP_RLOCK(inp); \
1546 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1548 SCTP_TCB_LOCK(stcb); \
1550 SCTP_INP_RUNLOCK(inp); \
1551 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1552 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1553 if (stcb == NULL) { \
1554 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1564 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1565 if (size < sizeof(type)) { \
1566 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1570 destp = (type *)srcp; \
1575 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1578 struct sctp_inpcb *inp = NULL;
1580 struct sctp_tcb *stcb = NULL;
1582 if (optval == NULL) {
1583 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1586 inp = (struct sctp_inpcb *)so->so_pcb;
1588 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1595 case SCTP_AUTOCLOSE:
1596 case SCTP_EXPLICIT_EOR:
1597 case SCTP_AUTO_ASCONF:
1598 case SCTP_DISABLE_FRAGMENTS:
1599 case SCTP_I_WANT_MAPPED_V4_ADDR:
1600 case SCTP_USE_EXT_RCVINFO:
1601 SCTP_INP_RLOCK(inp);
1603 case SCTP_DISABLE_FRAGMENTS:
1604 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1606 case SCTP_I_WANT_MAPPED_V4_ADDR:
1607 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1609 case SCTP_AUTO_ASCONF:
1610 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1611 /* only valid for bound all sockets */
1612 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1614 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1619 case SCTP_EXPLICIT_EOR:
1620 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1623 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1625 case SCTP_USE_EXT_RCVINFO:
1626 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1628 case SCTP_AUTOCLOSE:
1629 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1630 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1636 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1637 error = ENOPROTOOPT;
1638 } /* end switch (sopt->sopt_name) */
1639 if (*optsize < sizeof(val)) {
1640 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1644 SCTP_INP_RUNLOCK(inp);
1646 /* return the option value */
1647 *(int *)optval = val;
1648 *optsize = sizeof(val);
1651 case SCTP_GET_PACKET_LOG:
1653 #ifdef SCTP_PACKET_LOGGING
1657 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1658 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1661 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1666 case SCTP_REUSE_PORT:
1670 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1671 /* Can't do this for a 1-m socket */
1675 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1676 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1677 *optsize = sizeof(uint32_t);
1680 case SCTP_PARTIAL_DELIVERY_POINT:
1684 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1685 *value = inp->partial_delivery_point;
1686 *optsize = sizeof(uint32_t);
1689 case SCTP_FRAGMENT_INTERLEAVE:
1693 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1694 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1695 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1696 *value = SCTP_FRAG_LEVEL_2;
1698 *value = SCTP_FRAG_LEVEL_1;
1701 *value = SCTP_FRAG_LEVEL_0;
1703 *optsize = sizeof(uint32_t);
1706 case SCTP_INTERLEAVING_SUPPORTED:
1708 struct sctp_assoc_value *av;
1710 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1711 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1714 av->assoc_value = stcb->asoc.idata_supported;
1715 SCTP_TCB_UNLOCK(stcb);
1717 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1718 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1719 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1720 SCTP_INP_RLOCK(inp);
1721 if (inp->idata_supported) {
1722 av->assoc_value = 1;
1724 av->assoc_value = 0;
1726 SCTP_INP_RUNLOCK(inp);
1728 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1733 *optsize = sizeof(struct sctp_assoc_value);
1737 case SCTP_CMT_ON_OFF:
1739 struct sctp_assoc_value *av;
1741 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1742 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1744 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1745 SCTP_TCB_UNLOCK(stcb);
1747 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1748 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1749 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1750 SCTP_INP_RLOCK(inp);
1751 av->assoc_value = inp->sctp_cmt_on_off;
1752 SCTP_INP_RUNLOCK(inp);
1754 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1759 *optsize = sizeof(struct sctp_assoc_value);
1763 case SCTP_PLUGGABLE_CC:
1765 struct sctp_assoc_value *av;
1767 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1768 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1770 av->assoc_value = stcb->asoc.congestion_control_module;
1771 SCTP_TCB_UNLOCK(stcb);
1773 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1774 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1775 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1776 SCTP_INP_RLOCK(inp);
1777 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1778 SCTP_INP_RUNLOCK(inp);
1780 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1785 *optsize = sizeof(struct sctp_assoc_value);
1789 case SCTP_CC_OPTION:
1791 struct sctp_cc_option *cc_opt;
1793 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1794 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1798 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1801 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1802 *optsize = sizeof(struct sctp_cc_option);
1804 SCTP_TCB_UNLOCK(stcb);
1808 case SCTP_PLUGGABLE_SS:
1810 struct sctp_assoc_value *av;
1812 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1813 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1815 av->assoc_value = stcb->asoc.stream_scheduling_module;
1816 SCTP_TCB_UNLOCK(stcb);
1818 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1819 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1820 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1821 SCTP_INP_RLOCK(inp);
1822 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1823 SCTP_INP_RUNLOCK(inp);
1825 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1830 *optsize = sizeof(struct sctp_assoc_value);
1836 struct sctp_stream_value *av;
1838 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1839 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1841 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1842 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1843 &av->stream_value) < 0)) {
1844 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1847 *optsize = sizeof(struct sctp_stream_value);
1849 SCTP_TCB_UNLOCK(stcb);
1852 * Can't get stream value without
1855 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1860 case SCTP_GET_ADDR_LEN:
1862 struct sctp_assoc_value *av;
1864 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1867 if (av->assoc_value == AF_INET) {
1868 av->assoc_value = sizeof(struct sockaddr_in);
1873 if (av->assoc_value == AF_INET6) {
1874 av->assoc_value = sizeof(struct sockaddr_in6);
1879 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1881 *optsize = sizeof(struct sctp_assoc_value);
1885 case SCTP_GET_ASSOC_NUMBER:
1887 uint32_t *value, cnt;
1889 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1890 SCTP_INP_RLOCK(inp);
1891 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1892 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1893 /* Can't do this for a 1-1 socket */
1895 SCTP_INP_RUNLOCK(inp);
1899 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1902 SCTP_INP_RUNLOCK(inp);
1904 *optsize = sizeof(uint32_t);
1907 case SCTP_GET_ASSOC_ID_LIST:
1909 struct sctp_assoc_ids *ids;
1913 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1914 SCTP_INP_RLOCK(inp);
1915 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1916 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1917 /* Can't do this for a 1-1 socket */
1919 SCTP_INP_RUNLOCK(inp);
1923 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1924 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1926 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1929 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1934 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1938 SCTP_INP_RUNLOCK(inp);
1940 ids->gaids_number_of_ids = at;
1941 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1947 struct sctp_assoc_value *av;
1949 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1950 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1953 av->assoc_value = stcb->asoc.context;
1954 SCTP_TCB_UNLOCK(stcb);
1956 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1957 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1958 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1959 SCTP_INP_RLOCK(inp);
1960 av->assoc_value = inp->sctp_context;
1961 SCTP_INP_RUNLOCK(inp);
1963 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1968 *optsize = sizeof(struct sctp_assoc_value);
1974 uint32_t *default_vrfid;
1976 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1977 *default_vrfid = inp->def_vrf_id;
1978 *optsize = sizeof(uint32_t);
1981 case SCTP_GET_ASOC_VRF:
1983 struct sctp_assoc_value *id;
1985 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1986 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1991 id->assoc_value = stcb->asoc.vrf_id;
1992 *optsize = sizeof(struct sctp_assoc_value);
1996 case SCTP_GET_VRF_IDS:
1998 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2002 case SCTP_GET_NONCE_VALUES:
2004 struct sctp_get_nonce_values *gnv;
2006 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2007 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2010 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2011 gnv->gn_local_tag = stcb->asoc.my_vtag;
2012 SCTP_TCB_UNLOCK(stcb);
2013 *optsize = sizeof(struct sctp_get_nonce_values);
2015 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2020 case SCTP_DELAYED_SACK:
2022 struct sctp_sack_info *sack;
2024 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2025 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2027 sack->sack_delay = stcb->asoc.delayed_ack;
2028 sack->sack_freq = stcb->asoc.sack_freq;
2029 SCTP_TCB_UNLOCK(stcb);
2031 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2032 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2033 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2034 SCTP_INP_RLOCK(inp);
2035 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2036 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2037 SCTP_INP_RUNLOCK(inp);
2039 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2044 *optsize = sizeof(struct sctp_sack_info);
2048 case SCTP_GET_SNDBUF_USE:
2050 struct sctp_sockstat *ss;
2052 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2053 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2056 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2057 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2058 stcb->asoc.size_on_all_streams);
2059 SCTP_TCB_UNLOCK(stcb);
2060 *optsize = sizeof(struct sctp_sockstat);
2062 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2067 case SCTP_MAX_BURST:
2069 struct sctp_assoc_value *av;
2071 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2072 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2075 av->assoc_value = stcb->asoc.max_burst;
2076 SCTP_TCB_UNLOCK(stcb);
2078 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2079 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2080 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2081 SCTP_INP_RLOCK(inp);
2082 av->assoc_value = inp->sctp_ep.max_burst;
2083 SCTP_INP_RUNLOCK(inp);
2085 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2090 *optsize = sizeof(struct sctp_assoc_value);
2096 struct sctp_assoc_value *av;
2099 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2100 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2103 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2104 SCTP_TCB_UNLOCK(stcb);
2106 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2107 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2108 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2109 SCTP_INP_RLOCK(inp);
2110 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2111 ovh = SCTP_MED_OVERHEAD;
2113 ovh = SCTP_MED_V4_OVERHEAD;
2115 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2116 av->assoc_value = 0;
2118 av->assoc_value = inp->sctp_frag_point - ovh;
2119 SCTP_INP_RUNLOCK(inp);
2121 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2126 *optsize = sizeof(struct sctp_assoc_value);
2130 case SCTP_GET_STAT_LOG:
2131 error = sctp_fill_stat_log(optval, optsize);
2135 struct sctp_event_subscribe *events;
2137 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2138 memset(events, 0, sizeof(struct sctp_event_subscribe));
2139 SCTP_INP_RLOCK(inp);
2140 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2141 events->sctp_data_io_event = 1;
2143 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2144 events->sctp_association_event = 1;
2146 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2147 events->sctp_address_event = 1;
2149 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2150 events->sctp_send_failure_event = 1;
2152 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2153 events->sctp_peer_error_event = 1;
2155 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2156 events->sctp_shutdown_event = 1;
2158 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2159 events->sctp_partial_delivery_event = 1;
2161 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2162 events->sctp_adaptation_layer_event = 1;
2164 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2165 events->sctp_authentication_event = 1;
2167 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2168 events->sctp_sender_dry_event = 1;
2170 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2171 events->sctp_stream_reset_event = 1;
2172 SCTP_INP_RUNLOCK(inp);
2173 *optsize = sizeof(struct sctp_event_subscribe);
2176 case SCTP_ADAPTATION_LAYER:
2180 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2182 SCTP_INP_RLOCK(inp);
2183 *value = inp->sctp_ep.adaptation_layer_indicator;
2184 SCTP_INP_RUNLOCK(inp);
2185 *optsize = sizeof(uint32_t);
2188 case SCTP_SET_INITIAL_DBG_SEQ:
2192 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2193 SCTP_INP_RLOCK(inp);
2194 *value = inp->sctp_ep.initial_sequence_debug;
2195 SCTP_INP_RUNLOCK(inp);
2196 *optsize = sizeof(uint32_t);
2199 case SCTP_GET_LOCAL_ADDR_SIZE:
2203 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2204 SCTP_INP_RLOCK(inp);
2205 *value = sctp_count_max_addresses(inp);
2206 SCTP_INP_RUNLOCK(inp);
2207 *optsize = sizeof(uint32_t);
2210 case SCTP_GET_REMOTE_ADDR_SIZE:
2214 struct sctp_nets *net;
2216 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2217 /* FIXME MT: change to sctp_assoc_value? */
2218 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2222 /* Count the sizes */
2223 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2224 switch (net->ro._l_addr.sa.sa_family) {
2228 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2229 size += sizeof(struct sockaddr_in6);
2231 size += sizeof(struct sockaddr_in);
2234 size += sizeof(struct sockaddr_in);
2240 size += sizeof(struct sockaddr_in6);
2247 SCTP_TCB_UNLOCK(stcb);
2248 *value = (uint32_t) size;
2249 *optsize = sizeof(uint32_t);
2251 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2256 case SCTP_GET_PEER_ADDRESSES:
2258 * Get the address information, an array is passed in to
2259 * fill up we pack it.
2263 struct sockaddr_storage *sas;
2264 struct sctp_nets *net;
2265 struct sctp_getaddresses *saddr;
2267 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2268 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2271 left = (*optsize) - sizeof(struct sctp_getaddresses);
2272 *optsize = sizeof(struct sctp_getaddresses);
2273 sas = (struct sockaddr_storage *)&saddr->addr[0];
2275 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2276 switch (net->ro._l_addr.sa.sa_family) {
2280 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2281 cpsz = sizeof(struct sockaddr_in6);
2283 cpsz = sizeof(struct sockaddr_in);
2286 cpsz = sizeof(struct sockaddr_in);
2292 cpsz = sizeof(struct sockaddr_in6);
2303 /* not enough room. */
2306 #if defined(INET) && defined(INET6)
2307 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2308 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2309 /* Must map the address */
2310 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2311 (struct sockaddr_in6 *)sas);
2313 memcpy(sas, &net->ro._l_addr, cpsz);
2316 memcpy(sas, &net->ro._l_addr, cpsz);
2318 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2320 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2324 SCTP_TCB_UNLOCK(stcb);
2326 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2331 case SCTP_GET_LOCAL_ADDRESSES:
2333 size_t limit, actual;
2334 struct sockaddr_storage *sas;
2335 struct sctp_getaddresses *saddr;
2337 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2338 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2340 sas = (struct sockaddr_storage *)&saddr->addr[0];
2341 limit = *optsize - sizeof(sctp_assoc_t);
2342 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2344 SCTP_TCB_UNLOCK(stcb);
2346 *optsize = sizeof(struct sockaddr_storage) + actual;
2349 case SCTP_PEER_ADDR_PARAMS:
2351 struct sctp_paddrparams *paddrp;
2352 struct sctp_nets *net;
2353 struct sockaddr *addr;
2355 #if defined(INET) && defined(INET6)
2356 struct sockaddr_in sin_store;
2360 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2361 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2363 #if defined(INET) && defined(INET6)
2364 if (paddrp->spp_address.ss_family == AF_INET6) {
2365 struct sockaddr_in6 *sin6;
2367 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2368 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2369 in6_sin6_2_sin(&sin_store, sin6);
2370 addr = (struct sockaddr *)&sin_store;
2372 addr = (struct sockaddr *)&paddrp->spp_address;
2375 addr = (struct sockaddr *)&paddrp->spp_address;
2378 addr = (struct sockaddr *)&paddrp->spp_address;
2381 net = sctp_findnet(stcb, addr);
2384 * We increment here since
2385 * sctp_findassociation_ep_addr() wil do a
2386 * decrement if it finds the stcb as long as
2387 * the locked tcb (last argument) is NOT a
2391 SCTP_INP_INCR_REF(inp);
2392 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2394 SCTP_INP_DECR_REF(inp);
2397 if ((stcb != NULL) && (net == NULL)) {
2399 if (addr->sa_family == AF_INET) {
2400 struct sockaddr_in *sin;
2402 sin = (struct sockaddr_in *)addr;
2403 if (sin->sin_addr.s_addr != INADDR_ANY) {
2405 SCTP_TCB_UNLOCK(stcb);
2406 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2412 if (addr->sa_family == AF_INET6) {
2413 struct sockaddr_in6 *sin6;
2415 sin6 = (struct sockaddr_in6 *)addr;
2416 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2418 SCTP_TCB_UNLOCK(stcb);
2419 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2425 error = EAFNOSUPPORT;
2426 SCTP_TCB_UNLOCK(stcb);
2427 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2432 /* Applies to the specific association */
2433 paddrp->spp_flags = 0;
2435 paddrp->spp_hbinterval = net->heart_beat_delay;
2436 paddrp->spp_pathmaxrxt = net->failure_threshold;
2437 paddrp->spp_pathmtu = net->mtu;
2438 switch (net->ro._l_addr.sa.sa_family) {
2441 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2446 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2452 /* get flags for HB */
2453 if (net->dest_state & SCTP_ADDR_NOHB) {
2454 paddrp->spp_flags |= SPP_HB_DISABLE;
2456 paddrp->spp_flags |= SPP_HB_ENABLE;
2458 /* get flags for PMTU */
2459 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2460 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2462 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2464 if (net->dscp & 0x01) {
2465 paddrp->spp_dscp = net->dscp & 0xfc;
2466 paddrp->spp_flags |= SPP_DSCP;
2469 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2470 (net->flowlabel & 0x80000000)) {
2471 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2472 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2477 * No destination so return default
2480 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2481 paddrp->spp_pathmtu = 0;
2482 if (stcb->asoc.default_dscp & 0x01) {
2483 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2484 paddrp->spp_flags |= SPP_DSCP;
2487 if (stcb->asoc.default_flowlabel & 0x80000000) {
2488 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2489 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2492 /* default settings should be these */
2493 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2494 paddrp->spp_flags |= SPP_HB_DISABLE;
2496 paddrp->spp_flags |= SPP_HB_ENABLE;
2498 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2499 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2501 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2503 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2505 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2506 SCTP_TCB_UNLOCK(stcb);
2508 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2509 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2510 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2511 /* Use endpoint defaults */
2512 SCTP_INP_RLOCK(inp);
2513 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2514 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2515 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2516 /* get inp's default */
2517 if (inp->sctp_ep.default_dscp & 0x01) {
2518 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2519 paddrp->spp_flags |= SPP_DSCP;
2522 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2523 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2524 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2525 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2528 /* can't return this */
2529 paddrp->spp_pathmtu = 0;
2531 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2532 paddrp->spp_flags |= SPP_HB_ENABLE;
2534 paddrp->spp_flags |= SPP_HB_DISABLE;
2536 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2537 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2539 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2541 SCTP_INP_RUNLOCK(inp);
2543 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2548 *optsize = sizeof(struct sctp_paddrparams);
2552 case SCTP_GET_PEER_ADDR_INFO:
2554 struct sctp_paddrinfo *paddri;
2555 struct sctp_nets *net;
2556 struct sockaddr *addr;
2558 #if defined(INET) && defined(INET6)
2559 struct sockaddr_in sin_store;
2563 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2564 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2566 #if defined(INET) && defined(INET6)
2567 if (paddri->spinfo_address.ss_family == AF_INET6) {
2568 struct sockaddr_in6 *sin6;
2570 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2571 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2572 in6_sin6_2_sin(&sin_store, sin6);
2573 addr = (struct sockaddr *)&sin_store;
2575 addr = (struct sockaddr *)&paddri->spinfo_address;
2578 addr = (struct sockaddr *)&paddri->spinfo_address;
2581 addr = (struct sockaddr *)&paddri->spinfo_address;
2584 net = sctp_findnet(stcb, addr);
2587 * We increment here since
2588 * sctp_findassociation_ep_addr() wil do a
2589 * decrement if it finds the stcb as long as
2590 * the locked tcb (last argument) is NOT a
2594 SCTP_INP_INCR_REF(inp);
2595 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2597 SCTP_INP_DECR_REF(inp);
2601 if ((stcb != NULL) && (net != NULL)) {
2602 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2603 /* It's unconfirmed */
2604 paddri->spinfo_state = SCTP_UNCONFIRMED;
2605 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2607 paddri->spinfo_state = SCTP_ACTIVE;
2610 paddri->spinfo_state = SCTP_INACTIVE;
2612 paddri->spinfo_cwnd = net->cwnd;
2613 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2614 paddri->spinfo_rto = net->RTO;
2615 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2616 paddri->spinfo_mtu = net->mtu;
2617 switch (addr->sa_family) {
2620 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2625 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2631 SCTP_TCB_UNLOCK(stcb);
2632 *optsize = sizeof(struct sctp_paddrinfo);
2635 SCTP_TCB_UNLOCK(stcb);
2637 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2642 case SCTP_PCB_STATUS:
2644 struct sctp_pcbinfo *spcb;
2646 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2647 sctp_fill_pcbinfo(spcb);
2648 *optsize = sizeof(struct sctp_pcbinfo);
2653 struct sctp_nets *net;
2654 struct sctp_status *sstat;
2656 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2657 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2664 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2665 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2666 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2667 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2669 * We can't include chunks that have been passed to
2670 * the socket layer. Only things in queue.
2672 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2673 stcb->asoc.cnt_on_all_streams);
2676 sstat->sstat_instrms = stcb->asoc.streamincnt;
2677 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2678 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2679 memcpy(&sstat->sstat_primary.spinfo_address,
2680 &stcb->asoc.primary_destination->ro._l_addr,
2681 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2682 net = stcb->asoc.primary_destination;
2683 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2685 * Again the user can get info from sctp_constants.h
2686 * for what the state of the network is.
2688 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2689 /* It's unconfirmed */
2690 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2691 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2693 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2696 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2698 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2699 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2700 sstat->sstat_primary.spinfo_rto = net->RTO;
2701 sstat->sstat_primary.spinfo_mtu = net->mtu;
2702 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2705 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2710 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2716 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2717 SCTP_TCB_UNLOCK(stcb);
2718 *optsize = sizeof(struct sctp_status);
2723 struct sctp_rtoinfo *srto;
2725 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2726 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2729 srto->srto_initial = stcb->asoc.initial_rto;
2730 srto->srto_max = stcb->asoc.maxrto;
2731 srto->srto_min = stcb->asoc.minrto;
2732 SCTP_TCB_UNLOCK(stcb);
2734 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2735 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2736 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2737 SCTP_INP_RLOCK(inp);
2738 srto->srto_initial = inp->sctp_ep.initial_rto;
2739 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2740 srto->srto_min = inp->sctp_ep.sctp_minrto;
2741 SCTP_INP_RUNLOCK(inp);
2743 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2748 *optsize = sizeof(struct sctp_rtoinfo);
2754 struct sctp_timeouts *stimo;
2756 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2757 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2760 stimo->stimo_init = stcb->asoc.timoinit;
2761 stimo->stimo_data = stcb->asoc.timodata;
2762 stimo->stimo_sack = stcb->asoc.timosack;
2763 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2764 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2765 stimo->stimo_cookie = stcb->asoc.timocookie;
2766 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2767 SCTP_TCB_UNLOCK(stcb);
2768 *optsize = sizeof(struct sctp_timeouts);
2770 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2775 case SCTP_ASSOCINFO:
2777 struct sctp_assocparams *sasoc;
2779 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2780 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2783 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2784 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2785 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2786 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2787 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2788 SCTP_TCB_UNLOCK(stcb);
2790 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2791 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2792 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2793 SCTP_INP_RLOCK(inp);
2794 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2795 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2796 sasoc->sasoc_number_peer_destinations = 0;
2797 sasoc->sasoc_peer_rwnd = 0;
2798 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2799 SCTP_INP_RUNLOCK(inp);
2801 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2806 *optsize = sizeof(struct sctp_assocparams);
2810 case SCTP_DEFAULT_SEND_PARAM:
2812 struct sctp_sndrcvinfo *s_info;
2814 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2815 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2818 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2819 SCTP_TCB_UNLOCK(stcb);
2821 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2822 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2823 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2824 SCTP_INP_RLOCK(inp);
2825 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2826 SCTP_INP_RUNLOCK(inp);
2828 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2833 *optsize = sizeof(struct sctp_sndrcvinfo);
2839 struct sctp_initmsg *sinit;
2841 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2842 SCTP_INP_RLOCK(inp);
2843 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2844 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2845 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2846 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2847 SCTP_INP_RUNLOCK(inp);
2848 *optsize = sizeof(struct sctp_initmsg);
2851 case SCTP_PRIMARY_ADDR:
2852 /* we allow a "get" operation on this */
2854 struct sctp_setprim *ssp;
2856 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2857 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2860 union sctp_sockstore *addr;
2862 addr = &stcb->asoc.primary_destination->ro._l_addr;
2863 switch (addr->sa.sa_family) {
2867 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2868 in6_sin_2_v4mapsin6(&addr->sin,
2869 (struct sockaddr_in6 *)&ssp->ssp_addr);
2871 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2874 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2880 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2886 SCTP_TCB_UNLOCK(stcb);
2887 *optsize = sizeof(struct sctp_setprim);
2889 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2894 case SCTP_HMAC_IDENT:
2896 struct sctp_hmacalgo *shmac;
2897 sctp_hmaclist_t *hmaclist;
2901 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2903 SCTP_INP_RLOCK(inp);
2904 hmaclist = inp->sctp_ep.local_hmacs;
2905 if (hmaclist == NULL) {
2906 /* no HMACs to return */
2907 *optsize = sizeof(*shmac);
2908 SCTP_INP_RUNLOCK(inp);
2911 /* is there room for all of the hmac ids? */
2912 size = sizeof(*shmac) + (hmaclist->num_algo *
2913 sizeof(shmac->shmac_idents[0]));
2914 if ((size_t)(*optsize) < size) {
2915 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2917 SCTP_INP_RUNLOCK(inp);
2920 /* copy in the list */
2921 shmac->shmac_number_of_idents = hmaclist->num_algo;
2922 for (i = 0; i < hmaclist->num_algo; i++) {
2923 shmac->shmac_idents[i] = hmaclist->hmac[i];
2925 SCTP_INP_RUNLOCK(inp);
2929 case SCTP_AUTH_ACTIVE_KEY:
2931 struct sctp_authkeyid *scact;
2933 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2934 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2937 /* get the active key on the assoc */
2938 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2939 SCTP_TCB_UNLOCK(stcb);
2941 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2942 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2943 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2944 /* get the endpoint active key */
2945 SCTP_INP_RLOCK(inp);
2946 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2947 SCTP_INP_RUNLOCK(inp);
2949 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2954 *optsize = sizeof(struct sctp_authkeyid);
2958 case SCTP_LOCAL_AUTH_CHUNKS:
2960 struct sctp_authchunks *sac;
2961 sctp_auth_chklist_t *chklist = NULL;
2964 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2965 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2968 /* get off the assoc */
2969 chklist = stcb->asoc.local_auth_chunks;
2970 /* is there enough space? */
2971 size = sctp_auth_get_chklist_size(chklist);
2972 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2974 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2976 /* copy in the chunks */
2977 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2978 sac->gauth_number_of_chunks = (uint32_t) size;
2979 *optsize = sizeof(struct sctp_authchunks) + size;
2981 SCTP_TCB_UNLOCK(stcb);
2983 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2984 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2985 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2986 /* get off the endpoint */
2987 SCTP_INP_RLOCK(inp);
2988 chklist = inp->sctp_ep.local_auth_chunks;
2989 /* is there enough space? */
2990 size = sctp_auth_get_chklist_size(chklist);
2991 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2993 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2995 /* copy in the chunks */
2996 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2997 sac->gauth_number_of_chunks = (uint32_t) size;
2998 *optsize = sizeof(struct sctp_authchunks) + size;
3000 SCTP_INP_RUNLOCK(inp);
3002 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3008 case SCTP_PEER_AUTH_CHUNKS:
3010 struct sctp_authchunks *sac;
3011 sctp_auth_chklist_t *chklist = NULL;
3014 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
3015 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
3018 /* get off the assoc */
3019 chklist = stcb->asoc.peer_auth_chunks;
3020 /* is there enough space? */
3021 size = sctp_auth_get_chklist_size(chklist);
3022 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
3024 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3026 /* copy in the chunks */
3027 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3028 sac->gauth_number_of_chunks = (uint32_t) size;
3029 *optsize = sizeof(struct sctp_authchunks) + size;
3031 SCTP_TCB_UNLOCK(stcb);
3033 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3040 struct sctp_event *event;
3041 uint32_t event_type;
3043 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3044 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3046 switch (event->se_type) {
3047 case SCTP_ASSOC_CHANGE:
3048 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3050 case SCTP_PEER_ADDR_CHANGE:
3051 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3053 case SCTP_REMOTE_ERROR:
3054 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3056 case SCTP_SEND_FAILED:
3057 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3059 case SCTP_SHUTDOWN_EVENT:
3060 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3062 case SCTP_ADAPTATION_INDICATION:
3063 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3065 case SCTP_PARTIAL_DELIVERY_EVENT:
3066 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3068 case SCTP_AUTHENTICATION_EVENT:
3069 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3071 case SCTP_STREAM_RESET_EVENT:
3072 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3074 case SCTP_SENDER_DRY_EVENT:
3075 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3077 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3079 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3082 case SCTP_ASSOC_RESET_EVENT:
3083 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3085 case SCTP_STREAM_CHANGE_EVENT:
3086 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3088 case SCTP_SEND_FAILED_EVENT:
3089 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3093 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3097 if (event_type > 0) {
3099 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3100 SCTP_TCB_UNLOCK(stcb);
3102 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3103 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3104 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3105 SCTP_INP_RLOCK(inp);
3106 event->se_on = sctp_is_feature_on(inp, event_type);
3107 SCTP_INP_RUNLOCK(inp);
3109 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3115 *optsize = sizeof(struct sctp_event);
3119 case SCTP_RECVRCVINFO:
3123 if (*optsize < sizeof(int)) {
3124 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3127 SCTP_INP_RLOCK(inp);
3128 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3129 SCTP_INP_RUNLOCK(inp);
3132 /* return the option value */
3133 *(int *)optval = onoff;
3134 *optsize = sizeof(int);
3138 case SCTP_RECVNXTINFO:
3142 if (*optsize < sizeof(int)) {
3143 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3146 SCTP_INP_RLOCK(inp);
3147 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3148 SCTP_INP_RUNLOCK(inp);
3151 /* return the option value */
3152 *(int *)optval = onoff;
3153 *optsize = sizeof(int);
3157 case SCTP_DEFAULT_SNDINFO:
3159 struct sctp_sndinfo *info;
3161 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3162 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3165 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3166 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3167 info->snd_flags &= 0xfff0;
3168 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3169 info->snd_context = stcb->asoc.def_send.sinfo_context;
3170 SCTP_TCB_UNLOCK(stcb);
3172 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3173 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3174 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3175 SCTP_INP_RLOCK(inp);
3176 info->snd_sid = inp->def_send.sinfo_stream;
3177 info->snd_flags = inp->def_send.sinfo_flags;
3178 info->snd_flags &= 0xfff0;
3179 info->snd_ppid = inp->def_send.sinfo_ppid;
3180 info->snd_context = inp->def_send.sinfo_context;
3181 SCTP_INP_RUNLOCK(inp);
3183 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3188 *optsize = sizeof(struct sctp_sndinfo);
3192 case SCTP_DEFAULT_PRINFO:
3194 struct sctp_default_prinfo *info;
3196 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3197 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3200 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3201 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3202 SCTP_TCB_UNLOCK(stcb);
3204 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3205 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3206 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3207 SCTP_INP_RLOCK(inp);
3208 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3209 info->pr_value = inp->def_send.sinfo_timetolive;
3210 SCTP_INP_RUNLOCK(inp);
3212 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3217 *optsize = sizeof(struct sctp_default_prinfo);
3221 case SCTP_PEER_ADDR_THLDS:
3223 struct sctp_paddrthlds *thlds;
3224 struct sctp_nets *net;
3225 struct sockaddr *addr;
3227 #if defined(INET) && defined(INET6)
3228 struct sockaddr_in sin_store;
3232 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3233 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3235 #if defined(INET) && defined(INET6)
3236 if (thlds->spt_address.ss_family == AF_INET6) {
3237 struct sockaddr_in6 *sin6;
3239 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3240 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3241 in6_sin6_2_sin(&sin_store, sin6);
3242 addr = (struct sockaddr *)&sin_store;
3244 addr = (struct sockaddr *)&thlds->spt_address;
3247 addr = (struct sockaddr *)&thlds->spt_address;
3250 addr = (struct sockaddr *)&thlds->spt_address;
3253 net = sctp_findnet(stcb, addr);
3256 * We increment here since
3257 * sctp_findassociation_ep_addr() wil do a
3258 * decrement if it finds the stcb as long as
3259 * the locked tcb (last argument) is NOT a
3263 SCTP_INP_INCR_REF(inp);
3264 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3266 SCTP_INP_DECR_REF(inp);
3269 if ((stcb != NULL) && (net == NULL)) {
3271 if (addr->sa_family == AF_INET) {
3272 struct sockaddr_in *sin;
3274 sin = (struct sockaddr_in *)addr;
3275 if (sin->sin_addr.s_addr != INADDR_ANY) {
3277 SCTP_TCB_UNLOCK(stcb);
3278 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3284 if (addr->sa_family == AF_INET6) {
3285 struct sockaddr_in6 *sin6;
3287 sin6 = (struct sockaddr_in6 *)addr;
3288 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3290 SCTP_TCB_UNLOCK(stcb);
3291 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3297 error = EAFNOSUPPORT;
3298 SCTP_TCB_UNLOCK(stcb);
3299 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3305 thlds->spt_pathmaxrxt = net->failure_threshold;
3306 thlds->spt_pathpfthld = net->pf_threshold;
3308 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3309 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3311 thlds->spt_assoc_id = sctp_get_associd(stcb);
3312 SCTP_TCB_UNLOCK(stcb);
3314 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3315 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3316 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3317 /* Use endpoint defaults */
3318 SCTP_INP_RLOCK(inp);
3319 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3320 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3321 SCTP_INP_RUNLOCK(inp);
3323 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3328 *optsize = sizeof(struct sctp_paddrthlds);
3332 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3334 struct sctp_udpencaps *encaps;
3335 struct sctp_nets *net;
3336 struct sockaddr *addr;
3338 #if defined(INET) && defined(INET6)
3339 struct sockaddr_in sin_store;
3343 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3344 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3346 #if defined(INET) && defined(INET6)
3347 if (encaps->sue_address.ss_family == AF_INET6) {
3348 struct sockaddr_in6 *sin6;
3350 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3351 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3352 in6_sin6_2_sin(&sin_store, sin6);
3353 addr = (struct sockaddr *)&sin_store;
3355 addr = (struct sockaddr *)&encaps->sue_address;
3358 addr = (struct sockaddr *)&encaps->sue_address;
3361 addr = (struct sockaddr *)&encaps->sue_address;
3364 net = sctp_findnet(stcb, addr);
3367 * We increment here since
3368 * sctp_findassociation_ep_addr() wil do a
3369 * decrement if it finds the stcb as long as
3370 * the locked tcb (last argument) is NOT a
3374 SCTP_INP_INCR_REF(inp);
3375 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3377 SCTP_INP_DECR_REF(inp);
3380 if ((stcb != NULL) && (net == NULL)) {
3382 if (addr->sa_family == AF_INET) {
3383 struct sockaddr_in *sin;
3385 sin = (struct sockaddr_in *)addr;
3386 if (sin->sin_addr.s_addr != INADDR_ANY) {
3388 SCTP_TCB_UNLOCK(stcb);
3389 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3395 if (addr->sa_family == AF_INET6) {
3396 struct sockaddr_in6 *sin6;
3398 sin6 = (struct sockaddr_in6 *)addr;
3399 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3401 SCTP_TCB_UNLOCK(stcb);
3402 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3408 error = EAFNOSUPPORT;
3409 SCTP_TCB_UNLOCK(stcb);
3410 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3416 encaps->sue_port = net->port;
3418 encaps->sue_port = stcb->asoc.port;
3420 SCTP_TCB_UNLOCK(stcb);
3422 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3423 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3424 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3425 SCTP_INP_RLOCK(inp);
3426 encaps->sue_port = inp->sctp_ep.port;
3427 SCTP_INP_RUNLOCK(inp);
3429 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3434 *optsize = sizeof(struct sctp_udpencaps);
3438 case SCTP_ECN_SUPPORTED:
3440 struct sctp_assoc_value *av;
3442 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3443 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3446 av->assoc_value = stcb->asoc.ecn_supported;
3447 SCTP_TCB_UNLOCK(stcb);
3449 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3450 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3451 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3452 SCTP_INP_RLOCK(inp);
3453 av->assoc_value = inp->ecn_supported;
3454 SCTP_INP_RUNLOCK(inp);
3456 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3461 *optsize = sizeof(struct sctp_assoc_value);
3465 case SCTP_PR_SUPPORTED:
3467 struct sctp_assoc_value *av;
3469 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3470 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3473 av->assoc_value = stcb->asoc.prsctp_supported;
3474 SCTP_TCB_UNLOCK(stcb);
3476 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3477 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3478 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3479 SCTP_INP_RLOCK(inp);
3480 av->assoc_value = inp->prsctp_supported;
3481 SCTP_INP_RUNLOCK(inp);
3483 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3488 *optsize = sizeof(struct sctp_assoc_value);
3492 case SCTP_AUTH_SUPPORTED:
3494 struct sctp_assoc_value *av;
3496 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3497 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3500 av->assoc_value = stcb->asoc.auth_supported;
3501 SCTP_TCB_UNLOCK(stcb);
3503 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3504 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3505 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3506 SCTP_INP_RLOCK(inp);
3507 av->assoc_value = inp->auth_supported;
3508 SCTP_INP_RUNLOCK(inp);
3510 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3515 *optsize = sizeof(struct sctp_assoc_value);
3519 case SCTP_ASCONF_SUPPORTED:
3521 struct sctp_assoc_value *av;
3523 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3524 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3527 av->assoc_value = stcb->asoc.asconf_supported;
3528 SCTP_TCB_UNLOCK(stcb);
3530 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3531 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3532 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3533 SCTP_INP_RLOCK(inp);
3534 av->assoc_value = inp->asconf_supported;
3535 SCTP_INP_RUNLOCK(inp);
3537 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3542 *optsize = sizeof(struct sctp_assoc_value);
3546 case SCTP_RECONFIG_SUPPORTED:
3548 struct sctp_assoc_value *av;
3550 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3551 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3554 av->assoc_value = stcb->asoc.reconfig_supported;
3555 SCTP_TCB_UNLOCK(stcb);
3557 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3558 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3559 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3560 SCTP_INP_RLOCK(inp);
3561 av->assoc_value = inp->reconfig_supported;
3562 SCTP_INP_RUNLOCK(inp);
3564 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3569 *optsize = sizeof(struct sctp_assoc_value);
3573 case SCTP_NRSACK_SUPPORTED:
3575 struct sctp_assoc_value *av;
3577 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3578 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3581 av->assoc_value = stcb->asoc.nrsack_supported;
3582 SCTP_TCB_UNLOCK(stcb);
3584 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3585 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3586 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3587 SCTP_INP_RLOCK(inp);
3588 av->assoc_value = inp->nrsack_supported;
3589 SCTP_INP_RUNLOCK(inp);
3591 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3596 *optsize = sizeof(struct sctp_assoc_value);
3600 case SCTP_PKTDROP_SUPPORTED:
3602 struct sctp_assoc_value *av;
3604 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3605 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3608 av->assoc_value = stcb->asoc.pktdrop_supported;
3609 SCTP_TCB_UNLOCK(stcb);
3611 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3612 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3613 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3614 SCTP_INP_RLOCK(inp);
3615 av->assoc_value = inp->pktdrop_supported;
3616 SCTP_INP_RUNLOCK(inp);
3618 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3623 *optsize = sizeof(struct sctp_assoc_value);
3627 case SCTP_ENABLE_STREAM_RESET:
3629 struct sctp_assoc_value *av;
3631 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3632 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3635 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3636 SCTP_TCB_UNLOCK(stcb);
3638 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3639 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3640 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3641 SCTP_INP_RLOCK(inp);
3642 av->assoc_value = (uint32_t) inp->local_strreset_support;
3643 SCTP_INP_RUNLOCK(inp);
3645 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3650 *optsize = sizeof(struct sctp_assoc_value);
3654 case SCTP_PR_STREAM_STATUS:
3656 struct sctp_prstatus *sprstat;
3660 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3661 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3663 sid = sprstat->sprstat_sid;
3664 policy = sprstat->sprstat_policy;
3665 #if defined(SCTP_DETAILED_STR_STATS)
3666 if ((stcb != NULL) &&
3667 (sid < stcb->asoc.streamoutcnt) &&
3668 (policy != SCTP_PR_SCTP_NONE) &&
3669 ((policy <= SCTP_PR_SCTP_MAX) ||
3670 (policy == SCTP_PR_SCTP_ALL))) {
3671 if (policy == SCTP_PR_SCTP_ALL) {
3672 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3673 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3675 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3676 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3679 if ((stcb != NULL) &&
3680 (sid < stcb->asoc.streamoutcnt) &&
3681 (policy == SCTP_PR_SCTP_ALL)) {
3682 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3683 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3685 SCTP_TCB_UNLOCK(stcb);
3686 *optsize = sizeof(struct sctp_prstatus);
3688 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3693 case SCTP_PR_ASSOC_STATUS:
3695 struct sctp_prstatus *sprstat;
3698 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3699 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3701 policy = sprstat->sprstat_policy;
3702 if ((stcb != NULL) &&
3703 (policy != SCTP_PR_SCTP_NONE) &&
3704 ((policy <= SCTP_PR_SCTP_MAX) ||
3705 (policy == SCTP_PR_SCTP_ALL))) {
3706 if (policy == SCTP_PR_SCTP_ALL) {
3707 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3708 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3710 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3711 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3713 SCTP_TCB_UNLOCK(stcb);
3714 *optsize = sizeof(struct sctp_prstatus);
3716 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3723 struct sctp_assoc_value *av;
3725 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3726 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3729 av->assoc_value = stcb->asoc.max_cwnd;
3730 SCTP_TCB_UNLOCK(stcb);
3732 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3733 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3734 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3735 SCTP_INP_RLOCK(inp);
3736 av->assoc_value = inp->max_cwnd;
3737 SCTP_INP_RUNLOCK(inp);
3739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3744 *optsize = sizeof(struct sctp_assoc_value);
3749 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3750 error = ENOPROTOOPT;
3752 } /* end switch (sopt->sopt_name) */
3760 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3765 struct sctp_tcb *stcb = NULL;
3766 struct sctp_inpcb *inp = NULL;
3769 if (optval == NULL) {
3770 SCTP_PRINTF("optval is NULL\n");
3771 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3774 inp = (struct sctp_inpcb *)so->so_pcb;
3776 SCTP_PRINTF("inp is NULL?\n");
3777 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3780 vrf_id = inp->def_vrf_id;
3785 case SCTP_AUTOCLOSE:
3786 case SCTP_AUTO_ASCONF:
3787 case SCTP_EXPLICIT_EOR:
3788 case SCTP_DISABLE_FRAGMENTS:
3789 case SCTP_USE_EXT_RCVINFO:
3790 case SCTP_I_WANT_MAPPED_V4_ADDR:
3791 /* copy in the option value */
3792 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3797 case SCTP_DISABLE_FRAGMENTS:
3798 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3800 case SCTP_AUTO_ASCONF:
3802 * NOTE: we don't really support this flag
3804 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3805 /* only valid for bound all sockets */
3806 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3808 /* forbidden by admin */
3809 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3812 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3814 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3818 case SCTP_EXPLICIT_EOR:
3819 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3821 case SCTP_USE_EXT_RCVINFO:
3822 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3824 case SCTP_I_WANT_MAPPED_V4_ADDR:
3825 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3826 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3828 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3833 set_opt = SCTP_PCB_FLAGS_NODELAY;
3835 case SCTP_AUTOCLOSE:
3836 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3837 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3838 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3841 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3843 * The value is in ticks. Note this does not effect
3844 * old associations, only new ones.
3846 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3849 SCTP_INP_WLOCK(inp);
3851 sctp_feature_on(inp, set_opt);
3853 sctp_feature_off(inp, set_opt);
3855 SCTP_INP_WUNLOCK(inp);
3857 case SCTP_REUSE_PORT:
3859 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3860 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3861 /* Can't set it after we are bound */
3865 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3866 /* Can't do this for a 1-m socket */
3871 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3873 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3876 case SCTP_PARTIAL_DELIVERY_POINT:
3880 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3881 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3886 inp->partial_delivery_point = *value;
3889 case SCTP_FRAGMENT_INTERLEAVE:
3890 /* not yet until we re-write sctp_recvmsg() */
3894 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3895 if (*level == SCTP_FRAG_LEVEL_2) {
3896 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3897 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3898 } else if (*level == SCTP_FRAG_LEVEL_1) {
3899 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3900 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3901 } else if (*level == SCTP_FRAG_LEVEL_0) {
3902 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3903 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3906 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3911 case SCTP_INTERLEAVING_SUPPORTED:
3913 struct sctp_assoc_value *av;
3915 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3916 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3919 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3921 SCTP_TCB_UNLOCK(stcb);
3923 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3924 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3925 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3926 SCTP_INP_WLOCK(inp);
3927 if (av->assoc_value == 0) {
3928 inp->idata_supported = 0;
3930 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3931 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3932 inp->idata_supported = 1;
3940 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3944 SCTP_INP_WUNLOCK(inp);
3946 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3952 case SCTP_CMT_ON_OFF:
3953 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3954 struct sctp_assoc_value *av;
3956 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3957 if (av->assoc_value > SCTP_CMT_MAX) {
3958 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3962 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3964 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3965 SCTP_TCB_UNLOCK(stcb);
3967 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3968 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3969 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3970 (av->assoc_id == SCTP_ALL_ASSOC)) {
3971 SCTP_INP_WLOCK(inp);
3972 inp->sctp_cmt_on_off = av->assoc_value;
3973 SCTP_INP_WUNLOCK(inp);
3975 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3976 (av->assoc_id == SCTP_ALL_ASSOC)) {
3977 SCTP_INP_RLOCK(inp);
3978 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3979 SCTP_TCB_LOCK(stcb);
3980 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3981 SCTP_TCB_UNLOCK(stcb);
3983 SCTP_INP_RUNLOCK(inp);
3987 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3988 error = ENOPROTOOPT;
3991 case SCTP_PLUGGABLE_CC:
3993 struct sctp_assoc_value *av;
3994 struct sctp_nets *net;
3996 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3997 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3998 (av->assoc_value != SCTP_CC_HSTCP) &&
3999 (av->assoc_value != SCTP_CC_HTCP) &&
4000 (av->assoc_value != SCTP_CC_RTCC)) {
4001 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4005 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4007 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4008 stcb->asoc.congestion_control_module = av->assoc_value;
4009 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4010 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4011 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4014 SCTP_TCB_UNLOCK(stcb);
4016 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4017 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4018 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4019 (av->assoc_id == SCTP_ALL_ASSOC)) {
4020 SCTP_INP_WLOCK(inp);
4021 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
4022 SCTP_INP_WUNLOCK(inp);
4024 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4025 (av->assoc_id == SCTP_ALL_ASSOC)) {
4026 SCTP_INP_RLOCK(inp);
4027 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4028 SCTP_TCB_LOCK(stcb);
4029 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4030 stcb->asoc.congestion_control_module = av->assoc_value;
4031 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4032 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4033 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4036 SCTP_TCB_UNLOCK(stcb);
4038 SCTP_INP_RUNLOCK(inp);
4043 case SCTP_CC_OPTION:
4045 struct sctp_cc_option *cc_opt;
4047 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4048 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4050 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4051 SCTP_INP_RLOCK(inp);
4052 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4053 SCTP_TCB_LOCK(stcb);
4054 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4055 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4057 SCTP_TCB_UNLOCK(stcb);
4059 SCTP_INP_RUNLOCK(inp);
4064 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4067 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4070 SCTP_TCB_UNLOCK(stcb);
4074 case SCTP_PLUGGABLE_SS:
4076 struct sctp_assoc_value *av;
4078 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4079 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4080 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4081 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4082 (av->assoc_value != SCTP_SS_PRIORITY) &&
4083 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4084 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4085 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4089 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4091 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4092 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4093 stcb->asoc.stream_scheduling_module = av->assoc_value;
4094 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4095 SCTP_TCB_UNLOCK(stcb);
4097 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4098 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4099 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4100 (av->assoc_id == SCTP_ALL_ASSOC)) {
4101 SCTP_INP_WLOCK(inp);
4102 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4103 SCTP_INP_WUNLOCK(inp);
4105 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4106 (av->assoc_id == SCTP_ALL_ASSOC)) {
4107 SCTP_INP_RLOCK(inp);
4108 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4109 SCTP_TCB_LOCK(stcb);
4110 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4111 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4112 stcb->asoc.stream_scheduling_module = av->assoc_value;
4113 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4114 SCTP_TCB_UNLOCK(stcb);
4116 SCTP_INP_RUNLOCK(inp);
4123 struct sctp_stream_value *av;
4125 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4126 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4128 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4129 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4130 av->stream_value) < 0)) {
4131 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4134 SCTP_TCB_UNLOCK(stcb);
4136 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4137 SCTP_INP_RLOCK(inp);
4138 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4139 SCTP_TCB_LOCK(stcb);
4140 if (av->stream_id < stcb->asoc.streamoutcnt) {
4141 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4143 &stcb->asoc.strmout[av->stream_id],
4146 SCTP_TCB_UNLOCK(stcb);
4148 SCTP_INP_RUNLOCK(inp);
4151 * Can't set stream value without
4154 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4160 case SCTP_CLR_STAT_LOG:
4161 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4166 struct sctp_assoc_value *av;
4168 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4169 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4172 stcb->asoc.context = av->assoc_value;
4173 SCTP_TCB_UNLOCK(stcb);
4175 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4176 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4177 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4178 (av->assoc_id == SCTP_ALL_ASSOC)) {
4179 SCTP_INP_WLOCK(inp);
4180 inp->sctp_context = av->assoc_value;
4181 SCTP_INP_WUNLOCK(inp);
4183 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4184 (av->assoc_id == SCTP_ALL_ASSOC)) {
4185 SCTP_INP_RLOCK(inp);
4186 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4187 SCTP_TCB_LOCK(stcb);
4188 stcb->asoc.context = av->assoc_value;
4189 SCTP_TCB_UNLOCK(stcb);
4191 SCTP_INP_RUNLOCK(inp);
4198 uint32_t *default_vrfid;
4200 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4201 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4202 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4206 inp->def_vrf_id = *default_vrfid;
4209 case SCTP_DEL_VRF_ID:
4211 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4215 case SCTP_ADD_VRF_ID:
4217 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4221 case SCTP_DELAYED_SACK:
4223 struct sctp_sack_info *sack;
4225 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4226 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4227 if (sack->sack_delay) {
4228 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4229 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4230 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4231 sack->sack_delay = TICKS_TO_MSEC(1);
4235 if (sack->sack_delay) {
4236 stcb->asoc.delayed_ack = sack->sack_delay;
4238 if (sack->sack_freq) {
4239 stcb->asoc.sack_freq = sack->sack_freq;
4241 SCTP_TCB_UNLOCK(stcb);
4243 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4244 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4245 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4246 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4247 SCTP_INP_WLOCK(inp);
4248 if (sack->sack_delay) {
4249 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4251 if (sack->sack_freq) {
4252 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4254 SCTP_INP_WUNLOCK(inp);
4256 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4257 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4258 SCTP_INP_RLOCK(inp);
4259 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4260 SCTP_TCB_LOCK(stcb);
4261 if (sack->sack_delay) {
4262 stcb->asoc.delayed_ack = sack->sack_delay;
4264 if (sack->sack_freq) {
4265 stcb->asoc.sack_freq = sack->sack_freq;
4267 SCTP_TCB_UNLOCK(stcb);
4269 SCTP_INP_RUNLOCK(inp);
4274 case SCTP_AUTH_CHUNK:
4276 struct sctp_authchunk *sauth;
4278 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4280 SCTP_INP_WLOCK(inp);
4281 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4282 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4285 SCTP_INP_WUNLOCK(inp);
4290 struct sctp_authkey *sca;
4291 struct sctp_keyhead *shared_keys;
4292 sctp_sharedkey_t *shared_key;
4293 sctp_key_t *key = NULL;
4296 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4297 if (sca->sca_keylength == 0) {
4298 size = optsize - sizeof(struct sctp_authkey);
4300 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4301 size = sca->sca_keylength;
4303 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4308 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4311 shared_keys = &stcb->asoc.shared_keys;
4312 /* clear the cached keys for this key id */
4313 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4315 * create the new shared key and
4319 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4321 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4323 SCTP_TCB_UNLOCK(stcb);
4327 shared_key = sctp_alloc_sharedkey();
4328 if (shared_key == NULL) {
4330 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4332 SCTP_TCB_UNLOCK(stcb);
4335 shared_key->key = key;
4336 shared_key->keyid = sca->sca_keynumber;
4337 error = sctp_insert_sharedkey(shared_keys, shared_key);
4338 SCTP_TCB_UNLOCK(stcb);
4340 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4341 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4342 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4343 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4344 SCTP_INP_WLOCK(inp);
4345 shared_keys = &inp->sctp_ep.shared_keys;
4347 * clear the cached keys on all
4348 * assocs for this key id
4350 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4352 * create the new shared key and
4356 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4358 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4360 SCTP_INP_WUNLOCK(inp);
4364 shared_key = sctp_alloc_sharedkey();
4365 if (shared_key == NULL) {
4367 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4369 SCTP_INP_WUNLOCK(inp);
4372 shared_key->key = key;
4373 shared_key->keyid = sca->sca_keynumber;
4374 error = sctp_insert_sharedkey(shared_keys, shared_key);
4375 SCTP_INP_WUNLOCK(inp);
4377 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4378 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4379 SCTP_INP_RLOCK(inp);
4380 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4381 SCTP_TCB_LOCK(stcb);
4382 shared_keys = &stcb->asoc.shared_keys;
4384 * clear the cached keys for
4387 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4389 * create the new shared key
4390 * and insert/replace it
4393 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4395 SCTP_TCB_UNLOCK(stcb);
4399 shared_key = sctp_alloc_sharedkey();
4400 if (shared_key == NULL) {
4402 SCTP_TCB_UNLOCK(stcb);
4405 shared_key->key = key;
4406 shared_key->keyid = sca->sca_keynumber;
4407 error = sctp_insert_sharedkey(shared_keys, shared_key);
4408 SCTP_TCB_UNLOCK(stcb);
4410 SCTP_INP_RUNLOCK(inp);
4415 case SCTP_HMAC_IDENT:
4417 struct sctp_hmacalgo *shmac;
4418 sctp_hmaclist_t *hmaclist;
4422 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4423 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4424 (shmac->shmac_number_of_idents > 0xffff)) {
4425 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4429 hmaclist = sctp_alloc_hmaclist((uint16_t) shmac->shmac_number_of_idents);
4430 if (hmaclist == NULL) {
4431 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4435 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4436 hmacid = shmac->shmac_idents[i];
4437 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4438 /* invalid HMACs were found */ ;
4439 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4441 sctp_free_hmaclist(hmaclist);
4442 goto sctp_set_hmac_done;
4445 for (i = 0; i < hmaclist->num_algo; i++) {
4446 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4447 /* already in list */
4451 if (i == hmaclist->num_algo) {
4452 /* not found in list */
4453 sctp_free_hmaclist(hmaclist);
4454 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4458 /* set it on the endpoint */
4459 SCTP_INP_WLOCK(inp);
4460 if (inp->sctp_ep.local_hmacs)
4461 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4462 inp->sctp_ep.local_hmacs = hmaclist;
4463 SCTP_INP_WUNLOCK(inp);
4467 case SCTP_AUTH_ACTIVE_KEY:
4469 struct sctp_authkeyid *scact;
4471 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4472 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4474 /* set the active key on the right place */
4476 /* set the active key on the assoc */
4477 if (sctp_auth_setactivekey(stcb,
4478 scact->scact_keynumber)) {
4479 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4480 SCTP_FROM_SCTP_USRREQ,
4484 SCTP_TCB_UNLOCK(stcb);
4486 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4487 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4488 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4489 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4490 SCTP_INP_WLOCK(inp);
4491 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4492 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4495 SCTP_INP_WUNLOCK(inp);
4497 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4498 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4499 SCTP_INP_RLOCK(inp);
4500 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4501 SCTP_TCB_LOCK(stcb);
4502 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4503 SCTP_TCB_UNLOCK(stcb);
4505 SCTP_INP_RUNLOCK(inp);
4510 case SCTP_AUTH_DELETE_KEY:
4512 struct sctp_authkeyid *scdel;
4514 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4515 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4517 /* delete the key from the right place */
4519 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4520 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4523 SCTP_TCB_UNLOCK(stcb);
4525 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4526 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4527 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4528 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4529 SCTP_INP_WLOCK(inp);
4530 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4531 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4534 SCTP_INP_WUNLOCK(inp);
4536 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4537 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4538 SCTP_INP_RLOCK(inp);
4539 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4540 SCTP_TCB_LOCK(stcb);
4541 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4542 SCTP_TCB_UNLOCK(stcb);
4544 SCTP_INP_RUNLOCK(inp);
4549 case SCTP_AUTH_DEACTIVATE_KEY:
4551 struct sctp_authkeyid *keyid;
4553 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4554 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4556 /* deactivate the key from the right place */
4558 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4559 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4562 SCTP_TCB_UNLOCK(stcb);
4564 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4565 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4566 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4567 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4568 SCTP_INP_WLOCK(inp);
4569 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4570 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4573 SCTP_INP_WUNLOCK(inp);
4575 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4576 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4577 SCTP_INP_RLOCK(inp);
4578 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4579 SCTP_TCB_LOCK(stcb);
4580 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4581 SCTP_TCB_UNLOCK(stcb);
4583 SCTP_INP_RUNLOCK(inp);
4588 case SCTP_ENABLE_STREAM_RESET:
4590 struct sctp_assoc_value *av;
4592 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4593 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4598 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4600 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4601 SCTP_TCB_UNLOCK(stcb);
4603 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4604 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4605 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4606 (av->assoc_id == SCTP_ALL_ASSOC)) {
4607 SCTP_INP_WLOCK(inp);
4608 inp->local_strreset_support = (uint8_t) av->assoc_value;
4609 SCTP_INP_WUNLOCK(inp);
4611 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4612 (av->assoc_id == SCTP_ALL_ASSOC)) {
4613 SCTP_INP_RLOCK(inp);
4614 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4615 SCTP_TCB_LOCK(stcb);
4616 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4617 SCTP_TCB_UNLOCK(stcb);
4619 SCTP_INP_RUNLOCK(inp);
4624 case SCTP_RESET_STREAMS:
4626 struct sctp_reset_streams *strrst;
4627 int i, send_out = 0;
4630 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4631 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4633 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4637 if (stcb->asoc.reconfig_supported == 0) {
4639 * Peer does not support the chunk type.
4641 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4643 SCTP_TCB_UNLOCK(stcb);
4646 if (sizeof(struct sctp_reset_streams) +
4647 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4649 SCTP_TCB_UNLOCK(stcb);
4652 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4654 if (stcb->asoc.stream_reset_outstanding) {
4655 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4657 SCTP_TCB_UNLOCK(stcb);
4661 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4664 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4665 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4667 SCTP_TCB_UNLOCK(stcb);
4670 if ((send_in == 0) && (send_out == 0)) {
4671 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4673 SCTP_TCB_UNLOCK(stcb);
4676 for (i = 0; i < strrst->srs_number_streams; i++) {
4678 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4679 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4684 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4691 SCTP_TCB_UNLOCK(stcb);
4698 if (strrst->srs_number_streams) {
4699 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4700 strm = strrst->srs_stream_list[i];
4701 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4702 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4708 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4709 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4710 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4717 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4718 strrst->srs_stream_list,
4719 send_in, 0, 0, 0, 0, 0);
4721 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4724 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4727 * For outgoing streams don't report any
4728 * problems in sending the request to the
4729 * application. XXX: Double check resetting
4734 SCTP_TCB_UNLOCK(stcb);
4737 case SCTP_ADD_STREAMS:
4739 struct sctp_add_streams *stradd;
4740 uint8_t addstream = 0;
4741 uint16_t add_o_strmcnt = 0;
4742 uint16_t add_i_strmcnt = 0;
4744 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4745 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4747 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4751 if (stcb->asoc.reconfig_supported == 0) {
4753 * Peer does not support the chunk type.
4755 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4757 SCTP_TCB_UNLOCK(stcb);
4760 if (stcb->asoc.stream_reset_outstanding) {
4761 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4763 SCTP_TCB_UNLOCK(stcb);
4766 if ((stradd->sas_outstrms == 0) &&
4767 (stradd->sas_instrms == 0)) {
4771 if (stradd->sas_outstrms) {
4773 /* We allocate here */
4774 add_o_strmcnt = stradd->sas_outstrms;
4775 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4776 /* You can't have more than 64k */
4781 if (stradd->sas_instrms) {
4786 * We allocate inside
4787 * sctp_send_str_reset_req()
4789 add_i_strmcnt = stradd->sas_instrms;
4790 cnt = add_i_strmcnt;
4791 cnt += stcb->asoc.streamincnt;
4792 if (cnt > 0x0000ffff) {
4793 /* You can't have more than 64k */
4797 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4798 /* More than you are allowed */
4803 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4804 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4806 SCTP_TCB_UNLOCK(stcb);
4809 case SCTP_RESET_ASSOC:
4814 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4815 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4817 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4821 if (stcb->asoc.reconfig_supported == 0) {
4823 * Peer does not support the chunk type.
4825 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4827 SCTP_TCB_UNLOCK(stcb);
4830 if (stcb->asoc.stream_reset_outstanding) {
4831 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4833 SCTP_TCB_UNLOCK(stcb);
4837 * Is there any data pending in the send or sent
4840 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4841 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4844 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4845 SCTP_TCB_UNLOCK(stcb);
4848 /* Do any streams have data queued? */
4849 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4850 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4854 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4855 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4856 SCTP_TCB_UNLOCK(stcb);
4859 case SCTP_CONNECT_X:
4860 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4861 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4865 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4867 case SCTP_CONNECT_X_DELAYED:
4868 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4873 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4875 case SCTP_CONNECT_X_COMPLETE:
4877 struct sockaddr *sa;
4879 /* FIXME MT: check correct? */
4880 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4883 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4884 SCTP_INP_RLOCK(inp);
4885 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4887 SCTP_TCB_LOCK(stcb);
4889 SCTP_INP_RUNLOCK(inp);
4892 * We increment here since
4893 * sctp_findassociation_ep_addr() wil do a
4894 * decrement if it finds the stcb as long as
4895 * the locked tcb (last argument) is NOT a
4898 SCTP_INP_INCR_REF(inp);
4899 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4901 SCTP_INP_DECR_REF(inp);
4906 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4910 if (stcb->asoc.delayed_connection == 1) {
4911 stcb->asoc.delayed_connection = 0;
4912 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4913 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4914 stcb->asoc.primary_destination,
4915 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4916 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4919 * already expired or did not use delayed
4922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4925 SCTP_TCB_UNLOCK(stcb);
4928 case SCTP_MAX_BURST:
4930 struct sctp_assoc_value *av;
4932 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4933 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4936 stcb->asoc.max_burst = av->assoc_value;
4937 SCTP_TCB_UNLOCK(stcb);
4939 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4940 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4941 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4942 (av->assoc_id == SCTP_ALL_ASSOC)) {
4943 SCTP_INP_WLOCK(inp);
4944 inp->sctp_ep.max_burst = av->assoc_value;
4945 SCTP_INP_WUNLOCK(inp);
4947 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4948 (av->assoc_id == SCTP_ALL_ASSOC)) {
4949 SCTP_INP_RLOCK(inp);
4950 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4951 SCTP_TCB_LOCK(stcb);
4952 stcb->asoc.max_burst = av->assoc_value;
4953 SCTP_TCB_UNLOCK(stcb);
4955 SCTP_INP_RUNLOCK(inp);
4962 struct sctp_assoc_value *av;
4965 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4966 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4968 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4969 ovh = SCTP_MED_OVERHEAD;
4971 ovh = SCTP_MED_V4_OVERHEAD;
4974 if (av->assoc_value) {
4975 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4977 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4979 SCTP_TCB_UNLOCK(stcb);
4981 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4982 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4983 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4984 SCTP_INP_WLOCK(inp);
4986 * FIXME MT: I think this is not in
4987 * tune with the API ID
4989 if (av->assoc_value) {
4990 inp->sctp_frag_point = (av->assoc_value + ovh);
4992 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4994 SCTP_INP_WUNLOCK(inp);
4996 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5004 struct sctp_event_subscribe *events;
5006 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5008 SCTP_INP_WLOCK(inp);
5009 if (events->sctp_data_io_event) {
5010 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5012 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5015 if (events->sctp_association_event) {
5016 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5018 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5021 if (events->sctp_address_event) {
5022 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5024 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5027 if (events->sctp_send_failure_event) {
5028 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5030 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5033 if (events->sctp_peer_error_event) {
5034 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5036 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5039 if (events->sctp_shutdown_event) {
5040 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5042 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5045 if (events->sctp_partial_delivery_event) {
5046 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5048 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5051 if (events->sctp_adaptation_layer_event) {
5052 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5054 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5057 if (events->sctp_authentication_event) {
5058 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5060 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5063 if (events->sctp_sender_dry_event) {
5064 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5066 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5069 if (events->sctp_stream_reset_event) {
5070 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5072 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5074 SCTP_INP_WUNLOCK(inp);
5076 SCTP_INP_RLOCK(inp);
5077 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5078 SCTP_TCB_LOCK(stcb);
5079 if (events->sctp_association_event) {
5080 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5082 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5084 if (events->sctp_address_event) {
5085 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5087 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5089 if (events->sctp_send_failure_event) {
5090 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5092 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5094 if (events->sctp_peer_error_event) {
5095 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5097 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5099 if (events->sctp_shutdown_event) {
5100 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5102 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5104 if (events->sctp_partial_delivery_event) {
5105 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5107 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5109 if (events->sctp_adaptation_layer_event) {
5110 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5112 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5114 if (events->sctp_authentication_event) {
5115 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5117 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5119 if (events->sctp_sender_dry_event) {
5120 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5122 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5124 if (events->sctp_stream_reset_event) {
5125 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5127 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5129 SCTP_TCB_UNLOCK(stcb);
5132 * Send up the sender dry event only for 1-to-1
5135 if (events->sctp_sender_dry_event) {
5136 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5137 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5138 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5140 SCTP_TCB_LOCK(stcb);
5141 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5142 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5143 (stcb->asoc.stream_queue_cnt == 0)) {
5144 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5146 SCTP_TCB_UNLOCK(stcb);
5150 SCTP_INP_RUNLOCK(inp);
5153 case SCTP_ADAPTATION_LAYER:
5155 struct sctp_setadaptation *adap_bits;
5157 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5158 SCTP_INP_WLOCK(inp);
5159 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5160 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5161 SCTP_INP_WUNLOCK(inp);
5165 case SCTP_SET_INITIAL_DBG_SEQ:
5169 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5170 SCTP_INP_WLOCK(inp);
5171 inp->sctp_ep.initial_sequence_debug = *vvv;
5172 SCTP_INP_WUNLOCK(inp);
5176 case SCTP_DEFAULT_SEND_PARAM:
5178 struct sctp_sndrcvinfo *s_info;
5180 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5181 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5184 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5185 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5187 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5190 SCTP_TCB_UNLOCK(stcb);
5192 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5193 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5194 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5195 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5196 SCTP_INP_WLOCK(inp);
5197 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5198 SCTP_INP_WUNLOCK(inp);
5200 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5201 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5202 SCTP_INP_RLOCK(inp);
5203 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5204 SCTP_TCB_LOCK(stcb);
5205 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5206 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5208 SCTP_TCB_UNLOCK(stcb);
5210 SCTP_INP_RUNLOCK(inp);
5215 case SCTP_PEER_ADDR_PARAMS:
5217 struct sctp_paddrparams *paddrp;
5218 struct sctp_nets *net;
5219 struct sockaddr *addr;
5221 #if defined(INET) && defined(INET6)
5222 struct sockaddr_in sin_store;
5226 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5227 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5229 #if defined(INET) && defined(INET6)
5230 if (paddrp->spp_address.ss_family == AF_INET6) {
5231 struct sockaddr_in6 *sin6;
5233 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5234 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5235 in6_sin6_2_sin(&sin_store, sin6);
5236 addr = (struct sockaddr *)&sin_store;
5238 addr = (struct sockaddr *)&paddrp->spp_address;
5241 addr = (struct sockaddr *)&paddrp->spp_address;
5244 addr = (struct sockaddr *)&paddrp->spp_address;
5247 net = sctp_findnet(stcb, addr);
5250 * We increment here since
5251 * sctp_findassociation_ep_addr() wil do a
5252 * decrement if it finds the stcb as long as
5253 * the locked tcb (last argument) is NOT a
5257 SCTP_INP_INCR_REF(inp);
5258 stcb = sctp_findassociation_ep_addr(&inp, addr,
5261 SCTP_INP_DECR_REF(inp);
5264 if ((stcb != NULL) && (net == NULL)) {
5266 if (addr->sa_family == AF_INET) {
5268 struct sockaddr_in *sin;
5270 sin = (struct sockaddr_in *)addr;
5271 if (sin->sin_addr.s_addr != INADDR_ANY) {
5272 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5273 SCTP_TCB_UNLOCK(stcb);
5280 if (addr->sa_family == AF_INET6) {
5281 struct sockaddr_in6 *sin6;
5283 sin6 = (struct sockaddr_in6 *)addr;
5284 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5285 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5286 SCTP_TCB_UNLOCK(stcb);
5293 error = EAFNOSUPPORT;
5294 SCTP_TCB_UNLOCK(stcb);
5295 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5300 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5302 SCTP_TCB_UNLOCK(stcb);
5303 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5306 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5308 SCTP_TCB_UNLOCK(stcb);
5309 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5313 /************************TCB SPECIFIC SET ******************/
5315 /************************NET SPECIFIC SET ******************/
5316 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5317 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5318 !(net->dest_state & SCTP_ADDR_NOHB)) {
5319 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5320 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5322 net->dest_state |= SCTP_ADDR_NOHB;
5324 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5325 if (paddrp->spp_hbinterval) {
5326 net->heart_beat_delay = paddrp->spp_hbinterval;
5327 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5328 net->heart_beat_delay = 0;
5330 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5331 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5332 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5333 net->dest_state &= ~SCTP_ADDR_NOHB;
5335 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5337 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5338 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5339 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;
5447 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5448 if (paddrp->spp_hbinterval != 0) {
5449 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5450 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5451 stcb->asoc.heart_beat_delay = 0;
5453 /* Turn back on the timer */
5454 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5455 if (paddrp->spp_hbinterval != 0) {
5456 net->heart_beat_delay = paddrp->spp_hbinterval;
5457 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5458 net->heart_beat_delay = 0;
5460 if (net->dest_state & SCTP_ADDR_NOHB) {
5461 net->dest_state &= ~SCTP_ADDR_NOHB;
5463 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5464 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5465 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5467 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5469 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5470 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5471 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5472 net->dest_state |= SCTP_ADDR_NOHB;
5473 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5474 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5476 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5480 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5482 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5483 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5484 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5485 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5486 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5488 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5489 net->mtu = paddrp->spp_pathmtu;
5490 switch (net->ro._l_addr.sa.sa_family) {
5493 net->mtu += SCTP_MIN_V4_OVERHEAD;
5498 net->mtu += SCTP_MIN_OVERHEAD;
5504 if (net->mtu < stcb->asoc.smallest_mtu) {
5505 sctp_pathmtu_adjustment(stcb, net->mtu);
5508 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5510 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5511 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5512 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5513 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5515 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5517 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5519 if (paddrp->spp_flags & SPP_DSCP) {
5520 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5521 net->dscp = paddrp->spp_dscp & 0xfc;
5524 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5525 stcb->asoc.default_dscp |= 0x01;
5528 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5529 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5530 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5531 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5532 net->flowlabel |= 0x80000000;
5535 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5536 stcb->asoc.default_flowlabel |= 0x80000000;
5540 SCTP_TCB_UNLOCK(stcb);
5542 /************************NO TCB, SET TO default stuff ******************/
5543 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5544 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5545 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5546 SCTP_INP_WLOCK(inp);
5548 * For the TOS/FLOWLABEL stuff you
5549 * set it with the options on the
5552 if (paddrp->spp_pathmaxrxt != 0) {
5553 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5555 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5556 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5557 else if (paddrp->spp_hbinterval != 0) {
5558 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5559 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5560 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5562 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5563 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5564 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5565 } else if (paddrp->spp_hbinterval) {
5566 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5568 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5569 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5570 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5572 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5573 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5574 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5575 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5577 if (paddrp->spp_flags & SPP_DSCP) {
5578 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5579 inp->sctp_ep.default_dscp |= 0x01;
5582 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5583 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5584 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5585 inp->sctp_ep.default_flowlabel |= 0x80000000;
5589 SCTP_INP_WUNLOCK(inp);
5591 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5599 struct sctp_rtoinfo *srto;
5600 uint32_t new_init, new_min, new_max;
5602 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5603 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5606 if (srto->srto_initial)
5607 new_init = srto->srto_initial;
5609 new_init = stcb->asoc.initial_rto;
5611 new_max = srto->srto_max;
5613 new_max = stcb->asoc.maxrto;
5615 new_min = srto->srto_min;
5617 new_min = stcb->asoc.minrto;
5618 if ((new_min <= new_init) && (new_init <= new_max)) {
5619 stcb->asoc.initial_rto = new_init;
5620 stcb->asoc.maxrto = new_max;
5621 stcb->asoc.minrto = new_min;
5623 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5626 SCTP_TCB_UNLOCK(stcb);
5628 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5629 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5630 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5631 SCTP_INP_WLOCK(inp);
5632 if (srto->srto_initial)
5633 new_init = srto->srto_initial;
5635 new_init = inp->sctp_ep.initial_rto;
5637 new_max = srto->srto_max;
5639 new_max = inp->sctp_ep.sctp_maxrto;
5641 new_min = srto->srto_min;
5643 new_min = inp->sctp_ep.sctp_minrto;
5644 if ((new_min <= new_init) && (new_init <= new_max)) {
5645 inp->sctp_ep.initial_rto = new_init;
5646 inp->sctp_ep.sctp_maxrto = new_max;
5647 inp->sctp_ep.sctp_minrto = new_min;
5649 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5652 SCTP_INP_WUNLOCK(inp);
5654 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5660 case SCTP_ASSOCINFO:
5662 struct sctp_assocparams *sasoc;
5664 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5665 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5666 if (sasoc->sasoc_cookie_life) {
5667 /* boundary check the cookie life */
5668 if (sasoc->sasoc_cookie_life < 1000)
5669 sasoc->sasoc_cookie_life = 1000;
5670 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5671 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5675 if (sasoc->sasoc_asocmaxrxt)
5676 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5677 if (sasoc->sasoc_cookie_life) {
5678 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5680 SCTP_TCB_UNLOCK(stcb);
5682 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5683 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5684 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5685 SCTP_INP_WLOCK(inp);
5686 if (sasoc->sasoc_asocmaxrxt)
5687 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5688 if (sasoc->sasoc_cookie_life) {
5689 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5691 SCTP_INP_WUNLOCK(inp);
5693 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5701 struct sctp_initmsg *sinit;
5703 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5704 SCTP_INP_WLOCK(inp);
5705 if (sinit->sinit_num_ostreams)
5706 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5708 if (sinit->sinit_max_instreams)
5709 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5711 if (sinit->sinit_max_attempts)
5712 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5714 if (sinit->sinit_max_init_timeo)
5715 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5716 SCTP_INP_WUNLOCK(inp);
5719 case SCTP_PRIMARY_ADDR:
5721 struct sctp_setprim *spa;
5722 struct sctp_nets *net;
5723 struct sockaddr *addr;
5725 #if defined(INET) && defined(INET6)
5726 struct sockaddr_in sin_store;
5730 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5731 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5733 #if defined(INET) && defined(INET6)
5734 if (spa->ssp_addr.ss_family == AF_INET6) {
5735 struct sockaddr_in6 *sin6;
5737 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5738 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5739 in6_sin6_2_sin(&sin_store, sin6);
5740 addr = (struct sockaddr *)&sin_store;
5742 addr = (struct sockaddr *)&spa->ssp_addr;
5745 addr = (struct sockaddr *)&spa->ssp_addr;
5748 addr = (struct sockaddr *)&spa->ssp_addr;
5751 net = sctp_findnet(stcb, addr);
5754 * We increment here since
5755 * sctp_findassociation_ep_addr() wil do a
5756 * decrement if it finds the stcb as long as
5757 * the locked tcb (last argument) is NOT a
5761 SCTP_INP_INCR_REF(inp);
5762 stcb = sctp_findassociation_ep_addr(&inp, addr,
5765 SCTP_INP_DECR_REF(inp);
5769 if ((stcb != NULL) && (net != NULL)) {
5770 if (net != stcb->asoc.primary_destination) {
5771 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5772 /* Ok we need to set it */
5773 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5774 if ((stcb->asoc.alternate) &&
5775 (!(net->dest_state & SCTP_ADDR_PF)) &&
5776 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5777 sctp_free_remote_addr(stcb->asoc.alternate);
5778 stcb->asoc.alternate = NULL;
5781 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5785 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5790 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5794 SCTP_TCB_UNLOCK(stcb);
5798 case SCTP_SET_DYNAMIC_PRIMARY:
5800 union sctp_sockstore *ss;
5802 error = priv_check(curthread,
5803 PRIV_NETINET_RESERVEDPORT);
5807 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5808 /* SUPER USER CHECK? */
5809 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5812 case SCTP_SET_PEER_PRIMARY_ADDR:
5814 struct sctp_setpeerprim *sspp;
5815 struct sockaddr *addr;
5817 #if defined(INET) && defined(INET6)
5818 struct sockaddr_in sin_store;
5822 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5823 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5825 struct sctp_ifa *ifa;
5827 #if defined(INET) && defined(INET6)
5828 if (sspp->sspp_addr.ss_family == AF_INET6) {
5829 struct sockaddr_in6 *sin6;
5831 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5832 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5833 in6_sin6_2_sin(&sin_store, sin6);
5834 addr = (struct sockaddr *)&sin_store;
5836 addr = (struct sockaddr *)&sspp->sspp_addr;
5839 addr = (struct sockaddr *)&sspp->sspp_addr;
5842 addr = (struct sockaddr *)&sspp->sspp_addr;
5844 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5846 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5850 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5852 * Must validate the ifa found is in
5855 struct sctp_laddr *laddr;
5858 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5859 if (laddr->ifa == NULL) {
5860 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5864 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5865 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5868 if (laddr->ifa == ifa) {
5874 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5879 switch (addr->sa_family) {
5883 struct sockaddr_in *sin;
5885 sin = (struct sockaddr_in *)addr;
5886 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5887 &sin->sin_addr) != 0) {
5888 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5898 struct sockaddr_in6 *sin6;
5900 sin6 = (struct sockaddr_in6 *)addr;
5901 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5902 &sin6->sin6_addr) != 0) {
5903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5911 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5916 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5917 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5920 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5922 SCTP_TCB_UNLOCK(stcb);
5924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5929 case SCTP_BINDX_ADD_ADDR:
5931 struct sctp_getaddresses *addrs;
5934 td = (struct thread *)p;
5935 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5938 if (addrs->addr->sa_family == AF_INET) {
5939 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5940 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5944 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5945 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5951 if (addrs->addr->sa_family == AF_INET6) {
5952 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5953 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5957 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5958 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5959 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5965 error = EAFNOSUPPORT;
5968 sctp_bindx_add_address(so, inp, addrs->addr,
5969 addrs->sget_assoc_id, vrf_id,
5973 case SCTP_BINDX_REM_ADDR:
5975 struct sctp_getaddresses *addrs;
5978 td = (struct thread *)p;
5980 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5982 if (addrs->addr->sa_family == AF_INET) {
5983 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5984 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5988 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5989 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5995 if (addrs->addr->sa_family == AF_INET6) {
5996 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5997 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6002 (error = prison_local_ip6(td->td_ucred,
6003 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
6004 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6005 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6011 error = EAFNOSUPPORT;
6014 sctp_bindx_delete_address(inp, addrs->addr,
6015 addrs->sget_assoc_id, vrf_id,
6021 struct sctp_event *event;
6022 uint32_t event_type;
6024 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6025 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6026 switch (event->se_type) {
6027 case SCTP_ASSOC_CHANGE:
6028 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6030 case SCTP_PEER_ADDR_CHANGE:
6031 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6033 case SCTP_REMOTE_ERROR:
6034 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6036 case SCTP_SEND_FAILED:
6037 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6039 case SCTP_SHUTDOWN_EVENT:
6040 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6042 case SCTP_ADAPTATION_INDICATION:
6043 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6045 case SCTP_PARTIAL_DELIVERY_EVENT:
6046 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6048 case SCTP_AUTHENTICATION_EVENT:
6049 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6051 case SCTP_STREAM_RESET_EVENT:
6052 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6054 case SCTP_SENDER_DRY_EVENT:
6055 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6057 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6059 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6062 case SCTP_ASSOC_RESET_EVENT:
6063 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6065 case SCTP_STREAM_CHANGE_EVENT:
6066 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6068 case SCTP_SEND_FAILED_EVENT:
6069 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6073 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6077 if (event_type > 0) {
6080 sctp_stcb_feature_on(inp, stcb, event_type);
6081 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6082 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6083 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6084 (stcb->asoc.stream_queue_cnt == 0)) {
6085 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6089 sctp_stcb_feature_off(inp, stcb, event_type);
6091 SCTP_TCB_UNLOCK(stcb);
6094 * We don't want to send up a storm
6095 * of events, so return an error for
6098 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6099 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6100 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6101 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6102 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6103 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6107 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6108 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6109 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6110 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6111 SCTP_INP_WLOCK(inp);
6113 sctp_feature_on(inp, event_type);
6115 sctp_feature_off(inp, event_type);
6117 SCTP_INP_WUNLOCK(inp);
6119 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6120 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6121 SCTP_INP_RLOCK(inp);
6122 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6123 SCTP_TCB_LOCK(stcb);
6125 sctp_stcb_feature_on(inp, stcb, event_type);
6127 sctp_stcb_feature_off(inp, stcb, event_type);
6129 SCTP_TCB_UNLOCK(stcb);
6131 SCTP_INP_RUNLOCK(inp);
6137 case SCTP_RECVRCVINFO:
6141 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6142 SCTP_INP_WLOCK(inp);
6144 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6146 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6148 SCTP_INP_WUNLOCK(inp);
6151 case SCTP_RECVNXTINFO:
6155 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6156 SCTP_INP_WLOCK(inp);
6158 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6160 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6162 SCTP_INP_WUNLOCK(inp);
6165 case SCTP_DEFAULT_SNDINFO:
6167 struct sctp_sndinfo *info;
6170 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6171 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6174 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6175 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6176 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6177 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6178 stcb->asoc.def_send.sinfo_flags |= policy;
6179 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6180 stcb->asoc.def_send.sinfo_context = info->snd_context;
6182 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6185 SCTP_TCB_UNLOCK(stcb);
6187 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6188 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6189 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6190 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6191 SCTP_INP_WLOCK(inp);
6192 inp->def_send.sinfo_stream = info->snd_sid;
6193 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6194 inp->def_send.sinfo_flags = info->snd_flags;
6195 inp->def_send.sinfo_flags |= policy;
6196 inp->def_send.sinfo_ppid = info->snd_ppid;
6197 inp->def_send.sinfo_context = info->snd_context;
6198 SCTP_INP_WUNLOCK(inp);
6200 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6201 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6202 SCTP_INP_RLOCK(inp);
6203 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6204 SCTP_TCB_LOCK(stcb);
6205 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6206 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6207 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6208 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6209 stcb->asoc.def_send.sinfo_flags |= policy;
6210 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6211 stcb->asoc.def_send.sinfo_context = info->snd_context;
6213 SCTP_TCB_UNLOCK(stcb);
6215 SCTP_INP_RUNLOCK(inp);
6220 case SCTP_DEFAULT_PRINFO:
6222 struct sctp_default_prinfo *info;
6224 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6225 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6227 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6228 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6233 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6234 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6235 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6236 SCTP_TCB_UNLOCK(stcb);
6238 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6239 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6240 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6241 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6242 SCTP_INP_WLOCK(inp);
6243 inp->def_send.sinfo_flags &= 0xfff0;
6244 inp->def_send.sinfo_flags |= info->pr_policy;
6245 inp->def_send.sinfo_timetolive = info->pr_value;
6246 SCTP_INP_WUNLOCK(inp);
6248 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6249 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6250 SCTP_INP_RLOCK(inp);
6251 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6252 SCTP_TCB_LOCK(stcb);
6253 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6254 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6255 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6256 SCTP_TCB_UNLOCK(stcb);
6258 SCTP_INP_RUNLOCK(inp);
6263 case SCTP_PEER_ADDR_THLDS:
6264 /* Applies to the specific association */
6266 struct sctp_paddrthlds *thlds;
6267 struct sctp_nets *net;
6268 struct sockaddr *addr;
6270 #if defined(INET) && defined(INET6)
6271 struct sockaddr_in sin_store;
6275 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6276 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6278 #if defined(INET) && defined(INET6)
6279 if (thlds->spt_address.ss_family == AF_INET6) {
6280 struct sockaddr_in6 *sin6;
6282 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6283 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6284 in6_sin6_2_sin(&sin_store, sin6);
6285 addr = (struct sockaddr *)&sin_store;
6287 addr = (struct sockaddr *)&thlds->spt_address;
6290 addr = (struct sockaddr *)&thlds->spt_address;
6293 addr = (struct sockaddr *)&thlds->spt_address;
6296 net = sctp_findnet(stcb, addr);
6299 * We increment here since
6300 * sctp_findassociation_ep_addr() wil do a
6301 * decrement if it finds the stcb as long as
6302 * the locked tcb (last argument) is NOT a
6306 SCTP_INP_INCR_REF(inp);
6307 stcb = sctp_findassociation_ep_addr(&inp, addr,
6310 SCTP_INP_DECR_REF(inp);
6313 if ((stcb != NULL) && (net == NULL)) {
6315 if (addr->sa_family == AF_INET) {
6317 struct sockaddr_in *sin;
6319 sin = (struct sockaddr_in *)addr;
6320 if (sin->sin_addr.s_addr != INADDR_ANY) {
6321 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6322 SCTP_TCB_UNLOCK(stcb);
6329 if (addr->sa_family == AF_INET6) {
6330 struct sockaddr_in6 *sin6;
6332 sin6 = (struct sockaddr_in6 *)addr;
6333 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6334 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6335 SCTP_TCB_UNLOCK(stcb);
6342 error = EAFNOSUPPORT;
6343 SCTP_TCB_UNLOCK(stcb);
6344 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6350 net->failure_threshold = thlds->spt_pathmaxrxt;
6351 net->pf_threshold = thlds->spt_pathpfthld;
6352 if (net->dest_state & SCTP_ADDR_PF) {
6353 if ((net->error_count > net->failure_threshold) ||
6354 (net->error_count <= net->pf_threshold)) {
6355 net->dest_state &= ~SCTP_ADDR_PF;
6358 if ((net->error_count > net->pf_threshold) &&
6359 (net->error_count <= net->failure_threshold)) {
6360 net->dest_state |= SCTP_ADDR_PF;
6361 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6362 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6363 stcb->sctp_ep, stcb, net,
6364 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6365 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6368 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6369 if (net->error_count > net->failure_threshold) {
6370 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6371 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6374 if (net->error_count <= net->failure_threshold) {
6375 net->dest_state |= SCTP_ADDR_REACHABLE;
6376 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6380 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6381 net->failure_threshold = thlds->spt_pathmaxrxt;
6382 net->pf_threshold = thlds->spt_pathpfthld;
6383 if (net->dest_state & SCTP_ADDR_PF) {
6384 if ((net->error_count > net->failure_threshold) ||
6385 (net->error_count <= net->pf_threshold)) {
6386 net->dest_state &= ~SCTP_ADDR_PF;
6389 if ((net->error_count > net->pf_threshold) &&
6390 (net->error_count <= net->failure_threshold)) {
6391 net->dest_state |= SCTP_ADDR_PF;
6392 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6393 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6394 stcb->sctp_ep, stcb, net,
6395 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6396 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6399 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6400 if (net->error_count > net->failure_threshold) {
6401 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6402 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6405 if (net->error_count <= net->failure_threshold) {
6406 net->dest_state |= SCTP_ADDR_REACHABLE;
6407 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6411 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6412 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6414 SCTP_TCB_UNLOCK(stcb);
6416 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6417 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6418 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6419 SCTP_INP_WLOCK(inp);
6420 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6421 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6422 SCTP_INP_WUNLOCK(inp);
6424 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6430 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6432 struct sctp_udpencaps *encaps;
6433 struct sctp_nets *net;
6434 struct sockaddr *addr;
6436 #if defined(INET) && defined(INET6)
6437 struct sockaddr_in sin_store;
6441 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6442 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6444 #if defined(INET) && defined(INET6)
6445 if (encaps->sue_address.ss_family == AF_INET6) {
6446 struct sockaddr_in6 *sin6;
6448 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6449 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6450 in6_sin6_2_sin(&sin_store, sin6);
6451 addr = (struct sockaddr *)&sin_store;
6453 addr = (struct sockaddr *)&encaps->sue_address;
6456 addr = (struct sockaddr *)&encaps->sue_address;
6459 addr = (struct sockaddr *)&encaps->sue_address;
6462 net = sctp_findnet(stcb, addr);
6465 * We increment here since
6466 * sctp_findassociation_ep_addr() wil do a
6467 * decrement if it finds the stcb as long as
6468 * the locked tcb (last argument) is NOT a
6472 SCTP_INP_INCR_REF(inp);
6473 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6475 SCTP_INP_DECR_REF(inp);
6478 if ((stcb != NULL) && (net == NULL)) {
6480 if (addr->sa_family == AF_INET) {
6482 struct sockaddr_in *sin;
6484 sin = (struct sockaddr_in *)addr;
6485 if (sin->sin_addr.s_addr != INADDR_ANY) {
6486 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6487 SCTP_TCB_UNLOCK(stcb);
6494 if (addr->sa_family == AF_INET6) {
6495 struct sockaddr_in6 *sin6;
6497 sin6 = (struct sockaddr_in6 *)addr;
6498 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6499 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6500 SCTP_TCB_UNLOCK(stcb);
6507 error = EAFNOSUPPORT;
6508 SCTP_TCB_UNLOCK(stcb);
6509 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6515 net->port = encaps->sue_port;
6517 stcb->asoc.port = encaps->sue_port;
6519 SCTP_TCB_UNLOCK(stcb);
6521 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6522 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6523 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6524 SCTP_INP_WLOCK(inp);
6525 inp->sctp_ep.port = encaps->sue_port;
6526 SCTP_INP_WUNLOCK(inp);
6528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6534 case SCTP_ECN_SUPPORTED:
6536 struct sctp_assoc_value *av;
6538 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6539 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6542 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6544 SCTP_TCB_UNLOCK(stcb);
6546 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6547 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6548 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6549 SCTP_INP_WLOCK(inp);
6550 if (av->assoc_value == 0) {
6551 inp->ecn_supported = 0;
6553 inp->ecn_supported = 1;
6555 SCTP_INP_WUNLOCK(inp);
6557 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6563 case SCTP_PR_SUPPORTED:
6565 struct sctp_assoc_value *av;
6567 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6568 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6571 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6573 SCTP_TCB_UNLOCK(stcb);
6575 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6576 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6577 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6578 SCTP_INP_WLOCK(inp);
6579 if (av->assoc_value == 0) {
6580 inp->prsctp_supported = 0;
6582 inp->prsctp_supported = 1;
6584 SCTP_INP_WUNLOCK(inp);
6586 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6592 case SCTP_AUTH_SUPPORTED:
6594 struct sctp_assoc_value *av;
6596 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6597 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6600 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6602 SCTP_TCB_UNLOCK(stcb);
6604 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6605 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6606 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6607 if ((av->assoc_value == 0) &&
6608 (inp->asconf_supported == 1)) {
6610 * AUTH is required for
6613 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6616 SCTP_INP_WLOCK(inp);
6617 if (av->assoc_value == 0) {
6618 inp->auth_supported = 0;
6620 inp->auth_supported = 1;
6622 SCTP_INP_WUNLOCK(inp);
6625 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6631 case SCTP_ASCONF_SUPPORTED:
6633 struct sctp_assoc_value *av;
6635 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6636 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6639 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6641 SCTP_TCB_UNLOCK(stcb);
6643 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6644 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6645 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6646 if ((av->assoc_value != 0) &&
6647 (inp->auth_supported == 0)) {
6649 * AUTH is required for
6652 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6655 SCTP_INP_WLOCK(inp);
6656 if (av->assoc_value == 0) {
6657 inp->asconf_supported = 0;
6658 sctp_auth_delete_chunk(SCTP_ASCONF,
6659 inp->sctp_ep.local_auth_chunks);
6660 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6661 inp->sctp_ep.local_auth_chunks);
6663 inp->asconf_supported = 1;
6664 sctp_auth_add_chunk(SCTP_ASCONF,
6665 inp->sctp_ep.local_auth_chunks);
6666 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6667 inp->sctp_ep.local_auth_chunks);
6669 SCTP_INP_WUNLOCK(inp);
6672 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6678 case SCTP_RECONFIG_SUPPORTED:
6680 struct sctp_assoc_value *av;
6682 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6683 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6686 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6688 SCTP_TCB_UNLOCK(stcb);
6690 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6691 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6692 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6693 SCTP_INP_WLOCK(inp);
6694 if (av->assoc_value == 0) {
6695 inp->reconfig_supported = 0;
6697 inp->reconfig_supported = 1;
6699 SCTP_INP_WUNLOCK(inp);
6701 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6707 case SCTP_NRSACK_SUPPORTED:
6709 struct sctp_assoc_value *av;
6711 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6712 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6717 SCTP_TCB_UNLOCK(stcb);
6719 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6720 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6721 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6722 SCTP_INP_WLOCK(inp);
6723 if (av->assoc_value == 0) {
6724 inp->nrsack_supported = 0;
6726 inp->nrsack_supported = 1;
6728 SCTP_INP_WUNLOCK(inp);
6730 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6736 case SCTP_PKTDROP_SUPPORTED:
6738 struct sctp_assoc_value *av;
6740 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6741 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6744 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6746 SCTP_TCB_UNLOCK(stcb);
6748 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6749 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6750 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6751 SCTP_INP_WLOCK(inp);
6752 if (av->assoc_value == 0) {
6753 inp->pktdrop_supported = 0;
6755 inp->pktdrop_supported = 1;
6757 SCTP_INP_WUNLOCK(inp);
6759 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6767 struct sctp_assoc_value *av;
6768 struct sctp_nets *net;
6770 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6771 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6774 stcb->asoc.max_cwnd = av->assoc_value;
6775 if (stcb->asoc.max_cwnd > 0) {
6776 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6777 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6778 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6779 net->cwnd = stcb->asoc.max_cwnd;
6780 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6781 net->cwnd = net->mtu - sizeof(struct sctphdr);
6786 SCTP_TCB_UNLOCK(stcb);
6788 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6789 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6790 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6791 SCTP_INP_WLOCK(inp);
6792 inp->max_cwnd = av->assoc_value;
6793 SCTP_INP_WUNLOCK(inp);
6795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6802 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6803 error = ENOPROTOOPT;
6805 } /* end switch (opt) */
6810 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6812 void *optval = NULL;
6816 struct sctp_inpcb *inp;
6818 if ((sopt->sopt_level == SOL_SOCKET) &&
6819 (sopt->sopt_name == SO_SETFIB)) {
6820 inp = (struct sctp_inpcb *)so->so_pcb;
6822 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6825 SCTP_INP_WLOCK(inp);
6826 inp->fibnum = so->so_fibnum;
6827 SCTP_INP_WUNLOCK(inp);
6830 if (sopt->sopt_level != IPPROTO_SCTP) {
6831 /* wrong proto level... send back up to IP */
6833 if (INP_CHECK_SOCKAF(so, AF_INET6))
6834 error = ip6_ctloutput(so, sopt);
6836 #if defined(INET) && defined(INET6)
6840 error = ip_ctloutput(so, sopt);
6844 optsize = sopt->sopt_valsize;
6846 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6847 if (optval == NULL) {
6848 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6851 error = sooptcopyin(sopt, optval, optsize, optsize);
6853 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6857 p = (void *)sopt->sopt_td;
6858 if (sopt->sopt_dir == SOPT_SET) {
6859 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6860 } else if (sopt->sopt_dir == SOPT_GET) {
6861 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6863 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6866 if ((error == 0) && (optval != NULL)) {
6867 error = sooptcopyout(sopt, optval, optsize);
6868 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6869 } else if (optval != NULL) {
6870 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6878 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6881 int create_lock_on = 0;
6883 struct sctp_inpcb *inp;
6884 struct sctp_tcb *stcb = NULL;
6886 inp = (struct sctp_inpcb *)so->so_pcb;
6888 /* I made the same as TCP since we are not setup? */
6889 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6890 return (ECONNRESET);
6893 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6896 switch (addr->sa_family) {
6900 struct sockaddr_in6 *sin6p;
6902 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6906 sin6p = (struct sockaddr_in6 *)addr;
6907 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6908 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6917 struct sockaddr_in *sinp;
6919 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6920 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6923 sinp = (struct sockaddr_in *)addr;
6924 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6925 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6932 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6933 return (EAFNOSUPPORT);
6935 SCTP_INP_INCR_REF(inp);
6936 SCTP_ASOC_CREATE_LOCK(inp);
6940 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6941 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6942 /* Should I really unlock ? */
6943 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6948 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6949 (addr->sa_family == AF_INET6)) {
6950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6955 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6956 SCTP_PCB_FLAGS_UNBOUND) {
6957 /* Bind a ephemeral port */
6958 error = sctp_inpcb_bind(so, NULL, NULL, p);
6963 /* Now do we connect? */
6964 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6965 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6966 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6970 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6971 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6972 /* We are already connected AND the TCP model */
6973 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6977 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6978 SCTP_INP_RLOCK(inp);
6979 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6980 SCTP_INP_RUNLOCK(inp);
6983 * We increment here since sctp_findassociation_ep_addr()
6984 * will do a decrement if it finds the stcb as long as the
6985 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6987 SCTP_INP_INCR_REF(inp);
6988 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6990 SCTP_INP_DECR_REF(inp);
6992 SCTP_TCB_UNLOCK(stcb);
6996 /* Already have or am bring up an association */
6997 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7001 vrf_id = inp->def_vrf_id;
7002 /* We are GOOD to go */
7003 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
7004 inp->sctp_ep.pre_open_stream_count,
7005 inp->sctp_ep.port, p);
7007 /* Gak! no memory */
7010 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7011 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7012 /* Set the connected flag so we can queue data */
7015 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
7016 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7018 /* initialize authentication parameters for the assoc */
7019 sctp_initialize_auth_params(inp, stcb);
7021 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7022 SCTP_TCB_UNLOCK(stcb);
7024 if (create_lock_on) {
7025 SCTP_ASOC_CREATE_UNLOCK(inp);
7027 SCTP_INP_DECR_REF(inp);
7034 sctp_listen(struct socket *so, int backlog, struct thread *p)
7037 * Note this module depends on the protocol processing being called
7038 * AFTER any socket level flags and backlog are applied to the
7039 * socket. The traditional way that the socket flags are applied is
7040 * AFTER protocol processing. We have made a change to the
7041 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7042 * place if the socket API for SCTP is to work properly.
7046 struct sctp_inpcb *inp;
7048 inp = (struct sctp_inpcb *)so->so_pcb;
7050 /* I made the same as TCP since we are not setup? */
7051 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7052 return (ECONNRESET);
7054 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7055 /* See if we have a listener */
7056 struct sctp_inpcb *tinp;
7057 union sctp_sockstore store;
7059 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7061 struct sctp_laddr *laddr;
7063 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7064 memcpy(&store, &laddr->ifa->address, sizeof(store));
7065 switch (store.sa.sa_family) {
7068 store.sin.sin_port = inp->sctp_lport;
7073 store.sin6.sin6_port = inp->sctp_lport;
7079 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7080 if (tinp && (tinp != inp) &&
7081 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7082 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7083 (tinp->sctp_socket->so_qlimit)) {
7085 * we have a listener already and
7088 SCTP_INP_DECR_REF(tinp);
7089 return (EADDRINUSE);
7091 SCTP_INP_DECR_REF(tinp);
7095 /* Setup a local addr bound all */
7096 memset(&store, 0, sizeof(store));
7098 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7099 store.sa.sa_family = AF_INET6;
7100 store.sa.sa_len = sizeof(struct sockaddr_in6);
7104 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7105 store.sa.sa_family = AF_INET;
7106 store.sa.sa_len = sizeof(struct sockaddr_in);
7109 switch (store.sa.sa_family) {
7112 store.sin.sin_port = inp->sctp_lport;
7117 store.sin6.sin6_port = inp->sctp_lport;
7123 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7124 if (tinp && (tinp != inp) &&
7125 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7126 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7127 (tinp->sctp_socket->so_qlimit)) {
7129 * we have a listener already and its not
7132 SCTP_INP_DECR_REF(tinp);
7133 return (EADDRINUSE);
7135 SCTP_INP_DECR_REF(tinp);
7139 SCTP_INP_RLOCK(inp);
7140 #ifdef SCTP_LOCK_LOGGING
7141 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7142 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7146 error = solisten_proto_check(so);
7149 SCTP_INP_RUNLOCK(inp);
7152 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7153 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7155 * The unlucky case - We are in the tcp pool with this guy.
7156 * - Someone else is in the main inp slot. - We must move
7157 * this guy (the listener) to the main slot - We must then
7158 * move the guy that was listener to the TCP Pool.
7160 if (sctp_swap_inpcb_for_listen(inp)) {
7161 SCTP_INP_RUNLOCK(inp);
7162 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7163 return (EADDRINUSE);
7166 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7167 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7168 /* We are already connected AND the TCP model */
7169 SCTP_INP_RUNLOCK(inp);
7170 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7171 return (EADDRINUSE);
7173 SCTP_INP_RUNLOCK(inp);
7174 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7175 /* We must do a bind. */
7176 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7177 /* bind error, probably perm */
7182 /* It appears for 7.0 and on, we must always call this. */
7183 solisten_proto(so, backlog);
7184 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7185 /* remove the ACCEPTCONN flag for one-to-many sockets */
7186 so->so_options &= ~SO_ACCEPTCONN;
7189 /* turning off listen */
7190 so->so_options &= ~SO_ACCEPTCONN;
7196 static int sctp_defered_wakeup_cnt = 0;
7199 sctp_accept(struct socket *so, struct sockaddr **addr)
7201 struct sctp_tcb *stcb;
7202 struct sctp_inpcb *inp;
7203 union sctp_sockstore store;
7209 inp = (struct sctp_inpcb *)so->so_pcb;
7212 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7213 return (ECONNRESET);
7215 SCTP_INP_RLOCK(inp);
7216 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7217 SCTP_INP_RUNLOCK(inp);
7218 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7219 return (EOPNOTSUPP);
7221 if (so->so_state & SS_ISDISCONNECTED) {
7222 SCTP_INP_RUNLOCK(inp);
7223 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7224 return (ECONNABORTED);
7226 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7228 SCTP_INP_RUNLOCK(inp);
7229 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7230 return (ECONNRESET);
7232 SCTP_TCB_LOCK(stcb);
7233 SCTP_INP_RUNLOCK(inp);
7234 store = stcb->asoc.primary_destination->ro._l_addr;
7235 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7236 SCTP_TCB_UNLOCK(stcb);
7237 switch (store.sa.sa_family) {
7241 struct sockaddr_in *sin;
7243 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7246 sin->sin_family = AF_INET;
7247 sin->sin_len = sizeof(*sin);
7248 sin->sin_port = store.sin.sin_port;
7249 sin->sin_addr = store.sin.sin_addr;
7250 *addr = (struct sockaddr *)sin;
7257 struct sockaddr_in6 *sin6;
7259 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7262 sin6->sin6_family = AF_INET6;
7263 sin6->sin6_len = sizeof(*sin6);
7264 sin6->sin6_port = store.sin6.sin6_port;
7265 sin6->sin6_addr = store.sin6.sin6_addr;
7266 if ((error = sa6_recoverscope(sin6)) != 0) {
7267 SCTP_FREE_SONAME(sin6);
7270 *addr = (struct sockaddr *)sin6;
7278 /* Wake any delayed sleep action */
7279 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7280 SCTP_INP_WLOCK(inp);
7281 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7282 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7283 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7284 SCTP_INP_WUNLOCK(inp);
7285 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7286 if (sowriteable(inp->sctp_socket)) {
7287 sowwakeup_locked(inp->sctp_socket);
7289 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7291 SCTP_INP_WLOCK(inp);
7293 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7294 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7295 SCTP_INP_WUNLOCK(inp);
7296 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7297 if (soreadable(inp->sctp_socket)) {
7298 sctp_defered_wakeup_cnt++;
7299 sorwakeup_locked(inp->sctp_socket);
7301 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7303 SCTP_INP_WLOCK(inp);
7305 SCTP_INP_WUNLOCK(inp);
7307 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7308 SCTP_TCB_LOCK(stcb);
7309 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7310 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7317 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7319 struct sockaddr_in *sin;
7321 struct sctp_inpcb *inp;
7322 struct sctp_ifa *sctp_ifa;
7325 * Do the malloc first in case it blocks.
7327 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7330 sin->sin_family = AF_INET;
7331 sin->sin_len = sizeof(*sin);
7332 inp = (struct sctp_inpcb *)so->so_pcb;
7334 SCTP_FREE_SONAME(sin);
7335 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7336 return (ECONNRESET);
7338 SCTP_INP_RLOCK(inp);
7339 sin->sin_port = inp->sctp_lport;
7340 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7341 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7342 struct sctp_tcb *stcb;
7343 struct sockaddr_in *sin_a;
7344 struct sctp_nets *net;
7347 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7353 SCTP_TCB_LOCK(stcb);
7354 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7355 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7357 /* this will make coverity happy */
7360 if (sin_a->sin_family == AF_INET) {
7365 if ((!fnd) || (sin_a == NULL)) {
7367 SCTP_TCB_UNLOCK(stcb);
7370 vrf_id = inp->def_vrf_id;
7371 sctp_ifa = sctp_source_address_selection(inp,
7373 (sctp_route_t *) & net->ro,
7376 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7377 sctp_free_ifa(sctp_ifa);
7379 SCTP_TCB_UNLOCK(stcb);
7381 /* For the bound all case you get back 0 */
7383 sin->sin_addr.s_addr = 0;
7387 /* Take the first IPv4 address in the list */
7388 struct sctp_laddr *laddr;
7391 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7392 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7393 struct sockaddr_in *sin_a;
7395 sin_a = &laddr->ifa->address.sin;
7396 sin->sin_addr = sin_a->sin_addr;
7402 SCTP_FREE_SONAME(sin);
7403 SCTP_INP_RUNLOCK(inp);
7404 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7408 SCTP_INP_RUNLOCK(inp);
7409 (*addr) = (struct sockaddr *)sin;
7414 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7416 struct sockaddr_in *sin;
7418 struct sockaddr_in *sin_a;
7419 struct sctp_inpcb *inp;
7420 struct sctp_tcb *stcb;
7421 struct sctp_nets *net;
7423 /* Do the malloc first in case it blocks. */
7424 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7427 sin->sin_family = AF_INET;
7428 sin->sin_len = sizeof(*sin);
7430 inp = (struct sctp_inpcb *)so->so_pcb;
7431 if ((inp == NULL) ||
7432 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7433 /* UDP type and listeners will drop out here */
7434 SCTP_FREE_SONAME(sin);
7435 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7438 SCTP_INP_RLOCK(inp);
7439 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7441 SCTP_TCB_LOCK(stcb);
7443 SCTP_INP_RUNLOCK(inp);
7445 SCTP_FREE_SONAME(sin);
7446 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7447 return (ECONNRESET);
7450 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7451 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7452 if (sin_a->sin_family == AF_INET) {
7454 sin->sin_port = stcb->rport;
7455 sin->sin_addr = sin_a->sin_addr;
7459 SCTP_TCB_UNLOCK(stcb);
7461 /* No IPv4 address */
7462 SCTP_FREE_SONAME(sin);
7463 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7466 (*addr) = (struct sockaddr *)sin;
7470 struct pr_usrreqs sctp_usrreqs = {
7471 .pru_abort = sctp_abort,
7472 .pru_accept = sctp_accept,
7473 .pru_attach = sctp_attach,
7474 .pru_bind = sctp_bind,
7475 .pru_connect = sctp_connect,
7476 .pru_control = in_control,
7477 .pru_close = sctp_close,
7478 .pru_detach = sctp_close,
7479 .pru_sopoll = sopoll_generic,
7480 .pru_flush = sctp_flush,
7481 .pru_disconnect = sctp_disconnect,
7482 .pru_listen = sctp_listen,
7483 .pru_peeraddr = sctp_peeraddr,
7484 .pru_send = sctp_sendm,
7485 .pru_shutdown = sctp_shutdown,
7486 .pru_sockaddr = sctp_ingetaddr,
7487 .pru_sosend = sctp_sosend,
7488 .pru_soreceive = sctp_soreceive