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 (av->assoc_id == SCTP_FUTURE_ASSOC) {
1771 SCTP_INP_RLOCK(inp);
1772 av->assoc_value = inp->sctp_cmt_on_off;
1773 SCTP_INP_RUNLOCK(inp);
1775 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1780 *optsize = sizeof(struct sctp_assoc_value);
1784 case SCTP_PLUGGABLE_CC:
1786 struct sctp_assoc_value *av;
1788 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1789 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1791 av->assoc_value = stcb->asoc.congestion_control_module;
1792 SCTP_TCB_UNLOCK(stcb);
1794 if (av->assoc_id == SCTP_FUTURE_ASSOC) {
1795 SCTP_INP_RLOCK(inp);
1796 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1797 SCTP_INP_RUNLOCK(inp);
1799 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1804 *optsize = sizeof(struct sctp_assoc_value);
1808 case SCTP_CC_OPTION:
1810 struct sctp_cc_option *cc_opt;
1812 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1813 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1817 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1820 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1821 *optsize = sizeof(struct sctp_cc_option);
1823 SCTP_TCB_UNLOCK(stcb);
1827 case SCTP_PLUGGABLE_SS:
1829 struct sctp_assoc_value *av;
1831 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1832 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1834 av->assoc_value = stcb->asoc.stream_scheduling_module;
1835 SCTP_TCB_UNLOCK(stcb);
1837 if (av->assoc_id == SCTP_FUTURE_ASSOC) {
1838 SCTP_INP_RLOCK(inp);
1839 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1840 SCTP_INP_RUNLOCK(inp);
1842 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1847 *optsize = sizeof(struct sctp_assoc_value);
1853 struct sctp_stream_value *av;
1855 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1856 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1858 if (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1859 &av->stream_value) < 0) {
1860 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1863 *optsize = sizeof(struct sctp_stream_value);
1865 SCTP_TCB_UNLOCK(stcb);
1868 * Can't get stream value without
1871 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1876 case SCTP_GET_ADDR_LEN:
1878 struct sctp_assoc_value *av;
1880 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1883 if (av->assoc_value == AF_INET) {
1884 av->assoc_value = sizeof(struct sockaddr_in);
1889 if (av->assoc_value == AF_INET6) {
1890 av->assoc_value = sizeof(struct sockaddr_in6);
1895 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1897 *optsize = sizeof(struct sctp_assoc_value);
1901 case SCTP_GET_ASSOC_NUMBER:
1903 uint32_t *value, cnt;
1905 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1907 SCTP_INP_RLOCK(inp);
1908 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1911 SCTP_INP_RUNLOCK(inp);
1913 *optsize = sizeof(uint32_t);
1916 case SCTP_GET_ASSOC_ID_LIST:
1918 struct sctp_assoc_ids *ids;
1919 unsigned int at, limit;
1921 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1923 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1924 SCTP_INP_RLOCK(inp);
1925 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1927 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1934 SCTP_INP_RUNLOCK(inp);
1936 ids->gaids_number_of_ids = at;
1937 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1943 struct sctp_assoc_value *av;
1945 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1946 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1949 av->assoc_value = stcb->asoc.context;
1950 SCTP_TCB_UNLOCK(stcb);
1952 if (av->assoc_id == SCTP_FUTURE_ASSOC) {
1953 SCTP_INP_RLOCK(inp);
1954 av->assoc_value = inp->sctp_context;
1955 SCTP_INP_RUNLOCK(inp);
1957 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1962 *optsize = sizeof(struct sctp_assoc_value);
1968 uint32_t *default_vrfid;
1970 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1971 *default_vrfid = inp->def_vrf_id;
1972 *optsize = sizeof(uint32_t);
1975 case SCTP_GET_ASOC_VRF:
1977 struct sctp_assoc_value *id;
1979 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1980 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1983 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1985 id->assoc_value = stcb->asoc.vrf_id;
1986 *optsize = sizeof(struct sctp_assoc_value);
1990 case SCTP_GET_VRF_IDS:
1992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1996 case SCTP_GET_NONCE_VALUES:
1998 struct sctp_get_nonce_values *gnv;
2000 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2001 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2004 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2005 gnv->gn_local_tag = stcb->asoc.my_vtag;
2006 SCTP_TCB_UNLOCK(stcb);
2007 *optsize = sizeof(struct sctp_get_nonce_values);
2009 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2014 case SCTP_DELAYED_SACK:
2016 struct sctp_sack_info *sack;
2018 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2019 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2021 sack->sack_delay = stcb->asoc.delayed_ack;
2022 sack->sack_freq = stcb->asoc.sack_freq;
2023 SCTP_TCB_UNLOCK(stcb);
2025 if (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) {
2026 SCTP_INP_RLOCK(inp);
2027 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2028 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2029 SCTP_INP_RUNLOCK(inp);
2031 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2036 *optsize = sizeof(struct sctp_sack_info);
2040 case SCTP_GET_SNDBUF_USE:
2042 struct sctp_sockstat *ss;
2044 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2045 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2048 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2049 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2050 stcb->asoc.size_on_all_streams);
2051 SCTP_TCB_UNLOCK(stcb);
2052 *optsize = sizeof(struct sctp_sockstat);
2054 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2059 case SCTP_MAX_BURST:
2063 SCTP_CHECK_AND_CAST(value, optval, uint8_t, *optsize);
2065 SCTP_INP_RLOCK(inp);
2066 if (inp->sctp_ep.max_burst < 256) {
2067 *value = inp->sctp_ep.max_burst;
2071 SCTP_INP_RUNLOCK(inp);
2072 *optsize = sizeof(uint8_t);
2077 struct sctp_assoc_value *av;
2080 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2081 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2084 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2085 SCTP_TCB_UNLOCK(stcb);
2087 if (av->assoc_id == SCTP_FUTURE_ASSOC) {
2088 SCTP_INP_RLOCK(inp);
2089 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2090 ovh = SCTP_MED_OVERHEAD;
2092 ovh = SCTP_MED_V4_OVERHEAD;
2094 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2095 av->assoc_value = 0;
2097 av->assoc_value = inp->sctp_frag_point - ovh;
2098 SCTP_INP_RUNLOCK(inp);
2100 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2105 *optsize = sizeof(struct sctp_assoc_value);
2109 case SCTP_GET_STAT_LOG:
2110 error = sctp_fill_stat_log(optval, optsize);
2114 struct sctp_event_subscribe *events;
2116 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2117 memset(events, 0, sizeof(struct sctp_event_subscribe));
2118 SCTP_INP_RLOCK(inp);
2119 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2120 events->sctp_data_io_event = 1;
2122 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2123 events->sctp_association_event = 1;
2125 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2126 events->sctp_address_event = 1;
2128 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2129 events->sctp_send_failure_event = 1;
2131 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2132 events->sctp_peer_error_event = 1;
2134 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2135 events->sctp_shutdown_event = 1;
2137 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2138 events->sctp_partial_delivery_event = 1;
2140 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2141 events->sctp_adaptation_layer_event = 1;
2143 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2144 events->sctp_authentication_event = 1;
2146 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2147 events->sctp_sender_dry_event = 1;
2149 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2150 events->sctp_stream_reset_event = 1;
2151 SCTP_INP_RUNLOCK(inp);
2152 *optsize = sizeof(struct sctp_event_subscribe);
2155 case SCTP_ADAPTATION_LAYER:
2159 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2161 SCTP_INP_RLOCK(inp);
2162 *value = inp->sctp_ep.adaptation_layer_indicator;
2163 SCTP_INP_RUNLOCK(inp);
2164 *optsize = sizeof(uint32_t);
2167 case SCTP_SET_INITIAL_DBG_SEQ:
2171 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2172 SCTP_INP_RLOCK(inp);
2173 *value = inp->sctp_ep.initial_sequence_debug;
2174 SCTP_INP_RUNLOCK(inp);
2175 *optsize = sizeof(uint32_t);
2178 case SCTP_GET_LOCAL_ADDR_SIZE:
2182 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2183 SCTP_INP_RLOCK(inp);
2184 *value = sctp_count_max_addresses(inp);
2185 SCTP_INP_RUNLOCK(inp);
2186 *optsize = sizeof(uint32_t);
2189 case SCTP_GET_REMOTE_ADDR_SIZE:
2193 struct sctp_nets *net;
2195 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2196 /* FIXME MT: change to sctp_assoc_value? */
2197 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2201 /* Count the sizes */
2202 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2203 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2204 size += sizeof(struct sockaddr_in6);
2206 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2209 size += sizeof(struct sockaddr_in);
2214 size += sizeof(struct sockaddr_in6);
2222 SCTP_TCB_UNLOCK(stcb);
2223 *value = (uint32_t) size;
2224 *optsize = sizeof(uint32_t);
2226 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2231 case SCTP_GET_PEER_ADDRESSES:
2233 * Get the address information, an array is passed in to
2234 * fill up we pack it.
2238 struct sockaddr_storage *sas;
2239 struct sctp_nets *net;
2240 struct sctp_getaddresses *saddr;
2242 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2243 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2246 left = (*optsize) - sizeof(struct sctp_getaddresses);
2247 *optsize = sizeof(struct sctp_getaddresses);
2248 sas = (struct sockaddr_storage *)&saddr->addr[0];
2250 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2251 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2252 cpsz = sizeof(struct sockaddr_in6);
2254 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2257 cpsz = sizeof(struct sockaddr_in);
2262 cpsz = sizeof(struct sockaddr_in6);
2274 /* not enough room. */
2277 #if defined(INET) && defined(INET6)
2278 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2279 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2280 /* Must map the address */
2281 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2282 (struct sockaddr_in6 *)sas);
2285 memcpy(sas, &net->ro._l_addr, cpsz);
2286 #if defined(INET) && defined(INET6)
2289 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2291 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2295 SCTP_TCB_UNLOCK(stcb);
2297 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2302 case SCTP_GET_LOCAL_ADDRESSES:
2304 size_t limit, actual;
2305 struct sockaddr_storage *sas;
2306 struct sctp_getaddresses *saddr;
2308 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2309 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2311 sas = (struct sockaddr_storage *)&saddr->addr[0];
2312 limit = *optsize - sizeof(sctp_assoc_t);
2313 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2315 SCTP_TCB_UNLOCK(stcb);
2317 *optsize = sizeof(struct sockaddr_storage) + actual;
2320 case SCTP_PEER_ADDR_PARAMS:
2322 struct sctp_paddrparams *paddrp;
2323 struct sctp_nets *net;
2325 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2326 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2330 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2333 * We increment here since
2334 * sctp_findassociation_ep_addr() wil do a
2335 * decrement if it finds the stcb as long as
2336 * the locked tcb (last argument) is NOT a
2339 SCTP_INP_INCR_REF(inp);
2340 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2342 SCTP_INP_DECR_REF(inp);
2345 if (stcb && (net == NULL)) {
2346 struct sockaddr *sa;
2348 sa = (struct sockaddr *)&paddrp->spp_address;
2350 if (sa->sa_family == AF_INET) {
2351 struct sockaddr_in *sin;
2353 sin = (struct sockaddr_in *)sa;
2354 if (sin->sin_addr.s_addr) {
2356 SCTP_TCB_UNLOCK(stcb);
2357 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2363 if (sa->sa_family == AF_INET6) {
2364 struct sockaddr_in6 *sin6;
2366 sin6 = (struct sockaddr_in6 *)sa;
2367 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2369 SCTP_TCB_UNLOCK(stcb);
2370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2376 error = EAFNOSUPPORT;
2377 SCTP_TCB_UNLOCK(stcb);
2378 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2383 /* Applies to the specific association */
2384 paddrp->spp_flags = 0;
2388 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2389 ovh = SCTP_MED_OVERHEAD;
2391 ovh = SCTP_MED_V4_OVERHEAD;
2394 paddrp->spp_hbinterval = net->heart_beat_delay;
2395 paddrp->spp_pathmaxrxt = net->failure_threshold;
2396 paddrp->spp_pathmtu = net->mtu - ovh;
2397 /* get flags for HB */
2398 if (net->dest_state & SCTP_ADDR_NOHB)
2399 paddrp->spp_flags |= SPP_HB_DISABLE;
2401 paddrp->spp_flags |= SPP_HB_ENABLE;
2402 /* get flags for PMTU */
2403 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
2404 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2406 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2409 if (net->ro._l_addr.sin.sin_family == AF_INET) {
2410 paddrp->spp_dscp = net->dscp;
2411 paddrp->spp_flags |= SPP_DSCP;
2415 if (net->ro._l_addr.sin6.sin6_family == AF_INET6) {
2416 paddrp->spp_ipv6_flowlabel = net->flowlabel;
2417 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2422 * No destination so return default
2427 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2428 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2430 paddrp->spp_dscp = stcb->asoc.default_dscp & 0x000000fc;
2431 paddrp->spp_flags |= SPP_DSCP;
2434 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel;
2435 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2437 /* default settings should be these */
2438 if (sctp_is_feature_on(stcb->sctp_ep, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2439 paddrp->spp_flags |= SPP_HB_DISABLE;
2441 paddrp->spp_flags |= SPP_HB_ENABLE;
2443 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2444 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2445 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
2450 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2453 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2454 SCTP_TCB_UNLOCK(stcb);
2456 if (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC) {
2457 /* Use endpoint defaults */
2458 SCTP_INP_RLOCK(inp);
2459 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2460 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2461 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2462 /* get inp's default */
2464 paddrp->spp_dscp = inp->ip_inp.inp.inp_ip_tos;
2465 paddrp->spp_flags |= SPP_DSCP;
2468 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2469 paddrp->spp_ipv6_flowlabel = ((struct in6pcb *)inp)->in6p_flowinfo;
2470 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2473 /* can't return this */
2474 paddrp->spp_pathmtu = 0;
2476 /* default behavior, no stcb */
2477 paddrp->spp_flags = SPP_PMTUD_ENABLE;
2479 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2480 paddrp->spp_flags |= SPP_HB_ENABLE;
2482 paddrp->spp_flags |= SPP_HB_DISABLE;
2484 SCTP_INP_RUNLOCK(inp);
2486 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2491 *optsize = sizeof(struct sctp_paddrparams);
2495 case SCTP_GET_PEER_ADDR_INFO:
2497 struct sctp_paddrinfo *paddri;
2498 struct sctp_nets *net;
2500 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2501 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2505 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
2508 * We increment here since
2509 * sctp_findassociation_ep_addr() wil do a
2510 * decrement if it finds the stcb as long as
2511 * the locked tcb (last argument) is NOT a
2514 SCTP_INP_INCR_REF(inp);
2515 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
2517 SCTP_INP_DECR_REF(inp);
2521 if ((stcb) && (net)) {
2522 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2523 /* It's unconfirmed */
2524 paddri->spinfo_state = SCTP_UNCONFIRMED;
2525 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2527 paddri->spinfo_state = SCTP_ACTIVE;
2530 paddri->spinfo_state = SCTP_INACTIVE;
2532 paddri->spinfo_cwnd = net->cwnd;
2533 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2534 paddri->spinfo_rto = net->RTO;
2535 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2536 paddri->spinfo_mtu = net->mtu;
2537 SCTP_TCB_UNLOCK(stcb);
2538 *optsize = sizeof(struct sctp_paddrinfo);
2541 SCTP_TCB_UNLOCK(stcb);
2543 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2548 case SCTP_PCB_STATUS:
2550 struct sctp_pcbinfo *spcb;
2552 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2553 sctp_fill_pcbinfo(spcb);
2554 *optsize = sizeof(struct sctp_pcbinfo);
2559 struct sctp_nets *net;
2560 struct sctp_status *sstat;
2562 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2563 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2566 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2571 * I think passing the state is fine since
2572 * sctp_constants.h will be available to the user
2575 sstat->sstat_state = stcb->asoc.state;
2576 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2577 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2578 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2580 * We can't include chunks that have been passed to
2581 * the socket layer. Only things in queue.
2583 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2584 stcb->asoc.cnt_on_all_streams);
2587 sstat->sstat_instrms = stcb->asoc.streamincnt;
2588 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2589 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2590 memcpy(&sstat->sstat_primary.spinfo_address,
2591 &stcb->asoc.primary_destination->ro._l_addr,
2592 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2593 net = stcb->asoc.primary_destination;
2594 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2596 * Again the user can get info from sctp_constants.h
2597 * for what the state of the network is.
2599 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2600 /* It's unconfirmed */
2601 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2602 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2604 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2607 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2609 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2610 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2611 sstat->sstat_primary.spinfo_rto = net->RTO;
2612 sstat->sstat_primary.spinfo_mtu = net->mtu;
2613 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2614 SCTP_TCB_UNLOCK(stcb);
2615 *optsize = sizeof(struct sctp_status);
2620 struct sctp_rtoinfo *srto;
2622 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2623 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2626 srto->srto_initial = stcb->asoc.initial_rto;
2627 srto->srto_max = stcb->asoc.maxrto;
2628 srto->srto_min = stcb->asoc.minrto;
2629 SCTP_TCB_UNLOCK(stcb);
2631 if (srto->srto_assoc_id == SCTP_FUTURE_ASSOC) {
2632 SCTP_INP_RLOCK(inp);
2633 srto->srto_initial = inp->sctp_ep.initial_rto;
2634 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2635 srto->srto_min = inp->sctp_ep.sctp_minrto;
2636 SCTP_INP_RUNLOCK(inp);
2638 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2643 *optsize = sizeof(struct sctp_rtoinfo);
2649 struct sctp_timeouts *stimo;
2651 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2652 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2655 stimo->stimo_init = stcb->asoc.timoinit;
2656 stimo->stimo_data = stcb->asoc.timodata;
2657 stimo->stimo_sack = stcb->asoc.timosack;
2658 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2659 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2660 stimo->stimo_cookie = stcb->asoc.timocookie;
2661 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2662 SCTP_TCB_UNLOCK(stcb);
2663 *optsize = sizeof(struct sctp_timeouts);
2665 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2670 case SCTP_ASSOCINFO:
2672 struct sctp_assocparams *sasoc;
2674 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2675 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2678 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2679 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2680 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2681 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2682 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2683 SCTP_TCB_UNLOCK(stcb);
2685 if (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC) {
2686 SCTP_INP_RLOCK(inp);
2687 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2688 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2689 sasoc->sasoc_number_peer_destinations = 0;
2690 sasoc->sasoc_peer_rwnd = 0;
2691 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2692 SCTP_INP_RUNLOCK(inp);
2694 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2699 *optsize = sizeof(struct sctp_assocparams);
2703 case SCTP_DEFAULT_SEND_PARAM:
2705 struct sctp_sndrcvinfo *s_info;
2707 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2708 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2711 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2712 SCTP_TCB_UNLOCK(stcb);
2714 if (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) {
2715 SCTP_INP_RLOCK(inp);
2716 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2717 SCTP_INP_RUNLOCK(inp);
2719 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2724 *optsize = sizeof(struct sctp_sndrcvinfo);
2730 struct sctp_initmsg *sinit;
2732 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2733 SCTP_INP_RLOCK(inp);
2734 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2735 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2736 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2737 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2738 SCTP_INP_RUNLOCK(inp);
2739 *optsize = sizeof(struct sctp_initmsg);
2742 case SCTP_PRIMARY_ADDR:
2743 /* we allow a "get" operation on this */
2745 struct sctp_setprim *ssp;
2747 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2748 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2751 /* simply copy out the sockaddr_storage... */
2755 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
2756 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
2758 memcpy(&ssp->ssp_addr,
2759 &stcb->asoc.primary_destination->ro._l_addr,
2761 SCTP_TCB_UNLOCK(stcb);
2762 *optsize = sizeof(struct sctp_setprim);
2764 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2769 case SCTP_HMAC_IDENT:
2771 struct sctp_hmacalgo *shmac;
2772 sctp_hmaclist_t *hmaclist;
2776 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2778 SCTP_INP_RLOCK(inp);
2779 hmaclist = inp->sctp_ep.local_hmacs;
2780 if (hmaclist == NULL) {
2781 /* no HMACs to return */
2782 *optsize = sizeof(*shmac);
2783 SCTP_INP_RUNLOCK(inp);
2786 /* is there room for all of the hmac ids? */
2787 size = sizeof(*shmac) + (hmaclist->num_algo *
2788 sizeof(shmac->shmac_idents[0]));
2789 if ((size_t)(*optsize) < size) {
2790 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2792 SCTP_INP_RUNLOCK(inp);
2795 /* copy in the list */
2796 shmac->shmac_number_of_idents = hmaclist->num_algo;
2797 for (i = 0; i < hmaclist->num_algo; i++) {
2798 shmac->shmac_idents[i] = hmaclist->hmac[i];
2800 SCTP_INP_RUNLOCK(inp);
2804 case SCTP_AUTH_ACTIVE_KEY:
2806 struct sctp_authkeyid *scact;
2808 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2809 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2812 /* get the active key on the assoc */
2813 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2814 SCTP_TCB_UNLOCK(stcb);
2816 if (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) {
2817 /* get the endpoint active key */
2818 SCTP_INP_RLOCK(inp);
2819 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2820 SCTP_INP_RUNLOCK(inp);
2822 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2827 *optsize = sizeof(struct sctp_authkeyid);
2831 case SCTP_LOCAL_AUTH_CHUNKS:
2833 struct sctp_authchunks *sac;
2834 sctp_auth_chklist_t *chklist = NULL;
2837 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2838 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2841 /* get off the assoc */
2842 chklist = stcb->asoc.local_auth_chunks;
2843 /* is there enough space? */
2844 size = sctp_auth_get_chklist_size(chklist);
2845 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2847 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2849 /* copy in the chunks */
2850 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2851 *optsize = sizeof(struct sctp_authchunks) + size;
2853 SCTP_TCB_UNLOCK(stcb);
2855 if (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC) {
2856 /* get off the endpoint */
2857 SCTP_INP_RLOCK(inp);
2858 chklist = inp->sctp_ep.local_auth_chunks;
2859 /* is there enough space? */
2860 size = sctp_auth_get_chklist_size(chklist);
2861 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2863 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2865 /* copy in the chunks */
2866 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2867 *optsize = sizeof(struct sctp_authchunks) + size;
2869 SCTP_INP_RUNLOCK(inp);
2871 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2877 case SCTP_PEER_AUTH_CHUNKS:
2879 struct sctp_authchunks *sac;
2880 sctp_auth_chklist_t *chklist = NULL;
2883 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2884 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2887 /* get off the assoc */
2888 chklist = stcb->asoc.peer_auth_chunks;
2889 /* is there enough space? */
2890 size = sctp_auth_get_chklist_size(chklist);
2891 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2893 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2895 /* copy in the chunks */
2896 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2897 *optsize = sizeof(struct sctp_authchunks) + size;
2899 SCTP_TCB_UNLOCK(stcb);
2901 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2908 struct sctp_event *event;
2909 uint32_t event_type;
2911 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2912 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2914 switch (event->se_type) {
2915 case SCTP_ASSOC_CHANGE:
2916 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2918 case SCTP_PEER_ADDR_CHANGE:
2919 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
2921 case SCTP_REMOTE_ERROR:
2922 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
2924 case SCTP_SEND_FAILED:
2925 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
2927 case SCTP_SHUTDOWN_EVENT:
2928 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
2930 case SCTP_ADAPTATION_INDICATION:
2931 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
2933 case SCTP_PARTIAL_DELIVERY_EVENT:
2934 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
2936 case SCTP_AUTHENTICATION_EVENT:
2937 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
2939 case SCTP_STREAM_RESET_EVENT:
2940 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
2942 case SCTP_SENDER_DRY_EVENT:
2943 event_type = SCTP_PCB_FLAGS_DRYEVNT;
2945 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
2947 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
2952 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2956 if (event_type > 0) {
2958 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
2959 SCTP_TCB_UNLOCK(stcb);
2961 if (event->se_assoc_id == SCTP_FUTURE_ASSOC) {
2962 SCTP_INP_RLOCK(inp);
2963 event->se_on = sctp_is_feature_on(inp, event_type);
2964 SCTP_INP_RUNLOCK(inp);
2966 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2972 *optsize = sizeof(struct sctp_event);
2976 case SCTP_RECVRCVINFO:
2980 if (*optsize < sizeof(int)) {
2981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2984 SCTP_INP_RUNLOCK(inp);
2985 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
2986 SCTP_INP_RUNLOCK(inp);
2989 /* return the option value */
2990 *(int *)optval = onoff;
2991 *optsize = sizeof(int);
2995 case SCTP_RECVNXTINFO:
2999 if (*optsize < sizeof(int)) {
3000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3003 SCTP_INP_RUNLOCK(inp);
3004 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3005 SCTP_INP_RUNLOCK(inp);
3008 /* return the option value */
3009 *(int *)optval = onoff;
3010 *optsize = sizeof(int);
3014 case SCTP_DEFAULT_SNDINFO:
3016 struct sctp_sndinfo *info;
3018 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3019 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3022 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3023 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3024 info->snd_flags &= 0xfff0;
3025 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3026 info->snd_context = stcb->asoc.def_send.sinfo_context;
3027 SCTP_TCB_UNLOCK(stcb);
3029 if (info->snd_assoc_id == SCTP_FUTURE_ASSOC) {
3030 SCTP_INP_RLOCK(inp);
3031 info->snd_sid = inp->def_send.sinfo_stream;
3032 info->snd_flags = inp->def_send.sinfo_flags;
3033 info->snd_flags &= 0xfff0;
3034 info->snd_ppid = inp->def_send.sinfo_ppid;
3035 info->snd_context = inp->def_send.sinfo_context;
3036 SCTP_INP_RUNLOCK(inp);
3038 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3043 *optsize = sizeof(struct sctp_sndinfo);
3047 case SCTP_DEFAULT_PRINFO:
3049 struct sctp_default_prinfo *info;
3051 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3052 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3055 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3056 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3057 SCTP_TCB_UNLOCK(stcb);
3059 if (info->pr_assoc_id == SCTP_FUTURE_ASSOC) {
3060 SCTP_INP_RLOCK(inp);
3061 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3062 info->pr_value = inp->def_send.sinfo_timetolive;
3063 SCTP_INP_RUNLOCK(inp);
3065 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3070 *optsize = sizeof(struct sctp_default_prinfo);
3074 case SCTP_PEER_ADDR_THLDS:
3076 struct sctp_paddrthlds *thlds;
3077 struct sctp_nets *net;
3079 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3080 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3084 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
3087 * We increment here since
3088 * sctp_findassociation_ep_addr() wil do a
3089 * decrement if it finds the stcb as long as
3090 * the locked tcb (last argument) is NOT a
3093 SCTP_INP_INCR_REF(inp);
3094 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL);
3096 SCTP_INP_DECR_REF(inp);
3099 if (stcb && (net == NULL)) {
3100 struct sockaddr *sa;
3102 sa = (struct sockaddr *)&thlds->spt_address;
3104 if (sa->sa_family == AF_INET) {
3105 struct sockaddr_in *sin;
3107 sin = (struct sockaddr_in *)sa;
3108 if (sin->sin_addr.s_addr) {
3110 SCTP_TCB_UNLOCK(stcb);
3111 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3117 if (sa->sa_family == AF_INET6) {
3118 struct sockaddr_in6 *sin6;
3120 sin6 = (struct sockaddr_in6 *)sa;
3121 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3123 SCTP_TCB_UNLOCK(stcb);
3124 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3130 error = EAFNOSUPPORT;
3131 SCTP_TCB_UNLOCK(stcb);
3132 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3138 thlds->spt_pathmaxrxt = net->failure_threshold;
3139 thlds->spt_pathpfthld = net->pf_threshold;
3141 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3142 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3144 thlds->spt_assoc_id = sctp_get_associd(stcb);
3145 SCTP_TCB_UNLOCK(stcb);
3147 if (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC) {
3148 /* Use endpoint defaults */
3149 SCTP_INP_RLOCK(inp);
3150 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3151 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3152 SCTP_INP_RUNLOCK(inp);
3154 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3159 *optsize = sizeof(struct sctp_paddrthlds);
3164 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3165 error = ENOPROTOOPT;
3167 } /* end switch (sopt->sopt_name) */
3175 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3180 struct sctp_tcb *stcb = NULL;
3181 struct sctp_inpcb *inp = NULL;
3184 if (optval == NULL) {
3185 SCTP_PRINTF("optval is NULL\n");
3186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3189 inp = (struct sctp_inpcb *)so->so_pcb;
3191 SCTP_PRINTF("inp is NULL?\n");
3192 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3195 vrf_id = inp->def_vrf_id;
3200 case SCTP_AUTOCLOSE:
3201 case SCTP_AUTO_ASCONF:
3202 case SCTP_EXPLICIT_EOR:
3203 case SCTP_DISABLE_FRAGMENTS:
3204 case SCTP_USE_EXT_RCVINFO:
3205 case SCTP_I_WANT_MAPPED_V4_ADDR:
3206 /* copy in the option value */
3207 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3212 case SCTP_DISABLE_FRAGMENTS:
3213 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3215 case SCTP_AUTO_ASCONF:
3217 * NOTE: we don't really support this flag
3219 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3220 /* only valid for bound all sockets */
3221 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3223 /* forbidden by admin */
3224 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3227 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3229 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3233 case SCTP_EXPLICIT_EOR:
3234 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3236 case SCTP_USE_EXT_RCVINFO:
3237 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3239 case SCTP_I_WANT_MAPPED_V4_ADDR:
3240 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3241 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3243 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3248 set_opt = SCTP_PCB_FLAGS_NODELAY;
3250 case SCTP_AUTOCLOSE:
3251 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3252 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3253 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3256 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3258 * The value is in ticks. Note this does not effect
3259 * old associations, only new ones.
3261 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3264 SCTP_INP_WLOCK(inp);
3266 sctp_feature_on(inp, set_opt);
3268 sctp_feature_off(inp, set_opt);
3270 SCTP_INP_WUNLOCK(inp);
3272 case SCTP_REUSE_PORT:
3274 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3275 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3276 /* Can't set it after we are bound */
3280 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3281 /* Can't do this for a 1-m socket */
3286 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3288 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3291 case SCTP_PARTIAL_DELIVERY_POINT:
3295 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3296 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3297 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3301 inp->partial_delivery_point = *value;
3304 case SCTP_FRAGMENT_INTERLEAVE:
3305 /* not yet until we re-write sctp_recvmsg() */
3309 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3310 if (*level == SCTP_FRAG_LEVEL_2) {
3311 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3312 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3313 } else if (*level == SCTP_FRAG_LEVEL_1) {
3314 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3315 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3316 } else if (*level == SCTP_FRAG_LEVEL_0) {
3317 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3318 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3321 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3326 case SCTP_CMT_ON_OFF:
3327 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3328 struct sctp_assoc_value *av;
3330 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3331 if (av->assoc_value > SCTP_CMT_MAX) {
3332 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3336 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3338 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3339 SCTP_TCB_UNLOCK(stcb);
3341 if ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3342 (av->assoc_id == SCTP_ALL_ASSOC)) {
3343 SCTP_INP_WLOCK(inp);
3344 inp->sctp_cmt_on_off = av->assoc_value;
3345 SCTP_INP_WUNLOCK(inp);
3347 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3348 (av->assoc_id == SCTP_ALL_ASSOC)) {
3349 SCTP_INP_RLOCK(inp);
3350 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3351 SCTP_TCB_LOCK(stcb);
3352 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3353 SCTP_TCB_UNLOCK(stcb);
3354 SCTP_INP_RUNLOCK(inp);
3359 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3360 error = ENOPROTOOPT;
3363 case SCTP_PLUGGABLE_CC:
3365 struct sctp_assoc_value *av;
3366 struct sctp_nets *net;
3368 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3369 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3370 (av->assoc_value != SCTP_CC_HSTCP) &&
3371 (av->assoc_value != SCTP_CC_HTCP) &&
3372 (av->assoc_value != SCTP_CC_RTCC)) {
3373 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3377 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3379 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3380 stcb->asoc.congestion_control_module = av->assoc_value;
3381 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3382 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3383 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3386 SCTP_TCB_UNLOCK(stcb);
3388 if ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3389 (av->assoc_id == SCTP_ALL_ASSOC)) {
3390 SCTP_INP_WLOCK(inp);
3391 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3392 SCTP_INP_WUNLOCK(inp);
3394 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3395 (av->assoc_id == SCTP_ALL_ASSOC)) {
3396 SCTP_INP_RLOCK(inp);
3397 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3398 SCTP_TCB_LOCK(stcb);
3399 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3400 stcb->asoc.congestion_control_module = av->assoc_value;
3401 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3402 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3403 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3406 SCTP_TCB_UNLOCK(stcb);
3408 SCTP_INP_RUNLOCK(inp);
3413 case SCTP_CC_OPTION:
3415 struct sctp_cc_option *cc_opt;
3417 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3418 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3420 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3421 SCTP_INP_RLOCK(inp);
3422 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3423 SCTP_TCB_LOCK(stcb);
3424 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3425 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3427 SCTP_TCB_UNLOCK(stcb);
3429 SCTP_INP_RUNLOCK(inp);
3434 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3437 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3440 SCTP_TCB_UNLOCK(stcb);
3444 case SCTP_PLUGGABLE_SS:
3446 struct sctp_assoc_value *av;
3448 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3449 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3450 (av->assoc_value != SCTP_SS_DEFAULT) &&
3451 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3452 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3453 (av->assoc_value != SCTP_SS_PRIORITY) &&
3454 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3455 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3456 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3460 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3462 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3463 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3464 stcb->asoc.stream_scheduling_module = av->assoc_value;
3465 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3466 SCTP_TCB_UNLOCK(stcb);
3468 if ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3469 (av->assoc_id == SCTP_ALL_ASSOC)) {
3470 SCTP_INP_WLOCK(inp);
3471 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
3472 SCTP_INP_WUNLOCK(inp);
3474 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3475 (av->assoc_id == SCTP_ALL_ASSOC)) {
3476 SCTP_INP_RLOCK(inp);
3477 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3478 SCTP_TCB_LOCK(stcb);
3479 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3480 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3481 stcb->asoc.stream_scheduling_module = av->assoc_value;
3482 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3483 SCTP_TCB_UNLOCK(stcb);
3485 SCTP_INP_RUNLOCK(inp);
3492 struct sctp_stream_value *av;
3494 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
3495 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3497 if (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
3498 av->stream_value) < 0) {
3499 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3502 SCTP_TCB_UNLOCK(stcb);
3504 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
3505 SCTP_INP_RLOCK(inp);
3506 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3507 SCTP_TCB_LOCK(stcb);
3508 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
3510 &stcb->asoc.strmout[av->stream_id],
3512 SCTP_TCB_UNLOCK(stcb);
3514 SCTP_INP_RUNLOCK(inp);
3518 * Can't set stream value without
3521 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3527 case SCTP_CLR_STAT_LOG:
3528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3533 struct sctp_assoc_value *av;
3535 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3536 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3539 stcb->asoc.context = av->assoc_value;
3540 SCTP_TCB_UNLOCK(stcb);
3542 if ((av->assoc_id == SCTP_FUTURE_ASSOC) ||
3543 (av->assoc_id == SCTP_ALL_ASSOC)) {
3544 SCTP_INP_WLOCK(inp);
3545 inp->sctp_context = av->assoc_value;
3546 SCTP_INP_WUNLOCK(inp);
3548 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3549 (av->assoc_id == SCTP_ALL_ASSOC)) {
3550 SCTP_INP_RLOCK(inp);
3551 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3552 SCTP_TCB_LOCK(stcb);
3553 stcb->asoc.context = av->assoc_value;
3554 SCTP_TCB_UNLOCK(stcb);
3556 SCTP_INP_RUNLOCK(inp);
3563 uint32_t *default_vrfid;
3565 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
3566 if (*default_vrfid > SCTP_MAX_VRF_ID) {
3567 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3571 inp->def_vrf_id = *default_vrfid;
3574 case SCTP_DEL_VRF_ID:
3576 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3580 case SCTP_ADD_VRF_ID:
3582 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3586 case SCTP_DELAYED_SACK:
3588 struct sctp_sack_info *sack;
3590 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
3591 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
3592 if (sack->sack_delay) {
3593 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
3594 sack->sack_delay = SCTP_MAX_SACK_DELAY;
3595 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3596 sack->sack_delay = TICKS_TO_MSEC(1);
3600 if (sack->sack_delay) {
3601 stcb->asoc.delayed_ack = sack->sack_delay;
3603 if (sack->sack_freq) {
3604 stcb->asoc.sack_freq = sack->sack_freq;
3606 SCTP_TCB_UNLOCK(stcb);
3608 if ((sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
3609 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3610 SCTP_INP_WLOCK(inp);
3611 if (sack->sack_delay) {
3612 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
3614 if (sack->sack_freq) {
3615 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
3617 SCTP_INP_WUNLOCK(inp);
3619 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
3620 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3621 SCTP_INP_RLOCK(inp);
3622 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3623 SCTP_TCB_LOCK(stcb);
3624 if (sack->sack_delay) {
3625 stcb->asoc.delayed_ack = sack->sack_delay;
3627 if (sack->sack_freq) {
3628 stcb->asoc.sack_freq = sack->sack_freq;
3630 SCTP_TCB_UNLOCK(stcb);
3632 SCTP_INP_RUNLOCK(inp);
3637 case SCTP_AUTH_CHUNK:
3639 struct sctp_authchunk *sauth;
3641 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
3643 SCTP_INP_WLOCK(inp);
3644 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
3645 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3648 SCTP_INP_WUNLOCK(inp);
3653 struct sctp_authkey *sca;
3654 struct sctp_keyhead *shared_keys;
3655 sctp_sharedkey_t *shared_key;
3656 sctp_key_t *key = NULL;
3659 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
3660 if (sca->sca_keylength == 0) {
3661 size = optsize - sizeof(struct sctp_authkey);
3663 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
3664 size = sca->sca_keylength;
3666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3671 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
3674 shared_keys = &stcb->asoc.shared_keys;
3675 /* clear the cached keys for this key id */
3676 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3678 * create the new shared key and
3682 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3684 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3686 SCTP_TCB_UNLOCK(stcb);
3690 shared_key = sctp_alloc_sharedkey();
3691 if (shared_key == NULL) {
3693 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3695 SCTP_TCB_UNLOCK(stcb);
3698 shared_key->key = key;
3699 shared_key->keyid = sca->sca_keynumber;
3700 error = sctp_insert_sharedkey(shared_keys, shared_key);
3701 SCTP_TCB_UNLOCK(stcb);
3703 if ((sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
3704 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3705 SCTP_INP_WLOCK(inp);
3706 shared_keys = &inp->sctp_ep.shared_keys;
3708 * clear the cached keys on all
3709 * assocs for this key id
3711 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3713 * create the new shared key and
3717 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3719 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3721 SCTP_INP_WUNLOCK(inp);
3725 shared_key = sctp_alloc_sharedkey();
3726 if (shared_key == NULL) {
3728 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3730 SCTP_INP_WUNLOCK(inp);
3733 shared_key->key = key;
3734 shared_key->keyid = sca->sca_keynumber;
3735 error = sctp_insert_sharedkey(shared_keys, shared_key);
3736 SCTP_INP_WUNLOCK(inp);
3738 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
3739 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3740 SCTP_INP_RLOCK(inp);
3741 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3742 SCTP_TCB_LOCK(stcb);
3743 shared_keys = &stcb->asoc.shared_keys;
3745 * clear the cached keys for
3748 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3750 * create the new shared key
3751 * and insert/replace it
3754 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3756 SCTP_TCB_UNLOCK(stcb);
3760 shared_key = sctp_alloc_sharedkey();
3761 if (shared_key == NULL) {
3763 SCTP_TCB_UNLOCK(stcb);
3766 shared_key->key = key;
3767 shared_key->keyid = sca->sca_keynumber;
3768 error = sctp_insert_sharedkey(shared_keys, shared_key);
3769 SCTP_TCB_UNLOCK(stcb);
3771 SCTP_INP_RUNLOCK(inp);
3776 case SCTP_HMAC_IDENT:
3778 struct sctp_hmacalgo *shmac;
3779 sctp_hmaclist_t *hmaclist;
3784 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
3785 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
3786 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3790 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
3791 if (hmaclist == NULL) {
3792 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3796 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
3797 hmacid = shmac->shmac_idents[i];
3798 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
3799 /* invalid HMACs were found */ ;
3800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3802 sctp_free_hmaclist(hmaclist);
3803 goto sctp_set_hmac_done;
3807 for (i = 0; i < hmaclist->num_algo; i++) {
3808 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
3809 /* already in list */
3814 sctp_free_hmaclist(hmaclist);
3815 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3819 /* set it on the endpoint */
3820 SCTP_INP_WLOCK(inp);
3821 if (inp->sctp_ep.local_hmacs)
3822 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
3823 inp->sctp_ep.local_hmacs = hmaclist;
3824 SCTP_INP_WUNLOCK(inp);
3828 case SCTP_AUTH_ACTIVE_KEY:
3830 struct sctp_authkeyid *scact;
3832 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
3833 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
3835 /* set the active key on the right place */
3837 /* set the active key on the assoc */
3838 if (sctp_auth_setactivekey(stcb,
3839 scact->scact_keynumber)) {
3840 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
3841 SCTP_FROM_SCTP_USRREQ,
3845 SCTP_TCB_UNLOCK(stcb);
3847 if ((scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
3848 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
3849 SCTP_INP_WLOCK(inp);
3850 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
3851 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3854 SCTP_INP_WUNLOCK(inp);
3856 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
3857 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
3858 SCTP_INP_RLOCK(inp);
3859 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3860 SCTP_TCB_LOCK(stcb);
3861 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
3862 SCTP_TCB_UNLOCK(stcb);
3864 SCTP_INP_RUNLOCK(inp);
3869 case SCTP_AUTH_DELETE_KEY:
3871 struct sctp_authkeyid *scdel;
3873 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
3874 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
3876 /* delete the key from the right place */
3878 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
3879 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3882 SCTP_TCB_UNLOCK(stcb);
3884 if ((scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
3885 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
3886 SCTP_INP_WLOCK(inp);
3887 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
3888 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3891 SCTP_INP_WUNLOCK(inp);
3893 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
3894 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
3895 SCTP_INP_RLOCK(inp);
3896 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3897 SCTP_TCB_LOCK(stcb);
3898 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
3899 SCTP_TCB_UNLOCK(stcb);
3901 SCTP_INP_RUNLOCK(inp);
3906 case SCTP_AUTH_DEACTIVATE_KEY:
3908 struct sctp_authkeyid *keyid;
3910 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
3911 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
3913 /* deactivate the key from the right place */
3915 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
3916 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3919 SCTP_TCB_UNLOCK(stcb);
3921 if ((keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
3922 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
3923 SCTP_INP_WLOCK(inp);
3924 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
3925 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3928 SCTP_INP_WUNLOCK(inp);
3930 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
3931 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
3932 SCTP_INP_RLOCK(inp);
3933 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3934 SCTP_TCB_LOCK(stcb);
3935 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
3936 SCTP_TCB_UNLOCK(stcb);
3938 SCTP_INP_RUNLOCK(inp);
3944 case SCTP_RESET_STREAMS:
3946 struct sctp_stream_reset *strrst;
3947 uint8_t send_in = 0, send_tsn = 0, send_out = 0,
3949 uint16_t addstrmcnt = 0;
3952 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_stream_reset, optsize);
3953 SCTP_FIND_STCB(inp, stcb, strrst->strrst_assoc_id);
3956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3960 if (stcb->asoc.peer_supports_strreset == 0) {
3962 * Peer does not support it, we return
3963 * protocol not supported since this is true
3964 * for this feature and this peer, not the
3965 * socket request in general.
3967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPROTONOSUPPORT);
3968 error = EPROTONOSUPPORT;
3969 SCTP_TCB_UNLOCK(stcb);
3972 if (stcb->asoc.stream_reset_outstanding) {
3973 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
3975 SCTP_TCB_UNLOCK(stcb);
3978 if (strrst->strrst_flags == SCTP_RESET_LOCAL_RECV) {
3980 } else if (strrst->strrst_flags == SCTP_RESET_LOCAL_SEND) {
3982 } else if (strrst->strrst_flags == SCTP_RESET_BOTH) {
3985 } else if (strrst->strrst_flags == SCTP_RESET_TSN) {
3987 } else if (strrst->strrst_flags == SCTP_RESET_ADD_STREAMS) {
3991 /* We can't do that and add streams */
3995 if (stcb->asoc.stream_reset_outstanding) {
4000 /* We allocate here */
4001 addstrmcnt = strrst->strrst_num_streams;
4002 if ((int)(addstrmcnt + stcb->asoc.streamoutcnt) > 0xffff) {
4003 /* You can't have more than 64k */
4007 if ((stcb->asoc.strm_realoutsize - stcb->asoc.streamoutcnt) < addstrmcnt) {
4008 /* Need to allocate more */
4009 struct sctp_stream_out *oldstream;
4010 struct sctp_stream_queue_pending *sp,
4013 oldstream = stcb->asoc.strmout;
4015 SCTP_MALLOC(stcb->asoc.strmout, struct sctp_stream_out *,
4016 ((stcb->asoc.streamoutcnt + addstrmcnt) * sizeof(struct sctp_stream_out)),
4018 if (stcb->asoc.strmout == NULL) {
4019 stcb->asoc.strmout = oldstream;
4024 * Ok now we proceed with copying
4025 * the old out stuff and
4026 * initializing the new stuff.
4028 SCTP_TCB_SEND_LOCK(stcb);
4029 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 0, 1);
4030 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4031 TAILQ_INIT(&stcb->asoc.strmout[i].outqueue);
4032 stcb->asoc.strmout[i].next_sequence_sent = oldstream[i].next_sequence_sent;
4033 stcb->asoc.strmout[i].last_msg_incomplete = oldstream[i].last_msg_incomplete;
4034 stcb->asoc.strmout[i].stream_no = i;
4035 stcb->asoc.ss_functions.sctp_ss_init_stream(&stcb->asoc.strmout[i], &oldstream[i]);
4037 * now anything on those
4040 TAILQ_FOREACH_SAFE(sp, &oldstream[i].outqueue, next, nsp) {
4041 TAILQ_REMOVE(&oldstream[i].outqueue, sp, next);
4042 TAILQ_INSERT_TAIL(&stcb->asoc.strmout[i].outqueue, sp, next);
4045 * Now move assoc pointers
4048 if (stcb->asoc.last_out_stream == &oldstream[i]) {
4049 stcb->asoc.last_out_stream = &stcb->asoc.strmout[i];
4051 if (stcb->asoc.locked_on_sending == &oldstream[i]) {
4052 stcb->asoc.locked_on_sending = &stcb->asoc.strmout[i];
4055 /* now the new streams */
4056 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4057 for (i = stcb->asoc.streamoutcnt; i < (stcb->asoc.streamoutcnt + addstrmcnt); i++) {
4058 stcb->asoc.strmout[i].next_sequence_sent = 0x0;
4059 TAILQ_INIT(&stcb->asoc.strmout[i].outqueue);
4060 stcb->asoc.strmout[i].stream_no = i;
4061 stcb->asoc.strmout[i].last_msg_incomplete = 0;
4062 stcb->asoc.ss_functions.sctp_ss_init_stream(&stcb->asoc.strmout[i], NULL);
4064 stcb->asoc.strm_realoutsize = stcb->asoc.streamoutcnt + addstrmcnt;
4065 SCTP_FREE(oldstream, SCTP_M_STRMO);
4067 SCTP_TCB_SEND_UNLOCK(stcb);
4070 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4072 SCTP_TCB_UNLOCK(stcb);
4075 for (i = 0; i < strrst->strrst_num_streams; i++) {
4078 (strrst->strrst_list[i] > stcb->asoc.streamincnt)) {
4079 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4084 (strrst->strrst_list[i] > stcb->asoc.streamoutcnt)) {
4085 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4093 SCTP_TCB_UNLOCK(stcb);
4096 error = sctp_send_str_reset_req(stcb, strrst->strrst_num_streams,
4097 strrst->strrst_list,
4098 send_out, (stcb->asoc.str_reset_seq_in - 3),
4099 send_in, send_tsn, addstream, addstrmcnt);
4101 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4102 SCTP_TCB_UNLOCK(stcb);
4105 case SCTP_CONNECT_X:
4106 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4107 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4111 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4113 case SCTP_CONNECT_X_DELAYED:
4114 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4115 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4119 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4121 case SCTP_CONNECT_X_COMPLETE:
4123 struct sockaddr *sa;
4124 struct sctp_nets *net;
4126 /* FIXME MT: check correct? */
4127 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4130 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4131 SCTP_INP_RLOCK(inp);
4132 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4134 SCTP_TCB_LOCK(stcb);
4135 net = sctp_findnet(stcb, sa);
4137 SCTP_INP_RUNLOCK(inp);
4140 * We increment here since
4141 * sctp_findassociation_ep_addr() wil do a
4142 * decrement if it finds the stcb as long as
4143 * the locked tcb (last argument) is NOT a
4146 SCTP_INP_INCR_REF(inp);
4147 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4149 SCTP_INP_DECR_REF(inp);
4154 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4158 if (stcb->asoc.delayed_connection == 1) {
4159 stcb->asoc.delayed_connection = 0;
4160 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4161 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4162 stcb->asoc.primary_destination,
4163 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4164 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4167 * already expired or did not use delayed
4170 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4173 SCTP_TCB_UNLOCK(stcb);
4176 case SCTP_MAX_BURST:
4180 SCTP_CHECK_AND_CAST(burst, optval, uint8_t, optsize);
4182 SCTP_INP_WLOCK(inp);
4183 inp->sctp_ep.max_burst = *burst;
4184 SCTP_INP_WUNLOCK(inp);
4189 struct sctp_assoc_value *av;
4192 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4193 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4195 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4196 ovh = SCTP_MED_OVERHEAD;
4198 ovh = SCTP_MED_V4_OVERHEAD;
4201 if (av->assoc_value) {
4202 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4204 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4206 SCTP_TCB_UNLOCK(stcb);
4208 if (av->assoc_id == SCTP_FUTURE_ASSOC) {
4209 SCTP_INP_WLOCK(inp);
4211 * FIXME MT: I think this is not in
4212 * tune with the API ID
4214 if (av->assoc_value) {
4215 inp->sctp_frag_point = (av->assoc_value + ovh);
4217 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4219 SCTP_INP_WUNLOCK(inp);
4221 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4229 struct sctp_event_subscribe *events;
4231 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4233 SCTP_INP_WLOCK(inp);
4234 if (events->sctp_data_io_event) {
4235 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4237 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4240 if (events->sctp_association_event) {
4241 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4243 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4246 if (events->sctp_address_event) {
4247 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4249 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4252 if (events->sctp_send_failure_event) {
4253 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4255 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4258 if (events->sctp_peer_error_event) {
4259 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4261 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4264 if (events->sctp_shutdown_event) {
4265 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4267 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4270 if (events->sctp_partial_delivery_event) {
4271 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4273 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4276 if (events->sctp_adaptation_layer_event) {
4277 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4279 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4282 if (events->sctp_authentication_event) {
4283 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4285 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4288 if (events->sctp_sender_dry_event) {
4289 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4291 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4294 if (events->sctp_stream_reset_event) {
4295 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4297 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4299 SCTP_INP_WUNLOCK(inp);
4301 SCTP_INP_RLOCK(inp);
4302 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4303 SCTP_TCB_LOCK(stcb);
4304 if (events->sctp_association_event) {
4305 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4307 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4309 if (events->sctp_address_event) {
4310 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4312 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4314 if (events->sctp_send_failure_event) {
4315 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4317 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4319 if (events->sctp_peer_error_event) {
4320 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4322 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4324 if (events->sctp_shutdown_event) {
4325 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4327 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4329 if (events->sctp_partial_delivery_event) {
4330 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4332 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4334 if (events->sctp_adaptation_layer_event) {
4335 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4337 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4339 if (events->sctp_authentication_event) {
4340 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4342 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4344 if (events->sctp_sender_dry_event) {
4345 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4347 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4349 if (events->sctp_stream_reset_event) {
4350 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4352 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4354 SCTP_TCB_UNLOCK(stcb);
4357 * Send up the sender dry event only for 1-to-1
4360 if (events->sctp_sender_dry_event) {
4361 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4362 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4363 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4365 SCTP_TCB_LOCK(stcb);
4366 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4367 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4368 (stcb->asoc.stream_queue_cnt == 0)) {
4369 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4371 SCTP_TCB_UNLOCK(stcb);
4375 SCTP_INP_RUNLOCK(inp);
4378 case SCTP_ADAPTATION_LAYER:
4380 struct sctp_setadaptation *adap_bits;
4382 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
4383 SCTP_INP_WLOCK(inp);
4384 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
4385 SCTP_INP_WUNLOCK(inp);
4389 case SCTP_SET_INITIAL_DBG_SEQ:
4393 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
4394 SCTP_INP_WLOCK(inp);
4395 inp->sctp_ep.initial_sequence_debug = *vvv;
4396 SCTP_INP_WUNLOCK(inp);
4400 case SCTP_DEFAULT_SEND_PARAM:
4402 struct sctp_sndrcvinfo *s_info;
4404 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
4405 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
4408 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4409 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4411 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4414 SCTP_TCB_UNLOCK(stcb);
4416 if ((s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
4417 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4418 SCTP_INP_WLOCK(inp);
4419 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
4420 SCTP_INP_WUNLOCK(inp);
4422 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
4423 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4424 SCTP_INP_RLOCK(inp);
4425 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4426 SCTP_TCB_LOCK(stcb);
4427 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4428 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4430 SCTP_TCB_UNLOCK(stcb);
4432 SCTP_INP_RUNLOCK(inp);
4437 case SCTP_PEER_ADDR_PARAMS:
4438 /* Applies to the specific association */
4440 struct sctp_paddrparams *paddrp;
4441 struct sctp_nets *net;
4443 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
4444 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
4447 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
4450 * We increment here since
4451 * sctp_findassociation_ep_addr() wil do a
4452 * decrement if it finds the stcb as long as
4453 * the locked tcb (last argument) is NOT a
4456 SCTP_INP_INCR_REF(inp);
4457 stcb = sctp_findassociation_ep_addr(&inp,
4458 (struct sockaddr *)&paddrp->spp_address,
4461 SCTP_INP_DECR_REF(inp);
4464 if (stcb && (net == NULL)) {
4465 struct sockaddr *sa;
4467 sa = (struct sockaddr *)&paddrp->spp_address;
4469 if (sa->sa_family == AF_INET) {
4471 struct sockaddr_in *sin;
4473 sin = (struct sockaddr_in *)sa;
4474 if (sin->sin_addr.s_addr) {
4475 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4476 SCTP_TCB_UNLOCK(stcb);
4483 if (sa->sa_family == AF_INET6) {
4484 struct sockaddr_in6 *sin6;
4486 sin6 = (struct sockaddr_in6 *)sa;
4487 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
4488 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4489 SCTP_TCB_UNLOCK(stcb);
4496 error = EAFNOSUPPORT;
4497 SCTP_TCB_UNLOCK(stcb);
4498 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4503 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
4505 SCTP_TCB_UNLOCK(stcb);
4506 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4509 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
4511 SCTP_TCB_UNLOCK(stcb);
4512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4516 /************************TCB SPECIFIC SET ******************/
4518 * do we change the timer for HB, we run
4523 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4524 ovh = SCTP_MED_OVERHEAD;
4526 ovh = SCTP_MED_V4_OVERHEAD;
4529 /* network sets ? */
4531 /************************NET SPECIFIC SET ******************/
4532 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4533 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
4534 !(net->dest_state & SCTP_ADDR_NOHB)) {
4535 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4536 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4538 net->dest_state |= SCTP_ADDR_NOHB;
4540 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4541 if (paddrp->spp_hbinterval) {
4542 net->heart_beat_delay = paddrp->spp_hbinterval;
4543 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4544 net->heart_beat_delay = 0;
4546 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4547 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4548 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4549 net->dest_state &= ~SCTP_ADDR_NOHB;
4551 if (paddrp->spp_flags & SPP_HB_DEMAND) {
4553 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4554 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4556 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4557 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4558 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4559 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4561 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4562 net->mtu = paddrp->spp_pathmtu + ovh;
4563 if (net->mtu < stcb->asoc.smallest_mtu) {
4564 sctp_pathmtu_adjustment(inp, stcb, net, net->mtu);
4568 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4569 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4570 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4573 if (paddrp->spp_pathmaxrxt) {
4574 if (net->dest_state & SCTP_ADDR_PF) {
4575 if (net->error_count > paddrp->spp_pathmaxrxt) {
4576 net->dest_state &= ~SCTP_ADDR_PF;
4579 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4580 (net->error_count > net->pf_threshold)) {
4581 net->dest_state |= SCTP_ADDR_PF;
4582 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4583 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4584 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4587 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4588 if (net->error_count > paddrp->spp_pathmaxrxt) {
4589 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4590 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4593 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4594 net->dest_state |= SCTP_ADDR_REACHABLE;
4595 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4598 net->failure_threshold = paddrp->spp_pathmaxrxt;
4601 if (paddrp->spp_flags & SPP_DSCP) {
4602 if (net->ro._l_addr.sin.sin_family == AF_INET) {
4603 net->dscp = paddrp->spp_dscp & 0xfc;
4608 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4609 if (net->ro._l_addr.sin6.sin6_family == AF_INET6) {
4610 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4615 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
4616 if (paddrp->spp_pathmaxrxt) {
4617 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
4618 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4619 if (net->dest_state & SCTP_ADDR_PF) {
4620 if (net->error_count > paddrp->spp_pathmaxrxt) {
4621 net->dest_state &= ~SCTP_ADDR_PF;
4624 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4625 (net->error_count > net->pf_threshold)) {
4626 net->dest_state |= SCTP_ADDR_PF;
4627 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4628 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4629 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4632 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4633 if (net->error_count > paddrp->spp_pathmaxrxt) {
4634 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4635 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4638 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4639 net->dest_state |= SCTP_ADDR_REACHABLE;
4640 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4643 net->failure_threshold = paddrp->spp_pathmaxrxt;
4646 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4647 if (paddrp->spp_hbinterval) {
4648 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
4649 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4650 stcb->asoc.heart_beat_delay = 0;
4652 /* Turn back on the timer */
4653 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4654 if (paddrp->spp_hbinterval) {
4655 net->heart_beat_delay = paddrp->spp_hbinterval;
4656 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4657 net->heart_beat_delay = 0;
4659 if (net->dest_state & SCTP_ADDR_NOHB) {
4660 net->dest_state &= ~SCTP_ADDR_NOHB;
4662 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4663 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4664 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4667 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4668 /* Turn back on the timer */
4669 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4670 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
4671 net->dest_state |= SCTP_ADDR_NOHB;
4672 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
4673 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4678 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4679 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4680 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4681 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4682 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4684 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4685 net->mtu = paddrp->spp_pathmtu + ovh;
4686 if (net->mtu < stcb->asoc.smallest_mtu) {
4687 sctp_pathmtu_adjustment(inp, stcb, net, net->mtu);
4692 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4693 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4694 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4695 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4699 if (paddrp->spp_flags & SPP_DSCP) {
4700 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4701 net->dscp = paddrp->spp_dscp & 0x000000fc;
4703 stcb->asoc.default_dscp = paddrp->spp_dscp & 0x000000fc;
4705 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4706 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4707 net->flowlabel = paddrp->spp_ipv6_flowlabel;
4709 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel;
4712 SCTP_TCB_UNLOCK(stcb);
4714 /************************NO TCB, SET TO default stuff ******************/
4715 if (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC) {
4716 SCTP_INP_WLOCK(inp);
4718 * For the TOS/FLOWLABEL stuff you
4719 * set it with the options on the
4722 if (paddrp->spp_pathmaxrxt) {
4723 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
4725 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
4726 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4727 else if (paddrp->spp_hbinterval) {
4728 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
4729 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
4730 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4732 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4733 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4734 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4735 } else if (paddrp->spp_hbinterval) {
4736 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4738 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4739 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
4740 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4742 SCTP_INP_WUNLOCK(inp);
4744 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4752 struct sctp_rtoinfo *srto;
4753 uint32_t new_init, new_min, new_max;
4755 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
4756 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
4759 if (srto->srto_initial)
4760 new_init = srto->srto_initial;
4762 new_init = stcb->asoc.initial_rto;
4764 new_max = srto->srto_max;
4766 new_max = stcb->asoc.maxrto;
4768 new_min = srto->srto_min;
4770 new_min = stcb->asoc.minrto;
4771 if ((new_min <= new_init) && (new_init <= new_max)) {
4772 stcb->asoc.initial_rto = new_init;
4773 stcb->asoc.maxrto = new_max;
4774 stcb->asoc.minrto = new_min;
4776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4779 SCTP_TCB_UNLOCK(stcb);
4781 if (srto->srto_assoc_id == SCTP_FUTURE_ASSOC) {
4782 SCTP_INP_WLOCK(inp);
4783 if (srto->srto_initial)
4784 new_init = srto->srto_initial;
4786 new_init = inp->sctp_ep.initial_rto;
4788 new_max = srto->srto_max;
4790 new_max = inp->sctp_ep.sctp_maxrto;
4792 new_min = srto->srto_min;
4794 new_min = inp->sctp_ep.sctp_minrto;
4795 if ((new_min <= new_init) && (new_init <= new_max)) {
4796 inp->sctp_ep.initial_rto = new_init;
4797 inp->sctp_ep.sctp_maxrto = new_max;
4798 inp->sctp_ep.sctp_minrto = new_min;
4800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4803 SCTP_INP_WUNLOCK(inp);
4805 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4811 case SCTP_ASSOCINFO:
4813 struct sctp_assocparams *sasoc;
4815 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
4816 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
4817 if (sasoc->sasoc_cookie_life) {
4818 /* boundary check the cookie life */
4819 if (sasoc->sasoc_cookie_life < 1000)
4820 sasoc->sasoc_cookie_life = 1000;
4821 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
4822 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
4826 if (sasoc->sasoc_asocmaxrxt)
4827 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
4828 if (sasoc->sasoc_cookie_life) {
4829 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
4831 SCTP_TCB_UNLOCK(stcb);
4833 if (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC) {
4834 SCTP_INP_WLOCK(inp);
4835 if (sasoc->sasoc_asocmaxrxt)
4836 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
4837 if (sasoc->sasoc_cookie_life) {
4838 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
4840 SCTP_INP_WUNLOCK(inp);
4842 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4850 struct sctp_initmsg *sinit;
4852 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
4853 SCTP_INP_WLOCK(inp);
4854 if (sinit->sinit_num_ostreams)
4855 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
4857 if (sinit->sinit_max_instreams)
4858 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
4860 if (sinit->sinit_max_attempts)
4861 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
4863 if (sinit->sinit_max_init_timeo)
4864 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
4865 SCTP_INP_WUNLOCK(inp);
4868 case SCTP_PRIMARY_ADDR:
4870 struct sctp_setprim *spa;
4871 struct sctp_nets *net;
4873 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
4874 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
4878 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
4881 * We increment here since
4882 * sctp_findassociation_ep_addr() wil do a
4883 * decrement if it finds the stcb as long as
4884 * the locked tcb (last argument) is NOT a
4887 SCTP_INP_INCR_REF(inp);
4888 stcb = sctp_findassociation_ep_addr(&inp,
4889 (struct sockaddr *)&spa->ssp_addr,
4892 SCTP_INP_DECR_REF(inp);
4896 if ((stcb) && (net)) {
4897 if ((net != stcb->asoc.primary_destination) &&
4898 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
4899 /* Ok we need to set it */
4900 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
4901 if ((stcb->asoc.alternate) &&
4902 (!(net->dest_state & SCTP_ADDR_PF)) &&
4903 (net->dest_state & SCTP_ADDR_REACHABLE)) {
4904 sctp_free_remote_addr(stcb->asoc.alternate);
4905 stcb->asoc.alternate = NULL;
4910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4914 SCTP_TCB_UNLOCK(stcb);
4918 case SCTP_SET_DYNAMIC_PRIMARY:
4920 union sctp_sockstore *ss;
4922 error = priv_check(curthread,
4923 PRIV_NETINET_RESERVEDPORT);
4927 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
4928 /* SUPER USER CHECK? */
4929 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
4932 case SCTP_SET_PEER_PRIMARY_ADDR:
4934 struct sctp_setpeerprim *sspp;
4936 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
4937 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
4939 struct sctp_ifa *ifa;
4941 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
4942 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
4944 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4948 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
4950 * Must validate the ifa found is in
4953 struct sctp_laddr *laddr;
4956 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
4957 if (laddr->ifa == NULL) {
4958 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
4962 if (laddr->ifa == ifa) {
4968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4973 if (sctp_set_primary_ip_address_sa(stcb,
4974 (struct sockaddr *)&sspp->sspp_addr) != 0) {
4975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4979 SCTP_TCB_UNLOCK(stcb);
4981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4986 case SCTP_BINDX_ADD_ADDR:
4988 struct sctp_getaddresses *addrs;
4992 td = (struct thread *)p;
4993 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
4996 if (addrs->addr->sa_family == AF_INET) {
4997 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
4999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5003 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5004 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5010 if (addrs->addr->sa_family == AF_INET6) {
5011 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
5013 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5017 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5018 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5019 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5025 error = EAFNOSUPPORT;
5028 sctp_bindx_add_address(so, inp, addrs->addr,
5029 addrs->sget_assoc_id, vrf_id,
5033 case SCTP_BINDX_REM_ADDR:
5035 struct sctp_getaddresses *addrs;
5039 td = (struct thread *)p;
5041 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5043 if (addrs->addr->sa_family == AF_INET) {
5044 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
5046 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5050 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5051 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5057 if (addrs->addr->sa_family == AF_INET6) {
5058 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
5060 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5065 (error = prison_local_ip6(td->td_ucred,
5066 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5067 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5068 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5074 error = EAFNOSUPPORT;
5077 sctp_bindx_delete_address(so, inp, addrs->addr,
5078 addrs->sget_assoc_id, vrf_id,
5084 struct sctp_event *event;
5085 uint32_t event_type;
5087 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5088 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5089 switch (event->se_type) {
5090 case SCTP_ASSOC_CHANGE:
5091 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5093 case SCTP_PEER_ADDR_CHANGE:
5094 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5096 case SCTP_REMOTE_ERROR:
5097 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5099 case SCTP_SEND_FAILED:
5100 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5102 case SCTP_SHUTDOWN_EVENT:
5103 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5105 case SCTP_ADAPTATION_INDICATION:
5106 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5108 case SCTP_PARTIAL_DELIVERY_EVENT:
5109 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5111 case SCTP_AUTHENTICATION_EVENT:
5112 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5114 case SCTP_STREAM_RESET_EVENT:
5115 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5117 case SCTP_SENDER_DRY_EVENT:
5118 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5120 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5122 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5127 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5131 if (event_type > 0) {
5134 sctp_stcb_feature_on(inp, stcb, event_type);
5135 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5136 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5137 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5138 (stcb->asoc.stream_queue_cnt == 0)) {
5139 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5143 sctp_stcb_feature_off(inp, stcb, event_type);
5145 SCTP_TCB_UNLOCK(stcb);
5148 * We don't want to send up a storm
5149 * of events, so return an error for
5152 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5153 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5154 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5155 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5159 if ((event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5160 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5161 SCTP_INP_WLOCK(inp);
5163 sctp_feature_on(inp, event_type);
5165 sctp_feature_off(inp, event_type);
5167 SCTP_INP_WUNLOCK(inp);
5169 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5170 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5171 SCTP_INP_RLOCK(inp);
5172 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5173 SCTP_TCB_LOCK(stcb);
5175 sctp_stcb_feature_on(inp, stcb, event_type);
5177 sctp_stcb_feature_off(inp, stcb, event_type);
5179 SCTP_TCB_UNLOCK(stcb);
5181 SCTP_INP_RUNLOCK(inp);
5187 case SCTP_RECVRCVINFO:
5191 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5192 SCTP_INP_WLOCK(inp);
5194 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5196 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5198 SCTP_INP_WUNLOCK(inp);
5201 case SCTP_RECVNXTINFO:
5205 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5206 SCTP_INP_WLOCK(inp);
5208 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5210 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5212 SCTP_INP_WUNLOCK(inp);
5215 case SCTP_DEFAULT_SNDINFO:
5217 struct sctp_sndinfo *info;
5220 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5221 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5224 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5225 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5226 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5227 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5228 stcb->asoc.def_send.sinfo_flags |= policy;
5229 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5230 stcb->asoc.def_send.sinfo_context = info->snd_context;
5232 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5235 SCTP_TCB_UNLOCK(stcb);
5237 if ((info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
5238 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5239 SCTP_INP_WLOCK(inp);
5240 inp->def_send.sinfo_stream = info->snd_sid;
5241 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
5242 inp->def_send.sinfo_flags = info->snd_flags;
5243 inp->def_send.sinfo_flags |= policy;
5244 inp->def_send.sinfo_ppid = info->snd_ppid;
5245 inp->def_send.sinfo_context = info->snd_context;
5246 SCTP_INP_WUNLOCK(inp);
5248 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
5249 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5250 SCTP_INP_RLOCK(inp);
5251 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5252 SCTP_TCB_LOCK(stcb);
5253 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5254 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5255 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5256 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5257 stcb->asoc.def_send.sinfo_flags |= policy;
5258 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5259 stcb->asoc.def_send.sinfo_context = info->snd_context;
5261 SCTP_TCB_UNLOCK(stcb);
5263 SCTP_INP_RUNLOCK(inp);
5268 case SCTP_DEFAULT_PRINFO:
5270 struct sctp_default_prinfo *info;
5272 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
5273 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
5275 if (PR_SCTP_INVALID_POLICY(info->pr_policy)) {
5276 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5281 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5282 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5283 SCTP_TCB_UNLOCK(stcb);
5285 if ((info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
5286 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5287 SCTP_INP_WLOCK(inp);
5288 inp->def_send.sinfo_flags &= 0xfff0;
5289 inp->def_send.sinfo_flags |= info->pr_policy;
5290 SCTP_INP_WUNLOCK(inp);
5292 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
5293 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5294 SCTP_INP_RLOCK(inp);
5295 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5296 SCTP_TCB_LOCK(stcb);
5297 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5298 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5299 SCTP_TCB_UNLOCK(stcb);
5301 SCTP_INP_RUNLOCK(inp);
5306 case SCTP_PEER_ADDR_THLDS:
5307 /* Applies to the specific association */
5309 struct sctp_paddrthlds *thlds;
5310 struct sctp_nets *net;
5312 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
5313 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
5316 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_assoc_id);
5319 * We increment here since
5320 * sctp_findassociation_ep_addr() wil do a
5321 * decrement if it finds the stcb as long as
5322 * the locked tcb (last argument) is NOT a
5325 SCTP_INP_INCR_REF(inp);
5326 stcb = sctp_findassociation_ep_addr(&inp,
5327 (struct sockaddr *)&thlds->spt_assoc_id,
5330 SCTP_INP_DECR_REF(inp);
5333 if (stcb && (net == NULL)) {
5334 struct sockaddr *sa;
5336 sa = (struct sockaddr *)&thlds->spt_assoc_id;
5338 if (sa->sa_family == AF_INET) {
5340 struct sockaddr_in *sin;
5342 sin = (struct sockaddr_in *)sa;
5343 if (sin->sin_addr.s_addr) {
5344 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5345 SCTP_TCB_UNLOCK(stcb);
5352 if (sa->sa_family == AF_INET6) {
5353 struct sockaddr_in6 *sin6;
5355 sin6 = (struct sockaddr_in6 *)sa;
5356 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5357 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5358 SCTP_TCB_UNLOCK(stcb);
5365 error = EAFNOSUPPORT;
5366 SCTP_TCB_UNLOCK(stcb);
5367 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5373 if (net->dest_state & SCTP_ADDR_PF) {
5374 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5375 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5376 net->dest_state &= ~SCTP_ADDR_PF;
5379 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5380 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5381 net->dest_state |= SCTP_ADDR_PF;
5382 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5383 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5384 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5387 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5388 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5389 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5390 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5393 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5394 net->dest_state |= SCTP_ADDR_REACHABLE;
5395 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5398 net->failure_threshold = thlds->spt_pathmaxrxt;
5399 net->pf_threshold = thlds->spt_pathpfthld;
5401 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5402 if (net->dest_state & SCTP_ADDR_PF) {
5403 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5404 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5405 net->dest_state &= ~SCTP_ADDR_PF;
5408 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5409 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5410 net->dest_state |= SCTP_ADDR_PF;
5411 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5412 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5413 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5416 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5417 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5418 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5419 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5422 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5423 net->dest_state |= SCTP_ADDR_REACHABLE;
5424 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5427 net->failure_threshold = thlds->spt_pathmaxrxt;
5428 net->pf_threshold = thlds->spt_pathpfthld;
5430 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
5431 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
5434 if (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC) {
5435 SCTP_INP_WLOCK(inp);
5436 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
5437 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
5438 SCTP_INP_WUNLOCK(inp);
5440 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5447 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
5448 error = ENOPROTOOPT;
5450 } /* end switch (opt) */
5455 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
5457 void *optval = NULL;
5459 struct sctp_inpcb *inp;
5463 inp = (struct sctp_inpcb *)so->so_pcb;
5465 /* I made the same as TCP since we are not setup? */
5466 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5467 return (ECONNRESET);
5469 if (sopt->sopt_level != IPPROTO_SCTP) {
5470 /* wrong proto level... send back up to IP */
5472 if (INP_CHECK_SOCKAF(so, AF_INET6))
5473 error = ip6_ctloutput(so, sopt);
5475 #if defined(INET) && defined (INET6)
5479 error = ip_ctloutput(so, sopt);
5483 optsize = sopt->sopt_valsize;
5485 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
5486 if (optval == NULL) {
5487 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
5490 error = sooptcopyin(sopt, optval, optsize, optsize);
5492 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5496 p = (void *)sopt->sopt_td;
5497 if (sopt->sopt_dir == SOPT_SET) {
5498 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
5499 } else if (sopt->sopt_dir == SOPT_GET) {
5500 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
5502 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5505 if ((error == 0) && (optval != NULL)) {
5506 error = sooptcopyout(sopt, optval, optsize);
5507 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5508 } else if (optval != NULL) {
5509 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5517 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
5520 int create_lock_on = 0;
5522 struct sctp_inpcb *inp;
5523 struct sctp_tcb *stcb = NULL;
5525 inp = (struct sctp_inpcb *)so->so_pcb;
5527 /* I made the same as TCP since we are not setup? */
5528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5529 return (ECONNRESET);
5532 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5535 switch (addr->sa_family) {
5539 struct sockaddr_in6 *sin6p;
5541 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
5542 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5545 sin6p = (struct sockaddr_in6 *)addr;
5546 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
5547 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5556 struct sockaddr_in *sinp;
5558 if (addr->sa_len != sizeof(struct sockaddr_in)) {
5559 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5562 sinp = (struct sockaddr_in *)addr;
5563 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
5564 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5571 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
5572 return (EAFNOSUPPORT);
5574 SCTP_INP_INCR_REF(inp);
5575 SCTP_ASOC_CREATE_LOCK(inp);
5579 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
5580 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
5581 /* Should I really unlock ? */
5582 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
5587 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
5588 (addr->sa_family == AF_INET6)) {
5589 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5594 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
5595 SCTP_PCB_FLAGS_UNBOUND) {
5596 /* Bind a ephemeral port */
5597 error = sctp_inpcb_bind(so, NULL, NULL, p);
5602 /* Now do we connect? */
5603 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
5604 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
5605 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5609 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5610 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
5611 /* We are already connected AND the TCP model */
5612 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
5616 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
5617 SCTP_INP_RLOCK(inp);
5618 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5619 SCTP_INP_RUNLOCK(inp);
5622 * We increment here since sctp_findassociation_ep_addr()
5623 * will do a decrement if it finds the stcb as long as the
5624 * locked tcb (last argument) is NOT a TCB.. aka NULL.
5626 SCTP_INP_INCR_REF(inp);
5627 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
5629 SCTP_INP_DECR_REF(inp);
5631 SCTP_TCB_UNLOCK(stcb);
5635 /* Already have or am bring up an association */
5636 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
5640 vrf_id = inp->def_vrf_id;
5641 /* We are GOOD to go */
5642 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
5644 /* Gak! no memory */
5647 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
5648 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
5649 /* Set the connected flag so we can queue data */
5650 SOCKBUF_LOCK(&so->so_rcv);
5651 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
5652 SOCKBUF_UNLOCK(&so->so_rcv);
5653 SOCKBUF_LOCK(&so->so_snd);
5654 so->so_snd.sb_state &= ~SBS_CANTSENDMORE;
5655 SOCKBUF_UNLOCK(&so->so_snd);
5657 so->so_state &= ~SS_ISDISCONNECTING;
5661 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
5662 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
5664 /* initialize authentication parameters for the assoc */
5665 sctp_initialize_auth_params(inp, stcb);
5667 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
5668 SCTP_TCB_UNLOCK(stcb);
5670 if (create_lock_on) {
5671 SCTP_ASOC_CREATE_UNLOCK(inp);
5673 SCTP_INP_DECR_REF(inp);
5680 sctp_listen(struct socket *so, int backlog, struct thread *p)
5683 * Note this module depends on the protocol processing being called
5684 * AFTER any socket level flags and backlog are applied to the
5685 * socket. The traditional way that the socket flags are applied is
5686 * AFTER protocol processing. We have made a change to the
5687 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
5688 * place if the socket API for SCTP is to work properly.
5692 struct sctp_inpcb *inp;
5694 inp = (struct sctp_inpcb *)so->so_pcb;
5696 /* I made the same as TCP since we are not setup? */
5697 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5698 return (ECONNRESET);
5700 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
5701 /* See if we have a listener */
5702 struct sctp_inpcb *tinp;
5703 union sctp_sockstore store, *sp;
5706 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5708 struct sctp_laddr *laddr;
5710 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5711 memcpy(&store, &laddr->ifa->address, sizeof(store));
5712 switch (sp->sa.sa_family) {
5715 sp->sin.sin_port = inp->sctp_lport;
5720 sp->sin6.sin6_port = inp->sctp_lport;
5726 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
5727 if (tinp && (tinp != inp) &&
5728 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
5729 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
5730 (tinp->sctp_socket->so_qlimit)) {
5732 * we have a listener already and
5735 SCTP_INP_DECR_REF(tinp);
5736 return (EADDRINUSE);
5738 SCTP_INP_DECR_REF(tinp);
5742 /* Setup a local addr bound all */
5743 memset(&store, 0, sizeof(store));
5744 switch (sp->sa.sa_family) {
5747 store.sin.sin_port = inp->sctp_lport;
5752 sp->sin6.sin6_port = inp->sctp_lport;
5759 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5760 store.sa.sa_family = AF_INET6;
5761 store.sa.sa_len = sizeof(struct sockaddr_in6);
5765 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
5766 store.sa.sa_family = AF_INET;
5767 store.sa.sa_len = sizeof(struct sockaddr_in);
5770 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
5771 if (tinp && (tinp != inp) &&
5772 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
5773 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
5774 (tinp->sctp_socket->so_qlimit)) {
5776 * we have a listener already and its not
5779 SCTP_INP_DECR_REF(tinp);
5780 return (EADDRINUSE);
5782 SCTP_INP_DECR_REF(inp);
5786 SCTP_INP_RLOCK(inp);
5787 #ifdef SCTP_LOCK_LOGGING
5788 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
5789 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
5793 error = solisten_proto_check(so);
5796 SCTP_INP_RUNLOCK(inp);
5799 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
5800 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5802 * The unlucky case - We are in the tcp pool with this guy.
5803 * - Someone else is in the main inp slot. - We must move
5804 * this guy (the listener) to the main slot - We must then
5805 * move the guy that was listener to the TCP Pool.
5807 if (sctp_swap_inpcb_for_listen(inp)) {
5811 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5812 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
5813 /* We are already connected AND the TCP model */
5815 SCTP_INP_RUNLOCK(inp);
5817 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
5818 return (EADDRINUSE);
5820 SCTP_INP_RUNLOCK(inp);
5821 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
5822 /* We must do a bind. */
5824 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
5825 /* bind error, probably perm */
5830 /* It appears for 7.0 and on, we must always call this. */
5831 solisten_proto(so, backlog);
5832 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
5833 /* remove the ACCEPTCONN flag for one-to-many sockets */
5834 so->so_options &= ~SO_ACCEPTCONN;
5837 /* turning off listen */
5838 so->so_options &= ~SO_ACCEPTCONN;
5844 static int sctp_defered_wakeup_cnt = 0;
5847 sctp_accept(struct socket *so, struct sockaddr **addr)
5849 struct sctp_tcb *stcb;
5850 struct sctp_inpcb *inp;
5851 union sctp_sockstore store;
5857 inp = (struct sctp_inpcb *)so->so_pcb;
5860 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5861 return (ECONNRESET);
5863 SCTP_INP_RLOCK(inp);
5864 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
5865 SCTP_INP_RUNLOCK(inp);
5866 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
5867 return (EOPNOTSUPP);
5869 if (so->so_state & SS_ISDISCONNECTED) {
5870 SCTP_INP_RUNLOCK(inp);
5871 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
5872 return (ECONNABORTED);
5874 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5876 SCTP_INP_RUNLOCK(inp);
5877 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5878 return (ECONNRESET);
5880 SCTP_TCB_LOCK(stcb);
5881 SCTP_INP_RUNLOCK(inp);
5882 store = stcb->asoc.primary_destination->ro._l_addr;
5883 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
5884 SCTP_TCB_UNLOCK(stcb);
5885 switch (store.sa.sa_family) {
5889 struct sockaddr_in *sin;
5891 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
5894 sin->sin_family = AF_INET;
5895 sin->sin_len = sizeof(*sin);
5896 sin->sin_port = ((struct sockaddr_in *)&store)->sin_port;
5897 sin->sin_addr = ((struct sockaddr_in *)&store)->sin_addr;
5898 *addr = (struct sockaddr *)sin;
5905 struct sockaddr_in6 *sin6;
5907 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
5910 sin6->sin6_family = AF_INET6;
5911 sin6->sin6_len = sizeof(*sin6);
5912 sin6->sin6_port = ((struct sockaddr_in6 *)&store)->sin6_port;
5914 sin6->sin6_addr = ((struct sockaddr_in6 *)&store)->sin6_addr;
5915 if ((error = sa6_recoverscope(sin6)) != 0) {
5916 SCTP_FREE_SONAME(sin6);
5919 *addr = (struct sockaddr *)sin6;
5927 /* Wake any delayed sleep action */
5928 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
5929 SCTP_INP_WLOCK(inp);
5930 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
5931 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
5932 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
5933 SCTP_INP_WUNLOCK(inp);
5934 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
5935 if (sowriteable(inp->sctp_socket)) {
5936 sowwakeup_locked(inp->sctp_socket);
5938 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
5940 SCTP_INP_WLOCK(inp);
5942 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
5943 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
5944 SCTP_INP_WUNLOCK(inp);
5945 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
5946 if (soreadable(inp->sctp_socket)) {
5947 sctp_defered_wakeup_cnt++;
5948 sorwakeup_locked(inp->sctp_socket);
5950 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
5952 SCTP_INP_WLOCK(inp);
5954 SCTP_INP_WUNLOCK(inp);
5956 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
5957 SCTP_TCB_LOCK(stcb);
5958 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
5965 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
5967 struct sockaddr_in *sin;
5969 struct sctp_inpcb *inp;
5970 struct sctp_ifa *sctp_ifa;
5973 * Do the malloc first in case it blocks.
5975 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
5978 sin->sin_family = AF_INET;
5979 sin->sin_len = sizeof(*sin);
5980 inp = (struct sctp_inpcb *)so->so_pcb;
5982 SCTP_FREE_SONAME(sin);
5983 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5986 SCTP_INP_RLOCK(inp);
5987 sin->sin_port = inp->sctp_lport;
5988 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
5989 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
5990 struct sctp_tcb *stcb;
5991 struct sockaddr_in *sin_a;
5992 struct sctp_nets *net;
5995 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6001 SCTP_TCB_LOCK(stcb);
6002 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6003 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6005 /* this will make coverity happy */
6008 if (sin_a->sin_family == AF_INET) {
6013 if ((!fnd) || (sin_a == NULL)) {
6015 SCTP_TCB_UNLOCK(stcb);
6018 vrf_id = inp->def_vrf_id;
6019 sctp_ifa = sctp_source_address_selection(inp,
6021 (sctp_route_t *) & net->ro,
6024 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
6025 sctp_free_ifa(sctp_ifa);
6027 SCTP_TCB_UNLOCK(stcb);
6029 /* For the bound all case you get back 0 */
6031 sin->sin_addr.s_addr = 0;
6035 /* Take the first IPv4 address in the list */
6036 struct sctp_laddr *laddr;
6039 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6040 if (laddr->ifa->address.sa.sa_family == AF_INET) {
6041 struct sockaddr_in *sin_a;
6043 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
6044 sin->sin_addr = sin_a->sin_addr;
6050 SCTP_FREE_SONAME(sin);
6051 SCTP_INP_RUNLOCK(inp);
6052 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6056 SCTP_INP_RUNLOCK(inp);
6057 (*addr) = (struct sockaddr *)sin;
6062 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
6064 struct sockaddr_in *sin = (struct sockaddr_in *)*addr;
6066 struct sockaddr_in *sin_a;
6067 struct sctp_inpcb *inp;
6068 struct sctp_tcb *stcb;
6069 struct sctp_nets *net;
6071 /* Do the malloc first in case it blocks. */
6072 inp = (struct sctp_inpcb *)so->so_pcb;
6073 if ((inp == NULL) ||
6074 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
6075 /* UDP type and listeners will drop out here */
6076 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
6079 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6082 sin->sin_family = AF_INET;
6083 sin->sin_len = sizeof(*sin);
6085 /* We must recapture incase we blocked */
6086 inp = (struct sctp_inpcb *)so->so_pcb;
6088 SCTP_FREE_SONAME(sin);
6089 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6092 SCTP_INP_RLOCK(inp);
6093 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6095 SCTP_TCB_LOCK(stcb);
6097 SCTP_INP_RUNLOCK(inp);
6099 SCTP_FREE_SONAME(sin);
6100 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6104 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6105 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6106 if (sin_a->sin_family == AF_INET) {
6108 sin->sin_port = stcb->rport;
6109 sin->sin_addr = sin_a->sin_addr;
6113 SCTP_TCB_UNLOCK(stcb);
6115 /* No IPv4 address */
6116 SCTP_FREE_SONAME(sin);
6117 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6120 (*addr) = (struct sockaddr *)sin;
6125 struct pr_usrreqs sctp_usrreqs = {
6126 .pru_abort = sctp_abort,
6127 .pru_accept = sctp_accept,
6128 .pru_attach = sctp_attach,
6129 .pru_bind = sctp_bind,
6130 .pru_connect = sctp_connect,
6131 .pru_control = in_control,
6132 .pru_close = sctp_close,
6133 .pru_detach = sctp_close,
6134 .pru_sopoll = sopoll_generic,
6135 .pru_flush = sctp_flush,
6136 .pru_disconnect = sctp_disconnect,
6137 .pru_listen = sctp_listen,
6138 .pru_peeraddr = sctp_peeraddr,
6139 .pru_send = sctp_sendm,
6140 .pru_shutdown = sctp_shutdown,
6141 .pru_sockaddr = sctp_ingetaddr,
6142 .pru_sosend = sctp_sosend,
6143 .pru_soreceive = sctp_soreceive