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))
668 } else if (addr == NULL) {
669 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
670 error = EDESTADDRREQ;
673 sctp_m_freem(control);
679 if (addr->sa_family != AF_INET) {
680 /* must be a v4 address! */
681 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
684 sctp_m_freem(control);
687 error = EDESTADDRREQ;
692 /* now what about control */
695 SCTP_PRINTF("huh? control set?\n");
696 sctp_m_freem(inp->control);
699 inp->control = control;
703 SCTP_BUF_NEXT(inp->pkt_last) = m;
706 inp->pkt_last = inp->pkt = m;
709 /* FreeBSD uses a flag passed */
710 ((flags & PRUS_MORETOCOME) == 0)
713 * note with the current version this code will only be used
714 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
715 * re-defining sosend to use the sctp_sosend. One can
716 * optionally switch back to this code (by changing back the
717 * definitions) but this is not advisable. This code is used
718 * by FreeBSD when sending a file with sendfile() though.
722 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
732 sctp_disconnect(struct socket *so)
734 struct sctp_inpcb *inp;
736 inp = (struct sctp_inpcb *)so->so_pcb;
738 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
742 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
743 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
744 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
746 SCTP_INP_RUNLOCK(inp);
749 struct sctp_association *asoc;
750 struct sctp_tcb *stcb;
752 stcb = LIST_FIRST(&inp->sctp_asoc_list);
754 SCTP_INP_RUNLOCK(inp);
755 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
760 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
761 /* We are about to be freed, out of here */
762 SCTP_TCB_UNLOCK(stcb);
763 SCTP_INP_RUNLOCK(inp);
766 if (((so->so_options & SO_LINGER) &&
767 (so->so_linger == 0)) ||
768 (so->so_rcv.sb_cc > 0)) {
769 if (SCTP_GET_STATE(asoc) !=
770 SCTP_STATE_COOKIE_WAIT) {
771 /* Left with Data unread */
774 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_DONTWAIT, 1, MT_DATA);
780 struct sctp_paramhdr *ph;
782 ph = mtod(err, struct sctp_paramhdr *);
783 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
784 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
785 ph->param_length = htons(SCTP_BUF_LEN(err));
787 #if defined(SCTP_PANIC_ON_ABORT)
788 panic("disconnect does an abort");
790 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
791 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
793 SCTP_INP_RUNLOCK(inp);
794 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
795 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
796 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
798 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
799 /* No unlock tcb assoc is gone */
802 if (TAILQ_EMPTY(&asoc->send_queue) &&
803 TAILQ_EMPTY(&asoc->sent_queue) &&
804 (asoc->stream_queue_cnt == 0)) {
805 /* there is nothing queued to send, so done */
806 if (asoc->locked_on_sending) {
809 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
810 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
811 /* only send SHUTDOWN 1st time thru */
812 struct sctp_nets *netp;
814 if (stcb->asoc.alternate) {
815 netp = stcb->asoc.alternate;
817 netp = stcb->asoc.primary_destination;
819 sctp_stop_timers_for_shutdown(stcb);
820 sctp_send_shutdown(stcb, netp);
821 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
822 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
823 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
824 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
826 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
827 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
828 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
829 stcb->sctp_ep, stcb, netp);
830 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
831 stcb->sctp_ep, stcb, netp);
836 * we still got (or just got) data to send,
837 * so set SHUTDOWN_PENDING
840 * XXX sockets draft says that SCTP_EOF
841 * should be sent with no data. currently,
842 * we will allow user data to be sent first
843 * and move to SHUTDOWN-PENDING
845 struct sctp_nets *netp;
847 if (stcb->asoc.alternate) {
848 netp = stcb->asoc.alternate;
850 netp = stcb->asoc.primary_destination;
853 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
854 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
856 if (asoc->locked_on_sending) {
857 /* Locked to send out the data */
858 struct sctp_stream_queue_pending *sp;
860 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
862 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
863 asoc->locked_on_sending->stream_no);
865 if ((sp->length == 0) && (sp->msg_is_complete == 0))
866 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
869 if (TAILQ_EMPTY(&asoc->send_queue) &&
870 TAILQ_EMPTY(&asoc->sent_queue) &&
871 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
875 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
876 0, M_DONTWAIT, 1, MT_DATA);
882 struct sctp_paramhdr *ph;
885 SCTP_BUF_LEN(op_err) =
886 (sizeof(struct sctp_paramhdr) + sizeof(uint32_t));
888 struct sctp_paramhdr *);
889 ph->param_type = htons(
890 SCTP_CAUSE_USER_INITIATED_ABT);
891 ph->param_length = htons(SCTP_BUF_LEN(op_err));
892 ippp = (uint32_t *) (ph + 1);
893 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4);
895 #if defined(SCTP_PANIC_ON_ABORT)
896 panic("disconnect does an abort");
899 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
900 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
901 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
902 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
903 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
904 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
906 SCTP_INP_RUNLOCK(inp);
907 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
910 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
913 soisdisconnecting(so);
914 SCTP_TCB_UNLOCK(stcb);
915 SCTP_INP_RUNLOCK(inp);
920 /* UDP model does not support this */
921 SCTP_INP_RUNLOCK(inp);
922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
928 sctp_flush(struct socket *so, int how)
931 * We will just clear out the values and let subsequent close clear
932 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
933 * they will not be able to read the data, the socket will block
934 * that from happening.
936 struct sctp_inpcb *inp;
938 inp = (struct sctp_inpcb *)so->so_pcb;
940 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
944 /* For the 1 to many model this does nothing */
945 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
946 SCTP_INP_RUNLOCK(inp);
949 SCTP_INP_RUNLOCK(inp);
950 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
952 * First make sure the sb will be happy, we don't use these
953 * except maybe the count
956 SCTP_INP_READ_LOCK(inp);
957 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
958 SCTP_INP_READ_UNLOCK(inp);
959 SCTP_INP_WUNLOCK(inp);
960 so->so_rcv.sb_cc = 0;
961 so->so_rcv.sb_mbcnt = 0;
962 so->so_rcv.sb_mb = NULL;
964 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
966 * First make sure the sb will be happy, we don't use these
967 * except maybe the count
969 so->so_snd.sb_cc = 0;
970 so->so_snd.sb_mbcnt = 0;
971 so->so_snd.sb_mb = NULL;
978 sctp_shutdown(struct socket *so)
980 struct sctp_inpcb *inp;
982 inp = (struct sctp_inpcb *)so->so_pcb;
984 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
988 /* For UDP model this is a invalid call */
989 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
990 /* Restore the flags that the soshutdown took away. */
991 SOCKBUF_LOCK(&so->so_rcv);
992 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
993 SOCKBUF_UNLOCK(&so->so_rcv);
994 /* This proc will wakeup for read and do nothing (I hope) */
995 SCTP_INP_RUNLOCK(inp);
996 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1000 * Ok if we reach here its the TCP model and it is either a SHUT_WR
1001 * or SHUT_RDWR. This means we put the shutdown flag against it.
1004 struct sctp_tcb *stcb;
1005 struct sctp_association *asoc;
1008 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
1009 SCTP_INP_RUNLOCK(inp);
1014 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1017 * Ok we hit the case that the shutdown call was
1018 * made after an abort or something. Nothing to do
1021 SCTP_INP_RUNLOCK(inp);
1024 SCTP_TCB_LOCK(stcb);
1026 if (TAILQ_EMPTY(&asoc->send_queue) &&
1027 TAILQ_EMPTY(&asoc->sent_queue) &&
1028 (asoc->stream_queue_cnt == 0)) {
1029 if (asoc->locked_on_sending) {
1032 /* there is nothing queued to send, so I'm done... */
1033 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
1034 /* only send SHUTDOWN the first time through */
1035 struct sctp_nets *netp;
1037 if (stcb->asoc.alternate) {
1038 netp = stcb->asoc.alternate;
1040 netp = stcb->asoc.primary_destination;
1042 sctp_stop_timers_for_shutdown(stcb);
1043 sctp_send_shutdown(stcb, netp);
1044 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
1045 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
1046 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1047 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1049 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
1050 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
1051 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1052 stcb->sctp_ep, stcb, netp);
1053 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1054 stcb->sctp_ep, stcb, netp);
1058 * we still got (or just got) data to send, so set
1061 struct sctp_nets *netp;
1063 if (stcb->asoc.alternate) {
1064 netp = stcb->asoc.alternate;
1066 netp = stcb->asoc.primary_destination;
1069 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1070 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1073 if (asoc->locked_on_sending) {
1074 /* Locked to send out the data */
1075 struct sctp_stream_queue_pending *sp;
1077 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1079 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1080 asoc->locked_on_sending->stream_no);
1082 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1083 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1087 if (TAILQ_EMPTY(&asoc->send_queue) &&
1088 TAILQ_EMPTY(&asoc->sent_queue) &&
1089 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1090 struct mbuf *op_err;
1093 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
1094 0, M_DONTWAIT, 1, MT_DATA);
1096 /* Fill in the user initiated abort */
1097 struct sctp_paramhdr *ph;
1100 SCTP_BUF_LEN(op_err) =
1101 sizeof(struct sctp_paramhdr) + sizeof(uint32_t);
1103 struct sctp_paramhdr *);
1104 ph->param_type = htons(
1105 SCTP_CAUSE_USER_INITIATED_ABT);
1106 ph->param_length = htons(SCTP_BUF_LEN(op_err));
1107 ippp = (uint32_t *) (ph + 1);
1108 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1110 #if defined(SCTP_PANIC_ON_ABORT)
1111 panic("shutdown does an abort");
1113 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1114 sctp_abort_an_association(stcb->sctp_ep, stcb,
1115 SCTP_RESPONSE_TO_USER_REQ,
1116 op_err, SCTP_SO_LOCKED);
1119 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1122 SCTP_TCB_UNLOCK(stcb);
1125 SCTP_INP_RUNLOCK(inp);
1130 * copies a "user" presentable address and removes embedded scope, etc.
1131 * returns 0 on success, 1 on error
1134 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1137 struct sockaddr_in6 lsa6;
1139 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1142 memcpy(ss, sa, sa->sa_len);
1149 * NOTE: assumes addr lock is held
1152 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1153 struct sctp_tcb *stcb,
1155 struct sockaddr_storage *sas,
1158 struct sctp_ifn *sctp_ifn;
1159 struct sctp_ifa *sctp_ifa;
1160 int loopback_scope, ipv4_local_scope, local_scope, site_scope;
1162 int ipv4_addr_legal, ipv6_addr_legal;
1163 struct sctp_vrf *vrf;
1170 /* Turn on all the appropriate scope */
1171 loopback_scope = stcb->asoc.loopback_scope;
1172 ipv4_local_scope = stcb->asoc.ipv4_local_scope;
1173 local_scope = stcb->asoc.local_scope;
1174 site_scope = stcb->asoc.site_scope;
1176 /* Turn on ALL scope, since we look at the EP */
1177 loopback_scope = ipv4_local_scope = local_scope =
1180 ipv4_addr_legal = ipv6_addr_legal = 0;
1181 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1182 ipv6_addr_legal = 1;
1183 if (SCTP_IPV6_V6ONLY(inp) == 0) {
1184 ipv4_addr_legal = 1;
1187 ipv4_addr_legal = 1;
1189 vrf = sctp_find_vrf(vrf_id);
1193 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1194 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1195 if ((loopback_scope == 0) &&
1196 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1197 /* Skip loopback if loopback_scope not set */
1200 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1203 * For the BOUND-ALL case, the list
1204 * associated with a TCB is Always
1205 * considered a reverse list.. i.e.
1206 * it lists addresses that are NOT
1207 * part of the association. If this
1208 * is one of those we must skip it.
1210 if (sctp_is_addr_restricted(stcb,
1215 switch (sctp_ifa->address.sa.sa_family) {
1218 if (ipv4_addr_legal) {
1219 struct sockaddr_in *sin;
1221 sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
1222 if (sin->sin_addr.s_addr == 0) {
1230 if ((ipv4_local_scope == 0) &&
1231 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1235 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1236 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1237 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1238 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1239 actual += sizeof(struct sockaddr_in6);
1242 memcpy(sas, sin, sizeof(*sin));
1243 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1244 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1245 actual += sizeof(*sin);
1249 if (actual >= limit) {
1259 if (ipv6_addr_legal) {
1260 struct sockaddr_in6 *sin6;
1262 sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
1263 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1271 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1272 if (local_scope == 0)
1274 if (sin6->sin6_scope_id == 0) {
1275 if (sa6_recoverscope(sin6) != 0)
1293 if ((site_scope == 0) &&
1294 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1297 memcpy(sas, sin6, sizeof(*sin6));
1298 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1299 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1300 actual += sizeof(*sin6);
1301 if (actual >= limit) {
1316 struct sctp_laddr *laddr;
1318 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1320 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1324 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1327 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1328 sas = (struct sockaddr_storage *)((caddr_t)sas +
1329 laddr->ifa->address.sa.sa_len);
1330 actual += laddr->ifa->address.sa.sa_len;
1331 if (actual >= limit) {
1340 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1341 struct sctp_tcb *stcb,
1343 struct sockaddr_storage *sas)
1347 SCTP_IPI_ADDR_RLOCK();
1348 /* fill up addresses for the endpoint's default vrf */
1349 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1351 SCTP_IPI_ADDR_RUNLOCK();
1356 * NOTE: assumes addr lock is held
1359 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1362 struct sctp_vrf *vrf = NULL;
1365 * In both sub-set bound an bound_all cases we return the MAXIMUM
1366 * number of addresses that you COULD get. In reality the sub-set
1367 * bound may have an exclusion list for a given TCB OR in the
1368 * bound-all case a TCB may NOT include the loopback or other
1369 * addresses as well.
1371 vrf = sctp_find_vrf(vrf_id);
1375 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1376 struct sctp_ifn *sctp_ifn;
1377 struct sctp_ifa *sctp_ifa;
1379 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1380 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1381 /* Count them if they are the right type */
1382 switch (sctp_ifa->address.sa.sa_family) {
1385 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1386 cnt += sizeof(struct sockaddr_in6);
1388 cnt += sizeof(struct sockaddr_in);
1393 cnt += sizeof(struct sockaddr_in6);
1402 struct sctp_laddr *laddr;
1404 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1405 switch (laddr->ifa->address.sa.sa_family) {
1408 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1409 cnt += sizeof(struct sockaddr_in6);
1411 cnt += sizeof(struct sockaddr_in);
1416 cnt += sizeof(struct sockaddr_in6);
1428 sctp_count_max_addresses(struct sctp_inpcb *inp)
1432 SCTP_IPI_ADDR_RLOCK();
1433 /* count addresses for the endpoint's default VRF */
1434 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1435 SCTP_IPI_ADDR_RUNLOCK();
1440 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1441 size_t optsize, void *p, int delay)
1444 int creat_lock_on = 0;
1445 struct sctp_tcb *stcb = NULL;
1446 struct sockaddr *sa;
1447 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1449 int bad_addresses = 0;
1452 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1454 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1455 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1456 /* We are already connected AND the TCP model */
1457 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1458 return (EADDRINUSE);
1460 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1461 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1462 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1465 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1466 SCTP_INP_RLOCK(inp);
1467 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1468 SCTP_INP_RUNLOCK(inp);
1471 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1474 SCTP_INP_INCR_REF(inp);
1475 SCTP_ASOC_CREATE_LOCK(inp);
1477 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1478 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1479 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1483 totaddrp = (int *)optval;
1484 totaddr = *totaddrp;
1485 sa = (struct sockaddr *)(totaddrp + 1);
1486 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
1487 if ((stcb != NULL) || bad_addresses) {
1488 /* Already have or am bring up an association */
1489 SCTP_ASOC_CREATE_UNLOCK(inp);
1492 SCTP_TCB_UNLOCK(stcb);
1493 if (bad_addresses == 0) {
1494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1500 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1505 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1507 struct in6pcb *inp6;
1509 inp6 = (struct in6pcb *)inp;
1510 if (SCTP_IPV6_V6ONLY(inp6)) {
1512 * if IPV6_V6ONLY flag, ignore connections destined
1513 * to a v4 addr or v4-mapped addr
1515 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1521 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1522 SCTP_PCB_FLAGS_UNBOUND) {
1523 /* Bind a ephemeral port */
1524 error = sctp_inpcb_bind(so, NULL, NULL, p);
1529 /* FIX ME: do we want to pass in a vrf on the connect call? */
1530 vrf_id = inp->def_vrf_id;
1533 /* We are GOOD to go */
1534 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1538 /* Gak! no memory */
1541 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1542 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1543 /* Set the connected flag so we can queue data */
1546 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1547 /* move to second address */
1548 switch (sa->sa_family) {
1551 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1556 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1564 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1565 /* Fill in the return id */
1567 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1570 a_id = (sctp_assoc_t *) optval;
1571 *a_id = sctp_get_associd(stcb);
1573 /* initialize authentication parameters for the assoc */
1574 sctp_initialize_auth_params(inp, stcb);
1577 /* doing delayed connection */
1578 stcb->asoc.delayed_connection = 1;
1579 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1581 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1582 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1584 SCTP_TCB_UNLOCK(stcb);
1585 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1586 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1587 /* Set the connected flag so we can queue data */
1591 if (creat_lock_on) {
1592 SCTP_ASOC_CREATE_UNLOCK(inp);
1594 SCTP_INP_DECR_REF(inp);
1598 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1599 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1600 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1601 SCTP_INP_RLOCK(inp); \
1602 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1604 SCTP_TCB_LOCK(stcb); \
1606 SCTP_INP_RUNLOCK(inp); \
1607 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1608 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1609 if (stcb == NULL) { \
1610 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1620 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1621 if (size < sizeof(type)) { \
1622 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1626 destp = (type *)srcp; \
1631 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1634 struct sctp_inpcb *inp = NULL;
1636 struct sctp_tcb *stcb = NULL;
1638 if (optval == NULL) {
1639 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1642 inp = (struct sctp_inpcb *)so->so_pcb;
1644 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1651 case SCTP_AUTOCLOSE:
1652 case SCTP_EXPLICIT_EOR:
1653 case SCTP_AUTO_ASCONF:
1654 case SCTP_DISABLE_FRAGMENTS:
1655 case SCTP_I_WANT_MAPPED_V4_ADDR:
1656 case SCTP_USE_EXT_RCVINFO:
1657 SCTP_INP_RLOCK(inp);
1659 case SCTP_DISABLE_FRAGMENTS:
1660 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1662 case SCTP_I_WANT_MAPPED_V4_ADDR:
1663 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1665 case SCTP_AUTO_ASCONF:
1666 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1667 /* only valid for bound all sockets */
1668 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1670 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1675 case SCTP_EXPLICIT_EOR:
1676 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1679 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1681 case SCTP_USE_EXT_RCVINFO:
1682 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1684 case SCTP_AUTOCLOSE:
1685 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1686 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1693 error = ENOPROTOOPT;
1694 } /* end switch (sopt->sopt_name) */
1695 if (*optsize < sizeof(val)) {
1696 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1700 SCTP_INP_RUNLOCK(inp);
1702 /* return the option value */
1703 *(int *)optval = val;
1704 *optsize = sizeof(val);
1707 case SCTP_GET_PACKET_LOG:
1709 #ifdef SCTP_PACKET_LOGGING
1713 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1714 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1717 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1722 case SCTP_REUSE_PORT:
1726 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1727 /* Can't do this for a 1-m socket */
1731 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1732 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1733 *optsize = sizeof(uint32_t);
1736 case SCTP_PARTIAL_DELIVERY_POINT:
1740 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1741 *value = inp->partial_delivery_point;
1742 *optsize = sizeof(uint32_t);
1745 case SCTP_FRAGMENT_INTERLEAVE:
1749 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1750 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1751 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1752 *value = SCTP_FRAG_LEVEL_2;
1754 *value = SCTP_FRAG_LEVEL_1;
1757 *value = SCTP_FRAG_LEVEL_0;
1759 *optsize = sizeof(uint32_t);
1762 case SCTP_CMT_ON_OFF:
1764 struct sctp_assoc_value *av;
1766 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1767 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1769 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1770 SCTP_TCB_UNLOCK(stcb);
1772 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1773 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1774 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1775 SCTP_INP_RLOCK(inp);
1776 av->assoc_value = inp->sctp_cmt_on_off;
1777 SCTP_INP_RUNLOCK(inp);
1779 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1784 *optsize = sizeof(struct sctp_assoc_value);
1788 case SCTP_PLUGGABLE_CC:
1790 struct sctp_assoc_value *av;
1792 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1793 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1795 av->assoc_value = stcb->asoc.congestion_control_module;
1796 SCTP_TCB_UNLOCK(stcb);
1798 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1799 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1800 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1801 SCTP_INP_RLOCK(inp);
1802 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1803 SCTP_INP_RUNLOCK(inp);
1805 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1810 *optsize = sizeof(struct sctp_assoc_value);
1814 case SCTP_CC_OPTION:
1816 struct sctp_cc_option *cc_opt;
1818 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1819 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1823 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1826 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1827 *optsize = sizeof(struct sctp_cc_option);
1829 SCTP_TCB_UNLOCK(stcb);
1833 case SCTP_PLUGGABLE_SS:
1835 struct sctp_assoc_value *av;
1837 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1838 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1840 av->assoc_value = stcb->asoc.stream_scheduling_module;
1841 SCTP_TCB_UNLOCK(stcb);
1843 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1844 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1845 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1846 SCTP_INP_RLOCK(inp);
1847 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1848 SCTP_INP_RUNLOCK(inp);
1850 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1855 *optsize = sizeof(struct sctp_assoc_value);
1861 struct sctp_stream_value *av;
1863 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1864 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1866 if (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1867 &av->stream_value) < 0) {
1868 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1871 *optsize = sizeof(struct sctp_stream_value);
1873 SCTP_TCB_UNLOCK(stcb);
1876 * Can't get stream value without
1879 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1884 case SCTP_GET_ADDR_LEN:
1886 struct sctp_assoc_value *av;
1888 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1891 if (av->assoc_value == AF_INET) {
1892 av->assoc_value = sizeof(struct sockaddr_in);
1897 if (av->assoc_value == AF_INET6) {
1898 av->assoc_value = sizeof(struct sockaddr_in6);
1903 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1905 *optsize = sizeof(struct sctp_assoc_value);
1909 case SCTP_GET_ASSOC_NUMBER:
1911 uint32_t *value, cnt;
1913 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1915 SCTP_INP_RLOCK(inp);
1916 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1919 SCTP_INP_RUNLOCK(inp);
1921 *optsize = sizeof(uint32_t);
1924 case SCTP_GET_ASSOC_ID_LIST:
1926 struct sctp_assoc_ids *ids;
1927 unsigned int at, limit;
1929 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1931 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1932 SCTP_INP_RLOCK(inp);
1933 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1935 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1942 SCTP_INP_RUNLOCK(inp);
1944 ids->gaids_number_of_ids = at;
1945 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1951 struct sctp_assoc_value *av;
1953 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1954 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1957 av->assoc_value = stcb->asoc.context;
1958 SCTP_TCB_UNLOCK(stcb);
1960 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1961 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1962 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1963 SCTP_INP_RLOCK(inp);
1964 av->assoc_value = inp->sctp_context;
1965 SCTP_INP_RUNLOCK(inp);
1967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1972 *optsize = sizeof(struct sctp_assoc_value);
1978 uint32_t *default_vrfid;
1980 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1981 *default_vrfid = inp->def_vrf_id;
1982 *optsize = sizeof(uint32_t);
1985 case SCTP_GET_ASOC_VRF:
1987 struct sctp_assoc_value *id;
1989 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1990 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1993 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1995 id->assoc_value = stcb->asoc.vrf_id;
1996 *optsize = sizeof(struct sctp_assoc_value);
2000 case SCTP_GET_VRF_IDS:
2002 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2006 case SCTP_GET_NONCE_VALUES:
2008 struct sctp_get_nonce_values *gnv;
2010 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2011 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2014 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2015 gnv->gn_local_tag = stcb->asoc.my_vtag;
2016 SCTP_TCB_UNLOCK(stcb);
2017 *optsize = sizeof(struct sctp_get_nonce_values);
2019 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2024 case SCTP_DELAYED_SACK:
2026 struct sctp_sack_info *sack;
2028 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2029 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2031 sack->sack_delay = stcb->asoc.delayed_ack;
2032 sack->sack_freq = stcb->asoc.sack_freq;
2033 SCTP_TCB_UNLOCK(stcb);
2035 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2036 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2037 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2038 SCTP_INP_RLOCK(inp);
2039 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2040 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2041 SCTP_INP_RUNLOCK(inp);
2043 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2048 *optsize = sizeof(struct sctp_sack_info);
2052 case SCTP_GET_SNDBUF_USE:
2054 struct sctp_sockstat *ss;
2056 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2057 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2060 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2061 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2062 stcb->asoc.size_on_all_streams);
2063 SCTP_TCB_UNLOCK(stcb);
2064 *optsize = sizeof(struct sctp_sockstat);
2066 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2071 case SCTP_MAX_BURST:
2073 struct sctp_assoc_value *av;
2075 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2076 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2079 av->assoc_value = stcb->asoc.max_burst;
2080 SCTP_TCB_UNLOCK(stcb);
2082 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2083 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2084 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2085 SCTP_INP_RLOCK(inp);
2086 av->assoc_value = inp->sctp_ep.max_burst;
2087 SCTP_INP_RUNLOCK(inp);
2089 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2094 *optsize = sizeof(struct sctp_assoc_value);
2100 struct sctp_assoc_value *av;
2103 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2104 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2107 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2108 SCTP_TCB_UNLOCK(stcb);
2110 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2111 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2112 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2113 SCTP_INP_RLOCK(inp);
2114 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2115 ovh = SCTP_MED_OVERHEAD;
2117 ovh = SCTP_MED_V4_OVERHEAD;
2119 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2120 av->assoc_value = 0;
2122 av->assoc_value = inp->sctp_frag_point - ovh;
2123 SCTP_INP_RUNLOCK(inp);
2125 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2130 *optsize = sizeof(struct sctp_assoc_value);
2134 case SCTP_GET_STAT_LOG:
2135 error = sctp_fill_stat_log(optval, optsize);
2139 struct sctp_event_subscribe *events;
2141 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2142 memset(events, 0, sizeof(struct sctp_event_subscribe));
2143 SCTP_INP_RLOCK(inp);
2144 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2145 events->sctp_data_io_event = 1;
2147 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2148 events->sctp_association_event = 1;
2150 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2151 events->sctp_address_event = 1;
2153 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2154 events->sctp_send_failure_event = 1;
2156 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2157 events->sctp_peer_error_event = 1;
2159 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2160 events->sctp_shutdown_event = 1;
2162 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2163 events->sctp_partial_delivery_event = 1;
2165 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2166 events->sctp_adaptation_layer_event = 1;
2168 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2169 events->sctp_authentication_event = 1;
2171 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2172 events->sctp_sender_dry_event = 1;
2174 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2175 events->sctp_stream_reset_event = 1;
2176 SCTP_INP_RUNLOCK(inp);
2177 *optsize = sizeof(struct sctp_event_subscribe);
2180 case SCTP_ADAPTATION_LAYER:
2184 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2186 SCTP_INP_RLOCK(inp);
2187 *value = inp->sctp_ep.adaptation_layer_indicator;
2188 SCTP_INP_RUNLOCK(inp);
2189 *optsize = sizeof(uint32_t);
2192 case SCTP_SET_INITIAL_DBG_SEQ:
2196 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2197 SCTP_INP_RLOCK(inp);
2198 *value = inp->sctp_ep.initial_sequence_debug;
2199 SCTP_INP_RUNLOCK(inp);
2200 *optsize = sizeof(uint32_t);
2203 case SCTP_GET_LOCAL_ADDR_SIZE:
2207 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2208 SCTP_INP_RLOCK(inp);
2209 *value = sctp_count_max_addresses(inp);
2210 SCTP_INP_RUNLOCK(inp);
2211 *optsize = sizeof(uint32_t);
2214 case SCTP_GET_REMOTE_ADDR_SIZE:
2218 struct sctp_nets *net;
2220 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2221 /* FIXME MT: change to sctp_assoc_value? */
2222 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2226 /* Count the sizes */
2227 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2228 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2229 size += sizeof(struct sockaddr_in6);
2231 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2234 size += sizeof(struct sockaddr_in);
2239 size += sizeof(struct sockaddr_in6);
2247 SCTP_TCB_UNLOCK(stcb);
2248 *value = (uint32_t) size;
2249 *optsize = sizeof(uint32_t);
2251 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2256 case SCTP_GET_PEER_ADDRESSES:
2258 * Get the address information, an array is passed in to
2259 * fill up we pack it.
2263 struct sockaddr_storage *sas;
2264 struct sctp_nets *net;
2265 struct sctp_getaddresses *saddr;
2267 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2268 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2271 left = (*optsize) - sizeof(struct sctp_getaddresses);
2272 *optsize = sizeof(struct sctp_getaddresses);
2273 sas = (struct sockaddr_storage *)&saddr->addr[0];
2275 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2276 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2277 cpsz = sizeof(struct sockaddr_in6);
2279 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2282 cpsz = sizeof(struct sockaddr_in);
2287 cpsz = sizeof(struct sockaddr_in6);
2299 /* not enough room. */
2302 #if defined(INET) && defined(INET6)
2303 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2304 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2305 /* Must map the address */
2306 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2307 (struct sockaddr_in6 *)sas);
2310 memcpy(sas, &net->ro._l_addr, cpsz);
2311 #if defined(INET) && defined(INET6)
2314 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2316 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2320 SCTP_TCB_UNLOCK(stcb);
2322 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2327 case SCTP_GET_LOCAL_ADDRESSES:
2329 size_t limit, actual;
2330 struct sockaddr_storage *sas;
2331 struct sctp_getaddresses *saddr;
2333 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2334 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2336 sas = (struct sockaddr_storage *)&saddr->addr[0];
2337 limit = *optsize - sizeof(sctp_assoc_t);
2338 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2340 SCTP_TCB_UNLOCK(stcb);
2342 *optsize = sizeof(struct sockaddr_storage) + actual;
2345 case SCTP_PEER_ADDR_PARAMS:
2347 struct sctp_paddrparams *paddrp;
2348 struct sctp_nets *net;
2350 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2351 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2355 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2358 * We increment here since
2359 * sctp_findassociation_ep_addr() wil do a
2360 * decrement if it finds the stcb as long as
2361 * the locked tcb (last argument) is NOT a
2364 SCTP_INP_INCR_REF(inp);
2365 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2367 SCTP_INP_DECR_REF(inp);
2370 if (stcb && (net == NULL)) {
2371 struct sockaddr *sa;
2373 sa = (struct sockaddr *)&paddrp->spp_address;
2375 if (sa->sa_family == AF_INET) {
2376 struct sockaddr_in *sin;
2378 sin = (struct sockaddr_in *)sa;
2379 if (sin->sin_addr.s_addr) {
2381 SCTP_TCB_UNLOCK(stcb);
2382 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2388 if (sa->sa_family == AF_INET6) {
2389 struct sockaddr_in6 *sin6;
2391 sin6 = (struct sockaddr_in6 *)sa;
2392 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2394 SCTP_TCB_UNLOCK(stcb);
2395 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2401 error = EAFNOSUPPORT;
2402 SCTP_TCB_UNLOCK(stcb);
2403 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2408 /* Applies to the specific association */
2409 paddrp->spp_flags = 0;
2413 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2414 ovh = SCTP_MED_OVERHEAD;
2416 ovh = SCTP_MED_V4_OVERHEAD;
2419 paddrp->spp_hbinterval = net->heart_beat_delay;
2420 paddrp->spp_pathmaxrxt = net->failure_threshold;
2421 paddrp->spp_pathmtu = net->mtu - ovh;
2422 /* get flags for HB */
2423 if (net->dest_state & SCTP_ADDR_NOHB) {
2424 paddrp->spp_flags |= SPP_HB_DISABLE;
2426 paddrp->spp_flags |= SPP_HB_ENABLE;
2428 /* get flags for PMTU */
2429 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2430 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2432 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2434 if (net->dscp & 0x01) {
2435 paddrp->spp_dscp = net->dscp & 0xfc;
2436 paddrp->spp_flags |= SPP_DSCP;
2439 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2440 (net->flowlabel & 0x80000000)) {
2441 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2442 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2447 * No destination so return default
2450 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2451 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2452 if (stcb->asoc.default_dscp & 0x01) {
2453 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2454 paddrp->spp_flags |= SPP_DSCP;
2457 if (stcb->asoc.default_flowlabel & 0x80000000) {
2458 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2459 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2462 /* default settings should be these */
2463 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2464 paddrp->spp_flags |= SPP_HB_DISABLE;
2466 paddrp->spp_flags |= SPP_HB_ENABLE;
2468 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2469 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2471 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2473 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2475 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2476 SCTP_TCB_UNLOCK(stcb);
2478 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2479 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2480 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2481 /* Use endpoint defaults */
2482 SCTP_INP_RLOCK(inp);
2483 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2484 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2485 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2486 /* get inp's default */
2487 if (inp->sctp_ep.default_dscp & 0x01) {
2488 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2489 paddrp->spp_flags |= SPP_DSCP;
2492 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2493 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2494 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2495 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2498 /* can't return this */
2499 paddrp->spp_pathmtu = 0;
2501 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2502 paddrp->spp_flags |= SPP_HB_ENABLE;
2504 paddrp->spp_flags |= SPP_HB_DISABLE;
2506 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2507 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2509 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2511 SCTP_INP_RUNLOCK(inp);
2513 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2518 *optsize = sizeof(struct sctp_paddrparams);
2522 case SCTP_GET_PEER_ADDR_INFO:
2524 struct sctp_paddrinfo *paddri;
2525 struct sctp_nets *net;
2527 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2528 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2532 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
2535 * We increment here since
2536 * sctp_findassociation_ep_addr() wil do a
2537 * decrement if it finds the stcb as long as
2538 * the locked tcb (last argument) is NOT a
2541 SCTP_INP_INCR_REF(inp);
2542 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
2544 SCTP_INP_DECR_REF(inp);
2548 if ((stcb) && (net)) {
2549 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2550 /* It's unconfirmed */
2551 paddri->spinfo_state = SCTP_UNCONFIRMED;
2552 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2554 paddri->spinfo_state = SCTP_ACTIVE;
2557 paddri->spinfo_state = SCTP_INACTIVE;
2559 paddri->spinfo_cwnd = net->cwnd;
2560 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2561 paddri->spinfo_rto = net->RTO;
2562 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2563 paddri->spinfo_mtu = net->mtu;
2564 SCTP_TCB_UNLOCK(stcb);
2565 *optsize = sizeof(struct sctp_paddrinfo);
2568 SCTP_TCB_UNLOCK(stcb);
2570 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2575 case SCTP_PCB_STATUS:
2577 struct sctp_pcbinfo *spcb;
2579 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2580 sctp_fill_pcbinfo(spcb);
2581 *optsize = sizeof(struct sctp_pcbinfo);
2586 struct sctp_nets *net;
2587 struct sctp_status *sstat;
2589 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2590 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2593 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2598 * I think passing the state is fine since
2599 * sctp_constants.h will be available to the user
2602 sstat->sstat_state = stcb->asoc.state;
2603 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2604 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2605 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2607 * We can't include chunks that have been passed to
2608 * the socket layer. Only things in queue.
2610 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2611 stcb->asoc.cnt_on_all_streams);
2614 sstat->sstat_instrms = stcb->asoc.streamincnt;
2615 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2616 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2617 memcpy(&sstat->sstat_primary.spinfo_address,
2618 &stcb->asoc.primary_destination->ro._l_addr,
2619 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2620 net = stcb->asoc.primary_destination;
2621 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2623 * Again the user can get info from sctp_constants.h
2624 * for what the state of the network is.
2626 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2627 /* It's unconfirmed */
2628 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2629 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2631 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2634 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2636 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2637 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2638 sstat->sstat_primary.spinfo_rto = net->RTO;
2639 sstat->sstat_primary.spinfo_mtu = net->mtu;
2640 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2641 SCTP_TCB_UNLOCK(stcb);
2642 *optsize = sizeof(struct sctp_status);
2647 struct sctp_rtoinfo *srto;
2649 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2650 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2653 srto->srto_initial = stcb->asoc.initial_rto;
2654 srto->srto_max = stcb->asoc.maxrto;
2655 srto->srto_min = stcb->asoc.minrto;
2656 SCTP_TCB_UNLOCK(stcb);
2658 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2659 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2660 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2661 SCTP_INP_RLOCK(inp);
2662 srto->srto_initial = inp->sctp_ep.initial_rto;
2663 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2664 srto->srto_min = inp->sctp_ep.sctp_minrto;
2665 SCTP_INP_RUNLOCK(inp);
2667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2672 *optsize = sizeof(struct sctp_rtoinfo);
2678 struct sctp_timeouts *stimo;
2680 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2681 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2684 stimo->stimo_init = stcb->asoc.timoinit;
2685 stimo->stimo_data = stcb->asoc.timodata;
2686 stimo->stimo_sack = stcb->asoc.timosack;
2687 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2688 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2689 stimo->stimo_cookie = stcb->asoc.timocookie;
2690 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2691 SCTP_TCB_UNLOCK(stcb);
2692 *optsize = sizeof(struct sctp_timeouts);
2694 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2699 case SCTP_ASSOCINFO:
2701 struct sctp_assocparams *sasoc;
2703 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2704 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2707 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2708 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2709 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2710 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2711 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2712 SCTP_TCB_UNLOCK(stcb);
2714 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2715 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2716 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2717 SCTP_INP_RLOCK(inp);
2718 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2719 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2720 sasoc->sasoc_number_peer_destinations = 0;
2721 sasoc->sasoc_peer_rwnd = 0;
2722 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2723 SCTP_INP_RUNLOCK(inp);
2725 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2730 *optsize = sizeof(struct sctp_assocparams);
2734 case SCTP_DEFAULT_SEND_PARAM:
2736 struct sctp_sndrcvinfo *s_info;
2738 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2739 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2742 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2743 SCTP_TCB_UNLOCK(stcb);
2745 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2746 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2747 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2748 SCTP_INP_RLOCK(inp);
2749 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2750 SCTP_INP_RUNLOCK(inp);
2752 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2757 *optsize = sizeof(struct sctp_sndrcvinfo);
2763 struct sctp_initmsg *sinit;
2765 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2766 SCTP_INP_RLOCK(inp);
2767 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2768 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2769 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2770 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2771 SCTP_INP_RUNLOCK(inp);
2772 *optsize = sizeof(struct sctp_initmsg);
2775 case SCTP_PRIMARY_ADDR:
2776 /* we allow a "get" operation on this */
2778 struct sctp_setprim *ssp;
2780 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2781 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2784 /* simply copy out the sockaddr_storage... */
2788 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
2789 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
2791 memcpy(&ssp->ssp_addr,
2792 &stcb->asoc.primary_destination->ro._l_addr,
2794 SCTP_TCB_UNLOCK(stcb);
2795 *optsize = sizeof(struct sctp_setprim);
2797 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2802 case SCTP_HMAC_IDENT:
2804 struct sctp_hmacalgo *shmac;
2805 sctp_hmaclist_t *hmaclist;
2809 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2811 SCTP_INP_RLOCK(inp);
2812 hmaclist = inp->sctp_ep.local_hmacs;
2813 if (hmaclist == NULL) {
2814 /* no HMACs to return */
2815 *optsize = sizeof(*shmac);
2816 SCTP_INP_RUNLOCK(inp);
2819 /* is there room for all of the hmac ids? */
2820 size = sizeof(*shmac) + (hmaclist->num_algo *
2821 sizeof(shmac->shmac_idents[0]));
2822 if ((size_t)(*optsize) < size) {
2823 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2825 SCTP_INP_RUNLOCK(inp);
2828 /* copy in the list */
2829 shmac->shmac_number_of_idents = hmaclist->num_algo;
2830 for (i = 0; i < hmaclist->num_algo; i++) {
2831 shmac->shmac_idents[i] = hmaclist->hmac[i];
2833 SCTP_INP_RUNLOCK(inp);
2837 case SCTP_AUTH_ACTIVE_KEY:
2839 struct sctp_authkeyid *scact;
2841 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2842 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2845 /* get the active key on the assoc */
2846 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2847 SCTP_TCB_UNLOCK(stcb);
2849 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2850 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2851 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2852 /* get the endpoint active key */
2853 SCTP_INP_RLOCK(inp);
2854 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2855 SCTP_INP_RUNLOCK(inp);
2857 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2862 *optsize = sizeof(struct sctp_authkeyid);
2866 case SCTP_LOCAL_AUTH_CHUNKS:
2868 struct sctp_authchunks *sac;
2869 sctp_auth_chklist_t *chklist = NULL;
2872 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2873 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2876 /* get off the assoc */
2877 chklist = stcb->asoc.local_auth_chunks;
2878 /* is there enough space? */
2879 size = sctp_auth_get_chklist_size(chklist);
2880 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2884 /* copy in the chunks */
2885 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2886 *optsize = sizeof(struct sctp_authchunks) + size;
2888 SCTP_TCB_UNLOCK(stcb);
2890 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2891 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2892 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2893 /* get off the endpoint */
2894 SCTP_INP_RLOCK(inp);
2895 chklist = inp->sctp_ep.local_auth_chunks;
2896 /* is there enough space? */
2897 size = sctp_auth_get_chklist_size(chklist);
2898 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2900 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2902 /* copy in the chunks */
2903 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2904 *optsize = sizeof(struct sctp_authchunks) + size;
2906 SCTP_INP_RUNLOCK(inp);
2908 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2914 case SCTP_PEER_AUTH_CHUNKS:
2916 struct sctp_authchunks *sac;
2917 sctp_auth_chklist_t *chklist = NULL;
2920 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2921 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2924 /* get off the assoc */
2925 chklist = stcb->asoc.peer_auth_chunks;
2926 /* is there enough space? */
2927 size = sctp_auth_get_chklist_size(chklist);
2928 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2932 /* copy in the chunks */
2933 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2934 *optsize = sizeof(struct sctp_authchunks) + size;
2936 SCTP_TCB_UNLOCK(stcb);
2938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2945 struct sctp_event *event;
2946 uint32_t event_type;
2948 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2949 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2951 switch (event->se_type) {
2952 case SCTP_ASSOC_CHANGE:
2953 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2955 case SCTP_PEER_ADDR_CHANGE:
2956 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
2958 case SCTP_REMOTE_ERROR:
2959 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
2961 case SCTP_SEND_FAILED:
2962 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
2964 case SCTP_SHUTDOWN_EVENT:
2965 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
2967 case SCTP_ADAPTATION_INDICATION:
2968 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
2970 case SCTP_PARTIAL_DELIVERY_EVENT:
2971 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
2973 case SCTP_AUTHENTICATION_EVENT:
2974 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
2976 case SCTP_STREAM_RESET_EVENT:
2977 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
2979 case SCTP_SENDER_DRY_EVENT:
2980 event_type = SCTP_PCB_FLAGS_DRYEVNT;
2982 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
2984 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
2989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2993 if (event_type > 0) {
2995 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
2996 SCTP_TCB_UNLOCK(stcb);
2998 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2999 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3000 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3001 SCTP_INP_RLOCK(inp);
3002 event->se_on = sctp_is_feature_on(inp, event_type);
3003 SCTP_INP_RUNLOCK(inp);
3005 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3011 *optsize = sizeof(struct sctp_event);
3015 case SCTP_RECVRCVINFO:
3019 if (*optsize < sizeof(int)) {
3020 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3023 SCTP_INP_RUNLOCK(inp);
3024 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3025 SCTP_INP_RUNLOCK(inp);
3028 /* return the option value */
3029 *(int *)optval = onoff;
3030 *optsize = sizeof(int);
3034 case SCTP_RECVNXTINFO:
3038 if (*optsize < sizeof(int)) {
3039 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3042 SCTP_INP_RUNLOCK(inp);
3043 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3044 SCTP_INP_RUNLOCK(inp);
3047 /* return the option value */
3048 *(int *)optval = onoff;
3049 *optsize = sizeof(int);
3053 case SCTP_DEFAULT_SNDINFO:
3055 struct sctp_sndinfo *info;
3057 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3058 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3061 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3062 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3063 info->snd_flags &= 0xfff0;
3064 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3065 info->snd_context = stcb->asoc.def_send.sinfo_context;
3066 SCTP_TCB_UNLOCK(stcb);
3068 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3069 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3070 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3071 SCTP_INP_RLOCK(inp);
3072 info->snd_sid = inp->def_send.sinfo_stream;
3073 info->snd_flags = inp->def_send.sinfo_flags;
3074 info->snd_flags &= 0xfff0;
3075 info->snd_ppid = inp->def_send.sinfo_ppid;
3076 info->snd_context = inp->def_send.sinfo_context;
3077 SCTP_INP_RUNLOCK(inp);
3079 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3084 *optsize = sizeof(struct sctp_sndinfo);
3088 case SCTP_DEFAULT_PRINFO:
3090 struct sctp_default_prinfo *info;
3092 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3093 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3096 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3097 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3098 SCTP_TCB_UNLOCK(stcb);
3100 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3101 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3102 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3103 SCTP_INP_RLOCK(inp);
3104 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3105 info->pr_value = inp->def_send.sinfo_timetolive;
3106 SCTP_INP_RUNLOCK(inp);
3108 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3113 *optsize = sizeof(struct sctp_default_prinfo);
3117 case SCTP_PEER_ADDR_THLDS:
3119 struct sctp_paddrthlds *thlds;
3120 struct sctp_nets *net;
3122 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3123 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3127 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
3130 * We increment here since
3131 * sctp_findassociation_ep_addr() wil do a
3132 * decrement if it finds the stcb as long as
3133 * the locked tcb (last argument) is NOT a
3136 SCTP_INP_INCR_REF(inp);
3137 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL);
3139 SCTP_INP_DECR_REF(inp);
3142 if (stcb && (net == NULL)) {
3143 struct sockaddr *sa;
3145 sa = (struct sockaddr *)&thlds->spt_address;
3147 if (sa->sa_family == AF_INET) {
3148 struct sockaddr_in *sin;
3150 sin = (struct sockaddr_in *)sa;
3151 if (sin->sin_addr.s_addr) {
3153 SCTP_TCB_UNLOCK(stcb);
3154 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3160 if (sa->sa_family == AF_INET6) {
3161 struct sockaddr_in6 *sin6;
3163 sin6 = (struct sockaddr_in6 *)sa;
3164 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3166 SCTP_TCB_UNLOCK(stcb);
3167 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3173 error = EAFNOSUPPORT;
3174 SCTP_TCB_UNLOCK(stcb);
3175 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3181 thlds->spt_pathmaxrxt = net->failure_threshold;
3182 thlds->spt_pathpfthld = net->pf_threshold;
3184 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3185 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3187 thlds->spt_assoc_id = sctp_get_associd(stcb);
3188 SCTP_TCB_UNLOCK(stcb);
3190 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3191 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3192 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3193 /* Use endpoint defaults */
3194 SCTP_INP_RLOCK(inp);
3195 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3196 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3197 SCTP_INP_RUNLOCK(inp);
3199 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3204 *optsize = sizeof(struct sctp_paddrthlds);
3209 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3210 error = ENOPROTOOPT;
3212 } /* end switch (sopt->sopt_name) */
3220 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3225 struct sctp_tcb *stcb = NULL;
3226 struct sctp_inpcb *inp = NULL;
3229 if (optval == NULL) {
3230 SCTP_PRINTF("optval is NULL\n");
3231 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3234 inp = (struct sctp_inpcb *)so->so_pcb;
3236 SCTP_PRINTF("inp is NULL?\n");
3237 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3240 vrf_id = inp->def_vrf_id;
3245 case SCTP_AUTOCLOSE:
3246 case SCTP_AUTO_ASCONF:
3247 case SCTP_EXPLICIT_EOR:
3248 case SCTP_DISABLE_FRAGMENTS:
3249 case SCTP_USE_EXT_RCVINFO:
3250 case SCTP_I_WANT_MAPPED_V4_ADDR:
3251 /* copy in the option value */
3252 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3257 case SCTP_DISABLE_FRAGMENTS:
3258 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3260 case SCTP_AUTO_ASCONF:
3262 * NOTE: we don't really support this flag
3264 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3265 /* only valid for bound all sockets */
3266 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3268 /* forbidden by admin */
3269 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3272 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3274 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3278 case SCTP_EXPLICIT_EOR:
3279 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3281 case SCTP_USE_EXT_RCVINFO:
3282 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3284 case SCTP_I_WANT_MAPPED_V4_ADDR:
3285 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3286 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3288 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3293 set_opt = SCTP_PCB_FLAGS_NODELAY;
3295 case SCTP_AUTOCLOSE:
3296 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3297 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3298 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3301 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3303 * The value is in ticks. Note this does not effect
3304 * old associations, only new ones.
3306 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3309 SCTP_INP_WLOCK(inp);
3311 sctp_feature_on(inp, set_opt);
3313 sctp_feature_off(inp, set_opt);
3315 SCTP_INP_WUNLOCK(inp);
3317 case SCTP_REUSE_PORT:
3319 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3320 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3321 /* Can't set it after we are bound */
3325 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3326 /* Can't do this for a 1-m socket */
3331 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3333 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3336 case SCTP_PARTIAL_DELIVERY_POINT:
3340 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3341 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3342 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3346 inp->partial_delivery_point = *value;
3349 case SCTP_FRAGMENT_INTERLEAVE:
3350 /* not yet until we re-write sctp_recvmsg() */
3354 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3355 if (*level == SCTP_FRAG_LEVEL_2) {
3356 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3357 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3358 } else if (*level == SCTP_FRAG_LEVEL_1) {
3359 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3360 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3361 } else if (*level == SCTP_FRAG_LEVEL_0) {
3362 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3363 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3366 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3371 case SCTP_CMT_ON_OFF:
3372 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3373 struct sctp_assoc_value *av;
3375 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3376 if (av->assoc_value > SCTP_CMT_MAX) {
3377 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3381 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3383 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3384 SCTP_TCB_UNLOCK(stcb);
3386 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3387 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3388 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3389 (av->assoc_id == SCTP_ALL_ASSOC)) {
3390 SCTP_INP_WLOCK(inp);
3391 inp->sctp_cmt_on_off = av->assoc_value;
3392 SCTP_INP_WUNLOCK(inp);
3394 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3395 (av->assoc_id == SCTP_ALL_ASSOC)) {
3396 SCTP_INP_RLOCK(inp);
3397 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3398 SCTP_TCB_LOCK(stcb);
3399 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3400 SCTP_TCB_UNLOCK(stcb);
3402 SCTP_INP_RUNLOCK(inp);
3406 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3407 error = ENOPROTOOPT;
3410 case SCTP_PLUGGABLE_CC:
3412 struct sctp_assoc_value *av;
3413 struct sctp_nets *net;
3415 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3416 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3417 (av->assoc_value != SCTP_CC_HSTCP) &&
3418 (av->assoc_value != SCTP_CC_HTCP) &&
3419 (av->assoc_value != SCTP_CC_RTCC)) {
3420 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3424 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3426 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3427 stcb->asoc.congestion_control_module = av->assoc_value;
3428 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3429 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3430 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3433 SCTP_TCB_UNLOCK(stcb);
3435 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3436 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3437 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3438 (av->assoc_id == SCTP_ALL_ASSOC)) {
3439 SCTP_INP_WLOCK(inp);
3440 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3441 SCTP_INP_WUNLOCK(inp);
3443 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3444 (av->assoc_id == SCTP_ALL_ASSOC)) {
3445 SCTP_INP_RLOCK(inp);
3446 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3447 SCTP_TCB_LOCK(stcb);
3448 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3449 stcb->asoc.congestion_control_module = av->assoc_value;
3450 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3451 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3452 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3455 SCTP_TCB_UNLOCK(stcb);
3457 SCTP_INP_RUNLOCK(inp);
3462 case SCTP_CC_OPTION:
3464 struct sctp_cc_option *cc_opt;
3466 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3467 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3469 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3470 SCTP_INP_RLOCK(inp);
3471 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3472 SCTP_TCB_LOCK(stcb);
3473 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3474 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3476 SCTP_TCB_UNLOCK(stcb);
3478 SCTP_INP_RUNLOCK(inp);
3483 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3486 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3489 SCTP_TCB_UNLOCK(stcb);
3493 case SCTP_PLUGGABLE_SS:
3495 struct sctp_assoc_value *av;
3497 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3498 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3499 (av->assoc_value != SCTP_SS_DEFAULT) &&
3500 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3501 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3502 (av->assoc_value != SCTP_SS_PRIORITY) &&
3503 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3504 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3505 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3509 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3511 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3512 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3513 stcb->asoc.stream_scheduling_module = av->assoc_value;
3514 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3515 SCTP_TCB_UNLOCK(stcb);
3517 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3518 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3519 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3520 (av->assoc_id == SCTP_ALL_ASSOC)) {
3521 SCTP_INP_WLOCK(inp);
3522 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
3523 SCTP_INP_WUNLOCK(inp);
3525 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3526 (av->assoc_id == SCTP_ALL_ASSOC)) {
3527 SCTP_INP_RLOCK(inp);
3528 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3529 SCTP_TCB_LOCK(stcb);
3530 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3531 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3532 stcb->asoc.stream_scheduling_module = av->assoc_value;
3533 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3534 SCTP_TCB_UNLOCK(stcb);
3536 SCTP_INP_RUNLOCK(inp);
3543 struct sctp_stream_value *av;
3545 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
3546 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3548 if (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
3549 av->stream_value) < 0) {
3550 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3553 SCTP_TCB_UNLOCK(stcb);
3555 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
3556 SCTP_INP_RLOCK(inp);
3557 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3558 SCTP_TCB_LOCK(stcb);
3559 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
3561 &stcb->asoc.strmout[av->stream_id],
3563 SCTP_TCB_UNLOCK(stcb);
3565 SCTP_INP_RUNLOCK(inp);
3569 * Can't set stream value without
3572 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3578 case SCTP_CLR_STAT_LOG:
3579 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3584 struct sctp_assoc_value *av;
3586 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3587 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3590 stcb->asoc.context = av->assoc_value;
3591 SCTP_TCB_UNLOCK(stcb);
3593 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3594 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3595 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3596 (av->assoc_id == SCTP_ALL_ASSOC)) {
3597 SCTP_INP_WLOCK(inp);
3598 inp->sctp_context = av->assoc_value;
3599 SCTP_INP_WUNLOCK(inp);
3601 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3602 (av->assoc_id == SCTP_ALL_ASSOC)) {
3603 SCTP_INP_RLOCK(inp);
3604 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3605 SCTP_TCB_LOCK(stcb);
3606 stcb->asoc.context = av->assoc_value;
3607 SCTP_TCB_UNLOCK(stcb);
3609 SCTP_INP_RUNLOCK(inp);
3616 uint32_t *default_vrfid;
3618 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
3619 if (*default_vrfid > SCTP_MAX_VRF_ID) {
3620 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3624 inp->def_vrf_id = *default_vrfid;
3627 case SCTP_DEL_VRF_ID:
3629 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3633 case SCTP_ADD_VRF_ID:
3635 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3639 case SCTP_DELAYED_SACK:
3641 struct sctp_sack_info *sack;
3643 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
3644 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
3645 if (sack->sack_delay) {
3646 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
3647 sack->sack_delay = SCTP_MAX_SACK_DELAY;
3648 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3649 sack->sack_delay = TICKS_TO_MSEC(1);
3653 if (sack->sack_delay) {
3654 stcb->asoc.delayed_ack = sack->sack_delay;
3656 if (sack->sack_freq) {
3657 stcb->asoc.sack_freq = sack->sack_freq;
3659 SCTP_TCB_UNLOCK(stcb);
3661 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3662 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3663 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
3664 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3665 SCTP_INP_WLOCK(inp);
3666 if (sack->sack_delay) {
3667 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
3669 if (sack->sack_freq) {
3670 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
3672 SCTP_INP_WUNLOCK(inp);
3674 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
3675 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3676 SCTP_INP_RLOCK(inp);
3677 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3678 SCTP_TCB_LOCK(stcb);
3679 if (sack->sack_delay) {
3680 stcb->asoc.delayed_ack = sack->sack_delay;
3682 if (sack->sack_freq) {
3683 stcb->asoc.sack_freq = sack->sack_freq;
3685 SCTP_TCB_UNLOCK(stcb);
3687 SCTP_INP_RUNLOCK(inp);
3692 case SCTP_AUTH_CHUNK:
3694 struct sctp_authchunk *sauth;
3696 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
3698 SCTP_INP_WLOCK(inp);
3699 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
3700 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3703 SCTP_INP_WUNLOCK(inp);
3708 struct sctp_authkey *sca;
3709 struct sctp_keyhead *shared_keys;
3710 sctp_sharedkey_t *shared_key;
3711 sctp_key_t *key = NULL;
3714 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
3715 if (sca->sca_keylength == 0) {
3716 size = optsize - sizeof(struct sctp_authkey);
3718 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
3719 size = sca->sca_keylength;
3721 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3726 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
3729 shared_keys = &stcb->asoc.shared_keys;
3730 /* clear the cached keys for this key id */
3731 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3733 * create the new shared key and
3737 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3739 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3741 SCTP_TCB_UNLOCK(stcb);
3745 shared_key = sctp_alloc_sharedkey();
3746 if (shared_key == NULL) {
3748 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3750 SCTP_TCB_UNLOCK(stcb);
3753 shared_key->key = key;
3754 shared_key->keyid = sca->sca_keynumber;
3755 error = sctp_insert_sharedkey(shared_keys, shared_key);
3756 SCTP_TCB_UNLOCK(stcb);
3758 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3759 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3760 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
3761 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3762 SCTP_INP_WLOCK(inp);
3763 shared_keys = &inp->sctp_ep.shared_keys;
3765 * clear the cached keys on all
3766 * assocs for this key id
3768 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3770 * create the new shared key and
3774 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3778 SCTP_INP_WUNLOCK(inp);
3782 shared_key = sctp_alloc_sharedkey();
3783 if (shared_key == NULL) {
3785 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3787 SCTP_INP_WUNLOCK(inp);
3790 shared_key->key = key;
3791 shared_key->keyid = sca->sca_keynumber;
3792 error = sctp_insert_sharedkey(shared_keys, shared_key);
3793 SCTP_INP_WUNLOCK(inp);
3795 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
3796 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3797 SCTP_INP_RLOCK(inp);
3798 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3799 SCTP_TCB_LOCK(stcb);
3800 shared_keys = &stcb->asoc.shared_keys;
3802 * clear the cached keys for
3805 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3807 * create the new shared key
3808 * and insert/replace it
3811 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3813 SCTP_TCB_UNLOCK(stcb);
3817 shared_key = sctp_alloc_sharedkey();
3818 if (shared_key == NULL) {
3820 SCTP_TCB_UNLOCK(stcb);
3823 shared_key->key = key;
3824 shared_key->keyid = sca->sca_keynumber;
3825 error = sctp_insert_sharedkey(shared_keys, shared_key);
3826 SCTP_TCB_UNLOCK(stcb);
3828 SCTP_INP_RUNLOCK(inp);
3833 case SCTP_HMAC_IDENT:
3835 struct sctp_hmacalgo *shmac;
3836 sctp_hmaclist_t *hmaclist;
3841 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
3842 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
3843 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3847 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
3848 if (hmaclist == NULL) {
3849 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3853 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
3854 hmacid = shmac->shmac_idents[i];
3855 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
3856 /* invalid HMACs were found */ ;
3857 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3859 sctp_free_hmaclist(hmaclist);
3860 goto sctp_set_hmac_done;
3864 for (i = 0; i < hmaclist->num_algo; i++) {
3865 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
3866 /* already in list */
3871 sctp_free_hmaclist(hmaclist);
3872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3876 /* set it on the endpoint */
3877 SCTP_INP_WLOCK(inp);
3878 if (inp->sctp_ep.local_hmacs)
3879 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
3880 inp->sctp_ep.local_hmacs = hmaclist;
3881 SCTP_INP_WUNLOCK(inp);
3885 case SCTP_AUTH_ACTIVE_KEY:
3887 struct sctp_authkeyid *scact;
3889 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
3890 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
3892 /* set the active key on the right place */
3894 /* set the active key on the assoc */
3895 if (sctp_auth_setactivekey(stcb,
3896 scact->scact_keynumber)) {
3897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
3898 SCTP_FROM_SCTP_USRREQ,
3902 SCTP_TCB_UNLOCK(stcb);
3904 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3905 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3906 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
3907 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
3908 SCTP_INP_WLOCK(inp);
3909 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
3910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3913 SCTP_INP_WUNLOCK(inp);
3915 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
3916 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
3917 SCTP_INP_RLOCK(inp);
3918 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3919 SCTP_TCB_LOCK(stcb);
3920 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
3921 SCTP_TCB_UNLOCK(stcb);
3923 SCTP_INP_RUNLOCK(inp);
3928 case SCTP_AUTH_DELETE_KEY:
3930 struct sctp_authkeyid *scdel;
3932 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
3933 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
3935 /* delete the key from the right place */
3937 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
3938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3941 SCTP_TCB_UNLOCK(stcb);
3943 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3944 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3945 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
3946 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
3947 SCTP_INP_WLOCK(inp);
3948 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
3949 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3952 SCTP_INP_WUNLOCK(inp);
3954 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
3955 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
3956 SCTP_INP_RLOCK(inp);
3957 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3958 SCTP_TCB_LOCK(stcb);
3959 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
3960 SCTP_TCB_UNLOCK(stcb);
3962 SCTP_INP_RUNLOCK(inp);
3967 case SCTP_AUTH_DEACTIVATE_KEY:
3969 struct sctp_authkeyid *keyid;
3971 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
3972 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
3974 /* deactivate the key from the right place */
3976 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
3977 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3980 SCTP_TCB_UNLOCK(stcb);
3982 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3983 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3984 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
3985 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
3986 SCTP_INP_WLOCK(inp);
3987 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
3988 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3991 SCTP_INP_WUNLOCK(inp);
3993 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
3994 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
3995 SCTP_INP_RLOCK(inp);
3996 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3997 SCTP_TCB_LOCK(stcb);
3998 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
3999 SCTP_TCB_UNLOCK(stcb);
4001 SCTP_INP_RUNLOCK(inp);
4007 case SCTP_RESET_STREAMS:
4009 struct sctp_stream_reset *strrst;
4010 uint8_t send_in = 0, send_tsn = 0, send_out = 0,
4012 uint16_t addstrmcnt = 0;
4015 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_stream_reset, optsize);
4016 SCTP_FIND_STCB(inp, stcb, strrst->strrst_assoc_id);
4019 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4023 if (stcb->asoc.peer_supports_strreset == 0) {
4025 * Peer does not support it, we return
4026 * protocol not supported since this is true
4027 * for this feature and this peer, not the
4028 * socket request in general.
4030 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPROTONOSUPPORT);
4031 error = EPROTONOSUPPORT;
4032 SCTP_TCB_UNLOCK(stcb);
4035 if (stcb->asoc.stream_reset_outstanding) {
4036 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4038 SCTP_TCB_UNLOCK(stcb);
4041 if (strrst->strrst_flags == SCTP_RESET_LOCAL_RECV) {
4043 } else if (strrst->strrst_flags == SCTP_RESET_LOCAL_SEND) {
4045 } else if (strrst->strrst_flags == SCTP_RESET_BOTH) {
4048 } else if (strrst->strrst_flags == SCTP_RESET_TSN) {
4050 } else if (strrst->strrst_flags == SCTP_RESET_ADD_STREAMS) {
4054 /* We can't do that and add streams */
4058 if (stcb->asoc.stream_reset_outstanding) {
4063 /* We allocate here */
4064 addstrmcnt = strrst->strrst_num_streams;
4065 if ((int)(addstrmcnt + stcb->asoc.streamoutcnt) > 0xffff) {
4066 /* You can't have more than 64k */
4070 if ((stcb->asoc.strm_realoutsize - stcb->asoc.streamoutcnt) < addstrmcnt) {
4071 /* Need to allocate more */
4072 struct sctp_stream_out *oldstream;
4073 struct sctp_stream_queue_pending *sp,
4076 oldstream = stcb->asoc.strmout;
4078 SCTP_MALLOC(stcb->asoc.strmout, struct sctp_stream_out *,
4079 ((stcb->asoc.streamoutcnt + addstrmcnt) * sizeof(struct sctp_stream_out)),
4081 if (stcb->asoc.strmout == NULL) {
4082 stcb->asoc.strmout = oldstream;
4087 * Ok now we proceed with copying
4088 * the old out stuff and
4089 * initializing the new stuff.
4091 SCTP_TCB_SEND_LOCK(stcb);
4092 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 0, 1);
4093 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4094 TAILQ_INIT(&stcb->asoc.strmout[i].outqueue);
4095 stcb->asoc.strmout[i].next_sequence_sent = oldstream[i].next_sequence_sent;
4096 stcb->asoc.strmout[i].last_msg_incomplete = oldstream[i].last_msg_incomplete;
4097 stcb->asoc.strmout[i].stream_no = i;
4098 stcb->asoc.ss_functions.sctp_ss_init_stream(&stcb->asoc.strmout[i], &oldstream[i]);
4100 * now anything on those
4103 TAILQ_FOREACH_SAFE(sp, &oldstream[i].outqueue, next, nsp) {
4104 TAILQ_REMOVE(&oldstream[i].outqueue, sp, next);
4105 TAILQ_INSERT_TAIL(&stcb->asoc.strmout[i].outqueue, sp, next);
4108 * Now move assoc pointers
4111 if (stcb->asoc.last_out_stream == &oldstream[i]) {
4112 stcb->asoc.last_out_stream = &stcb->asoc.strmout[i];
4114 if (stcb->asoc.locked_on_sending == &oldstream[i]) {
4115 stcb->asoc.locked_on_sending = &stcb->asoc.strmout[i];
4118 /* now the new streams */
4119 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4120 for (i = stcb->asoc.streamoutcnt; i < (stcb->asoc.streamoutcnt + addstrmcnt); i++) {
4121 stcb->asoc.strmout[i].next_sequence_sent = 0x0;
4122 TAILQ_INIT(&stcb->asoc.strmout[i].outqueue);
4123 stcb->asoc.strmout[i].stream_no = i;
4124 stcb->asoc.strmout[i].last_msg_incomplete = 0;
4125 stcb->asoc.ss_functions.sctp_ss_init_stream(&stcb->asoc.strmout[i], NULL);
4127 stcb->asoc.strm_realoutsize = stcb->asoc.streamoutcnt + addstrmcnt;
4128 SCTP_FREE(oldstream, SCTP_M_STRMO);
4130 SCTP_TCB_SEND_UNLOCK(stcb);
4133 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4135 SCTP_TCB_UNLOCK(stcb);
4138 for (i = 0; i < strrst->strrst_num_streams; i++) {
4141 (strrst->strrst_list[i] > stcb->asoc.streamincnt)) {
4142 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4147 (strrst->strrst_list[i] > stcb->asoc.streamoutcnt)) {
4148 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4156 SCTP_TCB_UNLOCK(stcb);
4159 error = sctp_send_str_reset_req(stcb, strrst->strrst_num_streams,
4160 strrst->strrst_list,
4161 send_out, (stcb->asoc.str_reset_seq_in - 3),
4162 send_in, send_tsn, addstream, addstrmcnt);
4164 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4165 SCTP_TCB_UNLOCK(stcb);
4168 case SCTP_CONNECT_X:
4169 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4170 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4174 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4176 case SCTP_CONNECT_X_DELAYED:
4177 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4178 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4182 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4184 case SCTP_CONNECT_X_COMPLETE:
4186 struct sockaddr *sa;
4187 struct sctp_nets *net;
4189 /* FIXME MT: check correct? */
4190 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4193 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4194 SCTP_INP_RLOCK(inp);
4195 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4197 SCTP_TCB_LOCK(stcb);
4198 net = sctp_findnet(stcb, sa);
4200 SCTP_INP_RUNLOCK(inp);
4203 * We increment here since
4204 * sctp_findassociation_ep_addr() wil do a
4205 * decrement if it finds the stcb as long as
4206 * the locked tcb (last argument) is NOT a
4209 SCTP_INP_INCR_REF(inp);
4210 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4212 SCTP_INP_DECR_REF(inp);
4217 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4221 if (stcb->asoc.delayed_connection == 1) {
4222 stcb->asoc.delayed_connection = 0;
4223 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4224 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4225 stcb->asoc.primary_destination,
4226 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4227 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4230 * already expired or did not use delayed
4233 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4236 SCTP_TCB_UNLOCK(stcb);
4239 case SCTP_MAX_BURST:
4241 struct sctp_assoc_value *av;
4243 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4244 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4247 stcb->asoc.max_burst = av->assoc_value;
4248 SCTP_TCB_UNLOCK(stcb);
4250 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4251 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4252 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4253 (av->assoc_id == SCTP_ALL_ASSOC)) {
4254 SCTP_INP_WLOCK(inp);
4255 inp->sctp_ep.max_burst = av->assoc_value;
4256 SCTP_INP_WUNLOCK(inp);
4258 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4259 (av->assoc_id == SCTP_ALL_ASSOC)) {
4260 SCTP_INP_RLOCK(inp);
4261 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4262 SCTP_TCB_LOCK(stcb);
4263 stcb->asoc.max_burst = av->assoc_value;
4264 SCTP_TCB_UNLOCK(stcb);
4266 SCTP_INP_RUNLOCK(inp);
4273 struct sctp_assoc_value *av;
4276 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4277 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4279 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4280 ovh = SCTP_MED_OVERHEAD;
4282 ovh = SCTP_MED_V4_OVERHEAD;
4285 if (av->assoc_value) {
4286 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4288 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4290 SCTP_TCB_UNLOCK(stcb);
4292 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4293 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4294 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4295 SCTP_INP_WLOCK(inp);
4297 * FIXME MT: I think this is not in
4298 * tune with the API ID
4300 if (av->assoc_value) {
4301 inp->sctp_frag_point = (av->assoc_value + ovh);
4303 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4305 SCTP_INP_WUNLOCK(inp);
4307 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4315 struct sctp_event_subscribe *events;
4317 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4319 SCTP_INP_WLOCK(inp);
4320 if (events->sctp_data_io_event) {
4321 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4323 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4326 if (events->sctp_association_event) {
4327 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4329 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4332 if (events->sctp_address_event) {
4333 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4335 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4338 if (events->sctp_send_failure_event) {
4339 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4341 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4344 if (events->sctp_peer_error_event) {
4345 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4347 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4350 if (events->sctp_shutdown_event) {
4351 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4353 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4356 if (events->sctp_partial_delivery_event) {
4357 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4359 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4362 if (events->sctp_adaptation_layer_event) {
4363 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4365 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4368 if (events->sctp_authentication_event) {
4369 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4371 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4374 if (events->sctp_sender_dry_event) {
4375 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4377 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4380 if (events->sctp_stream_reset_event) {
4381 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4383 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4385 SCTP_INP_WUNLOCK(inp);
4387 SCTP_INP_RLOCK(inp);
4388 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4389 SCTP_TCB_LOCK(stcb);
4390 if (events->sctp_association_event) {
4391 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4393 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4395 if (events->sctp_address_event) {
4396 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4398 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4400 if (events->sctp_send_failure_event) {
4401 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4403 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4405 if (events->sctp_peer_error_event) {
4406 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4408 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4410 if (events->sctp_shutdown_event) {
4411 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4413 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4415 if (events->sctp_partial_delivery_event) {
4416 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4418 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4420 if (events->sctp_adaptation_layer_event) {
4421 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4423 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4425 if (events->sctp_authentication_event) {
4426 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4428 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4430 if (events->sctp_sender_dry_event) {
4431 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4433 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4435 if (events->sctp_stream_reset_event) {
4436 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4438 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4440 SCTP_TCB_UNLOCK(stcb);
4443 * Send up the sender dry event only for 1-to-1
4446 if (events->sctp_sender_dry_event) {
4447 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4448 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4449 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4451 SCTP_TCB_LOCK(stcb);
4452 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4453 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4454 (stcb->asoc.stream_queue_cnt == 0)) {
4455 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4457 SCTP_TCB_UNLOCK(stcb);
4461 SCTP_INP_RUNLOCK(inp);
4464 case SCTP_ADAPTATION_LAYER:
4466 struct sctp_setadaptation *adap_bits;
4468 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
4469 SCTP_INP_WLOCK(inp);
4470 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
4471 SCTP_INP_WUNLOCK(inp);
4475 case SCTP_SET_INITIAL_DBG_SEQ:
4479 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
4480 SCTP_INP_WLOCK(inp);
4481 inp->sctp_ep.initial_sequence_debug = *vvv;
4482 SCTP_INP_WUNLOCK(inp);
4486 case SCTP_DEFAULT_SEND_PARAM:
4488 struct sctp_sndrcvinfo *s_info;
4490 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
4491 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
4494 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4495 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4497 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4500 SCTP_TCB_UNLOCK(stcb);
4502 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4503 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4504 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
4505 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4506 SCTP_INP_WLOCK(inp);
4507 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
4508 SCTP_INP_WUNLOCK(inp);
4510 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
4511 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4512 SCTP_INP_RLOCK(inp);
4513 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4514 SCTP_TCB_LOCK(stcb);
4515 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4516 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4518 SCTP_TCB_UNLOCK(stcb);
4520 SCTP_INP_RUNLOCK(inp);
4525 case SCTP_PEER_ADDR_PARAMS:
4526 /* Applies to the specific association */
4528 struct sctp_paddrparams *paddrp;
4529 struct sctp_nets *net;
4531 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
4532 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
4535 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
4538 * We increment here since
4539 * sctp_findassociation_ep_addr() wil do a
4540 * decrement if it finds the stcb as long as
4541 * the locked tcb (last argument) is NOT a
4544 SCTP_INP_INCR_REF(inp);
4545 stcb = sctp_findassociation_ep_addr(&inp,
4546 (struct sockaddr *)&paddrp->spp_address,
4549 SCTP_INP_DECR_REF(inp);
4552 if (stcb && (net == NULL)) {
4553 struct sockaddr *sa;
4555 sa = (struct sockaddr *)&paddrp->spp_address;
4557 if (sa->sa_family == AF_INET) {
4559 struct sockaddr_in *sin;
4561 sin = (struct sockaddr_in *)sa;
4562 if (sin->sin_addr.s_addr) {
4563 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4564 SCTP_TCB_UNLOCK(stcb);
4571 if (sa->sa_family == AF_INET6) {
4572 struct sockaddr_in6 *sin6;
4574 sin6 = (struct sockaddr_in6 *)sa;
4575 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
4576 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4577 SCTP_TCB_UNLOCK(stcb);
4584 error = EAFNOSUPPORT;
4585 SCTP_TCB_UNLOCK(stcb);
4586 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4591 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
4593 SCTP_TCB_UNLOCK(stcb);
4594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4597 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
4599 SCTP_TCB_UNLOCK(stcb);
4600 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4604 /************************TCB SPECIFIC SET ******************/
4606 * do we change the timer for HB, we run
4611 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4612 ovh = SCTP_MED_OVERHEAD;
4614 ovh = SCTP_MED_V4_OVERHEAD;
4617 /* network sets ? */
4619 /************************NET SPECIFIC SET ******************/
4620 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4621 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
4622 !(net->dest_state & SCTP_ADDR_NOHB)) {
4623 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4624 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4626 net->dest_state |= SCTP_ADDR_NOHB;
4628 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4629 if (paddrp->spp_hbinterval) {
4630 net->heart_beat_delay = paddrp->spp_hbinterval;
4631 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4632 net->heart_beat_delay = 0;
4634 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4635 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4636 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4637 net->dest_state &= ~SCTP_ADDR_NOHB;
4639 if (paddrp->spp_flags & SPP_HB_DEMAND) {
4641 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4642 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
4643 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4645 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4646 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4647 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4648 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4650 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4651 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4652 net->mtu = paddrp->spp_pathmtu + ovh;
4653 if (net->mtu < stcb->asoc.smallest_mtu) {
4654 sctp_pathmtu_adjustment(stcb, net->mtu);
4658 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4659 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4660 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4662 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4664 if (paddrp->spp_pathmaxrxt) {
4665 if (net->dest_state & SCTP_ADDR_PF) {
4666 if (net->error_count > paddrp->spp_pathmaxrxt) {
4667 net->dest_state &= ~SCTP_ADDR_PF;
4670 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4671 (net->error_count > net->pf_threshold)) {
4672 net->dest_state |= SCTP_ADDR_PF;
4673 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4674 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4675 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4678 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4679 if (net->error_count > paddrp->spp_pathmaxrxt) {
4680 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4681 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4684 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4685 net->dest_state |= SCTP_ADDR_REACHABLE;
4686 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4689 net->failure_threshold = paddrp->spp_pathmaxrxt;
4691 if (paddrp->spp_flags & SPP_DSCP) {
4692 net->dscp = paddrp->spp_dscp & 0xfc;
4696 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4697 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4698 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4699 net->flowlabel |= 0x80000000;
4704 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
4705 if (paddrp->spp_pathmaxrxt) {
4706 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
4707 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4708 if (net->dest_state & SCTP_ADDR_PF) {
4709 if (net->error_count > paddrp->spp_pathmaxrxt) {
4710 net->dest_state &= ~SCTP_ADDR_PF;
4713 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4714 (net->error_count > net->pf_threshold)) {
4715 net->dest_state |= SCTP_ADDR_PF;
4716 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4717 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4718 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4721 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4722 if (net->error_count > paddrp->spp_pathmaxrxt) {
4723 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4724 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4727 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4728 net->dest_state |= SCTP_ADDR_REACHABLE;
4729 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4732 net->failure_threshold = paddrp->spp_pathmaxrxt;
4735 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4736 if (paddrp->spp_hbinterval) {
4737 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
4738 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4739 stcb->asoc.heart_beat_delay = 0;
4741 /* Turn back on the timer */
4742 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4743 if (paddrp->spp_hbinterval) {
4744 net->heart_beat_delay = paddrp->spp_hbinterval;
4745 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4746 net->heart_beat_delay = 0;
4748 if (net->dest_state & SCTP_ADDR_NOHB) {
4749 net->dest_state &= ~SCTP_ADDR_NOHB;
4751 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4752 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4753 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4755 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4757 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4758 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4759 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
4760 net->dest_state |= SCTP_ADDR_NOHB;
4761 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
4762 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4766 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4768 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4769 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4770 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4771 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4772 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4774 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4775 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4776 net->mtu = paddrp->spp_pathmtu + ovh;
4777 if (net->mtu < stcb->asoc.smallest_mtu) {
4778 sctp_pathmtu_adjustment(stcb, net->mtu);
4782 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4784 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4785 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4786 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4787 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4789 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4791 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4793 if (paddrp->spp_flags & SPP_DSCP) {
4794 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4795 net->dscp = paddrp->spp_dscp & 0xfc;
4798 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
4799 stcb->asoc.default_dscp |= 0x01;
4802 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4803 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4804 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4805 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4806 net->flowlabel |= 0x80000000;
4809 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4810 stcb->asoc.default_flowlabel |= 0x80000000;
4814 SCTP_TCB_UNLOCK(stcb);
4816 /************************NO TCB, SET TO default stuff ******************/
4817 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4818 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4819 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
4820 SCTP_INP_WLOCK(inp);
4822 * For the TOS/FLOWLABEL stuff you
4823 * set it with the options on the
4826 if (paddrp->spp_pathmaxrxt) {
4827 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
4829 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
4830 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4831 else if (paddrp->spp_hbinterval) {
4832 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
4833 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
4834 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4836 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4837 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4838 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4839 } else if (paddrp->spp_hbinterval) {
4840 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4842 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4843 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
4844 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4846 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4847 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4848 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
4849 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4851 if (paddrp->spp_flags & SPP_DSCP) {
4852 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
4853 inp->sctp_ep.default_dscp |= 0x01;
4856 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4857 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4858 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4859 inp->sctp_ep.default_flowlabel |= 0x80000000;
4863 SCTP_INP_WUNLOCK(inp);
4865 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4873 struct sctp_rtoinfo *srto;
4874 uint32_t new_init, new_min, new_max;
4876 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
4877 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
4880 if (srto->srto_initial)
4881 new_init = srto->srto_initial;
4883 new_init = stcb->asoc.initial_rto;
4885 new_max = srto->srto_max;
4887 new_max = stcb->asoc.maxrto;
4889 new_min = srto->srto_min;
4891 new_min = stcb->asoc.minrto;
4892 if ((new_min <= new_init) && (new_init <= new_max)) {
4893 stcb->asoc.initial_rto = new_init;
4894 stcb->asoc.maxrto = new_max;
4895 stcb->asoc.minrto = new_min;
4897 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4900 SCTP_TCB_UNLOCK(stcb);
4902 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4903 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4904 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
4905 SCTP_INP_WLOCK(inp);
4906 if (srto->srto_initial)
4907 new_init = srto->srto_initial;
4909 new_init = inp->sctp_ep.initial_rto;
4911 new_max = srto->srto_max;
4913 new_max = inp->sctp_ep.sctp_maxrto;
4915 new_min = srto->srto_min;
4917 new_min = inp->sctp_ep.sctp_minrto;
4918 if ((new_min <= new_init) && (new_init <= new_max)) {
4919 inp->sctp_ep.initial_rto = new_init;
4920 inp->sctp_ep.sctp_maxrto = new_max;
4921 inp->sctp_ep.sctp_minrto = new_min;
4923 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4926 SCTP_INP_WUNLOCK(inp);
4928 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4934 case SCTP_ASSOCINFO:
4936 struct sctp_assocparams *sasoc;
4938 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
4939 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
4940 if (sasoc->sasoc_cookie_life) {
4941 /* boundary check the cookie life */
4942 if (sasoc->sasoc_cookie_life < 1000)
4943 sasoc->sasoc_cookie_life = 1000;
4944 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
4945 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
4949 if (sasoc->sasoc_asocmaxrxt)
4950 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
4951 if (sasoc->sasoc_cookie_life) {
4952 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
4954 SCTP_TCB_UNLOCK(stcb);
4956 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4957 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4958 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
4959 SCTP_INP_WLOCK(inp);
4960 if (sasoc->sasoc_asocmaxrxt)
4961 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
4962 if (sasoc->sasoc_cookie_life) {
4963 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
4965 SCTP_INP_WUNLOCK(inp);
4967 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4975 struct sctp_initmsg *sinit;
4977 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
4978 SCTP_INP_WLOCK(inp);
4979 if (sinit->sinit_num_ostreams)
4980 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
4982 if (sinit->sinit_max_instreams)
4983 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
4985 if (sinit->sinit_max_attempts)
4986 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
4988 if (sinit->sinit_max_init_timeo)
4989 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
4990 SCTP_INP_WUNLOCK(inp);
4993 case SCTP_PRIMARY_ADDR:
4995 struct sctp_setprim *spa;
4996 struct sctp_nets *net;
4998 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
4999 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5003 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
5006 * We increment here since
5007 * sctp_findassociation_ep_addr() wil do a
5008 * decrement if it finds the stcb as long as
5009 * the locked tcb (last argument) is NOT a
5012 SCTP_INP_INCR_REF(inp);
5013 stcb = sctp_findassociation_ep_addr(&inp,
5014 (struct sockaddr *)&spa->ssp_addr,
5017 SCTP_INP_DECR_REF(inp);
5021 if ((stcb) && (net)) {
5022 if ((net != stcb->asoc.primary_destination) &&
5023 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
5024 /* Ok we need to set it */
5025 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5026 if ((stcb->asoc.alternate) &&
5027 (!(net->dest_state & SCTP_ADDR_PF)) &&
5028 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5029 sctp_free_remote_addr(stcb->asoc.alternate);
5030 stcb->asoc.alternate = NULL;
5035 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5039 SCTP_TCB_UNLOCK(stcb);
5043 case SCTP_SET_DYNAMIC_PRIMARY:
5045 union sctp_sockstore *ss;
5047 error = priv_check(curthread,
5048 PRIV_NETINET_RESERVEDPORT);
5052 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5053 /* SUPER USER CHECK? */
5054 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5057 case SCTP_SET_PEER_PRIMARY_ADDR:
5059 struct sctp_setpeerprim *sspp;
5061 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5062 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5064 struct sctp_ifa *ifa;
5066 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
5067 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5069 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5073 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5075 * Must validate the ifa found is in
5078 struct sctp_laddr *laddr;
5081 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5082 if (laddr->ifa == NULL) {
5083 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5087 if (laddr->ifa == ifa) {
5093 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5098 if (sctp_set_primary_ip_address_sa(stcb,
5099 (struct sockaddr *)&sspp->sspp_addr) != 0) {
5100 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5104 SCTP_TCB_UNLOCK(stcb);
5106 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5111 case SCTP_BINDX_ADD_ADDR:
5113 struct sctp_getaddresses *addrs;
5117 td = (struct thread *)p;
5118 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5121 if (addrs->addr->sa_family == AF_INET) {
5122 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
5124 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5128 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5129 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5135 if (addrs->addr->sa_family == AF_INET6) {
5136 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
5138 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5142 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5143 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5144 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5150 error = EAFNOSUPPORT;
5153 sctp_bindx_add_address(so, inp, addrs->addr,
5154 addrs->sget_assoc_id, vrf_id,
5158 case SCTP_BINDX_REM_ADDR:
5160 struct sctp_getaddresses *addrs;
5164 td = (struct thread *)p;
5166 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5168 if (addrs->addr->sa_family == AF_INET) {
5169 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
5171 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5175 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5176 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5182 if (addrs->addr->sa_family == AF_INET6) {
5183 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
5185 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5190 (error = prison_local_ip6(td->td_ucred,
5191 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5192 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5193 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5199 error = EAFNOSUPPORT;
5202 sctp_bindx_delete_address(inp, addrs->addr,
5203 addrs->sget_assoc_id, vrf_id,
5209 struct sctp_event *event;
5210 uint32_t event_type;
5212 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5213 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5214 switch (event->se_type) {
5215 case SCTP_ASSOC_CHANGE:
5216 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5218 case SCTP_PEER_ADDR_CHANGE:
5219 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5221 case SCTP_REMOTE_ERROR:
5222 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5224 case SCTP_SEND_FAILED:
5225 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5227 case SCTP_SHUTDOWN_EVENT:
5228 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5230 case SCTP_ADAPTATION_INDICATION:
5231 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5233 case SCTP_PARTIAL_DELIVERY_EVENT:
5234 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5236 case SCTP_AUTHENTICATION_EVENT:
5237 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5239 case SCTP_STREAM_RESET_EVENT:
5240 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5242 case SCTP_SENDER_DRY_EVENT:
5243 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5245 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5247 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5252 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5256 if (event_type > 0) {
5259 sctp_stcb_feature_on(inp, stcb, event_type);
5260 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5261 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5262 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5263 (stcb->asoc.stream_queue_cnt == 0)) {
5264 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5268 sctp_stcb_feature_off(inp, stcb, event_type);
5270 SCTP_TCB_UNLOCK(stcb);
5273 * We don't want to send up a storm
5274 * of events, so return an error for
5277 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5278 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5279 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5280 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5281 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5282 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5286 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5287 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5288 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5289 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5290 SCTP_INP_WLOCK(inp);
5292 sctp_feature_on(inp, event_type);
5294 sctp_feature_off(inp, event_type);
5296 SCTP_INP_WUNLOCK(inp);
5298 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5299 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5300 SCTP_INP_RLOCK(inp);
5301 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5302 SCTP_TCB_LOCK(stcb);
5304 sctp_stcb_feature_on(inp, stcb, event_type);
5306 sctp_stcb_feature_off(inp, stcb, event_type);
5308 SCTP_TCB_UNLOCK(stcb);
5310 SCTP_INP_RUNLOCK(inp);
5316 case SCTP_RECVRCVINFO:
5320 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5321 SCTP_INP_WLOCK(inp);
5323 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5325 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5327 SCTP_INP_WUNLOCK(inp);
5330 case SCTP_RECVNXTINFO:
5334 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5335 SCTP_INP_WLOCK(inp);
5337 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5339 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5341 SCTP_INP_WUNLOCK(inp);
5344 case SCTP_DEFAULT_SNDINFO:
5346 struct sctp_sndinfo *info;
5349 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5350 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5353 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5354 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5355 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5356 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5357 stcb->asoc.def_send.sinfo_flags |= policy;
5358 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5359 stcb->asoc.def_send.sinfo_context = info->snd_context;
5361 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5364 SCTP_TCB_UNLOCK(stcb);
5366 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5367 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5368 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
5369 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5370 SCTP_INP_WLOCK(inp);
5371 inp->def_send.sinfo_stream = info->snd_sid;
5372 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
5373 inp->def_send.sinfo_flags = info->snd_flags;
5374 inp->def_send.sinfo_flags |= policy;
5375 inp->def_send.sinfo_ppid = info->snd_ppid;
5376 inp->def_send.sinfo_context = info->snd_context;
5377 SCTP_INP_WUNLOCK(inp);
5379 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
5380 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5381 SCTP_INP_RLOCK(inp);
5382 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5383 SCTP_TCB_LOCK(stcb);
5384 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5385 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5386 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5387 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5388 stcb->asoc.def_send.sinfo_flags |= policy;
5389 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5390 stcb->asoc.def_send.sinfo_context = info->snd_context;
5392 SCTP_TCB_UNLOCK(stcb);
5394 SCTP_INP_RUNLOCK(inp);
5399 case SCTP_DEFAULT_PRINFO:
5401 struct sctp_default_prinfo *info;
5403 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
5404 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
5406 if (PR_SCTP_INVALID_POLICY(info->pr_policy)) {
5407 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5412 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5413 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5414 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5415 SCTP_TCB_UNLOCK(stcb);
5417 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5418 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5419 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
5420 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5421 SCTP_INP_WLOCK(inp);
5422 inp->def_send.sinfo_flags &= 0xfff0;
5423 inp->def_send.sinfo_flags |= info->pr_policy;
5424 inp->def_send.sinfo_timetolive = info->pr_value;
5425 SCTP_INP_WUNLOCK(inp);
5427 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
5428 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5429 SCTP_INP_RLOCK(inp);
5430 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5431 SCTP_TCB_LOCK(stcb);
5432 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5433 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5434 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5435 SCTP_TCB_UNLOCK(stcb);
5437 SCTP_INP_RUNLOCK(inp);
5442 case SCTP_PEER_ADDR_THLDS:
5443 /* Applies to the specific association */
5445 struct sctp_paddrthlds *thlds;
5446 struct sctp_nets *net;
5448 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
5449 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
5452 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_assoc_id);
5455 * We increment here since
5456 * sctp_findassociation_ep_addr() wil do a
5457 * decrement if it finds the stcb as long as
5458 * the locked tcb (last argument) is NOT a
5461 SCTP_INP_INCR_REF(inp);
5462 stcb = sctp_findassociation_ep_addr(&inp,
5463 (struct sockaddr *)&thlds->spt_assoc_id,
5466 SCTP_INP_DECR_REF(inp);
5469 if (stcb && (net == NULL)) {
5470 struct sockaddr *sa;
5472 sa = (struct sockaddr *)&thlds->spt_assoc_id;
5474 if (sa->sa_family == AF_INET) {
5476 struct sockaddr_in *sin;
5478 sin = (struct sockaddr_in *)sa;
5479 if (sin->sin_addr.s_addr) {
5480 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5481 SCTP_TCB_UNLOCK(stcb);
5488 if (sa->sa_family == AF_INET6) {
5489 struct sockaddr_in6 *sin6;
5491 sin6 = (struct sockaddr_in6 *)sa;
5492 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5493 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5494 SCTP_TCB_UNLOCK(stcb);
5501 error = EAFNOSUPPORT;
5502 SCTP_TCB_UNLOCK(stcb);
5503 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5509 if (net->dest_state & SCTP_ADDR_PF) {
5510 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5511 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5512 net->dest_state &= ~SCTP_ADDR_PF;
5515 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5516 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5517 net->dest_state |= SCTP_ADDR_PF;
5518 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5519 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5520 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5523 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5524 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5525 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5526 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5529 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5530 net->dest_state |= SCTP_ADDR_REACHABLE;
5531 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5534 net->failure_threshold = thlds->spt_pathmaxrxt;
5535 net->pf_threshold = thlds->spt_pathpfthld;
5537 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5538 if (net->dest_state & SCTP_ADDR_PF) {
5539 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5540 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5541 net->dest_state &= ~SCTP_ADDR_PF;
5544 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5545 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5546 net->dest_state |= SCTP_ADDR_PF;
5547 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5548 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5549 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5552 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5553 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5554 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5555 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5558 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5559 net->dest_state |= SCTP_ADDR_REACHABLE;
5560 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5563 net->failure_threshold = thlds->spt_pathmaxrxt;
5564 net->pf_threshold = thlds->spt_pathpfthld;
5566 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
5567 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
5570 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5571 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5572 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
5573 SCTP_INP_WLOCK(inp);
5574 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
5575 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
5576 SCTP_INP_WUNLOCK(inp);
5578 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5585 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
5586 error = ENOPROTOOPT;
5588 } /* end switch (opt) */
5593 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
5595 void *optval = NULL;
5597 struct sctp_inpcb *inp;
5601 inp = (struct sctp_inpcb *)so->so_pcb;
5603 /* I made the same as TCP since we are not setup? */
5604 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5605 return (ECONNRESET);
5607 if (sopt->sopt_level != IPPROTO_SCTP) {
5608 /* wrong proto level... send back up to IP */
5610 if (INP_CHECK_SOCKAF(so, AF_INET6))
5611 error = ip6_ctloutput(so, sopt);
5613 #if defined(INET) && defined (INET6)
5617 error = ip_ctloutput(so, sopt);
5621 optsize = sopt->sopt_valsize;
5623 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
5624 if (optval == NULL) {
5625 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
5628 error = sooptcopyin(sopt, optval, optsize, optsize);
5630 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5634 p = (void *)sopt->sopt_td;
5635 if (sopt->sopt_dir == SOPT_SET) {
5636 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
5637 } else if (sopt->sopt_dir == SOPT_GET) {
5638 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
5640 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5643 if ((error == 0) && (optval != NULL)) {
5644 error = sooptcopyout(sopt, optval, optsize);
5645 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5646 } else if (optval != NULL) {
5647 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5655 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
5658 int create_lock_on = 0;
5660 struct sctp_inpcb *inp;
5661 struct sctp_tcb *stcb = NULL;
5663 inp = (struct sctp_inpcb *)so->so_pcb;
5665 /* I made the same as TCP since we are not setup? */
5666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5667 return (ECONNRESET);
5670 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5673 switch (addr->sa_family) {
5677 struct sockaddr_in6 *sin6p;
5679 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
5680 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5683 sin6p = (struct sockaddr_in6 *)addr;
5684 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
5685 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5694 struct sockaddr_in *sinp;
5696 if (addr->sa_len != sizeof(struct sockaddr_in)) {
5697 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5700 sinp = (struct sockaddr_in *)addr;
5701 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
5702 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5709 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
5710 return (EAFNOSUPPORT);
5712 SCTP_INP_INCR_REF(inp);
5713 SCTP_ASOC_CREATE_LOCK(inp);
5717 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
5718 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
5719 /* Should I really unlock ? */
5720 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
5725 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
5726 (addr->sa_family == AF_INET6)) {
5727 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5732 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
5733 SCTP_PCB_FLAGS_UNBOUND) {
5734 /* Bind a ephemeral port */
5735 error = sctp_inpcb_bind(so, NULL, NULL, p);
5740 /* Now do we connect? */
5741 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
5742 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
5743 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5747 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5748 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
5749 /* We are already connected AND the TCP model */
5750 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
5754 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
5755 SCTP_INP_RLOCK(inp);
5756 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5757 SCTP_INP_RUNLOCK(inp);
5760 * We increment here since sctp_findassociation_ep_addr()
5761 * will do a decrement if it finds the stcb as long as the
5762 * locked tcb (last argument) is NOT a TCB.. aka NULL.
5764 SCTP_INP_INCR_REF(inp);
5765 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
5767 SCTP_INP_DECR_REF(inp);
5769 SCTP_TCB_UNLOCK(stcb);
5773 /* Already have or am bring up an association */
5774 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
5778 vrf_id = inp->def_vrf_id;
5779 /* We are GOOD to go */
5780 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
5782 /* Gak! no memory */
5785 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
5786 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
5787 /* Set the connected flag so we can queue data */
5790 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
5791 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
5793 /* initialize authentication parameters for the assoc */
5794 sctp_initialize_auth_params(inp, stcb);
5796 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
5797 SCTP_TCB_UNLOCK(stcb);
5799 if (create_lock_on) {
5800 SCTP_ASOC_CREATE_UNLOCK(inp);
5802 SCTP_INP_DECR_REF(inp);
5809 sctp_listen(struct socket *so, int backlog, struct thread *p)
5812 * Note this module depends on the protocol processing being called
5813 * AFTER any socket level flags and backlog are applied to the
5814 * socket. The traditional way that the socket flags are applied is
5815 * AFTER protocol processing. We have made a change to the
5816 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
5817 * place if the socket API for SCTP is to work properly.
5821 struct sctp_inpcb *inp;
5823 inp = (struct sctp_inpcb *)so->so_pcb;
5825 /* I made the same as TCP since we are not setup? */
5826 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5827 return (ECONNRESET);
5829 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
5830 /* See if we have a listener */
5831 struct sctp_inpcb *tinp;
5832 union sctp_sockstore store, *sp;
5835 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5837 struct sctp_laddr *laddr;
5839 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5840 memcpy(&store, &laddr->ifa->address, sizeof(store));
5841 switch (sp->sa.sa_family) {
5844 sp->sin.sin_port = inp->sctp_lport;
5849 sp->sin6.sin6_port = inp->sctp_lport;
5855 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
5856 if (tinp && (tinp != inp) &&
5857 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
5858 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
5859 (tinp->sctp_socket->so_qlimit)) {
5861 * we have a listener already and
5864 SCTP_INP_DECR_REF(tinp);
5865 return (EADDRINUSE);
5867 SCTP_INP_DECR_REF(tinp);
5871 /* Setup a local addr bound all */
5872 memset(&store, 0, sizeof(store));
5873 switch (sp->sa.sa_family) {
5876 store.sin.sin_port = inp->sctp_lport;
5881 sp->sin6.sin6_port = inp->sctp_lport;
5888 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5889 store.sa.sa_family = AF_INET6;
5890 store.sa.sa_len = sizeof(struct sockaddr_in6);
5894 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
5895 store.sa.sa_family = AF_INET;
5896 store.sa.sa_len = sizeof(struct sockaddr_in);
5899 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
5900 if (tinp && (tinp != inp) &&
5901 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
5902 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
5903 (tinp->sctp_socket->so_qlimit)) {
5905 * we have a listener already and its not
5908 SCTP_INP_DECR_REF(tinp);
5909 return (EADDRINUSE);
5911 SCTP_INP_DECR_REF(inp);
5915 SCTP_INP_RLOCK(inp);
5916 #ifdef SCTP_LOCK_LOGGING
5917 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
5918 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
5922 error = solisten_proto_check(so);
5925 SCTP_INP_RUNLOCK(inp);
5928 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
5929 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5931 * The unlucky case - We are in the tcp pool with this guy.
5932 * - Someone else is in the main inp slot. - We must move
5933 * this guy (the listener) to the main slot - We must then
5934 * move the guy that was listener to the TCP Pool.
5936 if (sctp_swap_inpcb_for_listen(inp)) {
5940 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5941 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
5942 /* We are already connected AND the TCP model */
5944 SCTP_INP_RUNLOCK(inp);
5946 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
5947 return (EADDRINUSE);
5949 SCTP_INP_RUNLOCK(inp);
5950 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
5951 /* We must do a bind. */
5953 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
5954 /* bind error, probably perm */
5959 /* It appears for 7.0 and on, we must always call this. */
5960 solisten_proto(so, backlog);
5961 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
5962 /* remove the ACCEPTCONN flag for one-to-many sockets */
5963 so->so_options &= ~SO_ACCEPTCONN;
5966 /* turning off listen */
5967 so->so_options &= ~SO_ACCEPTCONN;
5973 static int sctp_defered_wakeup_cnt = 0;
5976 sctp_accept(struct socket *so, struct sockaddr **addr)
5978 struct sctp_tcb *stcb;
5979 struct sctp_inpcb *inp;
5980 union sctp_sockstore store;
5986 inp = (struct sctp_inpcb *)so->so_pcb;
5989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5990 return (ECONNRESET);
5992 SCTP_INP_RLOCK(inp);
5993 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
5994 SCTP_INP_RUNLOCK(inp);
5995 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
5996 return (EOPNOTSUPP);
5998 if (so->so_state & SS_ISDISCONNECTED) {
5999 SCTP_INP_RUNLOCK(inp);
6000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
6001 return (ECONNABORTED);
6003 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6005 SCTP_INP_RUNLOCK(inp);
6006 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6007 return (ECONNRESET);
6009 SCTP_TCB_LOCK(stcb);
6010 SCTP_INP_RUNLOCK(inp);
6011 store = stcb->asoc.primary_destination->ro._l_addr;
6012 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
6013 SCTP_TCB_UNLOCK(stcb);
6014 switch (store.sa.sa_family) {
6018 struct sockaddr_in *sin;
6020 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6023 sin->sin_family = AF_INET;
6024 sin->sin_len = sizeof(*sin);
6025 sin->sin_port = ((struct sockaddr_in *)&store)->sin_port;
6026 sin->sin_addr = ((struct sockaddr_in *)&store)->sin_addr;
6027 *addr = (struct sockaddr *)sin;
6034 struct sockaddr_in6 *sin6;
6036 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
6039 sin6->sin6_family = AF_INET6;
6040 sin6->sin6_len = sizeof(*sin6);
6041 sin6->sin6_port = ((struct sockaddr_in6 *)&store)->sin6_port;
6043 sin6->sin6_addr = ((struct sockaddr_in6 *)&store)->sin6_addr;
6044 if ((error = sa6_recoverscope(sin6)) != 0) {
6045 SCTP_FREE_SONAME(sin6);
6048 *addr = (struct sockaddr *)sin6;
6056 /* Wake any delayed sleep action */
6057 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
6058 SCTP_INP_WLOCK(inp);
6059 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
6060 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
6061 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
6062 SCTP_INP_WUNLOCK(inp);
6063 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
6064 if (sowriteable(inp->sctp_socket)) {
6065 sowwakeup_locked(inp->sctp_socket);
6067 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
6069 SCTP_INP_WLOCK(inp);
6071 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
6072 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
6073 SCTP_INP_WUNLOCK(inp);
6074 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
6075 if (soreadable(inp->sctp_socket)) {
6076 sctp_defered_wakeup_cnt++;
6077 sorwakeup_locked(inp->sctp_socket);
6079 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
6081 SCTP_INP_WLOCK(inp);
6083 SCTP_INP_WUNLOCK(inp);
6085 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
6086 SCTP_TCB_LOCK(stcb);
6087 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
6094 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
6096 struct sockaddr_in *sin;
6098 struct sctp_inpcb *inp;
6099 struct sctp_ifa *sctp_ifa;
6102 * Do the malloc first in case it blocks.
6104 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6107 sin->sin_family = AF_INET;
6108 sin->sin_len = sizeof(*sin);
6109 inp = (struct sctp_inpcb *)so->so_pcb;
6111 SCTP_FREE_SONAME(sin);
6112 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6115 SCTP_INP_RLOCK(inp);
6116 sin->sin_port = inp->sctp_lport;
6117 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
6118 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6119 struct sctp_tcb *stcb;
6120 struct sockaddr_in *sin_a;
6121 struct sctp_nets *net;
6124 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6130 SCTP_TCB_LOCK(stcb);
6131 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6132 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6134 /* this will make coverity happy */
6137 if (sin_a->sin_family == AF_INET) {
6142 if ((!fnd) || (sin_a == NULL)) {
6144 SCTP_TCB_UNLOCK(stcb);
6147 vrf_id = inp->def_vrf_id;
6148 sctp_ifa = sctp_source_address_selection(inp,
6150 (sctp_route_t *) & net->ro,
6153 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
6154 sctp_free_ifa(sctp_ifa);
6156 SCTP_TCB_UNLOCK(stcb);
6158 /* For the bound all case you get back 0 */
6160 sin->sin_addr.s_addr = 0;
6164 /* Take the first IPv4 address in the list */
6165 struct sctp_laddr *laddr;
6168 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6169 if (laddr->ifa->address.sa.sa_family == AF_INET) {
6170 struct sockaddr_in *sin_a;
6172 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
6173 sin->sin_addr = sin_a->sin_addr;
6179 SCTP_FREE_SONAME(sin);
6180 SCTP_INP_RUNLOCK(inp);
6181 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6185 SCTP_INP_RUNLOCK(inp);
6186 (*addr) = (struct sockaddr *)sin;
6191 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
6193 struct sockaddr_in *sin = (struct sockaddr_in *)*addr;
6195 struct sockaddr_in *sin_a;
6196 struct sctp_inpcb *inp;
6197 struct sctp_tcb *stcb;
6198 struct sctp_nets *net;
6200 /* Do the malloc first in case it blocks. */
6201 inp = (struct sctp_inpcb *)so->so_pcb;
6202 if ((inp == NULL) ||
6203 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
6204 /* UDP type and listeners will drop out here */
6205 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
6208 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6211 sin->sin_family = AF_INET;
6212 sin->sin_len = sizeof(*sin);
6214 /* We must recapture incase we blocked */
6215 inp = (struct sctp_inpcb *)so->so_pcb;
6217 SCTP_FREE_SONAME(sin);
6218 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6221 SCTP_INP_RLOCK(inp);
6222 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6224 SCTP_TCB_LOCK(stcb);
6226 SCTP_INP_RUNLOCK(inp);
6228 SCTP_FREE_SONAME(sin);
6229 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6233 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6234 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6235 if (sin_a->sin_family == AF_INET) {
6237 sin->sin_port = stcb->rport;
6238 sin->sin_addr = sin_a->sin_addr;
6242 SCTP_TCB_UNLOCK(stcb);
6244 /* No IPv4 address */
6245 SCTP_FREE_SONAME(sin);
6246 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6249 (*addr) = (struct sockaddr *)sin;
6254 struct pr_usrreqs sctp_usrreqs = {
6255 .pru_abort = sctp_abort,
6256 .pru_accept = sctp_accept,
6257 .pru_attach = sctp_attach,
6258 .pru_bind = sctp_bind,
6259 .pru_connect = sctp_connect,
6260 .pru_control = in_control,
6261 .pru_close = sctp_close,
6262 .pru_detach = sctp_close,
6263 .pru_sopoll = sopoll_generic,
6264 .pru_flush = sctp_flush,
6265 .pru_disconnect = sctp_disconnect,
6266 .pru_listen = sctp_listen,
6267 .pru_peeraddr = sctp_peeraddr,
6268 .pru_send = sctp_sendm,
6269 .pru_shutdown = sctp_shutdown,
6270 .pru_sockaddr = sctp_ingetaddr,
6271 .pru_sosend = sctp_sosend,
6272 .pru_soreceive = sctp_soreceive