2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2011, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2011, by Michael Tuexen. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 /* $KAME: sctp_usrreq.c,v 1.48 2005/03/07 23:26:08 itojun Exp $ */
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
37 #include <netinet/sctp_os.h>
39 #include <netinet/sctp_pcb.h>
40 #include <netinet/sctp_header.h>
41 #include <netinet/sctp_var.h>
44 #include <netinet/sctp_sysctl.h>
45 #include <netinet/sctp_output.h>
46 #include <netinet/sctp_uio.h>
47 #include <netinet/sctp_asconf.h>
48 #include <netinet/sctputil.h>
49 #include <netinet/sctp_indata.h>
50 #include <netinet/sctp_timer.h>
51 #include <netinet/sctp_auth.h>
52 #include <netinet/sctp_bsd_addr.h>
53 #include <netinet/udp.h>
57 extern struct sctp_cc_functions sctp_cc_functions[];
58 extern struct sctp_ss_functions sctp_ss_functions[];
65 /* Initialize and modify the sysctled variables */
67 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
68 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
70 * Allow a user to take no more than 1/2 the number of clusters or
71 * the SB_MAX whichever is smaller for the send window.
73 sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
74 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
75 (((uint32_t) nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
77 * Now for the recv window, should we take the same amount? or
78 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
79 * now I will just copy.
81 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
83 SCTP_BASE_VAR(first_time) = 0;
84 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
86 #if defined(SCTP_PACKET_LOGGING)
87 SCTP_BASE_VAR(packet_log_writers) = 0;
88 SCTP_BASE_VAR(packet_log_end) = 0;
89 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
104 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
106 struct sctp_tmit_chunk *chk;
109 /* Adjust that too */
110 stcb->asoc.smallest_mtu = nxtsz;
111 /* now off to subtract IP_DF flag if needed */
112 overhead = IP_HDR_SIZE;
113 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
114 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
116 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
117 if ((chk->send_size + overhead) > nxtsz) {
118 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
121 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
122 if ((chk->send_size + overhead) > nxtsz) {
124 * For this guy we also mark for immediate resend
125 * since we sent to big of chunk
127 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
128 if (chk->sent < SCTP_DATAGRAM_RESEND) {
129 sctp_flight_size_decrease(chk);
130 sctp_total_flight_decrease(stcb, chk);
132 if (chk->sent != SCTP_DATAGRAM_RESEND) {
133 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
135 chk->sent = SCTP_DATAGRAM_RESEND;
136 chk->rec.data.doing_fast_retransmit = 0;
137 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
138 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
139 chk->whoTo->flight_size,
141 (uintptr_t) chk->whoTo,
142 chk->rec.data.TSN_seq);
144 /* Clear any time so NO RTT is being done */
152 sctp_notify_mbuf(struct sctp_inpcb *inp,
153 struct sctp_tcb *stcb,
154 struct sctp_nets *net,
159 int totsz, tmr_stopped = 0;
163 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
164 (ip == NULL) || (sh == NULL)) {
166 SCTP_TCB_UNLOCK(stcb);
170 /* First job is to verify the vtag matches what I would send */
171 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
172 SCTP_TCB_UNLOCK(stcb);
175 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
177 if (icmph->icmp_type != ICMP_UNREACH) {
178 /* We only care about unreachable */
179 SCTP_TCB_UNLOCK(stcb);
182 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
183 /* not a unreachable message due to frag. */
184 SCTP_TCB_UNLOCK(stcb);
189 nxtsz = ntohs(icmph->icmp_nextmtu);
192 * old type router that does not tell us what the next size
193 * mtu is. Rats we will have to guess (in a educated fashion
196 nxtsz = sctp_get_prev_mtu(totsz);
198 /* Stop any PMTU timer */
199 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
201 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
202 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
204 /* Adjust destination size limit */
205 if (net->mtu > nxtsz) {
208 net->mtu -= sizeof(struct udphdr);
211 /* now what about the ep? */
212 if (stcb->asoc.smallest_mtu > nxtsz) {
213 sctp_pathmtu_adjustment(stcb, nxtsz);
216 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
218 SCTP_TCB_UNLOCK(stcb);
224 sctp_notify(struct sctp_inpcb *inp,
228 struct sctp_tcb *stcb,
229 struct sctp_nets *net)
231 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
240 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
241 (sh == NULL) || (to == NULL)) {
243 SCTP_TCB_UNLOCK(stcb);
246 /* First job is to verify the vtag matches what I would send */
247 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
248 SCTP_TCB_UNLOCK(stcb);
251 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
253 if (icmph->icmp_type != ICMP_UNREACH) {
254 /* We only care about unreachable */
255 SCTP_TCB_UNLOCK(stcb);
258 if ((icmph->icmp_code == ICMP_UNREACH_NET) ||
259 (icmph->icmp_code == ICMP_UNREACH_HOST) ||
260 (icmph->icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
261 (icmph->icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
262 (icmph->icmp_code == ICMP_UNREACH_ISOLATED) ||
263 (icmph->icmp_code == ICMP_UNREACH_NET_PROHIB) ||
264 (icmph->icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
265 (icmph->icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
268 * Hmm reachablity problems we must examine closely. If its
269 * not reachable, we may have lost a network. Or if there is
270 * NO protocol at the other end named SCTP. well we consider
273 if (net->dest_state & SCTP_ADDR_REACHABLE) {
274 /* Ok that destination is NOT reachable */
275 net->dest_state &= ~SCTP_ADDR_REACHABLE;
276 net->dest_state &= ~SCTP_ADDR_PF;
277 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
278 stcb, SCTP_FAILED_THRESHOLD,
279 (void *)net, SCTP_SO_NOT_LOCKED);
281 SCTP_TCB_UNLOCK(stcb);
282 } else if ((icmph->icmp_code == ICMP_UNREACH_PROTOCOL) ||
283 (icmph->icmp_code == ICMP_UNREACH_PORT)) {
285 * Here the peer is either playing tricks on us, including
286 * an address that belongs to someone who does not support
287 * SCTP OR was a userland implementation that shutdown and
288 * now is dead. In either case treat it like a OOTB abort
291 reason = SCTP_PEER_FAULTY;
292 sctp_abort_notification(stcb, reason, SCTP_SO_NOT_LOCKED);
293 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
294 so = SCTP_INP_SO(inp);
295 atomic_add_int(&stcb->asoc.refcnt, 1);
296 SCTP_TCB_UNLOCK(stcb);
297 SCTP_SOCKET_LOCK(so, 1);
299 atomic_subtract_int(&stcb->asoc.refcnt, 1);
301 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
302 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
303 SCTP_SOCKET_UNLOCK(so, 1);
304 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
306 /* no need to unlock here, since the TCB is gone */
308 SCTP_TCB_UNLOCK(stcb);
314 sctp_ctlinput(cmd, sa, vip)
323 /* FIX, for non-bsd is this right? */
324 vrf_id = SCTP_DEFAULT_VRFID;
325 if (sa->sa_family != AF_INET ||
326 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
329 if (PRC_IS_REDIRECT(cmd)) {
331 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
335 struct sctp_inpcb *inp = NULL;
336 struct sctp_tcb *stcb = NULL;
337 struct sctp_nets *net = NULL;
338 struct sockaddr_in to, from;
340 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
341 bzero(&to, sizeof(to));
342 bzero(&from, sizeof(from));
343 from.sin_family = to.sin_family = AF_INET;
344 from.sin_len = to.sin_len = sizeof(to);
345 from.sin_port = sh->src_port;
346 from.sin_addr = ip->ip_src;
347 to.sin_port = sh->dest_port;
348 to.sin_addr = ip->ip_dst;
351 * 'to' holds the dest of the packet that failed to be sent.
352 * 'from' holds our local endpoint address. Thus we reverse
353 * the to and the from in the lookup.
355 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&from,
356 (struct sockaddr *)&to,
357 &inp, &net, 1, vrf_id);
358 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
359 if (cmd != PRC_MSGSIZE) {
360 sctp_notify(inp, ip, sh,
361 (struct sockaddr *)&to, stcb,
364 /* handle possible ICMP size messages */
365 sctp_notify_mbuf(inp, stcb, net, ip, sh);
368 if ((stcb == NULL) && (inp != NULL)) {
369 /* reduce ref-count */
371 SCTP_INP_DECR_REF(inp);
372 SCTP_INP_WUNLOCK(inp);
375 SCTP_TCB_UNLOCK(stcb);
385 sctp_getcred(SYSCTL_HANDLER_ARGS)
388 struct sockaddr_in addrs[2];
389 struct sctp_inpcb *inp;
390 struct sctp_nets *net;
391 struct sctp_tcb *stcb;
395 /* FIX, for non-bsd is this right? */
396 vrf_id = SCTP_DEFAULT_VRFID;
398 error = priv_check(req->td, PRIV_NETINET_GETCRED);
403 error = SYSCTL_IN(req, addrs, sizeof(addrs));
407 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[0]),
409 &inp, &net, 1, vrf_id);
410 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
411 if ((inp != NULL) && (stcb == NULL)) {
412 /* reduce ref-count */
414 SCTP_INP_DECR_REF(inp);
417 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
421 SCTP_TCB_UNLOCK(stcb);
423 * We use the write lock here, only since in the error leg we need
424 * it. If we used RLOCK, then we would have to
425 * wlock/decr/unlock/rlock. Which in theory could create a hole.
426 * Better to use higher wlock.
430 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
432 SCTP_INP_WUNLOCK(inp);
435 cru2x(inp->sctp_socket->so_cred, &xuc);
436 SCTP_INP_WUNLOCK(inp);
437 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
442 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
443 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
448 sctp_abort(struct socket *so)
450 struct sctp_inpcb *inp;
453 inp = (struct sctp_inpcb *)so->so_pcb;
458 flags = inp->sctp_flags;
459 #ifdef SCTP_LOG_CLOSING
460 sctp_log_closing(inp, NULL, 17);
462 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
463 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
464 #ifdef SCTP_LOG_CLOSING
465 sctp_log_closing(inp, NULL, 16);
467 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
468 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
470 SCTP_SB_CLEAR(so->so_snd);
472 * same for the rcv ones, they are only here for the
475 SCTP_SB_CLEAR(so->so_rcv);
477 /* Now null out the reference, we are completely detached. */
481 flags = inp->sctp_flags;
482 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
483 goto sctp_must_try_again;
490 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
492 struct sctp_inpcb *inp;
493 struct inpcb *ip_inp;
495 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
502 inp = (struct sctp_inpcb *)so->so_pcb;
504 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
507 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
508 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
513 error = sctp_inpcb_alloc(so, vrf_id);
517 inp = (struct sctp_inpcb *)so->so_pcb;
519 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
520 ip_inp = &inp->ip_inp.inp;
521 ip_inp->inp_vflag |= INP_IPV4;
522 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
524 error = ipsec_init_policy(so, &ip_inp->inp_sp);
525 #ifdef SCTP_LOG_CLOSING
526 sctp_log_closing(inp, NULL, 17);
530 flags = inp->sctp_flags;
531 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
532 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
533 #ifdef SCTP_LOG_CLOSING
534 sctp_log_closing(inp, NULL, 15);
536 SCTP_INP_WUNLOCK(inp);
537 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
538 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
540 flags = inp->sctp_flags;
541 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
544 SCTP_INP_WUNLOCK(inp);
550 SCTP_INP_WUNLOCK(inp);
555 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
557 struct sctp_inpcb *inp = NULL;
561 if (addr && addr->sa_family != AF_INET) {
562 /* must be a v4 address! */
563 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
567 if (addr && (addr->sa_len != sizeof(struct sockaddr_in))) {
568 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
571 inp = (struct sctp_inpcb *)so->so_pcb;
573 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
576 error = sctp_inpcb_bind(so, addr, NULL, p);
582 sctp_close(struct socket *so)
584 struct sctp_inpcb *inp;
587 inp = (struct sctp_inpcb *)so->so_pcb;
592 * Inform all the lower layer assoc that we are done.
595 flags = inp->sctp_flags;
596 #ifdef SCTP_LOG_CLOSING
597 sctp_log_closing(inp, NULL, 17);
599 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
600 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
601 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
602 (so->so_rcv.sb_cc > 0)) {
603 #ifdef SCTP_LOG_CLOSING
604 sctp_log_closing(inp, NULL, 13);
606 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
607 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
609 #ifdef SCTP_LOG_CLOSING
610 sctp_log_closing(inp, NULL, 14);
612 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
613 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
616 * The socket is now detached, no matter what the state of
617 * the SCTP association.
620 SCTP_SB_CLEAR(so->so_snd);
622 * same for the rcv ones, they are only here for the
625 SCTP_SB_CLEAR(so->so_rcv);
627 /* Now null out the reference, we are completely detached. */
631 flags = inp->sctp_flags;
632 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
633 goto sctp_must_try_again;
641 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
642 struct mbuf *control, struct thread *p);
646 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
647 struct mbuf *control, struct thread *p)
649 struct sctp_inpcb *inp;
652 inp = (struct sctp_inpcb *)so->so_pcb;
655 sctp_m_freem(control);
658 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
662 /* Got to have an to address if we are NOT a connected socket */
663 if ((addr == NULL) &&
664 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
665 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
667 } else if (addr == NULL) {
668 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
669 error = EDESTADDRREQ;
672 sctp_m_freem(control);
678 if (addr->sa_family != AF_INET) {
679 /* must be a v4 address! */
680 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
683 sctp_m_freem(control);
686 error = EDESTADDRREQ;
691 /* now what about control */
694 SCTP_PRINTF("huh? control set?\n");
695 sctp_m_freem(inp->control);
698 inp->control = control;
702 SCTP_BUF_NEXT(inp->pkt_last) = m;
705 inp->pkt_last = inp->pkt = m;
708 /* FreeBSD uses a flag passed */
709 ((flags & PRUS_MORETOCOME) == 0)
712 * note with the current version this code will only be used
713 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
714 * re-defining sosend to use the sctp_sosend. One can
715 * optionally switch back to this code (by changing back the
716 * definitions) but this is not advisable. This code is used
717 * by FreeBSD when sending a file with sendfile() though.
721 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
731 sctp_disconnect(struct socket *so)
733 struct sctp_inpcb *inp;
735 inp = (struct sctp_inpcb *)so->so_pcb;
737 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
741 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
742 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
743 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
745 SCTP_INP_RUNLOCK(inp);
748 struct sctp_association *asoc;
749 struct sctp_tcb *stcb;
751 stcb = LIST_FIRST(&inp->sctp_asoc_list);
753 SCTP_INP_RUNLOCK(inp);
754 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
759 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
760 /* We are about to be freed, out of here */
761 SCTP_TCB_UNLOCK(stcb);
762 SCTP_INP_RUNLOCK(inp);
765 if (((so->so_options & SO_LINGER) &&
766 (so->so_linger == 0)) ||
767 (so->so_rcv.sb_cc > 0)) {
768 if (SCTP_GET_STATE(asoc) !=
769 SCTP_STATE_COOKIE_WAIT) {
770 /* Left with Data unread */
773 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_DONTWAIT, 1, MT_DATA);
779 struct sctp_paramhdr *ph;
781 ph = mtod(err, struct sctp_paramhdr *);
782 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
783 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
784 ph->param_length = htons(SCTP_BUF_LEN(err));
786 #if defined(SCTP_PANIC_ON_ABORT)
787 panic("disconnect does an abort");
789 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
790 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
792 SCTP_INP_RUNLOCK(inp);
793 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
794 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
795 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
797 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
798 /* No unlock tcb assoc is gone */
801 if (TAILQ_EMPTY(&asoc->send_queue) &&
802 TAILQ_EMPTY(&asoc->sent_queue) &&
803 (asoc->stream_queue_cnt == 0)) {
804 /* there is nothing queued to send, so done */
805 if (asoc->locked_on_sending) {
808 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
809 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
810 /* only send SHUTDOWN 1st time thru */
811 struct sctp_nets *netp;
813 if (stcb->asoc.alternate) {
814 netp = stcb->asoc.alternate;
816 netp = stcb->asoc.primary_destination;
818 sctp_stop_timers_for_shutdown(stcb);
819 sctp_send_shutdown(stcb, netp);
820 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
821 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
822 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
823 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
825 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
826 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
827 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
828 stcb->sctp_ep, stcb, netp);
829 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
830 stcb->sctp_ep, stcb, netp);
835 * we still got (or just got) data to send,
836 * so set SHUTDOWN_PENDING
839 * XXX sockets draft says that SCTP_EOF
840 * should be sent with no data. currently,
841 * we will allow user data to be sent first
842 * and move to SHUTDOWN-PENDING
844 struct sctp_nets *netp;
846 if (stcb->asoc.alternate) {
847 netp = stcb->asoc.alternate;
849 netp = stcb->asoc.primary_destination;
852 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
853 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
855 if (asoc->locked_on_sending) {
856 /* Locked to send out the data */
857 struct sctp_stream_queue_pending *sp;
859 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
861 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
862 asoc->locked_on_sending->stream_no);
864 if ((sp->length == 0) && (sp->msg_is_complete == 0))
865 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
868 if (TAILQ_EMPTY(&asoc->send_queue) &&
869 TAILQ_EMPTY(&asoc->sent_queue) &&
870 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
874 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
875 0, M_DONTWAIT, 1, MT_DATA);
881 struct sctp_paramhdr *ph;
884 SCTP_BUF_LEN(op_err) =
885 (sizeof(struct sctp_paramhdr) + sizeof(uint32_t));
887 struct sctp_paramhdr *);
888 ph->param_type = htons(
889 SCTP_CAUSE_USER_INITIATED_ABT);
890 ph->param_length = htons(SCTP_BUF_LEN(op_err));
891 ippp = (uint32_t *) (ph + 1);
892 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4);
894 #if defined(SCTP_PANIC_ON_ABORT)
895 panic("disconnect does an abort");
898 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
899 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
900 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
901 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
902 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
903 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
905 SCTP_INP_RUNLOCK(inp);
906 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
909 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
912 soisdisconnecting(so);
913 SCTP_TCB_UNLOCK(stcb);
914 SCTP_INP_RUNLOCK(inp);
919 /* UDP model does not support this */
920 SCTP_INP_RUNLOCK(inp);
921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
927 sctp_flush(struct socket *so, int how)
930 * We will just clear out the values and let subsequent close clear
931 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
932 * they will not be able to read the data, the socket will block
933 * that from happening.
935 struct sctp_inpcb *inp;
937 inp = (struct sctp_inpcb *)so->so_pcb;
939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
943 /* For the 1 to many model this does nothing */
944 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
945 SCTP_INP_RUNLOCK(inp);
948 SCTP_INP_RUNLOCK(inp);
949 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
951 * First make sure the sb will be happy, we don't use these
952 * except maybe the count
955 SCTP_INP_READ_LOCK(inp);
956 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
957 SCTP_INP_READ_UNLOCK(inp);
958 SCTP_INP_WUNLOCK(inp);
959 so->so_rcv.sb_cc = 0;
960 so->so_rcv.sb_mbcnt = 0;
961 so->so_rcv.sb_mb = NULL;
963 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
965 * First make sure the sb will be happy, we don't use these
966 * except maybe the count
968 so->so_snd.sb_cc = 0;
969 so->so_snd.sb_mbcnt = 0;
970 so->so_snd.sb_mb = NULL;
977 sctp_shutdown(struct socket *so)
979 struct sctp_inpcb *inp;
981 inp = (struct sctp_inpcb *)so->so_pcb;
983 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
987 /* For UDP model this is a invalid call */
988 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
989 /* Restore the flags that the soshutdown took away. */
990 SOCKBUF_LOCK(&so->so_rcv);
991 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
992 SOCKBUF_UNLOCK(&so->so_rcv);
993 /* This proc will wakeup for read and do nothing (I hope) */
994 SCTP_INP_RUNLOCK(inp);
995 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
999 * Ok if we reach here its the TCP model and it is either a SHUT_WR
1000 * or SHUT_RDWR. This means we put the shutdown flag against it.
1003 struct sctp_tcb *stcb;
1004 struct sctp_association *asoc;
1007 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
1008 SCTP_INP_RUNLOCK(inp);
1013 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1016 * Ok we hit the case that the shutdown call was
1017 * made after an abort or something. Nothing to do
1020 SCTP_INP_RUNLOCK(inp);
1023 SCTP_TCB_LOCK(stcb);
1025 if (TAILQ_EMPTY(&asoc->send_queue) &&
1026 TAILQ_EMPTY(&asoc->sent_queue) &&
1027 (asoc->stream_queue_cnt == 0)) {
1028 if (asoc->locked_on_sending) {
1031 /* there is nothing queued to send, so I'm done... */
1032 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
1033 /* only send SHUTDOWN the first time through */
1034 struct sctp_nets *netp;
1036 if (stcb->asoc.alternate) {
1037 netp = stcb->asoc.alternate;
1039 netp = stcb->asoc.primary_destination;
1041 sctp_stop_timers_for_shutdown(stcb);
1042 sctp_send_shutdown(stcb, netp);
1043 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
1044 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
1045 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1046 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1048 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
1049 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
1050 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1051 stcb->sctp_ep, stcb, netp);
1052 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1053 stcb->sctp_ep, stcb, netp);
1057 * we still got (or just got) data to send, so set
1060 struct sctp_nets *netp;
1062 if (stcb->asoc.alternate) {
1063 netp = stcb->asoc.alternate;
1065 netp = stcb->asoc.primary_destination;
1068 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1069 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1072 if (asoc->locked_on_sending) {
1073 /* Locked to send out the data */
1074 struct sctp_stream_queue_pending *sp;
1076 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1078 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1079 asoc->locked_on_sending->stream_no);
1081 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1082 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1086 if (TAILQ_EMPTY(&asoc->send_queue) &&
1087 TAILQ_EMPTY(&asoc->sent_queue) &&
1088 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1089 struct mbuf *op_err;
1092 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
1093 0, M_DONTWAIT, 1, MT_DATA);
1095 /* Fill in the user initiated abort */
1096 struct sctp_paramhdr *ph;
1099 SCTP_BUF_LEN(op_err) =
1100 sizeof(struct sctp_paramhdr) + sizeof(uint32_t);
1102 struct sctp_paramhdr *);
1103 ph->param_type = htons(
1104 SCTP_CAUSE_USER_INITIATED_ABT);
1105 ph->param_length = htons(SCTP_BUF_LEN(op_err));
1106 ippp = (uint32_t *) (ph + 1);
1107 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1109 #if defined(SCTP_PANIC_ON_ABORT)
1110 panic("shutdown does an abort");
1112 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1113 sctp_abort_an_association(stcb->sctp_ep, stcb,
1114 SCTP_RESPONSE_TO_USER_REQ,
1115 op_err, SCTP_SO_LOCKED);
1118 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1121 SCTP_TCB_UNLOCK(stcb);
1124 SCTP_INP_RUNLOCK(inp);
1129 * copies a "user" presentable address and removes embedded scope, etc.
1130 * returns 0 on success, 1 on error
1133 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1136 struct sockaddr_in6 lsa6;
1138 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1141 memcpy(ss, sa, sa->sa_len);
1148 * NOTE: assumes addr lock is held
1151 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1152 struct sctp_tcb *stcb,
1154 struct sockaddr_storage *sas,
1157 struct sctp_ifn *sctp_ifn;
1158 struct sctp_ifa *sctp_ifa;
1159 int loopback_scope, ipv4_local_scope, local_scope, site_scope;
1161 int ipv4_addr_legal, ipv6_addr_legal;
1162 struct sctp_vrf *vrf;
1169 /* Turn on all the appropriate scope */
1170 loopback_scope = stcb->asoc.loopback_scope;
1171 ipv4_local_scope = stcb->asoc.ipv4_local_scope;
1172 local_scope = stcb->asoc.local_scope;
1173 site_scope = stcb->asoc.site_scope;
1175 /* Turn on ALL scope, since we look at the EP */
1176 loopback_scope = ipv4_local_scope = local_scope =
1179 ipv4_addr_legal = ipv6_addr_legal = 0;
1180 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1181 ipv6_addr_legal = 1;
1182 if (SCTP_IPV6_V6ONLY(inp) == 0) {
1183 ipv4_addr_legal = 1;
1186 ipv4_addr_legal = 1;
1188 vrf = sctp_find_vrf(vrf_id);
1192 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1193 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1194 if ((loopback_scope == 0) &&
1195 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1196 /* Skip loopback if loopback_scope not set */
1199 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1202 * For the BOUND-ALL case, the list
1203 * associated with a TCB is Always
1204 * considered a reverse list.. i.e.
1205 * it lists addresses that are NOT
1206 * part of the association. If this
1207 * is one of those we must skip it.
1209 if (sctp_is_addr_restricted(stcb,
1214 switch (sctp_ifa->address.sa.sa_family) {
1217 if (ipv4_addr_legal) {
1218 struct sockaddr_in *sin;
1220 sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
1221 if (sin->sin_addr.s_addr == 0) {
1229 if ((ipv4_local_scope == 0) &&
1230 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1234 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1235 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1236 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1237 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1238 actual += sizeof(struct sockaddr_in6);
1241 memcpy(sas, sin, sizeof(*sin));
1242 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1243 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1244 actual += sizeof(*sin);
1248 if (actual >= limit) {
1258 if (ipv6_addr_legal) {
1259 struct sockaddr_in6 *sin6;
1261 sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
1262 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1270 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1271 if (local_scope == 0)
1273 if (sin6->sin6_scope_id == 0) {
1274 if (sa6_recoverscope(sin6) != 0)
1292 if ((site_scope == 0) &&
1293 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1296 memcpy(sas, sin6, sizeof(*sin6));
1297 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1298 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1299 actual += sizeof(*sin6);
1300 if (actual >= limit) {
1315 struct sctp_laddr *laddr;
1317 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1319 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1323 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1326 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1327 sas = (struct sockaddr_storage *)((caddr_t)sas +
1328 laddr->ifa->address.sa.sa_len);
1329 actual += laddr->ifa->address.sa.sa_len;
1330 if (actual >= limit) {
1339 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1340 struct sctp_tcb *stcb,
1342 struct sockaddr_storage *sas)
1346 SCTP_IPI_ADDR_RLOCK();
1347 /* fill up addresses for the endpoint's default vrf */
1348 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1350 SCTP_IPI_ADDR_RUNLOCK();
1355 * NOTE: assumes addr lock is held
1358 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1361 struct sctp_vrf *vrf = NULL;
1364 * In both sub-set bound an bound_all cases we return the MAXIMUM
1365 * number of addresses that you COULD get. In reality the sub-set
1366 * bound may have an exclusion list for a given TCB OR in the
1367 * bound-all case a TCB may NOT include the loopback or other
1368 * addresses as well.
1370 vrf = sctp_find_vrf(vrf_id);
1374 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1375 struct sctp_ifn *sctp_ifn;
1376 struct sctp_ifa *sctp_ifa;
1378 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1379 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1380 /* Count them if they are the right type */
1381 switch (sctp_ifa->address.sa.sa_family) {
1384 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1385 cnt += sizeof(struct sockaddr_in6);
1387 cnt += sizeof(struct sockaddr_in);
1392 cnt += sizeof(struct sockaddr_in6);
1401 struct sctp_laddr *laddr;
1403 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1404 switch (laddr->ifa->address.sa.sa_family) {
1407 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1408 cnt += sizeof(struct sockaddr_in6);
1410 cnt += sizeof(struct sockaddr_in);
1415 cnt += sizeof(struct sockaddr_in6);
1427 sctp_count_max_addresses(struct sctp_inpcb *inp)
1431 SCTP_IPI_ADDR_RLOCK();
1432 /* count addresses for the endpoint's default VRF */
1433 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1434 SCTP_IPI_ADDR_RUNLOCK();
1439 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1440 size_t optsize, void *p, int delay)
1443 int creat_lock_on = 0;
1444 struct sctp_tcb *stcb = NULL;
1445 struct sockaddr *sa;
1446 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1448 int bad_addresses = 0;
1451 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1453 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1454 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1455 /* We are already connected AND the TCP model */
1456 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1457 return (EADDRINUSE);
1459 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1460 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1461 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1464 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1465 SCTP_INP_RLOCK(inp);
1466 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1467 SCTP_INP_RUNLOCK(inp);
1470 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1473 SCTP_INP_INCR_REF(inp);
1474 SCTP_ASOC_CREATE_LOCK(inp);
1476 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1477 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1478 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1482 totaddrp = (int *)optval;
1483 totaddr = *totaddrp;
1484 sa = (struct sockaddr *)(totaddrp + 1);
1485 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
1486 if ((stcb != NULL) || bad_addresses) {
1487 /* Already have or am bring up an association */
1488 SCTP_ASOC_CREATE_UNLOCK(inp);
1491 SCTP_TCB_UNLOCK(stcb);
1492 if (bad_addresses == 0) {
1493 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1499 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1504 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1506 struct in6pcb *inp6;
1508 inp6 = (struct in6pcb *)inp;
1509 if (SCTP_IPV6_V6ONLY(inp6)) {
1511 * if IPV6_V6ONLY flag, ignore connections destined
1512 * to a v4 addr or v4-mapped addr
1514 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1520 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1521 SCTP_PCB_FLAGS_UNBOUND) {
1522 /* Bind a ephemeral port */
1523 error = sctp_inpcb_bind(so, NULL, NULL, p);
1528 /* FIX ME: do we want to pass in a vrf on the connect call? */
1529 vrf_id = inp->def_vrf_id;
1532 /* We are GOOD to go */
1533 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1537 /* Gak! no memory */
1540 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1541 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1542 /* Set the connected flag so we can queue data */
1545 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1546 /* move to second address */
1547 switch (sa->sa_family) {
1550 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1555 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1563 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1564 /* Fill in the return id */
1566 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1569 a_id = (sctp_assoc_t *) optval;
1570 *a_id = sctp_get_associd(stcb);
1572 /* initialize authentication parameters for the assoc */
1573 sctp_initialize_auth_params(inp, stcb);
1576 /* doing delayed connection */
1577 stcb->asoc.delayed_connection = 1;
1578 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1580 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1581 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1583 SCTP_TCB_UNLOCK(stcb);
1584 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1585 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1586 /* Set the connected flag so we can queue data */
1590 if (creat_lock_on) {
1591 SCTP_ASOC_CREATE_UNLOCK(inp);
1593 SCTP_INP_DECR_REF(inp);
1597 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1598 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1599 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1600 SCTP_INP_RLOCK(inp); \
1601 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1603 SCTP_TCB_LOCK(stcb); \
1605 SCTP_INP_RUNLOCK(inp); \
1606 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1607 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1608 if (stcb == NULL) { \
1609 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1619 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1620 if (size < sizeof(type)) { \
1621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1625 destp = (type *)srcp; \
1630 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1633 struct sctp_inpcb *inp = NULL;
1635 struct sctp_tcb *stcb = NULL;
1637 if (optval == NULL) {
1638 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1641 inp = (struct sctp_inpcb *)so->so_pcb;
1643 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1650 case SCTP_AUTOCLOSE:
1651 case SCTP_EXPLICIT_EOR:
1652 case SCTP_AUTO_ASCONF:
1653 case SCTP_DISABLE_FRAGMENTS:
1654 case SCTP_I_WANT_MAPPED_V4_ADDR:
1655 case SCTP_USE_EXT_RCVINFO:
1656 SCTP_INP_RLOCK(inp);
1658 case SCTP_DISABLE_FRAGMENTS:
1659 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1661 case SCTP_I_WANT_MAPPED_V4_ADDR:
1662 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1664 case SCTP_AUTO_ASCONF:
1665 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1666 /* only valid for bound all sockets */
1667 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1669 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1674 case SCTP_EXPLICIT_EOR:
1675 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1678 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1680 case SCTP_USE_EXT_RCVINFO:
1681 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1683 case SCTP_AUTOCLOSE:
1684 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1685 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1692 error = ENOPROTOOPT;
1693 } /* end switch (sopt->sopt_name) */
1694 if (*optsize < sizeof(val)) {
1695 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1699 SCTP_INP_RUNLOCK(inp);
1701 /* return the option value */
1702 *(int *)optval = val;
1703 *optsize = sizeof(val);
1706 case SCTP_GET_PACKET_LOG:
1708 #ifdef SCTP_PACKET_LOGGING
1712 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1713 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1716 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1721 case SCTP_REUSE_PORT:
1725 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1726 /* Can't do this for a 1-m socket */
1730 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1731 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1732 *optsize = sizeof(uint32_t);
1735 case SCTP_PARTIAL_DELIVERY_POINT:
1739 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1740 *value = inp->partial_delivery_point;
1741 *optsize = sizeof(uint32_t);
1744 case SCTP_FRAGMENT_INTERLEAVE:
1748 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1749 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1750 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1751 *value = SCTP_FRAG_LEVEL_2;
1753 *value = SCTP_FRAG_LEVEL_1;
1756 *value = SCTP_FRAG_LEVEL_0;
1758 *optsize = sizeof(uint32_t);
1761 case SCTP_CMT_ON_OFF:
1763 struct sctp_assoc_value *av;
1765 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1766 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1768 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1769 SCTP_TCB_UNLOCK(stcb);
1771 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1772 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1773 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1774 SCTP_INP_RLOCK(inp);
1775 av->assoc_value = inp->sctp_cmt_on_off;
1776 SCTP_INP_RUNLOCK(inp);
1778 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1783 *optsize = sizeof(struct sctp_assoc_value);
1787 case SCTP_PLUGGABLE_CC:
1789 struct sctp_assoc_value *av;
1791 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1792 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1794 av->assoc_value = stcb->asoc.congestion_control_module;
1795 SCTP_TCB_UNLOCK(stcb);
1797 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1798 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1799 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1800 SCTP_INP_RLOCK(inp);
1801 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1802 SCTP_INP_RUNLOCK(inp);
1804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1809 *optsize = sizeof(struct sctp_assoc_value);
1813 case SCTP_CC_OPTION:
1815 struct sctp_cc_option *cc_opt;
1817 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1818 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1822 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1825 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1826 *optsize = sizeof(struct sctp_cc_option);
1828 SCTP_TCB_UNLOCK(stcb);
1832 case SCTP_PLUGGABLE_SS:
1834 struct sctp_assoc_value *av;
1836 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1837 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1839 av->assoc_value = stcb->asoc.stream_scheduling_module;
1840 SCTP_TCB_UNLOCK(stcb);
1842 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1843 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1844 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1845 SCTP_INP_RLOCK(inp);
1846 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1847 SCTP_INP_RUNLOCK(inp);
1849 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1854 *optsize = sizeof(struct sctp_assoc_value);
1860 struct sctp_stream_value *av;
1862 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1863 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1865 if (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1866 &av->stream_value) < 0) {
1867 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1870 *optsize = sizeof(struct sctp_stream_value);
1872 SCTP_TCB_UNLOCK(stcb);
1875 * Can't get stream value without
1878 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1883 case SCTP_GET_ADDR_LEN:
1885 struct sctp_assoc_value *av;
1887 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1890 if (av->assoc_value == AF_INET) {
1891 av->assoc_value = sizeof(struct sockaddr_in);
1896 if (av->assoc_value == AF_INET6) {
1897 av->assoc_value = sizeof(struct sockaddr_in6);
1902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1904 *optsize = sizeof(struct sctp_assoc_value);
1908 case SCTP_GET_ASSOC_NUMBER:
1910 uint32_t *value, cnt;
1912 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1914 SCTP_INP_RLOCK(inp);
1915 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1918 SCTP_INP_RUNLOCK(inp);
1920 *optsize = sizeof(uint32_t);
1923 case SCTP_GET_ASSOC_ID_LIST:
1925 struct sctp_assoc_ids *ids;
1926 unsigned int at, limit;
1928 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1930 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1931 SCTP_INP_RLOCK(inp);
1932 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1934 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1937 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1941 SCTP_INP_RUNLOCK(inp);
1943 ids->gaids_number_of_ids = at;
1944 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1950 struct sctp_assoc_value *av;
1952 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1953 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1956 av->assoc_value = stcb->asoc.context;
1957 SCTP_TCB_UNLOCK(stcb);
1959 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1960 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1961 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1962 SCTP_INP_RLOCK(inp);
1963 av->assoc_value = inp->sctp_context;
1964 SCTP_INP_RUNLOCK(inp);
1966 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1971 *optsize = sizeof(struct sctp_assoc_value);
1977 uint32_t *default_vrfid;
1979 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1980 *default_vrfid = inp->def_vrf_id;
1981 *optsize = sizeof(uint32_t);
1984 case SCTP_GET_ASOC_VRF:
1986 struct sctp_assoc_value *id;
1988 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1989 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1994 id->assoc_value = stcb->asoc.vrf_id;
1995 *optsize = sizeof(struct sctp_assoc_value);
1999 case SCTP_GET_VRF_IDS:
2001 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2005 case SCTP_GET_NONCE_VALUES:
2007 struct sctp_get_nonce_values *gnv;
2009 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2010 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2013 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2014 gnv->gn_local_tag = stcb->asoc.my_vtag;
2015 SCTP_TCB_UNLOCK(stcb);
2016 *optsize = sizeof(struct sctp_get_nonce_values);
2018 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2023 case SCTP_DELAYED_SACK:
2025 struct sctp_sack_info *sack;
2027 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2028 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2030 sack->sack_delay = stcb->asoc.delayed_ack;
2031 sack->sack_freq = stcb->asoc.sack_freq;
2032 SCTP_TCB_UNLOCK(stcb);
2034 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2035 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2036 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2037 SCTP_INP_RLOCK(inp);
2038 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2039 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2040 SCTP_INP_RUNLOCK(inp);
2042 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2047 *optsize = sizeof(struct sctp_sack_info);
2051 case SCTP_GET_SNDBUF_USE:
2053 struct sctp_sockstat *ss;
2055 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2056 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2059 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2060 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2061 stcb->asoc.size_on_all_streams);
2062 SCTP_TCB_UNLOCK(stcb);
2063 *optsize = sizeof(struct sctp_sockstat);
2065 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2070 case SCTP_MAX_BURST:
2074 SCTP_CHECK_AND_CAST(value, optval, uint8_t, *optsize);
2076 SCTP_INP_RLOCK(inp);
2077 if (inp->sctp_ep.max_burst < 256) {
2078 *value = inp->sctp_ep.max_burst;
2082 SCTP_INP_RUNLOCK(inp);
2083 *optsize = sizeof(uint8_t);
2088 struct sctp_assoc_value *av;
2091 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2092 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2095 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2096 SCTP_TCB_UNLOCK(stcb);
2098 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2099 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2100 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2101 SCTP_INP_RLOCK(inp);
2102 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2103 ovh = SCTP_MED_OVERHEAD;
2105 ovh = SCTP_MED_V4_OVERHEAD;
2107 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2108 av->assoc_value = 0;
2110 av->assoc_value = inp->sctp_frag_point - ovh;
2111 SCTP_INP_RUNLOCK(inp);
2113 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2118 *optsize = sizeof(struct sctp_assoc_value);
2122 case SCTP_GET_STAT_LOG:
2123 error = sctp_fill_stat_log(optval, optsize);
2127 struct sctp_event_subscribe *events;
2129 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2130 memset(events, 0, sizeof(struct sctp_event_subscribe));
2131 SCTP_INP_RLOCK(inp);
2132 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2133 events->sctp_data_io_event = 1;
2135 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2136 events->sctp_association_event = 1;
2138 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2139 events->sctp_address_event = 1;
2141 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2142 events->sctp_send_failure_event = 1;
2144 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2145 events->sctp_peer_error_event = 1;
2147 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2148 events->sctp_shutdown_event = 1;
2150 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2151 events->sctp_partial_delivery_event = 1;
2153 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2154 events->sctp_adaptation_layer_event = 1;
2156 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2157 events->sctp_authentication_event = 1;
2159 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2160 events->sctp_sender_dry_event = 1;
2162 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2163 events->sctp_stream_reset_event = 1;
2164 SCTP_INP_RUNLOCK(inp);
2165 *optsize = sizeof(struct sctp_event_subscribe);
2168 case SCTP_ADAPTATION_LAYER:
2172 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2174 SCTP_INP_RLOCK(inp);
2175 *value = inp->sctp_ep.adaptation_layer_indicator;
2176 SCTP_INP_RUNLOCK(inp);
2177 *optsize = sizeof(uint32_t);
2180 case SCTP_SET_INITIAL_DBG_SEQ:
2184 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2185 SCTP_INP_RLOCK(inp);
2186 *value = inp->sctp_ep.initial_sequence_debug;
2187 SCTP_INP_RUNLOCK(inp);
2188 *optsize = sizeof(uint32_t);
2191 case SCTP_GET_LOCAL_ADDR_SIZE:
2195 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2196 SCTP_INP_RLOCK(inp);
2197 *value = sctp_count_max_addresses(inp);
2198 SCTP_INP_RUNLOCK(inp);
2199 *optsize = sizeof(uint32_t);
2202 case SCTP_GET_REMOTE_ADDR_SIZE:
2206 struct sctp_nets *net;
2208 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2209 /* FIXME MT: change to sctp_assoc_value? */
2210 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2214 /* Count the sizes */
2215 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2216 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2217 size += sizeof(struct sockaddr_in6);
2219 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2222 size += sizeof(struct sockaddr_in);
2227 size += sizeof(struct sockaddr_in6);
2235 SCTP_TCB_UNLOCK(stcb);
2236 *value = (uint32_t) size;
2237 *optsize = sizeof(uint32_t);
2239 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2244 case SCTP_GET_PEER_ADDRESSES:
2246 * Get the address information, an array is passed in to
2247 * fill up we pack it.
2251 struct sockaddr_storage *sas;
2252 struct sctp_nets *net;
2253 struct sctp_getaddresses *saddr;
2255 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2256 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2259 left = (*optsize) - sizeof(struct sctp_getaddresses);
2260 *optsize = sizeof(struct sctp_getaddresses);
2261 sas = (struct sockaddr_storage *)&saddr->addr[0];
2263 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2264 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2265 cpsz = sizeof(struct sockaddr_in6);
2267 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2270 cpsz = sizeof(struct sockaddr_in);
2275 cpsz = sizeof(struct sockaddr_in6);
2287 /* not enough room. */
2290 #if defined(INET) && defined(INET6)
2291 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2292 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2293 /* Must map the address */
2294 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2295 (struct sockaddr_in6 *)sas);
2298 memcpy(sas, &net->ro._l_addr, cpsz);
2299 #if defined(INET) && defined(INET6)
2302 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2304 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2308 SCTP_TCB_UNLOCK(stcb);
2310 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2315 case SCTP_GET_LOCAL_ADDRESSES:
2317 size_t limit, actual;
2318 struct sockaddr_storage *sas;
2319 struct sctp_getaddresses *saddr;
2321 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2322 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2324 sas = (struct sockaddr_storage *)&saddr->addr[0];
2325 limit = *optsize - sizeof(sctp_assoc_t);
2326 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2328 SCTP_TCB_UNLOCK(stcb);
2330 *optsize = sizeof(struct sockaddr_storage) + actual;
2333 case SCTP_PEER_ADDR_PARAMS:
2335 struct sctp_paddrparams *paddrp;
2336 struct sctp_nets *net;
2338 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2339 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2343 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2346 * We increment here since
2347 * sctp_findassociation_ep_addr() wil do a
2348 * decrement if it finds the stcb as long as
2349 * the locked tcb (last argument) is NOT a
2352 SCTP_INP_INCR_REF(inp);
2353 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2355 SCTP_INP_DECR_REF(inp);
2358 if (stcb && (net == NULL)) {
2359 struct sockaddr *sa;
2361 sa = (struct sockaddr *)&paddrp->spp_address;
2363 if (sa->sa_family == AF_INET) {
2364 struct sockaddr_in *sin;
2366 sin = (struct sockaddr_in *)sa;
2367 if (sin->sin_addr.s_addr) {
2369 SCTP_TCB_UNLOCK(stcb);
2370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2376 if (sa->sa_family == AF_INET6) {
2377 struct sockaddr_in6 *sin6;
2379 sin6 = (struct sockaddr_in6 *)sa;
2380 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2382 SCTP_TCB_UNLOCK(stcb);
2383 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2389 error = EAFNOSUPPORT;
2390 SCTP_TCB_UNLOCK(stcb);
2391 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2396 /* Applies to the specific association */
2397 paddrp->spp_flags = 0;
2401 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2402 ovh = SCTP_MED_OVERHEAD;
2404 ovh = SCTP_MED_V4_OVERHEAD;
2407 paddrp->spp_hbinterval = net->heart_beat_delay;
2408 paddrp->spp_pathmaxrxt = net->failure_threshold;
2409 paddrp->spp_pathmtu = net->mtu - ovh;
2410 /* get flags for HB */
2411 if (net->dest_state & SCTP_ADDR_NOHB) {
2412 paddrp->spp_flags |= SPP_HB_DISABLE;
2414 paddrp->spp_flags |= SPP_HB_ENABLE;
2416 /* get flags for PMTU */
2417 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2418 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2420 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2422 if (net->dscp & 0x01) {
2423 paddrp->spp_dscp = net->dscp & 0xfc;
2424 paddrp->spp_flags |= SPP_DSCP;
2427 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2428 (net->flowlabel & 0x80000000)) {
2429 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2430 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2435 * No destination so return default
2438 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2439 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2440 if (stcb->asoc.default_dscp & 0x01) {
2441 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2442 paddrp->spp_flags |= SPP_DSCP;
2445 if (stcb->asoc.default_flowlabel & 0x80000000) {
2446 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2447 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2450 /* default settings should be these */
2451 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2452 paddrp->spp_flags |= SPP_HB_DISABLE;
2454 paddrp->spp_flags |= SPP_HB_ENABLE;
2456 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2457 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2459 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2461 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2463 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2464 SCTP_TCB_UNLOCK(stcb);
2466 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2467 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2468 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2469 /* Use endpoint defaults */
2470 SCTP_INP_RLOCK(inp);
2471 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2472 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2473 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2474 /* get inp's default */
2475 if (inp->sctp_ep.default_dscp & 0x01) {
2476 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2477 paddrp->spp_flags |= SPP_DSCP;
2480 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2481 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2482 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2483 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2486 /* can't return this */
2487 paddrp->spp_pathmtu = 0;
2489 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2490 paddrp->spp_flags |= SPP_HB_ENABLE;
2492 paddrp->spp_flags |= SPP_HB_DISABLE;
2494 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2495 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2497 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2499 SCTP_INP_RUNLOCK(inp);
2501 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2506 *optsize = sizeof(struct sctp_paddrparams);
2510 case SCTP_GET_PEER_ADDR_INFO:
2512 struct sctp_paddrinfo *paddri;
2513 struct sctp_nets *net;
2515 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2516 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2520 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
2523 * We increment here since
2524 * sctp_findassociation_ep_addr() wil do a
2525 * decrement if it finds the stcb as long as
2526 * the locked tcb (last argument) is NOT a
2529 SCTP_INP_INCR_REF(inp);
2530 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
2532 SCTP_INP_DECR_REF(inp);
2536 if ((stcb) && (net)) {
2537 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2538 /* It's unconfirmed */
2539 paddri->spinfo_state = SCTP_UNCONFIRMED;
2540 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2542 paddri->spinfo_state = SCTP_ACTIVE;
2545 paddri->spinfo_state = SCTP_INACTIVE;
2547 paddri->spinfo_cwnd = net->cwnd;
2548 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2549 paddri->spinfo_rto = net->RTO;
2550 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2551 paddri->spinfo_mtu = net->mtu;
2552 SCTP_TCB_UNLOCK(stcb);
2553 *optsize = sizeof(struct sctp_paddrinfo);
2556 SCTP_TCB_UNLOCK(stcb);
2558 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2563 case SCTP_PCB_STATUS:
2565 struct sctp_pcbinfo *spcb;
2567 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2568 sctp_fill_pcbinfo(spcb);
2569 *optsize = sizeof(struct sctp_pcbinfo);
2574 struct sctp_nets *net;
2575 struct sctp_status *sstat;
2577 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2578 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2581 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2586 * I think passing the state is fine since
2587 * sctp_constants.h will be available to the user
2590 sstat->sstat_state = stcb->asoc.state;
2591 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2592 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2593 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2595 * We can't include chunks that have been passed to
2596 * the socket layer. Only things in queue.
2598 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2599 stcb->asoc.cnt_on_all_streams);
2602 sstat->sstat_instrms = stcb->asoc.streamincnt;
2603 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2604 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2605 memcpy(&sstat->sstat_primary.spinfo_address,
2606 &stcb->asoc.primary_destination->ro._l_addr,
2607 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2608 net = stcb->asoc.primary_destination;
2609 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2611 * Again the user can get info from sctp_constants.h
2612 * for what the state of the network is.
2614 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2615 /* It's unconfirmed */
2616 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2617 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2619 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2622 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2624 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2625 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2626 sstat->sstat_primary.spinfo_rto = net->RTO;
2627 sstat->sstat_primary.spinfo_mtu = net->mtu;
2628 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2629 SCTP_TCB_UNLOCK(stcb);
2630 *optsize = sizeof(struct sctp_status);
2635 struct sctp_rtoinfo *srto;
2637 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2638 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2641 srto->srto_initial = stcb->asoc.initial_rto;
2642 srto->srto_max = stcb->asoc.maxrto;
2643 srto->srto_min = stcb->asoc.minrto;
2644 SCTP_TCB_UNLOCK(stcb);
2646 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2647 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2648 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2649 SCTP_INP_RLOCK(inp);
2650 srto->srto_initial = inp->sctp_ep.initial_rto;
2651 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2652 srto->srto_min = inp->sctp_ep.sctp_minrto;
2653 SCTP_INP_RUNLOCK(inp);
2655 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2660 *optsize = sizeof(struct sctp_rtoinfo);
2666 struct sctp_timeouts *stimo;
2668 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2669 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2672 stimo->stimo_init = stcb->asoc.timoinit;
2673 stimo->stimo_data = stcb->asoc.timodata;
2674 stimo->stimo_sack = stcb->asoc.timosack;
2675 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2676 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2677 stimo->stimo_cookie = stcb->asoc.timocookie;
2678 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2679 SCTP_TCB_UNLOCK(stcb);
2680 *optsize = sizeof(struct sctp_timeouts);
2682 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2687 case SCTP_ASSOCINFO:
2689 struct sctp_assocparams *sasoc;
2691 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2692 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2695 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2696 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2697 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2698 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2699 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2700 SCTP_TCB_UNLOCK(stcb);
2702 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2703 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2704 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2705 SCTP_INP_RLOCK(inp);
2706 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2707 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2708 sasoc->sasoc_number_peer_destinations = 0;
2709 sasoc->sasoc_peer_rwnd = 0;
2710 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2711 SCTP_INP_RUNLOCK(inp);
2713 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2718 *optsize = sizeof(struct sctp_assocparams);
2722 case SCTP_DEFAULT_SEND_PARAM:
2724 struct sctp_sndrcvinfo *s_info;
2726 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2727 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2730 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2731 SCTP_TCB_UNLOCK(stcb);
2733 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2734 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2735 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2736 SCTP_INP_RLOCK(inp);
2737 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2738 SCTP_INP_RUNLOCK(inp);
2740 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2745 *optsize = sizeof(struct sctp_sndrcvinfo);
2751 struct sctp_initmsg *sinit;
2753 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2754 SCTP_INP_RLOCK(inp);
2755 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2756 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2757 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2758 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2759 SCTP_INP_RUNLOCK(inp);
2760 *optsize = sizeof(struct sctp_initmsg);
2763 case SCTP_PRIMARY_ADDR:
2764 /* we allow a "get" operation on this */
2766 struct sctp_setprim *ssp;
2768 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2769 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2772 /* simply copy out the sockaddr_storage... */
2776 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
2777 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
2779 memcpy(&ssp->ssp_addr,
2780 &stcb->asoc.primary_destination->ro._l_addr,
2782 SCTP_TCB_UNLOCK(stcb);
2783 *optsize = sizeof(struct sctp_setprim);
2785 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2790 case SCTP_HMAC_IDENT:
2792 struct sctp_hmacalgo *shmac;
2793 sctp_hmaclist_t *hmaclist;
2797 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2799 SCTP_INP_RLOCK(inp);
2800 hmaclist = inp->sctp_ep.local_hmacs;
2801 if (hmaclist == NULL) {
2802 /* no HMACs to return */
2803 *optsize = sizeof(*shmac);
2804 SCTP_INP_RUNLOCK(inp);
2807 /* is there room for all of the hmac ids? */
2808 size = sizeof(*shmac) + (hmaclist->num_algo *
2809 sizeof(shmac->shmac_idents[0]));
2810 if ((size_t)(*optsize) < size) {
2811 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2813 SCTP_INP_RUNLOCK(inp);
2816 /* copy in the list */
2817 shmac->shmac_number_of_idents = hmaclist->num_algo;
2818 for (i = 0; i < hmaclist->num_algo; i++) {
2819 shmac->shmac_idents[i] = hmaclist->hmac[i];
2821 SCTP_INP_RUNLOCK(inp);
2825 case SCTP_AUTH_ACTIVE_KEY:
2827 struct sctp_authkeyid *scact;
2829 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2830 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2833 /* get the active key on the assoc */
2834 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2835 SCTP_TCB_UNLOCK(stcb);
2837 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2838 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2839 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2840 /* get the endpoint active key */
2841 SCTP_INP_RLOCK(inp);
2842 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2843 SCTP_INP_RUNLOCK(inp);
2845 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2850 *optsize = sizeof(struct sctp_authkeyid);
2854 case SCTP_LOCAL_AUTH_CHUNKS:
2856 struct sctp_authchunks *sac;
2857 sctp_auth_chklist_t *chklist = NULL;
2860 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2861 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2864 /* get off the assoc */
2865 chklist = stcb->asoc.local_auth_chunks;
2866 /* is there enough space? */
2867 size = sctp_auth_get_chklist_size(chklist);
2868 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2870 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2872 /* copy in the chunks */
2873 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2874 *optsize = sizeof(struct sctp_authchunks) + size;
2876 SCTP_TCB_UNLOCK(stcb);
2878 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2879 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2880 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2881 /* get off the endpoint */
2882 SCTP_INP_RLOCK(inp);
2883 chklist = inp->sctp_ep.local_auth_chunks;
2884 /* is there enough space? */
2885 size = sctp_auth_get_chklist_size(chklist);
2886 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2888 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2890 /* copy in the chunks */
2891 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2892 *optsize = sizeof(struct sctp_authchunks) + size;
2894 SCTP_INP_RUNLOCK(inp);
2896 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2902 case SCTP_PEER_AUTH_CHUNKS:
2904 struct sctp_authchunks *sac;
2905 sctp_auth_chklist_t *chklist = NULL;
2908 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2909 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2912 /* get off the assoc */
2913 chklist = stcb->asoc.peer_auth_chunks;
2914 /* is there enough space? */
2915 size = sctp_auth_get_chklist_size(chklist);
2916 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2918 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2920 /* copy in the chunks */
2921 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2922 *optsize = sizeof(struct sctp_authchunks) + size;
2924 SCTP_TCB_UNLOCK(stcb);
2926 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2933 struct sctp_event *event;
2934 uint32_t event_type;
2936 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2937 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2939 switch (event->se_type) {
2940 case SCTP_ASSOC_CHANGE:
2941 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2943 case SCTP_PEER_ADDR_CHANGE:
2944 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
2946 case SCTP_REMOTE_ERROR:
2947 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
2949 case SCTP_SEND_FAILED:
2950 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
2952 case SCTP_SHUTDOWN_EVENT:
2953 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
2955 case SCTP_ADAPTATION_INDICATION:
2956 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
2958 case SCTP_PARTIAL_DELIVERY_EVENT:
2959 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
2961 case SCTP_AUTHENTICATION_EVENT:
2962 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
2964 case SCTP_STREAM_RESET_EVENT:
2965 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
2967 case SCTP_SENDER_DRY_EVENT:
2968 event_type = SCTP_PCB_FLAGS_DRYEVNT;
2970 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
2972 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
2977 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2981 if (event_type > 0) {
2983 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
2984 SCTP_TCB_UNLOCK(stcb);
2986 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2987 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2988 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
2989 SCTP_INP_RLOCK(inp);
2990 event->se_on = sctp_is_feature_on(inp, event_type);
2991 SCTP_INP_RUNLOCK(inp);
2993 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2999 *optsize = sizeof(struct sctp_event);
3003 case SCTP_RECVRCVINFO:
3007 if (*optsize < sizeof(int)) {
3008 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3011 SCTP_INP_RLOCK(inp);
3012 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3013 SCTP_INP_RUNLOCK(inp);
3016 /* return the option value */
3017 *(int *)optval = onoff;
3018 *optsize = sizeof(int);
3022 case SCTP_RECVNXTINFO:
3026 if (*optsize < sizeof(int)) {
3027 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3030 SCTP_INP_RLOCK(inp);
3031 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3032 SCTP_INP_RUNLOCK(inp);
3035 /* return the option value */
3036 *(int *)optval = onoff;
3037 *optsize = sizeof(int);
3041 case SCTP_DEFAULT_SNDINFO:
3043 struct sctp_sndinfo *info;
3045 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3046 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3049 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3050 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3051 info->snd_flags &= 0xfff0;
3052 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3053 info->snd_context = stcb->asoc.def_send.sinfo_context;
3054 SCTP_TCB_UNLOCK(stcb);
3056 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3057 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3058 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3059 SCTP_INP_RLOCK(inp);
3060 info->snd_sid = inp->def_send.sinfo_stream;
3061 info->snd_flags = inp->def_send.sinfo_flags;
3062 info->snd_flags &= 0xfff0;
3063 info->snd_ppid = inp->def_send.sinfo_ppid;
3064 info->snd_context = inp->def_send.sinfo_context;
3065 SCTP_INP_RUNLOCK(inp);
3067 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3072 *optsize = sizeof(struct sctp_sndinfo);
3076 case SCTP_DEFAULT_PRINFO:
3078 struct sctp_default_prinfo *info;
3080 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3081 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3084 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3085 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3086 SCTP_TCB_UNLOCK(stcb);
3088 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3089 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3090 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3091 SCTP_INP_RLOCK(inp);
3092 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3093 info->pr_value = inp->def_send.sinfo_timetolive;
3094 SCTP_INP_RUNLOCK(inp);
3096 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3101 *optsize = sizeof(struct sctp_default_prinfo);
3105 case SCTP_PEER_ADDR_THLDS:
3107 struct sctp_paddrthlds *thlds;
3108 struct sctp_nets *net;
3110 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3111 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3115 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
3118 * We increment here since
3119 * sctp_findassociation_ep_addr() wil do a
3120 * decrement if it finds the stcb as long as
3121 * the locked tcb (last argument) is NOT a
3124 SCTP_INP_INCR_REF(inp);
3125 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL);
3127 SCTP_INP_DECR_REF(inp);
3130 if (stcb && (net == NULL)) {
3131 struct sockaddr *sa;
3133 sa = (struct sockaddr *)&thlds->spt_address;
3135 if (sa->sa_family == AF_INET) {
3136 struct sockaddr_in *sin;
3138 sin = (struct sockaddr_in *)sa;
3139 if (sin->sin_addr.s_addr) {
3141 SCTP_TCB_UNLOCK(stcb);
3142 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3148 if (sa->sa_family == AF_INET6) {
3149 struct sockaddr_in6 *sin6;
3151 sin6 = (struct sockaddr_in6 *)sa;
3152 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3154 SCTP_TCB_UNLOCK(stcb);
3155 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3161 error = EAFNOSUPPORT;
3162 SCTP_TCB_UNLOCK(stcb);
3163 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3169 thlds->spt_pathmaxrxt = net->failure_threshold;
3170 thlds->spt_pathpfthld = net->pf_threshold;
3172 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3173 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3175 thlds->spt_assoc_id = sctp_get_associd(stcb);
3176 SCTP_TCB_UNLOCK(stcb);
3178 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3179 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3180 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3181 /* Use endpoint defaults */
3182 SCTP_INP_RLOCK(inp);
3183 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3184 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3185 SCTP_INP_RUNLOCK(inp);
3187 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3192 *optsize = sizeof(struct sctp_paddrthlds);
3196 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3198 struct sctp_udpencaps *encaps;
3199 struct sctp_nets *net;
3201 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3202 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3205 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
3208 * We increment here since
3209 * sctp_findassociation_ep_addr() wil do a
3210 * decrement if it finds the stcb as long as
3211 * the locked tcb (last argument) is NOT a
3215 SCTP_INP_INCR_REF(inp);
3216 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
3218 SCTP_INP_DECR_REF(inp);
3221 if (stcb && (net == NULL)) {
3222 struct sockaddr *sa;
3224 sa = (struct sockaddr *)&encaps->sue_address;
3226 if (sa->sa_family == AF_INET) {
3227 struct sockaddr_in *sin;
3229 sin = (struct sockaddr_in *)sa;
3230 if (sin->sin_addr.s_addr) {
3232 SCTP_TCB_UNLOCK(stcb);
3233 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3239 if (sa->sa_family == AF_INET6) {
3240 struct sockaddr_in6 *sin6;
3242 sin6 = (struct sockaddr_in6 *)sa;
3243 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3245 SCTP_TCB_UNLOCK(stcb);
3246 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3252 error = EAFNOSUPPORT;
3253 SCTP_TCB_UNLOCK(stcb);
3254 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3260 encaps->sue_port = net->port;
3262 encaps->sue_port = stcb->asoc.port;
3264 SCTP_TCB_UNLOCK(stcb);
3266 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3267 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3268 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3269 SCTP_INP_RLOCK(inp);
3270 encaps->sue_port = inp->sctp_ep.port;
3271 SCTP_INP_RUNLOCK(inp);
3273 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3278 *optsize = sizeof(struct sctp_paddrparams);
3283 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3284 error = ENOPROTOOPT;
3286 } /* end switch (sopt->sopt_name) */
3294 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3299 struct sctp_tcb *stcb = NULL;
3300 struct sctp_inpcb *inp = NULL;
3303 if (optval == NULL) {
3304 SCTP_PRINTF("optval is NULL\n");
3305 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3308 inp = (struct sctp_inpcb *)so->so_pcb;
3310 SCTP_PRINTF("inp is NULL?\n");
3311 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3314 vrf_id = inp->def_vrf_id;
3319 case SCTP_AUTOCLOSE:
3320 case SCTP_AUTO_ASCONF:
3321 case SCTP_EXPLICIT_EOR:
3322 case SCTP_DISABLE_FRAGMENTS:
3323 case SCTP_USE_EXT_RCVINFO:
3324 case SCTP_I_WANT_MAPPED_V4_ADDR:
3325 /* copy in the option value */
3326 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3331 case SCTP_DISABLE_FRAGMENTS:
3332 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3334 case SCTP_AUTO_ASCONF:
3336 * NOTE: we don't really support this flag
3338 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3339 /* only valid for bound all sockets */
3340 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3342 /* forbidden by admin */
3343 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3346 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3348 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3352 case SCTP_EXPLICIT_EOR:
3353 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3355 case SCTP_USE_EXT_RCVINFO:
3356 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3358 case SCTP_I_WANT_MAPPED_V4_ADDR:
3359 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3360 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3362 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3367 set_opt = SCTP_PCB_FLAGS_NODELAY;
3369 case SCTP_AUTOCLOSE:
3370 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3371 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3372 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3375 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3377 * The value is in ticks. Note this does not effect
3378 * old associations, only new ones.
3380 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3383 SCTP_INP_WLOCK(inp);
3385 sctp_feature_on(inp, set_opt);
3387 sctp_feature_off(inp, set_opt);
3389 SCTP_INP_WUNLOCK(inp);
3391 case SCTP_REUSE_PORT:
3393 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3394 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3395 /* Can't set it after we are bound */
3399 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3400 /* Can't do this for a 1-m socket */
3405 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3407 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3410 case SCTP_PARTIAL_DELIVERY_POINT:
3414 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3415 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3416 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3420 inp->partial_delivery_point = *value;
3423 case SCTP_FRAGMENT_INTERLEAVE:
3424 /* not yet until we re-write sctp_recvmsg() */
3428 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3429 if (*level == SCTP_FRAG_LEVEL_2) {
3430 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3431 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3432 } else if (*level == SCTP_FRAG_LEVEL_1) {
3433 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3434 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3435 } else if (*level == SCTP_FRAG_LEVEL_0) {
3436 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3437 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3440 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3445 case SCTP_CMT_ON_OFF:
3446 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3447 struct sctp_assoc_value *av;
3449 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3450 if (av->assoc_value > SCTP_CMT_MAX) {
3451 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3455 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3457 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3458 SCTP_TCB_UNLOCK(stcb);
3460 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3461 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3462 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3463 (av->assoc_id == SCTP_ALL_ASSOC)) {
3464 SCTP_INP_WLOCK(inp);
3465 inp->sctp_cmt_on_off = av->assoc_value;
3466 SCTP_INP_WUNLOCK(inp);
3468 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3469 (av->assoc_id == SCTP_ALL_ASSOC)) {
3470 SCTP_INP_RLOCK(inp);
3471 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3472 SCTP_TCB_LOCK(stcb);
3473 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3474 SCTP_TCB_UNLOCK(stcb);
3476 SCTP_INP_RUNLOCK(inp);
3480 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3481 error = ENOPROTOOPT;
3484 case SCTP_PLUGGABLE_CC:
3486 struct sctp_assoc_value *av;
3487 struct sctp_nets *net;
3489 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3490 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3491 (av->assoc_value != SCTP_CC_HSTCP) &&
3492 (av->assoc_value != SCTP_CC_HTCP) &&
3493 (av->assoc_value != SCTP_CC_RTCC)) {
3494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3498 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3500 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3501 stcb->asoc.congestion_control_module = av->assoc_value;
3502 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3503 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3504 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3507 SCTP_TCB_UNLOCK(stcb);
3509 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3510 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3511 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3512 (av->assoc_id == SCTP_ALL_ASSOC)) {
3513 SCTP_INP_WLOCK(inp);
3514 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3515 SCTP_INP_WUNLOCK(inp);
3517 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3518 (av->assoc_id == SCTP_ALL_ASSOC)) {
3519 SCTP_INP_RLOCK(inp);
3520 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3521 SCTP_TCB_LOCK(stcb);
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 SCTP_INP_RUNLOCK(inp);
3536 case SCTP_CC_OPTION:
3538 struct sctp_cc_option *cc_opt;
3540 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3541 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3543 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3544 SCTP_INP_RLOCK(inp);
3545 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3546 SCTP_TCB_LOCK(stcb);
3547 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3548 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3550 SCTP_TCB_UNLOCK(stcb);
3552 SCTP_INP_RUNLOCK(inp);
3557 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3560 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3563 SCTP_TCB_UNLOCK(stcb);
3567 case SCTP_PLUGGABLE_SS:
3569 struct sctp_assoc_value *av;
3571 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3572 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3573 (av->assoc_value != SCTP_SS_DEFAULT) &&
3574 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3575 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3576 (av->assoc_value != SCTP_SS_PRIORITY) &&
3577 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3578 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3579 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3583 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3585 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3586 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3587 stcb->asoc.stream_scheduling_module = av->assoc_value;
3588 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3589 SCTP_TCB_UNLOCK(stcb);
3591 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3592 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3593 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3594 (av->assoc_id == SCTP_ALL_ASSOC)) {
3595 SCTP_INP_WLOCK(inp);
3596 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
3597 SCTP_INP_WUNLOCK(inp);
3599 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3600 (av->assoc_id == SCTP_ALL_ASSOC)) {
3601 SCTP_INP_RLOCK(inp);
3602 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3603 SCTP_TCB_LOCK(stcb);
3604 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3605 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3606 stcb->asoc.stream_scheduling_module = av->assoc_value;
3607 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3608 SCTP_TCB_UNLOCK(stcb);
3610 SCTP_INP_RUNLOCK(inp);
3617 struct sctp_stream_value *av;
3619 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
3620 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3622 if (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
3623 av->stream_value) < 0) {
3624 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3627 SCTP_TCB_UNLOCK(stcb);
3629 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
3630 SCTP_INP_RLOCK(inp);
3631 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3632 SCTP_TCB_LOCK(stcb);
3633 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
3635 &stcb->asoc.strmout[av->stream_id],
3637 SCTP_TCB_UNLOCK(stcb);
3639 SCTP_INP_RUNLOCK(inp);
3643 * Can't set stream value without
3646 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3652 case SCTP_CLR_STAT_LOG:
3653 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3658 struct sctp_assoc_value *av;
3660 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3661 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3664 stcb->asoc.context = av->assoc_value;
3665 SCTP_TCB_UNLOCK(stcb);
3667 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3668 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3669 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3670 (av->assoc_id == SCTP_ALL_ASSOC)) {
3671 SCTP_INP_WLOCK(inp);
3672 inp->sctp_context = av->assoc_value;
3673 SCTP_INP_WUNLOCK(inp);
3675 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3676 (av->assoc_id == SCTP_ALL_ASSOC)) {
3677 SCTP_INP_RLOCK(inp);
3678 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3679 SCTP_TCB_LOCK(stcb);
3680 stcb->asoc.context = av->assoc_value;
3681 SCTP_TCB_UNLOCK(stcb);
3683 SCTP_INP_RUNLOCK(inp);
3690 uint32_t *default_vrfid;
3692 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
3693 if (*default_vrfid > SCTP_MAX_VRF_ID) {
3694 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3698 inp->def_vrf_id = *default_vrfid;
3701 case SCTP_DEL_VRF_ID:
3703 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3707 case SCTP_ADD_VRF_ID:
3709 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3713 case SCTP_DELAYED_SACK:
3715 struct sctp_sack_info *sack;
3717 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
3718 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
3719 if (sack->sack_delay) {
3720 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
3721 sack->sack_delay = SCTP_MAX_SACK_DELAY;
3722 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3723 sack->sack_delay = TICKS_TO_MSEC(1);
3727 if (sack->sack_delay) {
3728 stcb->asoc.delayed_ack = sack->sack_delay;
3730 if (sack->sack_freq) {
3731 stcb->asoc.sack_freq = sack->sack_freq;
3733 SCTP_TCB_UNLOCK(stcb);
3735 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3736 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3737 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
3738 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3739 SCTP_INP_WLOCK(inp);
3740 if (sack->sack_delay) {
3741 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
3743 if (sack->sack_freq) {
3744 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
3746 SCTP_INP_WUNLOCK(inp);
3748 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
3749 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3750 SCTP_INP_RLOCK(inp);
3751 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3752 SCTP_TCB_LOCK(stcb);
3753 if (sack->sack_delay) {
3754 stcb->asoc.delayed_ack = sack->sack_delay;
3756 if (sack->sack_freq) {
3757 stcb->asoc.sack_freq = sack->sack_freq;
3759 SCTP_TCB_UNLOCK(stcb);
3761 SCTP_INP_RUNLOCK(inp);
3766 case SCTP_AUTH_CHUNK:
3768 struct sctp_authchunk *sauth;
3770 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
3772 SCTP_INP_WLOCK(inp);
3773 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
3774 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3777 SCTP_INP_WUNLOCK(inp);
3782 struct sctp_authkey *sca;
3783 struct sctp_keyhead *shared_keys;
3784 sctp_sharedkey_t *shared_key;
3785 sctp_key_t *key = NULL;
3788 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
3789 if (sca->sca_keylength == 0) {
3790 size = optsize - sizeof(struct sctp_authkey);
3792 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
3793 size = sca->sca_keylength;
3795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3800 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
3803 shared_keys = &stcb->asoc.shared_keys;
3804 /* clear the cached keys for this key id */
3805 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3807 * create the new shared key and
3811 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3813 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3815 SCTP_TCB_UNLOCK(stcb);
3819 shared_key = sctp_alloc_sharedkey();
3820 if (shared_key == NULL) {
3822 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3824 SCTP_TCB_UNLOCK(stcb);
3827 shared_key->key = key;
3828 shared_key->keyid = sca->sca_keynumber;
3829 error = sctp_insert_sharedkey(shared_keys, shared_key);
3830 SCTP_TCB_UNLOCK(stcb);
3832 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3833 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3834 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
3835 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3836 SCTP_INP_WLOCK(inp);
3837 shared_keys = &inp->sctp_ep.shared_keys;
3839 * clear the cached keys on all
3840 * assocs for this key id
3842 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3844 * create the new shared key and
3848 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3850 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3852 SCTP_INP_WUNLOCK(inp);
3856 shared_key = sctp_alloc_sharedkey();
3857 if (shared_key == NULL) {
3859 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3861 SCTP_INP_WUNLOCK(inp);
3864 shared_key->key = key;
3865 shared_key->keyid = sca->sca_keynumber;
3866 error = sctp_insert_sharedkey(shared_keys, shared_key);
3867 SCTP_INP_WUNLOCK(inp);
3869 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
3870 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3871 SCTP_INP_RLOCK(inp);
3872 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3873 SCTP_TCB_LOCK(stcb);
3874 shared_keys = &stcb->asoc.shared_keys;
3876 * clear the cached keys for
3879 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3881 * create the new shared key
3882 * and insert/replace it
3885 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3887 SCTP_TCB_UNLOCK(stcb);
3891 shared_key = sctp_alloc_sharedkey();
3892 if (shared_key == NULL) {
3894 SCTP_TCB_UNLOCK(stcb);
3897 shared_key->key = key;
3898 shared_key->keyid = sca->sca_keynumber;
3899 error = sctp_insert_sharedkey(shared_keys, shared_key);
3900 SCTP_TCB_UNLOCK(stcb);
3902 SCTP_INP_RUNLOCK(inp);
3907 case SCTP_HMAC_IDENT:
3909 struct sctp_hmacalgo *shmac;
3910 sctp_hmaclist_t *hmaclist;
3915 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
3916 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
3917 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3921 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
3922 if (hmaclist == NULL) {
3923 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3927 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
3928 hmacid = shmac->shmac_idents[i];
3929 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
3930 /* invalid HMACs were found */ ;
3931 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3933 sctp_free_hmaclist(hmaclist);
3934 goto sctp_set_hmac_done;
3938 for (i = 0; i < hmaclist->num_algo; i++) {
3939 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
3940 /* already in list */
3945 sctp_free_hmaclist(hmaclist);
3946 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3950 /* set it on the endpoint */
3951 SCTP_INP_WLOCK(inp);
3952 if (inp->sctp_ep.local_hmacs)
3953 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
3954 inp->sctp_ep.local_hmacs = hmaclist;
3955 SCTP_INP_WUNLOCK(inp);
3959 case SCTP_AUTH_ACTIVE_KEY:
3961 struct sctp_authkeyid *scact;
3963 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
3964 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
3966 /* set the active key on the right place */
3968 /* set the active key on the assoc */
3969 if (sctp_auth_setactivekey(stcb,
3970 scact->scact_keynumber)) {
3971 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
3972 SCTP_FROM_SCTP_USRREQ,
3976 SCTP_TCB_UNLOCK(stcb);
3978 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3979 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3980 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
3981 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
3982 SCTP_INP_WLOCK(inp);
3983 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
3984 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3987 SCTP_INP_WUNLOCK(inp);
3989 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
3990 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
3991 SCTP_INP_RLOCK(inp);
3992 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3993 SCTP_TCB_LOCK(stcb);
3994 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
3995 SCTP_TCB_UNLOCK(stcb);
3997 SCTP_INP_RUNLOCK(inp);
4002 case SCTP_AUTH_DELETE_KEY:
4004 struct sctp_authkeyid *scdel;
4006 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4007 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4009 /* delete the key from the right place */
4011 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4012 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4015 SCTP_TCB_UNLOCK(stcb);
4017 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4018 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4019 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4020 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4021 SCTP_INP_WLOCK(inp);
4022 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4023 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4026 SCTP_INP_WUNLOCK(inp);
4028 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4029 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4030 SCTP_INP_RLOCK(inp);
4031 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4032 SCTP_TCB_LOCK(stcb);
4033 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4034 SCTP_TCB_UNLOCK(stcb);
4036 SCTP_INP_RUNLOCK(inp);
4041 case SCTP_AUTH_DEACTIVATE_KEY:
4043 struct sctp_authkeyid *keyid;
4045 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4046 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4048 /* deactivate the key from the right place */
4050 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4051 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4054 SCTP_TCB_UNLOCK(stcb);
4056 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4057 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4058 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4059 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4060 SCTP_INP_WLOCK(inp);
4061 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4062 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4065 SCTP_INP_WUNLOCK(inp);
4067 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4068 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4069 SCTP_INP_RLOCK(inp);
4070 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4071 SCTP_TCB_LOCK(stcb);
4072 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4073 SCTP_TCB_UNLOCK(stcb);
4075 SCTP_INP_RUNLOCK(inp);
4081 case SCTP_RESET_STREAMS:
4083 struct sctp_stream_reset *strrst;
4084 uint8_t send_in = 0, send_tsn = 0, send_out = 0,
4086 uint16_t addstrmcnt = 0;
4089 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_stream_reset, optsize);
4090 SCTP_FIND_STCB(inp, stcb, strrst->strrst_assoc_id);
4093 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4097 if (stcb->asoc.peer_supports_strreset == 0) {
4099 * Peer does not support it, we return
4100 * protocol not supported since this is true
4101 * for this feature and this peer, not the
4102 * socket request in general.
4104 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPROTONOSUPPORT);
4105 error = EPROTONOSUPPORT;
4106 SCTP_TCB_UNLOCK(stcb);
4109 if (stcb->asoc.stream_reset_outstanding) {
4110 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4112 SCTP_TCB_UNLOCK(stcb);
4115 if (strrst->strrst_flags == SCTP_RESET_LOCAL_RECV) {
4117 } else if (strrst->strrst_flags == SCTP_RESET_LOCAL_SEND) {
4119 } else if (strrst->strrst_flags == SCTP_RESET_BOTH) {
4122 } else if (strrst->strrst_flags == SCTP_RESET_TSN) {
4124 } else if (strrst->strrst_flags == SCTP_RESET_ADD_STREAMS) {
4128 /* We can't do that and add streams */
4132 if (stcb->asoc.stream_reset_outstanding) {
4137 /* We allocate here */
4138 addstrmcnt = strrst->strrst_num_streams;
4139 if ((int)(addstrmcnt + stcb->asoc.streamoutcnt) > 0xffff) {
4140 /* You can't have more than 64k */
4144 if ((stcb->asoc.strm_realoutsize - stcb->asoc.streamoutcnt) < addstrmcnt) {
4145 /* Need to allocate more */
4146 struct sctp_stream_out *oldstream;
4147 struct sctp_stream_queue_pending *sp,
4150 oldstream = stcb->asoc.strmout;
4152 SCTP_MALLOC(stcb->asoc.strmout, struct sctp_stream_out *,
4153 ((stcb->asoc.streamoutcnt + addstrmcnt) * sizeof(struct sctp_stream_out)),
4155 if (stcb->asoc.strmout == NULL) {
4156 stcb->asoc.strmout = oldstream;
4161 * Ok now we proceed with copying
4162 * the old out stuff and
4163 * initializing the new stuff.
4165 SCTP_TCB_SEND_LOCK(stcb);
4166 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 0, 1);
4167 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4168 TAILQ_INIT(&stcb->asoc.strmout[i].outqueue);
4169 stcb->asoc.strmout[i].next_sequence_sent = oldstream[i].next_sequence_sent;
4170 stcb->asoc.strmout[i].last_msg_incomplete = oldstream[i].last_msg_incomplete;
4171 stcb->asoc.strmout[i].stream_no = i;
4172 stcb->asoc.ss_functions.sctp_ss_init_stream(&stcb->asoc.strmout[i], &oldstream[i]);
4174 * now anything on those
4177 TAILQ_FOREACH_SAFE(sp, &oldstream[i].outqueue, next, nsp) {
4178 TAILQ_REMOVE(&oldstream[i].outqueue, sp, next);
4179 TAILQ_INSERT_TAIL(&stcb->asoc.strmout[i].outqueue, sp, next);
4182 * Now move assoc pointers
4185 if (stcb->asoc.last_out_stream == &oldstream[i]) {
4186 stcb->asoc.last_out_stream = &stcb->asoc.strmout[i];
4188 if (stcb->asoc.locked_on_sending == &oldstream[i]) {
4189 stcb->asoc.locked_on_sending = &stcb->asoc.strmout[i];
4192 /* now the new streams */
4193 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4194 for (i = stcb->asoc.streamoutcnt; i < (stcb->asoc.streamoutcnt + addstrmcnt); i++) {
4195 stcb->asoc.strmout[i].next_sequence_sent = 0x0;
4196 TAILQ_INIT(&stcb->asoc.strmout[i].outqueue);
4197 stcb->asoc.strmout[i].stream_no = i;
4198 stcb->asoc.strmout[i].last_msg_incomplete = 0;
4199 stcb->asoc.ss_functions.sctp_ss_init_stream(&stcb->asoc.strmout[i], NULL);
4201 stcb->asoc.strm_realoutsize = stcb->asoc.streamoutcnt + addstrmcnt;
4202 SCTP_FREE(oldstream, SCTP_M_STRMO);
4204 SCTP_TCB_SEND_UNLOCK(stcb);
4207 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4209 SCTP_TCB_UNLOCK(stcb);
4212 for (i = 0; i < strrst->strrst_num_streams; i++) {
4215 (strrst->strrst_list[i] > stcb->asoc.streamincnt)) {
4216 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4221 (strrst->strrst_list[i] > stcb->asoc.streamoutcnt)) {
4222 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4230 SCTP_TCB_UNLOCK(stcb);
4233 error = sctp_send_str_reset_req(stcb, strrst->strrst_num_streams,
4234 strrst->strrst_list,
4235 send_out, (stcb->asoc.str_reset_seq_in - 3),
4236 send_in, send_tsn, addstream, addstrmcnt);
4238 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4239 SCTP_TCB_UNLOCK(stcb);
4242 case SCTP_CONNECT_X:
4243 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4244 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4248 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4250 case SCTP_CONNECT_X_DELAYED:
4251 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4252 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4256 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4258 case SCTP_CONNECT_X_COMPLETE:
4260 struct sockaddr *sa;
4261 struct sctp_nets *net;
4263 /* FIXME MT: check correct? */
4264 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4267 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4268 SCTP_INP_RLOCK(inp);
4269 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4271 SCTP_TCB_LOCK(stcb);
4272 net = sctp_findnet(stcb, sa);
4274 SCTP_INP_RUNLOCK(inp);
4277 * We increment here since
4278 * sctp_findassociation_ep_addr() wil do a
4279 * decrement if it finds the stcb as long as
4280 * the locked tcb (last argument) is NOT a
4283 SCTP_INP_INCR_REF(inp);
4284 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4286 SCTP_INP_DECR_REF(inp);
4291 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4295 if (stcb->asoc.delayed_connection == 1) {
4296 stcb->asoc.delayed_connection = 0;
4297 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4298 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4299 stcb->asoc.primary_destination,
4300 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4301 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4304 * already expired or did not use delayed
4307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4310 SCTP_TCB_UNLOCK(stcb);
4313 case SCTP_MAX_BURST:
4317 SCTP_CHECK_AND_CAST(burst, optval, uint8_t, optsize);
4319 SCTP_INP_WLOCK(inp);
4320 inp->sctp_ep.max_burst = *burst;
4321 SCTP_INP_WUNLOCK(inp);
4326 struct sctp_assoc_value *av;
4329 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4330 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4332 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4333 ovh = SCTP_MED_OVERHEAD;
4335 ovh = SCTP_MED_V4_OVERHEAD;
4338 if (av->assoc_value) {
4339 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4341 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4343 SCTP_TCB_UNLOCK(stcb);
4345 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4346 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4347 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4348 SCTP_INP_WLOCK(inp);
4350 * FIXME MT: I think this is not in
4351 * tune with the API ID
4353 if (av->assoc_value) {
4354 inp->sctp_frag_point = (av->assoc_value + ovh);
4356 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4358 SCTP_INP_WUNLOCK(inp);
4360 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4368 struct sctp_event_subscribe *events;
4370 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4372 SCTP_INP_WLOCK(inp);
4373 if (events->sctp_data_io_event) {
4374 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4376 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4379 if (events->sctp_association_event) {
4380 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4382 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4385 if (events->sctp_address_event) {
4386 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4388 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4391 if (events->sctp_send_failure_event) {
4392 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4394 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4397 if (events->sctp_peer_error_event) {
4398 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4400 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4403 if (events->sctp_shutdown_event) {
4404 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4406 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4409 if (events->sctp_partial_delivery_event) {
4410 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4412 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4415 if (events->sctp_adaptation_layer_event) {
4416 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4418 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4421 if (events->sctp_authentication_event) {
4422 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4424 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4427 if (events->sctp_sender_dry_event) {
4428 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4430 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4433 if (events->sctp_stream_reset_event) {
4434 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4436 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4438 SCTP_INP_WUNLOCK(inp);
4440 SCTP_INP_RLOCK(inp);
4441 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4442 SCTP_TCB_LOCK(stcb);
4443 if (events->sctp_association_event) {
4444 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4446 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4448 if (events->sctp_address_event) {
4449 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4451 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4453 if (events->sctp_send_failure_event) {
4454 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4456 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4458 if (events->sctp_peer_error_event) {
4459 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4461 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4463 if (events->sctp_shutdown_event) {
4464 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4466 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4468 if (events->sctp_partial_delivery_event) {
4469 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4471 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4473 if (events->sctp_adaptation_layer_event) {
4474 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4476 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4478 if (events->sctp_authentication_event) {
4479 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4481 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4483 if (events->sctp_sender_dry_event) {
4484 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4486 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4488 if (events->sctp_stream_reset_event) {
4489 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4491 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4493 SCTP_TCB_UNLOCK(stcb);
4496 * Send up the sender dry event only for 1-to-1
4499 if (events->sctp_sender_dry_event) {
4500 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4501 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4502 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4504 SCTP_TCB_LOCK(stcb);
4505 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4506 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4507 (stcb->asoc.stream_queue_cnt == 0)) {
4508 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4510 SCTP_TCB_UNLOCK(stcb);
4514 SCTP_INP_RUNLOCK(inp);
4517 case SCTP_ADAPTATION_LAYER:
4519 struct sctp_setadaptation *adap_bits;
4521 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
4522 SCTP_INP_WLOCK(inp);
4523 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
4524 SCTP_INP_WUNLOCK(inp);
4528 case SCTP_SET_INITIAL_DBG_SEQ:
4532 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
4533 SCTP_INP_WLOCK(inp);
4534 inp->sctp_ep.initial_sequence_debug = *vvv;
4535 SCTP_INP_WUNLOCK(inp);
4539 case SCTP_DEFAULT_SEND_PARAM:
4541 struct sctp_sndrcvinfo *s_info;
4543 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
4544 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
4547 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4548 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4550 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4553 SCTP_TCB_UNLOCK(stcb);
4555 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4556 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4557 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
4558 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4559 SCTP_INP_WLOCK(inp);
4560 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
4561 SCTP_INP_WUNLOCK(inp);
4563 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
4564 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4565 SCTP_INP_RLOCK(inp);
4566 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4567 SCTP_TCB_LOCK(stcb);
4568 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4569 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4571 SCTP_TCB_UNLOCK(stcb);
4573 SCTP_INP_RUNLOCK(inp);
4578 case SCTP_PEER_ADDR_PARAMS:
4580 struct sctp_paddrparams *paddrp;
4581 struct sctp_nets *net;
4583 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
4584 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
4587 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
4590 * We increment here since
4591 * sctp_findassociation_ep_addr() wil do a
4592 * decrement if it finds the stcb as long as
4593 * the locked tcb (last argument) is NOT a
4596 SCTP_INP_INCR_REF(inp);
4597 stcb = sctp_findassociation_ep_addr(&inp,
4598 (struct sockaddr *)&paddrp->spp_address,
4601 SCTP_INP_DECR_REF(inp);
4604 if (stcb && (net == NULL)) {
4605 struct sockaddr *sa;
4607 sa = (struct sockaddr *)&paddrp->spp_address;
4609 if (sa->sa_family == AF_INET) {
4611 struct sockaddr_in *sin;
4613 sin = (struct sockaddr_in *)sa;
4614 if (sin->sin_addr.s_addr) {
4615 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4616 SCTP_TCB_UNLOCK(stcb);
4623 if (sa->sa_family == AF_INET6) {
4624 struct sockaddr_in6 *sin6;
4626 sin6 = (struct sockaddr_in6 *)sa;
4627 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
4628 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4629 SCTP_TCB_UNLOCK(stcb);
4636 error = EAFNOSUPPORT;
4637 SCTP_TCB_UNLOCK(stcb);
4638 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4643 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
4645 SCTP_TCB_UNLOCK(stcb);
4646 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4649 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
4651 SCTP_TCB_UNLOCK(stcb);
4652 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4656 /************************TCB SPECIFIC SET ******************/
4658 * do we change the timer for HB, we run
4663 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4664 ovh = SCTP_MED_OVERHEAD;
4666 ovh = SCTP_MED_V4_OVERHEAD;
4669 /* network sets ? */
4671 /************************NET SPECIFIC SET ******************/
4672 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4673 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
4674 !(net->dest_state & SCTP_ADDR_NOHB)) {
4675 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4676 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4678 net->dest_state |= SCTP_ADDR_NOHB;
4680 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4681 if (paddrp->spp_hbinterval) {
4682 net->heart_beat_delay = paddrp->spp_hbinterval;
4683 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4684 net->heart_beat_delay = 0;
4686 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4687 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4688 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4689 net->dest_state &= ~SCTP_ADDR_NOHB;
4691 if (paddrp->spp_flags & SPP_HB_DEMAND) {
4693 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4694 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
4695 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4697 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4698 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4699 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4700 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4702 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4703 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4704 net->mtu = paddrp->spp_pathmtu + ovh;
4705 if (net->mtu < stcb->asoc.smallest_mtu) {
4706 sctp_pathmtu_adjustment(stcb, net->mtu);
4710 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4711 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4712 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4714 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4716 if (paddrp->spp_pathmaxrxt) {
4717 if (net->dest_state & SCTP_ADDR_PF) {
4718 if (net->error_count > paddrp->spp_pathmaxrxt) {
4719 net->dest_state &= ~SCTP_ADDR_PF;
4722 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4723 (net->error_count > net->pf_threshold)) {
4724 net->dest_state |= SCTP_ADDR_PF;
4725 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4726 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4727 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4730 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4731 if (net->error_count > paddrp->spp_pathmaxrxt) {
4732 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4733 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4736 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4737 net->dest_state |= SCTP_ADDR_REACHABLE;
4738 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4741 net->failure_threshold = paddrp->spp_pathmaxrxt;
4743 if (paddrp->spp_flags & SPP_DSCP) {
4744 net->dscp = paddrp->spp_dscp & 0xfc;
4748 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4749 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4750 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4751 net->flowlabel |= 0x80000000;
4756 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
4757 if (paddrp->spp_pathmaxrxt) {
4758 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
4759 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4760 if (net->dest_state & SCTP_ADDR_PF) {
4761 if (net->error_count > paddrp->spp_pathmaxrxt) {
4762 net->dest_state &= ~SCTP_ADDR_PF;
4765 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4766 (net->error_count > net->pf_threshold)) {
4767 net->dest_state |= SCTP_ADDR_PF;
4768 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4769 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4770 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4773 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4774 if (net->error_count > paddrp->spp_pathmaxrxt) {
4775 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4776 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4779 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4780 net->dest_state |= SCTP_ADDR_REACHABLE;
4781 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4784 net->failure_threshold = paddrp->spp_pathmaxrxt;
4787 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4788 if (paddrp->spp_hbinterval) {
4789 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
4790 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4791 stcb->asoc.heart_beat_delay = 0;
4793 /* Turn back on the timer */
4794 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4795 if (paddrp->spp_hbinterval) {
4796 net->heart_beat_delay = paddrp->spp_hbinterval;
4797 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4798 net->heart_beat_delay = 0;
4800 if (net->dest_state & SCTP_ADDR_NOHB) {
4801 net->dest_state &= ~SCTP_ADDR_NOHB;
4803 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4804 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4805 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4807 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4809 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4810 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4811 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
4812 net->dest_state |= SCTP_ADDR_NOHB;
4813 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
4814 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4818 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4820 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4821 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4822 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4823 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4824 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4826 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4827 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4828 net->mtu = paddrp->spp_pathmtu + ovh;
4829 if (net->mtu < stcb->asoc.smallest_mtu) {
4830 sctp_pathmtu_adjustment(stcb, net->mtu);
4834 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4836 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4837 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4838 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4839 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4841 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4843 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4845 if (paddrp->spp_flags & SPP_DSCP) {
4846 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4847 net->dscp = paddrp->spp_dscp & 0xfc;
4850 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
4851 stcb->asoc.default_dscp |= 0x01;
4854 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4855 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4856 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4857 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4858 net->flowlabel |= 0x80000000;
4861 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4862 stcb->asoc.default_flowlabel |= 0x80000000;
4866 SCTP_TCB_UNLOCK(stcb);
4868 /************************NO TCB, SET TO default stuff ******************/
4869 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4870 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4871 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
4872 SCTP_INP_WLOCK(inp);
4874 * For the TOS/FLOWLABEL stuff you
4875 * set it with the options on the
4878 if (paddrp->spp_pathmaxrxt) {
4879 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
4881 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
4882 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4883 else if (paddrp->spp_hbinterval) {
4884 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
4885 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
4886 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4888 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4889 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4890 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4891 } else if (paddrp->spp_hbinterval) {
4892 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4894 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4895 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
4896 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4898 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4899 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4900 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
4901 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4903 if (paddrp->spp_flags & SPP_DSCP) {
4904 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
4905 inp->sctp_ep.default_dscp |= 0x01;
4908 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4909 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4910 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4911 inp->sctp_ep.default_flowlabel |= 0x80000000;
4915 SCTP_INP_WUNLOCK(inp);
4917 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4925 struct sctp_rtoinfo *srto;
4926 uint32_t new_init, new_min, new_max;
4928 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
4929 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
4932 if (srto->srto_initial)
4933 new_init = srto->srto_initial;
4935 new_init = stcb->asoc.initial_rto;
4937 new_max = srto->srto_max;
4939 new_max = stcb->asoc.maxrto;
4941 new_min = srto->srto_min;
4943 new_min = stcb->asoc.minrto;
4944 if ((new_min <= new_init) && (new_init <= new_max)) {
4945 stcb->asoc.initial_rto = new_init;
4946 stcb->asoc.maxrto = new_max;
4947 stcb->asoc.minrto = new_min;
4949 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4952 SCTP_TCB_UNLOCK(stcb);
4954 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4955 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4956 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
4957 SCTP_INP_WLOCK(inp);
4958 if (srto->srto_initial)
4959 new_init = srto->srto_initial;
4961 new_init = inp->sctp_ep.initial_rto;
4963 new_max = srto->srto_max;
4965 new_max = inp->sctp_ep.sctp_maxrto;
4967 new_min = srto->srto_min;
4969 new_min = inp->sctp_ep.sctp_minrto;
4970 if ((new_min <= new_init) && (new_init <= new_max)) {
4971 inp->sctp_ep.initial_rto = new_init;
4972 inp->sctp_ep.sctp_maxrto = new_max;
4973 inp->sctp_ep.sctp_minrto = new_min;
4975 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4978 SCTP_INP_WUNLOCK(inp);
4980 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4986 case SCTP_ASSOCINFO:
4988 struct sctp_assocparams *sasoc;
4990 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
4991 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
4992 if (sasoc->sasoc_cookie_life) {
4993 /* boundary check the cookie life */
4994 if (sasoc->sasoc_cookie_life < 1000)
4995 sasoc->sasoc_cookie_life = 1000;
4996 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
4997 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5001 if (sasoc->sasoc_asocmaxrxt)
5002 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5003 if (sasoc->sasoc_cookie_life) {
5004 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5006 SCTP_TCB_UNLOCK(stcb);
5008 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5009 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5010 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5011 SCTP_INP_WLOCK(inp);
5012 if (sasoc->sasoc_asocmaxrxt)
5013 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5014 if (sasoc->sasoc_cookie_life) {
5015 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5017 SCTP_INP_WUNLOCK(inp);
5019 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5027 struct sctp_initmsg *sinit;
5029 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5030 SCTP_INP_WLOCK(inp);
5031 if (sinit->sinit_num_ostreams)
5032 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5034 if (sinit->sinit_max_instreams)
5035 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5037 if (sinit->sinit_max_attempts)
5038 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5040 if (sinit->sinit_max_init_timeo)
5041 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5042 SCTP_INP_WUNLOCK(inp);
5045 case SCTP_PRIMARY_ADDR:
5047 struct sctp_setprim *spa;
5048 struct sctp_nets *net;
5050 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5051 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5055 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
5058 * We increment here since
5059 * sctp_findassociation_ep_addr() wil do a
5060 * decrement if it finds the stcb as long as
5061 * the locked tcb (last argument) is NOT a
5064 SCTP_INP_INCR_REF(inp);
5065 stcb = sctp_findassociation_ep_addr(&inp,
5066 (struct sockaddr *)&spa->ssp_addr,
5069 SCTP_INP_DECR_REF(inp);
5073 if ((stcb) && (net)) {
5074 if ((net != stcb->asoc.primary_destination) &&
5075 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
5076 /* Ok we need to set it */
5077 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5078 if ((stcb->asoc.alternate) &&
5079 (!(net->dest_state & SCTP_ADDR_PF)) &&
5080 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5081 sctp_free_remote_addr(stcb->asoc.alternate);
5082 stcb->asoc.alternate = NULL;
5087 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5091 SCTP_TCB_UNLOCK(stcb);
5095 case SCTP_SET_DYNAMIC_PRIMARY:
5097 union sctp_sockstore *ss;
5099 error = priv_check(curthread,
5100 PRIV_NETINET_RESERVEDPORT);
5104 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5105 /* SUPER USER CHECK? */
5106 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5109 case SCTP_SET_PEER_PRIMARY_ADDR:
5111 struct sctp_setpeerprim *sspp;
5113 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5114 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5116 struct sctp_ifa *ifa;
5118 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
5119 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5121 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5125 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5127 * Must validate the ifa found is in
5130 struct sctp_laddr *laddr;
5133 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5134 if (laddr->ifa == NULL) {
5135 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5139 if (laddr->ifa == ifa) {
5145 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5150 if (sctp_set_primary_ip_address_sa(stcb,
5151 (struct sockaddr *)&sspp->sspp_addr) != 0) {
5152 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5156 SCTP_TCB_UNLOCK(stcb);
5158 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5163 case SCTP_BINDX_ADD_ADDR:
5165 struct sctp_getaddresses *addrs;
5169 td = (struct thread *)p;
5170 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5173 if (addrs->addr->sa_family == AF_INET) {
5174 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
5176 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5180 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5181 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5187 if (addrs->addr->sa_family == AF_INET6) {
5188 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
5190 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5194 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5195 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5196 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5202 error = EAFNOSUPPORT;
5205 sctp_bindx_add_address(so, inp, addrs->addr,
5206 addrs->sget_assoc_id, vrf_id,
5210 case SCTP_BINDX_REM_ADDR:
5212 struct sctp_getaddresses *addrs;
5216 td = (struct thread *)p;
5218 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5220 if (addrs->addr->sa_family == AF_INET) {
5221 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
5223 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5227 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5228 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5234 if (addrs->addr->sa_family == AF_INET6) {
5235 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
5237 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5242 (error = prison_local_ip6(td->td_ucred,
5243 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5244 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5245 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5251 error = EAFNOSUPPORT;
5254 sctp_bindx_delete_address(inp, addrs->addr,
5255 addrs->sget_assoc_id, vrf_id,
5261 struct sctp_event *event;
5262 uint32_t event_type;
5264 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5265 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5266 switch (event->se_type) {
5267 case SCTP_ASSOC_CHANGE:
5268 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5270 case SCTP_PEER_ADDR_CHANGE:
5271 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5273 case SCTP_REMOTE_ERROR:
5274 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5276 case SCTP_SEND_FAILED:
5277 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5279 case SCTP_SHUTDOWN_EVENT:
5280 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5282 case SCTP_ADAPTATION_INDICATION:
5283 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5285 case SCTP_PARTIAL_DELIVERY_EVENT:
5286 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5288 case SCTP_AUTHENTICATION_EVENT:
5289 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5291 case SCTP_STREAM_RESET_EVENT:
5292 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5294 case SCTP_SENDER_DRY_EVENT:
5295 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5297 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5299 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5304 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5308 if (event_type > 0) {
5311 sctp_stcb_feature_on(inp, stcb, event_type);
5312 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5313 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5314 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5315 (stcb->asoc.stream_queue_cnt == 0)) {
5316 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5320 sctp_stcb_feature_off(inp, stcb, event_type);
5322 SCTP_TCB_UNLOCK(stcb);
5325 * We don't want to send up a storm
5326 * of events, so return an error for
5329 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5330 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5331 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5332 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5333 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5334 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5338 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5339 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5340 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5341 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5342 SCTP_INP_WLOCK(inp);
5344 sctp_feature_on(inp, event_type);
5346 sctp_feature_off(inp, event_type);
5348 SCTP_INP_WUNLOCK(inp);
5350 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5351 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5352 SCTP_INP_RLOCK(inp);
5353 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5354 SCTP_TCB_LOCK(stcb);
5356 sctp_stcb_feature_on(inp, stcb, event_type);
5358 sctp_stcb_feature_off(inp, stcb, event_type);
5360 SCTP_TCB_UNLOCK(stcb);
5362 SCTP_INP_RUNLOCK(inp);
5368 case SCTP_RECVRCVINFO:
5372 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5373 SCTP_INP_WLOCK(inp);
5375 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5377 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5379 SCTP_INP_WUNLOCK(inp);
5382 case SCTP_RECVNXTINFO:
5386 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5387 SCTP_INP_WLOCK(inp);
5389 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5391 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5393 SCTP_INP_WUNLOCK(inp);
5396 case SCTP_DEFAULT_SNDINFO:
5398 struct sctp_sndinfo *info;
5401 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5402 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5405 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5406 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5407 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5408 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5409 stcb->asoc.def_send.sinfo_flags |= policy;
5410 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5411 stcb->asoc.def_send.sinfo_context = info->snd_context;
5413 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5416 SCTP_TCB_UNLOCK(stcb);
5418 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5419 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5420 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
5421 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5422 SCTP_INP_WLOCK(inp);
5423 inp->def_send.sinfo_stream = info->snd_sid;
5424 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
5425 inp->def_send.sinfo_flags = info->snd_flags;
5426 inp->def_send.sinfo_flags |= policy;
5427 inp->def_send.sinfo_ppid = info->snd_ppid;
5428 inp->def_send.sinfo_context = info->snd_context;
5429 SCTP_INP_WUNLOCK(inp);
5431 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
5432 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5433 SCTP_INP_RLOCK(inp);
5434 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5435 SCTP_TCB_LOCK(stcb);
5436 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5437 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5438 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5439 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5440 stcb->asoc.def_send.sinfo_flags |= policy;
5441 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5442 stcb->asoc.def_send.sinfo_context = info->snd_context;
5444 SCTP_TCB_UNLOCK(stcb);
5446 SCTP_INP_RUNLOCK(inp);
5451 case SCTP_DEFAULT_PRINFO:
5453 struct sctp_default_prinfo *info;
5455 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
5456 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
5458 if (PR_SCTP_INVALID_POLICY(info->pr_policy)) {
5459 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5464 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5465 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5466 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5467 SCTP_TCB_UNLOCK(stcb);
5469 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5470 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5471 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
5472 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5473 SCTP_INP_WLOCK(inp);
5474 inp->def_send.sinfo_flags &= 0xfff0;
5475 inp->def_send.sinfo_flags |= info->pr_policy;
5476 inp->def_send.sinfo_timetolive = info->pr_value;
5477 SCTP_INP_WUNLOCK(inp);
5479 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
5480 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5481 SCTP_INP_RLOCK(inp);
5482 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5483 SCTP_TCB_LOCK(stcb);
5484 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5485 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5486 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5487 SCTP_TCB_UNLOCK(stcb);
5489 SCTP_INP_RUNLOCK(inp);
5494 case SCTP_PEER_ADDR_THLDS:
5495 /* Applies to the specific association */
5497 struct sctp_paddrthlds *thlds;
5498 struct sctp_nets *net;
5500 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
5501 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
5504 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_assoc_id);
5507 * We increment here since
5508 * sctp_findassociation_ep_addr() wil do a
5509 * decrement if it finds the stcb as long as
5510 * the locked tcb (last argument) is NOT a
5513 SCTP_INP_INCR_REF(inp);
5514 stcb = sctp_findassociation_ep_addr(&inp,
5515 (struct sockaddr *)&thlds->spt_assoc_id,
5518 SCTP_INP_DECR_REF(inp);
5521 if (stcb && (net == NULL)) {
5522 struct sockaddr *sa;
5524 sa = (struct sockaddr *)&thlds->spt_assoc_id;
5526 if (sa->sa_family == AF_INET) {
5528 struct sockaddr_in *sin;
5530 sin = (struct sockaddr_in *)sa;
5531 if (sin->sin_addr.s_addr) {
5532 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5533 SCTP_TCB_UNLOCK(stcb);
5540 if (sa->sa_family == AF_INET6) {
5541 struct sockaddr_in6 *sin6;
5543 sin6 = (struct sockaddr_in6 *)sa;
5544 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5545 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5546 SCTP_TCB_UNLOCK(stcb);
5553 error = EAFNOSUPPORT;
5554 SCTP_TCB_UNLOCK(stcb);
5555 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5561 if (net->dest_state & SCTP_ADDR_PF) {
5562 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5563 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5564 net->dest_state &= ~SCTP_ADDR_PF;
5567 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5568 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5569 net->dest_state |= SCTP_ADDR_PF;
5570 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5571 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5572 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5575 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5576 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5577 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5578 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5581 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5582 net->dest_state |= SCTP_ADDR_REACHABLE;
5583 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5586 net->failure_threshold = thlds->spt_pathmaxrxt;
5587 net->pf_threshold = thlds->spt_pathpfthld;
5589 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5590 if (net->dest_state & SCTP_ADDR_PF) {
5591 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5592 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5593 net->dest_state &= ~SCTP_ADDR_PF;
5596 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5597 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5598 net->dest_state |= SCTP_ADDR_PF;
5599 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5600 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5601 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5604 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5605 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5606 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5607 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5610 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5611 net->dest_state |= SCTP_ADDR_REACHABLE;
5612 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5615 net->failure_threshold = thlds->spt_pathmaxrxt;
5616 net->pf_threshold = thlds->spt_pathpfthld;
5618 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
5619 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
5622 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5623 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5624 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
5625 SCTP_INP_WLOCK(inp);
5626 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
5627 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
5628 SCTP_INP_WUNLOCK(inp);
5630 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5636 case SCTP_REMOTE_UDP_ENCAPS_PORT:
5638 struct sctp_udpencaps *encaps;
5639 struct sctp_nets *net;
5641 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
5642 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
5644 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
5647 * We increment here since
5648 * sctp_findassociation_ep_addr() wil do a
5649 * decrement if it finds the stcb as long as
5650 * the locked tcb (last argument) is NOT a
5654 SCTP_INP_INCR_REF(inp);
5655 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
5657 SCTP_INP_DECR_REF(inp);
5660 if (stcb && (net == NULL)) {
5661 struct sockaddr *sa;
5663 sa = (struct sockaddr *)&encaps->sue_address;
5665 if (sa->sa_family == AF_INET) {
5667 struct sockaddr_in *sin;
5669 sin = (struct sockaddr_in *)sa;
5670 if (sin->sin_addr.s_addr) {
5671 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5672 SCTP_TCB_UNLOCK(stcb);
5679 if (sa->sa_family == AF_INET6) {
5680 struct sockaddr_in6 *sin6;
5682 sin6 = (struct sockaddr_in6 *)sa;
5683 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5684 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5685 SCTP_TCB_UNLOCK(stcb);
5692 error = EAFNOSUPPORT;
5693 SCTP_TCB_UNLOCK(stcb);
5694 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5700 net->port = encaps->sue_port;
5702 stcb->asoc.port = encaps->sue_port;
5704 SCTP_TCB_UNLOCK(stcb);
5706 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5707 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5708 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
5709 SCTP_INP_WLOCK(inp);
5710 inp->sctp_ep.port = encaps->sue_port;
5711 SCTP_INP_WUNLOCK(inp);
5713 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5720 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
5721 error = ENOPROTOOPT;
5723 } /* end switch (opt) */
5728 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
5730 void *optval = NULL;
5732 struct sctp_inpcb *inp;
5736 if (sopt->sopt_level != IPPROTO_SCTP) {
5737 /* wrong proto level... send back up to IP */
5739 if (INP_CHECK_SOCKAF(so, AF_INET6))
5740 error = ip6_ctloutput(so, sopt);
5742 #if defined(INET) && defined (INET6)
5746 error = ip_ctloutput(so, sopt);
5750 inp = (struct sctp_inpcb *)so->so_pcb;
5751 optsize = sopt->sopt_valsize;
5753 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
5754 if (optval == NULL) {
5755 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
5758 error = sooptcopyin(sopt, optval, optsize, optsize);
5760 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5764 p = (void *)sopt->sopt_td;
5765 if (sopt->sopt_dir == SOPT_SET) {
5766 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
5767 } else if (sopt->sopt_dir == SOPT_GET) {
5768 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
5770 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5773 if ((error == 0) && (optval != NULL)) {
5774 error = sooptcopyout(sopt, optval, optsize);
5775 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5776 } else if (optval != NULL) {
5777 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5785 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
5788 int create_lock_on = 0;
5790 struct sctp_inpcb *inp;
5791 struct sctp_tcb *stcb = NULL;
5793 inp = (struct sctp_inpcb *)so->so_pcb;
5795 /* I made the same as TCP since we are not setup? */
5796 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5797 return (ECONNRESET);
5800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5803 switch (addr->sa_family) {
5807 struct sockaddr_in6 *sin6p;
5809 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
5810 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5813 sin6p = (struct sockaddr_in6 *)addr;
5814 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
5815 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5824 struct sockaddr_in *sinp;
5826 if (addr->sa_len != sizeof(struct sockaddr_in)) {
5827 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5830 sinp = (struct sockaddr_in *)addr;
5831 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
5832 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5839 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
5840 return (EAFNOSUPPORT);
5842 SCTP_INP_INCR_REF(inp);
5843 SCTP_ASOC_CREATE_LOCK(inp);
5847 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
5848 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
5849 /* Should I really unlock ? */
5850 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
5855 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
5856 (addr->sa_family == AF_INET6)) {
5857 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5862 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
5863 SCTP_PCB_FLAGS_UNBOUND) {
5864 /* Bind a ephemeral port */
5865 error = sctp_inpcb_bind(so, NULL, NULL, p);
5870 /* Now do we connect? */
5871 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
5872 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
5873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5877 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5878 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
5879 /* We are already connected AND the TCP model */
5880 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
5884 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
5885 SCTP_INP_RLOCK(inp);
5886 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5887 SCTP_INP_RUNLOCK(inp);
5890 * We increment here since sctp_findassociation_ep_addr()
5891 * will do a decrement if it finds the stcb as long as the
5892 * locked tcb (last argument) is NOT a TCB.. aka NULL.
5894 SCTP_INP_INCR_REF(inp);
5895 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
5897 SCTP_INP_DECR_REF(inp);
5899 SCTP_TCB_UNLOCK(stcb);
5903 /* Already have or am bring up an association */
5904 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
5908 vrf_id = inp->def_vrf_id;
5909 /* We are GOOD to go */
5910 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
5912 /* Gak! no memory */
5915 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
5916 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
5917 /* Set the connected flag so we can queue data */
5920 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
5921 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
5923 /* initialize authentication parameters for the assoc */
5924 sctp_initialize_auth_params(inp, stcb);
5926 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
5927 SCTP_TCB_UNLOCK(stcb);
5929 if (create_lock_on) {
5930 SCTP_ASOC_CREATE_UNLOCK(inp);
5932 SCTP_INP_DECR_REF(inp);
5939 sctp_listen(struct socket *so, int backlog, struct thread *p)
5942 * Note this module depends on the protocol processing being called
5943 * AFTER any socket level flags and backlog are applied to the
5944 * socket. The traditional way that the socket flags are applied is
5945 * AFTER protocol processing. We have made a change to the
5946 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
5947 * place if the socket API for SCTP is to work properly.
5951 struct sctp_inpcb *inp;
5953 inp = (struct sctp_inpcb *)so->so_pcb;
5955 /* I made the same as TCP since we are not setup? */
5956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5957 return (ECONNRESET);
5959 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
5960 /* See if we have a listener */
5961 struct sctp_inpcb *tinp;
5962 union sctp_sockstore store, *sp;
5965 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5967 struct sctp_laddr *laddr;
5969 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5970 memcpy(&store, &laddr->ifa->address, sizeof(store));
5971 switch (sp->sa.sa_family) {
5974 sp->sin.sin_port = inp->sctp_lport;
5979 sp->sin6.sin6_port = inp->sctp_lport;
5985 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
5986 if (tinp && (tinp != inp) &&
5987 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
5988 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
5989 (tinp->sctp_socket->so_qlimit)) {
5991 * we have a listener already and
5994 SCTP_INP_DECR_REF(tinp);
5995 return (EADDRINUSE);
5997 SCTP_INP_DECR_REF(tinp);
6001 /* Setup a local addr bound all */
6002 memset(&store, 0, sizeof(store));
6003 switch (sp->sa.sa_family) {
6006 store.sin.sin_port = inp->sctp_lport;
6011 sp->sin6.sin6_port = inp->sctp_lport;
6018 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
6019 store.sa.sa_family = AF_INET6;
6020 store.sa.sa_len = sizeof(struct sockaddr_in6);
6024 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
6025 store.sa.sa_family = AF_INET;
6026 store.sa.sa_len = sizeof(struct sockaddr_in);
6029 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6030 if (tinp && (tinp != inp) &&
6031 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6032 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6033 (tinp->sctp_socket->so_qlimit)) {
6035 * we have a listener already and its not
6038 SCTP_INP_DECR_REF(tinp);
6039 return (EADDRINUSE);
6041 SCTP_INP_DECR_REF(inp);
6045 SCTP_INP_RLOCK(inp);
6046 #ifdef SCTP_LOCK_LOGGING
6047 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
6048 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
6052 error = solisten_proto_check(so);
6055 SCTP_INP_RUNLOCK(inp);
6058 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
6059 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
6061 * The unlucky case - We are in the tcp pool with this guy.
6062 * - Someone else is in the main inp slot. - We must move
6063 * this guy (the listener) to the main slot - We must then
6064 * move the guy that was listener to the TCP Pool.
6066 if (sctp_swap_inpcb_for_listen(inp)) {
6070 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6071 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6072 /* We are already connected AND the TCP model */
6074 SCTP_INP_RUNLOCK(inp);
6076 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6077 return (EADDRINUSE);
6079 SCTP_INP_RUNLOCK(inp);
6080 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
6081 /* We must do a bind. */
6083 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
6084 /* bind error, probably perm */
6089 /* It appears for 7.0 and on, we must always call this. */
6090 solisten_proto(so, backlog);
6091 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6092 /* remove the ACCEPTCONN flag for one-to-many sockets */
6093 so->so_options &= ~SO_ACCEPTCONN;
6096 /* turning off listen */
6097 so->so_options &= ~SO_ACCEPTCONN;
6103 static int sctp_defered_wakeup_cnt = 0;
6106 sctp_accept(struct socket *so, struct sockaddr **addr)
6108 struct sctp_tcb *stcb;
6109 struct sctp_inpcb *inp;
6110 union sctp_sockstore store;
6116 inp = (struct sctp_inpcb *)so->so_pcb;
6119 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6120 return (ECONNRESET);
6122 SCTP_INP_RLOCK(inp);
6123 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6124 SCTP_INP_RUNLOCK(inp);
6125 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
6126 return (EOPNOTSUPP);
6128 if (so->so_state & SS_ISDISCONNECTED) {
6129 SCTP_INP_RUNLOCK(inp);
6130 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
6131 return (ECONNABORTED);
6133 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6135 SCTP_INP_RUNLOCK(inp);
6136 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6137 return (ECONNRESET);
6139 SCTP_TCB_LOCK(stcb);
6140 SCTP_INP_RUNLOCK(inp);
6141 store = stcb->asoc.primary_destination->ro._l_addr;
6142 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
6143 SCTP_TCB_UNLOCK(stcb);
6144 switch (store.sa.sa_family) {
6148 struct sockaddr_in *sin;
6150 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6153 sin->sin_family = AF_INET;
6154 sin->sin_len = sizeof(*sin);
6155 sin->sin_port = ((struct sockaddr_in *)&store)->sin_port;
6156 sin->sin_addr = ((struct sockaddr_in *)&store)->sin_addr;
6157 *addr = (struct sockaddr *)sin;
6164 struct sockaddr_in6 *sin6;
6166 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
6169 sin6->sin6_family = AF_INET6;
6170 sin6->sin6_len = sizeof(*sin6);
6171 sin6->sin6_port = ((struct sockaddr_in6 *)&store)->sin6_port;
6173 sin6->sin6_addr = ((struct sockaddr_in6 *)&store)->sin6_addr;
6174 if ((error = sa6_recoverscope(sin6)) != 0) {
6175 SCTP_FREE_SONAME(sin6);
6178 *addr = (struct sockaddr *)sin6;
6186 /* Wake any delayed sleep action */
6187 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
6188 SCTP_INP_WLOCK(inp);
6189 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
6190 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
6191 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
6192 SCTP_INP_WUNLOCK(inp);
6193 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
6194 if (sowriteable(inp->sctp_socket)) {
6195 sowwakeup_locked(inp->sctp_socket);
6197 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
6199 SCTP_INP_WLOCK(inp);
6201 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
6202 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
6203 SCTP_INP_WUNLOCK(inp);
6204 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
6205 if (soreadable(inp->sctp_socket)) {
6206 sctp_defered_wakeup_cnt++;
6207 sorwakeup_locked(inp->sctp_socket);
6209 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
6211 SCTP_INP_WLOCK(inp);
6213 SCTP_INP_WUNLOCK(inp);
6215 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
6216 SCTP_TCB_LOCK(stcb);
6217 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
6224 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
6226 struct sockaddr_in *sin;
6228 struct sctp_inpcb *inp;
6229 struct sctp_ifa *sctp_ifa;
6232 * Do the malloc first in case it blocks.
6234 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6237 sin->sin_family = AF_INET;
6238 sin->sin_len = sizeof(*sin);
6239 inp = (struct sctp_inpcb *)so->so_pcb;
6241 SCTP_FREE_SONAME(sin);
6242 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6243 return (ECONNRESET);
6245 SCTP_INP_RLOCK(inp);
6246 sin->sin_port = inp->sctp_lport;
6247 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
6248 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6249 struct sctp_tcb *stcb;
6250 struct sockaddr_in *sin_a;
6251 struct sctp_nets *net;
6254 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6260 SCTP_TCB_LOCK(stcb);
6261 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6262 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6264 /* this will make coverity happy */
6267 if (sin_a->sin_family == AF_INET) {
6272 if ((!fnd) || (sin_a == NULL)) {
6274 SCTP_TCB_UNLOCK(stcb);
6277 vrf_id = inp->def_vrf_id;
6278 sctp_ifa = sctp_source_address_selection(inp,
6280 (sctp_route_t *) & net->ro,
6283 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
6284 sctp_free_ifa(sctp_ifa);
6286 SCTP_TCB_UNLOCK(stcb);
6288 /* For the bound all case you get back 0 */
6290 sin->sin_addr.s_addr = 0;
6294 /* Take the first IPv4 address in the list */
6295 struct sctp_laddr *laddr;
6298 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6299 if (laddr->ifa->address.sa.sa_family == AF_INET) {
6300 struct sockaddr_in *sin_a;
6302 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
6303 sin->sin_addr = sin_a->sin_addr;
6309 SCTP_FREE_SONAME(sin);
6310 SCTP_INP_RUNLOCK(inp);
6311 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6315 SCTP_INP_RUNLOCK(inp);
6316 (*addr) = (struct sockaddr *)sin;
6321 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
6323 struct sockaddr_in *sin;
6325 struct sockaddr_in *sin_a;
6326 struct sctp_inpcb *inp;
6327 struct sctp_tcb *stcb;
6328 struct sctp_nets *net;
6330 /* Do the malloc first in case it blocks. */
6331 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6334 sin->sin_family = AF_INET;
6335 sin->sin_len = sizeof(*sin);
6337 inp = (struct sctp_inpcb *)so->so_pcb;
6338 if ((inp == NULL) ||
6339 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
6340 /* UDP type and listeners will drop out here */
6341 SCTP_FREE_SONAME(sin);
6342 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
6345 SCTP_INP_RLOCK(inp);
6346 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6348 SCTP_TCB_LOCK(stcb);
6350 SCTP_INP_RUNLOCK(inp);
6352 SCTP_FREE_SONAME(sin);
6353 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6354 return (ECONNRESET);
6357 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6358 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6359 if (sin_a->sin_family == AF_INET) {
6361 sin->sin_port = stcb->rport;
6362 sin->sin_addr = sin_a->sin_addr;
6366 SCTP_TCB_UNLOCK(stcb);
6368 /* No IPv4 address */
6369 SCTP_FREE_SONAME(sin);
6370 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6373 (*addr) = (struct sockaddr *)sin;
6378 struct pr_usrreqs sctp_usrreqs = {
6379 .pru_abort = sctp_abort,
6380 .pru_accept = sctp_accept,
6381 .pru_attach = sctp_attach,
6382 .pru_bind = sctp_bind,
6383 .pru_connect = sctp_connect,
6384 .pru_control = in_control,
6385 .pru_close = sctp_close,
6386 .pru_detach = sctp_close,
6387 .pru_sopoll = sopoll_generic,
6388 .pru_flush = sctp_flush,
6389 .pru_disconnect = sctp_disconnect,
6390 .pru_listen = sctp_listen,
6391 .pru_peeraddr = sctp_peeraddr,
6392 .pru_send = sctp_sendm,
6393 .pru_shutdown = sctp_shutdown,
6394 .pru_sockaddr = sctp_ingetaddr,
6395 .pru_sosend = sctp_sosend,
6396 .pru_soreceive = sctp_soreceive