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 struct sctp_cc_functions sctp_cc_functions[];
58 extern 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 (uintptr_t) chk->whoTo,
136 chk->rec.data.TSN_seq);
138 /* Clear any time so NO RTT is being done */
147 sctp_notify_mbuf(struct sctp_inpcb *inp,
148 struct sctp_tcb *stcb,
149 struct sctp_nets *net,
154 int totsz, tmr_stopped = 0;
158 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
159 (ip == NULL) || (sh == NULL)) {
161 SCTP_TCB_UNLOCK(stcb);
165 /* First job is to verify the vtag matches what I would send */
166 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
167 SCTP_TCB_UNLOCK(stcb);
170 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
172 if (icmph->icmp_type != ICMP_UNREACH) {
173 /* We only care about unreachable */
174 SCTP_TCB_UNLOCK(stcb);
177 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
178 /* not a unreachable message due to frag. */
179 SCTP_TCB_UNLOCK(stcb);
182 totsz = ntohs(ip->ip_len);
184 nxtsz = ntohs(icmph->icmp_nextmtu);
187 * old type router that does not tell us what the next size
188 * mtu is. Rats we will have to guess (in a educated fashion
191 nxtsz = sctp_get_prev_mtu(totsz);
193 /* Stop any PMTU timer */
194 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
196 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
197 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
199 /* Adjust destination size limit */
200 if (net->mtu > nxtsz) {
203 net->mtu -= sizeof(struct udphdr);
206 /* now what about the ep? */
207 if (stcb->asoc.smallest_mtu > nxtsz) {
208 sctp_pathmtu_adjustment(stcb, nxtsz);
211 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
213 SCTP_TCB_UNLOCK(stcb);
217 sctp_notify(struct sctp_inpcb *inp,
221 struct sctp_tcb *stcb,
222 struct sctp_nets *net)
224 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
231 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
232 (sh == NULL) || (to == NULL)) {
234 SCTP_TCB_UNLOCK(stcb);
237 /* First job is to verify the vtag matches what I would send */
238 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
239 SCTP_TCB_UNLOCK(stcb);
242 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
244 if (icmph->icmp_type != ICMP_UNREACH) {
245 /* We only care about unreachable */
246 SCTP_TCB_UNLOCK(stcb);
249 if ((icmph->icmp_code == ICMP_UNREACH_NET) ||
250 (icmph->icmp_code == ICMP_UNREACH_HOST) ||
251 (icmph->icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
252 (icmph->icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
253 (icmph->icmp_code == ICMP_UNREACH_ISOLATED) ||
254 (icmph->icmp_code == ICMP_UNREACH_NET_PROHIB) ||
255 (icmph->icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
256 (icmph->icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
259 * Hmm reachablity problems we must examine closely. If its
260 * not reachable, we may have lost a network. Or if there is
261 * NO protocol at the other end named SCTP. well we consider
264 if (net->dest_state & SCTP_ADDR_REACHABLE) {
265 /* Ok that destination is NOT reachable */
266 net->dest_state &= ~SCTP_ADDR_REACHABLE;
267 net->dest_state &= ~SCTP_ADDR_PF;
268 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
270 (void *)net, SCTP_SO_NOT_LOCKED);
272 SCTP_TCB_UNLOCK(stcb);
273 } else if ((icmph->icmp_code == ICMP_UNREACH_PROTOCOL) ||
274 (icmph->icmp_code == ICMP_UNREACH_PORT)) {
276 * Here the peer is either playing tricks on us, including
277 * an address that belongs to someone who does not support
278 * SCTP OR was a userland implementation that shutdown and
279 * now is dead. In either case treat it like a OOTB abort
282 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
283 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
284 so = SCTP_INP_SO(inp);
285 atomic_add_int(&stcb->asoc.refcnt, 1);
286 SCTP_TCB_UNLOCK(stcb);
287 SCTP_SOCKET_LOCK(so, 1);
289 atomic_subtract_int(&stcb->asoc.refcnt, 1);
291 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
292 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
293 SCTP_SOCKET_UNLOCK(so, 1);
294 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
296 /* no need to unlock here, since the TCB is gone */
298 SCTP_TCB_UNLOCK(stcb);
306 sctp_ctlinput(cmd, sa, vip)
315 /* FIX, for non-bsd is this right? */
316 vrf_id = SCTP_DEFAULT_VRFID;
317 if (sa->sa_family != AF_INET ||
318 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
321 if (PRC_IS_REDIRECT(cmd)) {
323 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
327 struct sctp_inpcb *inp = NULL;
328 struct sctp_tcb *stcb = NULL;
329 struct sctp_nets *net = NULL;
330 struct sockaddr_in to, from;
332 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
333 bzero(&to, sizeof(to));
334 bzero(&from, sizeof(from));
335 from.sin_family = to.sin_family = AF_INET;
336 from.sin_len = to.sin_len = sizeof(to);
337 from.sin_port = sh->src_port;
338 from.sin_addr = ip->ip_src;
339 to.sin_port = sh->dest_port;
340 to.sin_addr = ip->ip_dst;
343 * 'to' holds the dest of the packet that failed to be sent.
344 * 'from' holds our local endpoint address. Thus we reverse
345 * the to and the from in the lookup.
347 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&to,
348 (struct sockaddr *)&from,
349 &inp, &net, 1, vrf_id);
350 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
351 if (cmd != PRC_MSGSIZE) {
352 sctp_notify(inp, ip, sh,
353 (struct sockaddr *)&to, stcb,
356 /* handle possible ICMP size messages */
357 sctp_notify_mbuf(inp, stcb, net, ip, sh);
360 if ((stcb == NULL) && (inp != NULL)) {
361 /* reduce ref-count */
363 SCTP_INP_DECR_REF(inp);
364 SCTP_INP_WUNLOCK(inp);
367 SCTP_TCB_UNLOCK(stcb);
377 sctp_getcred(SYSCTL_HANDLER_ARGS)
380 struct sockaddr_in addrs[2];
381 struct sctp_inpcb *inp;
382 struct sctp_nets *net;
383 struct sctp_tcb *stcb;
387 /* FIX, for non-bsd is this right? */
388 vrf_id = SCTP_DEFAULT_VRFID;
390 error = priv_check(req->td, PRIV_NETINET_GETCRED);
395 error = SYSCTL_IN(req, addrs, sizeof(addrs));
399 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
401 &inp, &net, 1, vrf_id);
402 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
403 if ((inp != NULL) && (stcb == NULL)) {
404 /* reduce ref-count */
406 SCTP_INP_DECR_REF(inp);
409 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
413 SCTP_TCB_UNLOCK(stcb);
415 * We use the write lock here, only since in the error leg we need
416 * it. If we used RLOCK, then we would have to
417 * wlock/decr/unlock/rlock. Which in theory could create a hole.
418 * Better to use higher wlock.
422 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
424 SCTP_INP_WUNLOCK(inp);
427 cru2x(inp->sctp_socket->so_cred, &xuc);
428 SCTP_INP_WUNLOCK(inp);
429 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
434 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
435 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
440 sctp_abort(struct socket *so)
442 struct sctp_inpcb *inp;
445 inp = (struct sctp_inpcb *)so->so_pcb;
450 flags = inp->sctp_flags;
451 #ifdef SCTP_LOG_CLOSING
452 sctp_log_closing(inp, NULL, 17);
454 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
455 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
456 #ifdef SCTP_LOG_CLOSING
457 sctp_log_closing(inp, NULL, 16);
459 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
460 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
462 SCTP_SB_CLEAR(so->so_snd);
464 * same for the rcv ones, they are only here for the
467 SCTP_SB_CLEAR(so->so_rcv);
469 /* Now null out the reference, we are completely detached. */
473 flags = inp->sctp_flags;
474 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
475 goto sctp_must_try_again;
482 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
484 struct sctp_inpcb *inp;
485 struct inpcb *ip_inp;
487 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
494 inp = (struct sctp_inpcb *)so->so_pcb;
496 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
499 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
500 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
505 error = sctp_inpcb_alloc(so, vrf_id);
509 inp = (struct sctp_inpcb *)so->so_pcb;
511 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
512 ip_inp = &inp->ip_inp.inp;
513 ip_inp->inp_vflag |= INP_IPV4;
514 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
516 error = ipsec_init_policy(so, &ip_inp->inp_sp);
517 #ifdef SCTP_LOG_CLOSING
518 sctp_log_closing(inp, NULL, 17);
522 flags = inp->sctp_flags;
523 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
524 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
525 #ifdef SCTP_LOG_CLOSING
526 sctp_log_closing(inp, NULL, 15);
528 SCTP_INP_WUNLOCK(inp);
529 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
530 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
532 flags = inp->sctp_flags;
533 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
536 SCTP_INP_WUNLOCK(inp);
542 SCTP_INP_WUNLOCK(inp);
547 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
549 struct sctp_inpcb *inp;
551 inp = (struct sctp_inpcb *)so->so_pcb;
553 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
557 if ((addr->sa_family != AF_INET) ||
558 (addr->sa_len != sizeof(struct sockaddr_in))) {
559 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
563 return (sctp_inpcb_bind(so, addr, NULL, p));
568 sctp_close(struct socket *so)
570 struct sctp_inpcb *inp;
573 inp = (struct sctp_inpcb *)so->so_pcb;
578 * Inform all the lower layer assoc that we are done.
581 flags = inp->sctp_flags;
582 #ifdef SCTP_LOG_CLOSING
583 sctp_log_closing(inp, NULL, 17);
585 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
586 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
587 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
588 (so->so_rcv.sb_cc > 0)) {
589 #ifdef SCTP_LOG_CLOSING
590 sctp_log_closing(inp, NULL, 13);
592 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
593 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
595 #ifdef SCTP_LOG_CLOSING
596 sctp_log_closing(inp, NULL, 14);
598 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
599 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
602 * The socket is now detached, no matter what the state of
603 * the SCTP association.
606 SCTP_SB_CLEAR(so->so_snd);
608 * same for the rcv ones, they are only here for the
611 SCTP_SB_CLEAR(so->so_rcv);
613 /* Now null out the reference, we are completely detached. */
617 flags = inp->sctp_flags;
618 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
619 goto sctp_must_try_again;
627 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
628 struct mbuf *control, struct thread *p);
632 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
633 struct mbuf *control, struct thread *p)
635 struct sctp_inpcb *inp;
638 inp = (struct sctp_inpcb *)so->so_pcb;
641 sctp_m_freem(control);
644 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
648 /* Got to have an to address if we are NOT a connected socket */
649 if ((addr == NULL) &&
650 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
651 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
653 } else if (addr == NULL) {
654 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
655 error = EDESTADDRREQ;
658 sctp_m_freem(control);
664 if (addr->sa_family != AF_INET) {
665 /* must be a v4 address! */
666 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
669 sctp_m_freem(control);
672 error = EDESTADDRREQ;
677 /* now what about control */
680 SCTP_PRINTF("huh? control set?\n");
681 sctp_m_freem(inp->control);
684 inp->control = control;
688 SCTP_BUF_NEXT(inp->pkt_last) = m;
691 inp->pkt_last = inp->pkt = m;
694 /* FreeBSD uses a flag passed */
695 ((flags & PRUS_MORETOCOME) == 0)
698 * note with the current version this code will only be used
699 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
700 * re-defining sosend to use the sctp_sosend. One can
701 * optionally switch back to this code (by changing back the
702 * definitions) but this is not advisable. This code is used
703 * by FreeBSD when sending a file with sendfile() though.
707 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
717 sctp_disconnect(struct socket *so)
719 struct sctp_inpcb *inp;
721 inp = (struct sctp_inpcb *)so->so_pcb;
723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
727 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
728 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
729 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
731 SCTP_INP_RUNLOCK(inp);
734 struct sctp_association *asoc;
735 struct sctp_tcb *stcb;
737 stcb = LIST_FIRST(&inp->sctp_asoc_list);
739 SCTP_INP_RUNLOCK(inp);
740 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
745 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
746 /* We are about to be freed, out of here */
747 SCTP_TCB_UNLOCK(stcb);
748 SCTP_INP_RUNLOCK(inp);
751 if (((so->so_options & SO_LINGER) &&
752 (so->so_linger == 0)) ||
753 (so->so_rcv.sb_cc > 0)) {
754 if (SCTP_GET_STATE(asoc) !=
755 SCTP_STATE_COOKIE_WAIT) {
756 /* Left with Data unread */
759 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_NOWAIT, 1, MT_DATA);
765 struct sctp_paramhdr *ph;
767 ph = mtod(err, struct sctp_paramhdr *);
768 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
769 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
770 ph->param_length = htons(SCTP_BUF_LEN(err));
772 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
773 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
775 SCTP_INP_RUNLOCK(inp);
776 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
777 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
778 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
780 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
781 /* No unlock tcb assoc is gone */
784 if (TAILQ_EMPTY(&asoc->send_queue) &&
785 TAILQ_EMPTY(&asoc->sent_queue) &&
786 (asoc->stream_queue_cnt == 0)) {
787 /* there is nothing queued to send, so done */
788 if (asoc->locked_on_sending) {
791 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
792 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
793 /* only send SHUTDOWN 1st time thru */
794 struct sctp_nets *netp;
796 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
797 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
798 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
800 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
801 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
802 sctp_stop_timers_for_shutdown(stcb);
803 if (stcb->asoc.alternate) {
804 netp = stcb->asoc.alternate;
806 netp = stcb->asoc.primary_destination;
808 sctp_send_shutdown(stcb, netp);
809 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
810 stcb->sctp_ep, stcb, netp);
811 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
812 stcb->sctp_ep, stcb, netp);
813 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
817 * we still got (or just got) data to send,
818 * so set SHUTDOWN_PENDING
821 * XXX sockets draft says that SCTP_EOF
822 * should be sent with no data. currently,
823 * we will allow user data to be sent first
824 * and move to SHUTDOWN-PENDING
826 struct sctp_nets *netp;
828 if (stcb->asoc.alternate) {
829 netp = stcb->asoc.alternate;
831 netp = stcb->asoc.primary_destination;
834 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
835 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
837 if (asoc->locked_on_sending) {
838 /* Locked to send out the data */
839 struct sctp_stream_queue_pending *sp;
841 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
843 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
844 asoc->locked_on_sending->stream_no);
846 if ((sp->length == 0) && (sp->msg_is_complete == 0))
847 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
850 if (TAILQ_EMPTY(&asoc->send_queue) &&
851 TAILQ_EMPTY(&asoc->sent_queue) &&
852 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
856 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
857 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
858 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
859 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
860 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
861 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
862 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
864 SCTP_INP_RUNLOCK(inp);
865 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
868 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
871 soisdisconnecting(so);
872 SCTP_TCB_UNLOCK(stcb);
873 SCTP_INP_RUNLOCK(inp);
878 /* UDP model does not support this */
879 SCTP_INP_RUNLOCK(inp);
880 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
886 sctp_flush(struct socket *so, int how)
889 * We will just clear out the values and let subsequent close clear
890 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
891 * they will not be able to read the data, the socket will block
892 * that from happening.
894 struct sctp_inpcb *inp;
896 inp = (struct sctp_inpcb *)so->so_pcb;
898 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
902 /* For the 1 to many model this does nothing */
903 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
904 SCTP_INP_RUNLOCK(inp);
907 SCTP_INP_RUNLOCK(inp);
908 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
910 * First make sure the sb will be happy, we don't use these
911 * except maybe the count
914 SCTP_INP_READ_LOCK(inp);
915 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
916 SCTP_INP_READ_UNLOCK(inp);
917 SCTP_INP_WUNLOCK(inp);
918 so->so_rcv.sb_cc = 0;
919 so->so_rcv.sb_mbcnt = 0;
920 so->so_rcv.sb_mb = NULL;
922 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
924 * First make sure the sb will be happy, we don't use these
925 * except maybe the count
927 so->so_snd.sb_cc = 0;
928 so->so_snd.sb_mbcnt = 0;
929 so->so_snd.sb_mb = NULL;
936 sctp_shutdown(struct socket *so)
938 struct sctp_inpcb *inp;
940 inp = (struct sctp_inpcb *)so->so_pcb;
942 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
946 /* For UDP model this is a invalid call */
947 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
948 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
949 /* Restore the flags that the soshutdown took away. */
950 SOCKBUF_LOCK(&so->so_rcv);
951 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
952 SOCKBUF_UNLOCK(&so->so_rcv);
953 /* This proc will wakeup for read and do nothing (I hope) */
954 SCTP_INP_RUNLOCK(inp);
955 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
959 * Ok if we reach here its the TCP model and it is either a SHUT_WR
960 * or SHUT_RDWR. This means we put the shutdown flag against it.
963 struct sctp_tcb *stcb;
964 struct sctp_association *asoc;
967 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
968 SCTP_INP_RUNLOCK(inp);
973 stcb = LIST_FIRST(&inp->sctp_asoc_list);
976 * Ok we hit the case that the shutdown call was
977 * made after an abort or something. Nothing to do
980 SCTP_INP_RUNLOCK(inp);
985 if (TAILQ_EMPTY(&asoc->send_queue) &&
986 TAILQ_EMPTY(&asoc->sent_queue) &&
987 (asoc->stream_queue_cnt == 0)) {
988 if (asoc->locked_on_sending) {
991 /* there is nothing queued to send, so I'm done... */
992 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
993 /* only send SHUTDOWN the first time through */
994 struct sctp_nets *netp;
996 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
997 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
998 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1000 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
1001 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
1002 sctp_stop_timers_for_shutdown(stcb);
1003 if (stcb->asoc.alternate) {
1004 netp = stcb->asoc.alternate;
1006 netp = stcb->asoc.primary_destination;
1008 sctp_send_shutdown(stcb, netp);
1009 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1010 stcb->sctp_ep, stcb, netp);
1011 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1012 stcb->sctp_ep, stcb, netp);
1013 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
1017 * we still got (or just got) data to send, so set
1020 struct sctp_nets *netp;
1022 if (stcb->asoc.alternate) {
1023 netp = stcb->asoc.alternate;
1025 netp = stcb->asoc.primary_destination;
1028 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1029 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1032 if (asoc->locked_on_sending) {
1033 /* Locked to send out the data */
1034 struct sctp_stream_queue_pending *sp;
1036 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1038 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1039 asoc->locked_on_sending->stream_no);
1041 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1042 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1046 if (TAILQ_EMPTY(&asoc->send_queue) &&
1047 TAILQ_EMPTY(&asoc->sent_queue) &&
1048 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1049 struct mbuf *op_err;
1052 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
1053 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1054 sctp_abort_an_association(stcb->sctp_ep, stcb,
1055 op_err, SCTP_SO_LOCKED);
1058 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1061 SCTP_TCB_UNLOCK(stcb);
1064 SCTP_INP_RUNLOCK(inp);
1069 * copies a "user" presentable address and removes embedded scope, etc.
1070 * returns 0 on success, 1 on error
1073 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1076 struct sockaddr_in6 lsa6;
1078 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1081 memcpy(ss, sa, sa->sa_len);
1088 * NOTE: assumes addr lock is held
1091 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1092 struct sctp_tcb *stcb,
1094 struct sockaddr_storage *sas,
1097 struct sctp_ifn *sctp_ifn;
1098 struct sctp_ifa *sctp_ifa;
1103 int ipv4_local_scope, ipv4_addr_legal;
1107 int local_scope, site_scope, ipv6_addr_legal;
1110 struct sctp_vrf *vrf;
1117 /* Turn on all the appropriate scope */
1118 loopback_scope = stcb->asoc.scope.loopback_scope;
1120 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1121 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1124 local_scope = stcb->asoc.scope.local_scope;
1125 site_scope = stcb->asoc.scope.site_scope;
1126 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1129 /* Use generic values for endpoints. */
1132 ipv4_local_scope = 1;
1138 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1140 ipv6_addr_legal = 1;
1143 if (SCTP_IPV6_V6ONLY(inp)) {
1144 ipv4_addr_legal = 0;
1146 ipv4_addr_legal = 1;
1151 ipv6_addr_legal = 0;
1154 ipv4_addr_legal = 1;
1158 vrf = sctp_find_vrf(vrf_id);
1162 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1163 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1164 if ((loopback_scope == 0) &&
1165 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1166 /* Skip loopback if loopback_scope not set */
1169 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1172 * For the BOUND-ALL case, the list
1173 * associated with a TCB is Always
1174 * considered a reverse list.. i.e.
1175 * it lists addresses that are NOT
1176 * part of the association. If this
1177 * is one of those we must skip it.
1179 if (sctp_is_addr_restricted(stcb,
1184 switch (sctp_ifa->address.sa.sa_family) {
1187 if (ipv4_addr_legal) {
1188 struct sockaddr_in *sin;
1190 sin = &sctp_ifa->address.sin;
1191 if (sin->sin_addr.s_addr == 0) {
1199 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1200 &sin->sin_addr) != 0) {
1203 if ((ipv4_local_scope == 0) &&
1204 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1208 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1209 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1210 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1211 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1212 actual += sizeof(struct sockaddr_in6);
1215 memcpy(sas, sin, sizeof(*sin));
1216 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1217 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1218 actual += sizeof(*sin);
1222 if (actual >= limit) {
1232 if (ipv6_addr_legal) {
1233 struct sockaddr_in6 *sin6;
1235 sin6 = &sctp_ifa->address.sin6;
1236 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1244 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1245 &sin6->sin6_addr) != 0) {
1248 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1249 if (local_scope == 0)
1251 if (sin6->sin6_scope_id == 0) {
1252 if (sa6_recoverscope(sin6) != 0)
1270 if ((site_scope == 0) &&
1271 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1274 memcpy(sas, sin6, sizeof(*sin6));
1275 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1276 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1277 actual += sizeof(*sin6);
1278 if (actual >= limit) {
1293 struct sctp_laddr *laddr;
1295 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1297 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1301 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1303 switch (laddr->ifa->address.sa.sa_family) {
1306 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1311 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1318 sas = (struct sockaddr_storage *)((caddr_t)sas +
1319 laddr->ifa->address.sa.sa_len);
1320 actual += laddr->ifa->address.sa.sa_len;
1321 if (actual >= limit) {
1330 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1331 struct sctp_tcb *stcb,
1333 struct sockaddr_storage *sas)
1337 SCTP_IPI_ADDR_RLOCK();
1338 /* fill up addresses for the endpoint's default vrf */
1339 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1341 SCTP_IPI_ADDR_RUNLOCK();
1346 * NOTE: assumes addr lock is held
1349 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1352 struct sctp_vrf *vrf = NULL;
1355 * In both sub-set bound an bound_all cases we return the MAXIMUM
1356 * number of addresses that you COULD get. In reality the sub-set
1357 * bound may have an exclusion list for a given TCB OR in the
1358 * bound-all case a TCB may NOT include the loopback or other
1359 * addresses as well.
1361 vrf = sctp_find_vrf(vrf_id);
1365 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1366 struct sctp_ifn *sctp_ifn;
1367 struct sctp_ifa *sctp_ifa;
1369 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1370 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1371 /* Count them if they are the right type */
1372 switch (sctp_ifa->address.sa.sa_family) {
1376 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1377 cnt += sizeof(struct sockaddr_in6);
1379 cnt += sizeof(struct sockaddr_in);
1381 cnt += sizeof(struct sockaddr_in);
1387 cnt += sizeof(struct sockaddr_in6);
1396 struct sctp_laddr *laddr;
1398 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1399 switch (laddr->ifa->address.sa.sa_family) {
1403 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1404 cnt += sizeof(struct sockaddr_in6);
1406 cnt += sizeof(struct sockaddr_in);
1408 cnt += sizeof(struct sockaddr_in);
1414 cnt += sizeof(struct sockaddr_in6);
1426 sctp_count_max_addresses(struct sctp_inpcb *inp)
1430 SCTP_IPI_ADDR_RLOCK();
1431 /* count addresses for the endpoint's default VRF */
1432 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1433 SCTP_IPI_ADDR_RUNLOCK();
1438 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1439 size_t optsize, void *p, int delay)
1442 int creat_lock_on = 0;
1443 struct sctp_tcb *stcb = NULL;
1444 struct sockaddr *sa;
1445 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1447 int bad_addresses = 0;
1450 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1452 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1453 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1454 /* We are already connected AND the TCP model */
1455 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1456 return (EADDRINUSE);
1458 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1459 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1460 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1463 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1464 SCTP_INP_RLOCK(inp);
1465 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1466 SCTP_INP_RUNLOCK(inp);
1469 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1472 SCTP_INP_INCR_REF(inp);
1473 SCTP_ASOC_CREATE_LOCK(inp);
1475 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1476 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1477 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1481 totaddrp = (int *)optval;
1482 totaddr = *totaddrp;
1483 sa = (struct sockaddr *)(totaddrp + 1);
1484 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
1485 if ((stcb != NULL) || bad_addresses) {
1486 /* Already have or am bring up an association */
1487 SCTP_ASOC_CREATE_UNLOCK(inp);
1490 SCTP_TCB_UNLOCK(stcb);
1491 if (bad_addresses == 0) {
1492 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1498 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1503 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1505 struct in6pcb *inp6;
1507 inp6 = (struct in6pcb *)inp;
1508 if (SCTP_IPV6_V6ONLY(inp6)) {
1510 * if IPV6_V6ONLY flag, ignore connections destined
1511 * to a v4 addr or v4-mapped addr
1513 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1519 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1520 SCTP_PCB_FLAGS_UNBOUND) {
1521 /* Bind a ephemeral port */
1522 error = sctp_inpcb_bind(so, NULL, NULL, p);
1527 /* FIX ME: do we want to pass in a vrf on the connect call? */
1528 vrf_id = inp->def_vrf_id;
1531 /* We are GOOD to go */
1532 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1536 /* Gak! no memory */
1539 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1540 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1541 /* Set the connected flag so we can queue data */
1544 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1545 /* move to second address */
1546 switch (sa->sa_family) {
1549 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1554 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1562 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1563 /* Fill in the return id */
1565 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1568 a_id = (sctp_assoc_t *) optval;
1569 *a_id = sctp_get_associd(stcb);
1571 /* initialize authentication parameters for the assoc */
1572 sctp_initialize_auth_params(inp, stcb);
1575 /* doing delayed connection */
1576 stcb->asoc.delayed_connection = 1;
1577 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1579 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1580 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1582 SCTP_TCB_UNLOCK(stcb);
1583 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1584 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1585 /* Set the connected flag so we can queue data */
1589 if (creat_lock_on) {
1590 SCTP_ASOC_CREATE_UNLOCK(inp);
1592 SCTP_INP_DECR_REF(inp);
1596 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1597 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1598 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1599 SCTP_INP_RLOCK(inp); \
1600 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1602 SCTP_TCB_LOCK(stcb); \
1604 SCTP_INP_RUNLOCK(inp); \
1605 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1606 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1607 if (stcb == NULL) { \
1608 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1618 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1619 if (size < sizeof(type)) { \
1620 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1624 destp = (type *)srcp; \
1629 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1632 struct sctp_inpcb *inp = NULL;
1634 struct sctp_tcb *stcb = NULL;
1636 if (optval == NULL) {
1637 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1640 inp = (struct sctp_inpcb *)so->so_pcb;
1642 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1649 case SCTP_AUTOCLOSE:
1650 case SCTP_EXPLICIT_EOR:
1651 case SCTP_AUTO_ASCONF:
1652 case SCTP_DISABLE_FRAGMENTS:
1653 case SCTP_I_WANT_MAPPED_V4_ADDR:
1654 case SCTP_USE_EXT_RCVINFO:
1655 SCTP_INP_RLOCK(inp);
1657 case SCTP_DISABLE_FRAGMENTS:
1658 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1660 case SCTP_I_WANT_MAPPED_V4_ADDR:
1661 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1663 case SCTP_AUTO_ASCONF:
1664 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1665 /* only valid for bound all sockets */
1666 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1668 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1673 case SCTP_EXPLICIT_EOR:
1674 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1677 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1679 case SCTP_USE_EXT_RCVINFO:
1680 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1682 case SCTP_AUTOCLOSE:
1683 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1684 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1690 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1691 error = ENOPROTOOPT;
1692 } /* end switch (sopt->sopt_name) */
1693 if (*optsize < sizeof(val)) {
1694 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1698 SCTP_INP_RUNLOCK(inp);
1700 /* return the option value */
1701 *(int *)optval = val;
1702 *optsize = sizeof(val);
1705 case SCTP_GET_PACKET_LOG:
1707 #ifdef SCTP_PACKET_LOGGING
1711 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1712 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1720 case SCTP_REUSE_PORT:
1724 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1725 /* Can't do this for a 1-m socket */
1729 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1730 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1731 *optsize = sizeof(uint32_t);
1734 case SCTP_PARTIAL_DELIVERY_POINT:
1738 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1739 *value = inp->partial_delivery_point;
1740 *optsize = sizeof(uint32_t);
1743 case SCTP_FRAGMENT_INTERLEAVE:
1747 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1748 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1749 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1750 *value = SCTP_FRAG_LEVEL_2;
1752 *value = SCTP_FRAG_LEVEL_1;
1755 *value = SCTP_FRAG_LEVEL_0;
1757 *optsize = sizeof(uint32_t);
1760 case SCTP_CMT_ON_OFF:
1762 struct sctp_assoc_value *av;
1764 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1765 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1767 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1768 SCTP_TCB_UNLOCK(stcb);
1770 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1771 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1772 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1773 SCTP_INP_RLOCK(inp);
1774 av->assoc_value = inp->sctp_cmt_on_off;
1775 SCTP_INP_RUNLOCK(inp);
1777 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1782 *optsize = sizeof(struct sctp_assoc_value);
1786 case SCTP_PLUGGABLE_CC:
1788 struct sctp_assoc_value *av;
1790 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1791 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1793 av->assoc_value = stcb->asoc.congestion_control_module;
1794 SCTP_TCB_UNLOCK(stcb);
1796 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1797 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1798 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1799 SCTP_INP_RLOCK(inp);
1800 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1801 SCTP_INP_RUNLOCK(inp);
1803 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1808 *optsize = sizeof(struct sctp_assoc_value);
1812 case SCTP_CC_OPTION:
1814 struct sctp_cc_option *cc_opt;
1816 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1817 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1821 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1824 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1825 *optsize = sizeof(struct sctp_cc_option);
1827 SCTP_TCB_UNLOCK(stcb);
1831 case SCTP_PLUGGABLE_SS:
1833 struct sctp_assoc_value *av;
1835 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1836 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1838 av->assoc_value = stcb->asoc.stream_scheduling_module;
1839 SCTP_TCB_UNLOCK(stcb);
1841 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1842 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1843 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1844 SCTP_INP_RLOCK(inp);
1845 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1846 SCTP_INP_RUNLOCK(inp);
1848 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1853 *optsize = sizeof(struct sctp_assoc_value);
1859 struct sctp_stream_value *av;
1861 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1862 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1864 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1865 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1866 &av->stream_value) < 0)) {
1867 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1870 *optsize = sizeof(struct sctp_stream_value);
1872 SCTP_TCB_UNLOCK(stcb);
1875 * Can't get stream value without
1878 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1883 case SCTP_GET_ADDR_LEN:
1885 struct sctp_assoc_value *av;
1887 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1890 if (av->assoc_value == AF_INET) {
1891 av->assoc_value = sizeof(struct sockaddr_in);
1896 if (av->assoc_value == AF_INET6) {
1897 av->assoc_value = sizeof(struct sockaddr_in6);
1902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1904 *optsize = sizeof(struct sctp_assoc_value);
1908 case SCTP_GET_ASSOC_NUMBER:
1910 uint32_t *value, cnt;
1912 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1914 SCTP_INP_RLOCK(inp);
1915 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1918 SCTP_INP_RUNLOCK(inp);
1920 *optsize = sizeof(uint32_t);
1923 case SCTP_GET_ASSOC_ID_LIST:
1925 struct sctp_assoc_ids *ids;
1926 unsigned int at, limit;
1928 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1930 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1931 SCTP_INP_RLOCK(inp);
1932 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1934 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1937 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1941 SCTP_INP_RUNLOCK(inp);
1943 ids->gaids_number_of_ids = at;
1944 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1950 struct sctp_assoc_value *av;
1952 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1953 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1956 av->assoc_value = stcb->asoc.context;
1957 SCTP_TCB_UNLOCK(stcb);
1959 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1960 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1961 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1962 SCTP_INP_RLOCK(inp);
1963 av->assoc_value = inp->sctp_context;
1964 SCTP_INP_RUNLOCK(inp);
1966 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1971 *optsize = sizeof(struct sctp_assoc_value);
1977 uint32_t *default_vrfid;
1979 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1980 *default_vrfid = inp->def_vrf_id;
1981 *optsize = sizeof(uint32_t);
1984 case SCTP_GET_ASOC_VRF:
1986 struct sctp_assoc_value *id;
1988 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1989 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1994 id->assoc_value = stcb->asoc.vrf_id;
1995 *optsize = sizeof(struct sctp_assoc_value);
1999 case SCTP_GET_VRF_IDS:
2001 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2005 case SCTP_GET_NONCE_VALUES:
2007 struct sctp_get_nonce_values *gnv;
2009 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2010 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2013 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2014 gnv->gn_local_tag = stcb->asoc.my_vtag;
2015 SCTP_TCB_UNLOCK(stcb);
2016 *optsize = sizeof(struct sctp_get_nonce_values);
2018 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2023 case SCTP_DELAYED_SACK:
2025 struct sctp_sack_info *sack;
2027 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2028 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2030 sack->sack_delay = stcb->asoc.delayed_ack;
2031 sack->sack_freq = stcb->asoc.sack_freq;
2032 SCTP_TCB_UNLOCK(stcb);
2034 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2035 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2036 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2037 SCTP_INP_RLOCK(inp);
2038 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2039 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2040 SCTP_INP_RUNLOCK(inp);
2042 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2047 *optsize = sizeof(struct sctp_sack_info);
2051 case SCTP_GET_SNDBUF_USE:
2053 struct sctp_sockstat *ss;
2055 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2056 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2059 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2060 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2061 stcb->asoc.size_on_all_streams);
2062 SCTP_TCB_UNLOCK(stcb);
2063 *optsize = sizeof(struct sctp_sockstat);
2065 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2070 case SCTP_MAX_BURST:
2072 struct sctp_assoc_value *av;
2074 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2075 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2078 av->assoc_value = stcb->asoc.max_burst;
2079 SCTP_TCB_UNLOCK(stcb);
2081 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2082 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2083 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2084 SCTP_INP_RLOCK(inp);
2085 av->assoc_value = inp->sctp_ep.max_burst;
2086 SCTP_INP_RUNLOCK(inp);
2088 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2093 *optsize = sizeof(struct sctp_assoc_value);
2099 struct sctp_assoc_value *av;
2102 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2103 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2106 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2107 SCTP_TCB_UNLOCK(stcb);
2109 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2110 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2111 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2112 SCTP_INP_RLOCK(inp);
2113 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2114 ovh = SCTP_MED_OVERHEAD;
2116 ovh = SCTP_MED_V4_OVERHEAD;
2118 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2119 av->assoc_value = 0;
2121 av->assoc_value = inp->sctp_frag_point - ovh;
2122 SCTP_INP_RUNLOCK(inp);
2124 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2129 *optsize = sizeof(struct sctp_assoc_value);
2133 case SCTP_GET_STAT_LOG:
2134 error = sctp_fill_stat_log(optval, optsize);
2138 struct sctp_event_subscribe *events;
2140 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2141 memset(events, 0, sizeof(struct sctp_event_subscribe));
2142 SCTP_INP_RLOCK(inp);
2143 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2144 events->sctp_data_io_event = 1;
2146 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2147 events->sctp_association_event = 1;
2149 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2150 events->sctp_address_event = 1;
2152 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2153 events->sctp_send_failure_event = 1;
2155 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2156 events->sctp_peer_error_event = 1;
2158 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2159 events->sctp_shutdown_event = 1;
2161 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2162 events->sctp_partial_delivery_event = 1;
2164 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2165 events->sctp_adaptation_layer_event = 1;
2167 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2168 events->sctp_authentication_event = 1;
2170 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2171 events->sctp_sender_dry_event = 1;
2173 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2174 events->sctp_stream_reset_event = 1;
2175 SCTP_INP_RUNLOCK(inp);
2176 *optsize = sizeof(struct sctp_event_subscribe);
2179 case SCTP_ADAPTATION_LAYER:
2183 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2185 SCTP_INP_RLOCK(inp);
2186 *value = inp->sctp_ep.adaptation_layer_indicator;
2187 SCTP_INP_RUNLOCK(inp);
2188 *optsize = sizeof(uint32_t);
2191 case SCTP_SET_INITIAL_DBG_SEQ:
2195 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2196 SCTP_INP_RLOCK(inp);
2197 *value = inp->sctp_ep.initial_sequence_debug;
2198 SCTP_INP_RUNLOCK(inp);
2199 *optsize = sizeof(uint32_t);
2202 case SCTP_GET_LOCAL_ADDR_SIZE:
2206 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2207 SCTP_INP_RLOCK(inp);
2208 *value = sctp_count_max_addresses(inp);
2209 SCTP_INP_RUNLOCK(inp);
2210 *optsize = sizeof(uint32_t);
2213 case SCTP_GET_REMOTE_ADDR_SIZE:
2217 struct sctp_nets *net;
2219 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2220 /* FIXME MT: change to sctp_assoc_value? */
2221 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2225 /* Count the sizes */
2226 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2227 switch (net->ro._l_addr.sa.sa_family) {
2231 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2232 size += sizeof(struct sockaddr_in6);
2234 size += sizeof(struct sockaddr_in);
2237 size += sizeof(struct sockaddr_in);
2243 size += sizeof(struct sockaddr_in6);
2250 SCTP_TCB_UNLOCK(stcb);
2251 *value = (uint32_t) size;
2252 *optsize = sizeof(uint32_t);
2254 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2259 case SCTP_GET_PEER_ADDRESSES:
2261 * Get the address information, an array is passed in to
2262 * fill up we pack it.
2266 struct sockaddr_storage *sas;
2267 struct sctp_nets *net;
2268 struct sctp_getaddresses *saddr;
2270 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2271 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2274 left = (*optsize) - sizeof(struct sctp_getaddresses);
2275 *optsize = sizeof(struct sctp_getaddresses);
2276 sas = (struct sockaddr_storage *)&saddr->addr[0];
2278 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2279 switch (net->ro._l_addr.sa.sa_family) {
2283 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2284 cpsz = sizeof(struct sockaddr_in6);
2286 cpsz = sizeof(struct sockaddr_in);
2289 cpsz = sizeof(struct sockaddr_in);
2295 cpsz = sizeof(struct sockaddr_in6);
2306 /* not enough room. */
2309 #if defined(INET) && defined(INET6)
2310 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2311 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2312 /* Must map the address */
2313 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2314 (struct sockaddr_in6 *)sas);
2316 memcpy(sas, &net->ro._l_addr, cpsz);
2319 memcpy(sas, &net->ro._l_addr, cpsz);
2321 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2323 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2327 SCTP_TCB_UNLOCK(stcb);
2329 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2334 case SCTP_GET_LOCAL_ADDRESSES:
2336 size_t limit, actual;
2337 struct sockaddr_storage *sas;
2338 struct sctp_getaddresses *saddr;
2340 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2341 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2343 sas = (struct sockaddr_storage *)&saddr->addr[0];
2344 limit = *optsize - sizeof(sctp_assoc_t);
2345 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2347 SCTP_TCB_UNLOCK(stcb);
2349 *optsize = sizeof(struct sockaddr_storage) + actual;
2352 case SCTP_PEER_ADDR_PARAMS:
2354 struct sctp_paddrparams *paddrp;
2355 struct sctp_nets *net;
2356 struct sockaddr *addr;
2358 #if defined(INET) && defined(INET6)
2359 struct sockaddr_in sin_store;
2363 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2364 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2366 #if defined(INET) && defined(INET6)
2367 if (paddrp->spp_address.ss_family == AF_INET6) {
2368 struct sockaddr_in6 *sin6;
2370 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2371 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2372 in6_sin6_2_sin(&sin_store, sin6);
2373 addr = (struct sockaddr *)&sin_store;
2375 addr = (struct sockaddr *)&paddrp->spp_address;
2378 addr = (struct sockaddr *)&paddrp->spp_address;
2381 addr = (struct sockaddr *)&paddrp->spp_address;
2384 net = sctp_findnet(stcb, addr);
2387 * We increment here since
2388 * sctp_findassociation_ep_addr() wil do a
2389 * decrement if it finds the stcb as long as
2390 * the locked tcb (last argument) is NOT a
2394 SCTP_INP_INCR_REF(inp);
2395 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2397 SCTP_INP_DECR_REF(inp);
2400 if ((stcb != NULL) && (net == NULL)) {
2402 if (addr->sa_family == AF_INET) {
2403 struct sockaddr_in *sin;
2405 sin = (struct sockaddr_in *)addr;
2406 if (sin->sin_addr.s_addr != INADDR_ANY) {
2408 SCTP_TCB_UNLOCK(stcb);
2409 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2415 if (addr->sa_family == AF_INET6) {
2416 struct sockaddr_in6 *sin6;
2418 sin6 = (struct sockaddr_in6 *)addr;
2419 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2421 SCTP_TCB_UNLOCK(stcb);
2422 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2428 error = EAFNOSUPPORT;
2429 SCTP_TCB_UNLOCK(stcb);
2430 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2435 /* Applies to the specific association */
2436 paddrp->spp_flags = 0;
2440 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2441 ovh = SCTP_MED_OVERHEAD;
2443 ovh = SCTP_MED_V4_OVERHEAD;
2446 paddrp->spp_hbinterval = net->heart_beat_delay;
2447 paddrp->spp_pathmaxrxt = net->failure_threshold;
2448 paddrp->spp_pathmtu = net->mtu - ovh;
2449 /* get flags for HB */
2450 if (net->dest_state & SCTP_ADDR_NOHB) {
2451 paddrp->spp_flags |= SPP_HB_DISABLE;
2453 paddrp->spp_flags |= SPP_HB_ENABLE;
2455 /* get flags for PMTU */
2456 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2457 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2459 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2461 if (net->dscp & 0x01) {
2462 paddrp->spp_dscp = net->dscp & 0xfc;
2463 paddrp->spp_flags |= SPP_DSCP;
2466 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2467 (net->flowlabel & 0x80000000)) {
2468 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2469 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2474 * No destination so return default
2477 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2478 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2479 if (stcb->asoc.default_dscp & 0x01) {
2480 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2481 paddrp->spp_flags |= SPP_DSCP;
2484 if (stcb->asoc.default_flowlabel & 0x80000000) {
2485 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2486 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2489 /* default settings should be these */
2490 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2491 paddrp->spp_flags |= SPP_HB_DISABLE;
2493 paddrp->spp_flags |= SPP_HB_ENABLE;
2495 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2496 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2498 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2500 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2502 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2503 SCTP_TCB_UNLOCK(stcb);
2505 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2506 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2507 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2508 /* Use endpoint defaults */
2509 SCTP_INP_RLOCK(inp);
2510 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2511 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2512 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2513 /* get inp's default */
2514 if (inp->sctp_ep.default_dscp & 0x01) {
2515 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2516 paddrp->spp_flags |= SPP_DSCP;
2519 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2520 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2521 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2522 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2525 /* can't return this */
2526 paddrp->spp_pathmtu = 0;
2528 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2529 paddrp->spp_flags |= SPP_HB_ENABLE;
2531 paddrp->spp_flags |= SPP_HB_DISABLE;
2533 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2534 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2536 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2538 SCTP_INP_RUNLOCK(inp);
2540 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2545 *optsize = sizeof(struct sctp_paddrparams);
2549 case SCTP_GET_PEER_ADDR_INFO:
2551 struct sctp_paddrinfo *paddri;
2552 struct sctp_nets *net;
2553 struct sockaddr *addr;
2555 #if defined(INET) && defined(INET6)
2556 struct sockaddr_in sin_store;
2560 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2561 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2563 #if defined(INET) && defined(INET6)
2564 if (paddri->spinfo_address.ss_family == AF_INET6) {
2565 struct sockaddr_in6 *sin6;
2567 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2568 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2569 in6_sin6_2_sin(&sin_store, sin6);
2570 addr = (struct sockaddr *)&sin_store;
2572 addr = (struct sockaddr *)&paddri->spinfo_address;
2575 addr = (struct sockaddr *)&paddri->spinfo_address;
2578 addr = (struct sockaddr *)&paddri->spinfo_address;
2581 net = sctp_findnet(stcb, addr);
2584 * We increment here since
2585 * sctp_findassociation_ep_addr() wil do a
2586 * decrement if it finds the stcb as long as
2587 * the locked tcb (last argument) is NOT a
2591 SCTP_INP_INCR_REF(inp);
2592 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2594 SCTP_INP_DECR_REF(inp);
2598 if ((stcb != NULL) && (net != NULL)) {
2599 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2600 /* It's unconfirmed */
2601 paddri->spinfo_state = SCTP_UNCONFIRMED;
2602 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2604 paddri->spinfo_state = SCTP_ACTIVE;
2607 paddri->spinfo_state = SCTP_INACTIVE;
2609 paddri->spinfo_cwnd = net->cwnd;
2610 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2611 paddri->spinfo_rto = net->RTO;
2612 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2613 paddri->spinfo_mtu = net->mtu;
2614 SCTP_TCB_UNLOCK(stcb);
2615 *optsize = sizeof(struct sctp_paddrinfo);
2618 SCTP_TCB_UNLOCK(stcb);
2620 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2625 case SCTP_PCB_STATUS:
2627 struct sctp_pcbinfo *spcb;
2629 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2630 sctp_fill_pcbinfo(spcb);
2631 *optsize = sizeof(struct sctp_pcbinfo);
2636 struct sctp_nets *net;
2637 struct sctp_status *sstat;
2639 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2640 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2643 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2648 * I think passing the state is fine since
2649 * sctp_constants.h will be available to the user
2652 sstat->sstat_state = stcb->asoc.state;
2653 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2654 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2655 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2657 * We can't include chunks that have been passed to
2658 * the socket layer. Only things in queue.
2660 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2661 stcb->asoc.cnt_on_all_streams);
2664 sstat->sstat_instrms = stcb->asoc.streamincnt;
2665 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2666 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2667 memcpy(&sstat->sstat_primary.spinfo_address,
2668 &stcb->asoc.primary_destination->ro._l_addr,
2669 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2670 net = stcb->asoc.primary_destination;
2671 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2673 * Again the user can get info from sctp_constants.h
2674 * for what the state of the network is.
2676 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2677 /* It's unconfirmed */
2678 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2679 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2681 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2684 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2686 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2687 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2688 sstat->sstat_primary.spinfo_rto = net->RTO;
2689 sstat->sstat_primary.spinfo_mtu = net->mtu;
2690 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2691 SCTP_TCB_UNLOCK(stcb);
2692 *optsize = sizeof(struct sctp_status);
2697 struct sctp_rtoinfo *srto;
2699 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2700 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2703 srto->srto_initial = stcb->asoc.initial_rto;
2704 srto->srto_max = stcb->asoc.maxrto;
2705 srto->srto_min = stcb->asoc.minrto;
2706 SCTP_TCB_UNLOCK(stcb);
2708 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2709 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2710 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2711 SCTP_INP_RLOCK(inp);
2712 srto->srto_initial = inp->sctp_ep.initial_rto;
2713 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2714 srto->srto_min = inp->sctp_ep.sctp_minrto;
2715 SCTP_INP_RUNLOCK(inp);
2717 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2722 *optsize = sizeof(struct sctp_rtoinfo);
2728 struct sctp_timeouts *stimo;
2730 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2731 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2734 stimo->stimo_init = stcb->asoc.timoinit;
2735 stimo->stimo_data = stcb->asoc.timodata;
2736 stimo->stimo_sack = stcb->asoc.timosack;
2737 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2738 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2739 stimo->stimo_cookie = stcb->asoc.timocookie;
2740 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2741 SCTP_TCB_UNLOCK(stcb);
2742 *optsize = sizeof(struct sctp_timeouts);
2744 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2749 case SCTP_ASSOCINFO:
2751 struct sctp_assocparams *sasoc;
2753 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2754 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2757 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2758 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2759 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2760 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2761 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2762 SCTP_TCB_UNLOCK(stcb);
2764 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2765 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2766 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2767 SCTP_INP_RLOCK(inp);
2768 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2769 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2770 sasoc->sasoc_number_peer_destinations = 0;
2771 sasoc->sasoc_peer_rwnd = 0;
2772 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2773 SCTP_INP_RUNLOCK(inp);
2775 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2780 *optsize = sizeof(struct sctp_assocparams);
2784 case SCTP_DEFAULT_SEND_PARAM:
2786 struct sctp_sndrcvinfo *s_info;
2788 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2789 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2792 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2793 SCTP_TCB_UNLOCK(stcb);
2795 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2796 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2797 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2798 SCTP_INP_RLOCK(inp);
2799 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2800 SCTP_INP_RUNLOCK(inp);
2802 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2807 *optsize = sizeof(struct sctp_sndrcvinfo);
2813 struct sctp_initmsg *sinit;
2815 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2816 SCTP_INP_RLOCK(inp);
2817 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2818 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2819 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2820 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2821 SCTP_INP_RUNLOCK(inp);
2822 *optsize = sizeof(struct sctp_initmsg);
2825 case SCTP_PRIMARY_ADDR:
2826 /* we allow a "get" operation on this */
2828 struct sctp_setprim *ssp;
2830 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2831 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2834 union sctp_sockstore *addr;
2836 addr = &stcb->asoc.primary_destination->ro._l_addr;
2837 switch (addr->sa.sa_family) {
2841 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2842 in6_sin_2_v4mapsin6(&addr->sin,
2843 (struct sockaddr_in6 *)&ssp->ssp_addr);
2845 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2848 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2854 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2860 SCTP_TCB_UNLOCK(stcb);
2861 *optsize = sizeof(struct sctp_setprim);
2863 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2868 case SCTP_HMAC_IDENT:
2870 struct sctp_hmacalgo *shmac;
2871 sctp_hmaclist_t *hmaclist;
2875 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2877 SCTP_INP_RLOCK(inp);
2878 hmaclist = inp->sctp_ep.local_hmacs;
2879 if (hmaclist == NULL) {
2880 /* no HMACs to return */
2881 *optsize = sizeof(*shmac);
2882 SCTP_INP_RUNLOCK(inp);
2885 /* is there room for all of the hmac ids? */
2886 size = sizeof(*shmac) + (hmaclist->num_algo *
2887 sizeof(shmac->shmac_idents[0]));
2888 if ((size_t)(*optsize) < size) {
2889 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2891 SCTP_INP_RUNLOCK(inp);
2894 /* copy in the list */
2895 shmac->shmac_number_of_idents = hmaclist->num_algo;
2896 for (i = 0; i < hmaclist->num_algo; i++) {
2897 shmac->shmac_idents[i] = hmaclist->hmac[i];
2899 SCTP_INP_RUNLOCK(inp);
2903 case SCTP_AUTH_ACTIVE_KEY:
2905 struct sctp_authkeyid *scact;
2907 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2908 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2911 /* get the active key on the assoc */
2912 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2913 SCTP_TCB_UNLOCK(stcb);
2915 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2916 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2917 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2918 /* get the endpoint active key */
2919 SCTP_INP_RLOCK(inp);
2920 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2921 SCTP_INP_RUNLOCK(inp);
2923 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2928 *optsize = sizeof(struct sctp_authkeyid);
2932 case SCTP_LOCAL_AUTH_CHUNKS:
2934 struct sctp_authchunks *sac;
2935 sctp_auth_chklist_t *chklist = NULL;
2938 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2939 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2942 /* get off the assoc */
2943 chklist = stcb->asoc.local_auth_chunks;
2944 /* is there enough space? */
2945 size = sctp_auth_get_chklist_size(chklist);
2946 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2948 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2950 /* copy in the chunks */
2951 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2952 sac->gauth_number_of_chunks = (uint32_t) size;
2953 *optsize = sizeof(struct sctp_authchunks) + size;
2955 SCTP_TCB_UNLOCK(stcb);
2957 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2958 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2959 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2960 /* get off the endpoint */
2961 SCTP_INP_RLOCK(inp);
2962 chklist = inp->sctp_ep.local_auth_chunks;
2963 /* is there enough space? */
2964 size = sctp_auth_get_chklist_size(chklist);
2965 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2969 /* copy in the chunks */
2970 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2971 sac->gauth_number_of_chunks = (uint32_t) size;
2972 *optsize = sizeof(struct sctp_authchunks) + size;
2974 SCTP_INP_RUNLOCK(inp);
2976 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2982 case SCTP_PEER_AUTH_CHUNKS:
2984 struct sctp_authchunks *sac;
2985 sctp_auth_chklist_t *chklist = NULL;
2988 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2989 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2992 /* get off the assoc */
2993 chklist = stcb->asoc.peer_auth_chunks;
2994 /* is there enough space? */
2995 size = sctp_auth_get_chklist_size(chklist);
2996 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2998 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3000 /* copy in the chunks */
3001 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3002 sac->gauth_number_of_chunks = (uint32_t) size;
3003 *optsize = sizeof(struct sctp_authchunks) + size;
3005 SCTP_TCB_UNLOCK(stcb);
3007 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3014 struct sctp_event *event;
3015 uint32_t event_type;
3017 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3018 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3020 switch (event->se_type) {
3021 case SCTP_ASSOC_CHANGE:
3022 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3024 case SCTP_PEER_ADDR_CHANGE:
3025 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3027 case SCTP_REMOTE_ERROR:
3028 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3030 case SCTP_SEND_FAILED:
3031 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3033 case SCTP_SHUTDOWN_EVENT:
3034 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3036 case SCTP_ADAPTATION_INDICATION:
3037 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3039 case SCTP_PARTIAL_DELIVERY_EVENT:
3040 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3042 case SCTP_AUTHENTICATION_EVENT:
3043 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3045 case SCTP_STREAM_RESET_EVENT:
3046 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3048 case SCTP_SENDER_DRY_EVENT:
3049 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3051 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3053 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3056 case SCTP_ASSOC_RESET_EVENT:
3057 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3059 case SCTP_STREAM_CHANGE_EVENT:
3060 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3062 case SCTP_SEND_FAILED_EVENT:
3063 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3067 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3071 if (event_type > 0) {
3073 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3074 SCTP_TCB_UNLOCK(stcb);
3076 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3077 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3078 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3079 SCTP_INP_RLOCK(inp);
3080 event->se_on = sctp_is_feature_on(inp, event_type);
3081 SCTP_INP_RUNLOCK(inp);
3083 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3089 *optsize = sizeof(struct sctp_event);
3093 case SCTP_RECVRCVINFO:
3097 if (*optsize < sizeof(int)) {
3098 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3101 SCTP_INP_RLOCK(inp);
3102 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3103 SCTP_INP_RUNLOCK(inp);
3106 /* return the option value */
3107 *(int *)optval = onoff;
3108 *optsize = sizeof(int);
3112 case SCTP_RECVNXTINFO:
3116 if (*optsize < sizeof(int)) {
3117 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3120 SCTP_INP_RLOCK(inp);
3121 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3122 SCTP_INP_RUNLOCK(inp);
3125 /* return the option value */
3126 *(int *)optval = onoff;
3127 *optsize = sizeof(int);
3131 case SCTP_DEFAULT_SNDINFO:
3133 struct sctp_sndinfo *info;
3135 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3136 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3139 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3140 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3141 info->snd_flags &= 0xfff0;
3142 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3143 info->snd_context = stcb->asoc.def_send.sinfo_context;
3144 SCTP_TCB_UNLOCK(stcb);
3146 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3147 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3148 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3149 SCTP_INP_RLOCK(inp);
3150 info->snd_sid = inp->def_send.sinfo_stream;
3151 info->snd_flags = inp->def_send.sinfo_flags;
3152 info->snd_flags &= 0xfff0;
3153 info->snd_ppid = inp->def_send.sinfo_ppid;
3154 info->snd_context = inp->def_send.sinfo_context;
3155 SCTP_INP_RUNLOCK(inp);
3157 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3162 *optsize = sizeof(struct sctp_sndinfo);
3166 case SCTP_DEFAULT_PRINFO:
3168 struct sctp_default_prinfo *info;
3170 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3171 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3174 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3175 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3176 SCTP_TCB_UNLOCK(stcb);
3178 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3179 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3180 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3181 SCTP_INP_RLOCK(inp);
3182 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3183 info->pr_value = inp->def_send.sinfo_timetolive;
3184 SCTP_INP_RUNLOCK(inp);
3186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3191 *optsize = sizeof(struct sctp_default_prinfo);
3195 case SCTP_PEER_ADDR_THLDS:
3197 struct sctp_paddrthlds *thlds;
3198 struct sctp_nets *net;
3199 struct sockaddr *addr;
3201 #if defined(INET) && defined(INET6)
3202 struct sockaddr_in sin_store;
3206 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3207 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3209 #if defined(INET) && defined(INET6)
3210 if (thlds->spt_address.ss_family == AF_INET6) {
3211 struct sockaddr_in6 *sin6;
3213 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3214 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3215 in6_sin6_2_sin(&sin_store, sin6);
3216 addr = (struct sockaddr *)&sin_store;
3218 addr = (struct sockaddr *)&thlds->spt_address;
3221 addr = (struct sockaddr *)&thlds->spt_address;
3224 addr = (struct sockaddr *)&thlds->spt_address;
3227 net = sctp_findnet(stcb, addr);
3230 * We increment here since
3231 * sctp_findassociation_ep_addr() wil do a
3232 * decrement if it finds the stcb as long as
3233 * the locked tcb (last argument) is NOT a
3237 SCTP_INP_INCR_REF(inp);
3238 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3240 SCTP_INP_DECR_REF(inp);
3243 if ((stcb != NULL) && (net == NULL)) {
3245 if (addr->sa_family == AF_INET) {
3246 struct sockaddr_in *sin;
3248 sin = (struct sockaddr_in *)addr;
3249 if (sin->sin_addr.s_addr != INADDR_ANY) {
3251 SCTP_TCB_UNLOCK(stcb);
3252 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3258 if (addr->sa_family == AF_INET6) {
3259 struct sockaddr_in6 *sin6;
3261 sin6 = (struct sockaddr_in6 *)addr;
3262 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3264 SCTP_TCB_UNLOCK(stcb);
3265 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3271 error = EAFNOSUPPORT;
3272 SCTP_TCB_UNLOCK(stcb);
3273 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3279 thlds->spt_pathmaxrxt = net->failure_threshold;
3280 thlds->spt_pathpfthld = net->pf_threshold;
3282 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3283 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3285 thlds->spt_assoc_id = sctp_get_associd(stcb);
3286 SCTP_TCB_UNLOCK(stcb);
3288 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3289 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3290 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3291 /* Use endpoint defaults */
3292 SCTP_INP_RLOCK(inp);
3293 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3294 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3295 SCTP_INP_RUNLOCK(inp);
3297 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3302 *optsize = sizeof(struct sctp_paddrthlds);
3306 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3308 struct sctp_udpencaps *encaps;
3309 struct sctp_nets *net;
3310 struct sockaddr *addr;
3312 #if defined(INET) && defined(INET6)
3313 struct sockaddr_in sin_store;
3317 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3318 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3320 #if defined(INET) && defined(INET6)
3321 if (encaps->sue_address.ss_family == AF_INET6) {
3322 struct sockaddr_in6 *sin6;
3324 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3325 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3326 in6_sin6_2_sin(&sin_store, sin6);
3327 addr = (struct sockaddr *)&sin_store;
3329 addr = (struct sockaddr *)&encaps->sue_address;
3332 addr = (struct sockaddr *)&encaps->sue_address;
3335 addr = (struct sockaddr *)&encaps->sue_address;
3338 net = sctp_findnet(stcb, addr);
3341 * We increment here since
3342 * sctp_findassociation_ep_addr() wil do a
3343 * decrement if it finds the stcb as long as
3344 * the locked tcb (last argument) is NOT a
3348 SCTP_INP_INCR_REF(inp);
3349 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3351 SCTP_INP_DECR_REF(inp);
3354 if ((stcb != NULL) && (net == NULL)) {
3356 if (addr->sa_family == AF_INET) {
3357 struct sockaddr_in *sin;
3359 sin = (struct sockaddr_in *)addr;
3360 if (sin->sin_addr.s_addr != INADDR_ANY) {
3362 SCTP_TCB_UNLOCK(stcb);
3363 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3369 if (addr->sa_family == AF_INET6) {
3370 struct sockaddr_in6 *sin6;
3372 sin6 = (struct sockaddr_in6 *)addr;
3373 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3375 SCTP_TCB_UNLOCK(stcb);
3376 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3382 error = EAFNOSUPPORT;
3383 SCTP_TCB_UNLOCK(stcb);
3384 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3390 encaps->sue_port = net->port;
3392 encaps->sue_port = stcb->asoc.port;
3394 SCTP_TCB_UNLOCK(stcb);
3396 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3397 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3398 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3399 SCTP_INP_RLOCK(inp);
3400 encaps->sue_port = inp->sctp_ep.port;
3401 SCTP_INP_RUNLOCK(inp);
3403 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3408 *optsize = sizeof(struct sctp_udpencaps);
3412 case SCTP_ECN_SUPPORTED:
3414 struct sctp_assoc_value *av;
3416 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3417 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3420 av->assoc_value = stcb->asoc.ecn_supported;
3421 SCTP_TCB_UNLOCK(stcb);
3423 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3424 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3425 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3426 SCTP_INP_RLOCK(inp);
3427 av->assoc_value = inp->ecn_supported;
3428 SCTP_INP_RUNLOCK(inp);
3430 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3435 *optsize = sizeof(struct sctp_assoc_value);
3439 case SCTP_PR_SUPPORTED:
3441 struct sctp_assoc_value *av;
3443 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3444 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3447 av->assoc_value = stcb->asoc.prsctp_supported;
3448 SCTP_TCB_UNLOCK(stcb);
3450 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3451 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3452 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3453 SCTP_INP_RLOCK(inp);
3454 av->assoc_value = inp->prsctp_supported;
3455 SCTP_INP_RUNLOCK(inp);
3457 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3462 *optsize = sizeof(struct sctp_assoc_value);
3466 case SCTP_AUTH_SUPPORTED:
3468 struct sctp_assoc_value *av;
3470 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3471 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3474 av->assoc_value = stcb->asoc.auth_supported;
3475 SCTP_TCB_UNLOCK(stcb);
3477 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3478 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3479 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3480 SCTP_INP_RLOCK(inp);
3481 av->assoc_value = inp->auth_supported;
3482 SCTP_INP_RUNLOCK(inp);
3484 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3489 *optsize = sizeof(struct sctp_assoc_value);
3493 case SCTP_ASCONF_SUPPORTED:
3495 struct sctp_assoc_value *av;
3497 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3498 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3501 av->assoc_value = stcb->asoc.asconf_supported;
3502 SCTP_TCB_UNLOCK(stcb);
3504 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3505 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3506 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3507 SCTP_INP_RLOCK(inp);
3508 av->assoc_value = inp->asconf_supported;
3509 SCTP_INP_RUNLOCK(inp);
3511 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3516 *optsize = sizeof(struct sctp_assoc_value);
3520 case SCTP_RECONFIG_SUPPORTED:
3522 struct sctp_assoc_value *av;
3524 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3525 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3528 av->assoc_value = stcb->asoc.reconfig_supported;
3529 SCTP_TCB_UNLOCK(stcb);
3531 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3532 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3533 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3534 SCTP_INP_RLOCK(inp);
3535 av->assoc_value = inp->reconfig_supported;
3536 SCTP_INP_RUNLOCK(inp);
3538 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3543 *optsize = sizeof(struct sctp_assoc_value);
3547 case SCTP_NRSACK_SUPPORTED:
3549 struct sctp_assoc_value *av;
3551 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3552 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3555 av->assoc_value = stcb->asoc.nrsack_supported;
3556 SCTP_TCB_UNLOCK(stcb);
3558 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3559 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3560 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3561 SCTP_INP_RLOCK(inp);
3562 av->assoc_value = inp->nrsack_supported;
3563 SCTP_INP_RUNLOCK(inp);
3565 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3570 *optsize = sizeof(struct sctp_assoc_value);
3574 case SCTP_PKTDROP_SUPPORTED:
3576 struct sctp_assoc_value *av;
3578 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3579 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3582 av->assoc_value = stcb->asoc.pktdrop_supported;
3583 SCTP_TCB_UNLOCK(stcb);
3585 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3586 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3587 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3588 SCTP_INP_RLOCK(inp);
3589 av->assoc_value = inp->pktdrop_supported;
3590 SCTP_INP_RUNLOCK(inp);
3592 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3597 *optsize = sizeof(struct sctp_assoc_value);
3601 case SCTP_ENABLE_STREAM_RESET:
3603 struct sctp_assoc_value *av;
3605 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3606 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3609 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3610 SCTP_TCB_UNLOCK(stcb);
3612 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3613 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3614 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3615 SCTP_INP_RLOCK(inp);
3616 av->assoc_value = (uint32_t) inp->local_strreset_support;
3617 SCTP_INP_RUNLOCK(inp);
3619 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3624 *optsize = sizeof(struct sctp_assoc_value);
3628 case SCTP_PR_STREAM_STATUS:
3630 struct sctp_prstatus *sprstat;
3634 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3635 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3637 sid = sprstat->sprstat_sid;
3638 policy = sprstat->sprstat_policy;
3639 #if defined(SCTP_DETAILED_STR_STATS)
3640 if ((stcb != NULL) &&
3641 (sid < stcb->asoc.streamoutcnt) &&
3642 (policy != SCTP_PR_SCTP_NONE) &&
3643 ((policy <= SCTP_PR_SCTP_MAX) ||
3644 (policy == SCTP_PR_SCTP_ALL))) {
3645 if (policy == SCTP_PR_SCTP_ALL) {
3646 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3647 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3649 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3650 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3653 if ((stcb != NULL) &&
3654 (sid < stcb->asoc.streamoutcnt) &&
3655 (policy == SCTP_PR_SCTP_ALL)) {
3656 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3657 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3659 SCTP_TCB_UNLOCK(stcb);
3660 *optsize = sizeof(struct sctp_prstatus);
3662 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3667 case SCTP_PR_ASSOC_STATUS:
3669 struct sctp_prstatus *sprstat;
3672 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3673 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3675 policy = sprstat->sprstat_policy;
3676 if ((stcb != NULL) &&
3677 (policy != SCTP_PR_SCTP_NONE) &&
3678 ((policy <= SCTP_PR_SCTP_MAX) ||
3679 (policy == SCTP_PR_SCTP_ALL))) {
3680 if (policy == SCTP_PR_SCTP_ALL) {
3681 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3682 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3684 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3685 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3687 SCTP_TCB_UNLOCK(stcb);
3688 *optsize = sizeof(struct sctp_prstatus);
3690 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3697 struct sctp_assoc_value *av;
3699 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3700 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3703 av->assoc_value = stcb->asoc.max_cwnd;
3704 SCTP_TCB_UNLOCK(stcb);
3706 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3707 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3708 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3709 SCTP_INP_RLOCK(inp);
3710 av->assoc_value = inp->max_cwnd;
3711 SCTP_INP_RUNLOCK(inp);
3713 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3718 *optsize = sizeof(struct sctp_assoc_value);
3723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3724 error = ENOPROTOOPT;
3726 } /* end switch (sopt->sopt_name) */
3734 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3739 struct sctp_tcb *stcb = NULL;
3740 struct sctp_inpcb *inp = NULL;
3743 if (optval == NULL) {
3744 SCTP_PRINTF("optval is NULL\n");
3745 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3748 inp = (struct sctp_inpcb *)so->so_pcb;
3750 SCTP_PRINTF("inp is NULL?\n");
3751 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3754 vrf_id = inp->def_vrf_id;
3759 case SCTP_AUTOCLOSE:
3760 case SCTP_AUTO_ASCONF:
3761 case SCTP_EXPLICIT_EOR:
3762 case SCTP_DISABLE_FRAGMENTS:
3763 case SCTP_USE_EXT_RCVINFO:
3764 case SCTP_I_WANT_MAPPED_V4_ADDR:
3765 /* copy in the option value */
3766 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3771 case SCTP_DISABLE_FRAGMENTS:
3772 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3774 case SCTP_AUTO_ASCONF:
3776 * NOTE: we don't really support this flag
3778 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3779 /* only valid for bound all sockets */
3780 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3782 /* forbidden by admin */
3783 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3786 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3788 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3792 case SCTP_EXPLICIT_EOR:
3793 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3795 case SCTP_USE_EXT_RCVINFO:
3796 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3798 case SCTP_I_WANT_MAPPED_V4_ADDR:
3799 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3800 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3802 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3807 set_opt = SCTP_PCB_FLAGS_NODELAY;
3809 case SCTP_AUTOCLOSE:
3810 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3811 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3812 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3815 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3817 * The value is in ticks. Note this does not effect
3818 * old associations, only new ones.
3820 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3823 SCTP_INP_WLOCK(inp);
3825 sctp_feature_on(inp, set_opt);
3827 sctp_feature_off(inp, set_opt);
3829 SCTP_INP_WUNLOCK(inp);
3831 case SCTP_REUSE_PORT:
3833 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3834 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3835 /* Can't set it after we are bound */
3839 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3840 /* Can't do this for a 1-m socket */
3845 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3847 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3850 case SCTP_PARTIAL_DELIVERY_POINT:
3854 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3855 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3856 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3860 inp->partial_delivery_point = *value;
3863 case SCTP_FRAGMENT_INTERLEAVE:
3864 /* not yet until we re-write sctp_recvmsg() */
3868 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3869 if (*level == SCTP_FRAG_LEVEL_2) {
3870 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3871 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3872 } else if (*level == SCTP_FRAG_LEVEL_1) {
3873 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3874 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3875 } else if (*level == SCTP_FRAG_LEVEL_0) {
3876 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3877 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3880 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3885 case SCTP_CMT_ON_OFF:
3886 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3887 struct sctp_assoc_value *av;
3889 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3890 if (av->assoc_value > SCTP_CMT_MAX) {
3891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3895 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3897 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3898 SCTP_TCB_UNLOCK(stcb);
3900 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3901 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3902 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3903 (av->assoc_id == SCTP_ALL_ASSOC)) {
3904 SCTP_INP_WLOCK(inp);
3905 inp->sctp_cmt_on_off = av->assoc_value;
3906 SCTP_INP_WUNLOCK(inp);
3908 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3909 (av->assoc_id == SCTP_ALL_ASSOC)) {
3910 SCTP_INP_RLOCK(inp);
3911 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3912 SCTP_TCB_LOCK(stcb);
3913 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3914 SCTP_TCB_UNLOCK(stcb);
3916 SCTP_INP_RUNLOCK(inp);
3920 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3921 error = ENOPROTOOPT;
3924 case SCTP_PLUGGABLE_CC:
3926 struct sctp_assoc_value *av;
3927 struct sctp_nets *net;
3929 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3930 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3931 (av->assoc_value != SCTP_CC_HSTCP) &&
3932 (av->assoc_value != SCTP_CC_HTCP) &&
3933 (av->assoc_value != SCTP_CC_RTCC)) {
3934 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3938 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3940 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3941 stcb->asoc.congestion_control_module = av->assoc_value;
3942 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3943 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3944 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3947 SCTP_TCB_UNLOCK(stcb);
3949 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3950 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3951 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3952 (av->assoc_id == SCTP_ALL_ASSOC)) {
3953 SCTP_INP_WLOCK(inp);
3954 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3955 SCTP_INP_WUNLOCK(inp);
3957 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3958 (av->assoc_id == SCTP_ALL_ASSOC)) {
3959 SCTP_INP_RLOCK(inp);
3960 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3961 SCTP_TCB_LOCK(stcb);
3962 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3963 stcb->asoc.congestion_control_module = av->assoc_value;
3964 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3965 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3966 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3969 SCTP_TCB_UNLOCK(stcb);
3971 SCTP_INP_RUNLOCK(inp);
3976 case SCTP_CC_OPTION:
3978 struct sctp_cc_option *cc_opt;
3980 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3981 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3983 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3984 SCTP_INP_RLOCK(inp);
3985 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3986 SCTP_TCB_LOCK(stcb);
3987 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3988 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3990 SCTP_TCB_UNLOCK(stcb);
3992 SCTP_INP_RUNLOCK(inp);
3997 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4000 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4003 SCTP_TCB_UNLOCK(stcb);
4007 case SCTP_PLUGGABLE_SS:
4009 struct sctp_assoc_value *av;
4011 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4012 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4013 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4014 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4015 (av->assoc_value != SCTP_SS_PRIORITY) &&
4016 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4017 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4018 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4022 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4024 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4025 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4026 stcb->asoc.stream_scheduling_module = av->assoc_value;
4027 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4028 SCTP_TCB_UNLOCK(stcb);
4030 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4031 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4032 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4033 (av->assoc_id == SCTP_ALL_ASSOC)) {
4034 SCTP_INP_WLOCK(inp);
4035 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4036 SCTP_INP_WUNLOCK(inp);
4038 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4039 (av->assoc_id == SCTP_ALL_ASSOC)) {
4040 SCTP_INP_RLOCK(inp);
4041 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4042 SCTP_TCB_LOCK(stcb);
4043 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4044 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4045 stcb->asoc.stream_scheduling_module = av->assoc_value;
4046 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4047 SCTP_TCB_UNLOCK(stcb);
4049 SCTP_INP_RUNLOCK(inp);
4056 struct sctp_stream_value *av;
4058 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4059 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4061 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4062 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4063 av->stream_value) < 0)) {
4064 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4067 SCTP_TCB_UNLOCK(stcb);
4069 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4070 SCTP_INP_RLOCK(inp);
4071 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4072 SCTP_TCB_LOCK(stcb);
4073 if (av->stream_id < stcb->asoc.streamoutcnt) {
4074 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4076 &stcb->asoc.strmout[av->stream_id],
4079 SCTP_TCB_UNLOCK(stcb);
4081 SCTP_INP_RUNLOCK(inp);
4084 * Can't set stream value without
4087 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4093 case SCTP_CLR_STAT_LOG:
4094 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4099 struct sctp_assoc_value *av;
4101 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4102 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4105 stcb->asoc.context = av->assoc_value;
4106 SCTP_TCB_UNLOCK(stcb);
4108 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4109 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4110 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4111 (av->assoc_id == SCTP_ALL_ASSOC)) {
4112 SCTP_INP_WLOCK(inp);
4113 inp->sctp_context = av->assoc_value;
4114 SCTP_INP_WUNLOCK(inp);
4116 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4117 (av->assoc_id == SCTP_ALL_ASSOC)) {
4118 SCTP_INP_RLOCK(inp);
4119 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4120 SCTP_TCB_LOCK(stcb);
4121 stcb->asoc.context = av->assoc_value;
4122 SCTP_TCB_UNLOCK(stcb);
4124 SCTP_INP_RUNLOCK(inp);
4131 uint32_t *default_vrfid;
4133 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4134 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4135 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4139 inp->def_vrf_id = *default_vrfid;
4142 case SCTP_DEL_VRF_ID:
4144 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4148 case SCTP_ADD_VRF_ID:
4150 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4154 case SCTP_DELAYED_SACK:
4156 struct sctp_sack_info *sack;
4158 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4159 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4160 if (sack->sack_delay) {
4161 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4162 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4163 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4164 sack->sack_delay = TICKS_TO_MSEC(1);
4168 if (sack->sack_delay) {
4169 stcb->asoc.delayed_ack = sack->sack_delay;
4171 if (sack->sack_freq) {
4172 stcb->asoc.sack_freq = sack->sack_freq;
4174 SCTP_TCB_UNLOCK(stcb);
4176 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4177 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4178 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4179 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4180 SCTP_INP_WLOCK(inp);
4181 if (sack->sack_delay) {
4182 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4184 if (sack->sack_freq) {
4185 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4187 SCTP_INP_WUNLOCK(inp);
4189 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4190 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4191 SCTP_INP_RLOCK(inp);
4192 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4193 SCTP_TCB_LOCK(stcb);
4194 if (sack->sack_delay) {
4195 stcb->asoc.delayed_ack = sack->sack_delay;
4197 if (sack->sack_freq) {
4198 stcb->asoc.sack_freq = sack->sack_freq;
4200 SCTP_TCB_UNLOCK(stcb);
4202 SCTP_INP_RUNLOCK(inp);
4207 case SCTP_AUTH_CHUNK:
4209 struct sctp_authchunk *sauth;
4211 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4213 SCTP_INP_WLOCK(inp);
4214 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4215 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4218 SCTP_INP_WUNLOCK(inp);
4223 struct sctp_authkey *sca;
4224 struct sctp_keyhead *shared_keys;
4225 sctp_sharedkey_t *shared_key;
4226 sctp_key_t *key = NULL;
4229 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4230 if (sca->sca_keylength == 0) {
4231 size = optsize - sizeof(struct sctp_authkey);
4233 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4234 size = sca->sca_keylength;
4236 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4241 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4244 shared_keys = &stcb->asoc.shared_keys;
4245 /* clear the cached keys for this key id */
4246 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4248 * create the new shared key and
4252 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4254 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4256 SCTP_TCB_UNLOCK(stcb);
4260 shared_key = sctp_alloc_sharedkey();
4261 if (shared_key == NULL) {
4263 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4265 SCTP_TCB_UNLOCK(stcb);
4268 shared_key->key = key;
4269 shared_key->keyid = sca->sca_keynumber;
4270 error = sctp_insert_sharedkey(shared_keys, shared_key);
4271 SCTP_TCB_UNLOCK(stcb);
4273 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4274 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4275 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4276 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4277 SCTP_INP_WLOCK(inp);
4278 shared_keys = &inp->sctp_ep.shared_keys;
4280 * clear the cached keys on all
4281 * assocs for this key id
4283 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4285 * create the new shared key and
4289 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4291 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4293 SCTP_INP_WUNLOCK(inp);
4297 shared_key = sctp_alloc_sharedkey();
4298 if (shared_key == NULL) {
4300 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4302 SCTP_INP_WUNLOCK(inp);
4305 shared_key->key = key;
4306 shared_key->keyid = sca->sca_keynumber;
4307 error = sctp_insert_sharedkey(shared_keys, shared_key);
4308 SCTP_INP_WUNLOCK(inp);
4310 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4311 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4312 SCTP_INP_RLOCK(inp);
4313 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4314 SCTP_TCB_LOCK(stcb);
4315 shared_keys = &stcb->asoc.shared_keys;
4317 * clear the cached keys for
4320 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4322 * create the new shared key
4323 * and insert/replace it
4326 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4328 SCTP_TCB_UNLOCK(stcb);
4332 shared_key = sctp_alloc_sharedkey();
4333 if (shared_key == NULL) {
4335 SCTP_TCB_UNLOCK(stcb);
4338 shared_key->key = key;
4339 shared_key->keyid = sca->sca_keynumber;
4340 error = sctp_insert_sharedkey(shared_keys, shared_key);
4341 SCTP_TCB_UNLOCK(stcb);
4343 SCTP_INP_RUNLOCK(inp);
4348 case SCTP_HMAC_IDENT:
4350 struct sctp_hmacalgo *shmac;
4351 sctp_hmaclist_t *hmaclist;
4355 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4356 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4357 (shmac->shmac_number_of_idents > 0xffff)) {
4358 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4362 hmaclist = sctp_alloc_hmaclist((uint16_t) shmac->shmac_number_of_idents);
4363 if (hmaclist == NULL) {
4364 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4368 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4369 hmacid = shmac->shmac_idents[i];
4370 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4371 /* invalid HMACs were found */ ;
4372 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4374 sctp_free_hmaclist(hmaclist);
4375 goto sctp_set_hmac_done;
4378 for (i = 0; i < hmaclist->num_algo; i++) {
4379 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4380 /* already in list */
4384 if (i == hmaclist->num_algo) {
4385 /* not found in list */
4386 sctp_free_hmaclist(hmaclist);
4387 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4391 /* set it on the endpoint */
4392 SCTP_INP_WLOCK(inp);
4393 if (inp->sctp_ep.local_hmacs)
4394 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4395 inp->sctp_ep.local_hmacs = hmaclist;
4396 SCTP_INP_WUNLOCK(inp);
4400 case SCTP_AUTH_ACTIVE_KEY:
4402 struct sctp_authkeyid *scact;
4404 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4405 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4407 /* set the active key on the right place */
4409 /* set the active key on the assoc */
4410 if (sctp_auth_setactivekey(stcb,
4411 scact->scact_keynumber)) {
4412 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4413 SCTP_FROM_SCTP_USRREQ,
4417 SCTP_TCB_UNLOCK(stcb);
4419 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4420 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4421 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4422 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4423 SCTP_INP_WLOCK(inp);
4424 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4425 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4428 SCTP_INP_WUNLOCK(inp);
4430 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4431 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4432 SCTP_INP_RLOCK(inp);
4433 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4434 SCTP_TCB_LOCK(stcb);
4435 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4436 SCTP_TCB_UNLOCK(stcb);
4438 SCTP_INP_RUNLOCK(inp);
4443 case SCTP_AUTH_DELETE_KEY:
4445 struct sctp_authkeyid *scdel;
4447 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4448 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4450 /* delete the key from the right place */
4452 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4453 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4456 SCTP_TCB_UNLOCK(stcb);
4458 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4459 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4460 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4461 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4462 SCTP_INP_WLOCK(inp);
4463 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4464 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4467 SCTP_INP_WUNLOCK(inp);
4469 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4470 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4471 SCTP_INP_RLOCK(inp);
4472 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4473 SCTP_TCB_LOCK(stcb);
4474 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4475 SCTP_TCB_UNLOCK(stcb);
4477 SCTP_INP_RUNLOCK(inp);
4482 case SCTP_AUTH_DEACTIVATE_KEY:
4484 struct sctp_authkeyid *keyid;
4486 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4487 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4489 /* deactivate the key from the right place */
4491 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4492 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4495 SCTP_TCB_UNLOCK(stcb);
4497 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4498 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4499 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4500 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4501 SCTP_INP_WLOCK(inp);
4502 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4503 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4506 SCTP_INP_WUNLOCK(inp);
4508 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4509 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4510 SCTP_INP_RLOCK(inp);
4511 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4512 SCTP_TCB_LOCK(stcb);
4513 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4514 SCTP_TCB_UNLOCK(stcb);
4516 SCTP_INP_RUNLOCK(inp);
4521 case SCTP_ENABLE_STREAM_RESET:
4523 struct sctp_assoc_value *av;
4525 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4526 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4527 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4531 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4533 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4534 SCTP_TCB_UNLOCK(stcb);
4536 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4537 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4538 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4539 (av->assoc_id == SCTP_ALL_ASSOC)) {
4540 SCTP_INP_WLOCK(inp);
4541 inp->local_strreset_support = (uint8_t) av->assoc_value;
4542 SCTP_INP_WUNLOCK(inp);
4544 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4545 (av->assoc_id == SCTP_ALL_ASSOC)) {
4546 SCTP_INP_RLOCK(inp);
4547 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4548 SCTP_TCB_LOCK(stcb);
4549 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4550 SCTP_TCB_UNLOCK(stcb);
4552 SCTP_INP_RUNLOCK(inp);
4557 case SCTP_RESET_STREAMS:
4559 struct sctp_reset_streams *strrst;
4560 int i, send_out = 0;
4563 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4564 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4566 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4570 if (stcb->asoc.reconfig_supported == 0) {
4572 * Peer does not support the chunk type.
4574 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4576 SCTP_TCB_UNLOCK(stcb);
4579 if (sizeof(struct sctp_reset_streams) +
4580 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4582 SCTP_TCB_UNLOCK(stcb);
4585 if (stcb->asoc.stream_reset_outstanding) {
4586 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4588 SCTP_TCB_UNLOCK(stcb);
4591 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4594 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4597 if ((send_in == 0) && (send_out == 0)) {
4598 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4600 SCTP_TCB_UNLOCK(stcb);
4603 for (i = 0; i < strrst->srs_number_streams; i++) {
4605 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4606 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4611 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4612 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4618 SCTP_TCB_UNLOCK(stcb);
4621 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4622 strrst->srs_stream_list,
4623 send_out, send_in, 0, 0, 0, 0, 0);
4625 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4626 SCTP_TCB_UNLOCK(stcb);
4629 case SCTP_ADD_STREAMS:
4631 struct sctp_add_streams *stradd;
4632 uint8_t addstream = 0;
4633 uint16_t add_o_strmcnt = 0;
4634 uint16_t add_i_strmcnt = 0;
4636 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4637 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4639 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4643 if (stcb->asoc.reconfig_supported == 0) {
4645 * Peer does not support the chunk type.
4647 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4649 SCTP_TCB_UNLOCK(stcb);
4652 if (stcb->asoc.stream_reset_outstanding) {
4653 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4655 SCTP_TCB_UNLOCK(stcb);
4658 if ((stradd->sas_outstrms == 0) &&
4659 (stradd->sas_instrms == 0)) {
4663 if (stradd->sas_outstrms) {
4665 /* We allocate here */
4666 add_o_strmcnt = stradd->sas_outstrms;
4667 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4668 /* You can't have more than 64k */
4673 if (stradd->sas_instrms) {
4678 * We allocate inside
4679 * sctp_send_str_reset_req()
4681 add_i_strmcnt = stradd->sas_instrms;
4682 cnt = add_i_strmcnt;
4683 cnt += stcb->asoc.streamincnt;
4684 if (cnt > 0x0000ffff) {
4685 /* You can't have more than 64k */
4689 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4690 /* More than you are allowed */
4695 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4696 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4698 SCTP_TCB_UNLOCK(stcb);
4701 case SCTP_RESET_ASSOC:
4705 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4706 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4708 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4712 if (stcb->asoc.reconfig_supported == 0) {
4714 * Peer does not support the chunk type.
4716 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4718 SCTP_TCB_UNLOCK(stcb);
4721 if (stcb->asoc.stream_reset_outstanding) {
4722 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4724 SCTP_TCB_UNLOCK(stcb);
4727 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 1, 0, 0, 0, 0);
4728 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4729 SCTP_TCB_UNLOCK(stcb);
4732 case SCTP_CONNECT_X:
4733 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4734 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4738 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4740 case SCTP_CONNECT_X_DELAYED:
4741 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4746 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4748 case SCTP_CONNECT_X_COMPLETE:
4750 struct sockaddr *sa;
4752 /* FIXME MT: check correct? */
4753 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4756 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4757 SCTP_INP_RLOCK(inp);
4758 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4760 SCTP_TCB_LOCK(stcb);
4762 SCTP_INP_RUNLOCK(inp);
4765 * We increment here since
4766 * sctp_findassociation_ep_addr() wil do a
4767 * decrement if it finds the stcb as long as
4768 * the locked tcb (last argument) is NOT a
4771 SCTP_INP_INCR_REF(inp);
4772 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4774 SCTP_INP_DECR_REF(inp);
4779 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4783 if (stcb->asoc.delayed_connection == 1) {
4784 stcb->asoc.delayed_connection = 0;
4785 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4786 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4787 stcb->asoc.primary_destination,
4788 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4789 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4792 * already expired or did not use delayed
4795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4798 SCTP_TCB_UNLOCK(stcb);
4801 case SCTP_MAX_BURST:
4803 struct sctp_assoc_value *av;
4805 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4806 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4809 stcb->asoc.max_burst = av->assoc_value;
4810 SCTP_TCB_UNLOCK(stcb);
4812 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4813 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4814 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4815 (av->assoc_id == SCTP_ALL_ASSOC)) {
4816 SCTP_INP_WLOCK(inp);
4817 inp->sctp_ep.max_burst = av->assoc_value;
4818 SCTP_INP_WUNLOCK(inp);
4820 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4821 (av->assoc_id == SCTP_ALL_ASSOC)) {
4822 SCTP_INP_RLOCK(inp);
4823 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4824 SCTP_TCB_LOCK(stcb);
4825 stcb->asoc.max_burst = av->assoc_value;
4826 SCTP_TCB_UNLOCK(stcb);
4828 SCTP_INP_RUNLOCK(inp);
4835 struct sctp_assoc_value *av;
4838 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4839 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4841 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4842 ovh = SCTP_MED_OVERHEAD;
4844 ovh = SCTP_MED_V4_OVERHEAD;
4847 if (av->assoc_value) {
4848 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4850 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4852 SCTP_TCB_UNLOCK(stcb);
4854 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4855 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4856 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4857 SCTP_INP_WLOCK(inp);
4859 * FIXME MT: I think this is not in
4860 * tune with the API ID
4862 if (av->assoc_value) {
4863 inp->sctp_frag_point = (av->assoc_value + ovh);
4865 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4867 SCTP_INP_WUNLOCK(inp);
4869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4877 struct sctp_event_subscribe *events;
4879 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4881 SCTP_INP_WLOCK(inp);
4882 if (events->sctp_data_io_event) {
4883 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4885 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4888 if (events->sctp_association_event) {
4889 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4891 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4894 if (events->sctp_address_event) {
4895 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4897 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4900 if (events->sctp_send_failure_event) {
4901 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4903 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4906 if (events->sctp_peer_error_event) {
4907 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4909 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4912 if (events->sctp_shutdown_event) {
4913 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4915 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4918 if (events->sctp_partial_delivery_event) {
4919 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4921 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4924 if (events->sctp_adaptation_layer_event) {
4925 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4927 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4930 if (events->sctp_authentication_event) {
4931 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4933 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4936 if (events->sctp_sender_dry_event) {
4937 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4939 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4942 if (events->sctp_stream_reset_event) {
4943 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4945 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4947 SCTP_INP_WUNLOCK(inp);
4949 SCTP_INP_RLOCK(inp);
4950 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4951 SCTP_TCB_LOCK(stcb);
4952 if (events->sctp_association_event) {
4953 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4955 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4957 if (events->sctp_address_event) {
4958 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4960 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4962 if (events->sctp_send_failure_event) {
4963 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4965 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4967 if (events->sctp_peer_error_event) {
4968 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4970 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4972 if (events->sctp_shutdown_event) {
4973 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4975 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4977 if (events->sctp_partial_delivery_event) {
4978 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4980 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4982 if (events->sctp_adaptation_layer_event) {
4983 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4985 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4987 if (events->sctp_authentication_event) {
4988 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4990 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4992 if (events->sctp_sender_dry_event) {
4993 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4995 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4997 if (events->sctp_stream_reset_event) {
4998 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5000 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5002 SCTP_TCB_UNLOCK(stcb);
5005 * Send up the sender dry event only for 1-to-1
5008 if (events->sctp_sender_dry_event) {
5009 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5010 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5011 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5013 SCTP_TCB_LOCK(stcb);
5014 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5015 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5016 (stcb->asoc.stream_queue_cnt == 0)) {
5017 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5019 SCTP_TCB_UNLOCK(stcb);
5023 SCTP_INP_RUNLOCK(inp);
5026 case SCTP_ADAPTATION_LAYER:
5028 struct sctp_setadaptation *adap_bits;
5030 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5031 SCTP_INP_WLOCK(inp);
5032 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5033 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5034 SCTP_INP_WUNLOCK(inp);
5038 case SCTP_SET_INITIAL_DBG_SEQ:
5042 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5043 SCTP_INP_WLOCK(inp);
5044 inp->sctp_ep.initial_sequence_debug = *vvv;
5045 SCTP_INP_WUNLOCK(inp);
5049 case SCTP_DEFAULT_SEND_PARAM:
5051 struct sctp_sndrcvinfo *s_info;
5053 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5054 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5057 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5058 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5060 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5063 SCTP_TCB_UNLOCK(stcb);
5065 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5066 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5067 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5068 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5069 SCTP_INP_WLOCK(inp);
5070 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5071 SCTP_INP_WUNLOCK(inp);
5073 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5074 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5075 SCTP_INP_RLOCK(inp);
5076 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5077 SCTP_TCB_LOCK(stcb);
5078 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5079 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5081 SCTP_TCB_UNLOCK(stcb);
5083 SCTP_INP_RUNLOCK(inp);
5088 case SCTP_PEER_ADDR_PARAMS:
5090 struct sctp_paddrparams *paddrp;
5091 struct sctp_nets *net;
5092 struct sockaddr *addr;
5094 #if defined(INET) && defined(INET6)
5095 struct sockaddr_in sin_store;
5099 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5100 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5102 #if defined(INET) && defined(INET6)
5103 if (paddrp->spp_address.ss_family == AF_INET6) {
5104 struct sockaddr_in6 *sin6;
5106 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5107 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5108 in6_sin6_2_sin(&sin_store, sin6);
5109 addr = (struct sockaddr *)&sin_store;
5111 addr = (struct sockaddr *)&paddrp->spp_address;
5114 addr = (struct sockaddr *)&paddrp->spp_address;
5117 addr = (struct sockaddr *)&paddrp->spp_address;
5120 net = sctp_findnet(stcb, addr);
5123 * We increment here since
5124 * sctp_findassociation_ep_addr() wil do a
5125 * decrement if it finds the stcb as long as
5126 * the locked tcb (last argument) is NOT a
5130 SCTP_INP_INCR_REF(inp);
5131 stcb = sctp_findassociation_ep_addr(&inp, addr,
5134 SCTP_INP_DECR_REF(inp);
5137 if ((stcb != NULL) && (net == NULL)) {
5139 if (addr->sa_family == AF_INET) {
5141 struct sockaddr_in *sin;
5143 sin = (struct sockaddr_in *)addr;
5144 if (sin->sin_addr.s_addr != INADDR_ANY) {
5145 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5146 SCTP_TCB_UNLOCK(stcb);
5153 if (addr->sa_family == AF_INET6) {
5154 struct sockaddr_in6 *sin6;
5156 sin6 = (struct sockaddr_in6 *)addr;
5157 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5158 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5159 SCTP_TCB_UNLOCK(stcb);
5166 error = EAFNOSUPPORT;
5167 SCTP_TCB_UNLOCK(stcb);
5168 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5173 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5175 SCTP_TCB_UNLOCK(stcb);
5176 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5179 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5181 SCTP_TCB_UNLOCK(stcb);
5182 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5186 /************************TCB SPECIFIC SET ******************/
5188 * do we change the timer for HB, we run
5193 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5194 ovh = SCTP_MED_OVERHEAD;
5196 ovh = SCTP_MED_V4_OVERHEAD;
5199 /* network sets ? */
5201 /************************NET SPECIFIC SET ******************/
5202 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5203 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5204 !(net->dest_state & SCTP_ADDR_NOHB)) {
5205 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5206 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5208 net->dest_state |= SCTP_ADDR_NOHB;
5210 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5211 if (paddrp->spp_hbinterval) {
5212 net->heart_beat_delay = paddrp->spp_hbinterval;
5213 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5214 net->heart_beat_delay = 0;
5216 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5217 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5218 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5219 net->dest_state &= ~SCTP_ADDR_NOHB;
5221 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5223 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5224 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5225 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5227 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5228 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5229 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5230 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5232 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5233 net->mtu = paddrp->spp_pathmtu + ovh;
5234 if (net->mtu < stcb->asoc.smallest_mtu) {
5235 sctp_pathmtu_adjustment(stcb, net->mtu);
5238 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5239 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5240 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5242 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5244 if (paddrp->spp_pathmaxrxt) {
5245 if (net->dest_state & SCTP_ADDR_PF) {
5246 if (net->error_count > paddrp->spp_pathmaxrxt) {
5247 net->dest_state &= ~SCTP_ADDR_PF;
5250 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5251 (net->error_count > net->pf_threshold)) {
5252 net->dest_state |= SCTP_ADDR_PF;
5253 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5254 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5255 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5258 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5259 if (net->error_count > paddrp->spp_pathmaxrxt) {
5260 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5261 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5264 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5265 net->dest_state |= SCTP_ADDR_REACHABLE;
5266 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5269 net->failure_threshold = paddrp->spp_pathmaxrxt;
5271 if (paddrp->spp_flags & SPP_DSCP) {
5272 net->dscp = paddrp->spp_dscp & 0xfc;
5276 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5277 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5278 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5279 net->flowlabel |= 0x80000000;
5284 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5285 if (paddrp->spp_pathmaxrxt != 0) {
5286 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5287 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5288 if (net->dest_state & SCTP_ADDR_PF) {
5289 if (net->error_count > paddrp->spp_pathmaxrxt) {
5290 net->dest_state &= ~SCTP_ADDR_PF;
5293 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5294 (net->error_count > net->pf_threshold)) {
5295 net->dest_state |= SCTP_ADDR_PF;
5296 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5297 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5298 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5301 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5302 if (net->error_count > paddrp->spp_pathmaxrxt) {
5303 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5304 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5307 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5308 net->dest_state |= SCTP_ADDR_REACHABLE;
5309 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5312 net->failure_threshold = paddrp->spp_pathmaxrxt;
5315 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5316 if (paddrp->spp_hbinterval != 0) {
5317 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5318 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5319 stcb->asoc.heart_beat_delay = 0;
5321 /* Turn back on the timer */
5322 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5323 if (paddrp->spp_hbinterval != 0) {
5324 net->heart_beat_delay = paddrp->spp_hbinterval;
5325 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5326 net->heart_beat_delay = 0;
5328 if (net->dest_state & SCTP_ADDR_NOHB) {
5329 net->dest_state &= ~SCTP_ADDR_NOHB;
5331 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5332 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5333 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5335 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5337 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5338 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5339 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5340 net->dest_state |= SCTP_ADDR_NOHB;
5341 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5342 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5346 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5348 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5349 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5350 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5351 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5352 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5354 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5355 net->mtu = paddrp->spp_pathmtu + ovh;
5356 if (net->mtu < stcb->asoc.smallest_mtu) {
5357 sctp_pathmtu_adjustment(stcb, net->mtu);
5360 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5362 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5363 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5364 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5365 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5367 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5369 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5371 if (paddrp->spp_flags & SPP_DSCP) {
5372 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5373 net->dscp = paddrp->spp_dscp & 0xfc;
5376 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5377 stcb->asoc.default_dscp |= 0x01;
5380 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5381 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5382 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5383 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5384 net->flowlabel |= 0x80000000;
5387 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5388 stcb->asoc.default_flowlabel |= 0x80000000;
5392 SCTP_TCB_UNLOCK(stcb);
5394 /************************NO TCB, SET TO default stuff ******************/
5395 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5396 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5397 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5398 SCTP_INP_WLOCK(inp);
5400 * For the TOS/FLOWLABEL stuff you
5401 * set it with the options on the
5404 if (paddrp->spp_pathmaxrxt != 0) {
5405 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5407 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5408 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5409 else if (paddrp->spp_hbinterval != 0) {
5410 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5411 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5412 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5414 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5415 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5416 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5417 } else if (paddrp->spp_hbinterval) {
5418 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5420 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5421 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5422 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5424 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5425 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5426 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5427 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5429 if (paddrp->spp_flags & SPP_DSCP) {
5430 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5431 inp->sctp_ep.default_dscp |= 0x01;
5434 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5435 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5436 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5437 inp->sctp_ep.default_flowlabel |= 0x80000000;
5441 SCTP_INP_WUNLOCK(inp);
5443 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5451 struct sctp_rtoinfo *srto;
5452 uint32_t new_init, new_min, new_max;
5454 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5455 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5458 if (srto->srto_initial)
5459 new_init = srto->srto_initial;
5461 new_init = stcb->asoc.initial_rto;
5463 new_max = srto->srto_max;
5465 new_max = stcb->asoc.maxrto;
5467 new_min = srto->srto_min;
5469 new_min = stcb->asoc.minrto;
5470 if ((new_min <= new_init) && (new_init <= new_max)) {
5471 stcb->asoc.initial_rto = new_init;
5472 stcb->asoc.maxrto = new_max;
5473 stcb->asoc.minrto = new_min;
5475 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5478 SCTP_TCB_UNLOCK(stcb);
5480 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5481 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5482 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5483 SCTP_INP_WLOCK(inp);
5484 if (srto->srto_initial)
5485 new_init = srto->srto_initial;
5487 new_init = inp->sctp_ep.initial_rto;
5489 new_max = srto->srto_max;
5491 new_max = inp->sctp_ep.sctp_maxrto;
5493 new_min = srto->srto_min;
5495 new_min = inp->sctp_ep.sctp_minrto;
5496 if ((new_min <= new_init) && (new_init <= new_max)) {
5497 inp->sctp_ep.initial_rto = new_init;
5498 inp->sctp_ep.sctp_maxrto = new_max;
5499 inp->sctp_ep.sctp_minrto = new_min;
5501 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5504 SCTP_INP_WUNLOCK(inp);
5506 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5512 case SCTP_ASSOCINFO:
5514 struct sctp_assocparams *sasoc;
5516 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5517 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5518 if (sasoc->sasoc_cookie_life) {
5519 /* boundary check the cookie life */
5520 if (sasoc->sasoc_cookie_life < 1000)
5521 sasoc->sasoc_cookie_life = 1000;
5522 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5523 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5527 if (sasoc->sasoc_asocmaxrxt)
5528 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5529 if (sasoc->sasoc_cookie_life) {
5530 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5532 SCTP_TCB_UNLOCK(stcb);
5534 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5535 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5536 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5537 SCTP_INP_WLOCK(inp);
5538 if (sasoc->sasoc_asocmaxrxt)
5539 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5540 if (sasoc->sasoc_cookie_life) {
5541 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5543 SCTP_INP_WUNLOCK(inp);
5545 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5553 struct sctp_initmsg *sinit;
5555 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5556 SCTP_INP_WLOCK(inp);
5557 if (sinit->sinit_num_ostreams)
5558 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5560 if (sinit->sinit_max_instreams)
5561 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5563 if (sinit->sinit_max_attempts)
5564 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5566 if (sinit->sinit_max_init_timeo)
5567 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5568 SCTP_INP_WUNLOCK(inp);
5571 case SCTP_PRIMARY_ADDR:
5573 struct sctp_setprim *spa;
5574 struct sctp_nets *net;
5575 struct sockaddr *addr;
5577 #if defined(INET) && defined(INET6)
5578 struct sockaddr_in sin_store;
5582 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5583 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5585 #if defined(INET) && defined(INET6)
5586 if (spa->ssp_addr.ss_family == AF_INET6) {
5587 struct sockaddr_in6 *sin6;
5589 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5590 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5591 in6_sin6_2_sin(&sin_store, sin6);
5592 addr = (struct sockaddr *)&sin_store;
5594 addr = (struct sockaddr *)&spa->ssp_addr;
5597 addr = (struct sockaddr *)&spa->ssp_addr;
5600 addr = (struct sockaddr *)&spa->ssp_addr;
5603 net = sctp_findnet(stcb, addr);
5606 * We increment here since
5607 * sctp_findassociation_ep_addr() wil do a
5608 * decrement if it finds the stcb as long as
5609 * the locked tcb (last argument) is NOT a
5613 SCTP_INP_INCR_REF(inp);
5614 stcb = sctp_findassociation_ep_addr(&inp, addr,
5617 SCTP_INP_DECR_REF(inp);
5621 if ((stcb != NULL) && (net != NULL)) {
5622 if ((net != stcb->asoc.primary_destination) &&
5623 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
5624 /* Ok we need to set it */
5625 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5626 if ((stcb->asoc.alternate) &&
5627 (!(net->dest_state & SCTP_ADDR_PF)) &&
5628 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5629 sctp_free_remote_addr(stcb->asoc.alternate);
5630 stcb->asoc.alternate = NULL;
5635 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5639 SCTP_TCB_UNLOCK(stcb);
5643 case SCTP_SET_DYNAMIC_PRIMARY:
5645 union sctp_sockstore *ss;
5647 error = priv_check(curthread,
5648 PRIV_NETINET_RESERVEDPORT);
5652 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5653 /* SUPER USER CHECK? */
5654 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5657 case SCTP_SET_PEER_PRIMARY_ADDR:
5659 struct sctp_setpeerprim *sspp;
5660 struct sockaddr *addr;
5662 #if defined(INET) && defined(INET6)
5663 struct sockaddr_in sin_store;
5667 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5668 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5670 struct sctp_ifa *ifa;
5672 #if defined(INET) && defined(INET6)
5673 if (sspp->sspp_addr.ss_family == AF_INET6) {
5674 struct sockaddr_in6 *sin6;
5676 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5677 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5678 in6_sin6_2_sin(&sin_store, sin6);
5679 addr = (struct sockaddr *)&sin_store;
5681 addr = (struct sockaddr *)&sspp->sspp_addr;
5684 addr = (struct sockaddr *)&sspp->sspp_addr;
5687 addr = (struct sockaddr *)&sspp->sspp_addr;
5689 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5695 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5697 * Must validate the ifa found is in
5700 struct sctp_laddr *laddr;
5703 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5704 if (laddr->ifa == NULL) {
5705 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5709 if (laddr->ifa == ifa) {
5715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5720 switch (addr->sa_family) {
5724 struct sockaddr_in *sin;
5726 sin = (struct sockaddr_in *)addr;
5727 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5728 &sin->sin_addr) != 0) {
5729 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5739 struct sockaddr_in6 *sin6;
5741 sin6 = (struct sockaddr_in6 *)addr;
5742 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5743 &sin6->sin6_addr) != 0) {
5744 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5752 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5757 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5758 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5762 SCTP_TCB_UNLOCK(stcb);
5764 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5769 case SCTP_BINDX_ADD_ADDR:
5771 struct sctp_getaddresses *addrs;
5774 td = (struct thread *)p;
5775 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5778 if (addrs->addr->sa_family == AF_INET) {
5779 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5780 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5784 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5785 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5791 if (addrs->addr->sa_family == AF_INET6) {
5792 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5793 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5797 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5798 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5799 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5805 error = EAFNOSUPPORT;
5808 sctp_bindx_add_address(so, inp, addrs->addr,
5809 addrs->sget_assoc_id, vrf_id,
5813 case SCTP_BINDX_REM_ADDR:
5815 struct sctp_getaddresses *addrs;
5818 td = (struct thread *)p;
5820 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5822 if (addrs->addr->sa_family == AF_INET) {
5823 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5824 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5828 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5829 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5835 if (addrs->addr->sa_family == AF_INET6) {
5836 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5837 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5842 (error = prison_local_ip6(td->td_ucred,
5843 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5844 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5845 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5851 error = EAFNOSUPPORT;
5854 sctp_bindx_delete_address(inp, addrs->addr,
5855 addrs->sget_assoc_id, vrf_id,
5861 struct sctp_event *event;
5862 uint32_t event_type;
5864 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5865 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5866 switch (event->se_type) {
5867 case SCTP_ASSOC_CHANGE:
5868 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5870 case SCTP_PEER_ADDR_CHANGE:
5871 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5873 case SCTP_REMOTE_ERROR:
5874 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5876 case SCTP_SEND_FAILED:
5877 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5879 case SCTP_SHUTDOWN_EVENT:
5880 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5882 case SCTP_ADAPTATION_INDICATION:
5883 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5885 case SCTP_PARTIAL_DELIVERY_EVENT:
5886 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5888 case SCTP_AUTHENTICATION_EVENT:
5889 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5891 case SCTP_STREAM_RESET_EVENT:
5892 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5894 case SCTP_SENDER_DRY_EVENT:
5895 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5897 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5899 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5902 case SCTP_ASSOC_RESET_EVENT:
5903 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
5905 case SCTP_STREAM_CHANGE_EVENT:
5906 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
5908 case SCTP_SEND_FAILED_EVENT:
5909 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
5913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5917 if (event_type > 0) {
5920 sctp_stcb_feature_on(inp, stcb, event_type);
5921 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5922 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5923 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5924 (stcb->asoc.stream_queue_cnt == 0)) {
5925 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5929 sctp_stcb_feature_off(inp, stcb, event_type);
5931 SCTP_TCB_UNLOCK(stcb);
5934 * We don't want to send up a storm
5935 * of events, so return an error for
5938 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5939 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5940 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5941 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5942 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5943 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5947 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5948 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5949 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5950 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5951 SCTP_INP_WLOCK(inp);
5953 sctp_feature_on(inp, event_type);
5955 sctp_feature_off(inp, event_type);
5957 SCTP_INP_WUNLOCK(inp);
5959 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5960 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5961 SCTP_INP_RLOCK(inp);
5962 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5963 SCTP_TCB_LOCK(stcb);
5965 sctp_stcb_feature_on(inp, stcb, event_type);
5967 sctp_stcb_feature_off(inp, stcb, event_type);
5969 SCTP_TCB_UNLOCK(stcb);
5971 SCTP_INP_RUNLOCK(inp);
5977 case SCTP_RECVRCVINFO:
5981 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5982 SCTP_INP_WLOCK(inp);
5984 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5986 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5988 SCTP_INP_WUNLOCK(inp);
5991 case SCTP_RECVNXTINFO:
5995 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5996 SCTP_INP_WLOCK(inp);
5998 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6000 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6002 SCTP_INP_WUNLOCK(inp);
6005 case SCTP_DEFAULT_SNDINFO:
6007 struct sctp_sndinfo *info;
6010 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6011 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6014 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6015 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6016 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6017 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6018 stcb->asoc.def_send.sinfo_flags |= policy;
6019 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6020 stcb->asoc.def_send.sinfo_context = info->snd_context;
6022 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6025 SCTP_TCB_UNLOCK(stcb);
6027 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6028 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6029 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6030 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6031 SCTP_INP_WLOCK(inp);
6032 inp->def_send.sinfo_stream = info->snd_sid;
6033 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6034 inp->def_send.sinfo_flags = info->snd_flags;
6035 inp->def_send.sinfo_flags |= policy;
6036 inp->def_send.sinfo_ppid = info->snd_ppid;
6037 inp->def_send.sinfo_context = info->snd_context;
6038 SCTP_INP_WUNLOCK(inp);
6040 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6041 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6042 SCTP_INP_RLOCK(inp);
6043 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6044 SCTP_TCB_LOCK(stcb);
6045 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6046 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6047 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6048 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6049 stcb->asoc.def_send.sinfo_flags |= policy;
6050 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6051 stcb->asoc.def_send.sinfo_context = info->snd_context;
6053 SCTP_TCB_UNLOCK(stcb);
6055 SCTP_INP_RUNLOCK(inp);
6060 case SCTP_DEFAULT_PRINFO:
6062 struct sctp_default_prinfo *info;
6064 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6065 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6067 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6068 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6073 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6074 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6075 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6076 SCTP_TCB_UNLOCK(stcb);
6078 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6079 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6080 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6081 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6082 SCTP_INP_WLOCK(inp);
6083 inp->def_send.sinfo_flags &= 0xfff0;
6084 inp->def_send.sinfo_flags |= info->pr_policy;
6085 inp->def_send.sinfo_timetolive = info->pr_value;
6086 SCTP_INP_WUNLOCK(inp);
6088 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6089 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6090 SCTP_INP_RLOCK(inp);
6091 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6092 SCTP_TCB_LOCK(stcb);
6093 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6094 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6095 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6096 SCTP_TCB_UNLOCK(stcb);
6098 SCTP_INP_RUNLOCK(inp);
6103 case SCTP_PEER_ADDR_THLDS:
6104 /* Applies to the specific association */
6106 struct sctp_paddrthlds *thlds;
6107 struct sctp_nets *net;
6108 struct sockaddr *addr;
6110 #if defined(INET) && defined(INET6)
6111 struct sockaddr_in sin_store;
6115 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6116 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6118 #if defined(INET) && defined(INET6)
6119 if (thlds->spt_address.ss_family == AF_INET6) {
6120 struct sockaddr_in6 *sin6;
6122 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6123 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6124 in6_sin6_2_sin(&sin_store, sin6);
6125 addr = (struct sockaddr *)&sin_store;
6127 addr = (struct sockaddr *)&thlds->spt_address;
6130 addr = (struct sockaddr *)&thlds->spt_address;
6133 addr = (struct sockaddr *)&thlds->spt_address;
6136 net = sctp_findnet(stcb, addr);
6139 * We increment here since
6140 * sctp_findassociation_ep_addr() wil do a
6141 * decrement if it finds the stcb as long as
6142 * the locked tcb (last argument) is NOT a
6146 SCTP_INP_INCR_REF(inp);
6147 stcb = sctp_findassociation_ep_addr(&inp, addr,
6150 SCTP_INP_DECR_REF(inp);
6153 if ((stcb != NULL) && (net == NULL)) {
6155 if (addr->sa_family == AF_INET) {
6157 struct sockaddr_in *sin;
6159 sin = (struct sockaddr_in *)addr;
6160 if (sin->sin_addr.s_addr != INADDR_ANY) {
6161 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6162 SCTP_TCB_UNLOCK(stcb);
6169 if (addr->sa_family == AF_INET6) {
6170 struct sockaddr_in6 *sin6;
6172 sin6 = (struct sockaddr_in6 *)addr;
6173 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6174 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6175 SCTP_TCB_UNLOCK(stcb);
6182 error = EAFNOSUPPORT;
6183 SCTP_TCB_UNLOCK(stcb);
6184 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6190 net->failure_threshold = thlds->spt_pathmaxrxt;
6191 net->pf_threshold = thlds->spt_pathpfthld;
6192 if (net->dest_state & SCTP_ADDR_PF) {
6193 if ((net->error_count > net->failure_threshold) ||
6194 (net->error_count <= net->pf_threshold)) {
6195 net->dest_state &= ~SCTP_ADDR_PF;
6198 if ((net->error_count > net->pf_threshold) &&
6199 (net->error_count <= net->failure_threshold)) {
6200 net->dest_state |= SCTP_ADDR_PF;
6201 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6202 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
6203 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6206 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6207 if (net->error_count > net->failure_threshold) {
6208 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6209 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6212 if (net->error_count <= net->failure_threshold) {
6213 net->dest_state |= SCTP_ADDR_REACHABLE;
6214 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6218 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6219 net->failure_threshold = thlds->spt_pathmaxrxt;
6220 net->pf_threshold = thlds->spt_pathpfthld;
6221 if (net->dest_state & SCTP_ADDR_PF) {
6222 if ((net->error_count > net->failure_threshold) ||
6223 (net->error_count <= net->pf_threshold)) {
6224 net->dest_state &= ~SCTP_ADDR_PF;
6227 if ((net->error_count > net->pf_threshold) &&
6228 (net->error_count <= net->failure_threshold)) {
6229 net->dest_state |= SCTP_ADDR_PF;
6230 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6231 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
6232 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6235 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6236 if (net->error_count > net->failure_threshold) {
6237 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6238 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6241 if (net->error_count <= net->failure_threshold) {
6242 net->dest_state |= SCTP_ADDR_REACHABLE;
6243 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6247 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6248 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6250 SCTP_TCB_UNLOCK(stcb);
6252 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6253 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6254 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6255 SCTP_INP_WLOCK(inp);
6256 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6257 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6258 SCTP_INP_WUNLOCK(inp);
6260 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6266 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6268 struct sctp_udpencaps *encaps;
6269 struct sctp_nets *net;
6270 struct sockaddr *addr;
6272 #if defined(INET) && defined(INET6)
6273 struct sockaddr_in sin_store;
6277 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6278 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6280 #if defined(INET) && defined(INET6)
6281 if (encaps->sue_address.ss_family == AF_INET6) {
6282 struct sockaddr_in6 *sin6;
6284 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6285 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6286 in6_sin6_2_sin(&sin_store, sin6);
6287 addr = (struct sockaddr *)&sin_store;
6289 addr = (struct sockaddr *)&encaps->sue_address;
6292 addr = (struct sockaddr *)&encaps->sue_address;
6295 addr = (struct sockaddr *)&encaps->sue_address;
6298 net = sctp_findnet(stcb, addr);
6301 * We increment here since
6302 * sctp_findassociation_ep_addr() wil do a
6303 * decrement if it finds the stcb as long as
6304 * the locked tcb (last argument) is NOT a
6308 SCTP_INP_INCR_REF(inp);
6309 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6311 SCTP_INP_DECR_REF(inp);
6314 if ((stcb != NULL) && (net == NULL)) {
6316 if (addr->sa_family == AF_INET) {
6318 struct sockaddr_in *sin;
6320 sin = (struct sockaddr_in *)addr;
6321 if (sin->sin_addr.s_addr != INADDR_ANY) {
6322 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6323 SCTP_TCB_UNLOCK(stcb);
6330 if (addr->sa_family == AF_INET6) {
6331 struct sockaddr_in6 *sin6;
6333 sin6 = (struct sockaddr_in6 *)addr;
6334 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6335 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6336 SCTP_TCB_UNLOCK(stcb);
6343 error = EAFNOSUPPORT;
6344 SCTP_TCB_UNLOCK(stcb);
6345 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6351 net->port = encaps->sue_port;
6353 stcb->asoc.port = encaps->sue_port;
6355 SCTP_TCB_UNLOCK(stcb);
6357 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6358 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6359 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6360 SCTP_INP_WLOCK(inp);
6361 inp->sctp_ep.port = encaps->sue_port;
6362 SCTP_INP_WUNLOCK(inp);
6364 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6370 case SCTP_ECN_SUPPORTED:
6372 struct sctp_assoc_value *av;
6374 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6375 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6378 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6380 SCTP_TCB_UNLOCK(stcb);
6382 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6383 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6384 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6385 SCTP_INP_WLOCK(inp);
6386 if (av->assoc_value == 0) {
6387 inp->ecn_supported = 0;
6389 inp->ecn_supported = 1;
6391 SCTP_INP_WUNLOCK(inp);
6393 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6399 case SCTP_PR_SUPPORTED:
6401 struct sctp_assoc_value *av;
6403 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6404 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6407 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6409 SCTP_TCB_UNLOCK(stcb);
6411 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6412 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6413 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6414 SCTP_INP_WLOCK(inp);
6415 if (av->assoc_value == 0) {
6416 inp->prsctp_supported = 0;
6418 inp->prsctp_supported = 1;
6420 SCTP_INP_WUNLOCK(inp);
6422 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6428 case SCTP_AUTH_SUPPORTED:
6430 struct sctp_assoc_value *av;
6432 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6433 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6436 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6438 SCTP_TCB_UNLOCK(stcb);
6440 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6441 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6442 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6443 if ((av->assoc_value == 0) &&
6444 (inp->asconf_supported == 1)) {
6446 * AUTH is required for
6449 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6452 SCTP_INP_WLOCK(inp);
6453 if (av->assoc_value == 0) {
6454 inp->auth_supported = 0;
6456 inp->auth_supported = 1;
6458 SCTP_INP_WUNLOCK(inp);
6461 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6467 case SCTP_ASCONF_SUPPORTED:
6469 struct sctp_assoc_value *av;
6471 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6472 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6475 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6477 SCTP_TCB_UNLOCK(stcb);
6479 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6480 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6481 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6482 if ((av->assoc_value != 0) &&
6483 (inp->auth_supported == 0)) {
6485 * AUTH is required for
6488 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6491 SCTP_INP_WLOCK(inp);
6492 if (av->assoc_value == 0) {
6493 inp->asconf_supported = 0;
6494 sctp_auth_delete_chunk(SCTP_ASCONF,
6495 inp->sctp_ep.local_auth_chunks);
6496 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6497 inp->sctp_ep.local_auth_chunks);
6499 inp->asconf_supported = 1;
6500 sctp_auth_add_chunk(SCTP_ASCONF,
6501 inp->sctp_ep.local_auth_chunks);
6502 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6503 inp->sctp_ep.local_auth_chunks);
6505 SCTP_INP_WUNLOCK(inp);
6508 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6514 case SCTP_RECONFIG_SUPPORTED:
6516 struct sctp_assoc_value *av;
6518 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6519 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6522 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6524 SCTP_TCB_UNLOCK(stcb);
6526 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6527 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6528 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6529 SCTP_INP_WLOCK(inp);
6530 if (av->assoc_value == 0) {
6531 inp->reconfig_supported = 0;
6533 inp->reconfig_supported = 1;
6535 SCTP_INP_WUNLOCK(inp);
6537 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6543 case SCTP_NRSACK_SUPPORTED:
6545 struct sctp_assoc_value *av;
6547 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6548 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6551 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6553 SCTP_TCB_UNLOCK(stcb);
6555 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6556 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6557 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6558 SCTP_INP_WLOCK(inp);
6559 if (av->assoc_value == 0) {
6560 inp->nrsack_supported = 0;
6562 inp->nrsack_supported = 1;
6564 SCTP_INP_WUNLOCK(inp);
6566 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6572 case SCTP_PKTDROP_SUPPORTED:
6574 struct sctp_assoc_value *av;
6576 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6577 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6580 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6582 SCTP_TCB_UNLOCK(stcb);
6584 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6585 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6586 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6587 SCTP_INP_WLOCK(inp);
6588 if (av->assoc_value == 0) {
6589 inp->pktdrop_supported = 0;
6591 inp->pktdrop_supported = 1;
6593 SCTP_INP_WUNLOCK(inp);
6595 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6603 struct sctp_assoc_value *av;
6604 struct sctp_nets *net;
6606 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6607 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6610 stcb->asoc.max_cwnd = av->assoc_value;
6611 if (stcb->asoc.max_cwnd > 0) {
6612 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6613 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6614 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6615 net->cwnd = stcb->asoc.max_cwnd;
6616 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6617 net->cwnd = net->mtu - sizeof(struct sctphdr);
6622 SCTP_TCB_UNLOCK(stcb);
6624 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6625 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6626 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6627 SCTP_INP_WLOCK(inp);
6628 inp->max_cwnd = av->assoc_value;
6629 SCTP_INP_WUNLOCK(inp);
6631 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6638 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6639 error = ENOPROTOOPT;
6641 } /* end switch (opt) */
6646 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6648 void *optval = NULL;
6653 if (sopt->sopt_level != IPPROTO_SCTP) {
6654 /* wrong proto level... send back up to IP */
6656 if (INP_CHECK_SOCKAF(so, AF_INET6))
6657 error = ip6_ctloutput(so, sopt);
6659 #if defined(INET) && defined(INET6)
6663 error = ip_ctloutput(so, sopt);
6667 optsize = sopt->sopt_valsize;
6669 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6670 if (optval == NULL) {
6671 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6674 error = sooptcopyin(sopt, optval, optsize, optsize);
6676 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6680 p = (void *)sopt->sopt_td;
6681 if (sopt->sopt_dir == SOPT_SET) {
6682 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6683 } else if (sopt->sopt_dir == SOPT_GET) {
6684 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6686 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6689 if ((error == 0) && (optval != NULL)) {
6690 error = sooptcopyout(sopt, optval, optsize);
6691 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6692 } else if (optval != NULL) {
6693 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6701 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6704 int create_lock_on = 0;
6706 struct sctp_inpcb *inp;
6707 struct sctp_tcb *stcb = NULL;
6709 inp = (struct sctp_inpcb *)so->so_pcb;
6711 /* I made the same as TCP since we are not setup? */
6712 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6713 return (ECONNRESET);
6716 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6719 switch (addr->sa_family) {
6723 struct sockaddr_in6 *sin6p;
6725 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6726 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6729 sin6p = (struct sockaddr_in6 *)addr;
6730 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6731 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6740 struct sockaddr_in *sinp;
6742 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6743 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6746 sinp = (struct sockaddr_in *)addr;
6747 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6748 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6755 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6756 return (EAFNOSUPPORT);
6758 SCTP_INP_INCR_REF(inp);
6759 SCTP_ASOC_CREATE_LOCK(inp);
6763 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6764 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6765 /* Should I really unlock ? */
6766 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6771 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6772 (addr->sa_family == AF_INET6)) {
6773 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6778 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6779 SCTP_PCB_FLAGS_UNBOUND) {
6780 /* Bind a ephemeral port */
6781 error = sctp_inpcb_bind(so, NULL, NULL, p);
6786 /* Now do we connect? */
6787 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6788 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6789 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6793 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6794 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6795 /* We are already connected AND the TCP model */
6796 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6800 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6801 SCTP_INP_RLOCK(inp);
6802 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6803 SCTP_INP_RUNLOCK(inp);
6806 * We increment here since sctp_findassociation_ep_addr()
6807 * will do a decrement if it finds the stcb as long as the
6808 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6810 SCTP_INP_INCR_REF(inp);
6811 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6813 SCTP_INP_DECR_REF(inp);
6815 SCTP_TCB_UNLOCK(stcb);
6819 /* Already have or am bring up an association */
6820 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6824 vrf_id = inp->def_vrf_id;
6825 /* We are GOOD to go */
6826 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
6828 /* Gak! no memory */
6831 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6832 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6833 /* Set the connected flag so we can queue data */
6836 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6837 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6839 /* initialize authentication parameters for the assoc */
6840 sctp_initialize_auth_params(inp, stcb);
6842 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6843 SCTP_TCB_UNLOCK(stcb);
6845 if (create_lock_on) {
6846 SCTP_ASOC_CREATE_UNLOCK(inp);
6848 SCTP_INP_DECR_REF(inp);
6855 sctp_listen(struct socket *so, int backlog, struct thread *p)
6858 * Note this module depends on the protocol processing being called
6859 * AFTER any socket level flags and backlog are applied to the
6860 * socket. The traditional way that the socket flags are applied is
6861 * AFTER protocol processing. We have made a change to the
6862 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6863 * place if the socket API for SCTP is to work properly.
6867 struct sctp_inpcb *inp;
6869 inp = (struct sctp_inpcb *)so->so_pcb;
6871 /* I made the same as TCP since we are not setup? */
6872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6873 return (ECONNRESET);
6875 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6876 /* See if we have a listener */
6877 struct sctp_inpcb *tinp;
6878 union sctp_sockstore store;
6880 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6882 struct sctp_laddr *laddr;
6884 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6885 memcpy(&store, &laddr->ifa->address, sizeof(store));
6886 switch (store.sa.sa_family) {
6889 store.sin.sin_port = inp->sctp_lport;
6894 store.sin6.sin6_port = inp->sctp_lport;
6900 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
6901 if (tinp && (tinp != inp) &&
6902 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6903 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6904 (tinp->sctp_socket->so_qlimit)) {
6906 * we have a listener already and
6909 SCTP_INP_DECR_REF(tinp);
6910 return (EADDRINUSE);
6912 SCTP_INP_DECR_REF(tinp);
6916 /* Setup a local addr bound all */
6917 memset(&store, 0, sizeof(store));
6919 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
6920 store.sa.sa_family = AF_INET6;
6921 store.sa.sa_len = sizeof(struct sockaddr_in6);
6925 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
6926 store.sa.sa_family = AF_INET;
6927 store.sa.sa_len = sizeof(struct sockaddr_in);
6930 switch (store.sa.sa_family) {
6933 store.sin.sin_port = inp->sctp_lport;
6938 store.sin6.sin6_port = inp->sctp_lport;
6944 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
6945 if (tinp && (tinp != inp) &&
6946 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6947 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6948 (tinp->sctp_socket->so_qlimit)) {
6950 * we have a listener already and its not
6953 SCTP_INP_DECR_REF(tinp);
6954 return (EADDRINUSE);
6956 SCTP_INP_DECR_REF(tinp);
6960 SCTP_INP_RLOCK(inp);
6961 #ifdef SCTP_LOCK_LOGGING
6962 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
6963 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
6967 error = solisten_proto_check(so);
6970 SCTP_INP_RUNLOCK(inp);
6973 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
6974 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
6976 * The unlucky case - We are in the tcp pool with this guy.
6977 * - Someone else is in the main inp slot. - We must move
6978 * this guy (the listener) to the main slot - We must then
6979 * move the guy that was listener to the TCP Pool.
6981 if (sctp_swap_inpcb_for_listen(inp)) {
6982 SCTP_INP_RUNLOCK(inp);
6983 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6984 return (EADDRINUSE);
6987 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6988 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6989 /* We are already connected AND the TCP model */
6990 SCTP_INP_RUNLOCK(inp);
6991 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6992 return (EADDRINUSE);
6994 SCTP_INP_RUNLOCK(inp);
6995 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
6996 /* We must do a bind. */
6997 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
6998 /* bind error, probably perm */
7003 /* It appears for 7.0 and on, we must always call this. */
7004 solisten_proto(so, backlog);
7005 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7006 /* remove the ACCEPTCONN flag for one-to-many sockets */
7007 so->so_options &= ~SO_ACCEPTCONN;
7010 /* turning off listen */
7011 so->so_options &= ~SO_ACCEPTCONN;
7017 static int sctp_defered_wakeup_cnt = 0;
7020 sctp_accept(struct socket *so, struct sockaddr **addr)
7022 struct sctp_tcb *stcb;
7023 struct sctp_inpcb *inp;
7024 union sctp_sockstore store;
7030 inp = (struct sctp_inpcb *)so->so_pcb;
7033 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7034 return (ECONNRESET);
7036 SCTP_INP_RLOCK(inp);
7037 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7038 SCTP_INP_RUNLOCK(inp);
7039 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7040 return (EOPNOTSUPP);
7042 if (so->so_state & SS_ISDISCONNECTED) {
7043 SCTP_INP_RUNLOCK(inp);
7044 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7045 return (ECONNABORTED);
7047 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7049 SCTP_INP_RUNLOCK(inp);
7050 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7051 return (ECONNRESET);
7053 SCTP_TCB_LOCK(stcb);
7054 SCTP_INP_RUNLOCK(inp);
7055 store = stcb->asoc.primary_destination->ro._l_addr;
7056 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7057 SCTP_TCB_UNLOCK(stcb);
7058 switch (store.sa.sa_family) {
7062 struct sockaddr_in *sin;
7064 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7067 sin->sin_family = AF_INET;
7068 sin->sin_len = sizeof(*sin);
7069 sin->sin_port = store.sin.sin_port;
7070 sin->sin_addr = store.sin.sin_addr;
7071 *addr = (struct sockaddr *)sin;
7078 struct sockaddr_in6 *sin6;
7080 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7083 sin6->sin6_family = AF_INET6;
7084 sin6->sin6_len = sizeof(*sin6);
7085 sin6->sin6_port = store.sin6.sin6_port;
7086 sin6->sin6_addr = store.sin6.sin6_addr;
7087 if ((error = sa6_recoverscope(sin6)) != 0) {
7088 SCTP_FREE_SONAME(sin6);
7091 *addr = (struct sockaddr *)sin6;
7099 /* Wake any delayed sleep action */
7100 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7101 SCTP_INP_WLOCK(inp);
7102 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7103 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7104 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7105 SCTP_INP_WUNLOCK(inp);
7106 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7107 if (sowriteable(inp->sctp_socket)) {
7108 sowwakeup_locked(inp->sctp_socket);
7110 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7112 SCTP_INP_WLOCK(inp);
7114 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7115 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7116 SCTP_INP_WUNLOCK(inp);
7117 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7118 if (soreadable(inp->sctp_socket)) {
7119 sctp_defered_wakeup_cnt++;
7120 sorwakeup_locked(inp->sctp_socket);
7122 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7124 SCTP_INP_WLOCK(inp);
7126 SCTP_INP_WUNLOCK(inp);
7128 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7129 SCTP_TCB_LOCK(stcb);
7130 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
7137 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7139 struct sockaddr_in *sin;
7141 struct sctp_inpcb *inp;
7142 struct sctp_ifa *sctp_ifa;
7145 * Do the malloc first in case it blocks.
7147 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7150 sin->sin_family = AF_INET;
7151 sin->sin_len = sizeof(*sin);
7152 inp = (struct sctp_inpcb *)so->so_pcb;
7154 SCTP_FREE_SONAME(sin);
7155 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7156 return (ECONNRESET);
7158 SCTP_INP_RLOCK(inp);
7159 sin->sin_port = inp->sctp_lport;
7160 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7161 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7162 struct sctp_tcb *stcb;
7163 struct sockaddr_in *sin_a;
7164 struct sctp_nets *net;
7167 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7173 SCTP_TCB_LOCK(stcb);
7174 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7175 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7177 /* this will make coverity happy */
7180 if (sin_a->sin_family == AF_INET) {
7185 if ((!fnd) || (sin_a == NULL)) {
7187 SCTP_TCB_UNLOCK(stcb);
7190 vrf_id = inp->def_vrf_id;
7191 sctp_ifa = sctp_source_address_selection(inp,
7193 (sctp_route_t *) & net->ro,
7196 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7197 sctp_free_ifa(sctp_ifa);
7199 SCTP_TCB_UNLOCK(stcb);
7201 /* For the bound all case you get back 0 */
7203 sin->sin_addr.s_addr = 0;
7207 /* Take the first IPv4 address in the list */
7208 struct sctp_laddr *laddr;
7211 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7212 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7213 struct sockaddr_in *sin_a;
7215 sin_a = &laddr->ifa->address.sin;
7216 sin->sin_addr = sin_a->sin_addr;
7222 SCTP_FREE_SONAME(sin);
7223 SCTP_INP_RUNLOCK(inp);
7224 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7228 SCTP_INP_RUNLOCK(inp);
7229 (*addr) = (struct sockaddr *)sin;
7234 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7236 struct sockaddr_in *sin;
7238 struct sockaddr_in *sin_a;
7239 struct sctp_inpcb *inp;
7240 struct sctp_tcb *stcb;
7241 struct sctp_nets *net;
7243 /* Do the malloc first in case it blocks. */
7244 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7247 sin->sin_family = AF_INET;
7248 sin->sin_len = sizeof(*sin);
7250 inp = (struct sctp_inpcb *)so->so_pcb;
7251 if ((inp == NULL) ||
7252 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7253 /* UDP type and listeners will drop out here */
7254 SCTP_FREE_SONAME(sin);
7255 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7258 SCTP_INP_RLOCK(inp);
7259 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7261 SCTP_TCB_LOCK(stcb);
7263 SCTP_INP_RUNLOCK(inp);
7265 SCTP_FREE_SONAME(sin);
7266 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7267 return (ECONNRESET);
7270 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7271 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7272 if (sin_a->sin_family == AF_INET) {
7274 sin->sin_port = stcb->rport;
7275 sin->sin_addr = sin_a->sin_addr;
7279 SCTP_TCB_UNLOCK(stcb);
7281 /* No IPv4 address */
7282 SCTP_FREE_SONAME(sin);
7283 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7286 (*addr) = (struct sockaddr *)sin;
7290 struct pr_usrreqs sctp_usrreqs = {
7291 .pru_abort = sctp_abort,
7292 .pru_accept = sctp_accept,
7293 .pru_attach = sctp_attach,
7294 .pru_bind = sctp_bind,
7295 .pru_connect = sctp_connect,
7296 .pru_control = in_control,
7297 .pru_close = sctp_close,
7298 .pru_detach = sctp_close,
7299 .pru_sopoll = sopoll_generic,
7300 .pru_flush = sctp_flush,
7301 .pru_disconnect = sctp_disconnect,
7302 .pru_listen = sctp_listen,
7303 .pru_peeraddr = sctp_peeraddr,
7304 .pru_send = sctp_sendm,
7305 .pru_shutdown = sctp_shutdown,
7306 .pru_sockaddr = sctp_ingetaddr,
7307 .pru_sosend = sctp_sosend,
7308 .pru_soreceive = sctp_soreceive