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,
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:
2057 SCTP_CHECK_AND_CAST(value, optval, uint8_t, *optsize);
2059 SCTP_INP_RLOCK(inp);
2060 if (inp->sctp_ep.max_burst < 256) {
2061 *value = inp->sctp_ep.max_burst;
2065 SCTP_INP_RUNLOCK(inp);
2066 *optsize = sizeof(uint8_t);
2071 struct sctp_assoc_value *av;
2074 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2075 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2078 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2079 SCTP_TCB_UNLOCK(stcb);
2081 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2082 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2083 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2084 SCTP_INP_RLOCK(inp);
2085 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2086 ovh = SCTP_MED_OVERHEAD;
2088 ovh = SCTP_MED_V4_OVERHEAD;
2090 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2091 av->assoc_value = 0;
2093 av->assoc_value = inp->sctp_frag_point - ovh;
2094 SCTP_INP_RUNLOCK(inp);
2096 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2101 *optsize = sizeof(struct sctp_assoc_value);
2105 case SCTP_GET_STAT_LOG:
2106 error = sctp_fill_stat_log(optval, optsize);
2110 struct sctp_event_subscribe *events;
2112 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2113 memset(events, 0, sizeof(struct sctp_event_subscribe));
2114 SCTP_INP_RLOCK(inp);
2115 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2116 events->sctp_data_io_event = 1;
2118 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2119 events->sctp_association_event = 1;
2121 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2122 events->sctp_address_event = 1;
2124 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2125 events->sctp_send_failure_event = 1;
2127 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2128 events->sctp_peer_error_event = 1;
2130 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2131 events->sctp_shutdown_event = 1;
2133 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2134 events->sctp_partial_delivery_event = 1;
2136 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2137 events->sctp_adaptation_layer_event = 1;
2139 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2140 events->sctp_authentication_event = 1;
2142 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2143 events->sctp_sender_dry_event = 1;
2145 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2146 events->sctp_stream_reset_event = 1;
2147 SCTP_INP_RUNLOCK(inp);
2148 *optsize = sizeof(struct sctp_event_subscribe);
2151 case SCTP_ADAPTATION_LAYER:
2155 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2157 SCTP_INP_RLOCK(inp);
2158 *value = inp->sctp_ep.adaptation_layer_indicator;
2159 SCTP_INP_RUNLOCK(inp);
2160 *optsize = sizeof(uint32_t);
2163 case SCTP_SET_INITIAL_DBG_SEQ:
2167 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2168 SCTP_INP_RLOCK(inp);
2169 *value = inp->sctp_ep.initial_sequence_debug;
2170 SCTP_INP_RUNLOCK(inp);
2171 *optsize = sizeof(uint32_t);
2174 case SCTP_GET_LOCAL_ADDR_SIZE:
2178 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2179 SCTP_INP_RLOCK(inp);
2180 *value = sctp_count_max_addresses(inp);
2181 SCTP_INP_RUNLOCK(inp);
2182 *optsize = sizeof(uint32_t);
2185 case SCTP_GET_REMOTE_ADDR_SIZE:
2189 struct sctp_nets *net;
2191 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2192 /* FIXME MT: change to sctp_assoc_value? */
2193 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2197 /* Count the sizes */
2198 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2199 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2200 size += sizeof(struct sockaddr_in6);
2202 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2205 size += sizeof(struct sockaddr_in);
2210 size += sizeof(struct sockaddr_in6);
2218 SCTP_TCB_UNLOCK(stcb);
2219 *value = (uint32_t) size;
2220 *optsize = sizeof(uint32_t);
2222 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2227 case SCTP_GET_PEER_ADDRESSES:
2229 * Get the address information, an array is passed in to
2230 * fill up we pack it.
2234 struct sockaddr_storage *sas;
2235 struct sctp_nets *net;
2236 struct sctp_getaddresses *saddr;
2238 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2239 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2242 left = (*optsize) - sizeof(struct sctp_getaddresses);
2243 *optsize = sizeof(struct sctp_getaddresses);
2244 sas = (struct sockaddr_storage *)&saddr->addr[0];
2246 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2247 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2248 cpsz = sizeof(struct sockaddr_in6);
2250 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2253 cpsz = sizeof(struct sockaddr_in);
2258 cpsz = sizeof(struct sockaddr_in6);
2270 /* not enough room. */
2273 #if defined(INET) && defined(INET6)
2274 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2275 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2276 /* Must map the address */
2277 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2278 (struct sockaddr_in6 *)sas);
2281 memcpy(sas, &net->ro._l_addr, cpsz);
2282 #if defined(INET) && defined(INET6)
2285 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2287 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2291 SCTP_TCB_UNLOCK(stcb);
2293 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2298 case SCTP_GET_LOCAL_ADDRESSES:
2300 size_t limit, actual;
2301 struct sockaddr_storage *sas;
2302 struct sctp_getaddresses *saddr;
2304 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2305 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2307 sas = (struct sockaddr_storage *)&saddr->addr[0];
2308 limit = *optsize - sizeof(sctp_assoc_t);
2309 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2311 SCTP_TCB_UNLOCK(stcb);
2313 *optsize = sizeof(struct sockaddr_storage) + actual;
2316 case SCTP_PEER_ADDR_PARAMS:
2318 struct sctp_paddrparams *paddrp;
2319 struct sctp_nets *net;
2321 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2322 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2326 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2329 * We increment here since
2330 * sctp_findassociation_ep_addr() wil do a
2331 * decrement if it finds the stcb as long as
2332 * the locked tcb (last argument) is NOT a
2335 SCTP_INP_INCR_REF(inp);
2336 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2338 SCTP_INP_DECR_REF(inp);
2341 if (stcb && (net == NULL)) {
2342 struct sockaddr *sa;
2344 sa = (struct sockaddr *)&paddrp->spp_address;
2346 if (sa->sa_family == AF_INET) {
2347 struct sockaddr_in *sin;
2349 sin = (struct sockaddr_in *)sa;
2350 if (sin->sin_addr.s_addr) {
2352 SCTP_TCB_UNLOCK(stcb);
2353 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2359 if (sa->sa_family == AF_INET6) {
2360 struct sockaddr_in6 *sin6;
2362 sin6 = (struct sockaddr_in6 *)sa;
2363 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2365 SCTP_TCB_UNLOCK(stcb);
2366 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2372 error = EAFNOSUPPORT;
2373 SCTP_TCB_UNLOCK(stcb);
2374 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2379 /* Applies to the specific association */
2380 paddrp->spp_flags = 0;
2384 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2385 ovh = SCTP_MED_OVERHEAD;
2387 ovh = SCTP_MED_V4_OVERHEAD;
2390 paddrp->spp_hbinterval = net->heart_beat_delay;
2391 paddrp->spp_pathmaxrxt = net->failure_threshold;
2392 paddrp->spp_pathmtu = net->mtu - ovh;
2393 /* get flags for HB */
2394 if (net->dest_state & SCTP_ADDR_NOHB) {
2395 paddrp->spp_flags |= SPP_HB_DISABLE;
2397 paddrp->spp_flags |= SPP_HB_ENABLE;
2399 /* get flags for PMTU */
2400 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2401 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2403 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2405 if (net->dscp & 0x01) {
2406 paddrp->spp_dscp = net->dscp & 0xfc;
2407 paddrp->spp_flags |= SPP_DSCP;
2410 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2411 (net->flowlabel & 0x80000000)) {
2412 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2413 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2418 * No destination so return default
2421 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2422 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2423 if (stcb->asoc.default_dscp & 0x01) {
2424 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2425 paddrp->spp_flags |= SPP_DSCP;
2428 if (stcb->asoc.default_flowlabel & 0x80000000) {
2429 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2430 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2433 /* default settings should be these */
2434 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2435 paddrp->spp_flags |= SPP_HB_DISABLE;
2437 paddrp->spp_flags |= SPP_HB_ENABLE;
2439 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2440 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2442 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2444 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2446 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2447 SCTP_TCB_UNLOCK(stcb);
2449 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2450 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2451 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2452 /* Use endpoint defaults */
2453 SCTP_INP_RLOCK(inp);
2454 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2455 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2456 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2457 /* get inp's default */
2458 if (inp->sctp_ep.default_dscp & 0x01) {
2459 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2460 paddrp->spp_flags |= SPP_DSCP;
2463 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2464 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2465 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2466 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2469 /* can't return this */
2470 paddrp->spp_pathmtu = 0;
2472 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2473 paddrp->spp_flags |= SPP_HB_ENABLE;
2475 paddrp->spp_flags |= SPP_HB_DISABLE;
2477 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2478 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2480 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2482 SCTP_INP_RUNLOCK(inp);
2484 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2489 *optsize = sizeof(struct sctp_paddrparams);
2493 case SCTP_GET_PEER_ADDR_INFO:
2495 struct sctp_paddrinfo *paddri;
2496 struct sctp_nets *net;
2498 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2499 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2503 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
2506 * We increment here since
2507 * sctp_findassociation_ep_addr() wil do a
2508 * decrement if it finds the stcb as long as
2509 * the locked tcb (last argument) is NOT a
2512 SCTP_INP_INCR_REF(inp);
2513 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
2515 SCTP_INP_DECR_REF(inp);
2519 if ((stcb) && (net)) {
2520 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2521 /* It's unconfirmed */
2522 paddri->spinfo_state = SCTP_UNCONFIRMED;
2523 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2525 paddri->spinfo_state = SCTP_ACTIVE;
2528 paddri->spinfo_state = SCTP_INACTIVE;
2530 paddri->spinfo_cwnd = net->cwnd;
2531 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2532 paddri->spinfo_rto = net->RTO;
2533 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2534 paddri->spinfo_mtu = net->mtu;
2535 SCTP_TCB_UNLOCK(stcb);
2536 *optsize = sizeof(struct sctp_paddrinfo);
2539 SCTP_TCB_UNLOCK(stcb);
2541 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2546 case SCTP_PCB_STATUS:
2548 struct sctp_pcbinfo *spcb;
2550 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2551 sctp_fill_pcbinfo(spcb);
2552 *optsize = sizeof(struct sctp_pcbinfo);
2557 struct sctp_nets *net;
2558 struct sctp_status *sstat;
2560 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2561 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2564 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2569 * I think passing the state is fine since
2570 * sctp_constants.h will be available to the user
2573 sstat->sstat_state = stcb->asoc.state;
2574 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2575 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2576 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2578 * We can't include chunks that have been passed to
2579 * the socket layer. Only things in queue.
2581 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2582 stcb->asoc.cnt_on_all_streams);
2585 sstat->sstat_instrms = stcb->asoc.streamincnt;
2586 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2587 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2588 memcpy(&sstat->sstat_primary.spinfo_address,
2589 &stcb->asoc.primary_destination->ro._l_addr,
2590 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2591 net = stcb->asoc.primary_destination;
2592 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2594 * Again the user can get info from sctp_constants.h
2595 * for what the state of the network is.
2597 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2598 /* It's unconfirmed */
2599 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2600 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2602 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2605 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2607 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2608 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2609 sstat->sstat_primary.spinfo_rto = net->RTO;
2610 sstat->sstat_primary.spinfo_mtu = net->mtu;
2611 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2612 SCTP_TCB_UNLOCK(stcb);
2613 *optsize = sizeof(struct sctp_status);
2618 struct sctp_rtoinfo *srto;
2620 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2621 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2624 srto->srto_initial = stcb->asoc.initial_rto;
2625 srto->srto_max = stcb->asoc.maxrto;
2626 srto->srto_min = stcb->asoc.minrto;
2627 SCTP_TCB_UNLOCK(stcb);
2629 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2630 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2631 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2632 SCTP_INP_RLOCK(inp);
2633 srto->srto_initial = inp->sctp_ep.initial_rto;
2634 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2635 srto->srto_min = inp->sctp_ep.sctp_minrto;
2636 SCTP_INP_RUNLOCK(inp);
2638 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2643 *optsize = sizeof(struct sctp_rtoinfo);
2649 struct sctp_timeouts *stimo;
2651 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2652 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2655 stimo->stimo_init = stcb->asoc.timoinit;
2656 stimo->stimo_data = stcb->asoc.timodata;
2657 stimo->stimo_sack = stcb->asoc.timosack;
2658 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2659 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2660 stimo->stimo_cookie = stcb->asoc.timocookie;
2661 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2662 SCTP_TCB_UNLOCK(stcb);
2663 *optsize = sizeof(struct sctp_timeouts);
2665 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2670 case SCTP_ASSOCINFO:
2672 struct sctp_assocparams *sasoc;
2674 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2675 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2678 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2679 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2680 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2681 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2682 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2683 SCTP_TCB_UNLOCK(stcb);
2685 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2686 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2687 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2688 SCTP_INP_RLOCK(inp);
2689 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2690 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2691 sasoc->sasoc_number_peer_destinations = 0;
2692 sasoc->sasoc_peer_rwnd = 0;
2693 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2694 SCTP_INP_RUNLOCK(inp);
2696 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2701 *optsize = sizeof(struct sctp_assocparams);
2705 case SCTP_DEFAULT_SEND_PARAM:
2707 struct sctp_sndrcvinfo *s_info;
2709 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2710 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2713 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2714 SCTP_TCB_UNLOCK(stcb);
2716 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2717 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2718 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2719 SCTP_INP_RLOCK(inp);
2720 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2721 SCTP_INP_RUNLOCK(inp);
2723 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2728 *optsize = sizeof(struct sctp_sndrcvinfo);
2734 struct sctp_initmsg *sinit;
2736 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2737 SCTP_INP_RLOCK(inp);
2738 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2739 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2740 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2741 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2742 SCTP_INP_RUNLOCK(inp);
2743 *optsize = sizeof(struct sctp_initmsg);
2746 case SCTP_PRIMARY_ADDR:
2747 /* we allow a "get" operation on this */
2749 struct sctp_setprim *ssp;
2751 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2752 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2755 /* simply copy out the sockaddr_storage... */
2759 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
2760 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
2762 memcpy(&ssp->ssp_addr,
2763 &stcb->asoc.primary_destination->ro._l_addr,
2765 SCTP_TCB_UNLOCK(stcb);
2766 *optsize = sizeof(struct sctp_setprim);
2768 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2773 case SCTP_HMAC_IDENT:
2775 struct sctp_hmacalgo *shmac;
2776 sctp_hmaclist_t *hmaclist;
2780 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2782 SCTP_INP_RLOCK(inp);
2783 hmaclist = inp->sctp_ep.local_hmacs;
2784 if (hmaclist == NULL) {
2785 /* no HMACs to return */
2786 *optsize = sizeof(*shmac);
2787 SCTP_INP_RUNLOCK(inp);
2790 /* is there room for all of the hmac ids? */
2791 size = sizeof(*shmac) + (hmaclist->num_algo *
2792 sizeof(shmac->shmac_idents[0]));
2793 if ((size_t)(*optsize) < size) {
2794 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2796 SCTP_INP_RUNLOCK(inp);
2799 /* copy in the list */
2800 shmac->shmac_number_of_idents = hmaclist->num_algo;
2801 for (i = 0; i < hmaclist->num_algo; i++) {
2802 shmac->shmac_idents[i] = hmaclist->hmac[i];
2804 SCTP_INP_RUNLOCK(inp);
2808 case SCTP_AUTH_ACTIVE_KEY:
2810 struct sctp_authkeyid *scact;
2812 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2813 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2816 /* get the active key on the assoc */
2817 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2818 SCTP_TCB_UNLOCK(stcb);
2820 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2821 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2822 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2823 /* get the endpoint active key */
2824 SCTP_INP_RLOCK(inp);
2825 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2826 SCTP_INP_RUNLOCK(inp);
2828 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2833 *optsize = sizeof(struct sctp_authkeyid);
2837 case SCTP_LOCAL_AUTH_CHUNKS:
2839 struct sctp_authchunks *sac;
2840 sctp_auth_chklist_t *chklist = NULL;
2843 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2844 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2847 /* get off the assoc */
2848 chklist = stcb->asoc.local_auth_chunks;
2849 /* is there enough space? */
2850 size = sctp_auth_get_chklist_size(chklist);
2851 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2853 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2855 /* copy in the chunks */
2856 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2857 sac->gauth_number_of_chunks = (uint32_t) size;
2858 *optsize = sizeof(struct sctp_authchunks) + size;
2860 SCTP_TCB_UNLOCK(stcb);
2862 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2863 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2864 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2865 /* get off the endpoint */
2866 SCTP_INP_RLOCK(inp);
2867 chklist = inp->sctp_ep.local_auth_chunks;
2868 /* is there enough space? */
2869 size = sctp_auth_get_chklist_size(chklist);
2870 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2874 /* copy in the chunks */
2875 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2876 sac->gauth_number_of_chunks = (uint32_t) size;
2877 *optsize = sizeof(struct sctp_authchunks) + size;
2879 SCTP_INP_RUNLOCK(inp);
2881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2887 case SCTP_PEER_AUTH_CHUNKS:
2889 struct sctp_authchunks *sac;
2890 sctp_auth_chklist_t *chklist = NULL;
2893 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2894 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2897 /* get off the assoc */
2898 chklist = stcb->asoc.peer_auth_chunks;
2899 /* is there enough space? */
2900 size = sctp_auth_get_chklist_size(chklist);
2901 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2905 /* copy in the chunks */
2906 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2907 sac->gauth_number_of_chunks = (uint32_t) size;
2908 *optsize = sizeof(struct sctp_authchunks) + size;
2910 SCTP_TCB_UNLOCK(stcb);
2912 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2919 struct sctp_event *event;
2920 uint32_t event_type;
2922 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2923 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2925 switch (event->se_type) {
2926 case SCTP_ASSOC_CHANGE:
2927 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2929 case SCTP_PEER_ADDR_CHANGE:
2930 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
2932 case SCTP_REMOTE_ERROR:
2933 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
2935 case SCTP_SEND_FAILED:
2936 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
2938 case SCTP_SHUTDOWN_EVENT:
2939 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
2941 case SCTP_ADAPTATION_INDICATION:
2942 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
2944 case SCTP_PARTIAL_DELIVERY_EVENT:
2945 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
2947 case SCTP_AUTHENTICATION_EVENT:
2948 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
2950 case SCTP_STREAM_RESET_EVENT:
2951 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
2953 case SCTP_SENDER_DRY_EVENT:
2954 event_type = SCTP_PCB_FLAGS_DRYEVNT;
2956 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
2958 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
2961 case SCTP_ASSOC_RESET_EVENT:
2962 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
2964 case SCTP_STREAM_CHANGE_EVENT:
2965 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
2967 case SCTP_SEND_FAILED_EVENT:
2968 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
2972 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2976 if (event_type > 0) {
2978 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
2979 SCTP_TCB_UNLOCK(stcb);
2981 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2982 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2983 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
2984 SCTP_INP_RLOCK(inp);
2985 event->se_on = sctp_is_feature_on(inp, event_type);
2986 SCTP_INP_RUNLOCK(inp);
2988 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2994 *optsize = sizeof(struct sctp_event);
2998 case SCTP_RECVRCVINFO:
3002 if (*optsize < sizeof(int)) {
3003 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3006 SCTP_INP_RLOCK(inp);
3007 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3008 SCTP_INP_RUNLOCK(inp);
3011 /* return the option value */
3012 *(int *)optval = onoff;
3013 *optsize = sizeof(int);
3017 case SCTP_RECVNXTINFO:
3021 if (*optsize < sizeof(int)) {
3022 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3025 SCTP_INP_RLOCK(inp);
3026 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3027 SCTP_INP_RUNLOCK(inp);
3030 /* return the option value */
3031 *(int *)optval = onoff;
3032 *optsize = sizeof(int);
3036 case SCTP_DEFAULT_SNDINFO:
3038 struct sctp_sndinfo *info;
3040 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3041 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3044 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3045 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3046 info->snd_flags &= 0xfff0;
3047 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3048 info->snd_context = stcb->asoc.def_send.sinfo_context;
3049 SCTP_TCB_UNLOCK(stcb);
3051 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3052 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3053 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3054 SCTP_INP_RLOCK(inp);
3055 info->snd_sid = inp->def_send.sinfo_stream;
3056 info->snd_flags = inp->def_send.sinfo_flags;
3057 info->snd_flags &= 0xfff0;
3058 info->snd_ppid = inp->def_send.sinfo_ppid;
3059 info->snd_context = inp->def_send.sinfo_context;
3060 SCTP_INP_RUNLOCK(inp);
3062 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3067 *optsize = sizeof(struct sctp_sndinfo);
3071 case SCTP_DEFAULT_PRINFO:
3073 struct sctp_default_prinfo *info;
3075 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3076 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3079 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3080 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3081 SCTP_TCB_UNLOCK(stcb);
3083 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3084 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3085 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3086 SCTP_INP_RLOCK(inp);
3087 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3088 info->pr_value = inp->def_send.sinfo_timetolive;
3089 SCTP_INP_RUNLOCK(inp);
3091 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3096 *optsize = sizeof(struct sctp_default_prinfo);
3100 case SCTP_PEER_ADDR_THLDS:
3102 struct sctp_paddrthlds *thlds;
3103 struct sctp_nets *net;
3105 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3106 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3110 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
3113 * We increment here since
3114 * sctp_findassociation_ep_addr() wil do a
3115 * decrement if it finds the stcb as long as
3116 * the locked tcb (last argument) is NOT a
3119 SCTP_INP_INCR_REF(inp);
3120 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL);
3122 SCTP_INP_DECR_REF(inp);
3125 if (stcb && (net == NULL)) {
3126 struct sockaddr *sa;
3128 sa = (struct sockaddr *)&thlds->spt_address;
3130 if (sa->sa_family == AF_INET) {
3131 struct sockaddr_in *sin;
3133 sin = (struct sockaddr_in *)sa;
3134 if (sin->sin_addr.s_addr) {
3136 SCTP_TCB_UNLOCK(stcb);
3137 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3143 if (sa->sa_family == AF_INET6) {
3144 struct sockaddr_in6 *sin6;
3146 sin6 = (struct sockaddr_in6 *)sa;
3147 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3149 SCTP_TCB_UNLOCK(stcb);
3150 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3156 error = EAFNOSUPPORT;
3157 SCTP_TCB_UNLOCK(stcb);
3158 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3164 thlds->spt_pathmaxrxt = net->failure_threshold;
3165 thlds->spt_pathpfthld = net->pf_threshold;
3167 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3168 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3170 thlds->spt_assoc_id = sctp_get_associd(stcb);
3171 SCTP_TCB_UNLOCK(stcb);
3173 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3174 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3175 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3176 /* Use endpoint defaults */
3177 SCTP_INP_RLOCK(inp);
3178 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3179 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3180 SCTP_INP_RUNLOCK(inp);
3182 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3187 *optsize = sizeof(struct sctp_paddrthlds);
3191 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3193 struct sctp_udpencaps *encaps;
3194 struct sctp_nets *net;
3196 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3197 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3200 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
3203 * We increment here since
3204 * sctp_findassociation_ep_addr() wil do a
3205 * decrement if it finds the stcb as long as
3206 * the locked tcb (last argument) is NOT a
3210 SCTP_INP_INCR_REF(inp);
3211 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
3213 SCTP_INP_DECR_REF(inp);
3216 if (stcb && (net == NULL)) {
3217 struct sockaddr *sa;
3219 sa = (struct sockaddr *)&encaps->sue_address;
3221 if (sa->sa_family == AF_INET) {
3222 struct sockaddr_in *sin;
3224 sin = (struct sockaddr_in *)sa;
3225 if (sin->sin_addr.s_addr) {
3227 SCTP_TCB_UNLOCK(stcb);
3228 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3234 if (sa->sa_family == AF_INET6) {
3235 struct sockaddr_in6 *sin6;
3237 sin6 = (struct sockaddr_in6 *)sa;
3238 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3240 SCTP_TCB_UNLOCK(stcb);
3241 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3247 error = EAFNOSUPPORT;
3248 SCTP_TCB_UNLOCK(stcb);
3249 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3255 encaps->sue_port = net->port;
3257 encaps->sue_port = stcb->asoc.port;
3259 SCTP_TCB_UNLOCK(stcb);
3261 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3262 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3263 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3264 SCTP_INP_RLOCK(inp);
3265 encaps->sue_port = inp->sctp_ep.port;
3266 SCTP_INP_RUNLOCK(inp);
3268 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3273 *optsize = sizeof(struct sctp_paddrparams);
3277 case SCTP_ENABLE_STREAM_RESET:
3279 struct sctp_assoc_value *av;
3281 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3282 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3285 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3286 SCTP_TCB_UNLOCK(stcb);
3288 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3289 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3290 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3291 SCTP_INP_RLOCK(inp);
3292 av->assoc_value = (uint32_t) inp->local_strreset_support;
3293 SCTP_INP_RUNLOCK(inp);
3295 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3300 *optsize = sizeof(struct sctp_assoc_value);
3305 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3306 error = ENOPROTOOPT;
3308 } /* end switch (sopt->sopt_name) */
3316 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3321 struct sctp_tcb *stcb = NULL;
3322 struct sctp_inpcb *inp = NULL;
3325 if (optval == NULL) {
3326 SCTP_PRINTF("optval is NULL\n");
3327 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3330 inp = (struct sctp_inpcb *)so->so_pcb;
3332 SCTP_PRINTF("inp is NULL?\n");
3333 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3336 vrf_id = inp->def_vrf_id;
3341 case SCTP_AUTOCLOSE:
3342 case SCTP_AUTO_ASCONF:
3343 case SCTP_EXPLICIT_EOR:
3344 case SCTP_DISABLE_FRAGMENTS:
3345 case SCTP_USE_EXT_RCVINFO:
3346 case SCTP_I_WANT_MAPPED_V4_ADDR:
3347 /* copy in the option value */
3348 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3353 case SCTP_DISABLE_FRAGMENTS:
3354 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3356 case SCTP_AUTO_ASCONF:
3358 * NOTE: we don't really support this flag
3360 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3361 /* only valid for bound all sockets */
3362 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3364 /* forbidden by admin */
3365 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3368 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3374 case SCTP_EXPLICIT_EOR:
3375 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3377 case SCTP_USE_EXT_RCVINFO:
3378 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3380 case SCTP_I_WANT_MAPPED_V4_ADDR:
3381 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3382 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3384 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3389 set_opt = SCTP_PCB_FLAGS_NODELAY;
3391 case SCTP_AUTOCLOSE:
3392 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3393 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3394 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3397 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3399 * The value is in ticks. Note this does not effect
3400 * old associations, only new ones.
3402 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3405 SCTP_INP_WLOCK(inp);
3407 sctp_feature_on(inp, set_opt);
3409 sctp_feature_off(inp, set_opt);
3411 SCTP_INP_WUNLOCK(inp);
3413 case SCTP_REUSE_PORT:
3415 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3416 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3417 /* Can't set it after we are bound */
3421 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3422 /* Can't do this for a 1-m socket */
3427 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3429 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3432 case SCTP_PARTIAL_DELIVERY_POINT:
3436 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3437 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3438 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3442 inp->partial_delivery_point = *value;
3445 case SCTP_FRAGMENT_INTERLEAVE:
3446 /* not yet until we re-write sctp_recvmsg() */
3450 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3451 if (*level == SCTP_FRAG_LEVEL_2) {
3452 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3453 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3454 } else if (*level == SCTP_FRAG_LEVEL_1) {
3455 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3456 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3457 } else if (*level == SCTP_FRAG_LEVEL_0) {
3458 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3459 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3462 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3467 case SCTP_CMT_ON_OFF:
3468 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3469 struct sctp_assoc_value *av;
3471 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3472 if (av->assoc_value > SCTP_CMT_MAX) {
3473 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3477 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3479 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3480 SCTP_TCB_UNLOCK(stcb);
3482 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3483 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3484 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3485 (av->assoc_id == SCTP_ALL_ASSOC)) {
3486 SCTP_INP_WLOCK(inp);
3487 inp->sctp_cmt_on_off = av->assoc_value;
3488 SCTP_INP_WUNLOCK(inp);
3490 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3491 (av->assoc_id == SCTP_ALL_ASSOC)) {
3492 SCTP_INP_RLOCK(inp);
3493 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3494 SCTP_TCB_LOCK(stcb);
3495 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3496 SCTP_TCB_UNLOCK(stcb);
3498 SCTP_INP_RUNLOCK(inp);
3502 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3503 error = ENOPROTOOPT;
3506 case SCTP_PLUGGABLE_CC:
3508 struct sctp_assoc_value *av;
3509 struct sctp_nets *net;
3511 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3512 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3513 (av->assoc_value != SCTP_CC_HSTCP) &&
3514 (av->assoc_value != SCTP_CC_HTCP) &&
3515 (av->assoc_value != SCTP_CC_RTCC)) {
3516 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3520 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3522 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3523 stcb->asoc.congestion_control_module = av->assoc_value;
3524 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3525 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3526 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3529 SCTP_TCB_UNLOCK(stcb);
3531 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3532 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3533 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3534 (av->assoc_id == SCTP_ALL_ASSOC)) {
3535 SCTP_INP_WLOCK(inp);
3536 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3537 SCTP_INP_WUNLOCK(inp);
3539 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3540 (av->assoc_id == SCTP_ALL_ASSOC)) {
3541 SCTP_INP_RLOCK(inp);
3542 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3543 SCTP_TCB_LOCK(stcb);
3544 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3545 stcb->asoc.congestion_control_module = av->assoc_value;
3546 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3547 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3548 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3551 SCTP_TCB_UNLOCK(stcb);
3553 SCTP_INP_RUNLOCK(inp);
3558 case SCTP_CC_OPTION:
3560 struct sctp_cc_option *cc_opt;
3562 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3563 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3565 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3566 SCTP_INP_RLOCK(inp);
3567 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3568 SCTP_TCB_LOCK(stcb);
3569 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3570 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3572 SCTP_TCB_UNLOCK(stcb);
3574 SCTP_INP_RUNLOCK(inp);
3579 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3582 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3585 SCTP_TCB_UNLOCK(stcb);
3589 case SCTP_PLUGGABLE_SS:
3591 struct sctp_assoc_value *av;
3593 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3594 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3595 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3596 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3597 (av->assoc_value != SCTP_SS_PRIORITY) &&
3598 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3599 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3600 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3604 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3606 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3607 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3608 stcb->asoc.stream_scheduling_module = av->assoc_value;
3609 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3610 SCTP_TCB_UNLOCK(stcb);
3612 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3613 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3614 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3615 (av->assoc_id == SCTP_ALL_ASSOC)) {
3616 SCTP_INP_WLOCK(inp);
3617 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
3618 SCTP_INP_WUNLOCK(inp);
3620 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3621 (av->assoc_id == SCTP_ALL_ASSOC)) {
3622 SCTP_INP_RLOCK(inp);
3623 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3624 SCTP_TCB_LOCK(stcb);
3625 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3626 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3627 stcb->asoc.stream_scheduling_module = av->assoc_value;
3628 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3629 SCTP_TCB_UNLOCK(stcb);
3631 SCTP_INP_RUNLOCK(inp);
3638 struct sctp_stream_value *av;
3640 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
3641 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3643 if (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
3644 av->stream_value) < 0) {
3645 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3648 SCTP_TCB_UNLOCK(stcb);
3650 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
3651 SCTP_INP_RLOCK(inp);
3652 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3653 SCTP_TCB_LOCK(stcb);
3654 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
3656 &stcb->asoc.strmout[av->stream_id],
3658 SCTP_TCB_UNLOCK(stcb);
3660 SCTP_INP_RUNLOCK(inp);
3664 * Can't set stream value without
3667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3673 case SCTP_CLR_STAT_LOG:
3674 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3679 struct sctp_assoc_value *av;
3681 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3682 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3685 stcb->asoc.context = av->assoc_value;
3686 SCTP_TCB_UNLOCK(stcb);
3688 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3689 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3690 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3691 (av->assoc_id == SCTP_ALL_ASSOC)) {
3692 SCTP_INP_WLOCK(inp);
3693 inp->sctp_context = av->assoc_value;
3694 SCTP_INP_WUNLOCK(inp);
3696 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3697 (av->assoc_id == SCTP_ALL_ASSOC)) {
3698 SCTP_INP_RLOCK(inp);
3699 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3700 SCTP_TCB_LOCK(stcb);
3701 stcb->asoc.context = av->assoc_value;
3702 SCTP_TCB_UNLOCK(stcb);
3704 SCTP_INP_RUNLOCK(inp);
3711 uint32_t *default_vrfid;
3713 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
3714 if (*default_vrfid > SCTP_MAX_VRF_ID) {
3715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3719 inp->def_vrf_id = *default_vrfid;
3722 case SCTP_DEL_VRF_ID:
3724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3728 case SCTP_ADD_VRF_ID:
3730 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3734 case SCTP_DELAYED_SACK:
3736 struct sctp_sack_info *sack;
3738 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
3739 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
3740 if (sack->sack_delay) {
3741 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
3742 sack->sack_delay = SCTP_MAX_SACK_DELAY;
3743 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3744 sack->sack_delay = TICKS_TO_MSEC(1);
3748 if (sack->sack_delay) {
3749 stcb->asoc.delayed_ack = sack->sack_delay;
3751 if (sack->sack_freq) {
3752 stcb->asoc.sack_freq = sack->sack_freq;
3754 SCTP_TCB_UNLOCK(stcb);
3756 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3757 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3758 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
3759 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3760 SCTP_INP_WLOCK(inp);
3761 if (sack->sack_delay) {
3762 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
3764 if (sack->sack_freq) {
3765 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
3767 SCTP_INP_WUNLOCK(inp);
3769 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
3770 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3771 SCTP_INP_RLOCK(inp);
3772 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3773 SCTP_TCB_LOCK(stcb);
3774 if (sack->sack_delay) {
3775 stcb->asoc.delayed_ack = sack->sack_delay;
3777 if (sack->sack_freq) {
3778 stcb->asoc.sack_freq = sack->sack_freq;
3780 SCTP_TCB_UNLOCK(stcb);
3782 SCTP_INP_RUNLOCK(inp);
3787 case SCTP_AUTH_CHUNK:
3789 struct sctp_authchunk *sauth;
3791 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
3793 SCTP_INP_WLOCK(inp);
3794 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
3795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3798 SCTP_INP_WUNLOCK(inp);
3803 struct sctp_authkey *sca;
3804 struct sctp_keyhead *shared_keys;
3805 sctp_sharedkey_t *shared_key;
3806 sctp_key_t *key = NULL;
3809 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
3810 if (sca->sca_keylength == 0) {
3811 size = optsize - sizeof(struct sctp_authkey);
3813 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
3814 size = sca->sca_keylength;
3816 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3821 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
3824 shared_keys = &stcb->asoc.shared_keys;
3825 /* clear the cached keys for this key id */
3826 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3828 * create the new shared key and
3832 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3834 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3836 SCTP_TCB_UNLOCK(stcb);
3840 shared_key = sctp_alloc_sharedkey();
3841 if (shared_key == NULL) {
3843 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3845 SCTP_TCB_UNLOCK(stcb);
3848 shared_key->key = key;
3849 shared_key->keyid = sca->sca_keynumber;
3850 error = sctp_insert_sharedkey(shared_keys, shared_key);
3851 SCTP_TCB_UNLOCK(stcb);
3853 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3854 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3855 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
3856 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3857 SCTP_INP_WLOCK(inp);
3858 shared_keys = &inp->sctp_ep.shared_keys;
3860 * clear the cached keys on all
3861 * assocs for this key id
3863 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3865 * create the new shared key and
3869 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3871 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3873 SCTP_INP_WUNLOCK(inp);
3877 shared_key = sctp_alloc_sharedkey();
3878 if (shared_key == NULL) {
3880 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3882 SCTP_INP_WUNLOCK(inp);
3885 shared_key->key = key;
3886 shared_key->keyid = sca->sca_keynumber;
3887 error = sctp_insert_sharedkey(shared_keys, shared_key);
3888 SCTP_INP_WUNLOCK(inp);
3890 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
3891 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3892 SCTP_INP_RLOCK(inp);
3893 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3894 SCTP_TCB_LOCK(stcb);
3895 shared_keys = &stcb->asoc.shared_keys;
3897 * clear the cached keys for
3900 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3902 * create the new shared key
3903 * and insert/replace it
3906 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3908 SCTP_TCB_UNLOCK(stcb);
3912 shared_key = sctp_alloc_sharedkey();
3913 if (shared_key == NULL) {
3915 SCTP_TCB_UNLOCK(stcb);
3918 shared_key->key = key;
3919 shared_key->keyid = sca->sca_keynumber;
3920 error = sctp_insert_sharedkey(shared_keys, shared_key);
3921 SCTP_TCB_UNLOCK(stcb);
3923 SCTP_INP_RUNLOCK(inp);
3928 case SCTP_HMAC_IDENT:
3930 struct sctp_hmacalgo *shmac;
3931 sctp_hmaclist_t *hmaclist;
3936 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
3937 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
3938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3942 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
3943 if (hmaclist == NULL) {
3944 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3948 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
3949 hmacid = shmac->shmac_idents[i];
3950 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
3951 /* invalid HMACs were found */ ;
3952 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3954 sctp_free_hmaclist(hmaclist);
3955 goto sctp_set_hmac_done;
3959 for (i = 0; i < hmaclist->num_algo; i++) {
3960 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
3961 /* already in list */
3966 sctp_free_hmaclist(hmaclist);
3967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3971 /* set it on the endpoint */
3972 SCTP_INP_WLOCK(inp);
3973 if (inp->sctp_ep.local_hmacs)
3974 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
3975 inp->sctp_ep.local_hmacs = hmaclist;
3976 SCTP_INP_WUNLOCK(inp);
3980 case SCTP_AUTH_ACTIVE_KEY:
3982 struct sctp_authkeyid *scact;
3984 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
3985 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
3987 /* set the active key on the right place */
3989 /* set the active key on the assoc */
3990 if (sctp_auth_setactivekey(stcb,
3991 scact->scact_keynumber)) {
3992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
3993 SCTP_FROM_SCTP_USRREQ,
3997 SCTP_TCB_UNLOCK(stcb);
3999 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4000 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4001 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4002 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4003 SCTP_INP_WLOCK(inp);
4004 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4005 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4008 SCTP_INP_WUNLOCK(inp);
4010 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4011 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4012 SCTP_INP_RLOCK(inp);
4013 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4014 SCTP_TCB_LOCK(stcb);
4015 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4016 SCTP_TCB_UNLOCK(stcb);
4018 SCTP_INP_RUNLOCK(inp);
4023 case SCTP_AUTH_DELETE_KEY:
4025 struct sctp_authkeyid *scdel;
4027 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4028 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4030 /* delete the key from the right place */
4032 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4033 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4036 SCTP_TCB_UNLOCK(stcb);
4038 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4039 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4040 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4041 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4042 SCTP_INP_WLOCK(inp);
4043 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4044 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4047 SCTP_INP_WUNLOCK(inp);
4049 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4050 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4051 SCTP_INP_RLOCK(inp);
4052 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4053 SCTP_TCB_LOCK(stcb);
4054 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4055 SCTP_TCB_UNLOCK(stcb);
4057 SCTP_INP_RUNLOCK(inp);
4062 case SCTP_AUTH_DEACTIVATE_KEY:
4064 struct sctp_authkeyid *keyid;
4066 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4067 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4069 /* deactivate the key from the right place */
4071 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4072 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4075 SCTP_TCB_UNLOCK(stcb);
4077 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4078 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4079 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4080 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4081 SCTP_INP_WLOCK(inp);
4082 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4083 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4086 SCTP_INP_WUNLOCK(inp);
4088 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4089 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4090 SCTP_INP_RLOCK(inp);
4091 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4092 SCTP_TCB_LOCK(stcb);
4093 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4094 SCTP_TCB_UNLOCK(stcb);
4096 SCTP_INP_RUNLOCK(inp);
4101 case SCTP_ENABLE_STREAM_RESET:
4103 struct sctp_assoc_value *av;
4105 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4106 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4107 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4111 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4113 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4114 SCTP_TCB_UNLOCK(stcb);
4116 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4117 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4118 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4119 (av->assoc_id == SCTP_ALL_ASSOC)) {
4120 SCTP_INP_WLOCK(inp);
4121 inp->local_strreset_support = (uint8_t) av->assoc_value;
4122 SCTP_INP_WUNLOCK(inp);
4124 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4125 (av->assoc_id == SCTP_ALL_ASSOC)) {
4126 SCTP_INP_RLOCK(inp);
4127 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4128 SCTP_TCB_LOCK(stcb);
4129 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4130 SCTP_TCB_UNLOCK(stcb);
4132 SCTP_INP_RUNLOCK(inp);
4137 case SCTP_RESET_STREAMS:
4139 struct sctp_reset_streams *strrst;
4140 int i, send_out = 0;
4143 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4144 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4146 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4150 if (stcb->asoc.peer_supports_strreset == 0) {
4152 * Peer does not support the chunk type.
4154 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4156 SCTP_TCB_UNLOCK(stcb);
4159 if (stcb->asoc.stream_reset_outstanding) {
4160 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4162 SCTP_TCB_UNLOCK(stcb);
4165 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4168 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4171 if ((send_in == 0) && (send_out == 0)) {
4172 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4174 SCTP_TCB_UNLOCK(stcb);
4177 for (i = 0; i < strrst->srs_number_streams; i++) {
4179 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4180 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4185 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4192 SCTP_TCB_UNLOCK(stcb);
4195 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4196 strrst->srs_stream_list,
4197 send_out, send_in, 0, 0, 0, 0, 0);
4199 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4200 SCTP_TCB_UNLOCK(stcb);
4203 case SCTP_ADD_STREAMS:
4205 struct sctp_add_streams *stradd;
4206 uint8_t addstream = 0;
4207 uint16_t add_o_strmcnt = 0;
4208 uint16_t add_i_strmcnt = 0;
4210 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4211 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4213 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4217 if (stcb->asoc.peer_supports_strreset == 0) {
4219 * Peer does not support the chunk type.
4221 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4223 SCTP_TCB_UNLOCK(stcb);
4226 if (stcb->asoc.stream_reset_outstanding) {
4227 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4229 SCTP_TCB_UNLOCK(stcb);
4232 if ((stradd->sas_outstrms == 0) &&
4233 (stradd->sas_instrms == 0)) {
4237 if (stradd->sas_outstrms) {
4239 /* We allocate here */
4240 add_o_strmcnt = stradd->sas_outstrms;
4241 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4242 /* You can't have more than 64k */
4247 if (stradd->sas_instrms) {
4252 * We allocate inside
4253 * sctp_send_str_reset_req()
4255 add_i_strmcnt = stradd->sas_instrms;
4256 cnt = add_i_strmcnt;
4257 cnt += stcb->asoc.streamincnt;
4258 if (cnt > 0x0000ffff) {
4259 /* You can't have more than 64k */
4263 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4264 /* More than you are allowed */
4269 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4270 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4272 SCTP_TCB_UNLOCK(stcb);
4275 case SCTP_RESET_ASSOC:
4279 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4280 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4282 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4286 if (stcb->asoc.peer_supports_strreset == 0) {
4288 * Peer does not support the chunk type.
4290 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4292 SCTP_TCB_UNLOCK(stcb);
4295 if (stcb->asoc.stream_reset_outstanding) {
4296 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4298 SCTP_TCB_UNLOCK(stcb);
4301 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 1, 0, 0, 0, 0);
4302 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4303 SCTP_TCB_UNLOCK(stcb);
4306 case SCTP_CONNECT_X:
4307 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4308 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4312 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4314 case SCTP_CONNECT_X_DELAYED:
4315 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4316 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4320 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4322 case SCTP_CONNECT_X_COMPLETE:
4324 struct sockaddr *sa;
4325 struct sctp_nets *net;
4327 /* FIXME MT: check correct? */
4328 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4331 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4332 SCTP_INP_RLOCK(inp);
4333 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4335 SCTP_TCB_LOCK(stcb);
4336 net = sctp_findnet(stcb, sa);
4338 SCTP_INP_RUNLOCK(inp);
4341 * We increment here since
4342 * sctp_findassociation_ep_addr() wil do a
4343 * decrement if it finds the stcb as long as
4344 * the locked tcb (last argument) is NOT a
4347 SCTP_INP_INCR_REF(inp);
4348 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4350 SCTP_INP_DECR_REF(inp);
4355 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4359 if (stcb->asoc.delayed_connection == 1) {
4360 stcb->asoc.delayed_connection = 0;
4361 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4362 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4363 stcb->asoc.primary_destination,
4364 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4365 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4368 * already expired or did not use delayed
4371 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4374 SCTP_TCB_UNLOCK(stcb);
4377 case SCTP_MAX_BURST:
4381 SCTP_CHECK_AND_CAST(burst, optval, uint8_t, optsize);
4383 SCTP_INP_WLOCK(inp);
4384 inp->sctp_ep.max_burst = *burst;
4385 SCTP_INP_WUNLOCK(inp);
4390 struct sctp_assoc_value *av;
4393 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4394 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4396 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4397 ovh = SCTP_MED_OVERHEAD;
4399 ovh = SCTP_MED_V4_OVERHEAD;
4402 if (av->assoc_value) {
4403 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4405 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4407 SCTP_TCB_UNLOCK(stcb);
4409 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4410 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4411 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4412 SCTP_INP_WLOCK(inp);
4414 * FIXME MT: I think this is not in
4415 * tune with the API ID
4417 if (av->assoc_value) {
4418 inp->sctp_frag_point = (av->assoc_value + ovh);
4420 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4422 SCTP_INP_WUNLOCK(inp);
4424 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4432 struct sctp_event_subscribe *events;
4434 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4436 SCTP_INP_WLOCK(inp);
4437 if (events->sctp_data_io_event) {
4438 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4440 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4443 if (events->sctp_association_event) {
4444 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4446 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4449 if (events->sctp_address_event) {
4450 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4452 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4455 if (events->sctp_send_failure_event) {
4456 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4458 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4461 if (events->sctp_peer_error_event) {
4462 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4464 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4467 if (events->sctp_shutdown_event) {
4468 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4470 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4473 if (events->sctp_partial_delivery_event) {
4474 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4476 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4479 if (events->sctp_adaptation_layer_event) {
4480 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4482 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4485 if (events->sctp_authentication_event) {
4486 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4488 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4491 if (events->sctp_sender_dry_event) {
4492 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4494 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4497 if (events->sctp_stream_reset_event) {
4498 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4500 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4502 SCTP_INP_WUNLOCK(inp);
4504 SCTP_INP_RLOCK(inp);
4505 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4506 SCTP_TCB_LOCK(stcb);
4507 if (events->sctp_association_event) {
4508 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4510 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4512 if (events->sctp_address_event) {
4513 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4515 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4517 if (events->sctp_send_failure_event) {
4518 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4520 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4522 if (events->sctp_peer_error_event) {
4523 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4525 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4527 if (events->sctp_shutdown_event) {
4528 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4530 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4532 if (events->sctp_partial_delivery_event) {
4533 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4535 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4537 if (events->sctp_adaptation_layer_event) {
4538 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4540 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4542 if (events->sctp_authentication_event) {
4543 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4545 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4547 if (events->sctp_sender_dry_event) {
4548 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4550 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4552 if (events->sctp_stream_reset_event) {
4553 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4555 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4557 SCTP_TCB_UNLOCK(stcb);
4560 * Send up the sender dry event only for 1-to-1
4563 if (events->sctp_sender_dry_event) {
4564 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4565 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4566 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4568 SCTP_TCB_LOCK(stcb);
4569 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4570 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4571 (stcb->asoc.stream_queue_cnt == 0)) {
4572 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4574 SCTP_TCB_UNLOCK(stcb);
4578 SCTP_INP_RUNLOCK(inp);
4581 case SCTP_ADAPTATION_LAYER:
4583 struct sctp_setadaptation *adap_bits;
4585 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
4586 SCTP_INP_WLOCK(inp);
4587 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
4588 SCTP_INP_WUNLOCK(inp);
4592 case SCTP_SET_INITIAL_DBG_SEQ:
4596 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
4597 SCTP_INP_WLOCK(inp);
4598 inp->sctp_ep.initial_sequence_debug = *vvv;
4599 SCTP_INP_WUNLOCK(inp);
4603 case SCTP_DEFAULT_SEND_PARAM:
4605 struct sctp_sndrcvinfo *s_info;
4607 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
4608 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
4611 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4612 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4614 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4617 SCTP_TCB_UNLOCK(stcb);
4619 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4620 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4621 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
4622 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4623 SCTP_INP_WLOCK(inp);
4624 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
4625 SCTP_INP_WUNLOCK(inp);
4627 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
4628 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4629 SCTP_INP_RLOCK(inp);
4630 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4631 SCTP_TCB_LOCK(stcb);
4632 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4633 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4635 SCTP_TCB_UNLOCK(stcb);
4637 SCTP_INP_RUNLOCK(inp);
4642 case SCTP_PEER_ADDR_PARAMS:
4644 struct sctp_paddrparams *paddrp;
4645 struct sctp_nets *net;
4647 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
4648 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
4651 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
4654 * We increment here since
4655 * sctp_findassociation_ep_addr() wil do a
4656 * decrement if it finds the stcb as long as
4657 * the locked tcb (last argument) is NOT a
4660 SCTP_INP_INCR_REF(inp);
4661 stcb = sctp_findassociation_ep_addr(&inp,
4662 (struct sockaddr *)&paddrp->spp_address,
4665 SCTP_INP_DECR_REF(inp);
4668 if (stcb && (net == NULL)) {
4669 struct sockaddr *sa;
4671 sa = (struct sockaddr *)&paddrp->spp_address;
4673 if (sa->sa_family == AF_INET) {
4675 struct sockaddr_in *sin;
4677 sin = (struct sockaddr_in *)sa;
4678 if (sin->sin_addr.s_addr) {
4679 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4680 SCTP_TCB_UNLOCK(stcb);
4687 if (sa->sa_family == AF_INET6) {
4688 struct sockaddr_in6 *sin6;
4690 sin6 = (struct sockaddr_in6 *)sa;
4691 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
4692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4693 SCTP_TCB_UNLOCK(stcb);
4700 error = EAFNOSUPPORT;
4701 SCTP_TCB_UNLOCK(stcb);
4702 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4707 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
4709 SCTP_TCB_UNLOCK(stcb);
4710 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4713 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
4715 SCTP_TCB_UNLOCK(stcb);
4716 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4720 /************************TCB SPECIFIC SET ******************/
4722 * do we change the timer for HB, we run
4727 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4728 ovh = SCTP_MED_OVERHEAD;
4730 ovh = SCTP_MED_V4_OVERHEAD;
4733 /* network sets ? */
4735 /************************NET SPECIFIC SET ******************/
4736 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4737 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
4738 !(net->dest_state & SCTP_ADDR_NOHB)) {
4739 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4740 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4742 net->dest_state |= SCTP_ADDR_NOHB;
4744 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4745 if (paddrp->spp_hbinterval) {
4746 net->heart_beat_delay = paddrp->spp_hbinterval;
4747 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4748 net->heart_beat_delay = 0;
4750 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4751 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4752 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4753 net->dest_state &= ~SCTP_ADDR_NOHB;
4755 if (paddrp->spp_flags & SPP_HB_DEMAND) {
4757 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4758 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
4759 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4761 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4762 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4763 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4764 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4766 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4767 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4768 net->mtu = paddrp->spp_pathmtu + ovh;
4769 if (net->mtu < stcb->asoc.smallest_mtu) {
4770 sctp_pathmtu_adjustment(stcb, net->mtu);
4774 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4775 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4776 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4778 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4780 if (paddrp->spp_pathmaxrxt) {
4781 if (net->dest_state & SCTP_ADDR_PF) {
4782 if (net->error_count > paddrp->spp_pathmaxrxt) {
4783 net->dest_state &= ~SCTP_ADDR_PF;
4786 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4787 (net->error_count > net->pf_threshold)) {
4788 net->dest_state |= SCTP_ADDR_PF;
4789 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4790 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4791 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4794 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4795 if (net->error_count > paddrp->spp_pathmaxrxt) {
4796 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4797 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4800 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4801 net->dest_state |= SCTP_ADDR_REACHABLE;
4802 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4805 net->failure_threshold = paddrp->spp_pathmaxrxt;
4807 if (paddrp->spp_flags & SPP_DSCP) {
4808 net->dscp = paddrp->spp_dscp & 0xfc;
4812 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4813 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4814 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4815 net->flowlabel |= 0x80000000;
4820 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
4821 if (paddrp->spp_pathmaxrxt) {
4822 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
4823 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4824 if (net->dest_state & SCTP_ADDR_PF) {
4825 if (net->error_count > paddrp->spp_pathmaxrxt) {
4826 net->dest_state &= ~SCTP_ADDR_PF;
4829 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4830 (net->error_count > net->pf_threshold)) {
4831 net->dest_state |= SCTP_ADDR_PF;
4832 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4833 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4834 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4837 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4838 if (net->error_count > paddrp->spp_pathmaxrxt) {
4839 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4840 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
4843 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4844 net->dest_state |= SCTP_ADDR_REACHABLE;
4845 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
4848 net->failure_threshold = paddrp->spp_pathmaxrxt;
4851 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4852 if (paddrp->spp_hbinterval) {
4853 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
4854 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4855 stcb->asoc.heart_beat_delay = 0;
4857 /* Turn back on the timer */
4858 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4859 if (paddrp->spp_hbinterval) {
4860 net->heart_beat_delay = paddrp->spp_hbinterval;
4861 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4862 net->heart_beat_delay = 0;
4864 if (net->dest_state & SCTP_ADDR_NOHB) {
4865 net->dest_state &= ~SCTP_ADDR_NOHB;
4867 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4868 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4869 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4871 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4873 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4874 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4875 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
4876 net->dest_state |= SCTP_ADDR_NOHB;
4877 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
4878 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4882 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4884 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4885 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4886 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4887 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4888 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4890 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4891 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4892 net->mtu = paddrp->spp_pathmtu + ovh;
4893 if (net->mtu < stcb->asoc.smallest_mtu) {
4894 sctp_pathmtu_adjustment(stcb, net->mtu);
4898 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4900 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4901 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4902 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4903 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4905 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4907 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4909 if (paddrp->spp_flags & SPP_DSCP) {
4910 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4911 net->dscp = paddrp->spp_dscp & 0xfc;
4914 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
4915 stcb->asoc.default_dscp |= 0x01;
4918 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4919 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4920 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4921 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4922 net->flowlabel |= 0x80000000;
4925 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4926 stcb->asoc.default_flowlabel |= 0x80000000;
4930 SCTP_TCB_UNLOCK(stcb);
4932 /************************NO TCB, SET TO default stuff ******************/
4933 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4934 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4935 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
4936 SCTP_INP_WLOCK(inp);
4938 * For the TOS/FLOWLABEL stuff you
4939 * set it with the options on the
4942 if (paddrp->spp_pathmaxrxt) {
4943 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
4945 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
4946 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4947 else if (paddrp->spp_hbinterval) {
4948 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
4949 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
4950 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4952 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4953 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4954 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4955 } else if (paddrp->spp_hbinterval) {
4956 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4958 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4959 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
4960 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4962 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4963 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4964 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
4965 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4967 if (paddrp->spp_flags & SPP_DSCP) {
4968 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
4969 inp->sctp_ep.default_dscp |= 0x01;
4972 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4973 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4974 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4975 inp->sctp_ep.default_flowlabel |= 0x80000000;
4979 SCTP_INP_WUNLOCK(inp);
4981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4989 struct sctp_rtoinfo *srto;
4990 uint32_t new_init, new_min, new_max;
4992 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
4993 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
4996 if (srto->srto_initial)
4997 new_init = srto->srto_initial;
4999 new_init = stcb->asoc.initial_rto;
5001 new_max = srto->srto_max;
5003 new_max = stcb->asoc.maxrto;
5005 new_min = srto->srto_min;
5007 new_min = stcb->asoc.minrto;
5008 if ((new_min <= new_init) && (new_init <= new_max)) {
5009 stcb->asoc.initial_rto = new_init;
5010 stcb->asoc.maxrto = new_max;
5011 stcb->asoc.minrto = new_min;
5013 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5016 SCTP_TCB_UNLOCK(stcb);
5018 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5019 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5020 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5021 SCTP_INP_WLOCK(inp);
5022 if (srto->srto_initial)
5023 new_init = srto->srto_initial;
5025 new_init = inp->sctp_ep.initial_rto;
5027 new_max = srto->srto_max;
5029 new_max = inp->sctp_ep.sctp_maxrto;
5031 new_min = srto->srto_min;
5033 new_min = inp->sctp_ep.sctp_minrto;
5034 if ((new_min <= new_init) && (new_init <= new_max)) {
5035 inp->sctp_ep.initial_rto = new_init;
5036 inp->sctp_ep.sctp_maxrto = new_max;
5037 inp->sctp_ep.sctp_minrto = new_min;
5039 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5042 SCTP_INP_WUNLOCK(inp);
5044 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5050 case SCTP_ASSOCINFO:
5052 struct sctp_assocparams *sasoc;
5054 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5055 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5056 if (sasoc->sasoc_cookie_life) {
5057 /* boundary check the cookie life */
5058 if (sasoc->sasoc_cookie_life < 1000)
5059 sasoc->sasoc_cookie_life = 1000;
5060 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5061 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5065 if (sasoc->sasoc_asocmaxrxt)
5066 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5067 if (sasoc->sasoc_cookie_life) {
5068 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5070 SCTP_TCB_UNLOCK(stcb);
5072 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5073 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5074 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5075 SCTP_INP_WLOCK(inp);
5076 if (sasoc->sasoc_asocmaxrxt)
5077 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5078 if (sasoc->sasoc_cookie_life) {
5079 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5081 SCTP_INP_WUNLOCK(inp);
5083 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5091 struct sctp_initmsg *sinit;
5093 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5094 SCTP_INP_WLOCK(inp);
5095 if (sinit->sinit_num_ostreams)
5096 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5098 if (sinit->sinit_max_instreams)
5099 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5101 if (sinit->sinit_max_attempts)
5102 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5104 if (sinit->sinit_max_init_timeo)
5105 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5106 SCTP_INP_WUNLOCK(inp);
5109 case SCTP_PRIMARY_ADDR:
5111 struct sctp_setprim *spa;
5112 struct sctp_nets *net;
5114 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5115 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5119 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
5122 * We increment here since
5123 * sctp_findassociation_ep_addr() wil do a
5124 * decrement if it finds the stcb as long as
5125 * the locked tcb (last argument) is NOT a
5128 SCTP_INP_INCR_REF(inp);
5129 stcb = sctp_findassociation_ep_addr(&inp,
5130 (struct sockaddr *)&spa->ssp_addr,
5133 SCTP_INP_DECR_REF(inp);
5137 if ((stcb) && (net)) {
5138 if ((net != stcb->asoc.primary_destination) &&
5139 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
5140 /* Ok we need to set it */
5141 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5142 if ((stcb->asoc.alternate) &&
5143 (!(net->dest_state & SCTP_ADDR_PF)) &&
5144 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5145 sctp_free_remote_addr(stcb->asoc.alternate);
5146 stcb->asoc.alternate = NULL;
5151 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5155 SCTP_TCB_UNLOCK(stcb);
5159 case SCTP_SET_DYNAMIC_PRIMARY:
5161 union sctp_sockstore *ss;
5163 error = priv_check(curthread,
5164 PRIV_NETINET_RESERVEDPORT);
5168 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5169 /* SUPER USER CHECK? */
5170 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5173 case SCTP_SET_PEER_PRIMARY_ADDR:
5175 struct sctp_setpeerprim *sspp;
5177 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5178 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5180 struct sctp_ifa *ifa;
5182 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
5183 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5185 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5189 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5191 * Must validate the ifa found is in
5194 struct sctp_laddr *laddr;
5197 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5198 if (laddr->ifa == NULL) {
5199 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5203 if (laddr->ifa == ifa) {
5209 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5214 if (sctp_set_primary_ip_address_sa(stcb,
5215 (struct sockaddr *)&sspp->sspp_addr) != 0) {
5216 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5220 SCTP_TCB_UNLOCK(stcb);
5222 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5227 case SCTP_BINDX_ADD_ADDR:
5229 struct sctp_getaddresses *addrs;
5233 td = (struct thread *)p;
5234 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5237 if (addrs->addr->sa_family == AF_INET) {
5238 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
5240 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5244 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5245 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5251 if (addrs->addr->sa_family == AF_INET6) {
5252 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
5254 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5258 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5259 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5260 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5266 error = EAFNOSUPPORT;
5269 sctp_bindx_add_address(so, inp, addrs->addr,
5270 addrs->sget_assoc_id, vrf_id,
5274 case SCTP_BINDX_REM_ADDR:
5276 struct sctp_getaddresses *addrs;
5280 td = (struct thread *)p;
5282 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5284 if (addrs->addr->sa_family == AF_INET) {
5285 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
5287 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5291 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5292 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5298 if (addrs->addr->sa_family == AF_INET6) {
5299 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
5301 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5306 (error = prison_local_ip6(td->td_ucred,
5307 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5308 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5309 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5315 error = EAFNOSUPPORT;
5318 sctp_bindx_delete_address(inp, addrs->addr,
5319 addrs->sget_assoc_id, vrf_id,
5325 struct sctp_event *event;
5326 uint32_t event_type;
5328 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5329 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5330 switch (event->se_type) {
5331 case SCTP_ASSOC_CHANGE:
5332 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5334 case SCTP_PEER_ADDR_CHANGE:
5335 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5337 case SCTP_REMOTE_ERROR:
5338 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5340 case SCTP_SEND_FAILED:
5341 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5343 case SCTP_SHUTDOWN_EVENT:
5344 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5346 case SCTP_ADAPTATION_INDICATION:
5347 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5349 case SCTP_PARTIAL_DELIVERY_EVENT:
5350 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5352 case SCTP_AUTHENTICATION_EVENT:
5353 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5355 case SCTP_STREAM_RESET_EVENT:
5356 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5358 case SCTP_SENDER_DRY_EVENT:
5359 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5361 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5363 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5366 case SCTP_ASSOC_RESET_EVENT:
5367 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
5369 case SCTP_STREAM_CHANGE_EVENT:
5370 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
5372 case SCTP_SEND_FAILED_EVENT:
5373 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
5377 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5381 if (event_type > 0) {
5384 sctp_stcb_feature_on(inp, stcb, event_type);
5385 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5386 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5387 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5388 (stcb->asoc.stream_queue_cnt == 0)) {
5389 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5393 sctp_stcb_feature_off(inp, stcb, event_type);
5395 SCTP_TCB_UNLOCK(stcb);
5398 * We don't want to send up a storm
5399 * of events, so return an error for
5402 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5403 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5404 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5405 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5406 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5407 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5411 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5412 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5413 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5414 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5415 SCTP_INP_WLOCK(inp);
5417 sctp_feature_on(inp, event_type);
5419 sctp_feature_off(inp, event_type);
5421 SCTP_INP_WUNLOCK(inp);
5423 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5424 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5425 SCTP_INP_RLOCK(inp);
5426 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5427 SCTP_TCB_LOCK(stcb);
5429 sctp_stcb_feature_on(inp, stcb, event_type);
5431 sctp_stcb_feature_off(inp, stcb, event_type);
5433 SCTP_TCB_UNLOCK(stcb);
5435 SCTP_INP_RUNLOCK(inp);
5441 case SCTP_RECVRCVINFO:
5445 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5446 SCTP_INP_WLOCK(inp);
5448 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5450 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5452 SCTP_INP_WUNLOCK(inp);
5455 case SCTP_RECVNXTINFO:
5459 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5460 SCTP_INP_WLOCK(inp);
5462 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5464 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5466 SCTP_INP_WUNLOCK(inp);
5469 case SCTP_DEFAULT_SNDINFO:
5471 struct sctp_sndinfo *info;
5474 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5475 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5478 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5479 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5480 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5481 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5482 stcb->asoc.def_send.sinfo_flags |= policy;
5483 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5484 stcb->asoc.def_send.sinfo_context = info->snd_context;
5486 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5489 SCTP_TCB_UNLOCK(stcb);
5491 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5492 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5493 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
5494 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5495 SCTP_INP_WLOCK(inp);
5496 inp->def_send.sinfo_stream = info->snd_sid;
5497 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
5498 inp->def_send.sinfo_flags = info->snd_flags;
5499 inp->def_send.sinfo_flags |= policy;
5500 inp->def_send.sinfo_ppid = info->snd_ppid;
5501 inp->def_send.sinfo_context = info->snd_context;
5502 SCTP_INP_WUNLOCK(inp);
5504 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
5505 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5506 SCTP_INP_RLOCK(inp);
5507 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5508 SCTP_TCB_LOCK(stcb);
5509 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5510 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5511 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5512 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5513 stcb->asoc.def_send.sinfo_flags |= policy;
5514 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5515 stcb->asoc.def_send.sinfo_context = info->snd_context;
5517 SCTP_TCB_UNLOCK(stcb);
5519 SCTP_INP_RUNLOCK(inp);
5524 case SCTP_DEFAULT_PRINFO:
5526 struct sctp_default_prinfo *info;
5528 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
5529 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
5531 if (PR_SCTP_INVALID_POLICY(info->pr_policy)) {
5532 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5537 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5538 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5539 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5540 SCTP_TCB_UNLOCK(stcb);
5542 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5543 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5544 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
5545 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5546 SCTP_INP_WLOCK(inp);
5547 inp->def_send.sinfo_flags &= 0xfff0;
5548 inp->def_send.sinfo_flags |= info->pr_policy;
5549 inp->def_send.sinfo_timetolive = info->pr_value;
5550 SCTP_INP_WUNLOCK(inp);
5552 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
5553 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5554 SCTP_INP_RLOCK(inp);
5555 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5556 SCTP_TCB_LOCK(stcb);
5557 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5558 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5559 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5560 SCTP_TCB_UNLOCK(stcb);
5562 SCTP_INP_RUNLOCK(inp);
5567 case SCTP_PEER_ADDR_THLDS:
5568 /* Applies to the specific association */
5570 struct sctp_paddrthlds *thlds;
5571 struct sctp_nets *net;
5573 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
5574 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
5577 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_assoc_id);
5580 * We increment here since
5581 * sctp_findassociation_ep_addr() wil do a
5582 * decrement if it finds the stcb as long as
5583 * the locked tcb (last argument) is NOT a
5586 SCTP_INP_INCR_REF(inp);
5587 stcb = sctp_findassociation_ep_addr(&inp,
5588 (struct sockaddr *)&thlds->spt_assoc_id,
5591 SCTP_INP_DECR_REF(inp);
5594 if (stcb && (net == NULL)) {
5595 struct sockaddr *sa;
5597 sa = (struct sockaddr *)&thlds->spt_assoc_id;
5599 if (sa->sa_family == AF_INET) {
5601 struct sockaddr_in *sin;
5603 sin = (struct sockaddr_in *)sa;
5604 if (sin->sin_addr.s_addr) {
5605 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5606 SCTP_TCB_UNLOCK(stcb);
5613 if (sa->sa_family == AF_INET6) {
5614 struct sockaddr_in6 *sin6;
5616 sin6 = (struct sockaddr_in6 *)sa;
5617 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5618 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5619 SCTP_TCB_UNLOCK(stcb);
5626 error = EAFNOSUPPORT;
5627 SCTP_TCB_UNLOCK(stcb);
5628 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5634 if (net->dest_state & SCTP_ADDR_PF) {
5635 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5636 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5637 net->dest_state &= ~SCTP_ADDR_PF;
5640 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5641 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5642 net->dest_state |= SCTP_ADDR_PF;
5643 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5644 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5645 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5648 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5649 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5650 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5651 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5654 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5655 net->dest_state |= SCTP_ADDR_REACHABLE;
5656 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5659 net->failure_threshold = thlds->spt_pathmaxrxt;
5660 net->pf_threshold = thlds->spt_pathpfthld;
5662 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5663 if (net->dest_state & SCTP_ADDR_PF) {
5664 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5665 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5666 net->dest_state &= ~SCTP_ADDR_PF;
5669 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5670 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5671 net->dest_state |= SCTP_ADDR_PF;
5672 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5673 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5674 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5677 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5678 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5679 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5680 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5683 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5684 net->dest_state |= SCTP_ADDR_REACHABLE;
5685 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5688 net->failure_threshold = thlds->spt_pathmaxrxt;
5689 net->pf_threshold = thlds->spt_pathpfthld;
5691 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
5692 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
5695 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5696 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5697 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
5698 SCTP_INP_WLOCK(inp);
5699 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
5700 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
5701 SCTP_INP_WUNLOCK(inp);
5703 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5709 case SCTP_REMOTE_UDP_ENCAPS_PORT:
5711 struct sctp_udpencaps *encaps;
5712 struct sctp_nets *net;
5714 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
5715 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
5717 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
5720 * We increment here since
5721 * sctp_findassociation_ep_addr() wil do a
5722 * decrement if it finds the stcb as long as
5723 * the locked tcb (last argument) is NOT a
5727 SCTP_INP_INCR_REF(inp);
5728 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
5730 SCTP_INP_DECR_REF(inp);
5733 if (stcb && (net == NULL)) {
5734 struct sockaddr *sa;
5736 sa = (struct sockaddr *)&encaps->sue_address;
5738 if (sa->sa_family == AF_INET) {
5740 struct sockaddr_in *sin;
5742 sin = (struct sockaddr_in *)sa;
5743 if (sin->sin_addr.s_addr) {
5744 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5745 SCTP_TCB_UNLOCK(stcb);
5752 if (sa->sa_family == AF_INET6) {
5753 struct sockaddr_in6 *sin6;
5755 sin6 = (struct sockaddr_in6 *)sa;
5756 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5757 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5758 SCTP_TCB_UNLOCK(stcb);
5765 error = EAFNOSUPPORT;
5766 SCTP_TCB_UNLOCK(stcb);
5767 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5773 net->port = encaps->sue_port;
5775 stcb->asoc.port = encaps->sue_port;
5777 SCTP_TCB_UNLOCK(stcb);
5779 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5780 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5781 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
5782 SCTP_INP_WLOCK(inp);
5783 inp->sctp_ep.port = encaps->sue_port;
5784 SCTP_INP_WUNLOCK(inp);
5786 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5793 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
5794 error = ENOPROTOOPT;
5796 } /* end switch (opt) */
5801 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
5803 void *optval = NULL;
5808 if (sopt->sopt_level != IPPROTO_SCTP) {
5809 /* wrong proto level... send back up to IP */
5811 if (INP_CHECK_SOCKAF(so, AF_INET6))
5812 error = ip6_ctloutput(so, sopt);
5814 #if defined(INET) && defined (INET6)
5818 error = ip_ctloutput(so, sopt);
5822 optsize = sopt->sopt_valsize;
5824 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
5825 if (optval == NULL) {
5826 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
5829 error = sooptcopyin(sopt, optval, optsize, optsize);
5831 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5835 p = (void *)sopt->sopt_td;
5836 if (sopt->sopt_dir == SOPT_SET) {
5837 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
5838 } else if (sopt->sopt_dir == SOPT_GET) {
5839 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
5841 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5844 if ((error == 0) && (optval != NULL)) {
5845 error = sooptcopyout(sopt, optval, optsize);
5846 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5847 } else if (optval != NULL) {
5848 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5856 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
5859 int create_lock_on = 0;
5861 struct sctp_inpcb *inp;
5862 struct sctp_tcb *stcb = NULL;
5864 inp = (struct sctp_inpcb *)so->so_pcb;
5866 /* I made the same as TCP since we are not setup? */
5867 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5868 return (ECONNRESET);
5871 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5874 switch (addr->sa_family) {
5878 struct sockaddr_in6 *sin6p;
5880 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
5881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5884 sin6p = (struct sockaddr_in6 *)addr;
5885 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
5886 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5895 struct sockaddr_in *sinp;
5897 if (addr->sa_len != sizeof(struct sockaddr_in)) {
5898 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5901 sinp = (struct sockaddr_in *)addr;
5902 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
5903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
5911 return (EAFNOSUPPORT);
5913 SCTP_INP_INCR_REF(inp);
5914 SCTP_ASOC_CREATE_LOCK(inp);
5918 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
5919 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
5920 /* Should I really unlock ? */
5921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
5926 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
5927 (addr->sa_family == AF_INET6)) {
5928 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5933 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
5934 SCTP_PCB_FLAGS_UNBOUND) {
5935 /* Bind a ephemeral port */
5936 error = sctp_inpcb_bind(so, NULL, NULL, p);
5941 /* Now do we connect? */
5942 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
5943 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
5944 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5948 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5949 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
5950 /* We are already connected AND the TCP model */
5951 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
5955 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
5956 SCTP_INP_RLOCK(inp);
5957 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5958 SCTP_INP_RUNLOCK(inp);
5961 * We increment here since sctp_findassociation_ep_addr()
5962 * will do a decrement if it finds the stcb as long as the
5963 * locked tcb (last argument) is NOT a TCB.. aka NULL.
5965 SCTP_INP_INCR_REF(inp);
5966 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
5968 SCTP_INP_DECR_REF(inp);
5970 SCTP_TCB_UNLOCK(stcb);
5974 /* Already have or am bring up an association */
5975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
5979 vrf_id = inp->def_vrf_id;
5980 /* We are GOOD to go */
5981 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
5983 /* Gak! no memory */
5986 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
5987 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
5988 /* Set the connected flag so we can queue data */
5991 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
5992 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
5994 /* initialize authentication parameters for the assoc */
5995 sctp_initialize_auth_params(inp, stcb);
5997 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
5998 SCTP_TCB_UNLOCK(stcb);
6000 if (create_lock_on) {
6001 SCTP_ASOC_CREATE_UNLOCK(inp);
6003 SCTP_INP_DECR_REF(inp);
6010 sctp_listen(struct socket *so, int backlog, struct thread *p)
6013 * Note this module depends on the protocol processing being called
6014 * AFTER any socket level flags and backlog are applied to the
6015 * socket. The traditional way that the socket flags are applied is
6016 * AFTER protocol processing. We have made a change to the
6017 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6018 * place if the socket API for SCTP is to work properly.
6022 struct sctp_inpcb *inp;
6024 inp = (struct sctp_inpcb *)so->so_pcb;
6026 /* I made the same as TCP since we are not setup? */
6027 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6028 return (ECONNRESET);
6030 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6031 /* See if we have a listener */
6032 struct sctp_inpcb *tinp;
6033 union sctp_sockstore store, *sp;
6036 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6038 struct sctp_laddr *laddr;
6040 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6041 memcpy(&store, &laddr->ifa->address, sizeof(store));
6042 switch (sp->sa.sa_family) {
6045 sp->sin.sin_port = inp->sctp_lport;
6050 sp->sin6.sin6_port = inp->sctp_lport;
6056 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6057 if (tinp && (tinp != inp) &&
6058 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6059 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6060 (tinp->sctp_socket->so_qlimit)) {
6062 * we have a listener already and
6065 SCTP_INP_DECR_REF(tinp);
6066 return (EADDRINUSE);
6068 SCTP_INP_DECR_REF(tinp);
6072 /* Setup a local addr bound all */
6073 memset(&store, 0, sizeof(store));
6074 switch (sp->sa.sa_family) {
6077 store.sin.sin_port = inp->sctp_lport;
6082 sp->sin6.sin6_port = inp->sctp_lport;
6089 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
6090 store.sa.sa_family = AF_INET6;
6091 store.sa.sa_len = sizeof(struct sockaddr_in6);
6095 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
6096 store.sa.sa_family = AF_INET;
6097 store.sa.sa_len = sizeof(struct sockaddr_in);
6100 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6101 if (tinp && (tinp != inp) &&
6102 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6103 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6104 (tinp->sctp_socket->so_qlimit)) {
6106 * we have a listener already and its not
6109 SCTP_INP_DECR_REF(tinp);
6110 return (EADDRINUSE);
6112 SCTP_INP_DECR_REF(inp);
6116 SCTP_INP_RLOCK(inp);
6117 #ifdef SCTP_LOCK_LOGGING
6118 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
6119 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
6123 error = solisten_proto_check(so);
6126 SCTP_INP_RUNLOCK(inp);
6129 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
6130 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
6132 * The unlucky case - We are in the tcp pool with this guy.
6133 * - Someone else is in the main inp slot. - We must move
6134 * this guy (the listener) to the main slot - We must then
6135 * move the guy that was listener to the TCP Pool.
6137 if (sctp_swap_inpcb_for_listen(inp)) {
6141 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6142 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6143 /* We are already connected AND the TCP model */
6145 SCTP_INP_RUNLOCK(inp);
6147 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6148 return (EADDRINUSE);
6150 SCTP_INP_RUNLOCK(inp);
6151 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
6152 /* We must do a bind. */
6154 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
6155 /* bind error, probably perm */
6160 /* It appears for 7.0 and on, we must always call this. */
6161 solisten_proto(so, backlog);
6162 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6163 /* remove the ACCEPTCONN flag for one-to-many sockets */
6164 so->so_options &= ~SO_ACCEPTCONN;
6167 /* turning off listen */
6168 so->so_options &= ~SO_ACCEPTCONN;
6174 static int sctp_defered_wakeup_cnt = 0;
6177 sctp_accept(struct socket *so, struct sockaddr **addr)
6179 struct sctp_tcb *stcb;
6180 struct sctp_inpcb *inp;
6181 union sctp_sockstore store;
6187 inp = (struct sctp_inpcb *)so->so_pcb;
6190 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6191 return (ECONNRESET);
6193 SCTP_INP_RLOCK(inp);
6194 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6195 SCTP_INP_RUNLOCK(inp);
6196 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
6197 return (EOPNOTSUPP);
6199 if (so->so_state & SS_ISDISCONNECTED) {
6200 SCTP_INP_RUNLOCK(inp);
6201 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
6202 return (ECONNABORTED);
6204 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6206 SCTP_INP_RUNLOCK(inp);
6207 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6208 return (ECONNRESET);
6210 SCTP_TCB_LOCK(stcb);
6211 SCTP_INP_RUNLOCK(inp);
6212 store = stcb->asoc.primary_destination->ro._l_addr;
6213 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
6214 SCTP_TCB_UNLOCK(stcb);
6215 switch (store.sa.sa_family) {
6219 struct sockaddr_in *sin;
6221 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6224 sin->sin_family = AF_INET;
6225 sin->sin_len = sizeof(*sin);
6226 sin->sin_port = ((struct sockaddr_in *)&store)->sin_port;
6227 sin->sin_addr = ((struct sockaddr_in *)&store)->sin_addr;
6228 *addr = (struct sockaddr *)sin;
6235 struct sockaddr_in6 *sin6;
6237 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
6240 sin6->sin6_family = AF_INET6;
6241 sin6->sin6_len = sizeof(*sin6);
6242 sin6->sin6_port = ((struct sockaddr_in6 *)&store)->sin6_port;
6244 sin6->sin6_addr = ((struct sockaddr_in6 *)&store)->sin6_addr;
6245 if ((error = sa6_recoverscope(sin6)) != 0) {
6246 SCTP_FREE_SONAME(sin6);
6249 *addr = (struct sockaddr *)sin6;
6257 /* Wake any delayed sleep action */
6258 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
6259 SCTP_INP_WLOCK(inp);
6260 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
6261 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
6262 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
6263 SCTP_INP_WUNLOCK(inp);
6264 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
6265 if (sowriteable(inp->sctp_socket)) {
6266 sowwakeup_locked(inp->sctp_socket);
6268 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
6270 SCTP_INP_WLOCK(inp);
6272 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
6273 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
6274 SCTP_INP_WUNLOCK(inp);
6275 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
6276 if (soreadable(inp->sctp_socket)) {
6277 sctp_defered_wakeup_cnt++;
6278 sorwakeup_locked(inp->sctp_socket);
6280 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
6282 SCTP_INP_WLOCK(inp);
6284 SCTP_INP_WUNLOCK(inp);
6286 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
6287 SCTP_TCB_LOCK(stcb);
6288 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
6295 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
6297 struct sockaddr_in *sin;
6299 struct sctp_inpcb *inp;
6300 struct sctp_ifa *sctp_ifa;
6303 * Do the malloc first in case it blocks.
6305 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6308 sin->sin_family = AF_INET;
6309 sin->sin_len = sizeof(*sin);
6310 inp = (struct sctp_inpcb *)so->so_pcb;
6312 SCTP_FREE_SONAME(sin);
6313 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6314 return (ECONNRESET);
6316 SCTP_INP_RLOCK(inp);
6317 sin->sin_port = inp->sctp_lport;
6318 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
6319 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6320 struct sctp_tcb *stcb;
6321 struct sockaddr_in *sin_a;
6322 struct sctp_nets *net;
6325 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6331 SCTP_TCB_LOCK(stcb);
6332 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6333 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6335 /* this will make coverity happy */
6338 if (sin_a->sin_family == AF_INET) {
6343 if ((!fnd) || (sin_a == NULL)) {
6345 SCTP_TCB_UNLOCK(stcb);
6348 vrf_id = inp->def_vrf_id;
6349 sctp_ifa = sctp_source_address_selection(inp,
6351 (sctp_route_t *) & net->ro,
6354 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
6355 sctp_free_ifa(sctp_ifa);
6357 SCTP_TCB_UNLOCK(stcb);
6359 /* For the bound all case you get back 0 */
6361 sin->sin_addr.s_addr = 0;
6365 /* Take the first IPv4 address in the list */
6366 struct sctp_laddr *laddr;
6369 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6370 if (laddr->ifa->address.sa.sa_family == AF_INET) {
6371 struct sockaddr_in *sin_a;
6373 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
6374 sin->sin_addr = sin_a->sin_addr;
6380 SCTP_FREE_SONAME(sin);
6381 SCTP_INP_RUNLOCK(inp);
6382 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6386 SCTP_INP_RUNLOCK(inp);
6387 (*addr) = (struct sockaddr *)sin;
6392 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
6394 struct sockaddr_in *sin;
6396 struct sockaddr_in *sin_a;
6397 struct sctp_inpcb *inp;
6398 struct sctp_tcb *stcb;
6399 struct sctp_nets *net;
6401 /* Do the malloc first in case it blocks. */
6402 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6405 sin->sin_family = AF_INET;
6406 sin->sin_len = sizeof(*sin);
6408 inp = (struct sctp_inpcb *)so->so_pcb;
6409 if ((inp == NULL) ||
6410 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
6411 /* UDP type and listeners will drop out here */
6412 SCTP_FREE_SONAME(sin);
6413 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
6416 SCTP_INP_RLOCK(inp);
6417 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6419 SCTP_TCB_LOCK(stcb);
6421 SCTP_INP_RUNLOCK(inp);
6423 SCTP_FREE_SONAME(sin);
6424 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6425 return (ECONNRESET);
6428 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6429 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6430 if (sin_a->sin_family == AF_INET) {
6432 sin->sin_port = stcb->rport;
6433 sin->sin_addr = sin_a->sin_addr;
6437 SCTP_TCB_UNLOCK(stcb);
6439 /* No IPv4 address */
6440 SCTP_FREE_SONAME(sin);
6441 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6444 (*addr) = (struct sockaddr *)sin;
6449 struct pr_usrreqs sctp_usrreqs = {
6450 .pru_abort = sctp_abort,
6451 .pru_accept = sctp_accept,
6452 .pru_attach = sctp_attach,
6453 .pru_bind = sctp_bind,
6454 .pru_connect = sctp_connect,
6455 .pru_control = in_control,
6456 .pru_close = sctp_close,
6457 .pru_detach = sctp_close,
6458 .pru_sopoll = sopoll_generic,
6459 .pru_flush = sctp_flush,
6460 .pru_disconnect = sctp_disconnect,
6461 .pru_listen = sctp_listen,
6462 .pru_peeraddr = sctp_peeraddr,
6463 .pru_send = sctp_sendm,
6464 .pru_shutdown = sctp_shutdown,
6465 .pru_sockaddr = sctp_ingetaddr,
6466 .pru_sosend = sctp_sosend,
6467 .pru_soreceive = sctp_soreceive