2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2011, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2011, 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 /* $KAME: sctp_usrreq.c,v 1.48 2005/03/07 23:26:08 itojun Exp $ */
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
37 #include <netinet/sctp_os.h>
39 #include <netinet/sctp_pcb.h>
40 #include <netinet/sctp_header.h>
41 #include <netinet/sctp_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);
83 SCTP_BASE_VAR(first_time) = 0;
84 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
86 #if defined(SCTP_PACKET_LOGGING)
87 SCTP_BASE_VAR(packet_log_writers) = 0;
88 SCTP_BASE_VAR(packet_log_end) = 0;
89 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
104 sctp_pathmtu_adjustment(struct sctp_inpcb *inp,
105 struct sctp_tcb *stcb,
106 struct sctp_nets *net,
109 struct sctp_tmit_chunk *chk;
112 /* Adjust that too */
113 stcb->asoc.smallest_mtu = nxtsz;
114 /* now off to subtract IP_DF flag if needed */
115 overhead = IP_HDR_SIZE;
116 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
117 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
119 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
120 if ((chk->send_size + overhead) > nxtsz) {
121 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
124 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
125 if ((chk->send_size + overhead) > nxtsz) {
127 * For this guy we also mark for immediate resend
128 * since we sent to big of chunk
130 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
131 if (chk->sent < SCTP_DATAGRAM_RESEND) {
132 sctp_flight_size_decrease(chk);
133 sctp_total_flight_decrease(stcb, chk);
135 if (chk->sent != SCTP_DATAGRAM_RESEND) {
136 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
138 chk->sent = SCTP_DATAGRAM_RESEND;
139 chk->rec.data.doing_fast_retransmit = 0;
140 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
141 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
142 chk->whoTo->flight_size,
144 (uintptr_t) chk->whoTo,
145 chk->rec.data.TSN_seq);
147 /* Clear any time so NO RTT is being done */
155 sctp_notify_mbuf(struct sctp_inpcb *inp,
156 struct sctp_tcb *stcb,
157 struct sctp_nets *net,
162 int totsz, tmr_stopped = 0;
166 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
167 (ip == NULL) || (sh == NULL)) {
169 SCTP_TCB_UNLOCK(stcb);
173 /* First job is to verify the vtag matches what I would send */
174 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
175 SCTP_TCB_UNLOCK(stcb);
178 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
180 if (icmph->icmp_type != ICMP_UNREACH) {
181 /* We only care about unreachable */
182 SCTP_TCB_UNLOCK(stcb);
185 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
186 /* not a unreachable message due to frag. */
187 SCTP_TCB_UNLOCK(stcb);
192 nxtsz = ntohs(icmph->icmp_nextmtu);
195 * old type router that does not tell us what the next size
196 * mtu is. Rats we will have to guess (in a educated fashion
199 nxtsz = sctp_get_prev_mtu(totsz);
201 /* Stop any PMTU timer */
202 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
204 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
205 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
207 /* Adjust destination size limit */
208 if (net->mtu > nxtsz) {
211 net->mtu -= sizeof(struct udphdr);
214 /* now what about the ep? */
215 if (stcb->asoc.smallest_mtu > nxtsz) {
216 sctp_pathmtu_adjustment(inp, stcb, net, nxtsz);
219 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
221 SCTP_TCB_UNLOCK(stcb);
227 sctp_notify(struct sctp_inpcb *inp,
231 struct sctp_tcb *stcb,
232 struct sctp_nets *net)
234 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
243 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
244 (sh == NULL) || (to == NULL)) {
246 SCTP_TCB_UNLOCK(stcb);
249 /* First job is to verify the vtag matches what I would send */
250 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
251 SCTP_TCB_UNLOCK(stcb);
254 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
256 if (icmph->icmp_type != ICMP_UNREACH) {
257 /* We only care about unreachable */
258 SCTP_TCB_UNLOCK(stcb);
261 if ((icmph->icmp_code == ICMP_UNREACH_NET) ||
262 (icmph->icmp_code == ICMP_UNREACH_HOST) ||
263 (icmph->icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
264 (icmph->icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
265 (icmph->icmp_code == ICMP_UNREACH_ISOLATED) ||
266 (icmph->icmp_code == ICMP_UNREACH_NET_PROHIB) ||
267 (icmph->icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
268 (icmph->icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
271 * Hmm reachablity problems we must examine closely. If its
272 * not reachable, we may have lost a network. Or if there is
273 * NO protocol at the other end named SCTP. well we consider
276 if (net->dest_state & SCTP_ADDR_REACHABLE) {
277 /* Ok that destination is NOT reachable */
278 net->dest_state &= ~SCTP_ADDR_REACHABLE;
279 net->dest_state &= ~SCTP_ADDR_PF;
280 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
281 stcb, SCTP_FAILED_THRESHOLD,
282 (void *)net, SCTP_SO_NOT_LOCKED);
284 SCTP_TCB_UNLOCK(stcb);
285 } else if ((icmph->icmp_code == ICMP_UNREACH_PROTOCOL) ||
286 (icmph->icmp_code == ICMP_UNREACH_PORT)) {
288 * Here the peer is either playing tricks on us, including
289 * an address that belongs to someone who does not support
290 * SCTP OR was a userland implementation that shutdown and
291 * now is dead. In either case treat it like a OOTB abort
294 reason = SCTP_PEER_FAULTY;
295 sctp_abort_notification(stcb, reason, SCTP_SO_NOT_LOCKED);
296 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
297 so = SCTP_INP_SO(inp);
298 atomic_add_int(&stcb->asoc.refcnt, 1);
299 SCTP_TCB_UNLOCK(stcb);
300 SCTP_SOCKET_LOCK(so, 1);
302 atomic_subtract_int(&stcb->asoc.refcnt, 1);
304 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
305 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
306 SCTP_SOCKET_UNLOCK(so, 1);
307 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
309 /* no need to unlock here, since the TCB is gone */
311 SCTP_TCB_UNLOCK(stcb);
317 sctp_ctlinput(cmd, sa, vip)
326 /* FIX, for non-bsd is this right? */
327 vrf_id = SCTP_DEFAULT_VRFID;
328 if (sa->sa_family != AF_INET ||
329 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
332 if (PRC_IS_REDIRECT(cmd)) {
334 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
338 struct sctp_inpcb *inp = NULL;
339 struct sctp_tcb *stcb = NULL;
340 struct sctp_nets *net = NULL;
341 struct sockaddr_in to, from;
343 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
344 bzero(&to, sizeof(to));
345 bzero(&from, sizeof(from));
346 from.sin_family = to.sin_family = AF_INET;
347 from.sin_len = to.sin_len = sizeof(to);
348 from.sin_port = sh->src_port;
349 from.sin_addr = ip->ip_src;
350 to.sin_port = sh->dest_port;
351 to.sin_addr = ip->ip_dst;
354 * 'to' holds the dest of the packet that failed to be sent.
355 * 'from' holds our local endpoint address. Thus we reverse
356 * the to and the from in the lookup.
358 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&from,
359 (struct sockaddr *)&to,
360 &inp, &net, 1, vrf_id);
361 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
362 if (cmd != PRC_MSGSIZE) {
363 sctp_notify(inp, ip, sh,
364 (struct sockaddr *)&to, stcb,
367 /* handle possible ICMP size messages */
368 sctp_notify_mbuf(inp, stcb, net, ip, sh);
371 if ((stcb == NULL) && (inp != NULL)) {
372 /* reduce ref-count */
374 SCTP_INP_DECR_REF(inp);
375 SCTP_INP_WUNLOCK(inp);
378 SCTP_TCB_UNLOCK(stcb);
388 sctp_getcred(SYSCTL_HANDLER_ARGS)
391 struct sockaddr_in addrs[2];
392 struct sctp_inpcb *inp;
393 struct sctp_nets *net;
394 struct sctp_tcb *stcb;
398 /* FIX, for non-bsd is this right? */
399 vrf_id = SCTP_DEFAULT_VRFID;
401 error = priv_check(req->td, PRIV_NETINET_GETCRED);
406 error = SYSCTL_IN(req, addrs, sizeof(addrs));
410 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[0]),
412 &inp, &net, 1, vrf_id);
413 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
414 if ((inp != NULL) && (stcb == NULL)) {
415 /* reduce ref-count */
417 SCTP_INP_DECR_REF(inp);
420 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
424 SCTP_TCB_UNLOCK(stcb);
426 * We use the write lock here, only since in the error leg we need
427 * it. If we used RLOCK, then we would have to
428 * wlock/decr/unlock/rlock. Which in theory could create a hole.
429 * Better to use higher wlock.
433 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
435 SCTP_INP_WUNLOCK(inp);
438 cru2x(inp->sctp_socket->so_cred, &xuc);
439 SCTP_INP_WUNLOCK(inp);
440 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
445 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
446 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
451 sctp_abort(struct socket *so)
453 struct sctp_inpcb *inp;
456 inp = (struct sctp_inpcb *)so->so_pcb;
461 flags = inp->sctp_flags;
462 #ifdef SCTP_LOG_CLOSING
463 sctp_log_closing(inp, NULL, 17);
465 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
466 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
467 #ifdef SCTP_LOG_CLOSING
468 sctp_log_closing(inp, NULL, 16);
470 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
471 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
473 SCTP_SB_CLEAR(so->so_snd);
475 * same for the rcv ones, they are only here for the
478 SCTP_SB_CLEAR(so->so_rcv);
480 /* Now null out the reference, we are completely detached. */
484 flags = inp->sctp_flags;
485 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
486 goto sctp_must_try_again;
493 sctp_attach(struct socket *so, int proto, struct thread *p)
495 struct sctp_inpcb *inp;
496 struct inpcb *ip_inp;
498 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
505 inp = (struct sctp_inpcb *)so->so_pcb;
507 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
510 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
511 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
516 error = sctp_inpcb_alloc(so, vrf_id);
520 inp = (struct sctp_inpcb *)so->so_pcb;
522 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
523 ip_inp = &inp->ip_inp.inp;
524 ip_inp->inp_vflag |= INP_IPV4;
525 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
527 error = ipsec_init_policy(so, &ip_inp->inp_sp);
528 #ifdef SCTP_LOG_CLOSING
529 sctp_log_closing(inp, NULL, 17);
533 flags = inp->sctp_flags;
534 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
535 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
536 #ifdef SCTP_LOG_CLOSING
537 sctp_log_closing(inp, NULL, 15);
539 SCTP_INP_WUNLOCK(inp);
540 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
541 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
543 flags = inp->sctp_flags;
544 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
547 SCTP_INP_WUNLOCK(inp);
553 SCTP_INP_WUNLOCK(inp);
558 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
560 struct sctp_inpcb *inp = NULL;
564 if (addr && addr->sa_family != AF_INET) {
565 /* must be a v4 address! */
566 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
570 if (addr && (addr->sa_len != sizeof(struct sockaddr_in))) {
571 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
574 inp = (struct sctp_inpcb *)so->so_pcb;
576 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
579 error = sctp_inpcb_bind(so, addr, NULL, p);
585 sctp_close(struct socket *so)
587 struct sctp_inpcb *inp;
590 inp = (struct sctp_inpcb *)so->so_pcb;
595 * Inform all the lower layer assoc that we are done.
598 flags = inp->sctp_flags;
599 #ifdef SCTP_LOG_CLOSING
600 sctp_log_closing(inp, NULL, 17);
602 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
603 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
604 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
605 (so->so_rcv.sb_cc > 0)) {
606 #ifdef SCTP_LOG_CLOSING
607 sctp_log_closing(inp, NULL, 13);
609 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
610 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
612 #ifdef SCTP_LOG_CLOSING
613 sctp_log_closing(inp, NULL, 14);
615 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
616 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
619 * The socket is now detached, no matter what the state of
620 * the SCTP association.
623 SCTP_SB_CLEAR(so->so_snd);
625 * same for the rcv ones, they are only here for the
628 SCTP_SB_CLEAR(so->so_rcv);
630 /* Now null out the reference, we are completely detached. */
634 flags = inp->sctp_flags;
635 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
636 goto sctp_must_try_again;
644 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
645 struct mbuf *control, struct thread *p);
649 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
650 struct mbuf *control, struct thread *p)
652 struct sctp_inpcb *inp;
655 inp = (struct sctp_inpcb *)so->so_pcb;
658 sctp_m_freem(control);
661 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
665 /* Got to have an to address if we are NOT a connected socket */
666 if ((addr == NULL) &&
667 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
668 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))
671 } else if (addr == NULL) {
672 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
673 error = EDESTADDRREQ;
676 sctp_m_freem(control);
682 if (addr->sa_family != AF_INET) {
683 /* must be a v4 address! */
684 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
687 sctp_m_freem(control);
690 error = EDESTADDRREQ;
695 /* now what about control */
698 SCTP_PRINTF("huh? control set?\n");
699 sctp_m_freem(inp->control);
702 inp->control = control;
706 SCTP_BUF_NEXT(inp->pkt_last) = m;
709 inp->pkt_last = inp->pkt = m;
712 /* FreeBSD uses a flag passed */
713 ((flags & PRUS_MORETOCOME) == 0)
716 * note with the current version this code will only be used
717 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
718 * re-defining sosend to use the sctp_sosend. One can
719 * optionally switch back to this code (by changing back the
720 * definitions) but this is not advisable. This code is used
721 * by FreeBSD when sending a file with sendfile() though.
725 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
735 sctp_disconnect(struct socket *so)
737 struct sctp_inpcb *inp;
739 inp = (struct sctp_inpcb *)so->so_pcb;
741 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
745 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
746 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
747 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
749 SCTP_INP_RUNLOCK(inp);
752 struct sctp_association *asoc;
753 struct sctp_tcb *stcb;
755 stcb = LIST_FIRST(&inp->sctp_asoc_list);
757 SCTP_INP_RUNLOCK(inp);
758 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
763 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
764 /* We are about to be freed, out of here */
765 SCTP_TCB_UNLOCK(stcb);
766 SCTP_INP_RUNLOCK(inp);
769 if (((so->so_options & SO_LINGER) &&
770 (so->so_linger == 0)) ||
771 (so->so_rcv.sb_cc > 0)) {
772 if (SCTP_GET_STATE(asoc) !=
773 SCTP_STATE_COOKIE_WAIT) {
774 /* Left with Data unread */
777 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_DONTWAIT, 1, MT_DATA);
783 struct sctp_paramhdr *ph;
785 ph = mtod(err, struct sctp_paramhdr *);
786 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
787 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
788 ph->param_length = htons(SCTP_BUF_LEN(err));
790 #if defined(SCTP_PANIC_ON_ABORT)
791 panic("disconnect does an abort");
793 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
794 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
796 SCTP_INP_RUNLOCK(inp);
797 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
798 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
799 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
801 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
802 /* No unlock tcb assoc is gone */
805 if (TAILQ_EMPTY(&asoc->send_queue) &&
806 TAILQ_EMPTY(&asoc->sent_queue) &&
807 (asoc->stream_queue_cnt == 0)) {
808 /* there is nothing queued to send, so done */
809 if (asoc->locked_on_sending) {
812 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
813 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
814 /* only send SHUTDOWN 1st time thru */
815 struct sctp_nets *netp;
817 if (stcb->asoc.alternate) {
818 netp = stcb->asoc.alternate;
820 netp = stcb->asoc.primary_destination;
822 sctp_stop_timers_for_shutdown(stcb);
823 sctp_send_shutdown(stcb, netp);
824 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
825 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
826 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
827 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
829 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
830 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
831 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
832 stcb->sctp_ep, stcb, netp);
833 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
834 stcb->sctp_ep, stcb, netp);
839 * we still got (or just got) data to send,
840 * so set SHUTDOWN_PENDING
843 * XXX sockets draft says that SCTP_EOF
844 * should be sent with no data. currently,
845 * we will allow user data to be sent first
846 * and move to SHUTDOWN-PENDING
848 struct sctp_nets *netp;
850 if (stcb->asoc.alternate) {
851 netp = stcb->asoc.alternate;
853 netp = stcb->asoc.primary_destination;
856 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
857 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
859 if (asoc->locked_on_sending) {
860 /* Locked to send out the data */
861 struct sctp_stream_queue_pending *sp;
863 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
865 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
866 asoc->locked_on_sending->stream_no);
868 if ((sp->length == 0) && (sp->msg_is_complete == 0))
869 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
872 if (TAILQ_EMPTY(&asoc->send_queue) &&
873 TAILQ_EMPTY(&asoc->sent_queue) &&
874 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
878 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
879 0, M_DONTWAIT, 1, MT_DATA);
885 struct sctp_paramhdr *ph;
888 SCTP_BUF_LEN(op_err) =
889 (sizeof(struct sctp_paramhdr) + sizeof(uint32_t));
891 struct sctp_paramhdr *);
892 ph->param_type = htons(
893 SCTP_CAUSE_USER_INITIATED_ABT);
894 ph->param_length = htons(SCTP_BUF_LEN(op_err));
895 ippp = (uint32_t *) (ph + 1);
896 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4);
898 #if defined(SCTP_PANIC_ON_ABORT)
899 panic("disconnect does an abort");
902 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
903 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
904 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
905 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
906 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
907 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
909 SCTP_INP_RUNLOCK(inp);
910 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
913 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
916 soisdisconnecting(so);
917 SCTP_TCB_UNLOCK(stcb);
918 SCTP_INP_RUNLOCK(inp);
923 /* UDP model does not support this */
924 SCTP_INP_RUNLOCK(inp);
925 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
931 sctp_flush(struct socket *so, int how)
934 * We will just clear out the values and let subsequent close clear
935 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
936 * they will not be able to read the data, the socket will block
937 * that from happening.
939 struct sctp_inpcb *inp;
941 inp = (struct sctp_inpcb *)so->so_pcb;
943 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
947 /* For the 1 to many model this does nothing */
948 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
949 SCTP_INP_RUNLOCK(inp);
952 SCTP_INP_RUNLOCK(inp);
953 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
955 * First make sure the sb will be happy, we don't use these
956 * except maybe the count
959 SCTP_INP_READ_LOCK(inp);
960 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
961 SCTP_INP_READ_UNLOCK(inp);
962 SCTP_INP_WUNLOCK(inp);
963 so->so_rcv.sb_cc = 0;
964 so->so_rcv.sb_mbcnt = 0;
965 so->so_rcv.sb_mb = NULL;
967 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
969 * First make sure the sb will be happy, we don't use these
970 * except maybe the count
972 so->so_snd.sb_cc = 0;
973 so->so_snd.sb_mbcnt = 0;
974 so->so_snd.sb_mb = NULL;
981 sctp_shutdown(struct socket *so)
983 struct sctp_inpcb *inp;
985 inp = (struct sctp_inpcb *)so->so_pcb;
987 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
991 /* For UDP model this is a invalid call */
992 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
993 /* Restore the flags that the soshutdown took away. */
994 SOCKBUF_LOCK(&so->so_rcv);
995 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
996 SOCKBUF_UNLOCK(&so->so_rcv);
997 /* This proc will wakeup for read and do nothing (I hope) */
998 SCTP_INP_RUNLOCK(inp);
999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1000 return (EOPNOTSUPP);
1003 * Ok if we reach here its the TCP model and it is either a SHUT_WR
1004 * or SHUT_RDWR. This means we put the shutdown flag against it.
1007 struct sctp_tcb *stcb;
1008 struct sctp_association *asoc;
1011 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
1012 SCTP_INP_RUNLOCK(inp);
1017 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1020 * Ok we hit the case that the shutdown call was
1021 * made after an abort or something. Nothing to do
1024 SCTP_INP_RUNLOCK(inp);
1027 SCTP_TCB_LOCK(stcb);
1029 if (TAILQ_EMPTY(&asoc->send_queue) &&
1030 TAILQ_EMPTY(&asoc->sent_queue) &&
1031 (asoc->stream_queue_cnt == 0)) {
1032 if (asoc->locked_on_sending) {
1035 /* there is nothing queued to send, so I'm done... */
1036 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
1037 /* only send SHUTDOWN the first time through */
1038 struct sctp_nets *netp;
1040 if (stcb->asoc.alternate) {
1041 netp = stcb->asoc.alternate;
1043 netp = stcb->asoc.primary_destination;
1045 sctp_stop_timers_for_shutdown(stcb);
1046 sctp_send_shutdown(stcb, netp);
1047 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
1048 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
1049 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1050 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1052 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
1053 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
1054 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1055 stcb->sctp_ep, stcb, netp);
1056 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1057 stcb->sctp_ep, stcb, netp);
1061 * we still got (or just got) data to send, so set
1064 struct sctp_nets *netp;
1066 if (stcb->asoc.alternate) {
1067 netp = stcb->asoc.alternate;
1069 netp = stcb->asoc.primary_destination;
1072 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1073 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1076 if (asoc->locked_on_sending) {
1077 /* Locked to send out the data */
1078 struct sctp_stream_queue_pending *sp;
1080 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1082 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1083 asoc->locked_on_sending->stream_no);
1085 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1086 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1090 if (TAILQ_EMPTY(&asoc->send_queue) &&
1091 TAILQ_EMPTY(&asoc->sent_queue) &&
1092 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1093 struct mbuf *op_err;
1096 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
1097 0, M_DONTWAIT, 1, MT_DATA);
1099 /* Fill in the user initiated abort */
1100 struct sctp_paramhdr *ph;
1103 SCTP_BUF_LEN(op_err) =
1104 sizeof(struct sctp_paramhdr) + sizeof(uint32_t);
1106 struct sctp_paramhdr *);
1107 ph->param_type = htons(
1108 SCTP_CAUSE_USER_INITIATED_ABT);
1109 ph->param_length = htons(SCTP_BUF_LEN(op_err));
1110 ippp = (uint32_t *) (ph + 1);
1111 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1113 #if defined(SCTP_PANIC_ON_ABORT)
1114 panic("shutdown does an abort");
1116 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1117 sctp_abort_an_association(stcb->sctp_ep, stcb,
1118 SCTP_RESPONSE_TO_USER_REQ,
1119 op_err, SCTP_SO_LOCKED);
1122 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1125 SCTP_TCB_UNLOCK(stcb);
1128 SCTP_INP_RUNLOCK(inp);
1133 * copies a "user" presentable address and removes embedded scope, etc.
1134 * returns 0 on success, 1 on error
1137 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1140 struct sockaddr_in6 lsa6;
1142 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1145 memcpy(ss, sa, sa->sa_len);
1152 * NOTE: assumes addr lock is held
1155 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1156 struct sctp_tcb *stcb,
1158 struct sockaddr_storage *sas,
1161 struct sctp_ifn *sctp_ifn;
1162 struct sctp_ifa *sctp_ifa;
1163 int loopback_scope, ipv4_local_scope, local_scope, site_scope;
1165 int ipv4_addr_legal, ipv6_addr_legal;
1166 struct sctp_vrf *vrf;
1173 /* Turn on all the appropriate scope */
1174 loopback_scope = stcb->asoc.loopback_scope;
1175 ipv4_local_scope = stcb->asoc.ipv4_local_scope;
1176 local_scope = stcb->asoc.local_scope;
1177 site_scope = stcb->asoc.site_scope;
1179 /* Turn on ALL scope, since we look at the EP */
1180 loopback_scope = ipv4_local_scope = local_scope =
1183 ipv4_addr_legal = ipv6_addr_legal = 0;
1184 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1185 ipv6_addr_legal = 1;
1186 if (SCTP_IPV6_V6ONLY(inp) == 0) {
1187 ipv4_addr_legal = 1;
1190 ipv4_addr_legal = 1;
1192 vrf = sctp_find_vrf(vrf_id);
1196 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1197 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1198 if ((loopback_scope == 0) &&
1199 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1200 /* Skip loopback if loopback_scope not set */
1203 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1206 * For the BOUND-ALL case, the list
1207 * associated with a TCB is Always
1208 * considered a reverse list.. i.e.
1209 * it lists addresses that are NOT
1210 * part of the association. If this
1211 * is one of those we must skip it.
1213 if (sctp_is_addr_restricted(stcb,
1218 switch (sctp_ifa->address.sa.sa_family) {
1221 if (ipv4_addr_legal) {
1222 struct sockaddr_in *sin;
1224 sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
1225 if (sin->sin_addr.s_addr == 0) {
1233 if ((ipv4_local_scope == 0) &&
1234 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1238 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1239 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1240 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1241 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1242 actual += sizeof(struct sockaddr_in6);
1245 memcpy(sas, sin, sizeof(*sin));
1246 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1247 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1248 actual += sizeof(*sin);
1252 if (actual >= limit) {
1262 if (ipv6_addr_legal) {
1263 struct sockaddr_in6 *sin6;
1265 sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
1266 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1274 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1275 if (local_scope == 0)
1277 if (sin6->sin6_scope_id == 0) {
1278 if (sa6_recoverscope(sin6) != 0)
1296 if ((site_scope == 0) &&
1297 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1300 memcpy(sas, sin6, sizeof(*sin6));
1301 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1302 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1303 actual += sizeof(*sin6);
1304 if (actual >= limit) {
1319 struct sctp_laddr *laddr;
1321 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1323 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1327 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1330 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1331 sas = (struct sockaddr_storage *)((caddr_t)sas +
1332 laddr->ifa->address.sa.sa_len);
1333 actual += laddr->ifa->address.sa.sa_len;
1334 if (actual >= limit) {
1343 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1344 struct sctp_tcb *stcb,
1346 struct sockaddr_storage *sas)
1350 SCTP_IPI_ADDR_RLOCK();
1351 /* fill up addresses for the endpoint's default vrf */
1352 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1354 SCTP_IPI_ADDR_RUNLOCK();
1359 * NOTE: assumes addr lock is held
1362 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1365 struct sctp_vrf *vrf = NULL;
1368 * In both sub-set bound an bound_all cases we return the MAXIMUM
1369 * number of addresses that you COULD get. In reality the sub-set
1370 * bound may have an exclusion list for a given TCB OR in the
1371 * bound-all case a TCB may NOT include the loopback or other
1372 * addresses as well.
1374 vrf = sctp_find_vrf(vrf_id);
1378 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1379 struct sctp_ifn *sctp_ifn;
1380 struct sctp_ifa *sctp_ifa;
1382 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1383 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1384 /* Count them if they are the right type */
1385 switch (sctp_ifa->address.sa.sa_family) {
1388 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1389 cnt += sizeof(struct sockaddr_in6);
1391 cnt += sizeof(struct sockaddr_in);
1396 cnt += sizeof(struct sockaddr_in6);
1405 struct sctp_laddr *laddr;
1407 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1408 switch (laddr->ifa->address.sa.sa_family) {
1411 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1412 cnt += sizeof(struct sockaddr_in6);
1414 cnt += sizeof(struct sockaddr_in);
1419 cnt += sizeof(struct sockaddr_in6);
1431 sctp_count_max_addresses(struct sctp_inpcb *inp)
1435 SCTP_IPI_ADDR_RLOCK();
1436 /* count addresses for the endpoint's default VRF */
1437 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1438 SCTP_IPI_ADDR_RUNLOCK();
1443 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1444 size_t optsize, void *p, int delay)
1447 int creat_lock_on = 0;
1448 struct sctp_tcb *stcb = NULL;
1449 struct sockaddr *sa;
1450 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1452 int bad_addresses = 0;
1455 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1457 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1458 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1459 /* We are already connected AND the TCP model */
1460 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1461 return (EADDRINUSE);
1463 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1464 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1465 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1468 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1469 SCTP_INP_RLOCK(inp);
1470 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1471 SCTP_INP_RUNLOCK(inp);
1474 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1477 SCTP_INP_INCR_REF(inp);
1478 SCTP_ASOC_CREATE_LOCK(inp);
1480 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1481 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1482 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1486 totaddrp = (int *)optval;
1487 totaddr = *totaddrp;
1488 sa = (struct sockaddr *)(totaddrp + 1);
1489 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
1490 if ((stcb != NULL) || bad_addresses) {
1491 /* Already have or am bring up an association */
1492 SCTP_ASOC_CREATE_UNLOCK(inp);
1495 SCTP_TCB_UNLOCK(stcb);
1496 if (bad_addresses == 0) {
1497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1503 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1508 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1510 struct in6pcb *inp6;
1512 inp6 = (struct in6pcb *)inp;
1513 if (SCTP_IPV6_V6ONLY(inp6)) {
1515 * if IPV6_V6ONLY flag, ignore connections destined
1516 * to a v4 addr or v4-mapped addr
1518 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1524 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1525 SCTP_PCB_FLAGS_UNBOUND) {
1526 /* Bind a ephemeral port */
1527 error = sctp_inpcb_bind(so, NULL, NULL, p);
1532 /* FIX ME: do we want to pass in a vrf on the connect call? */
1533 vrf_id = inp->def_vrf_id;
1536 /* We are GOOD to go */
1537 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1541 /* Gak! no memory */
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 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1865 &av->stream_value) < 0) {
1866 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1869 *optsize = sizeof(struct sctp_stream_value);
1871 SCTP_TCB_UNLOCK(stcb);
1874 * Can't get stream value without
1877 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1882 case SCTP_GET_ADDR_LEN:
1884 struct sctp_assoc_value *av;
1886 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1889 if (av->assoc_value == AF_INET) {
1890 av->assoc_value = sizeof(struct sockaddr_in);
1895 if (av->assoc_value == AF_INET6) {
1896 av->assoc_value = sizeof(struct sockaddr_in6);
1901 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1903 *optsize = sizeof(struct sctp_assoc_value);
1907 case SCTP_GET_ASSOC_NUMBER:
1909 uint32_t *value, cnt;
1911 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1913 SCTP_INP_RLOCK(inp);
1914 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1917 SCTP_INP_RUNLOCK(inp);
1919 *optsize = sizeof(uint32_t);
1922 case SCTP_GET_ASSOC_ID_LIST:
1924 struct sctp_assoc_ids *ids;
1925 unsigned int at, limit;
1927 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1929 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1930 SCTP_INP_RLOCK(inp);
1931 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1933 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1936 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1940 SCTP_INP_RUNLOCK(inp);
1942 ids->gaids_number_of_ids = at;
1943 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1949 struct sctp_assoc_value *av;
1951 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1952 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1955 av->assoc_value = stcb->asoc.context;
1956 SCTP_TCB_UNLOCK(stcb);
1958 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1959 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1960 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1961 SCTP_INP_RLOCK(inp);
1962 av->assoc_value = inp->sctp_context;
1963 SCTP_INP_RUNLOCK(inp);
1965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1970 *optsize = sizeof(struct sctp_assoc_value);
1976 uint32_t *default_vrfid;
1978 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1979 *default_vrfid = inp->def_vrf_id;
1980 *optsize = sizeof(uint32_t);
1983 case SCTP_GET_ASOC_VRF:
1985 struct sctp_assoc_value *id;
1987 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1988 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1991 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1993 id->assoc_value = stcb->asoc.vrf_id;
1994 *optsize = sizeof(struct sctp_assoc_value);
1998 case SCTP_GET_VRF_IDS:
2000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2004 case SCTP_GET_NONCE_VALUES:
2006 struct sctp_get_nonce_values *gnv;
2008 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2009 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2012 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2013 gnv->gn_local_tag = stcb->asoc.my_vtag;
2014 SCTP_TCB_UNLOCK(stcb);
2015 *optsize = sizeof(struct sctp_get_nonce_values);
2017 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2022 case SCTP_DELAYED_SACK:
2024 struct sctp_sack_info *sack;
2026 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2027 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2029 sack->sack_delay = stcb->asoc.delayed_ack;
2030 sack->sack_freq = stcb->asoc.sack_freq;
2031 SCTP_TCB_UNLOCK(stcb);
2033 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2034 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2035 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2036 SCTP_INP_RLOCK(inp);
2037 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2038 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2039 SCTP_INP_RUNLOCK(inp);
2041 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2046 *optsize = sizeof(struct sctp_sack_info);
2050 case SCTP_GET_SNDBUF_USE:
2052 struct sctp_sockstat *ss;
2054 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2055 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2058 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2059 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2060 stcb->asoc.size_on_all_streams);
2061 SCTP_TCB_UNLOCK(stcb);
2062 *optsize = sizeof(struct sctp_sockstat);
2064 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2069 case SCTP_MAX_BURST:
2073 SCTP_CHECK_AND_CAST(value, optval, uint8_t, *optsize);
2075 SCTP_INP_RLOCK(inp);
2076 if (inp->sctp_ep.max_burst < 256) {
2077 *value = inp->sctp_ep.max_burst;
2081 SCTP_INP_RUNLOCK(inp);
2082 *optsize = sizeof(uint8_t);
2087 struct sctp_assoc_value *av;
2090 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2091 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2094 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2095 SCTP_TCB_UNLOCK(stcb);
2097 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2098 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2099 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2100 SCTP_INP_RLOCK(inp);
2101 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2102 ovh = SCTP_MED_OVERHEAD;
2104 ovh = SCTP_MED_V4_OVERHEAD;
2106 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2107 av->assoc_value = 0;
2109 av->assoc_value = inp->sctp_frag_point - ovh;
2110 SCTP_INP_RUNLOCK(inp);
2112 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2117 *optsize = sizeof(struct sctp_assoc_value);
2121 case SCTP_GET_STAT_LOG:
2122 error = sctp_fill_stat_log(optval, optsize);
2126 struct sctp_event_subscribe *events;
2128 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2129 memset(events, 0, sizeof(struct sctp_event_subscribe));
2130 SCTP_INP_RLOCK(inp);
2131 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2132 events->sctp_data_io_event = 1;
2134 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2135 events->sctp_association_event = 1;
2137 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2138 events->sctp_address_event = 1;
2140 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2141 events->sctp_send_failure_event = 1;
2143 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2144 events->sctp_peer_error_event = 1;
2146 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2147 events->sctp_shutdown_event = 1;
2149 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2150 events->sctp_partial_delivery_event = 1;
2152 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2153 events->sctp_adaptation_layer_event = 1;
2155 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2156 events->sctp_authentication_event = 1;
2158 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2159 events->sctp_sender_dry_event = 1;
2161 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2162 events->sctp_stream_reset_event = 1;
2163 SCTP_INP_RUNLOCK(inp);
2164 *optsize = sizeof(struct sctp_event_subscribe);
2167 case SCTP_ADAPTATION_LAYER:
2171 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2173 SCTP_INP_RLOCK(inp);
2174 *value = inp->sctp_ep.adaptation_layer_indicator;
2175 SCTP_INP_RUNLOCK(inp);
2176 *optsize = sizeof(uint32_t);
2179 case SCTP_SET_INITIAL_DBG_SEQ:
2183 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2184 SCTP_INP_RLOCK(inp);
2185 *value = inp->sctp_ep.initial_sequence_debug;
2186 SCTP_INP_RUNLOCK(inp);
2187 *optsize = sizeof(uint32_t);
2190 case SCTP_GET_LOCAL_ADDR_SIZE:
2194 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2195 SCTP_INP_RLOCK(inp);
2196 *value = sctp_count_max_addresses(inp);
2197 SCTP_INP_RUNLOCK(inp);
2198 *optsize = sizeof(uint32_t);
2201 case SCTP_GET_REMOTE_ADDR_SIZE:
2205 struct sctp_nets *net;
2207 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2208 /* FIXME MT: change to sctp_assoc_value? */
2209 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2213 /* Count the sizes */
2214 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2215 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2216 size += sizeof(struct sockaddr_in6);
2218 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2221 size += sizeof(struct sockaddr_in);
2226 size += sizeof(struct sockaddr_in6);
2234 SCTP_TCB_UNLOCK(stcb);
2235 *value = (uint32_t) size;
2236 *optsize = sizeof(uint32_t);
2238 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2243 case SCTP_GET_PEER_ADDRESSES:
2245 * Get the address information, an array is passed in to
2246 * fill up we pack it.
2250 struct sockaddr_storage *sas;
2251 struct sctp_nets *net;
2252 struct sctp_getaddresses *saddr;
2254 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2255 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2258 left = (*optsize) - sizeof(struct sctp_getaddresses);
2259 *optsize = sizeof(struct sctp_getaddresses);
2260 sas = (struct sockaddr_storage *)&saddr->addr[0];
2262 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2263 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2264 cpsz = sizeof(struct sockaddr_in6);
2266 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2269 cpsz = sizeof(struct sockaddr_in);
2274 cpsz = sizeof(struct sockaddr_in6);
2286 /* not enough room. */
2289 #if defined(INET) && defined(INET6)
2290 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2291 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2292 /* Must map the address */
2293 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2294 (struct sockaddr_in6 *)sas);
2297 memcpy(sas, &net->ro._l_addr, cpsz);
2298 #if defined(INET) && defined(INET6)
2301 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2303 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2307 SCTP_TCB_UNLOCK(stcb);
2309 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2314 case SCTP_GET_LOCAL_ADDRESSES:
2316 size_t limit, actual;
2317 struct sockaddr_storage *sas;
2318 struct sctp_getaddresses *saddr;
2320 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2321 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2323 sas = (struct sockaddr_storage *)&saddr->addr[0];
2324 limit = *optsize - sizeof(sctp_assoc_t);
2325 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2327 SCTP_TCB_UNLOCK(stcb);
2329 *optsize = sizeof(struct sockaddr_storage) + actual;
2332 case SCTP_PEER_ADDR_PARAMS:
2334 struct sctp_paddrparams *paddrp;
2335 struct sctp_nets *net;
2337 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2338 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2342 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2345 * We increment here since
2346 * sctp_findassociation_ep_addr() wil do a
2347 * decrement if it finds the stcb as long as
2348 * the locked tcb (last argument) is NOT a
2351 SCTP_INP_INCR_REF(inp);
2352 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2354 SCTP_INP_DECR_REF(inp);
2357 if (stcb && (net == NULL)) {
2358 struct sockaddr *sa;
2360 sa = (struct sockaddr *)&paddrp->spp_address;
2362 if (sa->sa_family == AF_INET) {
2363 struct sockaddr_in *sin;
2365 sin = (struct sockaddr_in *)sa;
2366 if (sin->sin_addr.s_addr) {
2368 SCTP_TCB_UNLOCK(stcb);
2369 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2375 if (sa->sa_family == AF_INET6) {
2376 struct sockaddr_in6 *sin6;
2378 sin6 = (struct sockaddr_in6 *)sa;
2379 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2381 SCTP_TCB_UNLOCK(stcb);
2382 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2388 error = EAFNOSUPPORT;
2389 SCTP_TCB_UNLOCK(stcb);
2390 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2395 /* Applies to the specific association */
2396 paddrp->spp_flags = 0;
2400 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2401 ovh = SCTP_MED_OVERHEAD;
2403 ovh = SCTP_MED_V4_OVERHEAD;
2406 paddrp->spp_hbinterval = net->heart_beat_delay;
2407 paddrp->spp_pathmaxrxt = net->failure_threshold;
2408 paddrp->spp_pathmtu = net->mtu - ovh;
2409 /* get flags for HB */
2410 if (net->dest_state & SCTP_ADDR_NOHB)
2411 paddrp->spp_flags |= SPP_HB_DISABLE;
2413 paddrp->spp_flags |= SPP_HB_ENABLE;
2414 /* get flags for PMTU */
2415 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
2416 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2418 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2421 if (net->ro._l_addr.sin.sin_family == AF_INET) {
2422 paddrp->spp_dscp = net->dscp;
2423 paddrp->spp_flags |= SPP_DSCP;
2427 if (net->ro._l_addr.sin6.sin6_family == AF_INET6) {
2428 paddrp->spp_ipv6_flowlabel = net->flowlabel;
2429 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2434 * No destination so return default
2439 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2440 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2442 paddrp->spp_dscp = stcb->asoc.default_dscp & 0x000000fc;
2443 paddrp->spp_flags |= SPP_DSCP;
2446 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel;
2447 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2449 /* default settings should be these */
2450 if (sctp_is_feature_on(stcb->sctp_ep, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2451 paddrp->spp_flags |= SPP_HB_DISABLE;
2453 paddrp->spp_flags |= SPP_HB_ENABLE;
2455 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2456 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2457 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
2462 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2465 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2466 SCTP_TCB_UNLOCK(stcb);
2468 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2469 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2470 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2471 /* Use endpoint defaults */
2472 SCTP_INP_RLOCK(inp);
2473 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2474 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2475 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2476 /* get inp's default */
2478 paddrp->spp_dscp = inp->ip_inp.inp.inp_ip_tos;
2479 paddrp->spp_flags |= SPP_DSCP;
2482 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2483 paddrp->spp_ipv6_flowlabel = ((struct in6pcb *)inp)->in6p_flowinfo;
2484 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2487 /* can't return this */
2488 paddrp->spp_pathmtu = 0;
2490 /* default behavior, no stcb */
2491 paddrp->spp_flags = SPP_PMTUD_ENABLE;
2493 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2494 paddrp->spp_flags |= SPP_HB_ENABLE;
2496 paddrp->spp_flags |= SPP_HB_DISABLE;
2498 SCTP_INP_RUNLOCK(inp);
2500 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2505 *optsize = sizeof(struct sctp_paddrparams);
2509 case SCTP_GET_PEER_ADDR_INFO:
2511 struct sctp_paddrinfo *paddri;
2512 struct sctp_nets *net;
2514 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2515 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2519 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
2522 * We increment here since
2523 * sctp_findassociation_ep_addr() wil do a
2524 * decrement if it finds the stcb as long as
2525 * the locked tcb (last argument) is NOT a
2528 SCTP_INP_INCR_REF(inp);
2529 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
2531 SCTP_INP_DECR_REF(inp);
2535 if ((stcb) && (net)) {
2536 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2537 /* It's unconfirmed */
2538 paddri->spinfo_state = SCTP_UNCONFIRMED;
2539 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2541 paddri->spinfo_state = SCTP_ACTIVE;
2544 paddri->spinfo_state = SCTP_INACTIVE;
2546 paddri->spinfo_cwnd = net->cwnd;
2547 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2548 paddri->spinfo_rto = net->RTO;
2549 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2550 paddri->spinfo_mtu = net->mtu;
2551 SCTP_TCB_UNLOCK(stcb);
2552 *optsize = sizeof(struct sctp_paddrinfo);
2555 SCTP_TCB_UNLOCK(stcb);
2557 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2562 case SCTP_PCB_STATUS:
2564 struct sctp_pcbinfo *spcb;
2566 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2567 sctp_fill_pcbinfo(spcb);
2568 *optsize = sizeof(struct sctp_pcbinfo);
2573 struct sctp_nets *net;
2574 struct sctp_status *sstat;
2576 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2577 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2580 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2585 * I think passing the state is fine since
2586 * sctp_constants.h will be available to the user
2589 sstat->sstat_state = stcb->asoc.state;
2590 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2591 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2592 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2594 * We can't include chunks that have been passed to
2595 * the socket layer. Only things in queue.
2597 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2598 stcb->asoc.cnt_on_all_streams);
2601 sstat->sstat_instrms = stcb->asoc.streamincnt;
2602 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2603 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2604 memcpy(&sstat->sstat_primary.spinfo_address,
2605 &stcb->asoc.primary_destination->ro._l_addr,
2606 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2607 net = stcb->asoc.primary_destination;
2608 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2610 * Again the user can get info from sctp_constants.h
2611 * for what the state of the network is.
2613 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2614 /* It's unconfirmed */
2615 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2616 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2618 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2621 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2623 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2624 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2625 sstat->sstat_primary.spinfo_rto = net->RTO;
2626 sstat->sstat_primary.spinfo_mtu = net->mtu;
2627 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2628 SCTP_TCB_UNLOCK(stcb);
2629 *optsize = sizeof(struct sctp_status);
2634 struct sctp_rtoinfo *srto;
2636 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2637 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2640 srto->srto_initial = stcb->asoc.initial_rto;
2641 srto->srto_max = stcb->asoc.maxrto;
2642 srto->srto_min = stcb->asoc.minrto;
2643 SCTP_TCB_UNLOCK(stcb);
2645 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2646 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2647 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2648 SCTP_INP_RLOCK(inp);
2649 srto->srto_initial = inp->sctp_ep.initial_rto;
2650 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2651 srto->srto_min = inp->sctp_ep.sctp_minrto;
2652 SCTP_INP_RUNLOCK(inp);
2654 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2659 *optsize = sizeof(struct sctp_rtoinfo);
2665 struct sctp_timeouts *stimo;
2667 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2668 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2671 stimo->stimo_init = stcb->asoc.timoinit;
2672 stimo->stimo_data = stcb->asoc.timodata;
2673 stimo->stimo_sack = stcb->asoc.timosack;
2674 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2675 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2676 stimo->stimo_cookie = stcb->asoc.timocookie;
2677 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2678 SCTP_TCB_UNLOCK(stcb);
2679 *optsize = sizeof(struct sctp_timeouts);
2681 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2686 case SCTP_ASSOCINFO:
2688 struct sctp_assocparams *sasoc;
2690 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2691 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2694 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2695 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2696 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2697 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2698 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2699 SCTP_TCB_UNLOCK(stcb);
2701 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2702 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2703 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2704 SCTP_INP_RLOCK(inp);
2705 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2706 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2707 sasoc->sasoc_number_peer_destinations = 0;
2708 sasoc->sasoc_peer_rwnd = 0;
2709 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2710 SCTP_INP_RUNLOCK(inp);
2712 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2717 *optsize = sizeof(struct sctp_assocparams);
2721 case SCTP_DEFAULT_SEND_PARAM:
2723 struct sctp_sndrcvinfo *s_info;
2725 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2726 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2729 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2730 SCTP_TCB_UNLOCK(stcb);
2732 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2733 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2734 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2735 SCTP_INP_RLOCK(inp);
2736 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2737 SCTP_INP_RUNLOCK(inp);
2739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2744 *optsize = sizeof(struct sctp_sndrcvinfo);
2750 struct sctp_initmsg *sinit;
2752 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2753 SCTP_INP_RLOCK(inp);
2754 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2755 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2756 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2757 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2758 SCTP_INP_RUNLOCK(inp);
2759 *optsize = sizeof(struct sctp_initmsg);
2762 case SCTP_PRIMARY_ADDR:
2763 /* we allow a "get" operation on this */
2765 struct sctp_setprim *ssp;
2767 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2768 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2771 /* simply copy out the sockaddr_storage... */
2775 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
2776 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
2778 memcpy(&ssp->ssp_addr,
2779 &stcb->asoc.primary_destination->ro._l_addr,
2781 SCTP_TCB_UNLOCK(stcb);
2782 *optsize = sizeof(struct sctp_setprim);
2784 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2789 case SCTP_HMAC_IDENT:
2791 struct sctp_hmacalgo *shmac;
2792 sctp_hmaclist_t *hmaclist;
2796 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2798 SCTP_INP_RLOCK(inp);
2799 hmaclist = inp->sctp_ep.local_hmacs;
2800 if (hmaclist == NULL) {
2801 /* no HMACs to return */
2802 *optsize = sizeof(*shmac);
2803 SCTP_INP_RUNLOCK(inp);
2806 /* is there room for all of the hmac ids? */
2807 size = sizeof(*shmac) + (hmaclist->num_algo *
2808 sizeof(shmac->shmac_idents[0]));
2809 if ((size_t)(*optsize) < size) {
2810 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2812 SCTP_INP_RUNLOCK(inp);
2815 /* copy in the list */
2816 shmac->shmac_number_of_idents = hmaclist->num_algo;
2817 for (i = 0; i < hmaclist->num_algo; i++) {
2818 shmac->shmac_idents[i] = hmaclist->hmac[i];
2820 SCTP_INP_RUNLOCK(inp);
2824 case SCTP_AUTH_ACTIVE_KEY:
2826 struct sctp_authkeyid *scact;
2828 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2829 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2832 /* get the active key on the assoc */
2833 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2834 SCTP_TCB_UNLOCK(stcb);
2836 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2837 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2838 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2839 /* get the endpoint active key */
2840 SCTP_INP_RLOCK(inp);
2841 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2842 SCTP_INP_RUNLOCK(inp);
2844 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2849 *optsize = sizeof(struct sctp_authkeyid);
2853 case SCTP_LOCAL_AUTH_CHUNKS:
2855 struct sctp_authchunks *sac;
2856 sctp_auth_chklist_t *chklist = NULL;
2859 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2860 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2863 /* get off the assoc */
2864 chklist = stcb->asoc.local_auth_chunks;
2865 /* is there enough space? */
2866 size = sctp_auth_get_chklist_size(chklist);
2867 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2871 /* copy in the chunks */
2872 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2873 *optsize = sizeof(struct sctp_authchunks) + size;
2875 SCTP_TCB_UNLOCK(stcb);
2877 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2878 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2879 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2880 /* get off the endpoint */
2881 SCTP_INP_RLOCK(inp);
2882 chklist = inp->sctp_ep.local_auth_chunks;
2883 /* is there enough space? */
2884 size = sctp_auth_get_chklist_size(chklist);
2885 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2887 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2889 /* copy in the chunks */
2890 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2891 *optsize = sizeof(struct sctp_authchunks) + size;
2893 SCTP_INP_RUNLOCK(inp);
2895 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2901 case SCTP_PEER_AUTH_CHUNKS:
2903 struct sctp_authchunks *sac;
2904 sctp_auth_chklist_t *chklist = NULL;
2907 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2908 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2911 /* get off the assoc */
2912 chklist = stcb->asoc.peer_auth_chunks;
2913 /* is there enough space? */
2914 size = sctp_auth_get_chklist_size(chklist);
2915 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2917 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2919 /* copy in the chunks */
2920 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2921 *optsize = sizeof(struct sctp_authchunks) + size;
2923 SCTP_TCB_UNLOCK(stcb);
2925 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2932 struct sctp_event *event;
2933 uint32_t event_type;
2935 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2936 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2938 switch (event->se_type) {
2939 case SCTP_ASSOC_CHANGE:
2940 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2942 case SCTP_PEER_ADDR_CHANGE:
2943 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
2945 case SCTP_REMOTE_ERROR:
2946 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
2948 case SCTP_SEND_FAILED:
2949 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
2951 case SCTP_SHUTDOWN_EVENT:
2952 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
2954 case SCTP_ADAPTATION_INDICATION:
2955 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
2957 case SCTP_PARTIAL_DELIVERY_EVENT:
2958 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
2960 case SCTP_AUTHENTICATION_EVENT:
2961 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
2963 case SCTP_STREAM_RESET_EVENT:
2964 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
2966 case SCTP_SENDER_DRY_EVENT:
2967 event_type = SCTP_PCB_FLAGS_DRYEVNT;
2969 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
2971 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
2976 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2980 if (event_type > 0) {
2982 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
2983 SCTP_TCB_UNLOCK(stcb);
2985 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2986 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2987 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
2988 SCTP_INP_RLOCK(inp);
2989 event->se_on = sctp_is_feature_on(inp, event_type);
2990 SCTP_INP_RUNLOCK(inp);
2992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2998 *optsize = sizeof(struct sctp_event);
3002 case SCTP_RECVRCVINFO:
3006 if (*optsize < sizeof(int)) {
3007 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3010 SCTP_INP_RUNLOCK(inp);
3011 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3012 SCTP_INP_RUNLOCK(inp);
3015 /* return the option value */
3016 *(int *)optval = onoff;
3017 *optsize = sizeof(int);
3021 case SCTP_RECVNXTINFO:
3025 if (*optsize < sizeof(int)) {
3026 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3029 SCTP_INP_RUNLOCK(inp);
3030 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3031 SCTP_INP_RUNLOCK(inp);
3034 /* return the option value */
3035 *(int *)optval = onoff;
3036 *optsize = sizeof(int);
3040 case SCTP_DEFAULT_SNDINFO:
3042 struct sctp_sndinfo *info;
3044 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3045 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3048 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3049 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3050 info->snd_flags &= 0xfff0;
3051 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3052 info->snd_context = stcb->asoc.def_send.sinfo_context;
3053 SCTP_TCB_UNLOCK(stcb);
3055 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3056 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3057 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3058 SCTP_INP_RLOCK(inp);
3059 info->snd_sid = inp->def_send.sinfo_stream;
3060 info->snd_flags = inp->def_send.sinfo_flags;
3061 info->snd_flags &= 0xfff0;
3062 info->snd_ppid = inp->def_send.sinfo_ppid;
3063 info->snd_context = inp->def_send.sinfo_context;
3064 SCTP_INP_RUNLOCK(inp);
3066 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3071 *optsize = sizeof(struct sctp_sndinfo);
3075 case SCTP_DEFAULT_PRINFO:
3077 struct sctp_default_prinfo *info;
3079 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3080 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3083 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3084 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3085 SCTP_TCB_UNLOCK(stcb);
3087 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3088 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3089 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3090 SCTP_INP_RLOCK(inp);
3091 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3092 info->pr_value = inp->def_send.sinfo_timetolive;
3093 SCTP_INP_RUNLOCK(inp);
3095 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3100 *optsize = sizeof(struct sctp_default_prinfo);
3104 case SCTP_PEER_ADDR_THLDS:
3106 struct sctp_paddrthlds *thlds;
3107 struct sctp_nets *net;
3109 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3110 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3114 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
3117 * We increment here since
3118 * sctp_findassociation_ep_addr() wil do a
3119 * decrement if it finds the stcb as long as
3120 * the locked tcb (last argument) is NOT a
3123 SCTP_INP_INCR_REF(inp);
3124 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL);
3126 SCTP_INP_DECR_REF(inp);
3129 if (stcb && (net == NULL)) {
3130 struct sockaddr *sa;
3132 sa = (struct sockaddr *)&thlds->spt_address;
3134 if (sa->sa_family == AF_INET) {
3135 struct sockaddr_in *sin;
3137 sin = (struct sockaddr_in *)sa;
3138 if (sin->sin_addr.s_addr) {
3140 SCTP_TCB_UNLOCK(stcb);
3141 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3147 if (sa->sa_family == AF_INET6) {
3148 struct sockaddr_in6 *sin6;
3150 sin6 = (struct sockaddr_in6 *)sa;
3151 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3153 SCTP_TCB_UNLOCK(stcb);
3154 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3160 error = EAFNOSUPPORT;
3161 SCTP_TCB_UNLOCK(stcb);
3162 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3168 thlds->spt_pathmaxrxt = net->failure_threshold;
3169 thlds->spt_pathpfthld = net->pf_threshold;
3171 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3172 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3174 thlds->spt_assoc_id = sctp_get_associd(stcb);
3175 SCTP_TCB_UNLOCK(stcb);
3177 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3178 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3179 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3180 /* Use endpoint defaults */
3181 SCTP_INP_RLOCK(inp);
3182 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3183 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3184 SCTP_INP_RUNLOCK(inp);
3186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3191 *optsize = sizeof(struct sctp_paddrthlds);
3196 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3197 error = ENOPROTOOPT;
3199 } /* end switch (sopt->sopt_name) */
3207 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3212 struct sctp_tcb *stcb = NULL;
3213 struct sctp_inpcb *inp = NULL;
3216 if (optval == NULL) {
3217 SCTP_PRINTF("optval is NULL\n");
3218 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3221 inp = (struct sctp_inpcb *)so->so_pcb;
3223 SCTP_PRINTF("inp is NULL?\n");
3224 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3227 vrf_id = inp->def_vrf_id;
3232 case SCTP_AUTOCLOSE:
3233 case SCTP_AUTO_ASCONF:
3234 case SCTP_EXPLICIT_EOR:
3235 case SCTP_DISABLE_FRAGMENTS:
3236 case SCTP_USE_EXT_RCVINFO:
3237 case SCTP_I_WANT_MAPPED_V4_ADDR:
3238 /* copy in the option value */
3239 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3244 case SCTP_DISABLE_FRAGMENTS:
3245 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3247 case SCTP_AUTO_ASCONF:
3249 * NOTE: we don't really support this flag
3251 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3252 /* only valid for bound all sockets */
3253 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3255 /* forbidden by admin */
3256 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3259 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3261 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3265 case SCTP_EXPLICIT_EOR:
3266 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3268 case SCTP_USE_EXT_RCVINFO:
3269 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3271 case SCTP_I_WANT_MAPPED_V4_ADDR:
3272 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3273 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3275 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3280 set_opt = SCTP_PCB_FLAGS_NODELAY;
3282 case SCTP_AUTOCLOSE:
3283 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3284 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3285 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3288 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3290 * The value is in ticks. Note this does not effect
3291 * old associations, only new ones.
3293 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3296 SCTP_INP_WLOCK(inp);
3298 sctp_feature_on(inp, set_opt);
3300 sctp_feature_off(inp, set_opt);
3302 SCTP_INP_WUNLOCK(inp);
3304 case SCTP_REUSE_PORT:
3306 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3307 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3308 /* Can't set it after we are bound */
3312 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3313 /* Can't do this for a 1-m socket */
3318 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3320 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3323 case SCTP_PARTIAL_DELIVERY_POINT:
3327 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3328 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3329 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3333 inp->partial_delivery_point = *value;
3336 case SCTP_FRAGMENT_INTERLEAVE:
3337 /* not yet until we re-write sctp_recvmsg() */
3341 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3342 if (*level == SCTP_FRAG_LEVEL_2) {
3343 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3344 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3345 } else if (*level == SCTP_FRAG_LEVEL_1) {
3346 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3347 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3348 } else if (*level == SCTP_FRAG_LEVEL_0) {
3349 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3350 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3353 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3358 case SCTP_CMT_ON_OFF:
3359 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3360 struct sctp_assoc_value *av;
3362 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3363 if (av->assoc_value > SCTP_CMT_MAX) {
3364 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3368 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3370 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3371 SCTP_TCB_UNLOCK(stcb);
3373 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3374 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3375 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3376 (av->assoc_id == SCTP_ALL_ASSOC)) {
3377 SCTP_INP_WLOCK(inp);
3378 inp->sctp_cmt_on_off = av->assoc_value;
3379 SCTP_INP_WUNLOCK(inp);
3381 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3382 (av->assoc_id == SCTP_ALL_ASSOC)) {
3383 SCTP_INP_RLOCK(inp);
3384 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3385 SCTP_TCB_LOCK(stcb);
3386 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3387 SCTP_TCB_UNLOCK(stcb);
3389 SCTP_INP_RUNLOCK(inp);
3393 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3394 error = ENOPROTOOPT;
3397 case SCTP_PLUGGABLE_CC:
3399 struct sctp_assoc_value *av;
3400 struct sctp_nets *net;
3402 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3403 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3404 (av->assoc_value != SCTP_CC_HSTCP) &&
3405 (av->assoc_value != SCTP_CC_HTCP) &&
3406 (av->assoc_value != SCTP_CC_RTCC)) {
3407 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3411 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3413 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3414 stcb->asoc.congestion_control_module = av->assoc_value;
3415 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3416 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3417 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3420 SCTP_TCB_UNLOCK(stcb);
3422 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3423 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3424 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3425 (av->assoc_id == SCTP_ALL_ASSOC)) {
3426 SCTP_INP_WLOCK(inp);
3427 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3428 SCTP_INP_WUNLOCK(inp);
3430 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3431 (av->assoc_id == SCTP_ALL_ASSOC)) {
3432 SCTP_INP_RLOCK(inp);
3433 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3434 SCTP_TCB_LOCK(stcb);
3435 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3436 stcb->asoc.congestion_control_module = av->assoc_value;
3437 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3438 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3439 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3442 SCTP_TCB_UNLOCK(stcb);
3444 SCTP_INP_RUNLOCK(inp);
3449 case SCTP_CC_OPTION:
3451 struct sctp_cc_option *cc_opt;
3453 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3454 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3456 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3457 SCTP_INP_RLOCK(inp);
3458 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3459 SCTP_TCB_LOCK(stcb);
3460 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3461 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3463 SCTP_TCB_UNLOCK(stcb);
3465 SCTP_INP_RUNLOCK(inp);
3470 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3473 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3476 SCTP_TCB_UNLOCK(stcb);
3480 case SCTP_PLUGGABLE_SS:
3482 struct sctp_assoc_value *av;
3484 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3485 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3486 (av->assoc_value != SCTP_SS_DEFAULT) &&
3487 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3488 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3489 (av->assoc_value != SCTP_SS_PRIORITY) &&
3490 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3491 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3492 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3496 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3498 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3499 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3500 stcb->asoc.stream_scheduling_module = av->assoc_value;
3501 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
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 (av->assoc_id == SCTP_ALL_ASSOC)) {
3508 SCTP_INP_WLOCK(inp);
3509 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
3510 SCTP_INP_WUNLOCK(inp);
3512 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3513 (av->assoc_id == SCTP_ALL_ASSOC)) {
3514 SCTP_INP_RLOCK(inp);
3515 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3516 SCTP_TCB_LOCK(stcb);
3517 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3518 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3519 stcb->asoc.stream_scheduling_module = av->assoc_value;
3520 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3521 SCTP_TCB_UNLOCK(stcb);
3523 SCTP_INP_RUNLOCK(inp);
3530 struct sctp_stream_value *av;
3532 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
3533 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3535 if (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
3536 av->stream_value) < 0) {
3537 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3540 SCTP_TCB_UNLOCK(stcb);
3542 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
3543 SCTP_INP_RLOCK(inp);
3544 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3545 SCTP_TCB_LOCK(stcb);
3546 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
3548 &stcb->asoc.strmout[av->stream_id],
3550 SCTP_TCB_UNLOCK(stcb);
3552 SCTP_INP_RUNLOCK(inp);
3556 * Can't set stream value without
3559 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3565 case SCTP_CLR_STAT_LOG:
3566 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3571 struct sctp_assoc_value *av;
3573 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3574 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3577 stcb->asoc.context = av->assoc_value;
3578 SCTP_TCB_UNLOCK(stcb);
3580 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3581 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3582 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3583 (av->assoc_id == SCTP_ALL_ASSOC)) {
3584 SCTP_INP_WLOCK(inp);
3585 inp->sctp_context = av->assoc_value;
3586 SCTP_INP_WUNLOCK(inp);
3588 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3589 (av->assoc_id == SCTP_ALL_ASSOC)) {
3590 SCTP_INP_RLOCK(inp);
3591 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3592 SCTP_TCB_LOCK(stcb);
3593 stcb->asoc.context = av->assoc_value;
3594 SCTP_TCB_UNLOCK(stcb);
3596 SCTP_INP_RUNLOCK(inp);
3603 uint32_t *default_vrfid;
3605 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
3606 if (*default_vrfid > SCTP_MAX_VRF_ID) {
3607 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3611 inp->def_vrf_id = *default_vrfid;
3614 case SCTP_DEL_VRF_ID:
3616 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3620 case SCTP_ADD_VRF_ID:
3622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3626 case SCTP_DELAYED_SACK:
3628 struct sctp_sack_info *sack;
3630 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
3631 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
3632 if (sack->sack_delay) {
3633 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
3634 sack->sack_delay = SCTP_MAX_SACK_DELAY;
3635 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3636 sack->sack_delay = TICKS_TO_MSEC(1);
3640 if (sack->sack_delay) {
3641 stcb->asoc.delayed_ack = sack->sack_delay;
3643 if (sack->sack_freq) {
3644 stcb->asoc.sack_freq = sack->sack_freq;
3646 SCTP_TCB_UNLOCK(stcb);
3648 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3649 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3650 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
3651 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3652 SCTP_INP_WLOCK(inp);
3653 if (sack->sack_delay) {
3654 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
3656 if (sack->sack_freq) {
3657 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
3659 SCTP_INP_WUNLOCK(inp);
3661 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
3662 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3663 SCTP_INP_RLOCK(inp);
3664 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3665 SCTP_TCB_LOCK(stcb);
3666 if (sack->sack_delay) {
3667 stcb->asoc.delayed_ack = sack->sack_delay;
3669 if (sack->sack_freq) {
3670 stcb->asoc.sack_freq = sack->sack_freq;
3672 SCTP_TCB_UNLOCK(stcb);
3674 SCTP_INP_RUNLOCK(inp);
3679 case SCTP_AUTH_CHUNK:
3681 struct sctp_authchunk *sauth;
3683 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
3685 SCTP_INP_WLOCK(inp);
3686 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
3687 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3690 SCTP_INP_WUNLOCK(inp);
3695 struct sctp_authkey *sca;
3696 struct sctp_keyhead *shared_keys;
3697 sctp_sharedkey_t *shared_key;
3698 sctp_key_t *key = NULL;
3701 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
3702 if (sca->sca_keylength == 0) {
3703 size = optsize - sizeof(struct sctp_authkey);
3705 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
3706 size = sca->sca_keylength;
3708 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3713 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
3716 shared_keys = &stcb->asoc.shared_keys;
3717 /* clear the cached keys for this key id */
3718 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3720 * create the new shared key and
3724 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3726 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3728 SCTP_TCB_UNLOCK(stcb);
3732 shared_key = sctp_alloc_sharedkey();
3733 if (shared_key == NULL) {
3735 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3737 SCTP_TCB_UNLOCK(stcb);
3740 shared_key->key = key;
3741 shared_key->keyid = sca->sca_keynumber;
3742 error = sctp_insert_sharedkey(shared_keys, shared_key);
3743 SCTP_TCB_UNLOCK(stcb);
3745 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3746 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3747 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
3748 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3749 SCTP_INP_WLOCK(inp);
3750 shared_keys = &inp->sctp_ep.shared_keys;
3752 * clear the cached keys on all
3753 * assocs for this key id
3755 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3757 * create the new shared key and
3761 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3763 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3765 SCTP_INP_WUNLOCK(inp);
3769 shared_key = sctp_alloc_sharedkey();
3770 if (shared_key == NULL) {
3772 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3774 SCTP_INP_WUNLOCK(inp);
3777 shared_key->key = key;
3778 shared_key->keyid = sca->sca_keynumber;
3779 error = sctp_insert_sharedkey(shared_keys, shared_key);
3780 SCTP_INP_WUNLOCK(inp);
3782 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
3783 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3784 SCTP_INP_RLOCK(inp);
3785 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3786 SCTP_TCB_LOCK(stcb);
3787 shared_keys = &stcb->asoc.shared_keys;
3789 * clear the cached keys for
3792 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3794 * create the new shared key
3795 * and insert/replace it
3798 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3800 SCTP_TCB_UNLOCK(stcb);
3804 shared_key = sctp_alloc_sharedkey();
3805 if (shared_key == NULL) {
3807 SCTP_TCB_UNLOCK(stcb);
3810 shared_key->key = key;
3811 shared_key->keyid = sca->sca_keynumber;
3812 error = sctp_insert_sharedkey(shared_keys, shared_key);
3813 SCTP_TCB_UNLOCK(stcb);
3815 SCTP_INP_RUNLOCK(inp);
3820 case SCTP_HMAC_IDENT:
3822 struct sctp_hmacalgo *shmac;
3823 sctp_hmaclist_t *hmaclist;
3828 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
3829 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
3830 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3834 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
3835 if (hmaclist == NULL) {
3836 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3840 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
3841 hmacid = shmac->shmac_idents[i];
3842 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
3843 /* invalid HMACs were found */ ;
3844 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3846 sctp_free_hmaclist(hmaclist);
3847 goto sctp_set_hmac_done;
3851 for (i = 0; i < hmaclist->num_algo; i++) {
3852 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
3853 /* already in list */
3858 sctp_free_hmaclist(hmaclist);
3859 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3863 /* set it on the endpoint */
3864 SCTP_INP_WLOCK(inp);
3865 if (inp->sctp_ep.local_hmacs)
3866 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
3867 inp->sctp_ep.local_hmacs = hmaclist;
3868 SCTP_INP_WUNLOCK(inp);
3872 case SCTP_AUTH_ACTIVE_KEY:
3874 struct sctp_authkeyid *scact;
3876 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
3877 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
3879 /* set the active key on the right place */
3881 /* set the active key on the assoc */
3882 if (sctp_auth_setactivekey(stcb,
3883 scact->scact_keynumber)) {
3884 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
3885 SCTP_FROM_SCTP_USRREQ,
3889 SCTP_TCB_UNLOCK(stcb);
3891 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3892 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3893 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
3894 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
3895 SCTP_INP_WLOCK(inp);
3896 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
3897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3900 SCTP_INP_WUNLOCK(inp);
3902 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
3903 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
3904 SCTP_INP_RLOCK(inp);
3905 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3906 SCTP_TCB_LOCK(stcb);
3907 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
3908 SCTP_TCB_UNLOCK(stcb);
3910 SCTP_INP_RUNLOCK(inp);
3915 case SCTP_AUTH_DELETE_KEY:
3917 struct sctp_authkeyid *scdel;
3919 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
3920 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
3922 /* delete the key from the right place */
3924 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
3925 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3928 SCTP_TCB_UNLOCK(stcb);
3930 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3931 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3932 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
3933 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
3934 SCTP_INP_WLOCK(inp);
3935 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
3936 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3939 SCTP_INP_WUNLOCK(inp);
3941 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
3942 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
3943 SCTP_INP_RLOCK(inp);
3944 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3945 SCTP_TCB_LOCK(stcb);
3946 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
3947 SCTP_TCB_UNLOCK(stcb);
3949 SCTP_INP_RUNLOCK(inp);
3954 case SCTP_AUTH_DEACTIVATE_KEY:
3956 struct sctp_authkeyid *keyid;
3958 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
3959 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
3961 /* deactivate the key from the right place */
3963 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
3964 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3967 SCTP_TCB_UNLOCK(stcb);
3969 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3970 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3971 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
3972 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
3973 SCTP_INP_WLOCK(inp);
3974 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
3975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3978 SCTP_INP_WUNLOCK(inp);
3980 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
3981 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
3982 SCTP_INP_RLOCK(inp);
3983 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3984 SCTP_TCB_LOCK(stcb);
3985 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
3986 SCTP_TCB_UNLOCK(stcb);
3988 SCTP_INP_RUNLOCK(inp);
3994 case SCTP_RESET_STREAMS:
3996 struct sctp_stream_reset *strrst;
3997 uint8_t send_in = 0, send_tsn = 0, send_out = 0,
3999 uint16_t addstrmcnt = 0;
4002 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_stream_reset, optsize);
4003 SCTP_FIND_STCB(inp, stcb, strrst->strrst_assoc_id);
4006 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4010 if (stcb->asoc.peer_supports_strreset == 0) {
4012 * Peer does not support it, we return
4013 * protocol not supported since this is true
4014 * for this feature and this peer, not the
4015 * socket request in general.
4017 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPROTONOSUPPORT);
4018 error = EPROTONOSUPPORT;
4019 SCTP_TCB_UNLOCK(stcb);
4022 if (stcb->asoc.stream_reset_outstanding) {
4023 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4025 SCTP_TCB_UNLOCK(stcb);
4028 if (strrst->strrst_flags == SCTP_RESET_LOCAL_RECV) {
4030 } else if (strrst->strrst_flags == SCTP_RESET_LOCAL_SEND) {
4032 } else if (strrst->strrst_flags == SCTP_RESET_BOTH) {
4035 } else if (strrst->strrst_flags == SCTP_RESET_TSN) {
4037 } else if (strrst->strrst_flags == SCTP_RESET_ADD_STREAMS) {
4041 /* We can't do that and add streams */
4045 if (stcb->asoc.stream_reset_outstanding) {
4050 /* We allocate here */
4051 addstrmcnt = strrst->strrst_num_streams;
4052 if ((int)(addstrmcnt + stcb->asoc.streamoutcnt) > 0xffff) {
4053 /* You can't have more than 64k */
4057 if ((stcb->asoc.strm_realoutsize - stcb->asoc.streamoutcnt) < addstrmcnt) {
4058 /* Need to allocate more */
4059 struct sctp_stream_out *oldstream;
4060 struct sctp_stream_queue_pending *sp,
4063 oldstream = stcb->asoc.strmout;
4065 SCTP_MALLOC(stcb->asoc.strmout, struct sctp_stream_out *,
4066 ((stcb->asoc.streamoutcnt + addstrmcnt) * sizeof(struct sctp_stream_out)),
4068 if (stcb->asoc.strmout == NULL) {
4069 stcb->asoc.strmout = oldstream;
4074 * Ok now we proceed with copying
4075 * the old out stuff and
4076 * initializing the new stuff.
4078 SCTP_TCB_SEND_LOCK(stcb);
4079 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 0, 1);
4080 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4081 TAILQ_INIT(&stcb->asoc.strmout[i].outqueue);
4082 stcb->asoc.strmout[i].next_sequence_sent = oldstream[i].next_sequence_sent;
4083 stcb->asoc.strmout[i].last_msg_incomplete = oldstream[i].last_msg_incomplete;
4084 stcb->asoc.strmout[i].stream_no = i;
4085 stcb->asoc.ss_functions.sctp_ss_init_stream(&stcb->asoc.strmout[i], &oldstream[i]);
4087 * now anything on those
4090 TAILQ_FOREACH_SAFE(sp, &oldstream[i].outqueue, next, nsp) {
4091 TAILQ_REMOVE(&oldstream[i].outqueue, sp, next);
4092 TAILQ_INSERT_TAIL(&stcb->asoc.strmout[i].outqueue, sp, next);
4095 * Now move assoc pointers
4098 if (stcb->asoc.last_out_stream == &oldstream[i]) {
4099 stcb->asoc.last_out_stream = &stcb->asoc.strmout[i];
4101 if (stcb->asoc.locked_on_sending == &oldstream[i]) {
4102 stcb->asoc.locked_on_sending = &stcb->asoc.strmout[i];
4105 /* now the new streams */
4106 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4107 for (i = stcb->asoc.streamoutcnt; i < (stcb->asoc.streamoutcnt + addstrmcnt); i++) {
4108 stcb->asoc.strmout[i].next_sequence_sent = 0x0;
4109 TAILQ_INIT(&stcb->asoc.strmout[i].outqueue);
4110 stcb->asoc.strmout[i].stream_no = i;
4111 stcb->asoc.strmout[i].last_msg_incomplete = 0;
4112 stcb->asoc.ss_functions.sctp_ss_init_stream(&stcb->asoc.strmout[i], NULL);
4114 stcb->asoc.strm_realoutsize = stcb->asoc.streamoutcnt + addstrmcnt;
4115 SCTP_FREE(oldstream, SCTP_M_STRMO);
4117 SCTP_TCB_SEND_UNLOCK(stcb);
4120 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4122 SCTP_TCB_UNLOCK(stcb);
4125 for (i = 0; i < strrst->strrst_num_streams; i++) {
4128 (strrst->strrst_list[i] > stcb->asoc.streamincnt)) {
4129 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4134 (strrst->strrst_list[i] > stcb->asoc.streamoutcnt)) {
4135 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4143 SCTP_TCB_UNLOCK(stcb);
4146 error = sctp_send_str_reset_req(stcb, strrst->strrst_num_streams,
4147 strrst->strrst_list,
4148 send_out, (stcb->asoc.str_reset_seq_in - 3),
4149 send_in, send_tsn, addstream, addstrmcnt);
4151 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4152 SCTP_TCB_UNLOCK(stcb);
4155 case SCTP_CONNECT_X:
4156 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4157 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4161 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4163 case SCTP_CONNECT_X_DELAYED:
4164 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4165 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4169 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4171 case SCTP_CONNECT_X_COMPLETE:
4173 struct sockaddr *sa;
4174 struct sctp_nets *net;
4176 /* FIXME MT: check correct? */
4177 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4180 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4181 SCTP_INP_RLOCK(inp);
4182 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4184 SCTP_TCB_LOCK(stcb);
4185 net = sctp_findnet(stcb, sa);
4187 SCTP_INP_RUNLOCK(inp);
4190 * We increment here since
4191 * sctp_findassociation_ep_addr() wil do a
4192 * decrement if it finds the stcb as long as
4193 * the locked tcb (last argument) is NOT a
4196 SCTP_INP_INCR_REF(inp);
4197 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4199 SCTP_INP_DECR_REF(inp);
4204 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4208 if (stcb->asoc.delayed_connection == 1) {
4209 stcb->asoc.delayed_connection = 0;
4210 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4211 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4212 stcb->asoc.primary_destination,
4213 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4214 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4217 * already expired or did not use delayed
4220 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4223 SCTP_TCB_UNLOCK(stcb);
4226 case SCTP_MAX_BURST:
4230 SCTP_CHECK_AND_CAST(burst, optval, uint8_t, optsize);
4232 SCTP_INP_WLOCK(inp);
4233 inp->sctp_ep.max_burst = *burst;
4234 SCTP_INP_WUNLOCK(inp);
4239 struct sctp_assoc_value *av;
4242 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4243 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4245 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4246 ovh = SCTP_MED_OVERHEAD;
4248 ovh = SCTP_MED_V4_OVERHEAD;
4251 if (av->assoc_value) {
4252 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4254 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4256 SCTP_TCB_UNLOCK(stcb);
4258 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4259 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4260 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4261 SCTP_INP_WLOCK(inp);
4263 * FIXME MT: I think this is not in
4264 * tune with the API ID
4266 if (av->assoc_value) {
4267 inp->sctp_frag_point = (av->assoc_value + ovh);
4269 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4271 SCTP_INP_WUNLOCK(inp);
4273 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4281 struct sctp_event_subscribe *events;
4283 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4285 SCTP_INP_WLOCK(inp);
4286 if (events->sctp_data_io_event) {
4287 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4289 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4292 if (events->sctp_association_event) {
4293 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4295 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4298 if (events->sctp_address_event) {
4299 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4301 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4304 if (events->sctp_send_failure_event) {
4305 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4307 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4310 if (events->sctp_peer_error_event) {
4311 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4313 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4316 if (events->sctp_shutdown_event) {
4317 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4319 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4322 if (events->sctp_partial_delivery_event) {
4323 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4325 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4328 if (events->sctp_adaptation_layer_event) {
4329 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4331 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4334 if (events->sctp_authentication_event) {
4335 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4337 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4340 if (events->sctp_sender_dry_event) {
4341 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4343 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4346 if (events->sctp_stream_reset_event) {
4347 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4349 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4351 SCTP_INP_WUNLOCK(inp);
4353 SCTP_INP_RLOCK(inp);
4354 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4355 SCTP_TCB_LOCK(stcb);
4356 if (events->sctp_association_event) {
4357 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4359 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4361 if (events->sctp_address_event) {
4362 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4364 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4366 if (events->sctp_send_failure_event) {
4367 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4369 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4371 if (events->sctp_peer_error_event) {
4372 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4374 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4376 if (events->sctp_shutdown_event) {
4377 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4379 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4381 if (events->sctp_partial_delivery_event) {
4382 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4384 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4386 if (events->sctp_adaptation_layer_event) {
4387 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4389 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4391 if (events->sctp_authentication_event) {
4392 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4394 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4396 if (events->sctp_sender_dry_event) {
4397 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4399 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4401 if (events->sctp_stream_reset_event) {
4402 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4404 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4406 SCTP_TCB_UNLOCK(stcb);
4409 * Send up the sender dry event only for 1-to-1
4412 if (events->sctp_sender_dry_event) {
4413 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4414 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4415 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4417 SCTP_TCB_LOCK(stcb);
4418 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4419 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4420 (stcb->asoc.stream_queue_cnt == 0)) {
4421 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4423 SCTP_TCB_UNLOCK(stcb);
4427 SCTP_INP_RUNLOCK(inp);
4430 case SCTP_ADAPTATION_LAYER:
4432 struct sctp_setadaptation *adap_bits;
4434 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
4435 SCTP_INP_WLOCK(inp);
4436 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
4437 SCTP_INP_WUNLOCK(inp);
4441 case SCTP_SET_INITIAL_DBG_SEQ:
4445 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
4446 SCTP_INP_WLOCK(inp);
4447 inp->sctp_ep.initial_sequence_debug = *vvv;
4448 SCTP_INP_WUNLOCK(inp);
4452 case SCTP_DEFAULT_SEND_PARAM:
4454 struct sctp_sndrcvinfo *s_info;
4456 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
4457 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
4460 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4461 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4463 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4466 SCTP_TCB_UNLOCK(stcb);
4468 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4469 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4470 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
4471 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4472 SCTP_INP_WLOCK(inp);
4473 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
4474 SCTP_INP_WUNLOCK(inp);
4476 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
4477 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4478 SCTP_INP_RLOCK(inp);
4479 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4480 SCTP_TCB_LOCK(stcb);
4481 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4482 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4484 SCTP_TCB_UNLOCK(stcb);
4486 SCTP_INP_RUNLOCK(inp);
4491 case SCTP_PEER_ADDR_PARAMS:
4492 /* Applies to the specific association */
4494 struct sctp_paddrparams *paddrp;
4495 struct sctp_nets *net;
4497 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
4498 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
4501 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
4504 * We increment here since
4505 * sctp_findassociation_ep_addr() wil do a
4506 * decrement if it finds the stcb as long as
4507 * the locked tcb (last argument) is NOT a
4510 SCTP_INP_INCR_REF(inp);
4511 stcb = sctp_findassociation_ep_addr(&inp,
4512 (struct sockaddr *)&paddrp->spp_address,
4515 SCTP_INP_DECR_REF(inp);
4518 if (stcb && (net == NULL)) {
4519 struct sockaddr *sa;
4521 sa = (struct sockaddr *)&paddrp->spp_address;
4523 if (sa->sa_family == AF_INET) {
4525 struct sockaddr_in *sin;
4527 sin = (struct sockaddr_in *)sa;
4528 if (sin->sin_addr.s_addr) {
4529 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4530 SCTP_TCB_UNLOCK(stcb);
4537 if (sa->sa_family == AF_INET6) {
4538 struct sockaddr_in6 *sin6;
4540 sin6 = (struct sockaddr_in6 *)sa;
4541 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
4542 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4543 SCTP_TCB_UNLOCK(stcb);
4550 error = EAFNOSUPPORT;
4551 SCTP_TCB_UNLOCK(stcb);
4552 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4557 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
4559 SCTP_TCB_UNLOCK(stcb);
4560 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4563 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
4565 SCTP_TCB_UNLOCK(stcb);
4566 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4570 /************************TCB SPECIFIC SET ******************/
4572 * do we change the timer for HB, we run
4577 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4578 ovh = SCTP_MED_OVERHEAD;
4580 ovh = SCTP_MED_V4_OVERHEAD;
4583 /* network sets ? */
4585 /************************NET SPECIFIC SET ******************/
4586 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4587 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
4588 !(net->dest_state & SCTP_ADDR_NOHB)) {
4589 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4590 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4592 net->dest_state |= SCTP_ADDR_NOHB;
4594 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4595 if (paddrp->spp_hbinterval) {
4596 net->heart_beat_delay = paddrp->spp_hbinterval;
4597 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4598 net->heart_beat_delay = 0;
4600 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4601 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4602 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4603 net->dest_state &= ~SCTP_ADDR_NOHB;
4605 if (paddrp->spp_flags & SPP_HB_DEMAND) {
4607 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4608 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4610 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4611 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4612 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4613 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4615 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4616 net->mtu = paddrp->spp_pathmtu + ovh;
4617 if (net->mtu < stcb->asoc.smallest_mtu) {
4618 sctp_pathmtu_adjustment(inp, stcb, net, net->mtu);
4622 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4623 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4624 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4627 if (paddrp->spp_pathmaxrxt) {
4628 if (net->dest_state & SCTP_ADDR_PF) {
4629 if (net->error_count > paddrp->spp_pathmaxrxt) {
4630 net->dest_state &= ~SCTP_ADDR_PF;
4633 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4634 (net->error_count > net->pf_threshold)) {
4635 net->dest_state |= SCTP_ADDR_PF;
4636 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4637 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4638 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4641 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4642 if (net->error_count > paddrp->spp_pathmaxrxt) {
4643 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4644 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4647 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4648 net->dest_state |= SCTP_ADDR_REACHABLE;
4649 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4652 net->failure_threshold = paddrp->spp_pathmaxrxt;
4655 if (paddrp->spp_flags & SPP_DSCP) {
4656 if (net->ro._l_addr.sin.sin_family == AF_INET) {
4657 net->dscp = paddrp->spp_dscp & 0xfc;
4662 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4663 if (net->ro._l_addr.sin6.sin6_family == AF_INET6) {
4664 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4669 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
4670 if (paddrp->spp_pathmaxrxt) {
4671 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
4672 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4673 if (net->dest_state & SCTP_ADDR_PF) {
4674 if (net->error_count > paddrp->spp_pathmaxrxt) {
4675 net->dest_state &= ~SCTP_ADDR_PF;
4678 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4679 (net->error_count > net->pf_threshold)) {
4680 net->dest_state |= SCTP_ADDR_PF;
4681 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4682 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4683 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4686 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4687 if (net->error_count > paddrp->spp_pathmaxrxt) {
4688 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4689 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4692 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4693 net->dest_state |= SCTP_ADDR_REACHABLE;
4694 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4697 net->failure_threshold = paddrp->spp_pathmaxrxt;
4700 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4701 if (paddrp->spp_hbinterval) {
4702 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
4703 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4704 stcb->asoc.heart_beat_delay = 0;
4706 /* Turn back on the timer */
4707 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4708 if (paddrp->spp_hbinterval) {
4709 net->heart_beat_delay = paddrp->spp_hbinterval;
4710 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4711 net->heart_beat_delay = 0;
4713 if (net->dest_state & SCTP_ADDR_NOHB) {
4714 net->dest_state &= ~SCTP_ADDR_NOHB;
4716 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4717 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4718 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4721 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4722 /* Turn back on the timer */
4723 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4724 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
4725 net->dest_state |= SCTP_ADDR_NOHB;
4726 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
4727 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4732 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4733 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4734 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4735 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4736 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4738 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4739 net->mtu = paddrp->spp_pathmtu + ovh;
4740 if (net->mtu < stcb->asoc.smallest_mtu) {
4741 sctp_pathmtu_adjustment(inp, stcb, net, net->mtu);
4746 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4747 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4748 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4749 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4753 if (paddrp->spp_flags & SPP_DSCP) {
4754 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4755 net->dscp = paddrp->spp_dscp & 0x000000fc;
4757 stcb->asoc.default_dscp = paddrp->spp_dscp & 0x000000fc;
4759 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4760 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4761 net->flowlabel = paddrp->spp_ipv6_flowlabel;
4763 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel;
4766 SCTP_TCB_UNLOCK(stcb);
4768 /************************NO TCB, SET TO default stuff ******************/
4769 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4770 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4771 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
4772 SCTP_INP_WLOCK(inp);
4774 * For the TOS/FLOWLABEL stuff you
4775 * set it with the options on the
4778 if (paddrp->spp_pathmaxrxt) {
4779 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
4781 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
4782 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4783 else if (paddrp->spp_hbinterval) {
4784 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
4785 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
4786 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4788 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4789 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4790 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4791 } else if (paddrp->spp_hbinterval) {
4792 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4794 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4795 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
4796 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4798 SCTP_INP_WUNLOCK(inp);
4800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4808 struct sctp_rtoinfo *srto;
4809 uint32_t new_init, new_min, new_max;
4811 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
4812 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
4815 if (srto->srto_initial)
4816 new_init = srto->srto_initial;
4818 new_init = stcb->asoc.initial_rto;
4820 new_max = srto->srto_max;
4822 new_max = stcb->asoc.maxrto;
4824 new_min = srto->srto_min;
4826 new_min = stcb->asoc.minrto;
4827 if ((new_min <= new_init) && (new_init <= new_max)) {
4828 stcb->asoc.initial_rto = new_init;
4829 stcb->asoc.maxrto = new_max;
4830 stcb->asoc.minrto = new_min;
4832 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4835 SCTP_TCB_UNLOCK(stcb);
4837 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4838 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4839 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
4840 SCTP_INP_WLOCK(inp);
4841 if (srto->srto_initial)
4842 new_init = srto->srto_initial;
4844 new_init = inp->sctp_ep.initial_rto;
4846 new_max = srto->srto_max;
4848 new_max = inp->sctp_ep.sctp_maxrto;
4850 new_min = srto->srto_min;
4852 new_min = inp->sctp_ep.sctp_minrto;
4853 if ((new_min <= new_init) && (new_init <= new_max)) {
4854 inp->sctp_ep.initial_rto = new_init;
4855 inp->sctp_ep.sctp_maxrto = new_max;
4856 inp->sctp_ep.sctp_minrto = new_min;
4858 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4861 SCTP_INP_WUNLOCK(inp);
4863 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4869 case SCTP_ASSOCINFO:
4871 struct sctp_assocparams *sasoc;
4873 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
4874 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
4875 if (sasoc->sasoc_cookie_life) {
4876 /* boundary check the cookie life */
4877 if (sasoc->sasoc_cookie_life < 1000)
4878 sasoc->sasoc_cookie_life = 1000;
4879 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
4880 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
4884 if (sasoc->sasoc_asocmaxrxt)
4885 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
4886 if (sasoc->sasoc_cookie_life) {
4887 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
4889 SCTP_TCB_UNLOCK(stcb);
4891 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4892 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4893 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
4894 SCTP_INP_WLOCK(inp);
4895 if (sasoc->sasoc_asocmaxrxt)
4896 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
4897 if (sasoc->sasoc_cookie_life) {
4898 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
4900 SCTP_INP_WUNLOCK(inp);
4902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4910 struct sctp_initmsg *sinit;
4912 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
4913 SCTP_INP_WLOCK(inp);
4914 if (sinit->sinit_num_ostreams)
4915 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
4917 if (sinit->sinit_max_instreams)
4918 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
4920 if (sinit->sinit_max_attempts)
4921 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
4923 if (sinit->sinit_max_init_timeo)
4924 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
4925 SCTP_INP_WUNLOCK(inp);
4928 case SCTP_PRIMARY_ADDR:
4930 struct sctp_setprim *spa;
4931 struct sctp_nets *net;
4933 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
4934 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
4938 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
4941 * We increment here since
4942 * sctp_findassociation_ep_addr() wil do a
4943 * decrement if it finds the stcb as long as
4944 * the locked tcb (last argument) is NOT a
4947 SCTP_INP_INCR_REF(inp);
4948 stcb = sctp_findassociation_ep_addr(&inp,
4949 (struct sockaddr *)&spa->ssp_addr,
4952 SCTP_INP_DECR_REF(inp);
4956 if ((stcb) && (net)) {
4957 if ((net != stcb->asoc.primary_destination) &&
4958 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
4959 /* Ok we need to set it */
4960 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
4961 if ((stcb->asoc.alternate) &&
4962 (!(net->dest_state & SCTP_ADDR_PF)) &&
4963 (net->dest_state & SCTP_ADDR_REACHABLE)) {
4964 sctp_free_remote_addr(stcb->asoc.alternate);
4965 stcb->asoc.alternate = NULL;
4970 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4974 SCTP_TCB_UNLOCK(stcb);
4978 case SCTP_SET_DYNAMIC_PRIMARY:
4980 union sctp_sockstore *ss;
4982 error = priv_check(curthread,
4983 PRIV_NETINET_RESERVEDPORT);
4987 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
4988 /* SUPER USER CHECK? */
4989 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
4992 case SCTP_SET_PEER_PRIMARY_ADDR:
4994 struct sctp_setpeerprim *sspp;
4996 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
4997 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
4999 struct sctp_ifa *ifa;
5001 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
5002 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5004 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5008 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5010 * Must validate the ifa found is in
5013 struct sctp_laddr *laddr;
5016 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5017 if (laddr->ifa == NULL) {
5018 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5022 if (laddr->ifa == ifa) {
5028 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5033 if (sctp_set_primary_ip_address_sa(stcb,
5034 (struct sockaddr *)&sspp->sspp_addr) != 0) {
5035 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5039 SCTP_TCB_UNLOCK(stcb);
5041 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5046 case SCTP_BINDX_ADD_ADDR:
5048 struct sctp_getaddresses *addrs;
5052 td = (struct thread *)p;
5053 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5056 if (addrs->addr->sa_family == AF_INET) {
5057 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
5059 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5063 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5064 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5070 if (addrs->addr->sa_family == AF_INET6) {
5071 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
5073 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5077 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5078 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5079 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5085 error = EAFNOSUPPORT;
5088 sctp_bindx_add_address(so, inp, addrs->addr,
5089 addrs->sget_assoc_id, vrf_id,
5093 case SCTP_BINDX_REM_ADDR:
5095 struct sctp_getaddresses *addrs;
5099 td = (struct thread *)p;
5101 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5103 if (addrs->addr->sa_family == AF_INET) {
5104 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
5106 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5110 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5111 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5117 if (addrs->addr->sa_family == AF_INET6) {
5118 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
5120 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5125 (error = prison_local_ip6(td->td_ucred,
5126 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5127 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5128 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5134 error = EAFNOSUPPORT;
5137 sctp_bindx_delete_address(so, inp, addrs->addr,
5138 addrs->sget_assoc_id, vrf_id,
5144 struct sctp_event *event;
5145 uint32_t event_type;
5147 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5148 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5149 switch (event->se_type) {
5150 case SCTP_ASSOC_CHANGE:
5151 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5153 case SCTP_PEER_ADDR_CHANGE:
5154 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5156 case SCTP_REMOTE_ERROR:
5157 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5159 case SCTP_SEND_FAILED:
5160 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5162 case SCTP_SHUTDOWN_EVENT:
5163 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5165 case SCTP_ADAPTATION_INDICATION:
5166 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5168 case SCTP_PARTIAL_DELIVERY_EVENT:
5169 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5171 case SCTP_AUTHENTICATION_EVENT:
5172 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5174 case SCTP_STREAM_RESET_EVENT:
5175 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5177 case SCTP_SENDER_DRY_EVENT:
5178 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5180 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5182 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5187 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5191 if (event_type > 0) {
5194 sctp_stcb_feature_on(inp, stcb, event_type);
5195 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5196 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5197 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5198 (stcb->asoc.stream_queue_cnt == 0)) {
5199 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5203 sctp_stcb_feature_off(inp, stcb, event_type);
5205 SCTP_TCB_UNLOCK(stcb);
5208 * We don't want to send up a storm
5209 * of events, so return an error for
5212 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5213 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5214 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5215 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5216 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5217 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5221 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5222 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5223 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5224 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5225 SCTP_INP_WLOCK(inp);
5227 sctp_feature_on(inp, event_type);
5229 sctp_feature_off(inp, event_type);
5231 SCTP_INP_WUNLOCK(inp);
5233 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5234 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5235 SCTP_INP_RLOCK(inp);
5236 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5237 SCTP_TCB_LOCK(stcb);
5239 sctp_stcb_feature_on(inp, stcb, event_type);
5241 sctp_stcb_feature_off(inp, stcb, event_type);
5243 SCTP_TCB_UNLOCK(stcb);
5245 SCTP_INP_RUNLOCK(inp);
5251 case SCTP_RECVRCVINFO:
5255 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5256 SCTP_INP_WLOCK(inp);
5258 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5260 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5262 SCTP_INP_WUNLOCK(inp);
5265 case SCTP_RECVNXTINFO:
5269 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5270 SCTP_INP_WLOCK(inp);
5272 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5274 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5276 SCTP_INP_WUNLOCK(inp);
5279 case SCTP_DEFAULT_SNDINFO:
5281 struct sctp_sndinfo *info;
5284 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5285 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5288 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5289 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5290 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5291 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5292 stcb->asoc.def_send.sinfo_flags |= policy;
5293 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5294 stcb->asoc.def_send.sinfo_context = info->snd_context;
5296 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5299 SCTP_TCB_UNLOCK(stcb);
5301 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5302 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5303 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
5304 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5305 SCTP_INP_WLOCK(inp);
5306 inp->def_send.sinfo_stream = info->snd_sid;
5307 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
5308 inp->def_send.sinfo_flags = info->snd_flags;
5309 inp->def_send.sinfo_flags |= policy;
5310 inp->def_send.sinfo_ppid = info->snd_ppid;
5311 inp->def_send.sinfo_context = info->snd_context;
5312 SCTP_INP_WUNLOCK(inp);
5314 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
5315 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5316 SCTP_INP_RLOCK(inp);
5317 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5318 SCTP_TCB_LOCK(stcb);
5319 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5320 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5321 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5322 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5323 stcb->asoc.def_send.sinfo_flags |= policy;
5324 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5325 stcb->asoc.def_send.sinfo_context = info->snd_context;
5327 SCTP_TCB_UNLOCK(stcb);
5329 SCTP_INP_RUNLOCK(inp);
5334 case SCTP_DEFAULT_PRINFO:
5336 struct sctp_default_prinfo *info;
5338 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
5339 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
5341 if (PR_SCTP_INVALID_POLICY(info->pr_policy)) {
5342 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5347 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5348 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5349 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5350 SCTP_TCB_UNLOCK(stcb);
5352 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5353 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5354 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
5355 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5356 SCTP_INP_WLOCK(inp);
5357 inp->def_send.sinfo_flags &= 0xfff0;
5358 inp->def_send.sinfo_flags |= info->pr_policy;
5359 inp->def_send.sinfo_timetolive = info->pr_value;
5360 SCTP_INP_WUNLOCK(inp);
5362 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
5363 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5364 SCTP_INP_RLOCK(inp);
5365 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5366 SCTP_TCB_LOCK(stcb);
5367 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5368 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5369 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5370 SCTP_TCB_UNLOCK(stcb);
5372 SCTP_INP_RUNLOCK(inp);
5377 case SCTP_PEER_ADDR_THLDS:
5378 /* Applies to the specific association */
5380 struct sctp_paddrthlds *thlds;
5381 struct sctp_nets *net;
5383 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
5384 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
5387 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_assoc_id);
5390 * We increment here since
5391 * sctp_findassociation_ep_addr() wil do a
5392 * decrement if it finds the stcb as long as
5393 * the locked tcb (last argument) is NOT a
5396 SCTP_INP_INCR_REF(inp);
5397 stcb = sctp_findassociation_ep_addr(&inp,
5398 (struct sockaddr *)&thlds->spt_assoc_id,
5401 SCTP_INP_DECR_REF(inp);
5404 if (stcb && (net == NULL)) {
5405 struct sockaddr *sa;
5407 sa = (struct sockaddr *)&thlds->spt_assoc_id;
5409 if (sa->sa_family == AF_INET) {
5411 struct sockaddr_in *sin;
5413 sin = (struct sockaddr_in *)sa;
5414 if (sin->sin_addr.s_addr) {
5415 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5416 SCTP_TCB_UNLOCK(stcb);
5423 if (sa->sa_family == AF_INET6) {
5424 struct sockaddr_in6 *sin6;
5426 sin6 = (struct sockaddr_in6 *)sa;
5427 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5428 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5429 SCTP_TCB_UNLOCK(stcb);
5436 error = EAFNOSUPPORT;
5437 SCTP_TCB_UNLOCK(stcb);
5438 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5444 if (net->dest_state & SCTP_ADDR_PF) {
5445 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5446 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5447 net->dest_state &= ~SCTP_ADDR_PF;
5450 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5451 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5452 net->dest_state |= SCTP_ADDR_PF;
5453 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5454 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5455 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5458 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5459 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5460 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5461 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5464 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5465 net->dest_state |= SCTP_ADDR_REACHABLE;
5466 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5469 net->failure_threshold = thlds->spt_pathmaxrxt;
5470 net->pf_threshold = thlds->spt_pathpfthld;
5472 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5473 if (net->dest_state & SCTP_ADDR_PF) {
5474 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5475 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5476 net->dest_state &= ~SCTP_ADDR_PF;
5479 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5480 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5481 net->dest_state |= SCTP_ADDR_PF;
5482 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5483 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5484 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5487 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5488 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5489 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5490 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5493 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5494 net->dest_state |= SCTP_ADDR_REACHABLE;
5495 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5498 net->failure_threshold = thlds->spt_pathmaxrxt;
5499 net->pf_threshold = thlds->spt_pathpfthld;
5501 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
5502 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
5505 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5506 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5507 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
5508 SCTP_INP_WLOCK(inp);
5509 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
5510 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
5511 SCTP_INP_WUNLOCK(inp);
5513 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5520 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
5521 error = ENOPROTOOPT;
5523 } /* end switch (opt) */
5528 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
5530 void *optval = NULL;
5532 struct sctp_inpcb *inp;
5536 inp = (struct sctp_inpcb *)so->so_pcb;
5538 /* I made the same as TCP since we are not setup? */
5539 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5540 return (ECONNRESET);
5542 if (sopt->sopt_level != IPPROTO_SCTP) {
5543 /* wrong proto level... send back up to IP */
5545 if (INP_CHECK_SOCKAF(so, AF_INET6))
5546 error = ip6_ctloutput(so, sopt);
5548 #if defined(INET) && defined (INET6)
5552 error = ip_ctloutput(so, sopt);
5556 optsize = sopt->sopt_valsize;
5558 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
5559 if (optval == NULL) {
5560 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
5563 error = sooptcopyin(sopt, optval, optsize, optsize);
5565 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5569 p = (void *)sopt->sopt_td;
5570 if (sopt->sopt_dir == SOPT_SET) {
5571 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
5572 } else if (sopt->sopt_dir == SOPT_GET) {
5573 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
5575 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5578 if ((error == 0) && (optval != NULL)) {
5579 error = sooptcopyout(sopt, optval, optsize);
5580 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5581 } else if (optval != NULL) {
5582 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5590 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
5593 int create_lock_on = 0;
5595 struct sctp_inpcb *inp;
5596 struct sctp_tcb *stcb = NULL;
5598 inp = (struct sctp_inpcb *)so->so_pcb;
5600 /* I made the same as TCP since we are not setup? */
5601 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5602 return (ECONNRESET);
5605 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5608 switch (addr->sa_family) {
5612 struct sockaddr_in6 *sin6p;
5614 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
5615 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5618 sin6p = (struct sockaddr_in6 *)addr;
5619 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
5620 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5629 struct sockaddr_in *sinp;
5631 if (addr->sa_len != sizeof(struct sockaddr_in)) {
5632 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5635 sinp = (struct sockaddr_in *)addr;
5636 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
5637 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5644 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
5645 return (EAFNOSUPPORT);
5647 SCTP_INP_INCR_REF(inp);
5648 SCTP_ASOC_CREATE_LOCK(inp);
5652 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
5653 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
5654 /* Should I really unlock ? */
5655 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
5660 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
5661 (addr->sa_family == AF_INET6)) {
5662 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5667 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
5668 SCTP_PCB_FLAGS_UNBOUND) {
5669 /* Bind a ephemeral port */
5670 error = sctp_inpcb_bind(so, NULL, NULL, p);
5675 /* Now do we connect? */
5676 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
5677 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
5678 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5682 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5683 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
5684 /* We are already connected AND the TCP model */
5685 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
5689 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
5690 SCTP_INP_RLOCK(inp);
5691 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5692 SCTP_INP_RUNLOCK(inp);
5695 * We increment here since sctp_findassociation_ep_addr()
5696 * will do a decrement if it finds the stcb as long as the
5697 * locked tcb (last argument) is NOT a TCB.. aka NULL.
5699 SCTP_INP_INCR_REF(inp);
5700 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
5702 SCTP_INP_DECR_REF(inp);
5704 SCTP_TCB_UNLOCK(stcb);
5708 /* Already have or am bring up an association */
5709 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
5713 vrf_id = inp->def_vrf_id;
5714 /* We are GOOD to go */
5715 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
5717 /* Gak! no memory */
5720 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
5721 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
5722 /* Set the connected flag so we can queue data */
5723 SOCKBUF_LOCK(&so->so_rcv);
5724 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
5725 SOCKBUF_UNLOCK(&so->so_rcv);
5726 SOCKBUF_LOCK(&so->so_snd);
5727 so->so_snd.sb_state &= ~SBS_CANTSENDMORE;
5728 SOCKBUF_UNLOCK(&so->so_snd);
5730 so->so_state &= ~SS_ISDISCONNECTING;
5734 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
5735 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
5737 /* initialize authentication parameters for the assoc */
5738 sctp_initialize_auth_params(inp, stcb);
5740 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
5741 SCTP_TCB_UNLOCK(stcb);
5743 if (create_lock_on) {
5744 SCTP_ASOC_CREATE_UNLOCK(inp);
5746 SCTP_INP_DECR_REF(inp);
5753 sctp_listen(struct socket *so, int backlog, struct thread *p)
5756 * Note this module depends on the protocol processing being called
5757 * AFTER any socket level flags and backlog are applied to the
5758 * socket. The traditional way that the socket flags are applied is
5759 * AFTER protocol processing. We have made a change to the
5760 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
5761 * place if the socket API for SCTP is to work properly.
5765 struct sctp_inpcb *inp;
5767 inp = (struct sctp_inpcb *)so->so_pcb;
5769 /* I made the same as TCP since we are not setup? */
5770 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5771 return (ECONNRESET);
5773 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
5774 /* See if we have a listener */
5775 struct sctp_inpcb *tinp;
5776 union sctp_sockstore store, *sp;
5779 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5781 struct sctp_laddr *laddr;
5783 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5784 memcpy(&store, &laddr->ifa->address, sizeof(store));
5785 switch (sp->sa.sa_family) {
5788 sp->sin.sin_port = inp->sctp_lport;
5793 sp->sin6.sin6_port = inp->sctp_lport;
5799 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
5800 if (tinp && (tinp != inp) &&
5801 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
5802 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
5803 (tinp->sctp_socket->so_qlimit)) {
5805 * we have a listener already and
5808 SCTP_INP_DECR_REF(tinp);
5809 return (EADDRINUSE);
5811 SCTP_INP_DECR_REF(tinp);
5815 /* Setup a local addr bound all */
5816 memset(&store, 0, sizeof(store));
5817 switch (sp->sa.sa_family) {
5820 store.sin.sin_port = inp->sctp_lport;
5825 sp->sin6.sin6_port = inp->sctp_lport;
5832 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5833 store.sa.sa_family = AF_INET6;
5834 store.sa.sa_len = sizeof(struct sockaddr_in6);
5838 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
5839 store.sa.sa_family = AF_INET;
5840 store.sa.sa_len = sizeof(struct sockaddr_in);
5843 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
5844 if (tinp && (tinp != inp) &&
5845 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
5846 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
5847 (tinp->sctp_socket->so_qlimit)) {
5849 * we have a listener already and its not
5852 SCTP_INP_DECR_REF(tinp);
5853 return (EADDRINUSE);
5855 SCTP_INP_DECR_REF(inp);
5859 SCTP_INP_RLOCK(inp);
5860 #ifdef SCTP_LOCK_LOGGING
5861 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
5862 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
5866 error = solisten_proto_check(so);
5869 SCTP_INP_RUNLOCK(inp);
5872 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
5873 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5875 * The unlucky case - We are in the tcp pool with this guy.
5876 * - Someone else is in the main inp slot. - We must move
5877 * this guy (the listener) to the main slot - We must then
5878 * move the guy that was listener to the TCP Pool.
5880 if (sctp_swap_inpcb_for_listen(inp)) {
5884 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5885 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
5886 /* We are already connected AND the TCP model */
5888 SCTP_INP_RUNLOCK(inp);
5890 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
5891 return (EADDRINUSE);
5893 SCTP_INP_RUNLOCK(inp);
5894 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
5895 /* We must do a bind. */
5897 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
5898 /* bind error, probably perm */
5903 /* It appears for 7.0 and on, we must always call this. */
5904 solisten_proto(so, backlog);
5905 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
5906 /* remove the ACCEPTCONN flag for one-to-many sockets */
5907 so->so_options &= ~SO_ACCEPTCONN;
5910 /* turning off listen */
5911 so->so_options &= ~SO_ACCEPTCONN;
5917 static int sctp_defered_wakeup_cnt = 0;
5920 sctp_accept(struct socket *so, struct sockaddr **addr)
5922 struct sctp_tcb *stcb;
5923 struct sctp_inpcb *inp;
5924 union sctp_sockstore store;
5930 inp = (struct sctp_inpcb *)so->so_pcb;
5933 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5934 return (ECONNRESET);
5936 SCTP_INP_RLOCK(inp);
5937 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
5938 SCTP_INP_RUNLOCK(inp);
5939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
5940 return (EOPNOTSUPP);
5942 if (so->so_state & SS_ISDISCONNECTED) {
5943 SCTP_INP_RUNLOCK(inp);
5944 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
5945 return (ECONNABORTED);
5947 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5949 SCTP_INP_RUNLOCK(inp);
5950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5951 return (ECONNRESET);
5953 SCTP_TCB_LOCK(stcb);
5954 SCTP_INP_RUNLOCK(inp);
5955 store = stcb->asoc.primary_destination->ro._l_addr;
5956 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
5957 SCTP_TCB_UNLOCK(stcb);
5958 switch (store.sa.sa_family) {
5962 struct sockaddr_in *sin;
5964 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
5967 sin->sin_family = AF_INET;
5968 sin->sin_len = sizeof(*sin);
5969 sin->sin_port = ((struct sockaddr_in *)&store)->sin_port;
5970 sin->sin_addr = ((struct sockaddr_in *)&store)->sin_addr;
5971 *addr = (struct sockaddr *)sin;
5978 struct sockaddr_in6 *sin6;
5980 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
5983 sin6->sin6_family = AF_INET6;
5984 sin6->sin6_len = sizeof(*sin6);
5985 sin6->sin6_port = ((struct sockaddr_in6 *)&store)->sin6_port;
5987 sin6->sin6_addr = ((struct sockaddr_in6 *)&store)->sin6_addr;
5988 if ((error = sa6_recoverscope(sin6)) != 0) {
5989 SCTP_FREE_SONAME(sin6);
5992 *addr = (struct sockaddr *)sin6;
6000 /* Wake any delayed sleep action */
6001 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
6002 SCTP_INP_WLOCK(inp);
6003 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
6004 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
6005 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
6006 SCTP_INP_WUNLOCK(inp);
6007 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
6008 if (sowriteable(inp->sctp_socket)) {
6009 sowwakeup_locked(inp->sctp_socket);
6011 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
6013 SCTP_INP_WLOCK(inp);
6015 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
6016 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
6017 SCTP_INP_WUNLOCK(inp);
6018 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
6019 if (soreadable(inp->sctp_socket)) {
6020 sctp_defered_wakeup_cnt++;
6021 sorwakeup_locked(inp->sctp_socket);
6023 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
6025 SCTP_INP_WLOCK(inp);
6027 SCTP_INP_WUNLOCK(inp);
6029 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
6030 SCTP_TCB_LOCK(stcb);
6031 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
6038 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
6040 struct sockaddr_in *sin;
6042 struct sctp_inpcb *inp;
6043 struct sctp_ifa *sctp_ifa;
6046 * Do the malloc first in case it blocks.
6048 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6051 sin->sin_family = AF_INET;
6052 sin->sin_len = sizeof(*sin);
6053 inp = (struct sctp_inpcb *)so->so_pcb;
6055 SCTP_FREE_SONAME(sin);
6056 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6059 SCTP_INP_RLOCK(inp);
6060 sin->sin_port = inp->sctp_lport;
6061 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
6062 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6063 struct sctp_tcb *stcb;
6064 struct sockaddr_in *sin_a;
6065 struct sctp_nets *net;
6068 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6074 SCTP_TCB_LOCK(stcb);
6075 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6076 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6078 /* this will make coverity happy */
6081 if (sin_a->sin_family == AF_INET) {
6086 if ((!fnd) || (sin_a == NULL)) {
6088 SCTP_TCB_UNLOCK(stcb);
6091 vrf_id = inp->def_vrf_id;
6092 sctp_ifa = sctp_source_address_selection(inp,
6094 (sctp_route_t *) & net->ro,
6097 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
6098 sctp_free_ifa(sctp_ifa);
6100 SCTP_TCB_UNLOCK(stcb);
6102 /* For the bound all case you get back 0 */
6104 sin->sin_addr.s_addr = 0;
6108 /* Take the first IPv4 address in the list */
6109 struct sctp_laddr *laddr;
6112 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6113 if (laddr->ifa->address.sa.sa_family == AF_INET) {
6114 struct sockaddr_in *sin_a;
6116 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
6117 sin->sin_addr = sin_a->sin_addr;
6123 SCTP_FREE_SONAME(sin);
6124 SCTP_INP_RUNLOCK(inp);
6125 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6129 SCTP_INP_RUNLOCK(inp);
6130 (*addr) = (struct sockaddr *)sin;
6135 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
6137 struct sockaddr_in *sin = (struct sockaddr_in *)*addr;
6139 struct sockaddr_in *sin_a;
6140 struct sctp_inpcb *inp;
6141 struct sctp_tcb *stcb;
6142 struct sctp_nets *net;
6144 /* Do the malloc first in case it blocks. */
6145 inp = (struct sctp_inpcb *)so->so_pcb;
6146 if ((inp == NULL) ||
6147 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
6148 /* UDP type and listeners will drop out here */
6149 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
6152 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6155 sin->sin_family = AF_INET;
6156 sin->sin_len = sizeof(*sin);
6158 /* We must recapture incase we blocked */
6159 inp = (struct sctp_inpcb *)so->so_pcb;
6161 SCTP_FREE_SONAME(sin);
6162 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6165 SCTP_INP_RLOCK(inp);
6166 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6168 SCTP_TCB_LOCK(stcb);
6170 SCTP_INP_RUNLOCK(inp);
6172 SCTP_FREE_SONAME(sin);
6173 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6177 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6178 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6179 if (sin_a->sin_family == AF_INET) {
6181 sin->sin_port = stcb->rport;
6182 sin->sin_addr = sin_a->sin_addr;
6186 SCTP_TCB_UNLOCK(stcb);
6188 /* No IPv4 address */
6189 SCTP_FREE_SONAME(sin);
6190 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6193 (*addr) = (struct sockaddr *)sin;
6198 struct pr_usrreqs sctp_usrreqs = {
6199 .pru_abort = sctp_abort,
6200 .pru_accept = sctp_accept,
6201 .pru_attach = sctp_attach,
6202 .pru_bind = sctp_bind,
6203 .pru_connect = sctp_connect,
6204 .pru_control = in_control,
6205 .pru_close = sctp_close,
6206 .pru_detach = sctp_close,
6207 .pru_sopoll = sopoll_generic,
6208 .pru_flush = sctp_flush,
6209 .pru_disconnect = sctp_disconnect,
6210 .pru_listen = sctp_listen,
6211 .pru_peeraddr = sctp_peeraddr,
6212 .pru_send = sctp_sendm,
6213 .pru_shutdown = sctp_shutdown,
6214 .pru_sockaddr = sctp_ingetaddr,
6215 .pru_sosend = sctp_sosend,
6216 .pru_soreceive = sctp_soreceive