2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, 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 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <netinet/sctp_os.h>
38 #include <netinet/sctp_pcb.h>
39 #include <netinet/sctp_header.h>
40 #include <netinet/sctp_var.h>
42 #include <netinet6/sctp6_var.h>
44 #include <netinet/sctp_sysctl.h>
45 #include <netinet/sctp_output.h>
46 #include <netinet/sctp_uio.h>
47 #include <netinet/sctp_asconf.h>
48 #include <netinet/sctputil.h>
49 #include <netinet/sctp_indata.h>
50 #include <netinet/sctp_timer.h>
51 #include <netinet/sctp_auth.h>
52 #include <netinet/sctp_bsd_addr.h>
53 #include <netinet/udp.h>
57 extern struct sctp_cc_functions sctp_cc_functions[];
58 extern struct sctp_ss_functions sctp_ss_functions[];
65 /* Initialize and modify the sysctled variables */
67 if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE)
68 SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8);
70 * Allow a user to take no more than 1/2 the number of clusters or
71 * the SB_MAX whichever is smaller for the send window.
73 sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES));
74 SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj,
75 (((uint32_t) nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT));
77 * Now for the recv window, should we take the same amount? or
78 * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For
79 * now I will just copy.
81 SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace);
82 SCTP_BASE_VAR(first_time) = 0;
83 SCTP_BASE_VAR(sctp_pcb_initialized) = 0;
85 #if defined(SCTP_PACKET_LOGGING)
86 SCTP_BASE_VAR(packet_log_writers) = 0;
87 SCTP_BASE_VAR(packet_log_end) = 0;
88 bzero(&SCTP_BASE_VAR(packet_log_buffer), SCTP_PACKET_LOG_SIZE);
101 sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz)
103 struct sctp_tmit_chunk *chk;
106 /* Adjust that too */
107 stcb->asoc.smallest_mtu = nxtsz;
108 /* now off to subtract IP_DF flag if needed */
109 overhead = IP_HDR_SIZE;
110 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
111 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
113 TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) {
114 if ((chk->send_size + overhead) > nxtsz) {
115 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
118 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
119 if ((chk->send_size + overhead) > nxtsz) {
121 * For this guy we also mark for immediate resend
122 * since we sent to big of chunk
124 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
125 if (chk->sent < SCTP_DATAGRAM_RESEND) {
126 sctp_flight_size_decrease(chk);
127 sctp_total_flight_decrease(stcb, chk);
128 chk->sent = SCTP_DATAGRAM_RESEND;
129 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
130 chk->rec.data.doing_fast_retransmit = 0;
131 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
132 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU,
133 chk->whoTo->flight_size,
135 (uintptr_t) chk->whoTo,
136 chk->rec.data.TSN_seq);
138 /* Clear any time so NO RTT is being done */
147 sctp_notify_mbuf(struct sctp_inpcb *inp,
148 struct sctp_tcb *stcb,
149 struct sctp_nets *net,
154 int totsz, tmr_stopped = 0;
158 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
159 (ip == NULL) || (sh == NULL)) {
161 SCTP_TCB_UNLOCK(stcb);
165 /* First job is to verify the vtag matches what I would send */
166 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
167 SCTP_TCB_UNLOCK(stcb);
170 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
172 if (icmph->icmp_type != ICMP_UNREACH) {
173 /* We only care about unreachable */
174 SCTP_TCB_UNLOCK(stcb);
177 if (icmph->icmp_code != ICMP_UNREACH_NEEDFRAG) {
178 /* not a unreachable message due to frag. */
179 SCTP_TCB_UNLOCK(stcb);
182 totsz = ntohs(ip->ip_len);
184 nxtsz = ntohs(icmph->icmp_nextmtu);
187 * old type router that does not tell us what the next size
188 * mtu is. Rats we will have to guess (in a educated fashion
191 nxtsz = sctp_get_prev_mtu(totsz);
193 /* Stop any PMTU timer */
194 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
196 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
197 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1);
199 /* Adjust destination size limit */
200 if (net->mtu > nxtsz) {
203 net->mtu -= sizeof(struct udphdr);
206 /* now what about the ep? */
207 if (stcb->asoc.smallest_mtu > nxtsz) {
208 sctp_pathmtu_adjustment(stcb, nxtsz);
211 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
213 SCTP_TCB_UNLOCK(stcb);
217 sctp_notify(struct sctp_inpcb *inp,
221 struct sctp_tcb *stcb,
222 struct sctp_nets *net)
224 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
231 if ((inp == NULL) || (stcb == NULL) || (net == NULL) ||
232 (sh == NULL) || (to == NULL)) {
234 SCTP_TCB_UNLOCK(stcb);
237 /* First job is to verify the vtag matches what I would send */
238 if (ntohl(sh->v_tag) != (stcb->asoc.peer_vtag)) {
239 SCTP_TCB_UNLOCK(stcb);
242 icmph = (struct icmp *)((caddr_t)ip - (sizeof(struct icmp) -
244 if (icmph->icmp_type != ICMP_UNREACH) {
245 /* We only care about unreachable */
246 SCTP_TCB_UNLOCK(stcb);
249 if ((icmph->icmp_code == ICMP_UNREACH_NET) ||
250 (icmph->icmp_code == ICMP_UNREACH_HOST) ||
251 (icmph->icmp_code == ICMP_UNREACH_NET_UNKNOWN) ||
252 (icmph->icmp_code == ICMP_UNREACH_HOST_UNKNOWN) ||
253 (icmph->icmp_code == ICMP_UNREACH_ISOLATED) ||
254 (icmph->icmp_code == ICMP_UNREACH_NET_PROHIB) ||
255 (icmph->icmp_code == ICMP_UNREACH_HOST_PROHIB) ||
256 (icmph->icmp_code == ICMP_UNREACH_FILTER_PROHIB)) {
259 * Hmm reachablity problems we must examine closely. If its
260 * not reachable, we may have lost a network. Or if there is
261 * NO protocol at the other end named SCTP. well we consider
264 if (net->dest_state & SCTP_ADDR_REACHABLE) {
265 /* Ok that destination is NOT reachable */
266 net->dest_state &= ~SCTP_ADDR_REACHABLE;
267 net->dest_state &= ~SCTP_ADDR_PF;
268 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
270 (void *)net, SCTP_SO_NOT_LOCKED);
272 SCTP_TCB_UNLOCK(stcb);
273 } else if ((icmph->icmp_code == ICMP_UNREACH_PROTOCOL) ||
274 (icmph->icmp_code == ICMP_UNREACH_PORT)) {
276 * Here the peer is either playing tricks on us, including
277 * an address that belongs to someone who does not support
278 * SCTP OR was a userland implementation that shutdown and
279 * now is dead. In either case treat it like a OOTB abort
282 sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
283 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
284 so = SCTP_INP_SO(inp);
285 atomic_add_int(&stcb->asoc.refcnt, 1);
286 SCTP_TCB_UNLOCK(stcb);
287 SCTP_SOCKET_LOCK(so, 1);
289 atomic_subtract_int(&stcb->asoc.refcnt, 1);
291 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
292 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
293 #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
294 SCTP_SOCKET_UNLOCK(so, 1);
295 /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed. */
297 /* no need to unlock here, since the TCB is gone */
299 SCTP_TCB_UNLOCK(stcb);
307 sctp_ctlinput(cmd, sa, vip)
316 /* FIX, for non-bsd is this right? */
317 vrf_id = SCTP_DEFAULT_VRFID;
318 if (sa->sa_family != AF_INET ||
319 ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) {
322 if (PRC_IS_REDIRECT(cmd)) {
324 } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) {
328 struct sctp_inpcb *inp = NULL;
329 struct sctp_tcb *stcb = NULL;
330 struct sctp_nets *net = NULL;
331 struct sockaddr_in to, from;
333 sh = (struct sctphdr *)((caddr_t)ip + (ip->ip_hl << 2));
334 bzero(&to, sizeof(to));
335 bzero(&from, sizeof(from));
336 from.sin_family = to.sin_family = AF_INET;
337 from.sin_len = to.sin_len = sizeof(to);
338 from.sin_port = sh->src_port;
339 from.sin_addr = ip->ip_src;
340 to.sin_port = sh->dest_port;
341 to.sin_addr = ip->ip_dst;
344 * 'to' holds the dest of the packet that failed to be sent.
345 * 'from' holds our local endpoint address. Thus we reverse
346 * the to and the from in the lookup.
348 stcb = sctp_findassociation_addr_sa((struct sockaddr *)&to,
349 (struct sockaddr *)&from,
350 &inp, &net, 1, vrf_id);
351 if (stcb != NULL && inp && (inp->sctp_socket != NULL)) {
352 if (cmd != PRC_MSGSIZE) {
353 sctp_notify(inp, ip, sh,
354 (struct sockaddr *)&to, stcb,
357 /* handle possible ICMP size messages */
358 sctp_notify_mbuf(inp, stcb, net, ip, sh);
361 if ((stcb == NULL) && (inp != NULL)) {
362 /* reduce ref-count */
364 SCTP_INP_DECR_REF(inp);
365 SCTP_INP_WUNLOCK(inp);
368 SCTP_TCB_UNLOCK(stcb);
378 sctp_getcred(SYSCTL_HANDLER_ARGS)
381 struct sockaddr_in addrs[2];
382 struct sctp_inpcb *inp;
383 struct sctp_nets *net;
384 struct sctp_tcb *stcb;
388 /* FIX, for non-bsd is this right? */
389 vrf_id = SCTP_DEFAULT_VRFID;
391 error = priv_check(req->td, PRIV_NETINET_GETCRED);
396 error = SYSCTL_IN(req, addrs, sizeof(addrs));
400 stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]),
402 &inp, &net, 1, vrf_id);
403 if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) {
404 if ((inp != NULL) && (stcb == NULL)) {
405 /* reduce ref-count */
407 SCTP_INP_DECR_REF(inp);
410 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
414 SCTP_TCB_UNLOCK(stcb);
416 * We use the write lock here, only since in the error leg we need
417 * it. If we used RLOCK, then we would have to
418 * wlock/decr/unlock/rlock. Which in theory could create a hole.
419 * Better to use higher wlock.
423 error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket);
425 SCTP_INP_WUNLOCK(inp);
428 cru2x(inp->sctp_socket->so_cred, &xuc);
429 SCTP_INP_WUNLOCK(inp);
430 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
435 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
436 0, 0, sctp_getcred, "S,ucred", "Get the ucred of a SCTP connection");
441 sctp_abort(struct socket *so)
443 struct sctp_inpcb *inp;
446 inp = (struct sctp_inpcb *)so->so_pcb;
451 flags = inp->sctp_flags;
452 #ifdef SCTP_LOG_CLOSING
453 sctp_log_closing(inp, NULL, 17);
455 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
456 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
457 #ifdef SCTP_LOG_CLOSING
458 sctp_log_closing(inp, NULL, 16);
460 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
461 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
463 SCTP_SB_CLEAR(so->so_snd);
465 * same for the rcv ones, they are only here for the
468 SCTP_SB_CLEAR(so->so_rcv);
470 /* Now null out the reference, we are completely detached. */
474 flags = inp->sctp_flags;
475 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
476 goto sctp_must_try_again;
483 sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
485 struct sctp_inpcb *inp;
486 struct inpcb *ip_inp;
488 uint32_t vrf_id = SCTP_DEFAULT_VRFID;
490 inp = (struct sctp_inpcb *)so->so_pcb;
492 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
495 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
496 error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace));
501 error = sctp_inpcb_alloc(so, vrf_id);
505 inp = (struct sctp_inpcb *)so->so_pcb;
507 inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */
508 ip_inp = &inp->ip_inp.inp;
509 ip_inp->inp_vflag |= INP_IPV4;
510 ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
511 SCTP_INP_WUNLOCK(inp);
516 sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
518 struct sctp_inpcb *inp;
520 inp = (struct sctp_inpcb *)so->so_pcb;
522 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
526 if ((addr->sa_family != AF_INET) ||
527 (addr->sa_len != sizeof(struct sockaddr_in))) {
528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
532 return (sctp_inpcb_bind(so, addr, NULL, p));
537 sctp_close(struct socket *so)
539 struct sctp_inpcb *inp;
542 inp = (struct sctp_inpcb *)so->so_pcb;
547 * Inform all the lower layer assoc that we are done.
550 flags = inp->sctp_flags;
551 #ifdef SCTP_LOG_CLOSING
552 sctp_log_closing(inp, NULL, 17);
554 if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
555 (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) {
556 if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) ||
557 (so->so_rcv.sb_cc > 0)) {
558 #ifdef SCTP_LOG_CLOSING
559 sctp_log_closing(inp, NULL, 13);
561 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
562 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
564 #ifdef SCTP_LOG_CLOSING
565 sctp_log_closing(inp, NULL, 14);
567 sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
568 SCTP_CALLED_AFTER_CMPSET_OFCLOSE);
571 * The socket is now detached, no matter what the state of
572 * the SCTP association.
575 SCTP_SB_CLEAR(so->so_snd);
577 * same for the rcv ones, they are only here for the
580 SCTP_SB_CLEAR(so->so_rcv);
582 /* Now null out the reference, we are completely detached. */
586 flags = inp->sctp_flags;
587 if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
588 goto sctp_must_try_again;
596 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
597 struct mbuf *control, struct thread *p);
601 sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
602 struct mbuf *control, struct thread *p)
604 struct sctp_inpcb *inp;
607 inp = (struct sctp_inpcb *)so->so_pcb;
610 sctp_m_freem(control);
613 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
617 /* Got to have an to address if we are NOT a connected socket */
618 if ((addr == NULL) &&
619 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
620 (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
622 } else if (addr == NULL) {
623 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
624 error = EDESTADDRREQ;
627 sctp_m_freem(control);
633 if (addr->sa_family != AF_INET) {
634 /* must be a v4 address! */
635 SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
638 sctp_m_freem(control);
641 error = EDESTADDRREQ;
646 /* now what about control */
649 SCTP_PRINTF("huh? control set?\n");
650 sctp_m_freem(inp->control);
653 inp->control = control;
657 SCTP_BUF_NEXT(inp->pkt_last) = m;
660 inp->pkt_last = inp->pkt = m;
663 /* FreeBSD uses a flag passed */
664 ((flags & PRUS_MORETOCOME) == 0)
667 * note with the current version this code will only be used
668 * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for
669 * re-defining sosend to use the sctp_sosend. One can
670 * optionally switch back to this code (by changing back the
671 * definitions) but this is not advisable. This code is used
672 * by FreeBSD when sending a file with sendfile() though.
676 ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
686 sctp_disconnect(struct socket *so)
688 struct sctp_inpcb *inp;
690 inp = (struct sctp_inpcb *)so->so_pcb;
692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
696 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
697 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
698 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
700 SCTP_INP_RUNLOCK(inp);
703 struct sctp_association *asoc;
704 struct sctp_tcb *stcb;
706 stcb = LIST_FIRST(&inp->sctp_asoc_list);
708 SCTP_INP_RUNLOCK(inp);
709 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
714 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
715 /* We are about to be freed, out of here */
716 SCTP_TCB_UNLOCK(stcb);
717 SCTP_INP_RUNLOCK(inp);
720 if (((so->so_options & SO_LINGER) &&
721 (so->so_linger == 0)) ||
722 (so->so_rcv.sb_cc > 0)) {
723 if (SCTP_GET_STATE(asoc) !=
724 SCTP_STATE_COOKIE_WAIT) {
725 /* Left with Data unread */
728 err = sctp_get_mbuf_for_msg(sizeof(struct sctp_paramhdr), 0, M_NOWAIT, 1, MT_DATA);
734 struct sctp_paramhdr *ph;
736 ph = mtod(err, struct sctp_paramhdr *);
737 SCTP_BUF_LEN(err) = sizeof(struct sctp_paramhdr);
738 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
739 ph->param_length = htons(SCTP_BUF_LEN(err));
741 sctp_send_abort_tcb(stcb, err, SCTP_SO_LOCKED);
742 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
744 SCTP_INP_RUNLOCK(inp);
745 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
746 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
747 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
749 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
750 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3);
751 /* No unlock tcb assoc is gone */
754 if (TAILQ_EMPTY(&asoc->send_queue) &&
755 TAILQ_EMPTY(&asoc->sent_queue) &&
756 (asoc->stream_queue_cnt == 0)) {
757 /* there is nothing queued to send, so done */
758 if (asoc->locked_on_sending) {
761 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
762 (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
763 /* only send SHUTDOWN 1st time thru */
764 struct sctp_nets *netp;
766 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
767 (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
768 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
770 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
771 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
772 sctp_stop_timers_for_shutdown(stcb);
773 if (stcb->asoc.alternate) {
774 netp = stcb->asoc.alternate;
776 netp = stcb->asoc.primary_destination;
778 sctp_send_shutdown(stcb, netp);
779 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
780 stcb->sctp_ep, stcb, netp);
781 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
782 stcb->sctp_ep, stcb, netp);
783 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED);
787 * we still got (or just got) data to send,
788 * so set SHUTDOWN_PENDING
791 * XXX sockets draft says that SCTP_EOF
792 * should be sent with no data. currently,
793 * we will allow user data to be sent first
794 * and move to SHUTDOWN-PENDING
796 struct sctp_nets *netp;
798 if (stcb->asoc.alternate) {
799 netp = stcb->asoc.alternate;
801 netp = stcb->asoc.primary_destination;
804 asoc->state |= SCTP_STATE_SHUTDOWN_PENDING;
805 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
807 if (asoc->locked_on_sending) {
808 /* Locked to send out the data */
809 struct sctp_stream_queue_pending *sp;
811 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
813 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
814 asoc->locked_on_sending->stream_no);
816 if ((sp->length == 0) && (sp->msg_is_complete == 0))
817 asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
820 if (TAILQ_EMPTY(&asoc->send_queue) &&
821 TAILQ_EMPTY(&asoc->sent_queue) &&
822 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
826 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
827 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4;
828 sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED);
829 SCTP_STAT_INCR_COUNTER32(sctps_aborted);
830 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
831 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
832 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
834 SCTP_INP_RUNLOCK(inp);
835 (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
836 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5);
839 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
842 soisdisconnecting(so);
843 SCTP_TCB_UNLOCK(stcb);
844 SCTP_INP_RUNLOCK(inp);
849 /* UDP model does not support this */
850 SCTP_INP_RUNLOCK(inp);
851 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
857 sctp_flush(struct socket *so, int how)
860 * We will just clear out the values and let subsequent close clear
861 * out the data, if any. Note if the user did a shutdown(SHUT_RD)
862 * they will not be able to read the data, the socket will block
863 * that from happening.
865 struct sctp_inpcb *inp;
867 inp = (struct sctp_inpcb *)so->so_pcb;
869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
873 /* For the 1 to many model this does nothing */
874 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
875 SCTP_INP_RUNLOCK(inp);
878 SCTP_INP_RUNLOCK(inp);
879 if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) {
881 * First make sure the sb will be happy, we don't use these
882 * except maybe the count
885 SCTP_INP_READ_LOCK(inp);
886 inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ;
887 SCTP_INP_READ_UNLOCK(inp);
888 SCTP_INP_WUNLOCK(inp);
889 so->so_rcv.sb_cc = 0;
890 so->so_rcv.sb_mbcnt = 0;
891 so->so_rcv.sb_mb = NULL;
893 if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) {
895 * First make sure the sb will be happy, we don't use these
896 * except maybe the count
898 so->so_snd.sb_cc = 0;
899 so->so_snd.sb_mbcnt = 0;
900 so->so_snd.sb_mb = NULL;
907 sctp_shutdown(struct socket *so)
909 struct sctp_inpcb *inp;
911 inp = (struct sctp_inpcb *)so->so_pcb;
913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
917 /* For UDP model this is a invalid call */
918 if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
919 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
920 /* Restore the flags that the soshutdown took away. */
921 SOCKBUF_LOCK(&so->so_rcv);
922 so->so_rcv.sb_state &= ~SBS_CANTRCVMORE;
923 SOCKBUF_UNLOCK(&so->so_rcv);
924 /* This proc will wakeup for read and do nothing (I hope) */
925 SCTP_INP_RUNLOCK(inp);
926 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
930 * Ok, if we reach here its the TCP model and it is either a
931 * SHUT_WR or SHUT_RDWR. This means we put the shutdown flag
934 struct sctp_tcb *stcb;
935 struct sctp_association *asoc;
936 struct sctp_nets *netp;
939 (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
940 SCTP_INP_RUNLOCK(inp);
945 stcb = LIST_FIRST(&inp->sctp_asoc_list);
948 * Ok, we hit the case that the shutdown call was
949 * made after an abort or something. Nothing to do
952 SCTP_INP_RUNLOCK(inp);
957 if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
958 SCTP_TCB_UNLOCK(stcb);
959 SCTP_INP_RUNLOCK(inp);
962 if ((SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_WAIT) &&
963 (SCTP_GET_STATE(asoc) != SCTP_STATE_COOKIE_ECHOED) &&
964 (SCTP_GET_STATE(asoc) != SCTP_STATE_OPEN)) {
966 * If we are not in or before ESTABLISHED, there is
967 * no protocol action required.
969 SCTP_TCB_UNLOCK(stcb);
970 SCTP_INP_RUNLOCK(inp);
973 if (stcb->asoc.alternate) {
974 netp = stcb->asoc.alternate;
976 netp = stcb->asoc.primary_destination;
978 if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) &&
979 TAILQ_EMPTY(&asoc->send_queue) &&
980 TAILQ_EMPTY(&asoc->sent_queue) &&
981 (asoc->stream_queue_cnt == 0)) {
982 if (asoc->locked_on_sending) {
985 /* there is nothing queued to send, so I'm done... */
986 SCTP_STAT_DECR_GAUGE32(sctps_currestab);
987 SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
988 SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
989 sctp_stop_timers_for_shutdown(stcb);
990 sctp_send_shutdown(stcb, netp);
991 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
992 stcb->sctp_ep, stcb, netp);
995 * We still got (or just got) data to send, so set
998 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
999 if (asoc->locked_on_sending) {
1000 /* Locked to send out the data */
1001 struct sctp_stream_queue_pending *sp;
1003 sp = TAILQ_LAST(&asoc->locked_on_sending->outqueue, sctp_streamhead);
1005 SCTP_PRINTF("Error, sp is NULL, locked on sending is non-null strm:%d\n",
1006 asoc->locked_on_sending->stream_no);
1008 if ((sp->length == 0) && (sp->msg_is_complete == 0)) {
1009 SCTP_ADD_SUBSTATE(asoc, SCTP_STATE_PARTIAL_MSG_LEFT);
1013 if (TAILQ_EMPTY(&asoc->send_queue) &&
1014 TAILQ_EMPTY(&asoc->sent_queue) &&
1015 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
1016 struct mbuf *op_err;
1019 op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
1020 stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6;
1021 sctp_abort_an_association(stcb->sctp_ep, stcb,
1022 op_err, SCTP_SO_LOCKED);
1023 SCTP_INP_RUNLOCK(inp);
1027 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp);
1029 * XXX: Why do this in the case where we have still data
1032 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
1033 SCTP_TCB_UNLOCK(stcb);
1034 SCTP_INP_RUNLOCK(inp);
1040 * copies a "user" presentable address and removes embedded scope, etc.
1041 * returns 0 on success, 1 on error
1044 sctp_fill_user_address(struct sockaddr_storage *ss, struct sockaddr *sa)
1047 struct sockaddr_in6 lsa6;
1049 sa = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)sa,
1052 memcpy(ss, sa, sa->sa_len);
1059 * NOTE: assumes addr lock is held
1062 sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp,
1063 struct sctp_tcb *stcb,
1065 struct sockaddr_storage *sas,
1068 struct sctp_ifn *sctp_ifn;
1069 struct sctp_ifa *sctp_ifa;
1074 int ipv4_local_scope, ipv4_addr_legal;
1078 int local_scope, site_scope, ipv6_addr_legal;
1081 struct sctp_vrf *vrf;
1088 /* Turn on all the appropriate scope */
1089 loopback_scope = stcb->asoc.scope.loopback_scope;
1091 ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
1092 ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
1095 local_scope = stcb->asoc.scope.local_scope;
1096 site_scope = stcb->asoc.scope.site_scope;
1097 ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
1100 /* Use generic values for endpoints. */
1103 ipv4_local_scope = 1;
1109 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
1111 ipv6_addr_legal = 1;
1114 if (SCTP_IPV6_V6ONLY(inp)) {
1115 ipv4_addr_legal = 0;
1117 ipv4_addr_legal = 1;
1122 ipv6_addr_legal = 0;
1125 ipv4_addr_legal = 1;
1129 vrf = sctp_find_vrf(vrf_id);
1133 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1134 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1135 if ((loopback_scope == 0) &&
1136 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
1137 /* Skip loopback if loopback_scope not set */
1140 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1143 * For the BOUND-ALL case, the list
1144 * associated with a TCB is Always
1145 * considered a reverse list.. i.e.
1146 * it lists addresses that are NOT
1147 * part of the association. If this
1148 * is one of those we must skip it.
1150 if (sctp_is_addr_restricted(stcb,
1155 switch (sctp_ifa->address.sa.sa_family) {
1158 if (ipv4_addr_legal) {
1159 struct sockaddr_in *sin;
1161 sin = &sctp_ifa->address.sin;
1162 if (sin->sin_addr.s_addr == 0) {
1170 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1171 &sin->sin_addr) != 0) {
1174 if ((ipv4_local_scope == 0) &&
1175 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1179 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
1180 in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)sas);
1181 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1182 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(struct sockaddr_in6));
1183 actual += sizeof(struct sockaddr_in6);
1186 memcpy(sas, sin, sizeof(*sin));
1187 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1188 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin));
1189 actual += sizeof(*sin);
1193 if (actual >= limit) {
1203 if (ipv6_addr_legal) {
1204 struct sockaddr_in6 *sin6;
1206 sin6 = &sctp_ifa->address.sin6;
1207 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1215 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1216 &sin6->sin6_addr) != 0) {
1219 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1220 if (local_scope == 0)
1222 if (sin6->sin6_scope_id == 0) {
1223 if (sa6_recoverscope(sin6) != 0)
1241 if ((site_scope == 0) &&
1242 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1245 memcpy(sas, sin6, sizeof(*sin6));
1246 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1247 sas = (struct sockaddr_storage *)((caddr_t)sas + sizeof(*sin6));
1248 actual += sizeof(*sin6);
1249 if (actual >= limit) {
1264 struct sctp_laddr *laddr;
1266 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1268 if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
1272 if (sctp_fill_user_address(sas, &laddr->ifa->address.sa))
1274 switch (laddr->ifa->address.sa.sa_family) {
1277 ((struct sockaddr_in *)sas)->sin_port = inp->sctp_lport;
1282 ((struct sockaddr_in6 *)sas)->sin6_port = inp->sctp_lport;
1289 sas = (struct sockaddr_storage *)((caddr_t)sas +
1290 laddr->ifa->address.sa.sa_len);
1291 actual += laddr->ifa->address.sa.sa_len;
1292 if (actual >= limit) {
1301 sctp_fill_up_addresses(struct sctp_inpcb *inp,
1302 struct sctp_tcb *stcb,
1304 struct sockaddr_storage *sas)
1308 SCTP_IPI_ADDR_RLOCK();
1309 /* fill up addresses for the endpoint's default vrf */
1310 size = sctp_fill_up_addresses_vrf(inp, stcb, limit, sas,
1312 SCTP_IPI_ADDR_RUNLOCK();
1317 * NOTE: assumes addr lock is held
1320 sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id)
1323 struct sctp_vrf *vrf = NULL;
1326 * In both sub-set bound an bound_all cases we return the MAXIMUM
1327 * number of addresses that you COULD get. In reality the sub-set
1328 * bound may have an exclusion list for a given TCB OR in the
1329 * bound-all case a TCB may NOT include the loopback or other
1330 * addresses as well.
1332 vrf = sctp_find_vrf(vrf_id);
1336 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1337 struct sctp_ifn *sctp_ifn;
1338 struct sctp_ifa *sctp_ifa;
1340 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
1341 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
1342 /* Count them if they are the right type */
1343 switch (sctp_ifa->address.sa.sa_family) {
1347 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1348 cnt += sizeof(struct sockaddr_in6);
1350 cnt += sizeof(struct sockaddr_in);
1352 cnt += sizeof(struct sockaddr_in);
1358 cnt += sizeof(struct sockaddr_in6);
1367 struct sctp_laddr *laddr;
1369 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
1370 switch (laddr->ifa->address.sa.sa_family) {
1374 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4))
1375 cnt += sizeof(struct sockaddr_in6);
1377 cnt += sizeof(struct sockaddr_in);
1379 cnt += sizeof(struct sockaddr_in);
1385 cnt += sizeof(struct sockaddr_in6);
1397 sctp_count_max_addresses(struct sctp_inpcb *inp)
1401 SCTP_IPI_ADDR_RLOCK();
1402 /* count addresses for the endpoint's default VRF */
1403 cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id);
1404 SCTP_IPI_ADDR_RUNLOCK();
1409 sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval,
1410 size_t optsize, void *p, int delay)
1413 int creat_lock_on = 0;
1414 struct sctp_tcb *stcb = NULL;
1415 struct sockaddr *sa;
1416 int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr;
1418 int bad_addresses = 0;
1421 SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n");
1423 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1424 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
1425 /* We are already connected AND the TCP model */
1426 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
1427 return (EADDRINUSE);
1429 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
1430 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
1431 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1434 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
1435 SCTP_INP_RLOCK(inp);
1436 stcb = LIST_FIRST(&inp->sctp_asoc_list);
1437 SCTP_INP_RUNLOCK(inp);
1440 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1443 SCTP_INP_INCR_REF(inp);
1444 SCTP_ASOC_CREATE_LOCK(inp);
1446 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
1447 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
1448 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
1452 totaddrp = (int *)optval;
1453 totaddr = *totaddrp;
1454 sa = (struct sockaddr *)(totaddrp + 1);
1455 stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (optsize - sizeof(int)), &bad_addresses);
1456 if ((stcb != NULL) || bad_addresses) {
1457 /* Already have or am bring up an association */
1458 SCTP_ASOC_CREATE_UNLOCK(inp);
1461 SCTP_TCB_UNLOCK(stcb);
1462 if (bad_addresses == 0) {
1463 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
1469 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
1474 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1476 struct in6pcb *inp6;
1478 inp6 = (struct in6pcb *)inp;
1479 if (SCTP_IPV6_V6ONLY(inp6)) {
1481 * if IPV6_V6ONLY flag, ignore connections destined
1482 * to a v4 addr or v4-mapped addr
1484 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1490 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
1491 SCTP_PCB_FLAGS_UNBOUND) {
1492 /* Bind a ephemeral port */
1493 error = sctp_inpcb_bind(so, NULL, NULL, p);
1498 /* FIX ME: do we want to pass in a vrf on the connect call? */
1499 vrf_id = inp->def_vrf_id;
1502 /* We are GOOD to go */
1503 stcb = sctp_aloc_assoc(inp, sa, &error, 0, vrf_id,
1504 inp->sctp_ep.pre_open_stream_count,
1508 /* Gak! no memory */
1511 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1512 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1513 /* Set the connected flag so we can queue data */
1516 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1517 /* move to second address */
1518 switch (sa->sa_family) {
1521 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1526 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1534 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1535 /* Fill in the return id */
1537 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE,
1538 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
1541 a_id = (sctp_assoc_t *) optval;
1542 *a_id = sctp_get_associd(stcb);
1544 /* initialize authentication parameters for the assoc */
1545 sctp_initialize_auth_params(inp, stcb);
1548 /* doing delayed connection */
1549 stcb->asoc.delayed_connection = 1;
1550 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1552 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1553 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1555 SCTP_TCB_UNLOCK(stcb);
1556 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1557 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1558 /* Set the connected flag so we can queue data */
1562 if (creat_lock_on) {
1563 SCTP_ASOC_CREATE_UNLOCK(inp);
1565 SCTP_INP_DECR_REF(inp);
1569 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1570 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1571 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1572 SCTP_INP_RLOCK(inp); \
1573 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1575 SCTP_TCB_LOCK(stcb); \
1577 SCTP_INP_RUNLOCK(inp); \
1578 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1579 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1580 if (stcb == NULL) { \
1581 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1591 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1592 if (size < sizeof(type)) { \
1593 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1597 destp = (type *)srcp; \
1602 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1605 struct sctp_inpcb *inp = NULL;
1607 struct sctp_tcb *stcb = NULL;
1609 if (optval == NULL) {
1610 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1613 inp = (struct sctp_inpcb *)so->so_pcb;
1615 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1622 case SCTP_AUTOCLOSE:
1623 case SCTP_EXPLICIT_EOR:
1624 case SCTP_AUTO_ASCONF:
1625 case SCTP_DISABLE_FRAGMENTS:
1626 case SCTP_I_WANT_MAPPED_V4_ADDR:
1627 case SCTP_USE_EXT_RCVINFO:
1628 SCTP_INP_RLOCK(inp);
1630 case SCTP_DISABLE_FRAGMENTS:
1631 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1633 case SCTP_I_WANT_MAPPED_V4_ADDR:
1634 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1636 case SCTP_AUTO_ASCONF:
1637 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1638 /* only valid for bound all sockets */
1639 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1641 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1646 case SCTP_EXPLICIT_EOR:
1647 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1650 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1652 case SCTP_USE_EXT_RCVINFO:
1653 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1655 case SCTP_AUTOCLOSE:
1656 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1657 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1663 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1664 error = ENOPROTOOPT;
1665 } /* end switch (sopt->sopt_name) */
1666 if (*optsize < sizeof(val)) {
1667 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1671 SCTP_INP_RUNLOCK(inp);
1673 /* return the option value */
1674 *(int *)optval = val;
1675 *optsize = sizeof(val);
1678 case SCTP_GET_PACKET_LOG:
1680 #ifdef SCTP_PACKET_LOGGING
1684 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1685 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1688 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1693 case SCTP_REUSE_PORT:
1697 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1698 /* Can't do this for a 1-m socket */
1702 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1703 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1704 *optsize = sizeof(uint32_t);
1707 case SCTP_PARTIAL_DELIVERY_POINT:
1711 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1712 *value = inp->partial_delivery_point;
1713 *optsize = sizeof(uint32_t);
1716 case SCTP_FRAGMENT_INTERLEAVE:
1720 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1721 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1722 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1723 *value = SCTP_FRAG_LEVEL_2;
1725 *value = SCTP_FRAG_LEVEL_1;
1728 *value = SCTP_FRAG_LEVEL_0;
1730 *optsize = sizeof(uint32_t);
1733 case SCTP_CMT_ON_OFF:
1735 struct sctp_assoc_value *av;
1737 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1738 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1740 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1741 SCTP_TCB_UNLOCK(stcb);
1743 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1744 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1745 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1746 SCTP_INP_RLOCK(inp);
1747 av->assoc_value = inp->sctp_cmt_on_off;
1748 SCTP_INP_RUNLOCK(inp);
1750 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1755 *optsize = sizeof(struct sctp_assoc_value);
1759 case SCTP_PLUGGABLE_CC:
1761 struct sctp_assoc_value *av;
1763 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1764 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1766 av->assoc_value = stcb->asoc.congestion_control_module;
1767 SCTP_TCB_UNLOCK(stcb);
1769 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1770 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1771 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1772 SCTP_INP_RLOCK(inp);
1773 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1774 SCTP_INP_RUNLOCK(inp);
1776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1781 *optsize = sizeof(struct sctp_assoc_value);
1785 case SCTP_CC_OPTION:
1787 struct sctp_cc_option *cc_opt;
1789 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1790 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1794 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1797 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1798 *optsize = sizeof(struct sctp_cc_option);
1800 SCTP_TCB_UNLOCK(stcb);
1804 case SCTP_PLUGGABLE_SS:
1806 struct sctp_assoc_value *av;
1808 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1809 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1811 av->assoc_value = stcb->asoc.stream_scheduling_module;
1812 SCTP_TCB_UNLOCK(stcb);
1814 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1815 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1816 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1817 SCTP_INP_RLOCK(inp);
1818 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1819 SCTP_INP_RUNLOCK(inp);
1821 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1826 *optsize = sizeof(struct sctp_assoc_value);
1832 struct sctp_stream_value *av;
1834 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1835 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1837 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1838 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1839 &av->stream_value) < 0)) {
1840 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1843 *optsize = sizeof(struct sctp_stream_value);
1845 SCTP_TCB_UNLOCK(stcb);
1848 * Can't get stream value without
1851 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1856 case SCTP_GET_ADDR_LEN:
1858 struct sctp_assoc_value *av;
1860 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1863 if (av->assoc_value == AF_INET) {
1864 av->assoc_value = sizeof(struct sockaddr_in);
1869 if (av->assoc_value == AF_INET6) {
1870 av->assoc_value = sizeof(struct sockaddr_in6);
1875 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1877 *optsize = sizeof(struct sctp_assoc_value);
1881 case SCTP_GET_ASSOC_NUMBER:
1883 uint32_t *value, cnt;
1885 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1887 SCTP_INP_RLOCK(inp);
1888 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1891 SCTP_INP_RUNLOCK(inp);
1893 *optsize = sizeof(uint32_t);
1896 case SCTP_GET_ASSOC_ID_LIST:
1898 struct sctp_assoc_ids *ids;
1899 unsigned int at, limit;
1901 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1903 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1904 SCTP_INP_RLOCK(inp);
1905 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1907 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1910 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1914 SCTP_INP_RUNLOCK(inp);
1916 ids->gaids_number_of_ids = at;
1917 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1923 struct sctp_assoc_value *av;
1925 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1926 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1929 av->assoc_value = stcb->asoc.context;
1930 SCTP_TCB_UNLOCK(stcb);
1932 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1933 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1934 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1935 SCTP_INP_RLOCK(inp);
1936 av->assoc_value = inp->sctp_context;
1937 SCTP_INP_RUNLOCK(inp);
1939 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1944 *optsize = sizeof(struct sctp_assoc_value);
1950 uint32_t *default_vrfid;
1952 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1953 *default_vrfid = inp->def_vrf_id;
1954 *optsize = sizeof(uint32_t);
1957 case SCTP_GET_ASOC_VRF:
1959 struct sctp_assoc_value *id;
1961 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1962 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1965 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1967 id->assoc_value = stcb->asoc.vrf_id;
1968 *optsize = sizeof(struct sctp_assoc_value);
1972 case SCTP_GET_VRF_IDS:
1974 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1978 case SCTP_GET_NONCE_VALUES:
1980 struct sctp_get_nonce_values *gnv;
1982 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1983 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1986 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1987 gnv->gn_local_tag = stcb->asoc.my_vtag;
1988 SCTP_TCB_UNLOCK(stcb);
1989 *optsize = sizeof(struct sctp_get_nonce_values);
1991 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1996 case SCTP_DELAYED_SACK:
1998 struct sctp_sack_info *sack;
2000 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2001 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2003 sack->sack_delay = stcb->asoc.delayed_ack;
2004 sack->sack_freq = stcb->asoc.sack_freq;
2005 SCTP_TCB_UNLOCK(stcb);
2007 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2008 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2009 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2010 SCTP_INP_RLOCK(inp);
2011 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2012 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2013 SCTP_INP_RUNLOCK(inp);
2015 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2020 *optsize = sizeof(struct sctp_sack_info);
2024 case SCTP_GET_SNDBUF_USE:
2026 struct sctp_sockstat *ss;
2028 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2029 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2032 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2033 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2034 stcb->asoc.size_on_all_streams);
2035 SCTP_TCB_UNLOCK(stcb);
2036 *optsize = sizeof(struct sctp_sockstat);
2038 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2043 case SCTP_MAX_BURST:
2045 struct sctp_assoc_value *av;
2047 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2048 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2051 av->assoc_value = stcb->asoc.max_burst;
2052 SCTP_TCB_UNLOCK(stcb);
2054 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2055 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2056 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2057 SCTP_INP_RLOCK(inp);
2058 av->assoc_value = inp->sctp_ep.max_burst;
2059 SCTP_INP_RUNLOCK(inp);
2061 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2066 *optsize = sizeof(struct sctp_assoc_value);
2072 struct sctp_assoc_value *av;
2075 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2076 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2079 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2080 SCTP_TCB_UNLOCK(stcb);
2082 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2083 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2084 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2085 SCTP_INP_RLOCK(inp);
2086 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2087 ovh = SCTP_MED_OVERHEAD;
2089 ovh = SCTP_MED_V4_OVERHEAD;
2091 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2092 av->assoc_value = 0;
2094 av->assoc_value = inp->sctp_frag_point - ovh;
2095 SCTP_INP_RUNLOCK(inp);
2097 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2102 *optsize = sizeof(struct sctp_assoc_value);
2106 case SCTP_GET_STAT_LOG:
2107 error = sctp_fill_stat_log(optval, optsize);
2111 struct sctp_event_subscribe *events;
2113 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2114 memset(events, 0, sizeof(struct sctp_event_subscribe));
2115 SCTP_INP_RLOCK(inp);
2116 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2117 events->sctp_data_io_event = 1;
2119 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2120 events->sctp_association_event = 1;
2122 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2123 events->sctp_address_event = 1;
2125 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2126 events->sctp_send_failure_event = 1;
2128 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2129 events->sctp_peer_error_event = 1;
2131 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2132 events->sctp_shutdown_event = 1;
2134 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2135 events->sctp_partial_delivery_event = 1;
2137 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2138 events->sctp_adaptation_layer_event = 1;
2140 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2141 events->sctp_authentication_event = 1;
2143 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2144 events->sctp_sender_dry_event = 1;
2146 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2147 events->sctp_stream_reset_event = 1;
2148 SCTP_INP_RUNLOCK(inp);
2149 *optsize = sizeof(struct sctp_event_subscribe);
2152 case SCTP_ADAPTATION_LAYER:
2156 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2158 SCTP_INP_RLOCK(inp);
2159 *value = inp->sctp_ep.adaptation_layer_indicator;
2160 SCTP_INP_RUNLOCK(inp);
2161 *optsize = sizeof(uint32_t);
2164 case SCTP_SET_INITIAL_DBG_SEQ:
2168 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2169 SCTP_INP_RLOCK(inp);
2170 *value = inp->sctp_ep.initial_sequence_debug;
2171 SCTP_INP_RUNLOCK(inp);
2172 *optsize = sizeof(uint32_t);
2175 case SCTP_GET_LOCAL_ADDR_SIZE:
2179 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2180 SCTP_INP_RLOCK(inp);
2181 *value = sctp_count_max_addresses(inp);
2182 SCTP_INP_RUNLOCK(inp);
2183 *optsize = sizeof(uint32_t);
2186 case SCTP_GET_REMOTE_ADDR_SIZE:
2190 struct sctp_nets *net;
2192 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2193 /* FIXME MT: change to sctp_assoc_value? */
2194 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2198 /* Count the sizes */
2199 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2200 switch (net->ro._l_addr.sa.sa_family) {
2204 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2205 size += sizeof(struct sockaddr_in6);
2207 size += sizeof(struct sockaddr_in);
2210 size += sizeof(struct sockaddr_in);
2216 size += sizeof(struct sockaddr_in6);
2223 SCTP_TCB_UNLOCK(stcb);
2224 *value = (uint32_t) size;
2225 *optsize = sizeof(uint32_t);
2227 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2232 case SCTP_GET_PEER_ADDRESSES:
2234 * Get the address information, an array is passed in to
2235 * fill up we pack it.
2239 struct sockaddr_storage *sas;
2240 struct sctp_nets *net;
2241 struct sctp_getaddresses *saddr;
2243 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2244 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2247 left = (*optsize) - sizeof(struct sctp_getaddresses);
2248 *optsize = sizeof(struct sctp_getaddresses);
2249 sas = (struct sockaddr_storage *)&saddr->addr[0];
2251 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2252 switch (net->ro._l_addr.sa.sa_family) {
2256 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2257 cpsz = sizeof(struct sockaddr_in6);
2259 cpsz = sizeof(struct sockaddr_in);
2262 cpsz = sizeof(struct sockaddr_in);
2268 cpsz = sizeof(struct sockaddr_in6);
2279 /* not enough room. */
2282 #if defined(INET) && defined(INET6)
2283 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2284 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2285 /* Must map the address */
2286 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2287 (struct sockaddr_in6 *)sas);
2289 memcpy(sas, &net->ro._l_addr, cpsz);
2292 memcpy(sas, &net->ro._l_addr, cpsz);
2294 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2296 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2300 SCTP_TCB_UNLOCK(stcb);
2302 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2307 case SCTP_GET_LOCAL_ADDRESSES:
2309 size_t limit, actual;
2310 struct sockaddr_storage *sas;
2311 struct sctp_getaddresses *saddr;
2313 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2314 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2316 sas = (struct sockaddr_storage *)&saddr->addr[0];
2317 limit = *optsize - sizeof(sctp_assoc_t);
2318 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2320 SCTP_TCB_UNLOCK(stcb);
2322 *optsize = sizeof(struct sockaddr_storage) + actual;
2325 case SCTP_PEER_ADDR_PARAMS:
2327 struct sctp_paddrparams *paddrp;
2328 struct sctp_nets *net;
2329 struct sockaddr *addr;
2331 #if defined(INET) && defined(INET6)
2332 struct sockaddr_in sin_store;
2336 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2337 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2339 #if defined(INET) && defined(INET6)
2340 if (paddrp->spp_address.ss_family == AF_INET6) {
2341 struct sockaddr_in6 *sin6;
2343 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2344 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2345 in6_sin6_2_sin(&sin_store, sin6);
2346 addr = (struct sockaddr *)&sin_store;
2348 addr = (struct sockaddr *)&paddrp->spp_address;
2351 addr = (struct sockaddr *)&paddrp->spp_address;
2354 addr = (struct sockaddr *)&paddrp->spp_address;
2357 net = sctp_findnet(stcb, addr);
2360 * We increment here since
2361 * sctp_findassociation_ep_addr() wil do a
2362 * decrement if it finds the stcb as long as
2363 * the locked tcb (last argument) is NOT a
2367 SCTP_INP_INCR_REF(inp);
2368 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2370 SCTP_INP_DECR_REF(inp);
2373 if ((stcb != NULL) && (net == NULL)) {
2375 if (addr->sa_family == AF_INET) {
2376 struct sockaddr_in *sin;
2378 sin = (struct sockaddr_in *)addr;
2379 if (sin->sin_addr.s_addr != INADDR_ANY) {
2381 SCTP_TCB_UNLOCK(stcb);
2382 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2388 if (addr->sa_family == AF_INET6) {
2389 struct sockaddr_in6 *sin6;
2391 sin6 = (struct sockaddr_in6 *)addr;
2392 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2394 SCTP_TCB_UNLOCK(stcb);
2395 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2401 error = EAFNOSUPPORT;
2402 SCTP_TCB_UNLOCK(stcb);
2403 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2408 /* Applies to the specific association */
2409 paddrp->spp_flags = 0;
2411 paddrp->spp_hbinterval = net->heart_beat_delay;
2412 paddrp->spp_pathmaxrxt = net->failure_threshold;
2413 paddrp->spp_pathmtu = net->mtu;
2414 switch (net->ro._l_addr.sa.sa_family) {
2417 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2422 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2428 /* get flags for HB */
2429 if (net->dest_state & SCTP_ADDR_NOHB) {
2430 paddrp->spp_flags |= SPP_HB_DISABLE;
2432 paddrp->spp_flags |= SPP_HB_ENABLE;
2434 /* get flags for PMTU */
2435 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2436 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2438 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2440 if (net->dscp & 0x01) {
2441 paddrp->spp_dscp = net->dscp & 0xfc;
2442 paddrp->spp_flags |= SPP_DSCP;
2445 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2446 (net->flowlabel & 0x80000000)) {
2447 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2448 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2453 * No destination so return default
2456 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2457 paddrp->spp_pathmtu = 0;
2458 if (stcb->asoc.default_dscp & 0x01) {
2459 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2460 paddrp->spp_flags |= SPP_DSCP;
2463 if (stcb->asoc.default_flowlabel & 0x80000000) {
2464 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2465 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2468 /* default settings should be these */
2469 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2470 paddrp->spp_flags |= SPP_HB_DISABLE;
2472 paddrp->spp_flags |= SPP_HB_ENABLE;
2474 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2475 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2477 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2479 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2481 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2482 SCTP_TCB_UNLOCK(stcb);
2484 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2485 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2486 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2487 /* Use endpoint defaults */
2488 SCTP_INP_RLOCK(inp);
2489 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2490 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2491 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2492 /* get inp's default */
2493 if (inp->sctp_ep.default_dscp & 0x01) {
2494 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2495 paddrp->spp_flags |= SPP_DSCP;
2498 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2499 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2500 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2501 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2504 /* can't return this */
2505 paddrp->spp_pathmtu = 0;
2507 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2508 paddrp->spp_flags |= SPP_HB_ENABLE;
2510 paddrp->spp_flags |= SPP_HB_DISABLE;
2512 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2513 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2515 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2517 SCTP_INP_RUNLOCK(inp);
2519 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2524 *optsize = sizeof(struct sctp_paddrparams);
2528 case SCTP_GET_PEER_ADDR_INFO:
2530 struct sctp_paddrinfo *paddri;
2531 struct sctp_nets *net;
2532 struct sockaddr *addr;
2534 #if defined(INET) && defined(INET6)
2535 struct sockaddr_in sin_store;
2539 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2540 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2542 #if defined(INET) && defined(INET6)
2543 if (paddri->spinfo_address.ss_family == AF_INET6) {
2544 struct sockaddr_in6 *sin6;
2546 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2547 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2548 in6_sin6_2_sin(&sin_store, sin6);
2549 addr = (struct sockaddr *)&sin_store;
2551 addr = (struct sockaddr *)&paddri->spinfo_address;
2554 addr = (struct sockaddr *)&paddri->spinfo_address;
2557 addr = (struct sockaddr *)&paddri->spinfo_address;
2560 net = sctp_findnet(stcb, addr);
2563 * We increment here since
2564 * sctp_findassociation_ep_addr() wil do a
2565 * decrement if it finds the stcb as long as
2566 * the locked tcb (last argument) is NOT a
2570 SCTP_INP_INCR_REF(inp);
2571 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2573 SCTP_INP_DECR_REF(inp);
2577 if ((stcb != NULL) && (net != NULL)) {
2578 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2579 /* It's unconfirmed */
2580 paddri->spinfo_state = SCTP_UNCONFIRMED;
2581 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2583 paddri->spinfo_state = SCTP_ACTIVE;
2586 paddri->spinfo_state = SCTP_INACTIVE;
2588 paddri->spinfo_cwnd = net->cwnd;
2589 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2590 paddri->spinfo_rto = net->RTO;
2591 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2592 paddri->spinfo_mtu = net->mtu;
2593 switch (addr->sa_family) {
2596 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2601 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2607 SCTP_TCB_UNLOCK(stcb);
2608 *optsize = sizeof(struct sctp_paddrinfo);
2611 SCTP_TCB_UNLOCK(stcb);
2613 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2618 case SCTP_PCB_STATUS:
2620 struct sctp_pcbinfo *spcb;
2622 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2623 sctp_fill_pcbinfo(spcb);
2624 *optsize = sizeof(struct sctp_pcbinfo);
2629 struct sctp_nets *net;
2630 struct sctp_status *sstat;
2632 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2633 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2636 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2640 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2641 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2642 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2643 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2645 * We can't include chunks that have been passed to
2646 * the socket layer. Only things in queue.
2648 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2649 stcb->asoc.cnt_on_all_streams);
2652 sstat->sstat_instrms = stcb->asoc.streamincnt;
2653 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2654 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2655 memcpy(&sstat->sstat_primary.spinfo_address,
2656 &stcb->asoc.primary_destination->ro._l_addr,
2657 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2658 net = stcb->asoc.primary_destination;
2659 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2661 * Again the user can get info from sctp_constants.h
2662 * for what the state of the network is.
2664 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2665 /* It's unconfirmed */
2666 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2667 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2669 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2672 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2674 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2675 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2676 sstat->sstat_primary.spinfo_rto = net->RTO;
2677 sstat->sstat_primary.spinfo_mtu = net->mtu;
2678 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2681 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2686 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2692 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2693 SCTP_TCB_UNLOCK(stcb);
2694 *optsize = sizeof(struct sctp_status);
2699 struct sctp_rtoinfo *srto;
2701 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2702 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2705 srto->srto_initial = stcb->asoc.initial_rto;
2706 srto->srto_max = stcb->asoc.maxrto;
2707 srto->srto_min = stcb->asoc.minrto;
2708 SCTP_TCB_UNLOCK(stcb);
2710 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2711 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2712 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2713 SCTP_INP_RLOCK(inp);
2714 srto->srto_initial = inp->sctp_ep.initial_rto;
2715 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2716 srto->srto_min = inp->sctp_ep.sctp_minrto;
2717 SCTP_INP_RUNLOCK(inp);
2719 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2724 *optsize = sizeof(struct sctp_rtoinfo);
2730 struct sctp_timeouts *stimo;
2732 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2733 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2736 stimo->stimo_init = stcb->asoc.timoinit;
2737 stimo->stimo_data = stcb->asoc.timodata;
2738 stimo->stimo_sack = stcb->asoc.timosack;
2739 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2740 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2741 stimo->stimo_cookie = stcb->asoc.timocookie;
2742 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2743 SCTP_TCB_UNLOCK(stcb);
2744 *optsize = sizeof(struct sctp_timeouts);
2746 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2751 case SCTP_ASSOCINFO:
2753 struct sctp_assocparams *sasoc;
2755 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2756 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2759 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2760 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2761 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2762 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2763 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2764 SCTP_TCB_UNLOCK(stcb);
2766 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2767 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2768 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2769 SCTP_INP_RLOCK(inp);
2770 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2771 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2772 sasoc->sasoc_number_peer_destinations = 0;
2773 sasoc->sasoc_peer_rwnd = 0;
2774 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2775 SCTP_INP_RUNLOCK(inp);
2777 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2782 *optsize = sizeof(struct sctp_assocparams);
2786 case SCTP_DEFAULT_SEND_PARAM:
2788 struct sctp_sndrcvinfo *s_info;
2790 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2791 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2794 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2795 SCTP_TCB_UNLOCK(stcb);
2797 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2798 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2799 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2800 SCTP_INP_RLOCK(inp);
2801 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2802 SCTP_INP_RUNLOCK(inp);
2804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2809 *optsize = sizeof(struct sctp_sndrcvinfo);
2815 struct sctp_initmsg *sinit;
2817 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2818 SCTP_INP_RLOCK(inp);
2819 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2820 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2821 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2822 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2823 SCTP_INP_RUNLOCK(inp);
2824 *optsize = sizeof(struct sctp_initmsg);
2827 case SCTP_PRIMARY_ADDR:
2828 /* we allow a "get" operation on this */
2830 struct sctp_setprim *ssp;
2832 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2833 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2836 union sctp_sockstore *addr;
2838 addr = &stcb->asoc.primary_destination->ro._l_addr;
2839 switch (addr->sa.sa_family) {
2843 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2844 in6_sin_2_v4mapsin6(&addr->sin,
2845 (struct sockaddr_in6 *)&ssp->ssp_addr);
2847 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2850 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2856 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2862 SCTP_TCB_UNLOCK(stcb);
2863 *optsize = sizeof(struct sctp_setprim);
2865 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2870 case SCTP_HMAC_IDENT:
2872 struct sctp_hmacalgo *shmac;
2873 sctp_hmaclist_t *hmaclist;
2877 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2879 SCTP_INP_RLOCK(inp);
2880 hmaclist = inp->sctp_ep.local_hmacs;
2881 if (hmaclist == NULL) {
2882 /* no HMACs to return */
2883 *optsize = sizeof(*shmac);
2884 SCTP_INP_RUNLOCK(inp);
2887 /* is there room for all of the hmac ids? */
2888 size = sizeof(*shmac) + (hmaclist->num_algo *
2889 sizeof(shmac->shmac_idents[0]));
2890 if ((size_t)(*optsize) < size) {
2891 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2893 SCTP_INP_RUNLOCK(inp);
2896 /* copy in the list */
2897 shmac->shmac_number_of_idents = hmaclist->num_algo;
2898 for (i = 0; i < hmaclist->num_algo; i++) {
2899 shmac->shmac_idents[i] = hmaclist->hmac[i];
2901 SCTP_INP_RUNLOCK(inp);
2905 case SCTP_AUTH_ACTIVE_KEY:
2907 struct sctp_authkeyid *scact;
2909 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2910 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2913 /* get the active key on the assoc */
2914 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2915 SCTP_TCB_UNLOCK(stcb);
2917 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2918 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2919 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2920 /* get the endpoint active key */
2921 SCTP_INP_RLOCK(inp);
2922 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2923 SCTP_INP_RUNLOCK(inp);
2925 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2930 *optsize = sizeof(struct sctp_authkeyid);
2934 case SCTP_LOCAL_AUTH_CHUNKS:
2936 struct sctp_authchunks *sac;
2937 sctp_auth_chklist_t *chklist = NULL;
2940 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2941 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2944 /* get off the assoc */
2945 chklist = stcb->asoc.local_auth_chunks;
2946 /* is there enough space? */
2947 size = sctp_auth_get_chklist_size(chklist);
2948 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2950 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2952 /* copy in the chunks */
2953 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2954 sac->gauth_number_of_chunks = (uint32_t) size;
2955 *optsize = sizeof(struct sctp_authchunks) + size;
2957 SCTP_TCB_UNLOCK(stcb);
2959 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2960 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2961 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2962 /* get off the endpoint */
2963 SCTP_INP_RLOCK(inp);
2964 chklist = inp->sctp_ep.local_auth_chunks;
2965 /* is there enough space? */
2966 size = sctp_auth_get_chklist_size(chklist);
2967 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2969 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2971 /* copy in the chunks */
2972 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2973 sac->gauth_number_of_chunks = (uint32_t) size;
2974 *optsize = sizeof(struct sctp_authchunks) + size;
2976 SCTP_INP_RUNLOCK(inp);
2978 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2984 case SCTP_PEER_AUTH_CHUNKS:
2986 struct sctp_authchunks *sac;
2987 sctp_auth_chklist_t *chklist = NULL;
2990 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2991 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2994 /* get off the assoc */
2995 chklist = stcb->asoc.peer_auth_chunks;
2996 /* is there enough space? */
2997 size = sctp_auth_get_chklist_size(chklist);
2998 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
3000 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3002 /* copy in the chunks */
3003 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3004 sac->gauth_number_of_chunks = (uint32_t) size;
3005 *optsize = sizeof(struct sctp_authchunks) + size;
3007 SCTP_TCB_UNLOCK(stcb);
3009 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3016 struct sctp_event *event;
3017 uint32_t event_type;
3019 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3020 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3022 switch (event->se_type) {
3023 case SCTP_ASSOC_CHANGE:
3024 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3026 case SCTP_PEER_ADDR_CHANGE:
3027 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3029 case SCTP_REMOTE_ERROR:
3030 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3032 case SCTP_SEND_FAILED:
3033 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3035 case SCTP_SHUTDOWN_EVENT:
3036 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3038 case SCTP_ADAPTATION_INDICATION:
3039 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3041 case SCTP_PARTIAL_DELIVERY_EVENT:
3042 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3044 case SCTP_AUTHENTICATION_EVENT:
3045 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3047 case SCTP_STREAM_RESET_EVENT:
3048 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3050 case SCTP_SENDER_DRY_EVENT:
3051 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3053 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3055 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3058 case SCTP_ASSOC_RESET_EVENT:
3059 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3061 case SCTP_STREAM_CHANGE_EVENT:
3062 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3064 case SCTP_SEND_FAILED_EVENT:
3065 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3069 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3073 if (event_type > 0) {
3075 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3076 SCTP_TCB_UNLOCK(stcb);
3078 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3079 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3080 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3081 SCTP_INP_RLOCK(inp);
3082 event->se_on = sctp_is_feature_on(inp, event_type);
3083 SCTP_INP_RUNLOCK(inp);
3085 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3091 *optsize = sizeof(struct sctp_event);
3095 case SCTP_RECVRCVINFO:
3099 if (*optsize < sizeof(int)) {
3100 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3103 SCTP_INP_RLOCK(inp);
3104 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3105 SCTP_INP_RUNLOCK(inp);
3108 /* return the option value */
3109 *(int *)optval = onoff;
3110 *optsize = sizeof(int);
3114 case SCTP_RECVNXTINFO:
3118 if (*optsize < sizeof(int)) {
3119 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3122 SCTP_INP_RLOCK(inp);
3123 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3124 SCTP_INP_RUNLOCK(inp);
3127 /* return the option value */
3128 *(int *)optval = onoff;
3129 *optsize = sizeof(int);
3133 case SCTP_DEFAULT_SNDINFO:
3135 struct sctp_sndinfo *info;
3137 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3138 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3141 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3142 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3143 info->snd_flags &= 0xfff0;
3144 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3145 info->snd_context = stcb->asoc.def_send.sinfo_context;
3146 SCTP_TCB_UNLOCK(stcb);
3148 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3149 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3150 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3151 SCTP_INP_RLOCK(inp);
3152 info->snd_sid = inp->def_send.sinfo_stream;
3153 info->snd_flags = inp->def_send.sinfo_flags;
3154 info->snd_flags &= 0xfff0;
3155 info->snd_ppid = inp->def_send.sinfo_ppid;
3156 info->snd_context = inp->def_send.sinfo_context;
3157 SCTP_INP_RUNLOCK(inp);
3159 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3164 *optsize = sizeof(struct sctp_sndinfo);
3168 case SCTP_DEFAULT_PRINFO:
3170 struct sctp_default_prinfo *info;
3172 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3173 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3176 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3177 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3178 SCTP_TCB_UNLOCK(stcb);
3180 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3181 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3182 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3183 SCTP_INP_RLOCK(inp);
3184 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3185 info->pr_value = inp->def_send.sinfo_timetolive;
3186 SCTP_INP_RUNLOCK(inp);
3188 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3193 *optsize = sizeof(struct sctp_default_prinfo);
3197 case SCTP_PEER_ADDR_THLDS:
3199 struct sctp_paddrthlds *thlds;
3200 struct sctp_nets *net;
3201 struct sockaddr *addr;
3203 #if defined(INET) && defined(INET6)
3204 struct sockaddr_in sin_store;
3208 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3209 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3211 #if defined(INET) && defined(INET6)
3212 if (thlds->spt_address.ss_family == AF_INET6) {
3213 struct sockaddr_in6 *sin6;
3215 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3216 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3217 in6_sin6_2_sin(&sin_store, sin6);
3218 addr = (struct sockaddr *)&sin_store;
3220 addr = (struct sockaddr *)&thlds->spt_address;
3223 addr = (struct sockaddr *)&thlds->spt_address;
3226 addr = (struct sockaddr *)&thlds->spt_address;
3229 net = sctp_findnet(stcb, addr);
3232 * We increment here since
3233 * sctp_findassociation_ep_addr() wil do a
3234 * decrement if it finds the stcb as long as
3235 * the locked tcb (last argument) is NOT a
3239 SCTP_INP_INCR_REF(inp);
3240 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3242 SCTP_INP_DECR_REF(inp);
3245 if ((stcb != NULL) && (net == NULL)) {
3247 if (addr->sa_family == AF_INET) {
3248 struct sockaddr_in *sin;
3250 sin = (struct sockaddr_in *)addr;
3251 if (sin->sin_addr.s_addr != INADDR_ANY) {
3253 SCTP_TCB_UNLOCK(stcb);
3254 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3260 if (addr->sa_family == AF_INET6) {
3261 struct sockaddr_in6 *sin6;
3263 sin6 = (struct sockaddr_in6 *)addr;
3264 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3266 SCTP_TCB_UNLOCK(stcb);
3267 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3273 error = EAFNOSUPPORT;
3274 SCTP_TCB_UNLOCK(stcb);
3275 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3281 thlds->spt_pathmaxrxt = net->failure_threshold;
3282 thlds->spt_pathpfthld = net->pf_threshold;
3284 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3285 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3287 thlds->spt_assoc_id = sctp_get_associd(stcb);
3288 SCTP_TCB_UNLOCK(stcb);
3290 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3291 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3292 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3293 /* Use endpoint defaults */
3294 SCTP_INP_RLOCK(inp);
3295 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3296 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3297 SCTP_INP_RUNLOCK(inp);
3299 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3304 *optsize = sizeof(struct sctp_paddrthlds);
3308 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3310 struct sctp_udpencaps *encaps;
3311 struct sctp_nets *net;
3312 struct sockaddr *addr;
3314 #if defined(INET) && defined(INET6)
3315 struct sockaddr_in sin_store;
3319 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3320 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3322 #if defined(INET) && defined(INET6)
3323 if (encaps->sue_address.ss_family == AF_INET6) {
3324 struct sockaddr_in6 *sin6;
3326 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3327 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3328 in6_sin6_2_sin(&sin_store, sin6);
3329 addr = (struct sockaddr *)&sin_store;
3331 addr = (struct sockaddr *)&encaps->sue_address;
3334 addr = (struct sockaddr *)&encaps->sue_address;
3337 addr = (struct sockaddr *)&encaps->sue_address;
3340 net = sctp_findnet(stcb, addr);
3343 * We increment here since
3344 * sctp_findassociation_ep_addr() wil do a
3345 * decrement if it finds the stcb as long as
3346 * the locked tcb (last argument) is NOT a
3350 SCTP_INP_INCR_REF(inp);
3351 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3353 SCTP_INP_DECR_REF(inp);
3356 if ((stcb != NULL) && (net == NULL)) {
3358 if (addr->sa_family == AF_INET) {
3359 struct sockaddr_in *sin;
3361 sin = (struct sockaddr_in *)addr;
3362 if (sin->sin_addr.s_addr != INADDR_ANY) {
3364 SCTP_TCB_UNLOCK(stcb);
3365 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3371 if (addr->sa_family == AF_INET6) {
3372 struct sockaddr_in6 *sin6;
3374 sin6 = (struct sockaddr_in6 *)addr;
3375 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3377 SCTP_TCB_UNLOCK(stcb);
3378 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3384 error = EAFNOSUPPORT;
3385 SCTP_TCB_UNLOCK(stcb);
3386 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3392 encaps->sue_port = net->port;
3394 encaps->sue_port = stcb->asoc.port;
3396 SCTP_TCB_UNLOCK(stcb);
3398 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3399 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3400 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3401 SCTP_INP_RLOCK(inp);
3402 encaps->sue_port = inp->sctp_ep.port;
3403 SCTP_INP_RUNLOCK(inp);
3405 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3410 *optsize = sizeof(struct sctp_udpencaps);
3414 case SCTP_ECN_SUPPORTED:
3416 struct sctp_assoc_value *av;
3418 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3419 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3422 av->assoc_value = stcb->asoc.ecn_supported;
3423 SCTP_TCB_UNLOCK(stcb);
3425 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3426 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3427 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3428 SCTP_INP_RLOCK(inp);
3429 av->assoc_value = inp->ecn_supported;
3430 SCTP_INP_RUNLOCK(inp);
3432 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3437 *optsize = sizeof(struct sctp_assoc_value);
3441 case SCTP_PR_SUPPORTED:
3443 struct sctp_assoc_value *av;
3445 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3446 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3449 av->assoc_value = stcb->asoc.prsctp_supported;
3450 SCTP_TCB_UNLOCK(stcb);
3452 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3453 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3454 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3455 SCTP_INP_RLOCK(inp);
3456 av->assoc_value = inp->prsctp_supported;
3457 SCTP_INP_RUNLOCK(inp);
3459 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3464 *optsize = sizeof(struct sctp_assoc_value);
3468 case SCTP_AUTH_SUPPORTED:
3470 struct sctp_assoc_value *av;
3472 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3473 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3476 av->assoc_value = stcb->asoc.auth_supported;
3477 SCTP_TCB_UNLOCK(stcb);
3479 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3480 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3481 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3482 SCTP_INP_RLOCK(inp);
3483 av->assoc_value = inp->auth_supported;
3484 SCTP_INP_RUNLOCK(inp);
3486 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3491 *optsize = sizeof(struct sctp_assoc_value);
3495 case SCTP_ASCONF_SUPPORTED:
3497 struct sctp_assoc_value *av;
3499 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3500 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3503 av->assoc_value = stcb->asoc.asconf_supported;
3504 SCTP_TCB_UNLOCK(stcb);
3506 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3507 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3508 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3509 SCTP_INP_RLOCK(inp);
3510 av->assoc_value = inp->asconf_supported;
3511 SCTP_INP_RUNLOCK(inp);
3513 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3518 *optsize = sizeof(struct sctp_assoc_value);
3522 case SCTP_RECONFIG_SUPPORTED:
3524 struct sctp_assoc_value *av;
3526 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3527 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3530 av->assoc_value = stcb->asoc.reconfig_supported;
3531 SCTP_TCB_UNLOCK(stcb);
3533 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3534 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3535 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3536 SCTP_INP_RLOCK(inp);
3537 av->assoc_value = inp->reconfig_supported;
3538 SCTP_INP_RUNLOCK(inp);
3540 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3545 *optsize = sizeof(struct sctp_assoc_value);
3549 case SCTP_NRSACK_SUPPORTED:
3551 struct sctp_assoc_value *av;
3553 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3554 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3557 av->assoc_value = stcb->asoc.nrsack_supported;
3558 SCTP_TCB_UNLOCK(stcb);
3560 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3561 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3562 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3563 SCTP_INP_RLOCK(inp);
3564 av->assoc_value = inp->nrsack_supported;
3565 SCTP_INP_RUNLOCK(inp);
3567 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3572 *optsize = sizeof(struct sctp_assoc_value);
3576 case SCTP_PKTDROP_SUPPORTED:
3578 struct sctp_assoc_value *av;
3580 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3581 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3584 av->assoc_value = stcb->asoc.pktdrop_supported;
3585 SCTP_TCB_UNLOCK(stcb);
3587 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3588 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3589 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3590 SCTP_INP_RLOCK(inp);
3591 av->assoc_value = inp->pktdrop_supported;
3592 SCTP_INP_RUNLOCK(inp);
3594 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3599 *optsize = sizeof(struct sctp_assoc_value);
3603 case SCTP_ENABLE_STREAM_RESET:
3605 struct sctp_assoc_value *av;
3607 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3608 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3611 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3612 SCTP_TCB_UNLOCK(stcb);
3614 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3615 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3616 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3617 SCTP_INP_RLOCK(inp);
3618 av->assoc_value = (uint32_t) inp->local_strreset_support;
3619 SCTP_INP_RUNLOCK(inp);
3621 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3626 *optsize = sizeof(struct sctp_assoc_value);
3630 case SCTP_PR_STREAM_STATUS:
3632 struct sctp_prstatus *sprstat;
3636 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3637 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3639 sid = sprstat->sprstat_sid;
3640 policy = sprstat->sprstat_policy;
3641 #if defined(SCTP_DETAILED_STR_STATS)
3642 if ((stcb != NULL) &&
3643 (sid < stcb->asoc.streamoutcnt) &&
3644 (policy != SCTP_PR_SCTP_NONE) &&
3645 ((policy <= SCTP_PR_SCTP_MAX) ||
3646 (policy == SCTP_PR_SCTP_ALL))) {
3647 if (policy == SCTP_PR_SCTP_ALL) {
3648 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3649 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3651 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3652 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3655 if ((stcb != NULL) &&
3656 (sid < stcb->asoc.streamoutcnt) &&
3657 (policy == SCTP_PR_SCTP_ALL)) {
3658 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3659 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3661 SCTP_TCB_UNLOCK(stcb);
3662 *optsize = sizeof(struct sctp_prstatus);
3664 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3669 case SCTP_PR_ASSOC_STATUS:
3671 struct sctp_prstatus *sprstat;
3674 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3675 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3677 policy = sprstat->sprstat_policy;
3678 if ((stcb != NULL) &&
3679 (policy != SCTP_PR_SCTP_NONE) &&
3680 ((policy <= SCTP_PR_SCTP_MAX) ||
3681 (policy == SCTP_PR_SCTP_ALL))) {
3682 if (policy == SCTP_PR_SCTP_ALL) {
3683 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3684 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3686 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3687 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3689 SCTP_TCB_UNLOCK(stcb);
3690 *optsize = sizeof(struct sctp_prstatus);
3692 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3699 struct sctp_assoc_value *av;
3701 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3702 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3705 av->assoc_value = stcb->asoc.max_cwnd;
3706 SCTP_TCB_UNLOCK(stcb);
3708 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3709 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3710 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3711 SCTP_INP_RLOCK(inp);
3712 av->assoc_value = inp->max_cwnd;
3713 SCTP_INP_RUNLOCK(inp);
3715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3720 *optsize = sizeof(struct sctp_assoc_value);
3725 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3726 error = ENOPROTOOPT;
3728 } /* end switch (sopt->sopt_name) */
3736 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3741 struct sctp_tcb *stcb = NULL;
3742 struct sctp_inpcb *inp = NULL;
3745 if (optval == NULL) {
3746 SCTP_PRINTF("optval is NULL\n");
3747 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3750 inp = (struct sctp_inpcb *)so->so_pcb;
3752 SCTP_PRINTF("inp is NULL?\n");
3753 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3756 vrf_id = inp->def_vrf_id;
3761 case SCTP_AUTOCLOSE:
3762 case SCTP_AUTO_ASCONF:
3763 case SCTP_EXPLICIT_EOR:
3764 case SCTP_DISABLE_FRAGMENTS:
3765 case SCTP_USE_EXT_RCVINFO:
3766 case SCTP_I_WANT_MAPPED_V4_ADDR:
3767 /* copy in the option value */
3768 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3773 case SCTP_DISABLE_FRAGMENTS:
3774 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3776 case SCTP_AUTO_ASCONF:
3778 * NOTE: we don't really support this flag
3780 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3781 /* only valid for bound all sockets */
3782 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3784 /* forbidden by admin */
3785 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3788 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3790 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3794 case SCTP_EXPLICIT_EOR:
3795 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3797 case SCTP_USE_EXT_RCVINFO:
3798 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3800 case SCTP_I_WANT_MAPPED_V4_ADDR:
3801 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3802 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3809 set_opt = SCTP_PCB_FLAGS_NODELAY;
3811 case SCTP_AUTOCLOSE:
3812 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3813 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3814 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3817 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3819 * The value is in ticks. Note this does not effect
3820 * old associations, only new ones.
3822 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3825 SCTP_INP_WLOCK(inp);
3827 sctp_feature_on(inp, set_opt);
3829 sctp_feature_off(inp, set_opt);
3831 SCTP_INP_WUNLOCK(inp);
3833 case SCTP_REUSE_PORT:
3835 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3836 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3837 /* Can't set it after we are bound */
3841 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3842 /* Can't do this for a 1-m socket */
3847 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3849 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3852 case SCTP_PARTIAL_DELIVERY_POINT:
3856 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3857 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3858 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3862 inp->partial_delivery_point = *value;
3865 case SCTP_FRAGMENT_INTERLEAVE:
3866 /* not yet until we re-write sctp_recvmsg() */
3870 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3871 if (*level == SCTP_FRAG_LEVEL_2) {
3872 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3873 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3874 } else if (*level == SCTP_FRAG_LEVEL_1) {
3875 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3876 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3877 } else if (*level == SCTP_FRAG_LEVEL_0) {
3878 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3879 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3887 case SCTP_CMT_ON_OFF:
3888 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3889 struct sctp_assoc_value *av;
3891 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3892 if (av->assoc_value > SCTP_CMT_MAX) {
3893 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3897 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3899 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3900 SCTP_TCB_UNLOCK(stcb);
3902 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3903 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3904 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3905 (av->assoc_id == SCTP_ALL_ASSOC)) {
3906 SCTP_INP_WLOCK(inp);
3907 inp->sctp_cmt_on_off = av->assoc_value;
3908 SCTP_INP_WUNLOCK(inp);
3910 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3911 (av->assoc_id == SCTP_ALL_ASSOC)) {
3912 SCTP_INP_RLOCK(inp);
3913 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3914 SCTP_TCB_LOCK(stcb);
3915 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3916 SCTP_TCB_UNLOCK(stcb);
3918 SCTP_INP_RUNLOCK(inp);
3922 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3923 error = ENOPROTOOPT;
3926 case SCTP_PLUGGABLE_CC:
3928 struct sctp_assoc_value *av;
3929 struct sctp_nets *net;
3931 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3932 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3933 (av->assoc_value != SCTP_CC_HSTCP) &&
3934 (av->assoc_value != SCTP_CC_HTCP) &&
3935 (av->assoc_value != SCTP_CC_RTCC)) {
3936 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3940 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3942 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3943 stcb->asoc.congestion_control_module = av->assoc_value;
3944 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3945 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3946 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3949 SCTP_TCB_UNLOCK(stcb);
3951 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3952 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3953 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3954 (av->assoc_id == SCTP_ALL_ASSOC)) {
3955 SCTP_INP_WLOCK(inp);
3956 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3957 SCTP_INP_WUNLOCK(inp);
3959 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3960 (av->assoc_id == SCTP_ALL_ASSOC)) {
3961 SCTP_INP_RLOCK(inp);
3962 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3963 SCTP_TCB_LOCK(stcb);
3964 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3965 stcb->asoc.congestion_control_module = av->assoc_value;
3966 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3967 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3968 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3971 SCTP_TCB_UNLOCK(stcb);
3973 SCTP_INP_RUNLOCK(inp);
3978 case SCTP_CC_OPTION:
3980 struct sctp_cc_option *cc_opt;
3982 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3983 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3985 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3986 SCTP_INP_RLOCK(inp);
3987 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3988 SCTP_TCB_LOCK(stcb);
3989 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3990 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3992 SCTP_TCB_UNLOCK(stcb);
3994 SCTP_INP_RUNLOCK(inp);
3999 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4002 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4005 SCTP_TCB_UNLOCK(stcb);
4009 case SCTP_PLUGGABLE_SS:
4011 struct sctp_assoc_value *av;
4013 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4014 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4015 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4016 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4017 (av->assoc_value != SCTP_SS_PRIORITY) &&
4018 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4019 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4020 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4024 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4026 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4027 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4028 stcb->asoc.stream_scheduling_module = av->assoc_value;
4029 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4030 SCTP_TCB_UNLOCK(stcb);
4032 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4033 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4034 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4035 (av->assoc_id == SCTP_ALL_ASSOC)) {
4036 SCTP_INP_WLOCK(inp);
4037 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4038 SCTP_INP_WUNLOCK(inp);
4040 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4041 (av->assoc_id == SCTP_ALL_ASSOC)) {
4042 SCTP_INP_RLOCK(inp);
4043 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4044 SCTP_TCB_LOCK(stcb);
4045 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4046 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4047 stcb->asoc.stream_scheduling_module = av->assoc_value;
4048 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4049 SCTP_TCB_UNLOCK(stcb);
4051 SCTP_INP_RUNLOCK(inp);
4058 struct sctp_stream_value *av;
4060 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4061 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4063 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4064 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4065 av->stream_value) < 0)) {
4066 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4069 SCTP_TCB_UNLOCK(stcb);
4071 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4072 SCTP_INP_RLOCK(inp);
4073 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4074 SCTP_TCB_LOCK(stcb);
4075 if (av->stream_id < stcb->asoc.streamoutcnt) {
4076 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4078 &stcb->asoc.strmout[av->stream_id],
4081 SCTP_TCB_UNLOCK(stcb);
4083 SCTP_INP_RUNLOCK(inp);
4086 * Can't set stream value without
4089 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4095 case SCTP_CLR_STAT_LOG:
4096 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4101 struct sctp_assoc_value *av;
4103 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4104 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4107 stcb->asoc.context = av->assoc_value;
4108 SCTP_TCB_UNLOCK(stcb);
4110 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4111 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4112 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4113 (av->assoc_id == SCTP_ALL_ASSOC)) {
4114 SCTP_INP_WLOCK(inp);
4115 inp->sctp_context = av->assoc_value;
4116 SCTP_INP_WUNLOCK(inp);
4118 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4119 (av->assoc_id == SCTP_ALL_ASSOC)) {
4120 SCTP_INP_RLOCK(inp);
4121 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4122 SCTP_TCB_LOCK(stcb);
4123 stcb->asoc.context = av->assoc_value;
4124 SCTP_TCB_UNLOCK(stcb);
4126 SCTP_INP_RUNLOCK(inp);
4133 uint32_t *default_vrfid;
4135 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4136 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4137 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4141 inp->def_vrf_id = *default_vrfid;
4144 case SCTP_DEL_VRF_ID:
4146 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4150 case SCTP_ADD_VRF_ID:
4152 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4156 case SCTP_DELAYED_SACK:
4158 struct sctp_sack_info *sack;
4160 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4161 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4162 if (sack->sack_delay) {
4163 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4164 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4165 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4166 sack->sack_delay = TICKS_TO_MSEC(1);
4170 if (sack->sack_delay) {
4171 stcb->asoc.delayed_ack = sack->sack_delay;
4173 if (sack->sack_freq) {
4174 stcb->asoc.sack_freq = sack->sack_freq;
4176 SCTP_TCB_UNLOCK(stcb);
4178 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4179 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4180 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4181 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4182 SCTP_INP_WLOCK(inp);
4183 if (sack->sack_delay) {
4184 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4186 if (sack->sack_freq) {
4187 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4189 SCTP_INP_WUNLOCK(inp);
4191 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4192 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4193 SCTP_INP_RLOCK(inp);
4194 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4195 SCTP_TCB_LOCK(stcb);
4196 if (sack->sack_delay) {
4197 stcb->asoc.delayed_ack = sack->sack_delay;
4199 if (sack->sack_freq) {
4200 stcb->asoc.sack_freq = sack->sack_freq;
4202 SCTP_TCB_UNLOCK(stcb);
4204 SCTP_INP_RUNLOCK(inp);
4209 case SCTP_AUTH_CHUNK:
4211 struct sctp_authchunk *sauth;
4213 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4215 SCTP_INP_WLOCK(inp);
4216 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4217 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4220 SCTP_INP_WUNLOCK(inp);
4225 struct sctp_authkey *sca;
4226 struct sctp_keyhead *shared_keys;
4227 sctp_sharedkey_t *shared_key;
4228 sctp_key_t *key = NULL;
4231 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4232 if (sca->sca_keylength == 0) {
4233 size = optsize - sizeof(struct sctp_authkey);
4235 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4236 size = sca->sca_keylength;
4238 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4243 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4246 shared_keys = &stcb->asoc.shared_keys;
4247 /* clear the cached keys for this key id */
4248 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4250 * create the new shared key and
4254 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4256 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4258 SCTP_TCB_UNLOCK(stcb);
4262 shared_key = sctp_alloc_sharedkey();
4263 if (shared_key == NULL) {
4265 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4267 SCTP_TCB_UNLOCK(stcb);
4270 shared_key->key = key;
4271 shared_key->keyid = sca->sca_keynumber;
4272 error = sctp_insert_sharedkey(shared_keys, shared_key);
4273 SCTP_TCB_UNLOCK(stcb);
4275 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4276 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4277 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4278 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4279 SCTP_INP_WLOCK(inp);
4280 shared_keys = &inp->sctp_ep.shared_keys;
4282 * clear the cached keys on all
4283 * assocs for this key id
4285 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4287 * create the new shared key and
4291 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4293 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4295 SCTP_INP_WUNLOCK(inp);
4299 shared_key = sctp_alloc_sharedkey();
4300 if (shared_key == NULL) {
4302 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4304 SCTP_INP_WUNLOCK(inp);
4307 shared_key->key = key;
4308 shared_key->keyid = sca->sca_keynumber;
4309 error = sctp_insert_sharedkey(shared_keys, shared_key);
4310 SCTP_INP_WUNLOCK(inp);
4312 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4313 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4314 SCTP_INP_RLOCK(inp);
4315 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4316 SCTP_TCB_LOCK(stcb);
4317 shared_keys = &stcb->asoc.shared_keys;
4319 * clear the cached keys for
4322 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4324 * create the new shared key
4325 * and insert/replace it
4328 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4330 SCTP_TCB_UNLOCK(stcb);
4334 shared_key = sctp_alloc_sharedkey();
4335 if (shared_key == NULL) {
4337 SCTP_TCB_UNLOCK(stcb);
4340 shared_key->key = key;
4341 shared_key->keyid = sca->sca_keynumber;
4342 error = sctp_insert_sharedkey(shared_keys, shared_key);
4343 SCTP_TCB_UNLOCK(stcb);
4345 SCTP_INP_RUNLOCK(inp);
4350 case SCTP_HMAC_IDENT:
4352 struct sctp_hmacalgo *shmac;
4353 sctp_hmaclist_t *hmaclist;
4357 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4358 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4359 (shmac->shmac_number_of_idents > 0xffff)) {
4360 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4364 hmaclist = sctp_alloc_hmaclist((uint16_t) shmac->shmac_number_of_idents);
4365 if (hmaclist == NULL) {
4366 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4370 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4371 hmacid = shmac->shmac_idents[i];
4372 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4373 /* invalid HMACs were found */ ;
4374 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4376 sctp_free_hmaclist(hmaclist);
4377 goto sctp_set_hmac_done;
4380 for (i = 0; i < hmaclist->num_algo; i++) {
4381 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4382 /* already in list */
4386 if (i == hmaclist->num_algo) {
4387 /* not found in list */
4388 sctp_free_hmaclist(hmaclist);
4389 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4393 /* set it on the endpoint */
4394 SCTP_INP_WLOCK(inp);
4395 if (inp->sctp_ep.local_hmacs)
4396 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4397 inp->sctp_ep.local_hmacs = hmaclist;
4398 SCTP_INP_WUNLOCK(inp);
4402 case SCTP_AUTH_ACTIVE_KEY:
4404 struct sctp_authkeyid *scact;
4406 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4407 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4409 /* set the active key on the right place */
4411 /* set the active key on the assoc */
4412 if (sctp_auth_setactivekey(stcb,
4413 scact->scact_keynumber)) {
4414 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4415 SCTP_FROM_SCTP_USRREQ,
4419 SCTP_TCB_UNLOCK(stcb);
4421 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4422 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4423 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4424 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4425 SCTP_INP_WLOCK(inp);
4426 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4427 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4430 SCTP_INP_WUNLOCK(inp);
4432 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4433 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4434 SCTP_INP_RLOCK(inp);
4435 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4436 SCTP_TCB_LOCK(stcb);
4437 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4438 SCTP_TCB_UNLOCK(stcb);
4440 SCTP_INP_RUNLOCK(inp);
4445 case SCTP_AUTH_DELETE_KEY:
4447 struct sctp_authkeyid *scdel;
4449 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4450 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4452 /* delete the key from the right place */
4454 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4455 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4458 SCTP_TCB_UNLOCK(stcb);
4460 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4461 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4462 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4463 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4464 SCTP_INP_WLOCK(inp);
4465 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4466 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4469 SCTP_INP_WUNLOCK(inp);
4471 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4472 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4473 SCTP_INP_RLOCK(inp);
4474 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4475 SCTP_TCB_LOCK(stcb);
4476 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4477 SCTP_TCB_UNLOCK(stcb);
4479 SCTP_INP_RUNLOCK(inp);
4484 case SCTP_AUTH_DEACTIVATE_KEY:
4486 struct sctp_authkeyid *keyid;
4488 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4489 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4491 /* deactivate the key from the right place */
4493 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4494 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4497 SCTP_TCB_UNLOCK(stcb);
4499 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4500 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4501 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4502 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4503 SCTP_INP_WLOCK(inp);
4504 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4505 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4508 SCTP_INP_WUNLOCK(inp);
4510 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4511 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4512 SCTP_INP_RLOCK(inp);
4513 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4514 SCTP_TCB_LOCK(stcb);
4515 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4516 SCTP_TCB_UNLOCK(stcb);
4518 SCTP_INP_RUNLOCK(inp);
4523 case SCTP_ENABLE_STREAM_RESET:
4525 struct sctp_assoc_value *av;
4527 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4528 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4529 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4533 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4535 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4536 SCTP_TCB_UNLOCK(stcb);
4538 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4539 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4540 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4541 (av->assoc_id == SCTP_ALL_ASSOC)) {
4542 SCTP_INP_WLOCK(inp);
4543 inp->local_strreset_support = (uint8_t) av->assoc_value;
4544 SCTP_INP_WUNLOCK(inp);
4546 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4547 (av->assoc_id == SCTP_ALL_ASSOC)) {
4548 SCTP_INP_RLOCK(inp);
4549 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4550 SCTP_TCB_LOCK(stcb);
4551 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4552 SCTP_TCB_UNLOCK(stcb);
4554 SCTP_INP_RUNLOCK(inp);
4559 case SCTP_RESET_STREAMS:
4561 struct sctp_reset_streams *strrst;
4562 int i, send_out = 0;
4565 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4566 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4568 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4572 if (stcb->asoc.reconfig_supported == 0) {
4574 * Peer does not support the chunk type.
4576 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4578 SCTP_TCB_UNLOCK(stcb);
4581 if (sizeof(struct sctp_reset_streams) +
4582 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4584 SCTP_TCB_UNLOCK(stcb);
4587 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4589 if (stcb->asoc.stream_reset_outstanding) {
4590 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4592 SCTP_TCB_UNLOCK(stcb);
4596 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4599 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4600 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4602 SCTP_TCB_UNLOCK(stcb);
4605 if ((send_in == 0) && (send_out == 0)) {
4606 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4608 SCTP_TCB_UNLOCK(stcb);
4611 for (i = 0; i < strrst->srs_number_streams; i++) {
4613 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4614 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4619 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4620 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4626 SCTP_TCB_UNLOCK(stcb);
4633 if (strrst->srs_number_streams) {
4634 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4635 strm = strrst->srs_stream_list[i];
4636 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4637 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4643 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4644 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4645 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4652 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4653 strrst->srs_stream_list,
4654 send_in, 0, 0, 0, 0, 0);
4656 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4659 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4662 * For outgoing streams don't report any
4663 * problems in sending the request to the
4664 * application. XXX: Double check resetting
4669 SCTP_TCB_UNLOCK(stcb);
4672 case SCTP_ADD_STREAMS:
4674 struct sctp_add_streams *stradd;
4675 uint8_t addstream = 0;
4676 uint16_t add_o_strmcnt = 0;
4677 uint16_t add_i_strmcnt = 0;
4679 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4680 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4682 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4686 if (stcb->asoc.reconfig_supported == 0) {
4688 * Peer does not support the chunk type.
4690 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4692 SCTP_TCB_UNLOCK(stcb);
4695 if (stcb->asoc.stream_reset_outstanding) {
4696 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4698 SCTP_TCB_UNLOCK(stcb);
4701 if ((stradd->sas_outstrms == 0) &&
4702 (stradd->sas_instrms == 0)) {
4706 if (stradd->sas_outstrms) {
4708 /* We allocate here */
4709 add_o_strmcnt = stradd->sas_outstrms;
4710 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4711 /* You can't have more than 64k */
4716 if (stradd->sas_instrms) {
4721 * We allocate inside
4722 * sctp_send_str_reset_req()
4724 add_i_strmcnt = stradd->sas_instrms;
4725 cnt = add_i_strmcnt;
4726 cnt += stcb->asoc.streamincnt;
4727 if (cnt > 0x0000ffff) {
4728 /* You can't have more than 64k */
4732 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4733 /* More than you are allowed */
4738 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4739 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4741 SCTP_TCB_UNLOCK(stcb);
4744 case SCTP_RESET_ASSOC:
4749 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4750 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4752 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4756 if (stcb->asoc.reconfig_supported == 0) {
4758 * Peer does not support the chunk type.
4760 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4762 SCTP_TCB_UNLOCK(stcb);
4765 if (stcb->asoc.stream_reset_outstanding) {
4766 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4768 SCTP_TCB_UNLOCK(stcb);
4772 * Is there any data pending in the send or sent
4775 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4776 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4779 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4780 SCTP_TCB_UNLOCK(stcb);
4783 /* Do any streams have data queued? */
4784 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4785 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4789 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4790 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4791 SCTP_TCB_UNLOCK(stcb);
4794 case SCTP_CONNECT_X:
4795 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4796 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4800 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4802 case SCTP_CONNECT_X_DELAYED:
4803 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4808 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4810 case SCTP_CONNECT_X_COMPLETE:
4812 struct sockaddr *sa;
4814 /* FIXME MT: check correct? */
4815 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4818 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4819 SCTP_INP_RLOCK(inp);
4820 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4822 SCTP_TCB_LOCK(stcb);
4824 SCTP_INP_RUNLOCK(inp);
4827 * We increment here since
4828 * sctp_findassociation_ep_addr() wil do a
4829 * decrement if it finds the stcb as long as
4830 * the locked tcb (last argument) is NOT a
4833 SCTP_INP_INCR_REF(inp);
4834 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4836 SCTP_INP_DECR_REF(inp);
4841 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4845 if (stcb->asoc.delayed_connection == 1) {
4846 stcb->asoc.delayed_connection = 0;
4847 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4848 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4849 stcb->asoc.primary_destination,
4850 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4851 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4854 * already expired or did not use delayed
4857 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4860 SCTP_TCB_UNLOCK(stcb);
4863 case SCTP_MAX_BURST:
4865 struct sctp_assoc_value *av;
4867 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4868 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4871 stcb->asoc.max_burst = av->assoc_value;
4872 SCTP_TCB_UNLOCK(stcb);
4874 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4875 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4876 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4877 (av->assoc_id == SCTP_ALL_ASSOC)) {
4878 SCTP_INP_WLOCK(inp);
4879 inp->sctp_ep.max_burst = av->assoc_value;
4880 SCTP_INP_WUNLOCK(inp);
4882 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4883 (av->assoc_id == SCTP_ALL_ASSOC)) {
4884 SCTP_INP_RLOCK(inp);
4885 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4886 SCTP_TCB_LOCK(stcb);
4887 stcb->asoc.max_burst = av->assoc_value;
4888 SCTP_TCB_UNLOCK(stcb);
4890 SCTP_INP_RUNLOCK(inp);
4897 struct sctp_assoc_value *av;
4900 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4901 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4903 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4904 ovh = SCTP_MED_OVERHEAD;
4906 ovh = SCTP_MED_V4_OVERHEAD;
4909 if (av->assoc_value) {
4910 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4912 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4914 SCTP_TCB_UNLOCK(stcb);
4916 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4917 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4918 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4919 SCTP_INP_WLOCK(inp);
4921 * FIXME MT: I think this is not in
4922 * tune with the API ID
4924 if (av->assoc_value) {
4925 inp->sctp_frag_point = (av->assoc_value + ovh);
4927 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4929 SCTP_INP_WUNLOCK(inp);
4931 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4939 struct sctp_event_subscribe *events;
4941 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4943 SCTP_INP_WLOCK(inp);
4944 if (events->sctp_data_io_event) {
4945 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4947 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4950 if (events->sctp_association_event) {
4951 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4953 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4956 if (events->sctp_address_event) {
4957 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4959 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4962 if (events->sctp_send_failure_event) {
4963 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4965 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4968 if (events->sctp_peer_error_event) {
4969 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4971 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4974 if (events->sctp_shutdown_event) {
4975 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4977 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4980 if (events->sctp_partial_delivery_event) {
4981 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4983 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4986 if (events->sctp_adaptation_layer_event) {
4987 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4989 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4992 if (events->sctp_authentication_event) {
4993 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4995 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4998 if (events->sctp_sender_dry_event) {
4999 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5001 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5004 if (events->sctp_stream_reset_event) {
5005 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5007 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5009 SCTP_INP_WUNLOCK(inp);
5011 SCTP_INP_RLOCK(inp);
5012 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5013 SCTP_TCB_LOCK(stcb);
5014 if (events->sctp_association_event) {
5015 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5017 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5019 if (events->sctp_address_event) {
5020 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5022 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5024 if (events->sctp_send_failure_event) {
5025 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5027 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5029 if (events->sctp_peer_error_event) {
5030 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5032 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5034 if (events->sctp_shutdown_event) {
5035 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5037 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5039 if (events->sctp_partial_delivery_event) {
5040 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5042 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5044 if (events->sctp_adaptation_layer_event) {
5045 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5047 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5049 if (events->sctp_authentication_event) {
5050 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5052 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5054 if (events->sctp_sender_dry_event) {
5055 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5057 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5059 if (events->sctp_stream_reset_event) {
5060 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5062 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5064 SCTP_TCB_UNLOCK(stcb);
5067 * Send up the sender dry event only for 1-to-1
5070 if (events->sctp_sender_dry_event) {
5071 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5072 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5073 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5075 SCTP_TCB_LOCK(stcb);
5076 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5077 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5078 (stcb->asoc.stream_queue_cnt == 0)) {
5079 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5081 SCTP_TCB_UNLOCK(stcb);
5085 SCTP_INP_RUNLOCK(inp);
5088 case SCTP_ADAPTATION_LAYER:
5090 struct sctp_setadaptation *adap_bits;
5092 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5093 SCTP_INP_WLOCK(inp);
5094 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5095 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5096 SCTP_INP_WUNLOCK(inp);
5100 case SCTP_SET_INITIAL_DBG_SEQ:
5104 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5105 SCTP_INP_WLOCK(inp);
5106 inp->sctp_ep.initial_sequence_debug = *vvv;
5107 SCTP_INP_WUNLOCK(inp);
5111 case SCTP_DEFAULT_SEND_PARAM:
5113 struct sctp_sndrcvinfo *s_info;
5115 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5116 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5119 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5120 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5122 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5125 SCTP_TCB_UNLOCK(stcb);
5127 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5128 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5129 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5130 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5131 SCTP_INP_WLOCK(inp);
5132 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5133 SCTP_INP_WUNLOCK(inp);
5135 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5136 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5137 SCTP_INP_RLOCK(inp);
5138 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5139 SCTP_TCB_LOCK(stcb);
5140 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5141 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5143 SCTP_TCB_UNLOCK(stcb);
5145 SCTP_INP_RUNLOCK(inp);
5150 case SCTP_PEER_ADDR_PARAMS:
5152 struct sctp_paddrparams *paddrp;
5153 struct sctp_nets *net;
5154 struct sockaddr *addr;
5156 #if defined(INET) && defined(INET6)
5157 struct sockaddr_in sin_store;
5161 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5162 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5164 #if defined(INET) && defined(INET6)
5165 if (paddrp->spp_address.ss_family == AF_INET6) {
5166 struct sockaddr_in6 *sin6;
5168 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5169 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5170 in6_sin6_2_sin(&sin_store, sin6);
5171 addr = (struct sockaddr *)&sin_store;
5173 addr = (struct sockaddr *)&paddrp->spp_address;
5176 addr = (struct sockaddr *)&paddrp->spp_address;
5179 addr = (struct sockaddr *)&paddrp->spp_address;
5182 net = sctp_findnet(stcb, addr);
5185 * We increment here since
5186 * sctp_findassociation_ep_addr() wil do a
5187 * decrement if it finds the stcb as long as
5188 * the locked tcb (last argument) is NOT a
5192 SCTP_INP_INCR_REF(inp);
5193 stcb = sctp_findassociation_ep_addr(&inp, addr,
5196 SCTP_INP_DECR_REF(inp);
5199 if ((stcb != NULL) && (net == NULL)) {
5201 if (addr->sa_family == AF_INET) {
5203 struct sockaddr_in *sin;
5205 sin = (struct sockaddr_in *)addr;
5206 if (sin->sin_addr.s_addr != INADDR_ANY) {
5207 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5208 SCTP_TCB_UNLOCK(stcb);
5215 if (addr->sa_family == AF_INET6) {
5216 struct sockaddr_in6 *sin6;
5218 sin6 = (struct sockaddr_in6 *)addr;
5219 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5220 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5221 SCTP_TCB_UNLOCK(stcb);
5228 error = EAFNOSUPPORT;
5229 SCTP_TCB_UNLOCK(stcb);
5230 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5235 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5237 SCTP_TCB_UNLOCK(stcb);
5238 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5241 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5243 SCTP_TCB_UNLOCK(stcb);
5244 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5248 /************************TCB SPECIFIC SET ******************/
5250 /************************NET SPECIFIC SET ******************/
5251 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5252 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5253 !(net->dest_state & SCTP_ADDR_NOHB)) {
5254 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5255 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5257 net->dest_state |= SCTP_ADDR_NOHB;
5259 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5260 if (paddrp->spp_hbinterval) {
5261 net->heart_beat_delay = paddrp->spp_hbinterval;
5262 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5263 net->heart_beat_delay = 0;
5265 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5266 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5267 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5268 net->dest_state &= ~SCTP_ADDR_NOHB;
5270 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5272 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5273 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5274 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5276 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5277 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5278 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5279 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5281 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5282 net->mtu = paddrp->spp_pathmtu;
5283 switch (net->ro._l_addr.sa.sa_family) {
5286 net->mtu += SCTP_MIN_V4_OVERHEAD;
5291 net->mtu += SCTP_MIN_OVERHEAD;
5297 if (net->mtu < stcb->asoc.smallest_mtu) {
5298 sctp_pathmtu_adjustment(stcb, net->mtu);
5301 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5302 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5303 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5305 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5307 if (paddrp->spp_pathmaxrxt) {
5308 if (net->dest_state & SCTP_ADDR_PF) {
5309 if (net->error_count > paddrp->spp_pathmaxrxt) {
5310 net->dest_state &= ~SCTP_ADDR_PF;
5313 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5314 (net->error_count > net->pf_threshold)) {
5315 net->dest_state |= SCTP_ADDR_PF;
5316 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5317 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5318 stcb->sctp_ep, stcb, net,
5319 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5320 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5323 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5324 if (net->error_count > paddrp->spp_pathmaxrxt) {
5325 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5326 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5329 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5330 net->dest_state |= SCTP_ADDR_REACHABLE;
5331 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5334 net->failure_threshold = paddrp->spp_pathmaxrxt;
5336 if (paddrp->spp_flags & SPP_DSCP) {
5337 net->dscp = paddrp->spp_dscp & 0xfc;
5341 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5342 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5343 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5344 net->flowlabel |= 0x80000000;
5349 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5350 if (paddrp->spp_pathmaxrxt != 0) {
5351 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5352 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5353 if (net->dest_state & SCTP_ADDR_PF) {
5354 if (net->error_count > paddrp->spp_pathmaxrxt) {
5355 net->dest_state &= ~SCTP_ADDR_PF;
5358 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5359 (net->error_count > net->pf_threshold)) {
5360 net->dest_state |= SCTP_ADDR_PF;
5361 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5362 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5363 stcb->sctp_ep, stcb, net,
5364 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5365 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5368 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5369 if (net->error_count > paddrp->spp_pathmaxrxt) {
5370 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5371 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5374 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5375 net->dest_state |= SCTP_ADDR_REACHABLE;
5376 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5379 net->failure_threshold = paddrp->spp_pathmaxrxt;
5382 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5383 if (paddrp->spp_hbinterval != 0) {
5384 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5385 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5386 stcb->asoc.heart_beat_delay = 0;
5388 /* Turn back on the timer */
5389 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5390 if (paddrp->spp_hbinterval != 0) {
5391 net->heart_beat_delay = paddrp->spp_hbinterval;
5392 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5393 net->heart_beat_delay = 0;
5395 if (net->dest_state & SCTP_ADDR_NOHB) {
5396 net->dest_state &= ~SCTP_ADDR_NOHB;
5398 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5399 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5400 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5402 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5404 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5405 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5406 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5407 net->dest_state |= SCTP_ADDR_NOHB;
5408 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5409 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5411 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5415 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5417 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5418 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5419 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5420 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5421 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5423 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5424 net->mtu = paddrp->spp_pathmtu;
5425 switch (net->ro._l_addr.sa.sa_family) {
5428 net->mtu += SCTP_MIN_V4_OVERHEAD;
5433 net->mtu += SCTP_MIN_OVERHEAD;
5439 if (net->mtu < stcb->asoc.smallest_mtu) {
5440 sctp_pathmtu_adjustment(stcb, net->mtu);
5443 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5445 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5446 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5447 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5448 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5450 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5452 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5454 if (paddrp->spp_flags & SPP_DSCP) {
5455 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5456 net->dscp = paddrp->spp_dscp & 0xfc;
5459 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5460 stcb->asoc.default_dscp |= 0x01;
5463 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5464 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5465 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5466 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5467 net->flowlabel |= 0x80000000;
5470 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5471 stcb->asoc.default_flowlabel |= 0x80000000;
5475 SCTP_TCB_UNLOCK(stcb);
5477 /************************NO TCB, SET TO default stuff ******************/
5478 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5479 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5480 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5481 SCTP_INP_WLOCK(inp);
5483 * For the TOS/FLOWLABEL stuff you
5484 * set it with the options on the
5487 if (paddrp->spp_pathmaxrxt != 0) {
5488 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5490 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5491 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5492 else if (paddrp->spp_hbinterval != 0) {
5493 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5494 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5495 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5497 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5498 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5499 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5500 } else if (paddrp->spp_hbinterval) {
5501 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5503 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5504 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5505 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5507 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5508 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5509 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5510 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5512 if (paddrp->spp_flags & SPP_DSCP) {
5513 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5514 inp->sctp_ep.default_dscp |= 0x01;
5517 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5518 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5519 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5520 inp->sctp_ep.default_flowlabel |= 0x80000000;
5524 SCTP_INP_WUNLOCK(inp);
5526 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5534 struct sctp_rtoinfo *srto;
5535 uint32_t new_init, new_min, new_max;
5537 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5538 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5541 if (srto->srto_initial)
5542 new_init = srto->srto_initial;
5544 new_init = stcb->asoc.initial_rto;
5546 new_max = srto->srto_max;
5548 new_max = stcb->asoc.maxrto;
5550 new_min = srto->srto_min;
5552 new_min = stcb->asoc.minrto;
5553 if ((new_min <= new_init) && (new_init <= new_max)) {
5554 stcb->asoc.initial_rto = new_init;
5555 stcb->asoc.maxrto = new_max;
5556 stcb->asoc.minrto = new_min;
5558 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5561 SCTP_TCB_UNLOCK(stcb);
5563 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5564 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5565 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5566 SCTP_INP_WLOCK(inp);
5567 if (srto->srto_initial)
5568 new_init = srto->srto_initial;
5570 new_init = inp->sctp_ep.initial_rto;
5572 new_max = srto->srto_max;
5574 new_max = inp->sctp_ep.sctp_maxrto;
5576 new_min = srto->srto_min;
5578 new_min = inp->sctp_ep.sctp_minrto;
5579 if ((new_min <= new_init) && (new_init <= new_max)) {
5580 inp->sctp_ep.initial_rto = new_init;
5581 inp->sctp_ep.sctp_maxrto = new_max;
5582 inp->sctp_ep.sctp_minrto = new_min;
5584 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5587 SCTP_INP_WUNLOCK(inp);
5589 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5595 case SCTP_ASSOCINFO:
5597 struct sctp_assocparams *sasoc;
5599 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5600 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5601 if (sasoc->sasoc_cookie_life) {
5602 /* boundary check the cookie life */
5603 if (sasoc->sasoc_cookie_life < 1000)
5604 sasoc->sasoc_cookie_life = 1000;
5605 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5606 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5610 if (sasoc->sasoc_asocmaxrxt)
5611 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5612 if (sasoc->sasoc_cookie_life) {
5613 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5615 SCTP_TCB_UNLOCK(stcb);
5617 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5618 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5619 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5620 SCTP_INP_WLOCK(inp);
5621 if (sasoc->sasoc_asocmaxrxt)
5622 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5623 if (sasoc->sasoc_cookie_life) {
5624 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5626 SCTP_INP_WUNLOCK(inp);
5628 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5636 struct sctp_initmsg *sinit;
5638 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5639 SCTP_INP_WLOCK(inp);
5640 if (sinit->sinit_num_ostreams)
5641 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5643 if (sinit->sinit_max_instreams)
5644 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5646 if (sinit->sinit_max_attempts)
5647 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5649 if (sinit->sinit_max_init_timeo)
5650 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5651 SCTP_INP_WUNLOCK(inp);
5654 case SCTP_PRIMARY_ADDR:
5656 struct sctp_setprim *spa;
5657 struct sctp_nets *net;
5658 struct sockaddr *addr;
5660 #if defined(INET) && defined(INET6)
5661 struct sockaddr_in sin_store;
5665 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5666 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5668 #if defined(INET) && defined(INET6)
5669 if (spa->ssp_addr.ss_family == AF_INET6) {
5670 struct sockaddr_in6 *sin6;
5672 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5673 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5674 in6_sin6_2_sin(&sin_store, sin6);
5675 addr = (struct sockaddr *)&sin_store;
5677 addr = (struct sockaddr *)&spa->ssp_addr;
5680 addr = (struct sockaddr *)&spa->ssp_addr;
5683 addr = (struct sockaddr *)&spa->ssp_addr;
5686 net = sctp_findnet(stcb, addr);
5689 * We increment here since
5690 * sctp_findassociation_ep_addr() wil do a
5691 * decrement if it finds the stcb as long as
5692 * the locked tcb (last argument) is NOT a
5696 SCTP_INP_INCR_REF(inp);
5697 stcb = sctp_findassociation_ep_addr(&inp, addr,
5700 SCTP_INP_DECR_REF(inp);
5704 if ((stcb != NULL) && (net != NULL)) {
5705 if (net != stcb->asoc.primary_destination) {
5706 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5707 /* Ok we need to set it */
5708 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5709 if ((stcb->asoc.alternate) &&
5710 (!(net->dest_state & SCTP_ADDR_PF)) &&
5711 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5712 sctp_free_remote_addr(stcb->asoc.alternate);
5713 stcb->asoc.alternate = NULL;
5716 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5720 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5725 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5729 SCTP_TCB_UNLOCK(stcb);
5733 case SCTP_SET_DYNAMIC_PRIMARY:
5735 union sctp_sockstore *ss;
5737 error = priv_check(curthread,
5738 PRIV_NETINET_RESERVEDPORT);
5742 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5743 /* SUPER USER CHECK? */
5744 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5747 case SCTP_SET_PEER_PRIMARY_ADDR:
5749 struct sctp_setpeerprim *sspp;
5750 struct sockaddr *addr;
5752 #if defined(INET) && defined(INET6)
5753 struct sockaddr_in sin_store;
5757 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5758 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5760 struct sctp_ifa *ifa;
5762 #if defined(INET) && defined(INET6)
5763 if (sspp->sspp_addr.ss_family == AF_INET6) {
5764 struct sockaddr_in6 *sin6;
5766 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5767 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5768 in6_sin6_2_sin(&sin_store, sin6);
5769 addr = (struct sockaddr *)&sin_store;
5771 addr = (struct sockaddr *)&sspp->sspp_addr;
5774 addr = (struct sockaddr *)&sspp->sspp_addr;
5777 addr = (struct sockaddr *)&sspp->sspp_addr;
5779 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5781 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5785 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5787 * Must validate the ifa found is in
5790 struct sctp_laddr *laddr;
5793 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5794 if (laddr->ifa == NULL) {
5795 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5799 if (laddr->ifa == ifa) {
5805 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5810 switch (addr->sa_family) {
5814 struct sockaddr_in *sin;
5816 sin = (struct sockaddr_in *)addr;
5817 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5818 &sin->sin_addr) != 0) {
5819 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5829 struct sockaddr_in6 *sin6;
5831 sin6 = (struct sockaddr_in6 *)addr;
5832 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5833 &sin6->sin6_addr) != 0) {
5834 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5842 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5847 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5848 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5852 SCTP_TCB_UNLOCK(stcb);
5854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5859 case SCTP_BINDX_ADD_ADDR:
5861 struct sctp_getaddresses *addrs;
5864 td = (struct thread *)p;
5865 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5868 if (addrs->addr->sa_family == AF_INET) {
5869 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5870 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5874 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5875 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5881 if (addrs->addr->sa_family == AF_INET6) {
5882 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5883 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5887 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5888 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5889 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5895 error = EAFNOSUPPORT;
5898 sctp_bindx_add_address(so, inp, addrs->addr,
5899 addrs->sget_assoc_id, vrf_id,
5903 case SCTP_BINDX_REM_ADDR:
5905 struct sctp_getaddresses *addrs;
5908 td = (struct thread *)p;
5910 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5912 if (addrs->addr->sa_family == AF_INET) {
5913 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5914 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5918 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5919 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5925 if (addrs->addr->sa_family == AF_INET6) {
5926 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5927 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5932 (error = prison_local_ip6(td->td_ucred,
5933 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5934 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5935 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5941 error = EAFNOSUPPORT;
5944 sctp_bindx_delete_address(inp, addrs->addr,
5945 addrs->sget_assoc_id, vrf_id,
5951 struct sctp_event *event;
5952 uint32_t event_type;
5954 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5955 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5956 switch (event->se_type) {
5957 case SCTP_ASSOC_CHANGE:
5958 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5960 case SCTP_PEER_ADDR_CHANGE:
5961 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5963 case SCTP_REMOTE_ERROR:
5964 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5966 case SCTP_SEND_FAILED:
5967 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5969 case SCTP_SHUTDOWN_EVENT:
5970 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5972 case SCTP_ADAPTATION_INDICATION:
5973 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5975 case SCTP_PARTIAL_DELIVERY_EVENT:
5976 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5978 case SCTP_AUTHENTICATION_EVENT:
5979 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5981 case SCTP_STREAM_RESET_EVENT:
5982 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5984 case SCTP_SENDER_DRY_EVENT:
5985 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5987 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5989 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5992 case SCTP_ASSOC_RESET_EVENT:
5993 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
5995 case SCTP_STREAM_CHANGE_EVENT:
5996 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
5998 case SCTP_SEND_FAILED_EVENT:
5999 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6003 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6007 if (event_type > 0) {
6010 sctp_stcb_feature_on(inp, stcb, event_type);
6011 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6012 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6013 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6014 (stcb->asoc.stream_queue_cnt == 0)) {
6015 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6019 sctp_stcb_feature_off(inp, stcb, event_type);
6021 SCTP_TCB_UNLOCK(stcb);
6024 * We don't want to send up a storm
6025 * of events, so return an error for
6028 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6029 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6030 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6031 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6032 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6033 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6037 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6038 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6039 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6040 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6041 SCTP_INP_WLOCK(inp);
6043 sctp_feature_on(inp, event_type);
6045 sctp_feature_off(inp, event_type);
6047 SCTP_INP_WUNLOCK(inp);
6049 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6050 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6051 SCTP_INP_RLOCK(inp);
6052 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6053 SCTP_TCB_LOCK(stcb);
6055 sctp_stcb_feature_on(inp, stcb, event_type);
6057 sctp_stcb_feature_off(inp, stcb, event_type);
6059 SCTP_TCB_UNLOCK(stcb);
6061 SCTP_INP_RUNLOCK(inp);
6067 case SCTP_RECVRCVINFO:
6071 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6072 SCTP_INP_WLOCK(inp);
6074 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6076 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6078 SCTP_INP_WUNLOCK(inp);
6081 case SCTP_RECVNXTINFO:
6085 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6086 SCTP_INP_WLOCK(inp);
6088 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6090 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6092 SCTP_INP_WUNLOCK(inp);
6095 case SCTP_DEFAULT_SNDINFO:
6097 struct sctp_sndinfo *info;
6100 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6101 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6104 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6105 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6106 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6107 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6108 stcb->asoc.def_send.sinfo_flags |= policy;
6109 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6110 stcb->asoc.def_send.sinfo_context = info->snd_context;
6112 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6115 SCTP_TCB_UNLOCK(stcb);
6117 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6118 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6119 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6120 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6121 SCTP_INP_WLOCK(inp);
6122 inp->def_send.sinfo_stream = info->snd_sid;
6123 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6124 inp->def_send.sinfo_flags = info->snd_flags;
6125 inp->def_send.sinfo_flags |= policy;
6126 inp->def_send.sinfo_ppid = info->snd_ppid;
6127 inp->def_send.sinfo_context = info->snd_context;
6128 SCTP_INP_WUNLOCK(inp);
6130 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6131 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6132 SCTP_INP_RLOCK(inp);
6133 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6134 SCTP_TCB_LOCK(stcb);
6135 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6136 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6137 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6138 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6139 stcb->asoc.def_send.sinfo_flags |= policy;
6140 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6141 stcb->asoc.def_send.sinfo_context = info->snd_context;
6143 SCTP_TCB_UNLOCK(stcb);
6145 SCTP_INP_RUNLOCK(inp);
6150 case SCTP_DEFAULT_PRINFO:
6152 struct sctp_default_prinfo *info;
6154 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6155 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6157 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6158 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6163 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6164 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6165 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6166 SCTP_TCB_UNLOCK(stcb);
6168 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6169 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6170 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6171 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6172 SCTP_INP_WLOCK(inp);
6173 inp->def_send.sinfo_flags &= 0xfff0;
6174 inp->def_send.sinfo_flags |= info->pr_policy;
6175 inp->def_send.sinfo_timetolive = info->pr_value;
6176 SCTP_INP_WUNLOCK(inp);
6178 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6179 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6180 SCTP_INP_RLOCK(inp);
6181 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6182 SCTP_TCB_LOCK(stcb);
6183 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6184 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6185 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6186 SCTP_TCB_UNLOCK(stcb);
6188 SCTP_INP_RUNLOCK(inp);
6193 case SCTP_PEER_ADDR_THLDS:
6194 /* Applies to the specific association */
6196 struct sctp_paddrthlds *thlds;
6197 struct sctp_nets *net;
6198 struct sockaddr *addr;
6200 #if defined(INET) && defined(INET6)
6201 struct sockaddr_in sin_store;
6205 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6206 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6208 #if defined(INET) && defined(INET6)
6209 if (thlds->spt_address.ss_family == AF_INET6) {
6210 struct sockaddr_in6 *sin6;
6212 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6213 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6214 in6_sin6_2_sin(&sin_store, sin6);
6215 addr = (struct sockaddr *)&sin_store;
6217 addr = (struct sockaddr *)&thlds->spt_address;
6220 addr = (struct sockaddr *)&thlds->spt_address;
6223 addr = (struct sockaddr *)&thlds->spt_address;
6226 net = sctp_findnet(stcb, addr);
6229 * We increment here since
6230 * sctp_findassociation_ep_addr() wil do a
6231 * decrement if it finds the stcb as long as
6232 * the locked tcb (last argument) is NOT a
6236 SCTP_INP_INCR_REF(inp);
6237 stcb = sctp_findassociation_ep_addr(&inp, addr,
6240 SCTP_INP_DECR_REF(inp);
6243 if ((stcb != NULL) && (net == NULL)) {
6245 if (addr->sa_family == AF_INET) {
6247 struct sockaddr_in *sin;
6249 sin = (struct sockaddr_in *)addr;
6250 if (sin->sin_addr.s_addr != INADDR_ANY) {
6251 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6252 SCTP_TCB_UNLOCK(stcb);
6259 if (addr->sa_family == AF_INET6) {
6260 struct sockaddr_in6 *sin6;
6262 sin6 = (struct sockaddr_in6 *)addr;
6263 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6264 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6265 SCTP_TCB_UNLOCK(stcb);
6272 error = EAFNOSUPPORT;
6273 SCTP_TCB_UNLOCK(stcb);
6274 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6280 net->failure_threshold = thlds->spt_pathmaxrxt;
6281 net->pf_threshold = thlds->spt_pathpfthld;
6282 if (net->dest_state & SCTP_ADDR_PF) {
6283 if ((net->error_count > net->failure_threshold) ||
6284 (net->error_count <= net->pf_threshold)) {
6285 net->dest_state &= ~SCTP_ADDR_PF;
6288 if ((net->error_count > net->pf_threshold) &&
6289 (net->error_count <= net->failure_threshold)) {
6290 net->dest_state |= SCTP_ADDR_PF;
6291 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6292 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6293 stcb->sctp_ep, stcb, net,
6294 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6295 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6298 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6299 if (net->error_count > net->failure_threshold) {
6300 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6301 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6304 if (net->error_count <= net->failure_threshold) {
6305 net->dest_state |= SCTP_ADDR_REACHABLE;
6306 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6310 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6311 net->failure_threshold = thlds->spt_pathmaxrxt;
6312 net->pf_threshold = thlds->spt_pathpfthld;
6313 if (net->dest_state & SCTP_ADDR_PF) {
6314 if ((net->error_count > net->failure_threshold) ||
6315 (net->error_count <= net->pf_threshold)) {
6316 net->dest_state &= ~SCTP_ADDR_PF;
6319 if ((net->error_count > net->pf_threshold) &&
6320 (net->error_count <= net->failure_threshold)) {
6321 net->dest_state |= SCTP_ADDR_PF;
6322 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6323 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6324 stcb->sctp_ep, stcb, net,
6325 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6326 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6329 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6330 if (net->error_count > net->failure_threshold) {
6331 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6332 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6335 if (net->error_count <= net->failure_threshold) {
6336 net->dest_state |= SCTP_ADDR_REACHABLE;
6337 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6341 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6342 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6344 SCTP_TCB_UNLOCK(stcb);
6346 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6347 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6348 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6349 SCTP_INP_WLOCK(inp);
6350 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6351 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6352 SCTP_INP_WUNLOCK(inp);
6354 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6360 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6362 struct sctp_udpencaps *encaps;
6363 struct sctp_nets *net;
6364 struct sockaddr *addr;
6366 #if defined(INET) && defined(INET6)
6367 struct sockaddr_in sin_store;
6371 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6372 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6374 #if defined(INET) && defined(INET6)
6375 if (encaps->sue_address.ss_family == AF_INET6) {
6376 struct sockaddr_in6 *sin6;
6378 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6379 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6380 in6_sin6_2_sin(&sin_store, sin6);
6381 addr = (struct sockaddr *)&sin_store;
6383 addr = (struct sockaddr *)&encaps->sue_address;
6386 addr = (struct sockaddr *)&encaps->sue_address;
6389 addr = (struct sockaddr *)&encaps->sue_address;
6392 net = sctp_findnet(stcb, addr);
6395 * We increment here since
6396 * sctp_findassociation_ep_addr() wil do a
6397 * decrement if it finds the stcb as long as
6398 * the locked tcb (last argument) is NOT a
6402 SCTP_INP_INCR_REF(inp);
6403 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6405 SCTP_INP_DECR_REF(inp);
6408 if ((stcb != NULL) && (net == NULL)) {
6410 if (addr->sa_family == AF_INET) {
6412 struct sockaddr_in *sin;
6414 sin = (struct sockaddr_in *)addr;
6415 if (sin->sin_addr.s_addr != INADDR_ANY) {
6416 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6417 SCTP_TCB_UNLOCK(stcb);
6424 if (addr->sa_family == AF_INET6) {
6425 struct sockaddr_in6 *sin6;
6427 sin6 = (struct sockaddr_in6 *)addr;
6428 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6429 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6430 SCTP_TCB_UNLOCK(stcb);
6437 error = EAFNOSUPPORT;
6438 SCTP_TCB_UNLOCK(stcb);
6439 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6445 net->port = encaps->sue_port;
6447 stcb->asoc.port = encaps->sue_port;
6449 SCTP_TCB_UNLOCK(stcb);
6451 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6452 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6453 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6454 SCTP_INP_WLOCK(inp);
6455 inp->sctp_ep.port = encaps->sue_port;
6456 SCTP_INP_WUNLOCK(inp);
6458 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6464 case SCTP_ECN_SUPPORTED:
6466 struct sctp_assoc_value *av;
6468 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6469 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6472 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6474 SCTP_TCB_UNLOCK(stcb);
6476 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6477 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6478 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6479 SCTP_INP_WLOCK(inp);
6480 if (av->assoc_value == 0) {
6481 inp->ecn_supported = 0;
6483 inp->ecn_supported = 1;
6485 SCTP_INP_WUNLOCK(inp);
6487 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6493 case SCTP_PR_SUPPORTED:
6495 struct sctp_assoc_value *av;
6497 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6498 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6501 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6503 SCTP_TCB_UNLOCK(stcb);
6505 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6506 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6507 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6508 SCTP_INP_WLOCK(inp);
6509 if (av->assoc_value == 0) {
6510 inp->prsctp_supported = 0;
6512 inp->prsctp_supported = 1;
6514 SCTP_INP_WUNLOCK(inp);
6516 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6522 case SCTP_AUTH_SUPPORTED:
6524 struct sctp_assoc_value *av;
6526 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6527 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6530 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6532 SCTP_TCB_UNLOCK(stcb);
6534 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6535 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6536 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6537 if ((av->assoc_value == 0) &&
6538 (inp->asconf_supported == 1)) {
6540 * AUTH is required for
6543 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6546 SCTP_INP_WLOCK(inp);
6547 if (av->assoc_value == 0) {
6548 inp->auth_supported = 0;
6550 inp->auth_supported = 1;
6552 SCTP_INP_WUNLOCK(inp);
6555 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6561 case SCTP_ASCONF_SUPPORTED:
6563 struct sctp_assoc_value *av;
6565 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6566 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6569 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6571 SCTP_TCB_UNLOCK(stcb);
6573 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6574 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6575 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6576 if ((av->assoc_value != 0) &&
6577 (inp->auth_supported == 0)) {
6579 * AUTH is required for
6582 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6585 SCTP_INP_WLOCK(inp);
6586 if (av->assoc_value == 0) {
6587 inp->asconf_supported = 0;
6588 sctp_auth_delete_chunk(SCTP_ASCONF,
6589 inp->sctp_ep.local_auth_chunks);
6590 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6591 inp->sctp_ep.local_auth_chunks);
6593 inp->asconf_supported = 1;
6594 sctp_auth_add_chunk(SCTP_ASCONF,
6595 inp->sctp_ep.local_auth_chunks);
6596 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6597 inp->sctp_ep.local_auth_chunks);
6599 SCTP_INP_WUNLOCK(inp);
6602 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6608 case SCTP_RECONFIG_SUPPORTED:
6610 struct sctp_assoc_value *av;
6612 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6613 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6616 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6618 SCTP_TCB_UNLOCK(stcb);
6620 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6621 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6622 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6623 SCTP_INP_WLOCK(inp);
6624 if (av->assoc_value == 0) {
6625 inp->reconfig_supported = 0;
6627 inp->reconfig_supported = 1;
6629 SCTP_INP_WUNLOCK(inp);
6631 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6637 case SCTP_NRSACK_SUPPORTED:
6639 struct sctp_assoc_value *av;
6641 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6642 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6645 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6647 SCTP_TCB_UNLOCK(stcb);
6649 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6650 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6651 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6652 SCTP_INP_WLOCK(inp);
6653 if (av->assoc_value == 0) {
6654 inp->nrsack_supported = 0;
6656 inp->nrsack_supported = 1;
6658 SCTP_INP_WUNLOCK(inp);
6660 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6666 case SCTP_PKTDROP_SUPPORTED:
6668 struct sctp_assoc_value *av;
6670 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6671 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6674 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6676 SCTP_TCB_UNLOCK(stcb);
6678 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6679 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6680 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6681 SCTP_INP_WLOCK(inp);
6682 if (av->assoc_value == 0) {
6683 inp->pktdrop_supported = 0;
6685 inp->pktdrop_supported = 1;
6687 SCTP_INP_WUNLOCK(inp);
6689 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6697 struct sctp_assoc_value *av;
6698 struct sctp_nets *net;
6700 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6701 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6704 stcb->asoc.max_cwnd = av->assoc_value;
6705 if (stcb->asoc.max_cwnd > 0) {
6706 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6707 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6708 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6709 net->cwnd = stcb->asoc.max_cwnd;
6710 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6711 net->cwnd = net->mtu - sizeof(struct sctphdr);
6716 SCTP_TCB_UNLOCK(stcb);
6718 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6719 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6720 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6721 SCTP_INP_WLOCK(inp);
6722 inp->max_cwnd = av->assoc_value;
6723 SCTP_INP_WUNLOCK(inp);
6725 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6732 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6733 error = ENOPROTOOPT;
6735 } /* end switch (opt) */
6740 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6742 void *optval = NULL;
6746 struct sctp_inpcb *inp;
6748 if ((sopt->sopt_level == SOL_SOCKET) &&
6749 (sopt->sopt_name == SO_SETFIB)) {
6750 inp = (struct sctp_inpcb *)so->so_pcb;
6752 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6755 SCTP_INP_WLOCK(inp);
6756 inp->fibnum = so->so_fibnum;
6757 SCTP_INP_WUNLOCK(inp);
6760 if (sopt->sopt_level != IPPROTO_SCTP) {
6761 /* wrong proto level... send back up to IP */
6763 if (INP_CHECK_SOCKAF(so, AF_INET6))
6764 error = ip6_ctloutput(so, sopt);
6766 #if defined(INET) && defined(INET6)
6770 error = ip_ctloutput(so, sopt);
6774 optsize = sopt->sopt_valsize;
6776 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6777 if (optval == NULL) {
6778 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6781 error = sooptcopyin(sopt, optval, optsize, optsize);
6783 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6787 p = (void *)sopt->sopt_td;
6788 if (sopt->sopt_dir == SOPT_SET) {
6789 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6790 } else if (sopt->sopt_dir == SOPT_GET) {
6791 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6793 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6796 if ((error == 0) && (optval != NULL)) {
6797 error = sooptcopyout(sopt, optval, optsize);
6798 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6799 } else if (optval != NULL) {
6800 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6808 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6811 int create_lock_on = 0;
6813 struct sctp_inpcb *inp;
6814 struct sctp_tcb *stcb = NULL;
6816 inp = (struct sctp_inpcb *)so->so_pcb;
6818 /* I made the same as TCP since we are not setup? */
6819 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6820 return (ECONNRESET);
6823 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6826 switch (addr->sa_family) {
6830 struct sockaddr_in6 *sin6p;
6832 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6833 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6836 sin6p = (struct sockaddr_in6 *)addr;
6837 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6838 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6847 struct sockaddr_in *sinp;
6849 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6850 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6853 sinp = (struct sockaddr_in *)addr;
6854 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6855 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6862 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6863 return (EAFNOSUPPORT);
6865 SCTP_INP_INCR_REF(inp);
6866 SCTP_ASOC_CREATE_LOCK(inp);
6870 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6871 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6872 /* Should I really unlock ? */
6873 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6878 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6879 (addr->sa_family == AF_INET6)) {
6880 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6885 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6886 SCTP_PCB_FLAGS_UNBOUND) {
6887 /* Bind a ephemeral port */
6888 error = sctp_inpcb_bind(so, NULL, NULL, p);
6893 /* Now do we connect? */
6894 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6895 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6896 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6900 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6901 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6902 /* We are already connected AND the TCP model */
6903 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6907 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6908 SCTP_INP_RLOCK(inp);
6909 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6910 SCTP_INP_RUNLOCK(inp);
6913 * We increment here since sctp_findassociation_ep_addr()
6914 * will do a decrement if it finds the stcb as long as the
6915 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6917 SCTP_INP_INCR_REF(inp);
6918 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6920 SCTP_INP_DECR_REF(inp);
6922 SCTP_TCB_UNLOCK(stcb);
6926 /* Already have or am bring up an association */
6927 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6931 vrf_id = inp->def_vrf_id;
6932 /* We are GOOD to go */
6933 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, inp->sctp_ep.pre_open_stream_count, p);
6935 /* Gak! no memory */
6938 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6939 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6940 /* Set the connected flag so we can queue data */
6943 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6944 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6946 /* initialize authentication parameters for the assoc */
6947 sctp_initialize_auth_params(inp, stcb);
6949 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6950 SCTP_TCB_UNLOCK(stcb);
6952 if (create_lock_on) {
6953 SCTP_ASOC_CREATE_UNLOCK(inp);
6955 SCTP_INP_DECR_REF(inp);
6962 sctp_listen(struct socket *so, int backlog, struct thread *p)
6965 * Note this module depends on the protocol processing being called
6966 * AFTER any socket level flags and backlog are applied to the
6967 * socket. The traditional way that the socket flags are applied is
6968 * AFTER protocol processing. We have made a change to the
6969 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6970 * place if the socket API for SCTP is to work properly.
6974 struct sctp_inpcb *inp;
6976 inp = (struct sctp_inpcb *)so->so_pcb;
6978 /* I made the same as TCP since we are not setup? */
6979 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6980 return (ECONNRESET);
6982 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6983 /* See if we have a listener */
6984 struct sctp_inpcb *tinp;
6985 union sctp_sockstore store;
6987 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6989 struct sctp_laddr *laddr;
6991 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6992 memcpy(&store, &laddr->ifa->address, sizeof(store));
6993 switch (store.sa.sa_family) {
6996 store.sin.sin_port = inp->sctp_lport;
7001 store.sin6.sin6_port = inp->sctp_lport;
7007 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7008 if (tinp && (tinp != inp) &&
7009 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7010 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7011 (tinp->sctp_socket->so_qlimit)) {
7013 * we have a listener already and
7016 SCTP_INP_DECR_REF(tinp);
7017 return (EADDRINUSE);
7019 SCTP_INP_DECR_REF(tinp);
7023 /* Setup a local addr bound all */
7024 memset(&store, 0, sizeof(store));
7026 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7027 store.sa.sa_family = AF_INET6;
7028 store.sa.sa_len = sizeof(struct sockaddr_in6);
7032 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7033 store.sa.sa_family = AF_INET;
7034 store.sa.sa_len = sizeof(struct sockaddr_in);
7037 switch (store.sa.sa_family) {
7040 store.sin.sin_port = inp->sctp_lport;
7045 store.sin6.sin6_port = inp->sctp_lport;
7051 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7052 if (tinp && (tinp != inp) &&
7053 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7054 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7055 (tinp->sctp_socket->so_qlimit)) {
7057 * we have a listener already and its not
7060 SCTP_INP_DECR_REF(tinp);
7061 return (EADDRINUSE);
7063 SCTP_INP_DECR_REF(tinp);
7067 SCTP_INP_RLOCK(inp);
7068 #ifdef SCTP_LOCK_LOGGING
7069 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7070 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7074 error = solisten_proto_check(so);
7077 SCTP_INP_RUNLOCK(inp);
7080 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7081 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7083 * The unlucky case - We are in the tcp pool with this guy.
7084 * - Someone else is in the main inp slot. - We must move
7085 * this guy (the listener) to the main slot - We must then
7086 * move the guy that was listener to the TCP Pool.
7088 if (sctp_swap_inpcb_for_listen(inp)) {
7089 SCTP_INP_RUNLOCK(inp);
7090 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7091 return (EADDRINUSE);
7094 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7095 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7096 /* We are already connected AND the TCP model */
7097 SCTP_INP_RUNLOCK(inp);
7098 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7099 return (EADDRINUSE);
7101 SCTP_INP_RUNLOCK(inp);
7102 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7103 /* We must do a bind. */
7104 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7105 /* bind error, probably perm */
7110 /* It appears for 7.0 and on, we must always call this. */
7111 solisten_proto(so, backlog);
7112 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7113 /* remove the ACCEPTCONN flag for one-to-many sockets */
7114 so->so_options &= ~SO_ACCEPTCONN;
7117 /* turning off listen */
7118 so->so_options &= ~SO_ACCEPTCONN;
7124 static int sctp_defered_wakeup_cnt = 0;
7127 sctp_accept(struct socket *so, struct sockaddr **addr)
7129 struct sctp_tcb *stcb;
7130 struct sctp_inpcb *inp;
7131 union sctp_sockstore store;
7137 inp = (struct sctp_inpcb *)so->so_pcb;
7140 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7141 return (ECONNRESET);
7143 SCTP_INP_RLOCK(inp);
7144 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7145 SCTP_INP_RUNLOCK(inp);
7146 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7147 return (EOPNOTSUPP);
7149 if (so->so_state & SS_ISDISCONNECTED) {
7150 SCTP_INP_RUNLOCK(inp);
7151 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7152 return (ECONNABORTED);
7154 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7156 SCTP_INP_RUNLOCK(inp);
7157 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7158 return (ECONNRESET);
7160 SCTP_TCB_LOCK(stcb);
7161 SCTP_INP_RUNLOCK(inp);
7162 store = stcb->asoc.primary_destination->ro._l_addr;
7163 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7164 SCTP_TCB_UNLOCK(stcb);
7165 switch (store.sa.sa_family) {
7169 struct sockaddr_in *sin;
7171 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7174 sin->sin_family = AF_INET;
7175 sin->sin_len = sizeof(*sin);
7176 sin->sin_port = store.sin.sin_port;
7177 sin->sin_addr = store.sin.sin_addr;
7178 *addr = (struct sockaddr *)sin;
7185 struct sockaddr_in6 *sin6;
7187 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7190 sin6->sin6_family = AF_INET6;
7191 sin6->sin6_len = sizeof(*sin6);
7192 sin6->sin6_port = store.sin6.sin6_port;
7193 sin6->sin6_addr = store.sin6.sin6_addr;
7194 if ((error = sa6_recoverscope(sin6)) != 0) {
7195 SCTP_FREE_SONAME(sin6);
7198 *addr = (struct sockaddr *)sin6;
7206 /* Wake any delayed sleep action */
7207 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7208 SCTP_INP_WLOCK(inp);
7209 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7210 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7211 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7212 SCTP_INP_WUNLOCK(inp);
7213 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7214 if (sowriteable(inp->sctp_socket)) {
7215 sowwakeup_locked(inp->sctp_socket);
7217 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7219 SCTP_INP_WLOCK(inp);
7221 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7222 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7223 SCTP_INP_WUNLOCK(inp);
7224 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7225 if (soreadable(inp->sctp_socket)) {
7226 sctp_defered_wakeup_cnt++;
7227 sorwakeup_locked(inp->sctp_socket);
7229 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7231 SCTP_INP_WLOCK(inp);
7233 SCTP_INP_WUNLOCK(inp);
7235 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7236 SCTP_TCB_LOCK(stcb);
7237 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7238 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7245 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7247 struct sockaddr_in *sin;
7249 struct sctp_inpcb *inp;
7250 struct sctp_ifa *sctp_ifa;
7253 * Do the malloc first in case it blocks.
7255 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7258 sin->sin_family = AF_INET;
7259 sin->sin_len = sizeof(*sin);
7260 inp = (struct sctp_inpcb *)so->so_pcb;
7262 SCTP_FREE_SONAME(sin);
7263 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7264 return (ECONNRESET);
7266 SCTP_INP_RLOCK(inp);
7267 sin->sin_port = inp->sctp_lport;
7268 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7269 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7270 struct sctp_tcb *stcb;
7271 struct sockaddr_in *sin_a;
7272 struct sctp_nets *net;
7275 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7281 SCTP_TCB_LOCK(stcb);
7282 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7283 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7285 /* this will make coverity happy */
7288 if (sin_a->sin_family == AF_INET) {
7293 if ((!fnd) || (sin_a == NULL)) {
7295 SCTP_TCB_UNLOCK(stcb);
7298 vrf_id = inp->def_vrf_id;
7299 sctp_ifa = sctp_source_address_selection(inp,
7301 (sctp_route_t *) & net->ro,
7304 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7305 sctp_free_ifa(sctp_ifa);
7307 SCTP_TCB_UNLOCK(stcb);
7309 /* For the bound all case you get back 0 */
7311 sin->sin_addr.s_addr = 0;
7315 /* Take the first IPv4 address in the list */
7316 struct sctp_laddr *laddr;
7319 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7320 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7321 struct sockaddr_in *sin_a;
7323 sin_a = &laddr->ifa->address.sin;
7324 sin->sin_addr = sin_a->sin_addr;
7330 SCTP_FREE_SONAME(sin);
7331 SCTP_INP_RUNLOCK(inp);
7332 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7336 SCTP_INP_RUNLOCK(inp);
7337 (*addr) = (struct sockaddr *)sin;
7342 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7344 struct sockaddr_in *sin;
7346 struct sockaddr_in *sin_a;
7347 struct sctp_inpcb *inp;
7348 struct sctp_tcb *stcb;
7349 struct sctp_nets *net;
7351 /* Do the malloc first in case it blocks. */
7352 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7355 sin->sin_family = AF_INET;
7356 sin->sin_len = sizeof(*sin);
7358 inp = (struct sctp_inpcb *)so->so_pcb;
7359 if ((inp == NULL) ||
7360 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7361 /* UDP type and listeners will drop out here */
7362 SCTP_FREE_SONAME(sin);
7363 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7366 SCTP_INP_RLOCK(inp);
7367 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7369 SCTP_TCB_LOCK(stcb);
7371 SCTP_INP_RUNLOCK(inp);
7373 SCTP_FREE_SONAME(sin);
7374 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7375 return (ECONNRESET);
7378 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7379 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7380 if (sin_a->sin_family == AF_INET) {
7382 sin->sin_port = stcb->rport;
7383 sin->sin_addr = sin_a->sin_addr;
7387 SCTP_TCB_UNLOCK(stcb);
7389 /* No IPv4 address */
7390 SCTP_FREE_SONAME(sin);
7391 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7394 (*addr) = (struct sockaddr *)sin;
7398 struct pr_usrreqs sctp_usrreqs = {
7399 .pru_abort = sctp_abort,
7400 .pru_accept = sctp_accept,
7401 .pru_attach = sctp_attach,
7402 .pru_bind = sctp_bind,
7403 .pru_connect = sctp_connect,
7404 .pru_control = in_control,
7405 .pru_close = sctp_close,
7406 .pru_detach = sctp_close,
7407 .pru_sopoll = sopoll_generic,
7408 .pru_flush = sctp_flush,
7409 .pru_disconnect = sctp_disconnect,
7410 .pru_listen = sctp_listen,
7411 .pru_peeraddr = sctp_peeraddr,
7412 .pru_send = sctp_sendm,
7413 .pru_shutdown = sctp_shutdown,
7414 .pru_sockaddr = sctp_ingetaddr,
7415 .pru_sosend = sctp_sosend,
7416 .pru_soreceive = sctp_soreceive