2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2011, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2011, by Michael Tuexen. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 /* $KAME: sctp_usrreq.c,v 1.48 2005/03/07 23:26:08 itojun Exp $ */
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
37 #include <netinet/sctp_os.h>
39 #include <netinet/sctp_pcb.h>
40 #include <netinet/sctp_header.h>
41 #include <netinet/sctp_var.h>
44 #include <netinet/sctp_sysctl.h>
45 #include <netinet/sctp_output.h>
46 #include <netinet/sctp_uio.h>
47 #include <netinet/sctp_asconf.h>
48 #include <netinet/sctputil.h>
49 #include <netinet/sctp_indata.h>
50 #include <netinet/sctp_timer.h>
51 #include <netinet/sctp_auth.h>
52 #include <netinet/sctp_bsd_addr.h>
53 #include <netinet/udp.h>
57 extern struct sctp_cc_functions sctp_cc_functions[];
58 extern struct sctp_ss_functions sctp_ss_functions[];
65 /* Initialize and modify the sysctled variables */
67 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
68 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
70 * Allow a user to take no more than 1/2 the number of clusters or
71 * the SB_MAX whichever is smaller for the send window.
73 sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
74 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
75 (((uint32_t) nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
77 * Now for the recv window, should we take the same amount? or
78 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
79 * now I will just copy.
81 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
83 SCTP_BASE_VAR(first_time) = 0;
84 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
86 #if defined(SCTP_PACKET_LOGGING)
87 SCTP_BASE_VAR(packet_log_writers) = 0;
88 SCTP_BASE_VAR(packet_log_end) = 0;
89 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
104 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
106 struct sctp_tmit_chunk *chk;
109 /* Adjust that too */
110 stcb->asoc.smallest_mtu = nxtsz;
111 /* now off to subtract IP_DF flag if needed */
112 overhead = IP_HDR_SIZE;
113 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
114 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
116 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
117 if ((chk->send_size + overhead) > nxtsz) {
118 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
121 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
122 if ((chk->send_size + overhead) > nxtsz) {
124 * For this guy we also mark for immediate resend
125 * since we sent to big of chunk
127 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
128 if (chk->sent < SCTP_DATAGRAM_RESEND) {
129 sctp_flight_size_decrease(chk);
130 sctp_total_flight_decrease(stcb, chk);
132 if (chk->sent != SCTP_DATAGRAM_RESEND) {
133 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
135 chk->sent = SCTP_DATAGRAM_RESEND;
136 chk->rec.data.doing_fast_retransmit = 0;
137 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
138 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
139 chk->whoTo->flight_size,
141 (uintptr_t) chk->whoTo,
142 chk->rec.data.TSN_seq);
144 /* Clear any time so NO RTT is being done */
152 sctp_notify_mbuf(struct sctp_inpcb *inp,
153 struct sctp_tcb *stcb,
154 struct sctp_nets *net,
159 int totsz, tmr_stopped = 0;
163 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
164 (ip == NULL) || (sh == NULL)) {
166 SCTP_TCB_UNLOCK(stcb);
170 /* First job is to verify the vtag matches what I would send */
171 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
172 SCTP_TCB_UNLOCK(stcb);
175 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
177 if (icmph->icmp_type != ICMP_UNREACH) {
178 /* We only care about unreachable */
179 SCTP_TCB_UNLOCK(stcb);
182 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
183 /* not a unreachable message due to frag. */
184 SCTP_TCB_UNLOCK(stcb);
189 nxtsz = ntohs(icmph->icmp_nextmtu);
192 * old type router that does not tell us what the next size
193 * mtu is. Rats we will have to guess (in a educated fashion
196 nxtsz = sctp_get_prev_mtu(totsz);
198 /* Stop any PMTU timer */
199 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
201 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
202 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
204 /* Adjust destination size limit */
205 if (net->mtu > nxtsz) {
208 net->mtu -= sizeof(struct udphdr);
211 /* now what about the ep? */
212 if (stcb->asoc.smallest_mtu > nxtsz) {
213 sctp_pathmtu_adjustment(stcb, nxtsz);
216 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
218 SCTP_TCB_UNLOCK(stcb);
224 sctp_notify(struct sctp_inpcb *inp,
228 struct sctp_tcb *stcb,
229 struct sctp_nets *net)
231 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
240 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
241 (sh == NULL) || (to == NULL)) {
243 SCTP_TCB_UNLOCK(stcb);
246 /* First job is to verify the vtag matches what I would send */
247 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
248 SCTP_TCB_UNLOCK(stcb);
251 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
253 if (icmph->icmp_type != ICMP_UNREACH) {
254 /* We only care about unreachable */
255 SCTP_TCB_UNLOCK(stcb);
258 if ((icmph->icmp_code == ICMP_UNREACH_NET) ||
259 (icmph->icmp_code == ICMP_UNREACH_HOST) ||
260 (icmph->icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
261 (icmph->icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
262 (icmph->icmp_code == ICMP_UNREACH_ISOLATED) ||
263 (icmph->icmp_code == ICMP_UNREACH_NET_PROHIB) ||
264 (icmph->icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
265 (icmph->icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
268 * Hmm reachablity problems we must examine closely. If its
269 * not reachable, we may have lost a network. Or if there is
270 * NO protocol at the other end named SCTP. well we consider
273 if (net->dest_state & SCTP_ADDR_REACHABLE) {
274 /* Ok that destination is NOT reachable */
275 net->dest_state &= ~SCTP_ADDR_REACHABLE;
276 net->dest_state &= ~SCTP_ADDR_PF;
277 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
278 stcb, SCTP_FAILED_THRESHOLD,
279 (void *)net, SCTP_SO_NOT_LOCKED);
281 SCTP_TCB_UNLOCK(stcb);
282 } else if ((icmph->icmp_code == ICMP_UNREACH_PROTOCOL) ||
283 (icmph->icmp_code == ICMP_UNREACH_PORT)) {
285 * Here the peer is either playing tricks on us, including
286 * an address that belongs to someone who does not support
287 * SCTP OR was a userland implementation that shutdown and
288 * now is dead. In either case treat it like a OOTB abort
291 reason = SCTP_PEER_FAULTY;
292 sctp_abort_notification(stcb, reason, SCTP_SO_NOT_LOCKED);
293 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
294 so = SCTP_INP_SO(inp);
295 atomic_add_int(&stcb->asoc.refcnt, 1);
296 SCTP_TCB_UNLOCK(stcb);
297 SCTP_SOCKET_LOCK(so, 1);
299 atomic_subtract_int(&stcb->asoc.refcnt, 1);
301 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
302 #if defined (__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
303 SCTP_SOCKET_UNLOCK(so, 1);
304 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
306 /* no need to unlock here, since the TCB is gone */
308 SCTP_TCB_UNLOCK(stcb);
314 sctp_ctlinput(cmd, sa, vip)
323 /* FIX, for non-bsd is this right? */
324 vrf_id = SCTP_DEFAULT_VRFID;
325 if (sa->sa_family != AF_INET ||
326 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
329 if (PRC_IS_REDIRECT(cmd)) {
331 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
335 struct sctp_inpcb *inp = NULL;
336 struct sctp_tcb *stcb = NULL;
337 struct sctp_nets *net = NULL;
338 struct sockaddr_in to, from;
340 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
341 bzero(&to, sizeof(to));
342 bzero(&from, sizeof(from));
343 from.sin_family = to.sin_family = AF_INET;
344 from.sin_len = to.sin_len = sizeof(to);
345 from.sin_port = sh->src_port;
346 from.sin_addr = ip->ip_src;
347 to.sin_port = sh->dest_port;
348 to.sin_addr = ip->ip_dst;
351 * 'to' holds the dest of the packet that failed to be sent.
352 * 'from' holds our local endpoint address. Thus we reverse
353 * the to and the from in the lookup.
355 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&from,
356 (struct sockaddr *)&to,
357 &inp, &net, 1, vrf_id);
358 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
359 if (cmd != PRC_MSGSIZE) {
360 sctp_notify(inp, ip, sh,
361 (struct sockaddr *)&to, stcb,
364 /* handle possible ICMP size messages */
365 sctp_notify_mbuf(inp, stcb, net, ip, sh);
368 if ((stcb == NULL) && (inp != NULL)) {
369 /* reduce ref-count */
371 SCTP_INP_DECR_REF(inp);
372 SCTP_INP_WUNLOCK(inp);
375 SCTP_TCB_UNLOCK(stcb);
385 sctp_getcred(SYSCTL_HANDLER_ARGS)
388 struct sockaddr_in addrs[2];
389 struct sctp_inpcb *inp;
390 struct sctp_nets *net;
391 struct sctp_tcb *stcb;
395 /* FIX, for non-bsd is this right? */
396 vrf_id = SCTP_DEFAULT_VRFID;
398 error = priv_check(req->td, PRIV_NETINET_GETCRED);
403 error = SYSCTL_IN(req, addrs, sizeof(addrs));
407 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[0]),
409 &inp, &net, 1, vrf_id);
410 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
411 if ((inp != NULL) && (stcb == NULL)) {
412 /* reduce ref-count */
414 SCTP_INP_DECR_REF(inp);
417 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
421 SCTP_TCB_UNLOCK(stcb);
423 * We use the write lock here, only since in the error leg we need
424 * it. If we used RLOCK, then we would have to
425 * wlock/decr/unlock/rlock. Which in theory could create a hole.
426 * Better to use higher wlock.
430 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
432 SCTP_INP_WUNLOCK(inp);
435 cru2x(inp->sctp_socket->so_cred, &xuc);
436 SCTP_INP_WUNLOCK(inp);
437 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
442 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
443 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
448 sctp_abort(struct socket *so)
450 struct sctp_inpcb *inp;
453 inp = (struct sctp_inpcb *)so->so_pcb;
458 flags = inp->sctp_flags;
459 #ifdef SCTP_LOG_CLOSING
460 sctp_log_closing(inp, NULL, 17);
462 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
463 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
464 #ifdef SCTP_LOG_CLOSING
465 sctp_log_closing(inp, NULL, 16);
467 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
468 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
470 SCTP_SB_CLEAR(so->so_snd);
472 * same for the rcv ones, they are only here for the
475 SCTP_SB_CLEAR(so->so_rcv);
477 /* Now null out the reference, we are completely detached. */
481 flags = inp->sctp_flags;
482 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
483 goto sctp_must_try_again;
490 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
492 struct sctp_inpcb *inp;
493 struct inpcb *ip_inp;
495 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
502 inp = (struct sctp_inpcb *)so->so_pcb;
504 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
507 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
508 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
513 error = sctp_inpcb_alloc(so, vrf_id);
517 inp = (struct sctp_inpcb *)so->so_pcb;
519 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
520 ip_inp = &inp->ip_inp.inp;
521 ip_inp->inp_vflag |= INP_IPV4;
522 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
524 error = ipsec_init_policy(so, &ip_inp->inp_sp);
525 #ifdef SCTP_LOG_CLOSING
526 sctp_log_closing(inp, NULL, 17);
530 flags = inp->sctp_flags;
531 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
532 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
533 #ifdef SCTP_LOG_CLOSING
534 sctp_log_closing(inp, NULL, 15);
536 SCTP_INP_WUNLOCK(inp);
537 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
538 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
540 flags = inp->sctp_flags;
541 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
544 SCTP_INP_WUNLOCK(inp);
550 SCTP_INP_WUNLOCK(inp);
555 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
557 struct sctp_inpcb *inp = NULL;
561 if (addr && addr->sa_family != AF_INET) {
562 /* must be a v4 address! */
563 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
567 if (addr && (addr->sa_len != sizeof(struct sockaddr_in))) {
568 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
571 inp = (struct sctp_inpcb *)so->so_pcb;
573 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
576 error = sctp_inpcb_bind(so, addr, NULL, p);
582 sctp_close(struct socket *so)
584 struct sctp_inpcb *inp;
587 inp = (struct sctp_inpcb *)so->so_pcb;
592 * Inform all the lower layer assoc that we are done.
595 flags = inp->sctp_flags;
596 #ifdef SCTP_LOG_CLOSING
597 sctp_log_closing(inp, NULL, 17);
599 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
600 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
601 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
602 (so->so_rcv.sb_cc > 0)) {
603 #ifdef SCTP_LOG_CLOSING
604 sctp_log_closing(inp, NULL, 13);
606 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
607 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
609 #ifdef SCTP_LOG_CLOSING
610 sctp_log_closing(inp, NULL, 14);
612 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
613 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
616 * The socket is now detached, no matter what the state of
617 * the SCTP association.
620 SCTP_SB_CLEAR(so->so_snd);
622 * same for the rcv ones, they are only here for the
625 SCTP_SB_CLEAR(so->so_rcv);
627 /* Now null out the reference, we are completely detached. */
631 flags = inp->sctp_flags;
632 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
633 goto sctp_must_try_again;
641 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
642 struct mbuf *control, struct thread *p);
646 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
647 struct mbuf *control, struct thread *p)
649 struct sctp_inpcb *inp;
652 inp = (struct sctp_inpcb *)so->so_pcb;
655 sctp_m_freem(control);
658 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
662 /* Got to have an to address if we are NOT a connected socket */
663 if ((addr == NULL) &&
664 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
665 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
667 } else if (addr == NULL) {
668 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
669 error = EDESTADDRREQ;
672 sctp_m_freem(control);
678 if (addr->sa_family != AF_INET) {
679 /* must be a v4 address! */
680 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
683 sctp_m_freem(control);
686 error = EDESTADDRREQ;
691 /* now what about control */
694 SCTP_PRINTF("huh? control set?\n");
695 sctp_m_freem(inp->control);
698 inp->control = control;
702 SCTP_BUF_NEXT(inp->pkt_last) = m;
705 inp->pkt_last = inp->pkt = m;
708 /* FreeBSD uses a flag passed */
709 ((flags & PRUS_MORETOCOME) == 0)
712 * note with the current version this code will only be used
713 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
714 * re-defining sosend to use the sctp_sosend. One can
715 * optionally switch back to this code (by changing back the
716 * definitions) but this is not advisable. This code is used
717 * by FreeBSD when sending a file with sendfile() though.
721 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
731 sctp_disconnect(struct socket *so)
733 struct sctp_inpcb *inp;
735 inp = (struct sctp_inpcb *)so->so_pcb;
737 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
741 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
742 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
743 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
745 SCTP_INP_RUNLOCK(inp);
748 struct sctp_association *asoc;
749 struct sctp_tcb *stcb;
751 stcb = LIST_FIRST(&inp->sctp_asoc_list);
753 SCTP_INP_RUNLOCK(inp);
754 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
759 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
760 /* We are about to be freed, out of here */
761 SCTP_TCB_UNLOCK(stcb);
762 SCTP_INP_RUNLOCK(inp);
765 if (((so->so_options & SO_LINGER) &&
766 (so->so_linger == 0)) ||
767 (so->so_rcv.sb_cc > 0)) {
768 if (SCTP_GET_STATE(asoc) !=
769 SCTP_STATE_COOKIE_WAIT) {
770 /* Left with Data unread */
773 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_DONTWAIT, 1, MT_DATA);
779 struct sctp_paramhdr *ph;
781 ph = mtod(err, struct sctp_paramhdr *);
782 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
783 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
784 ph->param_length = htons(SCTP_BUF_LEN(err));
786 #if defined(SCTP_PANIC_ON_ABORT)
787 panic("disconnect does an abort");
789 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
790 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
792 SCTP_INP_RUNLOCK(inp);
793 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
794 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
795 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
797 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
798 /* No unlock tcb assoc is gone */
801 if (TAILQ_EMPTY(&asoc->send_queue) &&
802 TAILQ_EMPTY(&asoc->sent_queue) &&
803 (asoc->stream_queue_cnt == 0)) {
804 /* there is nothing queued to send, so done */
805 if (asoc->locked_on_sending) {
808 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
809 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
810 /* only send SHUTDOWN 1st time thru */
811 struct sctp_nets *netp;
813 if (stcb->asoc.alternate) {
814 netp = stcb->asoc.alternate;
816 netp = stcb->asoc.primary_destination;
818 sctp_stop_timers_for_shutdown(stcb);
819 sctp_send_shutdown(stcb, netp);
820 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
821 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
822 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
823 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
825 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
826 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
827 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
828 stcb->sctp_ep, stcb, netp);
829 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
830 stcb->sctp_ep, stcb, netp);
835 * we still got (or just got) data to send,
836 * so set SHUTDOWN_PENDING
839 * XXX sockets draft says that SCTP_EOF
840 * should be sent with no data. currently,
841 * we will allow user data to be sent first
842 * and move to SHUTDOWN-PENDING
844 struct sctp_nets *netp;
846 if (stcb->asoc.alternate) {
847 netp = stcb->asoc.alternate;
849 netp = stcb->asoc.primary_destination;
852 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
853 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
855 if (asoc->locked_on_sending) {
856 /* Locked to send out the data */
857 struct sctp_stream_queue_pending *sp;
859 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
861 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
862 asoc->locked_on_sending->stream_no);
864 if ((sp->length == 0) && (sp->msg_is_complete == 0))
865 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
868 if (TAILQ_EMPTY(&asoc->send_queue) &&
869 TAILQ_EMPTY(&asoc->sent_queue) &&
870 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
874 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
875 0, M_DONTWAIT, 1, MT_DATA);
881 struct sctp_paramhdr *ph;
884 SCTP_BUF_LEN(op_err) =
885 (sizeof(struct sctp_paramhdr) + sizeof(uint32_t));
887 struct sctp_paramhdr *);
888 ph->param_type = htons(
889 SCTP_CAUSE_USER_INITIATED_ABT);
890 ph->param_length = htons(SCTP_BUF_LEN(op_err));
891 ippp = (uint32_t *) (ph + 1);
892 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4);
894 #if defined(SCTP_PANIC_ON_ABORT)
895 panic("disconnect does an abort");
898 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
899 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
900 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
901 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
902 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
903 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
905 SCTP_INP_RUNLOCK(inp);
906 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
909 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
912 soisdisconnecting(so);
913 SCTP_TCB_UNLOCK(stcb);
914 SCTP_INP_RUNLOCK(inp);
919 /* UDP model does not support this */
920 SCTP_INP_RUNLOCK(inp);
921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
927 sctp_flush(struct socket *so, int how)
930 * We will just clear out the values and let subsequent close clear
931 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
932 * they will not be able to read the data, the socket will block
933 * that from happening.
935 struct sctp_inpcb *inp;
937 inp = (struct sctp_inpcb *)so->so_pcb;
939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
943 /* For the 1 to many model this does nothing */
944 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
945 SCTP_INP_RUNLOCK(inp);
948 SCTP_INP_RUNLOCK(inp);
949 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
951 * First make sure the sb will be happy, we don't use these
952 * except maybe the count
955 SCTP_INP_READ_LOCK(inp);
956 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
957 SCTP_INP_READ_UNLOCK(inp);
958 SCTP_INP_WUNLOCK(inp);
959 so->so_rcv.sb_cc = 0;
960 so->so_rcv.sb_mbcnt = 0;
961 so->so_rcv.sb_mb = NULL;
963 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
965 * First make sure the sb will be happy, we don't use these
966 * except maybe the count
968 so->so_snd.sb_cc = 0;
969 so->so_snd.sb_mbcnt = 0;
970 so->so_snd.sb_mb = NULL;
977 sctp_shutdown(struct socket *so)
979 struct sctp_inpcb *inp;
981 inp = (struct sctp_inpcb *)so->so_pcb;
983 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
987 /* For UDP model this is a invalid call */
988 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
989 /* Restore the flags that the soshutdown took away. */
990 SOCKBUF_LOCK(&so->so_rcv);
991 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
992 SOCKBUF_UNLOCK(&so->so_rcv);
993 /* This proc will wakeup for read and do nothing (I hope) */
994 SCTP_INP_RUNLOCK(inp);
995 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
999 * Ok if we reach here its the TCP model and it is either a SHUT_WR
1000 * or SHUT_RDWR. This means we put the shutdown flag against it.
1003 struct sctp_tcb *stcb;
1004 struct sctp_association *asoc;
1007 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
1008 SCTP_INP_RUNLOCK(inp);
1013 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1016 * Ok we hit the case that the shutdown call was
1017 * made after an abort or something. Nothing to do
1020 SCTP_INP_RUNLOCK(inp);
1023 SCTP_TCB_LOCK(stcb);
1025 if (TAILQ_EMPTY(&asoc->send_queue) &&
1026 TAILQ_EMPTY(&asoc->sent_queue) &&
1027 (asoc->stream_queue_cnt == 0)) {
1028 if (asoc->locked_on_sending) {
1031 /* there is nothing queued to send, so I'm done... */
1032 if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
1033 /* only send SHUTDOWN the first time through */
1034 struct sctp_nets *netp;
1036 if (stcb->asoc.alternate) {
1037 netp = stcb->asoc.alternate;
1039 netp = stcb->asoc.primary_destination;
1041 sctp_stop_timers_for_shutdown(stcb);
1042 sctp_send_shutdown(stcb, netp);
1043 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
1044 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
1045 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
1046 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
1048 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
1049 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
1050 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1051 stcb->sctp_ep, stcb, netp);
1052 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1053 stcb->sctp_ep, stcb, netp);
1057 * we still got (or just got) data to send, so set
1060 struct sctp_nets *netp;
1062 if (stcb->asoc.alternate) {
1063 netp = stcb->asoc.alternate;
1065 netp = stcb->asoc.primary_destination;
1068 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
1069 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
1072 if (asoc->locked_on_sending) {
1073 /* Locked to send out the data */
1074 struct sctp_stream_queue_pending *sp;
1076 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1078 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1079 asoc->locked_on_sending->stream_no);
1081 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1082 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
1086 if (TAILQ_EMPTY(&asoc->send_queue) &&
1087 TAILQ_EMPTY(&asoc->sent_queue) &&
1088 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1089 struct mbuf *op_err;
1092 op_err = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) + sizeof(uint32_t)),
1093 0, M_DONTWAIT, 1, MT_DATA);
1095 /* Fill in the user initiated abort */
1096 struct sctp_paramhdr *ph;
1099 SCTP_BUF_LEN(op_err) =
1100 sizeof(struct sctp_paramhdr) + sizeof(uint32_t);
1102 struct sctp_paramhdr *);
1103 ph->param_type = htons(
1104 SCTP_CAUSE_USER_INITIATED_ABT);
1105 ph->param_length = htons(SCTP_BUF_LEN(op_err));
1106 ippp = (uint32_t *) (ph + 1);
1107 *ippp = htonl(SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1109 #if defined(SCTP_PANIC_ON_ABORT)
1110 panic("shutdown does an abort");
1112 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1113 sctp_abort_an_association(stcb->sctp_ep, stcb,
1114 SCTP_RESPONSE_TO_USER_REQ,
1115 op_err, SCTP_SO_LOCKED);
1118 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1121 SCTP_TCB_UNLOCK(stcb);
1124 SCTP_INP_RUNLOCK(inp);
1129 * copies a "user" presentable address and removes embedded scope, etc.
1130 * returns 0 on success, 1 on error
1133 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1136 struct sockaddr_in6 lsa6;
1138 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1141 memcpy(ss, sa, sa->sa_len);
1148 * NOTE: assumes addr lock is held
1151 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1152 struct sctp_tcb *stcb,
1154 struct sockaddr_storage *sas,
1157 struct sctp_ifn *sctp_ifn;
1158 struct sctp_ifa *sctp_ifa;
1159 int loopback_scope, ipv4_local_scope, local_scope, site_scope;
1161 int ipv4_addr_legal, ipv6_addr_legal;
1162 struct sctp_vrf *vrf;
1169 /* Turn on all the appropriate scope */
1170 loopback_scope = stcb->asoc.loopback_scope;
1171 ipv4_local_scope = stcb->asoc.ipv4_local_scope;
1172 local_scope = stcb->asoc.local_scope;
1173 site_scope = stcb->asoc.site_scope;
1175 /* Turn on ALL scope, since we look at the EP */
1176 loopback_scope = ipv4_local_scope = local_scope =
1179 ipv4_addr_legal = ipv6_addr_legal = 0;
1180 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1181 ipv6_addr_legal = 1;
1182 if (SCTP_IPV6_V6ONLY(inp) == 0) {
1183 ipv4_addr_legal = 1;
1186 ipv4_addr_legal = 1;
1188 vrf = sctp_find_vrf(vrf_id);
1192 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1193 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1194 if ((loopback_scope == 0) &&
1195 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1196 /* Skip loopback if loopback_scope not set */
1199 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1202 * For the BOUND-ALL case, the list
1203 * associated with a TCB is Always
1204 * considered a reverse list.. i.e.
1205 * it lists addresses that are NOT
1206 * part of the association. If this
1207 * is one of those we must skip it.
1209 if (sctp_is_addr_restricted(stcb,
1214 switch (sctp_ifa->address.sa.sa_family) {
1217 if (ipv4_addr_legal) {
1218 struct sockaddr_in *sin;
1220 sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
1221 if (sin->sin_addr.s_addr == 0) {
1229 if ((ipv4_local_scope == 0) &&
1230 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1234 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1235 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1236 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1237 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1238 actual += sizeof(struct sockaddr_in6);
1241 memcpy(sas, sin, sizeof(*sin));
1242 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1243 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1244 actual += sizeof(*sin);
1248 if (actual >= limit) {
1258 if (ipv6_addr_legal) {
1259 struct sockaddr_in6 *sin6;
1261 sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
1262 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1270 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1271 if (local_scope == 0)
1273 if (sin6->sin6_scope_id == 0) {
1274 if (sa6_recoverscope(sin6) != 0)
1292 if ((site_scope == 0) &&
1293 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1296 memcpy(sas, sin6, sizeof(*sin6));
1297 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1298 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1299 actual += sizeof(*sin6);
1300 if (actual >= limit) {
1315 struct sctp_laddr *laddr;
1317 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1319 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1323 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1326 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1327 sas = (struct sockaddr_storage *)((caddr_t)sas +
1328 laddr->ifa->address.sa.sa_len);
1329 actual += laddr->ifa->address.sa.sa_len;
1330 if (actual >= limit) {
1339 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1340 struct sctp_tcb *stcb,
1342 struct sockaddr_storage *sas)
1346 SCTP_IPI_ADDR_RLOCK();
1347 /* fill up addresses for the endpoint's default vrf */
1348 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1350 SCTP_IPI_ADDR_RUNLOCK();
1355 * NOTE: assumes addr lock is held
1358 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1361 struct sctp_vrf *vrf = NULL;
1364 * In both sub-set bound an bound_all cases we return the MAXIMUM
1365 * number of addresses that you COULD get. In reality the sub-set
1366 * bound may have an exclusion list for a given TCB OR in the
1367 * bound-all case a TCB may NOT include the loopback or other
1368 * addresses as well.
1370 vrf = sctp_find_vrf(vrf_id);
1374 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1375 struct sctp_ifn *sctp_ifn;
1376 struct sctp_ifa *sctp_ifa;
1378 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1379 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1380 /* Count them if they are the right type */
1381 switch (sctp_ifa->address.sa.sa_family) {
1384 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1385 cnt += sizeof(struct sockaddr_in6);
1387 cnt += sizeof(struct sockaddr_in);
1392 cnt += sizeof(struct sockaddr_in6);
1401 struct sctp_laddr *laddr;
1403 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1404 switch (laddr->ifa->address.sa.sa_family) {
1407 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1408 cnt += sizeof(struct sockaddr_in6);
1410 cnt += sizeof(struct sockaddr_in);
1415 cnt += sizeof(struct sockaddr_in6);
1427 sctp_count_max_addresses(struct sctp_inpcb *inp)
1431 SCTP_IPI_ADDR_RLOCK();
1432 /* count addresses for the endpoint's default VRF */
1433 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1434 SCTP_IPI_ADDR_RUNLOCK();
1439 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1440 size_t optsize, void *p, int delay)
1443 int creat_lock_on = 0;
1444 struct sctp_tcb *stcb = NULL;
1445 struct sockaddr *sa;
1446 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1448 int bad_addresses = 0;
1451 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1453 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1454 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1455 /* We are already connected AND the TCP model */
1456 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1457 return (EADDRINUSE);
1459 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1460 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1461 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1464 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1465 SCTP_INP_RLOCK(inp);
1466 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1467 SCTP_INP_RUNLOCK(inp);
1470 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1473 SCTP_INP_INCR_REF(inp);
1474 SCTP_ASOC_CREATE_LOCK(inp);
1476 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1477 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1478 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1482 totaddrp = (int *)optval;
1483 totaddr = *totaddrp;
1484 sa = (struct sockaddr *)(totaddrp + 1);
1485 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
1486 if ((stcb != NULL) || bad_addresses) {
1487 /* Already have or am bring up an association */
1488 SCTP_ASOC_CREATE_UNLOCK(inp);
1491 SCTP_TCB_UNLOCK(stcb);
1492 if (bad_addresses == 0) {
1493 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1499 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1504 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1506 struct in6pcb *inp6;
1508 inp6 = (struct in6pcb *)inp;
1509 if (SCTP_IPV6_V6ONLY(inp6)) {
1511 * if IPV6_V6ONLY flag, ignore connections destined
1512 * to a v4 addr or v4-mapped addr
1514 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1520 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1521 SCTP_PCB_FLAGS_UNBOUND) {
1522 /* Bind a ephemeral port */
1523 error = sctp_inpcb_bind(so, NULL, NULL, p);
1528 /* FIX ME: do we want to pass in a vrf on the connect call? */
1529 vrf_id = inp->def_vrf_id;
1532 /* We are GOOD to go */
1533 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1537 /* Gak! no memory */
1540 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1541 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1542 /* Set the connected flag so we can queue data */
1545 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1546 /* move to second address */
1547 switch (sa->sa_family) {
1550 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1555 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1563 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1564 /* Fill in the return id */
1566 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6);
1569 a_id = (sctp_assoc_t *) optval;
1570 *a_id = sctp_get_associd(stcb);
1572 /* initialize authentication parameters for the assoc */
1573 sctp_initialize_auth_params(inp, stcb);
1576 /* doing delayed connection */
1577 stcb->asoc.delayed_connection = 1;
1578 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1580 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1581 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1583 SCTP_TCB_UNLOCK(stcb);
1584 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1585 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1586 /* Set the connected flag so we can queue data */
1590 if (creat_lock_on) {
1591 SCTP_ASOC_CREATE_UNLOCK(inp);
1593 SCTP_INP_DECR_REF(inp);
1597 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1598 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1599 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1600 SCTP_INP_RLOCK(inp); \
1601 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1603 SCTP_TCB_LOCK(stcb); \
1605 SCTP_INP_RUNLOCK(inp); \
1606 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1607 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1608 if (stcb == NULL) { \
1609 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1619 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1620 if (size < sizeof(type)) { \
1621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1625 destp = (type *)srcp; \
1630 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1633 struct sctp_inpcb *inp = NULL;
1635 struct sctp_tcb *stcb = NULL;
1637 if (optval == NULL) {
1638 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1641 inp = (struct sctp_inpcb *)so->so_pcb;
1643 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1650 case SCTP_AUTOCLOSE:
1651 case SCTP_EXPLICIT_EOR:
1652 case SCTP_AUTO_ASCONF:
1653 case SCTP_DISABLE_FRAGMENTS:
1654 case SCTP_I_WANT_MAPPED_V4_ADDR:
1655 case SCTP_USE_EXT_RCVINFO:
1656 SCTP_INP_RLOCK(inp);
1658 case SCTP_DISABLE_FRAGMENTS:
1659 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1661 case SCTP_I_WANT_MAPPED_V4_ADDR:
1662 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1664 case SCTP_AUTO_ASCONF:
1665 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1666 /* only valid for bound all sockets */
1667 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1669 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1674 case SCTP_EXPLICIT_EOR:
1675 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1678 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1680 case SCTP_USE_EXT_RCVINFO:
1681 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1683 case SCTP_AUTOCLOSE:
1684 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1685 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1692 error = ENOPROTOOPT;
1693 } /* end switch (sopt->sopt_name) */
1694 if (*optsize < sizeof(val)) {
1695 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1699 SCTP_INP_RUNLOCK(inp);
1701 /* return the option value */
1702 *(int *)optval = val;
1703 *optsize = sizeof(val);
1706 case SCTP_GET_PACKET_LOG:
1708 #ifdef SCTP_PACKET_LOGGING
1712 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1713 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1716 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1721 case SCTP_REUSE_PORT:
1725 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1726 /* Can't do this for a 1-m socket */
1730 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1731 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1732 *optsize = sizeof(uint32_t);
1735 case SCTP_PARTIAL_DELIVERY_POINT:
1739 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1740 *value = inp->partial_delivery_point;
1741 *optsize = sizeof(uint32_t);
1744 case SCTP_FRAGMENT_INTERLEAVE:
1748 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1749 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1750 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1751 *value = SCTP_FRAG_LEVEL_2;
1753 *value = SCTP_FRAG_LEVEL_1;
1756 *value = SCTP_FRAG_LEVEL_0;
1758 *optsize = sizeof(uint32_t);
1761 case SCTP_CMT_ON_OFF:
1763 struct sctp_assoc_value *av;
1765 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1766 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1768 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1769 SCTP_TCB_UNLOCK(stcb);
1771 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1772 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1773 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1774 SCTP_INP_RLOCK(inp);
1775 av->assoc_value = inp->sctp_cmt_on_off;
1776 SCTP_INP_RUNLOCK(inp);
1778 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1783 *optsize = sizeof(struct sctp_assoc_value);
1787 case SCTP_PLUGGABLE_CC:
1789 struct sctp_assoc_value *av;
1791 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1792 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1794 av->assoc_value = stcb->asoc.congestion_control_module;
1795 SCTP_TCB_UNLOCK(stcb);
1797 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1798 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1799 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1800 SCTP_INP_RLOCK(inp);
1801 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1802 SCTP_INP_RUNLOCK(inp);
1804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1809 *optsize = sizeof(struct sctp_assoc_value);
1813 case SCTP_CC_OPTION:
1815 struct sctp_cc_option *cc_opt;
1817 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1818 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1822 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1825 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1826 *optsize = sizeof(struct sctp_cc_option);
1828 SCTP_TCB_UNLOCK(stcb);
1832 case SCTP_PLUGGABLE_SS:
1834 struct sctp_assoc_value *av;
1836 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1837 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1839 av->assoc_value = stcb->asoc.stream_scheduling_module;
1840 SCTP_TCB_UNLOCK(stcb);
1842 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1843 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1844 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1845 SCTP_INP_RLOCK(inp);
1846 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1847 SCTP_INP_RUNLOCK(inp);
1849 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1854 *optsize = sizeof(struct sctp_assoc_value);
1860 struct sctp_stream_value *av;
1862 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1863 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1865 if (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1866 &av->stream_value) < 0) {
1867 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1870 *optsize = sizeof(struct sctp_stream_value);
1872 SCTP_TCB_UNLOCK(stcb);
1875 * Can't get stream value without
1878 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1883 case SCTP_GET_ADDR_LEN:
1885 struct sctp_assoc_value *av;
1887 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1890 if (av->assoc_value == AF_INET) {
1891 av->assoc_value = sizeof(struct sockaddr_in);
1896 if (av->assoc_value == AF_INET6) {
1897 av->assoc_value = sizeof(struct sockaddr_in6);
1902 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1904 *optsize = sizeof(struct sctp_assoc_value);
1908 case SCTP_GET_ASSOC_NUMBER:
1910 uint32_t *value, cnt;
1912 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1914 SCTP_INP_RLOCK(inp);
1915 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1918 SCTP_INP_RUNLOCK(inp);
1920 *optsize = sizeof(uint32_t);
1923 case SCTP_GET_ASSOC_ID_LIST:
1925 struct sctp_assoc_ids *ids;
1926 unsigned int at, limit;
1928 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1930 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1931 SCTP_INP_RLOCK(inp);
1932 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1934 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1937 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1941 SCTP_INP_RUNLOCK(inp);
1943 ids->gaids_number_of_ids = at;
1944 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1950 struct sctp_assoc_value *av;
1952 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1953 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1956 av->assoc_value = stcb->asoc.context;
1957 SCTP_TCB_UNLOCK(stcb);
1959 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1960 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1961 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1962 SCTP_INP_RLOCK(inp);
1963 av->assoc_value = inp->sctp_context;
1964 SCTP_INP_RUNLOCK(inp);
1966 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1971 *optsize = sizeof(struct sctp_assoc_value);
1977 uint32_t *default_vrfid;
1979 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1980 *default_vrfid = inp->def_vrf_id;
1981 *optsize = sizeof(uint32_t);
1984 case SCTP_GET_ASOC_VRF:
1986 struct sctp_assoc_value *id;
1988 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1989 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1992 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1994 id->assoc_value = stcb->asoc.vrf_id;
1995 *optsize = sizeof(struct sctp_assoc_value);
1999 case SCTP_GET_VRF_IDS:
2001 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
2005 case SCTP_GET_NONCE_VALUES:
2007 struct sctp_get_nonce_values *gnv;
2009 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
2010 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
2013 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
2014 gnv->gn_local_tag = stcb->asoc.my_vtag;
2015 SCTP_TCB_UNLOCK(stcb);
2016 *optsize = sizeof(struct sctp_get_nonce_values);
2018 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2023 case SCTP_DELAYED_SACK:
2025 struct sctp_sack_info *sack;
2027 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2028 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2030 sack->sack_delay = stcb->asoc.delayed_ack;
2031 sack->sack_freq = stcb->asoc.sack_freq;
2032 SCTP_TCB_UNLOCK(stcb);
2034 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2035 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2036 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2037 SCTP_INP_RLOCK(inp);
2038 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2039 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2040 SCTP_INP_RUNLOCK(inp);
2042 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2047 *optsize = sizeof(struct sctp_sack_info);
2051 case SCTP_GET_SNDBUF_USE:
2053 struct sctp_sockstat *ss;
2055 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2056 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2059 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2060 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2061 stcb->asoc.size_on_all_streams);
2062 SCTP_TCB_UNLOCK(stcb);
2063 *optsize = sizeof(struct sctp_sockstat);
2065 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2070 case SCTP_MAX_BURST:
2072 struct sctp_assoc_value *av;
2074 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2075 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2078 av->assoc_value = stcb->asoc.max_burst;
2079 SCTP_TCB_UNLOCK(stcb);
2081 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2082 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2083 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2084 SCTP_INP_RLOCK(inp);
2085 av->assoc_value = inp->sctp_ep.max_burst;
2086 SCTP_INP_RUNLOCK(inp);
2088 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2093 *optsize = sizeof(struct sctp_assoc_value);
2099 struct sctp_assoc_value *av;
2102 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2103 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2106 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2107 SCTP_TCB_UNLOCK(stcb);
2109 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2110 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2111 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2112 SCTP_INP_RLOCK(inp);
2113 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2114 ovh = SCTP_MED_OVERHEAD;
2116 ovh = SCTP_MED_V4_OVERHEAD;
2118 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2119 av->assoc_value = 0;
2121 av->assoc_value = inp->sctp_frag_point - ovh;
2122 SCTP_INP_RUNLOCK(inp);
2124 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2129 *optsize = sizeof(struct sctp_assoc_value);
2133 case SCTP_GET_STAT_LOG:
2134 error = sctp_fill_stat_log(optval, optsize);
2138 struct sctp_event_subscribe *events;
2140 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2141 memset(events, 0, sizeof(struct sctp_event_subscribe));
2142 SCTP_INP_RLOCK(inp);
2143 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2144 events->sctp_data_io_event = 1;
2146 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2147 events->sctp_association_event = 1;
2149 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2150 events->sctp_address_event = 1;
2152 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2153 events->sctp_send_failure_event = 1;
2155 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2156 events->sctp_peer_error_event = 1;
2158 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2159 events->sctp_shutdown_event = 1;
2161 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2162 events->sctp_partial_delivery_event = 1;
2164 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2165 events->sctp_adaptation_layer_event = 1;
2167 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2168 events->sctp_authentication_event = 1;
2170 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2171 events->sctp_sender_dry_event = 1;
2173 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2174 events->sctp_stream_reset_event = 1;
2175 SCTP_INP_RUNLOCK(inp);
2176 *optsize = sizeof(struct sctp_event_subscribe);
2179 case SCTP_ADAPTATION_LAYER:
2183 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2185 SCTP_INP_RLOCK(inp);
2186 *value = inp->sctp_ep.adaptation_layer_indicator;
2187 SCTP_INP_RUNLOCK(inp);
2188 *optsize = sizeof(uint32_t);
2191 case SCTP_SET_INITIAL_DBG_SEQ:
2195 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2196 SCTP_INP_RLOCK(inp);
2197 *value = inp->sctp_ep.initial_sequence_debug;
2198 SCTP_INP_RUNLOCK(inp);
2199 *optsize = sizeof(uint32_t);
2202 case SCTP_GET_LOCAL_ADDR_SIZE:
2206 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2207 SCTP_INP_RLOCK(inp);
2208 *value = sctp_count_max_addresses(inp);
2209 SCTP_INP_RUNLOCK(inp);
2210 *optsize = sizeof(uint32_t);
2213 case SCTP_GET_REMOTE_ADDR_SIZE:
2217 struct sctp_nets *net;
2219 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2220 /* FIXME MT: change to sctp_assoc_value? */
2221 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2225 /* Count the sizes */
2226 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2227 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2228 size += sizeof(struct sockaddr_in6);
2230 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2233 size += sizeof(struct sockaddr_in);
2238 size += sizeof(struct sockaddr_in6);
2246 SCTP_TCB_UNLOCK(stcb);
2247 *value = (uint32_t) size;
2248 *optsize = sizeof(uint32_t);
2250 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2255 case SCTP_GET_PEER_ADDRESSES:
2257 * Get the address information, an array is passed in to
2258 * fill up we pack it.
2262 struct sockaddr_storage *sas;
2263 struct sctp_nets *net;
2264 struct sctp_getaddresses *saddr;
2266 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2267 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2270 left = (*optsize) - sizeof(struct sctp_getaddresses);
2271 *optsize = sizeof(struct sctp_getaddresses);
2272 sas = (struct sockaddr_storage *)&saddr->addr[0];
2274 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2275 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2276 cpsz = sizeof(struct sockaddr_in6);
2278 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
2281 cpsz = sizeof(struct sockaddr_in);
2286 cpsz = sizeof(struct sockaddr_in6);
2298 /* not enough room. */
2301 #if defined(INET) && defined(INET6)
2302 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2303 (((struct sockaddr *)&net->ro._l_addr)->sa_family == AF_INET)) {
2304 /* Must map the address */
2305 in6_sin_2_v4mapsin6((struct sockaddr_in *)&net->ro._l_addr,
2306 (struct sockaddr_in6 *)sas);
2309 memcpy(sas, &net->ro._l_addr, cpsz);
2310 #if defined(INET) && defined(INET6)
2313 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2315 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2319 SCTP_TCB_UNLOCK(stcb);
2321 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2326 case SCTP_GET_LOCAL_ADDRESSES:
2328 size_t limit, actual;
2329 struct sockaddr_storage *sas;
2330 struct sctp_getaddresses *saddr;
2332 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2333 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2335 sas = (struct sockaddr_storage *)&saddr->addr[0];
2336 limit = *optsize - sizeof(sctp_assoc_t);
2337 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2339 SCTP_TCB_UNLOCK(stcb);
2341 *optsize = sizeof(struct sockaddr_storage) + actual;
2344 case SCTP_PEER_ADDR_PARAMS:
2346 struct sctp_paddrparams *paddrp;
2347 struct sctp_nets *net;
2349 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2350 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2354 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
2357 * We increment here since
2358 * sctp_findassociation_ep_addr() wil do a
2359 * decrement if it finds the stcb as long as
2360 * the locked tcb (last argument) is NOT a
2363 SCTP_INP_INCR_REF(inp);
2364 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddrp->spp_address, &net, NULL, NULL);
2366 SCTP_INP_DECR_REF(inp);
2369 if (stcb && (net == NULL)) {
2370 struct sockaddr *sa;
2372 sa = (struct sockaddr *)&paddrp->spp_address;
2374 if (sa->sa_family == AF_INET) {
2375 struct sockaddr_in *sin;
2377 sin = (struct sockaddr_in *)sa;
2378 if (sin->sin_addr.s_addr) {
2380 SCTP_TCB_UNLOCK(stcb);
2381 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2387 if (sa->sa_family == AF_INET6) {
2388 struct sockaddr_in6 *sin6;
2390 sin6 = (struct sockaddr_in6 *)sa;
2391 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2393 SCTP_TCB_UNLOCK(stcb);
2394 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2400 error = EAFNOSUPPORT;
2401 SCTP_TCB_UNLOCK(stcb);
2402 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2407 /* Applies to the specific association */
2408 paddrp->spp_flags = 0;
2412 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2413 ovh = SCTP_MED_OVERHEAD;
2415 ovh = SCTP_MED_V4_OVERHEAD;
2418 paddrp->spp_hbinterval = net->heart_beat_delay;
2419 paddrp->spp_pathmaxrxt = net->failure_threshold;
2420 paddrp->spp_pathmtu = net->mtu - ovh;
2421 /* get flags for HB */
2422 if (net->dest_state & SCTP_ADDR_NOHB) {
2423 paddrp->spp_flags |= SPP_HB_DISABLE;
2425 paddrp->spp_flags |= SPP_HB_ENABLE;
2427 /* get flags for PMTU */
2428 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2429 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2431 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2433 if (net->dscp & 0x01) {
2434 paddrp->spp_dscp = net->dscp & 0xfc;
2435 paddrp->spp_flags |= SPP_DSCP;
2438 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2439 (net->flowlabel & 0x80000000)) {
2440 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2441 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2446 * No destination so return default
2449 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2450 paddrp->spp_pathmtu = sctp_get_frag_point(stcb, &stcb->asoc);
2451 if (stcb->asoc.default_dscp & 0x01) {
2452 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2453 paddrp->spp_flags |= SPP_DSCP;
2456 if (stcb->asoc.default_flowlabel & 0x80000000) {
2457 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2458 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2461 /* default settings should be these */
2462 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2463 paddrp->spp_flags |= SPP_HB_DISABLE;
2465 paddrp->spp_flags |= SPP_HB_ENABLE;
2467 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2468 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2470 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2472 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2474 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2475 SCTP_TCB_UNLOCK(stcb);
2477 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2478 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2479 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2480 /* Use endpoint defaults */
2481 SCTP_INP_RLOCK(inp);
2482 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2483 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2484 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2485 /* get inp's default */
2486 if (inp->sctp_ep.default_dscp & 0x01) {
2487 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2488 paddrp->spp_flags |= SPP_DSCP;
2491 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2492 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2493 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2494 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2497 /* can't return this */
2498 paddrp->spp_pathmtu = 0;
2500 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2501 paddrp->spp_flags |= SPP_HB_ENABLE;
2503 paddrp->spp_flags |= SPP_HB_DISABLE;
2505 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2506 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2508 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2510 SCTP_INP_RUNLOCK(inp);
2512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2517 *optsize = sizeof(struct sctp_paddrparams);
2521 case SCTP_GET_PEER_ADDR_INFO:
2523 struct sctp_paddrinfo *paddri;
2524 struct sctp_nets *net;
2526 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2527 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2531 net = sctp_findnet(stcb, (struct sockaddr *)&paddri->spinfo_address);
2534 * We increment here since
2535 * sctp_findassociation_ep_addr() wil do a
2536 * decrement if it finds the stcb as long as
2537 * the locked tcb (last argument) is NOT a
2540 SCTP_INP_INCR_REF(inp);
2541 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&paddri->spinfo_address, &net, NULL, NULL);
2543 SCTP_INP_DECR_REF(inp);
2547 if ((stcb) && (net)) {
2548 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2549 /* It's unconfirmed */
2550 paddri->spinfo_state = SCTP_UNCONFIRMED;
2551 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2553 paddri->spinfo_state = SCTP_ACTIVE;
2556 paddri->spinfo_state = SCTP_INACTIVE;
2558 paddri->spinfo_cwnd = net->cwnd;
2559 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2560 paddri->spinfo_rto = net->RTO;
2561 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2562 paddri->spinfo_mtu = net->mtu;
2563 SCTP_TCB_UNLOCK(stcb);
2564 *optsize = sizeof(struct sctp_paddrinfo);
2567 SCTP_TCB_UNLOCK(stcb);
2569 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2574 case SCTP_PCB_STATUS:
2576 struct sctp_pcbinfo *spcb;
2578 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2579 sctp_fill_pcbinfo(spcb);
2580 *optsize = sizeof(struct sctp_pcbinfo);
2585 struct sctp_nets *net;
2586 struct sctp_status *sstat;
2588 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2589 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2592 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2597 * I think passing the state is fine since
2598 * sctp_constants.h will be available to the user
2601 sstat->sstat_state = stcb->asoc.state;
2602 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2603 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2604 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2606 * We can't include chunks that have been passed to
2607 * the socket layer. Only things in queue.
2609 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2610 stcb->asoc.cnt_on_all_streams);
2613 sstat->sstat_instrms = stcb->asoc.streamincnt;
2614 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2615 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2616 memcpy(&sstat->sstat_primary.spinfo_address,
2617 &stcb->asoc.primary_destination->ro._l_addr,
2618 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2619 net = stcb->asoc.primary_destination;
2620 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2622 * Again the user can get info from sctp_constants.h
2623 * for what the state of the network is.
2625 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2626 /* It's unconfirmed */
2627 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2628 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2630 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2633 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2635 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2636 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2637 sstat->sstat_primary.spinfo_rto = net->RTO;
2638 sstat->sstat_primary.spinfo_mtu = net->mtu;
2639 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2640 SCTP_TCB_UNLOCK(stcb);
2641 *optsize = sizeof(struct sctp_status);
2646 struct sctp_rtoinfo *srto;
2648 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2649 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2652 srto->srto_initial = stcb->asoc.initial_rto;
2653 srto->srto_max = stcb->asoc.maxrto;
2654 srto->srto_min = stcb->asoc.minrto;
2655 SCTP_TCB_UNLOCK(stcb);
2657 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2658 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2659 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2660 SCTP_INP_RLOCK(inp);
2661 srto->srto_initial = inp->sctp_ep.initial_rto;
2662 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2663 srto->srto_min = inp->sctp_ep.sctp_minrto;
2664 SCTP_INP_RUNLOCK(inp);
2666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2671 *optsize = sizeof(struct sctp_rtoinfo);
2677 struct sctp_timeouts *stimo;
2679 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2680 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2683 stimo->stimo_init = stcb->asoc.timoinit;
2684 stimo->stimo_data = stcb->asoc.timodata;
2685 stimo->stimo_sack = stcb->asoc.timosack;
2686 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2687 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2688 stimo->stimo_cookie = stcb->asoc.timocookie;
2689 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2690 SCTP_TCB_UNLOCK(stcb);
2691 *optsize = sizeof(struct sctp_timeouts);
2693 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2698 case SCTP_ASSOCINFO:
2700 struct sctp_assocparams *sasoc;
2702 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2703 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2706 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2707 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2708 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2709 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2710 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2711 SCTP_TCB_UNLOCK(stcb);
2713 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2714 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2715 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2716 SCTP_INP_RLOCK(inp);
2717 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2718 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2719 sasoc->sasoc_number_peer_destinations = 0;
2720 sasoc->sasoc_peer_rwnd = 0;
2721 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2722 SCTP_INP_RUNLOCK(inp);
2724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2729 *optsize = sizeof(struct sctp_assocparams);
2733 case SCTP_DEFAULT_SEND_PARAM:
2735 struct sctp_sndrcvinfo *s_info;
2737 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2738 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2741 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2742 SCTP_TCB_UNLOCK(stcb);
2744 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2745 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2746 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2747 SCTP_INP_RLOCK(inp);
2748 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2749 SCTP_INP_RUNLOCK(inp);
2751 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2756 *optsize = sizeof(struct sctp_sndrcvinfo);
2762 struct sctp_initmsg *sinit;
2764 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2765 SCTP_INP_RLOCK(inp);
2766 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2767 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2768 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2769 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2770 SCTP_INP_RUNLOCK(inp);
2771 *optsize = sizeof(struct sctp_initmsg);
2774 case SCTP_PRIMARY_ADDR:
2775 /* we allow a "get" operation on this */
2777 struct sctp_setprim *ssp;
2779 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2780 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2783 /* simply copy out the sockaddr_storage... */
2787 if (len > stcb->asoc.primary_destination->ro._l_addr.sa.sa_len)
2788 len = stcb->asoc.primary_destination->ro._l_addr.sa.sa_len;
2790 memcpy(&ssp->ssp_addr,
2791 &stcb->asoc.primary_destination->ro._l_addr,
2793 SCTP_TCB_UNLOCK(stcb);
2794 *optsize = sizeof(struct sctp_setprim);
2796 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2801 case SCTP_HMAC_IDENT:
2803 struct sctp_hmacalgo *shmac;
2804 sctp_hmaclist_t *hmaclist;
2808 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2810 SCTP_INP_RLOCK(inp);
2811 hmaclist = inp->sctp_ep.local_hmacs;
2812 if (hmaclist == NULL) {
2813 /* no HMACs to return */
2814 *optsize = sizeof(*shmac);
2815 SCTP_INP_RUNLOCK(inp);
2818 /* is there room for all of the hmac ids? */
2819 size = sizeof(*shmac) + (hmaclist->num_algo *
2820 sizeof(shmac->shmac_idents[0]));
2821 if ((size_t)(*optsize) < size) {
2822 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2824 SCTP_INP_RUNLOCK(inp);
2827 /* copy in the list */
2828 shmac->shmac_number_of_idents = hmaclist->num_algo;
2829 for (i = 0; i < hmaclist->num_algo; i++) {
2830 shmac->shmac_idents[i] = hmaclist->hmac[i];
2832 SCTP_INP_RUNLOCK(inp);
2836 case SCTP_AUTH_ACTIVE_KEY:
2838 struct sctp_authkeyid *scact;
2840 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2841 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2844 /* get the active key on the assoc */
2845 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2846 SCTP_TCB_UNLOCK(stcb);
2848 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2849 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2850 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2851 /* get the endpoint active key */
2852 SCTP_INP_RLOCK(inp);
2853 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2854 SCTP_INP_RUNLOCK(inp);
2856 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2861 *optsize = sizeof(struct sctp_authkeyid);
2865 case SCTP_LOCAL_AUTH_CHUNKS:
2867 struct sctp_authchunks *sac;
2868 sctp_auth_chklist_t *chklist = NULL;
2871 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2872 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2875 /* get off the assoc */
2876 chklist = stcb->asoc.local_auth_chunks;
2877 /* is there enough space? */
2878 size = sctp_auth_get_chklist_size(chklist);
2879 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2883 /* copy in the chunks */
2884 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2885 *optsize = sizeof(struct sctp_authchunks) + size;
2887 SCTP_TCB_UNLOCK(stcb);
2889 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2890 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2891 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2892 /* get off the endpoint */
2893 SCTP_INP_RLOCK(inp);
2894 chklist = inp->sctp_ep.local_auth_chunks;
2895 /* is there enough space? */
2896 size = sctp_auth_get_chklist_size(chklist);
2897 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2899 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2901 /* copy in the chunks */
2902 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2903 *optsize = sizeof(struct sctp_authchunks) + size;
2905 SCTP_INP_RUNLOCK(inp);
2907 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2913 case SCTP_PEER_AUTH_CHUNKS:
2915 struct sctp_authchunks *sac;
2916 sctp_auth_chklist_t *chklist = NULL;
2919 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2920 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2923 /* get off the assoc */
2924 chklist = stcb->asoc.peer_auth_chunks;
2925 /* is there enough space? */
2926 size = sctp_auth_get_chklist_size(chklist);
2927 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2929 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2931 /* copy in the chunks */
2932 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2933 *optsize = sizeof(struct sctp_authchunks) + size;
2935 SCTP_TCB_UNLOCK(stcb);
2937 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2944 struct sctp_event *event;
2945 uint32_t event_type;
2947 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
2948 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
2950 switch (event->se_type) {
2951 case SCTP_ASSOC_CHANGE:
2952 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
2954 case SCTP_PEER_ADDR_CHANGE:
2955 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
2957 case SCTP_REMOTE_ERROR:
2958 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
2960 case SCTP_SEND_FAILED:
2961 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
2963 case SCTP_SHUTDOWN_EVENT:
2964 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
2966 case SCTP_ADAPTATION_INDICATION:
2967 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
2969 case SCTP_PARTIAL_DELIVERY_EVENT:
2970 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
2972 case SCTP_AUTHENTICATION_EVENT:
2973 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
2975 case SCTP_STREAM_RESET_EVENT:
2976 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
2978 case SCTP_SENDER_DRY_EVENT:
2979 event_type = SCTP_PCB_FLAGS_DRYEVNT;
2981 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
2983 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
2988 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2992 if (event_type > 0) {
2994 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
2995 SCTP_TCB_UNLOCK(stcb);
2997 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2998 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2999 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3000 SCTP_INP_RLOCK(inp);
3001 event->se_on = sctp_is_feature_on(inp, event_type);
3002 SCTP_INP_RUNLOCK(inp);
3004 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3010 *optsize = sizeof(struct sctp_event);
3014 case SCTP_RECVRCVINFO:
3018 if (*optsize < sizeof(int)) {
3019 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3022 SCTP_INP_RLOCK(inp);
3023 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3024 SCTP_INP_RUNLOCK(inp);
3027 /* return the option value */
3028 *(int *)optval = onoff;
3029 *optsize = sizeof(int);
3033 case SCTP_RECVNXTINFO:
3037 if (*optsize < sizeof(int)) {
3038 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3041 SCTP_INP_RLOCK(inp);
3042 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3043 SCTP_INP_RUNLOCK(inp);
3046 /* return the option value */
3047 *(int *)optval = onoff;
3048 *optsize = sizeof(int);
3052 case SCTP_DEFAULT_SNDINFO:
3054 struct sctp_sndinfo *info;
3056 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3057 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3060 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3061 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3062 info->snd_flags &= 0xfff0;
3063 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3064 info->snd_context = stcb->asoc.def_send.sinfo_context;
3065 SCTP_TCB_UNLOCK(stcb);
3067 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3068 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3069 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3070 SCTP_INP_RLOCK(inp);
3071 info->snd_sid = inp->def_send.sinfo_stream;
3072 info->snd_flags = inp->def_send.sinfo_flags;
3073 info->snd_flags &= 0xfff0;
3074 info->snd_ppid = inp->def_send.sinfo_ppid;
3075 info->snd_context = inp->def_send.sinfo_context;
3076 SCTP_INP_RUNLOCK(inp);
3078 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3083 *optsize = sizeof(struct sctp_sndinfo);
3087 case SCTP_DEFAULT_PRINFO:
3089 struct sctp_default_prinfo *info;
3091 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3092 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3095 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3096 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3097 SCTP_TCB_UNLOCK(stcb);
3099 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3100 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3101 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3102 SCTP_INP_RLOCK(inp);
3103 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3104 info->pr_value = inp->def_send.sinfo_timetolive;
3105 SCTP_INP_RUNLOCK(inp);
3107 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3112 *optsize = sizeof(struct sctp_default_prinfo);
3116 case SCTP_PEER_ADDR_THLDS:
3118 struct sctp_paddrthlds *thlds;
3119 struct sctp_nets *net;
3121 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3122 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3126 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_address);
3129 * We increment here since
3130 * sctp_findassociation_ep_addr() wil do a
3131 * decrement if it finds the stcb as long as
3132 * the locked tcb (last argument) is NOT a
3135 SCTP_INP_INCR_REF(inp);
3136 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&thlds->spt_address, &net, NULL, NULL);
3138 SCTP_INP_DECR_REF(inp);
3141 if (stcb && (net == NULL)) {
3142 struct sockaddr *sa;
3144 sa = (struct sockaddr *)&thlds->spt_address;
3146 if (sa->sa_family == AF_INET) {
3147 struct sockaddr_in *sin;
3149 sin = (struct sockaddr_in *)sa;
3150 if (sin->sin_addr.s_addr) {
3152 SCTP_TCB_UNLOCK(stcb);
3153 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3159 if (sa->sa_family == AF_INET6) {
3160 struct sockaddr_in6 *sin6;
3162 sin6 = (struct sockaddr_in6 *)sa;
3163 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3165 SCTP_TCB_UNLOCK(stcb);
3166 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3172 error = EAFNOSUPPORT;
3173 SCTP_TCB_UNLOCK(stcb);
3174 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3180 thlds->spt_pathmaxrxt = net->failure_threshold;
3181 thlds->spt_pathpfthld = net->pf_threshold;
3183 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3184 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3186 thlds->spt_assoc_id = sctp_get_associd(stcb);
3187 SCTP_TCB_UNLOCK(stcb);
3189 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3190 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3191 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3192 /* Use endpoint defaults */
3193 SCTP_INP_RLOCK(inp);
3194 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3195 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3196 SCTP_INP_RUNLOCK(inp);
3198 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3203 *optsize = sizeof(struct sctp_paddrthlds);
3207 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3209 struct sctp_udpencaps *encaps;
3210 struct sctp_nets *net;
3212 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3213 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3216 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
3219 * We increment here since
3220 * sctp_findassociation_ep_addr() wil do a
3221 * decrement if it finds the stcb as long as
3222 * the locked tcb (last argument) is NOT a
3226 SCTP_INP_INCR_REF(inp);
3227 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
3229 SCTP_INP_DECR_REF(inp);
3232 if (stcb && (net == NULL)) {
3233 struct sockaddr *sa;
3235 sa = (struct sockaddr *)&encaps->sue_address;
3237 if (sa->sa_family == AF_INET) {
3238 struct sockaddr_in *sin;
3240 sin = (struct sockaddr_in *)sa;
3241 if (sin->sin_addr.s_addr) {
3243 SCTP_TCB_UNLOCK(stcb);
3244 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3250 if (sa->sa_family == AF_INET6) {
3251 struct sockaddr_in6 *sin6;
3253 sin6 = (struct sockaddr_in6 *)sa;
3254 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3256 SCTP_TCB_UNLOCK(stcb);
3257 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3263 error = EAFNOSUPPORT;
3264 SCTP_TCB_UNLOCK(stcb);
3265 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3271 encaps->sue_port = net->port;
3273 encaps->sue_port = stcb->asoc.port;
3275 SCTP_TCB_UNLOCK(stcb);
3277 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3278 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3279 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3280 SCTP_INP_RLOCK(inp);
3281 encaps->sue_port = inp->sctp_ep.port;
3282 SCTP_INP_RUNLOCK(inp);
3284 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3289 *optsize = sizeof(struct sctp_paddrparams);
3294 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3295 error = ENOPROTOOPT;
3297 } /* end switch (sopt->sopt_name) */
3305 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3310 struct sctp_tcb *stcb = NULL;
3311 struct sctp_inpcb *inp = NULL;
3314 if (optval == NULL) {
3315 SCTP_PRINTF("optval is NULL\n");
3316 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3319 inp = (struct sctp_inpcb *)so->so_pcb;
3321 SCTP_PRINTF("inp is NULL?\n");
3322 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3325 vrf_id = inp->def_vrf_id;
3330 case SCTP_AUTOCLOSE:
3331 case SCTP_AUTO_ASCONF:
3332 case SCTP_EXPLICIT_EOR:
3333 case SCTP_DISABLE_FRAGMENTS:
3334 case SCTP_USE_EXT_RCVINFO:
3335 case SCTP_I_WANT_MAPPED_V4_ADDR:
3336 /* copy in the option value */
3337 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3342 case SCTP_DISABLE_FRAGMENTS:
3343 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3345 case SCTP_AUTO_ASCONF:
3347 * NOTE: we don't really support this flag
3349 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3350 /* only valid for bound all sockets */
3351 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3353 /* forbidden by admin */
3354 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3357 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3359 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3363 case SCTP_EXPLICIT_EOR:
3364 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3366 case SCTP_USE_EXT_RCVINFO:
3367 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3369 case SCTP_I_WANT_MAPPED_V4_ADDR:
3370 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3371 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3373 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3378 set_opt = SCTP_PCB_FLAGS_NODELAY;
3380 case SCTP_AUTOCLOSE:
3381 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3382 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3383 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3386 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3388 * The value is in ticks. Note this does not effect
3389 * old associations, only new ones.
3391 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3394 SCTP_INP_WLOCK(inp);
3396 sctp_feature_on(inp, set_opt);
3398 sctp_feature_off(inp, set_opt);
3400 SCTP_INP_WUNLOCK(inp);
3402 case SCTP_REUSE_PORT:
3404 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3405 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3406 /* Can't set it after we are bound */
3410 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3411 /* Can't do this for a 1-m socket */
3416 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3418 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3421 case SCTP_PARTIAL_DELIVERY_POINT:
3425 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3426 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3427 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3431 inp->partial_delivery_point = *value;
3434 case SCTP_FRAGMENT_INTERLEAVE:
3435 /* not yet until we re-write sctp_recvmsg() */
3439 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3440 if (*level == SCTP_FRAG_LEVEL_2) {
3441 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3442 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3443 } else if (*level == SCTP_FRAG_LEVEL_1) {
3444 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3445 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3446 } else if (*level == SCTP_FRAG_LEVEL_0) {
3447 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3448 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3451 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3456 case SCTP_CMT_ON_OFF:
3457 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3458 struct sctp_assoc_value *av;
3460 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3461 if (av->assoc_value > SCTP_CMT_MAX) {
3462 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3466 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3468 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3469 SCTP_TCB_UNLOCK(stcb);
3471 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3472 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3473 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3474 (av->assoc_id == SCTP_ALL_ASSOC)) {
3475 SCTP_INP_WLOCK(inp);
3476 inp->sctp_cmt_on_off = av->assoc_value;
3477 SCTP_INP_WUNLOCK(inp);
3479 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3480 (av->assoc_id == SCTP_ALL_ASSOC)) {
3481 SCTP_INP_RLOCK(inp);
3482 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3483 SCTP_TCB_LOCK(stcb);
3484 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3485 SCTP_TCB_UNLOCK(stcb);
3487 SCTP_INP_RUNLOCK(inp);
3491 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3492 error = ENOPROTOOPT;
3495 case SCTP_PLUGGABLE_CC:
3497 struct sctp_assoc_value *av;
3498 struct sctp_nets *net;
3500 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3501 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3502 (av->assoc_value != SCTP_CC_HSTCP) &&
3503 (av->assoc_value != SCTP_CC_HTCP) &&
3504 (av->assoc_value != SCTP_CC_RTCC)) {
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.cc_functions = sctp_cc_functions[av->assoc_value];
3512 stcb->asoc.congestion_control_module = av->assoc_value;
3513 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3514 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3515 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3518 SCTP_TCB_UNLOCK(stcb);
3520 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3521 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3522 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3523 (av->assoc_id == SCTP_ALL_ASSOC)) {
3524 SCTP_INP_WLOCK(inp);
3525 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3526 SCTP_INP_WUNLOCK(inp);
3528 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3529 (av->assoc_id == SCTP_ALL_ASSOC)) {
3530 SCTP_INP_RLOCK(inp);
3531 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3532 SCTP_TCB_LOCK(stcb);
3533 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3534 stcb->asoc.congestion_control_module = av->assoc_value;
3535 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3536 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3537 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3540 SCTP_TCB_UNLOCK(stcb);
3542 SCTP_INP_RUNLOCK(inp);
3547 case SCTP_CC_OPTION:
3549 struct sctp_cc_option *cc_opt;
3551 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3552 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3554 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3555 SCTP_INP_RLOCK(inp);
3556 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3557 SCTP_TCB_LOCK(stcb);
3558 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3559 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3561 SCTP_TCB_UNLOCK(stcb);
3563 SCTP_INP_RUNLOCK(inp);
3568 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
3571 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
3574 SCTP_TCB_UNLOCK(stcb);
3578 case SCTP_PLUGGABLE_SS:
3580 struct sctp_assoc_value *av;
3582 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3583 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
3584 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
3585 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
3586 (av->assoc_value != SCTP_SS_PRIORITY) &&
3587 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
3588 (av->assoc_value != SCTP_SS_FIRST_COME)) {
3589 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3593 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3595 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3596 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3597 stcb->asoc.stream_scheduling_module = av->assoc_value;
3598 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3599 SCTP_TCB_UNLOCK(stcb);
3601 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3602 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3603 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3604 (av->assoc_id == SCTP_ALL_ASSOC)) {
3605 SCTP_INP_WLOCK(inp);
3606 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
3607 SCTP_INP_WUNLOCK(inp);
3609 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3610 (av->assoc_id == SCTP_ALL_ASSOC)) {
3611 SCTP_INP_RLOCK(inp);
3612 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3613 SCTP_TCB_LOCK(stcb);
3614 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
3615 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
3616 stcb->asoc.stream_scheduling_module = av->assoc_value;
3617 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
3618 SCTP_TCB_UNLOCK(stcb);
3620 SCTP_INP_RUNLOCK(inp);
3627 struct sctp_stream_value *av;
3629 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
3630 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3632 if (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
3633 av->stream_value) < 0) {
3634 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3637 SCTP_TCB_UNLOCK(stcb);
3639 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
3640 SCTP_INP_RLOCK(inp);
3641 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3642 SCTP_TCB_LOCK(stcb);
3643 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
3645 &stcb->asoc.strmout[av->stream_id],
3647 SCTP_TCB_UNLOCK(stcb);
3649 SCTP_INP_RUNLOCK(inp);
3653 * Can't set stream value without
3656 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3662 case SCTP_CLR_STAT_LOG:
3663 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3668 struct sctp_assoc_value *av;
3670 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3671 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3674 stcb->asoc.context = av->assoc_value;
3675 SCTP_TCB_UNLOCK(stcb);
3677 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3678 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3679 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3680 (av->assoc_id == SCTP_ALL_ASSOC)) {
3681 SCTP_INP_WLOCK(inp);
3682 inp->sctp_context = av->assoc_value;
3683 SCTP_INP_WUNLOCK(inp);
3685 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3686 (av->assoc_id == SCTP_ALL_ASSOC)) {
3687 SCTP_INP_RLOCK(inp);
3688 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3689 SCTP_TCB_LOCK(stcb);
3690 stcb->asoc.context = av->assoc_value;
3691 SCTP_TCB_UNLOCK(stcb);
3693 SCTP_INP_RUNLOCK(inp);
3700 uint32_t *default_vrfid;
3702 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
3703 if (*default_vrfid > SCTP_MAX_VRF_ID) {
3704 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3708 inp->def_vrf_id = *default_vrfid;
3711 case SCTP_DEL_VRF_ID:
3713 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3717 case SCTP_ADD_VRF_ID:
3719 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
3723 case SCTP_DELAYED_SACK:
3725 struct sctp_sack_info *sack;
3727 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
3728 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
3729 if (sack->sack_delay) {
3730 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
3731 sack->sack_delay = SCTP_MAX_SACK_DELAY;
3732 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
3733 sack->sack_delay = TICKS_TO_MSEC(1);
3737 if (sack->sack_delay) {
3738 stcb->asoc.delayed_ack = sack->sack_delay;
3740 if (sack->sack_freq) {
3741 stcb->asoc.sack_freq = sack->sack_freq;
3743 SCTP_TCB_UNLOCK(stcb);
3745 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3746 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3747 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
3748 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3749 SCTP_INP_WLOCK(inp);
3750 if (sack->sack_delay) {
3751 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
3753 if (sack->sack_freq) {
3754 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
3756 SCTP_INP_WUNLOCK(inp);
3758 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
3759 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
3760 SCTP_INP_RLOCK(inp);
3761 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3762 SCTP_TCB_LOCK(stcb);
3763 if (sack->sack_delay) {
3764 stcb->asoc.delayed_ack = sack->sack_delay;
3766 if (sack->sack_freq) {
3767 stcb->asoc.sack_freq = sack->sack_freq;
3769 SCTP_TCB_UNLOCK(stcb);
3771 SCTP_INP_RUNLOCK(inp);
3776 case SCTP_AUTH_CHUNK:
3778 struct sctp_authchunk *sauth;
3780 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
3782 SCTP_INP_WLOCK(inp);
3783 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
3784 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3787 SCTP_INP_WUNLOCK(inp);
3792 struct sctp_authkey *sca;
3793 struct sctp_keyhead *shared_keys;
3794 sctp_sharedkey_t *shared_key;
3795 sctp_key_t *key = NULL;
3798 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
3799 if (sca->sca_keylength == 0) {
3800 size = optsize - sizeof(struct sctp_authkey);
3802 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
3803 size = sca->sca_keylength;
3805 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3810 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
3813 shared_keys = &stcb->asoc.shared_keys;
3814 /* clear the cached keys for this key id */
3815 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3817 * create the new shared key and
3821 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3823 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3825 SCTP_TCB_UNLOCK(stcb);
3829 shared_key = sctp_alloc_sharedkey();
3830 if (shared_key == NULL) {
3832 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3834 SCTP_TCB_UNLOCK(stcb);
3837 shared_key->key = key;
3838 shared_key->keyid = sca->sca_keynumber;
3839 error = sctp_insert_sharedkey(shared_keys, shared_key);
3840 SCTP_TCB_UNLOCK(stcb);
3842 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3843 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3844 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
3845 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3846 SCTP_INP_WLOCK(inp);
3847 shared_keys = &inp->sctp_ep.shared_keys;
3849 * clear the cached keys on all
3850 * assocs for this key id
3852 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
3854 * create the new shared key and
3858 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3860 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3862 SCTP_INP_WUNLOCK(inp);
3866 shared_key = sctp_alloc_sharedkey();
3867 if (shared_key == NULL) {
3869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3871 SCTP_INP_WUNLOCK(inp);
3874 shared_key->key = key;
3875 shared_key->keyid = sca->sca_keynumber;
3876 error = sctp_insert_sharedkey(shared_keys, shared_key);
3877 SCTP_INP_WUNLOCK(inp);
3879 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
3880 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
3881 SCTP_INP_RLOCK(inp);
3882 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3883 SCTP_TCB_LOCK(stcb);
3884 shared_keys = &stcb->asoc.shared_keys;
3886 * clear the cached keys for
3889 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
3891 * create the new shared key
3892 * and insert/replace it
3895 key = sctp_set_key(sca->sca_key, (uint32_t) size);
3897 SCTP_TCB_UNLOCK(stcb);
3901 shared_key = sctp_alloc_sharedkey();
3902 if (shared_key == NULL) {
3904 SCTP_TCB_UNLOCK(stcb);
3907 shared_key->key = key;
3908 shared_key->keyid = sca->sca_keynumber;
3909 error = sctp_insert_sharedkey(shared_keys, shared_key);
3910 SCTP_TCB_UNLOCK(stcb);
3912 SCTP_INP_RUNLOCK(inp);
3917 case SCTP_HMAC_IDENT:
3919 struct sctp_hmacalgo *shmac;
3920 sctp_hmaclist_t *hmaclist;
3925 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
3926 if (optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) {
3927 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3931 hmaclist = sctp_alloc_hmaclist(shmac->shmac_number_of_idents);
3932 if (hmaclist == NULL) {
3933 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
3937 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
3938 hmacid = shmac->shmac_idents[i];
3939 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
3940 /* invalid HMACs were found */ ;
3941 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3943 sctp_free_hmaclist(hmaclist);
3944 goto sctp_set_hmac_done;
3948 for (i = 0; i < hmaclist->num_algo; i++) {
3949 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
3950 /* already in list */
3955 sctp_free_hmaclist(hmaclist);
3956 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3960 /* set it on the endpoint */
3961 SCTP_INP_WLOCK(inp);
3962 if (inp->sctp_ep.local_hmacs)
3963 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
3964 inp->sctp_ep.local_hmacs = hmaclist;
3965 SCTP_INP_WUNLOCK(inp);
3969 case SCTP_AUTH_ACTIVE_KEY:
3971 struct sctp_authkeyid *scact;
3973 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
3974 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
3976 /* set the active key on the right place */
3978 /* set the active key on the assoc */
3979 if (sctp_auth_setactivekey(stcb,
3980 scact->scact_keynumber)) {
3981 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
3982 SCTP_FROM_SCTP_USRREQ,
3986 SCTP_TCB_UNLOCK(stcb);
3988 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3989 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3990 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
3991 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
3992 SCTP_INP_WLOCK(inp);
3993 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
3994 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3997 SCTP_INP_WUNLOCK(inp);
3999 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4000 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4001 SCTP_INP_RLOCK(inp);
4002 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4003 SCTP_TCB_LOCK(stcb);
4004 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4005 SCTP_TCB_UNLOCK(stcb);
4007 SCTP_INP_RUNLOCK(inp);
4012 case SCTP_AUTH_DELETE_KEY:
4014 struct sctp_authkeyid *scdel;
4016 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4017 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4019 /* delete the key from the right place */
4021 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4022 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4025 SCTP_TCB_UNLOCK(stcb);
4027 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4028 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4029 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4030 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4031 SCTP_INP_WLOCK(inp);
4032 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4033 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4036 SCTP_INP_WUNLOCK(inp);
4038 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4039 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4040 SCTP_INP_RLOCK(inp);
4041 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4042 SCTP_TCB_LOCK(stcb);
4043 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4044 SCTP_TCB_UNLOCK(stcb);
4046 SCTP_INP_RUNLOCK(inp);
4051 case SCTP_AUTH_DEACTIVATE_KEY:
4053 struct sctp_authkeyid *keyid;
4055 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4056 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4058 /* deactivate the key from the right place */
4060 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4061 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4064 SCTP_TCB_UNLOCK(stcb);
4066 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4067 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4068 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4069 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4070 SCTP_INP_WLOCK(inp);
4071 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4072 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4075 SCTP_INP_WUNLOCK(inp);
4077 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4078 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4079 SCTP_INP_RLOCK(inp);
4080 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4081 SCTP_TCB_LOCK(stcb);
4082 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4083 SCTP_TCB_UNLOCK(stcb);
4085 SCTP_INP_RUNLOCK(inp);
4090 case SCTP_ENABLE_STREAM_RESET:
4092 struct sctp_assoc_value *av;
4093 uint8_t set_value = 0;
4095 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4096 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4097 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4101 set_value = av->assoc_value & SCTP_ENABLE_VALUE_MASK;
4102 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4104 stcb->asoc.local_strreset_support = set_value;
4105 SCTP_TCB_UNLOCK(stcb);
4107 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4108 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4109 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4110 (av->assoc_id == SCTP_ALL_ASSOC)) {
4111 SCTP_INP_WLOCK(inp);
4112 inp->local_strreset_support = set_value;
4113 SCTP_INP_WUNLOCK(inp);
4115 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4116 (av->assoc_id == SCTP_ALL_ASSOC)) {
4117 SCTP_INP_RLOCK(inp);
4118 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4119 SCTP_TCB_LOCK(stcb);
4120 stcb->asoc.local_strreset_support = set_value;
4121 SCTP_TCB_UNLOCK(stcb);
4123 SCTP_INP_RUNLOCK(inp);
4128 case SCTP_RESET_STREAMS:
4130 struct sctp_reset_streams *strrst;
4131 int i, send_out = 0;
4134 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4135 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4138 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4142 if (stcb->asoc.peer_supports_strreset == 0) {
4144 * Peer does not support the chunk type.
4146 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4148 SCTP_TCB_UNLOCK(stcb);
4151 if (!(stcb->asoc.local_strreset_support & SCTP_ENABLE_RESET_STREAM_REQ)) {
4153 * User did not enable the operation.
4155 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
4157 SCTP_TCB_UNLOCK(stcb);
4160 if (stcb->asoc.stream_reset_outstanding) {
4161 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4163 SCTP_TCB_UNLOCK(stcb);
4166 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4169 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4172 if ((send_in == 0) && (send_out == 0)) {
4173 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4175 SCTP_TCB_UNLOCK(stcb);
4178 for (i = 0; i < strrst->srs_number_streams; i++) {
4180 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4181 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4186 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4187 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4193 SCTP_TCB_UNLOCK(stcb);
4196 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4197 strrst->srs_stream_list,
4198 send_out, send_in, 0, 0, 0, 0, 0);
4200 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4201 SCTP_TCB_UNLOCK(stcb);
4204 case SCTP_ADD_STREAMS:
4206 struct sctp_add_streams *stradd;
4207 uint8_t addstream = 0;
4208 uint16_t add_o_strmcnt = 0;
4209 uint16_t add_i_strmcnt = 0;
4211 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4212 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4214 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4218 if ((stradd->sas_outstrms == 0) &&
4219 (stradd->sas_instrms == 0)) {
4223 if (stradd->sas_outstrms) {
4225 /* We allocate here */
4226 add_o_strmcnt = stradd->sas_outstrms;
4227 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4228 /* You can't have more than 64k */
4233 if (stradd->sas_instrms) {
4238 * We allocate inside
4239 * sctp_send_str_reset_req()
4241 add_i_strmcnt = stradd->sas_instrms;
4242 cnt = add_i_strmcnt;
4243 cnt += stcb->asoc.streamincnt;
4244 if (cnt > 0x0000ffff) {
4245 /* You can't have more than 64k */
4249 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4250 /* More than you are allowed */
4255 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4256 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4258 SCTP_TCB_UNLOCK(stcb);
4261 case SCTP_RESET_ASSOC:
4265 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4266 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4268 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4272 if (stcb->asoc.peer_supports_strreset == 0) {
4274 * Peer does not support the chunk type.
4276 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4278 SCTP_TCB_UNLOCK(stcb);
4281 if (!(stcb->asoc.local_strreset_support & SCTP_ENABLE_RESET_ASSOC_REQ)) {
4283 * User did not enable the operation.
4285 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
4287 SCTP_TCB_UNLOCK(stcb);
4290 if (stcb->asoc.stream_reset_outstanding) {
4291 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4293 SCTP_TCB_UNLOCK(stcb);
4296 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, 1, 0, 0, 0, 0);
4297 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4298 SCTP_TCB_UNLOCK(stcb);
4301 case SCTP_CONNECT_X:
4302 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4303 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4307 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4309 case SCTP_CONNECT_X_DELAYED:
4310 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4311 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4315 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4317 case SCTP_CONNECT_X_COMPLETE:
4319 struct sockaddr *sa;
4320 struct sctp_nets *net;
4322 /* FIXME MT: check correct? */
4323 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4326 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4327 SCTP_INP_RLOCK(inp);
4328 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4330 SCTP_TCB_LOCK(stcb);
4331 net = sctp_findnet(stcb, sa);
4333 SCTP_INP_RUNLOCK(inp);
4336 * We increment here since
4337 * sctp_findassociation_ep_addr() wil do a
4338 * decrement if it finds the stcb as long as
4339 * the locked tcb (last argument) is NOT a
4342 SCTP_INP_INCR_REF(inp);
4343 stcb = sctp_findassociation_ep_addr(&inp, sa, &net, NULL, NULL);
4345 SCTP_INP_DECR_REF(inp);
4350 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4354 if (stcb->asoc.delayed_connection == 1) {
4355 stcb->asoc.delayed_connection = 0;
4356 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4357 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4358 stcb->asoc.primary_destination,
4359 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
4360 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4363 * already expired or did not use delayed
4366 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4369 SCTP_TCB_UNLOCK(stcb);
4372 case SCTP_MAX_BURST:
4374 struct sctp_assoc_value *av;
4376 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4377 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4380 stcb->asoc.max_burst = av->assoc_value;
4381 SCTP_TCB_UNLOCK(stcb);
4383 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4384 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4385 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4386 (av->assoc_id == SCTP_ALL_ASSOC)) {
4387 SCTP_INP_WLOCK(inp);
4388 inp->sctp_ep.max_burst = av->assoc_value;
4389 SCTP_INP_WUNLOCK(inp);
4391 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4392 (av->assoc_id == SCTP_ALL_ASSOC)) {
4393 SCTP_INP_RLOCK(inp);
4394 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4395 SCTP_TCB_LOCK(stcb);
4396 stcb->asoc.max_burst = av->assoc_value;
4397 SCTP_TCB_UNLOCK(stcb);
4399 SCTP_INP_RUNLOCK(inp);
4406 struct sctp_assoc_value *av;
4409 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4410 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4412 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4413 ovh = SCTP_MED_OVERHEAD;
4415 ovh = SCTP_MED_V4_OVERHEAD;
4418 if (av->assoc_value) {
4419 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4421 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4423 SCTP_TCB_UNLOCK(stcb);
4425 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4426 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4427 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4428 SCTP_INP_WLOCK(inp);
4430 * FIXME MT: I think this is not in
4431 * tune with the API ID
4433 if (av->assoc_value) {
4434 inp->sctp_frag_point = (av->assoc_value + ovh);
4436 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4438 SCTP_INP_WUNLOCK(inp);
4440 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4448 struct sctp_event_subscribe *events;
4450 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4452 SCTP_INP_WLOCK(inp);
4453 if (events->sctp_data_io_event) {
4454 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4456 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4459 if (events->sctp_association_event) {
4460 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4462 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4465 if (events->sctp_address_event) {
4466 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4468 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4471 if (events->sctp_send_failure_event) {
4472 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4474 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4477 if (events->sctp_peer_error_event) {
4478 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4480 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4483 if (events->sctp_shutdown_event) {
4484 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4486 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4489 if (events->sctp_partial_delivery_event) {
4490 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4492 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4495 if (events->sctp_adaptation_layer_event) {
4496 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4498 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4501 if (events->sctp_authentication_event) {
4502 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4504 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4507 if (events->sctp_sender_dry_event) {
4508 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
4510 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
4513 if (events->sctp_stream_reset_event) {
4514 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4516 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4518 SCTP_INP_WUNLOCK(inp);
4520 SCTP_INP_RLOCK(inp);
4521 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4522 SCTP_TCB_LOCK(stcb);
4523 if (events->sctp_association_event) {
4524 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4526 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4528 if (events->sctp_address_event) {
4529 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4531 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
4533 if (events->sctp_send_failure_event) {
4534 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4536 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4538 if (events->sctp_peer_error_event) {
4539 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4541 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
4543 if (events->sctp_shutdown_event) {
4544 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4546 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4548 if (events->sctp_partial_delivery_event) {
4549 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4551 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
4553 if (events->sctp_adaptation_layer_event) {
4554 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4556 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4558 if (events->sctp_authentication_event) {
4559 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4561 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
4563 if (events->sctp_sender_dry_event) {
4564 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4566 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
4568 if (events->sctp_stream_reset_event) {
4569 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4571 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
4573 SCTP_TCB_UNLOCK(stcb);
4576 * Send up the sender dry event only for 1-to-1
4579 if (events->sctp_sender_dry_event) {
4580 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4581 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
4582 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4584 SCTP_TCB_LOCK(stcb);
4585 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
4586 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
4587 (stcb->asoc.stream_queue_cnt == 0)) {
4588 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
4590 SCTP_TCB_UNLOCK(stcb);
4594 SCTP_INP_RUNLOCK(inp);
4597 case SCTP_ADAPTATION_LAYER:
4599 struct sctp_setadaptation *adap_bits;
4601 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
4602 SCTP_INP_WLOCK(inp);
4603 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
4604 SCTP_INP_WUNLOCK(inp);
4608 case SCTP_SET_INITIAL_DBG_SEQ:
4612 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
4613 SCTP_INP_WLOCK(inp);
4614 inp->sctp_ep.initial_sequence_debug = *vvv;
4615 SCTP_INP_WUNLOCK(inp);
4619 case SCTP_DEFAULT_SEND_PARAM:
4621 struct sctp_sndrcvinfo *s_info;
4623 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
4624 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
4627 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4628 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4630 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4633 SCTP_TCB_UNLOCK(stcb);
4635 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4636 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4637 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
4638 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4639 SCTP_INP_WLOCK(inp);
4640 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
4641 SCTP_INP_WUNLOCK(inp);
4643 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
4644 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
4645 SCTP_INP_RLOCK(inp);
4646 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4647 SCTP_TCB_LOCK(stcb);
4648 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
4649 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
4651 SCTP_TCB_UNLOCK(stcb);
4653 SCTP_INP_RUNLOCK(inp);
4658 case SCTP_PEER_ADDR_PARAMS:
4660 struct sctp_paddrparams *paddrp;
4661 struct sctp_nets *net;
4663 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
4664 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
4667 net = sctp_findnet(stcb, (struct sockaddr *)&paddrp->spp_address);
4670 * We increment here since
4671 * sctp_findassociation_ep_addr() wil do a
4672 * decrement if it finds the stcb as long as
4673 * the locked tcb (last argument) is NOT a
4676 SCTP_INP_INCR_REF(inp);
4677 stcb = sctp_findassociation_ep_addr(&inp,
4678 (struct sockaddr *)&paddrp->spp_address,
4681 SCTP_INP_DECR_REF(inp);
4684 if (stcb && (net == NULL)) {
4685 struct sockaddr *sa;
4687 sa = (struct sockaddr *)&paddrp->spp_address;
4689 if (sa->sa_family == AF_INET) {
4691 struct sockaddr_in *sin;
4693 sin = (struct sockaddr_in *)sa;
4694 if (sin->sin_addr.s_addr) {
4695 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4696 SCTP_TCB_UNLOCK(stcb);
4703 if (sa->sa_family == AF_INET6) {
4704 struct sockaddr_in6 *sin6;
4706 sin6 = (struct sockaddr_in6 *)sa;
4707 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
4708 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4709 SCTP_TCB_UNLOCK(stcb);
4716 error = EAFNOSUPPORT;
4717 SCTP_TCB_UNLOCK(stcb);
4718 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4723 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
4725 SCTP_TCB_UNLOCK(stcb);
4726 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4729 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
4731 SCTP_TCB_UNLOCK(stcb);
4732 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4736 /************************TCB SPECIFIC SET ******************/
4738 * do we change the timer for HB, we run
4743 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4744 ovh = SCTP_MED_OVERHEAD;
4746 ovh = SCTP_MED_V4_OVERHEAD;
4749 /* network sets ? */
4751 /************************NET SPECIFIC SET ******************/
4752 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4753 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
4754 !(net->dest_state & SCTP_ADDR_NOHB)) {
4755 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4756 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4758 net->dest_state |= SCTP_ADDR_NOHB;
4760 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4761 if (paddrp->spp_hbinterval) {
4762 net->heart_beat_delay = paddrp->spp_hbinterval;
4763 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4764 net->heart_beat_delay = 0;
4766 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4767 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4768 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4769 net->dest_state &= ~SCTP_ADDR_NOHB;
4771 if (paddrp->spp_flags & SPP_HB_DEMAND) {
4773 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4774 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
4775 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4777 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4778 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4779 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4780 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4782 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4783 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4784 net->mtu = paddrp->spp_pathmtu + ovh;
4785 if (net->mtu < stcb->asoc.smallest_mtu) {
4786 sctp_pathmtu_adjustment(stcb, net->mtu);
4790 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4791 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4792 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4794 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4796 if (paddrp->spp_pathmaxrxt) {
4797 if (net->dest_state & SCTP_ADDR_PF) {
4798 if (net->error_count > paddrp->spp_pathmaxrxt) {
4799 net->dest_state &= ~SCTP_ADDR_PF;
4802 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4803 (net->error_count > net->pf_threshold)) {
4804 net->dest_state |= SCTP_ADDR_PF;
4805 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4806 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4807 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4810 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4811 if (net->error_count > paddrp->spp_pathmaxrxt) {
4812 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4813 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4816 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4817 net->dest_state |= SCTP_ADDR_REACHABLE;
4818 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4821 net->failure_threshold = paddrp->spp_pathmaxrxt;
4823 if (paddrp->spp_flags & SPP_DSCP) {
4824 net->dscp = paddrp->spp_dscp & 0xfc;
4828 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4829 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4830 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4831 net->flowlabel |= 0x80000000;
4836 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
4837 if (paddrp->spp_pathmaxrxt) {
4838 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
4839 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4840 if (net->dest_state & SCTP_ADDR_PF) {
4841 if (net->error_count > paddrp->spp_pathmaxrxt) {
4842 net->dest_state &= ~SCTP_ADDR_PF;
4845 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
4846 (net->error_count > net->pf_threshold)) {
4847 net->dest_state |= SCTP_ADDR_PF;
4848 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
4849 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
4850 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
4853 if (net->dest_state & SCTP_ADDR_REACHABLE) {
4854 if (net->error_count > paddrp->spp_pathmaxrxt) {
4855 net->dest_state &= ~SCTP_ADDR_REACHABLE;
4856 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4859 if (net->error_count <= paddrp->spp_pathmaxrxt) {
4860 net->dest_state |= SCTP_ADDR_REACHABLE;
4861 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
4864 net->failure_threshold = paddrp->spp_pathmaxrxt;
4867 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4868 if (paddrp->spp_hbinterval) {
4869 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
4870 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4871 stcb->asoc.heart_beat_delay = 0;
4873 /* Turn back on the timer */
4874 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4875 if (paddrp->spp_hbinterval) {
4876 net->heart_beat_delay = paddrp->spp_hbinterval;
4877 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4878 net->heart_beat_delay = 0;
4880 if (net->dest_state & SCTP_ADDR_NOHB) {
4881 net->dest_state &= ~SCTP_ADDR_NOHB;
4883 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
4884 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4885 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
4887 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4889 if (paddrp->spp_flags & SPP_HB_DISABLE) {
4890 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4891 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
4892 net->dest_state |= SCTP_ADDR_NOHB;
4893 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
4894 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4898 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4900 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
4901 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4902 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4903 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
4904 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
4906 net->dest_state |= SCTP_ADDR_NO_PMTUD;
4907 if (paddrp->spp_pathmtu > SCTP_DEFAULT_MINSEGMENT) {
4908 net->mtu = paddrp->spp_pathmtu + ovh;
4909 if (net->mtu < stcb->asoc.smallest_mtu) {
4910 sctp_pathmtu_adjustment(stcb, net->mtu);
4914 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4916 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4917 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4918 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
4919 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
4921 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
4923 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4925 if (paddrp->spp_flags & SPP_DSCP) {
4926 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4927 net->dscp = paddrp->spp_dscp & 0xfc;
4930 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
4931 stcb->asoc.default_dscp |= 0x01;
4934 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4935 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
4936 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4937 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4938 net->flowlabel |= 0x80000000;
4941 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4942 stcb->asoc.default_flowlabel |= 0x80000000;
4946 SCTP_TCB_UNLOCK(stcb);
4948 /************************NO TCB, SET TO default stuff ******************/
4949 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4950 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4951 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
4952 SCTP_INP_WLOCK(inp);
4954 * For the TOS/FLOWLABEL stuff you
4955 * set it with the options on the
4958 if (paddrp->spp_pathmaxrxt) {
4959 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
4961 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
4962 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4963 else if (paddrp->spp_hbinterval) {
4964 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
4965 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
4966 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4968 if (paddrp->spp_flags & SPP_HB_ENABLE) {
4969 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
4970 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
4971 } else if (paddrp->spp_hbinterval) {
4972 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
4974 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4975 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
4976 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
4978 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
4979 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4980 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
4981 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
4983 if (paddrp->spp_flags & SPP_DSCP) {
4984 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
4985 inp->sctp_ep.default_dscp |= 0x01;
4988 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
4989 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4990 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
4991 inp->sctp_ep.default_flowlabel |= 0x80000000;
4995 SCTP_INP_WUNLOCK(inp);
4997 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5005 struct sctp_rtoinfo *srto;
5006 uint32_t new_init, new_min, new_max;
5008 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5009 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5012 if (srto->srto_initial)
5013 new_init = srto->srto_initial;
5015 new_init = stcb->asoc.initial_rto;
5017 new_max = srto->srto_max;
5019 new_max = stcb->asoc.maxrto;
5021 new_min = srto->srto_min;
5023 new_min = stcb->asoc.minrto;
5024 if ((new_min <= new_init) && (new_init <= new_max)) {
5025 stcb->asoc.initial_rto = new_init;
5026 stcb->asoc.maxrto = new_max;
5027 stcb->asoc.minrto = new_min;
5029 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5032 SCTP_TCB_UNLOCK(stcb);
5034 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5035 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5036 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5037 SCTP_INP_WLOCK(inp);
5038 if (srto->srto_initial)
5039 new_init = srto->srto_initial;
5041 new_init = inp->sctp_ep.initial_rto;
5043 new_max = srto->srto_max;
5045 new_max = inp->sctp_ep.sctp_maxrto;
5047 new_min = srto->srto_min;
5049 new_min = inp->sctp_ep.sctp_minrto;
5050 if ((new_min <= new_init) && (new_init <= new_max)) {
5051 inp->sctp_ep.initial_rto = new_init;
5052 inp->sctp_ep.sctp_maxrto = new_max;
5053 inp->sctp_ep.sctp_minrto = new_min;
5055 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5058 SCTP_INP_WUNLOCK(inp);
5060 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5066 case SCTP_ASSOCINFO:
5068 struct sctp_assocparams *sasoc;
5070 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5071 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5072 if (sasoc->sasoc_cookie_life) {
5073 /* boundary check the cookie life */
5074 if (sasoc->sasoc_cookie_life < 1000)
5075 sasoc->sasoc_cookie_life = 1000;
5076 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5077 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5081 if (sasoc->sasoc_asocmaxrxt)
5082 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5083 if (sasoc->sasoc_cookie_life) {
5084 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5086 SCTP_TCB_UNLOCK(stcb);
5088 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5089 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5090 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5091 SCTP_INP_WLOCK(inp);
5092 if (sasoc->sasoc_asocmaxrxt)
5093 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5094 if (sasoc->sasoc_cookie_life) {
5095 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5097 SCTP_INP_WUNLOCK(inp);
5099 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5107 struct sctp_initmsg *sinit;
5109 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5110 SCTP_INP_WLOCK(inp);
5111 if (sinit->sinit_num_ostreams)
5112 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5114 if (sinit->sinit_max_instreams)
5115 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5117 if (sinit->sinit_max_attempts)
5118 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5120 if (sinit->sinit_max_init_timeo)
5121 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5122 SCTP_INP_WUNLOCK(inp);
5125 case SCTP_PRIMARY_ADDR:
5127 struct sctp_setprim *spa;
5128 struct sctp_nets *net;
5130 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5131 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5135 net = sctp_findnet(stcb, (struct sockaddr *)&spa->ssp_addr);
5138 * We increment here since
5139 * sctp_findassociation_ep_addr() wil do a
5140 * decrement if it finds the stcb as long as
5141 * the locked tcb (last argument) is NOT a
5144 SCTP_INP_INCR_REF(inp);
5145 stcb = sctp_findassociation_ep_addr(&inp,
5146 (struct sockaddr *)&spa->ssp_addr,
5149 SCTP_INP_DECR_REF(inp);
5153 if ((stcb) && (net)) {
5154 if ((net != stcb->asoc.primary_destination) &&
5155 (!(net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
5156 /* Ok we need to set it */
5157 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5158 if ((stcb->asoc.alternate) &&
5159 (!(net->dest_state & SCTP_ADDR_PF)) &&
5160 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5161 sctp_free_remote_addr(stcb->asoc.alternate);
5162 stcb->asoc.alternate = NULL;
5167 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5171 SCTP_TCB_UNLOCK(stcb);
5175 case SCTP_SET_DYNAMIC_PRIMARY:
5177 union sctp_sockstore *ss;
5179 error = priv_check(curthread,
5180 PRIV_NETINET_RESERVEDPORT);
5184 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5185 /* SUPER USER CHECK? */
5186 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5189 case SCTP_SET_PEER_PRIMARY_ADDR:
5191 struct sctp_setpeerprim *sspp;
5193 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5194 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5196 struct sctp_ifa *ifa;
5198 ifa = sctp_find_ifa_by_addr((struct sockaddr *)&sspp->sspp_addr,
5199 stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5201 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5205 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5207 * Must validate the ifa found is in
5210 struct sctp_laddr *laddr;
5213 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5214 if (laddr->ifa == NULL) {
5215 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5219 if (laddr->ifa == ifa) {
5225 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5230 if (sctp_set_primary_ip_address_sa(stcb,
5231 (struct sockaddr *)&sspp->sspp_addr) != 0) {
5232 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5236 SCTP_TCB_UNLOCK(stcb);
5238 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5243 case SCTP_BINDX_ADD_ADDR:
5245 struct sctp_getaddresses *addrs;
5249 td = (struct thread *)p;
5250 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5253 if (addrs->addr->sa_family == AF_INET) {
5254 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
5256 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5260 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5261 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5267 if (addrs->addr->sa_family == AF_INET6) {
5268 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
5270 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5274 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5275 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5276 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5282 error = EAFNOSUPPORT;
5285 sctp_bindx_add_address(so, inp, addrs->addr,
5286 addrs->sget_assoc_id, vrf_id,
5290 case SCTP_BINDX_REM_ADDR:
5292 struct sctp_getaddresses *addrs;
5296 td = (struct thread *)p;
5298 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5300 if (addrs->addr->sa_family == AF_INET) {
5301 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in);
5303 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5307 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5308 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5314 if (addrs->addr->sa_family == AF_INET6) {
5315 sz = sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6);
5317 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5322 (error = prison_local_ip6(td->td_ucred,
5323 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5324 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5325 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5331 error = EAFNOSUPPORT;
5334 sctp_bindx_delete_address(inp, addrs->addr,
5335 addrs->sget_assoc_id, vrf_id,
5341 struct sctp_event *event;
5342 uint32_t event_type;
5344 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5345 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5346 switch (event->se_type) {
5347 case SCTP_ASSOC_CHANGE:
5348 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5350 case SCTP_PEER_ADDR_CHANGE:
5351 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5353 case SCTP_REMOTE_ERROR:
5354 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5356 case SCTP_SEND_FAILED:
5357 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5359 case SCTP_SHUTDOWN_EVENT:
5360 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5362 case SCTP_ADAPTATION_INDICATION:
5363 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5365 case SCTP_PARTIAL_DELIVERY_EVENT:
5366 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5368 case SCTP_AUTHENTICATION_EVENT:
5369 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5371 case SCTP_STREAM_RESET_EVENT:
5372 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5374 case SCTP_SENDER_DRY_EVENT:
5375 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5377 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5379 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5384 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5388 if (event_type > 0) {
5391 sctp_stcb_feature_on(inp, stcb, event_type);
5392 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
5393 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5394 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5395 (stcb->asoc.stream_queue_cnt == 0)) {
5396 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5400 sctp_stcb_feature_off(inp, stcb, event_type);
5402 SCTP_TCB_UNLOCK(stcb);
5405 * We don't want to send up a storm
5406 * of events, so return an error for
5409 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
5410 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
5411 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
5412 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
5413 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
5414 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5418 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5419 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5420 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
5421 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5422 SCTP_INP_WLOCK(inp);
5424 sctp_feature_on(inp, event_type);
5426 sctp_feature_off(inp, event_type);
5428 SCTP_INP_WUNLOCK(inp);
5430 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
5431 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
5432 SCTP_INP_RLOCK(inp);
5433 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5434 SCTP_TCB_LOCK(stcb);
5436 sctp_stcb_feature_on(inp, stcb, event_type);
5438 sctp_stcb_feature_off(inp, stcb, event_type);
5440 SCTP_TCB_UNLOCK(stcb);
5442 SCTP_INP_RUNLOCK(inp);
5448 case SCTP_RECVRCVINFO:
5452 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5453 SCTP_INP_WLOCK(inp);
5455 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5457 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
5459 SCTP_INP_WUNLOCK(inp);
5462 case SCTP_RECVNXTINFO:
5466 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
5467 SCTP_INP_WLOCK(inp);
5469 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5471 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
5473 SCTP_INP_WUNLOCK(inp);
5476 case SCTP_DEFAULT_SNDINFO:
5478 struct sctp_sndinfo *info;
5481 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
5482 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
5485 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5486 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5487 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5488 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5489 stcb->asoc.def_send.sinfo_flags |= policy;
5490 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5491 stcb->asoc.def_send.sinfo_context = info->snd_context;
5493 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5496 SCTP_TCB_UNLOCK(stcb);
5498 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5499 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5500 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
5501 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5502 SCTP_INP_WLOCK(inp);
5503 inp->def_send.sinfo_stream = info->snd_sid;
5504 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
5505 inp->def_send.sinfo_flags = info->snd_flags;
5506 inp->def_send.sinfo_flags |= policy;
5507 inp->def_send.sinfo_ppid = info->snd_ppid;
5508 inp->def_send.sinfo_context = info->snd_context;
5509 SCTP_INP_WUNLOCK(inp);
5511 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
5512 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
5513 SCTP_INP_RLOCK(inp);
5514 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5515 SCTP_TCB_LOCK(stcb);
5516 if (info->snd_sid < stcb->asoc.streamoutcnt) {
5517 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
5518 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
5519 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
5520 stcb->asoc.def_send.sinfo_flags |= policy;
5521 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
5522 stcb->asoc.def_send.sinfo_context = info->snd_context;
5524 SCTP_TCB_UNLOCK(stcb);
5526 SCTP_INP_RUNLOCK(inp);
5531 case SCTP_DEFAULT_PRINFO:
5533 struct sctp_default_prinfo *info;
5535 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
5536 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
5538 if (PR_SCTP_INVALID_POLICY(info->pr_policy)) {
5539 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5544 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5545 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5546 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5547 SCTP_TCB_UNLOCK(stcb);
5549 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5550 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5551 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
5552 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5553 SCTP_INP_WLOCK(inp);
5554 inp->def_send.sinfo_flags &= 0xfff0;
5555 inp->def_send.sinfo_flags |= info->pr_policy;
5556 inp->def_send.sinfo_timetolive = info->pr_value;
5557 SCTP_INP_WUNLOCK(inp);
5559 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
5560 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
5561 SCTP_INP_RLOCK(inp);
5562 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5563 SCTP_TCB_LOCK(stcb);
5564 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
5565 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
5566 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
5567 SCTP_TCB_UNLOCK(stcb);
5569 SCTP_INP_RUNLOCK(inp);
5574 case SCTP_PEER_ADDR_THLDS:
5575 /* Applies to the specific association */
5577 struct sctp_paddrthlds *thlds;
5578 struct sctp_nets *net;
5580 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
5581 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
5584 net = sctp_findnet(stcb, (struct sockaddr *)&thlds->spt_assoc_id);
5587 * We increment here since
5588 * sctp_findassociation_ep_addr() wil do a
5589 * decrement if it finds the stcb as long as
5590 * the locked tcb (last argument) is NOT a
5593 SCTP_INP_INCR_REF(inp);
5594 stcb = sctp_findassociation_ep_addr(&inp,
5595 (struct sockaddr *)&thlds->spt_assoc_id,
5598 SCTP_INP_DECR_REF(inp);
5601 if (stcb && (net == NULL)) {
5602 struct sockaddr *sa;
5604 sa = (struct sockaddr *)&thlds->spt_assoc_id;
5606 if (sa->sa_family == AF_INET) {
5608 struct sockaddr_in *sin;
5610 sin = (struct sockaddr_in *)sa;
5611 if (sin->sin_addr.s_addr) {
5612 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5613 SCTP_TCB_UNLOCK(stcb);
5620 if (sa->sa_family == AF_INET6) {
5621 struct sockaddr_in6 *sin6;
5623 sin6 = (struct sockaddr_in6 *)sa;
5624 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5625 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5626 SCTP_TCB_UNLOCK(stcb);
5633 error = EAFNOSUPPORT;
5634 SCTP_TCB_UNLOCK(stcb);
5635 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5641 if (net->dest_state & SCTP_ADDR_PF) {
5642 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5643 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5644 net->dest_state &= ~SCTP_ADDR_PF;
5647 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5648 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5649 net->dest_state |= SCTP_ADDR_PF;
5650 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5651 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5652 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5655 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5656 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5657 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5658 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5661 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5662 net->dest_state |= SCTP_ADDR_REACHABLE;
5663 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5666 net->failure_threshold = thlds->spt_pathmaxrxt;
5667 net->pf_threshold = thlds->spt_pathpfthld;
5669 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5670 if (net->dest_state & SCTP_ADDR_PF) {
5671 if ((net->failure_threshold > thlds->spt_pathmaxrxt) ||
5672 (net->failure_threshold <= thlds->spt_pathpfthld)) {
5673 net->dest_state &= ~SCTP_ADDR_PF;
5676 if ((net->failure_threshold > thlds->spt_pathpfthld) &&
5677 (net->failure_threshold <= thlds->spt_pathmaxrxt)) {
5678 net->dest_state |= SCTP_ADDR_PF;
5679 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5680 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_TIMER + SCTP_LOC_3);
5681 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5684 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5685 if (net->failure_threshold > thlds->spt_pathmaxrxt) {
5686 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5687 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5690 if (net->failure_threshold <= thlds->spt_pathmaxrxt) {
5691 net->dest_state |= SCTP_ADDR_REACHABLE;
5692 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, SCTP_RESPONSE_TO_USER_REQ, net, SCTP_SO_LOCKED);
5695 net->failure_threshold = thlds->spt_pathmaxrxt;
5696 net->pf_threshold = thlds->spt_pathpfthld;
5698 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
5699 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
5702 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5703 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5704 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
5705 SCTP_INP_WLOCK(inp);
5706 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
5707 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
5708 SCTP_INP_WUNLOCK(inp);
5710 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5716 case SCTP_REMOTE_UDP_ENCAPS_PORT:
5718 struct sctp_udpencaps *encaps;
5719 struct sctp_nets *net;
5721 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
5722 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
5724 net = sctp_findnet(stcb, (struct sockaddr *)&encaps->sue_address);
5727 * We increment here since
5728 * sctp_findassociation_ep_addr() wil do a
5729 * decrement if it finds the stcb as long as
5730 * the locked tcb (last argument) is NOT a
5734 SCTP_INP_INCR_REF(inp);
5735 stcb = sctp_findassociation_ep_addr(&inp, (struct sockaddr *)&encaps->sue_address, &net, NULL, NULL);
5737 SCTP_INP_DECR_REF(inp);
5740 if (stcb && (net == NULL)) {
5741 struct sockaddr *sa;
5743 sa = (struct sockaddr *)&encaps->sue_address;
5745 if (sa->sa_family == AF_INET) {
5747 struct sockaddr_in *sin;
5749 sin = (struct sockaddr_in *)sa;
5750 if (sin->sin_addr.s_addr) {
5751 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5752 SCTP_TCB_UNLOCK(stcb);
5759 if (sa->sa_family == AF_INET6) {
5760 struct sockaddr_in6 *sin6;
5762 sin6 = (struct sockaddr_in6 *)sa;
5763 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5764 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5765 SCTP_TCB_UNLOCK(stcb);
5772 error = EAFNOSUPPORT;
5773 SCTP_TCB_UNLOCK(stcb);
5774 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5780 net->port = encaps->sue_port;
5782 stcb->asoc.port = encaps->sue_port;
5784 SCTP_TCB_UNLOCK(stcb);
5786 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5787 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5788 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
5789 SCTP_INP_WLOCK(inp);
5790 inp->sctp_ep.port = encaps->sue_port;
5791 SCTP_INP_WUNLOCK(inp);
5793 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5800 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
5801 error = ENOPROTOOPT;
5803 } /* end switch (opt) */
5808 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
5810 void *optval = NULL;
5812 struct sctp_inpcb *inp;
5816 if (sopt->sopt_level != IPPROTO_SCTP) {
5817 /* wrong proto level... send back up to IP */
5819 if (INP_CHECK_SOCKAF(so, AF_INET6))
5820 error = ip6_ctloutput(so, sopt);
5822 #if defined(INET) && defined (INET6)
5826 error = ip_ctloutput(so, sopt);
5830 inp = (struct sctp_inpcb *)so->so_pcb;
5831 optsize = sopt->sopt_valsize;
5833 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
5834 if (optval == NULL) {
5835 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
5838 error = sooptcopyin(sopt, optval, optsize, optsize);
5840 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5844 p = (void *)sopt->sopt_td;
5845 if (sopt->sopt_dir == SOPT_SET) {
5846 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
5847 } else if (sopt->sopt_dir == SOPT_GET) {
5848 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
5850 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5853 if ((error == 0) && (optval != NULL)) {
5854 error = sooptcopyout(sopt, optval, optsize);
5855 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5856 } else if (optval != NULL) {
5857 SCTP_FREE(optval, SCTP_M_SOCKOPT);
5865 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
5868 int create_lock_on = 0;
5870 struct sctp_inpcb *inp;
5871 struct sctp_tcb *stcb = NULL;
5873 inp = (struct sctp_inpcb *)so->so_pcb;
5875 /* I made the same as TCP since we are not setup? */
5876 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5877 return (ECONNRESET);
5880 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5883 switch (addr->sa_family) {
5887 struct sockaddr_in6 *sin6p;
5889 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
5890 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5893 sin6p = (struct sockaddr_in6 *)addr;
5894 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
5895 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5904 struct sockaddr_in *sinp;
5906 if (addr->sa_len != sizeof(struct sockaddr_in)) {
5907 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5910 sinp = (struct sockaddr_in *)addr;
5911 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
5912 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5919 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
5920 return (EAFNOSUPPORT);
5922 SCTP_INP_INCR_REF(inp);
5923 SCTP_ASOC_CREATE_LOCK(inp);
5927 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
5928 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
5929 /* Should I really unlock ? */
5930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
5935 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
5936 (addr->sa_family == AF_INET6)) {
5937 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5942 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
5943 SCTP_PCB_FLAGS_UNBOUND) {
5944 /* Bind a ephemeral port */
5945 error = sctp_inpcb_bind(so, NULL, NULL, p);
5950 /* Now do we connect? */
5951 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
5952 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
5953 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5957 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
5958 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
5959 /* We are already connected AND the TCP model */
5960 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
5964 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
5965 SCTP_INP_RLOCK(inp);
5966 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5967 SCTP_INP_RUNLOCK(inp);
5970 * We increment here since sctp_findassociation_ep_addr()
5971 * will do a decrement if it finds the stcb as long as the
5972 * locked tcb (last argument) is NOT a TCB.. aka NULL.
5974 SCTP_INP_INCR_REF(inp);
5975 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
5977 SCTP_INP_DECR_REF(inp);
5979 SCTP_TCB_UNLOCK(stcb);
5983 /* Already have or am bring up an association */
5984 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
5988 vrf_id = inp->def_vrf_id;
5989 /* We are GOOD to go */
5990 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
5992 /* Gak! no memory */
5995 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
5996 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
5997 /* Set the connected flag so we can queue data */
6000 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6001 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6003 /* initialize authentication parameters for the assoc */
6004 sctp_initialize_auth_params(inp, stcb);
6006 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6007 SCTP_TCB_UNLOCK(stcb);
6009 if (create_lock_on) {
6010 SCTP_ASOC_CREATE_UNLOCK(inp);
6012 SCTP_INP_DECR_REF(inp);
6019 sctp_listen(struct socket *so, int backlog, struct thread *p)
6022 * Note this module depends on the protocol processing being called
6023 * AFTER any socket level flags and backlog are applied to the
6024 * socket. The traditional way that the socket flags are applied is
6025 * AFTER protocol processing. We have made a change to the
6026 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6027 * place if the socket API for SCTP is to work properly.
6031 struct sctp_inpcb *inp;
6033 inp = (struct sctp_inpcb *)so->so_pcb;
6035 /* I made the same as TCP since we are not setup? */
6036 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6037 return (ECONNRESET);
6039 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6040 /* See if we have a listener */
6041 struct sctp_inpcb *tinp;
6042 union sctp_sockstore store, *sp;
6045 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6047 struct sctp_laddr *laddr;
6049 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6050 memcpy(&store, &laddr->ifa->address, sizeof(store));
6051 switch (sp->sa.sa_family) {
6054 sp->sin.sin_port = inp->sctp_lport;
6059 sp->sin6.sin6_port = inp->sctp_lport;
6065 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6066 if (tinp && (tinp != inp) &&
6067 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6068 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6069 (tinp->sctp_socket->so_qlimit)) {
6071 * we have a listener already and
6074 SCTP_INP_DECR_REF(tinp);
6075 return (EADDRINUSE);
6077 SCTP_INP_DECR_REF(tinp);
6081 /* Setup a local addr bound all */
6082 memset(&store, 0, sizeof(store));
6083 switch (sp->sa.sa_family) {
6086 store.sin.sin_port = inp->sctp_lport;
6091 sp->sin6.sin6_port = inp->sctp_lport;
6098 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
6099 store.sa.sa_family = AF_INET6;
6100 store.sa.sa_len = sizeof(struct sockaddr_in6);
6104 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
6105 store.sa.sa_family = AF_INET;
6106 store.sa.sa_len = sizeof(struct sockaddr_in);
6109 tinp = sctp_pcb_findep(&sp->sa, 0, 0, inp->def_vrf_id);
6110 if (tinp && (tinp != inp) &&
6111 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
6112 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
6113 (tinp->sctp_socket->so_qlimit)) {
6115 * we have a listener already and its not
6118 SCTP_INP_DECR_REF(tinp);
6119 return (EADDRINUSE);
6121 SCTP_INP_DECR_REF(inp);
6125 SCTP_INP_RLOCK(inp);
6126 #ifdef SCTP_LOCK_LOGGING
6127 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
6128 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
6132 error = solisten_proto_check(so);
6135 SCTP_INP_RUNLOCK(inp);
6138 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
6139 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
6141 * The unlucky case - We are in the tcp pool with this guy.
6142 * - Someone else is in the main inp slot. - We must move
6143 * this guy (the listener) to the main slot - We must then
6144 * move the guy that was listener to the TCP Pool.
6146 if (sctp_swap_inpcb_for_listen(inp)) {
6150 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6151 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6152 /* We are already connected AND the TCP model */
6154 SCTP_INP_RUNLOCK(inp);
6156 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6157 return (EADDRINUSE);
6159 SCTP_INP_RUNLOCK(inp);
6160 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
6161 /* We must do a bind. */
6163 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
6164 /* bind error, probably perm */
6169 /* It appears for 7.0 and on, we must always call this. */
6170 solisten_proto(so, backlog);
6171 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6172 /* remove the ACCEPTCONN flag for one-to-many sockets */
6173 so->so_options &= ~SO_ACCEPTCONN;
6176 /* turning off listen */
6177 so->so_options &= ~SO_ACCEPTCONN;
6183 static int sctp_defered_wakeup_cnt = 0;
6186 sctp_accept(struct socket *so, struct sockaddr **addr)
6188 struct sctp_tcb *stcb;
6189 struct sctp_inpcb *inp;
6190 union sctp_sockstore store;
6196 inp = (struct sctp_inpcb *)so->so_pcb;
6199 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6200 return (ECONNRESET);
6202 SCTP_INP_RLOCK(inp);
6203 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
6204 SCTP_INP_RUNLOCK(inp);
6205 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
6206 return (EOPNOTSUPP);
6208 if (so->so_state & SS_ISDISCONNECTED) {
6209 SCTP_INP_RUNLOCK(inp);
6210 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
6211 return (ECONNABORTED);
6213 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6215 SCTP_INP_RUNLOCK(inp);
6216 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6217 return (ECONNRESET);
6219 SCTP_TCB_LOCK(stcb);
6220 SCTP_INP_RUNLOCK(inp);
6221 store = stcb->asoc.primary_destination->ro._l_addr;
6222 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
6223 SCTP_TCB_UNLOCK(stcb);
6224 switch (store.sa.sa_family) {
6228 struct sockaddr_in *sin;
6230 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6233 sin->sin_family = AF_INET;
6234 sin->sin_len = sizeof(*sin);
6235 sin->sin_port = ((struct sockaddr_in *)&store)->sin_port;
6236 sin->sin_addr = ((struct sockaddr_in *)&store)->sin_addr;
6237 *addr = (struct sockaddr *)sin;
6244 struct sockaddr_in6 *sin6;
6246 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
6249 sin6->sin6_family = AF_INET6;
6250 sin6->sin6_len = sizeof(*sin6);
6251 sin6->sin6_port = ((struct sockaddr_in6 *)&store)->sin6_port;
6253 sin6->sin6_addr = ((struct sockaddr_in6 *)&store)->sin6_addr;
6254 if ((error = sa6_recoverscope(sin6)) != 0) {
6255 SCTP_FREE_SONAME(sin6);
6258 *addr = (struct sockaddr *)sin6;
6266 /* Wake any delayed sleep action */
6267 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
6268 SCTP_INP_WLOCK(inp);
6269 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
6270 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
6271 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
6272 SCTP_INP_WUNLOCK(inp);
6273 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
6274 if (sowriteable(inp->sctp_socket)) {
6275 sowwakeup_locked(inp->sctp_socket);
6277 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
6279 SCTP_INP_WLOCK(inp);
6281 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
6282 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
6283 SCTP_INP_WUNLOCK(inp);
6284 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
6285 if (soreadable(inp->sctp_socket)) {
6286 sctp_defered_wakeup_cnt++;
6287 sorwakeup_locked(inp->sctp_socket);
6289 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
6291 SCTP_INP_WLOCK(inp);
6293 SCTP_INP_WUNLOCK(inp);
6295 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
6296 SCTP_TCB_LOCK(stcb);
6297 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
6304 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
6306 struct sockaddr_in *sin;
6308 struct sctp_inpcb *inp;
6309 struct sctp_ifa *sctp_ifa;
6312 * Do the malloc first in case it blocks.
6314 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6317 sin->sin_family = AF_INET;
6318 sin->sin_len = sizeof(*sin);
6319 inp = (struct sctp_inpcb *)so->so_pcb;
6321 SCTP_FREE_SONAME(sin);
6322 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6323 return (ECONNRESET);
6325 SCTP_INP_RLOCK(inp);
6326 sin->sin_port = inp->sctp_lport;
6327 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
6328 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6329 struct sctp_tcb *stcb;
6330 struct sockaddr_in *sin_a;
6331 struct sctp_nets *net;
6334 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6340 SCTP_TCB_LOCK(stcb);
6341 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6342 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6344 /* this will make coverity happy */
6347 if (sin_a->sin_family == AF_INET) {
6352 if ((!fnd) || (sin_a == NULL)) {
6354 SCTP_TCB_UNLOCK(stcb);
6357 vrf_id = inp->def_vrf_id;
6358 sctp_ifa = sctp_source_address_selection(inp,
6360 (sctp_route_t *) & net->ro,
6363 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
6364 sctp_free_ifa(sctp_ifa);
6366 SCTP_TCB_UNLOCK(stcb);
6368 /* For the bound all case you get back 0 */
6370 sin->sin_addr.s_addr = 0;
6374 /* Take the first IPv4 address in the list */
6375 struct sctp_laddr *laddr;
6378 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6379 if (laddr->ifa->address.sa.sa_family == AF_INET) {
6380 struct sockaddr_in *sin_a;
6382 sin_a = (struct sockaddr_in *)&laddr->ifa->address.sa;
6383 sin->sin_addr = sin_a->sin_addr;
6389 SCTP_FREE_SONAME(sin);
6390 SCTP_INP_RUNLOCK(inp);
6391 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6395 SCTP_INP_RUNLOCK(inp);
6396 (*addr) = (struct sockaddr *)sin;
6401 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
6403 struct sockaddr_in *sin;
6405 struct sockaddr_in *sin_a;
6406 struct sctp_inpcb *inp;
6407 struct sctp_tcb *stcb;
6408 struct sctp_nets *net;
6410 /* Do the malloc first in case it blocks. */
6411 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
6414 sin->sin_family = AF_INET;
6415 sin->sin_len = sizeof(*sin);
6417 inp = (struct sctp_inpcb *)so->so_pcb;
6418 if ((inp == NULL) ||
6419 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
6420 /* UDP type and listeners will drop out here */
6421 SCTP_FREE_SONAME(sin);
6422 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
6425 SCTP_INP_RLOCK(inp);
6426 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6428 SCTP_TCB_LOCK(stcb);
6430 SCTP_INP_RUNLOCK(inp);
6432 SCTP_FREE_SONAME(sin);
6433 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6434 return (ECONNRESET);
6437 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6438 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
6439 if (sin_a->sin_family == AF_INET) {
6441 sin->sin_port = stcb->rport;
6442 sin->sin_addr = sin_a->sin_addr;
6446 SCTP_TCB_UNLOCK(stcb);
6448 /* No IPv4 address */
6449 SCTP_FREE_SONAME(sin);
6450 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
6453 (*addr) = (struct sockaddr *)sin;
6458 struct pr_usrreqs sctp_usrreqs = {
6459 .pru_abort = sctp_abort,
6460 .pru_accept = sctp_accept,
6461 .pru_attach = sctp_attach,
6462 .pru_bind = sctp_bind,
6463 .pru_connect = sctp_connect,
6464 .pru_control = in_control,
6465 .pru_close = sctp_close,
6466 .pru_detach = sctp_close,
6467 .pru_sopoll = sopoll_generic,
6468 .pru_flush = sctp_flush,
6469 .pru_disconnect = sctp_disconnect,
6470 .pru_listen = sctp_listen,
6471 .pru_peeraddr = sctp_peeraddr,
6472 .pru_send = sctp_sendm,
6473 .pru_shutdown = sctp_shutdown,
6474 .pru_sockaddr = sctp_ingetaddr,
6475 .pru_sosend = sctp_sosend,
6476 .pru_soreceive = sctp_soreceive