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,
1507 /* Gak! no memory */
1510 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1511 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1512 /* Set the connected flag so we can queue data */
1515 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
1516 /* move to second address */
1517 switch (sa->sa_family) {
1520 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in));
1525 sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6));
1533 sctp_connectx_helper_add(stcb, sa, (totaddr - 1), &error);
1534 /* Fill in the return id */
1536 (void)sctp_free_assoc(inp, stcb, SCTP_PCBFREE_FORCE,
1537 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7);
1540 a_id = (sctp_assoc_t *) optval;
1541 *a_id = sctp_get_associd(stcb);
1543 /* initialize authentication parameters for the assoc */
1544 sctp_initialize_auth_params(inp, stcb);
1547 /* doing delayed connection */
1548 stcb->asoc.delayed_connection = 1;
1549 sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination);
1551 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
1552 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
1554 SCTP_TCB_UNLOCK(stcb);
1555 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
1556 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1557 /* Set the connected flag so we can queue data */
1561 if (creat_lock_on) {
1562 SCTP_ASOC_CREATE_UNLOCK(inp);
1564 SCTP_INP_DECR_REF(inp);
1568 #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \
1569 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\
1570 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \
1571 SCTP_INP_RLOCK(inp); \
1572 stcb = LIST_FIRST(&inp->sctp_asoc_list); \
1574 SCTP_TCB_LOCK(stcb); \
1576 SCTP_INP_RUNLOCK(inp); \
1577 } else if (assoc_id > SCTP_ALL_ASSOC) { \
1578 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \
1579 if (stcb == NULL) { \
1580 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \
1590 #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\
1591 if (size < sizeof(type)) { \
1592 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \
1596 destp = (type *)srcp; \
1601 sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize,
1604 struct sctp_inpcb *inp = NULL;
1606 struct sctp_tcb *stcb = NULL;
1608 if (optval == NULL) {
1609 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1612 inp = (struct sctp_inpcb *)so->so_pcb;
1614 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1621 case SCTP_AUTOCLOSE:
1622 case SCTP_EXPLICIT_EOR:
1623 case SCTP_AUTO_ASCONF:
1624 case SCTP_DISABLE_FRAGMENTS:
1625 case SCTP_I_WANT_MAPPED_V4_ADDR:
1626 case SCTP_USE_EXT_RCVINFO:
1627 SCTP_INP_RLOCK(inp);
1629 case SCTP_DISABLE_FRAGMENTS:
1630 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT);
1632 case SCTP_I_WANT_MAPPED_V4_ADDR:
1633 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4);
1635 case SCTP_AUTO_ASCONF:
1636 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1637 /* only valid for bound all sockets */
1638 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
1640 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1645 case SCTP_EXPLICIT_EOR:
1646 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
1649 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY);
1651 case SCTP_USE_EXT_RCVINFO:
1652 val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO);
1654 case SCTP_AUTOCLOSE:
1655 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE))
1656 val = TICKS_TO_SEC(inp->sctp_ep.auto_close_time);
1662 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
1663 error = ENOPROTOOPT;
1664 } /* end switch (sopt->sopt_name) */
1665 if (*optsize < sizeof(val)) {
1666 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1670 SCTP_INP_RUNLOCK(inp);
1672 /* return the option value */
1673 *(int *)optval = val;
1674 *optsize = sizeof(val);
1677 case SCTP_GET_PACKET_LOG:
1679 #ifdef SCTP_PACKET_LOGGING
1683 SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize);
1684 ret = sctp_copy_out_packet_log(target, (int)*optsize);
1687 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1692 case SCTP_REUSE_PORT:
1696 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
1697 /* Can't do this for a 1-m socket */
1701 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1702 *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
1703 *optsize = sizeof(uint32_t);
1706 case SCTP_PARTIAL_DELIVERY_POINT:
1710 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1711 *value = inp->partial_delivery_point;
1712 *optsize = sizeof(uint32_t);
1715 case SCTP_FRAGMENT_INTERLEAVE:
1719 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1720 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) {
1721 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) {
1722 *value = SCTP_FRAG_LEVEL_2;
1724 *value = SCTP_FRAG_LEVEL_1;
1727 *value = SCTP_FRAG_LEVEL_0;
1729 *optsize = sizeof(uint32_t);
1732 case SCTP_CMT_ON_OFF:
1734 struct sctp_assoc_value *av;
1736 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1737 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1739 av->assoc_value = stcb->asoc.sctp_cmt_on_off;
1740 SCTP_TCB_UNLOCK(stcb);
1742 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1743 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1744 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1745 SCTP_INP_RLOCK(inp);
1746 av->assoc_value = inp->sctp_cmt_on_off;
1747 SCTP_INP_RUNLOCK(inp);
1749 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1754 *optsize = sizeof(struct sctp_assoc_value);
1758 case SCTP_PLUGGABLE_CC:
1760 struct sctp_assoc_value *av;
1762 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1763 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1765 av->assoc_value = stcb->asoc.congestion_control_module;
1766 SCTP_TCB_UNLOCK(stcb);
1768 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1769 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1770 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1771 SCTP_INP_RLOCK(inp);
1772 av->assoc_value = inp->sctp_ep.sctp_default_cc_module;
1773 SCTP_INP_RUNLOCK(inp);
1775 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1780 *optsize = sizeof(struct sctp_assoc_value);
1784 case SCTP_CC_OPTION:
1786 struct sctp_cc_option *cc_opt;
1788 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize);
1789 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
1793 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
1796 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 0, cc_opt);
1797 *optsize = sizeof(struct sctp_cc_option);
1799 SCTP_TCB_UNLOCK(stcb);
1803 case SCTP_PLUGGABLE_SS:
1805 struct sctp_assoc_value *av;
1807 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1808 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1810 av->assoc_value = stcb->asoc.stream_scheduling_module;
1811 SCTP_TCB_UNLOCK(stcb);
1813 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1814 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1815 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1816 SCTP_INP_RLOCK(inp);
1817 av->assoc_value = inp->sctp_ep.sctp_default_ss_module;
1818 SCTP_INP_RUNLOCK(inp);
1820 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1825 *optsize = sizeof(struct sctp_assoc_value);
1831 struct sctp_stream_value *av;
1833 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize);
1834 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1836 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
1837 (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
1838 &av->stream_value) < 0)) {
1839 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1842 *optsize = sizeof(struct sctp_stream_value);
1844 SCTP_TCB_UNLOCK(stcb);
1847 * Can't get stream value without
1850 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1855 case SCTP_GET_ADDR_LEN:
1857 struct sctp_assoc_value *av;
1859 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1862 if (av->assoc_value == AF_INET) {
1863 av->assoc_value = sizeof(struct sockaddr_in);
1868 if (av->assoc_value == AF_INET6) {
1869 av->assoc_value = sizeof(struct sockaddr_in6);
1874 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1876 *optsize = sizeof(struct sctp_assoc_value);
1880 case SCTP_GET_ASSOC_NUMBER:
1882 uint32_t *value, cnt;
1884 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
1886 SCTP_INP_RLOCK(inp);
1887 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1890 SCTP_INP_RUNLOCK(inp);
1892 *optsize = sizeof(uint32_t);
1895 case SCTP_GET_ASSOC_ID_LIST:
1897 struct sctp_assoc_ids *ids;
1898 unsigned int at, limit;
1900 SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize);
1902 limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t);
1903 SCTP_INP_RLOCK(inp);
1904 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1906 ids->gaids_assoc_id[at++] = sctp_get_associd(stcb);
1909 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1913 SCTP_INP_RUNLOCK(inp);
1915 ids->gaids_number_of_ids = at;
1916 *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t));
1922 struct sctp_assoc_value *av;
1924 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
1925 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
1928 av->assoc_value = stcb->asoc.context;
1929 SCTP_TCB_UNLOCK(stcb);
1931 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1932 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
1933 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
1934 SCTP_INP_RLOCK(inp);
1935 av->assoc_value = inp->sctp_context;
1936 SCTP_INP_RUNLOCK(inp);
1938 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
1943 *optsize = sizeof(struct sctp_assoc_value);
1949 uint32_t *default_vrfid;
1951 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize);
1952 *default_vrfid = inp->def_vrf_id;
1953 *optsize = sizeof(uint32_t);
1956 case SCTP_GET_ASOC_VRF:
1958 struct sctp_assoc_value *id;
1960 SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize);
1961 SCTP_FIND_STCB(inp, stcb, id->assoc_id);
1964 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
1966 id->assoc_value = stcb->asoc.vrf_id;
1967 *optsize = sizeof(struct sctp_assoc_value);
1971 case SCTP_GET_VRF_IDS:
1973 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
1977 case SCTP_GET_NONCE_VALUES:
1979 struct sctp_get_nonce_values *gnv;
1981 SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize);
1982 SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id);
1985 gnv->gn_peers_tag = stcb->asoc.peer_vtag;
1986 gnv->gn_local_tag = stcb->asoc.my_vtag;
1987 SCTP_TCB_UNLOCK(stcb);
1988 *optsize = sizeof(struct sctp_get_nonce_values);
1990 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
1995 case SCTP_DELAYED_SACK:
1997 struct sctp_sack_info *sack;
1999 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize);
2000 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
2002 sack->sack_delay = stcb->asoc.delayed_ack;
2003 sack->sack_freq = stcb->asoc.sack_freq;
2004 SCTP_TCB_UNLOCK(stcb);
2006 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2007 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2008 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC)) {
2009 SCTP_INP_RLOCK(inp);
2010 sack->sack_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
2011 sack->sack_freq = inp->sctp_ep.sctp_sack_freq;
2012 SCTP_INP_RUNLOCK(inp);
2014 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2019 *optsize = sizeof(struct sctp_sack_info);
2023 case SCTP_GET_SNDBUF_USE:
2025 struct sctp_sockstat *ss;
2027 SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize);
2028 SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id);
2031 ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size;
2032 ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue +
2033 stcb->asoc.size_on_all_streams);
2034 SCTP_TCB_UNLOCK(stcb);
2035 *optsize = sizeof(struct sctp_sockstat);
2037 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2042 case SCTP_MAX_BURST:
2044 struct sctp_assoc_value *av;
2046 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2047 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2050 av->assoc_value = stcb->asoc.max_burst;
2051 SCTP_TCB_UNLOCK(stcb);
2053 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2054 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2055 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2056 SCTP_INP_RLOCK(inp);
2057 av->assoc_value = inp->sctp_ep.max_burst;
2058 SCTP_INP_RUNLOCK(inp);
2060 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2065 *optsize = sizeof(struct sctp_assoc_value);
2071 struct sctp_assoc_value *av;
2074 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
2075 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
2078 av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc);
2079 SCTP_TCB_UNLOCK(stcb);
2081 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2082 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2083 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
2084 SCTP_INP_RLOCK(inp);
2085 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2086 ovh = SCTP_MED_OVERHEAD;
2088 ovh = SCTP_MED_V4_OVERHEAD;
2090 if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT)
2091 av->assoc_value = 0;
2093 av->assoc_value = inp->sctp_frag_point - ovh;
2094 SCTP_INP_RUNLOCK(inp);
2096 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2101 *optsize = sizeof(struct sctp_assoc_value);
2105 case SCTP_GET_STAT_LOG:
2106 error = sctp_fill_stat_log(optval, optsize);
2110 struct sctp_event_subscribe *events;
2112 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize);
2113 memset(events, 0, sizeof(struct sctp_event_subscribe));
2114 SCTP_INP_RLOCK(inp);
2115 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT))
2116 events->sctp_data_io_event = 1;
2118 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT))
2119 events->sctp_association_event = 1;
2121 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT))
2122 events->sctp_address_event = 1;
2124 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT))
2125 events->sctp_send_failure_event = 1;
2127 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR))
2128 events->sctp_peer_error_event = 1;
2130 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT))
2131 events->sctp_shutdown_event = 1;
2133 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT))
2134 events->sctp_partial_delivery_event = 1;
2136 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT))
2137 events->sctp_adaptation_layer_event = 1;
2139 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT))
2140 events->sctp_authentication_event = 1;
2142 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT))
2143 events->sctp_sender_dry_event = 1;
2145 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT))
2146 events->sctp_stream_reset_event = 1;
2147 SCTP_INP_RUNLOCK(inp);
2148 *optsize = sizeof(struct sctp_event_subscribe);
2151 case SCTP_ADAPTATION_LAYER:
2155 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2157 SCTP_INP_RLOCK(inp);
2158 *value = inp->sctp_ep.adaptation_layer_indicator;
2159 SCTP_INP_RUNLOCK(inp);
2160 *optsize = sizeof(uint32_t);
2163 case SCTP_SET_INITIAL_DBG_SEQ:
2167 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2168 SCTP_INP_RLOCK(inp);
2169 *value = inp->sctp_ep.initial_sequence_debug;
2170 SCTP_INP_RUNLOCK(inp);
2171 *optsize = sizeof(uint32_t);
2174 case SCTP_GET_LOCAL_ADDR_SIZE:
2178 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2179 SCTP_INP_RLOCK(inp);
2180 *value = sctp_count_max_addresses(inp);
2181 SCTP_INP_RUNLOCK(inp);
2182 *optsize = sizeof(uint32_t);
2185 case SCTP_GET_REMOTE_ADDR_SIZE:
2189 struct sctp_nets *net;
2191 SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize);
2192 /* FIXME MT: change to sctp_assoc_value? */
2193 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
2197 /* Count the sizes */
2198 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2199 switch (net->ro._l_addr.sa.sa_family) {
2203 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2204 size += sizeof(struct sockaddr_in6);
2206 size += sizeof(struct sockaddr_in);
2209 size += sizeof(struct sockaddr_in);
2215 size += sizeof(struct sockaddr_in6);
2222 SCTP_TCB_UNLOCK(stcb);
2223 *value = (uint32_t) size;
2224 *optsize = sizeof(uint32_t);
2226 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
2231 case SCTP_GET_PEER_ADDRESSES:
2233 * Get the address information, an array is passed in to
2234 * fill up we pack it.
2238 struct sockaddr_storage *sas;
2239 struct sctp_nets *net;
2240 struct sctp_getaddresses *saddr;
2242 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2243 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2246 left = (*optsize) - sizeof(struct sctp_getaddresses);
2247 *optsize = sizeof(struct sctp_getaddresses);
2248 sas = (struct sockaddr_storage *)&saddr->addr[0];
2250 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2251 switch (net->ro._l_addr.sa.sa_family) {
2255 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2256 cpsz = sizeof(struct sockaddr_in6);
2258 cpsz = sizeof(struct sockaddr_in);
2261 cpsz = sizeof(struct sockaddr_in);
2267 cpsz = sizeof(struct sockaddr_in6);
2278 /* not enough room. */
2281 #if defined(INET) && defined(INET6)
2282 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) &&
2283 (net->ro._l_addr.sa.sa_family == AF_INET)) {
2284 /* Must map the address */
2285 in6_sin_2_v4mapsin6(&net->ro._l_addr.sin,
2286 (struct sockaddr_in6 *)sas);
2288 memcpy(sas, &net->ro._l_addr, cpsz);
2291 memcpy(sas, &net->ro._l_addr, cpsz);
2293 ((struct sockaddr_in *)sas)->sin_port = stcb->rport;
2295 sas = (struct sockaddr_storage *)((caddr_t)sas + cpsz);
2299 SCTP_TCB_UNLOCK(stcb);
2301 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2306 case SCTP_GET_LOCAL_ADDRESSES:
2308 size_t limit, actual;
2309 struct sockaddr_storage *sas;
2310 struct sctp_getaddresses *saddr;
2312 SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
2313 SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
2315 sas = (struct sockaddr_storage *)&saddr->addr[0];
2316 limit = *optsize - sizeof(sctp_assoc_t);
2317 actual = sctp_fill_up_addresses(inp, stcb, limit, sas);
2319 SCTP_TCB_UNLOCK(stcb);
2321 *optsize = sizeof(struct sockaddr_storage) + actual;
2324 case SCTP_PEER_ADDR_PARAMS:
2326 struct sctp_paddrparams *paddrp;
2327 struct sctp_nets *net;
2328 struct sockaddr *addr;
2330 #if defined(INET) && defined(INET6)
2331 struct sockaddr_in sin_store;
2335 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize);
2336 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
2338 #if defined(INET) && defined(INET6)
2339 if (paddrp->spp_address.ss_family == AF_INET6) {
2340 struct sockaddr_in6 *sin6;
2342 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
2343 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2344 in6_sin6_2_sin(&sin_store, sin6);
2345 addr = (struct sockaddr *)&sin_store;
2347 addr = (struct sockaddr *)&paddrp->spp_address;
2350 addr = (struct sockaddr *)&paddrp->spp_address;
2353 addr = (struct sockaddr *)&paddrp->spp_address;
2356 net = sctp_findnet(stcb, addr);
2359 * We increment here since
2360 * sctp_findassociation_ep_addr() wil do a
2361 * decrement if it finds the stcb as long as
2362 * the locked tcb (last argument) is NOT a
2366 SCTP_INP_INCR_REF(inp);
2367 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2369 SCTP_INP_DECR_REF(inp);
2372 if ((stcb != NULL) && (net == NULL)) {
2374 if (addr->sa_family == AF_INET) {
2375 struct sockaddr_in *sin;
2377 sin = (struct sockaddr_in *)addr;
2378 if (sin->sin_addr.s_addr != INADDR_ANY) {
2380 SCTP_TCB_UNLOCK(stcb);
2381 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2387 if (addr->sa_family == AF_INET6) {
2388 struct sockaddr_in6 *sin6;
2390 sin6 = (struct sockaddr_in6 *)addr;
2391 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2393 SCTP_TCB_UNLOCK(stcb);
2394 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2400 error = EAFNOSUPPORT;
2401 SCTP_TCB_UNLOCK(stcb);
2402 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2407 /* Applies to the specific association */
2408 paddrp->spp_flags = 0;
2410 paddrp->spp_hbinterval = net->heart_beat_delay;
2411 paddrp->spp_pathmaxrxt = net->failure_threshold;
2412 paddrp->spp_pathmtu = net->mtu;
2413 switch (net->ro._l_addr.sa.sa_family) {
2416 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2421 paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD;
2427 /* get flags for HB */
2428 if (net->dest_state & SCTP_ADDR_NOHB) {
2429 paddrp->spp_flags |= SPP_HB_DISABLE;
2431 paddrp->spp_flags |= SPP_HB_ENABLE;
2433 /* get flags for PMTU */
2434 if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
2435 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2437 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2439 if (net->dscp & 0x01) {
2440 paddrp->spp_dscp = net->dscp & 0xfc;
2441 paddrp->spp_flags |= SPP_DSCP;
2444 if ((net->ro._l_addr.sa.sa_family == AF_INET6) &&
2445 (net->flowlabel & 0x80000000)) {
2446 paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff;
2447 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2452 * No destination so return default
2455 paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure;
2456 paddrp->spp_pathmtu = 0;
2457 if (stcb->asoc.default_dscp & 0x01) {
2458 paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc;
2459 paddrp->spp_flags |= SPP_DSCP;
2462 if (stcb->asoc.default_flowlabel & 0x80000000) {
2463 paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff;
2464 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2467 /* default settings should be these */
2468 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2469 paddrp->spp_flags |= SPP_HB_DISABLE;
2471 paddrp->spp_flags |= SPP_HB_ENABLE;
2473 if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2474 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2476 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2478 paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay;
2480 paddrp->spp_assoc_id = sctp_get_associd(stcb);
2481 SCTP_TCB_UNLOCK(stcb);
2483 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2484 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2485 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
2486 /* Use endpoint defaults */
2487 SCTP_INP_RLOCK(inp);
2488 paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure;
2489 paddrp->spp_hbinterval = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
2490 paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC;
2491 /* get inp's default */
2492 if (inp->sctp_ep.default_dscp & 0x01) {
2493 paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc;
2494 paddrp->spp_flags |= SPP_DSCP;
2497 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2498 (inp->sctp_ep.default_flowlabel & 0x80000000)) {
2499 paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff;
2500 paddrp->spp_flags |= SPP_IPV6_FLOWLABEL;
2503 /* can't return this */
2504 paddrp->spp_pathmtu = 0;
2506 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
2507 paddrp->spp_flags |= SPP_HB_ENABLE;
2509 paddrp->spp_flags |= SPP_HB_DISABLE;
2511 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
2512 paddrp->spp_flags |= SPP_PMTUD_ENABLE;
2514 paddrp->spp_flags |= SPP_PMTUD_DISABLE;
2516 SCTP_INP_RUNLOCK(inp);
2518 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2523 *optsize = sizeof(struct sctp_paddrparams);
2527 case SCTP_GET_PEER_ADDR_INFO:
2529 struct sctp_paddrinfo *paddri;
2530 struct sctp_nets *net;
2531 struct sockaddr *addr;
2533 #if defined(INET) && defined(INET6)
2534 struct sockaddr_in sin_store;
2538 SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize);
2539 SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id);
2541 #if defined(INET) && defined(INET6)
2542 if (paddri->spinfo_address.ss_family == AF_INET6) {
2543 struct sockaddr_in6 *sin6;
2545 sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address;
2546 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
2547 in6_sin6_2_sin(&sin_store, sin6);
2548 addr = (struct sockaddr *)&sin_store;
2550 addr = (struct sockaddr *)&paddri->spinfo_address;
2553 addr = (struct sockaddr *)&paddri->spinfo_address;
2556 addr = (struct sockaddr *)&paddri->spinfo_address;
2559 net = sctp_findnet(stcb, addr);
2562 * We increment here since
2563 * sctp_findassociation_ep_addr() wil do a
2564 * decrement if it finds the stcb as long as
2565 * the locked tcb (last argument) is NOT a
2569 SCTP_INP_INCR_REF(inp);
2570 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
2572 SCTP_INP_DECR_REF(inp);
2576 if ((stcb != NULL) && (net != NULL)) {
2577 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2578 /* It's unconfirmed */
2579 paddri->spinfo_state = SCTP_UNCONFIRMED;
2580 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2582 paddri->spinfo_state = SCTP_ACTIVE;
2585 paddri->spinfo_state = SCTP_INACTIVE;
2587 paddri->spinfo_cwnd = net->cwnd;
2588 paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2589 paddri->spinfo_rto = net->RTO;
2590 paddri->spinfo_assoc_id = sctp_get_associd(stcb);
2591 paddri->spinfo_mtu = net->mtu;
2592 switch (addr->sa_family) {
2595 paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2600 paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD;
2606 SCTP_TCB_UNLOCK(stcb);
2607 *optsize = sizeof(struct sctp_paddrinfo);
2610 SCTP_TCB_UNLOCK(stcb);
2612 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
2617 case SCTP_PCB_STATUS:
2619 struct sctp_pcbinfo *spcb;
2621 SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize);
2622 sctp_fill_pcbinfo(spcb);
2623 *optsize = sizeof(struct sctp_pcbinfo);
2628 struct sctp_nets *net;
2629 struct sctp_status *sstat;
2631 SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize);
2632 SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id);
2635 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2639 sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state);
2640 sstat->sstat_assoc_id = sctp_get_associd(stcb);
2641 sstat->sstat_rwnd = stcb->asoc.peers_rwnd;
2642 sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt;
2644 * We can't include chunks that have been passed to
2645 * the socket layer. Only things in queue.
2647 sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue +
2648 stcb->asoc.cnt_on_all_streams);
2651 sstat->sstat_instrms = stcb->asoc.streamincnt;
2652 sstat->sstat_outstrms = stcb->asoc.streamoutcnt;
2653 sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc);
2654 memcpy(&sstat->sstat_primary.spinfo_address,
2655 &stcb->asoc.primary_destination->ro._l_addr,
2656 ((struct sockaddr *)(&stcb->asoc.primary_destination->ro._l_addr))->sa_len);
2657 net = stcb->asoc.primary_destination;
2658 ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport;
2660 * Again the user can get info from sctp_constants.h
2661 * for what the state of the network is.
2663 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
2664 /* It's unconfirmed */
2665 sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED;
2666 } else if (net->dest_state & SCTP_ADDR_REACHABLE) {
2668 sstat->sstat_primary.spinfo_state = SCTP_ACTIVE;
2671 sstat->sstat_primary.spinfo_state = SCTP_INACTIVE;
2673 sstat->sstat_primary.spinfo_cwnd = net->cwnd;
2674 sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT;
2675 sstat->sstat_primary.spinfo_rto = net->RTO;
2676 sstat->sstat_primary.spinfo_mtu = net->mtu;
2677 switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) {
2680 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD;
2685 sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD;
2691 sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb);
2692 SCTP_TCB_UNLOCK(stcb);
2693 *optsize = sizeof(struct sctp_status);
2698 struct sctp_rtoinfo *srto;
2700 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize);
2701 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
2704 srto->srto_initial = stcb->asoc.initial_rto;
2705 srto->srto_max = stcb->asoc.maxrto;
2706 srto->srto_min = stcb->asoc.minrto;
2707 SCTP_TCB_UNLOCK(stcb);
2709 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2710 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2711 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
2712 SCTP_INP_RLOCK(inp);
2713 srto->srto_initial = inp->sctp_ep.initial_rto;
2714 srto->srto_max = inp->sctp_ep.sctp_maxrto;
2715 srto->srto_min = inp->sctp_ep.sctp_minrto;
2716 SCTP_INP_RUNLOCK(inp);
2718 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2723 *optsize = sizeof(struct sctp_rtoinfo);
2729 struct sctp_timeouts *stimo;
2731 SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize);
2732 SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id);
2735 stimo->stimo_init = stcb->asoc.timoinit;
2736 stimo->stimo_data = stcb->asoc.timodata;
2737 stimo->stimo_sack = stcb->asoc.timosack;
2738 stimo->stimo_shutdown = stcb->asoc.timoshutdown;
2739 stimo->stimo_heartbeat = stcb->asoc.timoheartbeat;
2740 stimo->stimo_cookie = stcb->asoc.timocookie;
2741 stimo->stimo_shutdownack = stcb->asoc.timoshutdownack;
2742 SCTP_TCB_UNLOCK(stcb);
2743 *optsize = sizeof(struct sctp_timeouts);
2745 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2750 case SCTP_ASSOCINFO:
2752 struct sctp_assocparams *sasoc;
2754 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize);
2755 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
2758 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(stcb->asoc.cookie_life);
2759 sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times;
2760 sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets;
2761 sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd;
2762 sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd;
2763 SCTP_TCB_UNLOCK(stcb);
2765 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2766 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2767 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
2768 SCTP_INP_RLOCK(inp);
2769 sasoc->sasoc_cookie_life = TICKS_TO_MSEC(inp->sctp_ep.def_cookie_life);
2770 sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times;
2771 sasoc->sasoc_number_peer_destinations = 0;
2772 sasoc->sasoc_peer_rwnd = 0;
2773 sasoc->sasoc_local_rwnd = sbspace(&inp->sctp_socket->so_rcv);
2774 SCTP_INP_RUNLOCK(inp);
2776 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2781 *optsize = sizeof(struct sctp_assocparams);
2785 case SCTP_DEFAULT_SEND_PARAM:
2787 struct sctp_sndrcvinfo *s_info;
2789 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize);
2790 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
2793 memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send));
2794 SCTP_TCB_UNLOCK(stcb);
2796 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2797 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2798 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC)) {
2799 SCTP_INP_RLOCK(inp);
2800 memcpy(s_info, &inp->def_send, sizeof(inp->def_send));
2801 SCTP_INP_RUNLOCK(inp);
2803 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2808 *optsize = sizeof(struct sctp_sndrcvinfo);
2814 struct sctp_initmsg *sinit;
2816 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize);
2817 SCTP_INP_RLOCK(inp);
2818 sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count;
2819 sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome;
2820 sinit->sinit_max_attempts = inp->sctp_ep.max_init_times;
2821 sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max;
2822 SCTP_INP_RUNLOCK(inp);
2823 *optsize = sizeof(struct sctp_initmsg);
2826 case SCTP_PRIMARY_ADDR:
2827 /* we allow a "get" operation on this */
2829 struct sctp_setprim *ssp;
2831 SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize);
2832 SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id);
2835 union sctp_sockstore *addr;
2837 addr = &stcb->asoc.primary_destination->ro._l_addr;
2838 switch (addr->sa.sa_family) {
2842 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
2843 in6_sin_2_v4mapsin6(&addr->sin,
2844 (struct sockaddr_in6 *)&ssp->ssp_addr);
2846 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2849 memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in));
2855 memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6));
2861 SCTP_TCB_UNLOCK(stcb);
2862 *optsize = sizeof(struct sctp_setprim);
2864 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2869 case SCTP_HMAC_IDENT:
2871 struct sctp_hmacalgo *shmac;
2872 sctp_hmaclist_t *hmaclist;
2876 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize);
2878 SCTP_INP_RLOCK(inp);
2879 hmaclist = inp->sctp_ep.local_hmacs;
2880 if (hmaclist == NULL) {
2881 /* no HMACs to return */
2882 *optsize = sizeof(*shmac);
2883 SCTP_INP_RUNLOCK(inp);
2886 /* is there room for all of the hmac ids? */
2887 size = sizeof(*shmac) + (hmaclist->num_algo *
2888 sizeof(shmac->shmac_idents[0]));
2889 if ((size_t)(*optsize) < size) {
2890 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2892 SCTP_INP_RUNLOCK(inp);
2895 /* copy in the list */
2896 shmac->shmac_number_of_idents = hmaclist->num_algo;
2897 for (i = 0; i < hmaclist->num_algo; i++) {
2898 shmac->shmac_idents[i] = hmaclist->hmac[i];
2900 SCTP_INP_RUNLOCK(inp);
2904 case SCTP_AUTH_ACTIVE_KEY:
2906 struct sctp_authkeyid *scact;
2908 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize);
2909 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
2912 /* get the active key on the assoc */
2913 scact->scact_keynumber = stcb->asoc.authinfo.active_keyid;
2914 SCTP_TCB_UNLOCK(stcb);
2916 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2917 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2918 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC)) {
2919 /* get the endpoint active key */
2920 SCTP_INP_RLOCK(inp);
2921 scact->scact_keynumber = inp->sctp_ep.default_keyid;
2922 SCTP_INP_RUNLOCK(inp);
2924 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2929 *optsize = sizeof(struct sctp_authkeyid);
2933 case SCTP_LOCAL_AUTH_CHUNKS:
2935 struct sctp_authchunks *sac;
2936 sctp_auth_chklist_t *chklist = NULL;
2939 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2940 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2943 /* get off the assoc */
2944 chklist = stcb->asoc.local_auth_chunks;
2945 /* is there enough space? */
2946 size = sctp_auth_get_chklist_size(chklist);
2947 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2949 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2951 /* copy in the chunks */
2952 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2953 sac->gauth_number_of_chunks = (uint32_t) size;
2954 *optsize = sizeof(struct sctp_authchunks) + size;
2956 SCTP_TCB_UNLOCK(stcb);
2958 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2959 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
2960 (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC)) {
2961 /* get off the endpoint */
2962 SCTP_INP_RLOCK(inp);
2963 chklist = inp->sctp_ep.local_auth_chunks;
2964 /* is there enough space? */
2965 size = sctp_auth_get_chklist_size(chklist);
2966 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2968 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
2970 /* copy in the chunks */
2971 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
2972 sac->gauth_number_of_chunks = (uint32_t) size;
2973 *optsize = sizeof(struct sctp_authchunks) + size;
2975 SCTP_INP_RUNLOCK(inp);
2977 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
2983 case SCTP_PEER_AUTH_CHUNKS:
2985 struct sctp_authchunks *sac;
2986 sctp_auth_chklist_t *chklist = NULL;
2989 SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize);
2990 SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id);
2993 /* get off the assoc */
2994 chklist = stcb->asoc.peer_auth_chunks;
2995 /* is there enough space? */
2996 size = sctp_auth_get_chklist_size(chklist);
2997 if (*optsize < (sizeof(struct sctp_authchunks) + size)) {
2999 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3001 /* copy in the chunks */
3002 (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks);
3003 sac->gauth_number_of_chunks = (uint32_t) size;
3004 *optsize = sizeof(struct sctp_authchunks) + size;
3006 SCTP_TCB_UNLOCK(stcb);
3008 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
3015 struct sctp_event *event;
3016 uint32_t event_type;
3018 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize);
3019 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
3021 switch (event->se_type) {
3022 case SCTP_ASSOC_CHANGE:
3023 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
3025 case SCTP_PEER_ADDR_CHANGE:
3026 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
3028 case SCTP_REMOTE_ERROR:
3029 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
3031 case SCTP_SEND_FAILED:
3032 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
3034 case SCTP_SHUTDOWN_EVENT:
3035 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
3037 case SCTP_ADAPTATION_INDICATION:
3038 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
3040 case SCTP_PARTIAL_DELIVERY_EVENT:
3041 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
3043 case SCTP_AUTHENTICATION_EVENT:
3044 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
3046 case SCTP_STREAM_RESET_EVENT:
3047 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
3049 case SCTP_SENDER_DRY_EVENT:
3050 event_type = SCTP_PCB_FLAGS_DRYEVNT;
3052 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
3054 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
3057 case SCTP_ASSOC_RESET_EVENT:
3058 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
3060 case SCTP_STREAM_CHANGE_EVENT:
3061 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
3063 case SCTP_SEND_FAILED_EVENT:
3064 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
3068 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3072 if (event_type > 0) {
3074 event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type);
3075 SCTP_TCB_UNLOCK(stcb);
3077 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3078 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3079 (event->se_assoc_id == SCTP_FUTURE_ASSOC)) {
3080 SCTP_INP_RLOCK(inp);
3081 event->se_on = sctp_is_feature_on(inp, event_type);
3082 SCTP_INP_RUNLOCK(inp);
3084 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3090 *optsize = sizeof(struct sctp_event);
3094 case SCTP_RECVRCVINFO:
3098 if (*optsize < sizeof(int)) {
3099 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3102 SCTP_INP_RLOCK(inp);
3103 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
3104 SCTP_INP_RUNLOCK(inp);
3107 /* return the option value */
3108 *(int *)optval = onoff;
3109 *optsize = sizeof(int);
3113 case SCTP_RECVNXTINFO:
3117 if (*optsize < sizeof(int)) {
3118 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3121 SCTP_INP_RLOCK(inp);
3122 onoff = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
3123 SCTP_INP_RUNLOCK(inp);
3126 /* return the option value */
3127 *(int *)optval = onoff;
3128 *optsize = sizeof(int);
3132 case SCTP_DEFAULT_SNDINFO:
3134 struct sctp_sndinfo *info;
3136 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize);
3137 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
3140 info->snd_sid = stcb->asoc.def_send.sinfo_stream;
3141 info->snd_flags = stcb->asoc.def_send.sinfo_flags;
3142 info->snd_flags &= 0xfff0;
3143 info->snd_ppid = stcb->asoc.def_send.sinfo_ppid;
3144 info->snd_context = stcb->asoc.def_send.sinfo_context;
3145 SCTP_TCB_UNLOCK(stcb);
3147 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3148 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3149 (info->snd_assoc_id == SCTP_FUTURE_ASSOC)) {
3150 SCTP_INP_RLOCK(inp);
3151 info->snd_sid = inp->def_send.sinfo_stream;
3152 info->snd_flags = inp->def_send.sinfo_flags;
3153 info->snd_flags &= 0xfff0;
3154 info->snd_ppid = inp->def_send.sinfo_ppid;
3155 info->snd_context = inp->def_send.sinfo_context;
3156 SCTP_INP_RUNLOCK(inp);
3158 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3163 *optsize = sizeof(struct sctp_sndinfo);
3167 case SCTP_DEFAULT_PRINFO:
3169 struct sctp_default_prinfo *info;
3171 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize);
3172 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
3175 info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
3176 info->pr_value = stcb->asoc.def_send.sinfo_timetolive;
3177 SCTP_TCB_UNLOCK(stcb);
3179 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3180 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3181 (info->pr_assoc_id == SCTP_FUTURE_ASSOC)) {
3182 SCTP_INP_RLOCK(inp);
3183 info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
3184 info->pr_value = inp->def_send.sinfo_timetolive;
3185 SCTP_INP_RUNLOCK(inp);
3187 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3192 *optsize = sizeof(struct sctp_default_prinfo);
3196 case SCTP_PEER_ADDR_THLDS:
3198 struct sctp_paddrthlds *thlds;
3199 struct sctp_nets *net;
3200 struct sockaddr *addr;
3202 #if defined(INET) && defined(INET6)
3203 struct sockaddr_in sin_store;
3207 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize);
3208 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
3210 #if defined(INET) && defined(INET6)
3211 if (thlds->spt_address.ss_family == AF_INET6) {
3212 struct sockaddr_in6 *sin6;
3214 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
3215 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3216 in6_sin6_2_sin(&sin_store, sin6);
3217 addr = (struct sockaddr *)&sin_store;
3219 addr = (struct sockaddr *)&thlds->spt_address;
3222 addr = (struct sockaddr *)&thlds->spt_address;
3225 addr = (struct sockaddr *)&thlds->spt_address;
3228 net = sctp_findnet(stcb, addr);
3231 * We increment here since
3232 * sctp_findassociation_ep_addr() wil do a
3233 * decrement if it finds the stcb as long as
3234 * the locked tcb (last argument) is NOT a
3238 SCTP_INP_INCR_REF(inp);
3239 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3241 SCTP_INP_DECR_REF(inp);
3244 if ((stcb != NULL) && (net == NULL)) {
3246 if (addr->sa_family == AF_INET) {
3247 struct sockaddr_in *sin;
3249 sin = (struct sockaddr_in *)addr;
3250 if (sin->sin_addr.s_addr != INADDR_ANY) {
3252 SCTP_TCB_UNLOCK(stcb);
3253 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3259 if (addr->sa_family == AF_INET6) {
3260 struct sockaddr_in6 *sin6;
3262 sin6 = (struct sockaddr_in6 *)addr;
3263 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3265 SCTP_TCB_UNLOCK(stcb);
3266 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3272 error = EAFNOSUPPORT;
3273 SCTP_TCB_UNLOCK(stcb);
3274 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3280 thlds->spt_pathmaxrxt = net->failure_threshold;
3281 thlds->spt_pathpfthld = net->pf_threshold;
3283 thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure;
3284 thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold;
3286 thlds->spt_assoc_id = sctp_get_associd(stcb);
3287 SCTP_TCB_UNLOCK(stcb);
3289 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3290 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3291 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
3292 /* Use endpoint defaults */
3293 SCTP_INP_RLOCK(inp);
3294 thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure;
3295 thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold;
3296 SCTP_INP_RUNLOCK(inp);
3298 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3303 *optsize = sizeof(struct sctp_paddrthlds);
3307 case SCTP_REMOTE_UDP_ENCAPS_PORT:
3309 struct sctp_udpencaps *encaps;
3310 struct sctp_nets *net;
3311 struct sockaddr *addr;
3313 #if defined(INET) && defined(INET6)
3314 struct sockaddr_in sin_store;
3318 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize);
3319 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
3321 #if defined(INET) && defined(INET6)
3322 if (encaps->sue_address.ss_family == AF_INET6) {
3323 struct sockaddr_in6 *sin6;
3325 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
3326 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
3327 in6_sin6_2_sin(&sin_store, sin6);
3328 addr = (struct sockaddr *)&sin_store;
3330 addr = (struct sockaddr *)&encaps->sue_address;
3333 addr = (struct sockaddr *)&encaps->sue_address;
3336 addr = (struct sockaddr *)&encaps->sue_address;
3339 net = sctp_findnet(stcb, addr);
3342 * We increment here since
3343 * sctp_findassociation_ep_addr() wil do a
3344 * decrement if it finds the stcb as long as
3345 * the locked tcb (last argument) is NOT a
3349 SCTP_INP_INCR_REF(inp);
3350 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
3352 SCTP_INP_DECR_REF(inp);
3355 if ((stcb != NULL) && (net == NULL)) {
3357 if (addr->sa_family == AF_INET) {
3358 struct sockaddr_in *sin;
3360 sin = (struct sockaddr_in *)addr;
3361 if (sin->sin_addr.s_addr != INADDR_ANY) {
3363 SCTP_TCB_UNLOCK(stcb);
3364 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3370 if (addr->sa_family == AF_INET6) {
3371 struct sockaddr_in6 *sin6;
3373 sin6 = (struct sockaddr_in6 *)addr;
3374 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
3376 SCTP_TCB_UNLOCK(stcb);
3377 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3383 error = EAFNOSUPPORT;
3384 SCTP_TCB_UNLOCK(stcb);
3385 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
3391 encaps->sue_port = net->port;
3393 encaps->sue_port = stcb->asoc.port;
3395 SCTP_TCB_UNLOCK(stcb);
3397 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3398 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3399 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
3400 SCTP_INP_RLOCK(inp);
3401 encaps->sue_port = inp->sctp_ep.port;
3402 SCTP_INP_RUNLOCK(inp);
3404 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3409 *optsize = sizeof(struct sctp_udpencaps);
3413 case SCTP_ECN_SUPPORTED:
3415 struct sctp_assoc_value *av;
3417 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3418 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3421 av->assoc_value = stcb->asoc.ecn_supported;
3422 SCTP_TCB_UNLOCK(stcb);
3424 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3425 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3426 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3427 SCTP_INP_RLOCK(inp);
3428 av->assoc_value = inp->ecn_supported;
3429 SCTP_INP_RUNLOCK(inp);
3431 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3436 *optsize = sizeof(struct sctp_assoc_value);
3440 case SCTP_PR_SUPPORTED:
3442 struct sctp_assoc_value *av;
3444 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3445 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3448 av->assoc_value = stcb->asoc.prsctp_supported;
3449 SCTP_TCB_UNLOCK(stcb);
3451 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3452 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3453 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3454 SCTP_INP_RLOCK(inp);
3455 av->assoc_value = inp->prsctp_supported;
3456 SCTP_INP_RUNLOCK(inp);
3458 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3463 *optsize = sizeof(struct sctp_assoc_value);
3467 case SCTP_AUTH_SUPPORTED:
3469 struct sctp_assoc_value *av;
3471 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3472 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3475 av->assoc_value = stcb->asoc.auth_supported;
3476 SCTP_TCB_UNLOCK(stcb);
3478 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3479 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3480 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3481 SCTP_INP_RLOCK(inp);
3482 av->assoc_value = inp->auth_supported;
3483 SCTP_INP_RUNLOCK(inp);
3485 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3490 *optsize = sizeof(struct sctp_assoc_value);
3494 case SCTP_ASCONF_SUPPORTED:
3496 struct sctp_assoc_value *av;
3498 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3499 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3502 av->assoc_value = stcb->asoc.asconf_supported;
3503 SCTP_TCB_UNLOCK(stcb);
3505 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3506 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3507 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3508 SCTP_INP_RLOCK(inp);
3509 av->assoc_value = inp->asconf_supported;
3510 SCTP_INP_RUNLOCK(inp);
3512 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3517 *optsize = sizeof(struct sctp_assoc_value);
3521 case SCTP_RECONFIG_SUPPORTED:
3523 struct sctp_assoc_value *av;
3525 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3526 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3529 av->assoc_value = stcb->asoc.reconfig_supported;
3530 SCTP_TCB_UNLOCK(stcb);
3532 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3533 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3534 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3535 SCTP_INP_RLOCK(inp);
3536 av->assoc_value = inp->reconfig_supported;
3537 SCTP_INP_RUNLOCK(inp);
3539 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3544 *optsize = sizeof(struct sctp_assoc_value);
3548 case SCTP_NRSACK_SUPPORTED:
3550 struct sctp_assoc_value *av;
3552 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3553 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3556 av->assoc_value = stcb->asoc.nrsack_supported;
3557 SCTP_TCB_UNLOCK(stcb);
3559 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3560 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3561 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3562 SCTP_INP_RLOCK(inp);
3563 av->assoc_value = inp->nrsack_supported;
3564 SCTP_INP_RUNLOCK(inp);
3566 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3571 *optsize = sizeof(struct sctp_assoc_value);
3575 case SCTP_PKTDROP_SUPPORTED:
3577 struct sctp_assoc_value *av;
3579 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3580 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3583 av->assoc_value = stcb->asoc.pktdrop_supported;
3584 SCTP_TCB_UNLOCK(stcb);
3586 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3587 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3588 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3589 SCTP_INP_RLOCK(inp);
3590 av->assoc_value = inp->pktdrop_supported;
3591 SCTP_INP_RUNLOCK(inp);
3593 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3598 *optsize = sizeof(struct sctp_assoc_value);
3602 case SCTP_ENABLE_STREAM_RESET:
3604 struct sctp_assoc_value *av;
3606 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3607 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3610 av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support;
3611 SCTP_TCB_UNLOCK(stcb);
3613 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3614 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3615 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3616 SCTP_INP_RLOCK(inp);
3617 av->assoc_value = (uint32_t) inp->local_strreset_support;
3618 SCTP_INP_RUNLOCK(inp);
3620 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3625 *optsize = sizeof(struct sctp_assoc_value);
3629 case SCTP_PR_STREAM_STATUS:
3631 struct sctp_prstatus *sprstat;
3635 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3636 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3638 sid = sprstat->sprstat_sid;
3639 policy = sprstat->sprstat_policy;
3640 #if defined(SCTP_DETAILED_STR_STATS)
3641 if ((stcb != NULL) &&
3642 (sid < stcb->asoc.streamoutcnt) &&
3643 (policy != SCTP_PR_SCTP_NONE) &&
3644 ((policy <= SCTP_PR_SCTP_MAX) ||
3645 (policy == SCTP_PR_SCTP_ALL))) {
3646 if (policy == SCTP_PR_SCTP_ALL) {
3647 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3648 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3650 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy];
3651 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy];
3654 if ((stcb != NULL) &&
3655 (sid < stcb->asoc.streamoutcnt) &&
3656 (policy == SCTP_PR_SCTP_ALL)) {
3657 sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0];
3658 sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0];
3660 SCTP_TCB_UNLOCK(stcb);
3661 *optsize = sizeof(struct sctp_prstatus);
3663 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3668 case SCTP_PR_ASSOC_STATUS:
3670 struct sctp_prstatus *sprstat;
3673 SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize);
3674 SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id);
3676 policy = sprstat->sprstat_policy;
3677 if ((stcb != NULL) &&
3678 (policy != SCTP_PR_SCTP_NONE) &&
3679 ((policy <= SCTP_PR_SCTP_MAX) ||
3680 (policy == SCTP_PR_SCTP_ALL))) {
3681 if (policy == SCTP_PR_SCTP_ALL) {
3682 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0];
3683 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0];
3685 sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy];
3686 sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy];
3688 SCTP_TCB_UNLOCK(stcb);
3689 *optsize = sizeof(struct sctp_prstatus);
3691 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3698 struct sctp_assoc_value *av;
3700 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize);
3701 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3704 av->assoc_value = stcb->asoc.max_cwnd;
3705 SCTP_TCB_UNLOCK(stcb);
3707 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3708 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3709 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
3710 SCTP_INP_RLOCK(inp);
3711 av->assoc_value = inp->max_cwnd;
3712 SCTP_INP_RUNLOCK(inp);
3714 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3719 *optsize = sizeof(struct sctp_assoc_value);
3724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3725 error = ENOPROTOOPT;
3727 } /* end switch (sopt->sopt_name) */
3735 sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
3740 struct sctp_tcb *stcb = NULL;
3741 struct sctp_inpcb *inp = NULL;
3744 if (optval == NULL) {
3745 SCTP_PRINTF("optval is NULL\n");
3746 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3749 inp = (struct sctp_inpcb *)so->so_pcb;
3751 SCTP_PRINTF("inp is NULL?\n");
3752 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3755 vrf_id = inp->def_vrf_id;
3760 case SCTP_AUTOCLOSE:
3761 case SCTP_AUTO_ASCONF:
3762 case SCTP_EXPLICIT_EOR:
3763 case SCTP_DISABLE_FRAGMENTS:
3764 case SCTP_USE_EXT_RCVINFO:
3765 case SCTP_I_WANT_MAPPED_V4_ADDR:
3766 /* copy in the option value */
3767 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3772 case SCTP_DISABLE_FRAGMENTS:
3773 set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT;
3775 case SCTP_AUTO_ASCONF:
3777 * NOTE: we don't really support this flag
3779 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3780 /* only valid for bound all sockets */
3781 if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) &&
3783 /* forbidden by admin */
3784 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM);
3787 set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF;
3789 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3793 case SCTP_EXPLICIT_EOR:
3794 set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR;
3796 case SCTP_USE_EXT_RCVINFO:
3797 set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO;
3799 case SCTP_I_WANT_MAPPED_V4_ADDR:
3800 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
3801 set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4;
3803 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3808 set_opt = SCTP_PCB_FLAGS_NODELAY;
3810 case SCTP_AUTOCLOSE:
3811 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3812 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
3813 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3816 set_opt = SCTP_PCB_FLAGS_AUTOCLOSE;
3818 * The value is in ticks. Note this does not effect
3819 * old associations, only new ones.
3821 inp->sctp_ep.auto_close_time = SEC_TO_TICKS(*mopt);
3824 SCTP_INP_WLOCK(inp);
3826 sctp_feature_on(inp, set_opt);
3828 sctp_feature_off(inp, set_opt);
3830 SCTP_INP_WUNLOCK(inp);
3832 case SCTP_REUSE_PORT:
3834 SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize);
3835 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
3836 /* Can't set it after we are bound */
3840 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
3841 /* Can't do this for a 1-m socket */
3846 sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE);
3848 sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE);
3851 case SCTP_PARTIAL_DELIVERY_POINT:
3855 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
3856 if (*value > SCTP_SB_LIMIT_RCV(so)) {
3857 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3861 inp->partial_delivery_point = *value;
3864 case SCTP_FRAGMENT_INTERLEAVE:
3865 /* not yet until we re-write sctp_recvmsg() */
3869 SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize);
3870 if (*level == SCTP_FRAG_LEVEL_2) {
3871 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3872 sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3873 } else if (*level == SCTP_FRAG_LEVEL_1) {
3874 sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3875 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3876 } else if (*level == SCTP_FRAG_LEVEL_0) {
3877 sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
3878 sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
3881 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3886 case SCTP_CMT_ON_OFF:
3887 if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) {
3888 struct sctp_assoc_value *av;
3890 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3891 if (av->assoc_value > SCTP_CMT_MAX) {
3892 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3896 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3898 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3899 SCTP_TCB_UNLOCK(stcb);
3901 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3902 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3903 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3904 (av->assoc_id == SCTP_ALL_ASSOC)) {
3905 SCTP_INP_WLOCK(inp);
3906 inp->sctp_cmt_on_off = av->assoc_value;
3907 SCTP_INP_WUNLOCK(inp);
3909 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3910 (av->assoc_id == SCTP_ALL_ASSOC)) {
3911 SCTP_INP_RLOCK(inp);
3912 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3913 SCTP_TCB_LOCK(stcb);
3914 stcb->asoc.sctp_cmt_on_off = av->assoc_value;
3915 SCTP_TCB_UNLOCK(stcb);
3917 SCTP_INP_RUNLOCK(inp);
3921 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
3922 error = ENOPROTOOPT;
3925 case SCTP_PLUGGABLE_CC:
3927 struct sctp_assoc_value *av;
3928 struct sctp_nets *net;
3930 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
3931 if ((av->assoc_value != SCTP_CC_RFC2581) &&
3932 (av->assoc_value != SCTP_CC_HSTCP) &&
3933 (av->assoc_value != SCTP_CC_HTCP) &&
3934 (av->assoc_value != SCTP_CC_RTCC)) {
3935 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
3939 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
3941 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3942 stcb->asoc.congestion_control_module = av->assoc_value;
3943 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3944 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3945 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3948 SCTP_TCB_UNLOCK(stcb);
3950 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
3951 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
3952 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
3953 (av->assoc_id == SCTP_ALL_ASSOC)) {
3954 SCTP_INP_WLOCK(inp);
3955 inp->sctp_ep.sctp_default_cc_module = av->assoc_value;
3956 SCTP_INP_WUNLOCK(inp);
3958 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
3959 (av->assoc_id == SCTP_ALL_ASSOC)) {
3960 SCTP_INP_RLOCK(inp);
3961 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3962 SCTP_TCB_LOCK(stcb);
3963 stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value];
3964 stcb->asoc.congestion_control_module = av->assoc_value;
3965 if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) {
3966 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
3967 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
3970 SCTP_TCB_UNLOCK(stcb);
3972 SCTP_INP_RUNLOCK(inp);
3977 case SCTP_CC_OPTION:
3979 struct sctp_cc_option *cc_opt;
3981 SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize);
3982 SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id);
3984 if (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC) {
3985 SCTP_INP_RLOCK(inp);
3986 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
3987 SCTP_TCB_LOCK(stcb);
3988 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) {
3989 (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1, cc_opt);
3991 SCTP_TCB_UNLOCK(stcb);
3993 SCTP_INP_RUNLOCK(inp);
3998 if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) {
4001 error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option) (stcb, 1,
4004 SCTP_TCB_UNLOCK(stcb);
4008 case SCTP_PLUGGABLE_SS:
4010 struct sctp_assoc_value *av;
4012 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4013 if ((av->assoc_value != SCTP_SS_DEFAULT) &&
4014 (av->assoc_value != SCTP_SS_ROUND_ROBIN) &&
4015 (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) &&
4016 (av->assoc_value != SCTP_SS_PRIORITY) &&
4017 (av->assoc_value != SCTP_SS_FAIR_BANDWITH) &&
4018 (av->assoc_value != SCTP_SS_FIRST_COME)) {
4019 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4023 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4025 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4026 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4027 stcb->asoc.stream_scheduling_module = av->assoc_value;
4028 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4029 SCTP_TCB_UNLOCK(stcb);
4031 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4032 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4033 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4034 (av->assoc_id == SCTP_ALL_ASSOC)) {
4035 SCTP_INP_WLOCK(inp);
4036 inp->sctp_ep.sctp_default_ss_module = av->assoc_value;
4037 SCTP_INP_WUNLOCK(inp);
4039 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4040 (av->assoc_id == SCTP_ALL_ASSOC)) {
4041 SCTP_INP_RLOCK(inp);
4042 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4043 SCTP_TCB_LOCK(stcb);
4044 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1);
4045 stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value];
4046 stcb->asoc.stream_scheduling_module = av->assoc_value;
4047 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1);
4048 SCTP_TCB_UNLOCK(stcb);
4050 SCTP_INP_RUNLOCK(inp);
4057 struct sctp_stream_value *av;
4059 SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize);
4060 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4062 if ((av->stream_id >= stcb->asoc.streamoutcnt) ||
4063 (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id],
4064 av->stream_value) < 0)) {
4065 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4068 SCTP_TCB_UNLOCK(stcb);
4070 if (av->assoc_id == SCTP_CURRENT_ASSOC) {
4071 SCTP_INP_RLOCK(inp);
4072 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4073 SCTP_TCB_LOCK(stcb);
4074 if (av->stream_id < stcb->asoc.streamoutcnt) {
4075 stcb->asoc.ss_functions.sctp_ss_set_value(stcb,
4077 &stcb->asoc.strmout[av->stream_id],
4080 SCTP_TCB_UNLOCK(stcb);
4082 SCTP_INP_RUNLOCK(inp);
4085 * Can't set stream value without
4088 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4094 case SCTP_CLR_STAT_LOG:
4095 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4100 struct sctp_assoc_value *av;
4102 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4103 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4106 stcb->asoc.context = av->assoc_value;
4107 SCTP_TCB_UNLOCK(stcb);
4109 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4110 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4111 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4112 (av->assoc_id == SCTP_ALL_ASSOC)) {
4113 SCTP_INP_WLOCK(inp);
4114 inp->sctp_context = av->assoc_value;
4115 SCTP_INP_WUNLOCK(inp);
4117 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4118 (av->assoc_id == SCTP_ALL_ASSOC)) {
4119 SCTP_INP_RLOCK(inp);
4120 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4121 SCTP_TCB_LOCK(stcb);
4122 stcb->asoc.context = av->assoc_value;
4123 SCTP_TCB_UNLOCK(stcb);
4125 SCTP_INP_RUNLOCK(inp);
4132 uint32_t *default_vrfid;
4134 SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize);
4135 if (*default_vrfid > SCTP_MAX_VRF_ID) {
4136 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4140 inp->def_vrf_id = *default_vrfid;
4143 case SCTP_DEL_VRF_ID:
4145 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4149 case SCTP_ADD_VRF_ID:
4151 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4155 case SCTP_DELAYED_SACK:
4157 struct sctp_sack_info *sack;
4159 SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize);
4160 SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id);
4161 if (sack->sack_delay) {
4162 if (sack->sack_delay > SCTP_MAX_SACK_DELAY)
4163 sack->sack_delay = SCTP_MAX_SACK_DELAY;
4164 if (MSEC_TO_TICKS(sack->sack_delay) < 1) {
4165 sack->sack_delay = TICKS_TO_MSEC(1);
4169 if (sack->sack_delay) {
4170 stcb->asoc.delayed_ack = sack->sack_delay;
4172 if (sack->sack_freq) {
4173 stcb->asoc.sack_freq = sack->sack_freq;
4175 SCTP_TCB_UNLOCK(stcb);
4177 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4178 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4179 (sack->sack_assoc_id == SCTP_FUTURE_ASSOC) ||
4180 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4181 SCTP_INP_WLOCK(inp);
4182 if (sack->sack_delay) {
4183 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(sack->sack_delay);
4185 if (sack->sack_freq) {
4186 inp->sctp_ep.sctp_sack_freq = sack->sack_freq;
4188 SCTP_INP_WUNLOCK(inp);
4190 if ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) ||
4191 (sack->sack_assoc_id == SCTP_ALL_ASSOC)) {
4192 SCTP_INP_RLOCK(inp);
4193 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4194 SCTP_TCB_LOCK(stcb);
4195 if (sack->sack_delay) {
4196 stcb->asoc.delayed_ack = sack->sack_delay;
4198 if (sack->sack_freq) {
4199 stcb->asoc.sack_freq = sack->sack_freq;
4201 SCTP_TCB_UNLOCK(stcb);
4203 SCTP_INP_RUNLOCK(inp);
4208 case SCTP_AUTH_CHUNK:
4210 struct sctp_authchunk *sauth;
4212 SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize);
4214 SCTP_INP_WLOCK(inp);
4215 if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) {
4216 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4219 SCTP_INP_WUNLOCK(inp);
4224 struct sctp_authkey *sca;
4225 struct sctp_keyhead *shared_keys;
4226 sctp_sharedkey_t *shared_key;
4227 sctp_key_t *key = NULL;
4230 SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize);
4231 if (sca->sca_keylength == 0) {
4232 size = optsize - sizeof(struct sctp_authkey);
4234 if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) {
4235 size = sca->sca_keylength;
4237 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4242 SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id);
4245 shared_keys = &stcb->asoc.shared_keys;
4246 /* clear the cached keys for this key id */
4247 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4249 * create the new shared key and
4253 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4255 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4257 SCTP_TCB_UNLOCK(stcb);
4261 shared_key = sctp_alloc_sharedkey();
4262 if (shared_key == NULL) {
4264 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4266 SCTP_TCB_UNLOCK(stcb);
4269 shared_key->key = key;
4270 shared_key->keyid = sca->sca_keynumber;
4271 error = sctp_insert_sharedkey(shared_keys, shared_key);
4272 SCTP_TCB_UNLOCK(stcb);
4274 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4275 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4276 (sca->sca_assoc_id == SCTP_FUTURE_ASSOC) ||
4277 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4278 SCTP_INP_WLOCK(inp);
4279 shared_keys = &inp->sctp_ep.shared_keys;
4281 * clear the cached keys on all
4282 * assocs for this key id
4284 sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber);
4286 * create the new shared key and
4290 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4292 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4294 SCTP_INP_WUNLOCK(inp);
4298 shared_key = sctp_alloc_sharedkey();
4299 if (shared_key == NULL) {
4301 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4303 SCTP_INP_WUNLOCK(inp);
4306 shared_key->key = key;
4307 shared_key->keyid = sca->sca_keynumber;
4308 error = sctp_insert_sharedkey(shared_keys, shared_key);
4309 SCTP_INP_WUNLOCK(inp);
4311 if ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) ||
4312 (sca->sca_assoc_id == SCTP_ALL_ASSOC)) {
4313 SCTP_INP_RLOCK(inp);
4314 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4315 SCTP_TCB_LOCK(stcb);
4316 shared_keys = &stcb->asoc.shared_keys;
4318 * clear the cached keys for
4321 sctp_clear_cachedkeys(stcb, sca->sca_keynumber);
4323 * create the new shared key
4324 * and insert/replace it
4327 key = sctp_set_key(sca->sca_key, (uint32_t) size);
4329 SCTP_TCB_UNLOCK(stcb);
4333 shared_key = sctp_alloc_sharedkey();
4334 if (shared_key == NULL) {
4336 SCTP_TCB_UNLOCK(stcb);
4339 shared_key->key = key;
4340 shared_key->keyid = sca->sca_keynumber;
4341 error = sctp_insert_sharedkey(shared_keys, shared_key);
4342 SCTP_TCB_UNLOCK(stcb);
4344 SCTP_INP_RUNLOCK(inp);
4349 case SCTP_HMAC_IDENT:
4351 struct sctp_hmacalgo *shmac;
4352 sctp_hmaclist_t *hmaclist;
4356 SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize);
4357 if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) ||
4358 (shmac->shmac_number_of_idents > 0xffff)) {
4359 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4363 hmaclist = sctp_alloc_hmaclist((uint16_t) shmac->shmac_number_of_idents);
4364 if (hmaclist == NULL) {
4365 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4369 for (i = 0; i < shmac->shmac_number_of_idents; i++) {
4370 hmacid = shmac->shmac_idents[i];
4371 if (sctp_auth_add_hmacid(hmaclist, hmacid)) {
4372 /* invalid HMACs were found */ ;
4373 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4375 sctp_free_hmaclist(hmaclist);
4376 goto sctp_set_hmac_done;
4379 for (i = 0; i < hmaclist->num_algo; i++) {
4380 if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) {
4381 /* already in list */
4385 if (i == hmaclist->num_algo) {
4386 /* not found in list */
4387 sctp_free_hmaclist(hmaclist);
4388 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4392 /* set it on the endpoint */
4393 SCTP_INP_WLOCK(inp);
4394 if (inp->sctp_ep.local_hmacs)
4395 sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
4396 inp->sctp_ep.local_hmacs = hmaclist;
4397 SCTP_INP_WUNLOCK(inp);
4401 case SCTP_AUTH_ACTIVE_KEY:
4403 struct sctp_authkeyid *scact;
4405 SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize);
4406 SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id);
4408 /* set the active key on the right place */
4410 /* set the active key on the assoc */
4411 if (sctp_auth_setactivekey(stcb,
4412 scact->scact_keynumber)) {
4413 SCTP_LTRACE_ERR_RET(inp, NULL, NULL,
4414 SCTP_FROM_SCTP_USRREQ,
4418 SCTP_TCB_UNLOCK(stcb);
4420 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4421 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4422 (scact->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4423 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4424 SCTP_INP_WLOCK(inp);
4425 if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) {
4426 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4429 SCTP_INP_WUNLOCK(inp);
4431 if ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4432 (scact->scact_assoc_id == SCTP_ALL_ASSOC)) {
4433 SCTP_INP_RLOCK(inp);
4434 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4435 SCTP_TCB_LOCK(stcb);
4436 sctp_auth_setactivekey(stcb, scact->scact_keynumber);
4437 SCTP_TCB_UNLOCK(stcb);
4439 SCTP_INP_RUNLOCK(inp);
4444 case SCTP_AUTH_DELETE_KEY:
4446 struct sctp_authkeyid *scdel;
4448 SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize);
4449 SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id);
4451 /* delete the key from the right place */
4453 if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) {
4454 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4457 SCTP_TCB_UNLOCK(stcb);
4459 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4460 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4461 (scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4462 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4463 SCTP_INP_WLOCK(inp);
4464 if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) {
4465 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4468 SCTP_INP_WUNLOCK(inp);
4470 if ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4471 (scdel->scact_assoc_id == SCTP_ALL_ASSOC)) {
4472 SCTP_INP_RLOCK(inp);
4473 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4474 SCTP_TCB_LOCK(stcb);
4475 sctp_delete_sharedkey(stcb, scdel->scact_keynumber);
4476 SCTP_TCB_UNLOCK(stcb);
4478 SCTP_INP_RUNLOCK(inp);
4483 case SCTP_AUTH_DEACTIVATE_KEY:
4485 struct sctp_authkeyid *keyid;
4487 SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize);
4488 SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id);
4490 /* deactivate the key from the right place */
4492 if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) {
4493 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4496 SCTP_TCB_UNLOCK(stcb);
4498 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4499 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4500 (keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) ||
4501 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4502 SCTP_INP_WLOCK(inp);
4503 if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) {
4504 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4507 SCTP_INP_WUNLOCK(inp);
4509 if ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) ||
4510 (keyid->scact_assoc_id == SCTP_ALL_ASSOC)) {
4511 SCTP_INP_RLOCK(inp);
4512 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4513 SCTP_TCB_LOCK(stcb);
4514 sctp_deact_sharedkey(stcb, keyid->scact_keynumber);
4515 SCTP_TCB_UNLOCK(stcb);
4517 SCTP_INP_RUNLOCK(inp);
4522 case SCTP_ENABLE_STREAM_RESET:
4524 struct sctp_assoc_value *av;
4526 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4527 if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) {
4528 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4532 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4534 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4535 SCTP_TCB_UNLOCK(stcb);
4537 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4538 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4539 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4540 (av->assoc_id == SCTP_ALL_ASSOC)) {
4541 SCTP_INP_WLOCK(inp);
4542 inp->local_strreset_support = (uint8_t) av->assoc_value;
4543 SCTP_INP_WUNLOCK(inp);
4545 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4546 (av->assoc_id == SCTP_ALL_ASSOC)) {
4547 SCTP_INP_RLOCK(inp);
4548 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4549 SCTP_TCB_LOCK(stcb);
4550 stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value;
4551 SCTP_TCB_UNLOCK(stcb);
4553 SCTP_INP_RUNLOCK(inp);
4558 case SCTP_RESET_STREAMS:
4560 struct sctp_reset_streams *strrst;
4561 int i, send_out = 0;
4564 SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize);
4565 SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id);
4567 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4571 if (stcb->asoc.reconfig_supported == 0) {
4573 * Peer does not support the chunk type.
4575 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4577 SCTP_TCB_UNLOCK(stcb);
4580 if (sizeof(struct sctp_reset_streams) +
4581 strrst->srs_number_streams * sizeof(uint16_t) > optsize) {
4583 SCTP_TCB_UNLOCK(stcb);
4586 if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) {
4588 if (stcb->asoc.stream_reset_outstanding) {
4589 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4591 SCTP_TCB_UNLOCK(stcb);
4595 if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) {
4598 if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) {
4599 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM);
4601 SCTP_TCB_UNLOCK(stcb);
4604 if ((send_in == 0) && (send_out == 0)) {
4605 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4607 SCTP_TCB_UNLOCK(stcb);
4610 for (i = 0; i < strrst->srs_number_streams; i++) {
4612 (strrst->srs_stream_list[i] > stcb->asoc.streamincnt)) {
4613 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4618 (strrst->srs_stream_list[i] > stcb->asoc.streamoutcnt)) {
4619 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4625 SCTP_TCB_UNLOCK(stcb);
4632 if (strrst->srs_number_streams) {
4633 for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) {
4634 strm = strrst->srs_stream_list[i];
4635 if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) {
4636 stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING;
4642 for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) {
4643 if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) {
4644 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING;
4651 error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams,
4652 strrst->srs_stream_list,
4653 send_in, 0, 0, 0, 0, 0);
4655 error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED);
4658 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4661 * For outgoing streams don't report any
4662 * problems in sending the request to the
4663 * application. XXX: Double check resetting
4668 SCTP_TCB_UNLOCK(stcb);
4671 case SCTP_ADD_STREAMS:
4673 struct sctp_add_streams *stradd;
4674 uint8_t addstream = 0;
4675 uint16_t add_o_strmcnt = 0;
4676 uint16_t add_i_strmcnt = 0;
4678 SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize);
4679 SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id);
4681 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4685 if (stcb->asoc.reconfig_supported == 0) {
4687 * Peer does not support the chunk type.
4689 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4691 SCTP_TCB_UNLOCK(stcb);
4694 if (stcb->asoc.stream_reset_outstanding) {
4695 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4697 SCTP_TCB_UNLOCK(stcb);
4700 if ((stradd->sas_outstrms == 0) &&
4701 (stradd->sas_instrms == 0)) {
4705 if (stradd->sas_outstrms) {
4707 /* We allocate here */
4708 add_o_strmcnt = stradd->sas_outstrms;
4709 if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) {
4710 /* You can't have more than 64k */
4715 if (stradd->sas_instrms) {
4720 * We allocate inside
4721 * sctp_send_str_reset_req()
4723 add_i_strmcnt = stradd->sas_instrms;
4724 cnt = add_i_strmcnt;
4725 cnt += stcb->asoc.streamincnt;
4726 if (cnt > 0x0000ffff) {
4727 /* You can't have more than 64k */
4731 if (cnt > (int)stcb->asoc.max_inbound_streams) {
4732 /* More than you are allowed */
4737 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0);
4738 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4740 SCTP_TCB_UNLOCK(stcb);
4743 case SCTP_RESET_ASSOC:
4748 SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize);
4749 SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value);
4751 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4755 if (stcb->asoc.reconfig_supported == 0) {
4757 * Peer does not support the chunk type.
4759 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
4761 SCTP_TCB_UNLOCK(stcb);
4764 if (stcb->asoc.stream_reset_outstanding) {
4765 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4767 SCTP_TCB_UNLOCK(stcb);
4771 * Is there any data pending in the send or sent
4774 if (!TAILQ_EMPTY(&stcb->asoc.send_queue) ||
4775 !TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
4778 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
4779 SCTP_TCB_UNLOCK(stcb);
4782 /* Do any streams have data queued? */
4783 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
4784 if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
4788 error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0);
4789 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED);
4790 SCTP_TCB_UNLOCK(stcb);
4793 case SCTP_CONNECT_X:
4794 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4795 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4799 error = sctp_do_connect_x(so, inp, optval, optsize, p, 0);
4801 case SCTP_CONNECT_X_DELAYED:
4802 if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) {
4803 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4807 error = sctp_do_connect_x(so, inp, optval, optsize, p, 1);
4809 case SCTP_CONNECT_X_COMPLETE:
4811 struct sockaddr *sa;
4813 /* FIXME MT: check correct? */
4814 SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize);
4817 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
4818 SCTP_INP_RLOCK(inp);
4819 stcb = LIST_FIRST(&inp->sctp_asoc_list);
4821 SCTP_TCB_LOCK(stcb);
4823 SCTP_INP_RUNLOCK(inp);
4826 * We increment here since
4827 * sctp_findassociation_ep_addr() wil do a
4828 * decrement if it finds the stcb as long as
4829 * the locked tcb (last argument) is NOT a
4832 SCTP_INP_INCR_REF(inp);
4833 stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
4835 SCTP_INP_DECR_REF(inp);
4840 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
4844 if (stcb->asoc.delayed_connection == 1) {
4845 stcb->asoc.delayed_connection = 0;
4846 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
4847 sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb,
4848 stcb->asoc.primary_destination,
4849 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8);
4850 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
4853 * already expired or did not use delayed
4856 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
4859 SCTP_TCB_UNLOCK(stcb);
4862 case SCTP_MAX_BURST:
4864 struct sctp_assoc_value *av;
4866 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4867 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4870 stcb->asoc.max_burst = av->assoc_value;
4871 SCTP_TCB_UNLOCK(stcb);
4873 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4874 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4875 (av->assoc_id == SCTP_FUTURE_ASSOC) ||
4876 (av->assoc_id == SCTP_ALL_ASSOC)) {
4877 SCTP_INP_WLOCK(inp);
4878 inp->sctp_ep.max_burst = av->assoc_value;
4879 SCTP_INP_WUNLOCK(inp);
4881 if ((av->assoc_id == SCTP_CURRENT_ASSOC) ||
4882 (av->assoc_id == SCTP_ALL_ASSOC)) {
4883 SCTP_INP_RLOCK(inp);
4884 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
4885 SCTP_TCB_LOCK(stcb);
4886 stcb->asoc.max_burst = av->assoc_value;
4887 SCTP_TCB_UNLOCK(stcb);
4889 SCTP_INP_RUNLOCK(inp);
4896 struct sctp_assoc_value *av;
4899 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
4900 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
4902 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
4903 ovh = SCTP_MED_OVERHEAD;
4905 ovh = SCTP_MED_V4_OVERHEAD;
4908 if (av->assoc_value) {
4909 stcb->asoc.sctp_frag_point = (av->assoc_value + ovh);
4911 stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4913 SCTP_TCB_UNLOCK(stcb);
4915 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
4916 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
4917 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
4918 SCTP_INP_WLOCK(inp);
4920 * FIXME MT: I think this is not in
4921 * tune with the API ID
4923 if (av->assoc_value) {
4924 inp->sctp_frag_point = (av->assoc_value + ovh);
4926 inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
4928 SCTP_INP_WUNLOCK(inp);
4930 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
4938 struct sctp_event_subscribe *events;
4940 SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize);
4942 SCTP_INP_WLOCK(inp);
4943 if (events->sctp_data_io_event) {
4944 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4946 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT);
4949 if (events->sctp_association_event) {
4950 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4952 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT);
4955 if (events->sctp_address_event) {
4956 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4958 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT);
4961 if (events->sctp_send_failure_event) {
4962 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4964 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
4967 if (events->sctp_peer_error_event) {
4968 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4970 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR);
4973 if (events->sctp_shutdown_event) {
4974 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4976 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
4979 if (events->sctp_partial_delivery_event) {
4980 sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4982 sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT);
4985 if (events->sctp_adaptation_layer_event) {
4986 sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4988 sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
4991 if (events->sctp_authentication_event) {
4992 sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4994 sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT);
4997 if (events->sctp_sender_dry_event) {
4998 sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT);
5000 sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT);
5003 if (events->sctp_stream_reset_event) {
5004 sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5006 sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5008 SCTP_INP_WUNLOCK(inp);
5010 SCTP_INP_RLOCK(inp);
5011 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5012 SCTP_TCB_LOCK(stcb);
5013 if (events->sctp_association_event) {
5014 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5016 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT);
5018 if (events->sctp_address_event) {
5019 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5021 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT);
5023 if (events->sctp_send_failure_event) {
5024 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5026 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT);
5028 if (events->sctp_peer_error_event) {
5029 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5031 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR);
5033 if (events->sctp_shutdown_event) {
5034 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5036 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT);
5038 if (events->sctp_partial_delivery_event) {
5039 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5041 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT);
5043 if (events->sctp_adaptation_layer_event) {
5044 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5046 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT);
5048 if (events->sctp_authentication_event) {
5049 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5051 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT);
5053 if (events->sctp_sender_dry_event) {
5054 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5056 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT);
5058 if (events->sctp_stream_reset_event) {
5059 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5061 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT);
5063 SCTP_TCB_UNLOCK(stcb);
5066 * Send up the sender dry event only for 1-to-1
5069 if (events->sctp_sender_dry_event) {
5070 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5071 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
5072 stcb = LIST_FIRST(&inp->sctp_asoc_list);
5074 SCTP_TCB_LOCK(stcb);
5075 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
5076 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
5077 (stcb->asoc.stream_queue_cnt == 0)) {
5078 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
5080 SCTP_TCB_UNLOCK(stcb);
5084 SCTP_INP_RUNLOCK(inp);
5087 case SCTP_ADAPTATION_LAYER:
5089 struct sctp_setadaptation *adap_bits;
5091 SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize);
5092 SCTP_INP_WLOCK(inp);
5093 inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind;
5094 inp->sctp_ep.adaptation_layer_indicator_provided = 1;
5095 SCTP_INP_WUNLOCK(inp);
5099 case SCTP_SET_INITIAL_DBG_SEQ:
5103 SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize);
5104 SCTP_INP_WLOCK(inp);
5105 inp->sctp_ep.initial_sequence_debug = *vvv;
5106 SCTP_INP_WUNLOCK(inp);
5110 case SCTP_DEFAULT_SEND_PARAM:
5112 struct sctp_sndrcvinfo *s_info;
5114 SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize);
5115 SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id);
5118 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5119 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5121 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5124 SCTP_TCB_UNLOCK(stcb);
5126 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5127 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5128 (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) ||
5129 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5130 SCTP_INP_WLOCK(inp);
5131 memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send)));
5132 SCTP_INP_WUNLOCK(inp);
5134 if ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) ||
5135 (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)) {
5136 SCTP_INP_RLOCK(inp);
5137 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
5138 SCTP_TCB_LOCK(stcb);
5139 if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) {
5140 memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send)));
5142 SCTP_TCB_UNLOCK(stcb);
5144 SCTP_INP_RUNLOCK(inp);
5149 case SCTP_PEER_ADDR_PARAMS:
5151 struct sctp_paddrparams *paddrp;
5152 struct sctp_nets *net;
5153 struct sockaddr *addr;
5155 #if defined(INET) && defined(INET6)
5156 struct sockaddr_in sin_store;
5160 SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize);
5161 SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id);
5163 #if defined(INET) && defined(INET6)
5164 if (paddrp->spp_address.ss_family == AF_INET6) {
5165 struct sockaddr_in6 *sin6;
5167 sin6 = (struct sockaddr_in6 *)&paddrp->spp_address;
5168 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5169 in6_sin6_2_sin(&sin_store, sin6);
5170 addr = (struct sockaddr *)&sin_store;
5172 addr = (struct sockaddr *)&paddrp->spp_address;
5175 addr = (struct sockaddr *)&paddrp->spp_address;
5178 addr = (struct sockaddr *)&paddrp->spp_address;
5181 net = sctp_findnet(stcb, addr);
5184 * We increment here since
5185 * sctp_findassociation_ep_addr() wil do a
5186 * decrement if it finds the stcb as long as
5187 * the locked tcb (last argument) is NOT a
5191 SCTP_INP_INCR_REF(inp);
5192 stcb = sctp_findassociation_ep_addr(&inp, addr,
5195 SCTP_INP_DECR_REF(inp);
5198 if ((stcb != NULL) && (net == NULL)) {
5200 if (addr->sa_family == AF_INET) {
5202 struct sockaddr_in *sin;
5204 sin = (struct sockaddr_in *)addr;
5205 if (sin->sin_addr.s_addr != INADDR_ANY) {
5206 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5207 SCTP_TCB_UNLOCK(stcb);
5214 if (addr->sa_family == AF_INET6) {
5215 struct sockaddr_in6 *sin6;
5217 sin6 = (struct sockaddr_in6 *)addr;
5218 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
5219 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5220 SCTP_TCB_UNLOCK(stcb);
5227 error = EAFNOSUPPORT;
5228 SCTP_TCB_UNLOCK(stcb);
5229 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
5234 if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) {
5236 SCTP_TCB_UNLOCK(stcb);
5237 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5240 if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) {
5242 SCTP_TCB_UNLOCK(stcb);
5243 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5247 /************************TCB SPECIFIC SET ******************/
5249 /************************NET SPECIFIC SET ******************/
5250 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5251 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
5252 !(net->dest_state & SCTP_ADDR_NOHB)) {
5253 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5254 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9);
5256 net->dest_state |= SCTP_ADDR_NOHB;
5258 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5259 if (paddrp->spp_hbinterval) {
5260 net->heart_beat_delay = paddrp->spp_hbinterval;
5261 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5262 net->heart_beat_delay = 0;
5264 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5265 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10);
5266 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5267 net->dest_state &= ~SCTP_ADDR_NOHB;
5269 if (paddrp->spp_flags & SPP_HB_DEMAND) {
5271 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5272 sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED);
5273 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5275 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5276 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5277 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5278 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
5280 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5281 net->mtu = paddrp->spp_pathmtu;
5282 switch (net->ro._l_addr.sa.sa_family) {
5285 net->mtu += SCTP_MIN_V4_OVERHEAD;
5290 net->mtu += SCTP_MIN_OVERHEAD;
5296 if (net->mtu < stcb->asoc.smallest_mtu) {
5297 sctp_pathmtu_adjustment(stcb, net->mtu);
5300 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5301 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5302 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5304 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5306 if (paddrp->spp_pathmaxrxt) {
5307 if (net->dest_state & SCTP_ADDR_PF) {
5308 if (net->error_count > paddrp->spp_pathmaxrxt) {
5309 net->dest_state &= ~SCTP_ADDR_PF;
5312 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5313 (net->error_count > net->pf_threshold)) {
5314 net->dest_state |= SCTP_ADDR_PF;
5315 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5316 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5317 stcb->sctp_ep, stcb, net,
5318 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12);
5319 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5322 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5323 if (net->error_count > paddrp->spp_pathmaxrxt) {
5324 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5325 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5328 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5329 net->dest_state |= SCTP_ADDR_REACHABLE;
5330 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5333 net->failure_threshold = paddrp->spp_pathmaxrxt;
5335 if (paddrp->spp_flags & SPP_DSCP) {
5336 net->dscp = paddrp->spp_dscp & 0xfc;
5340 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5341 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5342 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5343 net->flowlabel |= 0x80000000;
5348 /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
5349 if (paddrp->spp_pathmaxrxt != 0) {
5350 stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
5351 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5352 if (net->dest_state & SCTP_ADDR_PF) {
5353 if (net->error_count > paddrp->spp_pathmaxrxt) {
5354 net->dest_state &= ~SCTP_ADDR_PF;
5357 if ((net->error_count <= paddrp->spp_pathmaxrxt) &&
5358 (net->error_count > net->pf_threshold)) {
5359 net->dest_state |= SCTP_ADDR_PF;
5360 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
5361 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5362 stcb->sctp_ep, stcb, net,
5363 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13);
5364 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
5367 if (net->dest_state & SCTP_ADDR_REACHABLE) {
5368 if (net->error_count > paddrp->spp_pathmaxrxt) {
5369 net->dest_state &= ~SCTP_ADDR_REACHABLE;
5370 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
5373 if (net->error_count <= paddrp->spp_pathmaxrxt) {
5374 net->dest_state |= SCTP_ADDR_REACHABLE;
5375 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
5378 net->failure_threshold = paddrp->spp_pathmaxrxt;
5381 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5382 if (paddrp->spp_hbinterval != 0) {
5383 stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
5384 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5385 stcb->asoc.heart_beat_delay = 0;
5387 /* Turn back on the timer */
5388 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5389 if (paddrp->spp_hbinterval != 0) {
5390 net->heart_beat_delay = paddrp->spp_hbinterval;
5391 } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5392 net->heart_beat_delay = 0;
5394 if (net->dest_state & SCTP_ADDR_NOHB) {
5395 net->dest_state &= ~SCTP_ADDR_NOHB;
5397 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
5398 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14);
5399 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
5401 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5403 if (paddrp->spp_flags & SPP_HB_DISABLE) {
5404 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5405 if (!(net->dest_state & SCTP_ADDR_NOHB)) {
5406 net->dest_state |= SCTP_ADDR_NOHB;
5407 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5408 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
5410 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15);
5414 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5416 if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) {
5417 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5418 if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5419 sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net,
5420 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
5422 net->dest_state |= SCTP_ADDR_NO_PMTUD;
5423 net->mtu = paddrp->spp_pathmtu;
5424 switch (net->ro._l_addr.sa.sa_family) {
5427 net->mtu += SCTP_MIN_V4_OVERHEAD;
5432 net->mtu += SCTP_MIN_OVERHEAD;
5438 if (net->mtu < stcb->asoc.smallest_mtu) {
5439 sctp_pathmtu_adjustment(stcb, net->mtu);
5442 sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5444 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5445 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5446 if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
5447 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
5449 net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
5451 sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5453 if (paddrp->spp_flags & SPP_DSCP) {
5454 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5455 net->dscp = paddrp->spp_dscp & 0xfc;
5458 stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc;
5459 stcb->asoc.default_dscp |= 0x01;
5462 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5463 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
5464 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
5465 net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5466 net->flowlabel |= 0x80000000;
5469 stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5470 stcb->asoc.default_flowlabel |= 0x80000000;
5474 SCTP_TCB_UNLOCK(stcb);
5476 /************************NO TCB, SET TO default stuff ******************/
5477 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5478 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5479 (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC)) {
5480 SCTP_INP_WLOCK(inp);
5482 * For the TOS/FLOWLABEL stuff you
5483 * set it with the options on the
5486 if (paddrp->spp_pathmaxrxt != 0) {
5487 inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
5489 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO)
5490 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5491 else if (paddrp->spp_hbinterval != 0) {
5492 if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL)
5493 paddrp->spp_hbinterval = SCTP_MAX_HB_INTERVAL;
5494 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5496 if (paddrp->spp_flags & SPP_HB_ENABLE) {
5497 if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) {
5498 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0;
5499 } else if (paddrp->spp_hbinterval) {
5500 inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(paddrp->spp_hbinterval);
5502 sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5503 } else if (paddrp->spp_flags & SPP_HB_DISABLE) {
5504 sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT);
5506 if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
5507 sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5508 } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
5509 sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
5511 if (paddrp->spp_flags & SPP_DSCP) {
5512 inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc;
5513 inp->sctp_ep.default_dscp |= 0x01;
5516 if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) {
5517 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5518 inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff;
5519 inp->sctp_ep.default_flowlabel |= 0x80000000;
5523 SCTP_INP_WUNLOCK(inp);
5525 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5533 struct sctp_rtoinfo *srto;
5534 uint32_t new_init, new_min, new_max;
5536 SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize);
5537 SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id);
5540 if (srto->srto_initial)
5541 new_init = srto->srto_initial;
5543 new_init = stcb->asoc.initial_rto;
5545 new_max = srto->srto_max;
5547 new_max = stcb->asoc.maxrto;
5549 new_min = srto->srto_min;
5551 new_min = stcb->asoc.minrto;
5552 if ((new_min <= new_init) && (new_init <= new_max)) {
5553 stcb->asoc.initial_rto = new_init;
5554 stcb->asoc.maxrto = new_max;
5555 stcb->asoc.minrto = new_min;
5557 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5560 SCTP_TCB_UNLOCK(stcb);
5562 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5563 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5564 (srto->srto_assoc_id == SCTP_FUTURE_ASSOC)) {
5565 SCTP_INP_WLOCK(inp);
5566 if (srto->srto_initial)
5567 new_init = srto->srto_initial;
5569 new_init = inp->sctp_ep.initial_rto;
5571 new_max = srto->srto_max;
5573 new_max = inp->sctp_ep.sctp_maxrto;
5575 new_min = srto->srto_min;
5577 new_min = inp->sctp_ep.sctp_minrto;
5578 if ((new_min <= new_init) && (new_init <= new_max)) {
5579 inp->sctp_ep.initial_rto = new_init;
5580 inp->sctp_ep.sctp_maxrto = new_max;
5581 inp->sctp_ep.sctp_minrto = new_min;
5583 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5586 SCTP_INP_WUNLOCK(inp);
5588 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5594 case SCTP_ASSOCINFO:
5596 struct sctp_assocparams *sasoc;
5598 SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize);
5599 SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id);
5600 if (sasoc->sasoc_cookie_life) {
5601 /* boundary check the cookie life */
5602 if (sasoc->sasoc_cookie_life < 1000)
5603 sasoc->sasoc_cookie_life = 1000;
5604 if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) {
5605 sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE;
5609 if (sasoc->sasoc_asocmaxrxt)
5610 stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt;
5611 if (sasoc->sasoc_cookie_life) {
5612 stcb->asoc.cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5614 SCTP_TCB_UNLOCK(stcb);
5616 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
5617 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
5618 (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC)) {
5619 SCTP_INP_WLOCK(inp);
5620 if (sasoc->sasoc_asocmaxrxt)
5621 inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt;
5622 if (sasoc->sasoc_cookie_life) {
5623 inp->sctp_ep.def_cookie_life = MSEC_TO_TICKS(sasoc->sasoc_cookie_life);
5625 SCTP_INP_WUNLOCK(inp);
5627 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5635 struct sctp_initmsg *sinit;
5637 SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize);
5638 SCTP_INP_WLOCK(inp);
5639 if (sinit->sinit_num_ostreams)
5640 inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams;
5642 if (sinit->sinit_max_instreams)
5643 inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams;
5645 if (sinit->sinit_max_attempts)
5646 inp->sctp_ep.max_init_times = sinit->sinit_max_attempts;
5648 if (sinit->sinit_max_init_timeo)
5649 inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo;
5650 SCTP_INP_WUNLOCK(inp);
5653 case SCTP_PRIMARY_ADDR:
5655 struct sctp_setprim *spa;
5656 struct sctp_nets *net;
5657 struct sockaddr *addr;
5659 #if defined(INET) && defined(INET6)
5660 struct sockaddr_in sin_store;
5664 SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize);
5665 SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id);
5667 #if defined(INET) && defined(INET6)
5668 if (spa->ssp_addr.ss_family == AF_INET6) {
5669 struct sockaddr_in6 *sin6;
5671 sin6 = (struct sockaddr_in6 *)&spa->ssp_addr;
5672 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5673 in6_sin6_2_sin(&sin_store, sin6);
5674 addr = (struct sockaddr *)&sin_store;
5676 addr = (struct sockaddr *)&spa->ssp_addr;
5679 addr = (struct sockaddr *)&spa->ssp_addr;
5682 addr = (struct sockaddr *)&spa->ssp_addr;
5685 net = sctp_findnet(stcb, addr);
5688 * We increment here since
5689 * sctp_findassociation_ep_addr() wil do a
5690 * decrement if it finds the stcb as long as
5691 * the locked tcb (last argument) is NOT a
5695 SCTP_INP_INCR_REF(inp);
5696 stcb = sctp_findassociation_ep_addr(&inp, addr,
5699 SCTP_INP_DECR_REF(inp);
5703 if ((stcb != NULL) && (net != NULL)) {
5704 if (net != stcb->asoc.primary_destination) {
5705 if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
5706 /* Ok we need to set it */
5707 if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) {
5708 if ((stcb->asoc.alternate) &&
5709 (!(net->dest_state & SCTP_ADDR_PF)) &&
5710 (net->dest_state & SCTP_ADDR_REACHABLE)) {
5711 sctp_free_remote_addr(stcb->asoc.alternate);
5712 stcb->asoc.alternate = NULL;
5715 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5719 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5728 SCTP_TCB_UNLOCK(stcb);
5732 case SCTP_SET_DYNAMIC_PRIMARY:
5734 union sctp_sockstore *ss;
5736 error = priv_check(curthread,
5737 PRIV_NETINET_RESERVEDPORT);
5741 SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize);
5742 /* SUPER USER CHECK? */
5743 error = sctp_dynamic_set_primary(&ss->sa, vrf_id);
5746 case SCTP_SET_PEER_PRIMARY_ADDR:
5748 struct sctp_setpeerprim *sspp;
5749 struct sockaddr *addr;
5751 #if defined(INET) && defined(INET6)
5752 struct sockaddr_in sin_store;
5756 SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize);
5757 SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id);
5759 struct sctp_ifa *ifa;
5761 #if defined(INET) && defined(INET6)
5762 if (sspp->sspp_addr.ss_family == AF_INET6) {
5763 struct sockaddr_in6 *sin6;
5765 sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr;
5766 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
5767 in6_sin6_2_sin(&sin_store, sin6);
5768 addr = (struct sockaddr *)&sin_store;
5770 addr = (struct sockaddr *)&sspp->sspp_addr;
5773 addr = (struct sockaddr *)&sspp->sspp_addr;
5776 addr = (struct sockaddr *)&sspp->sspp_addr;
5778 ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
5780 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5784 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
5786 * Must validate the ifa found is in
5789 struct sctp_laddr *laddr;
5792 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
5793 if (laddr->ifa == NULL) {
5794 SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n",
5798 if (laddr->ifa == ifa) {
5804 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5809 switch (addr->sa_family) {
5813 struct sockaddr_in *sin;
5815 sin = (struct sockaddr_in *)addr;
5816 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
5817 &sin->sin_addr) != 0) {
5818 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5828 struct sockaddr_in6 *sin6;
5830 sin6 = (struct sockaddr_in6 *)addr;
5831 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
5832 &sin6->sin6_addr) != 0) {
5833 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5841 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5846 if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) {
5847 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5851 SCTP_TCB_UNLOCK(stcb);
5853 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5858 case SCTP_BINDX_ADD_ADDR:
5860 struct sctp_getaddresses *addrs;
5863 td = (struct thread *)p;
5864 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses,
5867 if (addrs->addr->sa_family == AF_INET) {
5868 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5869 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5873 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5874 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5880 if (addrs->addr->sa_family == AF_INET6) {
5881 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5882 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5886 if (td != NULL && (error = prison_local_ip6(td->td_ucred, &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5887 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5888 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5894 error = EAFNOSUPPORT;
5897 sctp_bindx_add_address(so, inp, addrs->addr,
5898 addrs->sget_assoc_id, vrf_id,
5902 case SCTP_BINDX_REM_ADDR:
5904 struct sctp_getaddresses *addrs;
5907 td = (struct thread *)p;
5909 SCTP_CHECK_AND_CAST(addrs, optval, struct sctp_getaddresses, optsize);
5911 if (addrs->addr->sa_family == AF_INET) {
5912 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in)) {
5913 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5917 if (td != NULL && (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)(addrs->addr))->sin_addr)))) {
5918 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5924 if (addrs->addr->sa_family == AF_INET6) {
5925 if (optsize < sizeof(struct sctp_getaddresses) - sizeof(struct sockaddr) + sizeof(struct sockaddr_in6)) {
5926 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
5931 (error = prison_local_ip6(td->td_ucred,
5932 &(((struct sockaddr_in6 *)(addrs->addr))->sin6_addr),
5933 (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
5934 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error);
5940 error = EAFNOSUPPORT;
5943 sctp_bindx_delete_address(inp, addrs->addr,
5944 addrs->sget_assoc_id, vrf_id,
5950 struct sctp_event *event;
5951 uint32_t event_type;
5953 SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize);
5954 SCTP_FIND_STCB(inp, stcb, event->se_assoc_id);
5955 switch (event->se_type) {
5956 case SCTP_ASSOC_CHANGE:
5957 event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT;
5959 case SCTP_PEER_ADDR_CHANGE:
5960 event_type = SCTP_PCB_FLAGS_RECVPADDREVNT;
5962 case SCTP_REMOTE_ERROR:
5963 event_type = SCTP_PCB_FLAGS_RECVPEERERR;
5965 case SCTP_SEND_FAILED:
5966 event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT;
5968 case SCTP_SHUTDOWN_EVENT:
5969 event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT;
5971 case SCTP_ADAPTATION_INDICATION:
5972 event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT;
5974 case SCTP_PARTIAL_DELIVERY_EVENT:
5975 event_type = SCTP_PCB_FLAGS_PDAPIEVNT;
5977 case SCTP_AUTHENTICATION_EVENT:
5978 event_type = SCTP_PCB_FLAGS_AUTHEVNT;
5980 case SCTP_STREAM_RESET_EVENT:
5981 event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT;
5983 case SCTP_SENDER_DRY_EVENT:
5984 event_type = SCTP_PCB_FLAGS_DRYEVNT;
5986 case SCTP_NOTIFICATIONS_STOPPED_EVENT:
5988 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
5991 case SCTP_ASSOC_RESET_EVENT:
5992 event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT;
5994 case SCTP_STREAM_CHANGE_EVENT:
5995 event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT;
5997 case SCTP_SEND_FAILED_EVENT:
5998 event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT;
6002 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6006 if (event_type > 0) {
6009 sctp_stcb_feature_on(inp, stcb, event_type);
6010 if (event_type == SCTP_PCB_FLAGS_DRYEVNT) {
6011 if (TAILQ_EMPTY(&stcb->asoc.send_queue) &&
6012 TAILQ_EMPTY(&stcb->asoc.sent_queue) &&
6013 (stcb->asoc.stream_queue_cnt == 0)) {
6014 sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED);
6018 sctp_stcb_feature_off(inp, stcb, event_type);
6020 SCTP_TCB_UNLOCK(stcb);
6023 * We don't want to send up a storm
6024 * of events, so return an error for
6027 if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) &&
6028 ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) == 0) &&
6029 ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) &&
6030 ((event->se_assoc_id == SCTP_ALL_ASSOC) ||
6031 (event->se_assoc_id == SCTP_CURRENT_ASSOC))) {
6032 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP);
6036 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6037 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6038 (event->se_assoc_id == SCTP_FUTURE_ASSOC) ||
6039 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6040 SCTP_INP_WLOCK(inp);
6042 sctp_feature_on(inp, event_type);
6044 sctp_feature_off(inp, event_type);
6046 SCTP_INP_WUNLOCK(inp);
6048 if ((event->se_assoc_id == SCTP_CURRENT_ASSOC) ||
6049 (event->se_assoc_id == SCTP_ALL_ASSOC)) {
6050 SCTP_INP_RLOCK(inp);
6051 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6052 SCTP_TCB_LOCK(stcb);
6054 sctp_stcb_feature_on(inp, stcb, event_type);
6056 sctp_stcb_feature_off(inp, stcb, event_type);
6058 SCTP_TCB_UNLOCK(stcb);
6060 SCTP_INP_RUNLOCK(inp);
6066 case SCTP_RECVRCVINFO:
6070 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6071 SCTP_INP_WLOCK(inp);
6073 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6075 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO);
6077 SCTP_INP_WUNLOCK(inp);
6080 case SCTP_RECVNXTINFO:
6084 SCTP_CHECK_AND_CAST(onoff, optval, int, optsize);
6085 SCTP_INP_WLOCK(inp);
6087 sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6089 sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO);
6091 SCTP_INP_WUNLOCK(inp);
6094 case SCTP_DEFAULT_SNDINFO:
6096 struct sctp_sndinfo *info;
6099 SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize);
6100 SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id);
6103 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6104 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6105 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6106 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6107 stcb->asoc.def_send.sinfo_flags |= policy;
6108 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6109 stcb->asoc.def_send.sinfo_context = info->snd_context;
6111 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6114 SCTP_TCB_UNLOCK(stcb);
6116 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6117 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6118 (info->snd_assoc_id == SCTP_FUTURE_ASSOC) ||
6119 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6120 SCTP_INP_WLOCK(inp);
6121 inp->def_send.sinfo_stream = info->snd_sid;
6122 policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags);
6123 inp->def_send.sinfo_flags = info->snd_flags;
6124 inp->def_send.sinfo_flags |= policy;
6125 inp->def_send.sinfo_ppid = info->snd_ppid;
6126 inp->def_send.sinfo_context = info->snd_context;
6127 SCTP_INP_WUNLOCK(inp);
6129 if ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) ||
6130 (info->snd_assoc_id == SCTP_ALL_ASSOC)) {
6131 SCTP_INP_RLOCK(inp);
6132 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6133 SCTP_TCB_LOCK(stcb);
6134 if (info->snd_sid < stcb->asoc.streamoutcnt) {
6135 stcb->asoc.def_send.sinfo_stream = info->snd_sid;
6136 policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags);
6137 stcb->asoc.def_send.sinfo_flags = info->snd_flags;
6138 stcb->asoc.def_send.sinfo_flags |= policy;
6139 stcb->asoc.def_send.sinfo_ppid = info->snd_ppid;
6140 stcb->asoc.def_send.sinfo_context = info->snd_context;
6142 SCTP_TCB_UNLOCK(stcb);
6144 SCTP_INP_RUNLOCK(inp);
6149 case SCTP_DEFAULT_PRINFO:
6151 struct sctp_default_prinfo *info;
6153 SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize);
6154 SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id);
6156 if (info->pr_policy > SCTP_PR_SCTP_MAX) {
6157 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6162 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6163 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6164 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6165 SCTP_TCB_UNLOCK(stcb);
6167 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6168 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6169 (info->pr_assoc_id == SCTP_FUTURE_ASSOC) ||
6170 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6171 SCTP_INP_WLOCK(inp);
6172 inp->def_send.sinfo_flags &= 0xfff0;
6173 inp->def_send.sinfo_flags |= info->pr_policy;
6174 inp->def_send.sinfo_timetolive = info->pr_value;
6175 SCTP_INP_WUNLOCK(inp);
6177 if ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) ||
6178 (info->pr_assoc_id == SCTP_ALL_ASSOC)) {
6179 SCTP_INP_RLOCK(inp);
6180 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
6181 SCTP_TCB_LOCK(stcb);
6182 stcb->asoc.def_send.sinfo_flags &= 0xfff0;
6183 stcb->asoc.def_send.sinfo_flags |= info->pr_policy;
6184 stcb->asoc.def_send.sinfo_timetolive = info->pr_value;
6185 SCTP_TCB_UNLOCK(stcb);
6187 SCTP_INP_RUNLOCK(inp);
6192 case SCTP_PEER_ADDR_THLDS:
6193 /* Applies to the specific association */
6195 struct sctp_paddrthlds *thlds;
6196 struct sctp_nets *net;
6197 struct sockaddr *addr;
6199 #if defined(INET) && defined(INET6)
6200 struct sockaddr_in sin_store;
6204 SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize);
6205 SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id);
6207 #if defined(INET) && defined(INET6)
6208 if (thlds->spt_address.ss_family == AF_INET6) {
6209 struct sockaddr_in6 *sin6;
6211 sin6 = (struct sockaddr_in6 *)&thlds->spt_address;
6212 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6213 in6_sin6_2_sin(&sin_store, sin6);
6214 addr = (struct sockaddr *)&sin_store;
6216 addr = (struct sockaddr *)&thlds->spt_address;
6219 addr = (struct sockaddr *)&thlds->spt_address;
6222 addr = (struct sockaddr *)&thlds->spt_address;
6225 net = sctp_findnet(stcb, addr);
6228 * We increment here since
6229 * sctp_findassociation_ep_addr() wil do a
6230 * decrement if it finds the stcb as long as
6231 * the locked tcb (last argument) is NOT a
6235 SCTP_INP_INCR_REF(inp);
6236 stcb = sctp_findassociation_ep_addr(&inp, addr,
6239 SCTP_INP_DECR_REF(inp);
6242 if ((stcb != NULL) && (net == NULL)) {
6244 if (addr->sa_family == AF_INET) {
6246 struct sockaddr_in *sin;
6248 sin = (struct sockaddr_in *)addr;
6249 if (sin->sin_addr.s_addr != INADDR_ANY) {
6250 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6251 SCTP_TCB_UNLOCK(stcb);
6258 if (addr->sa_family == AF_INET6) {
6259 struct sockaddr_in6 *sin6;
6261 sin6 = (struct sockaddr_in6 *)addr;
6262 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6263 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6264 SCTP_TCB_UNLOCK(stcb);
6271 error = EAFNOSUPPORT;
6272 SCTP_TCB_UNLOCK(stcb);
6273 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6279 net->failure_threshold = thlds->spt_pathmaxrxt;
6280 net->pf_threshold = thlds->spt_pathpfthld;
6281 if (net->dest_state & SCTP_ADDR_PF) {
6282 if ((net->error_count > net->failure_threshold) ||
6283 (net->error_count <= net->pf_threshold)) {
6284 net->dest_state &= ~SCTP_ADDR_PF;
6287 if ((net->error_count > net->pf_threshold) &&
6288 (net->error_count <= net->failure_threshold)) {
6289 net->dest_state |= SCTP_ADDR_PF;
6290 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6291 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6292 stcb->sctp_ep, stcb, net,
6293 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17);
6294 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6297 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6298 if (net->error_count > net->failure_threshold) {
6299 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6300 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6303 if (net->error_count <= net->failure_threshold) {
6304 net->dest_state |= SCTP_ADDR_REACHABLE;
6305 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6309 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6310 net->failure_threshold = thlds->spt_pathmaxrxt;
6311 net->pf_threshold = thlds->spt_pathpfthld;
6312 if (net->dest_state & SCTP_ADDR_PF) {
6313 if ((net->error_count > net->failure_threshold) ||
6314 (net->error_count <= net->pf_threshold)) {
6315 net->dest_state &= ~SCTP_ADDR_PF;
6318 if ((net->error_count > net->pf_threshold) &&
6319 (net->error_count <= net->failure_threshold)) {
6320 net->dest_state |= SCTP_ADDR_PF;
6321 sctp_send_hb(stcb, net, SCTP_SO_LOCKED);
6322 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
6323 stcb->sctp_ep, stcb, net,
6324 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18);
6325 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
6328 if (net->dest_state & SCTP_ADDR_REACHABLE) {
6329 if (net->error_count > net->failure_threshold) {
6330 net->dest_state &= ~SCTP_ADDR_REACHABLE;
6331 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED);
6334 if (net->error_count <= net->failure_threshold) {
6335 net->dest_state |= SCTP_ADDR_REACHABLE;
6336 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED);
6340 stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt;
6341 stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld;
6343 SCTP_TCB_UNLOCK(stcb);
6345 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6346 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6347 (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC)) {
6348 SCTP_INP_WLOCK(inp);
6349 inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt;
6350 inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld;
6351 SCTP_INP_WUNLOCK(inp);
6353 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6359 case SCTP_REMOTE_UDP_ENCAPS_PORT:
6361 struct sctp_udpencaps *encaps;
6362 struct sctp_nets *net;
6363 struct sockaddr *addr;
6365 #if defined(INET) && defined(INET6)
6366 struct sockaddr_in sin_store;
6370 SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize);
6371 SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id);
6373 #if defined(INET) && defined(INET6)
6374 if (encaps->sue_address.ss_family == AF_INET6) {
6375 struct sockaddr_in6 *sin6;
6377 sin6 = (struct sockaddr_in6 *)&encaps->sue_address;
6378 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
6379 in6_sin6_2_sin(&sin_store, sin6);
6380 addr = (struct sockaddr *)&sin_store;
6382 addr = (struct sockaddr *)&encaps->sue_address;
6385 addr = (struct sockaddr *)&encaps->sue_address;
6388 addr = (struct sockaddr *)&encaps->sue_address;
6391 net = sctp_findnet(stcb, addr);
6394 * We increment here since
6395 * sctp_findassociation_ep_addr() wil do a
6396 * decrement if it finds the stcb as long as
6397 * the locked tcb (last argument) is NOT a
6401 SCTP_INP_INCR_REF(inp);
6402 stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL);
6404 SCTP_INP_DECR_REF(inp);
6407 if ((stcb != NULL) && (net == NULL)) {
6409 if (addr->sa_family == AF_INET) {
6411 struct sockaddr_in *sin;
6413 sin = (struct sockaddr_in *)addr;
6414 if (sin->sin_addr.s_addr != INADDR_ANY) {
6415 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6416 SCTP_TCB_UNLOCK(stcb);
6423 if (addr->sa_family == AF_INET6) {
6424 struct sockaddr_in6 *sin6;
6426 sin6 = (struct sockaddr_in6 *)addr;
6427 if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
6428 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6429 SCTP_TCB_UNLOCK(stcb);
6436 error = EAFNOSUPPORT;
6437 SCTP_TCB_UNLOCK(stcb);
6438 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6444 net->port = encaps->sue_port;
6446 stcb->asoc.port = encaps->sue_port;
6448 SCTP_TCB_UNLOCK(stcb);
6450 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6451 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6452 (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC)) {
6453 SCTP_INP_WLOCK(inp);
6454 inp->sctp_ep.port = encaps->sue_port;
6455 SCTP_INP_WUNLOCK(inp);
6457 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6463 case SCTP_ECN_SUPPORTED:
6465 struct sctp_assoc_value *av;
6467 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6468 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6471 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6473 SCTP_TCB_UNLOCK(stcb);
6475 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6476 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6477 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6478 SCTP_INP_WLOCK(inp);
6479 if (av->assoc_value == 0) {
6480 inp->ecn_supported = 0;
6482 inp->ecn_supported = 1;
6484 SCTP_INP_WUNLOCK(inp);
6486 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6492 case SCTP_PR_SUPPORTED:
6494 struct sctp_assoc_value *av;
6496 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6497 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6500 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6502 SCTP_TCB_UNLOCK(stcb);
6504 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6505 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6506 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6507 SCTP_INP_WLOCK(inp);
6508 if (av->assoc_value == 0) {
6509 inp->prsctp_supported = 0;
6511 inp->prsctp_supported = 1;
6513 SCTP_INP_WUNLOCK(inp);
6515 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6521 case SCTP_AUTH_SUPPORTED:
6523 struct sctp_assoc_value *av;
6525 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6526 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6529 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6531 SCTP_TCB_UNLOCK(stcb);
6533 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6534 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6535 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6536 if ((av->assoc_value == 0) &&
6537 (inp->asconf_supported == 1)) {
6539 * AUTH is required for
6542 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6545 SCTP_INP_WLOCK(inp);
6546 if (av->assoc_value == 0) {
6547 inp->auth_supported = 0;
6549 inp->auth_supported = 1;
6551 SCTP_INP_WUNLOCK(inp);
6554 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6560 case SCTP_ASCONF_SUPPORTED:
6562 struct sctp_assoc_value *av;
6564 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6565 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6568 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6570 SCTP_TCB_UNLOCK(stcb);
6572 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6573 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6574 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6575 if ((av->assoc_value != 0) &&
6576 (inp->auth_supported == 0)) {
6578 * AUTH is required for
6581 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6584 SCTP_INP_WLOCK(inp);
6585 if (av->assoc_value == 0) {
6586 inp->asconf_supported = 0;
6587 sctp_auth_delete_chunk(SCTP_ASCONF,
6588 inp->sctp_ep.local_auth_chunks);
6589 sctp_auth_delete_chunk(SCTP_ASCONF_ACK,
6590 inp->sctp_ep.local_auth_chunks);
6592 inp->asconf_supported = 1;
6593 sctp_auth_add_chunk(SCTP_ASCONF,
6594 inp->sctp_ep.local_auth_chunks);
6595 sctp_auth_add_chunk(SCTP_ASCONF_ACK,
6596 inp->sctp_ep.local_auth_chunks);
6598 SCTP_INP_WUNLOCK(inp);
6601 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6607 case SCTP_RECONFIG_SUPPORTED:
6609 struct sctp_assoc_value *av;
6611 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6612 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6615 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6617 SCTP_TCB_UNLOCK(stcb);
6619 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6620 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6621 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6622 SCTP_INP_WLOCK(inp);
6623 if (av->assoc_value == 0) {
6624 inp->reconfig_supported = 0;
6626 inp->reconfig_supported = 1;
6628 SCTP_INP_WUNLOCK(inp);
6630 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6636 case SCTP_NRSACK_SUPPORTED:
6638 struct sctp_assoc_value *av;
6640 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6641 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6644 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6646 SCTP_TCB_UNLOCK(stcb);
6648 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6649 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6650 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6651 SCTP_INP_WLOCK(inp);
6652 if (av->assoc_value == 0) {
6653 inp->nrsack_supported = 0;
6655 inp->nrsack_supported = 1;
6657 SCTP_INP_WUNLOCK(inp);
6659 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6665 case SCTP_PKTDROP_SUPPORTED:
6667 struct sctp_assoc_value *av;
6669 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6670 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6673 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6675 SCTP_TCB_UNLOCK(stcb);
6677 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6678 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6679 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6680 SCTP_INP_WLOCK(inp);
6681 if (av->assoc_value == 0) {
6682 inp->pktdrop_supported = 0;
6684 inp->pktdrop_supported = 1;
6686 SCTP_INP_WUNLOCK(inp);
6688 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6696 struct sctp_assoc_value *av;
6697 struct sctp_nets *net;
6699 SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize);
6700 SCTP_FIND_STCB(inp, stcb, av->assoc_id);
6703 stcb->asoc.max_cwnd = av->assoc_value;
6704 if (stcb->asoc.max_cwnd > 0) {
6705 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
6706 if ((net->cwnd > stcb->asoc.max_cwnd) &&
6707 (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
6708 net->cwnd = stcb->asoc.max_cwnd;
6709 if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
6710 net->cwnd = net->mtu - sizeof(struct sctphdr);
6715 SCTP_TCB_UNLOCK(stcb);
6717 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
6718 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
6719 (av->assoc_id == SCTP_FUTURE_ASSOC)) {
6720 SCTP_INP_WLOCK(inp);
6721 inp->max_cwnd = av->assoc_value;
6722 SCTP_INP_WUNLOCK(inp);
6724 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6731 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT);
6732 error = ENOPROTOOPT;
6734 } /* end switch (opt) */
6739 sctp_ctloutput(struct socket *so, struct sockopt *sopt)
6741 void *optval = NULL;
6745 struct sctp_inpcb *inp;
6747 if ((sopt->sopt_level == SOL_SOCKET) &&
6748 (sopt->sopt_name == SO_SETFIB)) {
6749 inp = (struct sctp_inpcb *)so->so_pcb;
6751 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6754 SCTP_INP_WLOCK(inp);
6755 inp->fibnum = so->so_fibnum;
6756 SCTP_INP_WUNLOCK(inp);
6759 if (sopt->sopt_level != IPPROTO_SCTP) {
6760 /* wrong proto level... send back up to IP */
6762 if (INP_CHECK_SOCKAF(so, AF_INET6))
6763 error = ip6_ctloutput(so, sopt);
6765 #if defined(INET) && defined(INET6)
6769 error = ip_ctloutput(so, sopt);
6773 optsize = sopt->sopt_valsize;
6775 SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT);
6776 if (optval == NULL) {
6777 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
6780 error = sooptcopyin(sopt, optval, optsize, optsize);
6782 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6786 p = (void *)sopt->sopt_td;
6787 if (sopt->sopt_dir == SOPT_SET) {
6788 error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p);
6789 } else if (sopt->sopt_dir == SOPT_GET) {
6790 error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p);
6792 SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6795 if ((error == 0) && (optval != NULL)) {
6796 error = sooptcopyout(sopt, optval, optsize);
6797 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6798 } else if (optval != NULL) {
6799 SCTP_FREE(optval, SCTP_M_SOCKOPT);
6807 sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
6810 int create_lock_on = 0;
6812 struct sctp_inpcb *inp;
6813 struct sctp_tcb *stcb = NULL;
6815 inp = (struct sctp_inpcb *)so->so_pcb;
6817 /* I made the same as TCP since we are not setup? */
6818 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6819 return (ECONNRESET);
6822 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6825 switch (addr->sa_family) {
6829 struct sockaddr_in6 *sin6p;
6831 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
6832 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6835 sin6p = (struct sockaddr_in6 *)addr;
6836 if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6p->sin6_addr)) != 0) {
6837 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6846 struct sockaddr_in *sinp;
6848 if (addr->sa_len != sizeof(struct sockaddr_in)) {
6849 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6852 sinp = (struct sockaddr_in *)addr;
6853 if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sinp->sin_addr)) != 0) {
6854 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
6861 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
6862 return (EAFNOSUPPORT);
6864 SCTP_INP_INCR_REF(inp);
6865 SCTP_ASOC_CREATE_LOCK(inp);
6869 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
6870 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
6871 /* Should I really unlock ? */
6872 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT);
6877 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
6878 (addr->sa_family == AF_INET6)) {
6879 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6884 if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) ==
6885 SCTP_PCB_FLAGS_UNBOUND) {
6886 /* Bind a ephemeral port */
6887 error = sctp_inpcb_bind(so, NULL, NULL, p);
6892 /* Now do we connect? */
6893 if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
6894 (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) {
6895 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6899 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
6900 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
6901 /* We are already connected AND the TCP model */
6902 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
6906 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
6907 SCTP_INP_RLOCK(inp);
6908 stcb = LIST_FIRST(&inp->sctp_asoc_list);
6909 SCTP_INP_RUNLOCK(inp);
6912 * We increment here since sctp_findassociation_ep_addr()
6913 * will do a decrement if it finds the stcb as long as the
6914 * locked tcb (last argument) is NOT a TCB.. aka NULL.
6916 SCTP_INP_INCR_REF(inp);
6917 stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL);
6919 SCTP_INP_DECR_REF(inp);
6921 SCTP_TCB_UNLOCK(stcb);
6925 /* Already have or am bring up an association */
6926 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY);
6930 vrf_id = inp->def_vrf_id;
6931 /* We are GOOD to go */
6932 stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id, p);
6934 /* Gak! no memory */
6937 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
6938 stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
6939 /* Set the connected flag so we can queue data */
6942 SCTP_SET_STATE(&stcb->asoc, SCTP_STATE_COOKIE_WAIT);
6943 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
6945 /* initialize authentication parameters for the assoc */
6946 sctp_initialize_auth_params(inp, stcb);
6948 sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
6949 SCTP_TCB_UNLOCK(stcb);
6951 if (create_lock_on) {
6952 SCTP_ASOC_CREATE_UNLOCK(inp);
6954 SCTP_INP_DECR_REF(inp);
6961 sctp_listen(struct socket *so, int backlog, struct thread *p)
6964 * Note this module depends on the protocol processing being called
6965 * AFTER any socket level flags and backlog are applied to the
6966 * socket. The traditional way that the socket flags are applied is
6967 * AFTER protocol processing. We have made a change to the
6968 * sys/kern/uipc_socket.c module to reverse this but this MUST be in
6969 * place if the socket API for SCTP is to work properly.
6973 struct sctp_inpcb *inp;
6975 inp = (struct sctp_inpcb *)so->so_pcb;
6977 /* I made the same as TCP since we are not setup? */
6978 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
6979 return (ECONNRESET);
6981 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
6982 /* See if we have a listener */
6983 struct sctp_inpcb *tinp;
6984 union sctp_sockstore store;
6986 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
6988 struct sctp_laddr *laddr;
6990 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
6991 memcpy(&store, &laddr->ifa->address, sizeof(store));
6992 switch (store.sa.sa_family) {
6995 store.sin.sin_port = inp->sctp_lport;
7000 store.sin6.sin6_port = inp->sctp_lport;
7006 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7007 if (tinp && (tinp != inp) &&
7008 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7009 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7010 (tinp->sctp_socket->so_qlimit)) {
7012 * we have a listener already and
7015 SCTP_INP_DECR_REF(tinp);
7016 return (EADDRINUSE);
7018 SCTP_INP_DECR_REF(tinp);
7022 /* Setup a local addr bound all */
7023 memset(&store, 0, sizeof(store));
7025 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
7026 store.sa.sa_family = AF_INET6;
7027 store.sa.sa_len = sizeof(struct sockaddr_in6);
7031 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
7032 store.sa.sa_family = AF_INET;
7033 store.sa.sa_len = sizeof(struct sockaddr_in);
7036 switch (store.sa.sa_family) {
7039 store.sin.sin_port = inp->sctp_lport;
7044 store.sin6.sin6_port = inp->sctp_lport;
7050 tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id);
7051 if (tinp && (tinp != inp) &&
7052 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) &&
7053 ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) &&
7054 (tinp->sctp_socket->so_qlimit)) {
7056 * we have a listener already and its not
7059 SCTP_INP_DECR_REF(tinp);
7060 return (EADDRINUSE);
7062 SCTP_INP_DECR_REF(tinp);
7066 SCTP_INP_RLOCK(inp);
7067 #ifdef SCTP_LOCK_LOGGING
7068 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
7069 sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
7073 error = solisten_proto_check(so);
7076 SCTP_INP_RUNLOCK(inp);
7079 if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
7080 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
7082 * The unlucky case - We are in the tcp pool with this guy.
7083 * - Someone else is in the main inp slot. - We must move
7084 * this guy (the listener) to the main slot - We must then
7085 * move the guy that was listener to the TCP Pool.
7087 if (sctp_swap_inpcb_for_listen(inp)) {
7088 SCTP_INP_RUNLOCK(inp);
7089 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7090 return (EADDRINUSE);
7093 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
7094 (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) {
7095 /* We are already connected AND the TCP model */
7096 SCTP_INP_RUNLOCK(inp);
7097 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE);
7098 return (EADDRINUSE);
7100 SCTP_INP_RUNLOCK(inp);
7101 if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
7102 /* We must do a bind. */
7103 if ((error = sctp_inpcb_bind(so, NULL, NULL, p))) {
7104 /* bind error, probably perm */
7109 /* It appears for 7.0 and on, we must always call this. */
7110 solisten_proto(so, backlog);
7111 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7112 /* remove the ACCEPTCONN flag for one-to-many sockets */
7113 so->so_options &= ~SO_ACCEPTCONN;
7116 /* turning off listen */
7117 so->so_options &= ~SO_ACCEPTCONN;
7123 static int sctp_defered_wakeup_cnt = 0;
7126 sctp_accept(struct socket *so, struct sockaddr **addr)
7128 struct sctp_tcb *stcb;
7129 struct sctp_inpcb *inp;
7130 union sctp_sockstore store;
7136 inp = (struct sctp_inpcb *)so->so_pcb;
7139 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7140 return (ECONNRESET);
7142 SCTP_INP_RLOCK(inp);
7143 if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) {
7144 SCTP_INP_RUNLOCK(inp);
7145 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP);
7146 return (EOPNOTSUPP);
7148 if (so->so_state & SS_ISDISCONNECTED) {
7149 SCTP_INP_RUNLOCK(inp);
7150 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED);
7151 return (ECONNABORTED);
7153 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7155 SCTP_INP_RUNLOCK(inp);
7156 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7157 return (ECONNRESET);
7159 SCTP_TCB_LOCK(stcb);
7160 SCTP_INP_RUNLOCK(inp);
7161 store = stcb->asoc.primary_destination->ro._l_addr;
7162 stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
7163 SCTP_TCB_UNLOCK(stcb);
7164 switch (store.sa.sa_family) {
7168 struct sockaddr_in *sin;
7170 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7173 sin->sin_family = AF_INET;
7174 sin->sin_len = sizeof(*sin);
7175 sin->sin_port = store.sin.sin_port;
7176 sin->sin_addr = store.sin.sin_addr;
7177 *addr = (struct sockaddr *)sin;
7184 struct sockaddr_in6 *sin6;
7186 SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
7189 sin6->sin6_family = AF_INET6;
7190 sin6->sin6_len = sizeof(*sin6);
7191 sin6->sin6_port = store.sin6.sin6_port;
7192 sin6->sin6_addr = store.sin6.sin6_addr;
7193 if ((error = sa6_recoverscope(sin6)) != 0) {
7194 SCTP_FREE_SONAME(sin6);
7197 *addr = (struct sockaddr *)sin6;
7205 /* Wake any delayed sleep action */
7206 if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) {
7207 SCTP_INP_WLOCK(inp);
7208 inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE;
7209 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) {
7210 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
7211 SCTP_INP_WUNLOCK(inp);
7212 SOCKBUF_LOCK(&inp->sctp_socket->so_snd);
7213 if (sowriteable(inp->sctp_socket)) {
7214 sowwakeup_locked(inp->sctp_socket);
7216 SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd);
7218 SCTP_INP_WLOCK(inp);
7220 if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) {
7221 inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
7222 SCTP_INP_WUNLOCK(inp);
7223 SOCKBUF_LOCK(&inp->sctp_socket->so_rcv);
7224 if (soreadable(inp->sctp_socket)) {
7225 sctp_defered_wakeup_cnt++;
7226 sorwakeup_locked(inp->sctp_socket);
7228 SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv);
7230 SCTP_INP_WLOCK(inp);
7232 SCTP_INP_WUNLOCK(inp);
7234 if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
7235 SCTP_TCB_LOCK(stcb);
7236 sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
7237 SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19);
7244 sctp_ingetaddr(struct socket *so, struct sockaddr **addr)
7246 struct sockaddr_in *sin;
7248 struct sctp_inpcb *inp;
7249 struct sctp_ifa *sctp_ifa;
7252 * Do the malloc first in case it blocks.
7254 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7257 sin->sin_family = AF_INET;
7258 sin->sin_len = sizeof(*sin);
7259 inp = (struct sctp_inpcb *)so->so_pcb;
7261 SCTP_FREE_SONAME(sin);
7262 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7263 return (ECONNRESET);
7265 SCTP_INP_RLOCK(inp);
7266 sin->sin_port = inp->sctp_lport;
7267 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
7268 if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
7269 struct sctp_tcb *stcb;
7270 struct sockaddr_in *sin_a;
7271 struct sctp_nets *net;
7274 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7280 SCTP_TCB_LOCK(stcb);
7281 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7282 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7284 /* this will make coverity happy */
7287 if (sin_a->sin_family == AF_INET) {
7292 if ((!fnd) || (sin_a == NULL)) {
7294 SCTP_TCB_UNLOCK(stcb);
7297 vrf_id = inp->def_vrf_id;
7298 sctp_ifa = sctp_source_address_selection(inp,
7300 (sctp_route_t *) & net->ro,
7303 sin->sin_addr = sctp_ifa->address.sin.sin_addr;
7304 sctp_free_ifa(sctp_ifa);
7306 SCTP_TCB_UNLOCK(stcb);
7308 /* For the bound all case you get back 0 */
7310 sin->sin_addr.s_addr = 0;
7314 /* Take the first IPv4 address in the list */
7315 struct sctp_laddr *laddr;
7318 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
7319 if (laddr->ifa->address.sa.sa_family == AF_INET) {
7320 struct sockaddr_in *sin_a;
7322 sin_a = &laddr->ifa->address.sin;
7323 sin->sin_addr = sin_a->sin_addr;
7329 SCTP_FREE_SONAME(sin);
7330 SCTP_INP_RUNLOCK(inp);
7331 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7335 SCTP_INP_RUNLOCK(inp);
7336 (*addr) = (struct sockaddr *)sin;
7341 sctp_peeraddr(struct socket *so, struct sockaddr **addr)
7343 struct sockaddr_in *sin;
7345 struct sockaddr_in *sin_a;
7346 struct sctp_inpcb *inp;
7347 struct sctp_tcb *stcb;
7348 struct sctp_nets *net;
7350 /* Do the malloc first in case it blocks. */
7351 SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin);
7354 sin->sin_family = AF_INET;
7355 sin->sin_len = sizeof(*sin);
7357 inp = (struct sctp_inpcb *)so->so_pcb;
7358 if ((inp == NULL) ||
7359 ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
7360 /* UDP type and listeners will drop out here */
7361 SCTP_FREE_SONAME(sin);
7362 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
7365 SCTP_INP_RLOCK(inp);
7366 stcb = LIST_FIRST(&inp->sctp_asoc_list);
7368 SCTP_TCB_LOCK(stcb);
7370 SCTP_INP_RUNLOCK(inp);
7372 SCTP_FREE_SONAME(sin);
7373 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
7374 return (ECONNRESET);
7377 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
7378 sin_a = (struct sockaddr_in *)&net->ro._l_addr;
7379 if (sin_a->sin_family == AF_INET) {
7381 sin->sin_port = stcb->rport;
7382 sin->sin_addr = sin_a->sin_addr;
7386 SCTP_TCB_UNLOCK(stcb);
7388 /* No IPv4 address */
7389 SCTP_FREE_SONAME(sin);
7390 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
7393 (*addr) = (struct sockaddr *)sin;
7397 struct pr_usrreqs sctp_usrreqs = {
7398 .pru_abort = sctp_abort,
7399 .pru_accept = sctp_accept,
7400 .pru_attach = sctp_attach,
7401 .pru_bind = sctp_bind,
7402 .pru_connect = sctp_connect,
7403 .pru_control = in_control,
7404 .pru_close = sctp_close,
7405 .pru_detach = sctp_close,
7406 .pru_sopoll = sopoll_generic,
7407 .pru_flush = sctp_flush,
7408 .pru_disconnect = sctp_disconnect,
7409 .pru_listen = sctp_listen,
7410 .pru_peeraddr = sctp_peeraddr,
7411 .pru_send = sctp_sendm,
7412 .pru_shutdown = sctp_shutdown,
7413 .pru_sockaddr = sctp_ingetaddr,
7414 .pru_sosend = sctp_sosend,
7415 .pru_soreceive = sctp_soreceive