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,
1480 /* Gak! no memory */
1483 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1484 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1485 /* Set the connected flag so we can queue data */
1488 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1489 /* move to second address */
1490 switch (sa->sa_family) {
1493 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1498 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1506 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1507 /* Fill in the return id */
1509 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE,
1510 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
1513 a_id = (sctp_assoc_t *) optval;
1514 *a_id = sctp_get_associd(stcb);
1516 /* initialize authentication parameters for the assoc */
1517 sctp_initialize_auth_params(inp, stcb);
1520 /* doing delayed connection */
1521 stcb->asoc.delayed_connection = 1;
1522 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1524 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1525 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1527 SCTP_TCB_UNLOCK(stcb);
1528 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1529 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1530 /* Set the connected flag so we can queue data */
1534 if (creat_lock_on) {
1535 SCTP_ASOC_CREATE_UNLOCK(inp);
1537 SCTP_INP_DECR_REF(inp);
1541 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1542 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1543 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1544 SCTP_INP_RLOCK(inp); \
1545 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1547 SCTP_TCB_LOCK(stcb); \
1549 SCTP_INP_RUNLOCK(inp); \
1550 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1551 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1552 if (stcb == NULL) { \
1553 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1563 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1564 if (size < sizeof(type)) { \
1565 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1569 destp = (type *)srcp; \
1574 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1577 struct sctp_inpcb *inp = NULL;
1579 struct sctp_tcb *stcb = NULL;
1581 if (optval == NULL) {
1582 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1585 inp = (struct sctp_inpcb *)so->so_pcb;
1587 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1594 case SCTP_AUTOCLOSE:
1595 case SCTP_EXPLICIT_EOR:
1596 case SCTP_AUTO_ASCONF:
1597 case SCTP_DISABLE_FRAGMENTS:
1598 case SCTP_I_WANT_MAPPED_V4_ADDR:
1599 case SCTP_USE_EXT_RCVINFO:
1600 SCTP_INP_RLOCK(inp);
1602 case SCTP_DISABLE_FRAGMENTS:
1603 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1605 case SCTP_I_WANT_MAPPED_V4_ADDR:
1606 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1608 case SCTP_AUTO_ASCONF:
1609 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1610 /* only valid for bound all sockets */
1611 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1613 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1618 case SCTP_EXPLICIT_EOR:
1619 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1622 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1624 case SCTP_USE_EXT_RCVINFO:
1625 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1627 case SCTP_AUTOCLOSE:
1628 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1629 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1635 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1636 error = ENOPROTOOPT;
1637 } /* end switch (sopt->sopt_name) */
1638 if (*optsize < sizeof(val)) {
1639 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1643 SCTP_INP_RUNLOCK(inp);
1645 /* return the option value */
1646 *(int *)optval = val;
1647 *optsize = sizeof(val);
1650 case SCTP_GET_PACKET_LOG:
1652 #ifdef SCTP_PACKET_LOGGING
1656 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1657 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1665 case SCTP_REUSE_PORT:
1669 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1670 /* Can't do this for a 1-m socket */
1674 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1675 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1676 *optsize = sizeof(uint32_t);
1679 case SCTP_PARTIAL_DELIVERY_POINT:
1683 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1684 *value = inp->partial_delivery_point;
1685 *optsize = sizeof(uint32_t);
1688 case SCTP_FRAGMENT_INTERLEAVE:
1692 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1693 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1694 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1695 *value = SCTP_FRAG_LEVEL_2;
1697 *value = SCTP_FRAG_LEVEL_1;
1700 *value = SCTP_FRAG_LEVEL_0;
1702 *optsize = sizeof(uint32_t);
1705 case SCTP_INTERLEAVING_SUPPORTED:
1707 struct sctp_assoc_value *av;
1709 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1710 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1713 av->assoc_value = stcb->asoc.idata_supported;
1714 SCTP_TCB_UNLOCK(stcb);
1716 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1717 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1718 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1719 SCTP_INP_RLOCK(inp);
1720 if (inp->idata_supported) {
1721 av->assoc_value = 1;
1723 av->assoc_value = 0;
1725 SCTP_INP_RUNLOCK(inp);
1727 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1732 *optsize = sizeof(struct sctp_assoc_value);
1736 case SCTP_CMT_ON_OFF:
1738 struct sctp_assoc_value *av;
1740 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1741 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1743 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1744 SCTP_TCB_UNLOCK(stcb);
1746 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1747 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1748 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1749 SCTP_INP_RLOCK(inp);
1750 av->assoc_value = inp->sctp_cmt_on_off;
1751 SCTP_INP_RUNLOCK(inp);
1753 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1758 *optsize = sizeof(struct sctp_assoc_value);
1762 case SCTP_PLUGGABLE_CC:
1764 struct sctp_assoc_value *av;
1766 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1767 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1769 av->assoc_value = stcb->asoc.congestion_control_module;
1770 SCTP_TCB_UNLOCK(stcb);
1772 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1773 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1774 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1775 SCTP_INP_RLOCK(inp);
1776 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1777 SCTP_INP_RUNLOCK(inp);
1779 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1784 *optsize = sizeof(struct sctp_assoc_value);
1788 case SCTP_CC_OPTION:
1790 struct sctp_cc_option *cc_opt;
1792 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1793 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1797 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1800 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1801 *optsize = sizeof(struct sctp_cc_option);
1803 SCTP_TCB_UNLOCK(stcb);
1807 case SCTP_PLUGGABLE_SS:
1809 struct sctp_assoc_value *av;
1811 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1812 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1814 av->assoc_value = stcb->asoc.stream_scheduling_module;
1815 SCTP_TCB_UNLOCK(stcb);
1817 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1818 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1819 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1820 SCTP_INP_RLOCK(inp);
1821 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1822 SCTP_INP_RUNLOCK(inp);
1824 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1829 *optsize = sizeof(struct sctp_assoc_value);
1835 struct sctp_stream_value *av;
1837 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1838 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1840 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1841 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1842 &av->stream_value) < 0)) {
1843 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1846 *optsize = sizeof(struct sctp_stream_value);
1848 SCTP_TCB_UNLOCK(stcb);
1851 * Can't get stream value without
1854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1859 case SCTP_GET_ADDR_LEN:
1861 struct sctp_assoc_value *av;
1863 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1866 if (av->assoc_value == AF_INET) {
1867 av->assoc_value = sizeof(struct sockaddr_in);
1872 if (av->assoc_value == AF_INET6) {
1873 av->assoc_value = sizeof(struct sockaddr_in6);
1878 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1880 *optsize = sizeof(struct sctp_assoc_value);
1884 case SCTP_GET_ASSOC_NUMBER:
1886 uint32_t *value, cnt;
1888 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1889 SCTP_INP_RLOCK(inp);
1890 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1891 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1892 /* Can't do this for a 1-1 socket */
1894 SCTP_INP_RUNLOCK(inp);
1898 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1901 SCTP_INP_RUNLOCK(inp);
1903 *optsize = sizeof(uint32_t);
1906 case SCTP_GET_ASSOC_ID_LIST:
1908 struct sctp_assoc_ids *ids;
1912 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1913 SCTP_INP_RLOCK(inp);
1914 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1915 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
1916 /* Can't do this for a 1-1 socket */
1918 SCTP_INP_RUNLOCK(inp);
1922 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1923 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1925 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1928 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1933 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1937 SCTP_INP_RUNLOCK(inp);
1939 ids->gaids_number_of_ids = at;
1940 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1946 struct sctp_assoc_value *av;
1948 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1949 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1952 av->assoc_value = stcb->asoc.context;
1953 SCTP_TCB_UNLOCK(stcb);
1955 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1956 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1957 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1958 SCTP_INP_RLOCK(inp);
1959 av->assoc_value = inp->sctp_context;
1960 SCTP_INP_RUNLOCK(inp);
1962 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1967 *optsize = sizeof(struct sctp_assoc_value);
1973 uint32_t *default_vrfid;
1975 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1976 *default_vrfid = inp->def_vrf_id;
1977 *optsize = sizeof(uint32_t);
1980 case SCTP_GET_ASOC_VRF:
1982 struct sctp_assoc_value *id;
1984 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1985 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1988 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1990 id->assoc_value = stcb->asoc.vrf_id;
1991 *optsize = sizeof(struct sctp_assoc_value);
1995 case SCTP_GET_VRF_IDS:
1997 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2001 case SCTP_GET_NONCE_VALUES:
2003 struct sctp_get_nonce_values *gnv;
2005 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2006 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2009 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2010 gnv->gn_local_tag = stcb->asoc.my_vtag;
2011 SCTP_TCB_UNLOCK(stcb);
2012 *optsize = sizeof(struct sctp_get_nonce_values);
2014 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2019 case SCTP_DELAYED_SACK:
2021 struct sctp_sack_info *sack;
2023 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2024 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2026 sack->sack_delay = stcb->asoc.delayed_ack;
2027 sack->sack_freq = stcb->asoc.sack_freq;
2028 SCTP_TCB_UNLOCK(stcb);
2030 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2031 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2032 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2033 SCTP_INP_RLOCK(inp);
2034 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2035 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2036 SCTP_INP_RUNLOCK(inp);
2038 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2043 *optsize = sizeof(struct sctp_sack_info);
2047 case SCTP_GET_SNDBUF_USE:
2049 struct sctp_sockstat *ss;
2051 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2052 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2055 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2056 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2057 stcb->asoc.size_on_all_streams);
2058 SCTP_TCB_UNLOCK(stcb);
2059 *optsize = sizeof(struct sctp_sockstat);
2061 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2066 case SCTP_MAX_BURST:
2068 struct sctp_assoc_value *av;
2070 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2071 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2074 av->assoc_value = stcb->asoc.max_burst;
2075 SCTP_TCB_UNLOCK(stcb);
2077 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2078 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2079 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2080 SCTP_INP_RLOCK(inp);
2081 av->assoc_value = inp->sctp_ep.max_burst;
2082 SCTP_INP_RUNLOCK(inp);
2084 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2089 *optsize = sizeof(struct sctp_assoc_value);
2095 struct sctp_assoc_value *av;
2098 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2099 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2102 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2103 SCTP_TCB_UNLOCK(stcb);
2105 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2106 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2107 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2108 SCTP_INP_RLOCK(inp);
2109 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2110 ovh = SCTP_MED_OVERHEAD;
2112 ovh = SCTP_MED_V4_OVERHEAD;
2114 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2115 av->assoc_value = 0;
2117 av->assoc_value = inp->sctp_frag_point - ovh;
2118 SCTP_INP_RUNLOCK(inp);
2120 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2125 *optsize = sizeof(struct sctp_assoc_value);
2129 case SCTP_GET_STAT_LOG:
2130 error = sctp_fill_stat_log(optval, optsize);
2134 struct sctp_event_subscribe *events;
2136 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2137 memset(events, 0, sizeof(struct sctp_event_subscribe));
2138 SCTP_INP_RLOCK(inp);
2139 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2140 events->sctp_data_io_event = 1;
2142 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2143 events->sctp_association_event = 1;
2145 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2146 events->sctp_address_event = 1;
2148 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2149 events->sctp_send_failure_event = 1;
2151 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2152 events->sctp_peer_error_event = 1;
2154 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2155 events->sctp_shutdown_event = 1;
2157 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2158 events->sctp_partial_delivery_event = 1;
2160 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2161 events->sctp_adaptation_layer_event = 1;
2163 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2164 events->sctp_authentication_event = 1;
2166 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2167 events->sctp_sender_dry_event = 1;
2169 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2170 events->sctp_stream_reset_event = 1;
2171 SCTP_INP_RUNLOCK(inp);
2172 *optsize = sizeof(struct sctp_event_subscribe);
2175 case SCTP_ADAPTATION_LAYER:
2179 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2181 SCTP_INP_RLOCK(inp);
2182 *value = inp->sctp_ep.adaptation_layer_indicator;
2183 SCTP_INP_RUNLOCK(inp);
2184 *optsize = sizeof(uint32_t);
2187 case SCTP_SET_INITIAL_DBG_SEQ:
2191 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2192 SCTP_INP_RLOCK(inp);
2193 *value = inp->sctp_ep.initial_sequence_debug;
2194 SCTP_INP_RUNLOCK(inp);
2195 *optsize = sizeof(uint32_t);
2198 case SCTP_GET_LOCAL_ADDR_SIZE:
2202 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2203 SCTP_INP_RLOCK(inp);
2204 *value = sctp_count_max_addresses(inp);
2205 SCTP_INP_RUNLOCK(inp);
2206 *optsize = sizeof(uint32_t);
2209 case SCTP_GET_REMOTE_ADDR_SIZE:
2213 struct sctp_nets *net;
2215 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2216 /* FIXME MT: change to sctp_assoc_value? */
2217 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2221 /* Count the sizes */
2222 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2223 switch (net->ro._l_addr.sa.sa_family) {
2227 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2228 size += sizeof(struct sockaddr_in6);
2230 size += sizeof(struct sockaddr_in);
2233 size += sizeof(struct sockaddr_in);
2239 size += sizeof(struct sockaddr_in6);
2246 SCTP_TCB_UNLOCK(stcb);
2247 *value = (uint32_t) size;
2248 *optsize = sizeof(uint32_t);
2250 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2255 case SCTP_GET_PEER_ADDRESSES:
2257 * Get the address information, an array is passed in to
2258 * fill up we pack it.
2262 struct sockaddr_storage *sas;
2263 struct sctp_nets *net;
2264 struct sctp_getaddresses *saddr;
2266 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2267 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2270 left = (*optsize) - sizeof(struct sctp_getaddresses);
2271 *optsize = sizeof(struct sctp_getaddresses);
2272 sas = (struct sockaddr_storage *)&saddr->addr[0];
2274 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2275 switch (net->ro._l_addr.sa.sa_family) {
2279 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2280 cpsz = sizeof(struct sockaddr_in6);
2282 cpsz = sizeof(struct sockaddr_in);
2285 cpsz = sizeof(struct sockaddr_in);
2291 cpsz = sizeof(struct sockaddr_in6);
2302 /* not enough room. */
2305 #if defined(INET) && defined(INET6)
2306 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2307 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2308 /* Must map the address */
2309 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2310 (struct sockaddr_in6 *)sas);
2312 memcpy(sas, &net->ro._l_addr, cpsz);
2315 memcpy(sas, &net->ro._l_addr, cpsz);
2317 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2319 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2323 SCTP_TCB_UNLOCK(stcb);
2325 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2330 case SCTP_GET_LOCAL_ADDRESSES:
2332 size_t limit, actual;
2333 struct sockaddr_storage *sas;
2334 struct sctp_getaddresses *saddr;
2336 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2337 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2339 sas = (struct sockaddr_storage *)&saddr->addr[0];
2340 limit = *optsize - sizeof(sctp_assoc_t);
2341 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2343 SCTP_TCB_UNLOCK(stcb);
2345 *optsize = sizeof(struct sockaddr_storage) + actual;
2348 case SCTP_PEER_ADDR_PARAMS:
2350 struct sctp_paddrparams *paddrp;
2351 struct sctp_nets *net;
2352 struct sockaddr *addr;
2354 #if defined(INET) && defined(INET6)
2355 struct sockaddr_in sin_store;
2359 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2360 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2362 #if defined(INET) && defined(INET6)
2363 if (paddrp->spp_address.ss_family == AF_INET6) {
2364 struct sockaddr_in6 *sin6;
2366 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2367 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2368 in6_sin6_2_sin(&sin_store, sin6);
2369 addr = (struct sockaddr *)&sin_store;
2371 addr = (struct sockaddr *)&paddrp->spp_address;
2374 addr = (struct sockaddr *)&paddrp->spp_address;
2377 addr = (struct sockaddr *)&paddrp->spp_address;
2380 net = sctp_findnet(stcb, addr);
2383 * We increment here since
2384 * sctp_findassociation_ep_addr() wil do a
2385 * decrement if it finds the stcb as long as
2386 * the locked tcb (last argument) is NOT a
2390 SCTP_INP_INCR_REF(inp);
2391 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2393 SCTP_INP_DECR_REF(inp);
2396 if ((stcb != NULL) && (net == NULL)) {
2398 if (addr->sa_family == AF_INET) {
2399 struct sockaddr_in *sin;
2401 sin = (struct sockaddr_in *)addr;
2402 if (sin->sin_addr.s_addr != INADDR_ANY) {
2404 SCTP_TCB_UNLOCK(stcb);
2405 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2411 if (addr->sa_family == AF_INET6) {
2412 struct sockaddr_in6 *sin6;
2414 sin6 = (struct sockaddr_in6 *)addr;
2415 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2417 SCTP_TCB_UNLOCK(stcb);
2418 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2424 error = EAFNOSUPPORT;
2425 SCTP_TCB_UNLOCK(stcb);
2426 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2431 /* Applies to the specific association */
2432 paddrp->spp_flags = 0;
2434 paddrp->spp_hbinterval = net->heart_beat_delay;
2435 paddrp->spp_pathmaxrxt = net->failure_threshold;
2436 paddrp->spp_pathmtu = net->mtu;
2437 switch (net->ro._l_addr.sa.sa_family) {
2440 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2445 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2451 /* get flags for HB */
2452 if (net->dest_state & SCTP_ADDR_NOHB) {
2453 paddrp->spp_flags |= SPP_HB_DISABLE;
2455 paddrp->spp_flags |= SPP_HB_ENABLE;
2457 /* get flags for PMTU */
2458 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2459 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2461 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2463 if (net->dscp & 0x01) {
2464 paddrp->spp_dscp = net->dscp & 0xfc;
2465 paddrp->spp_flags |= SPP_DSCP;
2468 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2469 (net->flowlabel & 0x80000000)) {
2470 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2471 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2476 * No destination so return default
2479 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2480 paddrp->spp_pathmtu = 0;
2481 if (stcb->asoc.default_dscp & 0x01) {
2482 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2483 paddrp->spp_flags |= SPP_DSCP;
2486 if (stcb->asoc.default_flowlabel & 0x80000000) {
2487 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2488 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2491 /* default settings should be these */
2492 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2493 paddrp->spp_flags |= SPP_HB_DISABLE;
2495 paddrp->spp_flags |= SPP_HB_ENABLE;
2497 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2498 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2500 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2502 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2504 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2505 SCTP_TCB_UNLOCK(stcb);
2507 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2508 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2509 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2510 /* Use endpoint defaults */
2511 SCTP_INP_RLOCK(inp);
2512 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2513 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2514 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2515 /* get inp's default */
2516 if (inp->sctp_ep.default_dscp & 0x01) {
2517 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2518 paddrp->spp_flags |= SPP_DSCP;
2521 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2522 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2523 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2524 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2527 /* can't return this */
2528 paddrp->spp_pathmtu = 0;
2530 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2531 paddrp->spp_flags |= SPP_HB_ENABLE;
2533 paddrp->spp_flags |= SPP_HB_DISABLE;
2535 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2536 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2538 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2540 SCTP_INP_RUNLOCK(inp);
2542 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2547 *optsize = sizeof(struct sctp_paddrparams);
2551 case SCTP_GET_PEER_ADDR_INFO:
2553 struct sctp_paddrinfo *paddri;
2554 struct sctp_nets *net;
2555 struct sockaddr *addr;
2557 #if defined(INET) && defined(INET6)
2558 struct sockaddr_in sin_store;
2562 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2563 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2565 #if defined(INET) && defined(INET6)
2566 if (paddri->spinfo_address.ss_family == AF_INET6) {
2567 struct sockaddr_in6 *sin6;
2569 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2570 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2571 in6_sin6_2_sin(&sin_store, sin6);
2572 addr = (struct sockaddr *)&sin_store;
2574 addr = (struct sockaddr *)&paddri->spinfo_address;
2577 addr = (struct sockaddr *)&paddri->spinfo_address;
2580 addr = (struct sockaddr *)&paddri->spinfo_address;
2583 net = sctp_findnet(stcb, addr);
2586 * We increment here since
2587 * sctp_findassociation_ep_addr() wil do a
2588 * decrement if it finds the stcb as long as
2589 * the locked tcb (last argument) is NOT a
2593 SCTP_INP_INCR_REF(inp);
2594 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2596 SCTP_INP_DECR_REF(inp);
2600 if ((stcb != NULL) && (net != NULL)) {
2601 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2602 /* It's unconfirmed */
2603 paddri->spinfo_state = SCTP_UNCONFIRMED;
2604 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2606 paddri->spinfo_state = SCTP_ACTIVE;
2609 paddri->spinfo_state = SCTP_INACTIVE;
2611 paddri->spinfo_cwnd = net->cwnd;
2612 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2613 paddri->spinfo_rto = net->RTO;
2614 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2615 paddri->spinfo_mtu = net->mtu;
2616 switch (addr->sa_family) {
2619 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2624 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2630 SCTP_TCB_UNLOCK(stcb);
2631 *optsize = sizeof(struct sctp_paddrinfo);
2634 SCTP_TCB_UNLOCK(stcb);
2636 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2641 case SCTP_PCB_STATUS:
2643 struct sctp_pcbinfo *spcb;
2645 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2646 sctp_fill_pcbinfo(spcb);
2647 *optsize = sizeof(struct sctp_pcbinfo);
2652 struct sctp_nets *net;
2653 struct sctp_status *sstat;
2655 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2656 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2659 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2663 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2664 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2665 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2666 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2668 * We can't include chunks that have been passed to
2669 * the socket layer. Only things in queue.
2671 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2672 stcb->asoc.cnt_on_all_streams);
2675 sstat->sstat_instrms = stcb->asoc.streamincnt;
2676 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2677 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2678 memcpy(&sstat->sstat_primary.spinfo_address,
2679 &stcb->asoc.primary_destination->ro._l_addr,
2680 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2681 net = stcb->asoc.primary_destination;
2682 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2684 * Again the user can get info from sctp_constants.h
2685 * for what the state of the network is.
2687 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2688 /* It's unconfirmed */
2689 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2690 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2692 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2695 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2697 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2698 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2699 sstat->sstat_primary.spinfo_rto = net->RTO;
2700 sstat->sstat_primary.spinfo_mtu = net->mtu;
2701 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2704 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2709 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2715 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2716 SCTP_TCB_UNLOCK(stcb);
2717 *optsize = sizeof(struct sctp_status);
2722 struct sctp_rtoinfo *srto;
2724 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2725 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2728 srto->srto_initial = stcb->asoc.initial_rto;
2729 srto->srto_max = stcb->asoc.maxrto;
2730 srto->srto_min = stcb->asoc.minrto;
2731 SCTP_TCB_UNLOCK(stcb);
2733 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2734 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2735 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2736 SCTP_INP_RLOCK(inp);
2737 srto->srto_initial = inp->sctp_ep.initial_rto;
2738 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2739 srto->srto_min = inp->sctp_ep.sctp_minrto;
2740 SCTP_INP_RUNLOCK(inp);
2742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2747 *optsize = sizeof(struct sctp_rtoinfo);
2753 struct sctp_timeouts *stimo;
2755 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2756 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2759 stimo->stimo_init = stcb->asoc.timoinit;
2760 stimo->stimo_data = stcb->asoc.timodata;
2761 stimo->stimo_sack = stcb->asoc.timosack;
2762 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2763 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2764 stimo->stimo_cookie = stcb->asoc.timocookie;
2765 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2766 SCTP_TCB_UNLOCK(stcb);
2767 *optsize = sizeof(struct sctp_timeouts);
2769 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2774 case SCTP_ASSOCINFO:
2776 struct sctp_assocparams *sasoc;
2778 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2779 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2782 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2783 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2784 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2785 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2786 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2787 SCTP_TCB_UNLOCK(stcb);
2789 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2790 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2791 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2792 SCTP_INP_RLOCK(inp);
2793 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2794 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2795 sasoc->sasoc_number_peer_destinations = 0;
2796 sasoc->sasoc_peer_rwnd = 0;
2797 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2798 SCTP_INP_RUNLOCK(inp);
2800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2805 *optsize = sizeof(struct sctp_assocparams);
2809 case SCTP_DEFAULT_SEND_PARAM:
2811 struct sctp_sndrcvinfo *s_info;
2813 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2814 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2817 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2818 SCTP_TCB_UNLOCK(stcb);
2820 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2821 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2822 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2823 SCTP_INP_RLOCK(inp);
2824 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2825 SCTP_INP_RUNLOCK(inp);
2827 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2832 *optsize = sizeof(struct sctp_sndrcvinfo);
2838 struct sctp_initmsg *sinit;
2840 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2841 SCTP_INP_RLOCK(inp);
2842 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2843 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2844 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2845 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2846 SCTP_INP_RUNLOCK(inp);
2847 *optsize = sizeof(struct sctp_initmsg);
2850 case SCTP_PRIMARY_ADDR:
2851 /* we allow a "get" operation on this */
2853 struct sctp_setprim *ssp;
2855 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2856 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2859 union sctp_sockstore *addr;
2861 addr = &stcb->asoc.primary_destination->ro._l_addr;
2862 switch (addr->sa.sa_family) {
2866 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2867 in6_sin_2_v4mapsin6(&addr->sin,
2868 (struct sockaddr_in6 *)&ssp->ssp_addr);
2870 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2873 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2879 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2885 SCTP_TCB_UNLOCK(stcb);
2886 *optsize = sizeof(struct sctp_setprim);
2888 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2893 case SCTP_HMAC_IDENT:
2895 struct sctp_hmacalgo *shmac;
2896 sctp_hmaclist_t *hmaclist;
2900 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2902 SCTP_INP_RLOCK(inp);
2903 hmaclist = inp->sctp_ep.local_hmacs;
2904 if (hmaclist == NULL) {
2905 /* no HMACs to return */
2906 *optsize = sizeof(*shmac);
2907 SCTP_INP_RUNLOCK(inp);
2910 /* is there room for all of the hmac ids? */
2911 size = sizeof(*shmac) + (hmaclist->num_algo *
2912 sizeof(shmac->shmac_idents[0]));
2913 if ((size_t)(*optsize) < size) {
2914 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2916 SCTP_INP_RUNLOCK(inp);
2919 /* copy in the list */
2920 shmac->shmac_number_of_idents = hmaclist->num_algo;
2921 for (i = 0; i < hmaclist->num_algo; i++) {
2922 shmac->shmac_idents[i] = hmaclist->hmac[i];
2924 SCTP_INP_RUNLOCK(inp);
2928 case SCTP_AUTH_ACTIVE_KEY:
2930 struct sctp_authkeyid *scact;
2932 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2933 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2936 /* get the active key on the assoc */
2937 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2938 SCTP_TCB_UNLOCK(stcb);
2940 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2941 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2942 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2943 /* get the endpoint active key */
2944 SCTP_INP_RLOCK(inp);
2945 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2946 SCTP_INP_RUNLOCK(inp);
2948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2953 *optsize = sizeof(struct sctp_authkeyid);
2957 case SCTP_LOCAL_AUTH_CHUNKS:
2959 struct sctp_authchunks *sac;
2960 sctp_auth_chklist_t *chklist = NULL;
2963 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2964 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2967 /* get off the assoc */
2968 chklist = stcb->asoc.local_auth_chunks;
2969 /* is there enough space? */
2970 size = sctp_auth_get_chklist_size(chklist);
2971 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2973 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2975 /* copy in the chunks */
2976 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2977 sac->gauth_number_of_chunks = (uint32_t) size;
2978 *optsize = sizeof(struct sctp_authchunks) + size;
2980 SCTP_TCB_UNLOCK(stcb);
2982 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2983 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2984 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2985 /* get off the endpoint */
2986 SCTP_INP_RLOCK(inp);
2987 chklist = inp->sctp_ep.local_auth_chunks;
2988 /* is there enough space? */
2989 size = sctp_auth_get_chklist_size(chklist);
2990 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2994 /* copy in the chunks */
2995 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2996 sac->gauth_number_of_chunks = (uint32_t) size;
2997 *optsize = sizeof(struct sctp_authchunks) + size;
2999 SCTP_INP_RUNLOCK(inp);
3001 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3007 case SCTP_PEER_AUTH_CHUNKS:
3009 struct sctp_authchunks *sac;
3010 sctp_auth_chklist_t *chklist = NULL;
3013 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
3014 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
3017 /* get off the assoc */
3018 chklist = stcb->asoc.peer_auth_chunks;
3019 /* is there enough space? */
3020 size = sctp_auth_get_chklist_size(chklist);
3021 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
3023 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3025 /* copy in the chunks */
3026 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3027 sac->gauth_number_of_chunks = (uint32_t) size;
3028 *optsize = sizeof(struct sctp_authchunks) + size;
3030 SCTP_TCB_UNLOCK(stcb);
3032 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3039 struct sctp_event *event;
3040 uint32_t event_type;
3042 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3043 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3045 switch (event->se_type) {
3046 case SCTP_ASSOC_CHANGE:
3047 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3049 case SCTP_PEER_ADDR_CHANGE:
3050 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3052 case SCTP_REMOTE_ERROR:
3053 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3055 case SCTP_SEND_FAILED:
3056 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3058 case SCTP_SHUTDOWN_EVENT:
3059 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3061 case SCTP_ADAPTATION_INDICATION:
3062 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3064 case SCTP_PARTIAL_DELIVERY_EVENT:
3065 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3067 case SCTP_AUTHENTICATION_EVENT:
3068 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3070 case SCTP_STREAM_RESET_EVENT:
3071 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3073 case SCTP_SENDER_DRY_EVENT:
3074 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3076 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3078 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3081 case SCTP_ASSOC_RESET_EVENT:
3082 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3084 case SCTP_STREAM_CHANGE_EVENT:
3085 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3087 case SCTP_SEND_FAILED_EVENT:
3088 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3092 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3096 if (event_type > 0) {
3098 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3099 SCTP_TCB_UNLOCK(stcb);
3101 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3102 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3103 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3104 SCTP_INP_RLOCK(inp);
3105 event->se_on = sctp_is_feature_on(inp, event_type);
3106 SCTP_INP_RUNLOCK(inp);
3108 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3114 *optsize = sizeof(struct sctp_event);
3118 case SCTP_RECVRCVINFO:
3122 if (*optsize < sizeof(int)) {
3123 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3126 SCTP_INP_RLOCK(inp);
3127 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3128 SCTP_INP_RUNLOCK(inp);
3131 /* return the option value */
3132 *(int *)optval = onoff;
3133 *optsize = sizeof(int);
3137 case SCTP_RECVNXTINFO:
3141 if (*optsize < sizeof(int)) {
3142 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3145 SCTP_INP_RLOCK(inp);
3146 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3147 SCTP_INP_RUNLOCK(inp);
3150 /* return the option value */
3151 *(int *)optval = onoff;
3152 *optsize = sizeof(int);
3156 case SCTP_DEFAULT_SNDINFO:
3158 struct sctp_sndinfo *info;
3160 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3161 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3164 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3165 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3166 info->snd_flags &= 0xfff0;
3167 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3168 info->snd_context = stcb->asoc.def_send.sinfo_context;
3169 SCTP_TCB_UNLOCK(stcb);
3171 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3172 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3173 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3174 SCTP_INP_RLOCK(inp);
3175 info->snd_sid = inp->def_send.sinfo_stream;
3176 info->snd_flags = inp->def_send.sinfo_flags;
3177 info->snd_flags &= 0xfff0;
3178 info->snd_ppid = inp->def_send.sinfo_ppid;
3179 info->snd_context = inp->def_send.sinfo_context;
3180 SCTP_INP_RUNLOCK(inp);
3182 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3187 *optsize = sizeof(struct sctp_sndinfo);
3191 case SCTP_DEFAULT_PRINFO:
3193 struct sctp_default_prinfo *info;
3195 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3196 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3199 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3200 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3201 SCTP_TCB_UNLOCK(stcb);
3203 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3204 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3205 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3206 SCTP_INP_RLOCK(inp);
3207 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3208 info->pr_value = inp->def_send.sinfo_timetolive;
3209 SCTP_INP_RUNLOCK(inp);
3211 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3216 *optsize = sizeof(struct sctp_default_prinfo);
3220 case SCTP_PEER_ADDR_THLDS:
3222 struct sctp_paddrthlds *thlds;
3223 struct sctp_nets *net;
3224 struct sockaddr *addr;
3226 #if defined(INET) && defined(INET6)
3227 struct sockaddr_in sin_store;
3231 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3232 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3234 #if defined(INET) && defined(INET6)
3235 if (thlds->spt_address.ss_family == AF_INET6) {
3236 struct sockaddr_in6 *sin6;
3238 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3239 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3240 in6_sin6_2_sin(&sin_store, sin6);
3241 addr = (struct sockaddr *)&sin_store;
3243 addr = (struct sockaddr *)&thlds->spt_address;
3246 addr = (struct sockaddr *)&thlds->spt_address;
3249 addr = (struct sockaddr *)&thlds->spt_address;
3252 net = sctp_findnet(stcb, addr);
3255 * We increment here since
3256 * sctp_findassociation_ep_addr() wil do a
3257 * decrement if it finds the stcb as long as
3258 * the locked tcb (last argument) is NOT a
3262 SCTP_INP_INCR_REF(inp);
3263 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3265 SCTP_INP_DECR_REF(inp);
3268 if ((stcb != NULL) && (net == NULL)) {
3270 if (addr->sa_family == AF_INET) {
3271 struct sockaddr_in *sin;
3273 sin = (struct sockaddr_in *)addr;
3274 if (sin->sin_addr.s_addr != INADDR_ANY) {
3276 SCTP_TCB_UNLOCK(stcb);
3277 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3283 if (addr->sa_family == AF_INET6) {
3284 struct sockaddr_in6 *sin6;
3286 sin6 = (struct sockaddr_in6 *)addr;
3287 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3289 SCTP_TCB_UNLOCK(stcb);
3290 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3296 error = EAFNOSUPPORT;
3297 SCTP_TCB_UNLOCK(stcb);
3298 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3304 thlds->spt_pathmaxrxt = net->failure_threshold;
3305 thlds->spt_pathpfthld = net->pf_threshold;
3307 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3308 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3310 thlds->spt_assoc_id = sctp_get_associd(stcb);
3311 SCTP_TCB_UNLOCK(stcb);
3313 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3314 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3315 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3316 /* Use endpoint defaults */
3317 SCTP_INP_RLOCK(inp);
3318 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3319 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3320 SCTP_INP_RUNLOCK(inp);
3322 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3327 *optsize = sizeof(struct sctp_paddrthlds);
3331 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3333 struct sctp_udpencaps *encaps;
3334 struct sctp_nets *net;
3335 struct sockaddr *addr;
3337 #if defined(INET) && defined(INET6)
3338 struct sockaddr_in sin_store;
3342 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3343 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3345 #if defined(INET) && defined(INET6)
3346 if (encaps->sue_address.ss_family == AF_INET6) {
3347 struct sockaddr_in6 *sin6;
3349 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3350 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3351 in6_sin6_2_sin(&sin_store, sin6);
3352 addr = (struct sockaddr *)&sin_store;
3354 addr = (struct sockaddr *)&encaps->sue_address;
3357 addr = (struct sockaddr *)&encaps->sue_address;
3360 addr = (struct sockaddr *)&encaps->sue_address;
3363 net = sctp_findnet(stcb, addr);
3366 * We increment here since
3367 * sctp_findassociation_ep_addr() wil do a
3368 * decrement if it finds the stcb as long as
3369 * the locked tcb (last argument) is NOT a
3373 SCTP_INP_INCR_REF(inp);
3374 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3376 SCTP_INP_DECR_REF(inp);
3379 if ((stcb != NULL) && (net == NULL)) {
3381 if (addr->sa_family == AF_INET) {
3382 struct sockaddr_in *sin;
3384 sin = (struct sockaddr_in *)addr;
3385 if (sin->sin_addr.s_addr != INADDR_ANY) {
3387 SCTP_TCB_UNLOCK(stcb);
3388 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3394 if (addr->sa_family == AF_INET6) {
3395 struct sockaddr_in6 *sin6;
3397 sin6 = (struct sockaddr_in6 *)addr;
3398 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3400 SCTP_TCB_UNLOCK(stcb);
3401 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3407 error = EAFNOSUPPORT;
3408 SCTP_TCB_UNLOCK(stcb);
3409 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3415 encaps->sue_port = net->port;
3417 encaps->sue_port = stcb->asoc.port;
3419 SCTP_TCB_UNLOCK(stcb);
3421 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3422 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3423 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3424 SCTP_INP_RLOCK(inp);
3425 encaps->sue_port = inp->sctp_ep.port;
3426 SCTP_INP_RUNLOCK(inp);
3428 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3433 *optsize = sizeof(struct sctp_udpencaps);
3437 case SCTP_ECN_SUPPORTED:
3439 struct sctp_assoc_value *av;
3441 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3442 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3445 av->assoc_value = stcb->asoc.ecn_supported;
3446 SCTP_TCB_UNLOCK(stcb);
3448 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3449 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3450 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3451 SCTP_INP_RLOCK(inp);
3452 av->assoc_value = inp->ecn_supported;
3453 SCTP_INP_RUNLOCK(inp);
3455 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3460 *optsize = sizeof(struct sctp_assoc_value);
3464 case SCTP_PR_SUPPORTED:
3466 struct sctp_assoc_value *av;
3468 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3469 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3472 av->assoc_value = stcb->asoc.prsctp_supported;
3473 SCTP_TCB_UNLOCK(stcb);
3475 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3476 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3477 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3478 SCTP_INP_RLOCK(inp);
3479 av->assoc_value = inp->prsctp_supported;
3480 SCTP_INP_RUNLOCK(inp);
3482 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3487 *optsize = sizeof(struct sctp_assoc_value);
3491 case SCTP_AUTH_SUPPORTED:
3493 struct sctp_assoc_value *av;
3495 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3496 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3499 av->assoc_value = stcb->asoc.auth_supported;
3500 SCTP_TCB_UNLOCK(stcb);
3502 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3503 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3504 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3505 SCTP_INP_RLOCK(inp);
3506 av->assoc_value = inp->auth_supported;
3507 SCTP_INP_RUNLOCK(inp);
3509 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3514 *optsize = sizeof(struct sctp_assoc_value);
3518 case SCTP_ASCONF_SUPPORTED:
3520 struct sctp_assoc_value *av;
3522 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3523 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3526 av->assoc_value = stcb->asoc.asconf_supported;
3527 SCTP_TCB_UNLOCK(stcb);
3529 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3530 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3531 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3532 SCTP_INP_RLOCK(inp);
3533 av->assoc_value = inp->asconf_supported;
3534 SCTP_INP_RUNLOCK(inp);
3536 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3541 *optsize = sizeof(struct sctp_assoc_value);
3545 case SCTP_RECONFIG_SUPPORTED:
3547 struct sctp_assoc_value *av;
3549 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3550 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3553 av->assoc_value = stcb->asoc.reconfig_supported;
3554 SCTP_TCB_UNLOCK(stcb);
3556 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3557 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3558 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3559 SCTP_INP_RLOCK(inp);
3560 av->assoc_value = inp->reconfig_supported;
3561 SCTP_INP_RUNLOCK(inp);
3563 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3568 *optsize = sizeof(struct sctp_assoc_value);
3572 case SCTP_NRSACK_SUPPORTED:
3574 struct sctp_assoc_value *av;
3576 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3577 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3580 av->assoc_value = stcb->asoc.nrsack_supported;
3581 SCTP_TCB_UNLOCK(stcb);
3583 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3584 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3585 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3586 SCTP_INP_RLOCK(inp);
3587 av->assoc_value = inp->nrsack_supported;
3588 SCTP_INP_RUNLOCK(inp);
3590 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3595 *optsize = sizeof(struct sctp_assoc_value);
3599 case SCTP_PKTDROP_SUPPORTED:
3601 struct sctp_assoc_value *av;
3603 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3604 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3607 av->assoc_value = stcb->asoc.pktdrop_supported;
3608 SCTP_TCB_UNLOCK(stcb);
3610 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3611 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3612 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3613 SCTP_INP_RLOCK(inp);
3614 av->assoc_value = inp->pktdrop_supported;
3615 SCTP_INP_RUNLOCK(inp);
3617 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3622 *optsize = sizeof(struct sctp_assoc_value);
3626 case SCTP_ENABLE_STREAM_RESET:
3628 struct sctp_assoc_value *av;
3630 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3631 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3634 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3635 SCTP_TCB_UNLOCK(stcb);
3637 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3638 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3639 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3640 SCTP_INP_RLOCK(inp);
3641 av->assoc_value = (uint32_t) inp->local_strreset_support;
3642 SCTP_INP_RUNLOCK(inp);
3644 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3649 *optsize = sizeof(struct sctp_assoc_value);
3653 case SCTP_PR_STREAM_STATUS:
3655 struct sctp_prstatus *sprstat;
3659 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3660 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3662 sid = sprstat->sprstat_sid;
3663 policy = sprstat->sprstat_policy;
3664 #if defined(SCTP_DETAILED_STR_STATS)
3665 if ((stcb != NULL) &&
3666 (sid < stcb->asoc.streamoutcnt) &&
3667 (policy != SCTP_PR_SCTP_NONE) &&
3668 ((policy <= SCTP_PR_SCTP_MAX) ||
3669 (policy == SCTP_PR_SCTP_ALL))) {
3670 if (policy == SCTP_PR_SCTP_ALL) {
3671 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3672 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3674 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3675 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3678 if ((stcb != NULL) &&
3679 (sid < stcb->asoc.streamoutcnt) &&
3680 (policy == SCTP_PR_SCTP_ALL)) {
3681 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3682 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3684 SCTP_TCB_UNLOCK(stcb);
3685 *optsize = sizeof(struct sctp_prstatus);
3687 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3692 case SCTP_PR_ASSOC_STATUS:
3694 struct sctp_prstatus *sprstat;
3697 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3698 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3700 policy = sprstat->sprstat_policy;
3701 if ((stcb != NULL) &&
3702 (policy != SCTP_PR_SCTP_NONE) &&
3703 ((policy <= SCTP_PR_SCTP_MAX) ||
3704 (policy == SCTP_PR_SCTP_ALL))) {
3705 if (policy == SCTP_PR_SCTP_ALL) {
3706 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3707 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3709 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3710 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3712 SCTP_TCB_UNLOCK(stcb);
3713 *optsize = sizeof(struct sctp_prstatus);
3715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3722 struct sctp_assoc_value *av;
3724 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3725 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3728 av->assoc_value = stcb->asoc.max_cwnd;
3729 SCTP_TCB_UNLOCK(stcb);
3731 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3732 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3733 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3734 SCTP_INP_RLOCK(inp);
3735 av->assoc_value = inp->max_cwnd;
3736 SCTP_INP_RUNLOCK(inp);
3738 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3743 *optsize = sizeof(struct sctp_assoc_value);
3748 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3749 error = ENOPROTOOPT;
3751 } /* end switch (sopt->sopt_name) */
3759 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3764 struct sctp_tcb *stcb = NULL;
3765 struct sctp_inpcb *inp = NULL;
3768 if (optval == NULL) {
3769 SCTP_PRINTF("optval is NULL\n");
3770 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3773 inp = (struct sctp_inpcb *)so->so_pcb;
3775 SCTP_PRINTF("inp is NULL?\n");
3776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3779 vrf_id = inp->def_vrf_id;
3784 case SCTP_AUTOCLOSE:
3785 case SCTP_AUTO_ASCONF:
3786 case SCTP_EXPLICIT_EOR:
3787 case SCTP_DISABLE_FRAGMENTS:
3788 case SCTP_USE_EXT_RCVINFO:
3789 case SCTP_I_WANT_MAPPED_V4_ADDR:
3790 /* copy in the option value */
3791 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3796 case SCTP_DISABLE_FRAGMENTS:
3797 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3799 case SCTP_AUTO_ASCONF:
3801 * NOTE: we don't really support this flag
3803 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3804 /* only valid for bound all sockets */
3805 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3807 /* forbidden by admin */
3808 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3811 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3813 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3817 case SCTP_EXPLICIT_EOR:
3818 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3820 case SCTP_USE_EXT_RCVINFO:
3821 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3823 case SCTP_I_WANT_MAPPED_V4_ADDR:
3824 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3825 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3827 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3832 set_opt = SCTP_PCB_FLAGS_NODELAY;
3834 case SCTP_AUTOCLOSE:
3835 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3836 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3837 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3840 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3842 * The value is in ticks. Note this does not effect
3843 * old associations, only new ones.
3845 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3848 SCTP_INP_WLOCK(inp);
3850 sctp_feature_on(inp, set_opt);
3852 sctp_feature_off(inp, set_opt);
3854 SCTP_INP_WUNLOCK(inp);
3856 case SCTP_REUSE_PORT:
3858 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3859 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3860 /* Can't set it after we are bound */
3864 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3865 /* Can't do this for a 1-m socket */
3870 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3872 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3875 case SCTP_PARTIAL_DELIVERY_POINT:
3879 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3880 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3885 inp->partial_delivery_point = *value;
3888 case SCTP_FRAGMENT_INTERLEAVE:
3889 /* not yet until we re-write sctp_recvmsg() */
3893 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3894 if (*level == SCTP_FRAG_LEVEL_2) {
3895 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3896 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3897 } else if (*level == SCTP_FRAG_LEVEL_1) {
3898 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3899 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3900 } else if (*level == SCTP_FRAG_LEVEL_0) {
3901 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3902 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3905 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3910 case SCTP_INTERLEAVING_SUPPORTED:
3912 struct sctp_assoc_value *av;
3914 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3915 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3918 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3920 SCTP_TCB_UNLOCK(stcb);
3922 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3923 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3924 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3925 SCTP_INP_WLOCK(inp);
3926 if (av->assoc_value == 0) {
3927 inp->idata_supported = 0;
3929 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
3930 (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) {
3931 inp->idata_supported = 1;
3939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3943 SCTP_INP_WUNLOCK(inp);
3945 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3951 case SCTP_CMT_ON_OFF:
3952 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3953 struct sctp_assoc_value *av;
3955 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3956 if (av->assoc_value > SCTP_CMT_MAX) {
3957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3961 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3963 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3964 SCTP_TCB_UNLOCK(stcb);
3966 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3967 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3968 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3969 (av->assoc_id == SCTP_ALL_ASSOC)) {
3970 SCTP_INP_WLOCK(inp);
3971 inp->sctp_cmt_on_off = av->assoc_value;
3972 SCTP_INP_WUNLOCK(inp);
3974 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3975 (av->assoc_id == SCTP_ALL_ASSOC)) {
3976 SCTP_INP_RLOCK(inp);
3977 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3978 SCTP_TCB_LOCK(stcb);
3979 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3980 SCTP_TCB_UNLOCK(stcb);
3982 SCTP_INP_RUNLOCK(inp);
3986 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3987 error = ENOPROTOOPT;
3990 case SCTP_PLUGGABLE_CC:
3992 struct sctp_assoc_value *av;
3993 struct sctp_nets *net;
3995 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3996 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3997 (av->assoc_value != SCTP_CC_HSTCP) &&
3998 (av->assoc_value != SCTP_CC_HTCP) &&
3999 (av->assoc_value != SCTP_CC_RTCC)) {
4000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4004 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4006 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4007 stcb->asoc.congestion_control_module = av->assoc_value;
4008 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4009 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4010 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4013 SCTP_TCB_UNLOCK(stcb);
4015 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4016 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4017 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4018 (av->assoc_id == SCTP_ALL_ASSOC)) {
4019 SCTP_INP_WLOCK(inp);
4020 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
4021 SCTP_INP_WUNLOCK(inp);
4023 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4024 (av->assoc_id == SCTP_ALL_ASSOC)) {
4025 SCTP_INP_RLOCK(inp);
4026 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4027 SCTP_TCB_LOCK(stcb);
4028 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
4029 stcb->asoc.congestion_control_module = av->assoc_value;
4030 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
4031 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4032 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
4035 SCTP_TCB_UNLOCK(stcb);
4037 SCTP_INP_RUNLOCK(inp);
4042 case SCTP_CC_OPTION:
4044 struct sctp_cc_option *cc_opt;
4046 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
4047 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
4049 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
4050 SCTP_INP_RLOCK(inp);
4051 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4052 SCTP_TCB_LOCK(stcb);
4053 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
4054 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
4056 SCTP_TCB_UNLOCK(stcb);
4058 SCTP_INP_RUNLOCK(inp);
4063 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4066 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4069 SCTP_TCB_UNLOCK(stcb);
4073 case SCTP_PLUGGABLE_SS:
4075 struct sctp_assoc_value *av;
4077 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4078 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4079 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4080 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4081 (av->assoc_value != SCTP_SS_PRIORITY) &&
4082 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4083 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4084 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4088 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4090 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4091 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4092 stcb->asoc.stream_scheduling_module = av->assoc_value;
4093 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4094 SCTP_TCB_UNLOCK(stcb);
4096 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4097 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4098 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4099 (av->assoc_id == SCTP_ALL_ASSOC)) {
4100 SCTP_INP_WLOCK(inp);
4101 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4102 SCTP_INP_WUNLOCK(inp);
4104 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4105 (av->assoc_id == SCTP_ALL_ASSOC)) {
4106 SCTP_INP_RLOCK(inp);
4107 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4108 SCTP_TCB_LOCK(stcb);
4109 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4110 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4111 stcb->asoc.stream_scheduling_module = av->assoc_value;
4112 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4113 SCTP_TCB_UNLOCK(stcb);
4115 SCTP_INP_RUNLOCK(inp);
4122 struct sctp_stream_value *av;
4124 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4125 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4127 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4128 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4129 av->stream_value) < 0)) {
4130 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4133 SCTP_TCB_UNLOCK(stcb);
4135 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4136 SCTP_INP_RLOCK(inp);
4137 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4138 SCTP_TCB_LOCK(stcb);
4139 if (av->stream_id < stcb->asoc.streamoutcnt) {
4140 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4142 &stcb->asoc.strmout[av->stream_id],
4145 SCTP_TCB_UNLOCK(stcb);
4147 SCTP_INP_RUNLOCK(inp);
4150 * Can't set stream value without
4153 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4159 case SCTP_CLR_STAT_LOG:
4160 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4165 struct sctp_assoc_value *av;
4167 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4168 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4171 stcb->asoc.context = av->assoc_value;
4172 SCTP_TCB_UNLOCK(stcb);
4174 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4175 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4176 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4177 (av->assoc_id == SCTP_ALL_ASSOC)) {
4178 SCTP_INP_WLOCK(inp);
4179 inp->sctp_context = av->assoc_value;
4180 SCTP_INP_WUNLOCK(inp);
4182 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4183 (av->assoc_id == SCTP_ALL_ASSOC)) {
4184 SCTP_INP_RLOCK(inp);
4185 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4186 SCTP_TCB_LOCK(stcb);
4187 stcb->asoc.context = av->assoc_value;
4188 SCTP_TCB_UNLOCK(stcb);
4190 SCTP_INP_RUNLOCK(inp);
4197 uint32_t *default_vrfid;
4199 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4200 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4201 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4205 inp->def_vrf_id = *default_vrfid;
4208 case SCTP_DEL_VRF_ID:
4210 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4214 case SCTP_ADD_VRF_ID:
4216 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4220 case SCTP_DELAYED_SACK:
4222 struct sctp_sack_info *sack;
4224 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4225 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4226 if (sack->sack_delay) {
4227 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4228 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4229 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4230 sack->sack_delay = TICKS_TO_MSEC(1);
4234 if (sack->sack_delay) {
4235 stcb->asoc.delayed_ack = sack->sack_delay;
4237 if (sack->sack_freq) {
4238 stcb->asoc.sack_freq = sack->sack_freq;
4240 SCTP_TCB_UNLOCK(stcb);
4242 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4243 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4244 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4245 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4246 SCTP_INP_WLOCK(inp);
4247 if (sack->sack_delay) {
4248 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4250 if (sack->sack_freq) {
4251 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4253 SCTP_INP_WUNLOCK(inp);
4255 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4256 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4257 SCTP_INP_RLOCK(inp);
4258 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4259 SCTP_TCB_LOCK(stcb);
4260 if (sack->sack_delay) {
4261 stcb->asoc.delayed_ack = sack->sack_delay;
4263 if (sack->sack_freq) {
4264 stcb->asoc.sack_freq = sack->sack_freq;
4266 SCTP_TCB_UNLOCK(stcb);
4268 SCTP_INP_RUNLOCK(inp);
4273 case SCTP_AUTH_CHUNK:
4275 struct sctp_authchunk *sauth;
4277 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4279 SCTP_INP_WLOCK(inp);
4280 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4281 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4284 SCTP_INP_WUNLOCK(inp);
4289 struct sctp_authkey *sca;
4290 struct sctp_keyhead *shared_keys;
4291 sctp_sharedkey_t *shared_key;
4292 sctp_key_t *key = NULL;
4295 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4296 if (sca->sca_keylength == 0) {
4297 size = optsize - sizeof(struct sctp_authkey);
4299 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4300 size = sca->sca_keylength;
4302 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4307 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4310 shared_keys = &stcb->asoc.shared_keys;
4311 /* clear the cached keys for this key id */
4312 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4314 * create the new shared key and
4318 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4320 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4322 SCTP_TCB_UNLOCK(stcb);
4326 shared_key = sctp_alloc_sharedkey();
4327 if (shared_key == NULL) {
4329 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4331 SCTP_TCB_UNLOCK(stcb);
4334 shared_key->key = key;
4335 shared_key->keyid = sca->sca_keynumber;
4336 error = sctp_insert_sharedkey(shared_keys, shared_key);
4337 SCTP_TCB_UNLOCK(stcb);
4339 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4340 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4341 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4342 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4343 SCTP_INP_WLOCK(inp);
4344 shared_keys = &inp->sctp_ep.shared_keys;
4346 * clear the cached keys on all
4347 * assocs for this key id
4349 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4351 * create the new shared key and
4355 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4357 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4359 SCTP_INP_WUNLOCK(inp);
4363 shared_key = sctp_alloc_sharedkey();
4364 if (shared_key == NULL) {
4366 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4368 SCTP_INP_WUNLOCK(inp);
4371 shared_key->key = key;
4372 shared_key->keyid = sca->sca_keynumber;
4373 error = sctp_insert_sharedkey(shared_keys, shared_key);
4374 SCTP_INP_WUNLOCK(inp);
4376 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4377 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4378 SCTP_INP_RLOCK(inp);
4379 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4380 SCTP_TCB_LOCK(stcb);
4381 shared_keys = &stcb->asoc.shared_keys;
4383 * clear the cached keys for
4386 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4388 * create the new shared key
4389 * and insert/replace it
4392 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4394 SCTP_TCB_UNLOCK(stcb);
4398 shared_key = sctp_alloc_sharedkey();
4399 if (shared_key == NULL) {
4401 SCTP_TCB_UNLOCK(stcb);
4404 shared_key->key = key;
4405 shared_key->keyid = sca->sca_keynumber;
4406 error = sctp_insert_sharedkey(shared_keys, shared_key);
4407 SCTP_TCB_UNLOCK(stcb);
4409 SCTP_INP_RUNLOCK(inp);
4414 case SCTP_HMAC_IDENT:
4416 struct sctp_hmacalgo *shmac;
4417 sctp_hmaclist_t *hmaclist;
4421 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4422 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4423 (shmac->shmac_number_of_idents > 0xffff)) {
4424 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4428 hmaclist = sctp_alloc_hmaclist((uint16_t) shmac->shmac_number_of_idents);
4429 if (hmaclist == NULL) {
4430 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4434 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4435 hmacid = shmac->shmac_idents[i];
4436 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4437 /* invalid HMACs were found */ ;
4438 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4440 sctp_free_hmaclist(hmaclist);
4441 goto sctp_set_hmac_done;
4444 for (i = 0; i < hmaclist->num_algo; i++) {
4445 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4446 /* already in list */
4450 if (i == hmaclist->num_algo) {
4451 /* not found in list */
4452 sctp_free_hmaclist(hmaclist);
4453 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4457 /* set it on the endpoint */
4458 SCTP_INP_WLOCK(inp);
4459 if (inp->sctp_ep.local_hmacs)
4460 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4461 inp->sctp_ep.local_hmacs = hmaclist;
4462 SCTP_INP_WUNLOCK(inp);
4466 case SCTP_AUTH_ACTIVE_KEY:
4468 struct sctp_authkeyid *scact;
4470 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4471 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4473 /* set the active key on the right place */
4475 /* set the active key on the assoc */
4476 if (sctp_auth_setactivekey(stcb,
4477 scact->scact_keynumber)) {
4478 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4479 SCTP_FROM_SCTP_USRREQ,
4483 SCTP_TCB_UNLOCK(stcb);
4485 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4486 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4487 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4488 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4489 SCTP_INP_WLOCK(inp);
4490 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4491 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4494 SCTP_INP_WUNLOCK(inp);
4496 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4497 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4498 SCTP_INP_RLOCK(inp);
4499 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4500 SCTP_TCB_LOCK(stcb);
4501 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4502 SCTP_TCB_UNLOCK(stcb);
4504 SCTP_INP_RUNLOCK(inp);
4509 case SCTP_AUTH_DELETE_KEY:
4511 struct sctp_authkeyid *scdel;
4513 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4514 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4516 /* delete the key from the right place */
4518 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4519 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4522 SCTP_TCB_UNLOCK(stcb);
4524 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4525 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4526 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4527 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4528 SCTP_INP_WLOCK(inp);
4529 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4530 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4533 SCTP_INP_WUNLOCK(inp);
4535 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4536 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4537 SCTP_INP_RLOCK(inp);
4538 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4539 SCTP_TCB_LOCK(stcb);
4540 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4541 SCTP_TCB_UNLOCK(stcb);
4543 SCTP_INP_RUNLOCK(inp);
4548 case SCTP_AUTH_DEACTIVATE_KEY:
4550 struct sctp_authkeyid *keyid;
4552 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4553 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4555 /* deactivate the key from the right place */
4557 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4558 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4561 SCTP_TCB_UNLOCK(stcb);
4563 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4564 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4565 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4566 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4567 SCTP_INP_WLOCK(inp);
4568 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4569 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4572 SCTP_INP_WUNLOCK(inp);
4574 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4575 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4576 SCTP_INP_RLOCK(inp);
4577 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4578 SCTP_TCB_LOCK(stcb);
4579 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4580 SCTP_TCB_UNLOCK(stcb);
4582 SCTP_INP_RUNLOCK(inp);
4587 case SCTP_ENABLE_STREAM_RESET:
4589 struct sctp_assoc_value *av;
4591 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4592 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4593 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4597 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4599 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4600 SCTP_TCB_UNLOCK(stcb);
4602 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4603 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4604 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4605 (av->assoc_id == SCTP_ALL_ASSOC)) {
4606 SCTP_INP_WLOCK(inp);
4607 inp->local_strreset_support = (uint8_t) av->assoc_value;
4608 SCTP_INP_WUNLOCK(inp);
4610 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4611 (av->assoc_id == SCTP_ALL_ASSOC)) {
4612 SCTP_INP_RLOCK(inp);
4613 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4614 SCTP_TCB_LOCK(stcb);
4615 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4616 SCTP_TCB_UNLOCK(stcb);
4618 SCTP_INP_RUNLOCK(inp);
4623 case SCTP_RESET_STREAMS:
4625 struct sctp_reset_streams *strrst;
4626 int i, send_out = 0;
4629 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4630 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4632 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4636 if (stcb->asoc.reconfig_supported == 0) {
4638 * Peer does not support the chunk type.
4640 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4642 SCTP_TCB_UNLOCK(stcb);
4645 if (sizeof(struct sctp_reset_streams) +
4646 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4648 SCTP_TCB_UNLOCK(stcb);
4651 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4653 if (stcb->asoc.stream_reset_outstanding) {
4654 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4656 SCTP_TCB_UNLOCK(stcb);
4660 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4663 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4664 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4666 SCTP_TCB_UNLOCK(stcb);
4669 if ((send_in == 0) && (send_out == 0)) {
4670 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4672 SCTP_TCB_UNLOCK(stcb);
4675 for (i = 0; i < strrst->srs_number_streams; i++) {
4677 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4678 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4683 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4684 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4690 SCTP_TCB_UNLOCK(stcb);
4697 if (strrst->srs_number_streams) {
4698 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4699 strm = strrst->srs_stream_list[i];
4700 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4701 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4707 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4708 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4709 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4716 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4717 strrst->srs_stream_list,
4718 send_in, 0, 0, 0, 0, 0);
4720 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4723 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4726 * For outgoing streams don't report any
4727 * problems in sending the request to the
4728 * application. XXX: Double check resetting
4733 SCTP_TCB_UNLOCK(stcb);
4736 case SCTP_ADD_STREAMS:
4738 struct sctp_add_streams *stradd;
4739 uint8_t addstream = 0;
4740 uint16_t add_o_strmcnt = 0;
4741 uint16_t add_i_strmcnt = 0;
4743 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4744 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4746 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4750 if (stcb->asoc.reconfig_supported == 0) {
4752 * Peer does not support the chunk type.
4754 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4756 SCTP_TCB_UNLOCK(stcb);
4759 if (stcb->asoc.stream_reset_outstanding) {
4760 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4762 SCTP_TCB_UNLOCK(stcb);
4765 if ((stradd->sas_outstrms == 0) &&
4766 (stradd->sas_instrms == 0)) {
4770 if (stradd->sas_outstrms) {
4772 /* We allocate here */
4773 add_o_strmcnt = stradd->sas_outstrms;
4774 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4775 /* You can't have more than 64k */
4780 if (stradd->sas_instrms) {
4785 * We allocate inside
4786 * sctp_send_str_reset_req()
4788 add_i_strmcnt = stradd->sas_instrms;
4789 cnt = add_i_strmcnt;
4790 cnt += stcb->asoc.streamincnt;
4791 if (cnt > 0x0000ffff) {
4792 /* You can't have more than 64k */
4796 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4797 /* More than you are allowed */
4802 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4803 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4805 SCTP_TCB_UNLOCK(stcb);
4808 case SCTP_RESET_ASSOC:
4813 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4814 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4816 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4820 if (stcb->asoc.reconfig_supported == 0) {
4822 * Peer does not support the chunk type.
4824 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4826 SCTP_TCB_UNLOCK(stcb);
4829 if (stcb->asoc.stream_reset_outstanding) {
4830 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4832 SCTP_TCB_UNLOCK(stcb);
4836 * Is there any data pending in the send or sent
4839 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4840 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4843 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4844 SCTP_TCB_UNLOCK(stcb);
4847 /* Do any streams have data queued? */
4848 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4849 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4853 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4854 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4855 SCTP_TCB_UNLOCK(stcb);
4858 case SCTP_CONNECT_X:
4859 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4860 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4864 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4866 case SCTP_CONNECT_X_DELAYED:
4867 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4868 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4872 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4874 case SCTP_CONNECT_X_COMPLETE:
4876 struct sockaddr *sa;
4878 /* FIXME MT: check correct? */
4879 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4882 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4883 SCTP_INP_RLOCK(inp);
4884 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4886 SCTP_TCB_LOCK(stcb);
4888 SCTP_INP_RUNLOCK(inp);
4891 * We increment here since
4892 * sctp_findassociation_ep_addr() wil do a
4893 * decrement if it finds the stcb as long as
4894 * the locked tcb (last argument) is NOT a
4897 SCTP_INP_INCR_REF(inp);
4898 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4900 SCTP_INP_DECR_REF(inp);
4905 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4909 if (stcb->asoc.delayed_connection == 1) {
4910 stcb->asoc.delayed_connection = 0;
4911 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4912 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4913 stcb->asoc.primary_destination,
4914 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4915 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4918 * already expired or did not use delayed
4921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4924 SCTP_TCB_UNLOCK(stcb);
4927 case SCTP_MAX_BURST:
4929 struct sctp_assoc_value *av;
4931 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4932 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4935 stcb->asoc.max_burst = av->assoc_value;
4936 SCTP_TCB_UNLOCK(stcb);
4938 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4939 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4940 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4941 (av->assoc_id == SCTP_ALL_ASSOC)) {
4942 SCTP_INP_WLOCK(inp);
4943 inp->sctp_ep.max_burst = av->assoc_value;
4944 SCTP_INP_WUNLOCK(inp);
4946 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4947 (av->assoc_id == SCTP_ALL_ASSOC)) {
4948 SCTP_INP_RLOCK(inp);
4949 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4950 SCTP_TCB_LOCK(stcb);
4951 stcb->asoc.max_burst = av->assoc_value;
4952 SCTP_TCB_UNLOCK(stcb);
4954 SCTP_INP_RUNLOCK(inp);
4961 struct sctp_assoc_value *av;
4964 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4965 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4967 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4968 ovh = SCTP_MED_OVERHEAD;
4970 ovh = SCTP_MED_V4_OVERHEAD;
4973 if (av->assoc_value) {
4974 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4976 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4978 SCTP_TCB_UNLOCK(stcb);
4980 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4981 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4982 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4983 SCTP_INP_WLOCK(inp);
4985 * FIXME MT: I think this is not in
4986 * tune with the API ID
4988 if (av->assoc_value) {
4989 inp->sctp_frag_point = (av->assoc_value + ovh);
4991 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4993 SCTP_INP_WUNLOCK(inp);
4995 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5003 struct sctp_event_subscribe *events;
5005 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
5007 SCTP_INP_WLOCK(inp);
5008 if (events->sctp_data_io_event) {
5009 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5011 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
5014 if (events->sctp_association_event) {
5015 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5017 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5020 if (events->sctp_address_event) {
5021 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5023 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
5026 if (events->sctp_send_failure_event) {
5027 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5029 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5032 if (events->sctp_peer_error_event) {
5033 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5035 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
5038 if (events->sctp_shutdown_event) {
5039 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5041 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5044 if (events->sctp_partial_delivery_event) {
5045 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5047 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
5050 if (events->sctp_adaptation_layer_event) {
5051 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5053 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5056 if (events->sctp_authentication_event) {
5057 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5059 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
5062 if (events->sctp_sender_dry_event) {
5063 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5065 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5068 if (events->sctp_stream_reset_event) {
5069 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5071 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5073 SCTP_INP_WUNLOCK(inp);
5075 SCTP_INP_RLOCK(inp);
5076 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5077 SCTP_TCB_LOCK(stcb);
5078 if (events->sctp_association_event) {
5079 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5081 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5083 if (events->sctp_address_event) {
5084 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5086 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5088 if (events->sctp_send_failure_event) {
5089 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5091 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5093 if (events->sctp_peer_error_event) {
5094 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5096 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5098 if (events->sctp_shutdown_event) {
5099 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5101 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5103 if (events->sctp_partial_delivery_event) {
5104 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5106 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5108 if (events->sctp_adaptation_layer_event) {
5109 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5111 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5113 if (events->sctp_authentication_event) {
5114 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5116 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5118 if (events->sctp_sender_dry_event) {
5119 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5121 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5123 if (events->sctp_stream_reset_event) {
5124 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5126 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5128 SCTP_TCB_UNLOCK(stcb);
5131 * Send up the sender dry event only for 1-to-1
5134 if (events->sctp_sender_dry_event) {
5135 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5136 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5137 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5139 SCTP_TCB_LOCK(stcb);
5140 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5141 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5142 (stcb->asoc.stream_queue_cnt == 0)) {
5143 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5145 SCTP_TCB_UNLOCK(stcb);
5149 SCTP_INP_RUNLOCK(inp);
5152 case SCTP_ADAPTATION_LAYER:
5154 struct sctp_setadaptation *adap_bits;
5156 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5157 SCTP_INP_WLOCK(inp);
5158 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5159 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5160 SCTP_INP_WUNLOCK(inp);
5164 case SCTP_SET_INITIAL_DBG_SEQ:
5168 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5169 SCTP_INP_WLOCK(inp);
5170 inp->sctp_ep.initial_sequence_debug = *vvv;
5171 SCTP_INP_WUNLOCK(inp);
5175 case SCTP_DEFAULT_SEND_PARAM:
5177 struct sctp_sndrcvinfo *s_info;
5179 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5180 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5183 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5184 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5189 SCTP_TCB_UNLOCK(stcb);
5191 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5192 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5193 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5194 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5195 SCTP_INP_WLOCK(inp);
5196 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5197 SCTP_INP_WUNLOCK(inp);
5199 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5200 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5201 SCTP_INP_RLOCK(inp);
5202 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5203 SCTP_TCB_LOCK(stcb);
5204 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5205 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5207 SCTP_TCB_UNLOCK(stcb);
5209 SCTP_INP_RUNLOCK(inp);
5214 case SCTP_PEER_ADDR_PARAMS:
5216 struct sctp_paddrparams *paddrp;
5217 struct sctp_nets *net;
5218 struct sockaddr *addr;
5220 #if defined(INET) && defined(INET6)
5221 struct sockaddr_in sin_store;
5225 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5226 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5228 #if defined(INET) && defined(INET6)
5229 if (paddrp->spp_address.ss_family == AF_INET6) {
5230 struct sockaddr_in6 *sin6;
5232 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5233 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5234 in6_sin6_2_sin(&sin_store, sin6);
5235 addr = (struct sockaddr *)&sin_store;
5237 addr = (struct sockaddr *)&paddrp->spp_address;
5240 addr = (struct sockaddr *)&paddrp->spp_address;
5243 addr = (struct sockaddr *)&paddrp->spp_address;
5246 net = sctp_findnet(stcb, addr);
5249 * We increment here since
5250 * sctp_findassociation_ep_addr() wil do a
5251 * decrement if it finds the stcb as long as
5252 * the locked tcb (last argument) is NOT a
5256 SCTP_INP_INCR_REF(inp);
5257 stcb = sctp_findassociation_ep_addr(&inp, addr,
5260 SCTP_INP_DECR_REF(inp);
5263 if ((stcb != NULL) && (net == NULL)) {
5265 if (addr->sa_family == AF_INET) {
5267 struct sockaddr_in *sin;
5269 sin = (struct sockaddr_in *)addr;
5270 if (sin->sin_addr.s_addr != INADDR_ANY) {
5271 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5272 SCTP_TCB_UNLOCK(stcb);
5279 if (addr->sa_family == AF_INET6) {
5280 struct sockaddr_in6 *sin6;
5282 sin6 = (struct sockaddr_in6 *)addr;
5283 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5284 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5285 SCTP_TCB_UNLOCK(stcb);
5292 error = EAFNOSUPPORT;
5293 SCTP_TCB_UNLOCK(stcb);
5294 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5299 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5301 SCTP_TCB_UNLOCK(stcb);
5302 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5305 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5307 SCTP_TCB_UNLOCK(stcb);
5308 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5312 /************************TCB SPECIFIC SET ******************/
5314 /************************NET SPECIFIC SET ******************/
5315 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5316 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5317 !(net->dest_state & SCTP_ADDR_NOHB)) {
5318 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5319 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5321 net->dest_state |= SCTP_ADDR_NOHB;
5323 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5324 if (paddrp->spp_hbinterval) {
5325 net->heart_beat_delay = paddrp->spp_hbinterval;
5326 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5327 net->heart_beat_delay = 0;
5329 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5330 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5331 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5332 net->dest_state &= ~SCTP_ADDR_NOHB;
5334 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5336 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5337 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5338 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5340 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5341 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5342 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5343 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5345 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5346 net->mtu = paddrp->spp_pathmtu;
5347 switch (net->ro._l_addr.sa.sa_family) {
5350 net->mtu += SCTP_MIN_V4_OVERHEAD;
5355 net->mtu += SCTP_MIN_OVERHEAD;
5361 if (net->mtu < stcb->asoc.smallest_mtu) {
5362 sctp_pathmtu_adjustment(stcb, net->mtu);
5365 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5366 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5367 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5369 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5371 if (paddrp->spp_pathmaxrxt) {
5372 if (net->dest_state & SCTP_ADDR_PF) {
5373 if (net->error_count > paddrp->spp_pathmaxrxt) {
5374 net->dest_state &= ~SCTP_ADDR_PF;
5377 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5378 (net->error_count > net->pf_threshold)) {
5379 net->dest_state |= SCTP_ADDR_PF;
5380 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5381 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5382 stcb->sctp_ep, stcb, net,
5383 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5384 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5387 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5388 if (net->error_count > paddrp->spp_pathmaxrxt) {
5389 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5390 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5393 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5394 net->dest_state |= SCTP_ADDR_REACHABLE;
5395 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5398 net->failure_threshold = paddrp->spp_pathmaxrxt;
5400 if (paddrp->spp_flags & SPP_DSCP) {
5401 net->dscp = paddrp->spp_dscp & 0xfc;
5405 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5406 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5407 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5408 net->flowlabel |= 0x80000000;
5413 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5414 if (paddrp->spp_pathmaxrxt != 0) {
5415 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5416 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5417 if (net->dest_state & SCTP_ADDR_PF) {
5418 if (net->error_count > paddrp->spp_pathmaxrxt) {
5419 net->dest_state &= ~SCTP_ADDR_PF;
5422 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5423 (net->error_count > net->pf_threshold)) {
5424 net->dest_state |= SCTP_ADDR_PF;
5425 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5426 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5427 stcb->sctp_ep, stcb, net,
5428 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5429 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5432 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5433 if (net->error_count > paddrp->spp_pathmaxrxt) {
5434 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5435 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5438 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5439 net->dest_state |= SCTP_ADDR_REACHABLE;
5440 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5443 net->failure_threshold = paddrp->spp_pathmaxrxt;
5446 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5447 if (paddrp->spp_hbinterval != 0) {
5448 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5449 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5450 stcb->asoc.heart_beat_delay = 0;
5452 /* Turn back on the timer */
5453 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5454 if (paddrp->spp_hbinterval != 0) {
5455 net->heart_beat_delay = paddrp->spp_hbinterval;
5456 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5457 net->heart_beat_delay = 0;
5459 if (net->dest_state & SCTP_ADDR_NOHB) {
5460 net->dest_state &= ~SCTP_ADDR_NOHB;
5462 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5463 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5464 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5466 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5468 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5469 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5470 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5471 net->dest_state |= SCTP_ADDR_NOHB;
5472 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5473 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5475 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5479 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5481 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5482 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5483 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5484 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5485 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5487 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5488 net->mtu = paddrp->spp_pathmtu;
5489 switch (net->ro._l_addr.sa.sa_family) {
5492 net->mtu += SCTP_MIN_V4_OVERHEAD;
5497 net->mtu += SCTP_MIN_OVERHEAD;
5503 if (net->mtu < stcb->asoc.smallest_mtu) {
5504 sctp_pathmtu_adjustment(stcb, net->mtu);
5507 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5509 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5510 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5511 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5512 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5514 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5516 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5518 if (paddrp->spp_flags & SPP_DSCP) {
5519 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5520 net->dscp = paddrp->spp_dscp & 0xfc;
5523 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5524 stcb->asoc.default_dscp |= 0x01;
5527 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5528 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5529 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5530 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5531 net->flowlabel |= 0x80000000;
5534 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5535 stcb->asoc.default_flowlabel |= 0x80000000;
5539 SCTP_TCB_UNLOCK(stcb);
5541 /************************NO TCB, SET TO default stuff ******************/
5542 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5543 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5544 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5545 SCTP_INP_WLOCK(inp);
5547 * For the TOS/FLOWLABEL stuff you
5548 * set it with the options on the
5551 if (paddrp->spp_pathmaxrxt != 0) {
5552 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5554 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5555 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5556 else if (paddrp->spp_hbinterval != 0) {
5557 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5558 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5559 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5561 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5562 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5563 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5564 } else if (paddrp->spp_hbinterval) {
5565 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5567 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5568 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5569 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5571 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5572 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5573 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5574 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5576 if (paddrp->spp_flags & SPP_DSCP) {
5577 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5578 inp->sctp_ep.default_dscp |= 0x01;
5581 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5582 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5583 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5584 inp->sctp_ep.default_flowlabel |= 0x80000000;
5588 SCTP_INP_WUNLOCK(inp);
5590 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5598 struct sctp_rtoinfo *srto;
5599 uint32_t new_init, new_min, new_max;
5601 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5602 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5605 if (srto->srto_initial)
5606 new_init = srto->srto_initial;
5608 new_init = stcb->asoc.initial_rto;
5610 new_max = srto->srto_max;
5612 new_max = stcb->asoc.maxrto;
5614 new_min = srto->srto_min;
5616 new_min = stcb->asoc.minrto;
5617 if ((new_min <= new_init) && (new_init <= new_max)) {
5618 stcb->asoc.initial_rto = new_init;
5619 stcb->asoc.maxrto = new_max;
5620 stcb->asoc.minrto = new_min;
5622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5625 SCTP_TCB_UNLOCK(stcb);
5627 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5628 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5629 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5630 SCTP_INP_WLOCK(inp);
5631 if (srto->srto_initial)
5632 new_init = srto->srto_initial;
5634 new_init = inp->sctp_ep.initial_rto;
5636 new_max = srto->srto_max;
5638 new_max = inp->sctp_ep.sctp_maxrto;
5640 new_min = srto->srto_min;
5642 new_min = inp->sctp_ep.sctp_minrto;
5643 if ((new_min <= new_init) && (new_init <= new_max)) {
5644 inp->sctp_ep.initial_rto = new_init;
5645 inp->sctp_ep.sctp_maxrto = new_max;
5646 inp->sctp_ep.sctp_minrto = new_min;
5648 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5651 SCTP_INP_WUNLOCK(inp);
5653 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5659 case SCTP_ASSOCINFO:
5661 struct sctp_assocparams *sasoc;
5663 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5664 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5665 if (sasoc->sasoc_cookie_life) {
5666 /* boundary check the cookie life */
5667 if (sasoc->sasoc_cookie_life < 1000)
5668 sasoc->sasoc_cookie_life = 1000;
5669 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5670 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5674 if (sasoc->sasoc_asocmaxrxt)
5675 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5676 if (sasoc->sasoc_cookie_life) {
5677 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5679 SCTP_TCB_UNLOCK(stcb);
5681 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5682 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5683 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5684 SCTP_INP_WLOCK(inp);
5685 if (sasoc->sasoc_asocmaxrxt)
5686 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5687 if (sasoc->sasoc_cookie_life) {
5688 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5690 SCTP_INP_WUNLOCK(inp);
5692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5700 struct sctp_initmsg *sinit;
5702 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5703 SCTP_INP_WLOCK(inp);
5704 if (sinit->sinit_num_ostreams)
5705 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5707 if (sinit->sinit_max_instreams)
5708 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5710 if (sinit->sinit_max_attempts)
5711 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5713 if (sinit->sinit_max_init_timeo)
5714 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5715 SCTP_INP_WUNLOCK(inp);
5718 case SCTP_PRIMARY_ADDR:
5720 struct sctp_setprim *spa;
5721 struct sctp_nets *net;
5722 struct sockaddr *addr;
5724 #if defined(INET) && defined(INET6)
5725 struct sockaddr_in sin_store;
5729 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5730 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5732 #if defined(INET) && defined(INET6)
5733 if (spa->ssp_addr.ss_family == AF_INET6) {
5734 struct sockaddr_in6 *sin6;
5736 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5737 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5738 in6_sin6_2_sin(&sin_store, sin6);
5739 addr = (struct sockaddr *)&sin_store;
5741 addr = (struct sockaddr *)&spa->ssp_addr;
5744 addr = (struct sockaddr *)&spa->ssp_addr;
5747 addr = (struct sockaddr *)&spa->ssp_addr;
5750 net = sctp_findnet(stcb, addr);
5753 * We increment here since
5754 * sctp_findassociation_ep_addr() wil do a
5755 * decrement if it finds the stcb as long as
5756 * the locked tcb (last argument) is NOT a
5760 SCTP_INP_INCR_REF(inp);
5761 stcb = sctp_findassociation_ep_addr(&inp, addr,
5764 SCTP_INP_DECR_REF(inp);
5768 if ((stcb != NULL) && (net != NULL)) {
5769 if (net != stcb->asoc.primary_destination) {
5770 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5771 /* Ok we need to set it */
5772 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5773 if ((stcb->asoc.alternate) &&
5774 (!(net->dest_state & SCTP_ADDR_PF)) &&
5775 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5776 sctp_free_remote_addr(stcb->asoc.alternate);
5777 stcb->asoc.alternate = NULL;
5780 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5784 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5789 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5793 SCTP_TCB_UNLOCK(stcb);
5797 case SCTP_SET_DYNAMIC_PRIMARY:
5799 union sctp_sockstore *ss;
5801 error = priv_check(curthread,
5802 PRIV_NETINET_RESERVEDPORT);
5806 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5807 /* SUPER USER CHECK? */
5808 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5811 case SCTP_SET_PEER_PRIMARY_ADDR:
5813 struct sctp_setpeerprim *sspp;
5814 struct sockaddr *addr;
5816 #if defined(INET) && defined(INET6)
5817 struct sockaddr_in sin_store;
5821 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5822 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5824 struct sctp_ifa *ifa;
5826 #if defined(INET) && defined(INET6)
5827 if (sspp->sspp_addr.ss_family == AF_INET6) {
5828 struct sockaddr_in6 *sin6;
5830 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5831 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5832 in6_sin6_2_sin(&sin_store, sin6);
5833 addr = (struct sockaddr *)&sin_store;
5835 addr = (struct sockaddr *)&sspp->sspp_addr;
5838 addr = (struct sockaddr *)&sspp->sspp_addr;
5841 addr = (struct sockaddr *)&sspp->sspp_addr;
5843 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5845 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5849 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5851 * Must validate the ifa found is in
5854 struct sctp_laddr *laddr;
5857 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5858 if (laddr->ifa == NULL) {
5859 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5863 if ((sctp_is_addr_restricted(stcb, laddr->ifa)) &&
5864 (!sctp_is_addr_pending(stcb, laddr->ifa))) {
5867 if (laddr->ifa == ifa) {
5873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5878 switch (addr->sa_family) {
5882 struct sockaddr_in *sin;
5884 sin = (struct sockaddr_in *)addr;
5885 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5886 &sin->sin_addr) != 0) {
5887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5897 struct sockaddr_in6 *sin6;
5899 sin6 = (struct sockaddr_in6 *)addr;
5900 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5901 &sin6->sin6_addr) != 0) {
5902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5915 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5919 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5921 SCTP_TCB_UNLOCK(stcb);
5923 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5928 case SCTP_BINDX_ADD_ADDR:
5930 struct sctp_getaddresses *addrs;
5933 td = (struct thread *)p;
5934 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5937 if (addrs->addr->sa_family == AF_INET) {
5938 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5943 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5944 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5950 if (addrs->addr->sa_family == AF_INET6) {
5951 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5952 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5956 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5957 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5958 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5964 error = EAFNOSUPPORT;
5967 sctp_bindx_add_address(so, inp, addrs->addr,
5968 addrs->sget_assoc_id, vrf_id,
5972 case SCTP_BINDX_REM_ADDR:
5974 struct sctp_getaddresses *addrs;
5977 td = (struct thread *)p;
5979 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5981 if (addrs->addr->sa_family == AF_INET) {
5982 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5983 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5987 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5988 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5994 if (addrs->addr->sa_family == AF_INET6) {
5995 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5996 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6001 (error = prison_local_ip6(td->td_ucred,
6002 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
6003 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
6004 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
6010 error = EAFNOSUPPORT;
6013 sctp_bindx_delete_address(inp, addrs->addr,
6014 addrs->sget_assoc_id, vrf_id,
6020 struct sctp_event *event;
6021 uint32_t event_type;
6023 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
6024 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
6025 switch (event->se_type) {
6026 case SCTP_ASSOC_CHANGE:
6027 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
6029 case SCTP_PEER_ADDR_CHANGE:
6030 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
6032 case SCTP_REMOTE_ERROR:
6033 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
6035 case SCTP_SEND_FAILED:
6036 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
6038 case SCTP_SHUTDOWN_EVENT:
6039 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
6041 case SCTP_ADAPTATION_INDICATION:
6042 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
6044 case SCTP_PARTIAL_DELIVERY_EVENT:
6045 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
6047 case SCTP_AUTHENTICATION_EVENT:
6048 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
6050 case SCTP_STREAM_RESET_EVENT:
6051 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
6053 case SCTP_SENDER_DRY_EVENT:
6054 event_type = SCTP_PCB_FLAGS_DRYEVNT;
6056 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
6058 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6061 case SCTP_ASSOC_RESET_EVENT:
6062 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
6064 case SCTP_STREAM_CHANGE_EVENT:
6065 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
6067 case SCTP_SEND_FAILED_EVENT:
6068 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6072 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6076 if (event_type > 0) {
6079 sctp_stcb_feature_on(inp, stcb, event_type);
6080 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6081 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6082 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6083 (stcb->asoc.stream_queue_cnt == 0)) {
6084 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6088 sctp_stcb_feature_off(inp, stcb, event_type);
6090 SCTP_TCB_UNLOCK(stcb);
6093 * We don't want to send up a storm
6094 * of events, so return an error for
6097 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6098 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6099 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6100 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6101 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6102 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6106 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6107 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6108 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6109 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6110 SCTP_INP_WLOCK(inp);
6112 sctp_feature_on(inp, event_type);
6114 sctp_feature_off(inp, event_type);
6116 SCTP_INP_WUNLOCK(inp);
6118 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6119 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6120 SCTP_INP_RLOCK(inp);
6121 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6122 SCTP_TCB_LOCK(stcb);
6124 sctp_stcb_feature_on(inp, stcb, event_type);
6126 sctp_stcb_feature_off(inp, stcb, event_type);
6128 SCTP_TCB_UNLOCK(stcb);
6130 SCTP_INP_RUNLOCK(inp);
6136 case SCTP_RECVRCVINFO:
6140 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6141 SCTP_INP_WLOCK(inp);
6143 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6145 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6147 SCTP_INP_WUNLOCK(inp);
6150 case SCTP_RECVNXTINFO:
6154 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6155 SCTP_INP_WLOCK(inp);
6157 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6159 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6161 SCTP_INP_WUNLOCK(inp);
6164 case SCTP_DEFAULT_SNDINFO:
6166 struct sctp_sndinfo *info;
6169 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6170 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6173 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6174 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6175 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6176 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6177 stcb->asoc.def_send.sinfo_flags |= policy;
6178 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6179 stcb->asoc.def_send.sinfo_context = info->snd_context;
6181 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6184 SCTP_TCB_UNLOCK(stcb);
6186 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6187 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6188 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6189 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6190 SCTP_INP_WLOCK(inp);
6191 inp->def_send.sinfo_stream = info->snd_sid;
6192 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6193 inp->def_send.sinfo_flags = info->snd_flags;
6194 inp->def_send.sinfo_flags |= policy;
6195 inp->def_send.sinfo_ppid = info->snd_ppid;
6196 inp->def_send.sinfo_context = info->snd_context;
6197 SCTP_INP_WUNLOCK(inp);
6199 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6200 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6201 SCTP_INP_RLOCK(inp);
6202 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6203 SCTP_TCB_LOCK(stcb);
6204 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6205 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6206 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6207 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6208 stcb->asoc.def_send.sinfo_flags |= policy;
6209 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6210 stcb->asoc.def_send.sinfo_context = info->snd_context;
6212 SCTP_TCB_UNLOCK(stcb);
6214 SCTP_INP_RUNLOCK(inp);
6219 case SCTP_DEFAULT_PRINFO:
6221 struct sctp_default_prinfo *info;
6223 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6224 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6226 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6227 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6232 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6233 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6234 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6235 SCTP_TCB_UNLOCK(stcb);
6237 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6238 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6239 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6240 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6241 SCTP_INP_WLOCK(inp);
6242 inp->def_send.sinfo_flags &= 0xfff0;
6243 inp->def_send.sinfo_flags |= info->pr_policy;
6244 inp->def_send.sinfo_timetolive = info->pr_value;
6245 SCTP_INP_WUNLOCK(inp);
6247 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6248 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6249 SCTP_INP_RLOCK(inp);
6250 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6251 SCTP_TCB_LOCK(stcb);
6252 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6253 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6254 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6255 SCTP_TCB_UNLOCK(stcb);
6257 SCTP_INP_RUNLOCK(inp);
6262 case SCTP_PEER_ADDR_THLDS:
6263 /* Applies to the specific association */
6265 struct sctp_paddrthlds *thlds;
6266 struct sctp_nets *net;
6267 struct sockaddr *addr;
6269 #if defined(INET) && defined(INET6)
6270 struct sockaddr_in sin_store;
6274 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6275 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6277 #if defined(INET) && defined(INET6)
6278 if (thlds->spt_address.ss_family == AF_INET6) {
6279 struct sockaddr_in6 *sin6;
6281 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6282 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6283 in6_sin6_2_sin(&sin_store, sin6);
6284 addr = (struct sockaddr *)&sin_store;
6286 addr = (struct sockaddr *)&thlds->spt_address;
6289 addr = (struct sockaddr *)&thlds->spt_address;
6292 addr = (struct sockaddr *)&thlds->spt_address;
6295 net = sctp_findnet(stcb, addr);
6298 * We increment here since
6299 * sctp_findassociation_ep_addr() wil do a
6300 * decrement if it finds the stcb as long as
6301 * the locked tcb (last argument) is NOT a
6305 SCTP_INP_INCR_REF(inp);
6306 stcb = sctp_findassociation_ep_addr(&inp, addr,
6309 SCTP_INP_DECR_REF(inp);
6312 if ((stcb != NULL) && (net == NULL)) {
6314 if (addr->sa_family == AF_INET) {
6316 struct sockaddr_in *sin;
6318 sin = (struct sockaddr_in *)addr;
6319 if (sin->sin_addr.s_addr != INADDR_ANY) {
6320 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6321 SCTP_TCB_UNLOCK(stcb);
6328 if (addr->sa_family == AF_INET6) {
6329 struct sockaddr_in6 *sin6;
6331 sin6 = (struct sockaddr_in6 *)addr;
6332 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6333 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6334 SCTP_TCB_UNLOCK(stcb);
6341 error = EAFNOSUPPORT;
6342 SCTP_TCB_UNLOCK(stcb);
6343 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6349 net->failure_threshold = thlds->spt_pathmaxrxt;
6350 net->pf_threshold = thlds->spt_pathpfthld;
6351 if (net->dest_state & SCTP_ADDR_PF) {
6352 if ((net->error_count > net->failure_threshold) ||
6353 (net->error_count <= net->pf_threshold)) {
6354 net->dest_state &= ~SCTP_ADDR_PF;
6357 if ((net->error_count > net->pf_threshold) &&
6358 (net->error_count <= net->failure_threshold)) {
6359 net->dest_state |= SCTP_ADDR_PF;
6360 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6361 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6362 stcb->sctp_ep, stcb, net,
6363 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6364 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6367 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6368 if (net->error_count > net->failure_threshold) {
6369 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6370 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6373 if (net->error_count <= net->failure_threshold) {
6374 net->dest_state |= SCTP_ADDR_REACHABLE;
6375 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6379 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6380 net->failure_threshold = thlds->spt_pathmaxrxt;
6381 net->pf_threshold = thlds->spt_pathpfthld;
6382 if (net->dest_state & SCTP_ADDR_PF) {
6383 if ((net->error_count > net->failure_threshold) ||
6384 (net->error_count <= net->pf_threshold)) {
6385 net->dest_state &= ~SCTP_ADDR_PF;
6388 if ((net->error_count > net->pf_threshold) &&
6389 (net->error_count <= net->failure_threshold)) {
6390 net->dest_state |= SCTP_ADDR_PF;
6391 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6392 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6393 stcb->sctp_ep, stcb, net,
6394 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6395 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6398 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6399 if (net->error_count > net->failure_threshold) {
6400 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6401 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6404 if (net->error_count <= net->failure_threshold) {
6405 net->dest_state |= SCTP_ADDR_REACHABLE;
6406 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6410 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6411 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6413 SCTP_TCB_UNLOCK(stcb);
6415 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6416 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6417 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6418 SCTP_INP_WLOCK(inp);
6419 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6420 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6421 SCTP_INP_WUNLOCK(inp);
6423 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6429 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6431 struct sctp_udpencaps *encaps;
6432 struct sctp_nets *net;
6433 struct sockaddr *addr;
6435 #if defined(INET) && defined(INET6)
6436 struct sockaddr_in sin_store;
6440 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6441 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6443 #if defined(INET) && defined(INET6)
6444 if (encaps->sue_address.ss_family == AF_INET6) {
6445 struct sockaddr_in6 *sin6;
6447 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6448 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6449 in6_sin6_2_sin(&sin_store, sin6);
6450 addr = (struct sockaddr *)&sin_store;
6452 addr = (struct sockaddr *)&encaps->sue_address;
6455 addr = (struct sockaddr *)&encaps->sue_address;
6458 addr = (struct sockaddr *)&encaps->sue_address;
6461 net = sctp_findnet(stcb, addr);
6464 * We increment here since
6465 * sctp_findassociation_ep_addr() wil do a
6466 * decrement if it finds the stcb as long as
6467 * the locked tcb (last argument) is NOT a
6471 SCTP_INP_INCR_REF(inp);
6472 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6474 SCTP_INP_DECR_REF(inp);
6477 if ((stcb != NULL) && (net == NULL)) {
6479 if (addr->sa_family == AF_INET) {
6481 struct sockaddr_in *sin;
6483 sin = (struct sockaddr_in *)addr;
6484 if (sin->sin_addr.s_addr != INADDR_ANY) {
6485 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6486 SCTP_TCB_UNLOCK(stcb);
6493 if (addr->sa_family == AF_INET6) {
6494 struct sockaddr_in6 *sin6;
6496 sin6 = (struct sockaddr_in6 *)addr;
6497 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6498 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6499 SCTP_TCB_UNLOCK(stcb);
6506 error = EAFNOSUPPORT;
6507 SCTP_TCB_UNLOCK(stcb);
6508 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6514 net->port = encaps->sue_port;
6516 stcb->asoc.port = encaps->sue_port;
6518 SCTP_TCB_UNLOCK(stcb);
6520 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6521 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6522 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6523 SCTP_INP_WLOCK(inp);
6524 inp->sctp_ep.port = encaps->sue_port;
6525 SCTP_INP_WUNLOCK(inp);
6527 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6533 case SCTP_ECN_SUPPORTED:
6535 struct sctp_assoc_value *av;
6537 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6538 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6541 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6543 SCTP_TCB_UNLOCK(stcb);
6545 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6546 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6547 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6548 SCTP_INP_WLOCK(inp);
6549 if (av->assoc_value == 0) {
6550 inp->ecn_supported = 0;
6552 inp->ecn_supported = 1;
6554 SCTP_INP_WUNLOCK(inp);
6556 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6562 case SCTP_PR_SUPPORTED:
6564 struct sctp_assoc_value *av;
6566 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6567 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6570 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6572 SCTP_TCB_UNLOCK(stcb);
6574 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6575 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6576 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6577 SCTP_INP_WLOCK(inp);
6578 if (av->assoc_value == 0) {
6579 inp->prsctp_supported = 0;
6581 inp->prsctp_supported = 1;
6583 SCTP_INP_WUNLOCK(inp);
6585 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6591 case SCTP_AUTH_SUPPORTED:
6593 struct sctp_assoc_value *av;
6595 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6596 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6599 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6601 SCTP_TCB_UNLOCK(stcb);
6603 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6604 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6605 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6606 if ((av->assoc_value == 0) &&
6607 (inp->asconf_supported == 1)) {
6609 * AUTH is required for
6612 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6615 SCTP_INP_WLOCK(inp);
6616 if (av->assoc_value == 0) {
6617 inp->auth_supported = 0;
6619 inp->auth_supported = 1;
6621 SCTP_INP_WUNLOCK(inp);
6624 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6630 case SCTP_ASCONF_SUPPORTED:
6632 struct sctp_assoc_value *av;
6634 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6635 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6638 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6640 SCTP_TCB_UNLOCK(stcb);
6642 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6643 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6644 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6645 if ((av->assoc_value != 0) &&
6646 (inp->auth_supported == 0)) {
6648 * AUTH is required for
6651 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6654 SCTP_INP_WLOCK(inp);
6655 if (av->assoc_value == 0) {
6656 inp->asconf_supported = 0;
6657 sctp_auth_delete_chunk(SCTP_ASCONF,
6658 inp->sctp_ep.local_auth_chunks);
6659 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6660 inp->sctp_ep.local_auth_chunks);
6662 inp->asconf_supported = 1;
6663 sctp_auth_add_chunk(SCTP_ASCONF,
6664 inp->sctp_ep.local_auth_chunks);
6665 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6666 inp->sctp_ep.local_auth_chunks);
6668 SCTP_INP_WUNLOCK(inp);
6671 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6677 case SCTP_RECONFIG_SUPPORTED:
6679 struct sctp_assoc_value *av;
6681 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6682 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6687 SCTP_TCB_UNLOCK(stcb);
6689 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6690 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6691 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6692 SCTP_INP_WLOCK(inp);
6693 if (av->assoc_value == 0) {
6694 inp->reconfig_supported = 0;
6696 inp->reconfig_supported = 1;
6698 SCTP_INP_WUNLOCK(inp);
6700 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6706 case SCTP_NRSACK_SUPPORTED:
6708 struct sctp_assoc_value *av;
6710 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6711 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6714 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6716 SCTP_TCB_UNLOCK(stcb);
6718 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6719 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6720 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6721 SCTP_INP_WLOCK(inp);
6722 if (av->assoc_value == 0) {
6723 inp->nrsack_supported = 0;
6725 inp->nrsack_supported = 1;
6727 SCTP_INP_WUNLOCK(inp);
6729 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6735 case SCTP_PKTDROP_SUPPORTED:
6737 struct sctp_assoc_value *av;
6739 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6740 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6743 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6745 SCTP_TCB_UNLOCK(stcb);
6747 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6748 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6749 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6750 SCTP_INP_WLOCK(inp);
6751 if (av->assoc_value == 0) {
6752 inp->pktdrop_supported = 0;
6754 inp->pktdrop_supported = 1;
6756 SCTP_INP_WUNLOCK(inp);
6758 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6766 struct sctp_assoc_value *av;
6767 struct sctp_nets *net;
6769 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6770 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6773 stcb->asoc.max_cwnd = av->assoc_value;
6774 if (stcb->asoc.max_cwnd > 0) {
6775 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6776 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6777 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6778 net->cwnd = stcb->asoc.max_cwnd;
6779 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6780 net->cwnd = net->mtu - sizeof(struct sctphdr);
6785 SCTP_TCB_UNLOCK(stcb);
6787 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6788 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6789 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6790 SCTP_INP_WLOCK(inp);
6791 inp->max_cwnd = av->assoc_value;
6792 SCTP_INP_WUNLOCK(inp);
6794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6801 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6802 error = ENOPROTOOPT;
6804 } /* end switch (opt) */
6809 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6811 void *optval = NULL;
6815 struct sctp_inpcb *inp;
6817 if ((sopt->sopt_level == SOL_SOCKET) &&
6818 (sopt->sopt_name == SO_SETFIB)) {
6819 inp = (struct sctp_inpcb *)so->so_pcb;
6821 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6824 SCTP_INP_WLOCK(inp);
6825 inp->fibnum = so->so_fibnum;
6826 SCTP_INP_WUNLOCK(inp);
6829 if (sopt->sopt_level != IPPROTO_SCTP) {
6830 /* wrong proto level... send back up to IP */
6832 if (INP_CHECK_SOCKAF(so, AF_INET6))
6833 error = ip6_ctloutput(so, sopt);
6835 #if defined(INET) && defined(INET6)
6839 error = ip_ctloutput(so, sopt);
6843 optsize = sopt->sopt_valsize;
6845 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6846 if (optval == NULL) {
6847 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6850 error = sooptcopyin(sopt, optval, optsize, optsize);
6852 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6856 p = (void *)sopt->sopt_td;
6857 if (sopt->sopt_dir == SOPT_SET) {
6858 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6859 } else if (sopt->sopt_dir == SOPT_GET) {
6860 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6862 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6865 if ((error == 0) && (optval != NULL)) {
6866 error = sooptcopyout(sopt, optval, optsize);
6867 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6868 } else if (optval != NULL) {
6869 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6877 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6880 int create_lock_on = 0;
6882 struct sctp_inpcb *inp;
6883 struct sctp_tcb *stcb = NULL;
6885 inp = (struct sctp_inpcb *)so->so_pcb;
6887 /* I made the same as TCP since we are not setup? */
6888 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6889 return (ECONNRESET);
6892 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6895 switch (addr->sa_family) {
6899 struct sockaddr_in6 *sin6p;
6901 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6905 sin6p = (struct sockaddr_in6 *)addr;
6906 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6907 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6916 struct sockaddr_in *sinp;
6918 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6919 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6922 sinp = (struct sockaddr_in *)addr;
6923 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6931 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6932 return (EAFNOSUPPORT);
6934 SCTP_INP_INCR_REF(inp);
6935 SCTP_ASOC_CREATE_LOCK(inp);
6939 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6940 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6941 /* Should I really unlock ? */
6942 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6947 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6948 (addr->sa_family == AF_INET6)) {
6949 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6954 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6955 SCTP_PCB_FLAGS_UNBOUND) {
6956 /* Bind a ephemeral port */
6957 error = sctp_inpcb_bind(so, NULL, NULL, p);
6962 /* Now do we connect? */
6963 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6964 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6969 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6970 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6971 /* We are already connected AND the TCP model */
6972 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6976 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6977 SCTP_INP_RLOCK(inp);
6978 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6979 SCTP_INP_RUNLOCK(inp);
6982 * We increment here since sctp_findassociation_ep_addr()
6983 * will do a decrement if it finds the stcb as long as the
6984 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6986 SCTP_INP_INCR_REF(inp);
6987 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6989 SCTP_INP_DECR_REF(inp);
6991 SCTP_TCB_UNLOCK(stcb);
6995 /* Already have or am bring up an association */
6996 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
7000 vrf_id = inp->def_vrf_id;
7001 /* We are GOOD to go */
7002 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, inp->sctp_ep.pre_open_stream_count, p);
7004 /* Gak! no memory */
7007 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
7008 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
7009 /* Set the connected flag so we can queue data */
7012 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
7013 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
7015 /* initialize authentication parameters for the assoc */
7016 sctp_initialize_auth_params(inp, stcb);
7018 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
7019 SCTP_TCB_UNLOCK(stcb);
7021 if (create_lock_on) {
7022 SCTP_ASOC_CREATE_UNLOCK(inp);
7024 SCTP_INP_DECR_REF(inp);
7031 sctp_listen(struct socket *so, int backlog, struct thread *p)
7034 * Note this module depends on the protocol processing being called
7035 * AFTER any socket level flags and backlog are applied to the
7036 * socket. The traditional way that the socket flags are applied is
7037 * AFTER protocol processing. We have made a change to the
7038 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
7039 * place if the socket API for SCTP is to work properly.
7043 struct sctp_inpcb *inp;
7045 inp = (struct sctp_inpcb *)so->so_pcb;
7047 /* I made the same as TCP since we are not setup? */
7048 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7049 return (ECONNRESET);
7051 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
7052 /* See if we have a listener */
7053 struct sctp_inpcb *tinp;
7054 union sctp_sockstore store;
7056 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
7058 struct sctp_laddr *laddr;
7060 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7061 memcpy(&store, &laddr->ifa->address, sizeof(store));
7062 switch (store.sa.sa_family) {
7065 store.sin.sin_port = inp->sctp_lport;
7070 store.sin6.sin6_port = inp->sctp_lport;
7076 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7077 if (tinp && (tinp != inp) &&
7078 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7079 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7080 (tinp->sctp_socket->so_qlimit)) {
7082 * we have a listener already and
7085 SCTP_INP_DECR_REF(tinp);
7086 return (EADDRINUSE);
7088 SCTP_INP_DECR_REF(tinp);
7092 /* Setup a local addr bound all */
7093 memset(&store, 0, sizeof(store));
7095 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7096 store.sa.sa_family = AF_INET6;
7097 store.sa.sa_len = sizeof(struct sockaddr_in6);
7101 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7102 store.sa.sa_family = AF_INET;
7103 store.sa.sa_len = sizeof(struct sockaddr_in);
7106 switch (store.sa.sa_family) {
7109 store.sin.sin_port = inp->sctp_lport;
7114 store.sin6.sin6_port = inp->sctp_lport;
7120 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7121 if (tinp && (tinp != inp) &&
7122 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7123 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7124 (tinp->sctp_socket->so_qlimit)) {
7126 * we have a listener already and its not
7129 SCTP_INP_DECR_REF(tinp);
7130 return (EADDRINUSE);
7132 SCTP_INP_DECR_REF(tinp);
7136 SCTP_INP_RLOCK(inp);
7137 #ifdef SCTP_LOCK_LOGGING
7138 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7139 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7143 error = solisten_proto_check(so);
7146 SCTP_INP_RUNLOCK(inp);
7149 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7150 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7152 * The unlucky case - We are in the tcp pool with this guy.
7153 * - Someone else is in the main inp slot. - We must move
7154 * this guy (the listener) to the main slot - We must then
7155 * move the guy that was listener to the TCP Pool.
7157 if (sctp_swap_inpcb_for_listen(inp)) {
7158 SCTP_INP_RUNLOCK(inp);
7159 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7160 return (EADDRINUSE);
7163 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7164 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7165 /* We are already connected AND the TCP model */
7166 SCTP_INP_RUNLOCK(inp);
7167 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7168 return (EADDRINUSE);
7170 SCTP_INP_RUNLOCK(inp);
7171 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7172 /* We must do a bind. */
7173 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7174 /* bind error, probably perm */
7179 /* It appears for 7.0 and on, we must always call this. */
7180 solisten_proto(so, backlog);
7181 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7182 /* remove the ACCEPTCONN flag for one-to-many sockets */
7183 so->so_options &= ~SO_ACCEPTCONN;
7186 /* turning off listen */
7187 so->so_options &= ~SO_ACCEPTCONN;
7193 static int sctp_defered_wakeup_cnt = 0;
7196 sctp_accept(struct socket *so, struct sockaddr **addr)
7198 struct sctp_tcb *stcb;
7199 struct sctp_inpcb *inp;
7200 union sctp_sockstore store;
7206 inp = (struct sctp_inpcb *)so->so_pcb;
7209 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7210 return (ECONNRESET);
7212 SCTP_INP_RLOCK(inp);
7213 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7214 SCTP_INP_RUNLOCK(inp);
7215 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7216 return (EOPNOTSUPP);
7218 if (so->so_state & SS_ISDISCONNECTED) {
7219 SCTP_INP_RUNLOCK(inp);
7220 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7221 return (ECONNABORTED);
7223 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7225 SCTP_INP_RUNLOCK(inp);
7226 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7227 return (ECONNRESET);
7229 SCTP_TCB_LOCK(stcb);
7230 SCTP_INP_RUNLOCK(inp);
7231 store = stcb->asoc.primary_destination->ro._l_addr;
7232 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7233 SCTP_TCB_UNLOCK(stcb);
7234 switch (store.sa.sa_family) {
7238 struct sockaddr_in *sin;
7240 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7243 sin->sin_family = AF_INET;
7244 sin->sin_len = sizeof(*sin);
7245 sin->sin_port = store.sin.sin_port;
7246 sin->sin_addr = store.sin.sin_addr;
7247 *addr = (struct sockaddr *)sin;
7254 struct sockaddr_in6 *sin6;
7256 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7259 sin6->sin6_family = AF_INET6;
7260 sin6->sin6_len = sizeof(*sin6);
7261 sin6->sin6_port = store.sin6.sin6_port;
7262 sin6->sin6_addr = store.sin6.sin6_addr;
7263 if ((error = sa6_recoverscope(sin6)) != 0) {
7264 SCTP_FREE_SONAME(sin6);
7267 *addr = (struct sockaddr *)sin6;
7275 /* Wake any delayed sleep action */
7276 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7277 SCTP_INP_WLOCK(inp);
7278 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7279 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7280 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7281 SCTP_INP_WUNLOCK(inp);
7282 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7283 if (sowriteable(inp->sctp_socket)) {
7284 sowwakeup_locked(inp->sctp_socket);
7286 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7288 SCTP_INP_WLOCK(inp);
7290 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7291 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7292 SCTP_INP_WUNLOCK(inp);
7293 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7294 if (soreadable(inp->sctp_socket)) {
7295 sctp_defered_wakeup_cnt++;
7296 sorwakeup_locked(inp->sctp_socket);
7298 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7300 SCTP_INP_WLOCK(inp);
7302 SCTP_INP_WUNLOCK(inp);
7304 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7305 SCTP_TCB_LOCK(stcb);
7306 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7307 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7314 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7316 struct sockaddr_in *sin;
7318 struct sctp_inpcb *inp;
7319 struct sctp_ifa *sctp_ifa;
7322 * Do the malloc first in case it blocks.
7324 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7327 sin->sin_family = AF_INET;
7328 sin->sin_len = sizeof(*sin);
7329 inp = (struct sctp_inpcb *)so->so_pcb;
7331 SCTP_FREE_SONAME(sin);
7332 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7333 return (ECONNRESET);
7335 SCTP_INP_RLOCK(inp);
7336 sin->sin_port = inp->sctp_lport;
7337 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7338 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7339 struct sctp_tcb *stcb;
7340 struct sockaddr_in *sin_a;
7341 struct sctp_nets *net;
7344 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7350 SCTP_TCB_LOCK(stcb);
7351 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7352 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7354 /* this will make coverity happy */
7357 if (sin_a->sin_family == AF_INET) {
7362 if ((!fnd) || (sin_a == NULL)) {
7364 SCTP_TCB_UNLOCK(stcb);
7367 vrf_id = inp->def_vrf_id;
7368 sctp_ifa = sctp_source_address_selection(inp,
7370 (sctp_route_t *) & net->ro,
7373 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7374 sctp_free_ifa(sctp_ifa);
7376 SCTP_TCB_UNLOCK(stcb);
7378 /* For the bound all case you get back 0 */
7380 sin->sin_addr.s_addr = 0;
7384 /* Take the first IPv4 address in the list */
7385 struct sctp_laddr *laddr;
7388 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7389 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7390 struct sockaddr_in *sin_a;
7392 sin_a = &laddr->ifa->address.sin;
7393 sin->sin_addr = sin_a->sin_addr;
7399 SCTP_FREE_SONAME(sin);
7400 SCTP_INP_RUNLOCK(inp);
7401 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7405 SCTP_INP_RUNLOCK(inp);
7406 (*addr) = (struct sockaddr *)sin;
7411 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7413 struct sockaddr_in *sin;
7415 struct sockaddr_in *sin_a;
7416 struct sctp_inpcb *inp;
7417 struct sctp_tcb *stcb;
7418 struct sctp_nets *net;
7420 /* Do the malloc first in case it blocks. */
7421 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7424 sin->sin_family = AF_INET;
7425 sin->sin_len = sizeof(*sin);
7427 inp = (struct sctp_inpcb *)so->so_pcb;
7428 if ((inp == NULL) ||
7429 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7430 /* UDP type and listeners will drop out here */
7431 SCTP_FREE_SONAME(sin);
7432 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7435 SCTP_INP_RLOCK(inp);
7436 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7438 SCTP_TCB_LOCK(stcb);
7440 SCTP_INP_RUNLOCK(inp);
7442 SCTP_FREE_SONAME(sin);
7443 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7444 return (ECONNRESET);
7447 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7448 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7449 if (sin_a->sin_family == AF_INET) {
7451 sin->sin_port = stcb->rport;
7452 sin->sin_addr = sin_a->sin_addr;
7456 SCTP_TCB_UNLOCK(stcb);
7458 /* No IPv4 address */
7459 SCTP_FREE_SONAME(sin);
7460 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7463 (*addr) = (struct sockaddr *)sin;
7467 struct pr_usrreqs sctp_usrreqs = {
7468 .pru_abort = sctp_abort,
7469 .pru_accept = sctp_accept,
7470 .pru_attach = sctp_attach,
7471 .pru_bind = sctp_bind,
7472 .pru_connect = sctp_connect,
7473 .pru_control = in_control,
7474 .pru_close = sctp_close,
7475 .pru_detach = sctp_close,
7476 .pru_sopoll = sopoll_generic,
7477 .pru_flush = sctp_flush,
7478 .pru_disconnect = sctp_disconnect,
7479 .pru_listen = sctp_listen,
7480 .pru_peeraddr = sctp_peeraddr,
7481 .pru_send = sctp_sendm,
7482 .pru_shutdown = sctp_shutdown,
7483 .pru_sockaddr = sctp_ingetaddr,
7484 .pru_sosend = sctp_sosend,
7485 .pru_soreceive = sctp_soreceive