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);
82 SCTP_BASE_VAR(first_time) = 0;
83 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
85 #if defined(SCTP_PACKET_LOGGING)
86 SCTP_BASE_VAR(packet_log_writers) = 0;
87 SCTP_BASE_VAR(packet_log_end) = 0;
88 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
101 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
103 struct sctp_tmit_chunk *chk;
106 /* Adjust that too */
107 stcb->asoc.smallest_mtu = nxtsz;
108 /* now off to subtract IP_DF flag if needed */
109 overhead = IP_HDR_SIZE;
110 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
111 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
113 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
114 if ((chk->send_size + overhead) > nxtsz) {
115 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
118 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
119 if ((chk->send_size + overhead) > nxtsz) {
121 * For this guy we also mark for immediate resend
122 * since we sent to big of chunk
124 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
125 if (chk->sent < SCTP_DATAGRAM_RESEND) {
126 sctp_flight_size_decrease(chk);
127 sctp_total_flight_decrease(stcb, chk);
129 if (chk->sent != SCTP_DATAGRAM_RESEND) {
130 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
132 chk->sent = SCTP_DATAGRAM_RESEND;
133 chk->rec.data.doing_fast_retransmit = 0;
134 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
135 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
136 chk->whoTo->flight_size,
138 (uintptr_t) chk->whoTo,
139 chk->rec.data.TSN_seq);
141 /* Clear any time so NO RTT is being done */
149 sctp_notify_mbuf(struct sctp_inpcb *inp,
150 struct sctp_tcb *stcb,
151 struct sctp_nets *net,
156 int totsz, tmr_stopped = 0;
160 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
161 (ip == NULL) || (sh == NULL)) {
163 SCTP_TCB_UNLOCK(stcb);
167 /* First job is to verify the vtag matches what I would send */
168 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
169 SCTP_TCB_UNLOCK(stcb);
172 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
174 if (icmph->icmp_type != ICMP_UNREACH) {
175 /* We only care about unreachable */
176 SCTP_TCB_UNLOCK(stcb);
179 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
180 /* not a unreachable message due to frag. */
181 SCTP_TCB_UNLOCK(stcb);
186 nxtsz = ntohs(icmph->icmp_nextmtu);
189 * old type router that does not tell us what the next size
190 * mtu is. Rats we will have to guess (in a educated fashion
193 nxtsz = sctp_get_prev_mtu(totsz);
195 /* Stop any PMTU timer */
196 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
198 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
199 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
201 /* Adjust destination size limit */
202 if (net->mtu > nxtsz) {
205 net->mtu -= sizeof(struct udphdr);
208 /* now what about the ep? */
209 if (stcb->asoc.smallest_mtu > nxtsz) {
210 sctp_pathmtu_adjustment(stcb, nxtsz);
213 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
215 SCTP_TCB_UNLOCK(stcb);
221 sctp_notify(struct sctp_inpcb *inp,
225 struct sctp_tcb *stcb,
226 struct sctp_nets *net)
228 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
235 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
236 (sh == NULL) || (to == NULL)) {
238 SCTP_TCB_UNLOCK(stcb);
241 /* First job is to verify the vtag matches what I would send */
242 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
243 SCTP_TCB_UNLOCK(stcb);
246 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
248 if (icmph->icmp_type != ICMP_UNREACH) {
249 /* We only care about unreachable */
250 SCTP_TCB_UNLOCK(stcb);
253 if ((icmph->icmp_code == ICMP_UNREACH_NET) ||
254 (icmph->icmp_code == ICMP_UNREACH_HOST) ||
255 (icmph->icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
256 (icmph->icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
257 (icmph->icmp_code == ICMP_UNREACH_ISOLATED) ||
258 (icmph->icmp_code == ICMP_UNREACH_NET_PROHIB) ||
259 (icmph->icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
260 (icmph->icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
263 * Hmm reachablity problems we must examine closely. If its
264 * not reachable, we may have lost a network. Or if there is
265 * NO protocol at the other end named SCTP. well we consider
268 if (net->dest_state & SCTP_ADDR_REACHABLE) {
269 /* Ok that destination is NOT reachable */
270 net->dest_state &= ~SCTP_ADDR_REACHABLE;
271 net->dest_state &= ~SCTP_ADDR_PF;
272 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
273 stcb, SCTP_FAILED_THRESHOLD,
274 (void *)net, SCTP_SO_NOT_LOCKED);
276 SCTP_TCB_UNLOCK(stcb);
277 } else if ((icmph->icmp_code == ICMP_UNREACH_PROTOCOL) ||
278 (icmph->icmp_code == ICMP_UNREACH_PORT)) {
280 * Here the peer is either playing tricks on us, including
281 * an address that belongs to someone who does not support
282 * SCTP OR was a userland implementation that shutdown and
283 * now is dead. In either case treat it like a OOTB abort
286 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
287 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
288 so = SCTP_INP_SO(inp);
289 atomic_add_int(&stcb->asoc.refcnt, 1);
290 SCTP_TCB_UNLOCK(stcb);
291 SCTP_SOCKET_LOCK(so, 1);
293 atomic_subtract_int(&stcb->asoc.refcnt, 1);
295 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
296 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
297 SCTP_SOCKET_UNLOCK(so, 1);
298 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
300 /* no need to unlock here, since the TCB is gone */
302 SCTP_TCB_UNLOCK(stcb);
308 sctp_ctlinput(cmd, sa, vip)
317 /* FIX, for non-bsd is this right? */
318 vrf_id = SCTP_DEFAULT_VRFID;
319 if (sa->sa_family != AF_INET ||
320 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
323 if (PRC_IS_REDIRECT(cmd)) {
325 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
329 struct sctp_inpcb *inp = NULL;
330 struct sctp_tcb *stcb = NULL;
331 struct sctp_nets *net = NULL;
332 struct sockaddr_in to, from;
334 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
335 bzero(&to, sizeof(to));
336 bzero(&from, sizeof(from));
337 from.sin_family = to.sin_family = AF_INET;
338 from.sin_len = to.sin_len = sizeof(to);
339 from.sin_port = sh->src_port;
340 from.sin_addr = ip->ip_src;
341 to.sin_port = sh->dest_port;
342 to.sin_addr = ip->ip_dst;
345 * 'to' holds the dest of the packet that failed to be sent.
346 * 'from' holds our local endpoint address. Thus we reverse
347 * the to and the from in the lookup.
349 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&from,
350 (struct sockaddr *)&to,
351 &inp, &net, 1, vrf_id);
352 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
353 if (cmd != PRC_MSGSIZE) {
354 sctp_notify(inp, ip, sh,
355 (struct sockaddr *)&to, stcb,
358 /* handle possible ICMP size messages */
359 sctp_notify_mbuf(inp, stcb, net, ip, sh);
362 if ((stcb == NULL) && (inp != NULL)) {
363 /* reduce ref-count */
365 SCTP_INP_DECR_REF(inp);
366 SCTP_INP_WUNLOCK(inp);
369 SCTP_TCB_UNLOCK(stcb);
379 sctp_getcred(SYSCTL_HANDLER_ARGS)
382 struct sockaddr_in addrs[2];
383 struct sctp_inpcb *inp;
384 struct sctp_nets *net;
385 struct sctp_tcb *stcb;
389 /* FIX, for non-bsd is this right? */
390 vrf_id = SCTP_DEFAULT_VRFID;
392 error = priv_check(req->td, PRIV_NETINET_GETCRED);
397 error = SYSCTL_IN(req, addrs, sizeof(addrs));
401 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[0]),
403 &inp, &net, 1, vrf_id);
404 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
405 if ((inp != NULL) && (stcb == NULL)) {
406 /* reduce ref-count */
408 SCTP_INP_DECR_REF(inp);
411 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
415 SCTP_TCB_UNLOCK(stcb);
417 * We use the write lock here, only since in the error leg we need
418 * it. If we used RLOCK, then we would have to
419 * wlock/decr/unlock/rlock. Which in theory could create a hole.
420 * Better to use higher wlock.
424 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
426 SCTP_INP_WUNLOCK(inp);
429 cru2x(inp->sctp_socket->so_cred, &xuc);
430 SCTP_INP_WUNLOCK(inp);
431 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
436 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
437 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
442 sctp_abort(struct socket *so)
444 struct sctp_inpcb *inp;
447 inp = (struct sctp_inpcb *)so->so_pcb;
452 flags = inp->sctp_flags;
453 #ifdef SCTP_LOG_CLOSING
454 sctp_log_closing(inp, NULL, 17);
456 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
457 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
458 #ifdef SCTP_LOG_CLOSING
459 sctp_log_closing(inp, NULL, 16);
461 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
462 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
464 SCTP_SB_CLEAR(so->so_snd);
466 * same for the rcv ones, they are only here for the
469 SCTP_SB_CLEAR(so->so_rcv);
471 /* Now null out the reference, we are completely detached. */
475 flags = inp->sctp_flags;
476 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
477 goto sctp_must_try_again;
484 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
486 struct sctp_inpcb *inp;
487 struct inpcb *ip_inp;
489 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
496 inp = (struct sctp_inpcb *)so->so_pcb;
498 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
501 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
502 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
507 error = sctp_inpcb_alloc(so, vrf_id);
511 inp = (struct sctp_inpcb *)so->so_pcb;
513 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
514 ip_inp = &inp->ip_inp.inp;
515 ip_inp->inp_vflag |= INP_IPV4;
516 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
518 error = ipsec_init_policy(so, &ip_inp->inp_sp);
519 #ifdef SCTP_LOG_CLOSING
520 sctp_log_closing(inp, NULL, 17);
524 flags = inp->sctp_flags;
525 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
526 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
527 #ifdef SCTP_LOG_CLOSING
528 sctp_log_closing(inp, NULL, 15);
530 SCTP_INP_WUNLOCK(inp);
531 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
532 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
534 flags = inp->sctp_flags;
535 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
538 SCTP_INP_WUNLOCK(inp);
544 SCTP_INP_WUNLOCK(inp);
549 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
551 struct sctp_inpcb *inp = NULL;
555 if (addr && addr->sa_family != AF_INET) {
556 /* must be a v4 address! */
557 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
561 if (addr && (addr->sa_len != sizeof(struct sockaddr_in))) {
562 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
565 inp = (struct sctp_inpcb *)so->so_pcb;
567 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
570 error = sctp_inpcb_bind(so, addr, NULL, p);
576 sctp_close(struct socket *so)
578 struct sctp_inpcb *inp;
581 inp = (struct sctp_inpcb *)so->so_pcb;
586 * Inform all the lower layer assoc that we are done.
589 flags = inp->sctp_flags;
590 #ifdef SCTP_LOG_CLOSING
591 sctp_log_closing(inp, NULL, 17);
593 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
594 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
595 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
596 (so->so_rcv.sb_cc > 0)) {
597 #ifdef SCTP_LOG_CLOSING
598 sctp_log_closing(inp, NULL, 13);
600 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
601 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
603 #ifdef SCTP_LOG_CLOSING
604 sctp_log_closing(inp, NULL, 14);
606 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
607 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
610 * The socket is now detached, no matter what the state of
611 * the SCTP association.
614 SCTP_SB_CLEAR(so->so_snd);
616 * same for the rcv ones, they are only here for the
619 SCTP_SB_CLEAR(so->so_rcv);
621 /* Now null out the reference, we are completely detached. */
625 flags = inp->sctp_flags;
626 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
627 goto sctp_must_try_again;
635 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
636 struct mbuf *control, struct thread *p);
640 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
641 struct mbuf *control, struct thread *p)
643 struct sctp_inpcb *inp;
646 inp = (struct sctp_inpcb *)so->so_pcb;
649 sctp_m_freem(control);
652 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
656 /* Got to have an to address if we are NOT a connected socket */
657 if ((addr == NULL) &&
658 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
659 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
661 } else if (addr == NULL) {
662 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
663 error = EDESTADDRREQ;
666 sctp_m_freem(control);
672 if (addr->sa_family != AF_INET) {
673 /* must be a v4 address! */
674 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
677 sctp_m_freem(control);
680 error = EDESTADDRREQ;
685 /* now what about control */
688 SCTP_PRINTF("huh? control set?\n");
689 sctp_m_freem(inp->control);
692 inp->control = control;
696 SCTP_BUF_NEXT(inp->pkt_last) = m;
699 inp->pkt_last = inp->pkt = m;
702 /* FreeBSD uses a flag passed */
703 ((flags & PRUS_MORETOCOME) == 0)
706 * note with the current version this code will only be used
707 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
708 * re-defining sosend to use the sctp_sosend. One can
709 * optionally switch back to this code (by changing back the
710 * definitions) but this is not advisable. This code is used
711 * by FreeBSD when sending a file with sendfile() though.
715 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
725 sctp_disconnect(struct socket *so)
727 struct sctp_inpcb *inp;
729 inp = (struct sctp_inpcb *)so->so_pcb;
731 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
735 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
736 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
737 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
739 SCTP_INP_RUNLOCK(inp);
742 struct sctp_association *asoc;
743 struct sctp_tcb *stcb;
745 stcb = LIST_FIRST(&inp->sctp_asoc_list);
747 SCTP_INP_RUNLOCK(inp);
748 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
753 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
754 /* We are about to be freed, out of here */
755 SCTP_TCB_UNLOCK(stcb);
756 SCTP_INP_RUNLOCK(inp);
759 if (((so->so_options & SO_LINGER) &&
760 (so->so_linger == 0)) ||
761 (so->so_rcv.sb_cc > 0)) {
762 if (SCTP_GET_STATE(asoc) !=
763 SCTP_STATE_COOKIE_WAIT) {
764 /* Left with Data unread */
767 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_DONTWAIT, 1, MT_DATA);
773 struct sctp_paramhdr *ph;
775 ph = mtod(err, struct sctp_paramhdr *);
776 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
777 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
778 ph->param_length = htons(SCTP_BUF_LEN(err));
780 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
781 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
783 SCTP_INP_RUNLOCK(inp);
784 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
785 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
786 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
788 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
789 /* No unlock tcb assoc is gone */
792 if (TAILQ_EMPTY(&asoc->send_queue) &&
793 TAILQ_EMPTY(&asoc->sent_queue) &&
794 (asoc->stream_queue_cnt == 0)) {
795 /* there is nothing queued to send, so done */
796 if (asoc->locked_on_sending) {
799 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
800 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
801 /* only send SHUTDOWN 1st time thru */
802 struct sctp_nets *netp;
804 if (stcb->asoc.alternate) {
805 netp = stcb->asoc.alternate;
807 netp = stcb->asoc.primary_destination;
809 sctp_stop_timers_for_shutdown(stcb);
810 sctp_send_shutdown(stcb, netp);
811 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
812 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
813 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
814 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
816 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
817 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
818 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
819 stcb->sctp_ep, stcb, netp);
820 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
821 stcb->sctp_ep, stcb, netp);
826 * we still got (or just got) data to send,
827 * so set SHUTDOWN_PENDING
830 * XXX sockets draft says that SCTP_EOF
831 * should be sent with no data. currently,
832 * we will allow user data to be sent first
833 * and move to SHUTDOWN-PENDING
835 struct sctp_nets *netp;
837 if (stcb->asoc.alternate) {
838 netp = stcb->asoc.alternate;
840 netp = stcb->asoc.primary_destination;
843 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
844 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
846 if (asoc->locked_on_sending) {
847 /* Locked to send out the data */
848 struct sctp_stream_queue_pending *sp;
850 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
852 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
853 asoc->locked_on_sending->stream_no);
855 if ((sp->length == 0) && (sp->msg_is_complete == 0))
856 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
859 if (TAILQ_EMPTY(&asoc->send_queue) &&
860 TAILQ_EMPTY(&asoc->sent_queue) &&
861 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
865 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
866 0, M_DONTWAIT, 1, MT_DATA);
872 struct sctp_paramhdr *ph;
875 SCTP_BUF_LEN(op_err) =
876 (sizeof(struct sctp_paramhdr) + sizeof(uint32_t));
878 struct sctp_paramhdr *);
879 ph->param_type = htons(
880 SCTP_CAUSE_USER_INITIATED_ABT);
881 ph->param_length = htons(SCTP_BUF_LEN(op_err));
882 ippp = (uint32_t *) (ph + 1);
883 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4);
885 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
886 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
887 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
888 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
889 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
890 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
892 SCTP_INP_RUNLOCK(inp);
893 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
896 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
899 soisdisconnecting(so);
900 SCTP_TCB_UNLOCK(stcb);
901 SCTP_INP_RUNLOCK(inp);
906 /* UDP model does not support this */
907 SCTP_INP_RUNLOCK(inp);
908 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
914 sctp_flush(struct socket *so, int how)
917 * We will just clear out the values and let subsequent close clear
918 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
919 * they will not be able to read the data, the socket will block
920 * that from happening.
922 struct sctp_inpcb *inp;
924 inp = (struct sctp_inpcb *)so->so_pcb;
926 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
930 /* For the 1 to many model this does nothing */
931 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
932 SCTP_INP_RUNLOCK(inp);
935 SCTP_INP_RUNLOCK(inp);
936 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
938 * First make sure the sb will be happy, we don't use these
939 * except maybe the count
942 SCTP_INP_READ_LOCK(inp);
943 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
944 SCTP_INP_READ_UNLOCK(inp);
945 SCTP_INP_WUNLOCK(inp);
946 so->so_rcv.sb_cc = 0;
947 so->so_rcv.sb_mbcnt = 0;
948 so->so_rcv.sb_mb = NULL;
950 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
952 * First make sure the sb will be happy, we don't use these
953 * except maybe the count
955 so->so_snd.sb_cc = 0;
956 so->so_snd.sb_mbcnt = 0;
957 so->so_snd.sb_mb = NULL;
964 sctp_shutdown(struct socket *so)
966 struct sctp_inpcb *inp;
968 inp = (struct sctp_inpcb *)so->so_pcb;
970 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
974 /* For UDP model this is a invalid call */
975 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
976 /* Restore the flags that the soshutdown took away. */
977 SOCKBUF_LOCK(&so->so_rcv);
978 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
979 SOCKBUF_UNLOCK(&so->so_rcv);
980 /* This proc will wakeup for read and do nothing (I hope) */
981 SCTP_INP_RUNLOCK(inp);
982 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
986 * Ok if we reach here its the TCP model and it is either a SHUT_WR
987 * or SHUT_RDWR. This means we put the shutdown flag against it.
990 struct sctp_tcb *stcb;
991 struct sctp_association *asoc;
994 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
995 SCTP_INP_RUNLOCK(inp);
1000 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1003 * Ok we hit the case that the shutdown call was
1004 * made after an abort or something. Nothing to do
1007 SCTP_INP_RUNLOCK(inp);
1010 SCTP_TCB_LOCK(stcb);
1012 if (TAILQ_EMPTY(&asoc->send_queue) &&
1013 TAILQ_EMPTY(&asoc->sent_queue) &&
1014 (asoc->stream_queue_cnt == 0)) {
1015 if (asoc->locked_on_sending) {
1018 /* there is nothing queued to send, so I'm done... */
1019 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
1020 /* only send SHUTDOWN the first time through */
1021 struct sctp_nets *netp;
1023 if (stcb->asoc.alternate) {
1024 netp = stcb->asoc.alternate;
1026 netp = stcb->asoc.primary_destination;
1028 sctp_stop_timers_for_shutdown(stcb);
1029 sctp_send_shutdown(stcb, netp);
1030 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
1031 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
1032 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1033 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1035 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
1036 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
1037 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1038 stcb->sctp_ep, stcb, netp);
1039 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1040 stcb->sctp_ep, stcb, netp);
1044 * we still got (or just got) data to send, so set
1047 struct sctp_nets *netp;
1049 if (stcb->asoc.alternate) {
1050 netp = stcb->asoc.alternate;
1052 netp = stcb->asoc.primary_destination;
1055 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1056 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1059 if (asoc->locked_on_sending) {
1060 /* Locked to send out the data */
1061 struct sctp_stream_queue_pending *sp;
1063 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1065 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1066 asoc->locked_on_sending->stream_no);
1068 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1069 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1073 if (TAILQ_EMPTY(&asoc->send_queue) &&
1074 TAILQ_EMPTY(&asoc->sent_queue) &&
1075 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1076 struct mbuf *op_err;
1079 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
1080 0, M_DONTWAIT, 1, MT_DATA);
1082 /* Fill in the user initiated abort */
1083 struct sctp_paramhdr *ph;
1086 SCTP_BUF_LEN(op_err) =
1087 sizeof(struct sctp_paramhdr) + sizeof(uint32_t);
1089 struct sctp_paramhdr *);
1090 ph->param_type = htons(
1091 SCTP_CAUSE_USER_INITIATED_ABT);
1092 ph->param_length = htons(SCTP_BUF_LEN(op_err));
1093 ippp = (uint32_t *) (ph + 1);
1094 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1096 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1097 sctp_abort_an_association(stcb->sctp_ep, stcb,
1098 op_err, SCTP_SO_LOCKED);
1101 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1104 SCTP_TCB_UNLOCK(stcb);
1107 SCTP_INP_RUNLOCK(inp);
1112 * copies a "user" presentable address and removes embedded scope, etc.
1113 * returns 0 on success, 1 on error
1116 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1119 struct sockaddr_in6 lsa6;
1121 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1124 memcpy(ss, sa, sa->sa_len);
1131 * NOTE: assumes addr lock is held
1134 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1135 struct sctp_tcb *stcb,
1137 struct sockaddr_storage *sas,
1140 struct sctp_ifn *sctp_ifn;
1141 struct sctp_ifa *sctp_ifa;
1142 int loopback_scope, ipv4_local_scope, local_scope, site_scope;
1144 int ipv4_addr_legal, ipv6_addr_legal;
1145 struct sctp_vrf *vrf;
1152 /* Turn on all the appropriate scope */
1153 loopback_scope = stcb->asoc.loopback_scope;
1154 ipv4_local_scope = stcb->asoc.ipv4_local_scope;
1155 local_scope = stcb->asoc.local_scope;
1156 site_scope = stcb->asoc.site_scope;
1158 /* Turn on ALL scope, since we look at the EP */
1159 loopback_scope = ipv4_local_scope = local_scope =
1162 ipv4_addr_legal = ipv6_addr_legal = 0;
1163 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1164 ipv6_addr_legal = 1;
1165 if (SCTP_IPV6_V6ONLY(inp) == 0) {
1166 ipv4_addr_legal = 1;
1169 ipv4_addr_legal = 1;
1171 vrf = sctp_find_vrf(vrf_id);
1175 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1176 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1177 if ((loopback_scope == 0) &&
1178 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1179 /* Skip loopback if loopback_scope not set */
1182 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1185 * For the BOUND-ALL case, the list
1186 * associated with a TCB is Always
1187 * considered a reverse list.. i.e.
1188 * it lists addresses that are NOT
1189 * part of the association. If this
1190 * is one of those we must skip it.
1192 if (sctp_is_addr_restricted(stcb,
1197 switch (sctp_ifa->address.sa.sa_family) {
1200 if (ipv4_addr_legal) {
1201 struct sockaddr_in *sin;
1203 sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
1204 if (sin->sin_addr.s_addr == 0) {
1212 if ((ipv4_local_scope == 0) &&
1213 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1217 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1218 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1219 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1220 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1221 actual += sizeof(struct sockaddr_in6);
1224 memcpy(sas, sin, sizeof(*sin));
1225 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1226 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1227 actual += sizeof(*sin);
1231 if (actual >= limit) {
1241 if (ipv6_addr_legal) {
1242 struct sockaddr_in6 *sin6;
1244 sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
1245 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1253 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1254 if (local_scope == 0)
1256 if (sin6->sin6_scope_id == 0) {
1257 if (sa6_recoverscope(sin6) != 0)
1275 if ((site_scope == 0) &&
1276 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1279 memcpy(sas, sin6, sizeof(*sin6));
1280 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1281 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1282 actual += sizeof(*sin6);
1283 if (actual >= limit) {
1298 struct sctp_laddr *laddr;
1300 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1302 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1306 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1309 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1310 sas = (struct sockaddr_storage *)((caddr_t)sas +
1311 laddr->ifa->address.sa.sa_len);
1312 actual += laddr->ifa->address.sa.sa_len;
1313 if (actual >= limit) {
1322 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1323 struct sctp_tcb *stcb,
1325 struct sockaddr_storage *sas)
1329 SCTP_IPI_ADDR_RLOCK();
1330 /* fill up addresses for the endpoint's default vrf */
1331 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1333 SCTP_IPI_ADDR_RUNLOCK();
1338 * NOTE: assumes addr lock is held
1341 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1344 struct sctp_vrf *vrf = NULL;
1347 * In both sub-set bound an bound_all cases we return the MAXIMUM
1348 * number of addresses that you COULD get. In reality the sub-set
1349 * bound may have an exclusion list for a given TCB OR in the
1350 * bound-all case a TCB may NOT include the loopback or other
1351 * addresses as well.
1353 vrf = sctp_find_vrf(vrf_id);
1357 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1358 struct sctp_ifn *sctp_ifn;
1359 struct sctp_ifa *sctp_ifa;
1361 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1362 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1363 /* Count them if they are the right type */
1364 switch (sctp_ifa->address.sa.sa_family) {
1367 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1368 cnt += sizeof(struct sockaddr_in6);
1370 cnt += sizeof(struct sockaddr_in);
1375 cnt += sizeof(struct sockaddr_in6);
1384 struct sctp_laddr *laddr;
1386 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1387 switch (laddr->ifa->address.sa.sa_family) {
1390 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1391 cnt += sizeof(struct sockaddr_in6);
1393 cnt += sizeof(struct sockaddr_in);
1398 cnt += sizeof(struct sockaddr_in6);
1410 sctp_count_max_addresses(struct sctp_inpcb *inp)
1414 SCTP_IPI_ADDR_RLOCK();
1415 /* count addresses for the endpoint's default VRF */
1416 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1417 SCTP_IPI_ADDR_RUNLOCK();
1422 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1423 size_t optsize, void *p, int delay)
1426 int creat_lock_on = 0;
1427 struct sctp_tcb *stcb = NULL;
1428 struct sockaddr *sa;
1429 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1431 int bad_addresses = 0;
1434 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1436 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1437 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1438 /* We are already connected AND the TCP model */
1439 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1440 return (EADDRINUSE);
1442 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1443 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1444 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1447 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1448 SCTP_INP_RLOCK(inp);
1449 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1450 SCTP_INP_RUNLOCK(inp);
1453 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1456 SCTP_INP_INCR_REF(inp);
1457 SCTP_ASOC_CREATE_LOCK(inp);
1459 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1460 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1461 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1465 totaddrp = (int *)optval;
1466 totaddr = *totaddrp;
1467 sa = (struct sockaddr *)(totaddrp + 1);
1468 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
1469 if ((stcb != NULL) || bad_addresses) {
1470 /* Already have or am bring up an association */
1471 SCTP_ASOC_CREATE_UNLOCK(inp);
1474 SCTP_TCB_UNLOCK(stcb);
1475 if (bad_addresses == 0) {
1476 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1482 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1487 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1489 struct in6pcb *inp6;
1491 inp6 = (struct in6pcb *)inp;
1492 if (SCTP_IPV6_V6ONLY(inp6)) {
1494 * if IPV6_V6ONLY flag, ignore connections destined
1495 * to a v4 addr or v4-mapped addr
1497 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1503 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1504 SCTP_PCB_FLAGS_UNBOUND) {
1505 /* Bind a ephemeral port */
1506 error = sctp_inpcb_bind(so, NULL, NULL, p);
1511 /* FIX ME: do we want to pass in a vrf on the connect call? */
1512 vrf_id = inp->def_vrf_id;
1515 /* We are GOOD to go */
1516 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1520 /* Gak! no memory */
1523 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1524 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1525 /* Set the connected flag so we can queue data */
1528 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1529 /* move to second address */
1530 switch (sa->sa_family) {
1533 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1538 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1546 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1547 /* Fill in the return id */
1549 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1552 a_id = (sctp_assoc_t *) optval;
1553 *a_id = sctp_get_associd(stcb);
1555 /* initialize authentication parameters for the assoc */
1556 sctp_initialize_auth_params(inp, stcb);
1559 /* doing delayed connection */
1560 stcb->asoc.delayed_connection = 1;
1561 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1563 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1564 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1566 SCTP_TCB_UNLOCK(stcb);
1567 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1568 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1569 /* Set the connected flag so we can queue data */
1573 if (creat_lock_on) {
1574 SCTP_ASOC_CREATE_UNLOCK(inp);
1576 SCTP_INP_DECR_REF(inp);
1580 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1581 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1582 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1583 SCTP_INP_RLOCK(inp); \
1584 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1586 SCTP_TCB_LOCK(stcb); \
1588 SCTP_INP_RUNLOCK(inp); \
1589 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1590 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1591 if (stcb == NULL) { \
1592 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1602 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1603 if (size < sizeof(type)) { \
1604 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1608 destp = (type *)srcp; \
1613 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1616 struct sctp_inpcb *inp = NULL;
1618 struct sctp_tcb *stcb = NULL;
1620 if (optval == NULL) {
1621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1624 inp = (struct sctp_inpcb *)so->so_pcb;
1626 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1633 case SCTP_AUTOCLOSE:
1634 case SCTP_EXPLICIT_EOR:
1635 case SCTP_AUTO_ASCONF:
1636 case SCTP_DISABLE_FRAGMENTS:
1637 case SCTP_I_WANT_MAPPED_V4_ADDR:
1638 case SCTP_USE_EXT_RCVINFO:
1639 SCTP_INP_RLOCK(inp);
1641 case SCTP_DISABLE_FRAGMENTS:
1642 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1644 case SCTP_I_WANT_MAPPED_V4_ADDR:
1645 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1647 case SCTP_AUTO_ASCONF:
1648 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1649 /* only valid for bound all sockets */
1650 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1652 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1657 case SCTP_EXPLICIT_EOR:
1658 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1661 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1663 case SCTP_USE_EXT_RCVINFO:
1664 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1666 case SCTP_AUTOCLOSE:
1667 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1668 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1674 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1675 error = ENOPROTOOPT;
1676 } /* end switch (sopt->sopt_name) */
1677 if (*optsize < sizeof(val)) {
1678 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1682 SCTP_INP_RUNLOCK(inp);
1684 /* return the option value */
1685 *(int *)optval = val;
1686 *optsize = sizeof(val);
1689 case SCTP_GET_PACKET_LOG:
1691 #ifdef SCTP_PACKET_LOGGING
1695 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1696 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1699 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1704 case SCTP_REUSE_PORT:
1708 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1709 /* Can't do this for a 1-m socket */
1713 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1714 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1715 *optsize = sizeof(uint32_t);
1718 case SCTP_PARTIAL_DELIVERY_POINT:
1722 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1723 *value = inp->partial_delivery_point;
1724 *optsize = sizeof(uint32_t);
1727 case SCTP_FRAGMENT_INTERLEAVE:
1731 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1732 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1733 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1734 *value = SCTP_FRAG_LEVEL_2;
1736 *value = SCTP_FRAG_LEVEL_1;
1739 *value = SCTP_FRAG_LEVEL_0;
1741 *optsize = sizeof(uint32_t);
1744 case SCTP_CMT_ON_OFF:
1746 struct sctp_assoc_value *av;
1748 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1749 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1751 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1752 SCTP_TCB_UNLOCK(stcb);
1754 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1755 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1756 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1757 SCTP_INP_RLOCK(inp);
1758 av->assoc_value = inp->sctp_cmt_on_off;
1759 SCTP_INP_RUNLOCK(inp);
1761 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1766 *optsize = sizeof(struct sctp_assoc_value);
1770 case SCTP_PLUGGABLE_CC:
1772 struct sctp_assoc_value *av;
1774 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1775 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1777 av->assoc_value = stcb->asoc.congestion_control_module;
1778 SCTP_TCB_UNLOCK(stcb);
1780 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1781 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1782 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1783 SCTP_INP_RLOCK(inp);
1784 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1785 SCTP_INP_RUNLOCK(inp);
1787 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1792 *optsize = sizeof(struct sctp_assoc_value);
1796 case SCTP_CC_OPTION:
1798 struct sctp_cc_option *cc_opt;
1800 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1801 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1805 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1808 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1809 *optsize = sizeof(struct sctp_cc_option);
1811 SCTP_TCB_UNLOCK(stcb);
1815 case SCTP_PLUGGABLE_SS:
1817 struct sctp_assoc_value *av;
1819 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1820 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1822 av->assoc_value = stcb->asoc.stream_scheduling_module;
1823 SCTP_TCB_UNLOCK(stcb);
1825 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1826 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1827 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1828 SCTP_INP_RLOCK(inp);
1829 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1830 SCTP_INP_RUNLOCK(inp);
1832 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1837 *optsize = sizeof(struct sctp_assoc_value);
1843 struct sctp_stream_value *av;
1845 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1846 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1848 if (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1849 &av->stream_value) < 0) {
1850 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1853 *optsize = sizeof(struct sctp_stream_value);
1855 SCTP_TCB_UNLOCK(stcb);
1858 * Can't get stream value without
1861 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1866 case SCTP_GET_ADDR_LEN:
1868 struct sctp_assoc_value *av;
1870 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1873 if (av->assoc_value == AF_INET) {
1874 av->assoc_value = sizeof(struct sockaddr_in);
1879 if (av->assoc_value == AF_INET6) {
1880 av->assoc_value = sizeof(struct sockaddr_in6);
1885 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1887 *optsize = sizeof(struct sctp_assoc_value);
1891 case SCTP_GET_ASSOC_NUMBER:
1893 uint32_t *value, cnt;
1895 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1897 SCTP_INP_RLOCK(inp);
1898 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1901 SCTP_INP_RUNLOCK(inp);
1903 *optsize = sizeof(uint32_t);
1906 case SCTP_GET_ASSOC_ID_LIST:
1908 struct sctp_assoc_ids *ids;
1909 unsigned int at, limit;
1911 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1913 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1914 SCTP_INP_RLOCK(inp);
1915 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1917 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1920 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1924 SCTP_INP_RUNLOCK(inp);
1926 ids->gaids_number_of_ids = at;
1927 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1933 struct sctp_assoc_value *av;
1935 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1936 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1939 av->assoc_value = stcb->asoc.context;
1940 SCTP_TCB_UNLOCK(stcb);
1942 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1943 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1944 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1945 SCTP_INP_RLOCK(inp);
1946 av->assoc_value = inp->sctp_context;
1947 SCTP_INP_RUNLOCK(inp);
1949 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1954 *optsize = sizeof(struct sctp_assoc_value);
1960 uint32_t *default_vrfid;
1962 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1963 *default_vrfid = inp->def_vrf_id;
1964 *optsize = sizeof(uint32_t);
1967 case SCTP_GET_ASOC_VRF:
1969 struct sctp_assoc_value *id;
1971 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1972 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1977 id->assoc_value = stcb->asoc.vrf_id;
1978 *optsize = sizeof(struct sctp_assoc_value);
1982 case SCTP_GET_VRF_IDS:
1984 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1988 case SCTP_GET_NONCE_VALUES:
1990 struct sctp_get_nonce_values *gnv;
1992 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1993 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1996 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1997 gnv->gn_local_tag = stcb->asoc.my_vtag;
1998 SCTP_TCB_UNLOCK(stcb);
1999 *optsize = sizeof(struct sctp_get_nonce_values);
2001 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2006 case SCTP_DELAYED_SACK:
2008 struct sctp_sack_info *sack;
2010 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2011 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2013 sack->sack_delay = stcb->asoc.delayed_ack;
2014 sack->sack_freq = stcb->asoc.sack_freq;
2015 SCTP_TCB_UNLOCK(stcb);
2017 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2018 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2019 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2020 SCTP_INP_RLOCK(inp);
2021 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2022 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2023 SCTP_INP_RUNLOCK(inp);
2025 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2030 *optsize = sizeof(struct sctp_sack_info);
2034 case SCTP_GET_SNDBUF_USE:
2036 struct sctp_sockstat *ss;
2038 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2039 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2042 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2043 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2044 stcb->asoc.size_on_all_streams);
2045 SCTP_TCB_UNLOCK(stcb);
2046 *optsize = sizeof(struct sctp_sockstat);
2048 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2053 case SCTP_MAX_BURST:
2055 struct sctp_assoc_value *av;
2057 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2058 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2061 av->assoc_value = stcb->asoc.max_burst;
2062 SCTP_TCB_UNLOCK(stcb);
2064 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2065 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2066 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2067 SCTP_INP_RLOCK(inp);
2068 av->assoc_value = inp->sctp_ep.max_burst;
2069 SCTP_INP_RUNLOCK(inp);
2071 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2076 *optsize = sizeof(struct sctp_assoc_value);
2082 struct sctp_assoc_value *av;
2085 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2086 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2089 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2090 SCTP_TCB_UNLOCK(stcb);
2092 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2093 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2094 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2095 SCTP_INP_RLOCK(inp);
2096 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2097 ovh = SCTP_MED_OVERHEAD;
2099 ovh = SCTP_MED_V4_OVERHEAD;
2101 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2102 av->assoc_value = 0;
2104 av->assoc_value = inp->sctp_frag_point - ovh;
2105 SCTP_INP_RUNLOCK(inp);
2107 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2112 *optsize = sizeof(struct sctp_assoc_value);
2116 case SCTP_GET_STAT_LOG:
2117 error = sctp_fill_stat_log(optval, optsize);
2121 struct sctp_event_subscribe *events;
2123 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2124 memset(events, 0, sizeof(struct sctp_event_subscribe));
2125 SCTP_INP_RLOCK(inp);
2126 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2127 events->sctp_data_io_event = 1;
2129 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2130 events->sctp_association_event = 1;
2132 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2133 events->sctp_address_event = 1;
2135 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2136 events->sctp_send_failure_event = 1;
2138 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2139 events->sctp_peer_error_event = 1;
2141 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2142 events->sctp_shutdown_event = 1;
2144 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2145 events->sctp_partial_delivery_event = 1;
2147 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2148 events->sctp_adaptation_layer_event = 1;
2150 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2151 events->sctp_authentication_event = 1;
2153 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2154 events->sctp_sender_dry_event = 1;
2156 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2157 events->sctp_stream_reset_event = 1;
2158 SCTP_INP_RUNLOCK(inp);
2159 *optsize = sizeof(struct sctp_event_subscribe);
2162 case SCTP_ADAPTATION_LAYER:
2166 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2168 SCTP_INP_RLOCK(inp);
2169 *value = inp->sctp_ep.adaptation_layer_indicator;
2170 SCTP_INP_RUNLOCK(inp);
2171 *optsize = sizeof(uint32_t);
2174 case SCTP_SET_INITIAL_DBG_SEQ:
2178 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2179 SCTP_INP_RLOCK(inp);
2180 *value = inp->sctp_ep.initial_sequence_debug;
2181 SCTP_INP_RUNLOCK(inp);
2182 *optsize = sizeof(uint32_t);
2185 case SCTP_GET_LOCAL_ADDR_SIZE:
2189 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2190 SCTP_INP_RLOCK(inp);
2191 *value = sctp_count_max_addresses(inp);
2192 SCTP_INP_RUNLOCK(inp);
2193 *optsize = sizeof(uint32_t);
2196 case SCTP_GET_REMOTE_ADDR_SIZE:
2200 struct sctp_nets *net;
2202 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2203 /* FIXME MT: change to sctp_assoc_value? */
2204 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2208 /* Count the sizes */
2209 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2210 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2211 size += sizeof(struct sockaddr_in6);
2213 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2216 size += sizeof(struct sockaddr_in);
2221 size += sizeof(struct sockaddr_in6);
2229 SCTP_TCB_UNLOCK(stcb);
2230 *value = (uint32_t) size;
2231 *optsize = sizeof(uint32_t);
2233 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2238 case SCTP_GET_PEER_ADDRESSES:
2240 * Get the address information, an array is passed in to
2241 * fill up we pack it.
2245 struct sockaddr_storage *sas;
2246 struct sctp_nets *net;
2247 struct sctp_getaddresses *saddr;
2249 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2250 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2253 left = (*optsize) - sizeof(struct sctp_getaddresses);
2254 *optsize = sizeof(struct sctp_getaddresses);
2255 sas = (struct sockaddr_storage *)&saddr->addr[0];
2257 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2258 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2259 cpsz = sizeof(struct sockaddr_in6);
2261 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2264 cpsz = sizeof(struct sockaddr_in);
2269 cpsz = sizeof(struct sockaddr_in6);
2281 /* not enough room. */
2284 #if defined(INET) && defined(INET6)
2285 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2286 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2287 /* Must map the address */
2288 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2289 (struct sockaddr_in6 *)sas);
2292 memcpy(sas, &net->ro._l_addr, cpsz);
2293 #if defined(INET) && defined(INET6)
2296 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2298 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2302 SCTP_TCB_UNLOCK(stcb);
2304 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2309 case SCTP_GET_LOCAL_ADDRESSES:
2311 size_t limit, actual;
2312 struct sockaddr_storage *sas;
2313 struct sctp_getaddresses *saddr;
2315 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2316 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2318 sas = (struct sockaddr_storage *)&saddr->addr[0];
2319 limit = *optsize - sizeof(sctp_assoc_t);
2320 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2322 SCTP_TCB_UNLOCK(stcb);
2324 *optsize = sizeof(struct sockaddr_storage) + actual;
2327 case SCTP_PEER_ADDR_PARAMS:
2329 struct sctp_paddrparams *paddrp;
2330 struct sctp_nets *net;
2332 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2333 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2337 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2340 * We increment here since
2341 * sctp_findassociation_ep_addr() wil do a
2342 * decrement if it finds the stcb as long as
2343 * the locked tcb (last argument) is NOT a
2346 SCTP_INP_INCR_REF(inp);
2347 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2349 SCTP_INP_DECR_REF(inp);
2352 if (stcb && (net == NULL)) {
2353 struct sockaddr *sa;
2355 sa = (struct sockaddr *)&paddrp->spp_address;
2357 if (sa->sa_family == AF_INET) {
2358 struct sockaddr_in *sin;
2360 sin = (struct sockaddr_in *)sa;
2361 if (sin->sin_addr.s_addr) {
2363 SCTP_TCB_UNLOCK(stcb);
2364 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2370 if (sa->sa_family == AF_INET6) {
2371 struct sockaddr_in6 *sin6;
2373 sin6 = (struct sockaddr_in6 *)sa;
2374 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2376 SCTP_TCB_UNLOCK(stcb);
2377 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2383 error = EAFNOSUPPORT;
2384 SCTP_TCB_UNLOCK(stcb);
2385 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2390 /* Applies to the specific association */
2391 paddrp->spp_flags = 0;
2395 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2396 ovh = SCTP_MED_OVERHEAD;
2398 ovh = SCTP_MED_V4_OVERHEAD;
2401 paddrp->spp_hbinterval = net->heart_beat_delay;
2402 paddrp->spp_pathmaxrxt = net->failure_threshold;
2403 paddrp->spp_pathmtu = net->mtu - ovh;
2404 /* get flags for HB */
2405 if (net->dest_state & SCTP_ADDR_NOHB) {
2406 paddrp->spp_flags |= SPP_HB_DISABLE;
2408 paddrp->spp_flags |= SPP_HB_ENABLE;
2410 /* get flags for PMTU */
2411 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2412 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2414 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2416 if (net->dscp & 0x01) {
2417 paddrp->spp_dscp = net->dscp & 0xfc;
2418 paddrp->spp_flags |= SPP_DSCP;
2421 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2422 (net->flowlabel & 0x80000000)) {
2423 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2424 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2429 * No destination so return default
2432 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2433 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2434 if (stcb->asoc.default_dscp & 0x01) {
2435 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2436 paddrp->spp_flags |= SPP_DSCP;
2439 if (stcb->asoc.default_flowlabel & 0x80000000) {
2440 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2441 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2444 /* default settings should be these */
2445 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2446 paddrp->spp_flags |= SPP_HB_DISABLE;
2448 paddrp->spp_flags |= SPP_HB_ENABLE;
2450 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2451 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2453 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2455 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2457 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2458 SCTP_TCB_UNLOCK(stcb);
2460 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2461 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2462 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2463 /* Use endpoint defaults */
2464 SCTP_INP_RLOCK(inp);
2465 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2466 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2467 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2468 /* get inp's default */
2469 if (inp->sctp_ep.default_dscp & 0x01) {
2470 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2471 paddrp->spp_flags |= SPP_DSCP;
2474 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2475 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2476 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2477 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2480 /* can't return this */
2481 paddrp->spp_pathmtu = 0;
2483 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2484 paddrp->spp_flags |= SPP_HB_ENABLE;
2486 paddrp->spp_flags |= SPP_HB_DISABLE;
2488 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2489 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2491 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2493 SCTP_INP_RUNLOCK(inp);
2495 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2500 *optsize = sizeof(struct sctp_paddrparams);
2504 case SCTP_GET_PEER_ADDR_INFO:
2506 struct sctp_paddrinfo *paddri;
2507 struct sctp_nets *net;
2509 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2510 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2514 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
2517 * We increment here since
2518 * sctp_findassociation_ep_addr() wil do a
2519 * decrement if it finds the stcb as long as
2520 * the locked tcb (last argument) is NOT a
2523 SCTP_INP_INCR_REF(inp);
2524 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
2526 SCTP_INP_DECR_REF(inp);
2530 if ((stcb) && (net)) {
2531 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2532 /* It's unconfirmed */
2533 paddri->spinfo_state = SCTP_UNCONFIRMED;
2534 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2536 paddri->spinfo_state = SCTP_ACTIVE;
2539 paddri->spinfo_state = SCTP_INACTIVE;
2541 paddri->spinfo_cwnd = net->cwnd;
2542 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2543 paddri->spinfo_rto = net->RTO;
2544 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2545 paddri->spinfo_mtu = net->mtu;
2546 SCTP_TCB_UNLOCK(stcb);
2547 *optsize = sizeof(struct sctp_paddrinfo);
2550 SCTP_TCB_UNLOCK(stcb);
2552 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2557 case SCTP_PCB_STATUS:
2559 struct sctp_pcbinfo *spcb;
2561 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2562 sctp_fill_pcbinfo(spcb);
2563 *optsize = sizeof(struct sctp_pcbinfo);
2568 struct sctp_nets *net;
2569 struct sctp_status *sstat;
2571 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2572 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2575 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2580 * I think passing the state is fine since
2581 * sctp_constants.h will be available to the user
2584 sstat->sstat_state = stcb->asoc.state;
2585 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2586 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2587 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2589 * We can't include chunks that have been passed to
2590 * the socket layer. Only things in queue.
2592 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2593 stcb->asoc.cnt_on_all_streams);
2596 sstat->sstat_instrms = stcb->asoc.streamincnt;
2597 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2598 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2599 memcpy(&sstat->sstat_primary.spinfo_address,
2600 &stcb->asoc.primary_destination->ro._l_addr,
2601 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2602 net = stcb->asoc.primary_destination;
2603 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2605 * Again the user can get info from sctp_constants.h
2606 * for what the state of the network is.
2608 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2609 /* It's unconfirmed */
2610 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2611 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2613 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2616 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2618 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2619 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2620 sstat->sstat_primary.spinfo_rto = net->RTO;
2621 sstat->sstat_primary.spinfo_mtu = net->mtu;
2622 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2623 SCTP_TCB_UNLOCK(stcb);
2624 *optsize = sizeof(struct sctp_status);
2629 struct sctp_rtoinfo *srto;
2631 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2632 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2635 srto->srto_initial = stcb->asoc.initial_rto;
2636 srto->srto_max = stcb->asoc.maxrto;
2637 srto->srto_min = stcb->asoc.minrto;
2638 SCTP_TCB_UNLOCK(stcb);
2640 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2641 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2642 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2643 SCTP_INP_RLOCK(inp);
2644 srto->srto_initial = inp->sctp_ep.initial_rto;
2645 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2646 srto->srto_min = inp->sctp_ep.sctp_minrto;
2647 SCTP_INP_RUNLOCK(inp);
2649 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2654 *optsize = sizeof(struct sctp_rtoinfo);
2660 struct sctp_timeouts *stimo;
2662 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2663 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2666 stimo->stimo_init = stcb->asoc.timoinit;
2667 stimo->stimo_data = stcb->asoc.timodata;
2668 stimo->stimo_sack = stcb->asoc.timosack;
2669 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2670 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2671 stimo->stimo_cookie = stcb->asoc.timocookie;
2672 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2673 SCTP_TCB_UNLOCK(stcb);
2674 *optsize = sizeof(struct sctp_timeouts);
2676 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2681 case SCTP_ASSOCINFO:
2683 struct sctp_assocparams *sasoc;
2685 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2686 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2689 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2690 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2691 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2692 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2693 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2694 SCTP_TCB_UNLOCK(stcb);
2696 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2697 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2698 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2699 SCTP_INP_RLOCK(inp);
2700 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2701 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2702 sasoc->sasoc_number_peer_destinations = 0;
2703 sasoc->sasoc_peer_rwnd = 0;
2704 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2705 SCTP_INP_RUNLOCK(inp);
2707 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2712 *optsize = sizeof(struct sctp_assocparams);
2716 case SCTP_DEFAULT_SEND_PARAM:
2718 struct sctp_sndrcvinfo *s_info;
2720 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2721 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2724 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2725 SCTP_TCB_UNLOCK(stcb);
2727 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2728 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2729 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2730 SCTP_INP_RLOCK(inp);
2731 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2732 SCTP_INP_RUNLOCK(inp);
2734 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2739 *optsize = sizeof(struct sctp_sndrcvinfo);
2745 struct sctp_initmsg *sinit;
2747 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2748 SCTP_INP_RLOCK(inp);
2749 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2750 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2751 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2752 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2753 SCTP_INP_RUNLOCK(inp);
2754 *optsize = sizeof(struct sctp_initmsg);
2757 case SCTP_PRIMARY_ADDR:
2758 /* we allow a "get" operation on this */
2760 struct sctp_setprim *ssp;
2762 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2763 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2766 /* simply copy out the sockaddr_storage... */
2770 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
2771 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
2773 memcpy(&ssp->ssp_addr,
2774 &stcb->asoc.primary_destination->ro._l_addr,
2776 SCTP_TCB_UNLOCK(stcb);
2777 *optsize = sizeof(struct sctp_setprim);
2779 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2784 case SCTP_HMAC_IDENT:
2786 struct sctp_hmacalgo *shmac;
2787 sctp_hmaclist_t *hmaclist;
2791 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2793 SCTP_INP_RLOCK(inp);
2794 hmaclist = inp->sctp_ep.local_hmacs;
2795 if (hmaclist == NULL) {
2796 /* no HMACs to return */
2797 *optsize = sizeof(*shmac);
2798 SCTP_INP_RUNLOCK(inp);
2801 /* is there room for all of the hmac ids? */
2802 size = sizeof(*shmac) + (hmaclist->num_algo *
2803 sizeof(shmac->shmac_idents[0]));
2804 if ((size_t)(*optsize) < size) {
2805 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2807 SCTP_INP_RUNLOCK(inp);
2810 /* copy in the list */
2811 shmac->shmac_number_of_idents = hmaclist->num_algo;
2812 for (i = 0; i < hmaclist->num_algo; i++) {
2813 shmac->shmac_idents[i] = hmaclist->hmac[i];
2815 SCTP_INP_RUNLOCK(inp);
2819 case SCTP_AUTH_ACTIVE_KEY:
2821 struct sctp_authkeyid *scact;
2823 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2824 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2827 /* get the active key on the assoc */
2828 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2829 SCTP_TCB_UNLOCK(stcb);
2831 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2832 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2833 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2834 /* get the endpoint active key */
2835 SCTP_INP_RLOCK(inp);
2836 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2837 SCTP_INP_RUNLOCK(inp);
2839 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2844 *optsize = sizeof(struct sctp_authkeyid);
2848 case SCTP_LOCAL_AUTH_CHUNKS:
2850 struct sctp_authchunks *sac;
2851 sctp_auth_chklist_t *chklist = NULL;
2854 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2855 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2858 /* get off the assoc */
2859 chklist = stcb->asoc.local_auth_chunks;
2860 /* is there enough space? */
2861 size = sctp_auth_get_chklist_size(chklist);
2862 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2864 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2866 /* copy in the chunks */
2867 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2868 sac->gauth_number_of_chunks = (uint32_t) size;
2869 *optsize = sizeof(struct sctp_authchunks) + size;
2871 SCTP_TCB_UNLOCK(stcb);
2873 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2874 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2875 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2876 /* get off the endpoint */
2877 SCTP_INP_RLOCK(inp);
2878 chklist = inp->sctp_ep.local_auth_chunks;
2879 /* is there enough space? */
2880 size = sctp_auth_get_chklist_size(chklist);
2881 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2883 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2885 /* copy in the chunks */
2886 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2887 sac->gauth_number_of_chunks = (uint32_t) size;
2888 *optsize = sizeof(struct sctp_authchunks) + size;
2890 SCTP_INP_RUNLOCK(inp);
2892 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2898 case SCTP_PEER_AUTH_CHUNKS:
2900 struct sctp_authchunks *sac;
2901 sctp_auth_chklist_t *chklist = NULL;
2904 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2905 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2908 /* get off the assoc */
2909 chklist = stcb->asoc.peer_auth_chunks;
2910 /* is there enough space? */
2911 size = sctp_auth_get_chklist_size(chklist);
2912 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2914 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2916 /* copy in the chunks */
2917 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2918 sac->gauth_number_of_chunks = (uint32_t) size;
2919 *optsize = sizeof(struct sctp_authchunks) + size;
2921 SCTP_TCB_UNLOCK(stcb);
2923 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2930 struct sctp_event *event;
2931 uint32_t event_type;
2933 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2934 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2936 switch (event->se_type) {
2937 case SCTP_ASSOC_CHANGE:
2938 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2940 case SCTP_PEER_ADDR_CHANGE:
2941 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
2943 case SCTP_REMOTE_ERROR:
2944 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
2946 case SCTP_SEND_FAILED:
2947 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
2949 case SCTP_SHUTDOWN_EVENT:
2950 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
2952 case SCTP_ADAPTATION_INDICATION:
2953 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
2955 case SCTP_PARTIAL_DELIVERY_EVENT:
2956 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
2958 case SCTP_AUTHENTICATION_EVENT:
2959 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
2961 case SCTP_STREAM_RESET_EVENT:
2962 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
2964 case SCTP_SENDER_DRY_EVENT:
2965 event_type = SCTP_PCB_FLAGS_DRYEVNT;
2967 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
2969 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
2972 case SCTP_ASSOC_RESET_EVENT:
2973 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
2975 case SCTP_STREAM_CHANGE_EVENT:
2976 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
2978 case SCTP_SEND_FAILED_EVENT:
2979 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
2983 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2987 if (event_type > 0) {
2989 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
2990 SCTP_TCB_UNLOCK(stcb);
2992 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2993 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2994 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
2995 SCTP_INP_RLOCK(inp);
2996 event->se_on = sctp_is_feature_on(inp, event_type);
2997 SCTP_INP_RUNLOCK(inp);
2999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3005 *optsize = sizeof(struct sctp_event);
3009 case SCTP_RECVRCVINFO:
3013 if (*optsize < sizeof(int)) {
3014 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3017 SCTP_INP_RLOCK(inp);
3018 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3019 SCTP_INP_RUNLOCK(inp);
3022 /* return the option value */
3023 *(int *)optval = onoff;
3024 *optsize = sizeof(int);
3028 case SCTP_RECVNXTINFO:
3032 if (*optsize < sizeof(int)) {
3033 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3036 SCTP_INP_RLOCK(inp);
3037 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3038 SCTP_INP_RUNLOCK(inp);
3041 /* return the option value */
3042 *(int *)optval = onoff;
3043 *optsize = sizeof(int);
3047 case SCTP_DEFAULT_SNDINFO:
3049 struct sctp_sndinfo *info;
3051 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3052 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3055 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3056 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3057 info->snd_flags &= 0xfff0;
3058 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3059 info->snd_context = stcb->asoc.def_send.sinfo_context;
3060 SCTP_TCB_UNLOCK(stcb);
3062 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3063 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3064 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3065 SCTP_INP_RLOCK(inp);
3066 info->snd_sid = inp->def_send.sinfo_stream;
3067 info->snd_flags = inp->def_send.sinfo_flags;
3068 info->snd_flags &= 0xfff0;
3069 info->snd_ppid = inp->def_send.sinfo_ppid;
3070 info->snd_context = inp->def_send.sinfo_context;
3071 SCTP_INP_RUNLOCK(inp);
3073 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3078 *optsize = sizeof(struct sctp_sndinfo);
3082 case SCTP_DEFAULT_PRINFO:
3084 struct sctp_default_prinfo *info;
3086 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3087 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3090 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3091 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3092 SCTP_TCB_UNLOCK(stcb);
3094 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3095 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3096 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3097 SCTP_INP_RLOCK(inp);
3098 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3099 info->pr_value = inp->def_send.sinfo_timetolive;
3100 SCTP_INP_RUNLOCK(inp);
3102 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3107 *optsize = sizeof(struct sctp_default_prinfo);
3111 case SCTP_PEER_ADDR_THLDS:
3113 struct sctp_paddrthlds *thlds;
3114 struct sctp_nets *net;
3116 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3117 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3121 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
3124 * We increment here since
3125 * sctp_findassociation_ep_addr() wil do a
3126 * decrement if it finds the stcb as long as
3127 * the locked tcb (last argument) is NOT a
3130 SCTP_INP_INCR_REF(inp);
3131 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL);
3133 SCTP_INP_DECR_REF(inp);
3136 if (stcb && (net == NULL)) {
3137 struct sockaddr *sa;
3139 sa = (struct sockaddr *)&thlds->spt_address;
3141 if (sa->sa_family == AF_INET) {
3142 struct sockaddr_in *sin;
3144 sin = (struct sockaddr_in *)sa;
3145 if (sin->sin_addr.s_addr) {
3147 SCTP_TCB_UNLOCK(stcb);
3148 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3154 if (sa->sa_family == AF_INET6) {
3155 struct sockaddr_in6 *sin6;
3157 sin6 = (struct sockaddr_in6 *)sa;
3158 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3160 SCTP_TCB_UNLOCK(stcb);
3161 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3167 error = EAFNOSUPPORT;
3168 SCTP_TCB_UNLOCK(stcb);
3169 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3175 thlds->spt_pathmaxrxt = net->failure_threshold;
3176 thlds->spt_pathpfthld = net->pf_threshold;
3178 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3179 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3181 thlds->spt_assoc_id = sctp_get_associd(stcb);
3182 SCTP_TCB_UNLOCK(stcb);
3184 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3185 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3186 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3187 /* Use endpoint defaults */
3188 SCTP_INP_RLOCK(inp);
3189 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3190 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3191 SCTP_INP_RUNLOCK(inp);
3193 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3198 *optsize = sizeof(struct sctp_paddrthlds);
3202 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3204 struct sctp_udpencaps *encaps;
3205 struct sctp_nets *net;
3207 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3208 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3211 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
3214 * We increment here since
3215 * sctp_findassociation_ep_addr() wil do a
3216 * decrement if it finds the stcb as long as
3217 * the locked tcb (last argument) is NOT a
3221 SCTP_INP_INCR_REF(inp);
3222 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
3224 SCTP_INP_DECR_REF(inp);
3227 if (stcb && (net == NULL)) {
3228 struct sockaddr *sa;
3230 sa = (struct sockaddr *)&encaps->sue_address;
3232 if (sa->sa_family == AF_INET) {
3233 struct sockaddr_in *sin;
3235 sin = (struct sockaddr_in *)sa;
3236 if (sin->sin_addr.s_addr) {
3238 SCTP_TCB_UNLOCK(stcb);
3239 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3245 if (sa->sa_family == AF_INET6) {
3246 struct sockaddr_in6 *sin6;
3248 sin6 = (struct sockaddr_in6 *)sa;
3249 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3251 SCTP_TCB_UNLOCK(stcb);
3252 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3258 error = EAFNOSUPPORT;
3259 SCTP_TCB_UNLOCK(stcb);
3260 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3266 encaps->sue_port = net->port;
3268 encaps->sue_port = stcb->asoc.port;
3270 SCTP_TCB_UNLOCK(stcb);
3272 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3273 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3274 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3275 SCTP_INP_RLOCK(inp);
3276 encaps->sue_port = inp->sctp_ep.port;
3277 SCTP_INP_RUNLOCK(inp);
3279 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3284 *optsize = sizeof(struct sctp_paddrparams);
3288 case SCTP_ENABLE_STREAM_RESET:
3290 struct sctp_assoc_value *av;
3292 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3293 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3296 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3297 SCTP_TCB_UNLOCK(stcb);
3299 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3300 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3301 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3302 SCTP_INP_RLOCK(inp);
3303 av->assoc_value = (uint32_t) inp->local_strreset_support;
3304 SCTP_INP_RUNLOCK(inp);
3306 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3311 *optsize = sizeof(struct sctp_assoc_value);
3316 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3317 error = ENOPROTOOPT;
3319 } /* end switch (sopt->sopt_name) */
3327 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3332 struct sctp_tcb *stcb = NULL;
3333 struct sctp_inpcb *inp = NULL;
3336 if (optval == NULL) {
3337 SCTP_PRINTF("optval is NULL\n");
3338 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3341 inp = (struct sctp_inpcb *)so->so_pcb;
3343 SCTP_PRINTF("inp is NULL?\n");
3344 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3347 vrf_id = inp->def_vrf_id;
3352 case SCTP_AUTOCLOSE:
3353 case SCTP_AUTO_ASCONF:
3354 case SCTP_EXPLICIT_EOR:
3355 case SCTP_DISABLE_FRAGMENTS:
3356 case SCTP_USE_EXT_RCVINFO:
3357 case SCTP_I_WANT_MAPPED_V4_ADDR:
3358 /* copy in the option value */
3359 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3364 case SCTP_DISABLE_FRAGMENTS:
3365 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3367 case SCTP_AUTO_ASCONF:
3369 * NOTE: we don't really support this flag
3371 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3372 /* only valid for bound all sockets */
3373 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3375 /* forbidden by admin */
3376 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3379 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3381 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3385 case SCTP_EXPLICIT_EOR:
3386 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3388 case SCTP_USE_EXT_RCVINFO:
3389 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3391 case SCTP_I_WANT_MAPPED_V4_ADDR:
3392 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3393 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3395 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3400 set_opt = SCTP_PCB_FLAGS_NODELAY;
3402 case SCTP_AUTOCLOSE:
3403 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3404 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3405 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3408 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3410 * The value is in ticks. Note this does not effect
3411 * old associations, only new ones.
3413 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3416 SCTP_INP_WLOCK(inp);
3418 sctp_feature_on(inp, set_opt);
3420 sctp_feature_off(inp, set_opt);
3422 SCTP_INP_WUNLOCK(inp);
3424 case SCTP_REUSE_PORT:
3426 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3427 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3428 /* Can't set it after we are bound */
3432 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3433 /* Can't do this for a 1-m socket */
3438 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3440 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3443 case SCTP_PARTIAL_DELIVERY_POINT:
3447 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3448 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3449 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3453 inp->partial_delivery_point = *value;
3456 case SCTP_FRAGMENT_INTERLEAVE:
3457 /* not yet until we re-write sctp_recvmsg() */
3461 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3462 if (*level == SCTP_FRAG_LEVEL_2) {
3463 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3464 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3465 } else if (*level == SCTP_FRAG_LEVEL_1) {
3466 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3467 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3468 } else if (*level == SCTP_FRAG_LEVEL_0) {
3469 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3470 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3473 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3478 case SCTP_CMT_ON_OFF:
3479 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3480 struct sctp_assoc_value *av;
3482 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3483 if (av->assoc_value > SCTP_CMT_MAX) {
3484 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3488 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3490 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3491 SCTP_TCB_UNLOCK(stcb);
3493 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3494 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3495 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3496 (av->assoc_id == SCTP_ALL_ASSOC)) {
3497 SCTP_INP_WLOCK(inp);
3498 inp->sctp_cmt_on_off = av->assoc_value;
3499 SCTP_INP_WUNLOCK(inp);
3501 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3502 (av->assoc_id == SCTP_ALL_ASSOC)) {
3503 SCTP_INP_RLOCK(inp);
3504 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3505 SCTP_TCB_LOCK(stcb);
3506 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3507 SCTP_TCB_UNLOCK(stcb);
3509 SCTP_INP_RUNLOCK(inp);
3513 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3514 error = ENOPROTOOPT;
3517 case SCTP_PLUGGABLE_CC:
3519 struct sctp_assoc_value *av;
3520 struct sctp_nets *net;
3522 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3523 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3524 (av->assoc_value != SCTP_CC_HSTCP) &&
3525 (av->assoc_value != SCTP_CC_HTCP) &&
3526 (av->assoc_value != SCTP_CC_RTCC)) {
3527 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3531 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3533 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3534 stcb->asoc.congestion_control_module = av->assoc_value;
3535 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3536 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3537 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3540 SCTP_TCB_UNLOCK(stcb);
3542 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3543 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3544 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3545 (av->assoc_id == SCTP_ALL_ASSOC)) {
3546 SCTP_INP_WLOCK(inp);
3547 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3548 SCTP_INP_WUNLOCK(inp);
3550 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3551 (av->assoc_id == SCTP_ALL_ASSOC)) {
3552 SCTP_INP_RLOCK(inp);
3553 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3554 SCTP_TCB_LOCK(stcb);
3555 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3556 stcb->asoc.congestion_control_module = av->assoc_value;
3557 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3558 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3559 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3562 SCTP_TCB_UNLOCK(stcb);
3564 SCTP_INP_RUNLOCK(inp);
3569 case SCTP_CC_OPTION:
3571 struct sctp_cc_option *cc_opt;
3573 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3574 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3576 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3577 SCTP_INP_RLOCK(inp);
3578 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3579 SCTP_TCB_LOCK(stcb);
3580 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3581 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3583 SCTP_TCB_UNLOCK(stcb);
3585 SCTP_INP_RUNLOCK(inp);
3590 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3593 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3596 SCTP_TCB_UNLOCK(stcb);
3600 case SCTP_PLUGGABLE_SS:
3602 struct sctp_assoc_value *av;
3604 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3605 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3606 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3607 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3608 (av->assoc_value != SCTP_SS_PRIORITY) &&
3609 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3610 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3611 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3615 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3617 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3618 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3619 stcb->asoc.stream_scheduling_module = av->assoc_value;
3620 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3621 SCTP_TCB_UNLOCK(stcb);
3623 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3624 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3625 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3626 (av->assoc_id == SCTP_ALL_ASSOC)) {
3627 SCTP_INP_WLOCK(inp);
3628 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
3629 SCTP_INP_WUNLOCK(inp);
3631 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3632 (av->assoc_id == SCTP_ALL_ASSOC)) {
3633 SCTP_INP_RLOCK(inp);
3634 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3635 SCTP_TCB_LOCK(stcb);
3636 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3637 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3638 stcb->asoc.stream_scheduling_module = av->assoc_value;
3639 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3640 SCTP_TCB_UNLOCK(stcb);
3642 SCTP_INP_RUNLOCK(inp);
3649 struct sctp_stream_value *av;
3651 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
3652 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3654 if (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
3655 av->stream_value) < 0) {
3656 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3659 SCTP_TCB_UNLOCK(stcb);
3661 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
3662 SCTP_INP_RLOCK(inp);
3663 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3664 SCTP_TCB_LOCK(stcb);
3665 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
3667 &stcb->asoc.strmout[av->stream_id],
3669 SCTP_TCB_UNLOCK(stcb);
3671 SCTP_INP_RUNLOCK(inp);
3675 * Can't set stream value without
3678 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3684 case SCTP_CLR_STAT_LOG:
3685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3690 struct sctp_assoc_value *av;
3692 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3693 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3696 stcb->asoc.context = av->assoc_value;
3697 SCTP_TCB_UNLOCK(stcb);
3699 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3700 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3701 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3702 (av->assoc_id == SCTP_ALL_ASSOC)) {
3703 SCTP_INP_WLOCK(inp);
3704 inp->sctp_context = av->assoc_value;
3705 SCTP_INP_WUNLOCK(inp);
3707 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3708 (av->assoc_id == SCTP_ALL_ASSOC)) {
3709 SCTP_INP_RLOCK(inp);
3710 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3711 SCTP_TCB_LOCK(stcb);
3712 stcb->asoc.context = av->assoc_value;
3713 SCTP_TCB_UNLOCK(stcb);
3715 SCTP_INP_RUNLOCK(inp);
3722 uint32_t *default_vrfid;
3724 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
3725 if (*default_vrfid > SCTP_MAX_VRF_ID) {
3726 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3730 inp->def_vrf_id = *default_vrfid;
3733 case SCTP_DEL_VRF_ID:
3735 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3739 case SCTP_ADD_VRF_ID:
3741 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3745 case SCTP_DELAYED_SACK:
3747 struct sctp_sack_info *sack;
3749 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
3750 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
3751 if (sack->sack_delay) {
3752 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
3753 sack->sack_delay = SCTP_MAX_SACK_DELAY;
3754 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3755 sack->sack_delay = TICKS_TO_MSEC(1);
3759 if (sack->sack_delay) {
3760 stcb->asoc.delayed_ack = sack->sack_delay;
3762 if (sack->sack_freq) {
3763 stcb->asoc.sack_freq = sack->sack_freq;
3765 SCTP_TCB_UNLOCK(stcb);
3767 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3768 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3769 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
3770 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3771 SCTP_INP_WLOCK(inp);
3772 if (sack->sack_delay) {
3773 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
3775 if (sack->sack_freq) {
3776 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
3778 SCTP_INP_WUNLOCK(inp);
3780 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
3781 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3782 SCTP_INP_RLOCK(inp);
3783 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3784 SCTP_TCB_LOCK(stcb);
3785 if (sack->sack_delay) {
3786 stcb->asoc.delayed_ack = sack->sack_delay;
3788 if (sack->sack_freq) {
3789 stcb->asoc.sack_freq = sack->sack_freq;
3791 SCTP_TCB_UNLOCK(stcb);
3793 SCTP_INP_RUNLOCK(inp);
3798 case SCTP_AUTH_CHUNK:
3800 struct sctp_authchunk *sauth;
3802 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
3804 SCTP_INP_WLOCK(inp);
3805 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
3806 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3809 SCTP_INP_WUNLOCK(inp);
3814 struct sctp_authkey *sca;
3815 struct sctp_keyhead *shared_keys;
3816 sctp_sharedkey_t *shared_key;
3817 sctp_key_t *key = NULL;
3820 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
3821 if (sca->sca_keylength == 0) {
3822 size = optsize - sizeof(struct sctp_authkey);
3824 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
3825 size = sca->sca_keylength;
3827 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3832 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
3835 shared_keys = &stcb->asoc.shared_keys;
3836 /* clear the cached keys for this key id */
3837 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3839 * create the new shared key and
3843 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3845 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3847 SCTP_TCB_UNLOCK(stcb);
3851 shared_key = sctp_alloc_sharedkey();
3852 if (shared_key == NULL) {
3854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3856 SCTP_TCB_UNLOCK(stcb);
3859 shared_key->key = key;
3860 shared_key->keyid = sca->sca_keynumber;
3861 error = sctp_insert_sharedkey(shared_keys, shared_key);
3862 SCTP_TCB_UNLOCK(stcb);
3864 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3865 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3866 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
3867 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3868 SCTP_INP_WLOCK(inp);
3869 shared_keys = &inp->sctp_ep.shared_keys;
3871 * clear the cached keys on all
3872 * assocs for this key id
3874 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3876 * create the new shared key and
3880 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3884 SCTP_INP_WUNLOCK(inp);
3888 shared_key = sctp_alloc_sharedkey();
3889 if (shared_key == NULL) {
3891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3893 SCTP_INP_WUNLOCK(inp);
3896 shared_key->key = key;
3897 shared_key->keyid = sca->sca_keynumber;
3898 error = sctp_insert_sharedkey(shared_keys, shared_key);
3899 SCTP_INP_WUNLOCK(inp);
3901 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
3902 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3903 SCTP_INP_RLOCK(inp);
3904 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3905 SCTP_TCB_LOCK(stcb);
3906 shared_keys = &stcb->asoc.shared_keys;
3908 * clear the cached keys for
3911 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3913 * create the new shared key
3914 * and insert/replace it
3917 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3919 SCTP_TCB_UNLOCK(stcb);
3923 shared_key = sctp_alloc_sharedkey();
3924 if (shared_key == NULL) {
3926 SCTP_TCB_UNLOCK(stcb);
3929 shared_key->key = key;
3930 shared_key->keyid = sca->sca_keynumber;
3931 error = sctp_insert_sharedkey(shared_keys, shared_key);
3932 SCTP_TCB_UNLOCK(stcb);
3934 SCTP_INP_RUNLOCK(inp);
3939 case SCTP_HMAC_IDENT:
3941 struct sctp_hmacalgo *shmac;
3942 sctp_hmaclist_t *hmaclist;
3947 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
3948 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
3949 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3953 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
3954 if (hmaclist == NULL) {
3955 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3959 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
3960 hmacid = shmac->shmac_idents[i];
3961 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
3962 /* invalid HMACs were found */ ;
3963 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3965 sctp_free_hmaclist(hmaclist);
3966 goto sctp_set_hmac_done;
3970 for (i = 0; i < hmaclist->num_algo; i++) {
3971 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
3972 /* already in list */
3977 sctp_free_hmaclist(hmaclist);
3978 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3982 /* set it on the endpoint */
3983 SCTP_INP_WLOCK(inp);
3984 if (inp->sctp_ep.local_hmacs)
3985 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
3986 inp->sctp_ep.local_hmacs = hmaclist;
3987 SCTP_INP_WUNLOCK(inp);
3991 case SCTP_AUTH_ACTIVE_KEY:
3993 struct sctp_authkeyid *scact;
3995 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
3996 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
3998 /* set the active key on the right place */
4000 /* set the active key on the assoc */
4001 if (sctp_auth_setactivekey(stcb,
4002 scact->scact_keynumber)) {
4003 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4004 SCTP_FROM_SCTP_USRREQ,
4008 SCTP_TCB_UNLOCK(stcb);
4010 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4011 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4012 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4013 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4014 SCTP_INP_WLOCK(inp);
4015 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4016 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4019 SCTP_INP_WUNLOCK(inp);
4021 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4022 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4023 SCTP_INP_RLOCK(inp);
4024 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4025 SCTP_TCB_LOCK(stcb);
4026 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4027 SCTP_TCB_UNLOCK(stcb);
4029 SCTP_INP_RUNLOCK(inp);
4034 case SCTP_AUTH_DELETE_KEY:
4036 struct sctp_authkeyid *scdel;
4038 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4039 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4041 /* delete the key from the right place */
4043 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4044 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4047 SCTP_TCB_UNLOCK(stcb);
4049 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4050 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4051 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4052 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4053 SCTP_INP_WLOCK(inp);
4054 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4055 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4058 SCTP_INP_WUNLOCK(inp);
4060 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4061 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4062 SCTP_INP_RLOCK(inp);
4063 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4064 SCTP_TCB_LOCK(stcb);
4065 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4066 SCTP_TCB_UNLOCK(stcb);
4068 SCTP_INP_RUNLOCK(inp);
4073 case SCTP_AUTH_DEACTIVATE_KEY:
4075 struct sctp_authkeyid *keyid;
4077 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4078 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4080 /* deactivate the key from the right place */
4082 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4083 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4086 SCTP_TCB_UNLOCK(stcb);
4088 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4089 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4090 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4091 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4092 SCTP_INP_WLOCK(inp);
4093 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4094 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4097 SCTP_INP_WUNLOCK(inp);
4099 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4100 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4101 SCTP_INP_RLOCK(inp);
4102 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4103 SCTP_TCB_LOCK(stcb);
4104 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4105 SCTP_TCB_UNLOCK(stcb);
4107 SCTP_INP_RUNLOCK(inp);
4112 case SCTP_ENABLE_STREAM_RESET:
4114 struct sctp_assoc_value *av;
4116 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4117 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4118 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4122 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4124 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4125 SCTP_TCB_UNLOCK(stcb);
4127 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4128 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4129 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4130 (av->assoc_id == SCTP_ALL_ASSOC)) {
4131 SCTP_INP_WLOCK(inp);
4132 inp->local_strreset_support = (uint8_t) av->assoc_value;
4133 SCTP_INP_WUNLOCK(inp);
4135 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4136 (av->assoc_id == SCTP_ALL_ASSOC)) {
4137 SCTP_INP_RLOCK(inp);
4138 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4139 SCTP_TCB_LOCK(stcb);
4140 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4141 SCTP_TCB_UNLOCK(stcb);
4143 SCTP_INP_RUNLOCK(inp);
4148 case SCTP_RESET_STREAMS:
4150 struct sctp_reset_streams *strrst;
4151 int i, send_out = 0;
4154 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4155 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4157 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4161 if (stcb->asoc.peer_supports_strreset == 0) {
4163 * Peer does not support the chunk type.
4165 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4167 SCTP_TCB_UNLOCK(stcb);
4170 if (stcb->asoc.stream_reset_outstanding) {
4171 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4173 SCTP_TCB_UNLOCK(stcb);
4176 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4179 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4182 if ((send_in == 0) && (send_out == 0)) {
4183 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4185 SCTP_TCB_UNLOCK(stcb);
4188 for (i = 0; i < strrst->srs_number_streams; i++) {
4190 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4191 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4196 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4197 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4203 SCTP_TCB_UNLOCK(stcb);
4206 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4207 strrst->srs_stream_list,
4208 send_out, send_in, 0, 0, 0, 0, 0);
4210 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4211 SCTP_TCB_UNLOCK(stcb);
4214 case SCTP_ADD_STREAMS:
4216 struct sctp_add_streams *stradd;
4217 uint8_t addstream = 0;
4218 uint16_t add_o_strmcnt = 0;
4219 uint16_t add_i_strmcnt = 0;
4221 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4222 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4224 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4228 if (stcb->asoc.peer_supports_strreset == 0) {
4230 * Peer does not support the chunk type.
4232 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4234 SCTP_TCB_UNLOCK(stcb);
4237 if (stcb->asoc.stream_reset_outstanding) {
4238 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4240 SCTP_TCB_UNLOCK(stcb);
4243 if ((stradd->sas_outstrms == 0) &&
4244 (stradd->sas_instrms == 0)) {
4248 if (stradd->sas_outstrms) {
4250 /* We allocate here */
4251 add_o_strmcnt = stradd->sas_outstrms;
4252 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4253 /* You can't have more than 64k */
4258 if (stradd->sas_instrms) {
4263 * We allocate inside
4264 * sctp_send_str_reset_req()
4266 add_i_strmcnt = stradd->sas_instrms;
4267 cnt = add_i_strmcnt;
4268 cnt += stcb->asoc.streamincnt;
4269 if (cnt > 0x0000ffff) {
4270 /* You can't have more than 64k */
4274 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4275 /* More than you are allowed */
4280 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4281 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4283 SCTP_TCB_UNLOCK(stcb);
4286 case SCTP_RESET_ASSOC:
4290 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4291 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4293 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4297 if (stcb->asoc.peer_supports_strreset == 0) {
4299 * Peer does not support the chunk type.
4301 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4303 SCTP_TCB_UNLOCK(stcb);
4306 if (stcb->asoc.stream_reset_outstanding) {
4307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4309 SCTP_TCB_UNLOCK(stcb);
4312 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 1, 0, 0, 0, 0);
4313 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4314 SCTP_TCB_UNLOCK(stcb);
4317 case SCTP_CONNECT_X:
4318 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4319 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4323 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4325 case SCTP_CONNECT_X_DELAYED:
4326 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4327 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4331 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4333 case SCTP_CONNECT_X_COMPLETE:
4335 struct sockaddr *sa;
4336 struct sctp_nets *net;
4338 /* FIXME MT: check correct? */
4339 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4342 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4343 SCTP_INP_RLOCK(inp);
4344 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4346 SCTP_TCB_LOCK(stcb);
4347 net = sctp_findnet(stcb, sa);
4349 SCTP_INP_RUNLOCK(inp);
4352 * We increment here since
4353 * sctp_findassociation_ep_addr() wil do a
4354 * decrement if it finds the stcb as long as
4355 * the locked tcb (last argument) is NOT a
4358 SCTP_INP_INCR_REF(inp);
4359 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4361 SCTP_INP_DECR_REF(inp);
4366 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4370 if (stcb->asoc.delayed_connection == 1) {
4371 stcb->asoc.delayed_connection = 0;
4372 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4373 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4374 stcb->asoc.primary_destination,
4375 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4376 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4379 * already expired or did not use delayed
4382 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4385 SCTP_TCB_UNLOCK(stcb);
4388 case SCTP_MAX_BURST:
4390 struct sctp_assoc_value *av;
4392 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4393 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4396 stcb->asoc.max_burst = av->assoc_value;
4397 SCTP_TCB_UNLOCK(stcb);
4399 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4400 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4401 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4402 (av->assoc_id == SCTP_ALL_ASSOC)) {
4403 SCTP_INP_WLOCK(inp);
4404 inp->sctp_ep.max_burst = av->assoc_value;
4405 SCTP_INP_WUNLOCK(inp);
4407 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4408 (av->assoc_id == SCTP_ALL_ASSOC)) {
4409 SCTP_INP_RLOCK(inp);
4410 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4411 SCTP_TCB_LOCK(stcb);
4412 stcb->asoc.max_burst = av->assoc_value;
4413 SCTP_TCB_UNLOCK(stcb);
4415 SCTP_INP_RUNLOCK(inp);
4422 struct sctp_assoc_value *av;
4425 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4426 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4428 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4429 ovh = SCTP_MED_OVERHEAD;
4431 ovh = SCTP_MED_V4_OVERHEAD;
4434 if (av->assoc_value) {
4435 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4437 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4439 SCTP_TCB_UNLOCK(stcb);
4441 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4442 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4443 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4444 SCTP_INP_WLOCK(inp);
4446 * FIXME MT: I think this is not in
4447 * tune with the API ID
4449 if (av->assoc_value) {
4450 inp->sctp_frag_point = (av->assoc_value + ovh);
4452 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4454 SCTP_INP_WUNLOCK(inp);
4456 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4464 struct sctp_event_subscribe *events;
4466 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4468 SCTP_INP_WLOCK(inp);
4469 if (events->sctp_data_io_event) {
4470 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4472 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4475 if (events->sctp_association_event) {
4476 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4478 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4481 if (events->sctp_address_event) {
4482 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4484 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4487 if (events->sctp_send_failure_event) {
4488 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4490 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4493 if (events->sctp_peer_error_event) {
4494 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4496 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4499 if (events->sctp_shutdown_event) {
4500 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4502 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4505 if (events->sctp_partial_delivery_event) {
4506 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4508 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4511 if (events->sctp_adaptation_layer_event) {
4512 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4514 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4517 if (events->sctp_authentication_event) {
4518 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4520 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4523 if (events->sctp_sender_dry_event) {
4524 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4526 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4529 if (events->sctp_stream_reset_event) {
4530 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4532 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4534 SCTP_INP_WUNLOCK(inp);
4536 SCTP_INP_RLOCK(inp);
4537 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4538 SCTP_TCB_LOCK(stcb);
4539 if (events->sctp_association_event) {
4540 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4542 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4544 if (events->sctp_address_event) {
4545 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4547 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4549 if (events->sctp_send_failure_event) {
4550 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4552 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4554 if (events->sctp_peer_error_event) {
4555 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4557 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4559 if (events->sctp_shutdown_event) {
4560 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4562 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4564 if (events->sctp_partial_delivery_event) {
4565 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4567 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4569 if (events->sctp_adaptation_layer_event) {
4570 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4572 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4574 if (events->sctp_authentication_event) {
4575 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4577 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4579 if (events->sctp_sender_dry_event) {
4580 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4582 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4584 if (events->sctp_stream_reset_event) {
4585 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4587 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4589 SCTP_TCB_UNLOCK(stcb);
4592 * Send up the sender dry event only for 1-to-1
4595 if (events->sctp_sender_dry_event) {
4596 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4597 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4598 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4600 SCTP_TCB_LOCK(stcb);
4601 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4602 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4603 (stcb->asoc.stream_queue_cnt == 0)) {
4604 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4606 SCTP_TCB_UNLOCK(stcb);
4610 SCTP_INP_RUNLOCK(inp);
4613 case SCTP_ADAPTATION_LAYER:
4615 struct sctp_setadaptation *adap_bits;
4617 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
4618 SCTP_INP_WLOCK(inp);
4619 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
4620 SCTP_INP_WUNLOCK(inp);
4624 case SCTP_SET_INITIAL_DBG_SEQ:
4628 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
4629 SCTP_INP_WLOCK(inp);
4630 inp->sctp_ep.initial_sequence_debug = *vvv;
4631 SCTP_INP_WUNLOCK(inp);
4635 case SCTP_DEFAULT_SEND_PARAM:
4637 struct sctp_sndrcvinfo *s_info;
4639 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
4640 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
4643 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4644 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4646 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4649 SCTP_TCB_UNLOCK(stcb);
4651 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4652 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4653 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
4654 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4655 SCTP_INP_WLOCK(inp);
4656 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
4657 SCTP_INP_WUNLOCK(inp);
4659 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
4660 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4661 SCTP_INP_RLOCK(inp);
4662 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4663 SCTP_TCB_LOCK(stcb);
4664 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4665 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4667 SCTP_TCB_UNLOCK(stcb);
4669 SCTP_INP_RUNLOCK(inp);
4674 case SCTP_PEER_ADDR_PARAMS:
4676 struct sctp_paddrparams *paddrp;
4677 struct sctp_nets *net;
4679 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
4680 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
4683 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
4686 * We increment here since
4687 * sctp_findassociation_ep_addr() wil do a
4688 * decrement if it finds the stcb as long as
4689 * the locked tcb (last argument) is NOT a
4692 SCTP_INP_INCR_REF(inp);
4693 stcb = sctp_findassociation_ep_addr(&inp,
4694 (struct sockaddr *)&paddrp->spp_address,
4697 SCTP_INP_DECR_REF(inp);
4700 if (stcb && (net == NULL)) {
4701 struct sockaddr *sa;
4703 sa = (struct sockaddr *)&paddrp->spp_address;
4705 if (sa->sa_family == AF_INET) {
4707 struct sockaddr_in *sin;
4709 sin = (struct sockaddr_in *)sa;
4710 if (sin->sin_addr.s_addr) {
4711 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4712 SCTP_TCB_UNLOCK(stcb);
4719 if (sa->sa_family == AF_INET6) {
4720 struct sockaddr_in6 *sin6;
4722 sin6 = (struct sockaddr_in6 *)sa;
4723 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
4724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4725 SCTP_TCB_UNLOCK(stcb);
4732 error = EAFNOSUPPORT;
4733 SCTP_TCB_UNLOCK(stcb);
4734 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4739 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
4741 SCTP_TCB_UNLOCK(stcb);
4742 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4745 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
4747 SCTP_TCB_UNLOCK(stcb);
4748 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4752 /************************TCB SPECIFIC SET ******************/
4754 * do we change the timer for HB, we run
4759 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4760 ovh = SCTP_MED_OVERHEAD;
4762 ovh = SCTP_MED_V4_OVERHEAD;
4765 /* network sets ? */
4767 /************************NET SPECIFIC SET ******************/
4768 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4769 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
4770 !(net->dest_state & SCTP_ADDR_NOHB)) {
4771 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4772 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4774 net->dest_state |= SCTP_ADDR_NOHB;
4776 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4777 if (paddrp->spp_hbinterval) {
4778 net->heart_beat_delay = paddrp->spp_hbinterval;
4779 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4780 net->heart_beat_delay = 0;
4782 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4783 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4784 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4785 net->dest_state &= ~SCTP_ADDR_NOHB;
4787 if (paddrp->spp_flags & SPP_HB_DEMAND) {
4789 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4790 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
4791 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4793 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4794 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4795 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4796 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4798 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4799 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4800 net->mtu = paddrp->spp_pathmtu + ovh;
4801 if (net->mtu < stcb->asoc.smallest_mtu) {
4802 sctp_pathmtu_adjustment(stcb, net->mtu);
4806 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4807 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4808 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4810 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4812 if (paddrp->spp_pathmaxrxt) {
4813 if (net->dest_state & SCTP_ADDR_PF) {
4814 if (net->error_count > paddrp->spp_pathmaxrxt) {
4815 net->dest_state &= ~SCTP_ADDR_PF;
4818 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4819 (net->error_count > net->pf_threshold)) {
4820 net->dest_state |= SCTP_ADDR_PF;
4821 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4822 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4823 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4826 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4827 if (net->error_count > paddrp->spp_pathmaxrxt) {
4828 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4829 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4832 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4833 net->dest_state |= SCTP_ADDR_REACHABLE;
4834 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4837 net->failure_threshold = paddrp->spp_pathmaxrxt;
4839 if (paddrp->spp_flags & SPP_DSCP) {
4840 net->dscp = paddrp->spp_dscp & 0xfc;
4844 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4845 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4846 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4847 net->flowlabel |= 0x80000000;
4852 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
4853 if (paddrp->spp_pathmaxrxt) {
4854 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
4855 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4856 if (net->dest_state & SCTP_ADDR_PF) {
4857 if (net->error_count > paddrp->spp_pathmaxrxt) {
4858 net->dest_state &= ~SCTP_ADDR_PF;
4861 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4862 (net->error_count > net->pf_threshold)) {
4863 net->dest_state |= SCTP_ADDR_PF;
4864 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4865 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4866 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4869 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4870 if (net->error_count > paddrp->spp_pathmaxrxt) {
4871 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4872 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4875 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4876 net->dest_state |= SCTP_ADDR_REACHABLE;
4877 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4880 net->failure_threshold = paddrp->spp_pathmaxrxt;
4883 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4884 if (paddrp->spp_hbinterval) {
4885 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
4886 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4887 stcb->asoc.heart_beat_delay = 0;
4889 /* Turn back on the timer */
4890 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4891 if (paddrp->spp_hbinterval) {
4892 net->heart_beat_delay = paddrp->spp_hbinterval;
4893 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4894 net->heart_beat_delay = 0;
4896 if (net->dest_state & SCTP_ADDR_NOHB) {
4897 net->dest_state &= ~SCTP_ADDR_NOHB;
4899 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4900 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4901 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4903 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4905 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4906 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4907 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
4908 net->dest_state |= SCTP_ADDR_NOHB;
4909 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
4910 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4914 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4916 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4917 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4918 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4919 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4920 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4922 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4923 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4924 net->mtu = paddrp->spp_pathmtu + ovh;
4925 if (net->mtu < stcb->asoc.smallest_mtu) {
4926 sctp_pathmtu_adjustment(stcb, net->mtu);
4930 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4932 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4933 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4934 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4935 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4937 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4939 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4941 if (paddrp->spp_flags & SPP_DSCP) {
4942 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4943 net->dscp = paddrp->spp_dscp & 0xfc;
4946 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
4947 stcb->asoc.default_dscp |= 0x01;
4950 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4951 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4952 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4953 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4954 net->flowlabel |= 0x80000000;
4957 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4958 stcb->asoc.default_flowlabel |= 0x80000000;
4962 SCTP_TCB_UNLOCK(stcb);
4964 /************************NO TCB, SET TO default stuff ******************/
4965 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4966 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4967 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
4968 SCTP_INP_WLOCK(inp);
4970 * For the TOS/FLOWLABEL stuff you
4971 * set it with the options on the
4974 if (paddrp->spp_pathmaxrxt) {
4975 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
4977 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
4978 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4979 else if (paddrp->spp_hbinterval) {
4980 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
4981 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
4982 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4984 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4985 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4986 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4987 } else if (paddrp->spp_hbinterval) {
4988 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4990 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4991 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
4992 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4994 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4995 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4996 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
4997 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4999 if (paddrp->spp_flags & SPP_DSCP) {
5000 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5001 inp->sctp_ep.default_dscp |= 0x01;
5004 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5005 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5006 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5007 inp->sctp_ep.default_flowlabel |= 0x80000000;
5011 SCTP_INP_WUNLOCK(inp);
5013 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5021 struct sctp_rtoinfo *srto;
5022 uint32_t new_init, new_min, new_max;
5024 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5025 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5028 if (srto->srto_initial)
5029 new_init = srto->srto_initial;
5031 new_init = stcb->asoc.initial_rto;
5033 new_max = srto->srto_max;
5035 new_max = stcb->asoc.maxrto;
5037 new_min = srto->srto_min;
5039 new_min = stcb->asoc.minrto;
5040 if ((new_min <= new_init) && (new_init <= new_max)) {
5041 stcb->asoc.initial_rto = new_init;
5042 stcb->asoc.maxrto = new_max;
5043 stcb->asoc.minrto = new_min;
5045 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5048 SCTP_TCB_UNLOCK(stcb);
5050 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5051 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5052 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5053 SCTP_INP_WLOCK(inp);
5054 if (srto->srto_initial)
5055 new_init = srto->srto_initial;
5057 new_init = inp->sctp_ep.initial_rto;
5059 new_max = srto->srto_max;
5061 new_max = inp->sctp_ep.sctp_maxrto;
5063 new_min = srto->srto_min;
5065 new_min = inp->sctp_ep.sctp_minrto;
5066 if ((new_min <= new_init) && (new_init <= new_max)) {
5067 inp->sctp_ep.initial_rto = new_init;
5068 inp->sctp_ep.sctp_maxrto = new_max;
5069 inp->sctp_ep.sctp_minrto = new_min;
5071 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5074 SCTP_INP_WUNLOCK(inp);
5076 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5082 case SCTP_ASSOCINFO:
5084 struct sctp_assocparams *sasoc;
5086 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5087 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5088 if (sasoc->sasoc_cookie_life) {
5089 /* boundary check the cookie life */
5090 if (sasoc->sasoc_cookie_life < 1000)
5091 sasoc->sasoc_cookie_life = 1000;
5092 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5093 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5097 if (sasoc->sasoc_asocmaxrxt)
5098 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5099 if (sasoc->sasoc_cookie_life) {
5100 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5102 SCTP_TCB_UNLOCK(stcb);
5104 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5105 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5106 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5107 SCTP_INP_WLOCK(inp);
5108 if (sasoc->sasoc_asocmaxrxt)
5109 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5110 if (sasoc->sasoc_cookie_life) {
5111 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5113 SCTP_INP_WUNLOCK(inp);
5115 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5123 struct sctp_initmsg *sinit;
5125 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5126 SCTP_INP_WLOCK(inp);
5127 if (sinit->sinit_num_ostreams)
5128 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5130 if (sinit->sinit_max_instreams)
5131 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5133 if (sinit->sinit_max_attempts)
5134 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5136 if (sinit->sinit_max_init_timeo)
5137 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5138 SCTP_INP_WUNLOCK(inp);
5141 case SCTP_PRIMARY_ADDR:
5143 struct sctp_setprim *spa;
5144 struct sctp_nets *net;
5146 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5147 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5151 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
5154 * We increment here since
5155 * sctp_findassociation_ep_addr() wil do a
5156 * decrement if it finds the stcb as long as
5157 * the locked tcb (last argument) is NOT a
5160 SCTP_INP_INCR_REF(inp);
5161 stcb = sctp_findassociation_ep_addr(&inp,
5162 (struct sockaddr *)&spa->ssp_addr,
5165 SCTP_INP_DECR_REF(inp);
5169 if ((stcb) && (net)) {
5170 if ((net != stcb->asoc.primary_destination) &&
5171 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
5172 /* Ok we need to set it */
5173 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5174 if ((stcb->asoc.alternate) &&
5175 (!(net->dest_state & SCTP_ADDR_PF)) &&
5176 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5177 sctp_free_remote_addr(stcb->asoc.alternate);
5178 stcb->asoc.alternate = NULL;
5183 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5187 SCTP_TCB_UNLOCK(stcb);
5191 case SCTP_SET_DYNAMIC_PRIMARY:
5193 union sctp_sockstore *ss;
5195 error = priv_check(curthread,
5196 PRIV_NETINET_RESERVEDPORT);
5200 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5201 /* SUPER USER CHECK? */
5202 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5205 case SCTP_SET_PEER_PRIMARY_ADDR:
5207 struct sctp_setpeerprim *sspp;
5209 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5210 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5212 struct sctp_ifa *ifa;
5214 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
5215 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5217 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5221 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5223 * Must validate the ifa found is in
5226 struct sctp_laddr *laddr;
5229 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5230 if (laddr->ifa == NULL) {
5231 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5235 if (laddr->ifa == ifa) {
5241 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5246 if (sctp_set_primary_ip_address_sa(stcb,
5247 (struct sockaddr *)&sspp->sspp_addr) != 0) {
5248 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5252 SCTP_TCB_UNLOCK(stcb);
5254 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5259 case SCTP_BINDX_ADD_ADDR:
5261 struct sctp_getaddresses *addrs;
5265 td = (struct thread *)p;
5266 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5269 if (addrs->addr->sa_family == AF_INET) {
5270 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
5272 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5276 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5277 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5283 if (addrs->addr->sa_family == AF_INET6) {
5284 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
5286 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5290 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5291 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5292 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5298 error = EAFNOSUPPORT;
5301 sctp_bindx_add_address(so, inp, addrs->addr,
5302 addrs->sget_assoc_id, vrf_id,
5306 case SCTP_BINDX_REM_ADDR:
5308 struct sctp_getaddresses *addrs;
5312 td = (struct thread *)p;
5314 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5316 if (addrs->addr->sa_family == AF_INET) {
5317 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
5319 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5323 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5324 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5330 if (addrs->addr->sa_family == AF_INET6) {
5331 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
5333 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5338 (error = prison_local_ip6(td->td_ucred,
5339 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5340 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5341 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5347 error = EAFNOSUPPORT;
5350 sctp_bindx_delete_address(inp, addrs->addr,
5351 addrs->sget_assoc_id, vrf_id,
5357 struct sctp_event *event;
5358 uint32_t event_type;
5360 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5361 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5362 switch (event->se_type) {
5363 case SCTP_ASSOC_CHANGE:
5364 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5366 case SCTP_PEER_ADDR_CHANGE:
5367 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5369 case SCTP_REMOTE_ERROR:
5370 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5372 case SCTP_SEND_FAILED:
5373 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5375 case SCTP_SHUTDOWN_EVENT:
5376 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5378 case SCTP_ADAPTATION_INDICATION:
5379 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5381 case SCTP_PARTIAL_DELIVERY_EVENT:
5382 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5384 case SCTP_AUTHENTICATION_EVENT:
5385 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5387 case SCTP_STREAM_RESET_EVENT:
5388 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5390 case SCTP_SENDER_DRY_EVENT:
5391 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5393 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5395 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5398 case SCTP_ASSOC_RESET_EVENT:
5399 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
5401 case SCTP_STREAM_CHANGE_EVENT:
5402 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
5404 case SCTP_SEND_FAILED_EVENT:
5405 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
5409 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5413 if (event_type > 0) {
5416 sctp_stcb_feature_on(inp, stcb, event_type);
5417 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5418 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5419 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5420 (stcb->asoc.stream_queue_cnt == 0)) {
5421 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5425 sctp_stcb_feature_off(inp, stcb, event_type);
5427 SCTP_TCB_UNLOCK(stcb);
5430 * We don't want to send up a storm
5431 * of events, so return an error for
5434 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5435 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5436 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5437 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5438 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5439 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5443 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5444 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5445 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5446 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5447 SCTP_INP_WLOCK(inp);
5449 sctp_feature_on(inp, event_type);
5451 sctp_feature_off(inp, event_type);
5453 SCTP_INP_WUNLOCK(inp);
5455 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5456 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5457 SCTP_INP_RLOCK(inp);
5458 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5459 SCTP_TCB_LOCK(stcb);
5461 sctp_stcb_feature_on(inp, stcb, event_type);
5463 sctp_stcb_feature_off(inp, stcb, event_type);
5465 SCTP_TCB_UNLOCK(stcb);
5467 SCTP_INP_RUNLOCK(inp);
5473 case SCTP_RECVRCVINFO:
5477 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5478 SCTP_INP_WLOCK(inp);
5480 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5482 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5484 SCTP_INP_WUNLOCK(inp);
5487 case SCTP_RECVNXTINFO:
5491 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5492 SCTP_INP_WLOCK(inp);
5494 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5496 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5498 SCTP_INP_WUNLOCK(inp);
5501 case SCTP_DEFAULT_SNDINFO:
5503 struct sctp_sndinfo *info;
5506 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5507 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5510 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5511 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5512 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5513 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5514 stcb->asoc.def_send.sinfo_flags |= policy;
5515 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5516 stcb->asoc.def_send.sinfo_context = info->snd_context;
5518 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5521 SCTP_TCB_UNLOCK(stcb);
5523 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5524 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5525 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
5526 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5527 SCTP_INP_WLOCK(inp);
5528 inp->def_send.sinfo_stream = info->snd_sid;
5529 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
5530 inp->def_send.sinfo_flags = info->snd_flags;
5531 inp->def_send.sinfo_flags |= policy;
5532 inp->def_send.sinfo_ppid = info->snd_ppid;
5533 inp->def_send.sinfo_context = info->snd_context;
5534 SCTP_INP_WUNLOCK(inp);
5536 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
5537 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5538 SCTP_INP_RLOCK(inp);
5539 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5540 SCTP_TCB_LOCK(stcb);
5541 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5542 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5543 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5544 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5545 stcb->asoc.def_send.sinfo_flags |= policy;
5546 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5547 stcb->asoc.def_send.sinfo_context = info->snd_context;
5549 SCTP_TCB_UNLOCK(stcb);
5551 SCTP_INP_RUNLOCK(inp);
5556 case SCTP_DEFAULT_PRINFO:
5558 struct sctp_default_prinfo *info;
5560 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
5561 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
5563 if (PR_SCTP_INVALID_POLICY(info->pr_policy)) {
5564 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5569 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5570 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5571 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5572 SCTP_TCB_UNLOCK(stcb);
5574 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5575 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5576 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
5577 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5578 SCTP_INP_WLOCK(inp);
5579 inp->def_send.sinfo_flags &= 0xfff0;
5580 inp->def_send.sinfo_flags |= info->pr_policy;
5581 inp->def_send.sinfo_timetolive = info->pr_value;
5582 SCTP_INP_WUNLOCK(inp);
5584 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
5585 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5586 SCTP_INP_RLOCK(inp);
5587 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5588 SCTP_TCB_LOCK(stcb);
5589 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5590 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5591 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5592 SCTP_TCB_UNLOCK(stcb);
5594 SCTP_INP_RUNLOCK(inp);
5599 case SCTP_PEER_ADDR_THLDS:
5600 /* Applies to the specific association */
5602 struct sctp_paddrthlds *thlds;
5603 struct sctp_nets *net;
5605 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
5606 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
5609 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_assoc_id);
5612 * We increment here since
5613 * sctp_findassociation_ep_addr() wil do a
5614 * decrement if it finds the stcb as long as
5615 * the locked tcb (last argument) is NOT a
5618 SCTP_INP_INCR_REF(inp);
5619 stcb = sctp_findassociation_ep_addr(&inp,
5620 (struct sockaddr *)&thlds->spt_assoc_id,
5623 SCTP_INP_DECR_REF(inp);
5626 if (stcb && (net == NULL)) {
5627 struct sockaddr *sa;
5629 sa = (struct sockaddr *)&thlds->spt_assoc_id;
5631 if (sa->sa_family == AF_INET) {
5633 struct sockaddr_in *sin;
5635 sin = (struct sockaddr_in *)sa;
5636 if (sin->sin_addr.s_addr) {
5637 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5638 SCTP_TCB_UNLOCK(stcb);
5645 if (sa->sa_family == AF_INET6) {
5646 struct sockaddr_in6 *sin6;
5648 sin6 = (struct sockaddr_in6 *)sa;
5649 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5650 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5651 SCTP_TCB_UNLOCK(stcb);
5658 error = EAFNOSUPPORT;
5659 SCTP_TCB_UNLOCK(stcb);
5660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5666 if (net->dest_state & SCTP_ADDR_PF) {
5667 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5668 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5669 net->dest_state &= ~SCTP_ADDR_PF;
5672 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5673 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5674 net->dest_state |= SCTP_ADDR_PF;
5675 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5676 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5677 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5680 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5681 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5682 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5683 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5686 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5687 net->dest_state |= SCTP_ADDR_REACHABLE;
5688 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5691 net->failure_threshold = thlds->spt_pathmaxrxt;
5692 net->pf_threshold = thlds->spt_pathpfthld;
5694 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5695 if (net->dest_state & SCTP_ADDR_PF) {
5696 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5697 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5698 net->dest_state &= ~SCTP_ADDR_PF;
5701 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5702 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5703 net->dest_state |= SCTP_ADDR_PF;
5704 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5705 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5706 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5709 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5710 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5711 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5712 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5715 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5716 net->dest_state |= SCTP_ADDR_REACHABLE;
5717 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5720 net->failure_threshold = thlds->spt_pathmaxrxt;
5721 net->pf_threshold = thlds->spt_pathpfthld;
5723 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
5724 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
5727 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5728 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5729 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
5730 SCTP_INP_WLOCK(inp);
5731 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
5732 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
5733 SCTP_INP_WUNLOCK(inp);
5735 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5741 case SCTP_REMOTE_UDP_ENCAPS_PORT:
5743 struct sctp_udpencaps *encaps;
5744 struct sctp_nets *net;
5746 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
5747 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
5749 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
5752 * We increment here since
5753 * sctp_findassociation_ep_addr() wil do a
5754 * decrement if it finds the stcb as long as
5755 * the locked tcb (last argument) is NOT a
5759 SCTP_INP_INCR_REF(inp);
5760 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
5762 SCTP_INP_DECR_REF(inp);
5765 if (stcb && (net == NULL)) {
5766 struct sockaddr *sa;
5768 sa = (struct sockaddr *)&encaps->sue_address;
5770 if (sa->sa_family == AF_INET) {
5772 struct sockaddr_in *sin;
5774 sin = (struct sockaddr_in *)sa;
5775 if (sin->sin_addr.s_addr) {
5776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5777 SCTP_TCB_UNLOCK(stcb);
5784 if (sa->sa_family == AF_INET6) {
5785 struct sockaddr_in6 *sin6;
5787 sin6 = (struct sockaddr_in6 *)sa;
5788 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5789 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5790 SCTP_TCB_UNLOCK(stcb);
5797 error = EAFNOSUPPORT;
5798 SCTP_TCB_UNLOCK(stcb);
5799 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5805 net->port = encaps->sue_port;
5807 stcb->asoc.port = encaps->sue_port;
5809 SCTP_TCB_UNLOCK(stcb);
5811 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5812 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5813 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
5814 SCTP_INP_WLOCK(inp);
5815 inp->sctp_ep.port = encaps->sue_port;
5816 SCTP_INP_WUNLOCK(inp);
5818 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5825 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
5826 error = ENOPROTOOPT;
5828 } /* end switch (opt) */
5833 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
5835 void *optval = NULL;
5840 if (sopt->sopt_level != IPPROTO_SCTP) {
5841 /* wrong proto level... send back up to IP */
5843 if (INP_CHECK_SOCKAF(so, AF_INET6))
5844 error = ip6_ctloutput(so, sopt);
5846 #if defined(INET) && defined (INET6)
5850 error = ip_ctloutput(so, sopt);
5854 optsize = sopt->sopt_valsize;
5856 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
5857 if (optval == NULL) {
5858 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
5861 error = sooptcopyin(sopt, optval, optsize, optsize);
5863 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5867 p = (void *)sopt->sopt_td;
5868 if (sopt->sopt_dir == SOPT_SET) {
5869 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
5870 } else if (sopt->sopt_dir == SOPT_GET) {
5871 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
5873 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5876 if ((error == 0) && (optval != NULL)) {
5877 error = sooptcopyout(sopt, optval, optsize);
5878 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5879 } else if (optval != NULL) {
5880 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5888 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
5891 int create_lock_on = 0;
5893 struct sctp_inpcb *inp;
5894 struct sctp_tcb *stcb = NULL;
5896 inp = (struct sctp_inpcb *)so->so_pcb;
5898 /* I made the same as TCP since we are not setup? */
5899 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5900 return (ECONNRESET);
5903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5906 switch (addr->sa_family) {
5910 struct sockaddr_in6 *sin6p;
5912 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
5913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5916 sin6p = (struct sockaddr_in6 *)addr;
5917 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
5918 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5927 struct sockaddr_in *sinp;
5929 if (addr->sa_len != sizeof(struct sockaddr_in)) {
5930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5933 sinp = (struct sockaddr_in *)addr;
5934 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
5935 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5942 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
5943 return (EAFNOSUPPORT);
5945 SCTP_INP_INCR_REF(inp);
5946 SCTP_ASOC_CREATE_LOCK(inp);
5950 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
5951 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
5952 /* Should I really unlock ? */
5953 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
5958 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
5959 (addr->sa_family == AF_INET6)) {
5960 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5965 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
5966 SCTP_PCB_FLAGS_UNBOUND) {
5967 /* Bind a ephemeral port */
5968 error = sctp_inpcb_bind(so, NULL, NULL, p);
5973 /* Now do we connect? */
5974 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
5975 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
5976 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5980 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5981 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
5982 /* We are already connected AND the TCP model */
5983 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
5987 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
5988 SCTP_INP_RLOCK(inp);
5989 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5990 SCTP_INP_RUNLOCK(inp);
5993 * We increment here since sctp_findassociation_ep_addr()
5994 * will do a decrement if it finds the stcb as long as the
5995 * locked tcb (last argument) is NOT a TCB.. aka NULL.
5997 SCTP_INP_INCR_REF(inp);
5998 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6000 SCTP_INP_DECR_REF(inp);
6002 SCTP_TCB_UNLOCK(stcb);
6006 /* Already have or am bring up an association */
6007 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6011 vrf_id = inp->def_vrf_id;
6012 /* We are GOOD to go */
6013 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
6015 /* Gak! no memory */
6018 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6019 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6020 /* Set the connected flag so we can queue data */
6023 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6024 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6026 /* initialize authentication parameters for the assoc */
6027 sctp_initialize_auth_params(inp, stcb);
6029 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6030 SCTP_TCB_UNLOCK(stcb);
6032 if (create_lock_on) {
6033 SCTP_ASOC_CREATE_UNLOCK(inp);
6035 SCTP_INP_DECR_REF(inp);
6042 sctp_listen(struct socket *so, int backlog, struct thread *p)
6045 * Note this module depends on the protocol processing being called
6046 * AFTER any socket level flags and backlog are applied to the
6047 * socket. The traditional way that the socket flags are applied is
6048 * AFTER protocol processing. We have made a change to the
6049 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6050 * place if the socket API for SCTP is to work properly.
6054 struct sctp_inpcb *inp;
6056 inp = (struct sctp_inpcb *)so->so_pcb;
6058 /* I made the same as TCP since we are not setup? */
6059 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6060 return (ECONNRESET);
6062 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6063 /* See if we have a listener */
6064 struct sctp_inpcb *tinp;
6065 union sctp_sockstore store, *sp;
6068 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6070 struct sctp_laddr *laddr;
6072 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6073 memcpy(&store, &laddr->ifa->address, sizeof(store));
6074 switch (sp->sa.sa_family) {
6077 sp->sin.sin_port = inp->sctp_lport;
6082 sp->sin6.sin6_port = inp->sctp_lport;
6088 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6089 if (tinp && (tinp != inp) &&
6090 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6091 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6092 (tinp->sctp_socket->so_qlimit)) {
6094 * we have a listener already and
6097 SCTP_INP_DECR_REF(tinp);
6098 return (EADDRINUSE);
6100 SCTP_INP_DECR_REF(tinp);
6104 /* Setup a local addr bound all */
6105 memset(&store, 0, sizeof(store));
6106 switch (sp->sa.sa_family) {
6109 store.sin.sin_port = inp->sctp_lport;
6114 sp->sin6.sin6_port = inp->sctp_lport;
6121 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
6122 store.sa.sa_family = AF_INET6;
6123 store.sa.sa_len = sizeof(struct sockaddr_in6);
6127 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
6128 store.sa.sa_family = AF_INET;
6129 store.sa.sa_len = sizeof(struct sockaddr_in);
6132 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6133 if (tinp && (tinp != inp) &&
6134 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6135 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6136 (tinp->sctp_socket->so_qlimit)) {
6138 * we have a listener already and its not
6141 SCTP_INP_DECR_REF(tinp);
6142 return (EADDRINUSE);
6144 SCTP_INP_DECR_REF(inp);
6148 SCTP_INP_RLOCK(inp);
6149 #ifdef SCTP_LOCK_LOGGING
6150 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
6151 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
6155 error = solisten_proto_check(so);
6158 SCTP_INP_RUNLOCK(inp);
6161 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
6162 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
6164 * The unlucky case - We are in the tcp pool with this guy.
6165 * - Someone else is in the main inp slot. - We must move
6166 * this guy (the listener) to the main slot - We must then
6167 * move the guy that was listener to the TCP Pool.
6169 if (sctp_swap_inpcb_for_listen(inp)) {
6173 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6174 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6175 /* We are already connected AND the TCP model */
6177 SCTP_INP_RUNLOCK(inp);
6179 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6180 return (EADDRINUSE);
6182 SCTP_INP_RUNLOCK(inp);
6183 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
6184 /* We must do a bind. */
6186 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
6187 /* bind error, probably perm */
6192 /* It appears for 7.0 and on, we must always call this. */
6193 solisten_proto(so, backlog);
6194 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6195 /* remove the ACCEPTCONN flag for one-to-many sockets */
6196 so->so_options &= ~SO_ACCEPTCONN;
6199 /* turning off listen */
6200 so->so_options &= ~SO_ACCEPTCONN;
6206 static int sctp_defered_wakeup_cnt = 0;
6209 sctp_accept(struct socket *so, struct sockaddr **addr)
6211 struct sctp_tcb *stcb;
6212 struct sctp_inpcb *inp;
6213 union sctp_sockstore store;
6219 inp = (struct sctp_inpcb *)so->so_pcb;
6222 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6223 return (ECONNRESET);
6225 SCTP_INP_RLOCK(inp);
6226 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6227 SCTP_INP_RUNLOCK(inp);
6228 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
6229 return (EOPNOTSUPP);
6231 if (so->so_state & SS_ISDISCONNECTED) {
6232 SCTP_INP_RUNLOCK(inp);
6233 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
6234 return (ECONNABORTED);
6236 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6238 SCTP_INP_RUNLOCK(inp);
6239 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6240 return (ECONNRESET);
6242 SCTP_TCB_LOCK(stcb);
6243 SCTP_INP_RUNLOCK(inp);
6244 store = stcb->asoc.primary_destination->ro._l_addr;
6245 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
6246 SCTP_TCB_UNLOCK(stcb);
6247 switch (store.sa.sa_family) {
6251 struct sockaddr_in *sin;
6253 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6256 sin->sin_family = AF_INET;
6257 sin->sin_len = sizeof(*sin);
6258 sin->sin_port = ((struct sockaddr_in *)&store)->sin_port;
6259 sin->sin_addr = ((struct sockaddr_in *)&store)->sin_addr;
6260 *addr = (struct sockaddr *)sin;
6267 struct sockaddr_in6 *sin6;
6269 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
6272 sin6->sin6_family = AF_INET6;
6273 sin6->sin6_len = sizeof(*sin6);
6274 sin6->sin6_port = ((struct sockaddr_in6 *)&store)->sin6_port;
6276 sin6->sin6_addr = ((struct sockaddr_in6 *)&store)->sin6_addr;
6277 if ((error = sa6_recoverscope(sin6)) != 0) {
6278 SCTP_FREE_SONAME(sin6);
6281 *addr = (struct sockaddr *)sin6;
6289 /* Wake any delayed sleep action */
6290 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
6291 SCTP_INP_WLOCK(inp);
6292 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
6293 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
6294 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
6295 SCTP_INP_WUNLOCK(inp);
6296 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
6297 if (sowriteable(inp->sctp_socket)) {
6298 sowwakeup_locked(inp->sctp_socket);
6300 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
6302 SCTP_INP_WLOCK(inp);
6304 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
6305 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
6306 SCTP_INP_WUNLOCK(inp);
6307 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
6308 if (soreadable(inp->sctp_socket)) {
6309 sctp_defered_wakeup_cnt++;
6310 sorwakeup_locked(inp->sctp_socket);
6312 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
6314 SCTP_INP_WLOCK(inp);
6316 SCTP_INP_WUNLOCK(inp);
6318 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
6319 SCTP_TCB_LOCK(stcb);
6320 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
6327 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
6329 struct sockaddr_in *sin;
6331 struct sctp_inpcb *inp;
6332 struct sctp_ifa *sctp_ifa;
6335 * Do the malloc first in case it blocks.
6337 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6340 sin->sin_family = AF_INET;
6341 sin->sin_len = sizeof(*sin);
6342 inp = (struct sctp_inpcb *)so->so_pcb;
6344 SCTP_FREE_SONAME(sin);
6345 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6346 return (ECONNRESET);
6348 SCTP_INP_RLOCK(inp);
6349 sin->sin_port = inp->sctp_lport;
6350 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
6351 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6352 struct sctp_tcb *stcb;
6353 struct sockaddr_in *sin_a;
6354 struct sctp_nets *net;
6357 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6363 SCTP_TCB_LOCK(stcb);
6364 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6365 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6367 /* this will make coverity happy */
6370 if (sin_a->sin_family == AF_INET) {
6375 if ((!fnd) || (sin_a == NULL)) {
6377 SCTP_TCB_UNLOCK(stcb);
6380 vrf_id = inp->def_vrf_id;
6381 sctp_ifa = sctp_source_address_selection(inp,
6383 (sctp_route_t *) & net->ro,
6386 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
6387 sctp_free_ifa(sctp_ifa);
6389 SCTP_TCB_UNLOCK(stcb);
6391 /* For the bound all case you get back 0 */
6393 sin->sin_addr.s_addr = 0;
6397 /* Take the first IPv4 address in the list */
6398 struct sctp_laddr *laddr;
6401 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6402 if (laddr->ifa->address.sa.sa_family == AF_INET) {
6403 struct sockaddr_in *sin_a;
6405 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
6406 sin->sin_addr = sin_a->sin_addr;
6412 SCTP_FREE_SONAME(sin);
6413 SCTP_INP_RUNLOCK(inp);
6414 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6418 SCTP_INP_RUNLOCK(inp);
6419 (*addr) = (struct sockaddr *)sin;
6424 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
6426 struct sockaddr_in *sin;
6428 struct sockaddr_in *sin_a;
6429 struct sctp_inpcb *inp;
6430 struct sctp_tcb *stcb;
6431 struct sctp_nets *net;
6433 /* Do the malloc first in case it blocks. */
6434 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6437 sin->sin_family = AF_INET;
6438 sin->sin_len = sizeof(*sin);
6440 inp = (struct sctp_inpcb *)so->so_pcb;
6441 if ((inp == NULL) ||
6442 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
6443 /* UDP type and listeners will drop out here */
6444 SCTP_FREE_SONAME(sin);
6445 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
6448 SCTP_INP_RLOCK(inp);
6449 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6451 SCTP_TCB_LOCK(stcb);
6453 SCTP_INP_RUNLOCK(inp);
6455 SCTP_FREE_SONAME(sin);
6456 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6457 return (ECONNRESET);
6460 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6461 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6462 if (sin_a->sin_family == AF_INET) {
6464 sin->sin_port = stcb->rport;
6465 sin->sin_addr = sin_a->sin_addr;
6469 SCTP_TCB_UNLOCK(stcb);
6471 /* No IPv4 address */
6472 SCTP_FREE_SONAME(sin);
6473 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6476 (*addr) = (struct sockaddr *)sin;
6481 struct pr_usrreqs sctp_usrreqs = {
6482 .pru_abort = sctp_abort,
6483 .pru_accept = sctp_accept,
6484 .pru_attach = sctp_attach,
6485 .pru_bind = sctp_bind,
6486 .pru_connect = sctp_connect,
6487 .pru_control = in_control,
6488 .pru_close = sctp_close,
6489 .pru_detach = sctp_close,
6490 .pru_sopoll = sopoll_generic,
6491 .pru_flush = sctp_flush,
6492 .pru_disconnect = sctp_disconnect,
6493 .pru_listen = sctp_listen,
6494 .pru_peeraddr = sctp_peeraddr,
6495 .pru_send = sctp_sendm,
6496 .pru_shutdown = sctp_shutdown,
6497 .pru_sockaddr = sctp_ingetaddr,
6498 .pru_sosend = sctp_sosend,
6499 .pru_soreceive = sctp_soreceive